1 ; **************************************************************************** 2 ; line4.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel w/r tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 10/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm line4.s -l line4.txt -o LINE4.PRG -Z error.txt 9 ; (modified from 'line2.s', 10/02/2021) 10 11 ; Draw lines by using 'sysvideo' bh=020Eh (VESA VBE mode version) 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[D4050000] mov edi, bss_start 92 00000005 B908000000 mov ecx, (bss_end - bss_start)/4 93 ;xor eax, eax 94 0000000A F3AB rep stosd 95 96 ; program message 97 0000000C BE[6F040000] mov esi, program_msg 98 00000011 E879020000 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 110 0000002D 750E jnz short set_vesa_mode_101h_ok 111 112 terminate: 113 0000002F E834040000 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 ; create a box and the center of 640x480 screen 120 reset: 121 0000003D B394 mov bl, 148 ; color 122 0000003F 881D[D5050000] mov [color], bl 123 124 00000045 B140 mov cl, 64 125 00000047 880D[E0050000] mov [length], cl 126 127 ; BL = Line Color 128 ; CL = Line Size 129 130 ; move square to center of screen 131 center: 132 0000004D E8CB030000 call movecenter 133 _0: 134 00000052 E89C020000 call drawline 135 00000057 7206 jc short waitforkey 136 00000059 FE05[D4050000] inc byte [lphase] 137 waitforkey: 138 0000005F B401 mov ah, 1 139 00000061 CD32 int 32h 140 00000063 740C jz short getkey 141 00000065 66FF05[D6050000] inc word [counter] 142 0000006C 90 nop 143 0000006D 90 nop 144 0000006E 90 nop 145 0000006F EBEE jmp short waitforkey 146 getkey: 147 00000071 30E4 xor ah, ah 148 00000073 CD32 int 32h 149 150 00000075 663D032E cmp ax, 2E03h 151 00000079 74B4 je short terminate 152 0000007B 3C1B cmp al, 1Bh ; ESC key 153 0000007D 74B0 je short terminate 154 155 0000007F 3C2B cmp al, '+' 156 00000081 7541 jne short _1 157 158 00000083 803D[D4050000]04 cmp byte [lphase], 4 159 0000008A 0F82F5010000 jb _14 160 161 00000090 E82A020000 call clear_lines 162 ; increase length 163 00000095 FF05[E0050000] inc dword [length] 164 0000009B 7506 jnz short _incl 165 0000009D FF0D[E0050000] dec dword [length] 166 _incl: 167 _decl: 168 000000A3 E89C030000 call get_start_offset 169 000000A8 0305[E0050000] add eax, [length] 170 000000AE 3D00B00400 cmp eax, 640*480 171 000000B3 769D jna short _0 172 000000B5 FF0D[E0050000] dec dword [length] 173 000000BB 75E6 jnz short _incl 174 000000BD E894030000 call beep 175 000000C2 EB9B jmp short waitforkey 176 _1: 177 000000C4 3C2D cmp al, '-' 178 000000C6 7522 jne short _2 179 180 000000C8 803D[D4050000]04 cmp byte [lphase], 4 181 000000CF 0F82B0010000 jb _14 182 183 000000D5 E8E5010000 call clear_lines 184 ; decrease length 185 000000DA FF0D[E0050000] dec dword [length] 186 000000E0 75C1 jnz short _decl 187 000000E2 FF05[E0050000] inc dword [length] 188 000000E8 EBB9 jmp short _decl 189 _2: 190 000000EA 3C20 cmp al, 20h ; space 191 000000EC 7511 jne short _3 192 000000EE 8005[D5050000]08 add byte [color], 8 193 000000F5 E8F9010000 call drawline 194 000000FA E960FFFFFF jmp waitforkey 195 _3: 196 000000FF 80FC4B cmp ah, 4Bh 197 00000102 7532 jne short _4 198 199 ; left arrow 200 00000104 803D[D4050000]04 cmp byte [lphase], 4 201 0000010B 0F8274010000 jb _14 202 00000111 66833D[DC050000]00 cmp word [x_pos], 0 203 00000119 770A ja short _3_ 204 0000011B E836030000 call beep 205 00000120 E93AFFFFFF jmp waitforkey 206 _3_: 207 00000125 E895010000 call clear_lines 208 0000012A 66FF0D[DC050000] dec word [x_pos] 209 00000131 E91CFFFFFF jmp _0 210 _4: 211 00000136 80FC4D cmp ah, 4Dh 212 00000139 754A jne short _5 213 214 ; right arrow 215 0000013B 803D[D4050000]04 cmp byte [lphase], 4 216 00000142 0F823D010000 jb _14 217 00000148 E872010000 call clear_lines 218 0000014D 8B0D[DC050000] mov ecx, [x_pos] 219 00000153 030D[E0050000] add ecx, [length] 220 00000159 81F980020000 cmp ecx, 640 221 0000015F 7218 jb short _4_ 222 00000161 FF0D[E0050000] dec dword [length] 223 00000167 7510 jnz short _4_ 224 00000169 FF05[E0050000] inc dword [length] 225 0000016F E8E2020000 call beep 226 00000174 E9E6FEFFFF jmp waitforkey 227 _4_: 228 00000179 66FF05[DC050000] inc word [x_pos] 229 00000180 E9CDFEFFFF jmp _0 230 _5: 231 00000185 80FC50 cmp ah, 50h 232 00000188 7548 jne short _6 233 ; down arrow 234 0000018A 803D[D4050000]04 cmp byte [lphase], 4 235 00000191 0F82EE000000 jb _14 236 00000197 E823010000 call clear_lines 237 0000019C A1[D8050000] mov eax, [y_pos] 238 000001A1 0305[E0050000] add eax, [length] 239 000001A7 3DE0010000 cmp eax, 480 240 000001AC 7218 jb short _5_ 241 000001AE FF0D[E0050000] dec dword [length] 242 000001B4 7510 jnz short _5_ 243 000001B6 FF05[E0050000] inc dword [length] 244 000001BC E895020000 call beep 245 000001C1 E999FEFFFF jmp waitforkey 246 _5_: 247 000001C6 66FF05[D8050000] inc word [y_pos] 248 000001CD E980FEFFFF jmp _0 249 _6: 250 000001D2 80FC48 cmp ah, 48h 251 000001D5 7532 jne short _7 252 ; up arrow 253 000001D7 803D[D4050000]04 cmp byte [lphase], 4 254 000001DE 0F82A1000000 jb _14 255 000001E4 66833D[D8050000]00 cmp word [y_pos], 0 256 000001EC 770A ja short _6_ 257 000001EE E863020000 call beep 258 000001F3 E967FEFFFF jmp waitforkey 259 _6_: 260 000001F8 E8C2000000 call clear_lines 261 000001FD 66FF0D[D8050000] dec word [y_pos] 262 00000204 E949FEFFFF jmp _0 263 _7: 264 00000209 80FC47 cmp ah, 47h ; Home key 265 0000020C 751B jne short _8 266 0000020E E8AC000000 call clear_lines 267 00000213 E805020000 call movecenter 268 00000218 E883000000 call drawline_x 269 0000021D E87E000000 call drawline_x 270 00000222 E879000000 call drawline_x 271 00000227 EB5C jmp short _14 272 _8: 273 00000229 80FC4F cmp ah, 4Fh ; End key 274 0000022C 752B jne short _9 275 0000022E E88C000000 call clear_lines 276 00000233 B394 mov bl, 148 ; color 277 00000235 881D[D5050000] mov [color], bl 278 0000023B B140 mov cl, 64 279 0000023D 880D[E0050000] mov [length], cl 280 00000243 E8D5010000 call movecenter 281 00000248 E853000000 call drawline_x 282 0000024D E84E000000 call drawline_x 283 00000252 E849000000 call drawline_x 284 00000257 EB2C jmp short _14 285 _9: 286 00000259 663D0D1C cmp ax, 1C0Dh 287 0000025D 7426 je short _14 288 _10: 289 0000025F 80FC53 cmp ah, 53h ; INSERT 290 00000262 7421 je short _14 291 _11: 292 00000264 80FC52 cmp ah, 52h ; DEL 293 00000267 741C je short _14 294 _12: 295 00000269 80FC49 cmp ah, 49h ; Page UP 296 0000026C 7508 jne short _13 297 0000026E FE0D[D5050000] dec byte [color] 298 00000274 EB0F jmp short _14 299 _13: 300 00000276 80FC51 cmp ah, 51h ; Page Down 301 00000279 0F85E0FDFFFF jne waitforkey 302 0000027F FE05[D5050000] inc byte [color] 303 _14: 304 00000285 E816000000 call drawline_x 305 0000028A E9D0FDFFFF jmp waitforkey 306 307 print_msg: 308 0000028F B40E mov ah, 0Eh 309 00000291 BB07000000 mov ebx, 7 310 ;mov bl, 7 ; char attribute & color 311 p_next_chr: 312 00000296 AC lodsb 313 00000297 08C0 or al, al 314 00000299 7404 jz short p_retn ; retn 315 0000029B CD31 int 31h 316 0000029D EBF7 jmp short p_next_chr 317 p_retn: 318 0000029F C3 retn 319 320 drawline_x: 321 000002A0 803D[D4050000]04 cmp byte [lphase], 4 322 000002A7 7316 jnb short clear_lines 323 000002A9 E845000000 call drawline 324 000002AE 7308 jnc short drawline_x_ok 325 000002B0 C605[D4050000]04 mov byte [lphase], 4 326 000002B7 C3 retn 327 drawline_x_ok: 328 000002B8 FE05[D4050000] inc byte [lphase] 329 drawline_r: 330 000002BE C3 retn 331 clear_lines: 332 ; clear previous square by drawing black square 333 000002BF 30E4 xor ah, ah 334 000002C1 A0[D4050000] mov al, [lphase] 335 000002C6 8825[D4050000] mov [lphase], ah ; 0 336 000002CC 8625[D5050000] xchg [color], ah ; 0 337 csq_1: 338 000002D2 50 push eax 339 000002D3 E81B000000 call drawline 340 000002D8 58 pop eax 341 000002D9 20C0 and al, al 342 000002DB 740A jz short csq_2 343 000002DD FE05[D4050000] inc byte [lphase] 344 000002E3 FEC8 dec al 345 000002E5 EBEB jmp short csq_1 346 csq_2: 347 000002E7 A2[D4050000] mov [lphase], al ; 0 348 000002EC 8825[D5050000] mov [color], ah ; restore color 349 000002F2 C3 retn 350 drawline: 351 ; INPUT: 352 ; [x_pos] 353 ; [y_pos] 354 ; [length] 355 ; [color] 356 ; 357 ; Modified registers: edi, eax, ecx, ebx, edx 358 359 ; draw one segment of a square 360 _dline0: 361 000002F3 803D[D4050000]00 cmp byte [lphase], 0 362 000002FA 7744 ja short _dvline1 363 ; draw (x1,y1) to (x2,y1) horizontal line at first 364 _dline0_x: 365 000002FC 8B2D[E0050000] mov ebp, [length] 366 00000302 E83D010000 call get_start_offset 367 ; eax = start pos 368 ; ebp = length 369 00000307 89C7 mov edi, eax 370 00000309 01E8 add eax, ebp 371 0000030B 3D00B00400 cmp eax, 640*480 372 00000310 760F jna short _dline0_y 373 00000312 FF0D[E0050000] dec dword [length] 374 00000318 75E2 jnz short _dline0_x 375 _dvline_err: 376 0000031A E837010000 call beep 377 0000031F F9 stc 378 00000320 C3 retn 379 _dline0_y: 380 00000321 893D[E4050000] mov [p1pos], edi 381 00000327 48 dec eax 382 00000328 A3[E8050000] mov [p2pos], eax 383 ; draw horizontal line 384 0000032D 668B35[D8050000] mov si, [y_pos] 385 00000334 C1E610 shl esi, 16 386 00000337 668B35[DC050000] mov si, [x_pos] 387 0000033E EB73 jmp short _dvline_h 388 _dvline1: 389 00000340 803D[D4050000]01 cmp byte [lphase], 1 390 00000347 777F ja short _dvline2 391 ; draw (x2,y1) to (x2,y2) vertical line 392 _dline1_x: 393 00000349 8B2D[E0050000] mov ebp, [length] 394 395 0000034F 668B35[D8050000] mov si, [y_pos] 396 00000356 C1E610 shl esi, 16 397 00000359 668B35[DC050000] mov si, [x_pos] 398 00000360 6601EE add si, bp 399 00000363 664E dec si 400 401 00000365 B880020000 mov eax, 640 402 0000036A F7E5 mul ebp 403 0000036C 8B3D[E8050000] mov edi, [p2pos] 404 00000372 01F8 add eax, edi 405 00000374 3D00B00400 cmp eax, 640*480 406 00000379 762E jna short _dline1_y 407 408 0000037B 803D[E0050000]01 cmp byte [length], 1 409 00000382 7696 jna short _dvline_err 410 411 00000384 28C0 sub al, al 412 00000386 8605[D5050000] xchg [color], al ; 0 413 0000038C 50 push eax 414 0000038D E86AFFFFFF call _dline0_x 415 00000392 58 pop eax 416 00000393 A2[D5050000] mov [color], al 417 00000398 722D jc short _dvline_ok 418 0000039A FE0D[E0050000] dec byte [length] 419 000003A0 E857FFFFFF call _dline0_x 420 000003A5 7220 jc short _dvline_ok 421 000003A7 EBA0 jmp short _dline1_x 422 _dline1_y: 423 000003A9 A3[EC050000] mov [p3pos], eax 424 _dvline_v: 425 ; draw vertical line 426 000003AE 6681CD0010 or bp, 1000h ; vertical line 427 _dvline_h: 428 ; esi = line start position (row, column) 429 sys _video, 020Eh, [color], ebp 429 <1> 429 <1> 429 <1> 429 <1> 429 <1> %if %0 >= 2 429 000003B3 BB0E020000 <1> mov ebx, %2 429 <1> %if %0 >= 3 429 000003B8 8B0D[D5050000] <1> mov ecx, %3 429 <1> %if %0 = 4 429 000003BE 89EA <1> mov edx, %4 429 <1> %endif 429 <1> %endif 429 <1> %endif 429 000003C0 B81F000000 <1> mov eax, %1 429 <1> 429 000003C5 CD40 <1> int 40h 430 _dvline_ok: 431 000003C7 C3 retn 432 _dvline2: 433 000003C8 803D[D4050000]02 cmp byte [lphase], 2 434 000003CF 772D ja short _dvline3 435 ; draw (x2,y2) to (x3,y2) horizontal line 436 000003D1 8B2D[E0050000] mov ebp, [length] 437 000003D7 A1[EC050000] mov eax, [p3pos] 438 000003DC 40 inc eax 439 000003DD 89C7 mov edi, eax 440 000003DF 29E8 sub eax, ebp 441 ;jb _dvline_err 442 000003E1 A3[F0050000] mov [p4pos], eax 443 ; draw horizontal line 444 000003E6 668B35[D8050000] mov si, [y_pos] 445 000003ED 6601EE add si, bp 446 000003F0 664E dec si 447 000003F2 C1E610 shl esi, 16 448 000003F5 668B35[DC050000] mov si, [x_pos] 449 000003FC EBB5 jmp short _dvline_h 450 _dvline3: 451 ; draw (x3,y2) to (x1,y1) vertical line 452 000003FE 8B2D[E0050000] mov ebp, [length] 453 00000404 8B3D[F0050000] mov edi, [p4pos] 454 ; draw vertical line 455 0000040A 668B35[D8050000] mov si, [y_pos] 456 00000411 C1E610 shl esi, 16 457 00000414 668B35[DC050000] mov si, [x_pos] 458 0000041B EB91 jmp short _dvline_v 459 460 movecenter: 461 ; Modified registers: ecx 462 463 0000041D B980020000 mov ecx, 640 464 00000422 2B0D[E0050000] sub ecx, [length] 465 00000428 D1E9 shr ecx, 1 466 0000042A 890D[DC050000] mov [x_pos], ecx 467 00000430 B9E0010000 mov ecx, 480 468 00000435 2B0D[E0050000] sub ecx, [length] 469 0000043B D1E9 shr ecx, 1 470 0000043D 890D[D8050000] mov [y_pos], ecx 471 00000443 C3 retn 472 473 get_start_offset: 474 00000444 B880020000 mov eax, 640 475 00000449 F725[D8050000] mul dword [y_pos] 476 0000044F 0305[DC050000] add eax, [x_pos] 477 00000455 C3 retn 478 beep: 479 ; call beep function (16/64 second, 886Hz) 480 sys _audio, 16, 1331 480 <1> 480 <1> 480 <1> 480 <1> 480 <1> %if %0 >= 2 480 00000456 BB10000000 <1> mov ebx, %2 480 <1> %if %0 >= 3 480 0000045B B933050000 <1> mov ecx, %3 480 <1> %if %0 = 4 480 <1> mov edx, %4 480 <1> %endif 480 <1> %endif 480 <1> %endif 480 00000460 B820000000 <1> mov eax, %1 480 <1> 480 00000465 CD40 <1> int 40h 481 00000467 C3 retn 482 483 set_text_mode: 484 00000468 30E4 xor ah, ah 485 0000046A B003 mov al, 3 486 ;int 10h ; al = 03h text mode, int 10 video 487 0000046C CD31 int 31h ; TRDOS 386 - Video interrupt 488 0000046E C3 retn 489 490 program_msg: 491 0000046F 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Lines" 491 00000478 2076322E302E33202D- 491 00000481 202827737973766964- 491 0000048A 656F27292054657374- 491 00000493 2050726F6772616D20- 491 0000049C 2D2044726177204C69- 491 000004A5 6E6573 492 000004A8 0D0A db 0Dh, 0Ah 493 000004AA 6279204572646F6761- db "by Erdogan Tan - 10/02/2021" 493 000004B3 6E2054616E202D2031- 493 000004BC 302F30322F32303231 494 ;db 0Dh, 0Ah, 0 495 000004C5 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 496 497 000004C9 557365204172726F77- db "Use Arrow Keys, Home, End to move the LINE .." 497 000004D2 204B6579732C20486F- 497 000004DB 6D652C20456E642074- 497 000004E4 6F206D6F7665207468- 497 000004ED 65204C494E45202E2E 498 000004F6 0D0A db 0Dh, 0Ah 499 000004F8 557365202B2C2D206B- db "Use +,- keys to increase and decrease LENGTH .." 499 00000501 65797320746F20696E- 499 0000050A 63726561736520616E- 499 00000513 642064656372656173- 499 0000051C 65204C454E47544820- 499 00000525 2E2E 500 00000527 0D0A db 0Dh, 0Ah 501 00000529 55736520454E544552- db "Use ENTER key to draw SQUARE .." 501 00000532 206B657920746F2064- 501 0000053B 726177205351554152- 501 00000544 45202E2E 502 00000548 0D0A db 0Dh, 0Ah 503 0000054A 53504143452C205067- db "SPACE, Pg Up, Pg Down keys to change LINE COLOR .." 503 00000553 2055702C2050672044- 503 0000055C 6F776E206B65797320- 503 00000565 746F206368616E6765- 503 0000056E 204C494E4520434F4C- 503 00000577 4F52202E2E 504 0000057C 0D0A db 0Dh, 0Ah 505 0000057E 55736520496E736572- db "Use Insert, Delete keys to delete LINE or SQUARE .." 505 00000587 742C2044656C657465- 505 00000590 206B65797320746F20- 505 00000599 64656C657465204C49- 505 000005A2 4E45206F7220535155- 505 000005AB 415245202E2E 506 000005B1 0D0A db 0Dh, 0Ah 507 000005B3 0D0A db 0Dh, 0Ah 508 000005B5 507265737320616E79- db "Press any key to continue .." 508 000005BE 206B657920746F2063- 508 000005C7 6F6E74696E7565202E- 508 000005D0 2E 509 nextline: 510 000005D1 0D0A00 db 0Dh, 0Ah, 0 511 512 bss: 513 514 ABSOLUTE bss 515 516 alignb 4 517 518 bss_start: 519 520 521 000005D4 lphase: resb 1 522 000005D5 color: resb 1 523 524 000005D6 counter: resw 1 525 526 000005D8 y_pos: resd 1 527 000005DC x_pos: resd 1 528 000005E0 length: resd 1 529 530 000005E4 p1pos: resd 1 531 000005E8 p2pos: resd 1 532 000005EC p3pos: resd 1 533 000005F0 p4pos: resd 1 534 535 bss_end: