-
Notifications
You must be signed in to change notification settings - Fork 0
/
consoleIO.asm
203 lines (190 loc) · 5.63 KB
/
consoleIO.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
.686P; Pentium Pro or later
.MODEL flat, stdcall
.STACK 4096
.data
externdef fileNamePrompt:BYTE
externdef fileNamePromptLen:DWORD
externdef tempoPrompt:BYTE
externdef tempoPromptLen:DWORD
externdef minTempoPrompt:BYTE
externdef minTempoPromptLen:DWORD
externdef maxTempoPrompt:BYTE
externdef maxTempoPromptLen:DWORD
externdef outTempoPrompt:BYTE
externdef outTempoPromptLen:DWORD
externdef measurePrompt:BYTE
externdef measurePromptLen:DWORD
externdef minMeasurePrompt:BYTE
externdef minMeasurePromptLen:DWORD
externdef maxMeasurePrompt:BYTE
externdef maxMeasurePromptLen:DWORD
externdef outMeasurePrompt:BYTE
externdef outMeasurePromptLen:DWORD
externdef errorMsg:BYTE
externdef errorMsgLen:DWORD
externdef segmentNumOobErr:BYTE
externdef measureNumOobErr:BYTE
externdef velocityOorErr:BYTE
externdef pitchOorErr:BYTE
externdef invalidRange:BYTE
externdef testStr:BYTE
externdef crLfStr:BYTE
externdef consoleOutHandle:DWORD
externdef consoleInHandle:DWORD
externdef bytesRead:DWORD
externdef numStr:BYTE
invalidInputMsg BYTE "You have put in an invalid input. Please try again."; if user entered something that was wrong
fileNamePrompt BYTE "Enter the filename: "; prompts user for file name
fileNamePromptLen DWORD $-fileNamePrompt
tempoPrompt BYTE "Please enter a tempo range. To set a specific tempo, type it in for both the min and the max."; explains prompted input for user
tempoPromptLen DWORD $-tempoPrompt
minTempoPrompt BYTE "Enter the minimum tempo: "; prompts for min bpm
minTempoPromptLen DWORD $-minTempoPrompt
maxTempoPrompt BYTE "Enter the maximum tempo: "; prompts for max bpm
maxTempoPromptLen DWORD $-maxTempoPrompt
outTempoPrompt BYTE "The generated tempo is: "; tells user the limited rng bpm
outTempoPromptLen DWORD $-outTempoPrompt
measurePrompt BYTE "Please enter a measure range. To set a specific number of measures, type it in for both the min and the max."; explains to user what next prompts are for
measurePromptLen DWORD $-measurePrompt
minMeasurePrompt BYTE "Enter the minimum number of measures: "; prompts for min wanted measures
minMeasurePromptLen DWORD $-minMeasurePrompt
maxMeasurePrompt BYTE "Enter the maximum number of measures: "; prompts for max wanted measuers
maxMeasurePromptLen DWORD $-maxMeasurePrompt
outMeasurePrompt BYTE "The generated number of measures is: "; outputs the limited rng measure generated
outMeasurePromptLen DWORD $-outMeasurePrompt
errorMsg BYTE "An error has occured. Terminating."; error message produced if something goes wrong
errorMsgLen DWORD $-errorMsg
segmentNumOobErr BYTE "The segment number (in ESI) is out of bounds!"; tells if user segment is out of bounds
measureNumOobErr BYTE "The message number (in BL) is out of bounds!"; tells if user message is out of bounds
velocityOorErr BYTE "The veloctiy (in BL) is too high!"; tells if inputted time is out of bounds
pitchOorErr BYTE "The pitch (in DL) is too high!"; tells if user pitch is too high
invalidRange BYTE "The range you specified is invalid!"
testStr BYTE "test"
crLfStr BYTE 0dh, 0ah
bytesWritten dd ?
bytesRead dd ?
consoleOutHandle DWORD ?
consoleInHandle DWORD ?
STD_OUTPUT_HANDLE DWORD -11
STD_INPUT_HANDLE DWORD -10
numStr BYTE 8 DUP(0), "h"
.code
GetStdHandle PROTO,
nStdHandle : DWORD
ReadConsoleA PROTO,
hConsoleInput : DWORD,
lpBuffer : DWORD,
nNumberOfCharsToRead : DWORD,
lpNumberOfCharsRead : DWORD,
pInputControl : DWORD
SetConsoleCP PROTO,
wCodePageID:DWORD
WriteConsoleA PROTO,
hConsoleOutput:DWORD,
lpBuffer : DWORD,
nNumberOfCharsToWrite : DWORD,
lpNumberOfCharsWritten : DWORD,
lpReserved : DWORD
writeConsole PROC,
prompt:DWORD,
promptSize:DWORD
invoke WriteConsoleA, consoleOutHandle, prompt, promptSize, offset bytesWritten, 0
ret
writeConsole ENDP
; ------------------------------------------------------------------------------
ConsoleWriteHex PROC USES EAX ECX EDX,
num:DWORD
; ------------------------------------------------------------------------------
mov ecx, 7
mov edx, num
mov eax, edx
convertLoop:
and eax, 0fh
cmp eax, 0ah
jae letter
add eax, 30h
jmp store
letter:
add eax, 37h
store:
mov numStr[ecx], al
shr edx, 4
mov eax, edx
cmp ecx, 0
je write
dec ecx
jmp convertLoop
write:
invoke WriteConsoleA, consoleOutHandle, offset numStr, 9, offset bytesWritten, 0
mov ecx, 7
resetLoop:
mov numStr[ecx], 0
cmp ecx, 0
je done
dec ecx
jmp resetLoop
done:
invoke writeConsole, offset crLfStr, 2
ret
ConsoleWriteHex ENDP
; ------------------------------------------------------------------------------ -
hexStrToNum PROC USES EBX ECX EDX,
value:DWORD,
; ------------------------------------------------------------------------------ -
xor eax, eax
xor ecx, ecx
check_hexit:
mov edx, value
add edx, ecx
cmp BYTE PTR[edx], "0"
jb finish
cmp BYTE PTR[edx], "9"
jbe add_digit_to_num
cmp BYTE PTR[edx], "f"
ja finish
cmp BYTE PTR[edx], "a"
jae add_lower_hexit_to_num
cmp BYTE PTR[edx], "F"
ja finish
cmp BYTE PTR[edx], "A"
jae add_upper_hexit_to_num
jmp finish
add_digit_to_num:
shl eax, 4
movzx ebx, BYTE PTR[edx]
sub ebx, DWORD PTR 30h
add eax, ebx
inc ecx
jmp check_hexit
add_upper_hexit_to_num:
shl eax, 4
movzx ebx, BYTE PTR[edx]
sub ebx, DWORD PTR 37h
add eax, ebx
inc ecx
jmp check_hexit
add_lower_hexit_to_num:
shl eax, 4
movzx ebx, BYTE PTR[edx]
sub ebx, DWORD PTR 57h
add eax, ebx
inc ecx
jmp check_hexit
finish:
ret
hexStrToNum ENDP
initIO proc uses eax
invoke SetConsoleCP, 65001
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov[consoleOutHandle], eax
invoke GetStdHandle, STD_INPUT_HANDLE
mov[consoleInHandle], eax
ret
initIO endp
readConsole PROC,
readLoc:DWORD,
readAmount:DWORD
INVOKE ReadConsoleA, consoleInHandle, readLoc, readAmount, OFFSET bytesRead, 0
ret
readConsole ENDP
END