1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-06-07 15:50:17 +00:00

Cleaned up definitions in .h files

This commit is contained in:
Curtis F Kaylor 2018-02-13 18:16:23 -05:00
parent 2edb6da3cb
commit bb575122ca
18 changed files with 464 additions and 646 deletions

7
.gitignore vendored
View File

@ -1,3 +1,10 @@
#Compiled source code
*.exe
#Pelles C Auxillary Files
*.ppx
*.tag
#Files created when compiling a C02 program
*/*.asm
*/*.bin

18
asm.c
View File

@ -42,21 +42,3 @@ void cmtlin()
fprintf(outfil, "; %s\n", cmtasm);
setcmt("");
}
/* Output a variable definition line *
* Uses: word - assembly oprnd */
void equlin()
{
fprintf(outfil, ASMFMT, lblasm, EQUOP, word, "");
if (debug) printf(ASMFMT, lblasm, EQUOP, word, "");
lblasm[0] = 0;
}
void prolog()
{
DEBUG("Writing Assembly Prolog\n", 0);
asmlin(CPUOP,CPUARG);
strcpy(cmtasm, "Program ");
strcat(cmtasm, srcnam);
cmtlin();
}

5
asm.h
View File

@ -4,11 +4,6 @@
char lblasm[LABLEN+2]; //Label to emit on next asm line
void addcmt(char *s); //Append String to Assembly Line Comment
void asmlin(char *opcode, char *oprnd); //Output a line of assembly code
void chrcmt(char c); //Append Character to Assembly Line Comment
void cmtlin(); //Output a comment lines
void equlin(); //Output an equate line
void prccmt(); //Process comment
void prolog(); //Write Assembly Language Initialization Code
void setcmt(char *s); //Set Assembly Line Comment to String

10
c02.c
View File

@ -32,7 +32,6 @@ void init()
defcnt = 0;
varcnt = 0;
lblcnt = 0;
cmpsgn = 0;
curcol = 0;
curlin = 0;
inpfil = srcfil;
@ -80,6 +79,15 @@ void pdrctv()
ERROR("Illegal directive %s encountered\n", word, EXIT_FAILURE);
}
void prolog()
{
DEBUG("Writing Assembly Prolog\n", 0);
asmlin(CPUOP,CPUARG);
setcmt("Program ");
addcmt(srcnam);
cmtlin();
}
void epilog()
{
if (!vrwrtn) vartbl(); //Write Variable Table

BIN
c02.exe

Binary file not shown.

380
c02.ppj
View File

@ -1,179 +1,201 @@
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#
POC_PROJECT_VERSION = 7.00#
POC_PROJECT_TYPE = 3#
POC_PROJECT_OUTPUTDIR = output#
POC_PROJECT_RESULTDIR = .#
POC_PROJECT_ARGUMENTS = #
POC_PROJECT_WORKPATH = #
POC_PROJECT_EXECUTOR = #
POC_PROJECT_ZIPEXTRA = #
CC = pocc.exe#
AS = poasm.exe#
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -std:C11 -Tx86-coff -Ot -Ob1 -fp:precise -W0 -Gd -Zx -Go#
ASFLAGS = -AIA32#
RCFLAGS = -r#
LINKFLAGS = -machine:x86 -subsystem:console kernel32.lib advapi32.lib delayimp.lib#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#
#
# Build c02.exe.
#
c02.exe: \
output\c02.obj \
output\asm.obj \
output\common.obj \
output\cond.obj \
output\expr.obj \
output\files.obj \
output\include.obj \
output\label.obj \
output\parse.obj \
output\stmnt.obj \
output\vars.obj
$(LINK) $(LINKFLAGS) -out:"$@" $**
#
# Build c02.obj.
#
output\c02.obj: \
c02.c \
asm.h \
common.h \
cond.h \
expr.h \
files.h \
include.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build asm.obj.
#
output\asm.obj: \
asm.c \
asm.h \
common.h \
files.h \
parse.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build common.obj.
#
output\common.obj: \
common.c \
common.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build cond.obj.
#
output\cond.obj: \
cond.c \
asm.h \
common.h \
cond.h \
expr.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build expr.obj.
#
output\expr.obj: \
expr.c \
asm.h \
common.h \
expr.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build files.obj.
#
output\files.obj: \
files.c \
common.h \
files.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build include.obj.
#
output\include.obj: \
include.c \
asm.h \
common.h \
files.h \
include.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build label.obj.
#
output\label.obj: \
label.c \
asm.h \
common.h \
label.h \
parse.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build parse.obj.
#
output\parse.obj: \
parse.c \
common.h \
files.h \
parse.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build stmnt.obj.
#
output\stmnt.obj: \
stmnt.c \
asm.h \
common.h \
expr.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build vars.obj.
#
output\vars.obj: \
vars.c \
asm.h \
common.h \
files.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
.EXCLUDEDFILES:
.SILENT:
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#
POC_PROJECT_VERSION = 7.00#
POC_PROJECT_TYPE = 3#
POC_PROJECT_OUTPUTDIR = output#
POC_PROJECT_RESULTDIR = .#
POC_PROJECT_ARGUMENTS = #
POC_PROJECT_WORKPATH = .#
POC_PROJECT_EXECUTOR = #
POC_PROJECT_ZIPEXTRA = #
CC = pocc.exe#
AS = poasm.exe#
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -std:C11 -Tx86-coff -Ot -Ob1 -fp:precise -W0 -Gd -Zx -Go#
ASFLAGS = -AIA32#
RCFLAGS = -r#
LINKFLAGS = -machine:x86 -subsystem:console kernel32.lib advapi32.lib delayimp.lib#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#
#
# Build c02.exe.
#
c02.exe: \
output\asm.obj \
output\c02.obj \
output\common.obj \
output\cond.obj \
output\expr.obj \
output\files.obj \
output\include.obj \
output\label.obj \
output\parse.obj \
output\stmnt.obj \
output\vars.obj \
output\dclrtn.obj
$(LINK) $(LINKFLAGS) -out:"$@" $**
#
# Build c02.obj.
#
output\c02.obj: \
c02.c \
asm.h \
common.h \
cond.h \
dclrtn.h \
expr.h \
files.h \
include.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build asm.obj.
#
output\asm.obj: \
asm.c \
asm.h \
common.h \
files.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build common.obj.
#
output\common.obj: \
common.c \
common.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build cond.obj.
#
output\cond.obj: \
cond.c \
asm.h \
common.h \
cond.h \
expr.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build expr.obj.
#
output\expr.obj: \
expr.c \
asm.h \
common.h \
expr.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build files.obj.
#
output\files.obj: \
files.c \
common.h \
files.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build include.obj.
#
output\include.obj: \
include.c \
asm.h \
common.h \
dclrtn.h \
files.h \
include.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build label.obj.
#
output\label.obj: \
label.c \
asm.h \
common.h \
label.h \
parse.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build parse.obj.
#
output\parse.obj: \
parse.c \
asm.h \
common.h \
files.h \
parse.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build stmnt.obj.
#
output\stmnt.obj: \
stmnt.c \
asm.h \
common.h \
cond.h \
expr.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build vars.obj.
#
output\vars.obj: \
vars.c \
asm.h \
common.h \
files.h \
label.h \
parse.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
#
# Build dclrtn.obj.
#
output\dclrtn.obj: \
dclrtn.c \
asm.h \
common.h \
cond.h \
dclrtn.h \
expr.h \
label.h \
parse.h \
stmnt.h \
vars.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"
.SILENT:
.EXCLUDEDFILES:

147
c02.ppx
View File

@ -1,147 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings version="1.0">
<category name="expr.h" />
<category name="cond.h" />
<category name="asm.h">
<category name="Window">
<property name="Left" type="integer">0</property>
<property name="Top" type="integer">0</property>
<property name="Right" type="integer">953</property>
<property name="Bottom" type="integer">310</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="c02.c">
<category name="Window">
<property name="Left" type="integer">26</property>
<property name="Top" type="integer">26</property>
<property name="Right" type="integer">979</property>
<property name="Bottom" type="integer">336</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="stmnt.c">
<category name="Window">
<property name="Left" type="integer">52</property>
<property name="Top" type="integer">52</property>
<property name="Right" type="integer">1005</property>
<property name="Bottom" type="integer">362</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="asm.c">
<category name="Window">
<property name="Left" type="integer">78</property>
<property name="Top" type="integer">78</property>
<property name="Right" type="integer">1031</property>
<property name="Bottom" type="integer">388</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="vars.c">
<category name="Window">
<property name="Left" type="integer">104</property>
<property name="Top" type="integer">104</property>
<property name="Right" type="integer">1057</property>
<property name="Bottom" type="integer">414</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="parse.c">
<category name="Window">
<property name="Left" type="integer">130</property>
<property name="Top" type="integer">130</property>
<property name="Right" type="integer">1083</property>
<property name="Bottom" type="integer">440</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="include.c">
<category name="Window">
<property name="Left" type="integer">0</property>
<property name="Top" type="integer">0</property>
<property name="Right" type="integer">953</property>
<property name="Bottom" type="integer">310</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="expr.c">
<category name="Foldings">
<property name="Line1" type="integer">1</property>
<property name="Line2" type="integer">17</property>
<property name="Line3" type="integer">35</property>
<property name="Line4" type="integer">86</property>
<property name="Line5" type="integer">119</property>
<property name="Line6" type="integer">203</property>
<property name="Line7" type="integer">234</property>
</category>
<category name="Window">
<property name="Left" type="integer">26</property>
<property name="Top" type="integer">26</property>
<property name="Right" type="integer">979</property>
<property name="Bottom" type="integer">336</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="parse.h" />
<category name="common.h">
<category name="Window">
<property name="Left" type="integer">52</property>
<property name="Top" type="integer">52</property>
<property name="Right" type="integer">1005</property>
<property name="Bottom" type="integer">362</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="files.c" />
<category name="common.c">
<category name="Window">
<property name="Left" type="integer">78</property>
<property name="Top" type="integer">78</property>
<property name="Right" type="integer">1031</property>
<property name="Bottom" type="integer">388</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="label.c">
<category name="Window">
<property name="Left" type="integer">104</property>
<property name="Top" type="integer">104</property>
<property name="Right" type="integer">1057</property>
<property name="Bottom" type="integer">414</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="cond.c" />
<category name="label.h">
<category name="Window">
<property name="Left" type="integer">0</property>
<property name="Top" type="integer">0</property>
<property name="Right" type="integer">953</property>
<property name="Bottom" type="integer">310</property>
<property name="Maximized" type="integer">0</property>
<property name="Active" type="integer">0</property>
</category>
</category>
<category name="vars.h">
<category name="Window">
<property name="Left" type="integer">-8</property>
<property name="Top" type="integer">-31</property>
<property name="Right" type="integer">953</property>
<property name="Bottom" type="integer">422</property>
<property name="Maximized" type="integer">1</property>
<property name="Active" type="integer">1</property>
</category>
</category>
</settings>

BIN
c02.tag

Binary file not shown.

View File

@ -29,11 +29,12 @@
#define TRUE -1
#define FALSE 0
void prtpos(); //Print current file name and position
#define DEBUG(fmt, val) if (debug) {prtpos(); printf(fmt, val);}
#define DETAIL(fmt, val) if (debug) {printf(fmt, val);}
#define ERROR(fmt, val, err) if (debug) {fprintf(stderr, fmt, val);exterr(err);}
int debug; //Print Debug Info (TRUE or FALSE)
int debug; //Print Debug Info (TRUE or FALSE)
int gencmt; //Generate Assembly Language Comments
char asmcmt[LINELEN]; //Processed Assembly Language Comment
@ -58,8 +59,6 @@ int lsrtrn; //Last Statement was a Return
void exterr(int errnum); //Print current file name & position and exit
void expctd(char *expected); //Print Expected message and exit
void prtpos(); //Print current file name and position
void setblk(int blkflg); //Set Block Flag for Last Label
void addcmt(char *s); //Append string to comment
void chrcmt(char c); //Append character to comment

6
cond.h
View File

@ -2,10 +2,4 @@
* C02 Conditional Parsing Routines *
************************************/
int cmpsgn; // Comparison contains signed operands
int enccmp(char c); //Encode Comparison Operator Character
void prccmp(); //Process and Compile Comparison Operator
void prsflg(int revrse); //Parse Flag Operator
int prscmp(int revrse); //Parse Comparison
void prscnd(char trmntr, int revrse); //Parse Conditional Expression

1
expr.c
View File

@ -77,7 +77,6 @@ void prstrm()
strcpy(term, value);
DEBUG("Parsed term %s\n", term);
chkidx(); //Check for Array Index
//chkpst = ispopr(); //Check for Post-Op
skpspc();
}

9
expr.h
View File

@ -7,19 +7,12 @@ char term[255]; //Term parsed from equation
char fnstck[MAXFNS][VARLEN+1]; //Function Call Stack
int fnscnt; //Number of Functions in Stack
int chkpst; //Check for Post-Operator
int chkadr(int adract); //Check for and Process Address or String
int chkadr(int adract); //Check for and Process Address or String
void chkidx(); //Check for, Parse, and Process Index
void prcadr(int adract, char* symbol); //Process Address Reference
void prcopr(); //Process Arithmetic or Bitwise Operator
void prsadr(int adract); //Parse and Compile Address of Operator
void prsfnc(char trmntr); //Parse function call
void prsftm(); //Parse first term of expession
void prsidx(); //Parse Array Index
void prstrm(); //Parse Term in Expression
void prsstr(int adract); //Parse and Create Anonymous String
void prsval(int alwreg); //Parse value (constant or identifier)
void prsxpr(char trmntr); //Parse Expression

482
include.c
View File

@ -1,241 +1,241 @@
/*************************************
* C02 Include File Parsing Routines *
*************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include "common.h"
#include "files.h"
#include "asm.h"
#include "parse.h"
#include "label.h"
#include "vars.h"
#include "stmnt.h"
#include "dclrtn.h"
#include "include.h"
/* Read next include file name from Source File *
* Sets: incnam - the include file name */
void pincnm()
{
char dlmtr;
int inclen = 0;
skpspc();
dlmtr = getnxt();
if (dlmtr == '<') {
strcpy(incnam, incdir);
inclen = strlen(incnam);
dlmtr = '>';
}
else if (dlmtr != '"')
ERROR("Unexpected character '%c' after include\n", dlmtr, EXIT_FAILURE);
while (!match(dlmtr))
{
incnam[inclen++] = nxtchr;
skpchr();
}
skpchr(); //skip end dlmtr
incnam[inclen] = 0;
}
/* Process assembly language include file */
void incasm() {
opninc();
setcmt("======== Assembler File ");
addcmt(incnam);
addcmt(" =======");
cmtlin();
while (fgets(line, sizeof line, incfil) != NULL) {
DEBUG("Writing line: %s", line);
fputs(line, outfil);
}
setcmt("==========================================");
cmtlin();
clsinc();
}
/* Process define directive */
void pdefin()
{
getwrd(); //get defined identifier
DEBUG("Defining '%s'\n", word);
strncpy(defnam[defcnt], word, VARLEN);
setlbl(word); //Set label Assembler Line
expect('=');
defval[defcnt++] = prsbyt(); //Get Value
asmlin(EQUOP, value); //Write Definition
DEBUG("Defined as '%s'\n", value);
}
/* Parse ASCII Subdirective */
void pascii()
{
getwrd(); //Get Pragma Subdirective
if (wordis("INVERT")) {
invasc = TRUE;
}
else {
fprintf(stderr, "Unrecognized option '%s'\n", word);
exterr(EXIT_FAILURE);
}
}
/* Parse Origin Subdirective */
void porign()
{
prsnum(0xFFFF); //Get Origin Address
asmlin(ORGOP, value); //Emit Origin Instruction
DEBUG("Set origin to %s\n", value);
}
/* Parse Zeropage Subdirective */
void prszpg()
{
zpaddr = prsnum(0xFF); //Set Zero Page Address to Constant
DEBUG("Set zero page address to %d\n", zpaddr);
}
/* Process Vartable Subdirective */
void pvrtbl()
{
if (vrwrtn) {
ERROR("Variable table already written", 0, EXIT_FAILURE);
}
vartbl(); //Write Variable Table
}
/* Parse Pragma Directive */
void pprgma()
{
getwrd(); //Get Pragma Subdirective
DEBUG("Parsing pragma directive '%s'\n", word);
if (wordis("ASCII"))
pascii(); //Parse Ascii
else if (wordis("ORIGIN"))
porign(); //Parse Origin
else if (wordis("VARTABLE"))
pvrtbl(); //Parse Vartable
else if (wordis("ZEROPAGE"))
prszpg(); //Parse Origin
else
ERROR("Illegal pragma subdirective '%s'\n", word, EXIT_FAILURE);
}
/* Process Include File Directive */
void pincdr()
{
skpchr(); //skip '#'
getwrd(); //read directive into word
DEBUG("Processing include file directive '%s'\n", word);
if (wordis("DEFINE"))
pdefin();
if (wordis("PRAGMA"))
pprgma();
else {
fprintf(stderr, "Unrecognized directive '%s'\n", word);
exterr(EXIT_FAILURE);
}
}
/* Parse Header Word */
void phdwrd() {
getwrd();
if (!ptype(MTNONE)) {
fprintf(stderr, "Unexpected word '%s' in header\n", word);
exterr(EXIT_FAILURE);
}
}
/* Save Source File Information */
void savsrc() {
savchr = nxtchr;
savcol = curcol;
savlin = curlin;
}
/* Set Include File Information */
void setinc() {
curcol = 0;
curlin = 0;
inpfil = incfil;
strcpy(inpnam, incnam);
alcvar = FALSE;
}
/* Restore Source File Pointer*/
void rstsrc() {
nxtchr = savchr;
nxtupc = toupper(nxtchr);
curcol = savcol;
curlin = savlin;
inpfil = srcfil;
strcpy(inpnam, srcnam);
alcvar = TRUE;
}
/* Process header include file */
void inchdr() {
savsrc(); //Save Source File Information
opninc(); //Open Include File
setinc(); //Set Include File Information
skpchr();
while (TRUE)
{
skpspc();
if (match(EOF)) break;
DEBUG("Checking next character '%c'\n", nxtchr);
if (match('#'))
pincdr();
else if (match('/'))
skpcmt();
else if (isalph())
phdwrd();
else {
fprintf(stderr, "Unexpected character '%c'\n", nxtchr);
exterr(EXIT_FAILURE);
}
}
clsinc();
rstsrc();
nxtchr = savchr;
}
/* Process include file */
void pincfl()
{
pincnm(); //Parse Include File Name
DEBUG("Processing include file '%s'\n", incnam);
char *dot = strrchr(incnam, '.'); //find extension
if (dot == NULL) {
fprintf(stderr, "Invalid include file name '%sn", incnam);
exterr(EXIT_FAILURE);
}
if (strcmp(dot, ".a02") == 0)
incasm();
if (strcmp(dot, ".asm") == 0)
incasm();
else if (strcmp(dot, ".h02") == 0) {
inchdr(); //Process Header File
strcpy(dot, ".a02");
incasm(); //Process Assembly File with Same Name
}
else {
fprintf(stderr, "Unrecognized include file extension '%s'\n'", dot);
exterr(EXIT_FAILURE);
}
}
/* Print Definition Table to Log File */
void logdef()
{
int i;
fprintf(logfil, "\n%-31s %5s\n", "Definition", "Value");
for (i=0; i<defcnt; i++)
{
fprintf(logfil, "%-31s %5d\n", defnam[i], defval[i]);
}
}
/*************************************
* C02 Include File Parsing Routines *
*************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include "common.h"
#include "files.h"
#include "asm.h"
#include "parse.h"
#include "label.h"
#include "vars.h"
#include "stmnt.h"
#include "dclrtn.h"
#include "include.h"
/* Read next include file name from Source File *
* Sets: incnam - the include file name */
void pincnm()
{
char dlmtr;
int inclen = 0;
skpspc();
dlmtr = getnxt();
if (dlmtr == '<') {
strcpy(incnam, incdir);
inclen = strlen(incnam);
dlmtr = '>';
}
else if (dlmtr != '"')
ERROR("Unexpected character '%c' after include\n", dlmtr, EXIT_FAILURE);
while (!match(dlmtr))
{
incnam[inclen++] = nxtchr;
skpchr();
}
skpchr(); //skip end dlmtr
incnam[inclen] = 0;
}
/* Process assembly language include file */
void incasm() {
opninc();
setcmt("======== Assembler File ");
addcmt(incnam);
addcmt(" =======");
cmtlin();
while (fgets(line, sizeof line, incfil) != NULL) {
DEBUG("Writing line: %s", line);
fputs(line, outfil);
}
setcmt("==========================================");
cmtlin();
clsinc();
}
/* Process define directive */
void pdefin()
{
getwrd(); //get defined identifier
DEBUG("Defining '%s'\n", word);
strncpy(defnam[defcnt], word, VARLEN);
setlbl(word); //Set label Assembler Line
expect('=');
defval[defcnt++] = prsbyt(); //Get Value
asmlin(EQUOP, value); //Write Definition
DEBUG("Defined as '%s'\n", value);
}
/* Parse ASCII Subdirective */
void pascii()
{
getwrd(); //Get Pragma Subdirective
if (wordis("INVERT")) {
invasc = TRUE;
}
else {
fprintf(stderr, "Unrecognized option '%s'\n", word);
exterr(EXIT_FAILURE);
}
}
/* Parse Origin Subdirective */
void porign()
{
prsnum(0xFFFF); //Get Origin Address
asmlin(ORGOP, value); //Emit Origin Instruction
DEBUG("Set origin to %s\n", value);
}
/* Parse Zeropage Subdirective */
void prszpg()
{
zpaddr = prsnum(0xFF); //Set Zero Page Address to Constant
DEBUG("Set zero page address to %d\n", zpaddr);
}
/* Process Vartable Subdirective */
void pvrtbl()
{
if (vrwrtn) {
ERROR("Variable table already written", 0, EXIT_FAILURE);
}
vartbl(); //Write Variable Table
}
/* Parse Pragma Directive */
void pprgma()
{
getwrd(); //Get Pragma Subdirective
DEBUG("Parsing pragma directive '%s'\n", word);
if (wordis("ASCII"))
pascii(); //Parse Ascii
else if (wordis("ORIGIN"))
porign(); //Parse Origin
else if (wordis("VARTABLE"))
pvrtbl(); //Parse Vartable
else if (wordis("ZEROPAGE"))
prszpg(); //Parse Origin
else
ERROR("Illegal pragma subdirective '%s'\n", word, EXIT_FAILURE);
}
/* Process Include File Directive */
void pincdr()
{
skpchr(); //skip '#'
getwrd(); //read directive into word
DEBUG("Processing include file directive '%s'\n", word);
if (wordis("DEFINE"))
pdefin();
if (wordis("PRAGMA"))
pprgma();
else {
fprintf(stderr, "Unrecognized directive '%s'\n", word);
exterr(EXIT_FAILURE);
}
}
/* Parse Header Word */
void phdwrd() {
getwrd();
if (!ptype(MTNONE)) {
fprintf(stderr, "Unexpected word '%s' in header\n", word);
exterr(EXIT_FAILURE);
}
}
/* Save Source File Information */
void savsrc() {
savchr = nxtchr;
savcol = curcol;
savlin = curlin;
}
/* Set Include File Information */
void setinc() {
curcol = 0;
curlin = 0;
inpfil = incfil;
strcpy(inpnam, incnam);
alcvar = FALSE;
}
/* Restore Source File Pointer*/
void rstsrc() {
nxtchr = savchr;
nxtupc = toupper(nxtchr);
curcol = savcol;
curlin = savlin;
inpfil = srcfil;
strcpy(inpnam, srcnam);
alcvar = TRUE;
}
/* Process header include file */
void inchdr() {
savsrc(); //Save Source File Information
opninc(); //Open Include File
setinc(); //Set Include File Information
skpchr();
while (TRUE)
{
skpspc();
if (match(EOF)) break;
DEBUG("Checking next character '%c'\n", nxtchr);
if (match('#'))
pincdr();
else if (match('/'))
skpcmt();
else if (isalph())
phdwrd();
else {
fprintf(stderr, "Unexpected character '%c'\n", nxtchr);
exterr(EXIT_FAILURE);
}
}
clsinc();
rstsrc();
nxtchr = savchr;
}
/* Process include file */
void pincfl()
{
pincnm(); //Parse Include File Name
DEBUG("Processing include file '%s'\n", incnam);
char *dot = strrchr(incnam, '.'); //find extension
if (dot == NULL) {
fprintf(stderr, "Invalid include file name '%sn", incnam);
exterr(EXIT_FAILURE);
}
if (strcmp(dot, ".a02") == 0)
incasm();
if (strcmp(dot, ".asm") == 0)
incasm();
else if (strcmp(dot, ".h02") == 0) {
inchdr(); //Process Header File
strcpy(dot, ".a02");
incasm(); //Process Assembly File with Same Name
}
else {
fprintf(stderr, "Unrecognized include file extension '%s'\n'", dot);
exterr(EXIT_FAILURE);
}
}
/* Print Definition Table to Log File */
void logdef()
{
int i;
fprintf(logfil, "\n%-31s %5s\n", "Definition", "Value");
for (i=0; i<defcnt; i++)
{
fprintf(logfil, "%-31s %5d\n", defnam[i], defval[i]);
}
}

