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