[TI-84 ASM] 8x8 tile routine

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] 8x8 tile routine

Post by Nugget »

I've put together some code to draw 96 8x8 tiles to the screen (the entire 8 rows and 12 columns) However, it does not DO anything, and clears my RAM when I exit. My approach was to draw each COLUMN in succession because each individual tile was drawn top to bottom as well. Anybody care to analyze my code, and possibly give pointers on any optimization?

Code: Select all

.nolist
#define   EQU   .equ
#define   equ   .equ
#define   END   .end
#define   end   .end
#define   b_call B_CALL
#include    "ti83plus.inc"
.list
.org    $9D93
	.db    t2ByteTok, tAsmCmp

	CALL	DrawTile

DrawTile:

	;IX = Screen Address
	;DE = Map address
	;HL = Sprite address
	;B = Counter
	;C = Column Counter

	LD	IX, plotSscreen	;get starting screen address
	LD	DE, map+1	;get location of map file
				;get value of first map file item
	LD	A, (DE)		;get tile from the map value
	LD	H, 0
	LD	L, A
	LD	BC, tiles
	ADD	HL, BC		;add the tile location

	LD	C, 0
	LD	B, 12
	PUSH	BC
	LD	B, 8
	PUSH	BC
	JR	_SpriteRowLoop

_NextColumn:

	INC	C
	PUSH	BC
	LD	B, 0
	LD	IX, plotSscreen
	ADD	IX, BC	

_NextRow:
	
	INC	DE		;get next tile from map
	LD	A, (DE)
	LD	L, A		;get tile from the map value
	LD	H, 0
	PUSH	DE
	LD	DE, tiles
	ADD	HL, DE		;add the tile location
	POP DE
	LD	B, 8
	
_SpriteRowLoop:
	LD	A, (HL)
	LD	(IX), A		;draw sprite
	
	PUSH	DE
	LD	DE, 12
	ADD	IX, DE
	POP	DE
	INC	HL
	DJNZ	_SpriteRowLoop

	POP	BC
	DJNZ	_NextRow

	POP	BC
	DJNZ	_NextColumn

	bcall(_GrBufCpy)

	RET
	

;get next row, repeat above 4 steps 8 times
;get next column, repeat above 5 steps 12 times
;WIN





map:
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8
	.DB	1,2,3,4,5,6,7,8

tiles:
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110
	.DB	%10110110

.end
.end
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Got the bug:
You forgot a push bc between _NextRow and _SpriteRowLoop

Most of the time when a program fails to quit (or a routine) it's because a bad push/pop balance. Normally you should have the same amount of pushes and pops in a routine (not necessary as you can mess with the return address of a call instruction ;))

Also, I would go for row-major ordening because that's how the underlying structure is also made (the buffer). I don't know what the advantages are of using colum-major ordening except that it causes me headaches. :P

Once I wrote this piece of code:
Draws part of an any sized map (row major order), the first byte of the map data should be it's width (in tiles)
requires h_times_e routine (make it preserve D, output in HL, I believe directly ripped from 28days)
Also uses SMC for a pointer to the tile base address and something else ;)
I don't think it can be optimized any further (free cake for the one that can :mrgreen:, cheap tricks will result in cheap cake)
btw gbuf=plotsscreen

Code: Select all

;----------------------------------------------------------------
;            Draws an aligned tilemap with 8x8 tiles             
;----------------------------------------------------------------
;Author		Dries Guldolf
;Input		D	The xpos in the tilemap
;		E	The ypos in the tilemap
;		HL	Pointer to the tilemap
;Destroys	AF, BC, DE, HL
;

tilemap8x8_aligned:
	ld a, (hl)
	inc hl
	push hl
	ld h, a
	call h_times_e
	pop bc
	add hl, bc
	ld e, d
	ld d, 0
	add hl, de

	ld de, gbuf
	ld c, 8
_rowloop:
	ld b, 12
_colloop:
	push bc
	push de
	push hl
	ld l, (hl)
	ld h, 0
	add hl, hl
	add hl, hl
	add hl, hl
tilebase	equ	$ + 1
	ld bc, 0
	add hl, bc
	ex de, hl
	ld bc, 12
; Because I have no more registers this loop is unrolled (if I want to keep interrupts enabled)
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	add hl, bc
	inc de
	ld a, (de)
	ld (hl), a
	pop hl
	pop de
	pop bc
	inc de
	inc hl
	djnz _colloop
	push bc
_nextrow	equ	$ + 1
	ld bc, 0
	add hl, bc
	ex de, hl
	ld bc, 7 * 12
	add hl, bc
	ex de, hl
	pop bc
	dec c
	jr nz, _rowloop
	ret
Feel free to learn from it! (or use, whatever you want)

Of course I'm into smooth scrolling these days :P
Post Reply