Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong??? ASM...
#1
Unoptimized code...

water works fine but refrac sucks.

Water:
works pefectly!!!

Code:
.MODEL MEDIUM,BASIC
.STACK 30H
.386
.CODE

;SUB Water(BYVAL DESTSEG%,BYVAL SourceSeg%,)
;STACK
;DEST SEG       =10
;SourceSeg      =8  
;RET SEG        =6
;RET OFF        =4
;BP             =2
;DS             =0


;DS:SI      =Source SEG:Source OFF   buffer 1
;ES:DI      =DEST SEG:DEST OFF       buffer 2

ALIGN 2

PUBLIC Water
Water PROC

PUSH BP
PUSH DS


MOV BP,SP       ;Save BP

Mov ax,[Bp+10]  ;Put address of dest to ES
Mov bx,[Bp+08]  ;Put address of source to DS
Mov es,ax
Mov ds,bx
Mov si,320      ;non-edge pixel
Mov di,320

Mov cx,320

Lbl_Main_loop:
    xor ax,ax
    xor bx,bx
    mov bl,ds:[si+1]
    mov ax,bx
    mov bl,ds:[si-1]
    add ax,bx
    mov bl,ds:[si+320]
    add ax,bx
    mov bl,ds:[si-320]
    add ax,bx
    shr ax,1
    mov bl,es:[di]
    xor bh,bh
    sub ax,bx
    mov dx,ax
    shr dx,5
    sub ax,dx
    cmp ax,0
    jg Lbl_Skip_Neg
        neg ax
    Lbl_Skip_Neg:
    mov es:[di],al

    inc si
    inc di
    inc cx
    cmp cx,63680

Jbe Lbl_Main_loop



POP DS      ;RESTORE DS
POP BP      ;RESTORE BP


RET 4


Water ENDP

END


refraction:
Working but the're are some displacement

Code:
.MODEL MEDIUM,BASIC
.STACK 30H
.386
.CODE

;SUB Refrac(BYVAL DESTSEG%,BYVAL SourceSeg%, byval TextSeg%)
;STACK
;DEST SEG       =12
;SourceSeg      =10
;TextSeg        =8  
;RET SEG        =6
;RET OFF        =4
;BP             =2
;DS             =0
;temp           =-2
;temp           =-4

;ES:DI      =Dest SEG:Dest OFF       Vpage
;DS:SI      =source SEG:source OFF   buffer 1
;fS:SI      =Text SEG:Text OFF       texture 1


ALIGN 2

PUBLIC Refrac
Refrac PROC

PUSH BP
PUSH DS


MOV BP,SP       ;Save BP

Mov ax,[Bp+12]  ;Put address of Vpage to ES
Mov bx,[Bp+10]  ;Put address of Buffer to DS
mov cx,[bp+8]
Mov es,ax
Mov ds,bx
mov fs,cx
xor si,si      
xor di,di

Xor Eax,Eax
push Eax

;Cx=Xloop
;bl=Yloop

xor bx,bx
xor cx,cx


Lbl_Y_loop:
    xor cx,cx
Lbl_Main_loop:

    mov al,ds:[si+1]            ;xoff
    sub al,ds:[si]                    
    mov ah,ds:[si+320]          ;yoff
    sub ah,ds:[si]
    shr al,2                    ;al= xoff\4
    shr ah,2                    ;ah= yoff\4
    mov [bp-2],ax               ;save ax
    xchg ah,al                  ;swap so we could use ax
    xor ah,ah                   ;zero out high byte
    mov dx,ax                   ;put value in dx
    add dx,cx                   ;dx=Xt = X + Yoff \ 4
    mov [bp-4],cx               ;save counter
    mov ax,[bp-2]               ;restore
    xor ah,ah                   ;zero out ah
    mov cx,ax                   ;mov Y to cx
    xor bh,bh                   ;zero out bh
    add cx,bx                   ;cx=yt = y + xoff \ 4
    mov gs,si                   ;save si

                                ;cx=yt;dx=xt
                                ;calc offset in texture
    xor si,si        
    xchg ch,cl                  ;shl cx,8
    mov si,cx                   ;si=Y*256
    shr si,2                    ;si=Y*256/4=64
    add si,cx                   ;si=64+256 =320 :P  
    add si,dx                   ;si=Y*320+X

    mov bh,fs:[si]              ;get texture

    mov es:[di],bh              ;plot to layer
        
    mov si,gs                   ;restore si
    mov cx,[bp-4]               ;restore cx
    inc si
    inc di
    inc cx
    cmp cx,319
Jbe Lbl_Main_loop
    inc bl
    cmp bl,198
Jbe Lbl_Y_loop



add sp,4

POP DS      ;RESTORE DS
POP BP      ;RESTORE BP


RET 6


Refrac ENDP

END

Original QB code:

Code:
DEFINT A-Z

REM $DYNAMIC

DIM Vpage(32001) AS INTEGER             'The Screen
DIM TextPage(32001) AS INTEGER          'Texture
DIM Wpage1(32001) AS INTEGER            'Ripple
DIM Wpage2(32001) AS INTEGER            'Ripple


Vpage(0) = 2560
Vpage(1) = 200
Vseg = VARSEG(Vpage(0))
Voff = VARPTR(Vpage(2))

TextPage(0) = 2560
TextPage(1) = 200
TextSeg = VARSEG(TextPage(0))
TextOff = VARPTR(TextPage(2))

Wpage1(0) = 2560
Wpage1(1) = 200
Wseg1 = VARSEG(Wpage1(0))
Woff1 = VARPTR(Wpage1(2))

Wpage2(0) = 2560
Wpage2(1) = 200
Wseg2 = VARSEG(Wpage2(0))
Woff2 = VARPTR(Wpage2(2))


CLS
SCREEN 13


'our Nasty Texture

FOR X = 0 TO 319
    FOR Y = 0 TO 199
        PSET (X, Y), (X OR Y) AND 255
NEXT Y, X

GET (0, 0)-(319, 199), TextPage(0)          'Get texture

Frames& = 0
DO

  Frames& = Frames& + 1
  IF Frames& AND 3 THEN                     'Poke a pixel
      DEF SEG = Wseg1                       'To start a ripple
      POKE Woff1 + (63195 * RND), 255
  END IF

  SWAP Wseg1, Wseg2                         'Magic
  SWAP Woff1, Woff2

  Ptr = 320 + Woff1
  Ptr2 = 320 + Woff2

                                            'Do ripple
  FOR I& = 320 TO 63680
    DEF SEG = Wseg1
    C% = PEEK(Ptr + 1) + PEEK(Ptr - 1) + PEEK(Ptr + 320) + PEEK(Ptr - 320)
    DEF SEG = Wseg2
    C% = (C% \ 2) - PEEK(Ptr2)
    C% = ABS(C% - C% \ 256)
    POKE Ptr2, C%
   Ptr = Ptr + 1
   Ptr2 = Ptr2 + 1
  NEXT I&

  Ptr = Woff1
  PtrVpage = Voff


  FOR Y = 0 TO 198
  FOR X = 0 TO 319
    DEF SEG = Wseg1
     Xoff = PEEK(Ptr + 1) - PEEK(Ptr)                 'Shading
     Yoff = PEEK(Ptr + 320) - PEEK(Ptr)
    DEF SEG = TextSeg
     Xt = X + Yoff \ 4
     Yt = Y + Xoff \ 4
     C = PEEK((320 * Yt) + Xt)
    DEF SEG = Vseg                                 'Poke to screen
     POKE PtrVpage, C
     Ptr = Ptr + 1
     PtrVpage = PtrVpage + 1
  NEXT X
  NEXT Y


  PUT (0, 0), Vpage(0), PSET                        'Blite screen
LOOP UNTIL LEN(INKEY$)


CLS
SCREEN 0
WIDTH 80
END
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)