Reviewing NESASM 3 source code:
https://github.com/toastynerd/nesasm/tree/master/srcThis is a very basic/quick skim so I may have overlooked things.
Code:
$ grep -rin 'open file!' .
./src/pcx.c:378: error("Can not open file!");
./src/map.c:33: fatal_error("Can not open file!");
./src/command.c:594: fatal_error("Can not open file!");
./src/command.c:668: fatal_error("Can not open file!");
./src/command.c:812: fatal_error("Can not open file!");
src/pcx.c --
Function pcx_load()
Calls open_file(), which calls fopen() with arguments "rb" (read + binary file)
Function pcx_get_args() calls pcx_load()
Function do_incchr() calls pcx_get_args()
* This code is called when using
INCCHR or
.INCCHR on a file with a
.pcx extension
src/map.c --
Function pce_load_map()
Calls open_file(), which calls fopen() with arguments "rb" (read + binary file)
Function do_incbin() calls pce_load_map() when encountering a file extension of
.fmp* This code is called when using
INCBIN or
.INCBIN on a file with a
.fmp extension
src/command.c line 594 --
Function do_incbin()
Calls open_file(), which calls fopen() with arguments "rb" (read + binary file)
* This code is called when using
INCBIN or
.INCBIN on a file (as long as it doesn't end in
.fmp or
.mx)
src/command.c line 668 --
Function do_mx()
Calls open_file(), which calls fopen() with arguments "r" (read), which usually means a text file
Function do_incbin() calls do_mx() when encountering a file extension of
.mx* This code is called when using
INCBIN or
.INCBIN on a file with a
.mx extension
src/command.c line 812 --
Function do_include()
Calls open_input()
open_input() does some string/path mangling -- for example, it will auto-append
.asm in some cases
open_input() calls fopen() with arguments "r" (read), which usually means a text file
This function also supports nested includes for up to 7 levels deep (e.g. an included file can include another etc...)
* This code is called when using
INCLUDE or
.INCLUDE.
Function open_file() is pretty simple:
Code:
322 FILE *
323 open_file(char *name, char *mode)
324 {
325 FILE *fileptr;
326 char testname[256];
327 int i;
328
329 fileptr = fopen(name, mode);
330 if (fileptr != NULL) return(fileptr);
331
332 for (i = 0; i < 10; i++) {
333 if (strlen(incpath[i])) {
334 strcpy(testname, incpath[i]);
335 strcat(testname, name);
336
337 fileptr = fopen(testname, mode);
338 if (fileptr != NULL) break;
339 }
340 }
341
342 return (fileptr);
343 }
The logic works like this:
Call fopen() on the literal file/path given. If it works, great. If not, continue with a bunch of madness:
There's a multi-dimensional array declared as
char incpath[10][128]Function init_path() populates this array with data from... well... I don't even want to look at it, honestly. I don't want to know what's with the
; character in that code either, but I bet it's a delimiter for multiple directories/paths:
https://github.com/toastynerd/nesasm/bl ... nput.c#L21I assume it has something to do with this from the documentation:
Code:
Include path
------------
By default the assembler looks in the current directory when
loading an include file, but when it doesn't find the file it
then uses the environment variable 'NES_INCLUDE' to get a list
of include paths. Ideally, you will want to set this variable in
your 'AUTOEXEC.BAT' file, and have it point to the 'NES'
directory of MagicKit.
ex: set NES_INCLUDE=c:\magickit\nes
That's as much as I'm willing to look at this.
This is just another example of where good assembler documentation is necessary, else end-users get confused. :P