     1                                  ; ****************************************************************************
     2                                  ; line8.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests
     3                                  ; ----------------------------------------------------------------------------
     4                                  ;
     5                                  ; 20/02/2021
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  ; nasm line8.s -l line8.txt -o LINE8.PRG -Z error.txt
     9                                  ; (modified from 'line7.s', 20/02/2021)
    10                                  
    11                                  ; Draw line 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[C4070000]            	mov	edi, bss_start
    92 00000005 B90C020000              	mov	ecx, (bss_end - bss_start)/4
    93                                  	;xor	eax, eax
    94 0000000A F3AB                    	rep	stosd
    95                                  
    96                                  	; program message
    97 0000000C BE[8B030000]            	mov	esi, program_msg
    98 00000011 E89D010000              	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 inital values for angle and hypotenuse
   117 00000020 B82D000000              	mov	eax, 45
   118 00000025 C605[C6070000]2D        	mov	byte [angle], 45
   119 0000002C B08E                    	mov	al, 142 
   120                                  	;mov	[hipotenus], al ; 142
   121                                  	; Set start point of line(s)   
   122 0000002E C605[D0070000]A0        	mov	byte [_x0], 160
   123 00000035 C605[D4070000]96        	mov	byte [_y0], 150
   124                                  	; Set initial color
   125 0000003C C605[C8070000]1C         	mov	byte [color], 28
   126                                  _new_line_1:
   127 00000043 A2[CC070000]            	mov	[hipotenus], al
   128                                  _new_line_2:
   129 00000048 A0[C6070000]            	mov	al, [angle]
   130                                  _new_line_3:
   131                                  	; al = angle	
   132 0000004D E806030000              	call	getcosinus ; get cosine value * 16777216 for angle in AL
   133                                  	; eax= cos(angle) * 16777216 
   134 00000052 E823030000              	call	getxy	
   135 00000057 A3[D8070000]            	mov	[_x1], eax ; projection of end point on x-axis
   136 0000005C A0[C6070000]            	mov	al, [angle] 
   137 00000061 E8DE020000              	call	getsinus ; get sine value * 16777216 for angle in AL
   138                                  	; eax= sin(angle) * 16777216 
   139 00000066 E80F030000              	call	getxy		
   140 0000006B A3[DC070000]            	mov	[_y1], eax ; projection of end point on y-axis
   141                                  _0:
   142 00000070 E84F010000              	call	drawline
   143                                  waitforkey:
   144 00000075 B401                    	mov	ah, 1
   145 00000077 CD32                    	int	32h
   146 00000079 7419                    	jz	short getkey
   147 0000007B FE05[C4070000]          	inc	byte [counter]
   148 00000081 90                      	nop
   149 00000082 90                      	nop
   150 00000083 90                      	nop
   151 00000084 EBEF                    	jmp	short waitforkey
   152                                  
   153                                  terminate:
   154 00000086 E8F9020000              	call	set_text_mode
   155                                  	sys	_exit
   155                              <1> 
   155                              <1> 
   155                              <1> 
   155                              <1> 
   155                              <1>  %if %0 >= 2
   155                              <1>  mov ebx, %2
   155                              <1>  %if %0 >= 3
   155                              <1>  mov ecx, %3
   155                              <1>  %if %0 = 4
   155                              <1>  mov edx, %4
   155                              <1>  %endif
   155                              <1>  %endif
   155                              <1>  %endif
   155 0000008B B801000000          <1>  mov eax, %1
   155                              <1> 
   155 00000090 CD40                <1>  int 40h
   156                                  halt:
   157 00000092 EBFE                    	jmp	short halt
   158                                  
   159                                  getkey:
   160 00000094 30E4                    	xor	ah, ah
   161 00000096 CD32                    	int	32h
   162                                  
   163 00000098 663D032E                	cmp	ax, 2E03h
   164 0000009C 74E8                    	je	short terminate
   165 0000009E 3C1B                    	cmp	al, 1Bh ; ESC key
   166 000000A0 74E4                    	je	short terminate	
   167                                  
   168 000000A2 3C2B                    	cmp	al, '+'
   169 000000A4 7512                    	jne	short _1
   170                                  	
   171 000000A6 A0[CC070000]            	mov	al, [hipotenus]
   172                                  
   173 000000AB 3C8E                    	cmp	al, 142
   174 000000AD 734D                    	jnb	short _3_  ; beep
   175                                  	
   176                                  	; delete line by drawing black line
   177                                  	; with same length and with same x,y position
   178 000000AF E856020000              	call	blackline
   179                                  	; increase length of the line
   180 000000B4 FEC0                    	inc	al	
   181 000000B6 EB8B                    	jmp	short _new_line_1 ; draw with new length
   182                                  _1:
   183 000000B8 3C2D                    	cmp	al, '-'
   184 000000BA 7515                    	jne	short _2
   185                                  
   186 000000BC A0[CC070000]            	mov	al, [hipotenus]
   187                                  
   188 000000C1 3C03                    	cmp	al, 3
   189 000000C3 7637                    	jna	short _3_ ; beep
   190                                  	
   191                                  	; delete line by drawing black line
   192                                  	; with same length and with same x,y position
   193 000000C5 E840020000              	call	blackline
   194                                  	; decrease length of the line
   195 000000CA FEC8                    	dec	al	
   196 000000CC E972FFFFFF              	jmp	_new_line_1 ; draw with new length
   197                                  _2:
   198 000000D1 3C20                    	cmp	al, 20h  ; space
   199 000000D3 7509                    	jne	short _3
   200 000000D5 8005[C8070000]08        	add	byte [color], 8 	
   201 000000DC EB92                    	jmp	short _0
   202                                  _3:
   203 000000DE 80FC4B                  	cmp	ah, 4Bh
   204 000000E1 7523                    	jne	short _4
   205                                  	; left arrow
   206 000000E3 803D[C6070000]B4        	cmp	byte [angle], 180
   207 000000EA 73F2                    	jnb	short _3
   208 000000EC E819020000              	call	blackline ; clear current position 
   209 000000F1 FE05[C6070000]          	inc	byte [angle]
   210 000000F7 E94CFFFFFF              	jmp	_new_line_2
   211                                  _3_:
   212 000000FC E831020000              	call	beep
   213 00000101 E96FFFFFFF              	jmp	waitforkey
   214                                  _4:
   215 00000106 80FC4D                  	cmp	ah, 4Dh
   216 00000109 7519                    	jne	short _5
   217                                  	; right arrow
   218 0000010B 803D[C6070000]00        	cmp	byte [angle], 0
   219 00000112 76CA                    	jna	short _3
   220 00000114 E8F1010000              	call	blackline ; clear current position 
   221 00000119 FE0D[C6070000]          	dec	byte [angle]
   222 0000011F E924FFFFFF              	jmp	_new_line_2
   223                                  _5:
   224 00000124 80FC50                  	cmp	ah, 50h
   225 00000127 751F                    	jne	short _7
   226                                  	; down arrow
   227 00000129 A0[C6070000]            	mov	al, [angle]
   228 0000012E 2C05                    	sub	al, 5
   229 00000130 7707                    	ja	short _6
   230 00000132 E8FB010000              	call	beep
   231 00000137 30C0                    	xor	al, al ; 0
   232                                  _6:
   233 00000139 E8CC010000              	call	blackline ; clear current position 
   234 0000013E A2[C6070000]            	mov	[angle], al
   235 00000143 E905FFFFFF              	jmp	_new_line_3
   236                                  _7:
   237 00000148 80FC48                  	cmp	ah, 48h
   238 0000014B 7514                    	jne	short _8
   239                                  	; up arrow
   240 0000014D A0[C6070000]            	mov	al, [angle]
   241 00000152 0405                    	add	al, 5
   242 00000154 3CB4                    	cmp	al, 180
   243 00000156 72E1                    	jb	short _6
   244 00000158 E8D5010000              	call	beep
   245 0000015D B0B4                    	mov	al, 180
   246 0000015F EBD8                    	jmp	short _6
   247                                  _8:
   248 00000161 80FC47                  	cmp	ah, 47h ; Home key
   249 00000164 7504                    	jne	short _9
   250 00000166 28C0                    	sub	al, al ; 0 ; set angle to 0 degree
   251 00000168 EBCF                    	jmp	short _6
   252                                  _9:
   253 0000016A 80FC4F                  	cmp	ah, 4Fh ; End key
   254 0000016D 7504                    	jne	short _10
   255 0000016F B0B4                    	mov	al, 180 ; set angle to 180 degrees
   256 00000171 EBC6                    	jmp	short _6
   257                                  _10:	
   258 00000173 663D0D1C                	cmp	ax, 1C0Dh
   259 00000177 7509                    	jne	short _11
   260 00000179 8005[C8070000]04        	add	byte [color], 4
   261 00000180 EB22                    	jmp	short _13
   262                                  _11:	
   263 00000182 80FC53                  	cmp	ah, 53h ; INSERT
   264 00000185 741D                    	je	short _13
   265 00000187 80FC52                  	cmp	ah, 52h  ; DEL
   266 0000018A 7418                    	je	short _13
   267                                  
   268 0000018C 80FC49                  	cmp	ah, 49h  ; Page UP
   269 0000018F 7508                    	jne	short _12
   270 00000191 FE0D[C8070000]          	dec	byte [color]
   271 00000197 EB0B                    	jmp	short _13
   272                                  _12:
   273 00000199 80FC51                  	cmp	ah, 51h  ; Page Down
   274 0000019C 7510                    	jne	short _14
   275 0000019E FE05[C8070000]          	inc	byte [color]
   276                                  _13:
   277 000001A4 E889010000              	call	beep
   278 000001A9 E9C2FEFFFF              	jmp	_0
   279                                  _14:
   280 000001AE E9C2FEFFFF              	jmp	waitforkey
   281                                  
   282                                  print_msg:
   283 000001B3 B40E                    	mov	ah, 0Eh
   284 000001B5 BB07000000              	mov	ebx, 7
   285                                  	;mov	bl, 7 ; char attribute & color
   286                                  p_next_chr:
   287 000001BA AC                      	lodsb
   288 000001BB 08C0                    	or	al, al
   289 000001BD 7404                    	jz	short p_retn ; retn	
   290 000001BF CD31                    	int	31h
   291 000001C1 EBF7                    	jmp	short p_next_chr
   292                                  p_retn:
   293 000001C3 C3                      	retn
   294                                  
   295                                  drawline:
   296                                  	; INPUT:
   297                                  	;	[_x0]
   298                                  	;	[_y0]
   299                                  	;	[_x1]
   300                                  	;	[_y1]
   301                                  	;	[sin]
   302                                  	;	[cos]
   303                                  	;	[color]
   304                                  	;
   305                                  	; Modified registers: esi, edi, eax, ecx, ebx, edx
   306                                  
   307                                  _draw_l_0:
   308 000001C4 31C9                    	xor	ecx, ecx
   309 000001C6 890D[E0070000]          	mov	[_x2], ecx ; 0  ; reset
   310 000001CC 890D[E4070000]          	mov	[_y2], ecx ; 0	; reset
   311 000001D2 890D[F0070000]          	mov	[pixelcount], ecx ; reset
   312 000001D8 A0[D8070000]            	mov	al, [_x1]
   313 000001DD 3A05[DC070000]          	cmp	al, [_y1]
   314 000001E3 7302                    	jnb	short _draw_l_x0
   315                                  	; base axis is y-axis
   316 000001E5 EB7F                    	jmp	_draw_l_y0
   317                                  _draw_l_x0:
   318                                  	; base axis is x-axis
   319                                  	; draw line from x = 0 to [_x1]
   320                                  	; set y by using x*([sin]/[cos])
   321                                  	; cl = 0
   322                                  	;mov	byte [prevy], cl ; previous Y value
   323 000001E7 E8D7000000              	call	writepixel
   324 000001EC 8A0D[E4070000]          	mov	cl, [_y2]
   325                                  _draw_l_x1:
   326 000001F2 A1[E0070000]            	mov	eax, [_x2]
   327 000001F7 FEC0                    	inc	al
   328 000001F9 3A05[D8070000]          	cmp	al, [_x1]
   329 000001FF 7747                    	ja	short _draw_l_x3
   330 00000201 A2[E0070000]            	mov	[_x2], al	
   331 00000206 8B15[E8070000]          	mov	edx, [sin]
   332 0000020C F7E2                    	mul	edx
   333 0000020E 8B1D[EC070000]          	mov	ebx, [cos]
   334 00000214 F7F3                    	div	ebx
   335 00000216 A3[E4070000]            	mov	[_y2], eax
   336 0000021B 88C5                    	mov	ch, al
   337 0000021D FEC1                    	inc	cl
   338 0000021F 38E9                    	cmp	cl, ch ; previous Y+1 < current Y ?
   339                                  	;jnb	short _draw_l_x0
   340 00000221 EBC4                    	jmp	short _draw_l_x0
   341 00000223 FE0D[E0070000]          	dec	byte [_x2]
   342                                  _draw_l_x2:
   343 00000229 880D[E4070000]          	mov	[_y2], cl
   344 0000022F E88F000000              	call	writepixel
   345 00000234 FEC1                    	inc	cl
   346 00000236 38E9                    	cmp	cl, ch ; loop end for [_y2]
   347 00000238 72EF                    	jb	short _draw_l_x2
   348 0000023A 882D[E4070000]          	mov	[_y2], ch
   349 00000240 FE05[E0070000]          	inc	byte [_x2]
   350 00000246 EB9F                    	jmp	short _draw_l_x0
   351                                  
   352                                  _draw_l_x3:
   353                                  _draw_l_y3:
   354                                  writeline:
   355                                  	;mov	edx, [pixelcount]
   356                                  	; edx = pixel count
   357                                  	; esi = user's single color pixel buffer address
   358 00000248 BE[F4070000]            	mov	esi, _fx 
   359                                  	sys	_video, 0305h, [color], [pixelcount]
   359                              <1> 
   359                              <1> 
   359                              <1> 
   359                              <1> 
   359                              <1>  %if %0 >= 2
   359 0000024D BB05030000          <1>  mov ebx, %2
   359                              <1>  %if %0 >= 3
   359 00000252 8B0D[C8070000]      <1>  mov ecx, %3
   359                              <1>  %if %0 = 4
   359 00000258 8B15[F0070000]      <1>  mov edx, %4
   359                              <1>  %endif
   359                              <1>  %endif
   359                              <1>  %endif
   359 0000025E B81F000000          <1>  mov eax, %1
   359                              <1> 
   359 00000263 CD40                <1>  int 40h
   360                                  
   361 00000265 C3                      	retn
   362                                  		 	
   363                                  _draw_l_y0:
   364                                  	; base axis is y-axis
   365                                  	; draw line from y = 0 to [_y1]
   366                                  	; set x by using y*([cos]/[sin])
   367                                  	; cl = 0
   368                                  
   369                                  	;mov	byte [prevx], cl ; previous X value
   370 00000266 E858000000              	call	writepixel
   371 0000026B 8A0D[E0070000]          	mov	cl, [_x2]	
   372                                  _draw_l_y1:
   373 00000271 A1[E4070000]            	mov	eax, [_y2]
   374 00000276 FEC0                    	inc	al
   375 00000278 3A05[DC070000]          	cmp	al, [_y1]
   376 0000027E 77C8                    	ja	short _draw_l_y3
   377 00000280 A2[E4070000]            	mov	[_y2], al	
   378                                  	;mov	edx, [cos]
   379                                  	;mul	edx
   380 00000285 F725[EC070000]          	mul	dword [cos]
   381                                  	;mov	ebx, [sin]
   382                                  	;div	ebx
   383 0000028B F735[E8070000]          	div	dword [sin]
   384 00000291 A3[E0070000]            	mov	[_x2], eax
   385 00000296 88C5                    	mov	ch, al
   386 00000298 FEC1                    	inc	cl
   387 0000029A 38E9                    	cmp	cl, ch ; previous X+1 < current X ?
   388                                  	;jnb	short _draw_l_y0
   389 0000029C EBC8                    	jmp	short _draw_l_y0
   390 0000029E FE0D[E4070000]          	dec	byte [_y2]
   391                                  _draw_l_y2:
   392 000002A4 880D[E0070000]          	mov	[_x2], cl
   393 000002AA E814000000              	call	writepixel
   394 000002AF FEC1                    	inc	cl
   395 000002B1 38E9                    	cmp	cl, ch ; loop end for [_y2]
   396 000002B3 72EF                    	jb	short _draw_l_y2
   397 000002B5 882D[E0070000]          	mov	[_x2], ch
   398 000002BB FE05[E4070000]          	inc	byte [_y2]
   399 000002C1 EBA3                    	jmp	short _draw_l_y0
   400                                  
   401                                  writepixel:
   402                                  	; write pixel to line buffer (of user)	
   403                                  	; Modified registers: eax, ebx, edx
   404 000002C3 A1[D4070000]            	mov	eax, [_y0] ; 150	
   405 000002C8 2B05[E4070000]          	sub	eax, [_y2] ; max. 142
   406 000002CE BA40010000              	mov	edx, 320
   407 000002D3 F7E2                    	mul	edx
   408 000002D5 0305[D0070000]          	add	eax, [_x0] ; 160
   409                                  			; center of the screen 
   410 000002DB 803D[C6070000]5A        	cmp	byte [angle], 90
   411 000002E2 7608                    	jna	short wp_1
   412                                  wp_0:
   413 000002E4 2B05[E0070000]          	sub	eax, [_x2] ; negative direction
   414 000002EA EB06                    	jmp	short wp_2 
   415                                  wp_1:
   416 000002EC 0305[E0070000]          	add	eax, [_x2] ; positive direction	
   417                                  wp_2:
   418 000002F2 8B1D[F0070000]          	mov	ebx, [pixelcount]	
   419 000002F8 C1E302                  	shl	ebx, 2 ; * 4
   420 000002FB 81C3[F4070000]          	add	ebx, _fx ; line buffer
   421 00000301 8903                    	mov	[ebx], eax
   422 00000303 FF05[F0070000]          	inc	dword [pixelcount]
   423 00000309 C3                      	retn
   424                                  
   425                                  blackline:
   426 0000030A 50                      	push	eax
   427                                  	;xor	al, al
   428 0000030B A0[C4070000]            	mov	al, [counter] ; color effect for 'line8.s'
   429 00000310 8605[C8070000]          	xchg	[color], al ; color = 0	
   430 00000316 A2[C7070000]            	mov	[pcolor], al
   431 0000031B FE05[C4070000]          	inc	byte [counter] ; color effect for 'line8.s'
   432 00000321 E822FFFFFF              	call	writeline
   433 00000326 A0[C7070000]            	mov	al, [pcolor]
   434 0000032B A2[C8070000]            	mov	[color], al ; restore color
   435 00000330 58                      	pop	eax
   436 00000331 C3                      	retn
   437                                  
   438                                  beep:
   439                                  	; call beep function (16/64 second, 886Hz)
   440                                  	sys	_audio, 16, 1331
   440                              <1> 
   440                              <1> 
   440                              <1> 
   440                              <1> 
   440                              <1>  %if %0 >= 2
   440 00000332 BB10000000          <1>  mov ebx, %2
   440                              <1>  %if %0 >= 3
   440 00000337 B933050000          <1>  mov ecx, %3
   440                              <1>  %if %0 = 4
   440                              <1>  mov edx, %4
   440                              <1>  %endif
   440                              <1>  %endif
   440                              <1>  %endif
   440 0000033C B820000000          <1>  mov eax, %1
   440                              <1> 
   440 00000341 CD40                <1>  int 40h
   441 00000343 C3                      	retn
   442                                  
   443                                  getsinus:
   444                                  	; Input:
   445                                  	;	AL = angle
   446                                  	; output:
   447                                  	;	EAX = sin(angle) * 16777216
   448                                  	;
   449                                  	; Modified registers: eax, esi
   450                                  	;
   451 00000344 0FB6F0                  	movzx	esi, al
   452 00000347 C1E602                  	shl	esi, 2 ; * 4
   453 0000034A 81C6[F0040000]          	add	esi, sinustable
   454 00000350 8B06                    	mov	eax, [esi]
   455 00000352 A3[E8070000]            	mov	[sin], eax
   456 00000357 C3                      	retn	
   457                                  
   458                                  getcosinus:
   459                                  	; Input:
   460                                  	;	AL = angle
   461                                  	; output:
   462                                  	;	EAX = cos(angle) * 16777216
   463                                  	;
   464                                  	; Modified registers: eax, esi
   465                                  	
   466 00000358 3C5A                    	cmp	al, 90 ; 90 degrees
   467 0000035A 7209                    	jb	short gcos_1
   468 0000035C 2C5A                    	sub	al, 90	
   469 0000035E BE[F0040000]            	mov	esi, cos_90
   470 00000363 EB05                    	jmp	short gcos_2
   471                                  gcos_1:	
   472 00000365 BE[58060000]            	mov	esi, cos_0
   473                                  gcos_2:
   474 0000036A 0FB6C0                  	movzx	eax, al
   475 0000036D C1E002                  	shl	eax, 2 ; * 4
   476 00000370 01C6                    	add	esi, eax
   477 00000372 8B06                    	mov	eax, [esi]
   478 00000374 A3[EC070000]            	mov	[cos], eax
   479 00000379 C3                      	retn
   480                                  
   481                                  getxy:
   482                                  	; Input:
   483                                  	;	EAX = sin or cos value * 16777216
   484                                  	; output:
   485                                  	;	EAX = x or y projection
   486                                  	;
   487                                  	; Modified registers: eax, edx, (ecx)
   488                                  	;
   489                                  	
   490                                  	;mov	edx, [hipotenus]
   491                                  	;mul	edx
   492 0000037A F725[CC070000]          	mul	dword [hipotenus]
   493                                  	;mov	ecx, 16777216
   494                                  	;div	ecx
   495 00000380 C1E818                  	shr	eax, 24
   496 00000383 C3                      	retn
   497                                  
   498                                  set_text_mode:
   499 00000384 30E4                    	xor    ah, ah
   500 00000386 B003                    	mov    al, 3                        
   501                                   	;int   10h ; al = 03h text mode, int 10 video
   502 00000388 CD31                    	int    31h ; TRDOS 386 - Video interrupt
   503 0000038A C3                      	retn
   504                                  
   505                                  program_msg:
   506 0000038B 5452444F5320333836-     	db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Line (as rotated)"
   506 00000394 2076322E302E33202D-
   506 0000039D 202827737973766964-
   506 000003A6 656F27292054657374-
   506 000003AF 2050726F6772616D20-
   506 000003B8 2D2044726177204C69-
   506 000003C1 6E652028617320726F-
   506 000003CA 746174656429       
   507 000003D0 0D0A                    	db 0Dh, 0Ah
   508 000003D2 6279204572646F6761-     	db "by Erdogan Tan - 20/02/2021"
   508 000003DB 6E2054616E202D2032-
   508 000003E4 302F30322F32303231 
   509                                  	;db 0Dh, 0Ah, 0
   510 000003ED 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
   511                                  
   512 000003F1 557365204172726F77-     	db "Use Arrow Keys, Home, End to rotate the LINE .."
   512 000003FA 204B6579732C20486F-
   512 00000403 6D652C20456E642074-
   512 0000040C 6F20726F7461746520-
   512 00000415 746865204C494E4520-
   512 0000041E 2E2E               
   513 00000420 0D0A                    	db 0Dh, 0Ah
   514 00000422 557365202B2C2D206B-     	db "Use +,- keys to increase and decrease LINE LENGTH .."		
   514 0000042B 65797320746F20696E-
   514 00000434 63726561736520616E-
   514 0000043D 642064656372656173-
   514 00000446 65204C494E45204C45-
   514 0000044F 4E475448202E2E     
   515 00000456 0D0A                    	db 0Dh, 0Ah
   516 00000458 55736520454E544552-     	db "Use ENTER key to draw LINE with new color .."
   516 00000461 206B657920746F2064-
   516 0000046A 726177204C494E4520-
   516 00000473 77697468206E657720-
   516 0000047C 636F6C6F72202E2E   
   517 00000484 0D0A                    	db 0Dh, 0Ah
   518 00000486 557365205350414345-     	db "Use SPACE, Pg Up, Pg Down keys to change COLOR .."
   518 0000048F 2C2050672055702C20-
   518 00000498 506720446F776E206B-
   518 000004A1 65797320746F206368-
   518 000004AA 616E676520434F4C4F-
   518 000004B3 52202E2E           
   519 000004B7 0D0A                    	db 0Dh, 0Ah	
   520 000004B9 507265737320455343-     	db "Press ESC to exit .."
   520 000004C2 20746F206578697420-
   520 000004CB 2E2E               
   521 000004CD 0D0A                    	db 0Dh, 0Ah
   522 000004CF 0D0A                    	db 0Dh, 0Ah
   523 000004D1 507265737320616E79-     	db "Press any key to continue .."
   523 000004DA 206B657920746F2063-
   523 000004E3 6F6E74696E7565202E-
   523 000004EC 2E                 
   524                                  nextline:
   525 000004ED 0D0A00                  	db 0Dh, 0Ah, 0
   526                                  
   527                                  sinustable:
   528                                  	; from A = 0 degree to 180 degrees (sin(A)*65536)
   529                                  	;dd 0
   530                                  	;dd 1144, 2287, 3430, 4572, 5712, 6850, 7987, 9121, 10252, 11380, 12505, 13626
   531                                  	;dd 14742, 15855, 16962, 18064, 19161, 20252, 21336, 22415, 23486, 24550, 25607
   532                                  	;dd 26656, 27697, 28729, 29753, 30767, 31772, 32768, 33754, 34729, 35693, 36647
   533                                  	;dd 37590, 38521, 39441, 40348, 41243, 42126, 42995, 43852, 44695, 45525, 46341
   534                                  	;dd 47143, 47930, 48703, 49461, 50203, 50931, 51643, 52339, 53020, 53684, 54332
   535                                  	;dd 54963, 55578, 56175, 56756, 57319, 57865, 58393, 58903, 59396, 59870, 60326
   536                                  	;dd 60764, 61183, 61584, 61966, 62328, 62672, 62997, 63303, 63589, 63856, 64104
   537                                  	;dd 64332, 64540, 64729, 64898, 65048, 65177, 65287, 65376, 65446, 65496, 65526
   538                                  	;dd 65536
   539                                  	;dd 65526, 65496, 65446, 65376, 65287, 65177, 65048, 64898, 64729, 64540, 64332
   540                                  	;dd 64104, 63856, 63589, 63303, 62997, 62672, 62328, 61966, 61584, 61183, 60764
   541                                  	;dd 60326, 59870, 59396, 58903, 58393, 57865, 57319, 56756, 56175, 55578, 54963
   542                                  	;dd 54332, 53684, 53020, 52339, 51643, 50931, 50203, 49461, 48703, 47930, 47143
   543                                  	;dd 46341, 45525, 44695, 43852, 42995, 42126, 41243, 40348, 39441, 38521, 37590
   544                                  	;dd 36647, 35693, 34729, 33754, 32768, 31772, 30767, 29753, 28729, 27697, 26656
   545                                  	;dd 25607, 24550, 23486, 22415, 21336, 20252, 19161, 18064, 16962, 15855, 14742
   546                                  	;dd 13626, 12505, 11380, 10252, 9121, 7987, 6850, 5712, 4572, 3430, 2287, 1144
   547                                  	;dd 0
   548                                  	; from A = 0 degree to 180 degrees (sin(A)*65536*256)
   549                                  	; 0
   550 000004F0 00000000                cos_90:	dd 0
   551 000004F4 C37704002CEF0800E4-     	dd 292803, 585516, 878052, 1170319, 1462231, 1753697, 2044628, 2334937, 2624535, 2913333
   551 000004FD 650D008FDB1100D74F-
   551 00000506 160061C21A00D4321F-
   551 0000050F 00D9A02300170C2800-
   551 00000518 35742C00           
   552 0000051C DCD83000B339350064-     	dd 3201244, 3488179, 3774052, 4058776, 4342263, 4624427, 4905183, 5184445, 5462127, 5738146
   552 00000525 96390098EE3D00F741-
   552 0000052E 42002B904600DFD84A-
   552 00000537 00BD1B4F006F585300-
   552 00000540 A28E5700           
   553 00000544 00BE5B0038E65F00F5-     	dd 6012416, 6284856, 6555381, 6823909, 7090358, 7354647, 7616697, 7876426, 8133756
   553 0000054D 066400E51F6800B630-
   553 00000556 6C0017397000B93874-
   553 0000055F 004A2F78007C1C7C00 
   554                                  cos_60:	; 30
   555 00000568 0000800089D98300CA-     	dd 8388608, 8640905, 8890570, 9137527, 9381700, 9623016, 9861400, 10096781, 10329086, 10558244
   555 00000571 A88700776D8B004427-
   555 0000057A 8F00E8D59200187996-
   555 00000583 008D109A00FE9B9D00-
   555 0000058C 241BA100           
   556 00000590 BB8DA4007CF3A70025-     	dd 10784187, 11006844, 11226149, 11442034, 11654434
   556 00000599 4CAB007297AE0022D5-
   556 000005A2 B100               
   557                                  sin_45:	; 45
   558 000005A4 F304B500A726B800FF-     cos_45:	dd 11863283, 12068519, 12270079, 12467901, 12661926, 12852093, 13038346, 13220627, 13398880, 13573053
   558 000005AD 39BB00BD3EBE00A634-
   558 000005B6 C1007D1BC4000AF3C6-
   558 000005BF 0013BBC9006073CC00-
   558 000005C8 BD1BCF00           
   559 000005CC F3B3D100CE3BD4001D-     	dd 13743091, 13908942, 14070557, 14227886, 14380881
   559 000005D5 B3D600AE19D900516F-
   559 000005DE DB00               
   560                                  cos_30:	; 60
   561 000005E0 D7B3DD0014E7DF00DA-     	dd 14529495, 14673684, 14813402, 14948609, 15079262, 15205322, 15326749, 15443509, 15555564, 15662880
   561 000005E9 08E2000119E4005E17-
   561 000005F2 E600CA03E8001DDEE9-
   561 000005FB 0035A6EB00EC5BED00-
   561 00000604 20FFEE00           
   562 00000608 B28FF000810DF20071-     	dd 15765426, 15863169, 15956081, 16044131, 16127295, 16205546, 16278861, 16347217, 16410594, 16468971
   562 00000611 78F30063D0F4003F15-
   562 0000061A F600EA46F7004D65F8-
   562 00000623 005170F900E267FA00-
   562 0000062C EB4BFB00           
   563 00000630 5C1CFC0025D9FC0035-     	dd 16522332, 16570661, 16613941, 16652161, 16685309, 16713374, 16736348, 16754223, 16766996, 16774661
   563 00000639 82FD008117FE00FD98-
   563 00000642 FE009E06FF005C60FF-
   563 0000064B 002FA6FF0014D8FF00-
   563 00000654 05F6FF00           
   564                                  sin_90:	; 90
   565 00000658 0000000105F6FF0014-     cos_0:	dd 16777216, 16774661, 16766996, 16754223, 16736348, 16713374, 16685309, 16652161, 16613941, 16570661
   565 00000661 D8FF002FA6FF005C60-
   565 0000066A FF009E06FF00FD98FE-
   565 00000673 008117FE003582FD00-
   565 0000067C 25D9FC00           
   566 00000680 5C1CFC00EB4BFB00E2-     	dd 16522332, 16468971, 16410594, 16347217, 16278861, 16205546, 16127295, 16044131, 15956081, 15863169
   566 00000689 67FA005170F9004D65-
   566 00000692 F800EA46F7003F15F6-
   566 0000069B 0063D0F4007178F300-
   566 000006A4 810DF200           
   567 000006A8 B28FF00020FFEE00EC-     	dd 15765426, 15662880, 15555564, 15443509, 15326749, 15205322, 15079262, 14948609, 14813402, 14673684
   567 000006B1 5BED0035A6EB001DDE-
   567 000006BA E900CA03E8005E17E6-
   567 000006C3 000119E400DA08E200-
   567 000006CC 14E7DF00           
   568                                  	; 120
   569 000006D0 D7B3DD00516FDB00AE-     	dd 14529495, 14380881, 14227886, 14070557, 13908942, 13743091, 13573053, 13398880, 13220627, 13038346
   569 000006D9 19D9001DB3D600CE3B-
   569 000006E2 D400F3B3D100BD1BCF-
   569 000006EB 006073CC0013BBC900-
   569 000006F4 0AF3C600           
   570 000006F8 7D1BC400A634C100BD-     	dd 12852093, 12661926, 12467901, 12270079, 12068519
   570 00000701 3EBE00FF39BB00A726-
   570 0000070A B800               
   571                                  	; 135
   572 0000070C F304B50022D5B10072-     	dd 11863283, 11654434, 11442034, 11226149, 11006844, 10784187, 10558244, 10329086, 10096781, 9861400
   572 00000715 97AE00254CAB007CF3-
   572 0000071E A700BB8DA400241BA1-
   572 00000727 00FE9B9D008D109A00-
   572 00000730 18799600           
   573 00000734 E8D5920044278F0077-     	dd 9623016, 9381700, 9137527, 8890570, 8640905
   573 0000073D 6D8B00CAA8870089D9-
   573 00000746 8300               
   574                                  	; 150
   575 00000748 000080007C1C7C004A-     	dd 8388608, 8133756, 7876426, 7616697, 7354647, 7090358, 6823909, 6555381, 6284856, 6012416, 5738146
   575 00000751 2F7800B93874001739-
   575 0000075A 7000B6306C00E51F68-
   575 00000763 00F506640038E65F00-
   575 0000076C 00BE5B00A28E5700   
   576 00000774 6F585300BD1B4F00DF-     	dd 5462127, 5184445, 4905183, 4624427, 4342263, 4058776, 3774052, 3488179, 3201244, 2913333, 2624535
   576 0000077D D84A002B904600F741-
   576 00000786 420098EE3D00649639-
   576 0000078F 00B3393500DCD83000-
   576 00000798 35742C00170C2800   
   577 000007A0 D9A02300D4321F0061-     	dd 2334937, 2044628, 1753697, 1462231, 1170319, 878052, 585516, 292803
   577 000007A9 C21A00D74F16008FDB-
   577 000007B2 1100E4650D002CEF08-
   577 000007BB 00C3770400         
   578                                  	; 180
   579 000007C0 00000000                	dd 0
   580                                  
   581                                  bss:
   582                                  
   583                                  ABSOLUTE bss
   584                                  
   585                                  alignb 4
   586                                  
   587                                  bss_start:
   588                                  counter:
   589 000007C4 <res 00000002>          	resw 1
   590 000007C6 <res 00000001>          angle:	resb 1
   591 000007C7 <res 00000001>          pcolor:	resb 1 ; previous color (used for black line drawing)
   592 000007C8 <res 00000004>          color:	resd 1
   593                                  hipotenus:
   594 000007CC <res 00000004>          	resd 1 ; current hypotenuse value (line length)
   595 000007D0 <res 00000004>          _x0:	resd 1 ; horizontal start point
   596 000007D4 <res 00000004>          _y0:	resd 1 ; vertical start point
   597 000007D8 <res 00000004>          _x1:	resd 1 ; hypotenuse * cos(angle), X-axis value of the end point
   598 000007DC <res 00000004>          _y1:	resd 1 ; hypotenuse * sin(angle), Y-axis value of the end point
   599 000007E0 <res 00000004>          _x2:	resd 1 ; interim value of X (< _x1) = cotangent(angle)*_y1 (if _y1 > _x1)
   600 000007E4 <res 00000004>          _y2:	resd 1 ; interim value of Y (< _y1) = tangent(angle)*_x1 (if _x1 > _y1)
   601 000007E8 <res 00000004>          sin:	resd 1 ; sine(angle) * 16777216
   602 000007EC <res 00000004>          cos:	resd 1 ; cosine(angle) * 16777216
   603                                  pixelcount:
   604 000007F0 <res 00000004>          	resd 1
   605 000007F4 <res 00000238>          _fx:	resd 142 ; For every X values from 0 to 142
   606 00000A2C <res 000005C8>          	resd 512-142 ; additional buffer
   607                                  bss_end:
