Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added .lst file creation directives #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions asm6f.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* asm6f - asm6 with modifications for NES/Famicom development */

/* asm6f History:
1.6 + f003
* [icypawn] Added new directives for .lst file creation. (Aka unregistered)

1.6 + f002
* [nicklausw] Added new directives for INES header generation.
* [nicklausw] Put unstable/highly unstable opcode use behind directives,
Expand Down Expand Up @@ -502,6 +505,10 @@ 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;
int vacillatemacro=0;//remove MACRO definitions
int insiderept=0;//rept is being expanded
int needrept=1;//set to 0 if -u flag is set... 0: don't print rept lines in listing
int defMacro=0;//set to 1 if -U flag is set and a macro is defined; gets 0 if print attempt

static void* ptr_from_bool( int b )
{
Expand Down Expand Up @@ -1677,8 +1684,8 @@ void processline(char *src,char *errsrc,int errline) {

errmsg=0;
comment=expandline(line,src);
if(!insidemacro || verboselisting)
listline(line,comment);
if (!((insiderept || insidemacro && needrept) || defMacro) || verboselisting)//for -U :)
listline(line,comment);//^0_0

s=line;
if(errmsg) { //expandline error?
Expand All @@ -1693,6 +1700,7 @@ void processline(char *src,char *errsrc,int errline) {
}
if(p) if((*p).value==(ptrdiff_t)endm) {
comment=0;
defMacro=0; //0_0
if(endmac) {
endmac[0]='\n';
endmac[1]=0;//hide "ENDM" in case of "label: ENDM"
Expand Down Expand Up @@ -1758,8 +1766,8 @@ void processline(char *src,char *errsrc,int errline) {
break;
}
if(!p) {//maybe a label?
if(getlabel(word,&s2)) addlabel(word,insidemacro);
if(errmsg) goto badlabel;//fucked up label
if(getlabel(word,&s2)) addlabel(word,(insidemacro+insiderept)); //0_0
if(errmsg) goto badlabel;//######### label
p=getreserved(&s);
}
if(p) {
Expand Down Expand Up @@ -1789,11 +1797,13 @@ void showhelp(void) {
puts("\t-L\t\tcreate verbose listing (expand REPT, MACRO)");
puts("\t-d<name>\tdefine symbol");
puts("\t-q\t\tquiet mode (no output unless error)");
// [additions from various sources (freem, nicklausw, Sour)]
// [additions from various sources (freem, nicklausw, Sour, unregistered)]
puts("\t-n\t\texport FCEUX-compatible .nl files");
puts("\t-f\t\texport Lua symbol file");
puts("\t-c\t\texport .cdl for use with FCEUX/Mesen");
puts("\t-m\t\texport Mesen-compatible label file (.mlb)\n");
puts("\t-m\t\texport Mesen-compatible label file (.mlb)");
puts("\t-u\t\tcreate unreg listing (contracts rept; expands MACRO)"); //0_0
puts("\t-U\tcreate cool listing (expand only MACRO use&hide its definition)\n");//0_0
puts("See README.TXT for more info.\n");
}

Expand Down Expand Up @@ -1871,6 +1881,13 @@ int main(int argc,char **argv) {
case 'f':
genlua=1;
break;
// [unregistered addition]
case 'U':
vacillatemacro=1;
Copy link
Owner

@freem freem Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the fallthrough here intentional? (Or in other words, -u and -U are mostly similar, but -u doesn't set vacillatemacro)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the fallthrough on case U is intentional. (Just like loopy's -L -l fallthrough is intentional.) That's where that fallthrough idea came from; furthermore, the fallthrough on -U reduced the boolean algebra result on 1687. It is simpler and takes less lines of code. :) Both beneficial, for me at least. :)

Copy link
Author

@icypawn icypawn Apr 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's intentional. :) Both -u and -U set needrept to 0 and set listfilename to true_ptr (if listfilename==true_ptr then asm6 creates a listing file... listfilename=true_ptr is also underneath -L and -l; after thinking about this for quite a while, it doesn't seem possible to conveniently have -L, -l, -U, and -u to use the same listfilename=true_ptr). However, -U also sets vacillatemacro to 1. The state of the flags needrept and vacillatemacro help the program to know how to branch after loading them in other places in this commit's code. I have a page of boolean algebra that verifies what you encounter when you run this commit. It does work freem.

The simplicity is purposeful. Personally, I didn't want to cause the user's computer to have to do an extensive amount of work compared to asm6.

case 'u'://0_0
needrept=0;//for hiding rept lines in listfile creation
listfilename=true_ptr;
break;
default:
fatal_error("unknown option: %s",argv[i]);
}
Expand Down Expand Up @@ -2574,6 +2591,7 @@ void macro(label *id, char **next) {
errmsg=NeedName;

makemacro=true_ptr;//flag for processline to skip to ENDM
defMacro=vacillatemacro;//0_0
if(errmsg) {//no valid macro name
return;
} else if((*labelhere).type==LABEL) {//new macro
Expand Down Expand Up @@ -2699,7 +2717,7 @@ void expandrept(int errline,char *errsrc) {

start=(char**)repttext;//first rept data
oldscope=scope;
insidemacro++;
insiderept++;//insidemacro++;//0_0
for(i=rept_loops;i;--i) {
linecount=0;
scope=nextscope++;
Expand All @@ -2718,7 +2736,7 @@ void expandrept(int errline,char *errsrc) {
}
errmsg=0;
scope=oldscope;
insidemacro--;
insiderept--;//insidemacro--;//0_0
}

int enum_saveaddr;
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--------------------------------------------------------------
ASM6f (v1.6)
A 6502 assembler by loopy (loopy at mm.st)
With modifications by freem, nicklausw, and Sour
With modifications by freem, nicklausw, Sour, and unregistered
--------------------------------------------------------------

ASM6f is a fork of ASM6, primarily targeted at NES/Famicom development.
Expand Down Expand Up @@ -38,6 +38,9 @@ Options:
-f export Lua symbol file
-c export .cdl for use with FCEUX/Mesen
-m export Mesen-compatible label file (.mlb)
-u Create unreg listing (contracts rept; expands MACRO)
-U Create cool listing (expands only MACRO use and hides their definitions)

Default output is <sourcefile>.bin
Default listing is <sourcefile>.lst

Expand Down