TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: JASEN BETTS
from: FERNANDO ARIEL GONT
date: 1998-03-24 19:47:00
subject: putsprit.asm

Hullo Jasen Betts, hope you are having a nice day!!
10-Mar-98 16:50:00, Jasen Betts wrote to FERNANDO ARIEL GONT
          Subject: putsprit.asm
 JB> I've taken out PUSH CX/POP CX because I couldn't see what they
 JB> did. lodsb/stosb/movsb don't modify CX, it takes REP to modify CX.
 JB> and I've split the end of the loop to save the inc/dec/stosb
First, thank you for your remarks....
The fact is that when I was reading your answer I found the code I had
posted very strange... I looked it up in my directory, and I got this code,
which is different from the one it seems I posted here (maybe that I had
modified the code and posted the old version)...
Well, here's the code I should have posted, WITH SOME MODIFICATIONS i've
made according to your message:
/* (PUTSPRIT.ASM)
putsprite proc public
;**************************************
; On entry:
; cx= y coordinate
; dx= x coordinate
; bl= columns
; bh= rows
; ds:si= pointer to sprite
; *************************************
        
MODECOLUMNS equ 320
; Preserve the contents of the registers.
        push ax
        push bx
        push cx
        push dx
        push bp
; es= video memory segment
        mov ax, 0a000h
        mov es, ax
; Here I calculate a number that'll be added to di, so that the beginning
; of the next row will be pointed
        mov bp, MODECOLUMNS
        mov ax, bx
        and ax, 11111111b
        sub bp, ax
; Now I calculate the value di will hold. (Its the address of first
; pixel where the sprite will be put)
        
        push dx
        mov ax, MODECOLUMNS
        mul cx
        pop dx
        add ax, dx
        mov di, ax
; cld, so that the index registers will be incremented.
        cld
        xor cx, cx
        mov cl, bh
; Wait for vertical retrace.
        mov dx, 3dah
waitfor1:
        in al, dx        
        and al, 8
        jz waitfor1
waitfor0:
        in al, dx
        and al, 8
        jnz waitfor0
; These nestled loops puts the sprite on the screen.
; the inner loop is based on the number of columns of the sprite.
; The outter is based on the number of rows.
loophere:
        push cx
        mov cl, bl
putrow:
        lodsb
        and al, al
        jz nextrow
        stosb
loop putrow
nextrow:
     inc di
        loop putrow        
        add di, bp
        pop cx
        loop loophere
; Restore the contents of the registers.
        pop bp
        pop dx
        pop cx
        pop bx
        pop ax
        ret
putsprite endp
*/
It's fairly optimized? (Or at least, not so inefficient)
Feel free to correct my code, if you want....
 JB> you could probably gain even more speed by storing the sprites in
 JB> a format that allowed you to write the "solid" bits with "rep
 JB> movsb" and skip the blank bits with "add di,cx", but this would
 JB> make them harder to edit.
What format would you suggest?
 -=> Yours sincerely, Fernando Ariel Gont <=-
e-mail: FGont@siscor.bibnal.edu.ar
e-mail "Good Stuff!" _*Magazine*_ : gstuff@siscor.bibnal.edu.ar
FidoNet: 4:900/470.10
Sk-Network (Argentina): Murdock's Point (200:201/300.27)
--- Terminate 5.00 UnReg(161)
---------------
* Origin: A:-Have you ever been TERMINATEd? B:-By whom,daddy? (4:900/470.10)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.