Это видео недоступно.
Сожалеем об этом.
Write Your Own Emulator for Your Own CPU - Using a Raspberry Pi Pico
HTML-код
- Опубликовано: 17 авг 2024
- In previous videos I have talked about how CPUs work and machine code. I have also talked about how to design your own CPU instruction set, and how to write an assembler for that instruction set. Now it is time to emulate your CPU and run the code output by the assembler.
Design Your Own CPU Instruction Set: • Design Your Own CPU In...
Write Your Own Assembler for Your Own CPU: • Write Your Own Assembl...
How Does a CPU Work playlist: • How Does a CPU Work
Let Me Explain T-shirt: teespring.com/...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains
Makes me remember how back in the 80’s I wrote (in assembly) an emulator to fully emulate an Intel 8080 on a 6502 processor, on a homebrew small computer board. All this in 2kB of RAM, which was all I had. That board must still be around somewhere, although I have no clue anymore how to operate it.
Me and a buddy built a fully working RV32I core in a video game called Logic World :) ill be posting videos soon.
Sounds awesome, waiting for your video buddy🙈
@@parthpanchal3843 thank you! we are working on getting it to work on compiled rust code. But I think I'm going to release a video going over it's current state.
@@parthpanchal3843 video is out :)
Terrific. I’d love to see many more along this path. The multiple ICs with communicating functions sounds great. Also expansion of the CPU functions and even 1-, 2-, and 3-word instructions.
Emulating the metal!
RUclips should start a certification course now with the amount of good quality educational content it has
Ohh interesting, saving this to watch in the morning with a cup of tea.
About 15 years ago I wrote a 6502 emulator, set it going on an Acorn Electron ROM , traced it through, and ended up in a reset loop. I've tried to pick it up since but couldn't get inspired. Randomly this vid showed up on my feed and you may have triggered another attempt!
Great style, no nonsense clear presentation ,
+1 vote for multi IC project, and subbed!
Super cool idea! Look forward to see continuation of this video series!
Fantastic! Really useful design background as I study the 6502 and write my own emulator for it. Thank you.
Thanks for (another) fantastic video. I really hope it gets enough "attention" for it to be worthwhile Your efforts to keep on doing these more technical videos.
And personally I would really enjoy seeing this particular "series" being added to and expanded, You really have a knack for explaining and showing ALL the "working parts".
Best regards.
Professor this was and is great! Keep on keeping on with this avenue. So interesting. Tinkered with IBM 360 Assembler 40 years ago (80 col. punched cards and the ubiquitous Green Card). Refreshing all around.
Great project for kids to learn Assembler and how to debug a core dump.
comment for the algorithm this is ahead of my understanding but for some reason the youtube gods served this up to me before the other videos you mentioned. I still gained a chunk of info that made sense by 5mins30 - so bailing out now and when my brain has recovered I'll go and watch the initial ones, so that i've got a better chance when I watch this from the start again. Thanks for doing something interesting on youtube :)
Absolutely love these CPU designing, emulation, and implementation videos - got me sub'd looking forward to more
Me too!
Great work!, I was thinking that at 4 bucks and if we defined an emulation language/development envt., then the Pico could be used to emulate older chips by retro makers, or for chips that are more costly/not available now ( as long as the size is no an issue) with some emulation boards (easy pinouts for hookup).
Please make more of this series, maybe emulate a real CPU for retro use, one that supports an language that died because of no custom hardware at the time (forth, lisp, etc.), or a CPU that directly supports AI (I know much harder). I think a lot of folks have Picos, are way past the basics, and looking for something that will use the GPIO power to simulate other devices. Thanks Gary
I don't think this approach can emulate the hardware you suggested in real time. The pico runs its own instructions sequentially, and micropython creates another overhead with the interpreter and garbage collection, etc. On that many layers of overhead, even high level emulation will take significantly more processing that the pico may not be able to handle.
There are two approaches for what you want, one is to implement an emulator in something more accessible like webassembly, a great example is on archive.org where old games can be played online using emulator compiled to webassembly
Another would be FPGA which essentially morph into the gate arrangements in a hardware level and accurately emulate the behavior without latency
Since the old chips ran at just a few MHz, then the Pico could handle it easily. If Python proves to be too slow then the answer would be to use C.
@@harrytsang1501 Agree with you on micropython. I make an implementation of MIPS R2000 processor in FPGA but this processor is so simple that this is a waste of time. You can simulate this processor in the PICO with a transcompiler without problems, like many other pro emulators.
Thank you for this video, this popped up on my feed, I’ve been going through the others in the series and really liked the simplicity of how you’ve done your instructions (and even the nice simple way you worked out the label offsets in the assembler.)
I’ve been fumbling about trying to do this kind of thing myself, but these videos have got me inspired to have another go again. Thank you ☺️👍
Yes, definitely do that second one! I’m very interested to see how much can be done by ganging up several picos.
Fantastic! Brings back what i did in 1986. Asm+dasm level emu. Great work!
Funny, i didn't find any this hard or surprising, still i found the video ansolutely amazing! I just have never thought how easy it would be to do it. I imagined it being much harder.
Gary, thank you for opening my eyes to how I might build an emulator/virtual machine.
I only recently watched your other videos before this one, glad to see this one arrive and I've got a couple Pi Pico boards.
I like the idea of a single part per Pico to build up a system. It would be fun to build the same thing with Pi Pico that are longer boards then something dinky like the Pimoroni Tiny 2040, I can imagine a cool system mounted on a panel to make a working computer model ^_^
Definitely want to see the independent chips/bigger chips video!
Hey Gary, this is awesome! I'd bet much enjoy a video about a larger system!
Thanks!
Could be the start of a wonderful series - i'd enjoyed it!
I'm not typical; I do this sort of thing all the time (though not in Python).
There are two things I would suggest as improvements for your instruction set:
- opcode 0x00 should be either NOOP or HALT
- opcode 0xFF should be either HALT or NOOP
Why do you set the program counter to 0xFFFF on HALT? Wouldn't it be better to the program counter where it is when the instruction is encountered? Having started my assembly programming life on the PDP-11 where the PC automatically advanced by 2 for every instruction (see note, below), my custom instruction sets (and ISA interpreters) leave the PC pointing to the instruction (if any) following the HALT instruction.
Note: For those who argue, as some have in other forums, that the PDP-11 had both 16 and 32 bit instructions due to the immediate addressing modes, this isn't the case; The PDP-11 immediate mode (as in "MOV #65535., R0" to load 0xFFFF into register 0) is actually assembled as "MOV (PC)+, R0"; .word 65535.".
A video on separate devices / buses would be amazing!
Please do turn your Pi Pico into a “processor”. Learning how to control the pico’s I/O pins to operate within the confines of external timing would be very interesting.
Lord, this brings back memories. In the 70s a bunch of us wrote a PDP-11 emulator on an IBM 360. We implemented it in IBM 360 assembler (BAL... anyone old enough to remember the Yellow Cards?)). I remember the pain of the design and implementation and the pride when the &^*% thing finally worked.
Damn this is such an interesting video! Seriously great, Gary explains is a legend lol
In a moment of nostalgia, I decided to emulate a Motorola 6809 microprocessor using an Arduino Due. To keep with the moment I have built a front panel much like the Altair 8800. The electronics are coming along and I have the switch/LED hardware going. Just need to build the examine, deposit, etc switch board.
I used C++ to build the emulation and that seems to have worked out for me.
The IDE I am using is Visual Studio Code, very nice.
I realised that all my switches, LED's, etc are really a very slow DMA interface. Given that I can use the same hardware to reach memory, it's really a short jump to emulate any microprocessor, a job for another day. Having fun designing.
I think i'll try emulating a m68000. It had a fantastic instruction set 8 32-bit data registrers and 8 32-bit address registers which could be addressed directly, indirectly, directly with index and indirectly with indexes. Wow, it was a fantastic CPU.
And, the m68000 could multitask!
I teethed on a DEC PDP-8i, so for years I wanted to build something to emulate it. Somewhere around my junk box is an Intersil PDP-8x on a chip, but I never got around to using it. I bet these young whippersnappers would go crazy with a 12-bit CPU with only one register (the accumulator) and a whopping 4-k (that's 4 kilowords) of address space. (The one I used had 12k of core memory and block-switching in the software, and a 32k (not megs or gigs--KILOWORD) fixed-head hard drive--all with punched tape!)
Bragging about your humongous core and DF-32 :-) excellent
Ah, yes, the Intersil 6100 or 6120, which was effectively a PDP8e. At one time, you could buy an Ohio Scientific Challenger III with one of these along with a Z80 (or was it 8080) and a 6502. The more common version of the OSI C3 had a 6800 in place of the intersil chip.
One of the fun things about the PDP8 is that the peripheral controllers had their own instructions, so a PDP8 program would have both CPU instructions and I/O instructions in-line. I don't recall all the details anymore, but I do recall that it was difficult to write a portable program for the pdp8. The "DECMate" also used one of the Intersil chips for word processing (WPS8) and there was a VT76 (or was it VT78) which was effectively a VT52 with one of the intersil chips; I think it also ran WPS8 for local word processing and could also connect to a minicomputer over a serial line.
Imagine being able to turn the Pico into a Z80 processor: mount it on top of a 40 pin socket. the possibilities would be endless. Maybe someone's done this kind of thing already.
i would be interested in seeing option 2 of how to emulate the individual cpu components separately !
Nice and interesting video. I remember trying to multitask on the Arduino Uno, with a timer interrupt and some C code, and have also spent some time thinking about the tinyest CPU one can imagine, with a 1-bit ALU, using shift registers supplying data over a 1-bit data bus, spending 8,16,32 or whatever clockticks, to do an operation. :-) Unfortunately those shift registers probably require more gates than the ALU, and you need more of them, so there is no point other than for fun.
Thanks, much appreciated. You might be interested in my Piccolo OS videos on this channel.
How did you generate and display the .rom file in Hex?
I have toying with the idea of doing an IBM mainframe … S/370 generation… which, BTW, it was a collection of processors that were task specific… CPU, memory subsystem, channels for IO … all working together…
16 32 bit regs, 16 control regs, 31 bit addressing for memory, 16 channels,
Sounds like a cool idea. Maybe the Hercules S/370 emulator could be ported to the Pico!
I’ve been working on an assembler for my own 16-bit ISA. Still a work in progress tho… would like to look into emulating the ISA at some point.
so this is a fpga! yup! nice! this could also re-vive old cpus, 4 raw logic processing. right? super helpful vid.. reminds me of the land before cpu's, when
IC's roamed this land! and ate tape! ha..ha.. nice.. good luck with it!
Pi Pico is considered a low end computing device. Yet, it's at least 250 times faster, clock for clock, than a 6502 at 1 MHz.
@GaryExplains I am not able to download the "machine" module, please help.
Micropython for the Pico comes with that module built-in. So I am not sure what issue you are seeing exactly. You are running this on a Pico, no?
"LD destination, source" but "STL source, destination" - any reason for reversing? Why not just update the display when the video ram has been written to (destination address>=fbff)?
Man, plz put some speed tests on your other channel. We've been eagerly waiting.
The Pi Pico is an amazing value, but one of the things I miss the most vs. The Arduino world is the capacitive touch sense library. It saves me a lot of money, and a lot of extra wires/resistors to make my buttons out of simple metal push pins. Can we accomplish this with the Pico? Even if we have to use high value resistors, it would be nice to have. Thanks.
Does this help? forum.micropython.org/viewtopic.php?f=5&t=9829
@Gary Explains I think you have an off by one error. 0xfbff through 0xffff is actually 1025 bytes. Your video memory should start at 0xfc00 to only use 1K.
Probably, but it can still start at 0xfbff and only use 1k, it doesn't have to go to the end of memory 😜
But can it emulate the SuperFX? The historic SNES cart CPU.
why no speed test g yet with any snapdragon 8 gen 1, and dimensitiy 9000/8100t on your channel?
Is there a yacc or bison would emit python? I suppose that would defeat the educational thrust, or would it?
Interesting video. Just a question. Most applications handle one input/output pin at a time. How do you handle 8 in/output pins (full byte) at a time using (micro)python?
instead of the large if / elif /elif / (...) structure, you should use a function array
refreshing the display should probably be done when the memory mapped I/O corresponding to it is hit in write mode
LOL, no I shouldn't and I cover why I use the if/elif in the video. 🤦♂️
@@GaryExplains
Awesome!
why is the first few minutes of the vid is what i was thinking when i got a present from somebody i know that present was an arduino nano so i made a base that i can add a lot if instructions and stuff to
At 8:00, line 46 you have 65525 instead of 65535. Are the last 10 bytes reserved for something else?
No, it is a typo, it should be 65536.
Hi, I would like to see your Pico in the socket on a real computer board, working as a real CPU!
:-)
Many regards, Alexander
Impressive
Great video! I'm wondering why the mainmem is 65525 and not 65536?
typo ?
Oooopppps, well spotted that is a typo, I was aiming for 65535 and hit the 2 rather than the 3, but it should be 65536 as you say.
this is related to a video You released in 2018 how do you recover your Google account if you lost your keys!
Using YubiKey Security Keys to Protect Your Google Account (with U2F).??
For some real fun, how about writing a gcc backend for your CPU?
Hi professor, you forgot about your speed test g channel? We're waiting for new uploads special Samsung s22 series are released
LOL, I had an idea to do just this type of thing a few days ago. Nothing new under the sun, I guess....
Gary, 'would you give me your opinion on what you think of my project? My project is using the (RASPBERRY -- PI 4 or maybe, using the little Pi your talking about here in this Video to replace my Car Computer. I've been thinking about making a Clone or an Image of my Cars Computer, 'so I can Install (HYDROGEN GAS ON DEMAND). I'll be using Electronic Circuits and other components to produce the (Hydrogen Gas) without having to reprogram my Cars Computers, 'which I think, would be very Difficult to do considering today's Circuits and Chip programing Manufacturing processes of today. To reprogram an existing Cars Computer you'll need to know the How's, and Why's they used to do this and the Car or Truck Manufacturing will not Disclose this Information to me or anyone. The right to repair isn't there yet. I was hoping I could bypass all this by just making a Clone or a Image of the Cars Computer. Then just download all the Information to (RASPBERRY -- Pi) replacing the Car Computer. What would your opinion be? Thanks for the upload.
What does "reserved" really mean? Why are they "reserved" and not "not used" ?
"Not used" means that an engineer (hw or sw) can use them without worry. "Reserved" means you use them at your own peril as some day they will be used and then your hw/sw will break.
@@GaryExplains thanks for the clarification :)
Not only program an emulator inside you RPi Pico; also, add an assembler/compiler that takes a source code through serial port and returns the source assembled/compiled. Just like a GNU Bash text application, but connecting stdin and stdout to RPi Pico UART. Hahhahha, like a pile of really portable pocket apps inside a microcontroller...
Lots of elif - match case statements would be probably better...
I don't agree.
@@GaryExplains would you care to explain why not? Thank you for the video.
I don't agree because to a novice programmer if/elif makes a lot more sense than a match/case. Secondly match/case was only introduced in Pythion 3.10 (that is in 2021). So until recently Python didn't even have a switch/case construct. Also Python's match/case is quite controversial as it uses pattern matching. Not everyone is happy with it. Finally when teaching a concept ALWAYS go with the simplest code, it might not be the most elegant, but the simplest code is the easiest to understand.
@@GaryExplains I would argue that the switch-case construct should be more readable even to a novice - I am a Python novice :) But i agree that for backward compatibility its not good as it is a recent feature.
When learning programming do people learn "if" first or "switch-case"?
do something like HARDWARE ACCELERATED EMULATION exists? something like a emulation ASIC converting x86 codes to ARM in real time, with zero performance loss.
You can't convert anything with zero performance loss, you can't break the laws of physics.
🤘😎
Now you need to create the real cpu 😉
Yeah, that would be nice!
I don't get the point of the Pi Pico at all. There are plenty of micro processors of similar capability that offer excellent free toolchain support (Microchip PIC, STM32 etc). I can't understand why someone would waste time learning to use Pi Pico when there is real value (in terms of getting a job) by concentrating on mainstream devices that are no more difficult to use. I appreciate the full Pi fills a hole at the bottom end of application processor platforms but the release of this device does not. I think some newbies will set off learning this device and find they have wasted their efforts when they should be learning C or C++ of an industry standard microprocessor. Thanks for a great video, I do find it all interesting but the more I watch the more I don't understand why someone would use a Pi Pico over something else.
Maybe you should watch my Arduino vs Pico video.
You also might want to watch my videos on Piccolo OS. As you seem to think that the Pico doesn't use a standard tool chain or C/C++.
Why "noop" rather then the standard "nop"? If it works, why change it!
The beauty of designing your own stuff is that you can do it however you want. In your implementation you can do it however you wish
I know I’m being petty but you have a typo. 64K is 65535.
Yeah, and you are not the first to point it out 😜
dude 360p? Now where is my crt-screen, ive put it some where.........
Dude, I uploaded in HD, it looks like RUclips is behind in processing the HD version. I thought you would understand that.
no u r using pico so dont try emulate do pico lol
Congratulations for missing the point. 🎉🎉🎉
Thanks for (another) fantastic video. I really hope it gets enough "attention" for it to be worthwhile Your efforts to keep on doing these more technical videos.
And personally I would really enjoy seeing this particular "series" being added to and expanded, You really have a knack for explaining and showing ALL the "working parts".
Best regards.