# A83: A Little Help Plz

```
Hey could somebody help figure out why in the hell this program
isn't working correctly??  I believe I know what is happening but I
can't figure out where, ecxept for that its in the crash routine.
Here's what I'm doing.  I basically have a map like this.
1,1,1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,0,0,1
1,0,0,0,0,2,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1,1,1
I have the place where you are stored in "coor" then I run through
some checks to find which direction you are going and then add or
subtract to move the "coor" on the map.  This is where you will be.
Then I check to see if there is anything besides a 0 there and if
there is, it doesn't move you.  Seems simple but does want to work for
some reason.
You start out on the 2nd row, 2nd col so I say you arre at 14
(this is what you will add).  If you press down then it adds 12 to say
you are moving to 26.  It adds 26 - 1 (If you think about it, 1 should
be 0) to the map location and looks at what is there.  Then ect...
I can't figure out what I am doing wrong but I know it is in the
crash detection because otherwise it works fine.

Jimmy

Here's the CODE!!!

.NOLIST
#define equ .equ
#define EQU .equ
#define END .end
#define	x	8265h
#define	y	8266h
#define	dir	8267h
#define	coor	8268h
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
.org 9327h

ccf
jr	prog_start
.dw	\$0000
.dw	description
Description:
.db "This Game by Jimmy Conner",0
prog_start:
call	_clrLCDFull
call	_runIndicOff
call	_grbufclr
call	draw
call	_grbufcpy_v
jp	startup
draw:
ld	hl, database
dec	hl
xor	a
ld	(x), a
ld	(y), a
nextcol:
inc	hl
ld	a, (hl)
cp	0
cp	1
cp	2
push	hl
ld	a, (y)
ld	e, a
ld	a, (x)
call	sprxor
pop	hl
ld	a, (x)
ld	(x), a
cp	96
jp	nz, nextcol
nextrow:
xor	a
ld	(x), a
ld	a, (y)
ld	(y), a
cp	64
jp	nz, nextcol
ret
ld	bc, blank
ret
ld	bc, Mountain
ret
ld	bc, house
ret
delay:
ld 	bc, 0FFFFh		; Delay length->bc
delayLoop:
dec	bc			; bc-1->bc
ld 	a, b			; Find where it is at
or 	c			; ''     ''   ' '   '
jr	nz, delayLoop		; If not done reloop
ret				; Return the call
startup:

ld	a, 14
ld	(coor), a
ld	a, 8 		;Initial X & Y coords of mouse.
ld	(x), a
ld 	a, 8
ld	(y), a

moveloop:
call	delay
call	delay
call	putmse 		;Call putmse
call	_grbufcpy_v
jp	getky
getky: 				;routine getkey
ld	a, 0ffh
out	(1), a
ld	a, 0feh
out	(1), a
in	a, (1)
cp	253 		;If key Left. NOTE: I didn't bother
jp	z, left 		;Goto Left	     with key equates.
cp	251 		;If key right...
jp	z, right 		;Goto Right
cp	254 		;If key Up...
jp	z, up 		;Goto up
cp	247 		;If key down...
jp	z, down 		;Goto Down
ld	a, 0ffh
out	(1), a
ld	a, 0fdh
out	(1), a
in	a, (1)
cp	191 		;If the key clear...
jp	z, quit 		;...quit.
jp	getky 		;Repeat.

left:
call	putmse
xor	a
ld	(dir), a
ld	a, (x) 	;Load XCoord Variable into A
add	a, -8		;Decrease A
cp	-8
jp	z, moveloop
call	crashdetection
ld	(x), a 	;Load back into mse_x
ld	a, (coor)
dec	a
ld	(coor), a
jp	moveloop 	;goto moveloop
up:
call	putmse
ld	a, 1
ld	(dir), a
ld	a, (y) 	;Load YCoord Variable into A
add	a, 8 		;Increase A
cp	64
jp	z, moveloop
call	crashdetection
ld	(y), a 	;Load back into mse_y
ld	a, (coor)
ld	(coor), a
jp	moveloop 	;goto moveloop
right:
call putmse
ld	a, 2
ld	(dir), a
ld	a, (x) 	;Load XCoord Variable into A
add	a, 8 		;Increase A
cp	96
jp	z, moveloop
call	crashdetection
ld	(x), a 	;Load back into mse_x
ld	a, (coor)
inc	a
ld	(coor), a
jp	moveloop 	;goto moveloop
down:
call	putmse
ld	a, 3
ld	(dir), a
ld	a, (y) 	;Load YCoord Variable into A
cp	-8
jp	z, moveloop
call	crashdetection
ld	(y), a 	;Load back into mse_y
ld	a, (coor)
ld	(coor), a
jp	moveloop 	;goto moveloop

===========  Bug Some Where In Here ==============

crashdetection:
push	af
ld	a, (coor)
ld	c, a
ld	a, (dir) ; Direction you are going
cp      0
call	z, checkleft
cp	1
call	z, checkup
cp	2
call	z, checkright
cp	3
call	z, checkdown
ld	hl, database ; My Map
xor	b
ld	a, (hl)      ; New Location
cp	1
jp	z, moveloop
cp	2
jp	z, moveloop
pop	af
ret

checkleft:
dec	c
ret
checkup:
ld	a, -12
ld	c, a
ret
checkright:
inc	c
ret
checkdown:
ld	a, 12
ld	c, a
ret

putmse:
ld	a, (y)
ld	e, a
ld	a, (x)
ld	bc, man 	;Load sprite name to bc
call	SPRXOR 	;Call movax' Sprite Routine
ret

quit:
call	_clrLCDFull
call	_grbufclr
ret

man:
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111

Blank:
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
.db %00000000
House:
.db %00011000
.db %00100100
.db %01000010
.db %10000001
.db %10011001
.db %10011001
.db %10011001
.db %11111111
Mountain:
.db %00100000
.db %01010000
.db %10001000
.db %00000101
.db %01000010
.db %10100100
.db %00011001
.db %00010010

database:
.db	1,1,1,1,1,1,1,1,1,1,1,1
.db 	1,0,0,0,0,0,0,0,0,0,0,1
.db 	1,0,0,0,0,0,0,0,0,0,0,1
.db 	1,0,0,0,0,0,0,0,0,0,0,1
.db 	1,0,0,0,0,0,0,0,0,0,0,1
.db 	1,0,0,0,0,2,0,0,0,0,0,1
.db 	1,0,0,0,0,0,0,0,0,0,0,1
.db	1,1,1,1,1,1,1,1,1,1,1,1

; Xor 8x8 sprite þ a=x, e=y, bc=sprite address
SPRXOR:
push    bc              ; Save sprite address

;====   Calculate the address in graphbuf   ====

ld      hl,0            ; Do y*12
ld      d,0

ld      d,0             ; Do x/8
ld      e,a
srl     e
srl     e
srl     e

ld      de,8e29h

ld      b,00000111b     ; Get the remainder of x/8
and     b
cp      0               ; Is this sprite aligned to 8*n,y?
jp      z,ALIGN

;====   Non aligned sprite blit starts here   ====

pop     ix              ; ix->sprite
ld      d,a             ; d=how many bits to shift each line

ld      e,8             ; Line loop
LILOP:  ld      b,(ix+0)        ; Get sprite data

ld      c,0             ; Shift loop
push    de
SHLOP:  srl     b
rr      c
dec     d
jp      nz,SHLOP
pop     de

ld      a,b             ; Write line to graphbuf
xor     (hl)
ld      (hl),a

inc     hl
ld      a,c
xor     (hl)
ld      (hl),a

ld      bc,11           ; Calculate next line address
inc     ix              ; Inc spritepointer

dec     e
jp      nz,LILOP        ; Next line

jp      DONE1

;====   Aligned sprite blit starts here   ====

ALIGN:                          ; Blit an aligned sprite to graphbuf
pop     de              ; de->sprite

ld      b,8
ALOP1:  ld      a,(de)
xor     (hl)
ld      (hl),a
inc     de
push    bc
ld      bc,12
pop     bc
djnz    ALOP1

DONE1:
ret

;  »»»»»»»»»»»»»»»»»»»»»»»»»»»»» END SPRITE ROUNTINE
««««««««««««««««««««««««««««««««««««

.end
END

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

```