relsoft
Joined: 03 Apr 2006
Posts: 29
|
I was trying to figure out how to use procedures since the tutorial does not give me enough info, I hunted codes inside this forum and took it from there. :*) This uses precalculated sine tables from 0 to 512 instead of 0 to 2pi.
;sinwobble
;relsoft
;http://rel.betterwebber.com
org 100h
;*****************************************************************
;*****************************************************************
;*****************************************************************
zzzzzzztart: ;too much pocket books
call init13h ;set to 320*200*256
Mov ax,0a000h ;Vga seg
mov es, ax ;for blitting
;Mov ax,@data
;mov ds, ax ;data seg
call setpal
mov [frame], 0
MainLoop:
inc [frame]
call waitretrace ;ASM is *very^99999* fast
call wobble ;do the hustle!!!!
mov ah, 01h ; check for keypress
int 16h ; is a key waiting in the buffer?
Jz MainLoop
mov ah, 00h ; yes, so get the key
int 16h
call textmode
mov ah, 4ch
mov al, 00h
int 21h ; return to dos
;Initializes the screen to VGA 320x200x256
init13h:
mov ax, 0a000h ;load VGA segment(can't load
;directly to segment registers
mov es, ax ; es now points to the vga
mov ah, 00h ; set video mode
mov al, 13h ; mode 13h
int 10h ; we are now in 320x200x256
ret
;*****************************************************************
setpal:
mov dx, 03c8h ;palette write register
xor al, al ;start at color 0
cli ;disable interrupts
out dx, al ;send value
cld ;forward direction
inc dx ;0x3c9(write RGB values)
mov si, sintable
mov cx, 255 ;whole 256 colors
palloop:
mov bx, 255
sub bx, cx
shl bx,1
mov al, [ds:si+bx]
shr al,1
out dx, al ;red
shr bx,3 ;green
mov al, [ds:si+bx]
shl al,1 ;blue
shr al,1
out dx, al
mov bx, 255
sub bx, cx
mov al, [ds:si+bx]
shr al, 1
out dx, al ;than green
loop palloop ;go back if not 0
sti ; enable interrupts
ret
;*****************************************************************
;sets the screen to textmode
textmode:
mov ah, 00h ; set video mode
mov al, 03h ; mode 03h
int 10h ; enter 80x25x16 mode
ret
;*****************************************************************
;this waits for screen retrace/refresh or our demo being in ASM
;would as fast as an x-wing on steroids. :*)
waitretrace:
mov dx,03dah ;0x3da9 vertical retrace port
wret:
in al,dx
and al,08h ; is vga in retrace?
jnz wret
wref:
in al,dx
and al,08h ;is retrace finished?
jz wref
ret
;*****************************************************************
wobble:
mov di, 0
mov si, sintable
mov [ycounter], 0
mov ax, [frame]
and ax,1
cmp ax, 0
jne rotneg
mov [rot], 64
jmp y_loop
rotneg:
mov [rot], -64
y_loop:
;xsin = sins[(y + i) and 511]
xor bx, bx
mov bx, [ycounter]
add bx, [frame]
and bx, 511
mov al, [ds:si+bx]
mov [xsin], al
mov cx, 0
x_loop:
;col = (x + xsin) XOR (y + sins[(x + i + rot) and 511])
neg [rot]
mov bx, cx
add bx, [frame]
;sub bx, ycounter
add bx, [rot]
and bx, 511
xor ax, ax
mov al, [ds:si+bx]
add ax, [ycounter]
xor dx, dx
mov dl, [xsin]
add dx, cx
xor ax, dx
mov [es:di], al
inc di
inc cx
cmp cx, 319
jb x_loop
inc di
mov [es:di], al
inc [ycounter]
cmp [ycounter], 200
jb y_loop
ret
sintable db 0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 27, 28, 30
db 31, 33, 34, 36, 37, 39, 40, 42, 43, 45, 46, 48, 49, 50, 52, 53, 55, 56, 58, 59
db 60, 62, 63, 64, 66, 67, 68, 70, 71, 72, 74, 75, 76, 78, 79, 80, 81, 82, 84, 85
db 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106
db 106, 107, 108, 109, 110, 111, 111, 112, 113, 114, 114, 115, 116, 116, 117, 118, 118, 119, 119, 120
db 121, 121, 122, 122, 122, 123, 123, 124, 124, 125, 125, 125, 126, 126, 126, 126, 127, 127, 127, 127
db 127, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, 127, 127, 127, 127
db 127, 126, 126, 126, 126, 125, 125, 125, 124, 124, 123, 123, 122, 122, 122, 121, 121, 120, 119, 119
db 118, 118, 117, 116, 116, 115, 114, 114, 113, 112, 111, 111, 110, 109, 108, 107, 106, 106, 105, 104
db 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 89, 88, 87, 86, 85, 84, 82
db 81, 80, 79, 78, 76, 75, 74, 72, 71, 70, 68, 67, 66, 64, 63, 62, 60, 59, 58, 56
db 55, 53, 52, 50, 49, 48, 46, 45, 43, 42, 40, 39, 37, 36, 34, 33, 31, 30, 28, 27
db 25, 23, 22, 20, 19, 17, 16, 14, 13, 11, 9, 8, 6, 5, 3, 2, 0, -2, -3, -5
db -6, -8, -9, -11, -13, -14, -16, -17, -19, -20, -22, -23, -25, -27, -28, -30, -31, -33, -34, -36
db -37, -39, -40, -42, -43, -45, -46, -48, -49, -50, -52, -53, -55, -56, -58, -59, -60, -62, -63, -64
db -66, -67, -68, -70, -71, -72, -74, -75, -76, -78, -79, -80, -81, -82, -84, -85, -86, -87, -88, -89
db -91, -92, -93, -94, -95, -96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -106, -107, -108, -109
db -110, -111, -111, -112, -113, -114, -114, -115, -116, -116, -117, -118, -118, -119, -119, -120, -121, -121, -122, -122
db -122, -123, -123, -124, -124, -125, -125, -125, -126, -126, -126, -126, -127, -127, -127, -127, -127, -128, -128, -128
db -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -127, -127, -127, -127, -127, -126, -126, -126
db -126, -125, -125, -125, -124, -124, -123, -123, -122, -122, -122, -121, -121, -120, -119, -119, -118, -118, -117, -116
db -116, -115, -114, -114, -113, -112, -111, -111, -110, -109, -108, -107, -106, -106, -105, -104, -103, -102, -101, -100
db -99, -98, -97, -96, -95, -94, -93, -92, -91, -89, -88, -87, -86, -85, -84, -82, -81, -80, -79, -78
db -76, -75, -74, -72, -71, -70, -68, -67, -66, -64, -63, -62, -60, -59, -58, -56, -55, -53, -52, -50
db -49, -48, -46, -45, -43, -42, -40, -39, -37, -36, -34, -33, -31, -30, -28, -27, -25, -23, -22, -20
db -19, -17, -16, -14, -13, -11, -9, -8, -6, -5, -3, -2, 4
ycounter dw 0
xsin db 0
frame dw 0
rot dw 0
Now for the macros.
BTW, how do I set memory models in FASM. Like tiny, small, medium, etc and how do I define segments like .data and .code
Thanks!
_________________ Hello
|