1 ; **************************************************************************** 2 ; sinus2.s - TRDOS 386 (TRDOS v2.0.3) Test Program - 'sysvideo' pixel tests 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 19/02/2021 6 ; 7 ; **************************************************************************** 8 ; nasm sinus2.s -l sinus2.txt -o SINUS2.PRG -Z error.txt 9 ; (modified from 'sinus1.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[2C030000] mov edi, bss_start 92 00000005 B900040000 mov ecx, (bss_end - bss_start)/4 93 ;xor eax, eax 94 0000000A F3AB rep stosd 95 96 ; program message 97 0000000C BE[1E010000] mov esi, program_msg 98 00000011 E895000000 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 00000020 EB0E jmp short mode_13h_set_ok 114 115 terminate: 116 00000022 E8F0000000 call set_text_mode 117 sys _exit 117 <1> 117 <1> 117 <1> 117 <1> 117 <1> %if %0 >= 2 117 <1> mov ebx, %2 117 <1> %if %0 >= 3 117 <1> mov ecx, %3 117 <1> %if %0 = 4 117 <1> mov edx, %4 117 <1> %endif 117 <1> %endif 117 <1> %endif 117 00000027 B801000000 <1> mov eax, %1 117 <1> 117 0000002C CD40 <1> int 40h 118 halt: 119 0000002E EBFE jmp short halt 120 121 mode_13h_set_ok: 122 00000030 C605[24030000]1C mov byte [color], 28 ; initial pixel color 123 _0: 124 00000037 E880000000 call drawsinewave 125 waitforkey: 126 ;mov ah, 1 127 ;int 32h 128 ;jz short getkey 129 ;inc word [counter] 130 ;nop 131 ;nop 132 ;nop 133 ;jmp short waitforkey 134 getkey: 135 0000003C 30E4 xor ah, ah 136 0000003E CD32 int 32h 137 138 00000040 663D032E cmp ax, 2E03h 139 00000044 74DC je short terminate 140 00000046 3C1B cmp al, 1Bh ; ESC key 141 00000048 74D8 je short terminate 142 143 0000004A 3C2B cmp al, '+' 144 0000004C 7508 jne short _1 145 146 0000004E FE05[24030000] inc byte [color] 147 00000054 EBE1 jmp short _0 148 _1: 149 00000056 3C2D cmp al, '-' 150 00000058 7508 jne short _2 151 152 0000005A FE0D[24030000] dec byte [color] 153 00000060 EBD5 jmp short _0 154 _2: 155 00000062 3C20 cmp al, 20h ; space 156 00000064 7509 jne short _3 157 00000066 8005[24030000]08 add byte [color], 8 158 0000006D EBC8 jmp short _0 159 _3: 160 0000006F 80FC4B cmp ah, 4Bh 161 00000072 7507 jne short _5 162 ; left arrow 163 _4: 164 00000074 E88C000000 call beep 165 00000079 EBC1 jmp waitforkey 166 _5: 167 0000007B 80FC4D cmp ah, 4Dh 168 0000007E 7502 jne short _6 169 170 ; right arrow 171 00000080 EBF2 jmp short _4 172 _6: 173 00000082 80FC50 cmp ah, 50h 174 00000085 7502 jne short _7 175 ; down arrow 176 00000087 EBEB jmp short _4 177 _7: 178 00000089 80FC48 cmp ah, 48h 179 0000008C 7502 jne short _8 180 ; up arrow 181 0000008E EBE4 jmp short _4 182 _8: 183 00000090 663D0D1C cmp ax, 1C0Dh 184 00000094 750E jne short _9 185 00000096 E86A000000 call beep 186 0000009B 8005[24030000]04 add byte [color], 4 187 000000A2 EB93 jmp short _0 188 _9: 189 000000A4 E85C000000 call beep 190 000000A9 EB91 jmp waitforkey 191 192 print_msg: 193 000000AB B40E mov ah, 0Eh 194 000000AD BB07000000 mov ebx, 7 195 ;mov bl, 7 ; char attribute & color 196 p_next_chr: 197 000000B2 AC lodsb 198 000000B3 08C0 or al, al 199 000000B5 7404 jz short p_retn ; retn 200 000000B7 CD31 int 31h 201 000000B9 EBF7 jmp short p_next_chr 202 p_retn: 203 000000BB C3 retn 204 205 drawsinewave: 206 ; INPUT: 207 ; sinustable 208 ; 209 ; Modified registers: esi, edi, eax, ecx, ebx, edx 210 211 ; fill _fx table by using sine wave table 212 ; x = 0 to 319 213 ; y = +99 to -99 214 ; +99 --> 197 -> screen row position = 198-197 = 1 215 ; -99 --> 0 -> screen row position = 198-0 = 198 216 217 000000BC BE[E4010000] mov esi, sinustable 218 000000C1 BF[2C030000] mov edi, _fx 219 ;xor eax, eax 220 000000C6 29DB sub ebx, ebx ; 0 ; x 221 000000C8 31ED xor ebp, ebp ; pixel count 222 ;lodsb 223 ;jmp short _dsw_5 224 _dsw_0: 225 ;xor eax, eax 226 000000CA AC lodsb ; al = 198-y value 227 ; 228 ;cmp al, cl ; [prevy] 229 ;je short _dsw_5 230 ;jb short _dsw_3 231 ;_dsw_1: 232 ;inc cl ; previous 198-y 233 ;cmp al, cl 234 ;jna short _dsw_5 235 ;; ebx = x 236 ;; eax = 198 - y 237 ;call _dsw_4 238 ;jmp short _dsw_1 239 ;_dsw_2: 240 ;push eax 241 ;call getpixeloffset 242 ;stosd 243 ;pop eax 244 ;inc ebp ; increase pixel count 245 ;retn 246 ;_dsw_3: 247 ;dec cl ; previous 198-y 248 ;cmp al, cl 249 ;jnb short _dsw_5 250 ;; ebx = x 251 ;; eax = 198 - y 252 ;call _dsw_4 253 ;jmp short _dsw_3 254 ;_dsw_4: 255 ;push ebx 256 ;mov ebx, [prevx] 257 ;xchg al, cl ; [prevy] 258 ;call _dsw_2 259 ;xchg cl, al 260 ;pop ebx 261 ;inc dword [prevx] 262 ;retn 263 ;_dsw_5: 264 ;mov [prevx], ebx ; previous x value 265 ;mov cl, al ; 0 ; previous 198-y value 266 ;call _dsw_2 267 268 000000CB E825000000 call getpixeloffset 269 000000D0 AB stosd 270 000000D1 45 inc ebp ; increase pixel count 271 272 000000D2 43 inc ebx 273 000000D3 81FB40010000 cmp ebx, 320 274 000000D9 72EF jb short _dsw_0 275 276 000000DB BE[2C030000] mov esi, _fx 277 ;mov edx, ebp 278 ; 279 ; edx = pixel count 280 ; esi = user's single color pixel buffer address 281 sys _video, 0305h, [color], ebp 281 <1> 281 <1> 281 <1> 281 <1> 281 <1> %if %0 >= 2 281 000000E0 BB05030000 <1> mov ebx, %2 281 <1> %if %0 >= 3 281 000000E5 8B0D[24030000] <1> mov ecx, %3 281 <1> %if %0 = 4 281 000000EB 89EA <1> mov edx, %4 281 <1> %endif 281 <1> %endif 281 <1> %endif 281 000000ED B81F000000 <1> mov eax, %1 281 <1> 281 000000F2 CD40 <1> int 40h 282 283 000000F4 C3 retn 284 285 getpixeloffset: 286 ; ebx = x position 287 ; eax = 198 - y position 288 ;mov edx, 198 289 000000F5 31D2 xor edx, edx 290 000000F7 B2C6 mov dl, 198 291 ;sub edx, eax 292 000000F9 28C2 sub dl, al 293 000000FB B840010000 mov eax, 320 ; screen width 294 00000100 F7E2 mul edx 295 00000102 01D8 add eax, ebx ; add x to y*320 296 ; eax = pixel offset on display page 297 00000104 C3 retn 298 beep: 299 ; call beep function (16/64 second, 886Hz) 300 sys _audio, 16, 1331 300 <1> 300 <1> 300 <1> 300 <1> 300 <1> %if %0 >= 2 300 00000105 BB10000000 <1> mov ebx, %2 300 <1> %if %0 >= 3 300 0000010A B933050000 <1> mov ecx, %3 300 <1> %if %0 = 4 300 <1> mov edx, %4 300 <1> %endif 300 <1> %endif 300 <1> %endif 300 0000010F B820000000 <1> mov eax, %1 300 <1> 300 00000114 CD40 <1> int 40h 301 00000116 C3 retn 302 303 set_text_mode: 304 00000117 30E4 xor ah, ah 305 00000119 B003 mov al, 3 306 ;int 10h ; al = 03h text mode, int 10 video 307 0000011B CD31 int 31h ; TRDOS 386 - Video interrupt 308 0000011D C3 retn 309 310 program_msg: 311 0000011E 5452444F5320333836- db "TRDOS 386 v2.0.3 - ('sysvideo') Test Program - Draw Sine Wave" 311 00000127 2076322E302E33202D- 311 00000130 202827737973766964- 311 00000139 656F27292054657374- 311 00000142 2050726F6772616D20- 311 0000014B 2D2044726177205369- 311 00000154 6E652057617665 312 0000015B 0D0A db 0Dh, 0Ah 313 0000015D 6279204572646F6761- db "by Erdogan Tan - 19/02/2021" 313 00000166 6E2054616E202D2031- 313 0000016F 392F30322F32303231 314 ;db 0Dh, 0Ah, 0 315 00000178 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 316 317 0000017C 557365205350414345- db "Use SPACE,ENTER,'+','-' keys to change COLOR .." 317 00000185 2C454E5445522C272B- 317 0000018E 272C272D27206B6579- 317 00000197 7320746F206368616E- 317 000001A0 676520434F4C4F5220- 317 000001A9 2E2E 318 000001AB 0D0A db 0Dh, 0Ah 319 000001AD 507265737320455343- db "Press ESC to exit .." 319 000001B6 20746F206578697420- 319 000001BF 2E2E 320 000001C1 0D0A db 0Dh, 0Ah 321 000001C3 0D0A db 0Dh, 0Ah 322 000001C5 507265737320616E79- db "Press any key to continue .." 322 000001CE 206B657920746F2063- 322 000001D7 6F6E74696E7565202E- 322 000001E0 2E 323 nextline: 324 000001E1 0D0A00 db 0Dh, 0Ah, 0 325 326 sinustable: ; sine wave table (x=0 to 319, y= +99 to -99) 327 ; 19/02/2021 328 ; https://daycounter.com/Calculators/Sine-Generator-Calculator2.phtml 329 ; 320x198 (x= 0 to 319, y = 0 to 197) 330 000001E4 636466686A6C6E7072- db 99,100,102,104,106,108,110,112,114,116,118,120,121,123,125,127 330 000001ED 747678797B7D7F 331 000001F4 81838586888A8C8D8F- db 129,131,133,134,136,138,140,141,143,145,147,148,150,152,153,155 331 000001FD 9193949698999B 332 00000204 9C9E9FA1A2A4A5A7A8- db 156,158,159,161,162,164,165,167,168,170,171,172,173,175,176,177 332 0000020D AAABACADAFB0B1 333 00000214 B2B3B4B5B6B7B8B9BA- db 178,179,180,181,182,183,184,185,186,187,188,189,190,190,191,192 333 0000021D BBBCBDBEBEBFC0 334 00000224 C0C1C1C2C2C3C3C3C4- db 192,193,193,194,194,195,195,195,196,196,196,197,197,197,197,197 334 0000022D C4C4C5C5C5C5C5 335 00000234 C5C5C5C5C5C5C4C4C4- db 197,197,197,197,197,197,196,196,196,195,195,195,194,194,193,193 335 0000023D C3C3C3C2C2C1C1 336 00000244 C0C0BFBEBEBDBCBBBA- db 192,192,191,190,190,189,188,187,186,185,184,183,182,181,180,179 336 0000024D B9B8B7B6B5B4B3 337 00000254 B2B1B0AFADACABAAA8- db 178,177,176,175,173,172,171,170,168,167,165,164,162,161,159,158 337 0000025D A7A5A4A2A19F9E 338 00000264 9C9B9998969493918F- db 156,155,153,152,150,148,147,145,143,141,140,138,136,134,133,131 338 0000026D 8D8C8A88868583 339 00000274 817F7D7B7978767472- db 129,127,125,123,121,120,118,116,114,112,110,108,106,104,102,100 339 0000027D 706E6C6A686664 340 00000284 63615F5D5B59575553- db 99,97,95,93,91,89,87,85,83,81,79,77,76,74,72,70 340 0000028D 514F4D4C4A4846 341 00000294 4442403F3D3B393836- db 68,66,64,63,61,59,57,56,54,52,50,49,47,45,44,42 341 0000029D 3432312F2D2C2A 342 000002A4 292726242321201E1D- db 41,39,38,36,35,33,32,30,29,27,26,25,24,22,21,20 342 000002AD 1B1A1918161514 343 000002B4 131211100F0E0D0C0B- db 19,18,17,16,15,14,13,12,11,10,9,8,7,7,6,5 343 000002BD 0A090807070605 344 000002C4 050404030302020201- db 5,4,4,3,3,2,2,2,1,1,1,0,0,0,0,0 344 000002CD 01010000000000 345 000002D4 000000000000010101- db 0,0,0,0,0,0,1,1,1,2,2,2,3,3,4,4 345 000002DD 02020203030404 346 000002E4 050506070708090A0B- db 5,5,6,7,7,8,9,10,11,12,13,14,15,16,17,18 346 000002ED 0C0D0E0F101112 347 000002F4 1314151618191A1B1D- db 19,20,21,22,24,25,26,27,29,30,32,33,35,36,38,39 347 000002FD 1E202123242627 348 00000304 292A2C2D2F31323436- db 41,42,44,45,47,49,50,52,54,56,57,59,61,63,64,66 348 0000030D 38393B3D3F4042 349 00000314 4446484A4C4D4F5153- db 68,70,72,74,76,77,79,81,83,85,87,89,91,93,95,97 349 0000031D 5557595B5D5F61 350 bss: 351 352 ABSOLUTE bss 353 354 alignb 4 355 356 00000324 color: resd 1 357 00000328 prevx: resd 1 358 ;prevy: resd 1 359 360 bss_start: 361 0000032C _fx: resd 320 ; for every X values from 0 to 319 362 0000082C resd 1024-320 ; used for repetitive x values for continuity 363 bss_end: