It is currently Mon Oct 23, 2017 3:51 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Tue Jul 03, 2012 3:06 am 
Offline

Joined: Thu Oct 05, 2006 6:29 am
Posts: 911
Why not use one of the already available assemblers, like WLA-DX or RGBASM? Surely the time spent on hand-assembly could be better spent on writing more code or debugging.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2012 2:44 pm 
Offline

Joined: Tue Jul 14, 2009 11:04 am
Posts: 55
I looked at WLA actually, but it looked like I had to compile the latest version myself and I am totally unfamiliar with that process.

But I'm not that big of a GB hacker and the only other code at the moment I need to do is just some simple code to relocate some text at the end of bank to another bank. And at the moment, I have bunch of menu hacking to do which doesn't really require me to write any code of substance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2012 3:27 pm 
Offline

Joined: Mon Sep 27, 2004 2:57 pm
Posts: 1248
I've hand-assembled z80 dozens of times before. If it's just to assemble a small(ish) routine, then there's nothing wrong with it. :P


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2012 9:01 pm 
Offline

Joined: Mon Apr 07, 2008 6:08 pm
Posts: 325
Location: Missouri
Compiling WLA is no more complicated than running the included makefile. But I'm using the Windows version and WLA-GB refuses to assemble the code from WLAD-GB (The disassembler). Reading someone else's C code seems like less fun to me than reading asm.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2012 8:25 pm 
Offline

Joined: Mon Apr 07, 2008 6:08 pm
Posts: 325
Location: Missouri
So here's a story. I tried building wla-gb for windows and it would always shout "out of 8bit range" when assembling a JR opcode with a negative value. It won't assemble JR $FA but JR $-6 would work. This is interesting because wlad outputs JR $FA.

To fix the bug, I tinkered with wlad and added this code to the output_bank_opcodes routine in main.c (starts at line 198) so it would output JR $-6 instead of JR $FA:

Code:
   for (t = strlen(ot->op), x = 0, p = 0; x < t; ) {
     if (ot->op[x] == 'x') {
       bu[p] = 0;
      
      negval = in[(*i)++];
      if (0x38 == ot->hex || 0x30 == ot->hex || 0x28 == ot->hex || 0x20 == ot->hex || 0x18 == ot->hex || 0xF8 == ot->hex || 0xE8 == ot->hex) {
         if (negval > 0x7F && negval <= 0xFF) {
            signed int nb,na;
            nb = negval;
            negval = (negval - 0xFF) - 1;
            na = negval * -1;
            negval = (negval) + (na << 1);
            if (negval > 0x0F) {
               sprintf(tm, "-$%.2x",negval);
               p += 4;
            }
            else {
               sprintf(tm, "-$%.1x",negval);
               p += 3;
            }
         }
         else {
            sprintf(tm, "$%.2x",negval);
            p += 3;
         }
      }
      else {   
         sprintf(tm, "$%.2x",negval);
         p += 3;
      }
      
       strcat(bu, tm);
       /*p += 3;*/
       x++;
       a++;
     }
     else
       bu[p++] = ot->op[x++];
   }


That seemed to solve all the problems cropping up. Only now I'm trying to assemble this file (with wla-gb) that was generated with the wlad I modified. And now it's giving "unknown symbol JR" errors for no apparent reason at line 1325 ($08ef) even though there's no JR instruction at this line or the two lines before and after it. And of course it would have processed hundreds of JR opcodes at this point with no trouble.

Code:
LD A,($FF00+$a0)      ; $08e2
   INC A      ; $08e4
   CP $05      ; $08e5
   JR NZ,$-28      ; $08e7
   LD A,$04      ; $08e9
   JR $-2c      ; $08eb
   LD A,($FF00+$ac)      ; $08ed
   INC A      ; $08ef ; line 1325
   CP $05      ; $08f0
   JR NZ,$-27      ; $08f2
   LD A,$04      ; $08f4
   JR $-2b      ; $08f6


There could be a bug in wla-gb for assembling pure hex numbers (It seems to work fine with labels). But even after the effort I put into fixing the original problem, it's a very mysterious obstacle.

Edit: After playing around with the generated disassembly, a workaround would be to have the disassembler turn the negative jumps into labels. That should fix everything for good.

Edit: Code changed to reflect working wlad.


Last edited by strat on Sun Jul 08, 2012 11:44 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2012 10:51 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2963
Location: Tampere, Finland
strat wrote:
So here's a story. I tried building wla-gb for windows and it would always shout "out of 8bit range" when assembling a JR opcode with a negative value. It won't assemble JR $FA but JR $-6 would work. This is interesting because wlad outputs JR $FA.

I think you're mistaken here. $ probably denotes the current program counter value so "$-6" is not "negative 6" but "PC minus 6". At least it would make much more sense for the negative hexadecimal value to be denoted with "-$6" instead.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 08, 2012 11:43 pm 
Offline

Joined: Mon Apr 07, 2008 6:08 pm
Posts: 325
Location: Missouri
Sweet, that was it. I got wlad to output something that can be reassembled.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group