NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
sdm
Posts: 424
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by sdm »

There was a huge lack of ability to set the start and size of the included INCBIN in NESASM3 (which was probably in every other assembler). I wrote to the author of the compiler and he updated it.

https://github.com/pce-devel/huc/releases/tag/current
https://pcengine.proboards.com/thread/2 ... nks?page=3

Attaching a file with NameTable, for example:

Will read 768 Bytes from the beginning of the BIN file.

Code: Select all

	.incbin "nam\nametable.nam",0,768
It will only attach the 64 Bytes Attribute Table from the NAM file:

Code: Select all

	.incbin "nam\nametable.nam",960,64
User avatar
Dwedit
Posts: 4933
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Dwedit »

Specifying the start and size of an INCBIN is a great feature to have.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Pokun
Posts: 2714
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Pokun »

Indeed, it's one of those things I seldom use but when I do I'm glad it exists.
User avatar
Dwedit
Posts: 4933
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Dwedit »

INCBIN with start and size is especially powerful in ASM6, with the way its memory model works. You can use it to construct a patching system, where you can include sections of the original game, then start including real assembly code which gets assembled at the actual address. Then proceed and include more of the original game.

This works because INCBIN on ASM6 can use symbols as its size and address, including those that depend on the length of the code assembled.

I don't know if NESASM or CA65 can do the same or not.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Pokun
Posts: 2714
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Pokun »

I see, multi-pass assemblers such as ASM6 has an advantage that symbols can be used more freely without forward declaration, although I'm not sure if the multi-pass design is related in this case. CA65 might be more limited with its 2-pass design.
elmer
Posts: 5
Joined: Sat Apr 22, 2017 11:02 am

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by elmer »

sdm wrote: Tue Apr 02, 2024 3:15 am I wrote to the author of the compiler and he updated it.
I'm not the original author, just the person who is currently maintaining the version of NESASM4/PCEAS4 that is in the HuC repository. :D

Dwedit wrote: Tue Apr 02, 2024 9:05 pm Specifying the start and size of an INCBIN is a great feature to have.
If there are features that are missing in NESASM4 that people miss from other assemblers (or from ClusterM's NESASM 3.6), just let me know, and I'll consider adding them, within the limit that its purpose is to assemble directly to a binary image (i.e. a ROM), and not to generate an object-file that needs a seperate linker.

A lot of the most-useful recent additions to NESASM4 came about in order to make it compatible-enough with KickAssembler that it could assemble code produced by the KickC C compiler.

Additions are currently being worked on in order to make it compatible-enough with sdas6500 that it will be able to assemble code produced by the SDCC C compiler.

The main reason for wanting to use PCEAS4/NESASM4 with KickC or SDCC, is that PCEAS4 elegantly (and automatically) handles calling banked code in a ROM, while neither KickC nor SDCC is all that good at producing banked ROMs without a *lot* of extra tedious work on the part of the programmer.

NESASM4 doesn't currently have PCEAS4's capability to do this automatically, but that's primarily because I don't personally develop for the NES, and I have no idea what mappers are the most-common for NES developers to use. If someone can explain what small selection of mappers it would be worth supporting, then it *might* be worth adding this capability to NESASM4.

Dwedit wrote: Wed Apr 03, 2024 2:48 pm You can use it to construct a patching system, where you can include sections of the original game, then start including real assembly code which gets assembled at the actual address. Then proceed and include more of the original game.
If I understand you correctly, NESASM has always allowed this. You just ".incbin" the original game ROM, and the start patching/overwriting areas of it as you wish.

There were some annoying limitations with NESASM3 in that you didn't have direct access to the current program counter, but you do now in NESASM4 (it is the '*' symbol). That capability, plus the addition of true variables in NESASM4 (used with the ".set" pseudo-op), allows programmers to easily do some things that were a lot more difficult/annoying previously.

Dwedit wrote: Wed Apr 03, 2024 2:48 pm This works because INCBIN on ASM6 can use symbols as its size and address, including those that depend on the length of the code assembled.

I don't know if NESASM or CA65 can do the same or not.
As long as the symbols have been defined before the ".incbin", it'll work on NESASM4.

If you can provide a good example of *why* you would want to use symbols that haven't been defined yet in a ".incbin", then I can see about changing that.

One of the recent additions was the ability to use symbols that are undefined in a ".ds", so that you can set the size of some data tables at the end of the first pass, after you know just how big they need to be.

Pokun wrote: Fri Apr 05, 2024 8:23 am I see, multi-pass assemblers such as ASM6 has an advantage that symbols can be used more freely without forward declaration, although I'm not sure if the multi-pass design is related in this case. CA65 might be more limited with its 2-pass design.
NESASM4 has been multi-pass for a few years now. It runs in 2 passes when it can, but if it needs to execute extra passes (such as when changing forward-refereneced short branches to long branches), then it can.
Last edited by elmer on Mon Apr 08, 2024 1:51 pm, edited 1 time in total.
Pokun
Posts: 2714
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Pokun »

I see, PCEAS4 has certainly improved a lot over any older version.


elmer wrote: Mon Apr 08, 2024 7:13 am
sdm wrote: Tue Apr 02, 2024 3:15 am I wrote to the author of the compiler and he updated it.
I'm not the original author, just the person who is currently maintaining the version of NESASM4/PCEAS4 that is in the HuC repository. :D
According to the latest Magickit readme it was made (or at least last maintained before) by someone called David Michel and it is based on the source code for J. H. Van Ornum's assembler from 1984 (possibly as6502 from when he worked at AT&T Bell Labs).
elmer
Posts: 5
Joined: Sat Apr 22, 2017 11:02 am

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by elmer »

Pokun wrote: Mon Apr 08, 2024 1:00 pm According to the latest Magickit readme it was made (or at least last maintained before) by someone called David Michel and it is based on the source code for J. H. Van Ornum's assembler from 1984 (possibly as6502 from when he worked at AT&T Bell Labs).
David Michel is the author of the old MagicEngine and MagicFX emulators (www.magicengine.com).

He's not involved in PCE/NES development these days AFAIK.

Dave Shadoff (one of the other MagicKit developers) is still active, but less so in the PCE/NES software world, and more in hardware development and the MiSTer.
Last edited by elmer on Mon Apr 08, 2024 6:32 pm, edited 1 time in total.
Pokun
Posts: 2714
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NESASM Update. From now on, it is possible to set the start and size of the included INCBIN.

Post by Pokun »

Oh I see, that's why Magickit is hosted on his site and shares similar naming to his emulators.
Post Reply