6502 emulator in FB

General discussion for topics related to the FreeBASIC project or its community.
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

6502 emulator in FB

Post by squall4226 »

My new project. My head is spinning already. First of all I don't want to hear anyone give me the business for writing an emulator in a language other than C. C is great. Maybe for you. Maybe not for me. I know it, I took two courses in it and I just don't like it. Moving on.

Why? Fun, of course! To learn!
How? I've been studying the heck out of the 6502 architecture and emulator writing tutorials.
Previous knowledge? Well I've USED emulators all my life. I did just a tiny bit of work on a couple of patches for PCSX2 but those were more hacks than anything else. So my starting knowledge is probably 3/10.
Where? Here of course!
When? Uhm... no idea. Working on it now. All depends on what craziness happens in my life.
Hope to show you something within a few days!
Stonemonkey
Posts: 649
Joined: Jun 09, 2005 0:08

Re: 6502 emulator in FB

Post by Stonemonkey »

Cool, emulation of any particular machine?

I occasionally mess around with some asm on an electron emulator.
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: 6502 emulator in FB

Post by squall4226 »

IF and that's an if as big as this page, I can get the core 6502 to be nice then maybe... NES... maybe... lol. confidence=0 but then again I never had any confidence to do my other projects. And I did them. It's been a while since I wrote real code so getting back into it with this project is a big leap. I've always wanted to though. Enough time... and patience... and maybe it will explode. Lol.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 6502 emulator in FB

Post by D.J.Peters »

For learning purpose one 6510/02 emulator. c64.bas

Joshy
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: 6502 emulator in FB

Post by squall4226 »

Thank you very much! I was wishing for a reference like that~
Stonemonkey
Posts: 649
Joined: Jun 09, 2005 0:08

Re: 6502 emulator in FB

Post by Stonemonkey »

Nice Joshy, have you run any games on it?
tinram
Posts: 89
Joined: Nov 30, 2006 13:35
Location: UK

Re: 6502 emulator in FB

Post by tinram »

These 6502 emulators may be useful:
http://skilldrick.github.com/easy6502/
http://e-tradition.net/bytes/6502/
http://6502.org/tools/emu/

The best online emulator I used was http://6502asm.com, but unfortunately the domain seems expired.
Wayback confirms this: http://wayback.archive.org/web/*/6502asm.com
At least some of the source code is available through Wayback.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 6502 emulator in FB

Post by D.J.Peters »

@tinram
you are right the FreeBASIC version is too clever for you.. :lol:

Joshy
Last edited by D.J.Peters on Jan 09, 2013 17:44, edited 1 time in total.
tinram
Posts: 89
Joined: Nov 30, 2006 13:35
Location: UK

Re: 6502 emulator in FB

Post by tinram »

@Joshy

Yes, the brain I was given falls far short of yours (I've seen lots of your code, and respect it).

I know almost nothing about the Commodore 64, except the 'general view' that BASIC on it was bad enough that assembler was often preferred - hence, I guess why you might be suggesting your C64 emulator for learning 6502.

The 6502 links were reference suggestions, simpler, but perhaps a bit purer than going through a C64 emulator.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Re: 6502 emulator in FB

Post by AGS »

squall4226 wrote:My new project. My head is spinning already. First of all I don't want to hear anyone give me the business for writing an emulator in a language other than C. C is great. Maybe for you. Maybe not for me. I know it, I took two courses in it and I just don't like it. Moving on.
'To give someone the business'. Never heard that expression before (I am not from the US of A, GB etc...).
Anyway, great to see another interpreter/compiler related project. There can never be enough of those
kind of projects. Hope you come up with some beautiful code.

Aside: I preferred programming in assembler on the C64. BASIC was great but the raw speed I got by
using assembler was better (favourite instruction: NOP :) ).
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: 6502 emulator in FB

Post by squall4226 »

To "give someone the business" basically means to criticize them. I.e. in the case above it would be saying "It's stupid to write an emulator in any language but C. BASIC is useless for..." blah blah blah.

