[TI ASM]Error when exiting?

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

[TI ASM]Error when exiting?

Post by chickendude »

Is there something wrong with this code (aside from being inefficient)? It executes fine, but when I quit it gives some hugely messed up error. I'll post a video. This is what I'm using to select a character in my monopoly game, and this is where the trouble appears to be. It doesn't present any problem if 21 gets loaded in, but if I hit right once more (so that the cp 21 prevents (hl) from increasing) it gives some huge error when I quit.
notLeft:
cp skRight ;was it the right key?
jr nz,notRight ;if it wasn't, we don't want to run this
ld a,(hl)
cp 21
jr z,choosepieces
inc (hl)
inc (hl)
inc (hl)
notRight:

Image

It only does that when I try to go past the last sprite. If I quit from any of the other ones, it exits just fine.

Here's the rest of the code for that section:

Code: Select all

choosepieces:
 bcall(_cleargbuf)          ;clear the gbuf
 call putthesprite
 ld de,45*256+40
 ld (pencol),de
 ld hl,tile_data            ;I stored the '<' character in the first byte and the '>' character in the 3rd
 bcall(_vputs)
 ld a,53
 ld (pencol),a
 bcall(_vputs)
 call ionfastcopy

 ld hl,select_character
 bcall(_homeup)
 bcall(_puts)
;;;;TRY TO SIMULATE INGAME DELAY
 ei
 halt
 halt
 halt
 di
 bcall(_getcsc)
 push af                    ;we mess with 'a' down below (ld a,(hl)), so save it for lower keypresses
 ld hl,playerdata+6
 call determineplayer

 cp skLeft                    ;Was it the left key?
 jr nz,notLeft
 ld a,(hl)
 or a
 jr z,choosepieces
 dec (hl)
 dec (hl)
 dec (hl)
 xor a                       ;the getcsc value for the right arrow is 03h.  Therefore, if we loaded
                             ;playerdata+6 and it pointed to 3 (the second character) it would be tricked
                             ;into thinking that the right key was pressed with cp skRight.  I can't explain it,
                             ;try taking out the xor a and see what happens.
notLeft:
 cp skRight                  ;was it the right key?
 jr nz,notRight              ;if it wasn't, we don't want to run this
 ld a,(hl)
 cp 21
 jr z,choosepieces
 inc (hl)
 inc (hl)
 inc (hl)

notRight:
 pop af                     ;when the playerdata+6 variable equals nine, well actually 12, but the previous value was nine (the value of skEnter) it will think enter was pressed and select that character. thus we pop af
 cp skEnter                 ;was enter pressed?
 jr z,play2                ;if so, then go to label second
 cp skMode                  ;was mode pressed?
 jp z,quitter               ;if so, quit
 jr choosepieces            ;go to label start
optimizations are also welcome :)
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

seems to me like you forgot a pop/push somewhere. Shouldn't there be a pop in 'notLeft'?
Image
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

Ah! Very astute, I'll check that out now :)

Alright, it worked! Thanks kv, I probably would have never figured it out haha.
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

When you got problems when exiting your working program it's often a wrong sp :)
Image
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

I suggest you tab over whenever you push, then tab back when you pop. like curly braces in C. It helps you keep the stack straight.
You know your hexadecimal output routine is broken when it displays the character 'G'.
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

That's a good idea. I really need to start working on the structure/formatting of my code...
User avatar
Madskillz
Calc Wizard
Posts: 745
Joined: Fri 17 Dec, 2004 10:22 pm
Location: Wandering around in the Jungle...
Contact:

Post by Madskillz »

my code is always jumbled...I have no real organization other than a few headers to tell me what section I'm in.
The Revolution is here...
Post Reply