-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtests.asm
395 lines (308 loc) · 7.18 KB
/
tests.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
;===================================================================================================
; Testings
;
; Written By: Oded Cnaan ([email protected])
; Site: http://odedc.net
; Licence: GPLv3 (see LICENSE file)
; Package: AsmLib
;
; Description:
; Various test to validate functionality
;===================================================================================================
LOCALS @@
DATASEG
_bmp_file db "asset\\b1.bmp",0
_bmp db BMP_STRUCT_SIZE dup(0)
_sprite_w equ 30
_sprite_frames equ 6
_sprite_file db "asset\\sprite1.bmp",0
_sprite db BMP_STRUCT_SIZE dup(0)
_polygon dw 5,30,100,50,200,100,120,80,20,50
_keyPressedMsg db "Key was pressed","$"
_paletteFile db "asset\\bmp.pal",0
_arrRows equ 5
_arrCols equ 3
_arr2d dw _arrCols*_arrRows dup(1)
_string1 db "This is a test string.",0
_string2 db "And this is another string - ",0
db 50 dup(1)
_stringNeedle db "1234567",0
_stringHay db "123456",0
_stringDollar db "123456789",'$'
_stringEmpty db 50 dup(1)
;_palette db 400h dup(0)
CODESEG
;-----------------------------------------------------------------
; MAIN TEST FUNCTION
;-----------------------------------------------------------------
PROC TestMe
;call TestGetKey
;call TestShapes
;call TestBmp
;call TestSound
;call TestSavePalette
;call TestRandomAndPrint
;call TestPrint
;call TestMySprite
;call Test2DArray
;call TestFile
;call TestKeyboardISR
;call TestSimpleISR
call TestStrings
ret
ENDP TestMe
;///////////////////////////// BMP
PROC TestBmp
mov dx, offset _bmp_file
mov ax, offset _bmp
;grm_LoadBMPImage dx, [_dss], ax, [_dss]
push dx
push ds
push ax
push ds
call LoadBMPImage
mov ax, offset _bmp
grm_DisplayBMP ax, [_dss], 0, 5
mov ax, offset _bmp
grm_FreeBmp ax, [_dss]
@@end:
ret
ENDP TestBmp
;///////////////////////////// SPRITES
PROC TestMySprite
mov dx, offset _sprite_file
mov ax, offset _sprite
grm_LoadBMPImage dx, [_dss], ax, [_dss]
mov bx,0
@@kk:
grm_PlaySpriteInPlace bx, ax, ds, 0064h, 0064h, _sprite_w, _sprite_frames
inc bx
push 0003h
call Delay
cmp bx,_sprite_frames
jb @@kk
mov bx,0
jmp @@kk ; uncomment for infinite loop
@@outer:
ret
ENDP TestMySprite
;///////////////////////////// SOUND
PROC TestSound
mov cx,3
mov bx, 0122h
@@ss:
utm_Beep bx
utm_Sleep 1
utm_StopBeep
utm_Sleep 1
add bx, 80h
loop @@ss
ret
ENDP TestSound
;///////////////////////////// VGA PRINT
PROC TestRandomAndPrint
call RandomSeed
mov cx, 10
@@ddd:
call RandomByte
mov dx, ax
;PrintChar
PrintByteNewLine
call RandomByte
mov dx, ax
PrintByteNewLine
;PrintIntNewLine
call RandomByte
mov dx, ax
PrintByteNewLine
;PrintIntNewLine
loop @@ddd
ret
ENDP TestRandomAndPrint
;///////////////////////////// PRINT
PROC TestPrint
mov dl, 0dfh
call PrintByte
ret
ENDP TestPrint
;///////////////////////////// SHAPES
PROC TestShapes
mov ax, offset _polygon
grm_DrawPolygon 5, ax
gr_set_color GR_COLOR_YELLOW
grm_DrawRect 50,50,100,100
gr_set_color GR_COLOR_RED
grm_DrawLine 1,1,100,100
gr_set_color GR_COLOR_BLUE
grm_FillRect 200,20,80,50
call CopyDblBufToVideo
call WaitForKeypress
clear_screen_vga
call WaitForKeypress
gr_set_color GR_COLOR_BLUE
grm_DrawCircle 200,60,50
gr_set_color GR_COLOR_CYAN
grm_FillCircle 100,90,50
call CopyDblBufToVideo
@@exit:
ret
ENDP TestShapes
;///////////////////////////// GET KEY
PROC TestGetKey
gr_set_video_mode_txt
@@top:
call GetKeyboardKey
jnz @@cont
push ax
; key was pressed
mov dx, offset _keyPressedMsg
call PrintStr
call PrintSpace
pop ax
mov dx,ax
call PrintChar
cmp ax, SC_Q
je @@exit
utm_Sleep 1
clear_screen_txt
@@cont:
jmp @@top
@@exit:
ret
ENDP TestGetKey
;///////////////////////////// SAVE PALETTE
PROC TestSavePalette
;mov dx, offset _bmp_file
;mov ax, offset _bmp
;grm_LoadBMPImage dx, [_dss], ax, [_dss]
;mov ax, offset _bmp
;mov bx, offset _paletteFile
;grm_SavePalette ax, [_dss], bx
;push offset _paletteFile
;push ds
;push offset _palette
;push ds
;call LoadPalette
ret
ENDP TestSavePalette
;///////////////////////////// 2D ARRAY
PROC Test2DArray
mov cx,_arrCols*_arrRows ; 400h
mov si, offset _arr2d
xor dx,dx
@@init:
mov [word si], dx
inc dx
add si,2
loop @@init
mov bx, offset _arr2d
getCellAddress2dArrayWords si, bx, 2,1, _arrCols
setWordValue2dArray 66, bx, 2,1, _arrCols
ret
ENDP Test2DArray
;///////////////////////////// FILES
PROC TestFile
mov bx, offset _sprite_file
utm_fsize bx, ds
utm_fopen bx, ds
;mov cx, offset _palette
;utm_fread 50, cx, ds
utm_fclose
ret
ENDP TestFile
;///////////////////////////// KEYBOARD ISR
PROC TestKeyboardISR
call InitSampleISR
;call PrintFifoStatus
lea dx, [cs:KeyboardSampleISR]
push dx
push cs
call InstallKeyboardInterrupt
mov cx, 100
@@top:
call getcISR
cmp al,0
jne @@key
jmp @@next
@@key:
cmp al, 30 ; q
je @@end
mov dl, al
call PrintChar
;call PrintDecimal
mov dl,','
call PrintChar
@@next:
jmp @@top
@@end:
mov dl,'q'
call PrintChar
call RestoreKeyboardInterrupt
ret
ENDP TestKeyboardISR
;///////////////////////////// KEYBOARD SIMPLE ISR
PROC TestSimpleISR
lea dx, [cs:KeyboardISREvents]
push dx
push cs
call InstallKeyboardInterrupt
@@top:
call GetKeyboardKey
cmp al,0
jne @@key
jmp @@next
@@key:
cmp al, 30 ; q
je @@end
cmp al, 80h
ja @@next
mov dl, al
call PrintChar
;call PrintDecimal
mov dl,','
call PrintChar
@@next:
jmp @@top
@@end:
mov dl,'q'
call PrintChar
;call RestoreKeyboardInterrupt
ret
ENDP TestSimpleISR
;//////////////////////////// STRINGS
PROC TestStrings
jmp @@indexof
push offset _stringDollar
call StrlenDollar
mov dx, offset _string1
;call PrintCStr
;call PrintNewLine
push offset _stringEmpty
push offset _string1
call Strcpy
mov dx, offset _stringEmpty
call PrintCStr
call PrintNewLine
push offset _string2
push offset _string1
call Strcat
mov dx, offset _string2
call PrintCStr
call PrintNewLine
push offset _string2
push 'd'
call Strchr
push offset _string2
push offset _string2
call Strcmp
mov dl, al
call PrintByte
@@indexof:
push offset _stringHay
push offset _stringNeedle
call Strstr
mov dl, al
call PrintByte
@@end:
ret
ENDP TestStrings