Fixing the negative offset by allowing 65816 opcodes only in 65816 mode

This commit is contained in:
Andre Fachat 2019-11-04 20:03:08 +01:00
parent dccd33309d
commit 0991a45c18
14 changed files with 90 additions and 11 deletions

View File

@ -704,8 +704,14 @@ fprintf(stderr, "E_NODEF pass1 xat.c\n");
} else
sy=4+nk; /* absolute or zero page */
/* length counter set to maximum length + 1 */
bl=Maxbyt+1;
/* length counter set to maximum length + 1 */
if (w65816 || (t[l-1]=='@' || t[l-1] == '!')) {
/* for 65816 allow addressing modes up to 4 byte overall length */
bl=Maxbyt+1;
} else {
/* for other modes only check for addressing modes up to 3 byte overall length */
bl=Maxbyt;
}
/* find best fit for length of this operand */
while(--bl)
@ -1375,9 +1381,19 @@ fprintf(stderr, "Kdsb E_DSB %i\n", j);
}
}
}
bl=Maxbyt+1;
/* set bl to maximum overall length +1 as while() below starts with decrementing it */
if (w65816 || (t[*ll-1]=='@' || t[*ll-1] == '!')) {
/* for 65816 allow addressing modes up to 4 byte overall length */
bl=Maxbyt+1;
} else {
/* for other modes only check for addressing modes up to 3 byte overall length */
bl=Maxbyt;
}
#ifdef DEBUG_AM
printf("--- trying to find am using: (max+1) bl=%d, sy=%d\n", bl, sy);
#endif
while(--bl)
{
if((am=at[sy][bl-1])>=0)
@ -1415,8 +1431,8 @@ fprintf(stderr, "Kdsb E_DSB %i\n", j);
{
#ifdef DEBUG_AM
fprintf(stderr,
"b4: pc= %d, am = %d and vv[0] = %d, optimize = %d, bitmask = %d\n",
pc[segment], am, vv[0], fl, (vv[0]&0xffff00));
"b4: pc= %d, am = %d and vv[0] = %d, optimize = %d, bitmask = %u, er=%d\n",
pc[segment], am, vv[0], fl, (vv[0]&0xffff00), er);
#endif
/* terrible KLUDGE!!!! OH NOES!!!1!
@ -1455,15 +1471,21 @@ fprintf(stderr,
else
{
bl=le[am];
if ((am != 11 && am != 16) && (vv[0] > 255 || vv[0] < -256) && bl == 2) {
er = E_OVERFLOW;
} else
if ((am != 11 && am != 16) && (vv[0] > 65535 || vv[0] < -65536) && (bl == 2 || bl == 3)) {
er = E_OVERFLOW;
} else
if( ((ct[n][am]&0x400) && memode) || ((ct[n][am]&0x800) && xmode)) {
bl++;
}
}
*ll=bl;
}
#ifdef DEBUG_AM
fprintf(stderr, "byte length is now %d\n", bl);
fprintf(stderr, "byte length is now %d, am=%d, er=%d\n", bl, am, er);
#endif
if(!er)

View File

@ -1,12 +1,33 @@
default: test1 test2
default: test1 test2 test3 test4 test5 test6 test7 test8
test1:
../../xa -R -LLIB6502 test1.s -o test1.o
../hextool -cmp=ok < test1.o
../hextool -cmp=ok1 < test1.o
test2:
../../xa -R -LLIB6502 test2.s -o test2.o
../hextool -cmp=ok < test2.o
../hextool -cmp=ok2 < test2.o
test3:
../../xa -R -LLIB6502 test3.s -o test3.o
../hextool -cmp=ok3 < test3.o
test4:
../../xa -R -LLIB6502 test4.s -o test4.o
../hextool -cmp=ok4 < test4.o
test5:
../../xa -R -LLIB6502 test5.s -o test5.o
../hextool -cmp=ok5 < test5.o
test6:
../../xa -R -LLIB6502 test6.s -o test6.o || exit 0 && exit 1
test7:
../../xa -R -LLIB6502 test7.s -o test7.o || exit 0 && exit 1
test8:
../../xa -R -LLIB6502 test8.s -o test8.o || exit 0 && exit 1
clean:
rm -f *.o

BIN
xa/tests/neg_offset/a.o65 Normal file

Binary file not shown.

BIN
xa/tests/neg_offset/ok1 Normal file

Binary file not shown.

BIN
xa/tests/neg_offset/ok2 Normal file

Binary file not shown.

BIN
xa/tests/neg_offset/ok3 Normal file

Binary file not shown.

BIN
xa/tests/neg_offset/ok4 Normal file

Binary file not shown.

BIN
xa/tests/neg_offset/ok5 Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
.text
jsr LIB6502-255

View File

@ -0,0 +1,6 @@
.text
jsr LIB6502+256

View File

@ -0,0 +1,6 @@
.text
jsr LIB6502-256

View File

@ -0,0 +1,6 @@
.text
jsr LIB6502-65537

View File

@ -0,0 +1,6 @@
.text
jsr 65536

View File

@ -0,0 +1,6 @@
.text
jsr LIB6502+65536