Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASM FPU help...
#1
Hey guys, what am I doing wrong? I have to do this even if my freaking eyes hurt (for my nephew). arrghghghghghghgh!!!

1.
fbcode
Code:
xsin = sin((ycounter+ frame)/20)*10

asm code:

Code:
mov ax, ycounter
       add ax, frame
       cwde
       mov integer, eax
       fild integer                     ;st0 = y+i
       mov integer, 20
       fdiv integer                     ;st0=y+i/20
       fsin                                ;st0 = sin(st0)
       mov integer, 10
       fmul integer                    ;st0 = sin(st0)*10
       fistp integer
       fwait
       mov eax, integer
       mov xsin, ax

2.

fb:
Code:
col = (x + xsin) XOR (ycounter + (sin((x + frame + rot)/30)*60))
asm:
cx = x
xsin is the xsin caculated above

Code:
mov ax, cx
       add ax, frame
       add ax, rot
       cwde
       mov integer, eax
       fild integer              ;st0 = x + i + rot
       mov integer, 30
       fdiv integer             ;st0 = (x + 1 + rot)/30
       fsin
       mov integer, 60
       fmul integer            ;st0=sin(st0)*60
       fistp integer
       fwait
       mov eax, integer
       add ax, ycounter

       mov dx, xsin
       add dx, cx
       xor ax, dx
       mov es:[di], al

Thanks!!

In case your wondering, here's the version that used a sintable. But my nephew has to type the darn thing on his lab as they are not allowed to bring diskettes. Typing those numbers would be stupid.

original asm codeSadAssemble with tasm)

Code:
;*****************************************************************
; sine wobble by rel
; Assemble with TASM
; TASM Floor.ASM
; Tlink Floor.Obj
;
;
;    Http://Rel.Betterwebber.com
;*****************************************************************
.Model TINY                ;<64 kb code and data
.Stack 200h                ;512 bytes of stack
.386                    ;don't tell you're still using a 286

.data

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

.Code                    ;start code seg

;*****************************************************************
;Initializes the screen to VGA 320x200x256

init13h   proc
   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
init13h   endp

;*****************************************************************
setpal     proc
   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, offset 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
setpal  endp

;*****************************************************************
;sets the screen to textmode

textmode         proc
   mov   ah, 00h                       ; set video mode
   mov   al, 03h                       ; mode 03h
   int   10h                           ; enter 80x25x16 mode
   ret
textmode         endp

;*****************************************************************
;this waits for screen retrace/refresh or our demo being in ASM
;would as fast as an x-wing on steroids. :*)

waitretrace proc
        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
waitretrace endp


;*****************************************************************
;The heart of the program
;a pseudo 3d(Snes Mode7) direct to video screen blit
;the comments would explain most of how the code works


wobble Proc

       mov di, 0
       mov si, offset 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

wobble Endp



;*****************************************************************
;*****************************************************************
;*****************************************************************

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

END zzzzzzztart
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#2
Solved!!!

Code:
;*****************************************************************
; sine wobble by rel
; Assemble with TASM
; TASM sinfpu.ASM
; Tlink sinfpu.Obj
; uses the FPU now
;
;    Http://Rel.Betterwebber.com
;*****************************************************************
.Model TINY                ;<64 kb code and data
.Stack 200h                ;512 bytes of stack
.386                    ;don't tell you're still using a 286

.data


ycounter  dw  0
xsin      dw  0
frame     dw  0
rot       dw  0
rad       dd  0.0
integer   dd  0
real4     dd  0.0
ishort    dw  0



.Code                    ;start code seg

;*****************************************************************
;Initializes the screen to VGA 320x200x256

init13h   proc
   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
init13h   endp

degtorad macro deg
    mov ishort, deg
    fild ishort
    fldpi
    fstp real4
    fmul real4                         ;deg * pi
    mov word ptr[ishort], 180
    fild ishort
    fstp real4
    fdiv real4
    fstp real4
    fwait
endm degtorad

;*****************************************************************
setpal     proc
   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, offset sintable
   mov cx, 255                ;whole 256 colors
   palloop:
        mov bx, 255
        sub bx, cx
        shl bx,1
        degtorad bx
        fld real4
        fsin
        mov word ptr[ishort], 64
        fild ishort
        fstp real4
        fmul real4
        fistp ishort
        fwait
        mov ax, ishort
       out  dx, al            ;red
       shl al,1            ;blue

       out  dx, al
        shr al, 2
       out  dx, al            ;than green

   loop palloop                ;go back if not 0
   sti                                  ; enable interrupts
   ret
setpal  endp

;*****************************************************************
;sets the screen to textmode

textmode         proc
   mov   ah, 00h                       ; set video mode
   mov   al, 03h                       ; mode 03h
   int   10h                           ; enter 80x25x16 mode
   ret
textmode         endp

;*****************************************************************
;this waits for screen retrace/refresh or our demo being in ASM
;would as fast as an x-wing on steroids. :*)

waitretrace proc
        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
waitretrace endp


;*****************************************************************
;The heart of the program
;a pseudo 3d(Snes Mode7) direct to video screen blit
;the comments would explain most of how the code works


wobble Proc

       fninit
       mov di, 0
       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 = sin((y + i)/20)*10
       xor ax, ax
       mov ax, ycounter
       add ax, frame
       mov ishort, ax
       fild ishort                     ;st0 = y+i
       mov ax, 20
       mov ishort, ax
       fild ishort
       fstp real4
       fdiv real4                     ;st0=y+i/20
       fsin                             ;st0 = sin(st0)
       mov ax, 10
       mov ishort, ax
       fild ishort
       fstp real4
       fmul real4                     ;st0 = sin(st0)*10
       fistp ishort
       fwait
       mov ax, ishort
       mov xsin, ax
       mov cx, 0
x_loop:
       ;col = (x + xsin) XOR (y + (sin((x + i)/130)*60))
       neg rot
       mov ax, cx
       add ax, frame
       add ax, rot
       mov ishort, ax
       fild ishort             ;st0 = x + i + rot
       mov ax, 130
       mov ishort, ax
       fild ishort
       fstp real4
       fdiv real4             ;st0 = (x + 1 + rot)/30
       fsin
       mov ax, 60
       mov ishort, ax
       fild ishort
       fstp real4
       fmul real4             ;st0=sin(st0)*60
       fistp ishort
       fwait
       mov ax, ishort
       add ax, ycounter

       mov dx, 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

wobble Endp



;*****************************************************************
;*****************************************************************
;*****************************************************************

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

END zzzzzzztart
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
Thus you have proven that the only person smart enough to solve rel's complicated programming problems is but himself. :rotfl:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)