6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 5:36 am

All times are UTC




Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: MCL65+
PostPosted: Tue Dec 29, 2020 8:53 pm 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
Hi,

I thought I would share a project that I am currently working on. It is called the MCL65+ and is a 6502 emulator running on a Teensy 4.1. The goal is to build a board which can be used as a drop-in replacement for the 6502 which can run both as cycle accurate and accelerated modes. The code is open-source and compiles using the Arduino IDE, and the board is inexpensive ($5 for quantity 10) and uses through-hole components. It was designed to be accessible to anyone to wants to create their own builds!

Here is my blog: https://microcorelabs.wordpress.com

Thanks,
-Ted Fried


Last edited by MicroCoreLabs on Tue Dec 29, 2020 11:48 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Dec 29, 2020 9:31 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Great! That's got everything... (I even have a Teensy, but not a 4.1, as yet.)


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Wed Dec 30, 2020 12:43 am 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
Well, it has some possibilities at least!

Thanks,
-Ted


Last edited by MicroCoreLabs on Thu Dec 31, 2020 7:53 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Wed Dec 30, 2020 10:06 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
One thing @revaldinho found with an earlier Teensy is that the I/Os are not wired up in a very nice grouping, so reading or writing the micro's bus takes some shifting and masking. That takes up clock cycles - but at 600MHz, possibly no problem at all. Maybe you can even stick to C code and still meet the deadlines... do let us know how you get on.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Fri Jan 01, 2021 1:08 am 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
The same seems to be true for the Teensy 4.x boards if you need to achieve a fast parallel bus... Performing sixteen address bit writes using digitalWriteFast() was not fast enough to make bus timing, so I ended up performing read-modify-writes directly to three of the CPU's GPIO registers. It was a bit more complex due to the pin assignments which I chose to optimize the board layout rather than optimal register/GPIO mapping.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Fri Jan 01, 2021 10:00 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Meeting timing at 1MHz - that's a milestone! Well done.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 7:14 am 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
The boards and components arrived, so I assembled one today, plugged it into my VIC20, and got some good results!

Here's the update on my blog: https://microcorelabs.wordpress.com/2021/01/05/ml65-initial-results-in-a-vic20/

I am happy to say that it's possible to both emulate a 6502 as well as its bus interface.. at least at 1Mhz!

Some fun next steps will be to use the Teensy's huge memory to expand the VIC20's RAM to the max and to import some cartridges.
It would also be amusing to execute code from some memory ranges which are not limited to the 6502's 1Mhz bus but run at the mirocontroller's 600Mhz clock speed!

Attachment:
20210104_222705.jpg
20210104_222705.jpg [ 3.03 MiB | Viewed 13826 times ]


I will upload the project to GitHub shortly.

Thanks,
-Ted


Last edited by MicroCoreLabs on Tue Jan 05, 2021 6:13 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 3:59 pm 
Offline

Joined: Fri Apr 06, 2018 4:20 pm
Posts: 94
Do you have any idea how fast you can push the emulated 6502 clock speed and maintain accuracy on the 6502 bus?

My guess would be about 4-5mhz, which is still very fast.

I think it would be interesting to modify this project to emulate the 6510 in the Commodore 64. The VIC can let the processor know when it is safe to run at full speed when drawing the screen borders.

https://sites.google.com/site/h2obsessi ... mhz-border

It should also trivial to simulate a GEORAM expansion with the internal RAM of the Teensy. The possibilities are exciting.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 4:03 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
(Is the 6502 model cycle accurate in the sense, say, that a taken branch will take 3 cycles?)


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 5:47 pm 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
Quote:
Do you have any idea how fast you can push the emulated 6502 clock speed and maintain accuracy on the 6502 bus?

My guess would be about 4-5mhz, which is still very fast.

I think it would be interesting to modify this project to emulate the 6510 in the Commodore 64. The VIC can let the processor know when it is safe to run at full speed when drawing the screen borders.

https://sites.google.com/site/h2obsessi ... mhz-border

It should also trivial to simulate a GEORAM expansion with the internal RAM of the Teensy. The possibilities are exciting.


The limiting factor is the clock to address propagation time because all 16 address lines cannot be generated simultaneously with the Teensy 4.1. Also, the address cannot be generated until the previous instruction has been decoded which adds to the propagation time. I think this would limit the bus speed to the 1-2Mhz range using an off-the-shelf Teensy.

I think this project could easily be ported to emulate a 6510. It would just require a different PCB pinout and support for the new signals. I chose the 6502 pinout because I have a VIC20 and an Apple II+ that I can try it on.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 6:07 pm 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
Quote:
(Is the 6502 model cycle accurate in the sense, say, that a taken branch will take 3 cycles?)


Yes I tried to make the MCL65+ cycle accurate and included the extra clocks, fetches, and double write-backs as well as most of the undocumented opcodes. It's all simple C code, so in theory it can be massaged into a cycle-exact emulator. (Will probably need this forum's help to achieve that!).

I need to upload the code to GitHub, but I have less then two hours of uptime and I want to clean it up before posting.

One challenge I encountered was that the simple 10 a=a+1, 20 print a, 30 goto 10 program randomly stops due to a "Syntax Error on line 10". The VIC20 does not crash, it simply stops the program with this error.. and it does so randomly... sometimes after 200 iterations.. sometimes 1000... If I just print "Hello World" in this tight loop it never fails...

I believe it is caused by the "math". (happens if I do a=a+1 or a=a-1), and possibly something related to the flags and/or the stack and interrupts... I suspect that while the code is running an interrupt occurs which pushes the flags recently generated by the math, but the flags are not restored correctly upon RTI... This is just a guess!


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 7:11 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Mmm, that's tricky. Dave/hoglet's 6502 protocol analyser might be of use - it reads a trace and models the 6502 behaviour. And then there's Klaus' test suite too, if you haven't already run that.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 8:44 pm 
Offline

Joined: Fri Apr 06, 2018 4:20 pm
Posts: 94
MicroCoreLabs wrote:

The limiting factor is the clock to address propagation time because all 16 address lines cannot be generated simultaneously with the Teensy 4.1. Also, the address cannot be generated until the previous instruction has been decoded which adds to the propagation time. I think this would limit the bus speed to the 1-2Mhz range using an off-the-shelf Teensy.

I think this project could easily be ported to emulate a 6510. It would just require a different PCB pinout and support for the new signals. I chose the 6502 pinout because I have a VIC20 and an Apple II+ that I can try it on.


I did not know that.


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 9:33 pm 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
Quote:
Mmm, that's tricky. Dave/hoglet's 6502 protocol analyser might be of use - it reads a trace and models the 6502 behaviour. And then there's Klaus' test suite too, if you haven't already run that.


Found it... In the interrupt processing routine I was pushing PCH and then (PCL-1)... When the (-1) causes a borrow I was pushing a bad PCH... :)


Top
 Profile  
Reply with quote  
 Post subject: Re: MCL65+
PostPosted: Tue Jan 05, 2021 10:01 pm 
Offline

Joined: Thu Oct 05, 2017 2:04 am
Posts: 62
I mirrored the 6502's address range from 0x2000 to 0x8000 in the MCL65+ to increase the computer's memory. While read and write cycles are generated on the 6502's bus, the data for this range is handled using an internal memory array.

Is 28159 the maximum that the VIC20 supports, or can the expansion range from 0x0400 be harvested as well?


Attachments:
20210105_134959.jpg
20210105_134959.jpg [ 3.25 MiB | Viewed 13796 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 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:  
cron