1 ; **************************************************************************** 2 ; circle14.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 18/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm circle14.s -l circle14.txt -o CIRCLE14.PRG -Z error.txt 9 ; (modified from 'circle13.s', 18/02/2021) 10 11 ; Draw circle by using 'sysvideo' bx=0305h 12 ; and show diameter and origin by using bx=010Fh 13 14 ; 14/07/2020 15 ; 31/12/2017 16 ; TRDOS 386 (v2.0) system calls 17 _ver equ 0 18 _exit equ 1 19 _fork equ 2 20 _read equ 3 21 _write equ 4 22 _open equ 5 23 _close equ 6 24 _wait equ 7 25 _create equ 8 26 _rename equ 9 27 _delete equ 10 28 _exec equ 11 29 _chdir equ 12 30 _time equ 13 31 _mkdir equ 14 32 _chmod equ 15 33 _rmdir equ 16 34 _break equ 17 35 _drive equ 18 36 _seek equ 19 37 _tell equ 20 38 _memory equ 21 39 _prompt equ 22 40 _path equ 23 41 _env equ 24 42 _stime equ 25 43 _quit equ 26 44 _intr equ 27 45 _dir equ 28 46 _emt equ 29 47 _ldrvt equ 30 48 _video equ 31 49 _audio equ 32 50 _timer equ 33 51 _sleep equ 34 52 _msg equ 35 53 _geterr equ 36 54 _fpstat equ 37 55 _pri equ 38 56 _rele equ 39 57 _fff equ 40 58 _fnf equ 41 59 _alloc equ 42 60 _dalloc equ 43 61 _calbac equ 44 62 _dma equ 45 63 64 %macro sys 1-4 65 ; 29/04/2016 - TRDOS 386 (TRDOS v2.0) 66 ; 03/09/2015 67 ; 13/04/2015 68 ; Retro UNIX 386 v1 system call. 69 %if %0 >= 2 70 mov ebx, %2 71 %if %0 >= 3 72 mov ecx, %3 73 %if %0 = 4 74 mov edx, %4 75 %endif 76 %endif 77 %endif 78 mov eax, %1 79 ;int 30h 80 int 40h ; TRDOS 386 (TRDOS v2.0) 81 %endmacro 82 83 ; Retro UNIX 386 v1 system call format: 84 ; sys systemcall (eax) , , 85 86 [BITS 32] ; We need 32-bit intructions for protected mode 87 88 [ORG 0] 89 90 START_CODE: 91 ; clear bss 92 00000000 BF[D4070000] mov edi, bss_start 93 00000005 B90CED0000 mov ecx, (bss_end - bss_start)/4 94 ;xor eax, eax 95 0000000A F3AB rep stosd 96 97 ; program message 98 0000000C BE[87060000] mov esi, program_msg 99 00000011 E839020000 call print_msg 100 101 00000016 30E4 xor ah, ah 102 ;int 16h ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY 103 ; Return: AH = scan code, AL = character 104 00000018 CD32 int 32h ; TRDOS 386 Keyboard interrupt 105 106 ; Read (copy) 8x8 system fonts 107 0000001A BE[D4270000] mov esi, fontbuff1 108 sys _video, 0C02h, 256, 0 108 <1> 108 <1> 108 <1> 108 <1> 108 <1> %if %0 >= 2 108 0000001F BB020C0000 <1> mov ebx, %2 108 <1> %if %0 >= 3 108 00000024 B900010000 <1> mov ecx, %3 108 <1> %if %0 = 4 108 00000029 BA00000000 <1> mov edx, %4 108 <1> %endif 108 <1> %endif 108 <1> %endif 108 0000002E B81F000000 <1> mov eax, %1 108 <1> 108 00000033 CD40 <1> int 40h 109 110 ; convert 8x8 fonts to 16x16 fonts 111 ; by scaling each font 112 ;mov esi, fontbuff1 113 00000035 BF[D4070000] mov edi, fontbuff2 114 ;mov cx, 256 115 fontconvert: 116 0000003A 51 push ecx 117 0000003B B108 mov cl, 8 118 fntcnv0: 119 0000003D B608 mov dh, 8 120 0000003F 8A16 mov dl, [esi] 121 00000041 46 inc esi 122 fntcnv1: 123 00000042 66C1E002 shl ax, 2 124 00000046 D0E2 shl dl, 1 125 00000048 7302 jnc short fntcnv2 126 0000004A 0C03 or al, 3 127 fntcnv2: 128 0000004C FECE dec dh 129 0000004E 75F2 jnz short fntcnv1 130 00000050 66AB stosw 131 00000052 66AB stosw 132 00000054 FEC9 dec cl 133 00000056 75E5 jnz short fntcnv0 134 00000058 59 pop ecx 135 00000059 E2DF loop fontconvert 136 137 ; Set Video Mode to 101h ; 640x480, 256 colors 138 sys _video, 08FFh, 101h 138 <1> 138 <1> 138 <1> 138 <1> 138 <1> %if %0 >= 2 138 0000005B BBFF080000 <1> mov ebx, %2 138 <1> %if %0 >= 3 138 00000060 B901010000 <1> mov ecx, %3 138 <1> %if %0 = 4 138 <1> mov edx, %4 138 <1> %endif 138 <1> %endif 138 <1> %endif 138 00000065 B81F000000 <1> mov eax, %1 138 <1> 138 0000006A CD40 <1> int 40h 139 0000006C 09C0 or eax, eax 140 ;jz short terminate 141 ;mov [LFB_ADDR], edx ; pointer to LFB info table/structure 142 0000006E 7454 jz short terminate 143 144 set_vesa_mode_101h_ok: 145 ; Set squares of numbers from 0 to 255 146 00000070 BF[D42F0000] mov edi, _squares 147 00000075 B9FF000000 mov ecx, 255 148 0000007A BB01000000 mov ebx, 1 149 _ss_x: 150 0000007F 89D8 mov eax, ebx 151 00000081 F7E3 mul ebx 152 00000083 AB stosd 153 00000084 43 inc ebx 154 00000085 E2F8 loop _ss_x 155 156 00000087 C605[E2330000]8C mov byte [tcolor], 140 157 158 ;mov byte [prevd], 480 159 ;mov byte [prevx], 640/2 160 ;mov byte [prevy], 480/2 161 162 ;mov esi, circle_parameters 163 ;call print_msg 164 reset_color: 165 0000008E C605[EC330000]8E mov byte [color], 142 ; initial color 166 reset_diameter: 167 00000095 B8F0000000 mov eax, 240 168 ;mov eax, 255 ; initial radius 169 newdiameter: 170 ; Set radius to 255 171 ;mov dword [radius], 255 172 ;mov dword [_r2], 65025 173 0000009A A3[E4330000] mov [radius], eax 174 0000009F 89C3 mov ebx, eax 175 000000A1 F7E3 mul ebx 176 000000A3 A3[E8330000] mov [_r2], eax ; square of circle radius 177 ; x2+y2 = r2 178 ; Set Y values for X values from 1 to Radius - 1 179 000000A8 BF[00340000] mov edi, _fx 180 _yy_x: 181 000000AD 4B dec ebx 182 000000AE 7422 jz short center 183 000000B0 89D8 mov eax, ebx 184 000000B2 F7E0 mul eax 185 ; eax = square of ebx 186 000000B4 8B15[E8330000] mov edx, [_r2] 187 000000BA 29C2 sub edx, eax 188 000000BC E8F2030000 call get_squareroot 189 000000C1 AB stosd 190 000000C2 EBE9 jmp short _yy_x 191 192 ; *** 193 194 terminate: 195 000000C4 E804040000 call set_text_mode 196 sys _exit 196 <1> 196 <1> 196 <1> 196 <1> 196 <1> %if %0 >= 2 196 <1> mov ebx, %2 196 <1> %if %0 >= 3 196 <1> mov ecx, %3 196 <1> %if %0 = 4 196 <1> mov edx, %4 196 <1> %endif 196 <1> %endif 196 <1> %endif 196 000000C9 B801000000 <1> mov eax, %1 196 <1> 196 000000CE CD40 <1> int 40h 197 halt: 198 000000D0 EBFE jmp short halt 199 200 ; *** 201 202 ; move circle to center of screen 203 center: 204 000000D2 E825030000 call movecenter 205 _0: 206 000000D7 E884010000 call drawcircle 207 waitforkey: 208 000000DC B401 mov ah, 1 209 000000DE CD32 int 32h 210 000000E0 740B jz short getkey 211 000000E2 FE05[E0330000] inc byte [counter] 212 000000E8 90 nop 213 000000E9 90 nop 214 000000EA 90 nop 215 000000EB EBEF jmp short waitforkey 216 getkey: 217 000000ED 30E4 xor ah, ah 218 000000EF CD32 int 32h 219 220 000000F1 663D032E cmp ax, 2E03h 221 000000F5 74CD je short terminate 222 000000F7 3C1B cmp al, 1Bh ; ESC key 223 000000F9 74C9 je short terminate 224 225 000000FB 3C2B cmp al, '+' 226 000000FD 7513 jne short _1 227 228 000000FF A1[E4330000] mov eax, [radius] 229 230 ;cmp ax, 479 231 00000104 663DEF00 cmp ax, 239 232 00000108 7351 jnb short _3_ ; beep 233 234 ; delete circle by drawing black circle 235 ; with same diameter and at same coordinate 236 0000010A E87C030000 call black_circle 237 ; increase radius of the circle 238 0000010F 40 inc eax 239 ;mov [radius], eax 240 00000110 EB88 jmp newdiameter ; draw with new diameter 241 _1: 242 00000112 3C2D cmp al, '-' 243 00000114 7516 jne short _2 244 245 00000116 A1[E4330000] mov eax, [radius] 246 247 0000011B 6683F801 cmp ax, 1 248 0000011F 763A jna short _3_ ; beep 249 250 ; delete circle by drawing black circle 251 ; with same diameter and at same coordinate 252 00000121 E865030000 call black_circle 253 ; decrease radius of the circle 254 00000126 48 dec eax 255 ;mov [radius], eax 256 00000127 E96EFFFFFF jmp newdiameter ; draw with new diameter 257 _2: 258 0000012C 3C20 cmp al, 20h ; space 259 0000012E 7509 jne short _3 260 00000130 8005[EC330000]08 add byte [color], 8 261 00000137 EB9E jmp short _0 262 _3: 263 00000139 80FC4B cmp ah, 4Bh 264 0000013C 7527 jne short _4 265 ; left arrow 266 0000013E A1[E4330000] mov eax, [radius] 267 00000143 3B05[F0330000] cmp eax, [_x0] 268 00000149 7310 jnb short _3_ 269 0000014B E83B030000 call black_circle ; clear current position 270 00000150 FF0D[F0330000] dec dword [_x0] 271 00000156 E97CFFFFFF jmp _0 ; draw 272 _3_: 273 0000015B E841030000 call beep 274 00000160 E977FFFFFF jmp waitforkey 275 _4: 276 00000165 80FC4D cmp ah, 4Dh 277 00000168 7522 jne short _5 278 279 ; right arrow 280 0000016A A1[E4330000] mov eax, [radius] 281 0000016F 0305[F0330000] add eax, [_x0] 282 00000175 3D7F020000 cmp eax, 639 283 0000017A 73DF jnb short _3_ 284 0000017C E80A030000 call black_circle ; clear current position 285 00000181 FF05[F0330000] inc dword [_x0] 286 00000187 E94BFFFFFF jmp _0 ; draw 287 _5: 288 0000018C 80FC50 cmp ah, 50h 289 0000018F 7522 jne short _6 290 ; down arrow 291 00000191 A1[E4330000] mov eax, [radius] 292 00000196 0305[F4330000] add eax, [_y0] 293 0000019C 3DDF010000 cmp eax, 479 294 000001A1 73B8 jnb short _3_ 295 000001A3 E8E3020000 call black_circle ; clear current position 296 000001A8 FF05[F4330000] inc dword [_y0] 297 000001AE E924FFFFFF jmp _0 ; draw 298 _6: 299 000001B3 80FC48 cmp ah, 48h 300 000001B6 751D jne short _7 301 ; up arrow 302 000001B8 A1[E4330000] mov eax, [radius] 303 000001BD 3B05[F4330000] cmp eax, [_y0] 304 000001C3 7396 jnb short _3_ 305 000001C5 E8C1020000 call black_circle ; clear current position 306 000001CA FF0D[F4330000] dec dword [_y0] 307 000001D0 E902FFFFFF jmp _0 ; draw 308 _7: 309 000001D5 80FC47 cmp ah, 47h ; Home key 310 000001D8 750F jne short _8 311 000001DA E8AC020000 call black_circle ; clear current position 312 000001DF E8BD020000 call beep 313 000001E4 E9ACFEFFFF jmp reset_diameter 314 ; reset diameter, move to center 315 _8: 316 000001E9 80FC4F cmp ah, 4Fh ; End key 317 000001EC 750F jne short _9 318 000001EE E898020000 call black_circle ; clear current position 319 000001F3 E8A9020000 call beep 320 000001F8 E991FEFFFF jmp reset_color 321 ; reset color and diameter, move to center 322 _9: 323 000001FD 663D0D1C cmp ax, 1C0Dh 324 00000201 7509 jne short _10 325 00000203 8005[EC330000]04 add byte [color], 4 326 0000020A EB34 jmp short _14 327 _10: 328 0000020C 80FC53 cmp ah, 53h ; INSERT 329 0000020F 7509 jne short _11 330 00000211 8005[E2330000]04 add byte [tcolor], 4 331 00000218 EB26 jmp short _14 332 _11: 333 0000021A 80FC52 cmp ah, 52h ; DEL 334 0000021D 7509 jne short _12 335 0000021F 802D[E2330000]04 sub byte [tcolor], 4 336 00000226 EB18 jmp short _14 337 _12: 338 00000228 80FC49 cmp ah, 49h ; Page UP 339 0000022B 7508 jne short _13 340 0000022D FE0D[EC330000] dec byte [color] 341 00000233 EB0B jmp short _14 342 _13: 343 00000235 80FC51 cmp ah, 51h ; Page Down 344 00000238 7510 jne short _15 345 0000023A FE05[EC330000] inc byte [color] 346 _14: 347 00000240 E85C020000 call beep 348 00000245 E98DFEFFFF jmp _0 349 _15: 350 0000024A E98DFEFFFF jmp waitforkey 351 352 print_msg: 353 0000024F B40E mov ah, 0Eh 354 00000251 BB07000000 mov ebx, 7 355 ;mov bl, 7 ; char attribute & color 356 p_next_chr: 357 00000256 AC lodsb 358 00000257 08C0 or al, al 359 00000259 7404 jz short p_retn ; retn 360 0000025B CD31 int 31h 361 0000025D EBF7 jmp short p_next_chr 362 p_retn: 363 0000025F C3 retn 364 365 drawcircle: 366 ; INPUT: 367 ; [_x0] 368 ; [_y0] 369 ; [radius] 370 ; [color] 371 ; 372 ; Modified registers: esi, edi, eax, ecx, ebx, edx 373 374 ; write circle parameters to left top corner 375 00000260 E835030000 call print_diameter 376 00000265 E86A020000 call print_origin 377 378 ; set pixel pointer position to start of circle buffer 379 0000026A B8[04380000] mov eax, circlebuffer 380 0000026F A3[00380000] mov [pixelpos], eax 381 _dc_ph0: 382 ; quarter 1 383 ; start from y = 0, x = radius 384 00000274 31C0 xor eax, eax 385 00000276 A3[FC330000] mov [_y1], eax ; 0 386 0000027B A2[E3330000] mov [phase], al ; 0 387 00000280 8B2D[E4330000] mov ebp, [radius] 388 00000286 892D[F8330000] mov [_x1], ebp ; y = 0, x = r 389 0000028C BE[00340000] mov esi, _fx 390 _dc_ph0_n: 391 00000291 FF0D[F8330000] dec dword [_x1] 392 00000297 AD lodsd 393 _dc_ph0_x: 394 00000298 8B15[FC330000] mov edx, [_y1] 395 0000029E 42 inc edx 396 0000029F 39C2 cmp edx, eax 397 000002A1 7314 jnb short _dc_ph0_y 398 000002A3 50 push eax 399 000002A4 8915[FC330000] mov [_y1], edx 400 000002AA E862010000 call get_start_offset 401 000002AF E83A010000 call write_pixel 402 000002B4 58 pop eax 403 000002B5 EBE1 jmp short _dc_ph0_x 404 _dc_ph0_y: 405 000002B7 A3[FC330000] mov [_y1], eax 406 000002BC E850010000 call get_start_offset 407 000002C1 E828010000 call write_pixel 408 000002C6 4D dec ebp 409 000002C7 75C8 jnz short _dc_ph0_n 410 _dc_ph1: 411 ; quarter 2 412 ; start from y = radius, x = 0 413 000002C9 FE05[E3330000] inc byte [phase] 414 000002CF 31C0 xor eax, eax 415 000002D1 A3[F8330000] mov [_x1], eax ; 0 416 000002D6 8B2D[E4330000] mov ebp, [radius] 417 000002DC 892D[FC330000] mov [_y1], ebp ; y = r, x = 0 418 000002E2 BE[00340000] mov esi, _fx 419 _dc_ph1_n: 420 000002E7 FF0D[FC330000] dec dword [_y1] 421 000002ED AD lodsd 422 _dc_ph1_x: 423 000002EE 8B15[F8330000] mov edx, [_x1] 424 000002F4 42 inc edx 425 000002F5 39C2 cmp edx, eax 426 000002F7 7314 jnb short _dc_ph1_y 427 000002F9 50 push eax 428 000002FA 8915[F8330000] mov [_x1], edx 429 00000300 E80C010000 call get_start_offset 430 00000305 E8E4000000 call write_pixel 431 0000030A 58 pop eax 432 0000030B EBE1 jmp short _dc_ph1_x 433 _dc_ph1_y: 434 0000030D A3[F8330000] mov [_x1], eax 435 00000312 E8FA000000 call get_start_offset 436 00000317 E8D2000000 call write_pixel 437 0000031C 4D dec ebp 438 0000031D 75C8 jnz short _dc_ph1_n 439 _dc_ph2: 440 ; quarter 3 441 ; start from y = 0, x = radius 442 0000031F FE05[E3330000] inc byte [phase] 443 00000325 31C0 xor eax, eax 444 00000327 A3[FC330000] mov [_y1], eax ; 0 445 0000032C 8B2D[E4330000] mov ebp, [radius] 446 00000332 892D[F8330000] mov [_x1], ebp ; y = 0, x = r 447 00000338 BE[00340000] mov esi, _fx 448 _dc_ph2_n: 449 0000033D FF0D[F8330000] dec dword [_x1] 450 00000343 AD lodsd 451 _dc_ph2_x: 452 00000344 8B15[FC330000] mov edx, [_y1] 453 0000034A 42 inc edx 454 0000034B 39C2 cmp edx, eax 455 0000034D 7314 jnb short _dc_ph2_y 456 0000034F 50 push eax 457 00000350 8915[FC330000] mov [_y1], edx 458 00000356 E8B6000000 call get_start_offset 459 0000035B E88E000000 call write_pixel 460 00000360 58 pop eax 461 00000361 EBE1 jmp short _dc_ph2_x 462 _dc_ph2_y: 463 00000363 A3[FC330000] mov [_y1], eax 464 00000368 E8A4000000 call get_start_offset 465 0000036D E87C000000 call write_pixel 466 00000372 4D dec ebp 467 00000373 75C8 jnz short _dc_ph2_n 468 _dc_ph3: 469 ; quarter 4 470 ; start from y = radius, x = 0 471 00000375 FE05[E3330000] inc byte [phase] 472 0000037B 31C0 xor eax, eax 473 0000037D A3[F8330000] mov [_x1], eax ; 0 474 00000382 8B2D[E4330000] mov ebp, [radius] 475 00000388 892D[FC330000] mov [_y1], ebp ; y = r, x = 0 476 0000038E BE[00340000] mov esi, _fx 477 _dc_ph3_n: 478 00000393 FF0D[FC330000] dec dword [_y1] 479 00000399 AD lodsd 480 _dc_ph3_x: 481 0000039A 8B15[F8330000] mov edx, [_x1] 482 000003A0 42 inc edx 483 000003A1 39C2 cmp edx, eax 484 000003A3 7314 jnb short _dc_ph3_y 485 000003A5 50 push eax 486 000003A6 8915[F8330000] mov [_x1], edx 487 000003AC E860000000 call get_start_offset 488 000003B1 E838000000 call write_pixel 489 000003B6 58 pop eax 490 000003B7 EBE1 jmp short _dc_ph3_x 491 _dc_ph3_y: 492 000003B9 A3[F8330000] mov [_x1], eax 493 000003BE E84E000000 call get_start_offset 494 000003C3 E826000000 call write_pixel 495 000003C8 4D dec ebp 496 000003C9 75C8 jnz short _dc_ph3_n 497 _dc_ph4: 498 write_circle: 499 000003CB BE[04380000] mov esi, circlebuffer 500 000003D0 8B15[00380000] mov edx, [pixelpos] 501 000003D6 29F2 sub edx, esi 502 000003D8 C1EA02 shr edx, 2 ; / 4 503 ; edx = pixel count 504 ; esi = user's single color pixel buffer address 505 sys _video, 0305h, [color] 505 <1> 505 <1> 505 <1> 505 <1> 505 <1> %if %0 >= 2 505 000003DB BB05030000 <1> mov ebx, %2 505 <1> %if %0 >= 3 505 000003E0 8B0D[EC330000] <1> mov ecx, %3 505 <1> %if %0 = 4 505 <1> mov edx, %4 505 <1> %endif 505 <1> %endif 505 <1> %endif 505 000003E6 B81F000000 <1> mov eax, %1 505 <1> 505 000003EB CD40 <1> int 40h 506 507 000003ED C3 retn 508 509 write_pixel: 510 ; eax = (screen) pixel position 511 000003EE 8B3D[00380000] mov edi, [pixelpos] ; pointer 512 000003F4 AB stosd 513 000003F5 893D[00380000] mov [pixelpos], edi ; pointer 514 000003FB C3 retn 515 516 movecenter: 517 000003FC C705[F0330000]4001- mov dword [_x0], 640/2 517 00000404 0000 518 00000406 C705[F4330000]F000- mov dword [_y0], 480/2 518 0000040E 0000 519 00000410 C3 retn 520 521 get_start_offset: 522 00000411 B880020000 mov eax, 640 523 00000416 8B15[F4330000] mov edx, [_y0] 524 0000041C 803D[E3330000]00 cmp byte [phase], 0 525 00000423 7715 ja short gso_1 526 gso_0: 527 ; quarter 1 528 00000425 2B15[FC330000] sub edx, [_y1] ; y = 0 -> r 529 0000042B F7E2 mul edx 530 0000042D 0305[F0330000] add eax, [_x0] 531 00000433 0305[F8330000] add eax, [_x1] ; x = r -> 0 532 00000439 C3 retn 533 gso_1: 534 0000043A 803D[E3330000]01 cmp byte [phase], 1 535 00000441 7715 ja short gso_2 536 ; quarter 2 537 00000443 2B15[FC330000] sub edx, [_y1] ; y = r -> 0 538 00000449 F7E2 mul edx 539 0000044B 0305[F0330000] add eax, [_x0] 540 00000451 2B05[F8330000] sub eax, [_x1] ; x = 0 -> -r 541 00000457 C3 retn 542 gso_2: 543 00000458 803D[E3330000]02 cmp byte [phase], 2 544 0000045F 7715 ja short gso_3 545 ; quarter 3 546 00000461 0315[FC330000] add edx, [_y1] ; y = 0 -> -r 547 00000467 F7E2 mul edx 548 00000469 0305[F0330000] add eax, [_x0] 549 0000046F 2B05[F8330000] sub eax, [_x1] ; x = -r -> 0 550 00000475 C3 retn 551 gso_3: 552 ; quarter 4 553 00000476 0315[FC330000] add edx, [_y1] ; y = -r -> 0 554 0000047C F7E2 mul edx 555 0000047E 0305[F0330000] add eax, [_x0] 556 00000484 0305[F8330000] add eax, [_x1] ; x = 0 -> r 557 0000048A C3 retn 558 559 black_circle: 560 0000048B 30E4 xor ah, ah 561 0000048D 8625[EC330000] xchg [color], ah ; color = 0 562 00000493 50 push eax 563 00000494 E8C7FDFFFF call drawcircle 564 00000499 58 pop eax 565 0000049A 8625[EC330000] xchg [color], ah ; restore color 566 000004A0 C3 retn 567 568 beep: 569 ; call beep function (16/64 second, 886Hz) 570 sys _audio, 16, 1331 570 <1> 570 <1> 570 <1> 570 <1> 570 <1> %if %0 >= 2 570 000004A1 BB10000000 <1> mov ebx, %2 570 <1> %if %0 >= 3 570 000004A6 B933050000 <1> mov ecx, %3 570 <1> %if %0 = 4 570 <1> mov edx, %4 570 <1> %endif 570 <1> %endif 570 <1> %endif 570 000004AB B820000000 <1> mov eax, %1 570 <1> 570 000004B0 CD40 <1> int 40h 571 000004B2 C3 retn 572 573 get_squareroot: 574 ; input: edx = square of the number (y) 575 ; output: eax = approx. square root of ebx 576 000004B3 BE[D42F0000] mov esi, _squares 577 000004B8 53 push ebx 578 000004B9 31DB xor ebx, ebx 579 ;mov ecx, 256 580 000004BB 8B0D[E4330000] mov ecx, [radius] ; max. value of radius is 256 581 q_sr_x: 582 000004C1 AD lodsd 583 000004C2 39D0 cmp eax, edx 584 000004C4 7303 jnb short q_sr_ok 585 000004C6 43 inc ebx 586 000004C7 E2F8 loop q_sr_x 587 q_sr_ok: 588 000004C9 89D8 mov eax, ebx 589 000004CB 5B pop ebx 590 000004CC C3 retn 591 592 set_text_mode: 593 000004CD 30E4 xor ah, ah 594 000004CF B003 mov al, 3 595 ;int 10h ; al = 03h text mode, int 10 video 596 000004D1 CD31 int 31h ; TRDOS 386 - Video interrupt 597 000004D3 C3 retn 598 599 print_origin: 600 000004D4 803D[E2330000]00 cmp byte [tcolor], 0 601 000004DB 7707 ja short p_o_0 602 000004DD C605[E2330000]8E mov byte [tcolor], 142 603 p_o_0: 604 000004E4 A1[F0330000] mov eax, [_x0] 605 000004E9 3B05[D8330000] cmp eax, [prevx] 606 000004EF 744F je short _p_o_y 607 ; same x value don't write 608 000004F1 50 push eax ; current x (abscissa) value 609 000004F2 A0[E2330000] mov al, [tcolor] 610 000004F7 A2[E1330000] mov [pcolor], al 611 000004FC C605[E2330000]00 mov byte [tcolor], 0 ; blank (black color) 612 00000503 E810000000 call p_o_1 ; erase/blank previous text 613 00000508 A0[E1330000] mov al, [pcolor] 614 0000050D A2[E2330000] mov [tcolor], al 615 00000512 8F05[D8330000] pop dword [prevx] ; cur -> prev x (abscissa) value 616 p_o_1: 617 00000518 BD[75060000] mov ebp, txt_x0 618 0000051D BE08001C00 mov esi, 001C0008h ; row 28, column 8 619 00000522 E8DC000000 call p_d_x 620 00000527 A1[D8330000] mov eax, [prevx] ; [_x0] 621 0000052C BF[7A060000] mov edi, val_x0 622 00000531 E8FF000000 call num_to_txt 623 00000536 BD[7A060000] mov ebp, val_x0 624 0000053B E8C3000000 call p_d_x 625 _p_o_y: 626 00000540 A1[F4330000] mov eax, [_y0] 627 00000545 3B05[DC330000] cmp eax, [prevy] 628 0000054B 744C je short _p_o_y_ok 629 ; same y value don't write 630 0000054D 50 push eax ; current y (ordinate) value 631 0000054E A0[E2330000] mov al, [tcolor] 632 00000553 A2[E1330000] mov [pcolor], al 633 00000558 C605[E2330000]00 mov byte [tcolor], 0 ; blank (black color) 634 0000055F E810000000 call p_o_2 ; erase/blank previous text 635 00000564 A0[E1330000] mov al, [pcolor] 636 00000569 A2[E2330000] mov [tcolor], al 637 0000056E 8F05[DC330000] pop dword [prevy] ; cur -> prev y (ordinate) value 638 p_o_2: 639 00000574 BD[7E060000] mov ebp, txt_y0 640 00000579 BE08003000 mov esi, 00300008h ; row 48, column 8 641 0000057E E880000000 call p_d_x 642 00000583 A1[DC330000] mov eax, [prevy] ; [_y0] 643 00000588 BF[83060000] mov edi, val_y0 644 0000058D E8A3000000 call num_to_txt 645 00000592 BD[83060000] mov ebp, val_y0 646 00000597 EB6A jmp short p_d_x 647 _p_o_y_ok: 648 00000599 C3 retn 649 650 print_diameter: 651 0000059A 803D[E2330000]00 cmp byte [tcolor], 0 652 000005A1 7707 ja short p_d_0 653 000005A3 C605[E2330000]8E mov byte [tcolor], 142 654 p_d_0: 655 000005AA A1[E4330000] mov eax, [radius] 656 000005AF D1E0 shl eax, 1 657 000005B1 3B05[D4330000] cmp eax, [prevd] 658 000005B7 747B je short p_d_x_ok 659 ; same diameter don't write 660 000005B9 50 push eax ; current diameter 661 000005BA A0[E2330000] mov al, [tcolor] 662 000005BF A2[E1330000] mov [pcolor], al 663 000005C4 C605[E2330000]00 mov byte [tcolor], 0 ; blank (black color) 664 000005CB E810000000 call p_d_1 ; erase/blank previous text 665 000005D0 A0[E1330000] mov al, [pcolor] 666 000005D5 A2[E2330000] mov [tcolor], al 667 000005DA 8F05[D4330000] pop dword [prevd] ; cur -> prev diameter 668 p_d_1: 669 000005E0 BD[5F060000] mov ebp, txt_diameter 670 000005E5 BE08000800 mov esi, 00080008h ; row 8, column 8 671 000005EA E814000000 call p_d_x 672 000005EF A1[D4330000] mov eax, [prevd] ; diameter 673 000005F4 BF[6A060000] mov edi, val_diameter 674 000005F9 E837000000 call num_to_txt 675 000005FE BD[6A060000] mov ebp, val_diameter 676 ;jmp short p_d_x 677 p_d_x: 678 p_d_x_n: 679 00000603 31D2 xor edx, edx 680 00000605 8A5500 mov dl, [ebp] 681 00000608 20D2 and dl, dl 682 0000060A 7428 jz short p_d_x_ok 683 0000060C C1E205 shl edx, 5 ; * 32 (for 16x16 user font) 684 685 0000060F BF[D4070000] mov edi, fontbuff2 ; start of user font data 686 00000614 01D7 add edi, edx 687 688 ;; NOTE: Following system call writes fonts at 689 ;; Std VGA video memory 0A0000h, BL bit 7 selects 690 ;; screen width as 640 pixels (instead of 320 pixels) 691 ;; so 8Fh is sub function 0Fh (write char) 692 ;; with 640 pixels screen witdh. 693 ;; (Even if VESA VBE mode -LFB- is in use, QEMU and 694 ;; a real computer with NVIDIA GEFORCE FX 550 uses 695 ;; A0000h, so.. even if fonts are written at A0000h-B0000h 696 ;; region, the text is appeared on screen 697 ;; while LFB is at C0000000h or E0000000h.) 698 699 ;sys _video, 018Fh, [tcolor], 8002h 700 ;; use STD VGA video memory 701 ;; (0A0000h) 702 sys _video, 020Fh, [tcolor], 8002h ; 16x16 user font 702 <1> 702 <1> 702 <1> 702 <1> 702 <1> %if %0 >= 2 702 00000616 BB0F020000 <1> mov ebx, %2 702 <1> %if %0 >= 3 702 0000061B 8B0D[E2330000] <1> mov ecx, %3 702 <1> %if %0 = 4 702 00000621 BA02800000 <1> mov edx, %4 702 <1> %endif 702 <1> %endif 702 <1> %endif 702 00000626 B81F000000 <1> mov eax, %1 702 <1> 702 0000062B CD40 <1> int 40h 703 ; use LFB for current VBE mode 704 ; for writing fonts on screen 705 0000062D 45 inc ebp 706 0000062E 6683C611 add si, 17 ; next char pos 707 00000632 EBCF jmp short p_d_x_n 708 p_d_x_ok: 709 00000634 C3 retn 710 711 num_to_txt: 712 ; eax = number 713 ; edi = digit position 714 ;and eax, 999 715 00000635 83F863 cmp eax, 99 716 00000638 770C ja short numtxt_0 717 0000063A C60730 mov byte [edi], "0" 718 0000063D 47 inc edi 719 0000063E 3C09 cmp al, 9 720 00000640 7704 ja short numtxt_0 721 00000642 C60730 mov byte [edi], "0" 722 00000645 47 inc edi 723 numtxt_0: 724 00000646 B90A000000 mov ecx, 10 725 0000064B 89E5 mov ebp, esp 726 numtxt_1: 727 0000064D 29D2 sub edx, edx 728 0000064F F7F1 div ecx 729 00000651 52 push edx 730 00000652 09C0 or eax, eax 731 00000654 75F7 jnz short numtxt_1 732 numtxt_2: 733 00000656 58 pop eax 734 00000657 0430 add al, "0" 735 00000659 AA stosb 736 0000065A 39EC cmp esp, ebp 737 0000065C 72F8 jb short numtxt_2 738 0000065E C3 retn 739 740 circle_parameters: 741 ;db "Diameter: 320 pixels", 0Dh, 0Ah 742 ;db "x0: 160", 0Dh, 0Ah 743 ;db "y0: 100", 0Dh, 0Ah, 0 744 txt_diameter: 745 0000065F 4469616D657465723A- db "Diameter: ", 0 745 00000668 2000 746 val_diameter: 747 0000066A 30303020706978656C- db "000 pixels", 0 747 00000673 7300 748 00000675 78303A2000 txt_x0: db "x0: ", 0 749 0000067A 30303000 val_x0: db "000", 0 750 0000067E 79303A2000 txt_y0: db "y0: ", 0 751 00000683 30303000 val_y0: db "000", 0 752 753 program_msg: 754 00000687 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Circle" 754 00000690 2076322E302E33202D- 754 00000699 202827737973766964- 754 000006A2 656F27292054657374- 754 000006AB 2050726F6772616D20- 754 000006B4 2D2044726177204369- 754 000006BD 72636C65 755 000006C1 0D0A db 0Dh, 0Ah 756 000006C3 6279204572646F6761- db "by Erdogan Tan - 18/02/2021" 756 000006CC 6E2054616E202D2031- 756 000006D5 382F30322F32303231 757 ;db 0Dh, 0Ah, 0 758 000006DE 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 759 760 000006E2 557365204172726F77- db "Use Arrow Keys, Home, End to move the CIRCLE .." 760 000006EB 204B6579732C20486F- 760 000006F4 6D652C20456E642074- 760 000006FD 6F206D6F7665207468- 760 00000706 6520434952434C4520- 760 0000070F 2E2E 761 00000711 0D0A db 0Dh, 0Ah 762 00000713 557365202B2C2D206B- db "Use +,- keys to increase and decrease DIAMETER .." 762 0000071C 65797320746F20696E- 762 00000725 63726561736520616E- 762 0000072E 642064656372656173- 762 00000737 65204449414D455445- 762 00000740 52202E2E 763 00000744 0D0A db 0Dh, 0Ah 764 00000746 55736520454E544552- db "Use ENTER key to draw CIRCLE .." 764 0000074F 206B657920746F2064- 764 00000758 72617720434952434C- 764 00000761 45202E2E 765 00000765 0D0A db 0Dh, 0Ah 766 00000767 557365205350414345- db "Use SPACE, Pg Up, Pg Down keys to change COLOR .." 766 00000770 2C2050672055702C20- 766 00000779 506720446F776E206B- 766 00000782 65797320746F206368- 766 0000078B 616E676520434F4C4F- 766 00000794 52202E2E 767 00000798 0D0A db 0Dh, 0Ah 768 0000079A 507265737320455343- db "Press ESC to exit .." 768 000007A3 20746F206578697420- 768 000007AC 2E2E 769 000007AE 0D0A db 0Dh, 0Ah 770 000007B0 0D0A db 0Dh, 0Ah 771 000007B2 507265737320616E79- db "Press any key to continue .." 771 000007BB 206B657920746F2063- 771 000007C4 6F6E74696E7565202E- 771 000007CD 2E 772 nextline: 773 000007CE 0D0A00 db 0Dh, 0Ah, 0 774 bss: 775 776 ABSOLUTE bss 777 778 000007D1 alignb 4 779 780 bss_start: 781 fontbuff2: 782 000007D4 resb 2*256*16 ; 16x16 font data (modif. from 8x8) 783 fontbuff1: 784 000027D4 resb 256*8 ; 8x8 font data (from system) 785 _squares: 786 00002FD4 resd 256 ; squares of numbers from 0 t0 255 787 000033D4 prevd: resd 1 788 000033D8 prevx: resd 1 789 000033DC prevy resd 1 790 counter: 791 000033E0 resb 1 792 000033E1 pcolor: resb 1 ; previous (saved) text color 793 000033E2 tcolor: resb 1 ; text color 794 000033E3 phase: resb 1 ; circle phase (quarter) 795 000033E4 radius: resd 1 ; current radius value 796 000033E8 _r2: resd 1 ; square of R 797 000033EC color: resd 1 ; circle color 798 000033F0 _x0: resd 1 ; circle origin, x-axis 799 000033F4 _y0: resd 1 ; cirle origin, y-axis 800 000033F8 _x1: resd 1 ; recent value of abscissa 801 000033FC _y1: resd 1 ; recent value of ordinate 802 00003400 _fx: resd 256 ; for every X values from 0 to 255 803 pixelpos: 804 00003800 resd 1 805 circlebuffer: 806 00003804 resd 57600 ; 240*240*4 bytes 807 bss_end: