It is currently Sun Jul 22, 2018 11:49 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Apr 13, 2018 1:23 pm 
Offline
User avatar

Joined: Fri Mar 16, 2018 1:52 pm
Posts: 31
Location: Finland
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?


Top
 Profile  
 
PostPosted: Fri Apr 13, 2018 2:16 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2018 2:46 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3435
Location: Mountain View, CA
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:
$ 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#L21

I 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


Top
 Profile  
 
PostPosted: Fri Apr 13, 2018 6:40 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3090
Location: Tampere, Finland
Hard to help without seeing the code.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi


Top
 Profile  
 
PostPosted: Fri Apr 13, 2018 9:15 pm 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 293
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.


Top
 Profile  
 
PostPosted: Sat Apr 14, 2018 3:11 am 
Offline
User avatar

Joined: Fri Mar 16, 2018 1:52 pm
Posts: 31
Location: Finland
it seems that the reason for the error was simply a typo. I thought the file had some issue in it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group