It is currently Wed Oct 18, 2017 2:49 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Jun 14, 2017 5:40 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 39
I'm making assembly code for 6502 that I compile for ASM6.

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.


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 5:46 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5718
Location: Canada
There are several text editors for which you can use 6502 assembly formatting templates.

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.


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 6:09 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 39
thanks!!

is there an example of a full game I'd like to see how to structure a document?


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 6:16 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1771
Location: DIGDUG
Code Structure -

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.
-music engine
-music data
-sound effects data

Then each unique nametable will be a separate file (compressed)...
-title screen
-options screen
-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).

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 7:00 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10052
Location: Rio de Janeiro - Brazil
I think everyone structures their programs and files differently, since assembly gives us much more freedom than any other kind of programming.

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.


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 8:21 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19096
Location: NE Indiana, USA (NTSC)
I use ca65 instead of ASM6, but there are several NES-related repositories in my GitHub account.


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 10:32 pm 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 248
I use .asm and Reluached64 as it gives me auto-completion, and quick browsing of sections, labels etc. It has a few built in assembler formats, one of them might be compatible enough with ASM6.

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.


Top
 Profile  
 
PostPosted: Wed Jun 14, 2017 11:13 pm 
Offline
User avatar

Joined: Sun Nov 20, 2016 10:43 pm
Posts: 11
Location: Osaka, Japan
Being a Java programmer I found using this IDE works best for me - http://www.wudsn.com/index.php/ide
It has asm6 support.
Also it compiles the code and starts your chosen NES emulator with your program in 1 step.

Maybe I'm just too lazy :D

_________________
tempus edax rerum


Top
 Profile  
 
PostPosted: Thu Jun 15, 2017 5:01 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 39
thanks to all for the reply, really helps me!!

If someone has a simple example of using more than one file with ASM6, I'd be curious to see it


Top
 Profile  
 
PostPosted: Sat Jun 17, 2017 4:35 pm 
Offline
User avatar

Joined: Tue Apr 05, 2016 5:25 pm
Posts: 121
Generally, for a project that has multiple files (which should be anything larger than a "hello world" program), you'll run the assembler on each file separately to generate the object files. Then, you combine those object files together using your linker program. Typically the linker will have the configuration for how to lay everything out in memory. Each separately assembled file has code but no real physical location. The linker determines where in the output file everything should go, and then ties everything together.

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:
myassembler main.asm -o main.o
myassembler title.asm -o title.o
mylinker -o mygame.nes main.o title.o

I don't know ASM6 specifics (I do SNES with ca65), but I imagine the same concepts apply there as well.

_________________
SNES NTSC 2/1/3 1CHIP | serial number UN318588627


Top
 Profile  
 
PostPosted: Sat Jun 17, 2017 8:36 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10052
Location: Rio de Janeiro - Brazil
ASM6 doesn't ​work like that. You can only use multiple files using .include, as a way to make the source code more organized than a huge ASM file with everything. Ultimately, it's as if ASM6 concatenated all the included files to create a huge ASM file before assembling.


Top
 Profile  
 
PostPosted: Sun Jun 18, 2017 6:29 am 
Offline
User avatar

Joined: Tue Apr 05, 2016 5:25 pm
Posts: 121
Ah, so it's how my project used to be structured. Be careful on the order of your includes, as you will likely need to introduce symbols before they are used, and try to avoid creating circular dependencies too (file A needs something from file B needs something from file A).

_________________
SNES NTSC 2/1/3 1CHIP | serial number UN318588627


Top
 Profile  
 
PostPosted: Sun Jun 18, 2017 8:24 am 
Offline
User avatar

Joined: Sat Jan 03, 2015 5:58 pm
Posts: 367
Location: ...
In terms of text editors, I recommend Visual Studio Code or atom. I haven't been able to figure out how to make syntax highlighting for VS Code, but it's already there for Atom. Both of them have an integrated terminal which is very useful.

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.

HihiDanni wrote:
Be careful on the order of your includes, as you will likely need to introduce symbols before they are used

asm6 is a however-many pass assembler, so it doesn't have problems with forward-references.


Top
 Profile  
 
PostPosted: Sun Jun 18, 2017 10:01 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5718
Location: Canada
nicklausw wrote:
HihiDanni wrote:
Be careful on the order of your includes, as you will likely need to introduce symbols before they are used

asm6 is a however-many pass assembler, so it doesn't have problems with forward-references.

I think the only difference this makes in ca65 is with allocations on the zero-page.

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).


Top
 Profile  
 
PostPosted: Sun Jun 18, 2017 10:24 am 
Offline
User avatar

Joined: Tue Apr 05, 2016 5:25 pm
Posts: 121
rainwarrior wrote:
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...

_________________
SNES NTSC 2/1/3 1CHIP | serial number UN318588627


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Diskover and 9 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