(Yet Another) 6502 emulator in C

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
Post Reply
User avatar
DavidBuchanan
Posts: 26
Joined: 04 May 2015
Location: UK

(Yet Another) 6502 emulator in C

Post by DavidBuchanan »

Here it is: https://github.com/DavidBuchanan314/6502-emu

Nothing special, but it's completely free of macros which I personally find hard to read.

I started this project so I could debug programs for my SBC more easily, so it has the same hardware (so far only the 6850 UART is actually implemented).

I also plan to implement the GDB protocol, for debugging purposes.

I haven't implemented Decimal mode yet, but ehBasic apparently runs fine without that.

Edit: Adjusted README wording to avoid sounding over-confident :)
Last edited by DavidBuchanan on Tue Jan 03, 2017 9:31 pm, edited 2 times in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: (Yet Another) 6502 emulator in C

Post by BigEd »

Well done! I see you describe it as bug-free(!) - does that mean you've passed Klaus' test suite? Or maybe a different test suite?
User avatar
Arlet
Posts: 2353
Joined: 16 Nov 2010
Location: Gouda, The Netherlands
Contact:

Re: (Yet Another) 6502 emulator in C

Post by Arlet »

BigEd wrote:
I see you describe it as bug-free(!)
It looks like memory doesn't wrap around.
User avatar
DavidBuchanan
Posts: 26
Joined: 04 May 2015
Location: UK

Re: (Yet Another) 6502 emulator in C

Post by DavidBuchanan »

BigEd wrote:
Well done! I see you describe it as bug-free(!) - does that mean you've passed Klaus' test suite? Or maybe a different test suite?
Perhaps my wording was too ambiguous, the "relatively" part was also meant to refer to the bugs :lol:

But yes, I have tested it with Klaus's tests, up to the part where it tries (and fails) to run the decimal mode tests.
User avatar
DavidBuchanan
Posts: 26
Joined: 04 May 2015
Location: UK

Re: (Yet Another) 6502 emulator in C

Post by DavidBuchanan »

Arlet wrote:
BigEd wrote:
I see you describe it as bug-free(!)
It looks like memory doesn't wrap around.
Could you point to where? I tried to always access withthe index as a uint16_t (which inherently wraps), or with "& 0xFFFF" when addition is involved.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: (Yet Another) 6502 emulator in C

Post by barrym95838 »

ehBasic's HEX$() will malfunction without a proper decimal mode, but that's a very minor issue.

Mike B.

P.S. You are certainly welcome to use my BCD patches, with my blessing.

viewtopic.php?f=2&t=2052&p=37758&hilit=chambers#p37758
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: (Yet Another) 6502 emulator in C

Post by BigEd »

>relatively
Ah! But glad to hear you've passed Klaus' tests - the decimal tests are last, so you can only fail those by passing all the previous ones.
User avatar
DavidBuchanan
Posts: 26
Joined: 04 May 2015
Location: UK

Re: (Yet Another) 6502 emulator in C

Post by DavidBuchanan »

DavidBuchanan wrote:
Arlet wrote:
BigEd wrote:
I see you describe it as bug-free(!)
It looks like memory doesn't wrap around.
Could you point to where? I tried to always access withthe index as a uint16_t (which inherently wraps), or with "& 0xFFFF" when addition is involved.
Ah, you were right. Some of my address-mode decoding functions didn't wrap. I think I've fixed them now.

Thanks for pointing that out.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: (Yet Another) 6502 emulator in C

Post by BigEd »

That's interesting - some cases not yet covered by Klaus' tests. Could you raise an issue perhaps?
https://github.com/Klaus2m5/6502_65C02_ ... sts/issues
(If not, perhaps I can)
User avatar
DavidBuchanan
Posts: 26
Joined: 04 May 2015
Location: UK

Re: (Yet Another) 6502 emulator in C

Post by DavidBuchanan »

BigEd wrote:
That's interesting - some cases not yet covered by Klaus' tests. Could you raise an issue perhaps?
https://github.com/Klaus2m5/6502_65C02_ ... sts/issues
(If not, perhaps I can)
The bugs I just fixed were fairly harmless, and would only have any effect if the program counter was in the interrupt vectors (so can't really be tested against).

However, my relative adressing also failed to wrap, but it didn't actually matter because the program counter is a uint16_t (so in practice the value is wrapped) - If it wasn't that could have caused some nasty issues, so perhaps it could be added to the tests.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: (Yet Another) 6502 emulator in C

Post by BigEd »

No harm in wrapping by using 16 bit types, I think.
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: (Yet Another) 6502 emulator in C

Post by whartung »

DavidBuchanan wrote:
I started this project so I could debug programs for my SBC more easily, so it has the same hardware (so far only the 6850 UART is actually implemented).
There's something about stepping through the CPU in your IDE that certainly can make debugging your code a lot easier.

The problem I had later on, though, when debugging the Forth I was porting, was simply the bugs were higher level, and debugging at the instruction level, much less even small within the CPU, simply became far too much detail. I had to do stuff at a higher level. Not quite debugging Forth in Forth, but closer to that. It's times like that when you want NEXT to be primitive.
Post Reply