would someone be willing to help me debug the first step of my tile displaying routine for stratcon? for some reason it only seems to display the first column of tiles.....


Code:

tilemapdisp:
   ld a,0 ;y coord
tilemapiloop:
   ld e,0 ;x coord
tilemapiloop2:
   push af
   push de
   push af ;we want 2 copies on the stack, 1 is for later use.
   push de
   call getMapPixel ;get the pixel mask for e,a
   and (hl)       ;get the state of the pixel
   jr nz,tilemapiloopdland ;if the pixel is land, don't bother with a sprite
   pop de
   ld h,8
   call h_times_e
   pop af
   push hl
   ld e,a
   ld h,8
   call h_times_e ;l now has y coordinate
   pop de
   ld a,e         ;a now has x coord.
   ld b,8
   ld ix,spr_water
   call iPutSprite ;draw the water sprite
   jr endtilemapiloop2
tilemapiloopdland:
   pop de
   ld h,8
   call h_times_e
   pop af
   push hl
   ld e,a
   ld h,8
   call h_times_e ;l now has y coordinate
   pop de
   ld a,e         ;a now has x coord.
   ld b,8
   ld ix,spr_land
   call iPutSprite ;draw the water sprite
endtilemapiloop2:   
   pop de
   inc e
   ld a,e
   cp 12
   jr nz,endtilemapiloop
   ld e,0
endtilemapiloop:
   pop af
   inc a
   cp 8
   jr nz,tilemapiloop
   ret



Code:
getMapPixel:
   ld   d,$00
   ld   h,d
   ld   l,e
   add   hl,de
   add   hl,de
   add   hl,hl
   add   hl,hl
   ld   de,savesscreen
   add   hl,de
   ld   b,$00
   ld   c,a
   and   %00000111
   srl   c
   srl   c
   srl   c
   add   hl,bc
   ld   b,a
   inc   b
   ld   a,%00000001
getPixelLoop:
   rrca
   djnz   getPixelLoop
   ret
Well, I reformatted your code to make it a bit easier to read:


Code:
tilemapdisp:
   ld a,0 ;y coord
tilemapiloop:
   ld e,0 ;x coord
tilemapiloop2:
   push af
      push de
         push af ;we want 2 copies on the stack, 1 is for later use.
            push de
               call getMapPixel ;get the pixel mask for e,a
               and (hl)       ;get the state of the pixel
               jr nz,tilemapiloopdland ;if the pixel is land, don't bother with a sprite
               pop de
            ld h,8
            call h_times_e
            pop af
         push hl
            ld e,a
            ld h,8
            call h_times_e ;l now has y coordinate
            pop de
         ld a,e         ;a now has x coord.
         ld b,8
         ld ix,spr_water
         call iPutSprite ;draw the water sprite
         jr endtilemapiloop2
tilemapiloopdland:
               pop de   ;recall x coord [2nd copy]
            ld h,8
            call h_times_e
            pop af      ;recall y coord [2nd copy]
         push hl
            ld e,a
            ld h,8
            call h_times_e ;l now has y coordinate
            pop de
         ld a,e         ;a now has x coord.
         ld b,8
         ld ix,spr_land
         call iPutSprite ;draw the water sprite
endtilemapiloop2:   
         pop de          ;recall x coord [1st copy]
      inc e
      ld a,e
      cp 12            ;is it 12 yet?
      jr nz,endtilemapiloop   ;nope - loop
      ld e,0
endtilemapiloop:
      pop af            ;recall y coord
   inc a
   cp 8
   jr nz,tilemapiloop
   ret


Aaaand, problem found. Change, in the 8th line from the bottom:

Code:
jr nz,endtilemapiloop   ;nope - loop
to
Code:
jr nz,tilemapiloop   ;nope - loop
Nice one Kerm. I missed that.
w00t, thanks Kerm
(and chip for looking)

[edit]
hehe, fixed one thing only to find another,now it crashes
IT took me a few minutes because I was looking for something subtle like stack mismatches.
As was I.

Too bad you've got another bug. You think this code segment is responsible?

BTW, Kerm, you have to make the text white in the Topic Review for this new theme.
Chipmaster wrote:
As was I.

Too bad you've got another bug. You think this code segment is responsible?

BTW, Kerm, you have to make the text white in the Topic Review for this new theme.


quite sure, everything else was stable beforehand, and it only showed up after that one change, meaning its now finding something in the loop thats crashing it....
Does it manage to display the tiles before the crash?
Chipmaster wrote:
Does it manage to display the tiles before the crash?

not that I can tell...and it did before even though it was only the first column.
It's probably not important, but the seventh line from the bottom:
Code:
   ld e,0
is redundant.
good point, that wasn't the main bug though Neutral (somehow didn't expect it would be....redundancy rarely hurts)
elfprince13 wrote:
good point, that wasn't the main bug though Neutral (somehow didn't expect it would be....redundancy rarely hurts)
No no, of course not. I wonder what the problem could be this time...
Then in this case, open up Flash Debugger, enable the Trace option for the good rom page, and then run your program. When it bugs, stop the emulator and look at the trace log. It can help alot.

It displays the 1000 last instruction executed (or so)
Fallen Ghost wrote:
Then in this case, open up Flash Debugger, enable the Trace option for the good rom page, and then run your program. When it bugs, stop the emulator and look at the trace log. It can help alot.

It displays the 1000 last instruction executed (or so)
Razz Ugh, the Flash Debugger. How I despise that tool. Very Happy To tell you the truth, I've always found it to be a particularly badly-designed piece of software.
Got it. The problem is that you have a stack mismatch. Before you implemented the fix, if it were to be non-zero at
Code:
jr nz,endtilemapiloop   ;nope - loop
, it would still pop af (after it jumped over to endtilemapiloop). The problem is that, if it's non-zero now, it's just jumping back to the top, leaving an extra item on the stack. This will multiply pretty fast, and that's probably what's causing the crash. I'd bet that if you changed that last bit to something like:


Code:
endtilemapiloop2:   
      pop de          ;recall x coord [1st
      inc e
      ld a,e
      cp 12            ;is it 12 yet?
      jr nz,fixstack   ;nope - loop
      ld e,0
endtilemapiloop:
      pop af            ;recall y coord
      inc a
      cp 8
      jr nz,tilemapiloop
      ret
fixstack:
     pop af
     jr tilemapiloop


It might just work.
Aha, good call, Chip. You're absolutely right, and it looks to me like your code should do the trick....
Yea, I was trying to think of a more elegant solution, but I couldn't come up with one. I decided it was best that I just post the theory and let elf change it if he wishes.

/me crosses his fingers.
thanks, you guys are teh bomb.

/me pre sets up credits in the readme...Jim E, Kerm, Chip....

[edit]

came up with a more efficient way too Wink

edit2:
hmm, I now have an infinite loop of some sort....must debug....


Code:
tilemapdisp:
   xor a ;y coord
   jr tilemapiloop
stackfix:
   pop af
tilemapiloop:
   ld e,0 ;x coord
tilemapiloop2:
   push af
   push de
   push af ;we want 2 copies on the stack, 1 is for later use.
   push de
   call getMapPixel ;get the pixel mask for e,a
   and (hl)       ;get the state of the pixel
   jr nz,tilemapiloopdland ;if the pixel is land, we want the other sprite
tilemapiloopdwater:
   pop de
   ld h,8
   call h_times_e
   pop af
   push hl
   ld e,a
   ld h,8
   call h_times_e ;l now has y coordinate
   pop de
   ld a,e         ;a now has x coord.
   ld b,8
   ld ix,spr_water
   call iPutSprite ;draw the water sprite
   jr endtilemapiloop2
tilemapiloopdland:
   pop de
   ld h,8
   call h_times_e
   pop af
   push hl
   ld e,a
   ld h,8
   call h_times_e ;l now has y coordinate
   pop de
   ld a,e         ;a now has x coord.
   ld b,8
   ld ix,spr_land
   call iPutSprite ;draw the water sprite
endtilemapiloop2:   
   pop de
   inc e
   ld a,e
   cp 12
   jr nz,stackfix
endtilemapiloop:
   pop af
   inc a
   cp 8
   jr nz,tilemapiloop
   ret
Ok in this part of your code:


Code:
endtilemapiloop2:   
   pop de
   inc e
   ld a,e
   cp 12
   jr nz,stackfix


I don't think you preserve this new increased value of e ever after you increase it.
Chipmaster wrote:
Ok in this part of your code:


Code:
endtilemapiloop2:   
   pop de
   inc e
   ld a,e
   cp 12
   jr nz,stackfix


I don't think you preserve this new increased value of e ever after you increase it.


oh shnikey, I see the problem.
  
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 2
» 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