View File

@ -4,19 +4,7 @@
char line[255]; /*Entire line parsed from include file*/
void incasm(); //Process assembly language include file
void inchdr(); //Process header include file
void logdef(); //Print Definition Table to Log File
void pascii(); //Parse ASCII Subdirective
void pdefin(); //Process define directive
void phdwrd(); //Parse Header Word
void pincdr(); //Process Include File Directive
void pincfl(); //Process include file
void pincnm(); //Parse Include File Name
void porign(); //Parse Origin Subdirective
void pprgma(); //Parse Pragma Directive
void pvrtbl(); //Process Vartable Subdirective
void prszpg(); //Parse Zeropage Subdirective
void rstsrc(); //Restore Source File Pointer
void savsrc(); //Save Source File Information
void setinc(); //Set Include File Information

View File

@ -28,5 +28,5 @@ void pshlbl(int lbtype, char* lbname); //Push Label onto Stack
void reqlbl(char* lbname); //Require Label
void setblk(int blkflg); //Set Block Flag for Last Label
void setlbl(char *lblset); //Emit word as Label on Next Line
int toplbl(char *rtlbl); //Get Top Label and Return Type
int toplbl(char *rtlbl); //Get Top Label and Return Type

16
parse.h
View File

@ -22,7 +22,6 @@ int defidx; //Index into Definition Tables
int invasc; //Invert ASCII Flag
int match(char c); //Does Next Character match c
int inbtwn(char mn, char mx); //Is Next Character in Range ()mn - mx)
int isalph(); //Is Next Character Alphabetic
int isanum(); //Is Next Character AlphaNumeric
int isapos(); //Is Next Character an Apostrophe
@ -41,32 +40,19 @@ int isspc(); //Is Next Character a Space
int isvpre(); //Is Next Character a Value Prefix
int isxpre(); //Is Next Character an Expression Prefix
char escape(char c); //Escape Character
void expect(char c); //Look for Character and Exit if not found
void fnddef(char *name); //Find Definition
char getnxt(); //Return Next Character and Advance
void getstr(); //Get String
int gettyp(); //Get Value Type
void getwrd(); //Get Next Word
char invchr(char c); //Invert Character Case
int look(char c); //Look for Character
void prcidx(char *name, char *index); //Process Array Index
void prcpst(char* name, char *index); //Process Post Operator
int prsbin(); //Parse Binary Number
int prsbyt(); //Parse Numeric Byte
int prschr(); //Parse Character Constant
void prscon(); //Parse a Constant
int prsdec(); //Parse Decimal Number
int prsdef(); //Parse Definition
int prshex(); //Parse Hexadecimal Number
int prsnum(int maxval); //Parse Numeric
void prsopr(); //Parse Arithmetic Operator
int prspst(char trmntr, char* name, char* index); //Parse Post Operator
void skpchr(); //Skip Next Character
void skpcmt(); //Skip to End of Comment
void skpeol(); //Skip to End of Line
void skpspc(); //Advance to Next Printable Character
int wordis(char *s); //Does word match s
int wordis(char *s); //Does word match s

View File

@ -6,13 +6,9 @@ char asnvar[VARLEN+1]; //Assigned Variable Name
char asnidx[VARLEN+1] ; //Assigned Variable Index
int asnivt; //Assigned Index Variable Type
char xstmnt[LINELEN]; //Required Statement
char xstmnt[LINELEN]; //Expected Statement
void bgnblk(char blkchr); //End Program Block
void endblk(int blkflg); //End Program Block
void pdowhl(); //Parse and Compile WHILE after DO
void prcasn(char trmntr); //Process Assignment
void prcvar(char trmntr); //Process Variable at Beginning of Statement
void prsasn(char trmntr); //Parse and Compile and Assignment
void prssif(char trmntr); //Parse Shortcut If
void pstmnt(); //Parse and Compile Program Statement

4
vars.h
View File

@ -41,13 +41,9 @@ int prmcnt; //Number of Parameters
void addvar(int m, int t); //Parse and Compile Variable Declaration
void chksym(int alwreg, char *name); //Error if Variable not defined
int fndvar(char *name); //Lookup variable name in variable table
void prsdts(); //Parse Data String
void setdat(); //Set Variable Data
void setvar(int m, int t); //Set Variable Name and Size
void pdecl(int m, int t); //Parse Variable Declaration
void prsdat(); //Parse and store variable data
void prsdta(); //Parse Data Array
void prsdts(); //Parse Data String
void prsvar(int alwreg); //Parse Variable
void reqvar(int alwary); //Require and Parse Variable Name