[A83] Tilemapping System


[Prev][Next][Index][Thread]

[A83] Tilemapping System




I've been working on my tilemapper, EZTile, which I had some problems with
before with DevPac83 doing oddness . . . but anyway, there seems to be a
bit of a more serious bug.  The EZTRender call seems to blank the screen
and crash the calc.  Here's the source of the lib, along with line-by-line
commentary.  I noticed the bit where I call GetTile was reading the X and Y
Coordinate values rather than using bc.  There is a bit of code before
EZTRender, that is the BASIC code I was using to keep my thoughts straight
as I did the routine.  One more thing:  The defines have get moved to the
top of your program, and the #include for EZTile goes at the end.
;-----------
;| Defines |
;-----------
#define xdim saferam2+0
#define ydim saferam2+1
#define scrx saferam2+2
#define scry saferam2+3
#define numtiles saferam2+4
#define tileaddr saferam2+5
#define mapaddr saferam2+7

;-----------------------
;| Initialization      |
;-----------------------
;| a - Number of Tiles |
;| b - XDim            |
;| c - YDim            |
;| de - Map Address    |
;| hl - Tile Address   |
;-----------------------
eztInit:
	ld (numtiles),a		;Set NumTiles
	ld a,b			;Switch b to a so we can load to mem
	ld (xdim),a		;Load XDim
	ld a,c			;Switch c to a so we can load to mem
	ld (ydim),a		;Load YDim
	ld (tileaddr),hl	;Load Tile Address
	push de			;transfer de to hl, as ld hl,de isn't an opcode
	pop hl			;We do this to set to mem
	ld (mapaddr),hl		;Load Map Address
	ret			;Return

;-------------
;| Blank Map |
;-------------
eztBlank:
	ld a,(xdim)		;Get the XDim
	ld b,a			;Put it in b
	ld hl,(mapaddr)		;Get the Map Address
initxloop:			
	push bc			;Save bc
	ld a,(ydim)		;Get YDim
	ld b,a			;Put it in b
inityloop:
	ld (hl),0		;Put 0 at address
	inc hl			;Increment address
	djnz inityloop		;Loop if we haven't finished the row
	pop bc			;Get bc back
	djnz initxloop		;Loop if we're not done
	ret			;Return
	
;-------------------
;| Put Tile        |
;-------------------
;| a - Tile Number |
;| b - XPos        |
;| c - YPos        |
;-------------------
eztPutTile:
	push af			;Save af
	ld a,(ydim)		;Get YDim
	ld h,a			;Get ready to multiply
	ld l,b			;This will help get the sddress offset
	bcall(_htimesl)		;Its slow, I know, but this is beta <:)
	ld b,0			;Clear out b
	add hl,bc		;Add in the YPos
	ex de,hl		;Put hl into de
	ld hl,(mapaddr)		;Get the Map Address
	add hl,de		;Add the offset
	pop af			;Restore af
	ld (hl),a		;Write the data
	ret			;Return

;--------------
;| Get Tile   |
;--------------
;| b - XPos   |
;| c - YPos   |
;--------------
;| a - Result |
;--------------
eztGetTile:
	ld a,(ydim)		;Get the YDim
	ld h,a			;Get ready to multiply
	ld l,b			;This will help get the address offset
	bcall(_htimesl)		;Its slow, I know, but this is beta <:)
	ld b,0			;Clear out b
	add hl,bc		;Add in the YPos
	ex de,hl		;Put hl into de
	ld hl,(mapaddr)		;Get the Map Address
	add hl,de		;Add the offset
	ld a,(hl)		;Read the data
	ret			;Return

;----------
;| Render |
;----------
eztRender:
;for i=scrx to scrx+7
;	for j=scry to scry+11
;		x=(i-scrx)*8
;		y=(j=scry)*8
;		ix=tileaddr+(gettile(i,j)*8)
;		call ionputsprite
;	next j
;next i

	ld a,(scrx)		;Get the X Scroll
	sub 1			;Reduce it
	ld b,a			;Put it in b
	ld a,(scry)		;Get the Y Scroll
	sub 1			;Reduce it
	ld c,a			;Put it in c
iloop:
	inc b			;Increase X value (b)
	ld a,(scrx)		;Get the X Scroll
	ld d,a			;Put it in d
	ld a,b			;Get the X value into a
	sub d			;Subtract X Scroll (d)
	cp 7			;See if we hit 7
	ret z			;If so, we're done
jloop:
	inc c			;Increase Y value (c)
	ld a,(scry)		;Get the Y Scroll
	ld d,a			;Put it in d
	ld a,c			;Get the Y value into a
	sub d			;Subtract Y Scroll (d)
	cp 11			;See if we hit 11
	jp z,iloop		;If so, next column
	ld a,(scrx)		;Get the X Scroll
	ld d,a			;Put it in d
	ld a,b			;Get the X value into a
	sub d			;Subtract the X Scroll
	add a,a			;Times 2
	add a,a			;Times 4
	add a,a			;Times 8
	ld (xcoord),a		;Put it in X Coordinate
	ld a,(scry)		;Get the Y Scroll
	ld d,a			;Put it in d
	ld a,c			;Get the Y value into a
	sub d			;Subtract the Y Scroll
	add a,a			;Times 2
	add a,a			;Times 4
	add a,a			;Times 8
	ld (ycoord),a		;Put it in Y Coordinate
	;push bc			;Save bc
	;ld a,(xcoord)		;Get the X Coordinate
	;ld b,a			;Put it in b
	;ld a,(ycoord)		;Get the Y Coordinate
	;ld c,a			;Put it in c
	call eztgettile		;Get the map tile that's there
	add a,a			;Multiply the tile number by 2
	add a,a			;Times 4
	add a,a			;Times 8
	ld e,a			;Put the tile offset in e
	ld d,0			;Clear out d
	ld hl,(tileaddr)	;Get the Tile Address
	add hl,de		;Add the offset
	push hl			;This puts the new address
	pop ix			;into ix for IonPutSprite
	pop bc			;Get back bc
	ld a,(scry)		;Get the Y Scroll
	ld d,a			;Put it in d
	ld a,c			;Get the Y value into a
	sub d			;Subtract the Y Scroll
	ld l,a			;Put that in l
	ld a,(scrx)		;Get the X Scroll
	ld d,a			;Put it in d
	ld a,b			;Get the X value into a
	sub d			;Subtract the X Scroll
	push bc			;Save bc
	ld b,8			;Tile height is 8
	call ionputsprite	;Draw the sprite
	pop bc			;Recover bc
	jp jloop		;Loop




References: