Page 1 of 1

[TI ASM] Non-aligned Sprite Displaying Algorithm

Posted: Wed 24 May, 2006 10:28 pm
by cjgone
Can someone analyze my sprite displaying routine. I'm sorry that I did not add really useful comments :\ It uses the exact pixel on the screen, not the x and y coordinates. I have yet to do that :l Accepting suggestions :)

.NOLIST
#define EQU .equ
#define equ .equ
#define END .end
#define end .end
#include "ti83plus.inc"
.LIST

.org 9D93h
.db $BB,$6D
; Sprite Displaying Routine
______ ld hl,(Pixel) ;------ exact pixel to display to
______ ld a,l
______and %00000111 ;----- find the remainder of hl \ 8
______ ld b,a ;----- load the reaminder into b
______ld a,(Sprite)
______ld h,a ;----- load the image that is to be displayed into h
______ ld a,(Sprite_2)
______ ld l,a ;----load the image that is to be displayed into l
______ ld a,1 ; use a as a counter
Loop:
______ srl h ; this is the bit offset
______ rr l
______ or a
______ cp b
______ jp z,Next
______ inc a
______ jp Loop
Next:
______ ld a,h
______ ld (Spr),a ; -------store the fixed h and l registers into memory
______ ld a,l
______ ld (Spr_2),a
______ ld hl,$9340 ; ------ld hl with the screen buffer equate of Plotsscreen
______ ld de,(Pixel)
______ srl d
______ rr e
______ or a ;---------- reset the carry flag
______ srl d ; --------divide the pixel by 8
______ rr e
______ or a
______ srl d
______ rr e
______ or a
______ add hl,de
______ ld a,(Spr) ;--------- retrieve the stored memory
______ ld (hl),a
______ inc hl
______ ld a,(Spr_2)
______ ld (hl),a
______ B_CALL(_Grbufcpy)
______ ret


Sprite:
______ .db %11111111
Sprite_2:
______.db %00000000
Spr:
______ .db %00000000
Spr_2:
______.db %00000000
Pixel:
______ .db 734 ;----- pixel

.end
end

Re: Non-aligned Sprite Displaying Algorithm

Posted: Thu 25 May, 2006 1:21 am
by Liazon
at least i can still edit :D

so no one can see how stupidly i forgot the difference between preprocessor absolute addressing, and variable program addressing :(

Posted: Thu 25 May, 2006 3:51 am
by tr1p1ea
I was wondering if you had tested that yet? There ar e a few errors that i can see, and the method is unknown to me. Unfortunately i dont have much time to test it for you right now.

A good idea would be to grab the ion source and study the 'ionPutSprite' routine.

There is also a tutorial on an unaligned sprite routine in the ASM in 28 Days guide, which can be found on ticalc.org.

Posted: Fri 26 May, 2006 10:44 pm
by cjgone
Hmmm, it did work. The only thing that I'm not sure about is ---ld hl,(Pixel)... I added that so it was not showing one value as (Pixel), is what the pixel is. I don't know why I made two sprite labels. Its a bit dumb, sorry. This is no stub asm.

Posted: Fri 26 May, 2006 10:57 pm
by cjgone
I'm pretty sure this routine should be common, since the addresses for the screen are 8-bit, which each contain 8-pixels. If you were using an exact pixel, you would need to divide that pixel by 8 to get the adress its on. The remainder of the division should be the bit offset of the sprite....

Posted: Sat 27 May, 2006 12:42 am
by tr1p1ea
That is true, you perform a % 8 to find the pixel offset for the byte and you divide by 8 to find that byte: PlotsScreen+((y*12)+(x/8)).

An 8x8 unaligned sprite routine is pretty common, just not using the same methodology you do. You should check out the ion source to find a more standard way to do it.

Posted: Sat 27 May, 2006 12:43 am
by threefingeredguy
You should shift the byte to the right Xvalue%8 times, write it to the correct X/8 and Y byte in the buffer, then get whatever was shifted off and write it to the next bit over. I can't code it out for you now, but a good idea would be to look at something like Movax's, Sigma's (asm in 28 days), or ion's sprite routines. They all (especially the 28 days one) explain and show how to do it.

Posted: Sat 27 May, 2006 3:31 am
by cjgone
:\ Are you saying that my routine is very inefficient?

Posted: Sat 27 May, 2006 3:47 am
by cjgone
Hmm, I'm going to go work on a more effiecient x and y coordinate displaying routine..

Posted: Sat 27 May, 2006 5:04 am
by threefingeredguy
Read the guides, that's what they are there for.

Posted: Sat 27 May, 2006 6:17 pm
by Liazon
And no double posting.