I'm sorry for asking for more help but I have a bug in my program that I just can't figure out. So far I've narrowed it down and relized that for some reason Brass is compiling these two differently -


Code:

   bcall(_targetselect)
   push   hl
   strbox(straxecleave1,41)
   strbox(straxecleave2,47)
   strbox(straxecleave3,53)
   strbox(straxecleave4,59)
   waitclr()
   ld   a,(ix+4)
   add   a,5
   ld   (ix+4),a
   resdata(attackdata+2,7)

   ld   hl,49152
   ld   (attackdata+3),hl
   ld   a,45
   bcall(_random2)
   add   a,75
   ld   e,a   \   ld   d,0
   bcall(_damagecalculator)
   pop   ix
   bcall(_attackreciever)



Code:

.deflong   DamageFull(accu,inter,base)
   ld   hl,((accu-((accu/256)*256))*256)+(accu/256)
   ld   (attackdata+3),hl
   ld   a,inter
   bcall(_random2)
   add   a,base
   ld   e,a   \   ld   d,0
   bcall(_damagecalculator)
   pop   ix
   bcall(_attackreciever)
.enddeflong

   bcall(_targetselect)
   push   hl
   strbox(straxecleave1,41)
   strbox(straxecleave2,47)
   strbox(straxecleave3,53)
   strbox(straxecleave4,59)
   waitclr()
   ld   a,(ix+4)
   add   a,5
   ld   (ix+4),a
   resdata(attackdata+2,7)
   damagefull(192,45,75)


The first one seems to work how it should(mostly) but the second calls damagecalculator with a garbage number in de (which I've found out is always $D990) then crashes. Damagecalculator doesn't use the stack at all and attackreceiver only uses it in a small section which I've looked over a few times. Does anyone know what happened?
I assume you are already sure that damagecalculator is actually an offpage call? Anywho, what in the world is this mess?
Code:
   ld   hl,192
   ld   d,h
   ld   h,l
   ld   l,d
KermMartian wrote:
I assume you are already sure that damagecalculator is actually an offpage call? Anywho, what in the world is this mess?
Code:
   ld   hl,192
   ld   d,h
   ld   h,l
   ld   l,d

it *looks* like someone attempting to swap utilize a swap routine for the high and low bytes of hl, but....with a hardcoded input, which makes me wonder why you wouldn't just

Code:
ld hl, 49152
That's exactly what I mean, saves a neat 3 bytes and one register. Razz
elfprince13 wrote:
KermMartian wrote:
I assume you are already sure that damagecalculator is actually an offpage call? Anywho, what in the world is this mess?
Code:
   ld   hl,192
   ld   d,h
   ld   h,l
   ld   l,d

it *looks* like someone attempting to swap utilize a swap routine for the high and low bytes of hl, but....with a hardcoded input, which makes me wonder why you wouldn't just

Code:
ld hl, 49152


I used it for the macro since figuring out the reverse for each use would take more time to code(alright so I was lazy). I added it into the to the first block to make the two as identical as I could to fix the bug then optimize later.

Edit - Alright hows that? I'm not sure if brass treats all numbers as integers though but I really only need to fix the bug right now, not optimize.
To be honest, I'm not actually seeing anything broken about the second chunk of code. Can you set a breakpoint on the bcall (before it starts) and see if de has that same inexplicable value there?
hmm...Apparently the macro works fine until it gets to a bcall. I put that character on the same page as the bcalls and changed them to calls and it worked fine. Can I not use the macro bcall inside another macro?
lindenk wrote:
hmm...Apparently the macro works fine until it gets to a bcall. I put that character on the same page as the bcalls and changed them to calls and it worked fine. Can I not use the macro bcall inside another macro?
I guess not. Sad That's rather unfortunate.
...Alright then...would this work to get over whatever it could be?(mostly asking to see if the code itself would work the way it should)


Code:


Lcall   .equ   $8787+(grayscaleend-grayscale)

.deflong   DamageFull(accu,inter,base)
   ld   hl,((accu-((accu/256)*256))*256)+(accu/256)
   ld   (attackdata+3),hl
   ld   a,inter
   call  Lcall
   .db   1   ;random2
   add   a,base
   ld   e,a   \   ld   d,0
   call   Lcall
   .db   2
   pop   ix
   call   Lcall
   .db   3
.enddeflong

;rest of my header and such

Lcallhandler:
   ex   (sp),hl
   push   af
   in   a,(6)   ;save current page and swap to page 3(relative to my page 0)
   ld   (currentpage),a
   ld   a,(startingpage)
   add   a,3
   out   (6),a
   ld   a,(hl)
   ld   (freebyte),a
   pop   af
   
   ld   (savehl),hl   ;save next return
   ld   hl,freebyte
   dec   (hl)
   ex   (sp),hl   ;restore hl for the call
   call   z,random2
   ex   (sp),hl
   dec   (hl)
   ex   (sp),hl
   call   z,damagecalculator
   ex   (sp),hl
   dec   (hl)
   ex   (sp),hl
   call   z,attackreciever
   ex   (sp),hl
   dec   (hl)
   ex   (sp),hl
   call   z,waitloop
   ex   (sp),hl
   dec   (hl)
   ex   (sp),hl
   call   z,battlebufcpy
   ex   (sp),hl
   dec   (hl)
   ex   (sp),hl
   call   z,ctbf
   ex   (sp),hl
   ld   hl,(savehl)
   push   af
   ld   a,h
   ld   h,l
   ld   l,a
   ld   a,(currentpage)
   out   (6),a
   pop   af
   inc   hl   ;get over var
   ex   (sp),hl
   ret
Lcallend

main:
   in   a,(6)
   ld   (startingpage),a
   ld   hl,Lcallhandler
   ld   de,$8787+(grayscaleend-grayscale)
   ld   bc,Lcallend-Lcallhandler
   ldir
;rest of my code here



;later
   bcall(_targetselect)
   push   hl
   strbox(straxecleave1,41)
   strbox(straxecleave2,47)
   strbox(straxecleave3,53)
   strbox(straxecleave4,59)
   waitclr()
   ld   a,(ix+4)
   add   a,5
   ld   (ix+4),a
   resdata(attackdata+2,7)
   damagefull(192,45,75)


Sorry for so many edits, I shoulda looked through my code better before posting it
  
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