1 ; **************************************************************************** 2 ; line3.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel w/r tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 10/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm line3.s -l line3.txt -o LINE3.PRG -Z error.txt 9 ; (modified from 'line1.s', 09/02/2021) 10 11 ; Draw lines by using 'sysvideo' bx=010Eh 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[C8050000] 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[62040000] mov esi, program_msg 98 00000011 E86C020000 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 13h 106 ;sys _video, 0813h 107 ;cmp eax, 14h 108 ;je short mode_13h_set_ok 109 110 ; set VGA mode by using int 31h 111 0000001A 66B81300 mov ax, 13h ; mode 13h ; 112 0000001E CD31 int 31h ; real mode: int 10h 113 00000020 EB0E jmp short mode_13h_set_ok 114 115 terminate: 116 00000022 E834040000 call set_text_mode 117 sys _exit 117 <1> 117 <1> 117 <1> 117 <1> 117 <1> %if %0 >= 2 117 <1> mov ebx, %2 117 <1> %if %0 >= 3 117 <1> mov ecx, %3 117 <1> %if %0 = 4 117 <1> mov edx, %4 117 <1> %endif 117 <1> %endif 117 <1> %endif 117 00000027 B801000000 <1> mov eax, %1 117 <1> 117 0000002C CD40 <1> int 40h 118 halt: 119 0000002E EBFE jmp short halt 120 121 mode_13h_set_ok: 122 ; create a box and the center of 640x480 screen 123 reset: 124 00000030 B380 mov bl, 128 ; color 125 00000032 881D[C9050000] mov [color], bl 126 127 00000038 B140 mov cl, 64 128 0000003A 880D[D4050000] mov [length], cl 129 130 ; BL = Line Color 131 ; CL = Line Size 132 133 ; move square to center of screen 134 center: 135 00000040 E8CB030000 call movecenter 136 _0: 137 00000045 E89C020000 call drawline 138 0000004A 7206 jc short waitforkey 139 0000004C FE05[C8050000] inc byte [lphase] 140 waitforkey: 141 00000052 B401 mov ah, 1 142 00000054 CD32 int 32h 143 00000056 740C jz short getkey 144 00000058 66FF05[CA050000] inc word [counter] 145 0000005F 90 nop 146 00000060 90 nop 147 00000061 90 nop 148 00000062 EBEE jmp short waitforkey 149 getkey: 150 00000064 30E4 xor ah, ah 151 00000066 CD32 int 32h 152 153 00000068 663D032E cmp ax, 2E03h 154 0000006C 74B4 je short terminate 155 0000006E 3C1B cmp al, 1Bh ; ESC key 156 00000070 74B0 je short terminate 157 158 00000072 3C2B cmp al, '+' 159 00000074 7541 jne short _1 160 161 00000076 803D[C8050000]04 cmp byte [lphase], 4 162 0000007D 0F82F5010000 jb _14 163 164 00000083 E82A020000 call clear_lines 165 ; increase length 166 00000088 FE05[D4050000] inc byte [length] 167 0000008E 7506 jnz short _incl 168 00000090 FE0D[D4050000] dec byte [length] 169 _incl: 170 _decl: 171 00000096 E89C030000 call get_start_offset 172 0000009B 0305[D4050000] add eax, [length] 173 000000A1 3D00FA0000 cmp eax, 64000 174 000000A6 769D jna short _0 175 000000A8 FE0D[D4050000] dec byte [length] 176 000000AE 75E6 jnz short _incl 177 000000B0 E894030000 call beep 178 000000B5 EB9B jmp short waitforkey 179 _1: 180 000000B7 3C2D cmp al, '-' 181 000000B9 7522 jne short _2 182 183 000000BB 803D[C8050000]04 cmp byte [lphase], 4 184 000000C2 0F82B0010000 jb _14 185 186 000000C8 E8E5010000 call clear_lines 187 ; decrease length 188 000000CD FE0D[D4050000] dec byte [length] 189 000000D3 75C1 jnz short _decl 190 000000D5 FE05[D4050000] inc byte [length] 191 000000DB EBB9 jmp short _decl 192 _2: 193 000000DD 3C20 cmp al, 20h ; space 194 000000DF 7511 jne short _3 195 000000E1 8005[C9050000]08 add byte [color], 8 196 000000E8 E8F9010000 call drawline 197 000000ED E960FFFFFF jmp waitforkey 198 _3: 199 000000F2 80FC4B cmp ah, 4Bh 200 000000F5 7532 jne short _4 201 202 ; left arrow 203 000000F7 803D[C8050000]04 cmp byte [lphase], 4 204 000000FE 0F8274010000 jb _14 205 00000104 66833D[D0050000]00 cmp word [x_pos], 0 206 0000010C 770A ja short _3_ 207 0000010E E836030000 call beep 208 00000113 E93AFFFFFF jmp waitforkey 209 _3_: 210 00000118 E895010000 call clear_lines 211 0000011D 66FF0D[D0050000] dec word [x_pos] 212 00000124 E91CFFFFFF jmp _0 213 _4: 214 00000129 80FC4D cmp ah, 4Dh 215 0000012C 754A jne short _5 216 217 ; right arrow 218 0000012E 803D[C8050000]04 cmp byte [lphase], 4 219 00000135 0F823D010000 jb _14 220 0000013B E872010000 call clear_lines 221 00000140 8B0D[D0050000] mov ecx, [x_pos] 222 00000146 030D[D4050000] add ecx, [length] 223 0000014C 81F940010000 cmp ecx, 320 224 00000152 7218 jb short _4_ 225 00000154 FE0D[D4050000] dec byte [length] 226 0000015A 7510 jnz short _4_ 227 0000015C FE05[D4050000] inc byte [length] 228 00000162 E8E2020000 call beep 229 00000167 E9E6FEFFFF jmp waitforkey 230 _4_: 231 0000016C 66FF05[D0050000] inc word [x_pos] 232 00000173 E9CDFEFFFF jmp _0 233 _5: 234 00000178 80FC50 cmp ah, 50h 235 0000017B 7548 jne short _6 236 ; down arrow 237 0000017D 803D[C8050000]04 cmp byte [lphase], 4 238 00000184 0F82EE000000 jb _14 239 0000018A E823010000 call clear_lines 240 0000018F A1[CC050000] mov eax, [y_pos] 241 00000194 0305[D4050000] add eax, [length] 242 0000019A 3DC8000000 cmp eax, 200 243 0000019F 7218 jb short _5_ 244 000001A1 FE0D[D4050000] dec byte [length] 245 000001A7 7510 jnz short _5_ 246 000001A9 FE05[D4050000] inc byte [length] 247 000001AF E895020000 call beep 248 000001B4 E999FEFFFF jmp waitforkey 249 _5_: 250 000001B9 66FF05[CC050000] inc word [y_pos] 251 000001C0 E980FEFFFF jmp _0 252 _6: 253 000001C5 80FC48 cmp ah, 48h 254 000001C8 7532 jne short _7 255 ; up arrow 256 000001CA 803D[C8050000]04 cmp byte [lphase], 4 257 000001D1 0F82A1000000 jb _14 258 000001D7 66833D[CC050000]00 cmp word [y_pos], 0 259 000001DF 770A ja short _6_ 260 000001E1 E863020000 call beep 261 000001E6 E967FEFFFF jmp waitforkey 262 _6_: 263 000001EB E8C2000000 call clear_lines 264 000001F0 66FF0D[CC050000] dec word [y_pos] 265 000001F7 E949FEFFFF jmp _0 266 _7: 267 000001FC 80FC47 cmp ah, 47h ; Home key 268 000001FF 751B jne short _8 269 00000201 E8AC000000 call clear_lines 270 00000206 E805020000 call movecenter 271 0000020B E883000000 call drawline_x 272 00000210 E87E000000 call drawline_x 273 00000215 E879000000 call drawline_x 274 0000021A EB5C jmp short _14 275 _8: 276 0000021C 80FC4F cmp ah, 4Fh ; End key 277 0000021F 752B jne short _9 278 00000221 E88C000000 call clear_lines 279 00000226 B380 mov bl, 128 ; color 280 00000228 881D[C9050000] mov [color], bl 281 0000022E B140 mov cl, 64 282 00000230 880D[D4050000] mov [length], cl 283 00000236 E8D5010000 call movecenter 284 0000023B E853000000 call drawline_x 285 00000240 E84E000000 call drawline_x 286 00000245 E849000000 call drawline_x 287 0000024A EB2C jmp short _14 288 _9: 289 0000024C 663D0D1C cmp ax, 1C0Dh 290 00000250 7426 je short _14 291 _10: 292 00000252 80FC53 cmp ah, 53h ; INSERT 293 00000255 7421 je short _14 294 _11: 295 00000257 80FC52 cmp ah, 52h ; DEL 296 0000025A 741C je short _14 297 _12: 298 0000025C 80FC49 cmp ah, 49h ; Page UP 299 0000025F 7508 jne short _13 300 00000261 FE0D[C9050000] dec byte [color] 301 00000267 EB0F jmp short _14 302 _13: 303 00000269 80FC51 cmp ah, 51h ; Page Down 304 0000026C 0F85E0FDFFFF jne waitforkey 305 00000272 FE05[C9050000] inc byte [color] 306 _14: 307 00000278 E816000000 call drawline_x 308 0000027D E9D0FDFFFF jmp waitforkey 309 310 print_msg: 311 00000282 B40E mov ah, 0Eh 312 00000284 BB07000000 mov ebx, 7 313 ;mov bl, 7 ; char attribute & color 314 p_next_chr: 315 00000289 AC lodsb 316 0000028A 08C0 or al, al 317 0000028C 7404 jz short p_retn ; retn 318 0000028E CD31 int 31h 319 00000290 EBF7 jmp short p_next_chr 320 p_retn: 321 00000292 C3 retn 322 323 drawline_x: 324 00000293 803D[C8050000]04 cmp byte [lphase], 4 325 0000029A 7316 jnb short clear_lines 326 0000029C E845000000 call drawline 327 000002A1 7308 jnc short drawline_x_ok 328 000002A3 C605[C8050000]04 mov byte [lphase], 4 329 000002AA C3 retn 330 drawline_x_ok: 331 000002AB FE05[C8050000] inc byte [lphase] 332 drawline_r: 333 000002B1 C3 retn 334 clear_lines: 335 ; clear previous square by drawing black square 336 000002B2 30E4 xor ah, ah 337 000002B4 A0[C8050000] mov al, [lphase] 338 000002B9 8825[C8050000] mov [lphase], ah ; 0 339 000002BF 8625[C9050000] xchg [color], ah ; 0 340 csq_1: 341 000002C5 50 push eax 342 000002C6 E81B000000 call drawline 343 000002CB 58 pop eax 344 000002CC 20C0 and al, al 345 000002CE 740A jz short csq_2 346 000002D0 FE05[C8050000] inc byte [lphase] 347 000002D6 FEC8 dec al 348 000002D8 EBEB jmp short csq_1 349 csq_2: 350 000002DA A2[C8050000] mov [lphase], al ; 0 351 000002DF 8825[C9050000] mov [color], ah ; restore color 352 000002E5 C3 retn 353 drawline: 354 ; INPUT: 355 ; [x_pos] 356 ; [y_pos] 357 ; [length] 358 ; [color] 359 ; 360 ; Modified registers: edi, eax, ecx, ebx, edx 361 362 ; draw one segment of a square 363 _dline0: 364 000002E6 803D[C8050000]00 cmp byte [lphase], 0 365 000002ED 7744 ja short _dvline1 366 ; draw (x1,y1) to (x2,y1) horizontal line at first 367 _dline0_x: 368 000002EF E843010000 call get_start_offset 369 ; eax = start pos 370 000002F4 8B2D[D4050000] mov ebp, [length] 371 000002FA 89C7 mov edi, eax 372 000002FC 01E8 add eax, ebp 373 000002FE 3D00FA0000 cmp eax, 64000 374 00000303 760F jna short _dline0_y 375 00000305 FE0D[D4050000] dec byte [length] 376 0000030B 75E2 jnz short _dline0_x 377 _dvline_err: 378 0000030D E837010000 call beep 379 00000312 F9 stc 380 00000313 C3 retn 381 _dline0_y: 382 00000314 893D[D8050000] mov [p1pos], edi 383 0000031A 48 dec eax 384 0000031B A3[DC050000] mov [p2pos], eax 385 ; draw horizontal line 386 00000320 668B35[CC050000] mov si, [y_pos] 387 00000327 C1E610 shl esi, 16 388 0000032A 668B35[D0050000] mov si, [x_pos] 389 00000331 EB73 jmp short _dvline_h 390 _dvline1: 391 00000333 803D[C8050000]01 cmp byte [lphase], 1 392 0000033A 777F ja short _dvline2 393 ; draw (x2,y1) to (x2,y2) vertical line 394 _dline1_x: 395 0000033C 8B2D[D4050000] mov ebp, [length] 396 397 00000342 668B35[CC050000] mov si, [y_pos] 398 00000349 C1E610 shl esi, 16 399 0000034C 668B35[D0050000] mov si, [x_pos] 400 00000353 6601EE add si, bp 401 00000356 664E dec si 402 403 00000358 B840010000 mov eax, 320 404 0000035D F7E5 mul ebp 405 0000035F 8B3D[DC050000] mov edi, [p2pos] 406 00000365 01F8 add eax, edi 407 00000367 3D00FA0000 cmp eax, 64000 408 0000036C 762E jna short _dline1_y 409 410 0000036E 803D[D4050000]01 cmp byte [length], 1 411 00000375 7696 jna short _dvline_err 412 413 00000377 28C0 sub al, al 414 00000379 8605[C9050000] xchg [color], al ; 0 415 0000037F 50 push eax 416 00000380 E86AFFFFFF call _dline0_x 417 00000385 58 pop eax 418 00000386 A2[C9050000] mov [color], al 419 0000038B 722D jc short _dvline_ok 420 0000038D FE0D[D4050000] dec byte [length] 421 00000393 E857FFFFFF call _dline0_x 422 00000398 7220 jc short _dvline_ok 423 0000039A EBA0 jmp short _dline1_x 424 _dline1_y: 425 0000039C A3[E0050000] mov [p3pos], eax 426 _dvline_v: 427 ; draw vertical line 428 000003A1 6681CD0010 or bp, 1000h ; vertical line 429 _dvline_h: 430 ; esi = line start position (row, column) 431 sys _video, 010Eh, [color], ebp 431 <1> 431 <1> 431 <1> 431 <1> 431 <1> %if %0 >= 2 431 000003A6 BB0E010000 <1> mov ebx, %2 431 <1> %if %0 >= 3 431 000003AB 8B0D[C9050000] <1> mov ecx, %3 431 <1> %if %0 = 4 431 000003B1 89EA <1> mov edx, %4 431 <1> %endif 431 <1> %endif 431 <1> %endif 431 000003B3 B81F000000 <1> mov eax, %1 431 <1> 431 000003B8 CD40 <1> int 40h 432 _dvline_ok: 433 000003BA C3 retn 434 _dvline2: 435 000003BB 803D[C8050000]02 cmp byte [lphase], 2 436 000003C2 772D ja short _dvline3 437 ; draw (x2,y2) to (x3,y2) horizontal line 438 000003C4 8B2D[D4050000] mov ebp, [length] 439 000003CA A1[E0050000] mov eax, [p3pos] 440 000003CF 40 inc eax 441 000003D0 89C7 mov edi, eax 442 000003D2 29E8 sub eax, ebp 443 ;jb _dvline_err 444 000003D4 A3[E4050000] mov [p4pos], eax 445 ; draw horizontal line 446 000003D9 668B35[CC050000] mov si, [y_pos] 447 000003E0 6601EE add si, bp 448 000003E3 664E dec si 449 000003E5 C1E610 shl esi, 16 450 000003E8 668B35[D0050000] mov si, [x_pos] 451 000003EF EBB5 jmp short _dvline_h 452 _dvline3: 453 ; draw (x3,y2) to (x1,y1) vertical line 454 000003F1 8B2D[D4050000] mov ebp, [length] 455 000003F7 8B3D[E4050000] mov edi, [p4pos] 456 ; draw vertical line 457 000003FD 668B35[CC050000] mov si, [y_pos] 458 00000404 C1E610 shl esi, 16 459 00000407 668B35[D0050000] mov si, [x_pos] 460 0000040E EB91 jmp short _dvline_v 461 462 movecenter: 463 ; Modified registers: ecx 464 465 00000410 B940010000 mov ecx, 320 466 00000415 2B0D[D4050000] sub ecx, [length] 467 0000041B D1E9 shr ecx, 1 468 0000041D 890D[D0050000] mov [x_pos], ecx 469 00000423 B9C8000000 mov ecx, 200 470 00000428 2B0D[D4050000] sub ecx, [length] 471 0000042E D1E9 shr ecx, 1 472 00000430 890D[CC050000] mov [y_pos], ecx 473 00000436 C3 retn 474 475 get_start_offset: 476 00000437 B840010000 mov eax, 320 477 0000043C F725[CC050000] mul dword [y_pos] 478 00000442 0305[D0050000] add eax, [x_pos] 479 00000448 C3 retn 480 beep: 481 ; call beep function (16/64 second, 886Hz) 482 sys _audio, 16, 1331 482 <1> 482 <1> 482 <1> 482 <1> 482 <1> %if %0 >= 2 482 00000449 BB10000000 <1> mov ebx, %2 482 <1> %if %0 >= 3 482 0000044E B933050000 <1> mov ecx, %3 482 <1> %if %0 = 4 482 <1> mov edx, %4 482 <1> %endif 482 <1> %endif 482 <1> %endif 482 00000453 B820000000 <1> mov eax, %1 482 <1> 482 00000458 CD40 <1> int 40h 483 0000045A C3 retn 484 485 set_text_mode: 486 0000045B 30E4 xor ah, ah 487 0000045D B003 mov al, 3 488 ;int 10h ; al = 03h text mode, int 10 video 489 0000045F CD31 int 31h ; TRDOS 386 - Video interrupt 490 00000461 C3 retn 491 492 program_msg: 493 00000462 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Lines" 493 0000046B 2076322E302E33202D- 493 00000474 202827737973766964- 493 0000047D 656F27292054657374- 493 00000486 2050726F6772616D20- 493 0000048F 2D2044726177204C69- 493 00000498 6E6573 494 0000049B 0D0A db 0Dh, 0Ah 495 0000049D 6279204572646F6761- db "by Erdogan Tan - 10/02/2021" 495 000004A6 6E2054616E202D2031- 495 000004AF 302F30322F32303231 496 ;db 0Dh, 0Ah, 0 497 000004B8 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 498 499 000004BC 557365204172726F77- db "Use Arrow Keys, Home, End to move the LINE .." 499 000004C5 204B6579732C20486F- 499 000004CE 6D652C20456E642074- 499 000004D7 6F206D6F7665207468- 499 000004E0 65204C494E45202E2E 500 000004E9 0D0A db 0Dh, 0Ah 501 000004EB 557365202B2C2D206B- db "Use +,- keys to increase and decrease LENGTH .." 501 000004F4 65797320746F20696E- 501 000004FD 63726561736520616E- 501 00000506 642064656372656173- 501 0000050F 65204C454E47544820- 501 00000518 2E2E 502 0000051A 0D0A db 0Dh, 0Ah 503 0000051C 55736520454E544552- db "Use ENTER key to draw SQUARE .." 503 00000525 206B657920746F2064- 503 0000052E 726177205351554152- 503 00000537 45202E2E 504 0000053B 0D0A db 0Dh, 0Ah 505 0000053D 53504143452C205067- db "SPACE, Pg Up, Pg Down keys to change LINE COLOR .." 505 00000546 2055702C2050672044- 505 0000054F 6F776E206B65797320- 505 00000558 746F206368616E6765- 505 00000561 204C494E4520434F4C- 505 0000056A 4F52202E2E 506 0000056F 0D0A db 0Dh, 0Ah 507 00000571 55736520496E736572- db "Use Insert, Delete keys to delete LINE or SQUARE .." 507 0000057A 742C2044656C657465- 507 00000583 206B65797320746F20- 507 0000058C 64656C657465204C49- 507 00000595 4E45206F7220535155- 507 0000059E 415245202E2E 508 000005A4 0D0A db 0Dh, 0Ah 509 000005A6 0D0A db 0Dh, 0Ah 510 000005A8 507265737320616E79- db "Press any key to continue .." 510 000005B1 206B657920746F2063- 510 000005BA 6F6E74696E7565202E- 510 000005C3 2E 511 nextline: 512 000005C4 0D0A00 db 0Dh, 0Ah, 0 513 514 bss: 515 516 ABSOLUTE bss 517 518 000005C7 alignb 4 519 520 bss_start: 521 522 000005C8 lphase: resb 1 523 000005C9 color: resb 1 524 525 000005CA counter: resw 1 526 527 000005CC y_pos: resd 1 528 000005D0 x_pos: resd 1 529 000005D4 length: resd 1 530 531 000005D8 p1pos: resd 1 532 000005DC p2pos: resd 1 533 000005E0 p3pos: resd 1 534 000005E4 p4pos: resd 1 535 536 bss_end: