1 ; **************************************************************************** 2 ; sinus5.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 19/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm sinus5.s -l sinus5.txt -o SINUS5.PRG -Z error.txt 9 ; (modified from 'sinus3.s', 19/02/2021) 10 11 ; Draw sinus wave/curve 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) , , 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[B4030000] mov edi, bss_start 92 00000005 B900080000 mov ecx, (bss_end - bss_start)/4 93 ;xor eax, eax 94 0000000A F3AB rep stosd 95 96 ; program message 97 0000000C BE[7C010000] mov esi, program_msg 98 00000011 E8A2000000 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 101h ; 640x480, 256 colors 106 sys _video, 08FFh, 101h 106 <1> 106 <1> 106 <1> 106 <1> 106 <1> %if %0 >= 2 106 0000001A BBFF080000 <1> mov ebx, %2 106 <1> %if %0 >= 3 106 0000001F B901010000 <1> mov ecx, %3 106 <1> %if %0 = 4 106 <1> mov edx, %4 106 <1> %endif 106 <1> %endif 106 <1> %endif 106 00000024 B81F000000 <1> mov eax, %1 106 <1> 106 00000029 CD40 <1> int 40h 107 0000002B 09C0 or eax, eax 108 ;jz short terminate 109 ;mov [LFB_ADDR], edx ; pointer to LFB info table/structure 110 0000002D 750E jnz short set_vesa_mode_101h_ok 111 112 terminate: 113 0000002F E841010000 call set_text_mode 114 sys _exit 114 <1> 114 <1> 114 <1> 114 <1> 114 <1> %if %0 >= 2 114 <1> mov ebx, %2 114 <1> %if %0 >= 3 114 <1> mov ecx, %3 114 <1> %if %0 = 4 114 <1> mov edx, %4 114 <1> %endif 114 <1> %endif 114 <1> %endif 114 00000034 B801000000 <1> mov eax, %1 114 <1> 114 00000039 CD40 <1> int 40h 115 halt: 116 0000003B EBFE jmp short halt 117 118 set_vesa_mode_101h_ok: 119 0000003D C605[AC030000]1C mov byte [color], 28 ; initial pixel color 120 _0: 121 00000044 E880000000 call drawsinewave 122 waitforkey: 123 ;mov ah, 1 124 ;int 32h 125 ;jz short getkey 126 ;inc word [counter] 127 ;nop 128 ;nop 129 ;nop 130 ;jmp short waitforkey 131 getkey: 132 00000049 30E4 xor ah, ah 133 0000004B CD32 int 32h 134 135 0000004D 663D032E cmp ax, 2E03h 136 00000051 74DC je short terminate 137 00000053 3C1B cmp al, 1Bh ; ESC key 138 00000055 74D8 je short terminate 139 140 00000057 3C2B cmp al, '+' 141 00000059 7508 jne short _1 142 143 0000005B FE05[AC030000] inc byte [color] 144 00000061 EBE1 jmp short _0 145 _1: 146 00000063 3C2D cmp al, '-' 147 00000065 7508 jne short _2 148 149 00000067 FE0D[AC030000] dec byte [color] 150 0000006D EBD5 jmp short _0 151 _2: 152 0000006F 3C20 cmp al, 20h ; space 153 00000071 7509 jne short _3 154 00000073 8005[AC030000]08 add byte [color], 8 155 0000007A EBC8 jmp short _0 156 _3: 157 0000007C 80FC4B cmp ah, 4Bh 158 0000007F 7507 jne short _5 159 ; left arrow 160 _4: 161 00000081 E8DD000000 call beep 162 00000086 EBC1 jmp waitforkey 163 _5: 164 00000088 80FC4D cmp ah, 4Dh 165 0000008B 7502 jne short _6 166 167 ; right arrow 168 0000008D EBF2 jmp short _4 169 _6: 170 0000008F 80FC50 cmp ah, 50h 171 00000092 7502 jne short _7 172 ; down arrow 173 00000094 EBEB jmp short _4 174 _7: 175 00000096 80FC48 cmp ah, 48h 176 00000099 7502 jne short _8 177 ; up arrow 178 0000009B EBE4 jmp short _4 179 _8: 180 0000009D 663D0D1C cmp ax, 1C0Dh 181 000000A1 750E jne short _9 182 000000A3 E8BB000000 call beep 183 000000A8 8005[AC030000]04 add byte [color], 4 184 000000AF EB93 jmp short _0 185 _9: 186 000000B1 E8AD000000 call beep 187 000000B6 EB91 jmp waitforkey 188 189 print_msg: 190 000000B8 B40E mov ah, 0Eh 191 000000BA BB07000000 mov ebx, 7 192 ;mov bl, 7 ; char attribute & color 193 p_next_chr: 194 000000BF AC lodsb 195 000000C0 08C0 or al, al 196 000000C2 7404 jz short p_retn ; retn 197 000000C4 CD31 int 31h 198 000000C6 EBF7 jmp short p_next_chr 199 p_retn: 200 000000C8 C3 retn 201 202 drawsinewave: 203 ; INPUT: 204 ; sinustable 205 ; 206 ; Modified registers: esi, edi, eax, ecx, ebx, edx 207 208 ; fill _fx table by using sine wave table 209 ; x = 0 to 359 210 ; y = +128 to -128 211 ; +128 --> 255 -> screen row position = (256-255)+111 = 112 212 ; -128 --> 0 -> screen row position = (256-0)+111 = 367 213 214 000000C9 BE[42020000] mov esi, sinustable 215 000000CE BF[B4030000] mov edi, _fx 216 000000D3 31C0 xor eax, eax 217 000000D5 29DB sub ebx, ebx ; 0 ; x 218 000000D7 31ED xor ebp, ebp ; pixel count 219 000000D9 AC lodsb 220 000000DA EB43 jmp short _dsw_5 221 _dsw_0: 222 000000DC AC lodsb ; al = 256-y value 223 ; 224 000000DD 38C8 cmp al, cl ; [prevy] 225 000000DF 743E je short _dsw_5 226 000000E1 7217 jb short _dsw_3 227 _dsw_1: 228 000000E3 FEC1 inc cl ; previous 256-y 229 000000E5 38C8 cmp al, cl 230 000000E7 7636 jna short _dsw_5 231 ; ebx = x 232 ; eax = 256 - y 233 000000E9 E819000000 call _dsw_4 234 000000EE EBF3 jmp short _dsw_1 235 _dsw_2: 236 000000F0 50 push eax 237 000000F1 E859000000 call getpixeloffset 238 000000F6 AB stosd 239 000000F7 58 pop eax 240 000000F8 45 inc ebp ; increase pixel count 241 000000F9 C3 retn 242 _dsw_3: 243 000000FA FEC9 dec cl ; previous 256-y 244 000000FC 38C8 cmp al, cl 245 000000FE 731F jnb short _dsw_5 246 ; ebx = x 247 ; eax = 256 - y 248 00000100 E802000000 call _dsw_4 249 00000105 EBF3 jmp short _dsw_3 250 _dsw_4: 251 00000107 53 push ebx 252 00000108 8B1D[B0030000] mov ebx, [prevx] 253 0000010E 86C1 xchg al, cl ; [prevy] 254 00000110 E8DBFFFFFF call _dsw_2 255 00000115 86C8 xchg cl, al 256 00000117 5B pop ebx 257 00000118 FF05[B0030000] inc dword [prevx] 258 0000011E C3 retn 259 _dsw_5: 260 0000011F 891D[B0030000] mov [prevx], ebx ; previous x value 261 00000125 88C1 mov cl, al ; previous 256-y value 262 00000127 E8C4FFFFFF call _dsw_2 263 0000012C 43 inc ebx 264 0000012D 81FB68010000 cmp ebx, 360 ; x < 360 265 00000133 72A7 jb short _dsw_0 266 267 00000135 BE[B4030000] mov esi, _fx 268 ;mov edx, ebp 269 ; 270 ; edx = pixel count 271 ; esi = user's single color pixel buffer address 272 sys _video, 0305h, [color], ebp 272 <1> 272 <1> 272 <1> 272 <1> 272 <1> %if %0 >= 2 272 0000013A BB05030000 <1> mov ebx, %2 272 <1> %if %0 >= 3 272 0000013F 8B0D[AC030000] <1> mov ecx, %3 272 <1> %if %0 = 4 272 00000145 89EA <1> mov edx, %4 272 <1> %endif 272 <1> %endif 272 <1> %endif 272 00000147 B81F000000 <1> mov eax, %1 272 <1> 272 0000014C CD40 <1> int 40h 273 274 0000014E C3 retn 275 276 getpixeloffset: 277 ; ebx = x position 278 ; eax = 256 - y position 279 0000014F BA6F010000 mov edx, 256+111 ; 367 280 00000154 29C2 sub edx, eax ; convert row position from 256-y 281 ; row = (256-y)+111 282 00000156 B880020000 mov eax, 640 ; screen width 283 0000015B F7E2 mul edx 284 0000015D 01D8 add eax, ebx ; add x to y*640 285 0000015F 83C078 add eax, 480-360 ; add eax, 120 286 ; eax = pixel offset on display page 287 00000162 C3 retn 288 beep: 289 ; call beep function (16/64 second, 886Hz) 290 sys _audio, 16, 1331 290 <1> 290 <1> 290 <1> 290 <1> 290 <1> %if %0 >= 2 290 00000163 BB10000000 <1> mov ebx, %2 290 <1> %if %0 >= 3 290 00000168 B933050000 <1> mov ecx, %3 290 <1> %if %0 = 4 290 <1> mov edx, %4 290 <1> %endif 290 <1> %endif 290 <1> %endif 290 0000016D B820000000 <1> mov eax, %1 290 <1> 290 00000172 CD40 <1> int 40h 291 00000174 C3 retn 292 293 set_text_mode: 294 00000175 30E4 xor ah, ah 295 00000177 B003 mov al, 3 296 ;int 10h ; al = 03h text mode, int 10 video 297 00000179 CD31 int 31h ; TRDOS 386 - Video interrupt 298 0000017B C3 retn 299 300 program_msg: 301 0000017C 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Sine Wave" 301 00000185 2076322E302E33202D- 301 0000018E 202827737973766964- 301 00000197 656F27292054657374- 301 000001A0 2050726F6772616D20- 301 000001A9 2D2044726177205369- 301 000001B2 6E652057617665 302 000001B9 0D0A db 0Dh, 0Ah 303 000001BB 6279204572646F6761- db "by Erdogan Tan - 19/02/2021" 303 000001C4 6E2054616E202D2031- 303 000001CD 392F30322F32303231 304 ;db 0Dh, 0Ah, 0 305 000001D6 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 306 307 000001DA 557365205350414345- db "Use SPACE,ENTER,'+','-' keys to change COLOR .." 307 000001E3 2C454E5445522C272B- 307 000001EC 272C272D27206B6579- 307 000001F5 7320746F206368616E- 307 000001FE 676520434F4C4F5220- 307 00000207 2E2E 308 00000209 0D0A db 0Dh, 0Ah 309 0000020B 507265737320455343- db "Press ESC to exit .." 309 00000214 20746F206578697420- 309 0000021D 2E2E 310 0000021F 0D0A db 0Dh, 0Ah 311 00000221 0D0A db 0Dh, 0Ah 312 00000223 507265737320616E79- db "Press any key to continue .." 312 0000022C 206B657920746F2063- 312 00000235 6F6E74696E7565202E- 312 0000023E 2E 313 nextline: 314 0000023F 0D0A00 db 0Dh, 0Ah, 0 315 316 sinustable: ; sine wave table (x=0 to 639, y= +200 to -200) 317 ; 19/02/2021 318 ; https://daycounter.com/Calculators/Sine-Generator-Calculator2.phtml 319 ; 360x256 (x= 0 to 359, y = 0 to 255) 320 00000242 80828486888B8D8F91- db 128,130,132,134,136,139,141,143,145,147,150,152,154,156,158,160 320 0000024B 9396989A9C9EA0 321 00000252 A3A5A7A9ABADAFB1B3- db 163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193 321 0000025B B5B7B9BBBDBFC1 322 00000262 C3C5C7C9CACCCED0D1- db 195,197,199,201,202,204,206,208,209,211,213,214,216,218,219,221 322 0000026B D3D5D6D8DADBDD 323 00000272 DEE0E1E3E4E5E7E8E9- db 222,224,225,227,228,229,231,232,233,234,236,237,238,239,240,241 323 0000027B EAECEDEEEFF0F1 324 00000282 F2F3F4F5F6F7F7F8F9- db 242,243,244,245,246,247,247,248,249,249,250,251,251,252,252,253 324 0000028B F9FAFBFBFCFCFD 325 00000292 FDFDFEFEFEFFFFFFFF- db 253,253,254,254,254,255,255,255,255,255,255,255,255,255,255,255 325 0000029B FFFFFFFFFFFFFF 326 000002A2 FEFEFEFDFDFDFCFCFB- db 254,254,254,253,253,253,252,252,251,251,250,249,249,248,247,247 326 000002AB FBFAF9F9F8F7F7 327 000002B2 F6F5F4F3F2F1F0EFEE- db 246,245,244,243,242,241,240,239,238,237,236,234,233,232,231,229 327 000002BB EDECEAE9E8E7E5 328 000002C2 E4E3E1E0DEDDDBDAD8- db 228,227,225,224,222,221,219,218,216,214,213,211,209,208,206,204 328 000002CB D6D5D3D1D0CECC 329 000002D2 CAC9C7C5C3C1BFBDBB- db 202,201,199,197,195,193,191,189,187,185,183,181,179,177,175,173 329 000002DB B9B7B5B3B1AFAD 330 000002E2 ABA9A7A5A3A09E9C9A- db 171,169,167,165,163,160,158,156,154,152,150,147,145,143,141,139 330 000002EB 989693918F8D8B 331 000002F2 88868482807D7B7977- db 136,134,132,130,128,125,123,121,119,116,114,112,110,108,105,103 331 000002FB 7472706E6C6967 332 00000302 6563615F5C5A585654- db 101,99,97,95,92,90,88,86,84,82,80,78,76,74,72,70 332 0000030B 52504E4C4A4846 333 00000312 4442403E3C3A383635- db 68,66,64,62,60,58,56,54,53,51,49,47,46,44,42,41 333 0000031B 33312F2E2C2A29 334 00000322 27252422211F1E1C1B- db 39,37,36,34,33,31,30,28,27,26,24,23,22,21,19,18 334 0000032B 1A181716151312 335 00000332 11100F0E0D0C0B0A09- db 17,16,15,14,13,12,11,10,9,8,8,7,6,6,5,4 335 0000033B 08080706060504 336 00000342 040303020202010101- db 4,3,3,2,2,2,1,1,1,0,0,0,0,0,0,0 336 0000034B 00000000000000 337 00000352 000000000101010202- db 0,0,0,0,1,1,1,2,2,2,3,3,4,4,5,6 337 0000035B 02030304040506 338 00000362 06070808090A0B0C0D- db 6,7,8,8,9,10,11,12,13,14,15,16,17,18,19,21 338 0000036B 0E0F1011121315 339 00000372 1617181A1B1C1E1F21- db 22,23,24,26,27,28,30,31,33,34,36,37,39,41,42,44 339 0000037B 22242527292A2C 340 00000382 2E2F31333536383A3C- db 46,47,49,51,53,54,56,58,60,62,64,66,68,70,72,74 340 0000038B 3E40424446484A 341 00000392 4C4E50525456585A5C- db 76,78,80,82,84,86,88,90,92,95,97,99,101,103,105,108 341 0000039B 5F61636567696C 342 000003A2 6E70727477797B7D80 db 110,112,114,116,119,121,123,125,128 343 344 bss: 345 346 ABSOLUTE bss 347 348 000003AB alignb 4 349 350 000003AC color: resd 1 351 000003B0 prevx: resd 1 352 ;prevy: resd 1 353 354 bss_start: 355 000003B4 _fx: resd 640 ; for every X values from 0 to 639 356 00000DB4 resd 2048-640 ; used for repetitive x values for continuity 357 bss_end: