• Welcome to Dark Bit Factory & Gravity.
 

Assembly - Draw 2D sine wave

Started by Rbz, May 02, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Rbz

*** From DBF ezboard forum ***

rbraz
CBM 128

Posts: 152
(29/3/06 23:48)
Reply | Edit
Ã,  Assembly - Draw 2D sine wave
--------------------------------------------------------------------------------
Here a code for a simple sine wave (VGA mode X). Compile with FASMW 1.65

Hope its useful for someone...


;--------------------------------------------------------------------
org 100h

;-------------VGA mode X - 320x200x256k
mov al,13h
int 10h
push 0a000h ; Vga memory
pop es ;

;-------------- Palette
mov dx,3c8h
mov al,32 ;[col]
out dx,al
inc dx
mov al,63 ;[ r ]
out dx,al
mov al,40 ;[ g ]
out dx,al
mov al,0 ;[ b ]
out dx,al
;--------------

Main:

;-------------Wait for vertical retrace
mov dx,03DAh
.wait_for_retrace:
in al,dx
test al,8
jz .wait_for_retrace

;-------------Clear Screen
xor ax,ax
xor di,di
mov cx,16000
rep stosd

.draw:

;-------------Sine wave function
fld [angle]
fadd [one]
fst [angle]
fdiv [twopi]
fsin
fmul [mult]
fadd [ center ]
fistp [y]
mov ax,word [y]

mov bx,[x] ; bx = x

;-------------WritePixelFast :)
; vgamemory[x + (y*320)] = color ; bx=x, ax=y, cl=color
imul ax,320
add ax,bx
mov di,ax
mov byte [es:di],32 ; color = 32 or cl
mov ax,0 ; clear ax
mov bx,0 ; clear bx

;-------------Increments x pos
inc [x]
cmp [x],319
je .lp1
jmp .draw
.lp1:
mov [x],0
; mov [angle],0

;-------------Loop (While not key hit)
mov ah,01
int 16h
jz Main

;-------------Return to text mode
mov al,03h
int 10h

;-------------Exit to DOS
mov ax,4c00h
int 21h

;-------------Some variables
angle dd 0.0
one dd 0.25
mult dd 20.0
center dd 100.0
y dd 0.0
x dw 0
twopi dd 6.2830


Edited by: rbraz at: 29/3/06 23:51



QuoteThygrionÃ,  
DBF: Coder

Posts: 353
(10/4/06 2:54)
Reply
Ã,  Re: Assembly - Draw 2D sine wave
--------------------------------------------------------------------------------
you really need to begin tinycoding (try 256 or 512 bytes - nothing less is worth the time IMO) !!


--------------------------------------------------------------------------------

Finally 14!!

Quoterbraz
CBM 128

Posts: 159
(10/4/06 19:06)
Reply | Edit
Ã,  Re: Assembly - Draw 2D sine wave
--------------------------------------------------------------------------------
I just love tinycoding :)
Did you see my two ogl 1K prods?

I just need a good idea, and something that I can code in asm, of course :D



QuoteClyde RadcliffeÃ,  
Fuzzy Wuzzy

Posts: 18231
(10/4/06 21:41)
Reply
Ã,  Re: Assembly - Draw 2D sine wave
--------------------------------------------------------------------------------
We'll if its ideas then Ive plenty in store for us in Gravity land ;)Ã,  
Challenge Trophies Won:

Clyde

Thanks for the example Rbraz matey.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: