Skip to content

Commit

Permalink
added IGNORENL and ENDINL directives for ignoring certain labels in .…
Browse files Browse the repository at this point in the history
…nl file output
  • Loading branch information
freem committed Jun 19, 2015
1 parent 8327d14 commit 105ee3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
56 changes: 38 additions & 18 deletions asm6f.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Changed macro usage: no parentheses around arg list, and args must be comma separated.
*/

/* Original TODO */
//todo - do NOT open source files in update mode, since we do not want to modify them in any way
//todo - don't open text files in binary mode
//todo - thoroughly verify operation on big-endian machine
Expand All @@ -34,6 +35,9 @@
//todo - make everything static
//todo - redundant parsing code is all over the place, try clean it up / consolidate

/* freem TODO */
// implement ignorenl, endinl

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -68,7 +72,7 @@ typedef struct {
// ptrdiff_t so it can hold function pointer on 64-bit machines
ptrdiff_t value; //PC (label), value (equate), param count (macro), funcptr (reserved)

// freem add (from asm6_sonder.c)
// [freem addition (from asm6_sonder.c)]
int pos; // location in file; used to determine bank when exporting labels

char *line; //for macro or equate, also used to mark unknown label
Expand All @@ -79,18 +83,20 @@ typedef struct {
int used; //for EQU and MACRO recursion check
int pass; //when label was last defined
int scope; //where visible (0=global, nonzero=local)
int ignorenl; //[freem addition] output this label in .nl files? (0=yes, nonzero=no)
void *link; //labels that share the same name (local labels) are chained together
} label;

label firstlabel={ //'$' label
"$",//*name
0,//value
0,//freem edit: pos
0,//[freem edit (from asm6_sonder.c)] pos
(char*)&true_ptr,//*line
VALUE,//type
0,//used
0,//pass
0,//scope
0,//[freem addition] ignorenl
0,//link
};

Expand Down Expand Up @@ -138,14 +144,14 @@ void endr(label*,char**);
void rept(label*,char**);
void _enum(label*,char**);
void ende(label*,char**);
//void ignorenl(label*,char**); // +freem: "ignorenl"
//void endinl(label*,char**); // +freem: "endinl"
void ignorenl(label*,char**); // [freem addition] "ignorenl"
void endinl(label*,char**); // [freem addition] "endinl"
void fillval(label*,char**);
void expandmacro(label*,char**,int,char*);
void expandrept(int,char*);
void make_error(label*,char**);

// freem edit: from asm6_sonder.c
// [freem addition (from asm6_sonder.c)]
int filepos=0;

enum optypes {ACC,IMM,IND,INDX,INDY,ZPX,ZPY,ABSX,ABSY,ZP,ABS,REL,IMP};
Expand Down Expand Up @@ -363,8 +369,8 @@ struct {
"ENDR",endr,
"ENUM",_enum,
"ENDE",ende,
//"IGNORENL",ignorenl,
//"ENDINL",endinl,
"IGNORENL",ignorenl,
"ENDINL",endinl,
"FILLVALUE",fillval,
"DL",dl,
"DH",dh,
Expand All @@ -388,14 +394,14 @@ char CantOpen[]="Can't open file.";
char ExtraENDM[]="ENDM without MACRO.";
char ExtraENDR[]="ENDR without REPT.";
char ExtraENDE[]="ENDE without ENUM.";
//char ExtraENDINL[]="ENDINL without IGNORENL.";
char ExtraENDINL[]="ENDINL without IGNORENL.";
char RecurseMACRO[]="Recursive MACRO not allowed.";
char RecurseEQU[]="Recursive EQU not allowed.";
char NoENDIF[]="Missing ENDIF.";
char NoENDM[]="Missing ENDM.";
char NoENDR[]="Missing ENDR.";
char NoENDE[]="Missing ENDE.";
//char NoENDINL[]="Missing ENDINL.";
char NoENDINL[]="Missing ENDINL.";
char IfNestLimit[]="Too many nested IFs.";
char undefinedPC[]="PC is undefined (use ORG first)";

Expand All @@ -420,7 +426,7 @@ char *inputfilename=0;
char *outputfilename=0;
char *listfilename=0;
int verboselisting=0;//expand REPT loops in listing
int genfceuxnl=0;//freem edit: generate FCEUX .nl files for symbolic debugging
int genfceuxnl=0;//[freem addition] generate FCEUX .nl files for symbolic debugging
const char *listerr=0;//error message for list file
label *labelhere;//points to the label being defined on the current line (for EQU, =, etc)
FILE *listfile=0;
Expand All @@ -435,7 +441,7 @@ int labelstart;//index of first label
int labelend;//index of last label
label *lastlabel;//last label created
int nooutput=0;//supress output (use with ENUM)
//int nonl=0;//supress output to .nl files
int nonl=0;//[freem addition] supress output to .nl files
int defaultfiller;//default fill value
int insidemacro=0;//macro/rept is being expanded
int verbose=1;
Expand Down Expand Up @@ -1062,7 +1068,7 @@ void reverse(char *dst,char *src) {
}

//===========================================================================================================
/* freem edit: imported code from asm6_sonder.c */
/* [freem addition(imported code from asm6_sonder.c)] */
void export_labelfiles() {
// iterate through all the labels and output FCEUX-compatible label info files
// based on their type (LABEL's,EQUATE's,VALUE's), address (ram/rom), and position (bank)
Expand Down Expand Up @@ -1102,6 +1108,11 @@ void export_labelfiles() {

for(i=labelstart;i<labelend;i++){
l=labellist[i];

// [freem addition]: handle IGNORENL'd labels
if((*l).ignorenl)
continue;

if(
(
(*l).type==LABEL ||
Expand Down Expand Up @@ -1157,9 +1168,12 @@ void addlabel(char *word, int local) {
(*labelhere).line=ptr_from_bool(addr>=0);
(*labelhere).used=0;

// freem edit from asm6_sonder.c
// [freem edit (from asm6_sonder.c)]
(*labelhere).pos=filepos;

// [freem addition]
(*labelhere).ignorenl=nonl;

if(c==LOCALCHAR || local) { //local
(*labelhere).scope=scope;
} else { //global
Expand Down Expand Up @@ -1505,7 +1519,7 @@ void showhelp(void) {
puts(" -L create verbose listing (expand REPT, MACRO)");
puts(" -d<name> define symbol");
puts(" -q quiet mode (no output unless error)");
// freem add:
// [freem addition]
puts(" -n export FCEUX-compatible .nl files\n");
puts("See README.TXT for more info.\n");
}
Expand Down Expand Up @@ -1570,7 +1584,7 @@ int main(int argc,char **argv) {
case 'q':
verbose=0;
break;
// freem add:
// [freem addition]
case 'n':
genfceuxnl=1;
break;
Expand Down Expand Up @@ -1670,7 +1684,7 @@ int main(int argc,char **argv) {
if(listfile)
listline(0,0);

// freem add: only generate labelfiles if asked
// [freem addition] only generate labelfiles if asked
if(genfceuxnl)
export_labelfiles();

Expand Down Expand Up @@ -2375,13 +2389,19 @@ void ende(label *id, char **next) {
}
}

/*
// [freem addition]
void ignorenl(label *id, char **next) {
nonl=1;
}

// [freem addition]
void endinl(label *id, char **next) {
if(nonl){
nonl=0;
} else {
errmsg=ExtraENDINL;
}
}
*/

void fillval(label *id,char **next) {
dependant=0;
Expand Down
28 changes: 25 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Features compared to stock ASM6
* Support for some illegal/undocumented opcodes.
(Note: Support for unstable opcodes requires compile flags.)
* Code from sonder's fork of ASM6 to allow output of FCEUX-compatible .nl files.
* New directives "IGNORENL" and "ENDINL".
These two are used for ignoring certain defines when using the -n option.

--------------------------------------------------------------
Command line
Expand All @@ -35,14 +37,34 @@ Options:
Right now, everything else is the same as the original ASM6, so check out
readme-original.txt for more information.

--------------------------------------------------------------
Additional assembler directives
--------------------------------------------------------------

IGNORENL/ENDINL

Suppresses output of any labels when exporting FCEUX .nl files.
Useful for defining labels that may conflict with zero page addresses.

; don't show these button masks in the .nl file
IGNORENL
PAD_A = %10000000
PAD_B = %01000000
PAD_SELECT = %00100000
PAD_START = %00010000
PAD_UP = %00001000
PAD_DOWN = %00000100
PAD_LEFT = %00000010
PAD_RIGHT = %00000001
ENDINL

--------------------------------------------------------------
freem's To-Do List
--------------------------------------------------------------
* add .undef?
* Add "IGNORENL" and "ENDINL" for ignoring certain defines when using -n
* add .undef? (could react badly on other passes)
* Allow -d option to set the symbols to whatever value instead of 1
* add ca65 debug format for NintendulatorDX
* add absolute addressing via "a:" (ca65 syntax), if loopy doesn't do it first
* add ca65 debug format for NintendulatorDX

--------------------------------------------------------------
<EOF>

0 comments on commit 105ee3c

Please sign in to comment.