Is there a program to write this so it is easy to read and is there a proposed structure?
I'm just making it in .txt file, I don't know what kind of structure I should have for when it will become too big... what tools I could use.
I use Notepad++ myself, but there's lots of others (Scintilla, etc.)
The usual filename extension is either .s or .asm I think, but what you want to name the files is really up to you.
You will probably make level specific files. Let's say you make a game with 15 mazes. Each maze will be stored ina separate file. Then 1 big file with shared code, possibly more if it gets too big.
Then music files might be 3 files.
-sound effects data
Then each unique nametable will be a separate file (compressed)...
-in game screens
-victory screen / end credits
Then, if you are using asm6 or nesasm, a master file that links all these together, with include and incbin statements.
If you are using ca65, then the linker / config file will link them all together.
I also like a separate header file to keep all my variable definitions, and define statements.
Edit - and a file with your CHR ROM (graphics).
I personally like to have a master file that includes everything else at the correct places. First, I have a handful of declaration files for the different modules of my programs (input, audio, graphics, gameplay, etc.) which contain all the constants, variables and macros for each module. Then comes the NES header, which I build using macros from the "header" module. Next in the main file are the actual PRG and CHR banks, with all the .ORGs, .BASEs, . SEGMENTs and whatever else is necessary to structure a valid ROM file, and inside the banks I include all the all functions, tables, tiles, etc. where I want them to be. Even the interrupt vectors are treated as a regular data table.
You do have to be careful when the same code/data must appear multiple times in the ROM (such as when you're simulating a hardwired PRG bank in a mapper that doesn't have one) to avoid "duplicate label" errors. What I do in ASM6 is declare the global label of a function/table/whatever like DrawSprites = * instead of DrawSprites:, and below that I only use temporary labels. In ca65 I scope everything and only create global symbols for things that aren't defined yet. Either way you have to be extra careful to include the thing at the exact same address every time (you can write code to detect screw ups, though).
I guess this is it... I try to mimic some of the features of high level languages and I have strict consistent ways of declaring everything, in order to make things more organized and easier to debug.
You have to find the structure you're most comfortable working with, and you'll probably be changing little things from protect to project as you progressively see what works and what doesn't for you. I'm still tweaking my "formula" every now and then.
Edit: Oh, and for writing code I use Notepad++ with 6502 syntax highlighting. To build the project I have a batch file I can double click that builds the .nes file and automatically opens it in an emulator.
Since it only offers auto complete for a single file, I tend to make giant monolithic asm files, but sections and code folding make it not so bad.
If you have any files that are included directly in other assembly sources, you should not run the assembler on those files separately. This is because using the "include" directive will directly insert the contents into the source at assemble time, so they do not need to be linked together.
Usage will probably look something like this:
Code: Select all
myassembler main.asm -o main.o myassembler title.asm -o title.o mylinker -o mygame.nes main.o title.o
With code structure, the way my most recent project has things structured is single-module and three files: nes.s is hardware defines and functions, game.s is software defines and functions, main.s is the NES "frontend" (NMI and reset vectors and stuff) and it's what is actually given to the assembler.
asm6 is a however-many pass assembler, so it doesn't have problems with forward-references.HihiDanni wrote:Be careful on the order of your includes, as you will likely need to introduce symbols before they are used
I think the only difference this makes in ca65 is with allocations on the zero-page.nicklausw wrote:asm6 is a however-many pass assembler, so it doesn't have problems with forward-references.HihiDanni wrote:Be careful on the order of your includes, as you will likely need to introduce symbols before they are used
If they aren't defined above where they are used, the assembler has to assume 16-bit addressing and you lose the zero-page advantage. Basically just keep your ZP .res stuff at the top of the file and you're fine.
Otherwise, I don't believe it makes a difference. It's a "one-pass" assemble, but it does fill in forward references (unlike C, which requires forward declarations to even compile).
Yet another bullet point on the list of reasons why C is not a good language. When even assemblers do a better job at this...rainwarrior wrote:It's a "one-pass" assemble, but it does fill in forward references (unlike C, which requires forward declarations to even compile).