good dasm documentation?

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
mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

good dasm documentation?

Post by mreiland » Fri May 01, 2015 11:22 pm

I'm not that experienced with assembly programming and there seems to be so much conflicting information online that I never know what to believe.

Is there a good resource for dasm, meaning a listing of the directives, that sort of thing? I've seen references to some documentation, but I couldn't find it.

I recently discovered I needed to put a single space in front of opcodes in order for dasm to add them to the binary, but I'm unsure why. I found a reference somewhere that talked about directives needing to be indented, but I never found anything that stated opcodes do.

I'm sure that gives you an idea of just how ignorant I am, I'm finding the mishmash of information online to be overwhelming since a lot of it doesn't seem to apply.

I would love book recommendations as well, direct links with identifiers or whathave you are also welcome. I want to learn, but I'm finding it difficult to sift through all of the information available to glean what's relevant to what I'm doing specifically.


I did come across this, which I've been sifting through. I'm wondering just how much I can take away from it.

ftp://ftp.apple.asimov.net/pub/apple_II ... amming.pdf

I did notice on page 115 under section 9 it stated the CPU reads the opcodes, advances the PC to the *next opcode* and *then* executes the original opcode. That's a little different from how I've been implementing things.

Resources with explicit descriptions of that sort of thing would be invaluable to me.

mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

Re: good dasm documentation?

Post by mreiland » Sat May 02, 2015 3:42 am

Found something useful: http://www.nintendoage.com/forum/messag ... eadid=4440

I can't believe how long it took me to find that.

I'm still looking for more resources though if you guys have anything to add to it.

User avatar
Movax12
Posts: 529
Joined: Sun Jan 02, 2011 11:50 am

Re: good dasm documentation?

Post by Movax12 » Sat May 02, 2015 4:37 am

The link in your second post has information on how to use NESASM. The real question is why would you want to use dasm when there are better options available? Either asm6 or ca65 would be a good choice. (DASM is an actual assembler application. Sounds like you are just looking for information on assembly language?)

mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

Re: good dasm documentation?

Post by mreiland » Sat May 02, 2015 3:36 pm

I want to be able to start testing my CPU, and also be able to understand some of the other test suites out there. A lot of the information out there explains things I already understand such as addressing modes, etc, but don't really go into detail about 6502 asm dev.

Also, with tidbits that I mentioned earlier about exactly how and when the PC is incremented, that sort of knowledge will assist me in implementing things more accurately now rather than trying to figure out why it isn't working properly.

mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

Re: good dasm documentation?

Post by mreiland » Sat May 02, 2015 3:37 pm

And if you have a tool you think is better suited for my purposes, by all means, I just grabbed dasm because someone else stated that's what they've been using (successfully). I'm not too invested in the specific tool I'm using, I just want to be able to produce binaries myself from 6502 assembly.

User avatar
Movax12
Posts: 529
Joined: Sun Jan 02, 2011 11:50 am

Re: good dasm documentation?

Post by Movax12 » Sat May 02, 2015 5:39 pm

There are a number of members here that use asm6 and ca65 and maybe a few that use NESASM.
You would probably be able to find help if you choose one of them.

See: viewtopic.php?f=2&t=7274

User avatar
koitsu
Posts: 4218
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: good dasm documentation?

Post by koitsu » Sat May 02, 2015 6:35 pm

There are two subjects being repeatedly intermixed here, and I've been having trouble figuring out what exactly is truly needed/wanted by the OP, while having to make blind assumptions about experience level. Thus I'll cover both:

About assemblers:

asm6 will take you less time to get started + set up, i.e. you'll be spending more time writing actual code than you will be messing around with assembler directives, a linker, and a configuration template setup. Anyone who tells you otherwise is either unfamiliar with the ca65/cc65 suite or has spent so much time in it that they've forgotten how painful it can be when starting out. Do not let people tell you "here are some config templates" and link .zip files at you -- all these will do is confuse you even more. You want something bare-bones and minimal as possible so that you can get started doing what actually matters. asm6, or possibly NESASM3 (ugh), will let you do this.

You didn't disclose what operating system you're using. (It matters, as some of these tools are primarily available on Windows. For example, the best NES emulator debugger is in FCEUX for Windows only (this can greatly help you debug your own programs and step through them one instruction at a time), so people on OS X or Linux use Wine to run it.)

About learning 6502:

Covered here: http://wiki.nesdev.com/w/index.php/Prog ... _materials

And I would suggest getting the "Programming the 6502/65c02/65816" PDF (it does have mistakes/errors as a result of negligent OCR, but you'll just have to make do for now -- WDC is in the process of fixing those), as it will teach you about how the CPU actually behaves/operates. It does primarily focus on 65816, but if you pay close attention to the parts about 8-bit vs. 16-bit (the book does a good job clarifying this), and looking through the opcode tables to know which are only 6502 (the NES uses a 6502, not 65c02, and also lacks decimal mode (that is a NES-specific thing)), you should do okay. The original Lichty/Eyes book is by far the best material for describing clearly how the processors work.

You will find much material on 6502 online, scattered all over the place. Almost every resource I've looked at has mistakes of some kind.

So, if you combine all these resources, you should be able to make do.

Feel free to ask about 6502 behaviours/etc. in individual threads (separate threads) in the NESdev or NESemdev board/forum depending on if you're asking questions either regarding how the CPU works vs. how to implement something in an emulator.

Oh, and when you get to adc/sbc, you will certainly implement those incorrectly (most people do) or become confused. For that, see this post of mine with links to relevant information (and please READ those threads linked, not skim): viewtopic.php?p=119626#p119626

P.S. -- Can I ask why you're making a 6502 core? More specifically, is it intended to be used in a NES emulator you're making?

mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

Re: good dasm documentation?

Post by mreiland » Sun May 03, 2015 5:54 am

There are two subjects being repeatedly intermixed here, and I've been having trouble figuring out what exactly is truly needed/wanted by the OP, while having to make blind assumptions about experience level. Thus I'll cover both:
It's probably safe to assume I'm a dumbass :)

This will be a little involved, but it's so I can give you an idea of what I've been doing. The hope is that you can tell me where I've gone horrifically wrong.

Basically, I'm wanting to implement an NES Emulator for fun and I'm running into obstacles. I had gotten all of the 6502 opcodes implemented and wanted to start testing it before I started looking at the NES specific functionality. At that point I was using bvi to manually write the binaries that I was testing for, and running C code to poke at the CPU state to determine if it was running correctly. This is terrible for a multitude of reasons, not the least of which is that I can test that the core is doing what I expect it to be doing, but I don't know if my expectation is correct.

So I'm on a mission to find a good way to test the core. I've had nestest.nes recommended to me and I'll eventually get to using that, but even with that I need to be able to implement my own tests (maybe "need to" is a bit strong, but I feel a lot more comfortable if I can implement my own binaries and throw it at my emulator).

That led me to a recommendation of dasm, but I couldn't for the life of me get it to output anything. Eventually I realized I needed to put a space in front of the opcodes.

But I don't understand why. I dislike not understanding things. I've looked at the source for several different emulators and it seems like a lot of them get their inspiration from the same source, which isn't a bad thing, but I really don't want to blindly implement what I'm seeing in other emulators without understanding everything first. And I'm not accusing the other emulator writers of having done so, simply pointing out that I could choose that route and I'm trying to make sure I understand things before I implement them. For me this project is about learning and having fun, the working emulator part will come when it comes.

The challenges I'm facing are that

1. C and C++ are as low level as I typically get, so I'm new to developing in assembly to begin with.

2. A severe lack of tools (because I'm so ignorant of 6502)

3. I don't know enough to be able to sift through all the information online to determine what is and isn't relevant for me. You mentioned most online resources having mistakes. I'm too ignorant to be able to determine if things aren't working because the guide is wrong or I'm wrong, and it's causing me to mistrust everything and just all around making things harder for me.

4. I'm completely new to emulation dev so I don't really know what the best way to start is. In my head I figured implement a 6502 CPU, get it working fairly well, then start looking at adapting it for the specific NES use case. However, I'm starting to discover that getting memory access nailed down was probably a better approach (I initially assumed flat memory with no memory mapped address spaces, which I now realize is silly).

So there you have it, my life story :) Sorry for the long post.

I'm developing this in an Arch Linux VM using C++ and tup (for the build system). If I need to use FCEUX to debug my written assembly code it's not that difficult I have a file server available to both OS's I can use to make the source available to both.


And to be clear, I personally don't care what tools I use outside of insisting that I develop the emulator itself in Linux (it's for fun and I prefer that environment). NESASM, ca65, dasm, all a means to an end as far as I'm concerned. I just want to get the tools and workflow I need.

mreiland
Posts: 29
Joined: Wed Dec 17, 2014 3:28 am

Re: good dasm documentation?

Post by mreiland » Sun May 03, 2015 5:58 am

Also, if my post seems disjointed it's because I'm tired :)

I appreciate the resources you've mentioned here, I'll be coming back and looking further into them when I'm a little more coherent.

User avatar
koitsu
Posts: 4218
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: good dasm documentation?

Post by koitsu » Sun May 03, 2015 5:22 pm

There are several sets of "NES test ROMs" that various developers have written over the years, including ones for the CPU. They're listed here, as well as the link to github of a very large archive of all of them:

http://wiki.nesdev.com/w/index.php/Emulator_tests

Post Reply