diff --git a/doc/c02.txt b/doc/c02.txt index 0aa9b52..98febbe 100644 --- a/doc/c02.txt +++ b/doc/c02.txt @@ -131,6 +131,16 @@ Examples: #pragma origin $0400 //Compiled code starts at address 1024 #pragma origin 8192 //Compiled code starts at address 8192 +PRAGMA PADDING + +The #pragma padding directive adds empty bytes to the end of the compiled +program. It should be used with target systems that require the object +code to be padded with a specific number of bytes. + +Examples: + #pragma padding 1 //Add one empty byte to end of code + #pragma padding $FF //Add 255 empty bytes to end of code + PRAGMA VARTABLE The #pragma vartable directive forces the variable table to be written. diff --git a/src/c02.c b/src/c02.c index f845efe..86c33bc 100644 --- a/src/c02.c +++ b/src/c02.c @@ -31,6 +31,7 @@ void init(void) { concnt = 0; //Number of Constants Defined varcnt = 0; //Number of Variables in Table lblcnt = 0; //Number of Labels in stack + padcnt = 0; //Number of Padding Bytes at End curcol = 0; //Current Column in Source Code curlin = 0; //Current Line in Source Code alcvar = TRUE; //Allocate Variables Flag @@ -84,6 +85,11 @@ void prolog(void) { void epilog(void) { if (!vrwrtn) vartbl(); //Write Variable Table + if (padcnt) { + SCMNT("PADDING BYTES") + sprintf(word, "$%hhX", padcnt); + asmlin(STROP, word); + } } /* Compile Source Code*/ diff --git a/src/common.h b/src/common.h index 6b3d1ac..53c743d 100644 --- a/src/common.h +++ b/src/common.h @@ -67,6 +67,8 @@ int infunc; //Inside Function Definition Flag int lsrtrn; //Last Statement was a Return Flag int fcase; //First Case Statement Flag +int padcnt; //Number of Padding Bytes at End of Program + void exterr(int errnum); //Print current file name & position and exit void expctd(char *expected); //Print Expected message and exit diff --git a/src/include.c b/src/include.c index 09fc378..7987f89 100644 --- a/src/include.c +++ b/src/include.c @@ -80,6 +80,12 @@ void porign(void) { DEBUG("Set origin to %s\n", value) } +/* Parse Padding Subdirective */ +void ppddng(void) { + padcnt = prsnum(0xFF); //Get Number of Padding Bytes + DEBUG("Set padding to %d\n", padcnt) +} + /* Parse Zeropage Subdirective */ void prszpg(void) { zpaddr = prsnum(0xFF); //Set Zero Page Address to Literal @@ -102,6 +108,8 @@ void pprgma(void) { pascii(); //Parse Ascii else if (wordis("ORIGIN")) porign(); //Parse Origin + else if (wordis("PADDING")) + ppddng(); //Parse Origin else if (wordis("VARTABLE")) pvrtbl(); //Parse Vartable else if (wordis("ZEROPAGE")) diff --git a/test/test.c02 b/test/test.c02 index a31952b..46655c6 100644 --- a/test/test.c02 +++ b/test/test.c02 @@ -3,6 +3,7 @@ * Test file for Compiler * ********************************************/ +#pragma padding 1 /* Constants */ const #TRUE = $FF, #FALSE = 0;