On topic, a lot has been going on in my life. I haven't gotten much done on this project except studying D.J. Peters' code. I've written the basic skeleton for all the instructions (LDA, LSR, etc) and some memory related code.
Hope you come up with some beautiful code.
Beauty is in the eye of the beholder... hehe. Honestly I had gotten to where I was writing some pretty elegant stuff a couple of years ago. Especially after I took a college course called "Logic and Design in Programming" which taught me a lot about writing better, more organized, more readable code. Like in my RPG engine, it says in the source code itself that the code within ranges from hackish beginner stuff to very well written advanced stuff. The reason is that was my first major project and I started pretty much as a newbie, but worked on it for two years and got better and better. I don't expect my code to go back to the "hackish" level, but I do expect it will take me a bit to get back in the game.
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: 6502 emulator in FB

Post by squall4226 »

Yeah it's been over a year but I recently picked up the project again and it's actually going somewhere this time! I've even emulated a small program correctly. I've gotten really interested in emulation again since becoming a moderator on the PCSX2 forums. My thread about this project there is:

http://forums.pcsx2.net/Thread-My-6502- ... an-NES-emu

My most recent update I posted was:
Well despite the flu I have I finished all the opcodes that only operate in implied mode today. So:

BRK, CLC, CLD, CLI, CLV, DEX, DEY, INX, INY, NOP, PHA, PHP, PLA, PLP, RTI, RTS, SEC, SED, SEI, TAX, TAY, TXA, TYA

In addition, AND, ADC, STA, LDA are done for certain address modes.

I find myself actually scared. Normally when I write a program I can check its progress rather often to make sure I'm not screwing it up, but a lot of this is "hope I did it right." I'm sure I made some errors here and there, I'm just afraid I will get to the end and have something completely unworkable or wacky that can't be fixed. I will seriously be crushed if that happens, and probably give up programming for good. I know that seems a bit extreme, but I really don't have any confidence in my code, despite some of the things I've written(media player, RPG engine, etc). Anyway I'm feeling wicked sick from the flu now so I'm going back to bed.

Edit: oh I also implemented the stack today.

So yeah, this may just happen after all. I'm excited. Stay tuned!
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: 6502 emulator in FB

Post by marcov »

tinram wrote:
I know almost nothing about the Commodore 64, except the 'general view' that BASIC on it was bad enough that assembler was often preferred - hence, I guess why you might be suggesting your C64 emulator for learning 6502.
The BASIC itself was not that bad (maybe a tad slow and memoryhungry), the problem was more that it never was extended for any form of graphics or sound. Not even changing the colour of the PRINTed text or a BEEP command, let alone graphics mode and 3 voice polyphonic music. Only POKE and PEEK to write/read memory addresses.

That being said, I rarely made purely assembler programs, other that for demo compo's. To just _do_ things it was often more constructive to use the basic to script the asm together.
squall4226
Posts: 284
Joined: Dec 21, 2008 15:08
Contact:

Re: 6502 emulator in FB

Post by squall4226 »

Well, despite being even sicker I made some progress. I did some modularization, wrote some code to allow me to step through the program and view the processor status after each opcode, wrote some of the addressing modes, wrote a few small homebrews to test that things were working right, and I mean really small, stuff like:

LDA #$FA
AND #$44

Just to check each opcode I've finished so far produces correct output. So far so good. I was hoping to finish all the addressing mode stuff tonight, but my fever is 103F and my brain is no longer thinking well, so I had to stop. Sucks being sick. Still, this time I am chest deep in this project and it's gonna happen come hell or high water!

I need to think of a name for it!
tinram
Posts: 89
Joined: Nov 30, 2006 13:35
Location: UK

Re: 6502 emulator in FB

Post by tinram »

@marcov
Thanks, that's good clarification on the C64.
And is starting to refresh my memory.

@squall4226
Hope you get better soon.
Your project sounds promising.
Post Reply