NESASM3 - "Cannot open file!" error

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

NESASM3 - "Cannot open file!" error

Post by SusiKette »

The title is very self explanatory. This error appears when it tries to include the *.chr file to the ROM. What could be causing this?
Avatar is pixel art of Noah Prime from Astral Chain
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: NESASM3 - "Cannot open file!" error

Post by unregistered »

I'm not sure about nesasm3, but in asm6 I have to use .incbin to include .chr files. In asm6, .include doesn't work because there isn't any text in a .chr file. :) Hope this helps; maybe someone else with experience with nesasm can help you more.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: NESASM3 - "Cannot open file!" error

Post by koitsu »

Reviewing NESASM 3 source code: https://github.com/toastynerd/nesasm/tree/master/src

This is a very basic/quick skim so I may have overlooked things.

Code: Select all

$ 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: Select all

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#L21

I assume it has something to do with this from the documentation:

Code: Select all

    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
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: NESASM3 - "Cannot open file!" error

Post by thefox »

Hard to help without seeing the code.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Punch
Posts: 365
Joined: Sat Feb 16, 2013 11:52 am

Re: NESASM3 - "Cannot open file!" error

Post by Punch »

Using include instead of incbin and/or actually not pointing to the correct directory/filename. Check the .chr's path and use absolute paths whenever possible.
This is a block of text that can be added to posts you make. There is a 255 character limit.
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: NESASM3 - "Cannot open file!" error

Post by SusiKette »

it seems that the reason for the error was simply a typo. I thought the file had some issue in it.
Avatar is pixel art of Noah Prime from Astral Chain
Post Reply