6502.org http://forum.6502.org/ |
|
New Project: A New 65C02 Core (first try!) http://forum.6502.org/viewtopic.php?f=10&t=6855 |
Page 1 of 2 |
Author: | Jmstein7 [ Thu Nov 04, 2021 2:43 pm ] |
Post subject: | New Project: A New 65C02 Core (first try!) |
https://github.com/jmstein7/65c02_core Hey, all! I'm trying my hand at a new FPGA implementation of the 65C02 ISA as an exercise in processor design, and I figured I'd share my progress here. Thus far, I've implemented all the structures and connections set forth on figure 2-1, page seven, of the WDC Data Sheet (Internal Architecture Block Diagram). And I've run all the control signals to the Instruction Decoder. However, the ALU function, and the ISA, has not been implemented yet (because I haven't yet decided the best way to go about it. Maybe microcode?) Like I said, this is the first time I've tried my hand at processor core design. Anyhow, feel free to have a look and, if you like, to tinker with what's there so far! Any input is welcome. The top level of the design is "processor wrapper". Right now it's for the Artix-7, with a stand-in CMOD A7 target, but that is subject to change. Best, Jon Github: https://github.com/jmstein7/65c02_core PS I've been working on this for a week, so it wouldn't hurt to have some fresh eyes on it, to boot. |
Author: | MicroCoreLabs [ Thu Nov 04, 2021 11:12 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Good luck on your new FPGA project! If you decide to go the microsequencer route you could look over my code for some ideas: https://github.com/MicroCoreLabs/Projects/tree/master/MCL65 |
Author: | Jmstein7 [ Fri Nov 05, 2021 2:07 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
MicroCoreLabs wrote: Good luck on your new FPGA project! If you decide to go the microsequencer route you could look over my code for some ideas: https://github.com/MicroCoreLabs/Projects/tree/master/MCL65 Ted, Thanks for the encouragement! Now that all the moving parts seem to be in place, I just need to figure out how to choreograph that movement I have to say, having tried this, I've so much respect for guys like you and others here who actually have completed entire cores. Jon |
Author: | Jmstein7 [ Sat Nov 06, 2021 7:45 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
I had some time to work on this, so I pushed the new material, and changes, to the repository: https://github.com/jmstein7/65c02_core/tree/main Jon PS Time to do the ALU! |
Author: | Proxy [ Sun Nov 07, 2021 11:06 am ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
good choice! the 65C02 is a pretty simple Processor, perfect for educational projects like these. I once made a 65C02 in a logic simulator called "Logisim Evo HC". though there is a very important detail that can make the whole project a lot easier (or harder depending on knowledge): do you aim for a prefect replica of the original hardware, down to the data paths and decoding logic? or do you just want something that is software compatible and is otherwise your own design? with my project i didn't want to replicate the exact inner workings of the CPU as i felt i would learn more by doing those things by myself from scratch. besides the Instruction set and pins on the virtual processor being identical to the real 65C02, almost everything on the inside is very different. I still use it to this day to test programs i would run on my real life SBC, as a logic simulator is a lot more in-depth and customizable than a regular emulator. you can take a look at my spaghetti if you want, maybe it gives you a few ideas for your own Processor. though be warned that i did not intent for anyone besides myself to look at it, so it might be hard to understand what is going on... either way, good luck with your project! Attachment:
|
Author: | Jmstein7 [ Sun Nov 07, 2021 2:01 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Proxy wrote: good choice! the 65C02 is a pretty simple Processor, perfect for educational projects like these. I once made a 65C02 in a logic simulator called "Logisim Evo HC". though there is a very important detail that can make the whole project a lot easier (or harder depending on knowledge): do you aim for a prefect replica of the original hardware, down to the data paths and decoding logic? or do you just want something that is software compatible and is otherwise your own design? with my project i didn't want to replicate the exact inner workings of the CPU as i felt i would learn more by doing those things by myself from scratch. besides the Instruction set and pins on the virtual processor being identical to the real 65C02, almost everything on the inside is very different. I still use it to this day to test programs i would run on my real life SBC, as a logic simulator is a lot more in-depth and customizable than a regular emulator. you can take a look at my spaghetti if you want, maybe it gives you a few ideas for your own Processor. though be warned that i did not intent for anyone besides myself to look at it, so it might be hard to understand what is going on... either way, good luck with your project! Attachment: 65C02 Logisim.zip One thing I would love to have is a simple way to figure the overflow flag on SBC. Jon |
Author: | barrym95838 [ Sun Nov 07, 2021 4:23 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Jmstein7 wrote: One thing I would love to have is a simple way to figure the overflow flag on SBC. Did you already figure it out for ADC? Correct me if I'm wrong, but there should be absolutely no difference between ADC ~operand and SBC operand, including the result and all flag effects. [I suppose the one caveat is that you need the nines complement instead of the ones complement if D is set, but in BCD mode V is a bit of a crapshoot anyway ...] |
Author: | Proxy [ Sun Nov 07, 2021 6:24 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Jmstein7 wrote: One thing I would love to have is a simple way to figure the overflow flag on SBC. Jon that is one i also struggled with, you can find it in my core, hidden deep inside the "ADDER" subcircuit. because you can switch between Binary and BCD mode my simulated core has 2 seperate Adder and Overflow circuits. with the bianry one i split the 8-bit Adder into 2 parts, a 7-bit Adder for the lower bits 0-6, and a 1-bit Adder for the upper 7th bit. the Carry output of the 7-bit Adder went directly to the Carry input of the 1-bit Adder, forming a complete 8-bit Adder while giving me access to the 6th bit Carry. you then take the Carry from both Adders and XOR them together, the output the Overflow flag. so basically, whenever the 6th bit overflows into the 7th bit, or the 7th overflows without the 6th overflowing as well, the Overflow bit gets set. Attachment: for BCD the whole circuit is a lot more complex. just talking about the Overflow flag though, i basically did: take bit 7 of Input A and XOR it with bit 7 of Input B take bit 7 of Input A and XOR it with bit 7 of the Output then take the output of both XOR's and NAND them together. the output of the NAND is the Overflow flag when BCD is enabled. honestly i couldn't tell you what is happening in that circuit, but it seems to work. BCD is weird. barrym95838 wrote: I suppose the one caveat is that you need the nines complement instead of the ones complement if D is set isn't the 65C02 using two's Complement in Bianry mode? |
Author: | Jmstein7 [ Sun Nov 07, 2021 6:26 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
barrym95838 wrote: Jmstein7 wrote: One thing I would love to have is a simple way to figure the overflow flag on SBC. Did you already figure it out for ADC? Correct me if I'm wrong, but there should be absolutely no difference between ADC ~operand and SBC operand, including the result and all flag effects. [I suppose the one caveat is that you need the nines complement instead of the ones complement if D is set, but in BCD mode V is a bit of a crapshoot anyway ...] Here is my rather sloppy solution for ADC: Code: /* Overflow V */ assign ova = a_register[7:7] + b_register[7:7]; assign ovb = a_register[6:6] + b_register[6:6]; assign ovv = ova[1:1]; assign ovf = ovb[1:1]; v_result <= (ovf ^ ovv); It has to be different for SBC , because you're effectively adding a negative number, right? |
Author: | Proxy [ Sun Nov 07, 2021 7:01 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
the circuit i've posted works for both ADC and SBC. both Addition and Subtraction use the same exact circuit, only difference is that when subtracting you invert all the bits of Input B (and in BCD Mode you do 9's Complement). that's the reason you have to clear the Carry flag when doing Addition, but set it when doing Subtraction. so barry was right, it is applying 1's Complement in Binary mode, if the 6502 used 2's Complement you would need to clear the Carry flag for Subtraction as well. |
Author: | Jmstein7 [ Sun Nov 07, 2021 7:46 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Proxy wrote: the circuit i've posted works for both ADC and SBC. both Addition and Subtraction use the same exact circuit, only difference is that when subtracting you invert all the bits of Input B (and in BCD Mode you do 9's Complement). that's the reason you have to clear the Carry flag when doing Addition, but set it when doing Subtraction. so barry was right, it is applying 1's Complement in Binary mode, if the 6502 used 2's Complement you would need to clear the Carry flag for Subtraction as well. So, for SBC, I just need to XOR the resulting Carry Bit with the "carry bit" of bit 6 (of the result)? |
Author: | Jmstein7 [ Mon Nov 08, 2021 5:47 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
I just pushed another update to GitHub - I finished writing the ALU over the weekend; now I'm going to test the heck out of it. Thanks for all the help with the V flag - I think I nailed it. Jonathan |
Author: | GARTHWILSON [ Mon Nov 08, 2021 8:16 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
Jmstein7 wrote: One thing I would love to have is a simple way to figure the overflow flag on SBC. For this and so many other parts of your project, you'll want to spend some time looking through the posts of forum member ttlworks. He has written extensively on 6502 chip design, ALU design, TTL 6502 design (this one too, and this one, and this one), also how the SID's innards work at the silicon level, VIC design, etc.. His 7-part ALU-design series is indexed at http://6502.org/users/dieter/ . You'll spend a lot of time going through it all, but it may save you a lot of time in the long run too. There's also this topic, "Overflow confusion with more links, and probably more if you search for "overflow" or "V flag" in topic titles. |
Author: | Jmstein7 [ Mon Nov 08, 2021 9:16 pm ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
GARTHWILSON wrote: Jmstein7 wrote: One thing I would love to have is a simple way to figure the overflow flag on SBC. For this and so many other parts of your project, you'll want to spend some time looking through the posts of forum member ttlworks. He has written extensively on 6502 chip design, ALU design, TTL 6502 design (this one too, and this one, and this one), also how the SID's innards work at the silicon level, VIC design, etc.. His 7-part ALU-design series is indexed at http://6502.org/users/dieter/ . You'll spend a lot of time going through it all, but it may save you a lot of time in the long run too. There's also this topic, "Overflow confusion with more links, and probably more if you search for "overflow" or "V flag" in topic titles. Thanks, Garth, that's great (and helpful) stuff!!!!!!! |
Author: | Jmstein7 [ Tue Nov 09, 2021 1:26 am ] |
Post subject: | Re: New Project: A New 65C02 Core (first try!) |
I had some time to work on this today, so I pushed another update. https://github.com/jmstein7/65c02_core It's time to program the op codes in! |
Page 1 of 2 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |