Page 2 of 2
Posted: Tue Jul 03, 2012 3:06 am
by mic_
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.
Posted: Tue Jul 03, 2012 2:44 pm
by Pennywise
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.
Posted: Tue Jul 03, 2012 3:27 pm
by Drag
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.

Posted: Tue Jul 03, 2012 9:01 pm
by strat
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.
Posted: Sat Jul 07, 2012 8:25 pm
by strat
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: Select all
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: Select all
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.
Posted: Sat Jul 07, 2012 10:51 pm
by thefox
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.
Posted: Sun Jul 08, 2012 11:43 pm
by strat
Sweet, that was it. I got wlad to output something that can be reassembled.