diff --git a/iasm/assemble.c b/iasm/assemble.c index 4756114..490926f 100755 --- a/iasm/assemble.c +++ b/iasm/assemble.c @@ -375,7 +375,7 @@ Description : Delimit label, opcode and address fields of assembler line. : field - address of address field pointer (returned) : comment - address of comment string (returned) Returns : - Comments : The buffer is broken into shorter strings (destroyed). + Comments : 'buffer' is destroyed (broken into shorter strings. ******************************************************************************/ static void delimfields(char *buffer, @@ -401,19 +401,25 @@ delimfields(char *buffer, if (*chptr != ';' && *chptr != '\n') { *opcode = chptr; - while (!isspace(*chptr)) + while (!isspace(*chptr) && *chptr != ';' && *chptr != '\n') ++chptr; - *chptr = '\0'; - ++chptr; + // at end of opcode + if (isspace(*chptr) || *chptr == ';' || *chptr == '\n') + { + *chptr = '\0'; + ++chptr; + } - while (isspace(*chptr) && *chptr != ';' && *chptr != '\n') + while (*chptr != '\0' && isspace(*chptr) && *chptr != ';' && *chptr != '\n') ++chptr; - if (*chptr != ';' && *chptr != '\n') + + if (*chptr && *chptr != ';' && *chptr != '\n') { *field = chptr; while (!isspace(*chptr) && *chptr != ';' && *chptr != '\n') ++chptr; *chptr = '\0'; + ++chptr; if (strlen(*field) == 0) *field = NULL; } diff --git a/iasm/iasm.c b/iasm/iasm.c index 2cc51df..2e23439 100755 --- a/iasm/iasm.c +++ b/iasm/iasm.c @@ -93,6 +93,7 @@ Debug(char *fmt, ...) vsprintf(buff, fmt, ap); fprintf(stdout, "%s\n", buff); va_end(ap); + fflush(stdout); } diff --git a/pymlac/Makefile b/pymlac/Makefile index e9d1ee7..b7cdf67 100644 --- a/pymlac/Makefile +++ b/pymlac/Makefile @@ -18,4 +18,4 @@ lst: $(TESTS) ../iasm/iasm -l $*.lst $< clean: - rm -Rf *.pyc *~ *.out test_*.ptp *.lst test_*.trace _#*#_.ptp + rm -Rf *.pyc *~ *.out test_*.ptp *.lst test_*.trace _#ASM#_.* diff --git a/pymlac/test_CPU.py b/pymlac/test_CPU.py index 9f30368..c435268 100644 --- a/pymlac/test_CPU.py +++ b/pymlac/test_CPU.py @@ -11,6 +11,8 @@ where is a file of test instructions and -h prints this help and stops """ +import time + # We implement a small interpreter to test the CPU. The test code is read in # from a file: # @@ -93,7 +95,9 @@ class TestCPU(object): fd.write('\tend\n') # now assemble file - os.system('../iasm/iasm -l %s.lst %s.asm' % (self.AsmFilename, self.AsmFilename)) + #cmd = '../iasm/iasm -l %s.lst %s.asm >xyzzy 2>&1' % (self.AsmFilename, self.AsmFilename) + cmd = '../iasm/iasm -l %s.lst %s.asm' % (self.AsmFilename, self.AsmFilename) + res = os.system(cmd) # read the listing file to get assembled opcode (second line) with open(self.AsmFilename+'.lst', 'rb') as fd: