Author Topic: Assembly - Draw 2D sine wave  (Read 4456 times)

0 Members and 1 Guest are viewing this topic.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Assembly - Draw 2D sine wave
« on: May 02, 2006 »
*** From DBF ezboard forum ***

Code: [Select]
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

 
Quote
Thygrion  
 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!!

Quote
rbraz
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


 
Quote
Clyde 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 ;)Â  
« Last Edit: May 02, 2006 by Rbraz »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Assembly - Draw 2D sine wave
« Reply #1 on: September 19, 2006 »
Thanks for the example Rbraz matey.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: