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 Very Happy

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
I see 3 things:
1) Register A is modified when you press an arrow key, which *may* cause it seems you selected 2 keys.
2) SetRandomY can be optimized to
Code:
call RandomNumber
dec a
and a, 15
inc a
ret
Same with SetRandomX, but use "and a, 7" instead.
3) You are comparing (H and E) and (L and D). Shouldn't that be (H and D) and (L and E)?
I figured it out. The comparison worked but when it jumped to finish, it was being RETurned to the Input loop because of me being bad at calls and the stack and stuff. Now all that's left is to add a scoring system and a timer!
Still don't know how to stop screen scroll and update the screen to remove old "-" tho Question
PT_ wrote:

2) SetRandomY can be optimized to
Code:
call RandomNumber
dec a
and a, 15
inc a
ret

Thanks! Works the same and looks a lot better Laughing
I'm not sure why the screen would scroll... some text printing calls will automatically scroll the screen by a line when printing into the last row, but _PutC shouldn't do that.

As for removing previously printed characters, I'd suggest printing a space over them to erase them.
Runer112 wrote:
I'm not sure why the screen would scroll... some text printing calls will automatically scroll the screen by a line when printing into the last row, but _PutC shouldn't do that.

Printing is fine, but If I move the cursor to the bottom right corner or off the bottom of the screen it will glitch out in what I assume is an endless scroll? 28 days mentions this briefly, saying,
"If you reset AppAutoScroll, (IY + AppFlags), the display will not scroll when (CurRow) is greater than 7. The problem is that you have to make sure to set (CurRow) to under 8 when you want to display text again, or it'll suck to be you."
I don't know if this will fix my problem with going off screen, I guess I could just make it so you cant go off the screen, which is what I'd have to do if I got no scrolling to work anyway. But this is a learning experience so I gotta try everything
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement