diff --git a/pyasm/pyasm b/pyasm/pyasm index 12e30b2..b49acac 100755 --- a/pyasm/pyasm +++ b/pyasm/pyasm @@ -209,8 +209,6 @@ OpcodeData = { 'DNOP': (0004000, ANO, 0, False), } -print('OpcodeData=%s' % str(OpcodeData)) - ###### # The papertape/teletype loader code ###### @@ -924,217 +922,6 @@ def main(): if __name__ == '__main__': main() -# sys.exit(0) -# -# -#/****** -# * Local constants, definitions, etc. -# ******/ -# -##define BUFFERSIZE 1024 -##define MAXNAME_LEN 7 -##define HASHTABSIZE 1023 -##define MAXBLOCKSIZE 255 -##define WORDADDRMASK 03777 -##define INDIRECTBIT (1 << 15) -##define WORDMASK 0xFFFF -# -#typedef int WORD; -# -#typedef struct sym /* one symbol */ -#{ -# struct sym *next; /* next symbol */ -# char name[MAXNAME_LEN + 1]; /* symbol name */ -# WORD address; /* symbol address */ -#} SYM; -# -# -#/****** -# * File globals. -# ******/ -# -#static char inputline[BUFFERSIZE + 1]; -#static SYM *hashtab[HASHTABSIZE]; -# -#static long dot = -1L; -#static WORD codeblockstart = 0; -#static WORD codeblock[MAXBLOCKSIZE]; -#static int nextcodeword = 0; -# -#static int LineNumber = 0; -# -# -#/****** -# * Forward prototypes. -# ******/ -# -#static WORD atoo(char *str); -#static SYM *deflabel(char *name, WORD address); -#static void emitblock(void); -#static void emitbyte(WORD word); -#static void emitloader(void); -#static void emitstart(); -#static void emitword(WORD word); -#static void emitcode(WORD code); -#static WORD geninc(char *field); -#static WORD genincbyte(char *field); -#static void genlist(WORD code); -#static WORD getaddress(char *field, BOOL indok); -#static int hash(char *name); -#static BOOL isdecimal(char *str); -#static BOOL islabel(char *name); -#static BOOL isoctal(char *str); -#static SYM *lookup(char *label); -#static OPCODE *lookupopcode(char *opcode); -#static void newcodeblock(WORD org); -#static SYM *newSYM(char *name); -#static void strupper(char *str); -#static void synerror(char *buff, char *fmt, ...); -# -# -#/****************************************************************************** -# Name : atoo() -#Description : Get octal number from a string. -# Parameters : str - string to get octal number from -# Returns : The octal value of the string. -# Comments : -# ******************************************************************************/ -#static WORD -#atoo(char *str) -#{ -# WORD result = 0; -# -# for (; *str; ++str) -# result = result * 8 + *str - '0'; -# -# return result; -#} -# -# -#/****************************************************************************** -# Name : deflabel() -#Description : Define a label in the symbol table. -# Parameters : name - name to define -# : addr - the label address -# Returns : -# Comments : -# ******************************************************************************/ -#static SYM * -#deflabel(char *name, WORD addr) -#{ -# int hashval = hash(name); -# SYM *newsym = newSYM(name); -# -# newsym->address = addr; -# -# newsym->next = hashtab[hashval]; -# hashtab[hashval] = newsym; -# -# return newsym; -#} -# -# -#/****************************************************************************** -# Name : delimfields() -#Description : Delimit label, opcode and address fields of assembler line. -# Parameters : buffer - address of line buffer -# : label - address of label pointer (returned) -# : opcode - address of opcode pointer (returned) -# : field - address of address field pointer (returned) -# : comment - address of comment string (returned) -# Returns : -# Comments : 'buffer' is destroyed (broken into shorter strings). -# : If any field is empty, return NULL in corresponding pointer. -# ******************************************************************************/ -#static void -#delimfields(char *buffer, -# char **label, char **opcode, char **field, char **comment) -#{ -# char *chptr; -# -# // point 'label', 'opcode' and 'field' to strings -# *label = *opcode = *field = *comment = NULL; -# -# chptr = buffer; -# -# // handle comment starting column 1 -# if (*chptr == ';') -# { -# *comment = chptr; -# return; -# } -# -# // check for a label starting column 1 -# if (isalpha(*chptr)) -# { -# *label = chptr; -# while (!isspace(*chptr) && *chptr != ';') -# ++chptr; -# if (*chptr) -# *(chptr++) = '\0'; -# } -# -# /* if not off end of buffer, look for opcode */ -# if (*chptr) -# { -# while (*chptr && isspace(*chptr) && *chptr != ';') -# ++chptr; -# -# if (*chptr) -# { -# if (*chptr == ';') -# { -# *comment = chptr; -# return; -# } -# else -# { -# *opcode = chptr; -# while (*chptr && !isspace(*chptr) && *chptr != ';') -# ++chptr; -# if (*chptr) -# *(chptr++) = '\0'; -# -# } -# } -# } -# -# /* if not off end of buffer, look for field */ -# if (*chptr) -# { -# while (*chptr && isspace(*chptr) && *chptr != ';') -# ++chptr; -# -# if (*chptr) -# { -# if (*chptr == ';') -# { -# *comment = chptr; -# return; -# } -# else -# { -# *field = chptr; -# while (*chptr && !isspace(*chptr) && *chptr != ';') -# ++chptr; -# if (*chptr) -# *(chptr++) = '\0'; -# } -# } -# } -# -# if (*chptr == ';') -# *comment = chptr; -# -# if (*label) -# strupper(*label); -# if (*opcode) -# strupper(*opcode); -# if (*field) -# strupper(*field); -#} -# -# #/****************************************************************************** # Name : emitblock() #Description : Emit the code for the current block. @@ -1182,20 +969,6 @@ if __name__ == '__main__': # # #/****************************************************************************** -# Name : emitbyte() -#Description : Emit one BYTE to output stream. -# Parameters : word - the BYTE value to emit -# Returns : -# Comments : -# ******************************************************************************/ -#static void -#emitbyte(WORD word) -#{ -# fputc(word & 0xFF, OutFile); -#} -# -# -#/****************************************************************************** # Name : emitcode() #Description : Generate code for one word. # Parameters : code - the WORD to put into current code block @@ -1222,186 +995,6 @@ if __name__ == '__main__': # # #/****************************************************************************** -# Name : emitloader() -#Description : Emit papertape loader. -# Parameters : fname - output filename (for error reporting) -# Returns : -# Comments : -# ******************************************************************************/ -#static void -#emitloader(void) -#{ -# int i; -# -# for (i = 0; i < ZEROLEADERSIZE; ++i) -# emitbyte(0); -# -# for (i = 0; i < BLKLDR_SIZE; ++i) -# emitword(blkldr[i]); -# -# for (i = 0; i < ZEROLEADERSIZE; ++i) -# emitbyte(0); -#} -# -# -#/****************************************************************************** -# Name : emitstart() -#Description : Emit papertape end-of-code start block. -# Parameters : address - the program start address -# Returns : -# Comments : We have to emit a block size byte, just use 1 -# ******************************************************************************/ -#static void -#emitstart(WORD address) -#{ -# emitbyte(1); /* one byte block */ -# emitword(address); /* start address */ -#} -# -# -#/****************************************************************************** -# Name : emitword() -#Description : Emit one WORD to output stream. -# Parameters : word - the WORD value to emit -# : out - open FILE stream for output -# Returns : -# Comments : -# ******************************************************************************/ -#static void -#emitword(WORD word) -#{ -# fputc((word >> 8) & 0xFF, OutFile); -# fputc(word & 0xFF, OutFile); -#} -# -# -#/****************************************************************************** -# Name : gencode() -#Description : Generate code for one line. -# Parameters : olabel - pointer to label token (NULL if no label) -# : oopcode - pointer to opcode token (NULL if no opcode) -# : ofield - pointer to field buffer (NULL if no field) -# : comment - pointer to coment buffer (NULL if no field) -# Returns : True if assembly should continue, False if END opcode found. -# Comments : Called by pass 2. -# ******************************************************************************/ -#static BOOL -#gencode(char *olabel, char *oopcode, char *ofield, char *comment) -#{ -# BOOL result = True; -# char *label = CopyStr(olabel); -# char *opcode = CopyStr(oopcode); -# char *field = CopyStr(ofield); -# -#/****** -# * If there is a label, make sure it's valid. -# ******/ -# -# if (label != NULL && !islabel(label)) -# synerror(inputline, "Label '%s' is not legal", olabel); -# -#/****** -# * If there is an opcode, handle it. -# ******/ -# -# if (opcode != NULL) -# { -# if (STREQ(opcode, "ORG")) -# { -# if (label != NULL) -# synerror(inputline, "Label not allowed on ORG statement"); -# -# if (field == NULL || !isoctal(field)) -# synerror(inputline, "ORG statement must have octal address"); -# -# emitblock(); -# dot = atoo(field); -# newcodeblock(dot); -# genlist(-1); -# } -# else if (STREQ(opcode, "END")) -# { -# if (label != NULL) -# synerror(inputline, "Label not allowed on END statement"); -# if (field != NULL) -# synerror(inputline, "Address not allowed on END statement"); -# result = False; -# genlist(-1); -# } -# else if (STREQ(opcode, "DATA")) -# { -# WORD code; -# -# if (field == NULL) -# synerror(inputline, "Data field required on DATA statement"); -# if (isoctal(field)) -# code = atoo(field); -# else if (isdecimal(field)) -# code = atoi(field); -# else -# code = getaddress(field, False); -#/* synerror(inputline, "DATA field must be octal or decimal"); */ -# -# emitcode(code); -# genlist(code); -# ++dot; -# } -# else if (STREQ(opcode, "INC")) -# { -# WORD code = geninc(field); -# -# emitcode(code); -# genlist(code); -# ++dot; -# } -# else -# { -# OPCODE *optr = lookupopcode(opcode); -# WORD code; -# -# if (optr == NULL) -# synerror(inputline, "Unrecognised opcode"); -# -# if (optr->address == AYES && field == NULL) -# synerror(inputline, "Opcode requires address field"); -# -# if (optr->address == ANO && field != NULL) -# synerror(inputline, "Opcode must not have address field"); -# -# code = optr->code; -# -# if (field != NULL) -# { -# WORD address; -# WORD mask = optr->addrmask; -# -# if (optr->indirect) -# mask |= INDIRECTBIT; -# -# address = getaddress(field, optr->indirect); -# if (address & ~mask) -# synerror(inputline, "Address field overflow!"); -# -# code = (code & ~optr->addrmask) | address; -# } -# -# emitcode(code); -# genlist(code); -# ++dot; -# } -# } -# else /* blank line */ -# genlist(-1); -# -#/****** -# * Return line assemble result. -# ******/ -# -# return result; -#} -# -# -#/****************************************************************************** # Name : geninc() #Description : Generate code for one word of INC code. # Parameters : field - INC field to generate code for @@ -1540,568 +1133,3 @@ if __name__ == '__main__': # # # -#/****************************************************************************** -# Name : genlist() -#Description : Generate a listing line, if required. -# Parameters : code - the code word generated by this instruction -# Returns : -# Comments : If 'code' is -1, don't show code word. -# ******************************************************************************/ -#static void -#genlist(WORD code) -#{ -# if (ListFile != NULL) -# { -# if (code == -1) -# fprintf(ListFile, " %4d:\t%s", -# LineNumber, inputline); -# else -# fprintf(ListFile, "%6.6o %6.6o %4d:\t%s", -# code, (int) dot, LineNumber, inputline); -# } -#} -# -# -#/****************************************************************************** -# Name : getaddress() -#Description : Get an address value from the 'field' string. -# Parameters : field - the field string to get the address from -# : indok - True if indirection allowed -# Returns : The address value. -# Comments : A valid address field can be: -# :