1 ; **************************************************************************** 2 ; sinus3.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 19/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm sinus3.s -l sinus3.txt -o SINUS3.PRG -Z error.txt 9 ; (modified from 'sinus1.s', 19/02/2021) 10 11 ; Draw sinus wave/curve by using 'sysvideo' bx=0305h 12 13 ; 14/07/2020 14 ; 31/12/2017 15 ; TRDOS 386 (v2.0) system calls 16 _ver equ 0 17 _exit equ 1 18 _fork equ 2 19 _read equ 3 20 _write equ 4 21 _open equ 5 22 _close equ 6 23 _wait equ 7 24 _create equ 8 25 _rename equ 9 26 _delete equ 10 27 _exec equ 11 28 _chdir equ 12 29 _time equ 13 30 _mkdir equ 14 31 _chmod equ 15 32 _rmdir equ 16 33 _break equ 17 34 _drive equ 18 35 _seek equ 19 36 _tell equ 20 37 _memory equ 21 38 _prompt equ 22 39 _path equ 23 40 _env equ 24 41 _stime equ 25 42 _quit equ 26 43 _intr equ 27 44 _dir equ 28 45 _emt equ 29 46 _ldrvt equ 30 47 _video equ 31 48 _audio equ 32 49 _timer equ 33 50 _sleep equ 34 51 _msg equ 35 52 _geterr equ 36 53 _fpstat equ 37 54 _pri equ 38 55 _rele equ 39 56 _fff equ 40 57 _fnf equ 41 58 _alloc equ 42 59 _dalloc equ 43 60 _calbac equ 44 61 _dma equ 45 62 63 %macro sys 1-4 64 ; 29/04/2016 - TRDOS 386 (TRDOS v2.0) 65 ; 03/09/2015 66 ; 13/04/2015 67 ; Retro UNIX 386 v1 system call. 68 %if %0 >= 2 69 mov ebx, %2 70 %if %0 >= 3 71 mov ecx, %3 72 %if %0 = 4 73 mov edx, %4 74 %endif 75 %endif 76 %endif 77 mov eax, %1 78 ;int 30h 79 int 40h ; TRDOS 386 (TRDOS v2.0) 80 %endmacro 81 82 ; Retro UNIX 386 v1 system call format: 83 ; sys systemcall (eax) , , 84 85 [BITS 32] ; We need 32-bit intructions for protected mode 86 87 [ORG 0] 88 89 START_CODE: 90 ; clear bss 91 00000000 BF[4C070000] mov edi, bss_start 92 00000005 B900080000 mov ecx, (bss_end - bss_start)/4 93 ;xor eax, eax 94 0000000A F3AB rep stosd 95 96 ; program message 97 0000000C BE[7C010000] mov esi, program_msg 98 00000011 E8A2000000 call print_msg 99 100 00000016 30E4 xor ah, ah 101 ;int 16h ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY 102 ; Return: AH = scan code, AL = character 103 00000018 CD32 int 32h ; TRDOS 386 Keyboard interrupt 104 105 ; Set Video Mode to 101h ; 640x480, 256 colors 106 sys _video, 08FFh, 101h 106 <1> 106 <1> 106 <1> 106 <1> 106 <1> %if %0 >= 2 106 0000001A BBFF080000 <1> mov ebx, %2 106 <1> %if %0 >= 3 106 0000001F B901010000 <1> mov ecx, %3 106 <1> %if %0 = 4 106 <1> mov edx, %4 106 <1> %endif 106 <1> %endif 106 <1> %endif 106 00000024 B81F000000 <1> mov eax, %1 106 <1> 106 00000029 CD40 <1> int 40h 107 0000002B 09C0 or eax, eax 108 ;jz short terminate 109 ;mov [LFB_ADDR], edx ; pointer to LFB info table/structure 110 0000002D 750E jnz short set_vesa_mode_101h_ok 111 112 terminate: 113 0000002F E841010000 call set_text_mode 114 sys _exit 114 <1> 114 <1> 114 <1> 114 <1> 114 <1> %if %0 >= 2 114 <1> mov ebx, %2 114 <1> %if %0 >= 3 114 <1> mov ecx, %3 114 <1> %if %0 = 4 114 <1> mov edx, %4 114 <1> %endif 114 <1> %endif 114 <1> %endif 114 00000034 B801000000 <1> mov eax, %1 114 <1> 114 00000039 CD40 <1> int 40h 115 halt: 116 0000003B EBFE jmp short halt 117 118 set_vesa_mode_101h_ok: 119 0000003D C605[44070000]1C mov byte [color], 28 ; initial pixel color 120 _0: 121 00000044 E880000000 call drawsinewave 122 waitforkey: 123 ;mov ah, 1 124 ;int 32h 125 ;jz short getkey 126 ;inc word [counter] 127 ;nop 128 ;nop 129 ;nop 130 ;jmp short waitforkey 131 getkey: 132 00000049 30E4 xor ah, ah 133 0000004B CD32 int 32h 134 135 0000004D 663D032E cmp ax, 2E03h 136 00000051 74DC je short terminate 137 00000053 3C1B cmp al, 1Bh ; ESC key 138 00000055 74D8 je short terminate 139 140 00000057 3C2B cmp al, '+' 141 00000059 7508 jne short _1 142 143 0000005B FE05[44070000] inc byte [color] 144 00000061 EBE1 jmp short _0 145 _1: 146 00000063 3C2D cmp al, '-' 147 00000065 7508 jne short _2 148 149 00000067 FE0D[44070000] dec byte [color] 150 0000006D EBD5 jmp short _0 151 _2: 152 0000006F 3C20 cmp al, 20h ; space 153 00000071 7509 jne short _3 154 00000073 8005[44070000]08 add byte [color], 8 155 0000007A EBC8 jmp short _0 156 _3: 157 0000007C 80FC4B cmp ah, 4Bh 158 0000007F 7507 jne short _5 159 ; left arrow 160 _4: 161 00000081 E8DD000000 call beep 162 00000086 EBC1 jmp waitforkey 163 _5: 164 00000088 80FC4D cmp ah, 4Dh 165 0000008B 7502 jne short _6 166 167 ; right arrow 168 0000008D EBF2 jmp short _4 169 _6: 170 0000008F 80FC50 cmp ah, 50h 171 00000092 7502 jne short _7 172 ; down arrow 173 00000094 EBEB jmp short _4 174 _7: 175 00000096 80FC48 cmp ah, 48h 176 00000099 7502 jne short _8 177 ; up arrow 178 0000009B EBE4 jmp short _4 179 _8: 180 0000009D 663D0D1C cmp ax, 1C0Dh 181 000000A1 750E jne short _9 182 000000A3 E8BB000000 call beep 183 000000A8 8005[44070000]04 add byte [color], 4 184 000000AF EB93 jmp short _0 185 _9: 186 000000B1 E8AD000000 call beep 187 000000B6 EB91 jmp waitforkey 188 189 print_msg: 190 000000B8 B40E mov ah, 0Eh 191 000000BA BB07000000 mov ebx, 7 192 ;mov bl, 7 ; char attribute & color 193 p_next_chr: 194 000000BF AC lodsb 195 000000C0 08C0 or al, al 196 000000C2 7404 jz short p_retn ; retn 197 000000C4 CD31 int 31h 198 000000C6 EBF7 jmp short p_next_chr 199 p_retn: 200 000000C8 C3 retn 201 202 drawsinewave: 203 ; INPUT: 204 ; sinustable 205 ; 206 ; Modified registers: esi, edi, eax, ecx, ebx, edx 207 208 ; fill _fx table by using sine wave table 209 ; x = 0 to 639 210 ; y = +200 to -200 211 ; +200 --> 399 -> screen row position = (400-399)+39 = 40 212 ; -200 --> 0 -> screen row position = (400-0)+39 = 439 213 214 000000C9 BE[42020000] mov esi, sinustable 215 000000CE BF[4C070000] mov edi, _fx 216 000000D3 31C0 xor eax, eax 217 000000D5 29DB sub ebx, ebx ; 0 ; x 218 000000D7 31ED xor ebp, ebp ; pixel count 219 000000D9 66AD lodsw 220 000000DB EB45 jmp short _dsw_5 221 _dsw_0: 222 000000DD 66AD lodsw ; ax = 400-y value 223 ; 224 000000DF 6639C8 cmp ax, cx ; [prevy] 225 000000E2 743E je short _dsw_5 226 000000E4 7218 jb short _dsw_3 227 _dsw_1: 228 000000E6 6641 inc cx ; previous 400-y 229 000000E8 6639C8 cmp ax, cx 230 000000EB 7635 jna short _dsw_5 231 ; ebx = x 232 ; eax = 400 - y 233 000000ED E81A000000 call _dsw_4 234 000000F2 EBF2 jmp short _dsw_1 235 _dsw_2: 236 000000F4 50 push eax 237 000000F5 E858000000 call getpixeloffset 238 000000FA AB stosd 239 000000FB 58 pop eax 240 000000FC 45 inc ebp ; increase pixel count 241 000000FD C3 retn 242 _dsw_3: 243 000000FE 6649 dec cx ; previous 400-y 244 00000100 6639C8 cmp ax, cx 245 00000103 731D jnb short _dsw_5 246 ; ebx = x 247 ; eax = 400 - y 248 00000105 E802000000 call _dsw_4 249 0000010A EBF2 jmp short _dsw_3 250 _dsw_4: 251 0000010C 53 push ebx 252 0000010D 8B1D[48070000] mov ebx, [prevx] 253 00000113 91 xchg eax, ecx ; [prevy] 254 00000114 E8DBFFFFFF call _dsw_2 255 00000119 91 xchg ecx, eax 256 0000011A 5B pop ebx 257 0000011B FF05[48070000] inc dword [prevx] 258 00000121 C3 retn 259 _dsw_5: 260 00000122 891D[48070000] mov [prevx], ebx ; previous x value 261 00000128 89C1 mov ecx, eax ; previous 400-y value 262 0000012A E8C5FFFFFF call _dsw_2 263 0000012F 43 inc ebx 264 00000130 81FB80020000 cmp ebx, 640 265 00000136 72A5 jb short _dsw_0 266 267 00000138 BE[4C070000] mov esi, _fx 268 ;mov edx, ebp 269 ; 270 ; edx = pixel count 271 ; esi = user's single color pixel buffer address 272 sys _video, 0305h, [color], ebp 272 <1> 272 <1> 272 <1> 272 <1> 272 <1> %if %0 >= 2 272 0000013D BB05030000 <1> mov ebx, %2 272 <1> %if %0 >= 3 272 00000142 8B0D[44070000] <1> mov ecx, %3 272 <1> %if %0 = 4 272 00000148 89EA <1> mov edx, %4 272 <1> %endif 272 <1> %endif 272 <1> %endif 272 0000014A B81F000000 <1> mov eax, %1 272 <1> 272 0000014F CD40 <1> int 40h 273 274 00000151 C3 retn 275 276 getpixeloffset: 277 ; ebx = x position 278 ; eax = 400 - y position 279 00000152 BAB7010000 mov edx, 439 280 00000157 29C2 sub edx, eax ; convert row position from 400-y 281 ; row = (400-y)+39 282 00000159 B880020000 mov eax, 640 ; screen width 283 0000015E F7E2 mul edx 284 00000160 01D8 add eax, ebx ; add x to y*640 285 ; eax = pixel offset on display page 286 00000162 C3 retn 287 beep: 288 ; call beep function (16/64 second, 886Hz) 289 sys _audio, 16, 1331 289 <1> 289 <1> 289 <1> 289 <1> 289 <1> %if %0 >= 2 289 00000163 BB10000000 <1> mov ebx, %2 289 <1> %if %0 >= 3 289 00000168 B933050000 <1> mov ecx, %3 289 <1> %if %0 = 4 289 <1> mov edx, %4 289 <1> %endif 289 <1> %endif 289 <1> %endif 289 0000016D B820000000 <1> mov eax, %1 289 <1> 289 00000172 CD40 <1> int 40h 290 00000174 C3 retn 291 292 set_text_mode: 293 00000175 30E4 xor ah, ah 294 00000177 B003 mov al, 3 295 ;int 10h ; al = 03h text mode, int 10 video 296 00000179 CD31 int 31h ; TRDOS 386 - Video interrupt 297 0000017B C3 retn 298 299 program_msg: 300 0000017C 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Sine Wave" 300 00000185 2076322E302E33202D- 300 0000018E 202827737973766964- 300 00000197 656F27292054657374- 300 000001A0 2050726F6772616D20- 300 000001A9 2D2044726177205369- 300 000001B2 6E652057617665 301 000001B9 0D0A db 0Dh, 0Ah 302 000001BB 6279204572646F6761- db "by Erdogan Tan - 19/02/2021" 302 000001C4 6E2054616E202D2031- 302 000001CD 392F30322F32303231 303 ;db 0Dh, 0Ah, 0 304 000001D6 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 305 306 000001DA 557365205350414345- db "Use SPACE,ENTER,'+','-' keys to change COLOR .." 306 000001E3 2C454E5445522C272B- 306 000001EC 272C272D27206B6579- 306 000001F5 7320746F206368616E- 306 000001FE 676520434F4C4F5220- 306 00000207 2E2E 307 00000209 0D0A db 0Dh, 0Ah 308 0000020B 507265737320455343- db "Press ESC to exit .." 308 00000214 20746F206578697420- 308 0000021D 2E2E 309 0000021F 0D0A db 0Dh, 0Ah 310 00000221 0D0A db 0Dh, 0Ah 311 00000223 507265737320616E79- db "Press any key to continue .." 311 0000022C 206B657920746F2063- 311 00000235 6F6E74696E7565202E- 311 0000023E 2E 312 nextline: 313 0000023F 0D0A00 db 0Dh, 0Ah, 0 314 315 sinustable: ; sine wave table (x=0 to 639, y= +200 to -200) 316 ; 19/02/2021 317 ; https://daycounter.com/Calculators/Sine-Generator-Calculator2.phtml 318 ; 640x400 (x= 0 to 639, y = 0 to 399) 319 00000242 C800C900CB00CD00CF- dw 200,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229 319 0000024B 00D100D300D500D700- 319 00000254 D900DB00DD00DF00E1- 319 0000025D 00E300E500 320 00000262 E700E900EB00EC00EE- dw 231,233,235,236,238,240,242,244,246,248,250,252,254,256,257,259 320 0000026B 00F000F200F400F600- 320 00000274 F800FA00FC00FE0000- 320 0000027D 0101010301 321 00000282 0501070109010B010D- dw 261,263,265,267,269,270,272,274,276,278,279,281,283,285,287,288 321 0000028B 010E01100112011401- 321 00000294 1601170119011B011D- 321 0000029D 011F012001 322 000002A2 220124012601270129- dw 290,292,294,295,297,299,300,302,304,305,307,309,310,312,314,315 322 000002AB 012B012C012E013001- 322 000002B4 310133013501360138- 322 000002BD 013A013B01 323 000002C2 3D013E014001410143- dw 317,318,320,321,323,325,326,328,329,331,332,333,335,336,338,339 323 000002CB 014501460148014901- 323 000002D4 4B014C014D014F0150- 323 000002DD 0152015301 324 000002E2 55015601570159015A- dw 341,342,343,345,346,347,349,350,351,352,354,355,356,357,359,360 324 000002EB 015B015D015E015F01- 324 000002F4 600162016301640165- 324 000002FD 0167016801 325 00000302 69016A016B016C016D- dw 361,362,363,364,365,366,368,369,370,371,372,373,374,375,375,376 325 0000030B 016E01700171017201- 325 00000314 730174017501760177- 325 0000031D 0177017801 326 00000322 79017A017B017C017D- dw 377,378,379,380,381,381,382,383,384,385,385,386,387,387,388,389 326 0000032B 017D017E017F018001- 326 00000334 810181018201830183- 326 0000033D 0184018501 327 00000342 850186018601870188- dw 389,390,390,391,392,392,393,393,393,394,394,395,395,396,396,396 327 0000034B 018801890189018901- 327 00000354 8A018A018B018B018C- 327 0000035D 018C018C01 328 00000362 8D018D018D018D018E- dw 397,397,397,397,398,398,398,398,398,399,399,399,399,399,399,399 328 0000036B 018E018E018E018E01- 328 00000374 8F018F018F018F018F- 328 0000037D 018F018F01 329 00000382 8F018F018F018F018F- dw 399,399,399,399,399,399,399,399,398,398,398,398,398,397,397,397 329 0000038B 018F018F018F018E01- 329 00000394 8E018E018E018E018D- 329 0000039D 018D018D01 330 000003A2 8D018C018C018C018B- dw 397,396,396,396,395,395,394,394,393,393,393,392,392,391,390,390 330 000003AB 018B018A018A018901- 330 000003B4 890189018801880187- 330 000003BD 0186018601 331 000003C2 850185018401830183- dw 389,389,388,387,387,386,385,385,384,383,382,381,381,380,379,378 331 000003CB 018201810181018001- 331 000003D4 7F017E017D017D017C- 331 000003DD 017B017A01 332 000003E2 790178017701770176- dw 377,376,375,375,374,373,372,371,370,369,368,366,365,364,363,362 332 000003EB 017501740173017201- 332 000003F4 710170016E016D016C- 332 000003FD 016B016A01 333 00000402 690168016701650164- dw 361,360,359,357,356,355,354,352,351,350,349,347,346,345,343,342 333 0000040B 016301620160015F01- 333 00000414 5E015D015B015A0159- 333 0000041D 0157015601 334 00000422 55015301520150014F- dw 341,339,338,336,335,333,332,331,329,328,326,325,323,321,320,318 334 0000042B 014D014C014B014901- 334 00000434 480146014501430141- 334 0000043D 0140013E01 335 00000442 3D013B013A01380136- dw 317,315,314,312,310,309,307,305,304,302,300,299,297,295,294,292 335 0000044B 013501330131013001- 335 00000454 2E012C012B01290127- 335 0000045D 0126012401 336 00000462 220120011F011D011B- dw 290,288,287,285,283,281,279,278,276,274,272,270,269,267,265,263 336 0000046B 011901170116011401- 336 00000474 120110010E010D010B- 336 0000047D 0109010701 337 00000482 0501030101010001FE- dw 261,259,257,256,254,252,250,248,246,244,242,240,238,236,235,233 337 0000048B 00FC00FA00F800F600- 337 00000494 F400F200F000EE00EC- 337 0000049D 00EB00E900 338 000004A2 E700E500E300E100DF- dw 231,229,227,225,223,221,219,217,215,213,211,209,207,205,203,201 338 000004AB 00DD00DB00D900D700- 338 000004B4 D500D300D100CF00CD- 338 000004BD 00CB00C900 339 000004C2 C800C600C400C200C0- dw 200,198,196,194,192,190,188,186,184,182,180,178,176,174,172,170 339 000004CB 00BE00BC00BA00B800- 339 000004D4 B600B400B200B000AE- 339 000004DD 00AC00AA00 340 000004E2 A800A600A400A300A1- dw 168,166,164,163,161,159,157,155,153,151,149,147,145,143,142,140 340 000004EB 009F009D009B009900- 340 000004F4 97009500930091008F- 340 000004FD 008E008C00 341 00000502 8A0088008600840082- dw 138,136,134,132,130,129,127,125,123,121,120,118,116,114,112,111 341 0000050B 0081007F007D007B00- 341 00000514 790078007600740072- 341 0000051D 0070006F00 342 00000522 6D006B006900680066- dw 109,107,105,104,102,100,99,97,95,94,92,90,89,87,85,84 342 0000052B 006400630061005F00- 342 00000534 5E005C005A00590057- 342 0000053D 0055005400 343 00000542 520051004F004E004C- dw 82,81,79,78,76,74,73,71,70,68,67,66,64,63,61,60 343 0000054B 004A00490047004600- 343 00000554 44004300420040003F- 343 0000055D 003D003C00 344 00000562 3A0039003800360035- dw 58,57,56,54,53,52,50,49,48,47,45,44,43,42,40,39 344 0000056B 003400320031003000- 344 00000574 2F002D002C002B002A- 344 0000057D 0028002700 345 00000582 260025002400230022- dw 38,37,36,35,34,33,31,30,29,28,27,26,25,24,24,23 345 0000058B 0021001F001E001D00- 345 00000594 1C001B001A00190018- 345 0000059D 0018001700 346 000005A2 160015001400130012- dw 22,21,20,19,18,18,17,16,15,14,14,13,12,12,11,10 346 000005AB 001200110010000F00- 346 000005B4 0E000E000D000C000C- 346 000005BD 000B000A00 347 000005C2 0A0009000900080007- dw 10,9,9,8,7,7,6,6,6,5,5,4,4,3,3,3 347 000005CB 000700060006000600- 347 000005D4 050005000400040003- 347 000005DD 0003000300 348 000005E2 020002000200020001- dw 2,2,2,2,1,1,1,1,1,0,0,0,0,0,0,0 348 000005EB 000100010001000100- 348 000005F4 000000000000000000- 348 000005FD 0000000000 349 00000602 000000000000000000- dw 0,0,0,0,0,0,0,0,1,1,1,1,1,2,2,2 349 0000060B 000000000000000100- 349 00000614 010001000100010002- 349 0000061D 0002000200 350 00000622 020003000300030004- dw 2,3,3,3,4,4,5,5,6,6,6,7,7,8,9,9 350 0000062B 000400050005000600- 350 00000634 060006000700070008- 350 0000063D 0009000900 351 00000642 0A000A000B000C000C- dw 10,10,11,12,12,13,14,14,15,16,17,18,18,19,20,21 351 0000064B 000D000E000E000F00- 351 00000654 100011001200120013- 351 0000065D 0014001500 352 00000662 160017001800180019- dw 22,23,24,24,25,26,27,28,29,30,31,33,34,35,36,37 352 0000066B 001A001B001C001D00- 352 00000674 1E001F002100220023- 352 0000067D 0024002500 353 00000682 2600270028002A002B- dw 38,39,40,42,43,44,45,47,48,49,50,52,53,54,56,57 353 0000068B 002C002D002F003000- 353 00000694 310032003400350036- 353 0000069D 0038003900 354 000006A2 3A003C003D003F0040- dw 58,60,61,63,64,66,67,68,70,71,73,74,76,78,79,81 354 000006AB 004200430044004600- 354 000006B4 470049004A004C004E- 354 000006BD 004F005100 355 000006C2 520054005500570059- dw 82,84,85,87,89,90,92,94,95,97,99,100,102,104,105,107 355 000006CB 005A005C005E005F00- 355 000006D4 610063006400660068- 355 000006DD 0069006B00 356 000006E2 6D006F007000720074- dw 109,111,112,114,116,118,120,121,123,125,127,129,130,132,134,136 356 000006EB 007600780079007B00- 356 000006F4 7D007F008100820084- 356 000006FD 0086008800 357 00000702 8A008C008E008F0091- dw 138,140,142,143,145,147,149,151,153,155,157,159,161,163,164,166 357 0000070B 009300950097009900- 357 00000714 9B009D009F00A100A3- 357 0000071D 00A400A600 358 00000722 A800AA00AC00AE00B0- dw 168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198 358 0000072B 00B200B400B600B800- 358 00000734 BA00BC00BE00C000C2- 358 0000073D 00C400C600 359 360 bss: 361 362 ABSOLUTE bss 363 364 00000742 alignb 4 365 366 00000744 color: resd 1 367 00000748 prevx: resd 1 368 ;prevy: resd 1 369 370 bss_start: 371 0000074C _fx: resd 640 ; for every X values from 0 to 639 372 0000114C resd 2048-640 ; used for repetitive x values for continuity 373 bss_end: