mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-22 10:29:10 +00:00
Add generation of BRA instructions for 65C02
This commit is contained in:
parent
702e7f7c56
commit
ae38a81b3f
33
apple1/oldclude/apple1.h
Normal file
33
apple1/oldclude/apple1.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* Apple 1 Header File */
|
||||||
|
|
||||||
|
//The keyboard data register returns ASCII codes with the high bit set
|
||||||
|
//These can be safely printed, since the display hardware ignores the high bit
|
||||||
|
#define CR $8D //Carriage Return key code
|
||||||
|
#define ESC $9B //Escape key code
|
||||||
|
#define DEL $DF //Delete (Backspace) key code
|
||||||
|
|
||||||
|
//Memory locations used by monitor program
|
||||||
|
char* buffer = $0200 //Monitor Input Buffer
|
||||||
|
|
||||||
|
//PIA 6820 Registers
|
||||||
|
char* kbd = $D010 //Keyboard Data
|
||||||
|
char* kbdcr = $D011 //Keyboard Control Register
|
||||||
|
char* dsp = $D012 //Display Data
|
||||||
|
char* dspcr = $D013 //Display Control Register
|
||||||
|
|
||||||
|
#label exit $FF00 //Monitor Entry Point
|
||||||
|
|
||||||
|
/*
|
||||||
|
void echo(A) = $FFEF //Print Character in Accumulator
|
||||||
|
void prbyte(A) = $FFDC //Print Accumulator as Hexadadecimal number
|
||||||
|
void prhex(A) = $FFE5 //Print Low Nybble of Accumulator as Hex Digit
|
||||||
|
*/
|
||||||
|
|
||||||
|
#origin $0300 //$0200 through $02FF used as a string buffer
|
||||||
|
|
||||||
|
/*
|
||||||
|
#asm
|
||||||
|
#endasm
|
||||||
|
char getkey();
|
||||||
|
*/
|
||||||
|
|
1
c02.c
1
c02.c
@ -164,6 +164,7 @@ void pargs(int argc, char *argv[])
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
t65c02 = TRUE; //Target 65C02 Processor
|
||||||
debug = TRUE; //Output Debug Info
|
debug = TRUE; //Output Debug Info
|
||||||
gencmt = TRUE; //Generate Assembly Language Comments
|
gencmt = TRUE; //Generate Assembly Language Comments
|
||||||
|
|
||||||
|
74
c02.ppx
74
c02.ppx
@ -3,41 +3,87 @@
|
|||||||
<category name="expr.h" />
|
<category name="expr.h" />
|
||||||
<category name="cond.h" />
|
<category name="cond.h" />
|
||||||
<category name="asm.h" />
|
<category name="asm.h" />
|
||||||
<category name="c02.c" />
|
<category name="c02.c">
|
||||||
|
<category name="Window">
|
||||||
|
<property name="Left" type="integer">0</property>
|
||||||
|
<property name="Top" type="integer">0</property>
|
||||||
|
<property name="Right" type="integer">952</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="stmnt.c">
|
<category name="stmnt.c">
|
||||||
<category name="Window">
|
<category name="Window">
|
||||||
<property name="Left" type="integer">-8</property>
|
<property name="Left" type="integer">26</property>
|
||||||
<property name="Top" type="integer">-31</property>
|
<property name="Top" type="integer">26</property>
|
||||||
<property name="Right" type="integer">952</property>
|
<property name="Right" type="integer">978</property>
|
||||||
<property name="Bottom" type="integer">422</property>
|
<property name="Bottom" type="integer">336</property>
|
||||||
<property name="Maximized" type="integer">1</property>
|
<property name="Maximized" type="integer">0</property>
|
||||||
<property name="Active" type="integer">1</property>
|
<property name="Active" type="integer">0</property>
|
||||||
</category>
|
</category>
|
||||||
</category>
|
</category>
|
||||||
<category name="asm.c" />
|
<category name="asm.c" />
|
||||||
<category name="vars.c" />
|
<category name="vars.c">
|
||||||
<category name="parse.c">
|
|
||||||
<category name="Window">
|
<category name="Window">
|
||||||
<property name="Left" type="integer">52</property>
|
<property name="Left" type="integer">52</property>
|
||||||
<property name="Top" type="integer">52</property>
|
<property name="Top" type="integer">52</property>
|
||||||
<property name="Right" type="integer">760</property>
|
<property name="Right" type="integer">1004</property>
|
||||||
<property name="Bottom" type="integer">362</property>
|
<property name="Bottom" type="integer">362</property>
|
||||||
<property name="Maximized" type="integer">0</property>
|
<property name="Maximized" type="integer">0</property>
|
||||||
<property name="Active" type="integer">0</property>
|
<property name="Active" type="integer">0</property>
|
||||||
</category>
|
</category>
|
||||||
</category>
|
</category>
|
||||||
<category name="include.c" />
|
<category name="parse.c">
|
||||||
<category name="expr.c">
|
|
||||||
<category name="Window">
|
<category name="Window">
|
||||||
<property name="Left" type="integer">78</property>
|
<property name="Left" type="integer">78</property>
|
||||||
<property name="Top" type="integer">78</property>
|
<property name="Top" type="integer">78</property>
|
||||||
<property name="Right" type="integer">786</property>
|
<property name="Right" type="integer">1030</property>
|
||||||
<property name="Bottom" type="integer">388</property>
|
<property name="Bottom" type="integer">388</property>
|
||||||
<property name="Maximized" type="integer">0</property>
|
<property name="Maximized" type="integer">0</property>
|
||||||
<property name="Active" type="integer">0</property>
|
<property name="Active" type="integer">0</property>
|
||||||
</category>
|
</category>
|
||||||
</category>
|
</category>
|
||||||
|
<category name="include.c">
|
||||||
|
<category name="Window">
|
||||||
|
<property name="Left" type="integer">104</property>
|
||||||
|
<property name="Top" type="integer">104</property>
|
||||||
|
<property name="Right" type="integer">1056</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="expr.c">
|
||||||
|
<category name="Window">
|
||||||
|
<property name="Left" type="integer">130</property>
|
||||||
|
<property name="Top" type="integer">130</property>
|
||||||
|
<property name="Right" type="integer">1082</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="parse.h" />
|
<category name="parse.h" />
|
||||||
<category name="common.h" />
|
<category name="common.h">
|
||||||
|
<category name="Window">
|
||||||
|
<property name="Left" type="integer">0</property>
|
||||||
|
<property name="Top" type="integer">0</property>
|
||||||
|
<property name="Right" type="integer">952</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="files.c" />
|
<category name="files.c" />
|
||||||
|
<category name="common.c">
|
||||||
|
<category name="Window">
|
||||||
|
<property name="Left" type="integer">26</property>
|
||||||
|
<property name="Top" type="integer">26</property>
|
||||||
|
<property name="Right" type="integer">978</property>
|
||||||
|
<property name="Bottom" type="integer">336</property>
|
||||||
|
<property name="Maximized" type="integer">0</property>
|
||||||
|
<property name="Active" type="integer">0</property>
|
||||||
|
</category>
|
||||||
|
</category>
|
||||||
</settings>
|
</settings>
|
||||||
|
7
common.h
7
common.h
@ -20,7 +20,7 @@
|
|||||||
#define MAXLAB 15 //Maximum Number of Labels (Nesting Depth)
|
#define MAXLAB 15 //Maximum Number of Labels (Nesting Depth)
|
||||||
|
|
||||||
#define CPUOP "PROCESSOR" //Target CPU Pseudo-Operator
|
#define CPUOP "PROCESSOR" //Target CPU Pseudo-Operator
|
||||||
#define CPUARG "6502" //Target CPU Operand
|
#define CPUARG "65C02" //Target CPU Operand
|
||||||
#define ORGOP "ORG" //Origin Pseudo-Op
|
#define ORGOP "ORG" //Origin Pseudo-Op
|
||||||
#define EQUOP "EQU" //Equate Pseudo-Op
|
#define EQUOP "EQU" //Equate Pseudo-Op
|
||||||
#define BYTEOP "DC" //Define Byte Pseudo-Op
|
#define BYTEOP "DC" //Define Byte Pseudo-Op
|
||||||
@ -40,8 +40,9 @@
|
|||||||
#define ACMNT(str) if (gencmt) {addcmt(str);}
|
#define ACMNT(str) if (gencmt) {addcmt(str);}
|
||||||
#define CCMNT(chr) if (gencmt) {chrcmt(chr);}
|
#define CCMNT(chr) if (gencmt) {chrcmt(chr);}
|
||||||
|
|
||||||
int gencmt; //Generate Assembly Language Comments
|
int t65c02; //Target 65C02 Processor
|
||||||
int debug; //Print Debug Info (TRUE or FALSE)
|
int gencmt; //Generate Assembly Language Comments
|
||||||
|
int debug; //Print Debug Info (TRUE or FALSE)
|
||||||
|
|
||||||
int curcol, curlin; //Position in Source Code
|
int curcol, curlin; //Position in Source Code
|
||||||
int savcol, savlin; //Save Position in Source Code
|
int savcol, savlin; //Save Position in Source Code
|
||||||
|
3
parse.c
3
parse.c
@ -145,6 +145,7 @@ char escape(char c)
|
|||||||
{
|
{
|
||||||
DEBUG("Escaping character '%c'\n", c);
|
DEBUG("Escaping character '%c'\n", c);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'n': return 0x0a;
|
||||||
case 'r': return 0x0d;
|
case 'r': return 0x0d;
|
||||||
default: return c;
|
default: return c;
|
||||||
}
|
}
|
||||||
@ -158,7 +159,7 @@ void getstr() {
|
|||||||
DEBUG("Parsing string\n", 0);
|
DEBUG("Parsing string\n", 0);
|
||||||
strdel = getnxt(); //Get String Delimiter
|
strdel = getnxt(); //Get String Delimiter
|
||||||
CCMNT(strdel);
|
CCMNT(strdel);
|
||||||
while(match(strdel) == escnxt) {
|
while(!match(strdel) || escnxt) {
|
||||||
CCMNT(nxtchr);
|
CCMNT(nxtchr);
|
||||||
if (escnxt) {
|
if (escnxt) {
|
||||||
word[wrdlen++] = escape(getnxt());
|
word[wrdlen++] = escape(getnxt());
|
||||||
|
14
stmnt.c
14
stmnt.c
@ -15,6 +15,12 @@
|
|||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "stmnt.h"
|
#include "stmnt.h"
|
||||||
|
|
||||||
|
/* Emit BRA or JMP */
|
||||||
|
void brajmp(char *lbl) {
|
||||||
|
if (t65c02) asmlin("BRA", lbl);
|
||||||
|
else asmlin("JMP", lbl);
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse Shortcut If */
|
/* Parse Shortcut If */
|
||||||
void prssif(char trmntr) {
|
void prssif(char trmntr) {
|
||||||
newlbl(cndlbl); //Create Label for "if FALSE" expression
|
newlbl(cndlbl); //Create Label for "if FALSE" expression
|
||||||
@ -22,7 +28,7 @@ void prssif(char trmntr) {
|
|||||||
expect('?');
|
expect('?');
|
||||||
prsxpr(':'); //Parse "if TRUE" expression
|
prsxpr(':'); //Parse "if TRUE" expression
|
||||||
newlbl(tmplbl); //Create End of Expression Label
|
newlbl(tmplbl); //Create End of Expression Label
|
||||||
asmlin("JMP", tmplbl); //Jump over "if FALSE" expression
|
brajmp(tmplbl); //Jump over "if FALSE" expression
|
||||||
setlbl(cndlbl); //Emit "if FALSE" label
|
setlbl(cndlbl); //Emit "if FALSE" label
|
||||||
prsxpr(trmntr); //Parse "if FALSE" expression
|
prsxpr(trmntr); //Parse "if FALSE" expression
|
||||||
setlbl(tmplbl); //Emit End of Expression Label
|
setlbl(tmplbl); //Emit End of Expression Label
|
||||||
@ -194,10 +200,10 @@ void pfor() {
|
|||||||
pshlbl(LTLOOP, loplbl); //and Push onto Stack
|
pshlbl(LTLOOP, loplbl); //and Push onto Stack
|
||||||
newlbl(cndlbl); //Create Conditional Label
|
newlbl(cndlbl); //Create Conditional Label
|
||||||
prscnd(';', TRUE); //Parse Conditional Expession
|
prscnd(';', TRUE); //Parse Conditional Expession
|
||||||
asmlin("JMP", endlbl); //Jump over Increment
|
asmlin("JMP", endlbl); //Jump to End of Loop
|
||||||
setlbl(loplbl); //Set to Emit on Next Line
|
setlbl(loplbl); //Set to Emit on Next Line
|
||||||
prsasn(')'); //Parse Increment Assignment
|
prsasn(')'); //Parse Increment Assignment
|
||||||
asmlin("JMP", forlbl); //Jump to Conditional
|
brajmp(forlbl); //Jump to Conditional
|
||||||
setlbl(cndlbl); //Emit Label at Start of Loop
|
setlbl(cndlbl); //Emit Label at Start of Loop
|
||||||
bgnblk(FALSE); //Check For and Begin Block
|
bgnblk(FALSE); //Check For and Begin Block
|
||||||
}
|
}
|
||||||
@ -219,7 +225,7 @@ void pelse() {
|
|||||||
lblasm[0] = 0; //and Clear It
|
lblasm[0] = 0; //and Clear It
|
||||||
newlbl(skplbl); //Create Skip Label
|
newlbl(skplbl); //Create Skip Label
|
||||||
pshlbl(LTIF, skplbl); //Push Onto Stack
|
pshlbl(LTIF, skplbl); //Push Onto Stack
|
||||||
asmlin("JMP", skplbl); //Emit Jump over Block Code
|
brajmp(skplbl); //Emit Jump over Block Code
|
||||||
strcpy(lblasm, lbltmp); //Restore Line Label
|
strcpy(lblasm, lbltmp); //Restore Line Label
|
||||||
bgnblk(FALSE); //Check For and Begin Block
|
bgnblk(FALSE); //Check For and Begin Block
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user