     1                                  ; ****************************************************************************
     2                                  ; circle4.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; 15/02/2021
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  ; nasm circle4.s -l circle4.txt -o CIRCLE4.PRG -Z error.txt
     9                                  ; (modified from 'circle1.s', 14/02/2021)
    10                                  
    11                                  ; Draw circle by using 'sysvideo' bx=0305h
    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[A4050000]            	mov	edi, bss_start
    92 00000005 B919290000              	mov	ecx, (bss_end - bss_start)/4
    93                                  	;xor	eax, eax
    94 0000000A F3AB                    	rep	stosd
    95                                  
    96                                  	; program message
    97 0000000C BE[58040000]            	mov	esi, program_msg
    98 00000011 E8C7010000              	call	print_msg
    99                                  
   100 00000016 30E4                    	xor	ah, ah
   101                                  	;int	16h	; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
   102                                  			; Return: AH = scan code, AL = character
   103 00000018 CD32                    	int	32h	; TRDOS 386 Keyboard interrupt 
   104                                  
   105                                  	;; Set Video Mode to 13h
   106                                  	;sys	_video, 0813h
   107                                  	;cmp	eax, 14h 
   108                                  	;je	short mode_13h_set_ok
   109                                  
   110                                  	; set VGA mode by using int 31h
   111 0000001A 66B81300                	mov	ax, 13h	; mode 13h ; 
   112 0000001E CD31                    	int	31h	; real mode: int 10h
   113                                  	;jmp	short mode_13h_set_ok
   114                                  
   115                                  mode_13h_set_ok:
   116                                  	; Set squares of number from 0 to 255
   117 00000020 BF[A4050000]            	mov	edi, _squares
   118 00000025 B9FF000000              	mov	ecx, 255
   119 0000002A BB01000000              	mov	ebx, 1
   120                                  _ss_x:
   121 0000002F 89D8                    	mov	eax, ebx
   122 00000031 F7E3                    	mul	ebx
   123 00000033 AB                      	stosd
   124 00000034 43                      	inc	ebx
   125 00000035 E2F8                    	loop	_ss_x
   126                                  reset_color:
   127 00000037 C605[B0090000]8E        	mov	byte [color], 142 ; initial color
   128                                  reset_diameter:
   129 0000003E B864000000              	mov	eax, 100 ; initial diameter 
   130                                  newdiameter:	
   131                                  	; Set radius to 100
   132                                  	;mov	dword [radius], 100
   133                                  	;mov	dword [_r2], 10000
   134 00000043 A3[A8090000]            	mov	[radius], eax
   135 00000048 89C3                    	mov	ebx, eax
   136 0000004A F7E3                    	mul	ebx
   137 0000004C A3[AC090000]            	mov	[_r2], eax ; square of circle radius
   138                                  	; x2+y2 = r2	
   139                                  	; Set Y values for X values from 1 to Radius - 1
   140 00000051 BF[C4090000]            	mov	edi, _fx
   141                                  _yy_x:	
   142 00000056 4B                      	dec	ebx
   143 00000057 7422                    	jz	short center
   144 00000059 89D8                    	mov	eax, ebx
   145 0000005B F7E0                    	mul	eax
   146                                  	; eax = square of ebx
   147 0000005D 8B15[AC090000]          	mov	edx, [_r2]
   148 00000063 29C2                    	sub	edx, eax
   149 00000065 E8CD030000              	call	get_squareroot
   150 0000006A AB                      	stosd
   151 0000006B EBE9                    	jmp	short _yy_x
   152                                  
   153                                  	; ***
   154                                  
   155                                  terminate:
   156 0000006D E8DF030000              	call	set_text_mode
   157                                  	sys	_exit
   157                              <1> 
   157                              <1> 
   157                              <1> 
   157                              <1> 
   157                              <1>  %if %0 >= 2
   157                              <1>  mov ebx, %2
   157                              <1>  %if %0 >= 3
   157                              <1>  mov ecx, %3
   157                              <1>  %if %0 = 4
   157                              <1>  mov edx, %4
   157                              <1>  %endif
   157                              <1>  %endif
   157                              <1>  %endif
   157 00000072 B801000000          <1>  mov eax, %1
   157                              <1> 
   157 00000077 CD40                <1>  int 40h
   158                                  halt:
   159 00000079 EBFE                    	jmp	short halt
   160                                  
   161                                  	; ***
   162                                  
   163                                  	; move circle to center of screen
   164                                  center:
   165 0000007B E800030000              	call	movecenter
   166                                  _0:
   167 00000080 E869010000              	call	drawcircle
   168                                  waitforkey:
   169 00000085 B401                    	mov	ah, 1
   170 00000087 CD32                    	int	32h
   171 00000089 740C                    	jz	short getkey
   172 0000008B 66FF05[A4090000]        	inc	word [counter]
   173 00000092 90                      	nop
   174 00000093 90                      	nop
   175 00000094 90                      	nop
   176 00000095 EBEE                    	jmp	short waitforkey
   177                                  getkey:
   178 00000097 30E4                    	xor	ah, ah
   179 00000099 CD32                    	int	32h
   180                                  
   181 0000009B 663D032E                	cmp	ax, 2E03h
   182 0000009F 74CC                    	je	short terminate
   183 000000A1 3C1B                    	cmp	al, 1Bh ; ESC key
   184 000000A3 74C8                    	je	short terminate	
   185                                  
   186 000000A5 3C2B                    	cmp	al, '+'
   187 000000A7 7511                    	jne	short _1
   188                                  	
   189 000000A9 A1[A8090000]            	mov	eax, [radius]
   190                                  
   191 000000AE 3C63                    	cmp	al, 99
   192 000000B0 734C                    	jnb	short _3_  ; beep
   193                                  	
   194                                  	; delete circle by drawing black circle
   195                                  	; with same diameter and at same coordinate
   196 000000B2 E858030000              	call	black_circle
   197                                  	; increase radius of the circle
   198 000000B7 40                      	inc	eax	
   199                                  	;mov	[radius], eax
   200 000000B8 EB89                    	jmp	newdiameter ; draw with new diameter
   201                                  _1:
   202 000000BA 3C2D                    	cmp	al, '-'
   203 000000BC 7514                    	jne	short _2
   204                                  
   205 000000BE A1[A8090000]            	mov	eax, [radius]
   206                                  
   207 000000C3 3C01                    	cmp	al, 1
   208 000000C5 7637                    	jna	short _3_ ; beep
   209                                  	
   210                                  	; delete circle by drawing black circle
   211                                  	; with same diameter and at same coordinate
   212 000000C7 E843030000              	call	black_circle
   213                                  	; decrease radius of the circle
   214 000000CC 48                      	dec	eax	
   215                                  	;mov	[radius], eax
   216 000000CD E971FFFFFF              	jmp	newdiameter ; draw with new diameter
   217                                  _2:
   218 000000D2 3C20                    	cmp	al, 20h  ; space
   219 000000D4 7509                    	jne	short _3
   220 000000D6 8005[B0090000]08        	add	byte [color], 8 	
   221 000000DD EBA1                    	jmp	short _0
   222                                  _3:
   223 000000DF 80FC4B                  	cmp	ah, 4Bh
   224 000000E2 7521                    	jne	short _4
   225                                  	; left arrow
   226 000000E4 A1[A8090000]            	mov	eax, [radius]
   227 000000E9 3B05[B4090000]          	cmp	eax, [_x0]
   228 000000EF 730D                    	jnb	short _3_
   229 000000F1 E819030000              	call	black_circle ; clear current position 
   230 000000F6 FF0D[B4090000]          	dec	dword [_x0]
   231 000000FC EB82                    	jmp	_0 ; draw 
   232                                  _3_:
   233 000000FE E822030000              	call	beep
   234 00000103 EB80                    	jmp	waitforkey
   235                                  _4:
   236 00000105 80FC4D                  	cmp	ah, 4Dh
   237 00000108 7522                    	jne	short _5
   238                                  
   239                                  	; right arrow
   240 0000010A A1[A8090000]            	mov	eax, [radius]
   241 0000010F 0305[B4090000]          	add	eax, [_x0]
   242 00000115 3D3F010000              	cmp	eax, 319
   243 0000011A 73E2                    	jnb	short _3_
   244 0000011C E8EE020000              	call	black_circle ; clear current position 
   245 00000121 FF05[B4090000]          	inc	dword [_x0]
   246 00000127 E954FFFFFF              	jmp	_0 ; draw 
   247                                  _5:
   248 0000012C 80FC50                  	cmp	ah, 50h
   249 0000012F 7522                    	jne	short _6
   250                                  	; down arrow
   251 00000131 A1[A8090000]            	mov	eax, [radius]
   252 00000136 0305[B8090000]          	add	eax, [_y0]
   253 0000013C 3DC7000000              	cmp	eax, 199
   254 00000141 73BB                    	jnb	short _3_
   255 00000143 E8C7020000              	call	black_circle ; clear current position 
   256 00000148 FF05[B8090000]          	inc	dword [_y0]
   257 0000014E E92DFFFFFF              	jmp	_0 ; draw 
   258                                  _6:
   259 00000153 80FC48                  	cmp	ah, 48h
   260 00000156 751D                    	jne	short _7
   261                                  	; up arrow
   262 00000158 A1[A8090000]            	mov	eax, [radius]
   263 0000015D 3B05[B8090000]          	cmp	eax, [_y0]
   264 00000163 7399                    	jnb	short _3_
   265 00000165 E8A5020000              	call	black_circle ; clear current position 
   266 0000016A FF0D[B8090000]          	dec	dword [_y0]
   267 00000170 E90BFFFFFF              	jmp	_0 ; draw 
   268                                  _7:
   269 00000175 80FC47                  	cmp	ah, 47h ; Home key
   270 00000178 750F                    	jne	short _8
   271 0000017A E890020000              	call	black_circle ; clear current position 
   272 0000017F E8A1020000              	call	beep
   273 00000184 E9B5FEFFFF              	jmp	reset_diameter
   274                                  		; reset diameter, move to center
   275                                  _8:
   276 00000189 80FC4F                  	cmp	ah, 4Fh ; End key
   277 0000018C 750F                    	jne	short _9
   278 0000018E E87C020000              	call	black_circle ; clear current position 
   279 00000193 E88D020000              	call	beep
   280 00000198 E99AFEFFFF              	jmp	reset_color 
   281                                  		; reset color and diameter, move to center
   282                                  _9:	
   283 0000019D 663D0D1C                	cmp	ax, 1C0Dh
   284 000001A1 7509                    	jne	short _10
   285 000001A3 8005[B0090000]04        	add	byte [color], 4
   286 000001AA EB22                    	jmp	short _14
   287                                  _10:	
   288 000001AC 80FC53                  	cmp	ah, 53h ; INSERT
   289 000001AF 741D                    	je	short _14
   290                                  _11:
   291 000001B1 80FC52                  	cmp	ah, 52h  ; DEL
   292 000001B4 7418                    	je	short _14
   293                                  _12:
   294 000001B6 80FC49                  	cmp	ah, 49h  ; Page UP
   295 000001B9 7508                    	jne	short _13
   296 000001BB FE0D[B0090000]          	dec	byte [color]
   297 000001C1 EB0B                    	jmp	short _14
   298                                  _13:
   299 000001C3 80FC51                  	cmp	ah, 51h  ; Page Down
   300 000001C6 7510                    	jne	short _15
   301 000001C8 FE05[B0090000]          	inc	byte [color]
   302                                  _14:
   303 000001CE E852020000              	call	beep
   304 000001D3 E9A8FEFFFF              	jmp	_0
   305                                  _15:
   306 000001D8 E9A8FEFFFF              	jmp	waitforkey
   307                                  
   308                                  print_msg:
   309 000001DD B40E                    	mov	ah, 0Eh
   310 000001DF BB07000000              	mov	ebx, 7
   311                                  	;mov	bl, 7 ; char attribute & color
   312                                  p_next_chr:
   313 000001E4 AC                      	lodsb
   314 000001E5 08C0                    	or	al, al
   315 000001E7 7404                    	jz	short p_retn ; retn	
   316 000001E9 CD31                    	int	31h
   317 000001EB EBF7                    	jmp	short p_next_chr
   318                                  p_retn:
   319 000001ED C3                      	retn
   320                                  
   321                                  drawcircle:
   322                                  	; INPUT:
   323                                  	;	[_x0]
   324                                  	;	[_y0]
   325                                  	;	[radius]
   326                                  	;	[color]
   327                                  	;
   328                                  	; Modified registers: esi, edi, eax, ecx, ebx, edx
   329                                  
   330                                  	; set pixel pointer position to start of circle buffer
   331 000001EE B8[C80D0000]            	mov	eax, circlebuffer
   332 000001F3 A3[C40D0000]            	mov	[pixelpos], eax	
   333                                  _dc_ph0:
   334                                  	; quarter 1	
   335                                  	; start from y = 0, x = radius
   336 000001F8 31C0                    	xor	eax, eax
   337 000001FA A3[C0090000]            	mov	[_y1], eax ; 0
   338 000001FF A2[A6090000]            	mov	[phase], al ; 0
   339 00000204 8B2D[A8090000]          	mov	ebp, [radius]
   340 0000020A 892D[BC090000]          	mov	[_x1], ebp ; y = 0, x = r
   341 00000210 BE[C4090000]            	mov	esi, _fx
   342                                  _dc_ph0_n:
   343 00000215 FF0D[BC090000]          	dec	dword [_x1]
   344 0000021B AD                      	lodsd
   345                                  _dc_ph0_x:
   346 0000021C 8B15[C0090000]          	mov	edx, [_y1]
   347 00000222 42                      	inc	edx
   348 00000223 39C2                    	cmp	edx, eax
   349 00000225 7314                    	jnb	short _dc_ph0_y
   350 00000227 50                      	push	eax
   351 00000228 8915[C0090000]          	mov	[_y1], edx
   352 0000022E E862010000              	call	get_start_offset
   353 00000233 E83A010000              	call	write_pixel
   354 00000238 58                      	pop	eax
   355 00000239 EBE1                    	jmp	short _dc_ph0_x	
   356                                  _dc_ph0_y:
   357 0000023B A3[C0090000]            	mov	[_y1], eax
   358 00000240 E850010000              	call	get_start_offset
   359 00000245 E828010000              	call	write_pixel
   360 0000024A 4D                      	dec	ebp
   361 0000024B 75C8                    	jnz	short _dc_ph0_n
   362                                  _dc_ph1:
   363                                  	; quarter 2	
   364                                  	; start from y = radius, x = 0
   365 0000024D FE05[A6090000]          	inc	byte [phase]
   366 00000253 31C0                    	xor	eax, eax
   367 00000255 A3[BC090000]            	mov	[_x1], eax ; 0
   368 0000025A 8B2D[A8090000]          	mov	ebp, [radius]
   369 00000260 892D[C0090000]          	mov	[_y1], ebp ; y = r, x = 0
   370 00000266 BE[C4090000]            	mov	esi, _fx
   371                                  _dc_ph1_n:
   372 0000026B FF0D[C0090000]          	dec 	dword [_y1]
   373 00000271 AD                      	lodsd
   374                                  _dc_ph1_x:
   375 00000272 8B15[BC090000]          	mov	edx, [_x1]
   376 00000278 42                      	inc	edx
   377 00000279 39C2                    	cmp	edx, eax
   378 0000027B 7314                    	jnb	short _dc_ph1_y
   379 0000027D 50                      	push	eax
   380 0000027E 8915[BC090000]          	mov	[_x1], edx
   381 00000284 E80C010000              	call	get_start_offset
   382 00000289 E8E4000000              	call	write_pixel
   383 0000028E 58                      	pop	eax
   384 0000028F EBE1                    	jmp	short _dc_ph1_x	
   385                                  _dc_ph1_y:
   386 00000291 A3[BC090000]            	mov	[_x1], eax
   387 00000296 E8FA000000              	call	get_start_offset
   388 0000029B E8D2000000              	call	write_pixel
   389 000002A0 4D                      	dec	ebp
   390 000002A1 75C8                    	jnz	short _dc_ph1_n
   391                                  _dc_ph2:
   392                                  	; quarter 3	
   393                                  	; start from y = 0, x = radius
   394 000002A3 FE05[A6090000]          	inc	byte [phase]
   395 000002A9 31C0                    	xor	eax, eax
   396 000002AB A3[C0090000]            	mov	[_y1], eax ; 0
   397 000002B0 8B2D[A8090000]          	mov	ebp, [radius]
   398 000002B6 892D[BC090000]          	mov	[_x1], ebp ; y = 0, x = r
   399 000002BC BE[C4090000]            	mov	esi, _fx
   400                                  _dc_ph2_n:
   401 000002C1 FF0D[BC090000]          	dec	dword [_x1]
   402 000002C7 AD                      	lodsd
   403                                  _dc_ph2_x:
   404 000002C8 8B15[C0090000]          	mov	edx, [_y1]
   405 000002CE 42                      	inc	edx
   406 000002CF 39C2                    	cmp	edx, eax
   407 000002D1 7314                    	jnb	short _dc_ph2_y
   408 000002D3 50                      	push	eax
   409 000002D4 8915[C0090000]          	mov	[_y1], edx
   410 000002DA E8B6000000              	call	get_start_offset
   411 000002DF E88E000000              	call	write_pixel
   412 000002E4 58                      	pop	eax
   413 000002E5 EBE1                    	jmp	short _dc_ph2_x	
   414                                  _dc_ph2_y:
   415 000002E7 A3[C0090000]            	mov	[_y1], eax
   416 000002EC E8A4000000              	call	get_start_offset
   417 000002F1 E87C000000              	call	write_pixel
   418 000002F6 4D                      	dec	ebp
   419 000002F7 75C8                    	jnz	short _dc_ph2_n
   420                                  _dc_ph3:
   421                                  	; quarter 4	
   422                                  	; start from y = radius, x = 0
   423 000002F9 FE05[A6090000]          	inc	byte [phase]
   424 000002FF 31C0                    	xor	eax, eax
   425 00000301 A3[BC090000]            	mov	[_x1], eax ; 0
   426 00000306 8B2D[A8090000]          	mov	ebp, [radius]
   427 0000030C 892D[C0090000]          	mov	[_y1], ebp ; y = r, x = 0
   428 00000312 BE[C4090000]            	mov	esi, _fx
   429                                  _dc_ph3_n:
   430 00000317 FF0D[C0090000]          	dec	dword [_y1]
   431 0000031D AD                      	lodsd
   432                                  _dc_ph3_x:
   433 0000031E 8B15[BC090000]          	mov	edx, [_x1]
   434 00000324 42                      	inc	edx
   435 00000325 39C2                    	cmp	edx, eax
   436 00000327 7314                    	jnb	short _dc_ph3_y
   437 00000329 50                      	push	eax
   438 0000032A 8915[BC090000]          	mov	[_x1], edx
   439 00000330 E860000000              	call	get_start_offset
   440 00000335 E838000000              	call	write_pixel
   441 0000033A 58                      	pop	eax
   442 0000033B EBE1                    	jmp	short _dc_ph3_x	
   443                                  _dc_ph3_y:
   444 0000033D A3[BC090000]            	mov	[_x1], eax
   445 00000342 E84E000000              	call	get_start_offset
   446 00000347 E826000000              	call	write_pixel
   447 0000034C 4D                      	dec	ebp
   448 0000034D 75C8                    	jnz	short _dc_ph3_n
   449                                  _dc_ph4:
   450                                  write_circle:
   451 0000034F BE[C80D0000]            	mov	esi, circlebuffer
   452 00000354 8B15[C40D0000]          	mov	edx, [pixelpos]
   453 0000035A 29F2                    	sub	edx, esi
   454 0000035C C1EA02                  	shr	edx, 2 ; / 4
   455                                  	; edx = pixel count
   456                                  	; esi = user's single color pixel buffer address
   457                                  	sys	_video, 0305h, [color]
   457                              <1> 
   457                              <1> 
   457                              <1> 
   457                              <1> 
   457                              <1>  %if %0 >= 2
   457 0000035F BB05030000          <1>  mov ebx, %2
   457                              <1>  %if %0 >= 3
   457 00000364 8B0D[B0090000]      <1>  mov ecx, %3
   457                              <1>  %if %0 = 4
   457                              <1>  mov edx, %4
   457                              <1>  %endif
   457                              <1>  %endif
   457                              <1>  %endif
   457 0000036A B81F000000          <1>  mov eax, %1
   457                              <1> 
   457 0000036F CD40                <1>  int 40h
   458                                  
   459 00000371 C3                      	retn	
   460                                  
   461                                  write_pixel:
   462                                  	; eax = (screen) pixel position
   463 00000372 8B3D[C40D0000]          	mov	edi, [pixelpos] ; pointer
   464 00000378 AB                      	stosd
   465 00000379 893D[C40D0000]          	mov	[pixelpos], edi ; pointer
   466 0000037F C3                      	retn
   467                                  
   468                                  movecenter:
   469 00000380 C705[B4090000]A000-     	mov	dword [_x0], 320/2
   469 00000388 0000               
   470 0000038A C705[B8090000]6400-     	mov	dword [_y0], 200/2
   470 00000392 0000               
   471 00000394 C3                      	retn
   472                                  
   473                                  get_start_offset:
   474 00000395 B840010000              	mov	eax, 320
   475 0000039A 8B15[B8090000]          	mov	edx, [_y0]
   476 000003A0 803D[A6090000]00        	cmp	byte [phase], 0
   477 000003A7 7715                    	ja	short gso_1
   478                                  gso_0:
   479                                  	; quarter 1
   480 000003A9 2B15[C0090000]          	sub	edx, [_y1] ; y = 0 -> r
   481 000003AF F7E2                    	mul	edx
   482 000003B1 0305[B4090000]          	add	eax, [_x0]
   483 000003B7 0305[BC090000]          	add	eax, [_x1] ; x = r -> 0
   484 000003BD C3                      	retn
   485                                  gso_1:
   486 000003BE 803D[A6090000]01        	cmp	byte [phase], 1
   487 000003C5 7715                    	ja	short gso_2
   488                                  	; quarter 2
   489 000003C7 2B15[C0090000]          	sub	edx, [_y1] ; y = r -> 0
   490 000003CD F7E2                    	mul	edx
   491 000003CF 0305[B4090000]          	add	eax, [_x0]
   492 000003D5 2B05[BC090000]          	sub	eax, [_x1] ; x = 0 -> -r
   493 000003DB C3                      	retn
   494                                  gso_2:
   495 000003DC 803D[A6090000]02        	cmp	byte [phase], 2
   496 000003E3 7715                    	ja	short gso_3
   497                                  	; quarter 3
   498 000003E5 0315[C0090000]          	add	edx, [_y1] ; y = 0 -> -r 
   499 000003EB F7E2                    	mul	edx
   500 000003ED 0305[B4090000]          	add	eax, [_x0]
   501 000003F3 2B05[BC090000]          	sub	eax, [_x1] ; x = -r -> 0 
   502 000003F9 C3                      	retn
   503                                  gso_3:
   504                                  	; quarter 4
   505 000003FA 0315[C0090000]          	add	edx, [_y1] ; y = -r -> 0
   506 00000400 F7E2                    	mul	edx
   507 00000402 0305[B4090000]          	add	eax, [_x0]
   508 00000408 0305[BC090000]          	add	eax, [_x1] ; x = 0 -> r 
   509 0000040E C3                      	retn
   510                                  
   511                                  black_circle:
   512 0000040F 30E4                    	xor	ah, ah
   513 00000411 8625[B0090000]          	xchg	[color], ah ; color = 0 
   514 00000417 50                      	push	eax
   515 00000418 E8D1FDFFFF              	call	drawcircle
   516 0000041D 58                      	pop	eax
   517 0000041E 8625[B0090000]          	xchg	[color], ah ; restore color
   518 00000424 C3                      	retn
   519                                  
   520                                  beep:
   521                                  	; call beep function (16/64 second, 886Hz)
   522                                  	sys	_audio, 16, 1331
   522                              <1> 
   522                              <1> 
   522                              <1> 
   522                              <1> 
   522                              <1>  %if %0 >= 2
   522 00000425 BB10000000          <1>  mov ebx, %2
   522                              <1>  %if %0 >= 3
   522 0000042A B933050000          <1>  mov ecx, %3
   522                              <1>  %if %0 = 4
   522                              <1>  mov edx, %4
   522                              <1>  %endif
   522                              <1>  %endif
   522                              <1>  %endif
   522 0000042F B820000000          <1>  mov eax, %1
   522                              <1> 
   522 00000434 CD40                <1>  int 40h
   523 00000436 C3                      	retn
   524                                  
   525                                  get_squareroot:
   526                                  	; input: edx = square of the number (y)
   527                                  	; output: eax = approx. square root of ebx 
   528 00000437 BE[A4050000]            	mov	esi, _squares
   529 0000043C 53                      	push	ebx
   530 0000043D 31DB                    	xor	ebx, ebx
   531                                  	;mov	ecx, 256
   532 0000043F 8B0D[A8090000]          	mov	ecx, [radius] ; max. value of radius is 256
   533                                  q_sr_x:	
   534 00000445 AD                      	lodsd
   535 00000446 39D0                    	cmp	eax, edx
   536 00000448 7303                    	jnb	short q_sr_ok
   537 0000044A 43                      	inc	ebx
   538 0000044B E2F8                    	loop	q_sr_x
   539                                  q_sr_ok:
   540 0000044D 89D8                    	mov	eax, ebx
   541 0000044F 5B                      	pop	ebx
   542 00000450 C3                      	retn
   543                                  
   544                                  set_text_mode:
   545 00000451 30E4                    	xor    ah, ah
   546 00000453 B003                    	mov    al, 3                        
   547                                   	;int   10h ; al = 03h text mode, int 10 video
   548 00000455 CD31                    	int    31h ; TRDOS 386 - Video interrupt
   549 00000457 C3                      	retn
   550                                  		
   551                                  program_msg:
   552 00000458 5452444F5320333836-     	db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Circle"
   552 00000461 2076322E302E33202D-
   552 0000046A 202827737973766964-
   552 00000473 656F27292054657374-
   552 0000047C 2050726F6772616D20-
   552 00000485 2D2044726177204369-
   552 0000048E 72636C65           
   553 00000492 0D0A                    	db 0Dh, 0Ah
   554 00000494 6279204572646F6761-     	db "by Erdogan Tan - 15/02/2021"
   554 0000049D 6E2054616E202D2031-
   554 000004A6 352F30322F32303231 
   555                                  	;db 0Dh, 0Ah, 0
   556 000004AF 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
   557                                  
   558 000004B3 557365204172726F77-     	db "Use Arrow Keys, Home, End to move the CIRCLE .."
   558 000004BC 204B6579732C20486F-
   558 000004C5 6D652C20456E642074-
   558 000004CE 6F206D6F7665207468-
   558 000004D7 6520434952434C4520-
   558 000004E0 2E2E               
   559 000004E2 0D0A                    	db 0Dh, 0Ah
   560 000004E4 557365202B2C2D206B-     	db "Use +,- keys to increase and decrease DIAMETER .."		
   560 000004ED 65797320746F20696E-
   560 000004F6 63726561736520616E-
   560 000004FF 642064656372656173-
   560 00000508 65204449414D455445-
   560 00000511 52202E2E           
   561 00000515 0D0A                    	db 0Dh, 0Ah
   562 00000517 55736520454E544552-     	db "Use ENTER key to draw CIRCLE .."
   562 00000520 206B657920746F2064-
   562 00000529 72617720434952434C-
   562 00000532 45202E2E           
   563 00000536 0D0A                    	db 0Dh, 0Ah
   564 00000538 557365205350414345-     	db "Use SPACE, Pg Up, Pg Down keys to change COLOR .."
   564 00000541 2C2050672055702C20-
   564 0000054A 506720446F776E206B-
   564 00000553 65797320746F206368-
   564 0000055C 616E676520434F4C4F-
   564 00000565 52202E2E           
   565 00000569 0D0A                    	db 0Dh, 0Ah	
   566 0000056B 507265737320455343-     	db "Press ESC to exit .."
   566 00000574 20746F206578697420-
   566 0000057D 2E2E               
   567 0000057F 0D0A                    	db 0Dh, 0Ah
   568 00000581 0D0A                    	db 0Dh, 0Ah
   569 00000583 507265737320616E79-     	db "Press any key to continue .."
   569 0000058C 206B657920746F2063-
   569 00000595 6F6E74696E7565202E-
   569 0000059E 2E                 
   570                                  nextline:
   571 0000059F 0D0A00                  	db 0Dh, 0Ah, 0	
   572                                  
   573                                  bss:
   574                                  
   575                                  ABSOLUTE bss
   576                                  
   577 000005A2 <res 00000002>          alignb 4
   578                                  
   579                                  bss_start:
   580                                  _squares:
   581 000005A4 <res 00000400>          	resd 256 ; squares of numbers from 0 t0 255	
   582                                  counter:
   583 000009A4 <res 00000002>          	resw 1
   584 000009A6 <res 00000002>          phase:	resw 1
   585 000009A8 <res 00000004>          radius:	resd 1 ; Current Radius value
   586 000009AC <res 00000004>          _r2:	resd 1 ; Square of R
   587 000009B0 <res 00000004>          color:	resd 1
   588 000009B4 <res 00000004>          _x0:	resd 1
   589 000009B8 <res 00000004>          _y0:	resd 1
   590 000009BC <res 00000004>          _x1:	resd 1
   591 000009C0 <res 00000004>          _y1:	resd 1
   592 000009C4 <res 00000400>          _fx:	resd 256 ; For every X values from 0 to 255
   593                                  pixelpos:
   594 00000DC4 <res 00000004>          	resd 1
   595                                  circlebuffer:
   596 00000DC8 <res 00009C40>          	resd 10000 ; 100*100*4 bytes
   597                                  
   598                                  bss_end:
