     1                                  ; ****************************************************************************
     2                                  ; circle17.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; 07/03/2021
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  ; nasm circle17.s -l circle17.txt -o CIRCLE17.PRG -Z error.txt
     9                                  ; (modified from 'circle3.s', 14/02/2021)
    10                                  
    11                                  ; Draw circle by using 'sysvideo' bh=3 (VESA VBE mode version, 1024*768*24bpp)
    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) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    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[AC050000]            	mov	edi, bss_start
    92 00000005 B908020000              	mov	ecx, (bss_end - bss_start)/4
    93                                  	;xor	eax, eax
    94 0000000A F3AB                    	rep	stosd
    95                                  
    96                                  	; program message
    97 0000000C BE[60040000]            	mov	esi, program_msg
    98 00000011 E8EF010000              	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                                  	;mov	ax, 4F02h ; vbe function 02h, set video mode
   106                                  	;;int   10h	  ; bios video interrupt
   107                                  	;mov	bx, 4118h ; vbe mode 118h with LFB 
   108                                  	;int	31h ; TRDOS 386 - Video interrupt
   109                                  	;cmp	ax, 004Fh
   110                                  	;jne	short terminate	
   111                                  
   112                                  	; edx = 0 (do not return LFB Info)
   113                                  
   114                                  	; Set Video Mode to 118h ; 1024x768, 24 bit true colors
   115                                  	sys	_video, 08FFh, 118h
    64                              <1> 
    65                              <1> 
    66                              <1> 
    67                              <1> 
    68                              <1>  %if %0 >= 2
    69 0000001A BBFF080000          <1>  mov ebx, %2
    70                              <1>  %if %0 >= 3
    71 0000001F B918010000          <1>  mov ecx, %3
    72                              <1>  %if %0 = 4
    73                              <1>  mov edx, %4
    74                              <1>  %endif
    75                              <1>  %endif
    76                              <1>  %endif
    77 00000024 B81F000000          <1>  mov eax, %1
    78                              <1> 
    79 00000029 CD40                <1>  int 40h
   116 0000002B 09C0                    	or	eax, eax
   117                                  	;jz	short terminate
   118                                  	;mov	[LFB_ADDR], edx ; pointer to LFB info table/structure
   119 0000002D 7450                    	jz	short terminate
   120                                  
   121                                  set_vesa_mode_118h_ok:
   122                                  	; Set squares of number from 0 to 255
   123 0000002F BF[AC050000]            	mov	edi, _squares
   124 00000034 B900010000              	mov	ecx, 256
   125 00000039 BB01000000              	mov	ebx, 1
   126                                  _ss_x:
   127 0000003E 89D8                    	mov	eax, ebx
   128 00000040 F7E3                    	mul	ebx
   129 00000042 AB                      	stosd
   130 00000043 43                      	inc	ebx
   131 00000044 E2F8                    	loop	_ss_x
   132                                  reset_color:
   133 00000046 C705[B8090000]00FF-     	mov	dword [color], 00FF00h ; initial color (green)
   133 0000004E 0000               
   134                                  reset_diameter:
   135 00000050 B8FF000000              	mov	eax, 255 ; initial diameter 
   136                                  newdiameter:	
   137                                  	; Set radius to 256
   138                                  	;mov	dword [radius], 255
   139                                  	;mov	dword [_r2], 65025
   140 00000055 A3[B0090000]            	mov	[radius], eax
   141 0000005A 89C3                    	mov	ebx, eax
   142 0000005C F7E3                    	mul	ebx
   143 0000005E A3[B4090000]            	mov	[_r2], eax ; square of circle radius
   144                                  	; x2+y2 = r2	
   145                                  	; Set Y values for X values from 1 to Radius - 1
   146 00000063 BF[CC090000]            	mov	edi, _fx
   147                                  _yy_x:	
   148 00000068 4B                      	dec	ebx
   149 00000069 7422                    	jz	short center
   150 0000006B 89D8                    	mov	eax, ebx
   151 0000006D F7E0                    	mul	eax
   152                                  	; eax = square of ebx
   153 0000006F 8B15[B4090000]          	mov	edx, [_r2]
   154 00000075 29C2                    	sub	edx, eax
   155 00000077 E8C3030000              	call	get_squareroot
   156 0000007C AB                      	stosd
   157 0000007D EBE9                    	jmp	short _yy_x
   158                                  
   159                                  	; ***
   160                                  
   161                                  terminate:
   162 0000007F E8D5030000              	call	set_text_mode
   163                                  	sys	_exit
    64                              <1> 
    65                              <1> 
    66                              <1> 
    67                              <1> 
    68                              <1>  %if %0 >= 2
    69                              <1>  mov ebx, %2
    70                              <1>  %if %0 >= 3
    71                              <1>  mov ecx, %3
    72                              <1>  %if %0 = 4
    73                              <1>  mov edx, %4
    74                              <1>  %endif
    75                              <1>  %endif
    76                              <1>  %endif
    77 00000084 B801000000          <1>  mov eax, %1
    78                              <1> 
    79 00000089 CD40                <1>  int 40h
   164                                  halt:
   165 0000008B EBFE                    	jmp	short halt
   166                                  
   167                                  	; ***
   168                                  
   169                                  	; move circle to center of screen
   170                                  center:
   171 0000008D E8F5020000              	call	movecenter
   172                                  _0:
   173 00000092 E87F010000              	call	drawcircle
   174                                  waitforkey:
   175 00000097 B401                    	mov	ah, 1
   176 00000099 CD32                    	int	32h
   177 0000009B 740A                    	jz	short getkey
   178 0000009D 66FF05[AC090000]        	inc	word [counter]
   179 000000A4 90                      	nop
   180 000000A5 EBF0                    	jmp	short waitforkey
   181                                  getkey:
   182 000000A7 30E4                    	xor	ah, ah
   183 000000A9 CD32                    	int	32h
   184                                  
   185 000000AB 663D032E                	cmp	ax, 2E03h
   186 000000AF 74CE                    	je	short terminate
   187 000000B1 3C1B                    	cmp	al, 1Bh ; ESC key
   188 000000B3 74CA                    	je	short terminate	
   189                                  
   190 000000B5 3C2B                    	cmp	al, '+'
   191 000000B7 7513                    	jne	short _1
   192                                  	
   193 000000B9 A1[B0090000]            	mov	eax, [radius]
   194                                  
   195 000000BE 663DFF00                	cmp	ax, 255
   196 000000C2 7354                    	jnb	short _3_  ; beep
   197                                  	
   198                                  	; delete circle by drawing black circle
   199                                  	; with same diameter and at same coordinate
   200 000000C4 E84D030000              	call	black_circle
   201                                  	; increase radius of the circle
   202 000000C9 40                      	inc	eax	
   203                                  	;mov	[radius], eax
   204 000000CA EB89                    	jmp	newdiameter ; draw with new diameter
   205                                  _1:
   206 000000CC 3C2D                    	cmp	al, '-'
   207 000000CE 7516                    	jne	short _2
   208                                  
   209 000000D0 A1[B0090000]            	mov	eax, [radius]
   210                                  
   211 000000D5 6683F801                	cmp	ax, 1
   212 000000D9 763D                    	jna	short _3_ ; beep
   213                                  	
   214                                  	; delete circle by drawing black circle
   215                                  	; with same diameter and at same coordinate
   216 000000DB E836030000              	call	black_circle
   217                                  	; decrease radius of the circle
   218 000000E0 48                      	dec	eax	
   219                                  	;mov	[radius], eax
   220 000000E1 E96FFFFFFF              	jmp	newdiameter ; draw with new diameter
   221                                  _2:
   222 000000E6 3C20                    	cmp	al, 20h  ; space
   223 000000E8 750C                    	jne	short _3
   224 000000EA 8105[B8090000]3020-     	add	dword [color], 402030h 	
   224 000000F2 4000               
   225 000000F4 EB9C                    	jmp	short _0
   226                                  _3:
   227 000000F6 80FC4B                  	cmp	ah, 4Bh
   228 000000F9 7527                    	jne	short _4
   229                                  	; left arrow
   230 000000FB A1[B0090000]            	mov	eax, [radius]
   231 00000100 3B05[BC090000]          	cmp	eax, [_x0]
   232 00000106 7310                    	jnb	short _3_
   233 00000108 E809030000              	call	black_circle ; clear current position 
   234 0000010D FF0D[BC090000]          	dec	dword [_x0]
   235 00000113 E97AFFFFFF              	jmp	_0 ; draw 
   236                                  _3_:
   237 00000118 E810030000              	call	beep
   238 0000011D E975FFFFFF              	jmp	waitforkey
   239                                  _4:
   240 00000122 80FC4D                  	cmp	ah, 4Dh
   241 00000125 7522                    	jne	short _5
   242                                  
   243                                  	; right arrow
   244 00000127 A1[B0090000]            	mov	eax, [radius]
   245 0000012C 0305[BC090000]          	add	eax, [_x0]
   246 00000132 3DFF030000              	cmp	eax, 1023
   247 00000137 73DF                    	jnb	short _3_
   248 00000139 E8D8020000              	call	black_circle ; clear current position 
   249 0000013E FF05[BC090000]          	inc	dword [_x0]
   250 00000144 E949FFFFFF              	jmp	_0 ; draw 
   251                                  _5:
   252 00000149 80FC50                  	cmp	ah, 50h
   253 0000014C 7522                    	jne	short _6
   254                                  	; down arrow
   255 0000014E A1[B0090000]            	mov	eax, [radius]
   256 00000153 0305[C0090000]          	add	eax, [_y0]
   257 00000159 3DFF020000              	cmp	eax, 767
   258 0000015E 73B8                    	jnb	short _3_
   259 00000160 E8B1020000              	call	black_circle ; clear current position 
   260 00000165 FF05[C0090000]          	inc	dword [_y0]
   261 0000016B E922FFFFFF              	jmp	_0 ; draw 
   262                                  _6:
   263 00000170 80FC48                  	cmp	ah, 48h
   264 00000173 751D                    	jne	short _7
   265                                  	; up arrow
   266 00000175 A1[B0090000]            	mov	eax, [radius]
   267 0000017A 3B05[C0090000]          	cmp	eax, [_y0]
   268 00000180 7396                    	jnb	short _3_
   269 00000182 E88F020000              	call	black_circle ; clear current position 
   270 00000187 FF0D[C0090000]          	dec	dword [_y0]
   271 0000018D E900FFFFFF              	jmp	_0 ; draw 
   272                                  _7:
   273 00000192 80FC47                  	cmp	ah, 47h ; Home key
   274 00000195 750F                    	jne	short _8
   275 00000197 E87A020000              	call	black_circle ; clear current position 
   276 0000019C E88C020000              	call	beep
   277 000001A1 E9AAFEFFFF              	jmp	reset_diameter
   278                                  		; reset diameter, move to center
   279                                  _8:
   280 000001A6 80FC4F                  	cmp	ah, 4Fh ; End key
   281 000001A9 750F                    	jne	short _9
   282 000001AB E866020000              	call	black_circle ; clear current position 
   283 000001B0 E878020000              	call	beep
   284 000001B5 E98CFEFFFF              	jmp	reset_color 
   285                                  		; reset color and diameter, move to center
   286                                  _9:	
   287 000001BA 663D0D1C                	cmp	ax, 1C0Dh
   288 000001BE 750C                    	jne	short _10
   289 000001C0 8105[B8090000]4030-     	add	dword [color], 203040h 
   289 000001C8 2000               
   290 000001CA EB2A                    	jmp	short _14
   291                                  _10:	
   292 000001CC 80FC53                  	cmp	ah, 53h ; INSERT
   293 000001CF 7425                    	je	short _14
   294                                  _11:
   295 000001D1 80FC52                  	cmp	ah, 52h  ; DEL
   296 000001D4 7420                    	je	short _14
   297                                  _12:
   298 000001D6 80FC49                  	cmp	ah, 49h  ; Page UP
   299 000001D9 750C                    	jne	short _13
   300 000001DB 812D[B8090000]3010-     	sub	dword [color], 201030h 
   300 000001E3 2000               
   301 000001E5 EB0F                    	jmp	short _14
   302                                  _13:
   303 000001E7 80FC51                  	cmp	ah, 51h  ; Page Down
   304 000001EA 7514                    	jne	short _15
   305 000001EC 8105[B8090000]3010-     	add	dword [color], 201030h 
   305 000001F4 2000               
   306                                  _14:
   307 000001F6 E832020000              	call	beep
   308 000001FB E992FEFFFF              	jmp	_0
   309                                  _15:
   310 00000200 E992FEFFFF              	jmp	waitforkey
   311                                  
   312                                  print_msg:
   313 00000205 B40E                    	mov	ah, 0Eh
   314 00000207 BB07000000              	mov	ebx, 7
   315                                  	;mov	bl, 7 ; char attribute & color
   316                                  p_next_chr:
   317 0000020C AC                      	lodsb
   318 0000020D 08C0                    	or	al, al
   319 0000020F 7404                    	jz	short p_retn ; retn	
   320 00000211 CD31                    	int	31h
   321 00000213 EBF7                    	jmp	short p_next_chr
   322                                  p_retn:
   323 00000215 C3                      	retn
   324                                  
   325                                  drawcircle:
   326                                  	; INPUT:
   327                                  	;	[_x0]
   328                                  	;	[_y0]
   329                                  	;	[radius]
   330                                  	;	[color]
   331                                  	;
   332                                  	; Modified registers: esi, eax, ecx, ebx, edx	
   333                                  _dc_ph0:
   334                                  	; quarter 1	
   335                                  	; start from y = 0, x = radius
   336 00000216 31C0                    	xor	eax, eax
   337 00000218 A3[C8090000]            	mov	[_y1], eax ; 0
   338 0000021D A2[AE090000]            	mov	[phase], al ; 0
   339 00000222 8B2D[B0090000]          	mov	ebp, [radius]
   340 00000228 892D[C4090000]          	mov	[_x1], ebp ; y = 0, x = r
   341 0000022E BE[CC090000]            	mov	esi, _fx
   342                                  _dc_ph0_n:
   343 00000233 FF0D[C4090000]          	dec	dword [_x1]
   344 00000239 AD                      	lodsd
   345                                  _dc_ph0_x:
   346 0000023A 8B15[C8090000]          	mov	edx, [_y1]
   347 00000240 42                      	inc	edx
   348 00000241 39C2                    	cmp	edx, eax
   349 00000243 7314                    	jnb	short _dc_ph0_y
   350 00000245 50                      	push	eax
   351 00000246 8915[C8090000]          	mov	[_y1], edx
   352 0000024C E84B010000              	call	get_start_offset
   353 00000251 E818010000              	call	write_pixel
   354 00000256 58                      	pop	eax
   355 00000257 EBE1                    	jmp	short _dc_ph0_x	
   356                                  _dc_ph0_y:
   357 00000259 A3[C8090000]            	mov	[_y1], eax
   358 0000025E E839010000              	call	get_start_offset
   359 00000263 E806010000              	call	write_pixel
   360 00000268 4D                      	dec	ebp
   361 00000269 75C8                    	jnz	short _dc_ph0_n
   362                                  _dc_ph1:
   363                                  	; quarter 2	
   364                                  	; start from y = radius, x = 0
   365 0000026B FE05[AE090000]          	inc	byte [phase]
   366 00000271 31C0                    	xor	eax, eax
   367 00000273 A3[C4090000]            	mov	[_x1], eax ; 0
   368 00000278 8B2D[B0090000]          	mov	ebp, [radius]
   369 0000027E 892D[C8090000]          	mov	[_y1], ebp ; y = r, x = 0
   370 00000284 BE[CC090000]            	mov	esi, _fx
   371                                  _dc_ph1_n:
   372 00000289 FF0D[C8090000]          	dec 	dword [_y1]
   373 0000028F AD                      	lodsd
   374                                  _dc_ph1_x:
   375 00000290 8B15[C4090000]          	mov	edx, [_x1]
   376 00000296 42                      	inc	edx
   377 00000297 39C2                    	cmp	edx, eax
   378 00000299 7314                    	jnb	short _dc_ph1_y
   379 0000029B 50                      	push	eax
   380 0000029C 8915[C4090000]          	mov	[_x1], edx
   381 000002A2 E8F5000000              	call	get_start_offset
   382 000002A7 E8C2000000              	call	write_pixel
   383 000002AC 58                      	pop	eax
   384 000002AD EBE1                    	jmp	short _dc_ph1_x	
   385                                  _dc_ph1_y:
   386 000002AF A3[C4090000]            	mov	[_x1], eax
   387 000002B4 E8E3000000              	call	get_start_offset
   388 000002B9 E8B0000000              	call	write_pixel
   389 000002BE 4D                      	dec	ebp
   390 000002BF 75C8                    	jnz	short _dc_ph1_n
   391                                  _dc_ph2:
   392                                  	; quarter 3	
   393                                  	; start from y = 0, x = radius
   394 000002C1 FE05[AE090000]          	inc	byte [phase]
   395 000002C7 31C0                    	xor	eax, eax
   396 000002C9 A3[C8090000]            	mov	[_y1], eax ; 0
   397 000002CE 8B2D[B0090000]          	mov	ebp, [radius]
   398 000002D4 892D[C4090000]          	mov	[_x1], ebp ; y = 0, x = r
   399 000002DA BE[CC090000]            	mov	esi, _fx
   400                                  _dc_ph2_n:
   401 000002DF FF0D[C4090000]          	dec	dword [_x1]
   402 000002E5 AD                      	lodsd
   403                                  _dc_ph2_x:
   404 000002E6 8B15[C8090000]          	mov	edx, [_y1]
   405 000002EC 42                      	inc	edx
   406 000002ED 39C2                    	cmp	edx, eax
   407 000002EF 7314                    	jnb	short _dc_ph2_y
   408 000002F1 50                      	push	eax
   409 000002F2 8915[C8090000]          	mov	[_y1], edx
   410 000002F8 E89F000000              	call	get_start_offset
   411 000002FD E86C000000              	call	write_pixel
   412 00000302 58                      	pop	eax
   413 00000303 EBE1                    	jmp	short _dc_ph2_x	
   414                                  _dc_ph2_y:
   415 00000305 A3[C8090000]            	mov	[_y1], eax
   416 0000030A E88D000000              	call	get_start_offset
   417 0000030F E85A000000              	call	write_pixel
   418 00000314 4D                      	dec	ebp
   419 00000315 75C8                    	jnz	short _dc_ph2_n
   420                                  _dc_ph3:
   421                                  	; quarter 4	
   422                                  	; start from y = radius, x = 0
   423 00000317 FE05[AE090000]          	inc	byte [phase]
   424 0000031D 31C0                    	xor	eax, eax
   425 0000031F A3[C4090000]            	mov	[_x1], eax ; 0
   426 00000324 8B2D[B0090000]          	mov	ebp, [radius]
   427 0000032A 892D[C8090000]          	mov	[_y1], ebp ; y = r, x = 0
   428 00000330 BE[CC090000]            	mov	esi, _fx
   429                                  _dc_ph3_n:
   430 00000335 FF0D[C8090000]          	dec	dword [_y1]
   431 0000033B AD                      	lodsd
   432                                  _dc_ph3_x:
   433 0000033C 8B15[C4090000]          	mov	edx, [_x1]
   434 00000342 42                      	inc	edx
   435 00000343 39C2                    	cmp	edx, eax
   436 00000345 7314                    	jnb	short _dc_ph3_y
   437 00000347 50                      	push	eax
   438 00000348 8915[C4090000]          	mov	[_x1], edx
   439 0000034E E849000000              	call	get_start_offset
   440 00000353 E816000000              	call	write_pixel
   441 00000358 58                      	pop	eax
   442 00000359 EBE1                    	jmp	short _dc_ph3_x	
   443                                  _dc_ph3_y:
   444 0000035B A3[C4090000]            	mov	[_x1], eax
   445 00000360 E837000000              	call	get_start_offset
   446 00000365 E804000000              	call	write_pixel
   447 0000036A 4D                      	dec	ebp
   448 0000036B 75C8                    	jnz	short _dc_ph3_n
   449                                  _dc_ph4:
   450 0000036D C3                      	retn	
   451                                  
   452                                  write_pixel:
   453                                  	; convert pixel offset to 24bpp offset (*3)
   454 0000036E 89C2                    	mov	edx, eax
   455 00000370 D1E2                    	shl	edx, 1
   456 00000372 01C2                    	add	edx, eax
   457                                  
   458                                  	sys	_video, 0301h, [color]
    64                              <1> 
    65                              <1> 
    66                              <1> 
    67                              <1> 
    68                              <1>  %if %0 >= 2
    69 00000374 BB01030000          <1>  mov ebx, %2
    70                              <1>  %if %0 >= 3
    71 00000379 8B0D[B8090000]      <1>  mov ecx, %3
    72                              <1>  %if %0 = 4
    73                              <1>  mov edx, %4
    74                              <1>  %endif
    75                              <1>  %endif
    76                              <1>  %endif
    77 0000037F B81F000000          <1>  mov eax, %1
    78                              <1> 
    79 00000384 CD40                <1>  int 40h
   459 00000386 C3                      	retn  
   460                                  
   461                                  movecenter:
   462 00000387 C705[BC090000]0002-     	mov	dword [_x0], 1024/2
   462 0000038F 0000               
   463 00000391 C705[C0090000]8001-     	mov	dword [_y0], 768/2
   463 00000399 0000               
   464 0000039B C3                      	retn
   465                                  
   466                                  get_start_offset:
   467 0000039C B800040000              	mov	eax, 1024
   468 000003A1 8B15[C0090000]          	mov	edx, [_y0]
   469 000003A7 803D[AE090000]00        	cmp	byte [phase], 0
   470 000003AE 7715                    	ja	short gso_1
   471                                  gso_0:
   472                                  	; quarter 1
   473 000003B0 2B15[C8090000]          	sub	edx, [_y1] ; y = 0 -> r
   474 000003B6 F7E2                    	mul	edx
   475 000003B8 0305[BC090000]          	add	eax, [_x0]
   476 000003BE 0305[C4090000]          	add	eax, [_x1] ; x = r -> 0
   477 000003C4 C3                      	retn
   478                                  gso_1:
   479 000003C5 803D[AE090000]01        	cmp	byte [phase], 1
   480 000003CC 7715                    	ja	short gso_2
   481                                  	; quarter 2
   482 000003CE 2B15[C8090000]          	sub	edx, [_y1] ; y = r -> 0
   483 000003D4 F7E2                    	mul	edx
   484 000003D6 0305[BC090000]          	add	eax, [_x0]
   485 000003DC 2B05[C4090000]          	sub	eax, [_x1] ; x = 0 -> -r
   486 000003E2 C3                      	retn
   487                                  gso_2:
   488 000003E3 803D[AE090000]02        	cmp	byte [phase], 2
   489 000003EA 7715                    	ja	short gso_3
   490                                  	; quarter 3
   491 000003EC 0315[C8090000]          	add	edx, [_y1] ; y = 0 -> -r 
   492 000003F2 F7E2                    	mul	edx
   493 000003F4 0305[BC090000]          	add	eax, [_x0]
   494 000003FA 2B05[C4090000]          	sub	eax, [_x1] ; x = -r -> 0
   495 00000400 C3                      	retn
   496                                  gso_3:
   497                                  	; quarter 4
   498 00000401 0315[C8090000]          	add	edx, [_y1] ; y = -r -> 0
   499 00000407 F7E2                    	mul	edx
   500 00000409 0305[BC090000]          	add	eax, [_x0]
   501 0000040F 0305[C4090000]          	add	eax, [_x1] ; x = 0 -> r
   502 00000415 C3                      	retn
   503                                  
   504                                  black_circle:
   505 00000416 50                      	push	eax ; *
   506 00000417 29C0                    	sub	eax, eax
   507 00000419 8705[B8090000]          	xchg	eax, [color] ; 0
   508 0000041F 50                      	push	eax ; **
   509 00000420 E8F1FDFFFF              	call	drawcircle
   510 00000425 8F05[B8090000]          	pop	dword [color] ; **
   511 0000042B 58                      	pop	eax ; *
   512 0000042C C3                      	retn
   513                                  
   514                                  beep:
   515                                  	; call beep function (16/64 second, 886Hz)
   516                                  	sys	_audio, 16, 1331
    64                              <1> 
    65                              <1> 
    66                              <1> 
    67                              <1> 
    68                              <1>  %if %0 >= 2
    69 0000042D BB10000000          <1>  mov ebx, %2
    70                              <1>  %if %0 >= 3
    71 00000432 B933050000          <1>  mov ecx, %3
    72                              <1>  %if %0 = 4
    73                              <1>  mov edx, %4
    74                              <1>  %endif
    75                              <1>  %endif
    76                              <1>  %endif
    77 00000437 B820000000          <1>  mov eax, %1
    78                              <1> 
    79 0000043C CD40                <1>  int 40h
   517 0000043E C3                      	retn
   518                                  
   519                                  get_squareroot:
   520                                  	; input: edx = square of the number (y)
   521                                  	; output: eax = approx. square root of ebx 
   522 0000043F BE[AC050000]            	mov	esi, _squares
   523 00000444 53                      	push	ebx
   524 00000445 31DB                    	xor	ebx, ebx
   525                                  	;mov	ecx, 256
   526 00000447 8B0D[B0090000]          	mov	ecx, [radius] ; max. value of radius is 256
   527                                  q_sr_x:	
   528 0000044D AD                      	lodsd
   529 0000044E 39D0                    	cmp	eax, edx
   530 00000450 7303                    	jnb	short q_sr_ok
   531 00000452 43                      	inc	ebx
   532 00000453 E2F8                    	loop	q_sr_x
   533                                  q_sr_ok:
   534 00000455 89D8                    	mov	eax, ebx
   535 00000457 5B                      	pop	ebx
   536 00000458 C3                      	retn
   537                                  
   538                                  set_text_mode:
   539 00000459 30E4                    	xor    ah, ah
   540 0000045B B003                    	mov    al, 3                        
   541                                   	;int   10h	; al = 03h text mode, int 10 video
   542 0000045D CD31                    	int    31h ; TRDOS 386 - Video interrupt
   543 0000045F C3                      	retn
   544                                  		
   545                                  program_msg:
   546 00000460 5452444F5320333836-     	db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Circle"
   546 00000469 2076322E302E33202D-
   546 00000472 202827737973766964-
   546 0000047B 656F27292054657374-
   546 00000484 2050726F6772616D20-
   546 0000048D 2D2044726177204369-
   546 00000496 72636C65           
   547 0000049A 0D0A                    	db 0Dh, 0Ah
   548 0000049C 6279204572646F6761-     	db "by Erdogan Tan - 07/03/2021"
   548 000004A5 6E2054616E202D2030-
   548 000004AE 372F30332F32303231 
   549                                  	;db 0Dh, 0Ah, 0
   550 000004B7 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
   551                                  
   552 000004BB 557365204172726F77-     	db "Use Arrow Keys, Home, End to move the CIRCLE .."
   552 000004C4 204B6579732C20486F-
   552 000004CD 6D652C20456E642074-
   552 000004D6 6F206D6F7665207468-
   552 000004DF 6520434952434C4520-
   552 000004E8 2E2E               
   553 000004EA 0D0A                    	db 0Dh, 0Ah
   554 000004EC 557365202B2C2D206B-     	db "Use +,- keys to increase and decrease DIAMETER .."		
   554 000004F5 65797320746F20696E-
   554 000004FE 63726561736520616E-
   554 00000507 642064656372656173-
   554 00000510 65204449414D455445-
   554 00000519 52202E2E           
   555 0000051D 0D0A                    	db 0Dh, 0Ah
   556 0000051F 55736520454E544552-     	db "Use ENTER key to draw CIRCLE .."
   556 00000528 206B657920746F2064-
   556 00000531 72617720434952434C-
   556 0000053A 45202E2E           
   557 0000053E 0D0A                    	db 0Dh, 0Ah
   558 00000540 557365205350414345-     	db "Use SPACE, Pg Up, Pg Down keys to change COLOR .."
   558 00000549 2C2050672055702C20-
   558 00000552 506720446F776E206B-
   558 0000055B 65797320746F206368-
   558 00000564 616E676520434F4C4F-
   558 0000056D 52202E2E           
   559 00000571 0D0A                    	db 0Dh, 0Ah	
   560 00000573 507265737320455343-     	db "Press ESC to exit .."
   560 0000057C 20746F206578697420-
   560 00000585 2E2E               
   561 00000587 0D0A                    	db 0Dh, 0Ah
   562 00000589 0D0A                    	db 0Dh, 0Ah
   563 0000058B 507265737320616E79-     	db "Press any key to continue .."
   563 00000594 206B657920746F2063-
   563 0000059D 6F6E74696E7565202E-
   563 000005A6 2E                 
   564                                  nextline:
   565 000005A7 0D0A00                  	db 0Dh, 0Ah, 0	
   566                                  
   567                                  bss:
   568                                  
   569                                  ABSOLUTE bss
   570                                  
   571 000005AA ????                    alignb 4
   572                                  
   573                                  bss_start:
   574                                  _squares:
   575 000005AC <res 400h>              	resd 256 ; squares of numbers from 0 t0 255	
   576                                  counter:
   577 000009AC ????                    	resw 1
   578 000009AE ????                    phase:	resw 1
   579 000009B0 ????????                radius:	resd 1 ; Current Radius value
   580 000009B4 ????????                _r2:	resd 1 ; Square of R
   581 000009B8 ????????                color:	resd 1
   582 000009BC ????????                _x0:	resd 1
   583 000009C0 ????????                _y0:	resd 1
   584 000009C4 ????????                _x1:	resd 1
   585 000009C8 ????????                _y1:	resd 1
   586 000009CC <res 400h>              _fx:	resd 256 ; For every X values from 0 to 255
   587                                  bss_end:
