i was learning asm, and i was trying to create a tilemap draw routine for practice
however, my routine ends up drawing only sprite 1
this is my code, i comented it so it is easer to read
i probaby did someting wrong in calucating the sprite offset (check comments)
by the way, we really need options for hiding those huge code blocks
Code: .nolist
#include "ti83plus.inc"
#include "ti83plusasm.inc"
#define ProgStart $9D95 -2
.list
.org ProgStart
.db t2ByteTok, tAsmCmp
;BCALL(_runindicoff)
;BCALL(_clrLCDfull)
LD H, 0;Xpos
LD L, 0;Ypos
loopX:
PUSH HL
CALL sprite
BCALL(_GrBufCpy) ;i know this is slow... just did it so it is easier to see whats going on
POP HL
INC H
LD A,H
CP 12
JR Z,loopY
JR loopX
loopY:
LD H, 0
INC L
INC L
INC L
INC L
INC L
INC L
INC L
INC L
LD A, L
CP 8*8
JR Z,exit
JR loopX
;-----the next part is wrong???-----(up to the next line)-------
sprite:
PUSH HL
PUSH HL;multiply Ypos by 12
LD H,0;L=ypos
ADD HL,HL;HL=2Y
ADD HL,HL;4Y
LD D,H;D=0
LD E,L;E=2Y
ADD HL,HL;8Y
ADD HL,DE;12Y
POP DE;get Xpos back....
LD A,D;A=Xpos
LD E,A;E=xpos
LD D,0;DE=$00+Xpos
ADD HL,DE;HL is now offset tilemap
LD DE,tilemap ;get adress of tilemap
ADD HL,DE;add offset to tilemap
EX DE,HL;DE is now (finaly) adress of correct byte in tilemap
;get whatever is in tilemap
LD A,(HL)
;and multiply by 8
ADD A,A;2
ADD A,A;4
ADD A,A;8
;A = 8*tilemap
LD C,A;save 8*tilemap[y][x]
LD B,0
POP HL;next block of code requires X and Y pos in HL
PUSH BC
;---------------------------------works-------------------------------------------
LD A,H ;preserve "X" as HL is being worked on
LD H,$00 ;clear out H so HL has nothing but "Y".
ADD HL,HL ;HL x 2 (starting multiply by 12)
ADD HL,HL ;HL x 4
LD E,L ;Save HL to DE while HL = HL times 4
LD D,H ;
ADD HL,HL ;HL x 8
ADD HL,DE ;HL x 12. HL now is at start of row indicated
LD E,A ;Restore "X" back into LSB of DE
LD D,$00 ;Clear out top of register pair
ADD HL,DE ;row + col....
LD DE,plotsscreen ;getting address of the buffer
ADD HL,DE ;we now have correct address in the buffer
;-----------------------------------------------------------------------------------
POP DE
PUSH HL
LD HL,pic
ADD HL,DE;get correct bit from sprite..
EX DE,HL
LD B,8 ;eight copy loops for height.
POP HL
;-------------works----------------
spriteloop:
PUSH BC ;preserve BC (not enough registers)
LD A,(DE) ;get a byte from the sprite
OR (HL) ;OR sprite with contents of the buffer
LD (HL),A ;save the result back to the buffer
INC DE ;go to next byte in sprite
LD BC,12 ;next row below is 12 bytes
ADD HL,BC ;go to next byte underneath this
POP BC ;restore the byte in BC (B is the loop counter)
DJNZ spriteloop ;simple loop that stops after eight iterations.
RET ;return
;--------------------------------------
exit:
RET
tilemap:
.db $010101010101010101010101;1,1,1,1,1,1,1,1,1,1,1,1
.db $010000000000000000000001;1,0,0,0,0,0,0,0,0,0,0,1
.db $010002000200020002000001;1,0,2,0,2,0,2,0,2,0,0,1
.db $010000020002000200020001;1,0,0,2,0,2,0,2,0,2,0,1
.db $010002000200020002000001;1,0,2,0,2,0,2,0,2,0,0,1
.db $010000020002000200020001;1,0,0,2,0,2,0,2,0,2,0,1
.db $010000000000000000000001;1,0,0,0,0,0,0,0,0,0,0,1
.db $010101010101010101010101;1,1,1,1,1,1,1,1,1,1,1,1
pic:
;sprite 0
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
;sprite 1
.db %11111111; the program draws only this sprite atm
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11111111
;sprite 2
.db %01111000 ;by the way, this sprite looks like a '2'
.db %10000100
.db %00000010
.db %00000100
.db %00001000
.db %00010000
.db %00100000
.db %01111111
.end
.end
[code] → [codebox]
Last edited by Guest on 07 Sep 2008 04:26:29 pm; edited 1 time in total |