Let's Emulate a Real Computer from Scratch in C++ (250 Lines)

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024
  • I write a cycle exact real-time emulator for a real CPU system in C++ in about 250 lines of code and explain things along the way as good as I can. I am sure there are bugs or improvements to find. Please let me know if you have any suggestions.
    Minimal UART CPU: github.com/slu...

ความคิดเห็น • 46

  • @whoblue579beta3
    @whoblue579beta3 3 ปีที่แล้ว +30

    I will never see anything more underrated than this channel in my entire life. you were at 500 subs????!!!! soo small, I immediately subed and now its 501

    • @slu467
      @slu467  3 ปีที่แล้ว

      Whoblue579 Beta, you made my day, man! Thanks for tuning in, it's comments like your's that keep me motivated :-)

    • @BryanChance
      @BryanChance 2 ปีที่แล้ว

      Absolutely awesome

  • @AlanMedina314
    @AlanMedina314 3 ปีที่แล้ว +15

    I had no idea that you could simulate a basic cpu in C++ under 250 lines
    Thank You for showing me you can.
    This video is Fire.

    • @slu467
      @slu467  3 ปีที่แล้ว +5

      Hi Alan, glad I got you started here. Basically, the video shows how to implement your own design and have it running without building it on breadboards ;-)

    • @AlanMedina314
      @AlanMedina314 3 ปีที่แล้ว +2

      @@slu467
      I like that very much its basic yet the potential to add enhancements is through the roof.
      Unlike modeling it in verilog which is laborious at best.

  • @ithaca2076
    @ithaca2076 3 ปีที่แล้ว +5

    I love the pitter patter of your keyboard and especially the work you've done here! I plan on learning C++ since I've already learnt python, C#, and Rust. I love watching videos like these because I work a lot better with hardware, and being able to combine both worlds like this makes me learn so much better! Thank you :)

    • @slu467
      @slu467  3 ปีที่แล้ว +2

      Glad you like this stuff!

  • @alessiocaffi5992
    @alessiocaffi5992 3 ปีที่แล้ว +4

    Woo that is a truly compact code , well done and thanks for making this video (almost missed it). I gat to look into this now.

    • @slu467
      @slu467  3 ปีที่แล้ว +1

      Hope you enjoy it!

  • @amnesie6615
    @amnesie6615 3 ปีที่แล้ว +5

    Wow einfach großartig und lehrreich, auch wenn ich noch nicht so dermaßen viel davon verstehe!

    • @slu467
      @slu467  3 ปีที่แล้ว +3

      Danke! Es ist halt C++ :-)

  • @devjosh5580
    @devjosh5580 3 ปีที่แล้ว +3

    Emulating a cpu is a nice idea.. Im not that of a C++ guy, I'm more a java guy. But maybe I should try that out. Thanks for this exotic idea!

    • @slu467
      @slu467  3 ปีที่แล้ว +2

      Actually, before writing this in C++ I started with a version in Java (Processing actually). Works just as good :-)

    • @devjosh5580
      @devjosh5580 3 ปีที่แล้ว +2

      @@slu467 Gut, dann dürfte das ja nicht so schwer sein. :)

    • @cambrown5777
      @cambrown5777 ปีที่แล้ว +2

      fun fact.... not as exotic as you might think! In both industry and academia, computer architects use software-simulated CPUs to test new optimization ideas and run experiments!

    • @brandonbinkley3936
      @brandonbinkley3936 6 หลายเดือนก่อน

      @@slu467 Any chance you could share your java code?

  • @tonym5857
    @tonym5857 2 หลายเดือนก่อน

    Great, thank you for sharing 👏💪👌

  • @richardbloemenkamp8532
    @richardbloemenkamp8532 3 ปีที่แล้ว +4

    I just compiled it in visual studio under win 10 on an old PC. I had to change some kbhit to _kbhit and the same for getch. Then when I run in release mode blocks works fine.

    • @slu467
      @slu467  3 ปีที่แล้ว +1

      Happy to hear that it's running on your end!

  • @Alexander_Gurov_RF
    @Alexander_Gurov_RF ปีที่แล้ว

    The "msys2" is a set of Unix utilities. But the compiler is called "MinGW". Yes, it is GCC based.

  • @hstrinzel
    @hstrinzel 2 หลายเดือนก่อน

    BRILLIANT TUTORIAL!

  • @레드스위치
    @레드스위치 7 หลายเดือนก่อน +1

    Thank you for your good contents, but how did you launch the console window that has big raster fonts (vintage 8x8 ASCII bitmap fonts)?

    • @slu467
      @slu467  7 หลายเดือนก่อน

      It is just a nice-looking TrueType I had downloaded. C64 style.

    • @레드스위치
      @레드스위치 7 หลายเดือนก่อน

      @@slu467 you mean "install .ttf and then add it to CMD using regedit"? thanks in advance

    • @레드스위치
      @레드스위치 7 หลายเดือนก่อน

      @@slu467 you mean "install .ttf and then set CMD using regedit?" thanks in advance

    • @slu467
      @slu467  7 หลายเดือนก่อน

      Just open the console and change the font. Its a menu option. No regedit required 😀

  • @Rand0081
    @Rand0081 3 ปีที่แล้ว +3

    I find awesome to emulate a CPU by coding the response of its components to the clock.
    But I am wondering if polymorphism and vectors of shared pointers are really needed, but that's just me, since the CPU architecture is fixed and well-known at compile time, I would instead code flat classes for each component, use a tuple instead of a vector, and iterate over it with some template magic. I would also suggest you to use Windows Terminal so you can avoid the start command and the SetConsoleMode, and just run the application in the same window.

    • @slu467
      @slu467  3 ปีที่แล้ว +1

      Thanks for diving into the idea, Rand0081, your suggestions are really appreciated. I am sure there are many (probably cleaner) ways of expressing this idea than the one I have used :-D Let me know if you build something yourself that follows your route! Cheers, slu4

  • @ducksonplays4190
    @ducksonplays4190 3 ปีที่แล้ว +1

    The link in the description goes to TH-cam studio of your channel not your actual channel page.

    • @slu467
      @slu467  3 ปีที่แล้ว

      Thanks for pointing me to that bug, have fixed it ;-)

  • @arkanjo7509
    @arkanjo7509 3 ปีที่แล้ว +1

    very cool

  • @FrostGamingHype
    @FrostGamingHype ปีที่แล้ว

    Its not showing reset

  • @ChandrashekarCN
    @ChandrashekarCN ปีที่แล้ว

    💖💖💖💖

  • @talkysassis
    @talkysassis 2 ปีที่แล้ว

    If you like to use g++, why not set up a WSL or a Docker to use it? As I remember, installing gcc on windows was a nightmare

    • @Alexander_Gurov_RF
      @Alexander_Gurov_RF ปีที่แล้ว

      The MinGW GCC port works fine under the Windows. What's the problems? The WSL is useful to compile Linux executables.

  • @scottpizzakingdom
    @scottpizzakingdom 2 ปีที่แล้ว

    7:50
    for later ig

  • @justal787
    @justal787 2 ปีที่แล้ว

    Is this pipelined?

    • @slu467
      @slu467  2 ปีที่แล้ว

      Nope, this design is deliberately as simple as possible. Cheers.

  • @DavidL-ii7yn
    @DavidL-ii7yn 10 หลายเดือนก่อน

    Interesting food for thought in there. I feel that you breezed over the microcode way too quickly.

  • @Lucretia9000
    @Lucretia9000 ปีที่แล้ว

    So you created your own CPU? This is a simulator not an emulator. The difference is in how similar you are making it to the hardware. Pretty sure emulators don't handle all the line transitions from 0 1.

  • @corinemilanib3779
    @corinemilanib3779 3 ปีที่แล้ว +1

    Woow woow 😍💋 💝💖❤️