-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmymacros.inc
360 lines (303 loc) · 6.93 KB
/
mymacros.inc
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
;-----------------MACROS------
ShowMessage MACRO MyMessage
pusha
mov ah,9h
mov dx,offset MyMessage
int 21h
popa
ENDM ShowMessage
ShowThreeTimes MACRO MyMessage
LOCAL AGAIN
mov cx,3
mov ah,9h
mov dx,offset MyMessage
AGAIN:int 21h
LOOP AGAIN
ENDM ShowThreeTimes
TakeInput Macro InputBuffer ; take the value that shall be changed when taking an input
mov ah,0ah
mov dx,offset InputBuffer; ah and dx are altered
int 21h
ENDM TakeInput
DisplayChar Macro char
mov ah,2 ;output whatever in dl as 1 char
mov dl,char
int 21h
ENDM DisplayChar
NewLine Macro
DisplayChar 10
DisplayChar 13
ENDM NewLine
ReadChar Macro Num
mov ah,07
int 21h
mov dl, al
mov ah, 0
sub al,'0'
mov Num,ax
mov ah,2
int 21h
ENDM ReadChar
ShowMessageAtPos MACRO Pos
mov ah,9h
mov dx,pos
int 21h
ENDM ShowMessageAtPos
PrintRegister MACRO Result
LOCAL Loop1
LOCAL loop2
pusha
mov cx,0
mov bx,10
mov si, offset Result
Loop1:
mov dx,0
div bx
add dx,'0'
push dx
inc cx
cmp ax,9
jg Loop1
add ax,'0'
mov [si],ax
Loop2:
pop ax
inc si
mov [si],ax
loop Loop2
ShowMessage Result
popa
ENDM PrintRegister
FromRegToString MACRO Result, Color
LOCAL Loop1
LOCAL loop2
LOCAL Fill
LOCAL No
pusha
mov cx,0
mov bx,10
mov si, offset Result
Loop1:
mov dx,0
div bx
add dx,'0'
push dx
inc cx
cmp ax,9
jg Loop1
mov bx,2
sub bx,cx
Fill:
jz No
mov [si],'0'
inc si
dec bx
jnz Fill
No:
add ax,'0'
mov [si],ax
Loop2:
pop ax
inc si
mov [si],ax
loop Loop2
;Uncomment the following if you want a normal printable string (no color)
;inc si
;mov [si], ' '
;inc si
;mov [si], '$'
;ShowMessage Result (No color)
popa
ENDM FromRegToString
PrintStringWithColor MACRO Message
LOCAL Loop1
pusha
mov si, offset Message
mov di, 3 ;size of the message
; the color is stored in bl
Loop1:
mov al,[si]
inc si
mov cx,1
mov ah,9
int 10h
mov ah,3h
mov bh,0h
int 10h
inc dl
mov ah,2
int 10h
dec di
jnz Loop1
DisplayChar ' '
popa
ENDM PrintStringWithColor
ReadDecimalNumber Macro input, output
LOCAL pow
LOCAL NoPow
LOCAL Convert
LOCAL Sum
TakeInput input
mov cl, input[1]
dec cl
mov bl,10
mov al,1
pow:
cmp cl,0
je Nopow
mul bl
dec cl
jnz pow
NoPow:
mov si, offset input+2
mov bh, input[1]
Convert:
mov dl,[si]
sub dl,'0'
mov cl,al
mov al,dl
mul cl
push ax
mov ch,0
mov ax,cx
div bl
inc si
dec bh
jnz Convert
mov cl, input[1]
mov bx, 0
Sum:
pop ax
add bx,ax
dec cl
jnz Sum
mov output,bl ;up to 2-digits
;mov output,bx ;up to 3-digits
ENDM ReadDecimalNumber
MACRO DrawVerticalLine startX, startY, length, color
;StartX, StartY and length are words, color is a byte
pusha
LOCAL Draw
mov cx,startX
mov dx,startY
mov al,color
mov ah,0ch
mov bx,startY
add bx,length
Draw:
int 10h
inc dx
cmp dx,bx
jnz Draw
popa
ENDM DrawVerticalLine
MACRO DrawHorizontalLine startX, startY, length, color
;StartX, StartY and length are words, color is a byte
pusha
LOCAL Draw
mov cx,startX
mov dx,startY
mov al,color
mov ah,0ch
mov bx,startx
add bx,length
Draw:
int 10h
inc cx
cmp cx,bx
jnz Draw
popa
ENDM DrawHorizontalLine
MACRO DrawPixel x,y,color
pusha
mov cx,x
mov dx,y
mov al,color
mov ah,0ch
int 10h
popa
ENDM DrawPixel
CLEAR_SCREEN_UP MACRO
mov ax,0600h ;Scroll Screen AH=06 (Scroll),AL=0 Entire Page
mov bh,07 ;Normal attributes
mov cx,0 ;from 0,0
mov dx,184FH ;To 18h,4fh
int 10h
ENDM CLEAR_SCREEN_UP
MOVECURSOR MACRO ROW,COL
mov bh,00
MOV DH,ROW
MOV DL,COL
MOV AH,2
INT 10H
ENDM MOVECURSOR
scroll MACRO from, to
mov ah,06h ;Scroll Screen AH=06 (Scroll)
mov al,01h
mov bh,07 ;Normal attributes
mov cx, from ;from 0,0
mov dx, to ;To 18h,4fh
int 10h
ENDM scroll
;-----------------------------
;TEST
portinitialization MACRO
pusha
;Set Divisor Latch Access Bit
mov dx,3fbh ; Line Control Register
mov al,10000000b ;Set Divisor Latch Access Bit
out dx,al ;Out it
;Set LSB byte of the Baud Rate Divisor Latch register.
mov dx,3f8h
mov al,0ch
out dx,al
;Set MSB byte of the Baud Rate Divisor Latch register.
mov dx,3f9h
mov al,00h
out dx,al
;Set port configuration
mov dx,3fbh
mov al,00011011b
;0:Access to Receiver buffer, Transmitter buffer
;0:Set Break disabled
;011:Even Parity
;0:One Stop Bit
;11:8bits
out dx,al
popa
ENDM portinitialization
;send a value
send MACRO value
LOCAL AGAIN
pusha
;Check that Transmitter Holding Register is Empty
mov dx,3FDH ; Line Status Register
AGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ AGAIN
;If empty put the VALUE in Transmit data register
mov dx,3F8H ; Transmit data register
mov al,value
out dx,al
popa
ENDM send
;recieve a value
receive MACRO value
LOCAL read
LOCAL finish
pusha
;Check that Data Ready
mov dx,3FDH ; Line Status Register
in al,dx
AND al,1
jnz read
jmp finish
read:
;If Ready read the VALUE in Receive data register
mov dx,03F8H
in al,dx
mov value,al
finish:
popa
ENDM receive