6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat May 11, 2024 9:54 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Mon Mar 03, 2014 7:52 pm 
Offline

Joined: Mon Mar 03, 2014 7:19 pm
Posts: 7
I'm working on a 6502 emulation. Does anyone know where I can find detailed descriptions for each instruction? I'm interested in knowing what happens in each cycle for each instruction (fetch, execute, etc). If an instruction needs 3 cycles, I'd like to know what happens in each of them.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 03, 2014 8:32 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
They're in the excellent programming manual linked at the top of the page at http://6502.org/documents/datasheets/wdc/ and in the 65c02 and '816 data sheets linked there. These won't tell you what all the internal operations are, but they'll tell you what's on the bus in each cycle.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 03, 2014 9:23 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Also, you can run short test programs in visual6502, which will tell you what the NMOS 6502 does:
http://visual6502.org/JSSim/expert.html ... 03e9f3eaea

And, welcome!

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 9:41 pm 
Offline

Joined: Mon Mar 03, 2014 7:19 pm
Posts: 7
GARTHWILSON wrote:
They're in the excellent programming manual linked at the top of the page at http://6502.org/documents/datasheets/wdc/ and in the 65c02 and '816 data sheets linked there. These won't tell you what all the internal operations are, but they'll tell you what's on the bus in each cycle.

Thanks for this info. This programming manual is very helpful. It looks like it's quite difficult to program exactly what happens in each cycle. There are times when an instruction will be fetched, and the previous instruction is still executing in the same cycle. I learned this from this video on reverse engineering the 6502 (http://www.youtube.com/watch?v=fWqBmmPQP40).

My dilemma is what level of detail should I take my emulator to. I really just want to be able to execute a series of 6502 machine language instructions quickly. Any advice?


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 9:46 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Perhaps the question to answer first is, "What is the goal?" There are hundreds of 6502 simulators out there, yet I never use a simulator.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 9:52 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
I suggest start with a minimal goal, and extend it incrementally. Don't worry about cycle counts at first. In fact choose some subset of instructions and addressing modes and get them working first. Write, or find, a short 6502 program, and make it your aim to emulate that program,

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 4:01 am 
Offline

Joined: Mon Mar 03, 2014 7:19 pm
Posts: 7
GARTHWILSON wrote:
Perhaps the question to answer first is, "What is the goal?" There are hundreds of 6502 simulators out there, yet I never use a simulator.


My main goal is to have a 6502 simulation that can execute machine language instructions. Eventually, I would like to create a NES emulator using this program.

I'm really just doing this for fun because I love this stuff. It's also for my own enrichment. I appreciate all the great input.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 4:04 am 
Offline

Joined: Mon Mar 03, 2014 7:19 pm
Posts: 7
BigEd wrote:
I suggest start with a minimal goal, and extend it incrementally. Don't worry about cycle counts at first. In fact choose some subset of instructions and addressing modes and get them working first. Write, or find, a short 6502 program, and make it your aim to emulate that program,

Cheers
Ed


I will start my emulator like this. Thank you for the idea.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 4:52 am 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
BigEd wrote:
Write, or find, a short 6502 program, and make it your aim to emulate that program

That's how I wrote my emulators for a 16-bit minicomputer and a 32-bit minicomputer. Although I had some quite good documentation there were still undocumented parts (including for some instructions) so it was not entirely straight forward. I had some binary images of programs I wrote way back then which I tried to get running. So I implemented the first minor sets of instructions and worked on getting the setup of the CPU right w.r.t. to the executable image (mapping memory and loading the executable etc). Then I ran it with a disassembly trace until it found an unknown instruction and bailed out (I implemented the tracing disassembler iteratively at the same time). Add the missing instruction and retry. Had lots of fun. For the 32-bit system this was really the only way to see any progress in a reasonable timeframe, as it had more than a thousand instructions and 28 addressing modes (which I also implemented on a need-to-have basis).

So I started with small programs and got those to run, then I moved on to vendor-provided executables like program editors and compilers (I had some backup tapes which I managed to extract files from). I was pretty happy when I had the full-screen programmer's editor running! I spent a couple of vacations sitting all day in a cafeteria with documentation and computer. Could easily get into "the flow" that way. [I can see why so many authors write their books in coffee shops. There's coffee, and lunch, and quiet corners, none of your usual distractions and nobody to interrupt you.]

The good thing about this iterative approach is that the emulator actually does something from the very beginning. Along the way I implemented a debugger and a register trace feature, and improved the disassembler. This was also fun to work with: I had something fully functional which I could improve on when the emulators were still in their infancy.

Now, a 6502 is a much simpler architecture than what I worked on above so it's not directly comparable, still I would follow the same approach - and I will implement a 6502 emulator too one day, even though there are so many in existence already (unlike those I mentioned above. I'm only aware of two other efforts for the 16-bit one and as far as I know mine is the only emulator for the 32-bit one).

-Tor


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 7:10 am 
Offline

Joined: Thu Mar 03, 2011 5:56 pm
Posts: 277
Tor wrote:
BigEd wrote:
Write, or find, a short 6502 program, and make it your aim to emulate that program

That's how I wrote my emulators for a 16-bit minicomputer and a 32-bit minicomputer.


Would those be ND100/ND500, by any chance?


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 3:37 pm 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
Yes, that's correct (obvious from my location maybe).
[Edit: Longer description deleted so not to derail the thread]

-Tor


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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: