     1                                  ; ****************************************************************************
     2                                  ; circle5.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; 15/02/2021
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  ; nasm circle5.s -l circle5.txt -o CIRCLE5.PRG -Z error.txt
     9                                  ; (modified from 'circle4.s', 15/02/2021)
    10                                  
    11                                  ; Draw circle by using 'sysvideo' bx=0306h
    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[DC050000]            	mov	edi, bss_start
    92 00000005 B929500000              	mov	ecx, (bss_end - bss_start)/4
    93                                  	;xor	eax, eax
    94 0000000A F3AB                    	rep	stosd
    95                                  
    96                                  	; program message
    97 0000000C BE[92040000]            	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[DC050000]            	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[E8090000]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[E0090000]            	mov	[radius], eax
   135 00000048 89C3                    	mov	ebx, eax
   136 0000004A F7E3                    	mul	ebx
   137 0000004C A3[E4090000]            	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[FC090000]            	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[E4090000]          	mov	edx, [_r2]
   148 00000063 29C2                    	sub	edx, eax
   149 00000065 E8ED030000              	call	get_squareroot
   150 0000006A AB                      	stosd
   151 0000006B EBE9                    	jmp	short _yy_x
   152                                  
   153                                  	; ***
   154                                  
   155                                  terminate:
   156 0000006D E819040000              	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 E814030000              	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[DC090000]        	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[E0090000]            	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 E86C030000              	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[E0090000]            	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 E857030000              	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[E8090000]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[E0090000]            	mov	eax, [radius]
   227 000000E9 3B05[EC090000]          	cmp	eax, [_x0]
   228 000000EF 730D                    	jnb	short _3_
   229 000000F1 E82D030000              	call	black_circle ; clear current position 
   230 000000F6 FF0D[EC090000]          	dec	dword [_x0]
   231 000000FC EB82                    	jmp	_0 ; draw 
   232                                  _3_:
   233 000000FE E842030000              	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[E0090000]            	mov	eax, [radius]
   241 0000010F 0305[EC090000]          	add	eax, [_x0]
   242 00000115 3D3F010000              	cmp	eax, 319
   243 0000011A 73E2                    	jnb	short _3_
   244 0000011C E802030000              	call	black_circle ; clear current position 
   245 00000121 FF05[EC090000]          	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[E0090000]            	mov	eax, [radius]
   252 00000136 0305[F0090000]          	add	eax, [_y0]
   253 0000013C 3DC7000000              	cmp	eax, 199
   254 00000141 73BB                    	jnb	short _3_
   255 00000143 E8DB020000              	call	black_circle ; clear current position 
   256 00000148 FF05[F0090000]          	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[E0090000]            	mov	eax, [radius]
   263 0000015D 3B05[F0090000]          	cmp	eax, [_y0]
   264 00000163 7399                    	jnb	short _3_
   265 00000165 E8B9020000              	call	black_circle ; clear current position 
   266 0000016A FF0D[F0090000]          	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 E8A4020000              	call	black_circle ; clear current position 
   272 0000017F E8C1020000              	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 E890020000              	call	black_circle ; clear current position 
   279 00000193 E8AD020000              	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[E8090000]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[E8090000]          	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[E8090000]          	inc	byte [color]
   302                                  _14:
   303 000001CE E872020000              	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[000E0000]            	mov	eax, circlebuffer
   332 000001F3 A3[FC0D0000]            	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[F8090000]            	mov	[_y1], eax ; 0
   338 000001FF A2[DF090000]            	mov	[phase], al ; 0
   339 00000204 8B2D[E0090000]          	mov	ebp, [radius]
   340 0000020A 892D[F4090000]          	mov	[_x1], ebp ; y = 0, x = r
   341 00000210 BE[FC090000]            	mov	esi, _fx
   342                                  _dc_ph0_n:
   343 00000215 FF0D[F4090000]          	dec	dword [_x1]
   344 0000021B AD                      	lodsd
   345                                  _dc_ph0_x:
   346 0000021C 8B15[F8090000]          	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[F8090000]          	mov	[_y1], edx
   352 0000022E E876010000              	call	get_start_offset
   353 00000233 E848010000              	call	write_pixel
   354 00000238 58                      	pop	eax
   355 00000239 EBE1                    	jmp	short _dc_ph0_x	
   356                                  _dc_ph0_y:
   357 0000023B A3[F8090000]            	mov	[_y1], eax
   358 00000240 E864010000              	call	get_start_offset
   359 00000245 E836010000              	call	write_pixel
   360 0000024A E822020000              	call	color_change
   361 0000024F 4D                      	dec	ebp
   362 00000250 75C3                    	jnz	short _dc_ph0_n
   363                                  _dc_ph1:
   364                                  	; quarter 2	
   365                                  	; start from y = radius, x = 0
   366 00000252 FE05[DF090000]          	inc	byte [phase]
   367 00000258 31C0                    	xor	eax, eax
   368 0000025A A3[F4090000]            	mov	[_x1], eax ; 0
   369 0000025F 8B2D[E0090000]          	mov	ebp, [radius]
   370 00000265 892D[F8090000]          	mov	[_y1], ebp ; y = r, x = 0
   371 0000026B BE[FC090000]            	mov	esi, _fx
   372                                  _dc_ph1_n:
   373 00000270 FF0D[F8090000]          	dec 	dword [_y1]
   374 00000276 AD                      	lodsd
   375                                  _dc_ph1_x:
   376 00000277 8B15[F4090000]          	mov	edx, [_x1]
   377 0000027D 42                      	inc	edx
   378 0000027E 39C2                    	cmp	edx, eax
   379 00000280 7314                    	jnb	short _dc_ph1_y
   380 00000282 50                      	push	eax
   381 00000283 8915[F4090000]          	mov	[_x1], edx
   382 00000289 E81B010000              	call	get_start_offset
   383 0000028E E8ED000000              	call	write_pixel
   384 00000293 58                      	pop	eax
   385 00000294 EBE1                    	jmp	short _dc_ph1_x	
   386                                  _dc_ph1_y:
   387 00000296 A3[F4090000]            	mov	[_x1], eax
   388 0000029B E809010000              	call	get_start_offset
   389 000002A0 E8DB000000              	call	write_pixel
   390 000002A5 E8C7010000              	call	color_change
   391 000002AA 4D                      	dec	ebp
   392 000002AB 75C3                    	jnz	short _dc_ph1_n
   393                                  _dc_ph2:
   394                                  	; quarter 3	
   395                                  	; start from y = 0, x = radius
   396 000002AD FE05[DF090000]          	inc	byte [phase]
   397 000002B3 31C0                    	xor	eax, eax
   398 000002B5 A3[F8090000]            	mov	[_y1], eax ; 0
   399 000002BA 8B2D[E0090000]          	mov	ebp, [radius]
   400 000002C0 892D[F4090000]          	mov	[_x1], ebp ; y = 0, x = r
   401 000002C6 BE[FC090000]            	mov	esi, _fx
   402                                  _dc_ph2_n:
   403 000002CB FF0D[F4090000]          	dec	dword [_x1]
   404 000002D1 AD                      	lodsd
   405                                  _dc_ph2_x:
   406 000002D2 8B15[F8090000]          	mov	edx, [_y1]
   407 000002D8 42                      	inc	edx
   408 000002D9 39C2                    	cmp	edx, eax
   409 000002DB 7314                    	jnb	short _dc_ph2_y
   410 000002DD 50                      	push	eax
   411 000002DE 8915[F8090000]          	mov	[_y1], edx
   412 000002E4 E8C0000000              	call	get_start_offset
   413 000002E9 E892000000              	call	write_pixel
   414 000002EE 58                      	pop	eax
   415 000002EF EBE1                    	jmp	short _dc_ph2_x	
   416                                  _dc_ph2_y:
   417 000002F1 A3[F8090000]            	mov	[_y1], eax
   418 000002F6 E8AE000000              	call	get_start_offset
   419 000002FB E880000000              	call	write_pixel
   420 00000300 E86C010000              	call	color_change
   421 00000305 4D                      	dec	ebp
   422 00000306 75C3                    	jnz	short _dc_ph2_n
   423                                  _dc_ph3:
   424                                  	; quarter 4	
   425                                  	; start from y = radius, x = 0
   426 00000308 FE05[DF090000]          	inc	byte [phase]
   427 0000030E 31C0                    	xor	eax, eax
   428 00000310 A3[F4090000]            	mov	[_x1], eax ; 0
   429 00000315 8B2D[E0090000]          	mov	ebp, [radius]
   430 0000031B 892D[F8090000]          	mov	[_y1], ebp ; y = r, x = 0
   431 00000321 BE[FC090000]            	mov	esi, _fx
   432                                  _dc_ph3_n:
   433 00000326 FF0D[F8090000]          	dec	dword [_y1]
   434 0000032C AD                      	lodsd
   435                                  _dc_ph3_x:
   436 0000032D 8B15[F4090000]          	mov	edx, [_x1]
   437 00000333 42                      	inc	edx
   438 00000334 39C2                    	cmp	edx, eax
   439 00000336 7314                    	jnb	short _dc_ph3_y
   440 00000338 50                      	push	eax
   441 00000339 8915[F4090000]          	mov	[_x1], edx
   442 0000033F E865000000              	call	get_start_offset
   443 00000344 E837000000              	call	write_pixel
   444 00000349 58                      	pop	eax
   445 0000034A EBE1                    	jmp	short _dc_ph3_x	
   446                                  _dc_ph3_y:
   447 0000034C A3[F4090000]            	mov	[_x1], eax
   448 00000351 E853000000              	call	get_start_offset
   449 00000356 E825000000              	call	write_pixel
   450 0000035B E811010000              	call	color_change
   451 00000360 4D                      	dec	ebp
   452 00000361 75C3                    	jnz	short _dc_ph3_n
   453                                  _dc_ph4:
   454                                  write_circle:
   455 00000363 BE[000E0000]            	mov	esi, circlebuffer
   456 00000368 8B15[FC0D0000]          	mov	edx, [pixelpos]
   457 0000036E 29F2                    	sub	edx, esi
   458 00000370 C1EA03                  	shr	edx, 3 ; / 8
   459                                  	; edx = pixel count
   460                                  	; esi = user's multi colors pixel buffer address
   461                                  	sys	_video, 0306h
   461                              <1> 
   461                              <1> 
   461                              <1> 
   461                              <1> 
   461                              <1>  %if %0 >= 2
   461 00000373 BB06030000          <1>  mov ebx, %2
   461                              <1>  %if %0 >= 3
   461                              <1>  mov ecx, %3
   461                              <1>  %if %0 = 4
   461                              <1>  mov edx, %4
   461                              <1>  %endif
   461                              <1>  %endif
   461                              <1>  %endif
   461 00000378 B81F000000          <1>  mov eax, %1
   461                              <1> 
   461 0000037D CD40                <1>  int 40h
   462                                  
   463 0000037F C3                      	retn	
   464                                  
   465                                  write_pixel:
   466                                  	; eax = (screen) pixel position
   467 00000380 8B3D[FC0D0000]          	mov	edi, [pixelpos] ; pointer
   468 00000386 AB                      	stosd
   469 00000387 A1[E8090000]            	mov	eax, [color]
   470 0000038C AB                      	stosd	; color
   471 0000038D 893D[FC0D0000]          	mov	[pixelpos], edi ; pointer
   472 00000393 C3                      	retn
   473                                  
   474                                  movecenter:
   475 00000394 C705[EC090000]A000-     	mov	dword [_x0], 320/2
   475 0000039C 0000               
   476 0000039E C705[F0090000]6400-     	mov	dword [_y0], 200/2
   476 000003A6 0000               
   477 000003A8 C3                      	retn
   478                                  
   479                                  get_start_offset:
   480 000003A9 B840010000              	mov	eax, 320
   481 000003AE 8B15[F0090000]          	mov	edx, [_y0]
   482 000003B4 803D[DF090000]00        	cmp	byte [phase], 0
   483 000003BB 7715                    	ja	short gso_1
   484                                  gso_0:
   485                                  	; quarter 1
   486 000003BD 2B15[F8090000]          	sub	edx, [_y1] ; y = 0 -> r
   487 000003C3 F7E2                    	mul	edx
   488 000003C5 0305[EC090000]          	add	eax, [_x0]
   489 000003CB 0305[F4090000]          	add	eax, [_x1] ; x = r -> 0
   490 000003D1 C3                      	retn
   491                                  gso_1:
   492 000003D2 803D[DF090000]01        	cmp	byte [phase], 1
   493 000003D9 7715                    	ja	short gso_2
   494                                  	; quarter 2
   495 000003DB 2B15[F8090000]          	sub	edx, [_y1] ; y = r -> 0
   496 000003E1 F7E2                    	mul	edx
   497 000003E3 0305[EC090000]          	add	eax, [_x0]
   498 000003E9 2B05[F4090000]          	sub	eax, [_x1] ; x = 0 -> -r
   499 000003EF C3                      	retn
   500                                  gso_2:
   501 000003F0 803D[DF090000]02        	cmp	byte [phase], 2
   502 000003F7 7715                    	ja	short gso_3
   503                                  	; quarter 3
   504 000003F9 0315[F8090000]          	add	edx, [_y1] ; y = 0 -> -r 
   505 000003FF F7E2                    	mul	edx
   506 00000401 0305[EC090000]          	add	eax, [_x0]
   507 00000407 2B05[F4090000]          	sub	eax, [_x1] ; x = -r -> 0 
   508 0000040D C3                      	retn
   509                                  gso_3:
   510                                  	; quarter 4
   511 0000040E 0315[F8090000]          	add	edx, [_y1] ; y = -r -> 0
   512 00000414 F7E2                    	mul	edx
   513 00000416 0305[EC090000]          	add	eax, [_x0]
   514 0000041C 0305[F4090000]          	add	eax, [_x1] ; x = 0 -> r 
   515 00000422 C3                      	retn
   516                                  
   517                                  black_circle:
   518 00000423 30E4                    	xor	ah, ah
   519 00000425 8625[E8090000]          	xchg	[color], ah ; color = 0 
   520 0000042B FE05[DE090000]          	inc	byte [blank] ; black circle
   521                                  			; (no color change)     	
   522 00000431 50                      	push	eax
   523 00000432 E8B7FDFFFF              	call	drawcircle
   524 00000437 58                      	pop	eax
   525 00000438 8625[E8090000]          	xchg	[color], ah ; restore color
   526 0000043E 8825[DE090000]          	mov	[blank], ah ; 0
   527 00000444 C3                      	retn
   528                                  
   529                                  beep:
   530                                  	; call beep function (16/64 second, 886Hz)
   531                                  	sys	_audio, 16, 1331
   531                              <1> 
   531                              <1> 
   531                              <1> 
   531                              <1> 
   531                              <1>  %if %0 >= 2
   531 00000445 BB10000000          <1>  mov ebx, %2
   531                              <1>  %if %0 >= 3
   531 0000044A B933050000          <1>  mov ecx, %3
   531                              <1>  %if %0 = 4
   531                              <1>  mov edx, %4
   531                              <1>  %endif
   531                              <1>  %endif
   531                              <1>  %endif
   531 0000044F B820000000          <1>  mov eax, %1
   531                              <1> 
   531 00000454 CD40                <1>  int 40h
   532 00000456 C3                      	retn
   533                                  
   534                                  get_squareroot:
   535                                  	; input: edx = square of the number (y)
   536                                  	; output: eax = approx. square root of ebx 
   537 00000457 BE[DC050000]            	mov	esi, _squares
   538 0000045C 53                      	push	ebx
   539 0000045D 31DB                    	xor	ebx, ebx
   540                                  	;mov	ecx, 256
   541 0000045F 8B0D[E0090000]          	mov	ecx, [radius] ; max. value of radius is 256
   542                                  q_sr_x:	
   543 00000465 AD                      	lodsd
   544 00000466 39D0                    	cmp	eax, edx
   545 00000468 7303                    	jnb	short q_sr_ok
   546 0000046A 43                      	inc	ebx
   547 0000046B E2F8                    	loop	q_sr_x
   548                                  q_sr_ok:
   549 0000046D 89D8                    	mov	eax, ebx
   550 0000046F 5B                      	pop	ebx
   551 00000470 C3                      	retn
   552                                  
   553                                  color_change:
   554 00000471 803D[DE090000]01        	cmp	byte [blank], 1
   555 00000478 7310                    	jnb	short chgc_2
   556 0000047A A0[E8090000]            	mov	al, [color]
   557 0000047F FEC0                    	inc	al
   558 00000481 7502                    	jnz	short chgc_1
   559 00000483 FEC0                    	inc	al
   560                                  chgc_1:
   561 00000485 A2[E8090000]            	mov	[color], al
   562                                  chgc_2:
   563 0000048A C3                      	retn
   564                                  
   565                                  set_text_mode:
   566 0000048B 30E4                    	xor    ah, ah
   567 0000048D B003                    	mov    al, 3                        
   568                                   	;int   10h ; al = 03h text mode, int 10 video
   569 0000048F CD31                    	int    31h ; TRDOS 386 - Video interrupt
   570 00000491 C3                      	retn
   571                                  		
   572                                  program_msg:
   573 00000492 5452444F5320333836-     	db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Circle"
   573 0000049B 2076322E302E33202D-
   573 000004A4 202827737973766964-
   573 000004AD 656F27292054657374-
   573 000004B6 2050726F6772616D20-
   573 000004BF 2D2044726177204369-
   573 000004C8 72636C65           
   574 000004CC 0D0A                    	db 0Dh, 0Ah
   575 000004CE 6279204572646F6761-     	db "by Erdogan Tan - 15/02/2021"
   575 000004D7 6E2054616E202D2031-
   575 000004E0 352F30322F32303231 
   576                                  	;db 0Dh, 0Ah, 0
   577 000004E9 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
   578                                  
   579 000004ED 557365204172726F77-     	db "Use Arrow Keys, Home, End to move the CIRCLE .."
   579 000004F6 204B6579732C20486F-
   579 000004FF 6D652C20456E642074-
   579 00000508 6F206D6F7665207468-
   579 00000511 6520434952434C4520-
   579 0000051A 2E2E               
   580 0000051C 0D0A                    	db 0Dh, 0Ah
   581 0000051E 557365202B2C2D206B-     	db "Use +,- keys to increase and decrease DIAMETER .."		
   581 00000527 65797320746F20696E-
   581 00000530 63726561736520616E-
   581 00000539 642064656372656173-
   581 00000542 65204449414D455445-
   581 0000054B 52202E2E           
   582 0000054F 0D0A                    	db 0Dh, 0Ah
   583 00000551 55736520454E544552-     	db "Use ENTER key to draw CIRCLE .."
   583 0000055A 206B657920746F2064-
   583 00000563 72617720434952434C-
   583 0000056C 45202E2E           
   584 00000570 0D0A                    	db 0Dh, 0Ah
   585 00000572 557365205350414345-     	db "Use SPACE, Pg Up, Pg Down keys to change COLOR .."
   585 0000057B 2C2050672055702C20-
   585 00000584 506720446F776E206B-
   585 0000058D 65797320746F206368-
   585 00000596 616E676520434F4C4F-
   585 0000059F 52202E2E           
   586 000005A3 0D0A                    	db 0Dh, 0Ah	
   587 000005A5 507265737320455343-     	db "Press ESC to exit .."
   587 000005AE 20746F206578697420-
   587 000005B7 2E2E               
   588 000005B9 0D0A                    	db 0Dh, 0Ah
   589 000005BB 0D0A                    	db 0Dh, 0Ah
   590 000005BD 507265737320616E79-     	db "Press any key to continue .."
   590 000005C6 206B657920746F2063-
   590 000005CF 6F6E74696E7565202E-
   590 000005D8 2E                 
   591                                  nextline:
   592 000005D9 0D0A00                  	db 0Dh, 0Ah, 0	
   593                                  
   594                                  bss:
   595                                  
   596                                  ABSOLUTE bss
   597                                  
   598                                  alignb 4
   599                                  
   600                                  bss_start:
   601                                  _squares:
   602 000005DC <res 00000400>          	resd 256 ; squares of numbers from 0 t0 255	
   603                                  counter:
   604 000009DC <res 00000002>          	resw 1
   605 000009DE <res 00000001>          blank:	resb 1
   606 000009DF <res 00000001>          phase:	resb 1
   607 000009E0 <res 00000004>          radius:	resd 1 ; Current Radius value
   608 000009E4 <res 00000004>          _r2:	resd 1 ; Square of R
   609 000009E8 <res 00000004>          color:	resd 1
   610 000009EC <res 00000004>          _x0:	resd 1
   611 000009F0 <res 00000004>          _y0:	resd 1
   612 000009F4 <res 00000004>          _x1:	resd 1
   613 000009F8 <res 00000004>          _y1:	resd 1
   614 000009FC <res 00000400>          _fx:	resd 256 ; For every X values from 0 to 255
   615                                  pixelpos:
   616 00000DFC <res 00000004>          	resd 1
   617                                  circlebuffer:
   618 00000E00 <res 00013880>          	resd 2*10000 ; 100*100*8 bytes
   619                                  
   620                                  bss_end:
