source: xtideuniversalbios/trunk/Assembly_Library/Src/LibraryTests.asm@ 44

Last change on this file since 44 was 44, checked in by Tomi Tilli, 15 years ago

Spaces can now be generated before format specifier when printing formatted string.
Background character and attribute can now be easily specified before compiling.

File size: 15.5 KB
RevLine 
[41]1; File name : LibraryTests.asm
2; Project name : Assembly Library
3; Created date : 27.6.2010
[44]4; Last update : 27.9.2010
[41]5; Author : Tomi Tilli
6; Description : Tests for Assembly Library.
7; This file should not be included when using the library on
8; some other project.
9
10; Include .inc files
11%define INCLUDE_MENU_DIALOGS
12%include "AssemblyLibrary.inc" ; Assembly Library. Must be included first!
13
14
15; Section containing code
16SECTION .text
17
18; Program first instruction.
19ORG 100h ; Code starts at offset 100h (DOS .COM)
20Start:
21 jmp LibraryTests_Start
22
23; Include library sources
24%include "AssemblyLibrary.asm"
25
26
27;--------------------------------------------------------------------
28; Program start
29;--------------------------------------------------------------------
30ALIGN JUMP_ALIGN
31LibraryTests_Start:
32 CALL_DISPLAY_LIBRARY InitializeDisplayContext
33 CALL_DISPLAY_LIBRARY ClearScreen
34
35 call LibraryTests_ForDisplayLibrary
36 ;call LibraryTests_ForKeyboardLibrary
37 call LibraryTests_ForMenuLibrary
38
39 ; Exit to DOS
40 ;mov ax, CURSOR_XY(1, 1)
41 ;CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
42 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware
43 mov ax, 4C00h ; Exit to DOS
44 int 21h
45
46;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47ALIGN JUMP_ALIGN
48LibraryTests_ForMenuLibrary:
49 mov [cs:g_dialogInputOutput+DIALOG_INPUT.fszTitle+2], cs
50 mov [cs:g_dialogInputOutput+DIALOG_INPUT.fszItems+2], cs
51 mov [cs:g_dialogInputOutput+DIALOG_INPUT.fszInfo+2], cs
52
53 mov bx, .MenuEventHandler
54 call MenuInit_DisplayMenuWithHandlerInBXandUserDataInDXAX
55 ret
56
57ALIGN JUMP_ALIGN
58.MenuEventHandler:
59 jmp [cs:bx+.rgfnMenuEvents]
60.NotHandled:
61 clc ; Not handled so clear
62 ret
63
64ALIGN JUMP_ALIGN
65.InitializeMenu:
66 mov WORD [si+MENUINIT.wTimeoutTicks], 10000 / 55 ; 10 seconds
67 mov WORD [si+MENUINIT.wItems], 51
68 mov BYTE [si+MENUINIT.bWidth], 40
69 mov BYTE [si+MENUINIT.bHeight], 20
70 mov BYTE [si+MENUINIT.bTitleLines], TEST_MENU_TITLE_LINES
71 mov BYTE [si+MENUINIT.bInfoLines], TEST_MENU_INFO_LINES
72 mov ax, 1
73 CALL_MENU_LIBRARY HighlightItemFromAX
74 stc
75 ret
76
77ALIGN JUMP_ALIGN
78.RefreshTitle:
79 mov si, .szMenuTitle
80 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
81 stc
82 ret
83.szMenuTitle:
84 db "First line for menu title.",CR,LF,
85 db "This is the second line.",NULL
86
87ALIGN JUMP_ALIGN
88.RefreshInformation:
89 push bp
90 mov bp, sp
91 mov si, .szInfoTitle
92 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
93 pop bp
94 stc
95 ret
96.szInfoTitle:
97 db "Information line 1,",CR,LF,
98 db "Information line 2,",CR,LF,
99 db "This is the last information line.",NULL
100
101ALIGN JUMP_ALIGN
102.RefreshItemFromCX:
103 cmp cx, TEST_MENU_VALID_ITEMS
104 jb SHORT .PrintKnownItem
105
106 push bp
107 mov si, .szItem
108 mov bp, sp
109 push cx ; Item index
110 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
111 pop bp
112 stc
113 ret
114.szItem:
115 db "This is item %d.",NULL
116.PrintKnownItem:
117 mov si, cx
118 shl si, 1
119 mov si, [cs:si+.rgszItems]
120 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
121 stc
122 ret
123
124ALIGN JUMP_ALIGN
125.ItemSelectedFromCX:
126 push cs
127 pop ds
128 cmp cx, TEST_MENU_VALID_ITEMS
129 jae SHORT .ReturnWithoutHandling
130 mov bx, cx
131 shl bx, 1
132 jmp [bx+.rgfnSelectionHandler]
133.ReturnWithoutHandling:
134 stc
135 ret
136
137ALIGN WORD_ALIGN
138.rgfnSelectionHandler:
139 dw .ExitMenu
140 dw .ToggleTitle
141 dw .ToggleInfo
142 dw .ShowMessageDialogWithUnformattedText
143 dw .AskWordFromUser
144 dw .AskStringFromUser
145 dw .AskSelectionFromUser
146 dw .AskFileFromUser
147 dw .TestProgressBar
148
149
150ALIGN JUMP_ALIGN
151.ExitMenu:
152 CALL_MENU_LIBRARY Close
153 stc
154 ret
155
156ALIGN JUMP_ALIGN
157.ToggleTitle:
158 mov al, [bp+MENUINIT.bTitleLines]
159 xor al, TEST_MENU_TITLE_LINES
160 CALL_MENU_LIBRARY SetTitleHeightFromAL
161 jmp SHORT .RefreshMenuWindow
162ALIGN JUMP_ALIGN
163.ToggleInfo:
164 mov al, [bp+MENUINIT.bInfoLines]
165 xor al, TEST_MENU_INFO_LINES
166 CALL_MENU_LIBRARY SetInformationHeightFromAL
167.RefreshMenuWindow:
168 CALL_MENU_LIBRARY RestartTimeout
169 CALL_MENU_LIBRARY RefreshWindow
170 stc
171 ret
172
173ALIGN JUMP_ALIGN
174.ShowMessageDialogWithUnformattedText:
175 mov di, g_szVeryLongString
176 jmp .ShowDialogWithStringInCSDI
177
178ALIGN JUMP_ALIGN
179.AskWordFromUser:
180 mov si, g_dialogInputOutput
181 mov BYTE [si+WORD_DIALOG_IO.bNumericBase], 10
182 mov WORD [si+WORD_DIALOG_IO.wMin], 10
183 mov WORD [si+WORD_DIALOG_IO.wMax], 20
184 CALL_MENU_LIBRARY GetWordWithIoInDSSI
185
186 mov ax, [si+WORD_DIALOG_IO.wReturnWord]
187 mov di, g_szBuffer
188 call .FormatWordFromAXtoStringBufferInCSDI
189 call .ShowDialogWithStringInCSDI
190 stc
191 ret
192
193ALIGN JUMP_ALIGN
194.AskStringFromUser:
195 mov si, g_dialogInputOutput
196 mov WORD [si+STRING_DIALOG_IO.fnCharFilter], NULL
197 mov WORD [si+STRING_DIALOG_IO.wBufferSize], 17
198 mov WORD [si+STRING_DIALOG_IO.fpReturnBuffer], g_szBuffer
199 mov [si+STRING_DIALOG_IO.fpReturnBuffer+2], cs
200 CALL_MENU_LIBRARY GetStringWithIoInDSSI
201
202 mov di, g_szBuffer
203 call .ShowDialogWithStringInCSDI
204 stc
205 ret
206
207ALIGN JUMP_ALIGN
208.AskSelectionFromUser:
209 mov si, g_dialogInputOutput
210 mov WORD [si+DIALOG_INPUT.fszItems], .szSelections
211 CALL_MENU_LIBRARY GetSelectionToAXwithInputInDSSI
212
213 mov di, g_szBuffer
214 call .FormatWordFromAXtoStringBufferInCSDI
215 call .ShowDialogWithStringInCSDI
216 stc
217 ret
218.szSelections:
219 db "Cancel",LF
220 db "Yes",LF
221 db "No",NULL
222
223ALIGN JUMP_ALIGN
224.AskFileFromUser:
225 mov si, g_dialogInputOutput
226 mov WORD [si+DIALOG_INPUT.fszItems], g_szBuffer
227 mov BYTE [si+FILE_DIALOG_IO.bDialogFlags], FLG_FILEDIALOG_DIRECTORY | FLG_FILEDIALOG_NEW | FLG_FILEDIALOG_DRIVES
228 mov BYTE [si+FILE_DIALOG_IO.bFileAttributes], FLG_FILEATTR_DIRECTORY | FLG_FILEATTR_ARCHIVE
229 mov WORD [si+FILE_DIALOG_IO.fpFileFilterString], .szAllFiles
230 mov [si+FILE_DIALOG_IO.fpFileFilterString+2], cs
231 mov [si+STRING_DIALOG_IO.fpReturnBuffer+2], cs
232 CALL_MENU_LIBRARY GetFileNameWithIoInDSSI
233 cmp BYTE [g_dialogInputOutput+FILE_DIALOG_IO.bUserCancellation], TRUE
234 je SHORT .FileSelectionCancelled
235
236 mov di, g_dialogInputOutput + FILE_DIALOG_IO.szFile
237 call .ShowDialogWithStringInCSDI
238.FileSelectionCancelled:
239 stc
240 ret
241.szAllFiles:
242 db "*.*",NULL
243
244
245ALIGN JUMP_ALIGN
246.FormatWordFromAXtoStringBufferInCSDI:
247 push bp
248 push di
249 mov si, di
250 xchg cx, ax
251 CALL_DISPLAY_LIBRARY PushDisplayContext
252
253 mov bx, cs
254 mov ax, si
255 CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
[44]256 mov dl, ATTRIBUTES_NOT_USED
[41]257 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
[44]258 CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
[41]259 lea ax, [si+STRING_BUFFER_SIZE]
260 CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
261
262 mov si, .szFormatWord
263 mov bp, sp
264 push cx
265 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
266 mov al, NULL
267 CALL_DISPLAY_LIBRARY PrintCharacterFromAL ; Terminate buffer with NULL
268
269 CALL_DISPLAY_LIBRARY PopDisplayContext
270 pop di
271 pop bp
272 ret
273.szFormatWord:
274 db "Integer %d selected!",NULL
275
276
277ALIGN JUMP_ALIGN
278.ShowDialogWithStringInCSDI:
279 push cs
280 pop ds
281 mov si, g_dialogInputOutput
282 mov WORD [si+DIALOG_INPUT.fszItems], di
283 CALL_MENU_LIBRARY DisplayMessageWithInputInDSSI
284 stc
285 ret
286
287
288ALIGN JUMP_ALIGN
289.TestProgressBar:
290 push cs
291 pop ds
292 mov si, g_dialogInputOutput
293 mov WORD [si+PROGRESS_DIALOG_IO.wCurrentProgressValue], 0
294 mov WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue], 500
295 mov WORD [si+PROGRESS_DIALOG_IO.wMinProgressValue], 0
296 mov WORD [si+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI], .ProgressTaskWithParamInDSSI
297 mov ax, 500 ; Counter for progress task
298 CALL_MENU_LIBRARY StartProgressTaskWithIoInDSSIandParamInDXAX
299 stc
300 ret
301
302ALIGN JUMP_ALIGN
303.ProgressTaskWithParamInDSSI:
304 mov ax, 50000 ; 50 millisec delay
305 call Delay_MicrosecondsFromAX
306 dec si
307 CALL_MENU_LIBRARY SetUserDataFromDSSI
308 mov ax, 500
309 sub ax, si
310 push si
311 CALL_MENU_LIBRARY SetProgressValueFromAX
312 pop si
313 test si, si
314 jnz .ProgressTaskWithParamInDSSI
315 ret
316
317
318
319ALIGN WORD_ALIGN
320.rgfnMenuEvents:
321 dw .InitializeMenu ; .InitializeMenuinitToDSSI
322 dw .NotHandled ; .ExitMenu
323 dw .NotHandled ; .IdleProcessing
324 dw .NotHandled ; .ItemHighlightedFromCX
325 dw .ItemSelectedFromCX ; .ItemSelectedFromCX
326 dw .NotHandled ; .KeyStrokeInDX
327 dw .RefreshTitle ; .RefreshTitle
328 dw .RefreshInformation ; .RefreshInformation
329 dw .RefreshItemFromCX ; .RefreshItemFromCX
330
331.rgszItems:
332 dw .szExitMenu
333 dw .szToggleTitle
334 dw .szToggleInfo
335 dw .szShowMessage
336 dw .szAskWord
337 dw .szAskString
338 dw .szAskSelection
339 dw .szAskFile
340 dw .szTestProgress
341.szExitMenu: db "Exit menu",NULL
342.szToggleTitle: db "Toggle title",NULL
343.szToggleInfo: db "Toggle information",NULL
344.szShowMessage: db "Display unformatted message",NULL
345.szAskWord: db "Input word",NULL
346.szAskString: db "Input string",NULL
347.szAskSelection:db "Display selection dialog",NULL
348.szAskFile: db "Display file dialog",NULL
349.szTestProgress:db "Display progress bar",NULL
350TEST_MENU_VALID_ITEMS EQU 9
351TEST_MENU_TITLE_LINES EQU 2
352TEST_MENU_INFO_LINES EQU 3
353
354
355
356;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
357ALIGN JUMP_ALIGN
358LibraryTests_ForKeyboardLibrary:
359 mov ax, CURSOR_XY(0, 6)
360 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
361 call ReadUnsignedDecimalInteger
362 call ReadHexadecimalWord
363 ret
364
365
366ReadUnsignedDecimalInteger:
367 mov si, .szEnterUnsignedWord
368 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
369 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware ; Move hardware cursor
370
371 mov bx, 10 ; Numeric base
372 call Keyboard_ReadUserInputtedWordWhilePrinting
373
374 mov si, .szWordEntered
375 mov bp, sp
376 push ax
377 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
378 ret
379.szWordEntered:
380 db ". Word entered: %u",LF,CR,NULL
381.szEnterUnsignedWord:
382 db "Enter unsigned word: ",NULL
383
384
385ReadHexadecimalWord:
386 mov si, .szEnterHexadecimalWord
387 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
388 CALL_DISPLAY_LIBRARY SynchronizeDisplayContextToHardware ; Move hardware cursor
389
390 mov bx, 16 ; Numeric base
391 call Keyboard_ReadUserInputtedWordWhilePrinting
392
393 mov si, .szWordEntered
394 mov bp, sp
395 push ax
396 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
397 ret
398.szWordEntered:
399 db ". Word entered: %x",LF,CR,NULL
400.szEnterHexadecimalWord:
401 db "Enter hexadecimal word: ",NULL
402
403
404
405;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406ALIGN JUMP_ALIGN
407LibraryTests_ForDisplayLibrary:
408 CALL_DISPLAY_LIBRARY PushDisplayContext
409 call PrintHorizontalRuler
410 call PrintVerticalRuler
[44]411
412 mov al, COLOR_ATTRIBUTE(COLOR_BRIGHT_WHITE, COLOR_BLACK)
413 CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
[41]414
415 mov ax, CURSOR_XY(0, 1)
416 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
417 call PrintFormattedStrings
418
419 CALL_DISPLAY_LIBRARY PopDisplayContext
420 ret
421
422
423PrintHorizontalRuler:
424 mov ax, CURSOR_XY(0, 0)
425 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
426 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
427 eMOVZX cx, al
428 mov bx, 10<<8 ; Divider 10 to BH
429.ColumnNumberLoop:
430 eMOVZX ax, bl ; Column index to AX (0...79)
431 div bh ; AH = 0...9, AL = attribute
432 mov dx, ax
433 inc ax ; Increment attribute for non-black foreground
434 CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
435 xchg ax, dx
436 mov al, '0'
437 add al, ah ; AL = '0'...'9'
438 CALL_DISPLAY_LIBRARY PrintCharacterFromAL
439 inc bx ; Increment column index
440 loop .ColumnNumberLoop
441 ret
442
443
444PrintVerticalRuler:
445 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
446 eMOVZX cx, ah ; Number of rows to CX
447 dec ax ; Last column
448 xor ah, ah
449 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
450
451 dec cx ; Decrement rows to print last row outside loop
452 mov bx, 10<<8 ; BH = 10 (divider), BL = 0 (row index)
453 mov si, .szVerticalRulerCharacter
454.RowNumberLoop:
455 call .PrintRowNumberFromBL
456 inc bx ; Increment row index
457 loop .RowNumberLoop
458
459 ; Last row
460 mov si, .szLastVerticalRulerCharacter
461.PrintRowNumberFromBL:
462 eMOVZX ax, bl ; Row index to AX (0...24)
463 div bh ; AH = 0...9, AL = attribute
464 add al, COLOR_GRAY ; Start from color GRAY
465 mov bp, sp ; Prepare BP for string formatting
466 push ax ; Push attribute
467 eMOVZX ax, ah
468 push ax ; Push row index
469 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
470 ret
471
472.szVerticalRulerCharacter:
473 db "%A%u",LF,NULL
474.szLastVerticalRulerCharacter:
475 db "%A%u",NULL
476
477
478PrintFormattedStrings:
479 call .PrintIntegers
480 call .PrintHexadecimals
481 call .PrintCharacters
482 call .PrintStrings
483 call .RepeatChar
484 ret
485
486.PrintIntegers:
487 mov si, .szIntegers
488 mov bp, sp
489 ePUSH_T ax, COLOR_ATTRIBUTE(COLOR_RED, COLOR_BLACK)
490 ePUSH_T ax, -32768
491 ePUSH_T ax, -1
492 ePUSH_T ax, 0
493 ePUSH_T ax, 1
494 ePUSH_T ax, 65535
495 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
496 ret
497.szIntegers:
[44]498 db "Integers -32768, -1, 0, 1, 65535: %A|%6-d|%6-d|%6-d|%6-d|%6-u|",LF,CR,NULL
[41]499
500.PrintHexadecimals:
501 mov si, .szHexadecimals
502 mov bp, sp
503 ePUSH_T ax, COLOR_ATTRIBUTE(COLOR_RED, COLOR_BLACK)
504 ePUSH_T ax, 0CACAh
505 ePUSH_T ax, 0FFFFh
506 ePUSH_T ax, 0
507 ePUSH_T ax, 5A5Ah
508 ePUSH_T ax, 0A5A5h
509 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
510 ret
511.szHexadecimals:
[44]512 db "Hexadecimals CACAh, FFFFh, 0, 5A5Ah, A5A5h:%A|%6-x|%6-x|%6-x|%6-x|%6-x|",LF,CR,NULL
[41]513
514.PrintCharacters:
515 mov si, .szCharacters
516 mov bp, sp
517 ePUSH_T ax, COLOR_ATTRIBUTE(COLOR_RED, COLOR_BLACK)
518 ePUSH_T ax, 'a'
519 ePUSH_T ax, 'B'
520 ePUSH_T ax, 'c'
521 ePUSH_T ax, 'D'
522 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
523 ret
524.szCharacters:
525 db "Characters a, B, c, D, percent: %A|%6c|%6c|%6c|%6c|%6%|",LF,CR,NULL
526
527.PrintStrings:
528 mov si, .szStrings
529 mov bp, sp
530 ePUSH_T ax, COLOR_ATTRIBUTE(COLOR_RED, COLOR_BLACK)
531 ePUSH_T ax, .szCSSI
532 ePUSH_T ax, .szFar
533 push cs
534 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
535 ret
536.szStrings:
537 db "Strings ",'"',"Hello CSSI",'"'," and ",'"',"Far",'"',": %A|%20s|%13S|",LF,CR,NULL
538.szCSSI:
539 db "Hello CSSI",NULL
540.szFar:
541 db "Far",NULL
542
543.RepeatChar:
544 mov si, .szRepeat
545 mov bp, sp
546 ePUSH_T ax, COLOR_ATTRIBUTE(COLOR_RED, COLOR_BLACK)
547 ePUSH_T ax, '-'
548 ePUSH_T ax, 36
549 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
550 ret
551.szRepeat:
552 db "Repeating character '-': %A%t",LF,CR,NULL
553
554
555
556; Section containing initialized data
557;SECTION .data
558
559g_szDialogTitle:
560 db "This is a generic title for all dialogs.",NULL
561g_szDialogInfo:
562 db "This is a generic information for all dialogs.",NULL
563g_szVeryLongString:
564 db "This is a very long string containing multiple lines of text. This is needed "
565 db "so scroll bars and message dialog can be tested. This string does not use "
566 db "formatting so it should be simple to display this correctly. This string "
567 db "does, however, use newline characters. Lets change line right now!",CR,LF,
568 db "Well did it work? Let's try line feed alone",LF,"Well? "
569 db "We could also see what two spaces does _ _. There was two spaces between "
570 db "underscores. Lets try three this time _ _. Well, did they work correctly? "
571 db "What next, I guess that was all, no wait. Let's see what TAB does! Here it "
572 db "goes:",TAB,"Well did it work? Just one more time:",TAB,"Well are we good? "
573 db "No since LF is the only supported control character, unfortunately. "
574 db "This is the last sentence of this long string!",NULL
575
576g_dialogInputOutput:
577istruc DIALOG_INPUT
578 at DIALOG_INPUT.fszTitle, dw g_szDialogTitle
579 at DIALOG_INPUT.fszInfo, dw g_szDialogInfo
580iend
581 times 20 db 0
582
583
584; Section containing uninitialized data
585SECTION .bss
586
587STRING_BUFFER_SIZE EQU 100
588g_szBuffer:
Note: See TracBrowser for help on using the repository browser.