- Help Comparing HL with DE
- 07 Mar 2018 02:55:21 pm
- Last edited by KaneE. on 07 Mar 2018 04:25:10 pm; edited 1 time in total
I've been stuck on this for a decent amount of time so I'm asking for help (Look at me go)
I'll paste the entire code here, but what I'm having troubles with is the part labeled "Compare Coordinates"
Little Walkthrough of whats supposed to happen:
-Generates a random (X,Y) coordinate for the screen and displays a "@" there
-Places a "-" At the left of the screen
-Gets user input and changes the "-" Accordingly with arrow key presses
(Heres The Issue)
-As soon as the "-" (X,Y) is changed, checks to see if its the same as the random (X,Y)
-If it's the same, It's supposed to quit the program, But It doesn't
I don't know how to use the debugger on Wabbitemu or SourceCoder 3 so I don't know if I'm accidentally calling something that changes these values or if my method of comparing is flawed. If you have any input on debugging or on how to fix my code your input would be greatly appreciated
Edit:
Also, I don't how to stop the screen from scrolling, or the most efficient way to clear the screen/Get rid of the "-" once it moves. If anyone knows or has an idea of what I can try again, input would be greatly appreciated
Code:
I'll paste the entire code here, but what I'm having troubles with is the part labeled "Compare Coordinates"
Little Walkthrough of whats supposed to happen:
-Generates a random (X,Y) coordinate for the screen and displays a "@" there
-Places a "-" At the left of the screen
-Gets user input and changes the "-" Accordingly with arrow key presses
(Heres The Issue)
-As soon as the "-" (X,Y) is changed, checks to see if its the same as the random (X,Y)
-If it's the same, It's supposed to quit the program, But It doesn't
I don't know how to use the debugger on Wabbitemu or SourceCoder 3 so I don't know if I'm accidentally calling something that changes these values or if my method of comparing is flawed. If you have any input on debugging or on how to fix my code your input would be greatly appreciated
Edit:
Also, I don't how to stop the screen from scrolling, or the most efficient way to clear the screen/Get rid of the "-" once it moves. If anyone knows or has an idea of what I can try again, input would be greatly appreciated
Code:
#include "ti83plus.inc"
.org userMem-2
.db $BB,$6D
BCALL(_HomeUp)
BCALL(_ClrScrnFull)
;-----------------------
; Set Basic Variables
;-----------------------
LD HL,0
CALL SetRandomY
LD H,A
CALL SetRandomX
LD L,A ;Random (X,Y) Stored in HL
;H is Y, L is X
LD D,0
LD E,4 ;Player (X,Y) Stored in DE
;E is Y, D is X
LD C,0 ;This does nothing yet, C will eventually be the score
;-----------------------
; Main Program Start
;-----------------------
InputLoop:
CALL UpdateScreen
PUSH HL
BCALL(_GetCSC)
POP HL
CP skUp
CALL z,YDec
CP skDown
CALL z,YInc
CP skLeft
CALL z,XDec
CP skRight
CALL z,XInc
CP skClear
JP z,Finish
JR InputLoop
;-----------------------
; User Input Results
;-----------------------
YInc:
INC E
CALL XYCheck
LD A,c
CP -1
JP z,Finish
ret
YDec:
DEC E
CALL XYCheck
LD A,c
CP -1
JP z,Finish
ret
XInc:
INC D
CALL XYCheck
LD A,c
CP -1
JP z,Finish
ret
XDec:
DEC D
CALL XYCheck
LD A,c
CP -1
JP z,Finish
ret
;-----------------------
; Set Random (X,Y)
;-----------------------
SetRandomY:
CALL RandomNumber
Zto16Loop:
SUB 16
JR c,Add16
CP 0
JR z,Add16
JR Zto16Loop
Add16:
ADD A,16
ret
SetRandomX:
Call RandomNumber
Zto8Loop:
SUB 8
JR c,Add8
CP 0
JR z,Add8
JR Zto8Loop
Add8:
ADD A,8
ret
RandomNumber:
LD A, ($9000) ;Load a random number seed
LD B, A
LD A, R ;Load Memory Refresh Register
ADD A, B ;Add seed and register
ret
;-----------------------
; Display Screen
;-----------------------
UpdateScreen:
LD (CurRow),HL
LD a,'@'
BCALL(_PutC)
LD (CurRow),DE
LD a,'-'
BCALL(_PutC)
ret
;-----------------------
; Compare Coordinates ;This is the part that doesn't work
;-----------------------
XYCheck:
LD A,H ;DE is Player XY
CP E ;HL is Random XY
JR nz,NotEqual
LD A,L
CP D
JR nz,NotEqual
LD c,-1
NotEqual:
ret
;-----------------------
; End Game
;-----------------------
Finish:
ret