     1                                  ; ****************************************************************************
     2                                  ; circle6.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; 16/02/2021 (15/02/2021)
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  ; nasm circle6.s -l circle6.txt -o CIRCLE6.PRG -Z error.txt
     9                                  ; (modified from 'circle4.s', 15/02/2021)
    10                                  
    11                                  ; Draw circle by using 'sysvideo' bx=0305h
    12                                  ; and show diameter and origin by using bx=010Fh
    13                                  
    14                                  ; 14/07/2020
    15                                  ; 31/12/2017
    16                                  ; TRDOS 386 (v2.0) system calls
    17                                  _ver 	equ 0
    18                                  _exit 	equ 1
    19                                  _fork 	equ 2
    20                                  _read 	equ 3
    21                                  _write	equ 4
    22                                  _open	equ 5
    23                                  _close 	equ 6
    24                                  _wait 	equ 7
    25                                  _create	equ 8
    26                                  _rename	equ 9
    27                                  _delete	equ 10
    28                                  _exec	equ 11
    29                                  _chdir	equ 12
    30                                  _time 	equ 13
    31                                  _mkdir 	equ 14
    32                                  _chmod	equ 15
    33                                  _rmdir	equ 16
    34                                  _break	equ 17
    35                                  _drive	equ 18
    36                                  _seek	equ 19
    37                                  _tell 	equ 20
    38                                  _memory	equ 21
    39                                  _prompt	equ 22
    40                                  _path	equ 23
    41                                  _env	equ 24
    42                                  _stime	equ 25
    43                                  _quit	equ 26	
    44                                  _intr	equ 27
    45                                  _dir	equ 28
    46                                  _emt 	equ 29
    47                                  _ldrvt 	equ 30
    48                                  _video 	equ 31
    49                                  _audio	equ 32
    50                                  _timer	equ 33
    51                                  _sleep	equ 34
    52                                  _msg    equ 35
    53                                  _geterr	equ 36
    54                                  _fpstat	equ 37
    55                                  _pri	equ 38
    56                                  _rele	equ 39
    57                                  _fff	equ 40
    58                                  _fnf	equ 41
    59                                  _alloc	equ 42
    60                                  _dalloc equ 43
    61                                  _calbac equ 44
    62                                  _dma	equ 45	
    63                                  
    64                                  %macro sys 1-4
    65                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    66                                      ; 03/09/2015	
    67                                      ; 13/04/2015
    68                                      ; Retro UNIX 386 v1 system call.		
    69                                      %if %0 >= 2   
    70                                          mov ebx, %2
    71                                          %if %0 >= 3    
    72                                              mov ecx, %3
    73                                              %if %0 = 4
    74                                                 mov edx, %4   
    75                                              %endif
    76                                          %endif
    77                                      %endif
    78                                      mov eax, %1
    79                                      ;int 30h
    80                                      int 40h ; TRDOS 386 (TRDOS v2.0)		   
    81                                  %endmacro
    82                                  
    83                                  ; Retro UNIX 386 v1 system call format:
    84                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    85                                  
    86                                  [BITS 32] ; We need 32-bit intructions for protected mode
    87                                  
    88                                  [ORG 0] 
    89                                  
    90                                  START_CODE:
    91                                  	; clear bss
    92 00000000 BF[80070000]            	mov	edi, bss_start
    93 00000005 B91C290000              	mov	ecx, (bss_end - bss_start)/4
    94                                  	;xor	eax, eax
    95 0000000A F3AB                    	rep	stosd
    96                                  
    97                                  	; program message
    98 0000000C BE[33060000]            	mov	esi, program_msg
    99 00000011 E8F4010000              	call	print_msg
   100                                  
   101 00000016 30E4                    	xor	ah, ah
   102                                  	;int	16h	; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
   103                                  			; Return: AH = scan code, AL = character
   104 00000018 CD32                    	int	32h	; TRDOS 386 Keyboard interrupt 
   105                                  
   106                                  	;; Set Video Mode to 13h
   107                                  	;sys	_video, 0813h
   108                                  	;cmp	eax, 14h 
   109                                  	;je	short mode_13h_set_ok
   110                                  
   111                                  	; set VGA mode by using int 31h
   112 0000001A 66B81300                	mov	ax, 13h	; mode 13h ; 
   113 0000001E CD31                    	int	31h	; real mode: int 10h
   114                                  	;jmp	short mode_13h_set_ok
   115                                  
   116                                  mode_13h_set_ok:
   117                                  	; Set squares of number from 0 to 255
   118 00000020 BF[80070000]            	mov	edi, _squares
   119 00000025 B9FF000000              	mov	ecx, 255
   120 0000002A BB01000000              	mov	ebx, 1
   121                                  _ss_x:
   122 0000002F 89D8                    	mov	eax, ebx
   123 00000031 F7E3                    	mul	ebx
   124 00000033 AB                      	stosd
   125 00000034 43                      	inc	ebx
   126 00000035 E2F8                    	loop	_ss_x
   127                                  
   128 00000037 C605[8E0B0000]8C        	mov	byte [tcolor], 140
   129                                  
   130 0000003E C605[800B0000]C8        	mov	byte [prevd], 200
   131 00000045 C605[840B0000]A0        	mov	byte [prevx], 320/2 
   132 0000004C C605[880B0000]64        	mov	byte [prevy], 200/2
   133                                  
   134                                  	;mov	esi, circle_parameters
   135                                  	;call	print_msg
   136                                  reset_color:
   137 00000053 C605[980B0000]8E        	mov	byte [color], 142 ; initial color
   138                                  reset_diameter:
   139 0000005A B864000000              	mov	eax, 100 ; initial diameter 
   140                                  newdiameter:	
   141                                  	; Set radius to 100
   142                                  	;mov	dword [radius], 100
   143                                  	;mov	dword [_r2], 10000
   144 0000005F A3[900B0000]            	mov	[radius], eax
   145 00000064 89C3                    	mov	ebx, eax
   146 00000066 F7E3                    	mul	ebx
   147 00000068 A3[940B0000]            	mov	[_r2], eax ; square of circle radius
   148                                  	; x2+y2 = r2	
   149                                  	; Set Y values for X values from 1 to Radius - 1
   150 0000006D BF[AC0B0000]            	mov	edi, _fx
   151                                  _yy_x:	
   152 00000072 4B                      	dec	ebx
   153 00000073 7422                    	jz	short center
   154 00000075 89D8                    	mov	eax, ebx
   155 00000077 F7E0                    	mul	eax
   156                                  	; eax = square of ebx
   157 00000079 8B15[940B0000]          	mov	edx, [_r2]
   158 0000007F 29C2                    	sub	edx, eax
   159 00000081 E8E8030000              	call	get_squareroot
   160 00000086 AB                      	stosd
   161 00000087 EBE9                    	jmp	short _yy_x
   162                                  
   163                                  	; ***
   164                                  
   165                                  terminate:
   166 00000089 E8FA030000              	call	set_text_mode
   167                                  	sys	_exit
   167                              <1> 
   167                              <1> 
   167                              <1> 
   167                              <1> 
   167                              <1>  %if %0 >= 2
   167                              <1>  mov ebx, %2
   167                              <1>  %if %0 >= 3
   167                              <1>  mov ecx, %3
   167                              <1>  %if %0 = 4
   167                              <1>  mov edx, %4
   167                              <1>  %endif
   167                              <1>  %endif
   167                              <1>  %endif
   167 0000008E B801000000          <1>  mov eax, %1
   167                              <1> 
   167 00000093 CD40                <1>  int 40h
   168                                  halt:
   169 00000095 EBFE                    	jmp	short halt
   170                                  
   171                                  	; ***
   172                                  
   173                                  	; move circle to center of screen
   174                                  center:
   175 00000097 E81B030000              	call	movecenter
   176                                  _0:
   177 0000009C E87A010000              	call	drawcircle
   178                                  waitforkey:
   179 000000A1 B401                    	mov	ah, 1
   180 000000A3 CD32                    	int	32h
   181 000000A5 740B                    	jz	short getkey
   182 000000A7 FE05[8C0B0000]          	inc	byte [counter]
   183 000000AD 90                      	nop
   184 000000AE 90                      	nop
   185 000000AF 90                      	nop
   186 000000B0 EBEF                    	jmp	short waitforkey
   187                                  getkey:
   188 000000B2 30E4                    	xor	ah, ah
   189 000000B4 CD32                    	int	32h
   190                                  
   191 000000B6 663D032E                	cmp	ax, 2E03h
   192 000000BA 74CD                    	je	short terminate
   193 000000BC 3C1B                    	cmp	al, 1Bh ; ESC key
   194 000000BE 74C9                    	je	short terminate	
   195                                  
   196 000000C0 3C2B                    	cmp	al, '+'
   197 000000C2 7511                    	jne	short _1
   198                                  	
   199 000000C4 A1[900B0000]            	mov	eax, [radius]
   200                                  
   201 000000C9 3C63                    	cmp	al, 99
   202 000000CB 734C                    	jnb	short _3_  ; beep
   203                                  	
   204                                  	; delete circle by drawing black circle
   205                                  	; with same diameter and at same coordinate
   206 000000CD E874030000              	call	black_circle
   207                                  	; increase radius of the circle
   208 000000D2 40                      	inc	eax	
   209                                  	;mov	[radius], eax
   210 000000D3 EB8A                    	jmp	newdiameter ; draw with new diameter
   211                                  _1:
   212 000000D5 3C2D                    	cmp	al, '-'
   213 000000D7 7514                    	jne	short _2
   214                                  
   215 000000D9 A1[900B0000]            	mov	eax, [radius]
   216                                  
   217 000000DE 3C01                    	cmp	al, 1
   218 000000E0 7637                    	jna	short _3_ ; beep
   219                                  	
   220                                  	; delete circle by drawing black circle
   221                                  	; with same diameter and at same coordinate
   222 000000E2 E85F030000              	call	black_circle
   223                                  	; decrease radius of the circle
   224 000000E7 48                      	dec	eax	
   225                                  	;mov	[radius], eax
   226 000000E8 E972FFFFFF              	jmp	newdiameter ; draw with new diameter
   227                                  _2:
   228 000000ED 3C20                    	cmp	al, 20h  ; space
   229 000000EF 7509                    	jne	short _3
   230 000000F1 8005[980B0000]08        	add	byte [color], 8 	
   231 000000F8 EBA2                    	jmp	short _0
   232                                  _3:
   233 000000FA 80FC4B                  	cmp	ah, 4Bh
   234 000000FD 7521                    	jne	short _4
   235                                  	; left arrow
   236 000000FF A1[900B0000]            	mov	eax, [radius]
   237 00000104 3B05[9C0B0000]          	cmp	eax, [_x0]
   238 0000010A 730D                    	jnb	short _3_
   239 0000010C E835030000              	call	black_circle ; clear current position 
   240 00000111 FF0D[9C0B0000]          	dec	dword [_x0]
   241 00000117 EB83                    	jmp	_0 ; draw 
   242                                  _3_:
   243 00000119 E83E030000              	call	beep
   244 0000011E EB81                    	jmp	waitforkey
   245                                  _4:
   246 00000120 80FC4D                  	cmp	ah, 4Dh
   247 00000123 7522                    	jne	short _5
   248                                  
   249                                  	; right arrow
   250 00000125 A1[900B0000]            	mov	eax, [radius]
   251 0000012A 0305[9C0B0000]          	add	eax, [_x0]
   252 00000130 3D3F010000              	cmp	eax, 319
   253 00000135 73E2                    	jnb	short _3_
   254 00000137 E80A030000              	call	black_circle ; clear current position 
   255 0000013C FF05[9C0B0000]          	inc	dword [_x0]
   256 00000142 E955FFFFFF              	jmp	_0 ; draw 
   257                                  _5:
   258 00000147 80FC50                  	cmp	ah, 50h
   259 0000014A 7522                    	jne	short _6
   260                                  	; down arrow
   261 0000014C A1[900B0000]            	mov	eax, [radius]
   262 00000151 0305[A00B0000]          	add	eax, [_y0]
   263 00000157 3DC7000000              	cmp	eax, 199
   264 0000015C 73BB                    	jnb	short _3_
   265 0000015E E8E3020000              	call	black_circle ; clear current position 
   266 00000163 FF05[A00B0000]          	inc	dword [_y0]
   267 00000169 E92EFFFFFF              	jmp	_0 ; draw 
   268                                  _6:
   269 0000016E 80FC48                  	cmp	ah, 48h
   270 00000171 751D                    	jne	short _7
   271                                  	; up arrow
   272 00000173 A1[900B0000]            	mov	eax, [radius]
   273 00000178 3B05[A00B0000]          	cmp	eax, [_y0]
   274 0000017E 7399                    	jnb	short _3_
   275 00000180 E8C1020000              	call	black_circle ; clear current position 
   276 00000185 FF0D[A00B0000]          	dec	dword [_y0]
   277 0000018B E90CFFFFFF              	jmp	_0 ; draw 
   278                                  _7:
   279 00000190 80FC47                  	cmp	ah, 47h ; Home key
   280 00000193 750F                    	jne	short _8
   281 00000195 E8AC020000              	call	black_circle ; clear current position 
   282 0000019A E8BD020000              	call	beep
   283 0000019F E9B6FEFFFF              	jmp	reset_diameter
   284                                  		; reset diameter, move to center
   285                                  _8:
   286 000001A4 80FC4F                  	cmp	ah, 4Fh ; End key
   287 000001A7 750F                    	jne	short _9
   288 000001A9 E898020000              	call	black_circle ; clear current position 
   289 000001AE E8A9020000              	call	beep
   290 000001B3 E99BFEFFFF              	jmp	reset_color 
   291                                  		; reset color and diameter, move to center
   292                                  _9:	
   293 000001B8 663D0D1C                	cmp	ax, 1C0Dh
   294 000001BC 7509                    	jne	short _10
   295 000001BE 8005[980B0000]04        	add	byte [color], 4
   296 000001C5 EB34                    	jmp	short _14
   297                                  _10:	
   298 000001C7 80FC53                  	cmp	ah, 53h ; INSERT
   299 000001CA 7509                    	jne	short _11
   300 000001CC 8005[8E0B0000]04        	add	byte [tcolor], 4
   301 000001D3 EB26                    	jmp	short _14
   302                                  _11:
   303 000001D5 80FC52                  	cmp	ah, 52h  ; DEL
   304 000001D8 7509                    	jne	short _12
   305 000001DA 802D[8E0B0000]04        	sub	byte [tcolor], 4
   306 000001E1 EB18                    	jmp	short _14
   307                                  _12:
   308 000001E3 80FC49                  	cmp	ah, 49h  ; Page UP
   309 000001E6 7508                    	jne	short _13
   310 000001E8 FE0D[980B0000]          	dec	byte [color]
   311 000001EE EB0B                    	jmp	short _14
   312                                  _13:
   313 000001F0 80FC51                  	cmp	ah, 51h  ; Page Down
   314 000001F3 7510                    	jne	short _15
   315 000001F5 FE05[980B0000]          	inc	byte [color]
   316                                  _14:
   317 000001FB E85C020000              	call	beep
   318 00000200 E997FEFFFF              	jmp	_0
   319                                  _15:
   320 00000205 E997FEFFFF              	jmp	waitforkey
   321                                  
   322                                  print_msg:
   323 0000020A B40E                    	mov	ah, 0Eh
   324 0000020C BB07000000              	mov	ebx, 7
   325                                  	;mov	bl, 7 ; char attribute & color
   326                                  p_next_chr:
   327 00000211 AC                      	lodsb
   328 00000212 08C0                    	or	al, al
   329 00000214 7404                    	jz	short p_retn ; retn	
   330 00000216 CD31                    	int	31h
   331 00000218 EBF7                    	jmp	short p_next_chr
   332                                  p_retn:
   333 0000021A C3                      	retn
   334                                  
   335                                  drawcircle:
   336                                  	; INPUT:
   337                                  	;	[_x0]
   338                                  	;	[_y0]
   339                                  	;	[radius]
   340                                  	;	[color]
   341                                  	;
   342                                  	; Modified registers: esi, edi, eax, ecx, ebx, edx
   343                                  
   344                                  	; write circle parameters to left top corner
   345 0000021B E835030000              	call	print_diameter
   346 00000220 E86A020000              	call	print_origin
   347                                  
   348                                  	; set pixel pointer position to start of circle buffer
   349 00000225 B8[B00F0000]            	mov	eax, circlebuffer
   350 0000022A A3[AC0F0000]            	mov	[pixelpos], eax	
   351                                  _dc_ph0:
   352                                  	; quarter 1	
   353                                  	; start from y = 0, x = radius
   354 0000022F 31C0                    	xor	eax, eax
   355 00000231 A3[A80B0000]            	mov	[_y1], eax ; 0
   356 00000236 A2[8F0B0000]            	mov	[phase], al ; 0
   357 0000023B 8B2D[900B0000]          	mov	ebp, [radius]
   358 00000241 892D[A40B0000]          	mov	[_x1], ebp ; y = 0, x = r
   359 00000247 BE[AC0B0000]            	mov	esi, _fx
   360                                  _dc_ph0_n:
   361 0000024C FF0D[A40B0000]          	dec	dword [_x1]
   362 00000252 AD                      	lodsd
   363                                  _dc_ph0_x:
   364 00000253 8B15[A80B0000]          	mov	edx, [_y1]
   365 00000259 42                      	inc	edx
   366 0000025A 39C2                    	cmp	edx, eax
   367 0000025C 7314                    	jnb	short _dc_ph0_y
   368 0000025E 50                      	push	eax
   369 0000025F 8915[A80B0000]          	mov	[_y1], edx
   370 00000265 E862010000              	call	get_start_offset
   371 0000026A E83A010000              	call	write_pixel
   372 0000026F 58                      	pop	eax
   373 00000270 EBE1                    	jmp	short _dc_ph0_x	
   374                                  _dc_ph0_y:
   375 00000272 A3[A80B0000]            	mov	[_y1], eax
   376 00000277 E850010000              	call	get_start_offset
   377 0000027C E828010000              	call	write_pixel
   378 00000281 4D                      	dec	ebp
   379 00000282 75C8                    	jnz	short _dc_ph0_n
   380                                  _dc_ph1:
   381                                  	; quarter 2	
   382                                  	; start from y = radius, x = 0
   383 00000284 FE05[8F0B0000]          	inc	byte [phase]
   384 0000028A 31C0                    	xor	eax, eax
   385 0000028C A3[A40B0000]            	mov	[_x1], eax ; 0
   386 00000291 8B2D[900B0000]          	mov	ebp, [radius]
   387 00000297 892D[A80B0000]          	mov	[_y1], ebp ; y = r, x = 0
   388 0000029D BE[AC0B0000]            	mov	esi, _fx
   389                                  _dc_ph1_n:
   390 000002A2 FF0D[A80B0000]          	dec 	dword [_y1]
   391 000002A8 AD                      	lodsd
   392                                  _dc_ph1_x:
   393 000002A9 8B15[A40B0000]          	mov	edx, [_x1]
   394 000002AF 42                      	inc	edx
   395 000002B0 39C2                    	cmp	edx, eax
   396 000002B2 7314                    	jnb	short _dc_ph1_y
   397 000002B4 50                      	push	eax
   398 000002B5 8915[A40B0000]          	mov	[_x1], edx
   399 000002BB E80C010000              	call	get_start_offset
   400 000002C0 E8E4000000              	call	write_pixel
   401 000002C5 58                      	pop	eax
   402 000002C6 EBE1                    	jmp	short _dc_ph1_x	
   403                                  _dc_ph1_y:
   404 000002C8 A3[A40B0000]            	mov	[_x1], eax
   405 000002CD E8FA000000              	call	get_start_offset
   406 000002D2 E8D2000000              	call	write_pixel
   407 000002D7 4D                      	dec	ebp
   408 000002D8 75C8                    	jnz	short _dc_ph1_n
   409                                  _dc_ph2:
   410                                  	; quarter 3	
   411                                  	; start from y = 0, x = radius
   412 000002DA FE05[8F0B0000]          	inc	byte [phase]
   413 000002E0 31C0                    	xor	eax, eax
   414 000002E2 A3[A80B0000]            	mov	[_y1], eax ; 0
   415 000002E7 8B2D[900B0000]          	mov	ebp, [radius]
   416 000002ED 892D[A40B0000]          	mov	[_x1], ebp ; y = 0, x = r
   417 000002F3 BE[AC0B0000]            	mov	esi, _fx
   418                                  _dc_ph2_n:
   419 000002F8 FF0D[A40B0000]          	dec	dword [_x1]
   420 000002FE AD                      	lodsd
   421                                  _dc_ph2_x:
   422 000002FF 8B15[A80B0000]          	mov	edx, [_y1]
   423 00000305 42                      	inc	edx
   424 00000306 39C2                    	cmp	edx, eax
   425 00000308 7314                    	jnb	short _dc_ph2_y
   426 0000030A 50                      	push	eax
   427 0000030B 8915[A80B0000]          	mov	[_y1], edx
   428 00000311 E8B6000000              	call	get_start_offset
   429 00000316 E88E000000              	call	write_pixel
   430 0000031B 58                      	pop	eax
   431 0000031C EBE1                    	jmp	short _dc_ph2_x	
   432                                  _dc_ph2_y:
   433 0000031E A3[A80B0000]            	mov	[_y1], eax
   434 00000323 E8A4000000              	call	get_start_offset
   435 00000328 E87C000000              	call	write_pixel
   436 0000032D 4D                      	dec	ebp
   437 0000032E 75C8                    	jnz	short _dc_ph2_n
   438                                  _dc_ph3:
   439                                  	; quarter 4	
   440                                  	; start from y = radius, x = 0
   441 00000330 FE05[8F0B0000]          	inc	byte [phase]
   442 00000336 31C0                    	xor	eax, eax
   443 00000338 A3[A40B0000]            	mov	[_x1], eax ; 0
   444 0000033D 8B2D[900B0000]          	mov	ebp, [radius]
   445 00000343 892D[A80B0000]          	mov	[_y1], ebp ; y = r, x = 0
   446 00000349 BE[AC0B0000]            	mov	esi, _fx
   447                                  _dc_ph3_n:
   448 0000034E FF0D[A80B0000]          	dec	dword [_y1]
   449 00000354 AD                      	lodsd
   450                                  _dc_ph3_x:
   451 00000355 8B15[A40B0000]          	mov	edx, [_x1]
   452 0000035B 42                      	inc	edx
   453 0000035C 39C2                    	cmp	edx, eax
   454 0000035E 7314                    	jnb	short _dc_ph3_y
   455 00000360 50                      	push	eax
   456 00000361 8915[A40B0000]          	mov	[_x1], edx
   457 00000367 E860000000              	call	get_start_offset
   458 0000036C E838000000              	call	write_pixel
   459 00000371 58                      	pop	eax
   460 00000372 EBE1                    	jmp	short _dc_ph3_x	
   461                                  _dc_ph3_y:
   462 00000374 A3[A40B0000]            	mov	[_x1], eax
   463 00000379 E84E000000              	call	get_start_offset
   464 0000037E E826000000              	call	write_pixel
   465 00000383 4D                      	dec	ebp
   466 00000384 75C8                    	jnz	short _dc_ph3_n
   467                                  _dc_ph4:
   468                                  write_circle:
   469 00000386 BE[B00F0000]            	mov	esi, circlebuffer
   470 0000038B 8B15[AC0F0000]          	mov	edx, [pixelpos]
   471 00000391 29F2                    	sub	edx, esi
   472 00000393 C1EA02                  	shr	edx, 2 ; / 4
   473                                  	; edx = pixel count
   474                                  	; esi = user's single color pixel buffer address
   475                                  	sys	_video, 0305h, [color]
   475                              <1> 
   475                              <1> 
   475                              <1> 
   475                              <1> 
   475                              <1>  %if %0 >= 2
   475 00000396 BB05030000          <1>  mov ebx, %2
   475                              <1>  %if %0 >= 3
   475 0000039B 8B0D[980B0000]      <1>  mov ecx, %3
   475                              <1>  %if %0 = 4
   475                              <1>  mov edx, %4
   475                              <1>  %endif
   475                              <1>  %endif
   475                              <1>  %endif
   475 000003A1 B81F000000          <1>  mov eax, %1
   475                              <1> 
   475 000003A6 CD40                <1>  int 40h
   476                                  
   477 000003A8 C3                      	retn	
   478                                  
   479                                  write_pixel:
   480                                  	; eax = (screen) pixel position
   481 000003A9 8B3D[AC0F0000]          	mov	edi, [pixelpos] ; pointer
   482 000003AF AB                      	stosd
   483 000003B0 893D[AC0F0000]          	mov	[pixelpos], edi ; pointer
   484 000003B6 C3                      	retn
   485                                  
   486                                  movecenter:
   487 000003B7 C705[9C0B0000]A000-     	mov	dword [_x0], 320/2
   487 000003BF 0000               
   488 000003C1 C705[A00B0000]6400-     	mov	dword [_y0], 200/2
   488 000003C9 0000               
   489 000003CB C3                      	retn
   490                                  
   491                                  get_start_offset:
   492 000003CC B840010000              	mov	eax, 320
   493 000003D1 8B15[A00B0000]          	mov	edx, [_y0]
   494 000003D7 803D[8F0B0000]00        	cmp	byte [phase], 0
   495 000003DE 7715                    	ja	short gso_1
   496                                  gso_0:
   497                                  	; quarter 1
   498 000003E0 2B15[A80B0000]          	sub	edx, [_y1] ; y = 0 -> r
   499 000003E6 F7E2                    	mul	edx
   500 000003E8 0305[9C0B0000]          	add	eax, [_x0]
   501 000003EE 0305[A40B0000]          	add	eax, [_x1] ; x = r -> 0
   502 000003F4 C3                      	retn
   503                                  gso_1:
   504 000003F5 803D[8F0B0000]01        	cmp	byte [phase], 1
   505 000003FC 7715                    	ja	short gso_2
   506                                  	; quarter 2
   507 000003FE 2B15[A80B0000]          	sub	edx, [_y1] ; y = r -> 0
   508 00000404 F7E2                    	mul	edx
   509 00000406 0305[9C0B0000]          	add	eax, [_x0]
   510 0000040C 2B05[A40B0000]          	sub	eax, [_x1] ; x = 0 -> -r
   511 00000412 C3                      	retn
   512                                  gso_2:
   513 00000413 803D[8F0B0000]02        	cmp	byte [phase], 2
   514 0000041A 7715                    	ja	short gso_3
   515                                  	; quarter 3
   516 0000041C 0315[A80B0000]          	add	edx, [_y1] ; y = 0 -> -r 
   517 00000422 F7E2                    	mul	edx
   518 00000424 0305[9C0B0000]          	add	eax, [_x0]
   519 0000042A 2B05[A40B0000]          	sub	eax, [_x1] ; x = -r -> 0 
   520 00000430 C3                      	retn
   521                                  gso_3:
   522                                  	; quarter 4
   523 00000431 0315[A80B0000]          	add	edx, [_y1] ; y = -r -> 0
   524 00000437 F7E2                    	mul	edx
   525 00000439 0305[9C0B0000]          	add	eax, [_x0]
   526 0000043F 0305[A40B0000]          	add	eax, [_x1] ; x = 0 -> r 
   527 00000445 C3                      	retn
   528                                  
   529                                  black_circle:
   530 00000446 30E4                    	xor	ah, ah
   531 00000448 8625[980B0000]          	xchg	[color], ah ; color = 0 
   532 0000044E 50                      	push	eax
   533 0000044F E8C7FDFFFF              	call	drawcircle
   534 00000454 58                      	pop	eax
   535 00000455 8625[980B0000]          	xchg	[color], ah ; restore color
   536 0000045B C3                      	retn
   537                                  
   538                                  beep:
   539                                  	; call beep function (16/64 second, 886Hz)
   540                                  	sys	_audio, 16, 1331
   540                              <1> 
   540                              <1> 
   540                              <1> 
   540                              <1> 
   540                              <1>  %if %0 >= 2
   540 0000045C BB10000000          <1>  mov ebx, %2
   540                              <1>  %if %0 >= 3
   540 00000461 B933050000          <1>  mov ecx, %3
   540                              <1>  %if %0 = 4
   540                              <1>  mov edx, %4
   540                              <1>  %endif
   540                              <1>  %endif
   540                              <1>  %endif
   540 00000466 B820000000          <1>  mov eax, %1
   540                              <1> 
   540 0000046B CD40                <1>  int 40h
   541 0000046D C3                      	retn
   542                                  
   543                                  get_squareroot:
   544                                  	; input: edx = square of the number (y)
   545                                  	; output: eax = approx. square root of ebx 
   546 0000046E BE[80070000]            	mov	esi, _squares
   547 00000473 53                      	push	ebx
   548 00000474 31DB                    	xor	ebx, ebx
   549                                  	;mov	ecx, 256
   550 00000476 8B0D[900B0000]          	mov	ecx, [radius] ; max. value of radius is 256
   551                                  q_sr_x:	
   552 0000047C AD                      	lodsd
   553 0000047D 39D0                    	cmp	eax, edx
   554 0000047F 7303                    	jnb	short q_sr_ok
   555 00000481 43                      	inc	ebx
   556 00000482 E2F8                    	loop	q_sr_x
   557                                  q_sr_ok:
   558 00000484 89D8                    	mov	eax, ebx
   559 00000486 5B                      	pop	ebx
   560 00000487 C3                      	retn
   561                                  
   562                                  set_text_mode:
   563 00000488 30E4                    	xor    ah, ah
   564 0000048A B003                    	mov    al, 3                        
   565                                   	;int   10h ; al = 03h text mode, int 10 video
   566 0000048C CD31                    	int    31h ; TRDOS 386 - Video interrupt
   567 0000048E C3                      	retn
   568                                  
   569                                  print_origin:
   570 0000048F 803D[8E0B0000]00        	cmp	byte [tcolor], 0
   571 00000496 7707                    	ja	short p_o_0
   572 00000498 C605[8E0B0000]8E        	mov	byte [tcolor], 142
   573                                  p_o_0:
   574 0000049F A1[9C0B0000]            	mov	eax, [_x0]
   575 000004A4 3B05[840B0000]          	cmp	eax, [prevx]
   576 000004AA 744F                    	je	short _p_o_y
   577                                  		; same x value don't write
   578 000004AC 50                      	push	eax	; current x (abscissa) value
   579 000004AD A0[8E0B0000]            	mov	al, [tcolor]
   580 000004B2 A2[8D0B0000]            	mov	[pcolor], al
   581 000004B7 C605[8E0B0000]00        	mov	byte [tcolor], 0 ; blank (black color)
   582 000004BE E810000000              	call	p_o_1  ; erase/blank previous text
   583 000004C3 A0[8D0B0000]            	mov	al, [pcolor]
   584 000004C8 A2[8E0B0000]            	mov	[tcolor], al
   585 000004CD 8F05[840B0000]          	pop	dword [prevx] ; cur -> prev x (abscissa) value
   586                                  p_o_1:
   587 000004D3 BD[21060000]            	mov	ebp, txt_x0
   588 000004D8 BE04001000              	mov	esi, 00100004h ; row 16, column 4
   589 000004DD E8DC000000              	call	p_d_x
   590 000004E2 A1[840B0000]            	mov	eax, [prevx] ; [_x0]
   591 000004E7 BF[26060000]            	mov	edi, val_x0
   592 000004EC E8F0000000              	call	num_to_txt
   593 000004F1 BD[26060000]            	mov	ebp, val_x0
   594 000004F6 E8C3000000              	call	p_d_x
   595                                  _p_o_y:
   596 000004FB A1[A00B0000]            	mov	eax, [_y0]
   597 00000500 3B05[880B0000]          	cmp	eax, [prevy]
   598 00000506 744C                    	je	short _p_o_y_ok
   599                                  		; same y value don't write
   600 00000508 50                      	push	eax	; current y (ordinate) value
   601 00000509 A0[8E0B0000]            	mov	al, [tcolor]
   602 0000050E A2[8D0B0000]            	mov	[pcolor], al
   603 00000513 C605[8E0B0000]00        	mov	byte [tcolor], 0 ; blank (black color)
   604 0000051A E810000000              	call	p_o_2  ; erase/blank previous text
   605 0000051F A0[8D0B0000]            	mov	al, [pcolor]
   606 00000524 A2[8E0B0000]            	mov	[tcolor], al
   607 00000529 8F05[880B0000]          	pop	dword [prevy] ; cur -> prev y (ordinate) value
   608                                  p_o_2:
   609 0000052F BD[2A060000]            	mov	ebp, txt_y0
   610 00000534 BE04001A00              	mov	esi, 001A0004h ; row 26, column 4
   611 00000539 E880000000              	call	p_d_x
   612 0000053E A1[880B0000]            	mov	eax, [prevy] ; [_y0]
   613 00000543 BF[2F060000]            	mov	edi, val_y0
   614 00000548 E894000000              	call	num_to_txt
   615 0000054D BD[2F060000]            	mov	ebp, val_y0
   616 00000552 EB6A                    	jmp	short p_d_x
   617                                  _p_o_y_ok:
   618 00000554 C3                      	retn
   619                                  
   620                                  print_diameter:
   621 00000555 803D[8E0B0000]00        	cmp	byte [tcolor], 0
   622 0000055C 7707                    	ja	short p_d_0
   623 0000055E C605[8E0B0000]8E        	mov	byte [tcolor], 142
   624                                  p_d_0:
   625 00000565 A1[900B0000]            	mov	eax, [radius]
   626 0000056A D1E0                    	shl	eax, 1
   627 0000056C 3B05[800B0000]          	cmp	eax, [prevd]
   628 00000572 746C                    	je	short p_d_x_ok 
   629                                  		; same diameter don't write
   630 00000574 50                      	push	eax	; current diameter	
   631 00000575 A0[8E0B0000]            	mov	al, [tcolor]
   632 0000057A A2[8D0B0000]            	mov	[pcolor], al
   633 0000057F C605[8E0B0000]00        	mov	byte [tcolor], 0 ; blank (black color)
   634 00000586 E810000000              	call	p_d_1  ; erase/blank previous text
   635 0000058B A0[8D0B0000]            	mov	al, [pcolor]
   636 00000590 A2[8E0B0000]            	mov	[tcolor], al
   637 00000595 8F05[800B0000]          	pop	dword [prevd] ; cur -> prev diameter
   638                                  p_d_1:
   639 0000059B BD[0B060000]            	mov	ebp, txt_diameter
   640 000005A0 BE04000400              	mov	esi, 00040004h ; row 4, column 4
   641 000005A5 E814000000              	call	p_d_x
   642 000005AA A1[800B0000]            	mov	eax, [prevd] ; diameter
   643 000005AF BF[16060000]            	mov	edi, val_diameter 
   644 000005B4 E828000000              	call	num_to_txt
   645 000005B9 BD[16060000]            	mov	ebp, val_diameter
   646                                  	;jmp	short p_d_x
   647                                  p_d_x:
   648 000005BE B601                    	mov	dh, 01h ; 8x8 system font
   649                                  p_d_x_n:
   650 000005C0 8A5500                  	mov	dl, [ebp]
   651 000005C3 20D2                    	and	dl, dl
   652 000005C5 7419                    	jz	short p_d_x_ok
   653                                  	sys	_video, 010Fh, [tcolor] 
   653                              <1> 
   653                              <1> 
   653                              <1> 
   653                              <1> 
   653                              <1>  %if %0 >= 2
   653 000005C7 BB0F010000          <1>  mov ebx, %2
   653                              <1>  %if %0 >= 3
   653 000005CC 8B0D[8E0B0000]      <1>  mov ecx, %3
   653                              <1>  %if %0 = 4
   653                              <1>  mov edx, %4
   653                              <1>  %endif
   653                              <1>  %endif
   653                              <1>  %endif
   653 000005D2 B81F000000          <1>  mov eax, %1
   653                              <1> 
   653 000005D7 CD40                <1>  int 40h
   654 000005D9 45                      	inc	ebp
   655 000005DA 6683C608                	add	si, 8 ; next char pos
   656 000005DE EBE0                    	jmp	short p_d_x_n
   657                                  p_d_x_ok:
   658 000005E0 C3                      	retn
   659                                  
   660                                  num_to_txt:
   661                                  	; eax = number
   662                                  	; edi = digit position
   663                                  	;and	eax, 999
   664 000005E1 83F863                  	cmp	eax, 99
   665 000005E4 770C                    	ja	short numtxt_0
   666 000005E6 C60730                  	mov	byte [edi], "0"
   667 000005E9 47                      	inc	edi
   668 000005EA 3C09                    	cmp	al, 9
   669 000005EC 7704                    	ja	short numtxt_0
   670 000005EE C60730                  	mov	byte [edi], "0"
   671 000005F1 47                      	inc	edi
   672                                  numtxt_0:
   673 000005F2 B90A000000              	mov	ecx, 10
   674 000005F7 89E5                    	mov	ebp, esp
   675                                  numtxt_1:
   676 000005F9 29D2                    	sub	edx, edx
   677 000005FB F7F1                    	div	ecx
   678 000005FD 52                      	push	edx
   679 000005FE 09C0                    	or	eax, eax
   680 00000600 75F7                    	jnz	short numtxt_1
   681                                  numtxt_2:
   682 00000602 58                      	pop	eax
   683 00000603 0430                    	add	al, "0"
   684 00000605 AA                      	stosb
   685 00000606 39EC                    	cmp	esp, ebp
   686 00000608 72F8                    	jb	short numtxt_2
   687 0000060A C3                      	retn 
   688                                  
   689                                  circle_parameters:
   690                                  	;db "Diameter: 320 pixels", 0Dh, 0Ah
   691                                  	;db "x0: 160", 0Dh, 0Ah
   692                                  	;db "y0: 100", 0Dh, 0Ah, 0
   693                                  txt_diameter:
   694 0000060B 4469616D657465723A-     	db "Diameter: ", 0
   694 00000614 2000               
   695                                  val_diameter:	
   696 00000616 30303020706978656C-     	db "000 pixels", 0
   696 0000061F 7300               
   697 00000621 78303A2000              txt_x0:	db "x0: ", 0
   698 00000626 30303000                val_x0: db "000", 0
   699 0000062A 79303A2000              txt_y0:	db "y0: ", 0
   700 0000062F 30303000                val_y0: db "000", 0
   701                                  		
   702                                  program_msg:
   703 00000633 5452444F5320333836-     	db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Circle"
   703 0000063C 2076322E302E33202D-
   703 00000645 202827737973766964-
   703 0000064E 656F27292054657374-
   703 00000657 2050726F6772616D20-
   703 00000660 2D2044726177204369-
   703 00000669 72636C65           
   704 0000066D 0D0A                    	db 0Dh, 0Ah
   705 0000066F 6279204572646F6761-     	db "by Erdogan Tan - 16/02/2021"
   705 00000678 6E2054616E202D2031-
   705 00000681 362F30322F32303231 
   706                                  	;db 0Dh, 0Ah, 0
   707 0000068A 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
   708                                  
   709 0000068E 557365204172726F77-     	db "Use Arrow Keys, Home, End to move the CIRCLE .."
   709 00000697 204B6579732C20486F-
   709 000006A0 6D652C20456E642074-
   709 000006A9 6F206D6F7665207468-
   709 000006B2 6520434952434C4520-
   709 000006BB 2E2E               
   710 000006BD 0D0A                    	db 0Dh, 0Ah
   711 000006BF 557365202B2C2D206B-     	db "Use +,- keys to increase and decrease DIAMETER .."		
   711 000006C8 65797320746F20696E-
   711 000006D1 63726561736520616E-
   711 000006DA 642064656372656173-
   711 000006E3 65204449414D455445-
   711 000006EC 52202E2E           
   712 000006F0 0D0A                    	db 0Dh, 0Ah
   713 000006F2 55736520454E544552-     	db "Use ENTER key to draw CIRCLE .."
   713 000006FB 206B657920746F2064-
   713 00000704 72617720434952434C-
   713 0000070D 45202E2E           
   714 00000711 0D0A                    	db 0Dh, 0Ah
   715 00000713 557365205350414345-     	db "Use SPACE, Pg Up, Pg Down keys to change COLOR .."
   715 0000071C 2C2050672055702C20-
   715 00000725 506720446F776E206B-
   715 0000072E 65797320746F206368-
   715 00000737 616E676520434F4C4F-
   715 00000740 52202E2E           
   716 00000744 0D0A                    	db 0Dh, 0Ah	
   717 00000746 507265737320455343-     	db "Press ESC to exit .."
   717 0000074F 20746F206578697420-
   717 00000758 2E2E               
   718 0000075A 0D0A                    	db 0Dh, 0Ah
   719 0000075C 0D0A                    	db 0Dh, 0Ah
   720 0000075E 507265737320616E79-     	db "Press any key to continue .."
   720 00000767 206B657920746F2063-
   720 00000770 6F6E74696E7565202E-
   720 00000779 2E                 
   721                                  nextline:
   722 0000077A 0D0A00                  	db 0Dh, 0Ah, 0
   723                                  bss:
   724                                  
   725                                  ABSOLUTE bss
   726                                  
   727 0000077D <res 00000003>          alignb 4
   728                                  
   729                                  bss_start:
   730                                  _squares:
   731 00000780 <res 00000400>          	resd 256 ; squares of numbers from 0 t0 255	
   732 00000B80 <res 00000004>          prevd:	resd 1
   733 00000B84 <res 00000004>          prevx:	resd 1
   734 00000B88 <res 00000004>          prevy	resd 1
   735                                  counter: 
   736 00000B8C <res 00000001>          	resb 1
   737 00000B8D <res 00000001>          pcolor:	resb 1 ; previous (saved) text color
   738 00000B8E <res 00000001>          tcolor: resb 1 ; text color
   739 00000B8F <res 00000001>          phase:	resb 1 ; circle phase (quarter)
   740 00000B90 <res 00000004>          radius:	resd 1 ; Current Radius value
   741 00000B94 <res 00000004>          _r2:	resd 1 ; Square of R
   742 00000B98 <res 00000004>          color:	resd 1 ; circle color
   743 00000B9C <res 00000004>          _x0:	resd 1 ; circle origin, x-axis
   744 00000BA0 <res 00000004>          _y0:	resd 1 ; cirle origin, y-axis
   745 00000BA4 <res 00000004>          _x1:	resd 1 ; recent value of abscissa
   746 00000BA8 <res 00000004>          _y1:	resd 1 ; recent value of ordinate
   747 00000BAC <res 00000400>          _fx:	resd 256 ; for every X values from 0 to 255
   748                                  pixelpos:
   749 00000FAC <res 00000004>          	resd 1
   750                                  circlebuffer:
   751 00000FB0 <res 00009C40>          	resd 10000 ; 100*100*4 bytes
   752                                  
   753                                  bss_end:
