1
0
mirror of https://github.com/rzzzwilson/pymlac.git synced 2025-06-10 09:32:41 +00:00

Just delete old commented C code

This commit is contained in:
Ross Wilson
2016-01-29 12:07:42 +07:00
parent a9dbc0c5e6
commit a21fad3fc4

View File

@@ -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:
# : <label>
# : <octal>
# : .+<octal>
# : .-<octal>
# : If the field is a <label> and the label is not yet defined, create
# : a fixup and return a zero address.
# ******************************************************************************/
#static WORD
#getaddress(char *field, BOOL indok)
#{
# WORD result = 0;
# SYM *sym;
#
#/******
# * If indirect flag, note and continue.
# ******/
#
# if (*field == '*')
# {
# result = INDIRECTBIT;
# ++field;
# }
#
# switch (*field)
# {
# case '0': /* an octal value */
# if (!isoctal(field))
# synerror(inputline, "Bad octal address");
# result |= atoo(field);
# break;
# case '1': case '2': case '3': case '4': case '5':
# case '6': case '7': case '8': case '9': /* a decimal value */
# if (!isdecimal(field))
# synerror(inputline, "Bad decimal address");
# result |= atoi(field);
# break;
# case '.': /* a relative value */
# ++field;
# if (!isoctal(field + 1) && !isdecimal(field + 1))
# synerror(inputline, "Badly formed address");
# switch (*field)
# {
# case '+':
# if (isoctal(field + 1))
# result |= dot + atoo(field + 1);
# else
# result |= dot + atoi(field + 1);
# break;
# case '-':
# if (isoctal(field + 1))
# result |= dot - atoo(field + 1);
# else
# result |= dot - atoi(field + 1);
# break;
# default:
# synerror(inputline, "Badly formed address");
# }
# break;
# default: /* probably a label */
# if (!islabel(field))
# synerror(inputline, "Illegal address");
# sym = lookup(field);
# if (sym == NULL)
# synerror(inputline, "Badly formed address");
# result |= sym->address;
# break;
# }
#
# return result;
#}
#
#
#/******************************************************************************
# Name : hash()
#Description : Generate a hash value for a name.
# Parameters : name - name string to make hash value for
# Returns : The hash value in range [0,HASHTABSIZE).
# Comments :
# ******************************************************************************/
#static int
#hash(char *name)
#{
# int result = *name * strlen(name);
#
# while (*++name)
# result = (result << 1) + *name;
#
# return result / HASHTABSIZE;
#}
#
#
#/******************************************************************************
# Name : isdecimal()
#Description : Function to decide if a string is purely a decimal number.
# Parameters : str - string to look at
# Returns : True if 'str' is a decimal number, else False.
# Comments :
# ******************************************************************************/
#static BOOL
#isdecimal(char *str)
#{
# for (; *str; ++str)
# if (*str < '0' || *str > '9')
# return False;
#
# return True;
#}
#
#
#/******************************************************************************
# Name : islabel()
#Description : Function to decide if a string is a legal label.
# Parameters : name - string to check
# Returns : True if 'name' is legal label string, else False.
# Comments :
# ******************************************************************************/
#static BOOL
#islabel(char *name)
#{
# if (!isalpha(*name))
# return False;
#
# for (; *name; ++name)
# if (!isalpha(*name) && !isdigit(*name))
# return False;
#
# return True;
#}
#
#
#/******************************************************************************
# Name : isoctal()
#Description : Function to decide if a string is purely an octal number.
# Parameters : str - string to look at
# Returns : True if 'str' is an octal number, else False.
# Comments : An octal number must start with a '0' and contain only octal
# : digits after that,
# ******************************************************************************/
#static BOOL
#isoctal(char *str)
#{
# if (*str != '0')
# return False;
#
# for (; *str; ++str)
# if (*str < '0' || *str > '7')
# return False;
#
# return True;
#}
#
#
#/******************************************************************************
# Name : lookup()
#Description : Lookup a name in the symbol table.
# Parameters : name - name string to look for
# Returns : Address of SYM for name 'name' if found, else NULL.
# Comments :
# ******************************************************************************/
#static SYM *
#lookup(char *name)
#{
# char *uname = CopyStr(name);
# SYM *result;
#
# strupper(uname);
# result = hashtab[hash(uname)];
#
# while (result != NULL)
# {
# if (STREQ(result->name, name))
# return result;
#
# result = result->next;
# }
#
# return NULL;
#}
#
#
#/******************************************************************************
# Name : lookupopcode()
#Description : Lookup an opcode in opcodes[] table.
# Parameters : opcode - opcode to lookup
# Returns : Address of OPCODE struct if found, else NULL.
# Comments :
# ******************************************************************************/
#static OPCODE *
#lookupopcode(char *opcode)
#{
# int i;
#
# for (i = 0; i < NUMOPCODES; ++i)
# if (STREQ(opcodes[i].opcode, opcode))
# return &opcodes[i];
#
# return NULL;
#}
#
#
#/******************************************************************************
# Name : newcodeblock()
#Description : Prepare for a new block of code.
# Parameters : org - start address of block
# Returns :
# Comments :
# ******************************************************************************/
#static void
#newcodeblock(WORD org)
#{
# codeblockstart = org;
# nextcodeword = 0;
#}
#
#
#/******************************************************************************
# Name : newSYM()
#Description : Create a new SYM object.
# Parameters : name - name string of new symbol
# Returns : Address of new SYM object.
# Comments :
# ******************************************************************************/
#static SYM *
#newSYM(char *name)
#{
# SYM *result = malloc(sizeof(SYM));
#
# if (result == NULL)
# Error("Out of memory in file '%s', line %d", __FILE__, __LINE__);
#
# result->next = NULL;
# strcpy(result->name, name);
# result->address = 0;
#
# return result;
#}
#
#
#/******************************************************************************
# Name : numgenwords()
#Description : Get the number of generated WORDs for an opcode (or pseudoopcode).
# Parameters : opcode - pointer to opcode token (NULL if no opcode)
# : field - address field for opcode
# Returns : The number of WORDs generated (0 or 1).
# Comments : Called in pass 1 only.
# ******************************************************************************/
#static int
#numgenwords(char *opcode, char *field)
#{
# int result = 0;
#
#/******
# * If there is an opcode, handle it.
# ******/
#
# if (opcode != NULL)
# {
# if (STREQ(opcode, "ORG"))
# {
# result = 0;
# }
# else if (STREQ(opcode, "END"))
# {
# result = 0;
# }
# else /* we assume opcode is OK, check in pass 2 */
# {
# result = 1;
# }
# }
#
#/******
# * Return # generated words.
# ******/
#
# return result;
#}
#
#
#/******************************************************************************
# Name : Pass1()
#Description : Perform first pass on a file.
# Parameters :
# Returns : True if no errors, else False.
# Comments : Just define labels. Leave most errors for pass 2.
# ******************************************************************************/
#BOOL
#Pass1(void)
#{
# char buffer[BUFFERSIZE + 1];
# char *label;
# char *opcode;
# char *field;
# char *comment;
# int i;
# int genwords;
#
#/******
# * Initialise the hash table, et al.
# ******/
#
# for (i = 0; i < HASHTABSIZE; ++i)
# hashtab[i] = NULL;
#
# LineNumber = 0;
#
# dot = -1L;
#
#/******
# * Read and process the file.
# * Just fill in the symbol table (labels) as we go.
# ******/
#
# while (fgets(buffer, sizeof(buffer), InFile) != NULL)
# {
# ++LineNumber;
#
# strcpy(inputline, buffer);
#
# /* point 'label', 'opcode' and 'field' to strings */
# delimfields(buffer, &label, &opcode, &field, &comment);
#
# /* if there's something there, get # generated words */
# if (opcode != NULL)
# {
# if (STREQ(opcode, "END"))
# break;
#
# if (STREQ(opcode, "ORG"))
# {
# if (field == NULL || !isoctal(field))
# {
# synerror(inputline, "Bad ORG adress");
# return False;
# }
#
# dot = atoo(field);
# }
# else
# {
# genwords = numgenwords(opcode, field);
#
# if (label != NULL)
# {
# if (lookup(label))
# synerror(inputline, "Label already defined");
# deflabel(label, dot);
# }
#
# dot += genwords;
# }
# }
# }
#
# return True;
#}
#
#
#/******************************************************************************
# Name : Pass2()
#Description : Perform second pass on a file.
# Parameters :
# Returns :
# Comments :
# ******************************************************************************/
#BOOL
#Pass2(void)
#{
# char buffer[BUFFERSIZE + 1];
# char *label;
# char *opcode;
# char *field;
# char *comment;
#
#/******
# * Initialize linenumber, et al.
# ******/
#
# LineNumber = 0;
# dot = -1L;
#
#/******
# * Start the output - emit tape or tty block loader
# ******/
#
# emitloader();
#
#/******
# * Read the file, generating code as we go.
# ******/
#
# while (fgets(buffer, sizeof(buffer), InFile) != NULL)
# {
# char *chptr;
#
# ++LineNumber;
#
# chptr = strrchr(buffer, '\r');
# if (chptr)
# strcpy(chptr, chptr + 1);
#
# strcpy(inputline, buffer);
#
# /* point 'label', 'opcode' and 'field' to strings */
# delimfields(buffer, &label, &opcode, &field, &comment);
#
# /* if there's something there, generate code */
# if (gencode(label, opcode, field, comment) == False)
# break; /* gencode() returns False on 'END' pseudoop */
# }
#
#/******
# * Check there is nothing after END statement.
# ******/
#
# if (fgets(buffer, sizeof(buffer), InFile) != NULL)
# {
# ++LineNumber;
# synerror(buffer, "Something after END!?");
# return False;
# }
#
#/******
# * Emit the data.
# ******/
#
# emitblock();
# emitstart(WORDMASK);
#
# return True;
#}
#
#
#/******************************************************************************
# Name : synerror()
#Description : Generate a syntax error, then stop.
# Parameters : inputline - line that had error
# : fmt - start of printf() style params
# Returns : Doesn't!
# Comments :
# ******************************************************************************/
#static void
#synerror(char *inputline, char *fmt, ...)
#{
# va_list ap;
# char msg[1024];
#
# fprintf(stderr, "------------------------------------------------------\n");
# fprintf(stderr, "%s", inputline);
# fprintf(stderr, "------------------------------------------------------\n");
#
# va_start(ap, fmt);
# fprintf(stderr, "File %s, line %d: ", InFileName, LineNumber);
# vsprintf(msg, fmt, ap);
# fprintf(stderr, "%s\n", msg);
# va_end(ap);
#
# fflush(stderr);
#
# exit(EXIT_FAILURE);
#}
#
##ifdef JUNK
#/******************************************************************************
# Name : synwarn()
#Description : Generate a syntax error, and continue.
# Parameters : fmt - start of printf() style params
# Returns :
# Comments :
# ******************************************************************************/
#static void
#synwarn(char *fmt, ...)
#{
# va_list ap;
# char msg[1024];
#
# va_start(ap, fmt);
# vsprintf(msg, fmt, ap);
# fprintf(stdout, "%s\n", msg);
# va_end(ap);
#
# fflush(stdout);
#}
##endif
#
#
#/******************************************************************************
# Name : strupper()
#Description : Convert a string to uppercase, in situ.
# Parameters : str - address of string to convert
# Returns :
# Comments :
# ******************************************************************************/
#static void
#strupper(char *str)
#{
# for (; *str; ++str)
# *str = toupper(*str);
#}
#
#
##ifdef JUNK
#/******************************************************************************
# Name : xemitcode()
#Description : Emit papertape code.
# Parameters : fname - output filename (for error reporting)
# : out - open FILE stream for output
# Returns :
# Comments :
# ******************************************************************************/
#static void
#xemitcode(char *fname, FILE *out)
#{
# BLOCK *bptr;
#
# for (bptr = blocklist; bptr != NULL; bptr = bptr->next)
# {
# WORD checksum = (bptr->org + ((-bptr->nextword) & WORDMASK)) & WORDMASK;
# WORD i;
#
# for (i = 0; i < bptr->nextword; ++i)
# checksum = (checksum + bptr->code[i]) & WORDMASK;
#
# emitword(bptr->org);
# emitword(-bptr->nextword);
# emitword(checksum);
#
# for (i = 0; i < bptr->nextword; ++i)
# emitword(bptr->code[i]);
#
# }
#}
#
##endif
#
#