X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=6502.c;h=711435e1bac68f7205fc5b50390f3e4b3e8c5397;hp=099c89d115f2ab208560b8705c2c0fb38ca02e5b;hb=f3c7d186a15b89c39e360b9cc89545a0d24bd6a4;hpb=2161b198b7b333147c89ef0346d8e9bb6ab9ffd9 diff --git a/6502.c b/6502.c index 099c89d..711435e 100644 --- a/6502.c +++ b/6502.c @@ -1,5 +1,9 @@ // -// 6502 Assembler +// RMAC - Reboot's Macro Assembler for all Atari computers +// 6502.C - 6502 Assembler +// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends +// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 +// Source utilised with the kind permission of Landon Dyer // // Init6502 initialization // d_6502 handle ".6502" directive @@ -162,8 +166,9 @@ static char a8internal[] = 'y', 121, 'z', 122 }; + // -// initialize 6502 assembler +// Initialize 6502 assembler // void Init6502() { @@ -203,26 +208,26 @@ void Init6502() // Set up first org section (set to zero) orgmap[0][0] = 0; - SwitchSection(M6502); // Switch to 6502 section - // - // Initialise string conversion table(s) - // - - char *p = a8internal; - memset(strtoa8, 31, 128); // 31=fallback value ("?") - for (; p < a8internal + sizeof(a8internal); p += 2) - { - strtoa8[p[0]] = p[1]; - } - - if (challoc == 0) { - // Allocate and clear 64K of space for the 6502 section - chcheck(UPSEG_SIZE); - memset(sect[M6502].scode->chptr, 0, UPSEG_SIZE); - } - SwitchSection(TEXT); // Go back to TEXT + SwitchSection(M6502); // Switch to 6502 section + + // Initialise string conversion table(s) + char * p = a8internal; + memset(strtoa8, 31, 128); // 31=fallback value ("?") + + for(; pchptr, 0, UPSEG_SIZE); + } + + SwitchSection(TEXT); // Go back to TEXT } + // // .6502 --- enter 6502 mode // @@ -242,7 +247,7 @@ void m6502cg(int op) { register int amode; // (Parsed) addressing mode register int i; - VALUE eval; // Expression value + uint64_t eval; // Expression value WORD eattr; // Expression attributes int zpreq; // 1, optimize instr to zero-page form register char * p; // (Temp) string usage @@ -253,27 +258,29 @@ void m6502cg(int op) // zpreq = 0; - switch ((int)*tok) + switch (tok.u32[0]) { case EOL: amode = A65_IMPL; break; case '#': - tok++; + tok.u32++; - if (*tok == '>') + if (*tok.u32 == '>') { - tok++; + tok.u32++; + if (expr(exprbuf, &eval, &eattr, NULL) < 0) return; amode = A65_IMMEDH; break; } - else if (*tok == '<') + else if (*tok.u32 == '<') { - tok++; + tok.u32++; + if (expr(exprbuf, &eval, &eattr, NULL) < 0) return; @@ -288,41 +295,43 @@ void m6502cg(int op) break; case '(': - tok++; + tok.u32++; if (expr(exprbuf, &eval, &eattr, NULL) < 0) return; - if (*tok == ')') + if (*tok.u32 == ')') { // (foo) or (foo),y - if (*++tok == ',') + if (*++tok.u32 == ',') { // (foo),y - tok++; - p = string[tok[1]]; + tok.u32++; + p = string[tok.u32[1]]; - if (*tok != SYMBOL || p[1] != EOS || (*p | 0x20) != 'y') // Sleazo tolower() + // Sleazo tolower() ---------------------vvvvvvvvvvv + if (*tok.u32 != SYMBOL || p[1] != EOS || (*p | 0x20) != 'y') goto badmode; - tok += 2; + tok.u32 += 2; amode = A65_INDY; } else amode = A65_IND; } - else if (*tok == ',') + else if (*tok.u32 == ',') { // (foo,x) - tok++; - p = string[tok[1]]; + tok.u32++; + p = string[tok.u32[1]]; - if (*tok != SYMBOL || p[1] != EOS || (*p | 0x20) != 'x') // Sleazo tolower() + // Sleazo tolower() ---------------------vvvvvvvvvvv + if (*tok.u32 != SYMBOL || p[1] != EOS || (*p | 0x20) != 'x') goto badmode; - tok += 2; + tok.u32 += 2; - if (*tok++ != ')') + if (*tok.u32++ != ')') goto badmode; amode = A65_INDX; @@ -333,17 +342,17 @@ void m6502cg(int op) break; case '@': - tok++; + tok.u32++; if (expr(exprbuf, &eval, &eattr, NULL) < 0) return; - if (*tok == '(') + if (*tok.u32 == '(') { - tok++; - p = string[tok[1]]; + tok.u32++; + p = string[tok.u32[1]]; - if (*tok != SYMBOL || p[1] != EOS || tok[2] != ')' || tok[3] != EOL) + if (*tok.u32 != SYMBOL || p[1] != EOS || tok.u32[2] != ')' || tok.u32[3] != EOL) goto badmode; i = (*p | 0x20); // Sleazo tolower() @@ -355,10 +364,10 @@ void m6502cg(int op) else goto badmode; - tok += 3; // Past SYMBOL ')' EOL + tok.u32 += 3; // Past SYMBOL ')' EOL zpreq = 1; // Request zeropage optimization } - else if (*tok == EOL) + else if (*tok.u32 == EOL) amode = A65_IND; else goto badmode; @@ -371,7 +380,7 @@ void m6502cg(int op) // x,foo // y,foo // - p = string[tok[1]]; + p = string[tok.u32[1]]; // ggn: the following code is effectively disabled as it would make // single letter labels not work correctly (would not identify the // label properly). And from what I understand it's something to @@ -407,17 +416,17 @@ not_coinop: zpreq = 1; - if (*tok == EOL) + if (*tok.u32 == EOL) amode = A65_ABS; - else if (*tok == ',') + else if (*tok.u32 == ',') { - tok++; - p = string[tok[1]]; + tok.u32++; + p = string[tok.u32[1]]; - if (*tok != SYMBOL || p[1] != EOS) + if (*tok.u32 != SYMBOL || p[1] != EOS) goto badmode; - tok += 2; + tok.u32 += 2; // // Check for X or Y index register; @@ -574,7 +583,7 @@ badmode: if (sloc > 0x10000L) fatal("6502 code pointer > 64K"); - if (*tok != EOL) + if (*tok.u32 != EOL) error(extra_stuff); }