[TI-84 ASM] Can't get sprites to display

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
Nugget
New Member
Posts: 5
Joined: Fri 18 Jan, 2008 9:10 pm

[TI-84 ASM] Can't get sprites to display

Post by Nugget »

I came up with a sprite display routine for 8x8 sprites, which I believe is very similar to the one covered in LEARN TI ASM IN 28 DAYS. But, somehow, the sprite doesn't show up on the screen. It should draw a ball on the top left of the screen, but it just makes the screen blank. Could somebody look at my code and tell me what I missed? I get no errors when compiling. Just nothing displays on screen.

Code: Select all

.nolist
#define   EQU   .equ
#define   equ   .equ
#define   END   .end
#define   end   .end
#define   B_CALL   bcall
#include    "ti83plus.inc"
.list
.org    $9D93
	.DB    t2ByteTok, tAsmCmp
        
	bcall(_RunIndicOff)
	bcall(_GrBufClr)

	LD	A, 0
	LD	L, 0
	LD	IX, Sprite
	LD	B, 8

Sprite8x8:
	;a=x
	;l=y;
	;ix=sprite index
	;B = number of rows (8)
	LD	H, 0
	LD	D, H
	LD	E, L
	ADD	HL, HL	;Yx2
	ADD	HL, DE	;x3
	ADD	HL, HL	;x6
	ADD	HL, HL	;x12
	LD	E, A	;copy A
	SRL	E	;divide x by 8
	SRL	E
	SRL	E
	ADD	HL, DE
	LD	DE, plotSScreen
	ADD	HL, DE	;drawing location
	AND	%00000111	;A mod 8 = SHIFT
	LD	c, A		;copy A
	LD	DE, 12		;LOAD 12 TO DE	
	
_RowLoop:
	PUSH	BC		;SAVE BC (number of rows)
	LD	B, C		;Copy SHIFT TO B
	LD	C, (IX)		;Copy sprite index to C
	XOR	A		;Clear 2nd byte
_Shiftloop:	
	SRL	C		;shift C right
	RRA			;Catch carry to 2nd byte
	DJNZ	_Shiftloop	;repeatSHIFT times
	
	INC	HL		;Paste sprite to buffer
	LD	(HL), A		;PART 2
	DEC	HL
	LD	A, C		;PART 1
	LD	(HL), A

	ADD	HL, DE		;add 12 to buffer location
	INC	IX		;get next byte of sprite
	POP	BC		;get number of rows back
	DJNZ	_RowLoop	;If not done with rows, do again

	bcall(_GrBufCpy)

	
	RET
	
Sprite:
	.DB	%00111100
	.DB	%01111110
	.DB	%11110011
	.DB	%11100011
	.DB	%11000111
	.DB	%11001111
	.DB	%01111110
	.DB	%00111100
	

.end
.end	
Spencer
Extreme Poster
Posts: 346
Joined: Mon 17 Jan, 2005 8:56 am
Location: Indiana

Post by Spencer »

You have to skip the rotations if your shift is zero. Maybe replace with something like this

Code: Select all

_RowLoop:
   PUSH   BC      ;SAVE BC (number of rows)
   LD   B, C      ;Copy SHIFT TO B
   LD   C, (IX)      ;Copy sprite index to C
   XOR   A      ;Clear 2nd byte
   CP B
   JR Z,_SkipShift
_Shiftloop:   
   SRL   C      ;shift C right
   RRA         ;Catch carry to 2nd byte
   DJNZ   _Shiftloop   ;repeatSHIFT times 
_SkipShift:
Also remember that (hl) acts like just another 8-bit register, you can LD (HL),C.
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

--ROFL, Spencer beat me ... :D--

You've missed the ALIGNED cases. If the sprite is aligned to a byte boundry its x value will be a multiple of 8, meaning that the AND %00000111 will result in a 0 -- which of course when loaded into B for your shift loop will cause it to shift 256 times! (djnz decreases B *before* checking if its zero). Change your x input to 1 and it should draw correctly.

Just skip the shift loop on an aligned case.

One last thing, instructions like 'LD (HL),C' are perfectly valid, should save you some bytes/cycles. Also you could change DE to 11 and not worry about moving forward/back with plotsscreen ... if you get what i mean.

Code: Select all

   LD   DE, 11  
    
_RowLoop: 
   PUSH   BC      ;SAVE BC (number of rows) 
   LD   B, C      ;Copy SHIFT TO B 
   LD   C, (IX)      ;Copy sprite index to C 
   XOR   A      ;Clear 2nd byte 
   CP B
   JR Z,_Aligned
_Shiftloop:    
   SRL   C      ;shift C right 
   RRA         ;Catch carry to 2nd byte 
   DJNZ   _Shiftloop   ;repeatSHIFT times 
_Aligned:
    
   LD   (HL), C
   INC   HL 
   LD   (HL), A
At one stage you may also want to change it so that it OR's with the buffer or something too.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Post Reply