#include "mntab.h"
// Address-mode information
-int nmodes; // Number of addr'ing modes found
-int am0; // Addressing mode
-int a0reg; // Register
-TOKEN a0expr[EXPRSIZE]; // Expression
-VALUE a0exval; // Expression's value
-WORD a0exattr; // Expression's attribute
-int a0ixreg; // Index register
-int a0ixsiz; // Index register size (and scale)
-TOKEN a0oexpr[EXPRSIZE]; // Outer displacement expression
-VALUE a0oexval; // Outer displacement value
-WORD a0oexattr; // Outer displacement attribute
-SYM * a0esym; // External symbol involved in expr
-
-int am1; // Addressing mode
-int a1reg; // Register
-TOKEN a1expr[EXPRSIZE]; // Expression
-VALUE a1exval; // Expression's value
-WORD a1exattr; // Expression's attribute
-int a1ixreg; // Index register
-int a1ixsiz; // Index register size (and scale)
-TOKEN a1oexpr[EXPRSIZE]; // Outer displacement expression
-VALUE a1oexval; // Outer displacement value
-WORD a1oexattr; // Outer displacement attribute
-SYM * a1esym; // External symbol involved in expr
+int nmodes; // Number of addr'ing modes found
+int am0; // Addressing mode
+int a0reg; // Register
+TOKEN a0expr[EXPRSIZE]; // Expression
+VALUE a0exval; // Expression's value
+WORD a0exattr; // Expression's attribute
+int a0ixreg; // Index register
+int a0ixsiz; // Index register size (and scale)
+TOKEN a0oexpr[EXPRSIZE]; // Outer displacement expression
+VALUE a0oexval; // Outer displacement value
+WORD a0oexattr; // Outer displacement attribute
+SYM * a0esym; // External symbol involved in expr
+
+int am1; // Addressing mode
+int a1reg; // Register
+TOKEN a1expr[EXPRSIZE]; // Expression
+VALUE a1exval; // Expression's value
+WORD a1exattr; // Expression's attribute
+int a1ixreg; // Index register
+int a1ixsiz; // Index register size (and scale)
+TOKEN a1oexpr[EXPRSIZE]; // Outer displacement expression
+VALUE a1oexval; // Outer displacement value
+WORD a1oexattr; // Outer displacement attribute
+SYM * a1esym; // External symbol involved in expr
//
-// Parse Addressing Mode
+// Parse addressing mode
//
int amode(int acount)
{
//
-// Parse Register List
+// Parse register list
//
int reglist(WORD * a_rmask)
{
//
-// Print 'c' Visibly
+// Print 'c' visibly
//
int visprt(char c)
{
//
-// Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together:
+// Dump memory from 'start' for 'count' bytes; `flg' is the following ORed
+// together:
// 0 - bytes
// 1 - words
// 2 - longwords
//
-// if `base' is not -1, then print it at the start of each line, incremented accordingly.
+// if `base' is not -1, then print it at the start of each line, incremented
+// accordingly.
//
int mdump(char * start, LONG count, int flg, LONG base)
{
base += 1 << (flg & 3);
}
- // Print remaining bit of ascii; the hairy expression computes the number of
- // spaces to print to make the ascii line up nicely.
+ // Print remaining bit of ASCII; the hairy expression computes the number
+ // of spaces to print to make the ASCII line up nicely.
if (j != i)
{
k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3];
//
-// Dump Everything
+// Dump everything
//
int dump_everything(void)
{
if (*tok != EOL)
{
-// error("syntax error");
sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
error(msg);
}
//
-// Cannot Create a File
+// Cannot create a file
//
void cantcreat(const char * fn)
{
//
-// Setup for Error Message
+// Setup for error message
// o Create error listing file (if necessary)
// o Set current filename
//
//
-// Display Error Message
+// Display error message
//
int error(const char * s)
{
//
-// Initialize Macro Processor
+// Initialize macro processor
//
void InitMacro(void)
{
//
-// Exit from a Macro;
+// Exit from a macro;
// -- pop any intervening include files and repeat blocks;
// -- restore argument stack;
// -- pop the macro.
//
-// Add a Formal Argument to a Macro Definition
+// Add a formal argument to a macro definition
//
int defmac2(char * argname)
{
Shamus:
This construct is meant to deal with nested macros, so the simple minded way
we deal with them now won't work. :-/ Have to think about how to fix.
-What we could do is simply move the argp with each call, and move it back by the
-number of arguments in the macro that's ending. That would solve the problem nicely.
+What we could do is simply move the argp with each call, and move it back by
+the number of arguments in the macro that's ending. That would solve the
+problem nicely.
[Which we do now. But that uncovered another problem: the token strings are all
-stale by the time a nested macro gets to the end. But they're supposed to be symbols,
-which means if we put symbol references into the argument token streams, we can
-alleviate this problem.]
+stale by the time a nested macro gets to the end. But they're supposed to be
+symbols, which means if we put symbol references into the argument token
+streams, we can alleviate this problem.]
*/
#if 0
argptr = (TOKEN **)malloc((nargs + 1) * sizeof(LONG));
PTR markptr; // Deposit point in current mark chunk
LONG mcalloc; // #bytes alloc'd to current mark chunk
LONG mcused; // #bytes used in current mark chunk
-uint16_t curfrom; // Current "from" section
+uint16_t curfrom; // Current "from" section
//#define DEBUG_IMAGE_MARKING
//
-// Initialize Marker
+// Initialize marker
//
void InitMark(void)
{
//
// Wrap up marker (called after final mark is made)
//
-void stopmark(void)
+void StopMark(void)
{
if (curmch)
{
{
if (w & (DATA|BSS))
{
- dp = objimage + BSDHDRSIZE + loc;
+ dp = objImage + BSDHDRSIZE + loc;
diff = ((LONG)(*dp++ & 0xFF)) << 24;
diff |= ((LONG)(*dp++ & 0xFF)) << 16;
diff |= ((LONG)(*dp++ & 0xFF)) << 8;
if (rflag & 0x01)
diff = ((diff >> 16) & 0x0000FFFF) | ((diff << 16) & 0xFFFF0000);
- dp = objimage + BSDHDRSIZE + loc;
+ dp = objImage + BSDHDRSIZE + loc;
*dp++ = (char)(diff >> 24);
*dp++ = (char)(diff >> 16);
*dp++ = (char)(diff >> 8);
#define MARK_ALLOC_INCR 1024 // # bytes to alloc for more mark space
#define MIN_MARK_MEM (3 * sizeof(WORD) + 2 * sizeof(LONG))
-// Globals, Externals etc
+// Globals, externals, etc.
extern MCHUNK * firstmch;
-// Prototypes
+// Exported functions
void InitMark(void);
-void stopmark(void);
-//int rmark(int, LONG, int, int, SYM *);
+void StopMark(void);
int rmark(uint16_t, uint32_t, uint16_t, uint16_t, SYM *);
int amark(void);
LONG bsdmarkimg(char *, LONG, LONG, int);
#endif // __MARK_H__
+
LONG symsize = 0; // Size of BSD symbol table
LONG strindx = 0x00000004; // BSD string table index
char * strtable; // Pointer to the symbol string table
-char * objimage; // Global object image pointer
+char * objImage; // Global object image pointer
//
//
-// Generate object file
+// Write an object file to the passed in file descriptor
+// N.B.: Return value is ignored...
//
-int object(WORD fd)
+int WriteObject(int fd)
{
LONG t; // Scratch long
LONG tds; // TEXT & DATA segment size
return ERROR;
}
- memset(buf, 0, 0x600000); // Reset allocated memory
- objimage = buf; // Set global object image pointer
- strtable = malloc(0x200000); // Allocate 2mb scratch buffer
+ memset(buf, 0, 0x600000); // Reset allocated memory
+ objImage = buf; // Set global object image pointer
+ strtable = malloc(0x200000); // Allocate 2mb scratch buffer
if (strtable == NULL)
{
return ERROR;
}
- memset(strtable, 0, 0x200000); // Reset allocated memory
+ memset(strtable, 0, 0x200000); // Reset allocated memory
// Build object file header
- chptr = buf; // Base of header
- 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
+ chptr = buf; // Base of header
+ 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;
{
for(cp=sect[i].sfcode; cp!=NULL; cp=cp->chnext)
{
- copy(p, cp->chptr, cp->ch_size);
+ memcpy(p, cp->chptr, cp->ch_size);
p += cp->ch_size;
}
}
return 0;
}
+
#ifndef __OBJECT_H__
#define __OBJECT_H__
-#include "rmac.h"
+// Size of BSD header
+#define BSDHDRSIZE 0x20
-#define BSDHDRSIZE 0x20 // Size of BSD header
+// Globals, externals, etc.
+extern char * objImage;
-// Globals, externals etc
-extern char * objimage;
-
-// Prototypes
-int object(WORD);
+// Exported functions
+int WriteObject(int);
#endif // __OBJECT_H__
+
//
-// Initialize Line Processor
+// Initialize line processor
//
void InitLineProcessor(void)
{
//
-// Line Processor
+// Line processor
//
void Assemble(void)
{
//
-// .if, Start Conditional Assembly
+// .if, Start conditional assembly
//
int d_if(void)
{
//
-// .else, Do Alternate Case For .if
+// .else, Do alternate case for .if
//
int d_else(void)
{
const char reg_err[] = "missing register R0...R31";
-// Jaguar Jump Condition Names
+// Jaguar jump condition names
const char condname[MAXINTERNCC][5] = {
"NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ",
"N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO",
"PL", "MI", "F"
};
-// Jaguar Jump Condition Numbers
+// Jaguar jump condition numbers
const char condnumber[] = {
1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26,
0, 0, 1, 2, 4, 4, 5, 8, 8, 20, 24, 31
#include "symbol.h"
#include "object.h"
-int perm_verb_flag; // Permanently verbose, interactive mode
-int list_flag; // "-l" Listing flag on command line
-int verb_flag; // Be verbose about what's going on
-int as68_flag; // as68 kludge mode
-int glob_flag; // Assume undefined symbols are global
-int lsym_flag; // Include local symbols in object file
-int sbra_flag; // Warn about possible short branches
-int legacy_flag; // Do stuff like insert code in RISC assembler
-int obj_format; // Object format flag
-int debug; // [1..9] Enable debugging levels
-int err_flag; // '-e' specified
-int err_fd; // File to write error messages to
-int rgpu, rdsp; // Assembling Jaguar GPU or DSP code
-int list_fd; // File to write listing to
-int regbank; // RISC register bank
-int segpadsize; // Segment padding size
-int endian; // Host processor endianess
-char * objfname; // Object filename pointer
-char * firstfname; // First source filename
-char * cmdlnexec; // Executable name, pointer to ARGV[0]
-char * searchpath; // Search path for include files
-char defname[] = "noname.o"; // Default output filename
-
-
-//
-// Copy stuff around, return pointer to dest+count+1 (doesn't handle overlap)
-//
-char * copy(char * dest, char * src, LONG count)
-{
- while (count--)
- *dest++ = *src++;
-
- return dest;
-}
-
-
-//
-// Clear a region of memory
-//
-void clear(char * dest, LONG count)
-{
- while(count--)
- *dest++ = 0;
-}
-
-
-//
-// Check to see if the string is a keyword. Returns -1, or a value from the
-// 'accept[]' table
-//
-int kmatch(char * p, int * base, int * check, int * tab, int * accept)
-{
- int state;
- int j;
-
- for(state=0; state>=0;)
- {
- j = base[state] + (int)tolowertab[*p];
-
- if (check[j] != state)
- { // Reject, character doesn't match
- state = -1; // No match
- break;
- }
-
- if (!*++p)
- { // Must accept or reject at EOS
- state = accept[j]; // (-1 on no terminal match)
- break;
- }
-
- state = tab[j];
- }
-
- return state;
-}
-
-
-//
-// Auto-even a section
-//
-void autoeven(int sect)
-{
- SwitchSection(sect);
- d_even();
- SaveSection();
-}
+int perm_verb_flag; // Permanently verbose, interactive mode
+int list_flag; // "-l" listing flag on command line
+int verb_flag; // Be verbose about what's going on
+int as68_flag; // as68 kludge mode
+int glob_flag; // Assume undefined symbols are global
+int lsym_flag; // Include local symbols in object file
+int sbra_flag; // Warn about possible short branches
+int legacy_flag; // Do stuff like insert code in RISC assembler
+int obj_format; // Object format flag
+int debug; // [1..9] Enable debugging levels
+int err_flag; // '-e' specified
+int err_fd; // File to write error messages to
+int rgpu, rdsp; // Assembling Jaguar GPU or DSP code
+int list_fd; // File to write listing to
+int regbank; // RISC register bank
+int segpadsize; // Segment padding size
+int endian; // Host processor endianess
+char * objfname; // Object filename pointer
+char * firstfname; // First source filename
+char * cmdlnexec; // Executable name, pointer to ARGV[0]
+char * searchpath; // Search path for include files
+char defname[] = "noname.o"; // Default output filename
//
// Manipulate file extension.
-// `name' must be large enough to hold any possible filename.
-// If `stripp' is nonzero, any old extension is removed.
-// Then, if the file does not already have an extension,
-// `extension' is appended to the filename.
+//
+// 'name' must be large enough to hold any possible filename. If 'stripp' is
+// nonzero, any old extension is removed. If the file does not already have an
+// extension, 'extension' is appended to the filename.
//
char * fext(char * name, char * extension, int stripp)
{
- char * s, * beg; // String pointers
+ char * s;
- // Find beginning of "real" name
- beg = name + strlen(name) - 1;
+ // Find beginning of "real" name (strip off path)
+ char * beg = strrchr(name, SLASHCHAR);
- for(; beg>name; --beg)
- {
- if (*beg == SLASHCHAR)
- {
- ++beg;
- break;
- }
- }
+ if (beg == NULL)
+ beg = name;
+ // Clobber any old extension, if requested
if (stripp)
- { // Clobber any old extension
+ {
for(s=beg; *s && *s!='.'; ++s)
;
*s = '\0';
}
- for(s=beg; *s!='.'; ++s)
- {
- if (!*s)
- { // Append the new extension
- strcat(beg, extension);
- break;
- }
- }
+ if (strrchr(beg, '.') == NULL)
+ strcat(beg, extension);
return name;
}
//
-// Return `item'nth element of semicolon-seperated pathnames specified in the
-// enviroment string `s'. Copy the pathname to `buf'. Return 0 if the `item'
+// Return 'item'nth element of semicolon-seperated pathnames specified in the
+// enviroment string 's'. Copy the pathname to 'buf'. Return 0 if the 'item'
// nth path doesn't exist.
//
-// [`item' ranges from 0 to N-1, where N = #elements in search path]
+// ['item' ranges from 0 to N-1, where N = #elements in search path]
//
int nthpath(char * env_var, int itemno, char * buf)
{
//
-// Display Command Line Help
+// Display command line help
//
-void display_help(void)
+void DisplayHelp(void)
{
printf("Usage:\n"
" %s [options] srcfile\n"
//
-// Display Version Information
+// Display version information
//
-void display_version(void)
+void DisplayVersion(void)
{
printf("\nReboot's Macro Assembler for Atari Jaguar\n"
"Copyright (C) 199x Landon Dyer, 2011 Reboot\n"
//
-// Process Command Line Arguments and do an Assembly
+// Process command line arguments and do an assembly
//
-int process(int argc, char ** argv)
+int Process(int argc, char ** argv)
{
int argno; // Argument number
SYM * sy; // Pointer to a symbol record
{
switch (argv[argno][1])
{
- case 'd': // Define symbol
+ case 'd': // Define symbol
case 'D':
for(s=argv[argno]+2; *s!=EOS;)
{
}
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': // Redirect error message output
case 'E':
err_fname = argv[argno] + 2;
break;
- case 'f': // -f<format>
+ case 'f': // -f<format>
case 'F':
switch (argv[argno][2])
{
case EOS:
- case 'b': // -fb = BSD (Jaguar Recommended)
+ case 'b': // -fb = BSD (Jaguar Recommended)
case 'B':
obj_format = BSD;
break;
return errcnt;
}
break;
- case 'g': // Debugging flag
+ case 'g': // Debugging flag
case 'G':
printf("Debugging flag (-g) not yet implemented\n");
break;
- case 'i': // Set directory search path
+ case 'i': // Set directory search path
case 'I':
searchpath = argv[argno] + 2;
break;
- case 'l': // Produce listing file
+ case 'l': // Produce listing file
case 'L':
list_fname = argv[argno] + 2;
listing = 1;
list_flag = 1;
lnsave++;
break;
- case 'o': // Direct object file output
+ case 'o': // Direct object file output
case 'O':
if (argv[argno][2] != EOS)
objfname = argv[argno] + 2;
}
break;
- case 'r': // Pad seg to requested boundary size
+ case 'r': // Pad seg to requested boundary size
case 'R':
switch(argv[argno][2])
{
case 'p': case 'P': segpadsize = 8; break;
case 'd': case 'D': segpadsize = 16; break;
case 'q': case 'Q': segpadsize = 32; break;
- default: segpadsize = 2; break; // Effective autoeven();
+ default: segpadsize = 2; break; // Effective autoeven();
}
break;
- case 's': // Warn about possible short branches
+ case 's': // Warn about possible short branches
case 'S':
sbra_flag = 1;
break;
- case 'u': // Make undefined symbols .globl
+ case 'u': // Make undefined symbols .globl
case 'U':
glob_flag = 1;
break;
- case 'v': // Verbose flag
+ case 'v': // Verbose flag
case 'V':
verb_flag++;
if (verb_flag > 1)
- display_version();
+ DisplayVersion();
break;
- case 'x': // Turn on debugging
+ case 'x': // Turn on debugging
case 'X':
debug = 1;
printf("~ Debugging ON\n");
break;
- case 'y': // -y<pagelen>
+ case 'y': // -y<pagelen>
case 'Y':
pagelen = atoi(argv[argno] + 2);
}
break;
- case EOS: // Input is stdin
- if (firstfname == NULL) // Kludge first filename
+ case EOS: // Input is stdin
+ if (firstfname == NULL) // Kludge first filename
firstfname = defname;
include(0, "(stdin)");
Assemble();
break;
- case 'h': // Display command line usage
+ case 'h': // Display command line usage
case 'H':
case '?':
- display_version();
- display_help();
+ DisplayVersion();
+ DisplayHelp();
errcnt++;
break;
- case 'n': // Turn off legacy mode
+ case 'n': // Turn off legacy mode
case 'N':
legacy_flag = 0;
printf("Legacy mode OFF\n");
break;
default:
- display_version();
+ DisplayVersion();
printf("Unknown switch: %s\n\n", argv[argno]);
- display_help();
+ DisplayHelp();
errcnt++;
break;
}
// Wind-up processing;
// o save current section (no more code generation)
- // o do auto-even of all sections (or boundary alignment as requested through '-r')
+ // o do auto-even of all sections (or boundary alignment as requested
+ // through '-r')
// o determine name of object file:
// - "foo.o" for linkable output;
// - "foo.prg" for GEMDOS executable (-p flag).
// (2) generate the output file image and symbol table;
// (3) generate relocation information from left-over fixups.
ResolveAllFixups(); // Do all fixups
- stopmark(); // Stop mark tape-recorder
+ StopMark(); // Stop mark tape-recorder
if (errcnt == 0)
{
printf("[Writing %s file: %s]\n", s, objfname);
}
- object((WORD)fd);
+ WriteObject(fd);
close(fd);
if (errcnt != 0)
//
-// Determine Processor Endianess
+// Determine processor endianess
//
-int get_endianess(void)
+int GetEndianess(void)
{
int i = 1;
char * p = (char *)&i;
//
-// Application Entry Point; Handle the Command Line
+// Application entry point
//
int main(int argc, char ** argv)
{
legacy_flag = 1; // Default is legacy mode on (:-P)
cmdlnexec = argv[0]; // Obtain executable name
- endian = get_endianess(); // Get processor endianess
+ endian = GetEndianess(); // Get processor endianess
// If commands were passed in, process them
if (argc > 1)
- {
- return process(argc - 1, argv + 1);
- }
+ return Process(argc - 1, argv + 1);
- display_version();
- display_help();
+ DisplayVersion();
+ DisplayHelp();
return 0;
}
// TARGET SPECIFIC BUILD SETTINGS
//
#ifdef WIN32
- #define PLATFORM "Win32" // Release platform - windows
+ // Release platform - windows
+ #define PLATFORM "Win32"
#define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR
#define _OPEN_INC _O_RDONLY|_O_BINARY
#define _PERM_MODE _S_IREAD|_S_IWRITE
#include <sys/stat.h>
#else
#ifdef __GCCUNIX__
- #define PLATFORM "OSX/Linux" // Release platform - mac OS-X or linux
+ // Release platform - mac OS-X or linux
+ #define PLATFORM "OSX/Linux"
#define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR
#define _OPEN_INC O_RDONLY
#define _PERM_MODE S_IREAD|S_IWRITE
#include <sys/stat.h>
#include <unistd.h>
#else
- #define PLATFORM "Unknown" // Release platform - not specified
+ // Release platform - not specified
+ #define PLATFORM "Unknown"
#define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR
#define _OPEN_INC O_RDONLY
#define _PERM_MODE S_IREAD|S_IWRITE
#define ERROR (-1) // Generic error return
#define EOS '\0' // End of string
-#define SPACE ' ' // Ascii space
+#define SPACE ' ' // ASCII space
#define SLASHCHAR '/'
#define SLASHSTRING "/"
#define VALUE LONG // Assembler value
//#define RISCSYM 0x00010000
-// Globals, externals etc
+// Globals, externals, etc.
extern int verb_flag;
extern int debug;
extern int rgpu, rdsp;
extern int sbra_flag;
extern int obj_format;
extern int legacy_flag;
-//extern LONG amemtot;
-// Prototypes
-void init_sym(void);
-SYM * newsym(char *, int, int);
+// Exported functions
char * fext(char *, char *, int);
-int kmatch(char *, int *, int *, int *, int *);
-void autoeven(int);
int nthpath(char *, int, char *);
-void clear(char *, LONG);
-char * copy(char *, char *, LONG);
#endif // __RMAC_H__
+
void SwitchSection(int);
// Section descriptors
-SECT sect[NSECTS]; // All sections...
-int cursect; // Current section number
+SECT sect[NSECTS]; // All sections...
+int cursect; // Current section number
// These are copied from the section descriptor, the current code chunk
// descriptor and the current fixup chunk descriptor when a switch is made into
// a section. They are copied back to the descriptors when the section is left.
-WORD scattr; // Section attributes
-LONG sloc; // Current loc in section
+WORD scattr; // Section attributes
+LONG sloc; // Current loc in section
-CHUNK * scode; // Current (last) code chunk
-LONG challoc; // # bytes alloc'd to code chunk
-LONG ch_size; // # bytes used in code chunk
-char * chptr; // Deposit point in code chunk buffer
+CHUNK * scode; // Current (last) code chunk
+LONG challoc; // # bytes alloc'd to code chunk
+LONG ch_size; // # bytes used in code chunk
+char * chptr; // Deposit point in code chunk buffer
-CHUNK * sfix; // Current (last) fixup chunk
-LONG fchalloc; // # bytes alloc'd to fixup chunk
-LONG fchsize; // # bytes used in fixup chunk
-PTR fchptr; // Deposit point in fixup chunk buffer
+CHUNK * sfix; // Current (last) fixup chunk
+LONG fchalloc; // # bytes alloc'd to fixup chunk
+LONG fchsize; // # bytes used in fixup chunk
+PTR fchptr; // Deposit point in fixup chunk buffer
// Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is
// associated with a location.
//
-// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections
+// Initialize sections; setup initial ABS, TEXT, DATA and BSS sections
//
void InitSection(void)
{
MakeSection(BSS, SUSED | BSS | SBSS); // BSS
// MakeSection(M6502, SUSED | TEXT ); // 6502 code section
- SwitchSection(TEXT); // Switch to TEXT for starters
+ // Switch to TEXT for starters
+ SwitchSection(TEXT);
}
//
-// Make a New (Clean) Section
+// Make a new (clean) section
//
void MakeSection(int sno, WORD attr)
{
//
void SwitchSection(int sno)
{
- CHUNK * cp; // Chunk pointer
+ CHUNK * cp;
cursect = sno;
SECT * p = §[sno];
- scattr = p->scattr; // Copy section vars
+ // Copy section vars
+ scattr = p->scattr;
sloc = p->sloc;
scode = p->scode;
sfix = p->sfix;
WORD w;
LONG xloc;
- stopmark(); // Force update to sect[] variables
+ // Force update to sect[] variables
+ StopMark();
- // Hairy, ugly linear search for a mark on our location;
- // the speed doesn't matter, since this is only done when generating a
- // listing, which is SLOW.
+ // Hairy, ugly linear search for a mark on our location; the speed doesn't
+ // matter, since this is only done when generating a listing, which is
+ // SLOW.
for(ch=sect[sno].sffix; ch!=NULL; ch=ch->chnext)
{
fup.cp = (char *)ch->chptr;
fup.lp += w;
}
else
- ++fup.lp;
+ fup.lp++;
}
}
//
-// Check that there are at least `amt' bytes left in the current chunk. If
-// there are not, allocate another chunk of at least `amt' bytes (and probably
+// Check that there are at least 'amt' bytes left in the current chunk. If
+// there are not, allocate another chunk of at least 'amt' bytes (and probably
// more).
//
-// If `amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise.
+// If 'amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise.
//
int chcheck(LONG amt)
{
}
-// This is really wrong. We need to make some proper structures here so we don't
-// have to count sizes of objects, that's what the compiler's for! :-P
+// This is really wrong. We need to make some proper structures here so we
+// don't have to count sizes of objects, that's what the compiler's for! :-P
#define FIXUP_BASE_SIZE (sizeof(WORD) + sizeof(LONG) + sizeof(WORD) + sizeof(WORD))
//
// Arrange for a fixup on a location
LONG len = 0;
CHUNK * cp;
SECT * p;
- // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix this.
+ // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix
+ // this.
#warning "!!! AddFixup() is filled with VOODOO !!!"
DEBUG printf("FIXUP@$%X: $%X\n", loc, attr);
if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR)
{
// Just a single symbol
- // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
+ // SCPCD : correct bit mask for attr (else other FU_xxx will match)
+ // NYAN !
if ((attr & FUMASKRISC) == FU_JR)
{
// i = 18;
//
-// Resolve all Fixups
+// Resolve all fixups
//
int ResolveAllFixups(void)
{
// Make undefined symbols GLOBL
if (glob_flag)
- syg_fix();
+ ForceUndefinedSymbolsGlobal();
DEBUG printf("Resolving TEXT sections...\n");
ResolveFixups(TEXT);
//
-// Resolve Fixups in a Section
+// Resolve fixups in a section
//
int ResolveFixups(int sno)
{
// "Cache" first chunk
CHUNK * cch = sc->sfcode;
- // Can't fixup a sect with nothing in it
+ // Can't fixup a section with nothing in it
if (cch == NULL)
return 0;
//
-// Initialize Symbol Table
+// Initialize symbol table
//
void InitSymbolTable(void)
{
//
-// Hash the Print Name and Enviroment Number
+// Hash the print name and enviroment number
//
int HashSymbol(char * name, int envno)
{
symbol->stype = (BYTE)type;
symbol->senv = (WORD)envno;
symbol->sattr = 0;
-//we don't do this, it could be a forward reference!
+ // Don't do this, it could be a forward reference!
// symbol->sattr = DEFINED; // We just defined it...
// This is a bad assumption. Not every symbol 1st seen in a RISC section is
// a RISC symbol!
//
// Make all referenced, undefined symbols global
//
-int syg_fix(void)
+void ForceUndefinedSymbolsGlobal(void)
{
SYM * sy;
- DEBUG printf("~syg_fix()\n");
+ DEBUG printf("~ForceUndefinedSymbolsGlobal()\n");
// Scan through all symbols;
// If a symbol is REFERENCED but not DEFINED, then make it global.
&& ((sy->sattr & (REFERENCED | DEFINED)) == REFERENCED))
sy->sattr |= GLOBAL;
}
-
- return 0;
}
int sy_assign(char * buf, char *(* constr)())
{
SYM * sy;
- int scount;
- //int i;
-
- scount = 0;
+ int scount = 0;
if (buf == NULL)
{
{
// Essentially the same as 'sym_decl()' above:
if (sy->sattr & SDECLLIST)
- continue; // Already on list
+ continue; // Already on list
- sy->sattr |= SDECLLIST; // Mark "on the list"
+ sy->sattr |= SDECLLIST; // Mark "on the list"
if (sdecl == NULL)
- sdecl = sy; // First on decl-list
+ sdecl = sy; // First on decl-list
else
- sdecltail->sdecl = sy; // Add to end of list
+ sdecltail->sdecl = sy; // Add to end of list
- sy->sdecl = NULL; // Fix up list's tail
+ sy->sdecl = NULL; // Fix up list's tail
sdecltail = sy;
}
}
// Allocate storage for list headers and partition all labels.
// Throw away macros and macro arguments.
-// sy = (SYM **)amem((LONG)(128 * sizeof(LONG)));
sy = (SYM **)malloc(128 * sizeof(LONG));
for(i=0; i<128; ++i)
j = *p->sname;
r = NULL;
- if (p->stype != LABEL)
- continue; // Ignore non-labels
-
- if (p->sattre & UNDEF_EQUR)
+ // Ignore non-labels
+ if ((p->stype != LABEL) || (p->sattre & UNDEF_EQUR))
continue;
for(q=sy[j]; q!=NULL; q=q->snext)
{
if (strcmp(p->sname, q->sname) < 0)
break;
- else
- r = q;
+
+ r = q;
}
if (r == NULL)
- { // Insert at front of list
+ {
+ // Insert at front of list
p->snext = sy[j];
sy[j] = p;
}
else
- { // Insert in middle or append to list
+ {
+ // Insert in middle or append to list
p->snext = r->snext;
r->snext = p;
}
return 0;
}
+
uint32_t uid; // Symbol's unique ID
};
-// Globals, externals etc
+// Globals, externals, etc.
extern int curenv;
extern char subttl[];
-// Prototypes
+// Exported functions
SYM * lookup(char *, int, int);
void InitSymbolTable(void);
SYM * NewSymbol(char *, int, int);
void AddToSymbolOrderList(SYM *);
-int syg_fix(void);
+void ForceUndefinedSymbolsGlobal(void);
int symtable(void);
int sy_assign(char *, char *(*)());
char * GetSymbolNameByUID(uint32_t);
#endif // __SYMBOL_H__
+
//
-// Initialize Tokenizer
+// Initialize tokenizer
//
void InitTokenizer(void)
{
//
-// Get Next Line of Text from a Macro
+// Get next line of text from a macro
//
char * GetNextMacroLine(void)
{
//
-// Get Next Line of Text from a Repeat Block
+// Get next line of text from a repeat block
//
char * GetNextRepeatLine(void)
{
//
-// Include a Source File used at the Root, and for ".include" Files
+// Include a source file used at the root, and for ".include" files
//
int include(int handle, char * fname)
{
//
-// Pop the Current Input Level
+// Pop the current input level
//
int fpop(void)
{
// Scan for next end-of-line; handle stupid text formats by treating
// \r\n the same as \n. (lone '\r' at end of buffer means we have to
// check for '\n').
-#if 0
- i = 0;
- j = fl->ifcnt;
- d = &fl->ifbuf[fl->ifind];
-
- for(p=d; i<j; i++, p++)
-#else
d = &fl->ifbuf[fl->ifind];
for(p=d, i=0, j=fl->ifcnt; i<j; i++, p++)
-#endif
{
if (*p == '\r' || *p == '\n')
{
if (*p == '\r')
{
if (i >= j)
- break; // Need to read more, then look for '\n' to eat
+ break; // Need to read more, then look for '\n' to eat
else if (p[1] == '\n')
i++;
}
*p = '\0';
return NULL;
#else
- // Really should check to see if we're at the end of the buffer! :-P
+ // Really should check to see if we're at the end of the buffer!
+ // :-P
fl->ifbuf[fl->ifind + fl->ifcnt] = '\0';
fl->ifcnt = 0;
return &fl->ifbuf[fl->ifind];
//
-// Tokenize a Line
+// Tokenize a line
//
int TokenizeLine(void)
{
- char * ln = NULL; // Ptr to current position in line
- char * p; // Random character ptr
- TOKEN * tk; // Token-deposit ptr
- int state = 0; // State for keyword detector
- int j = 0; // Var for keyword detector
- char c; // Random char
- VALUE v; // Random value
- char * nullspot = NULL; // Spot to clobber for SYMBOL terminatn
- int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot
+ char * ln = NULL; // Ptr to current position in line
+ char * p; // Random character ptr
+ TOKEN * tk; // Token-deposit ptr
+ int state = 0; // State for keyword detector
+ int j = 0; // Var for keyword detector
+ char c; // Random char
+ VALUE v; // Random value
+ char * nullspot = NULL; // Spot to clobber for SYMBOL termination
+ int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot
char c1;
- int stringNum = 0; // Pointer to string locations in tokenized line
+ int stringNum = 0; // Pointer to string locations in tokenized line
retry:
if (cur_inobj == NULL) // Return EOF if input stack is empty
return TKEOF;
- // Get another line of input from the current input source: a file,
- // a macro, or a repeat-block
+ // Get another line of input from the current input source: a file, a
+ // macro, or a repeat-block
switch (cur_inobj->in_type)
{
// Include-file:
strcpy(lnbuf, ln);
// General house-keeping
- tok = tokeol; // Set "tok" to EOL in case of error
- tk = etok; // Reset token ptr
- stuffnull = 0; // Don't stuff nulls
- totlines++; // Bump total #lines assembled
+ tok = tokeol; // Set "tok" to EOL in case of error
+ tk = etok; // Reset token ptr
+ stuffnull = 0; // Don't stuff nulls
+ totlines++; // Bump total #lines assembled
// See if the entire line is a comment. This is a win if the programmer
// puts in lots of comments
j = -1;
}
- //make j = -1 if time, date etc with no preceeding ^^
- //defined, referenced, streq, macdef, date and time
+ // Make j = -1 if time, date etc with no preceeding ^^
+ // defined, referenced, streq, macdef, date and time
switch ((TOKEN)j)
{
case 112: // defined
{
switch (*ln++)
{
- case '!': // ! or !=
+ case '!': // ! or !=
if (*ln == '=')
{
*tk++ = NE;
*tk++ = '!';
continue;
- case '\'': // 'string'
- case '\"': // "string"
+ case '\'': // 'string'
+ case '\"': // "string"
c1 = ln[-1];
*tk++ = STRING;
//#warning
*p++ = EOS;
continue;
- case '$': // $, hex constant
+ case '$': // $, hex constant
if ((int)chrtab[*ln] & HDIGIT)
{
v = 0;
*tk++ = '$';
continue;
- case '<': // < or << or <> or <=
+ case '<': // < or << or <> or <=
switch (*ln)
{
case '<':
*tk++ = '<';
continue;
}
- case ':': // : or ::
+ case ':': // : or ::
if (*ln == ':')
{
*tk++ = DCOLON;
*tk++ = ':';
continue;
- case '=': // = or ==
+ case '=': // = or ==
if (*ln == '=')
{
*tk++ = DEQUALS;
*tk++ = '=';
continue;
- case '>': // > or >> or >=
+ case '>': // > or >> or >=
switch (*ln)
{
case '>':
*tk++ = '>';
continue;
}
- case '%': // % or binary constant
+ case '%': // % or binary constant
if (*ln < '0' || *ln > '1')
{
*tk++ = '%';
*tk++ = CONST;
*tk++ = v;
continue;
- case '@': // @ or octal constant
+ case '@': // @ or octal constant
if (*ln < '0' || *ln > '7')
{
*tk++ = '@';
*tk++ = CONST;
*tk++ = v;
continue;
- case '^': // ^ or ^^ <operator-name>
+ case '^': // ^ or ^^ <operator-name>
if (*ln != '^')
{
*tk++ = '^';
*tk++ = (TOKEN)j;
continue;
default:
- interror(2); // Bad MULTX entry in chrtab
+ interror(2); // Bad MULTX entry in chrtab
continue;
}
}
//int d_goto(void)
int d_goto(WORD unused)
{
- char * s1; // Temps for string comparison
- char * s2;
+ char * s1, * s2;
// Setup for the search
if (*tok != SYMBOL)
else if (*t == ACONST)
printf("[ACONST]");
else if (*t == STRING)
-// printf("[STRING]");
{
t++;
printf("[STRING:\"%s\"]", string[*t]);
printf("[A%u]", ((uint32_t)*t) - 0x88);
else
printf("[%X:%c]", (uint32_t)*t, (char)*t);
-// printf("[%X]", (uint32_t)*t);
}
printf("[EOL]\n");