#include <ctype.h>
#include <stdlib.h>
+
#define EOS '\0'
int kwnum = 1; /* current op# for kwgen output */
-
-FILE * kfp; /* keyword file */
-
+FILE * kfp; /* keyword file */
int lineno = 0;
+// Function prototypes
void error(char *, char *);
void procln(int, char **);
+
int main(int argc, char ** argv)
{
char * namv[256];
#include "rmac.h"
// 68000 and 68020 addressing modes
-#define DREG 000 // Dn
-#define AREG 010 // An
-#define AIND 020 // (An)
-#define APOSTINC 030 // (An)+
-#define APREDEC 040 // -(An)
-#define ADISP 050 // (d16,An) d16(An)
-#define AINDEXED 060 // (d8,An,Xn) d8(An,Xn)
-#define ABSW 070 // xxx.W
-#define ABSL 071 // xxx or xxx.L
-#define PCDISP 072 // (d16,PC) d16(PC)
-#define PCINDEXED 073 // (d16,PC,Xn) d16(PC,Xn)
-#define IMMED 074 // #data
-#define ABASE 0100 // (bd,An,Xn)
-#define MEMPOST 0101 // ([bd,An],Xn,od)
-#define MEMPRE 0102 // ([bc,An,Xn],od)
-#define PCBASE 0103 // (bd,PC,Xn)
-#define PCMPOST 0104 // ([bd,PC],Xn,od)
-#define PCMPRE 0105 // ([bc,PC,Xn],od)
+#define DREG 000 // Dn
+#define AREG 010 // An
+#define AIND 020 // (An)
+#define APOSTINC 030 // (An)+
+#define APREDEC 040 // -(An)
+#define ADISP 050 // (d16,An) d16(An)
+#define AINDEXED 060 // (d8,An,Xn) d8(An,Xn)
+#define ABSW 070 // xxx.W
+#define ABSL 071 // xxx or xxx.L
+#define PCDISP 072 // (d16,PC) d16(PC)
+#define PCINDEXED 073 // (d16,PC,Xn) d16(PC,Xn)
+#define IMMED 074 // #data
+#define ABASE 0100 // (bd,An,Xn)
+#define MEMPOST 0101 // ([bd,An],Xn,od)
+#define MEMPRE 0102 // ([bc,An,Xn],od)
+#define PCBASE 0103 // (bd,PC,Xn)
+#define PCMPOST 0104 // ([bd,PC],Xn,od)
+#define PCMPRE 0105 // ([bc,PC,Xn],od)
#define AM_USP 0106
#define AM_SR 0107
#define AM_CCR 0110
-#define AM_NONE 0111 // Nothing
+#define AM_NONE 0111 // Nothing
// Addressing-mode masks
-#define M_DREG 0x00000001L // Dn
-#define M_AREG 0x00000002L // An
-#define M_AIND 0x00000004L // (An)
-#define M_APOSTINC 0x00000008L // (An)+
-#define M_APREDEC 0x00000010L // -(An)
-#define M_ADISP 0x00000020L // (d16,An) d16(An)
-#define M_AINDEXED 0x00000040L // (d8,An,Xn) d8(An,Xn)
-#define M_ABSW 0x00000080L // xxx.W
-#define M_ABSL 0x00000100L // xxx or xxx.L
-#define M_PCDISP 0x00000200L // (d16,PC) d16(PC)
-#define M_PCINDEXED 0x00000400L // (d16,PC,Xn) d16(PC,Xn)
-#define M_IMMED 0x00000800L // #data
-#define M_ABASE 0x00001000L // (bd,An,Xn)
-#define M_MEMPOST 0x00002000L // ([bd,An],Xn,od)
-#define M_MEMPRE 0x00004000L // ([bc,An,Xn],od)
-#define M_PCBASE 0x00008000L // (bd,PC,Xn)
-#define M_PCMPOST 0x00010000L // ([bd,PC],Xn,od)
-#define M_PCMPRE 0x00020000L // ([bc,PC,Xn],od)
-#define M_AM_USP 0x00040000L // USP
-#define M_AM_SR 0x00080000L // SR
-#define M_AM_CCR 0x00100000L // CCR
-#define M_AM_NONE 0x00200000L // (nothing)
+#define M_DREG 0x00000001L // Dn
+#define M_AREG 0x00000002L // An
+#define M_AIND 0x00000004L // (An)
+#define M_APOSTINC 0x00000008L // (An)+
+#define M_APREDEC 0x00000010L // -(An)
+#define M_ADISP 0x00000020L // (d16,An) d16(An)
+#define M_AINDEXED 0x00000040L // (d8,An,Xn) d8(An,Xn)
+#define M_ABSW 0x00000080L // xxx.W
+#define M_ABSL 0x00000100L // xxx or xxx.L
+#define M_PCDISP 0x00000200L // (d16,PC) d16(PC)
+#define M_PCINDEXED 0x00000400L // (d16,PC,Xn) d16(PC,Xn)
+#define M_IMMED 0x00000800L // #data
+#define M_ABASE 0x00001000L // (bd,An,Xn)
+#define M_MEMPOST 0x00002000L // ([bd,An],Xn,od)
+#define M_MEMPRE 0x00004000L // ([bc,An,Xn],od)
+#define M_PCBASE 0x00008000L // (bd,PC,Xn)
+#define M_PCMPOST 0x00010000L // ([bd,PC],Xn,od)
+#define M_PCMPRE 0x00020000L // ([bc,PC,Xn],od)
+#define M_AM_USP 0x00040000L // USP
+#define M_AM_SR 0x00080000L // SR
+#define M_AM_CCR 0x00100000L // CCR
+#define M_AM_NONE 0x00200000L // (nothing)
// Addr mode categories
-#define C_ALL 0x00000fffL
-#define C_DATA 0x00000ffdL
-#define C_MEM 0x00000ffcL
-#define C_CTRL 0x000007e4L
-#define C_ALT 0x000001ffL
+#define C_ALL 0x00000FFFL
+#define C_DATA 0x00000FFDL
+#define C_MEM 0x00000FFCL
+#define C_CTRL 0x000007E4L
+#define C_ALT 0x000001FFL
#define C_ALTDATA (C_DATA&C_ALT)
#define C_ALTMEM (C_MEM&C_ALT)
#define C_NONE M_AM_NONE
// Scales
-#define TIMES1 00000 // (empty or *1)
-#define TIMES2 01000 // *2
-#define TIMES4 02000 // *4
-#define TIMES8 03000 // *8
+#define TIMES1 00000 // (empty or *1)
+#define TIMES2 01000 // *2
+#define TIMES4 02000 // *4
+#define TIMES8 03000 // *8
-#define EXPRSIZE 128 // Maximum #tokens in an expression
+#define EXPRSIZE 128 // Maximum #tokens in an expression
// Addressing mode variables, output of amode()
extern int nmodes;
// Mnemonic table structure
#define MNTAB struct _mntab
MNTAB {
- WORD mnattr; // Attributes (CGSPECIAL, SIZN, ...)
- LONG mn0, mn1; // Addressing modes
- WORD mninst; // Instruction mask
- WORD mncont; // Continuation (or -1)
- int (*mnfunc)(WORD, WORD); // Mnemonic builder
+ WORD mnattr; // Attributes (CGSPECIAL, SIZN, ...)
+ LONG mn0, mn1; // Addressing modes
+ WORD mninst; // Instruction mask
+ WORD mncont; // Continuation (or -1)
+ int (*mnfunc)(WORD, WORD); // Mnemonic builder
};
// mnattr:
-#define CGSPECIAL 0x8000 // Special (don't parse addr modes)
+#define CGSPECIAL 0x8000 // Special (don't parse addr modes)
// Prototypes
int amode(int);
int reglist(WORD *);
#endif // __AMODE_H__
+
printf("\nMarks:\n");
mudump(); // Dump marks
- printf("Total memory allocated=$%X\n", amemtot);
+// printf("Total memory allocated=$%X\n", amemtot);
return 0;
}
#define DEF_KW
#include "kwtab.h"
+
TOKEN exprbuf[128]; // Expression buffer
SYM * symbolPtr[1000000]; // Symbol pointers table
+static long unused; // For supressing 'write' warnings
+
// Directive handler table
int (*dirtab[])() = {
printf("%s", prntstr);
if (list_fd)
- write(list_fd, prntstr, (LONG)strlen(prntstr));
+ unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
tok += 2;
break;
printf("%s", prntstr);
if (list_fd)
- write(list_fd, prntstr, (LONG)strlen(prntstr));
+ unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
formatting = 0;
wordlong = 0;
#include "token.h"
#include "listing.h"
-int errcnt; // Error count
-char * err_fname; // Name of error message file
+int errcnt; // Error count
+char * err_fname; // Name of error message file
-static char nl[] = "\n";
+static const char nl[] = "\n";
+static long unused; // For supressing 'write' warnings
//
//
int at_eol(void)
{
- if (*tok != EOL)
- error("syntax error");
+ if (*tok != EOL)
+ error("syntax error");
- return 0;
+ return 0;
}
//
// Cannot Create a File
//
-void cantcreat(char * fn)
+void cantcreat(const char * fn)
{
- printf("cannot create: '%s'\n", fn);
- exit(1);
+ printf("cannot create: '%s'\n", fn);
+ exit(1);
}
length = strlen(buf);
if (err_flag)
- write(err_fd, buf, length);
+ unused = write(err_fd, buf, length);
else
printf("%s", buf);
}
-int errors(char * s, char * s1)
+int errors(const char * s, char * s1)
{
char buf[EBUFSIZ];
char buf1[EBUFSIZ];
sprintf(buf1, "%s %d: Error: %s%s", curfname, curlineno, buf, nl);
if (err_flag)
- write(err_fd, buf1, (LONG)strlen(buf1));
+ unused = write(err_fd, buf1, (LONG)strlen(buf1));
else
printf("%s", buf1);
}
-int warn(char * s)
+int warn(const char * s)
{
char buf[EBUFSIZ];
sprintf(buf, "%s %d: Warning: %s%s", curfname, curlineno, s, nl);
if (err_flag)
- write(err_fd, buf, (LONG)strlen(buf));
+ unused = write(err_fd, buf, (LONG)strlen(buf));
else
printf("%s", buf);
}
-int warns(char * s, char * s1)
+int warns(const char * s, char * s1)
{
char buf[EBUFSIZ];
char buf1[EBUFSIZ];
sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
if (err_flag)
- write(err_fd, buf1, (LONG)strlen(buf1));
+ unused = write(err_fd, buf1, (LONG)strlen(buf1));
else
printf("%s", buf1);
}
-int warni(char * s, unsigned i)
+int warni(const char * s, unsigned i)
{
char buf[EBUFSIZ];
char buf1[EBUFSIZ];
sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
if (err_flag)
- write(err_fd, buf1, (LONG)strlen(buf1));
+ unused = write(err_fd, buf1, (LONG)strlen(buf1));
else
printf("%s", buf1);
}
-int fatal(char * s)
+int fatal(const char * s)
{
char buf[EBUFSIZ];
sprintf(buf, "%s %d: Fatal: %s%s", curfname, curlineno, s, nl);
if (err_flag)
- write(err_fd, buf, (LONG)strlen(buf));
+ unused = write(err_fd, buf, (LONG)strlen(buf));
else
printf("%s", buf);
ship_ln(buf);
if (err_flag)
- write(err_fd, buf, (LONG)strlen(buf));
+ unused = write(err_fd, buf, (LONG)strlen(buf));
else
printf("%s", buf);
exit(1);
}
+
// Prototypes
int error(const char *);
-int errors(char *, char *);
-int fatal(char *);
-int warn(char *);
-int warns(char *, char *);
-int warni(char *, unsigned);
+int errors(const char *, char *);
+int fatal(const char *);
+int warn(const char *);
+int warns(const char *, char *);
+int warni(const char *, unsigned);
int interror(int);
-void cantcreat(char *);
+void cantcreat(const char *);
void err_setup(void);
#endif // __ERROR_H__
//
// Initialize Expression Analyzer
//
-void init_expr(void)
+void InitExpression(void)
{
int i; // Iterator
char * p; // Token pointer
#define OR 12 // Bitwise or: |
// Prototypes
-void init_expr(void);
+void InitExpression(void);
int expr1(void);
int expr2(void);
int expr(TOKEN *, VALUE *, WORD *, SYM **);
#include "sect.h"
#include "error.h"
-char * list_fname; // Listing filename
-char subttl[TITLESIZ]; // Current subtitle
-int listing; // Listing level
-int pagelen = 61; // Lines on a page
-int nlines; // #lines on page so far
-LONG lsloc; // `sloc' at start of line
+char * list_fname; // Listing filename
+char subttl[TITLESIZ]; // Current subtitle
+int listing; // Listing level
+int pagelen = 61; // Lines on a page
+int nlines; // #lines on page so far
+LONG lsloc; // `sloc' at start of line
// Private
-static int lcursect; // `cursect' at start of line
-static int llineno; // `curlineno' at start of line
-static int pageno; // Current page number
-static int pagewidth; // #columns on a page
-static int subflag; // 0, don't do .eject on subttl (set 1)
-static char lnimage[IMAGESIZ]; // Image of output line
-static char title[TITLESIZ]; // Current title
-static char datestr[20]; // Current date dd-mon-yyyy
-static char timestr[20]; // Current time hh:mm:ss [am|pm]
-static char buf[IMAGESIZ]; // Buffer for numbers
+static int lcursect; // `cursect' at start of line
+static int llineno; // `curlineno' at start of line
+static int pageno; // Current page number
+static int pagewidth; // #columns on a page
+static int subflag; // 0, don't do .eject on subttl (set 1)
+static char lnimage[IMAGESIZ]; // Image of output line
+static char title[TITLESIZ]; // Current title
+static char datestr[20]; // Current date dd-mon-yyyy
+static char timestr[20]; // Current time hh:mm:ss [am|pm]
+static char buf[IMAGESIZ]; // Buffer for numbers
+static long unused; // For supressing 'write' warnings
static char * month[16] = { "", "Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
list_setup();
length = strlen(ln);
- write(list_fd, ln, length);
- write(list_fd, "\n", 1L);
+ unused = write(list_fd, ln, length);
+ unused = write(list_fd, "\n", 1L);
}
//
// Initialize Listing Generator
//
-void init_list(void)
+void InitListing(void)
{
extern VALUE dos_date(), dos_time();
extern LONG lsloc;
// Prototypes
-void init_list(void);
+void InitListing(void);
void ship_ln(const char *);
void taglist(char);
void println(const char *);
#define DEF_KW
#include "kwtab.h"
+
+// Fucntion prototypes
+int m_unimp(WORD, WORD), m_badmode(WORD, WORD), m_bad6mode(WORD, WORD), m_bad6inst(WORD, WORD);
+int m_self(WORD, WORD);
+int m_abcd(WORD, WORD);
+int m_reg(WORD, WORD);
+int m_imm(WORD, WORD);
+int m_imm8(WORD, WORD);
+int m_shi(WORD, WORD);
+int m_shr(WORD, WORD);
+int m_bitop(WORD, WORD);
+int m_exg(WORD, WORD);
+int m_ea(WORD, WORD);
+int m_br(WORD, WORD);
+int m_dbra(WORD, WORD);
+int m_link(WORD, WORD);
+int m_adda(WORD, WORD);
+int m_addq(WORD, WORD);
+//int m_move(WORD, int);
+int m_move(WORD, WORD);
+int m_moveq(WORD, WORD);
+int m_usp(WORD, WORD);
+int m_movep(WORD, WORD);
+int m_trap(WORD, WORD);
+int m_movem(WORD, WORD);
+int m_clra(WORD, WORD);
+
// Common error messages
char range_error[] = "expression out of range";
char abs_error[] = "illegal absolute expression";
// Include code tables
MNTAB machtab[] = {
- { (WORD)-1, (unsigned long)-1L, (unsigned long)-1L, 0x0000, 0, m_badmode }, // 0
+// { (WORD)-1, (unsigned long)-1L, (unsigned long)-1L, 0x0000, 0, m_badmode }, // 0
+ { 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000, 0, m_badmode }, // 0
#include "68ktab.h"
{ 0, 0L, 0L, 0x0000, 0, m_unimp } // Last entry
};
// Error messages
-int m_unimp(void)
+int m_unimp(WORD unused1, WORD unused2)
{
return (int)error("unimplemented mnemonic");
}
-int m_badmode(void)
+//int m_badmode(void)
+int m_badmode(WORD unused1, WORD unused2)
{
return (int)error("inappropriate addressing mode");
}
-int m_self(WORD inst)
+int m_self(WORD inst, WORD usused)
{
D_word(inst);
return 0;
//
int m_ea(WORD inst, WORD siz)
{
- WORD flg;
-
- flg = inst; // Save flag bits
- inst &= ~0x3f; // Clobber flag bits in instr
+ WORD flg = inst; // Save flag bits
+ inst &= ~0x3F; // Clobber flag bits in instr
- if (flg & 4) // Install "standard" instr size bits
+ // Install "standard" instr size bits
+ if (flg & 4)
inst |= siz_6[siz];
if (flg & 16)
- { // OR-in register number
+ {
+ // OR-in register number
if (flg & 8)
{
- inst |= reg_9[a1reg]; // ea1reg in bits 9..11
+ inst |= reg_9[a1reg]; // ea1reg in bits 9..11
}
else
{
- inst |= reg_9[a0reg]; // ea0reg in bits 9..11
+ inst |= reg_9[a0reg]; // ea0reg in bits 9..11
}
}
if (flg & 1)
- { // Use am1
- inst |= am1 | a1reg; // Get ea1 into instr
- D_word(inst); // Deposit instr
+ {
+ // Use am1
+ inst |= am1 | a1reg; // Get ea1 into instr
+ D_word(inst); // Deposit instr
- if (flg & 2) // Generate ea0 if requested
+ // Generate ea0 if requested
+ if (flg & 2)
ea0gen(siz);
- ea1gen(siz); // Generate ea1
+ ea1gen(siz); // Generate ea1
}
else
- { // Use am0
- inst |= am0 | a0reg; // Get ea0 into instr
- D_word(inst); // Deposit instr
- ea0gen(siz); // Generate ea0
+ {
+ // Use am0
+ inst |= am0 | a0reg; // Get ea0 into instr
+ D_word(inst); // Deposit instr
+ ea0gen(siz); // Generate ea0
- if (flg & 2) // Generate ea1 if requested
+ // Generate ea1 if requested
+ if (flg & 2)
ea1gen(siz);
}
int m_abcd(WORD inst, WORD siz)
{
if (inst & 1)
- { // Install size bits
- --inst;
+ {
+ // Install size bits
+ inst--;
inst |= siz_6[siz];
}
{
inst |= am0 | a0reg | lwsiz_8[siz] | reg_9[a1reg];
D_word(inst);
- ea0gen(siz); // Gen EA
+ ea0gen(siz); // Generate EA
return 0;
}
//
int m_reg(WORD inst, WORD siz)
{
- if (inst & 1) // Install size bits
+ if (inst & 1)
+ // Install size bits
inst |= siz_6[siz];
- if (inst & 2) // Install other register (9..11)
+ if (inst & 2)
+ // Install other register (9..11)
inst |= reg_9[a1reg];
- inst &= ~7; // Clear off crufty bits
- inst |= a0reg; // Install first register
+ inst &= ~7; // Clear off crufty bits
+ inst |= a0reg; // Install first register
D_word(inst);
return 0;
{
// Enforce instruction sizes
if (am1 == DREG)
- { // X,Dn must be .n or .l
- if (siz & (SIZB|SIZW))
+ { // X,Dn must be .n or .l
+ if (siz & (SIZB | SIZW))
return error(siz_error);
}
- else if (siz & (SIZW|SIZL)) // X,ea must be .n or .b
+ else if (siz & (SIZW | SIZL)) // X,ea must be .n or .b
return error(siz_error);
// Construct instr and EAs
if (am0 == IMMED)
{
D_word(inst);
- ea0gen(SIZB); // Immediate bit number
+ ea0gen(SIZB); // Immediate bit number
}
else
{
D_word(inst);
}
- ea1gen(SIZB); // ea to bit-munch
+ // ea to bit-munch
+ ea1gen(SIZB);
return 0;
}
}
else
{
- fixup(FU_WORD|FU_PCREL|FU_ISBRA, sloc, a1expr);
+ fixup(FU_WORD | FU_PCREL | FU_ISBRA, sloc, a1expr);
D_word(0);
}
//
// Optimize MOVE.L #<smalldata>,D0 to a MOVEQ
//
-int m_move(WORD inst, int siz)
+//int m_move(WORD inst, int siz)
+int m_move(WORD inst, WORD size)
{
+ // Cast the passed in value to an int
+ int siz = (int)size;
+
// Try to optimize to MOVEQ
if (siz == SIZL && am0 == IMMED && am1 == DREG
&& (a0exattr & (TDB|DEFINED)) == DEFINED && a0exval + 0x80 < 0x100)
siz = siz;
if (am0 == AM_USP)
- inst |= a1reg; // USP,An
+ inst |= a1reg; // USP, An
else
- inst |= a0reg; // An,USP
+ inst |= a0reg; // An, USP
D_word(inst);
else if (a0exval + 0x100 >= 0x200)
return error(range_error);
- inst |= reg_9[a1reg] | (a0exval & 0xff);
+ inst |= reg_9[a1reg] | (a0exval & 0xFF);
D_word(inst);
return 0;
//
-// movep Dn,disp(An) -- movep disp(An),Dn
+// movep Dn, disp(An) -- movep disp(An), Dn
//
int m_movep(WORD inst, WORD siz)
{
- //WORD k;
-
if (siz == SIZL)
inst |= 0x0040;
D_word(inst);
if (am1 == AIND)
- {
D_word(0);
- }
else
ea1gen(siz);
}
D_word(inst);
if (am0 == AIND)
- {
D_word(0);
- }
else
ea0gen(siz);
}
if (siz == SIZN)
{
if (v != 0 && v + 0x80 < 0x100)
- { // Fits in .B
- inst |= v & 0xff;
+ {
+ // Fits in .B
+ inst |= v & 0xFF;
D_word(inst);
return 0;
}
else
- { // Fits in .W
+ {
+ // Fits in .W
if (v + 0x8000 > 0x10000)
return error(range_error);
if (v + 0x80 >= 0x100)
return error(range_error);
- inst |= v & 0xff;
+ inst |= v & 0xFF;
D_word(inst);
}
else
siz = SIZW;
if (siz == SIZB)
- { // .B
- fixup(FU_BBRA|FU_PCREL|FU_SEXT, sloc, a0expr);
+ {
+ // .B
+ fixup(FU_BBRA | FU_PCREL | FU_SEXT, sloc, a0expr);
D_word(inst);
return 0;
}
else
- { // .W
+ {
+ // .W
D_word(inst);
- fixup(FU_WORD|FU_PCREL|FU_LBRA|FU_ISBRA, sloc, a0expr);
+ fixup(FU_WORD | FU_PCREL | FU_LBRA | FU_ISBRA, sloc, a0expr);
D_word(0);
}
inst |= 0x0040;
if (*tok == '#')
- { // Handle #<expr>,ea
- ++tok;
+ {
+ // Handle #<expr>, ea
+ tok++;
if (abs_expr(&eval) != OK)
return 0;
}
if (*tok >= KW_D0 && *tok <= KW_A7)
- { // <rlist>,ea
+ {
+ // <rlist>, ea
if (reglist(&rmask) < 0)
return 0;
inst |= am0 | a0reg;
- if (!(amsktab[am0] & (C_ALTCTRL|M_APREDEC)))
+ if (!(amsktab[am0] & (C_ALTCTRL | M_APREDEC)))
return error("invalid addressing mode");
// If APREDEC, reverse register mask
}
}
else
- { // ea,<rlist>
+ {
+ // ea, <rlist>
if (amode(0) < 0)
return 0;
return error("missing register list");
if (*tok == '#')
- { // ea,#<expr>
- ++tok;
+ {
+ // ea, #<expr>
+ tok++;
if (abs_expr(&eval) != OK)
return 0;
else if (reglist(&rmask) < 0)
return 0;
- if (!(amsktab[am0] & (C_CTRL|M_APOSTINC)))
+ if (!(amsktab[am0] & (C_CTRL | M_APOSTINC)))
return error("invalid addressing mode");
}
return 0;
}
+
extern char abs_error[];
extern MNTAB machtab[];
-// Prototypes
-int m_unimp(), m_badmode(), m_bad6mode(), m_bad6inst();
-int m_self(WORD);
-int m_abcd(WORD, WORD);
-int m_reg(WORD, WORD);
-int m_imm(WORD, WORD);
-int m_imm8(WORD, WORD);
-int m_shi(WORD, WORD);
-int m_shr(WORD, WORD);
-int m_bitop(WORD, WORD);
-int m_exg(WORD, WORD);
-int m_ea(WORD, WORD);
-int m_br(WORD, WORD);
-int m_dbra(WORD, WORD);
-int m_link(WORD, WORD);
-int m_adda(WORD, WORD);
-int m_addq(WORD, WORD);
-int m_move(WORD, int);
-int m_moveq(WORD, WORD);
-int m_usp(WORD, WORD);
-int m_movep(WORD, WORD);
-int m_trap(WORD, WORD);
-int m_movem(WORD, WORD);
-int m_clra(WORD, WORD);
-
#endif // __MACH_H__
for(;;)
{
- if (tokln() == TKEOF)
+ if (TokenizeLine() == TKEOF)
{
errors("encountered end-of-file looking for '%s'", dirlist);
fatal("cannot continue");
if ((tok[2] == ':' || tok[2] == DCOLON))
{
if (tok[3] == SYMBOL) // label: symbol
-#if 0
- p = (char *)tok[4];
-#else
p = string[tok[4]];
-#endif
}
else
{
-#if 0
- p = (char *)tok[1]; // symbol
-#else
p = string[tok[1]]; // Symbol
-#endif
}
}
//
// Initialize Marker
//
-void init_mark(void)
+void InitMark(void)
{
firstmch = curmch = NULL;
mcalloc = mcused = 0;
extern MCHUNK * firstmch;
// Prototypes
-void init_mark(void);
+void InitMark(void);
void stopmark(void);
//int rmark(int, LONG, int, int, SYM *);
int rmark(uint16_t, uint32_t, uint16_t, uint16_t, SYM *);
//
int object(WORD fd)
{
- LONG t; // Scratch long
- LONG tds; // TEXT & DATA segment size
- int i; // Temporary int
- CHUNK * cp; // Chunk (for gather)
- char * buf; // Scratch area
- char * p; // Temporary ptr
- LONG ssize; // Size of symbols
- LONG trsize, drsize; // Size of relocations
+ LONG t; // Scratch long
+ LONG tds; // TEXT & DATA segment size
+ int i; // Temporary int
+ CHUNK * cp; // Chunk (for gather)
+ char * buf; // Scratch area
+ char * p; // Temporary ptr
+ LONG ssize; // Size of symbols
+ LONG trsize, drsize; // Size of relocations
+ long unused; // For supressing 'write' warnings
// Write requested object file...
switch (obj_format)
// Build object file header
chptr = buf; // Base of header
- t = 0x00000107;
- D_long(t); // Magic number
- t = sect[TEXT].sloc; // TEXT size
- D_long(t);
- t = sect[DATA].sloc; // DATA size
- D_long(t);
- t = sect[BSS].sloc; // BSS size
- D_long(t);
- t = 0x00000000;
- D_long(t); // Symbol size
- D_long(t); // First entry (0L)
- D_long(t); // TEXT relocation size
- D_long(t); // BSD relocation size
+ D_long(0x00000107); // Magic number
+ D_long(sect[TEXT].sloc); // TEXT size
+ D_long(sect[DATA].sloc); // DATA size
+ D_long(sect[BSS].sloc); // BSS size
+ D_long(0x00000000); // Symbol size
+ D_long(0x00000000); // First entry (0L)
+ D_long(0x00000000); // TEXT relocation size
+ D_long(0x00000000); // BSD relocation size
// Construct TEXT and DATA segments (without relocation changes)
p = buf + BSDHDRSIZE;
D_long(strindx); // Write string table size
// Write the BSD object file from the object image buffer
- write(fd, buf, BSDHDRSIZE + tds + trsize + drsize + symsize + strindx + 4);
+ unused = write(fd, buf, BSDHDRSIZE + tds + trsize + drsize + symsize + strindx + 4);
if (buf)
free(buf); // Free allocated memory
IFENT * ifent; // Current ifent
SYM * lab_sym; // Label on line (or NULL)
-char extra_stuff[] = "extra (unexpected) text found after addressing mode";
-char * comma_error = "missing comma";
-char * syntax_error = "syntax error";
-char * locgl_error = "cannot GLOBL local symbol";
-char * lab_ignored = "label ignored";
+const char extra_stuff[] = "extra (unexpected) text found after addressing mode";
+const char comma_error[] = "missing comma";
+const char syntax_error[] = "syntax error";
+const char locgl_error[] = "cannot GLOBL local symbol";
+const char lab_ignored[] = "label ignored";
// Table to convert an addressing-mode number to a bitmask.
LONG amsktab[0112] = {
//
// Initialize Line Processor
//
-void init_procln(void)
+void InitLineProcessor(void)
{
disabled = 0;
ifent = &ifent0;
WORD rmask; // Register list, for REG
int registerbank; // RISC register bank
int riscreg; // RISC register
-
listflag = 0; // Initialise listing flag
loop: // Line processing loop label
// Get another line of tokens
- if (tokln() == TKEOF)
+ if (TokenizeLine() == TKEOF)
{
if (verb_flag) printf("Assemble: Found TKEOF flag...\n");
if (list_flag && listflag) // Flush last line of source
sy->sattre = EQUATEDREG | RISCSYM; // Mark as equated register
riscreg = (*tok - KW_R0);
//is there any reason to do this, since we're putting this in svalue?
- sy->sattre |= (riscreg << 8); // Store register number
-
+//i'm thinking, no. Let's test that out! :-D
+// sy->sattre |= (riscreg << 8); // Store register number
+//everything seems to build fine without it... We'll leave it here Just In Case(tm)
+
+#define DEBODGE_REGBANK
+#ifdef DEBODGE_REGBANK
+ // Default is current state of "regbank"
+ registerbank = regbank;
+#else
// Default is no register bank specified
registerbank = BANK_N;
+#endif
- // Check for ",<bank #>" notation
+ // Check for ",<bank #>" override notation
if ((tok[1] == ',') && (tok[2] == CONST))
{
// Advance token pointer to the constant
registerbank = BANK_1;
}
+#ifdef DEBODGE_REGBANK
+ sy->sattre |= registerbank; // Store register bank
+#else
// What needs to happen here is to prime registerbank with regbank, then use
// registerbank down below for the bank marking.
#warning "!!! regbank <-> registerbank confusion here !!!"
// not in what ends up in symbol->svalue?
// ".regbankN" is not an original Madmac directive, so it's suspect
sy->sattre |= regbank; // Store register bank
+#endif
eattr = ABS | DEFINED | GLOBAL;
// & what does this $80000080 constant mean???
// eval = 0x80000080 + (riscreg) + (registerbank << 8);
sy->stype = sy2->stype;
sy->sattr = sy2->sattr;
sy->sattre = sy2->sattre;
- sy->svalue = (sy2->svalue & 0xFFFFF0FF);
+//ICK sy->svalue = (sy2->svalue & 0xFFFFF0FF);
+ sy->svalue = sy2->svalue;
goto loop;
}
else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
{
do_label:
// Check for dot in front of label; means this is a local label if present
-#if 0
- j = 0;
-
- if (*label == '.')
- j = curenv;
-#else
j = (*label == '.' ? curenv : 0);
-#endif
-
sy = lookup(label, LABEL, j);
if (sy == NULL)
// Globals, externals etc
extern IFENT * ifent;
-extern char * comma_error;
-extern char * locgl_error;
-extern char * syntax_error;
+extern const char comma_error[];
+extern const char locgl_error[];
+extern const char syntax_error[];
+extern const char extra_stuff[];
extern int just_bss;
extern VALUE pcloc;
-extern IFENT * ifent;
+//extern IFENT * ifent;
extern SYM * lab_sym;
-extern char extra_stuff[];
extern LONG amsktab[];
// Prototypes
-void init_procln(void);
+void InitLineProcessor(void);
void Assemble(void);
int eject(void);
int d_if(void);
char * searchpath; // Search path for include files
char defname[] = "noname.o"; // Default output filename
-// Under Windows and UNIX malloc() is an expensive call, so for small amounts
-// of memory we allocate from a previously allocated buffer.
-
-#define A_AMOUNT 4096 // Amount to malloc() at a time
-#define A_THRESH 64 // Use malloc() for amounts >= A_THRESH
-
-static LONG a_amount; // Amount left at a_ptr
-static char * a_ptr; // Next free chunk
-LONG amemtot; // amem() total of requests
-
-// Qsort; The THRESHold below is the insertion sort threshold, and has been adjusted
-// for records of size 48 bytes.The MTHREShold is where we stop finding a better median.
-
-#define THRESH 4 // Threshold for insertion
-#define MTHRESH 6 // Threshold for median
-
-static int (*qcmp)(); // The comparison routine
-static int qsz; // Size of each record
-static int thresh; // THRESHold in chars
-static int mthresh; // MTHRESHold in chars
-
-// This is unused BOLLOCKS
-#if 0
-//
-// qst: Do a quicksort. First, find the median element, and put that one in the
-// first place as the discriminator. (This "median" is just the median of the
-// first, last and middle elements). (Using this median instead of the first
-// element is a big win). Then, the usual partitioning/swapping, followed by
-// moving the discriminator into the right place. Then, figure out the sizes of
-// the two partions, do the smaller one recursively and the larger one via a
-// repeat of this code. Stopping when there are less than THRESH elements in a
-// partition and cleaning up with an insertion sort (in our caller) is a huge
-// win. All data swaps are done in-line, which is space-losing but time-saving.
-// (And there are only three places where this is done).
-//
-static int qst(char * base, char * max)
-{
- char c, * i, * j, * jj;
- int ii;
- char * mid, * tmp;
- long lo, hi;
-
- /*
- * At the top here, lo is the number of characters of elements in the
- * current partition. (Which should be max - base).
- * Find the median of the first, last, and middle element and make
- * that the middle element. Set j to largest of first and middle.
- * If max is larger than that guy, then it's that guy, else compare
- * max with loser of first and take larger. Things are set up to
- * prefer the middle, then the first in case of ties.
- */
- lo = max - base; /* number of elements as chars */
-
- do
- {
- mid = i = base + qsz * ((lo / qsz) >> 1);
-
- if (lo >= mthresh)
- {
- j = (qcmp((jj = base), i) > 0 ? jj : i);
-
- if (qcmp(j, (tmp = max - qsz)) > 0)
- {
- /* switch to first loser */
- j = (j == jj ? i : jj);
-
- if (qcmp(j, tmp) < 0)
- j = tmp;
- }
-
- if (j != i)
- {
- ii = qsz;
-
- do
- {
- c = *i;
- *i++ = *j;
- *j++ = c;
- }
- while (--ii);
- }
- }
-
- /*
- * Semi-standard quicksort partitioning/swapping
- */
- for(i=base, j=max-qsz; ;)
- {
- while (i < mid && qcmp(i, mid) <= 0)
- i += qsz;
-
- while (j > mid)
- {
- if (qcmp(mid, j) <= 0)
- {
- j -= qsz;
- continue;
- }
-
- tmp = i + qsz; /* value of i after swap */
-
- if (i == mid)
- {
- /* j <-> mid, new mid is j */
- mid = jj = j;
- }
- else
- {
- /* i <-> j */
- jj = j;
- j -= qsz;
- }
-
- goto swap;
- }
-
- if (i == mid)
- {
- break;
- }
- else
- {
- /* i <-> mid, new mid is i */
- jj = mid;
- tmp = mid = i; /* value of i after swap */
- j -= qsz;
- }
-swap:
- ii = qsz;
-
- do
- {
- c = *i;
- *i++ = *jj;
- *jj++ = c;
- }
- while (--ii);
-
- i = tmp;
- }
-
- /*
- * Look at sizes of the two partitions, do the smaller
- * one first by recursion, then do the larger one by
- * making sure lo is its size, base and max are update
- * correctly, and branching back. But only repeat
- * (recursively or by branching) if the partition is
- * of at least size THRESH.
- */
- i = (j = mid) + qsz;
-
- if ((lo = j - base) <= (hi = max - i))
- {
- if (lo >= thresh)
- qst(base, j);
-
- base = i;
- lo = hi;
- }
- else
- {
- if (hi >= thresh)
- qst(i, max);
-
- max = j;
- }
- }
- while (lo >= thresh);
-
- return 0;
-}
-
-
-/*
- * qsort:
- * First, set up some global parameters for qst to share. Then, quicksort
- * with qst(), and then a cleanup insertion sort ourselves. Sound simple?
- * It's not...
- */
-int rmac_qsort(char * base, int n, int size, int (*compar)())
-{
- register char c, * i, * j, * lo, * hi;
- char * min, * max;
-
- if (n <= 1)
- return 0;
-
- qsz = size;
- qcmp = compar;
- thresh = qsz * THRESH;
- mthresh = qsz * MTHRESH;
- max = base + n * qsz;
-
- if (n >= THRESH)
- {
- qst(base, max);
- hi = base + thresh;
- }
- else
- {
- hi = max;
- }
-
- /*
- * First put smallest element, which must be in the first THRESH, in
- * the first position as a sentinel. This is done just by searching
- * the first THRESH elements (or the first n if n < THRESH), finding
- * the min, and swapping it into the first position.
- */
- for(j=lo=base; (lo+=qsz)<hi;)
- {
- if (qcmp(j, lo) > 0)
- j = lo;
- }
-
- if (j != base)
- {
- /* swap j into place */
- for(i=base, hi=base+qsz; i<hi;)
- {
- c = *j;
- *j++ = *i;
- *i++ = c;
- }
- }
-
- /*
- * With our sentinel in place, we now run the following hyper-fast
- * insertion sort. For each remaining element, min, from [1] to [n-1],
- * set hi to the index of the element AFTER which this one goes.
- * Then, do the standard insertion sort shift on a character at a time
- * basis for each element in the frob.
- */
- for(min=base; (hi=min+=qsz)<max;)
- {
- while (qcmp(hi -= qsz, min) > 0)
- /* void */;
-
- if ((hi += qsz) != min)
- {
- for(lo=min+qsz; --lo>=min;)
- {
- c = *lo;
-
- for(i=j=lo; (j-=qsz)>=hi; i=j)
- *i = *j;
-
- *i = c;
- }
- }
- }
-
- return 0;
-}
-#endif
-
-#if 0
-//
-// Allocate memory; Panic and Quit if we Run Out
-//
-char * amem(LONG amount)
-{
- char * p;
-
-// if (amount & 1) // Keep word alignment
-// amount++;
- amount = (amount + 1) & ~(0x01); // Keep word alignment
-
- // Honor *small* request (< 64 bytes)
- if (amount < A_THRESH)
- {
- if (a_amount < amount)
- {
- a_ptr = amem(A_AMOUNT); // Allocate 4K bytes
- a_amount = A_AMOUNT;
- }
-
- p = a_ptr;
- a_ptr += amount;
- a_amount -= amount;
- }
- else
- {
- amemtot += amount; // Bump total alloc
- p = (char *)malloc(amount); // Get memory from malloc
-
- if (p == NULL)
- fatal("Memory exhausted!");
-
- memset(p, 0, amount);
- }
-
- return p;
-}
-#endif
-
//
// Copy stuff around, return pointer to dest+count+1 (doesn't handle overlap)
//
void display_help(void)
{
- printf("Usage:\n");
- printf(" %s [options] srcfile\n", cmdlnexec);
- printf("\n");
- printf("Options:\n");
- printf(" -? or -h display usage information\n");
- printf(" -dsymbol[=value] define symbol\n");
- printf(" -e[errorfile] send error messages to file, not stdout\n");
- printf(" -f[format] output object file format\n");
- printf(" b: BSD (use this for Jaguar)\n");
- printf(" -i[path] directory to search for include files\n");
- printf(" -l[filename] create an output listing file\n");
- printf(" -o file output file name\n");
- printf(" -r[size] pad segments to boundary size specified\n");
- printf(" w: word (2 bytes, default alignment)\n");
- printf(" l: long (4 bytes)\n");
- printf(" p: phrase (8 bytes)\n");
- printf(" d: double phrase (16 bytes)\n");
- printf(" q: quad phrase (32 bytes)\n");
- printf(" -s warn about possible short branches\n");
- printf(" -u force referenced and undefined symbols global\n");
- printf(" -v set verbose mode\n");
- printf(" -y[pagelen] set page line length (default: 61)\n");
- printf("\n");
+ printf("Usage:\n"
+ " %s [options] srcfile\n"
+ "\n"
+ "Options:\n"
+ " -? or -h Display usage information\n"
+ " -dsymbol[=value] Define symbol\n"
+ " -e[errorfile] Send error messages to file, not stdout\n"
+ " -f[format] Output object file format\n"
+ " b: BSD (use this for Jaguar)\n"
+ " -i[path] Directory to search for include files\n"
+ " -l[filename] Create an output listing file\n"
+ " -o file Output file name\n"
+ " -r[size] Pad segments to boundary size specified\n"
+ " w: word (2 bytes, default alignment)\n"
+ " l: long (4 bytes)\n"
+ " p: phrase (8 bytes)\n"
+ " d: double phrase (16 bytes)\n"
+ " q: quad phrase (32 bytes)\n"
+ " -s Warn about possible short branches\n"
+ " -u Force referenced and undefined symbols global\n"
+ " -v Set verbose mode\n"
+ " -y[pagelen] Set page line length (default: 61)\n"
+ "\n", cmdlnexec);
}
//
void display_version(void)
{
- printf("\nReboot's Macro Assembler for Atari Jaguar\n");
- printf("Copyright (C) 199x Landon Dyer, 2011 Reboot\n");
- printf("V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
+ printf("\nReboot's Macro Assembler for Atari Jaguar\n"
+ "Copyright (C) 199x Landon Dyer, 2011 Reboot\n"
+ "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
}
regbank = BANK_N; // No RISC register bank specified
orgactive = 0; // Not in RISC org section
orgwarning = 0; // No ORG warning issued
- a_amount = 0;
segpadsize = 2; // Initialise segment padding size
// Initialise modules
InitSymbolTable(); // Symbol table
- init_token(); // Tokenizer
- init_procln(); // Line processor
- init_expr(); // Expression analyzer
- init_sect(); // Section manager / code generator
- init_mark(); // Mark tape-recorder
+ InitTokenizer(); // Tokenizer
+ InitLineProcessor(); // Line processor
+ InitExpression(); // Expression analyzer
+ InitSection(); // Section manager / code generator
+ InitMark(); // Mark tape-recorder
InitMacro(); // Macro processor
- init_list(); // Listing generator
+ InitListing(); // Listing generator
// Process command line arguments and assemble source files
for(argno=0; argno<argc; ++argno)
if (argv[argno][2] == EOS)
{
printf("-d: empty symbol\n");
- ++errcnt;
+ errcnt++;
return errcnt;
}
}
sy->sattr = DEFINED | EQUATED | ABS;
-
+#if 0
if (*s)
sy->svalue = (VALUE)atoi(s);
else
sy->svalue = 0;
-
+#else
+ sy->svalue = (*s ? (VALUE)atoi(s) : 0);
+#endif
break;
case 'e': // Redirect error message output
case 'E':
void init_sym(void);
SYM * newsym(char *, int, int);
char * fext(char *, char *, int);
-void cantcreat(char *);
int kmatch(char *, int *, int *, int *, int *);
void autoeven(int);
int nthpath(char *, int, char *);
void clear(char *, LONG);
char * copy(char *, char *, LONG);
-//int rmac_qsort(char *, int, int, int (*)());
#endif // __RMAC_H__
#include "token.h"
+// Function prototypes
+void mksect(int, WORD);
+void switchsect(int);
+
// Section descriptors
SECT sect[NSECTS]; // All sections...
int cursect; // Current section number
LONG fchsize; // # bytes used in fixup chunk
PTR fchptr; // Deposit point in fixup chunk buffer
-// BOLLOCKS
-//unsigned fwdjump[MAXFWDJUMPS]; // forward jump check table
-//unsigned fwindex = 0; // forward jump index
-
// Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is
// associated with a location.
static char fusiztab[] = {
};
+//
+// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections
+//
+void InitSection(void)
+{
+ int i;
+
+ // Cleanup all sections
+ for(i=0; i<NSECTS; i++)
+ mksect(i, 0);
+
+ // Construct default sections, make TEXT the current section
+ mksect(ABS, SUSED | SABS | SBSS); // ABS
+ mksect(TEXT, SUSED | TEXT ); // TEXT
+ mksect(DATA, SUSED | DATA ); // DATA
+ mksect(BSS, SUSED | BSS | SBSS ); // BSS
+// mksect(M6502, SUSED | TEXT ); // 6502 code section
+
+ switchsect(TEXT); // Switch to TEXT for starters
+}
+
+
//
// Make a New (Clean) Section
//
}
-//
-// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections
-//
-void init_sect(void)
-{
- int i;
-
- // Cleanup all sections
- for(i=0; i<NSECTS; i++)
- mksect(i, 0);
-
- // Construct default sections, make TEXT the current section
- mksect(ABS, SUSED | SABS | SBSS); // ABS
- mksect(TEXT, SUSED | TEXT ); // TEXT
- mksect(DATA, SUSED | DATA ); // DATA
- mksect(BSS, SUSED | BSS | SBSS ); // BSS
-// mksect(M6502, SUSED | TEXT ); // 6502 code section
-
- switchsect(TEXT); // Switch to TEXT for starters
-}
-
-
//
// Test to see if a location has a fixup sic'd on it. This is used by the
// listing generator to print 'xx's instead of '00's for forward references
// Macros to deposit code in the current section
// D_rword deposits a "6502" format (low, high) word (01).
// D_rlong deposits a MWC "canonical byte order" longword (2301).
-#define D_byte(b) {*chptr++=(char)b; ++sloc; ++ch_size; if(orgactive) ++orgaddr;}
-#define D_word(w) {chcheck(2);*chptr++=(char)(w>>8); *chptr++=(char)w; \
- sloc+=2; ch_size+=2; if(orgactive) orgaddr += 2;}
-#define D_long(lw) {*chptr++=(char)(lw>>24); *chptr++=(char)(lw>>16);\
- *chptr++=(char)(lw>>8); *chptr++=(char)lw; \
- sloc+=4; ch_size += 4; if(orgactive) orgaddr += 4;}
-#define D_rword(w) {*chptr++=(char)w; *chptr++=(char)(w>>8); \
- sloc+=2; ch_size+=2;if(orgactive) orgaddr += 2;}
-#define D_rlong(lw) {*chptr++=(char)(lw>>16);*chptr++=(char)(lw>>24);\
- *chptr++=(char)lw;*chptr++=(char)(lw>>8); \
- sloc+=4; ch_size += 4;if(orgactive) orgaddr += 4;}
+#define D_byte(b) {*chptr++=(char)b; ++sloc; ++ch_size; if(orgactive) ++orgaddr;}
+#define D_word(w) {chcheck(2);*chptr++=(char)(w>>8); *chptr++=(char)w; \
+ sloc+=2; ch_size+=2; if(orgactive) orgaddr += 2;}
+#define D_long(lw) {*chptr++=(char)(lw>>24); *chptr++=(char)(lw>>16);\
+ *chptr++=(char)(lw>>8); *chptr++=(char)lw; \
+ sloc+=4; ch_size += 4; if(orgactive) orgaddr += 4;}
+//#define D_rword(w) {*chptr++=(char)w; *chptr++=(char)(w>>8); \
+// sloc+=2; ch_size+=2;if(orgactive) orgaddr += 2;}
+//#define D_rlong(lw) {*chptr++=(char)(lw>>16);*chptr++=(char)(lw>>24);\
+// *chptr++=(char)lw;*chptr++=(char)(lw>>8); \
+// sloc+=4; ch_size += 4;if(orgactive) orgaddr += 4;}
#define NSECTS 16 // Max. number of sections
extern CHUNK * scode;
// Prototypes
-void init_sect(void);
+void InitSection(void);
void switchsect(int);
void savsect(void);
int fixtest(int, LONG);
int chcheck(LONG);
int fixup(WORD, LONG, TOKEN *);
int ResolveAllFixups(void);
-//int ResolveFixups(int);
#endif // __SECT_H__
};
+//
+// Initialize Tokenizer
+//
+void InitTokenizer(void)
+{
+ int i; // Iterator
+ char * htab = "0123456789abcdefABCDEF"; // Hex character table
+
+ lnsave = 0; // Don't save lines
+ curfname = ""; // No file, empty filename
+ filecount = (WORD)-1;
+ cfileno = (WORD)-1; // cfileno gets bumped to 0
+ curlineno = 0;
+ totlines = 0;
+ etok = tokbuf;
+ f_inobj = NULL;
+ f_ifile = NULL;
+ f_imacro = NULL;
+ cur_inobj = NULL;
+ filerec = NULL;
+ last_fr = NULL;
+ lntag = SPACE;
+
+ // Initialize hex, "dot" and tolower tables
+ for(i=0; i<128; i++)
+ {
+ hextab[i] = -1;
+ dotxtab[i] = 0;
+ tolowertab[i] = (char)i;
+ }
+
+ for(i=0; htab[i]!=EOS; i++)
+ hextab[htab[i]] = (char)((i < 16) ? i : i - 6);
+
+ for(i='A'; i<='Z'; i++)
+ tolowertab[i] |= 0x20;
+
+ // These characters are legal immediately after a period
+ dotxtab['b'] = DOTB; // .b .B .s .S
+ dotxtab['B'] = DOTB;
+ dotxtab['s'] = DOTB;
+ dotxtab['S'] = DOTB;
+ dotxtab['w'] = DOTW; // .w .W
+ dotxtab['W'] = DOTW;
+ dotxtab['l'] = DOTL; // .l .L
+ dotxtab['L'] = DOTL;
+ dotxtab['i'] = DOTI; // .i .I (???)
+ dotxtab['I'] = DOTI;
+}
+
+
void SetFilenameForErrorReporting(void)
{
WORD fnum = cfileno;
//
// Get Next Line of Text from a Macro
//
-char * getmln(void)
+char * GetNextMacroLine(void)
{
unsigned source_addr;
// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ);
-// bollocks
-#if 0
- if (!strcmp(imacro->im_macro->sname, "mjump") && !mjump_align)
- {
- // if we need to adjust the alignment of the jump source address to
- // meet the rules of gpu main execution we need to skip the first nop
- // of the macro. This is simpler than trying to insert nop's mid macro.
- source_addr = (orgactive ? orgaddr : sloc);
- source_addr += 8;
-
- if (source_addr % 4)
- {
- strp = imacro->im_nextln;
-
- if (strp == NULL)
- return NULL;
-
-// imacro->im_nextln = (LONG *)*strp;
-// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
- imacro->im_nextln = strp->next;
- ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ);
- }
-
- mjump_align = 1;
- }
-#endif
-
return imacro->im_lnbuf;
}
//
// Get Next Line of Text from a Repeat Block
//
-char * getrln(void)
+char * GetNextRepeatLine(void)
{
IREPT * irept = cur_inobj->inobj.irept;
}
-//
-// Initialize Tokenizer
-//
-void init_token(void)
-{
- int i; // Iterator
- char * htab = "0123456789abcdefABCDEF"; // Hex character table
-
- lnsave = 0; // Don't save lines
- curfname = ""; // No file, empty filename
- filecount = (WORD)-1;
- cfileno = (WORD)-1; // cfileno gets bumped to 0
- curlineno = 0;
- totlines = 0;
- etok = tokbuf;
- f_inobj = NULL;
- f_ifile = NULL;
- f_imacro = NULL;
- cur_inobj = NULL;
- filerec = NULL;
- last_fr = NULL;
- lntag = SPACE;
-
- // Initialize hex, "dot" and tolower tables
- for(i=0; i<128; i++)
- {
- hextab[i] = -1;
- dotxtab[i] = 0;
- tolowertab[i] = (char)i;
- }
-
- for(i=0; htab[i]!=EOS; i++)
- hextab[htab[i]] = (char)((i < 16) ? i : i - 6);
-
- for(i='A'; i<='Z'; i++)
- tolowertab[i] |= 0x20;
-
- // These characters are legal immediately after a period
- dotxtab['b'] = DOTB; // .b .B .s .S
- dotxtab['B'] = DOTB;
- dotxtab['s'] = DOTB;
- dotxtab['S'] = DOTB;
- dotxtab['w'] = DOTW; // .w .W
- dotxtab['W'] = DOTW;
- dotxtab['l'] = DOTL; // .l .L
- dotxtab['L'] = DOTL;
- dotxtab['I'] = DOTI; // .l .L
- dotxtab['I'] = DOTI;
-}
-
-
//
// Pop the Current Input Level
//
// Get line from file into buf, return NULL on EOF or ptr to the start of a
// null-term line
//
-char * getln(void)
+char * GetNextLine(void)
{
int i, j;
char * p, * d;
//
// Tokenize a Line
//
-int tokln(void)
+int TokenizeLine(void)
{
char * ln = NULL; // Ptr to current position in line
char * p; // Random character ptr
char c1;
int stringNum = 0; // Pointer to string locations in tokenized line
- retry:
+retry:
if (cur_inobj == NULL) // Return EOF if input stack is empty
return TKEOF;
// o tag the listing-line with a space;
// o kludge lines generated by Alcyon C.
case SRC_IFILE:
- if ((ln = getln()) == NULL)
+ if ((ln = GetNextLine()) == NULL)
{
-if (verb_flag) printf("tokln: Calling fpop() from SRC_IFILE...\n");
+if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n");
fpop(); // Pop input level
goto retry; // Try for more lines
}
// o Handle end-of-macro;
// o tag the listing-line with an at (@) sign.
case SRC_IMACRO:
- if ((ln = getmln()) == NULL)
+ if ((ln = GetNextMacroLine()) == NULL)
{
ExitMacro(); // Exit macro (pop args, do fpop(), etc)
goto retry; // Try for more lines...
// o Handle end-of-repeat-block;
// o tag the listing-line with a pound (#) sign.
case SRC_IREPT:
- if ((ln = getrln()) == NULL)
+ if ((ln = GetNextRepeatLine()) == NULL)
{
-if (verb_flag) printf("tokln: Calling fpop() from SRC_IREPT...\n");
+if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n");
fpop();
goto retry;
}
break;
default:
warn("bad backslash code in string");
- --ln;
+ ln--;
break;
}
}
if (*ln == '.')
{
- if ((*(ln+1) == 'b') || (*(ln+1) == 'B'))
+ if ((*(ln + 1) == 'b') || (*(ln + 1) == 'B'))
{
v &= 0x000000FF;
ln += 2;
}
- if ((*(ln+1) == 'w') || (*(ln+1) == 'W'))
+ if ((*(ln + 1) == 'w') || (*(ln + 1) == 'W'))
{
v &= 0x0000FFFF;
ln += 2;
}
- if ((*(ln+1) == 'l') || (*(ln+1) == 'L'))
+ if ((*(ln + 1) == 'l') || (*(ln + 1) == 'L'))
{
ln += 2;
}
{
case '>':
*tk++ = SHR;
- ++ln;
+ ln++;
continue;
case '=':
*tk++ = GE;
- ++ln;
+ ln++;
continue;
default:
*tk++ = '>';
{
// Compare names (sleazo string compare)
// This string compare is not right. Doesn't check for lengths.
+ // (actually it does, but in a crappy, unclear way.)
#warning "!!! Bad string comparison !!!"
s1 = sym;
// s2 = (char *)(defln + 1) + 1;
// Prototypes
int include(int, char *);
-void init_token(void);
+void InitTokenizer(void);
void SetFilenameForErrorReporting(void);
-int tokln(void);
+int TokenizeLine(void);
int fpop(void);
int d_goto(WORD);
//int d_goto(void);