Тёмный

Creating a Chip8 interpreter/emulator in C++14 

Bisqwit
Подписаться 147 тыс.
Просмотров 112 тыс.
50% 1

In this tool-assisted education video I create a #Chip8 interpreter in #C++14. We overview the architecture specification document and use that to create a working emulator. Some sample games are run.
Download: bisqwit.iki.fi/jutut/kuvat/pr...
Twitter: / realbisqwit
Patreon: / bisqwit (alternatives at iki.fi/bisqwit/donate.html)
Twitch: / realbisqwit
Homepage: iki.fi/bisqwit/
You can contribute subtitles/captions at: ru-vid.com_vid... Or to any video on my channel at:
ru-vid.com_cs_...
The desktop environment is Enlightenment for Linux.
The editor is a custom editor that only runs in DOS.
The music is from Kingyo Chuihou! Tobidase Game Gakuen, converted into OPL3 using the means described in this video: • SNES music through OPL...
You can download/listen to the song separately here: bisqwit.iki.fi/jutut/kuvat/pr...
NOTE: It's been brought to my attention that the document that I was reading has several misconceptions of the Chip8 architecture. Though I also read the Wikipedia article and a few other documents, there's a few things I missed. Here's a list of errors in my interpreter. Note that most of these "errors" have no practical bearing to executing pure chip8 programs, but are merely pedantic compatibility issues targeting the platform where the Chip-8 interpreter was originally released.
-- I and PC are 16-bit registers, not 12. That means that the "& 0xFFF" parts in my code should not be there, or should be replaced with "& 0xFFFF". This applies also to how the carry flag is handled in the "add I, Vx" instruction.
-- The memory map is 64 kilobytes, not 4 kilobytes. However, only the first 4 kilobytes are RAM. It is in fact possible to have more RAM (or less), from 2 to 32 kB. RAM is mirrored in the whole $0000-$7FFF range. A conforming implementation should perhaps use a 64-kilobyte array, and permit modifications only within the first 4 kilobytes. Ideally, part of the array should contain a verbatim copy of the Telmac 1800 ROM...
-- The built-in font should not be stored in the first 4 kilobytes, but within the "ROM", which is mapped at $8000-$81FF and probably mirrored throughout $8000-$FFFF. This memory should also be non-modifiable. See www.chip8.com/cosmacvip/VIP_Ma... for information about the exact location and layout.
-- The 12-element stack should be stored at the particular address of $0FA0-$0FCF (or in an equivalent address of whichever bank is the last RAM bank)
-- The 16 V registers should be stored at the particular addresses of $0FF0-$0FFF (same note as above).
-- The 256-byte display memory should be stored at $0E00-$0EFF (same note as above).
-- The timer registers and stack pointer should not be stored in RAM (the COSMAC VIP stores them in R8 and R2 registers respectively).
-- The "sys" instruction should do emulation of RCA 1802 (COSMAC). This is deliberately left out from almost all modern Chip8 interpreters, including mine. On a similar note, the "cls" and "ret" instructions (00E0 and 00EE respectively) should be implemented as RCA 1802 code pre-initialized in those RAM addresses, and treated as the "sys" instruction instead. But then you could just create a COSMAC #emulator and forget about Chip8, as it's just a program running within the first 256 bytes of RAM and utilizing the 512-byte ROM. More information: datasheets.chipdb.org/RCA/MPM-...

Наука

Опубликовано:

 

25 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 449   
@j5679
@j5679 7 лет назад
0:15 "I count maybe six videos" puts up fingers 00110 I see what you did there ;)
@oiSinCryo
@oiSinCryo 5 лет назад
Yeah, good thing it's not 4.
@clodgozon3968
@clodgozon3968 5 лет назад
ahh same. Clever
@Hyp3rborean
@Hyp3rborean 4 года назад
@@oiSinCryo lol
@gameraxel4388
@gameraxel4388 3 года назад
@@oiSinCryo 🤦
@Snugglelol
@Snugglelol 7 лет назад
Your channel makes me feel like im in the 80s
@hdhwkq
@hdhwkq 3 года назад
Exactly and the way he drees
@Bisqwit
@Bisqwit 3 года назад
The way I drees? [sic] For the record in this video I had my work clothes on (I was working as a bus driver).
@hdhwkq
@hdhwkq 3 года назад
@@Bisqwit wow that cool
@videogamehistorian
@videogamehistorian 8 лет назад
I'm no longer into CHIP-8 stuff but I like seeing that my original documentation has been improved. Reminds me the good old days when I wrote the first emulator under MS-DOS, which finally supported both CHIP-8 and Super CHIP. Was kind of a hassle to perfect emulation when, back in the day, few documentation existed. But that was a real challenge. Would be nice to see my Minesweeper and Space Invaders running under your well written port.
@segatendo4705
@segatendo4705 3 года назад
It’s the man himself! Hello, sir. Pleasure having the chance to get my message out to you. You’re quite a legend!
@leoferaderonugraha1930
@leoferaderonugraha1930 2 года назад
Thanks for the documentation, it was a great source for learning!
@samarth2126
@samarth2126 Год назад
Your documentation was amazing.. Thank you for your work : )
@Quaker763
@Quaker763 9 лет назад
Wow your English has gotten so much clearer!!! Keep up the good work, I love watching your videos!
@Bisqwit
@Bisqwit 9 лет назад
Quaker763 Thanks! Practice makes perfect, they say. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-vRqdjDmFUG4.html
@wicqedeyebot5631
@wicqedeyebot5631 5 лет назад
People like you are obsessed with criticizing someone's ability to speak English. The point is why don't you made one so everyone can judge your accent?
@froycardenas
@froycardenas 4 года назад
@@Bisqwit it seems they are not watching some Hindu English speaking videos... those are epics
@Bisqwit
@Bisqwit 9 лет назад
A reminder to everyone! (Looks like I have to say this separately for every video I upload.) If you ask questions in the comments, or if you want a reply for some other reason, _please_ *PLEASE* make sure your google+/youtube privacy settings do not prevent people from replying to what you post. If I don't see a "Reply" button right next to your comment, or when posting a comment the box grays out for a moment and returns back to editing without actually posting the comment, I _will not_ attempt to find an alternative way to reach you. More information: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-n_8umKxnxl0.html
@orsonpeters
@orsonpeters 9 лет назад
Bisqwit You did find an alternative way to reach me - through a video :)
@ConnorRentzz
@ConnorRentzz 9 лет назад
Make a program to automatically post this comment on every video :D
@guzman-do
@guzman-do 8 лет назад
+Bisqwit Can you make a MIPS I Emulator? it has a RISC instruction set and can run linux.. it will be nice
@Bisqwit
@Bisqwit 8 лет назад
+L.G. BookTranslator MIPS was one of those architectures that I was considering when I was planning to make a video about creating an emulator that can run Linux. I ended up choosing MicroBlaze. I looked at QEMU's MIPS emulation, and it looked too complex for me. However, now that you said MIPS *I*, it seems that the architecture has had several revisions, and the first revision is very simple indeed. However, the CPU is not _all_ that is necessary for an emulator. MIPS is just a standard for an instruction set. It says nothing about the rest of the computer. There's also the MMU, the IRQ controller, and all other peripherals. Do you have some particular platform in mind?
@guzman-do
@guzman-do 8 лет назад
Yes you are right. I meant to say the R2000 microprocessor which implements the MIPS I instruction set. It was the first implementation from MIPS Technologies and I believe it was the simplest CPU in the MIPS family, before all the subsequent extensions. In that CPU even the floating point unit (co-processor 1) was optional. If you find it interesting, maybe you could do a 2 part video. Part 2, the floating point unit, do it you think it worth it and not too much hassle, of course. I started doing research and I figured out the op-code values for decoding each instruction in that set, I can send you the values if you like. That would save you lots of time.
@mikaelmoizt
@mikaelmoizt 9 лет назад
Interesting, entertaining and inspiring. I find myself watching all your videos like a marathon every once in a while. Although I suck terribly in c/c++, it fascinates me. Keep up the good work.
@TheComputadude
@TheComputadude 9 лет назад
Your videos are awesome! Im always happy when I see one in my subscription box.
@ehguacho2008
@ehguacho2008 9 лет назад
a nice one! i've made one too. it was actually my second attempt in emulation, the first one was on the NES. congrats man, wonderful job!
@vvviiimmm
@vvviiimmm 9 лет назад
7:44 IMO Actually, this IS the most interesting part. I would really enjoy watching your thought process, seeing mistakes, redesigns, debugging, testing and so on, because thats what programming is about. But anyways, keep up the great work!
@Bisqwit
@Bisqwit 9 лет назад
lexvi The problem is it takes hours. Tens of hours. Including hours spent sleeping, because the most clever ideas come after sleeping a night. Minutes here and there spent just adjusting the indentation. I can't imagine a way to make such a process into an entertaining video. And you'd need to narrate everything. I don't think in language. Adding language into problem solving makes it a cumbersome process.
@psyjax2
@psyjax2 8 лет назад
Love your vids bisqwit! I have learned a lot about low-level programming from watching your vids. I think its awesome that you are like a total computer wizard and choose to drive a bus for a living, very zen ;)
@Bisqwit
@Bisqwit 8 лет назад
+psyjax2 Thanks :-)
@abusque
@abusque 9 лет назад
Hey Joel, thanks for the video, very interesting. The use of the union to represent the registers and memory, while rather simple, was quite clever and efficient. Looking forward to see more!
@Bisqwit
@Bisqwit 9 лет назад
Antoine Busque Using union is actually only necessary for the font (and even there you could just use a pointer to Mem). It's the "struct" that does the "representing" thing. However, union makes it possible to _overlap_ the physical storage of these, so that actual bytes within Mem[] are being used to store the values for registers -- something which probably no Chip8 program actually abuses, but they _could_ do so.
@videosyoutube718
@videosyoutube718 9 лет назад
Bisqwit you are pretty weird but i love you, you are a fucking master, ¿how did you learn to code like this?
@romainvincent7346
@romainvincent7346 5 лет назад
about what you say at 7:45. Watching someone think is boring yes, but watching someone like you explain their conclusion is very entertaining. I would love to see more videos explaining the "whys". Because I think it's the part where the beginner is lacking the most, and where the master has the most to teach.
@cosmicrdt
@cosmicrdt 9 лет назад
Hey Joel I always love seeing your newest videos. They keep getting better and better. I especially enjoy your personal intros and outros. I would love to see some more Tandy 1000 stuff if you have it. I used to own a Tandy 1000HX and still have font memories of it. Maybe you could write a Sierra AGI interpreter or similar.
@Bisqwit
@Bisqwit 9 лет назад
cosmicrdt Yeah, I still have the Tandy 1000; it's sitting not far from me as I type this message, lacking use. Unfortunately it's not a terribly exciting platform though -- and offers nothing that DOSBox doesn't these days. Add to that the difficulty of transferring programs from/to it (no networking, an unreliable diskette drive)... yeah. Basically its only merit is once in a blue moon to prove that something cool _runs_ on it. :-)
@luisgbm
@luisgbm 5 лет назад
I'm trying to write a CHIP-8 interpreter for browsers in JavaScript! Your video served as a great inspiration to me. Thank you!
@Cypryssss
@Cypryssss 8 лет назад
I recently started C++ programming and I love 3D! looking forward to more 3D rendering videos. Keep it up!
@brennosantos1777
@brennosantos1777 3 года назад
Shalom, bisqwit! I have been watched your videos since I started programming, and they are my biggest motivations to continue on It when the syntaxes errors make me feels impatient. It's a truth the phrase "programming isn't for impatiente persons", but with a litte bit of work we have the pleasure of seeings the good results! Now I am working in a programming language with its own byte code virtual machine (Just like Java, but Very simple) and I am trying to get inspirate wih your videos! I am from Brasil and my english may be a litte broken, but i give you now a sincerous hold and thanks you. Please don't stop! Haha, Just like a Brazilian would say: beijos de luz!
@Zyhorn
@Zyhorn 7 лет назад
Just regently found your channel and I love it! I subscribed right away and I hope you continue. Awesome work.
@seanpianka1818
@seanpianka1818 8 лет назад
This just makes me so happy to watch. Thank you so much for making these!
@deadalnix
@deadalnix 9 лет назад
Love it. There are a lot of small details to be learned from the way you code these things. Keep it comming :)
@gldev8191
@gldev8191 9 лет назад
This is incredible Joel, keep up making great videos. Thank you for all your hard work.
@KennetP
@KennetP 7 лет назад
Great video, Bisqwit. If you keep making videos, I'll sure watch! I am really a novice programmer but I get a lot of insight from watching your videos. Thanks!
@vittorioromeo1
@vittorioromeo1 9 лет назад
Fantastic work as always, you're an inspiration :)
@redchards
@redchards 9 лет назад
***** That's funny, the other day I stumbled into your FastFunc gist, the adaptation of the Don's Clugston delegate concept. Anyway, I find it funny that you're following bisqwit too :)
@MrSlashStudios
@MrSlashStudios 8 лет назад
I love your programming videos Bisqwit! I learn so much from them :)
@Bisqwit
@Bisqwit 8 лет назад
+MrSlashStudios Thank you very much!
@irateyourvideo2
@irateyourvideo2 9 лет назад
fascinating, as always. looking forward to your next project
@Sengeto
@Sengeto 9 лет назад
Love your intros, and your entire videos are very good as well
@radnyx_games
@radnyx_games 9 лет назад
Glad to see you posting more programming videos Joel!
@Alejandro213sk8
@Alejandro213sk8 6 лет назад
I love your programing an educational videos, keep up the excellent work .
@masterthie6622
@masterthie6622 9 лет назад
Love your videos, with this personally touch;) always fun to watch!
@mgetommy
@mgetommy 7 лет назад
holy crap you put so much work into this. amazing. good job!!!
@doncuco
@doncuco 8 лет назад
This is just amazing... Hope you keep making more videos.
@victornaut
@victornaut 9 лет назад
I neither have the time nor the experience to go this low level, but I still find this very motivational :) Thank you very much for sharing Joel.
@Eldanoth
@Eldanoth 7 лет назад
You are a genius! Big fan of you even if i haven't got any programming video on my channel
@spidermcgavenport8767
@spidermcgavenport8767 8 лет назад
Very impressive write up, very happy that the resources are available that a few year's back those diagrams and schematics would require reverse engineering now it's possible for it to be open source.
@testaajatestaaja7215
@testaajatestaaja7215 9 лет назад
Super interesting video - as always! Your videos actually inspired me to start writing a 6502 assembler of my own and a simple emulator (interpreter really) for it. Normally I'd probably have written that in C, but I decided to learn Rust while doing that instead. Rust is quite a nice language actually. It has both low and high level features and a really clever ownership based resource management mechanism. I won't be emulating hardware or anything fancy like that. Some very simple I/O will do. It's been a nice hobby project so far.
@Bisqwit
@Bisqwit 9 лет назад
Testaaja Testaaja Rust is also one of those languages that I plan to learn some day. I just need a good enough reason to start.
@Bisqwit
@Bisqwit 9 лет назад
***** Other than that it seems interesting, I have no experience-based opinion to share, considering I haven't actually _started_ learning it yet.
@Bri-Sci
@Bri-Sci 9 лет назад
This is a nice video because it gives me a little insight on what i would have to do for instruction interpreting. I wanted to make an emulation of a CPU i designed a while back just for fun and i now hope i can make a small emulation.
@InOtherNews1
@InOtherNews1 7 лет назад
I'm dying to know what that sneak peak video was! Can't wait for it to come out!
@oatbringer627
@oatbringer627 7 лет назад
Very enjoyable and informative video, keep up with the good work!
@Bisqwit
@Bisqwit 7 лет назад
I am glad if I was able to help!
@jullebulle8448
@jullebulle8448 8 лет назад
Great video! Thank you for making these!
@snokzor
@snokzor 9 лет назад
colour me impressed. btw,you put it so nicely "programming is not for the impatient man"
@yoimtv1945
@yoimtv1945 11 месяцев назад
this was the exact thing I was looking for. Thanks man
@Junior7setti
@Junior7setti 9 лет назад
Another amazing video. Im really excited to more
@halemm
@halemm 9 лет назад
wow you're amazing, great programming skills!
@side2sideful
@side2sideful 9 лет назад
New Bisqwit video! Yaaaaay! ^_^
@adilmalik7066
@adilmalik7066 8 лет назад
your amazing! please keep these videos up
@multicoloredwiz
@multicoloredwiz 9 лет назад
seeing this nice river of ducks next to a programming video brought me back to old tycoon games.. those guys always showed up in your lakes!
@KatzRool
@KatzRool 2 года назад
I really loved when you held up 110 fingers at 0:16
@lauretivan6231
@lauretivan6231 7 лет назад
i love your text editor !!! i'm also a DOS guy
@patinbsb
@patinbsb 9 лет назад
i appreciate the work you put into the videos, keep it up
@IsometricSandwiches
@IsometricSandwiches 3 года назад
I love your videos ... I just love them so much
@ZLau13
@ZLau13 9 лет назад
Interesting indeed, I think I should write an emulator :D Also please keep the computer graphics related videos coming!
@davidlukenyaguilarmoreira4764
@davidlukenyaguilarmoreira4764 5 лет назад
i use to see your videos, i think all your videos are very interesting, also i love the videos releated with videogames.
@davidlukenyaguilarmoreira4764
@davidlukenyaguilarmoreira4764 5 лет назад
i'm a computation engineer
@rexf5152
@rexf5152 5 лет назад
you're incredible, thanks for the videos!
@lufog
@lufog 5 лет назад
Thank you so much for such an interesting and useful video.
@MindLessWiz
@MindLessWiz 9 лет назад
Commenting to create motivation! That was great. :)
@iProgramInCpp
@iProgramInCpp 5 лет назад
*You are winner!* This might be a reference to Big Rigs.
@Zenas521
@Zenas521 6 лет назад
That was a good video. I see you are using more interesting camera techniques. The interpreter looked vary good. Here is an idea, Make a game system emulator with access to an external port that you plug game cartridges into. I like your videos.
@zeroclaw
@zeroclaw 7 лет назад
You know what? I will try to program my own Chip-8 emulator. Thank you for giving me something to do in my holidays! I thought I would die because of boredom...
@PandaMoniumHUN
@PandaMoniumHUN 9 лет назад
Amazing as always. I tried to write a Chip 8 emulator myself a few months ago but I got stuck/frustrated at the drawing OPcode and quit, later deleting the project. Maybe I should try again after my current project. :)
@TheProgrammer10
@TheProgrammer10 5 лет назад
it took me a good couple minutes see what was goin on with those macros. bravo (:
@hotchalupa
@hotchalupa 9 лет назад
We need more humans like you in this planet!
@someone2three
@someone2three 8 лет назад
Hello Bisqwit, love the video. Do you think you could elaborate a little bit on how you implemented the instruction set? I am not familiar with how you used the pre-processor to do that (ie. how you created that 'list'). Thanks!
@Bisqwit
@Bisqwit 8 лет назад
Each instruction is a bit pattern. Bit patterns are extracted with the >> and & operators. If you are not familiar with these operators and using them, study them first. The preprocessor technique I used is called "x-macro". You can read more about it here. en.wikipedia.org/wiki/X_Macro Experiment with this technique, and then use your mind to preprocess the source code you see on the screen at 5:51 in the video.
@viajantedotempoperdi
@viajantedotempoperdi 9 лет назад
Nice video! Thank you for inspiring me.
@jojodi
@jojodi 9 лет назад
Fantastic video as usual. A friend and I recently played Donkey Kong to completion on an NES emulator we wrote over the last week. Your videos were a great inspiration and help in understanding how emulation works and how to design some aspects of the system. I'd love to see more emulator stuff. (Maybe an 8080 or 65K? SNES Emulation sounds significantly more laborious though.) Do you have any experience on how to gather information for emulating a much newer or less well known system? When it comes to something like the NES, there is a ton of information to help, however, how do you think people should approach attempting to find information for a less-documented system? Any particular tricks/tips for reverse-engineering?
@spacecore3979
@spacecore3979 7 лет назад
awesome! i coded up a Chip8 "emulator" a few months ago. took me forever.. never got around to implementing keys or graphics. it merely ran a program and dumped the memory after it reached the end of its 4k memory.
@6mikaoP6
@6mikaoP6 9 лет назад
Awesome video!! Best chip8 explained video that I found. Could you make a video about dynamic recompilation? I searched a lot but I do not understand how it works and what are its pros/cons... Thanks!
@Bisqwit
@Bisqwit 9 лет назад
Raúl Peñacoba Veigas Not sure what specifically is the kind of dynamic recompilation you are interested in. It sounds like you've heard a buzzword, or it's a checkbox option in some particular brand of a commercial compiler. What I mean is there's multiple ways to go with that topic. Can you elaborate please? Basically I believe you are referring to JIT (just-in-time) translation where instructions or a function is compiled into machine-language code on the system that the program runs _while_ the program is running (as opposed to compiling before shipping), and then executing that machine-language code that runs a lot faster than the interpreter would. Compiling takes time however, and if the time of compilation + time of running is greater than the time of interpreting, the compilation is not worth-while. In addition, there are a number of situations where the compilation can not be done or requires extraordinary attention, such as self-modifying code, code that uses parts of instructions as new instructions, code that reinterprets data as instructions, and so on.
@wilbercastaneda2839
@wilbercastaneda2839 4 года назад
I have been looking a lot of your videos. I'm amazed by your mastery of programming, low level systems, and logic. I wanted to ask you how can someone get into the world of low level systems when the tasks seems too daunting. Thank you very much! Hopefully this question hasn't been asked before.
@Bisqwit
@Bisqwit 4 года назад
Perhaps a book would help? Sorry I have no book recommendations. Anything I learned from books is quite obsolete, and I have been adding to it with practical experience.
@adruvitpandit5816
@adruvitpandit5816 Год назад
Google doesnt do a good job of notification i have never seen this video and i am seeing your channel for 10 Yrs.
@Bisqwit
@Bisqwit Год назад
I agree, I haven’t seen _any_ new upload notifications for a few years. So, I check this page many times in a day: ru-vid.comsubscriptions
@Plrang
@Plrang 8 лет назад
I almost made it, have some artifacts in apps you wrote for it, but I'm sure it's on my end.After that it will be 100% functional. Tx for the inspiration
@diverseprogrammer18
@diverseprogrammer18 5 лет назад
When I see this kind of video, I assume it's Bisqwit. So cool! Anyway, gotta study linear algebra.
@automedi
@automedi 5 лет назад
I love your videos !
@dfruk1
@dfruk1 9 лет назад
Nice job Bisqwit :)
@TTaylor
@TTaylor 9 лет назад
Love your videos and your accent
@LeandroSQ01
@LeandroSQ01 8 лет назад
I need to say this again... GREAT VIDEO!! I just watch this like 5 times... When you will post a new video ?
@pooyamz
@pooyamz 9 лет назад
Are you from this world ??! Like always very very good job.
@nialltownley1788
@nialltownley1788 6 лет назад
What is that thing you do with #define LIST_INSTRUCTIONS(o) etc. Is it like a map? How do you do it?
@LeandroSQ01
@LeandroSQ01 8 лет назад
Great video, i can't stop to watch !! please make a emulator of Z80 :)
@zrk1011network
@zrk1011network 9 лет назад
Nice video. I like your stuff,
@XaetaCore
@XaetaCore 9 лет назад
You are the best!
@horseradish843
@horseradish843 8 лет назад
I actually created a c++ chip8 emulator as one of my first c++ programs.
@horseradish843
@horseradish843 8 лет назад
Kishore G. Yes i had alot of experience with similar programming languages and i had done it in an another programming language before :).
@retrophylien
@retrophylien 9 лет назад
Dude you are amazing !!!
@oweindouard3790
@oweindouard3790 9 лет назад
I don't understand much of what I saw, but that was awesome.
@KishoreG2396
@KishoreG2396 4 года назад
In the lambda function defined in the spec.callback variable, what is the purpose of the unnamed void* parameter?
@Bisqwit
@Bisqwit 4 года назад
The callback variable expects a pointer to a function that accepts one void* parameter. It will pass the value of spec.userdata (which I didn’t assign) to that function. My design does not need this parameter, so I just ignore it - but I must still accept it, otherwise the code will not compile.
@xkazinx
@xkazinx 9 лет назад
You are such a great guy.
@teknastyk
@teknastyk 5 лет назад
you once said you were not so good at math but your programming videos look like that matrix backround #asciieverywhere xD ..keep up the good work
@izaac229
@izaac229 7 лет назад
Hello Bisqwit! Thanks to your channel, I've decided to have a go at emulation. I have a question though, may I ask why 0x100 is multiplied to the first byte of unsigned opcode? Thanks in advance :)
@Bisqwit
@Bisqwit 7 лет назад
You are referring to this line, right? unsigned opcode = Mem[PC & 0xFFF]*0x100 + Mem[(PC+1) & 0xFFF]; Imagine the opcode is a decimal number of two digits. Say, 35. The first digit is 3, and the second digit is 5. How do you get 35 from 3 and 5? Like this: 3*10+5. But here, the opcode is composed of two bytes (0x00-0xFF), not two digits (0-9). To compose a two-byte number from two bytes, you multiply the high-order byte by 0x100.
@k4b00m6
@k4b00m6 7 лет назад
I have question, I am always jumping programming languages and always don't know where to start, right now I am in the middle of C# and thinking of going to C++. I usually learn from books I have K&R for C, Visual C#2010 for C#, and C++ for Dummies. Idk what to do and also another question I would like to ask is how should I learn how to program? (Self teaching)
@alexplay3
@alexplay3 7 лет назад
Genius and eloquent
@BenicioDomi
@BenicioDomi 3 года назад
Very interesting video! New suscriber!
@WarpRulez
@WarpRulez 9 лет назад
There are many practical reasons why preprocessor macros in C++ are avoided, unless there's a very good reason to use them ('assert' being a quintessential example of the latter.) When you "call" a preprocessor macro, that's _one_ line of code from the compiler's point of view. That's fine if the implementation of the macro is one line long in source code, but the more lines it's split into, the more complicated it becomes to find and understand compiler errors about it (because they will all refer to that one single line, which doesn't correspond to how you wrote the macro in your source code). Compilers have become better at giving more meaningful error messages about macros, but it can still be confusing for longer ones. Of course there's also the problem that macros are not type-safe, which is always a big deal especially in C++. You can "call" a macro with any parameters, and then get all kinds of confusing error messages (or, in the worst cases, it might even compile but work incorrectly.) Then there's the classical problem with macros that you have to be careful when implementing them, as macro parameters do not work like function parameters. A classical type of example is like: #define MUL(a, b) a*b which is just wrong. There are myriads of other reasons as well (such as the fact that they can't be put into namespaces, etc.) That doesn't mean that macros are never useful or should be avoided like the plague. It's just that they should generally speaking not be too liberally used either, especially if an actual C++ implementation would work just as fine (if not even better).
@SianaGearz
@SianaGearz 9 лет назад
WarpRulez Macros not being type-safe as you say, or rather not being type-aware is pretty much the reason they're still used and useful, as a way to cut down on boilerplate or avoid textual code generators. The most important thing about macros is to avoid them cutting across the code and expanding in unexpected places, and if the author does so consistently, i'd say it's decent enough. And it's always a larger concern in big software than in toy software that fits in a few screens. I'm not sure how useful they were in this very case though.
@GrepGaming
@GrepGaming 8 лет назад
I am having issues with my Load function, using the same function as you, I am not getting into the for loop using any of your example binary files. Any idea what that could be?
@Bisqwit
@Bisqwit 8 лет назад
Have you verified that you are able to access the files? Make sure you haven't e.g. typoed the filename, or failed to escape windows-style backslashes.
@ConnorRentzz
@ConnorRentzz 8 лет назад
Hello, bisqwit! I know this is an old video and all but could you explain what the for(unsigned n: {0xblah blah }) does? I assume it sets n to each number consecutively?
@Bisqwit
@Bisqwit 8 лет назад
Yes, that's what it accomplishes. What it does is is construct a temporary std::initializer_list (en.cppreference.com/w/cpp/utility/initializer_list), and iterate through it using the C++11 range-based for-loop (en.cppreference.com/w/cpp/language/range-for).
@ConnorRentzz
@ConnorRentzz 8 лет назад
Thanks for the quick answer! Hope, you have a good one
@Hopkroft
@Hopkroft 9 лет назад
It's great that you found time for creating new video. Are you going to create new videos with explaining technology of rendering(Like Duke Nukem 3D)?
@Bisqwit
@Bisqwit 9 лет назад
Hopkroft I am going to return to that topic eventually, yes. Right now I'm struggling to create an algorithm to divide an arbitrary mesh (that represents walls) into a set of convex polygonal hulls...
@KishoreG2396
@KishoreG2396 4 года назад
The documentation says "The data should be stored in the interpreter area of Chip-8 memory (0x000 to 0x1FF). Below is a listing of each character's bytes, in binary and hexadecimal:" Which part of your code corresponds to this?
@Bisqwit
@Bisqwit 4 года назад
The four lines under “// Install the built-in font”.
@hwpoison
@hwpoison 5 лет назад
Que maestro, saludos desde Argentina
@Bisqwit
@Bisqwit 5 лет назад
Obrigado!
@BlackTrusty
@BlackTrusty 4 года назад
Hi ! I really like your videos. You shows stuffs in programming I don't usually see and that's really cool and interesting! I have a question. How did those lines work (in the ExecIns function) ? #define o(mnemonic,bits,test,ops) if(test) { ops; } else LIST_INSTRUCTIONS(o) {} #undef o I understand the "if" part, but what about the else part ? If the test is not correct, then the program will execute all the lines present in the LIST_INSTRUCTIONS macro ? It seems odd to me. Thanks again for your amazing work !
@Bisqwit
@Bisqwit 4 года назад
Your approach needs to be a bit different. Macros are text replacements. A #define will not execute any code, and not even interpret it. It just defines a text substitution pattern for the precompiler. Consider this example: #define LIST(xx) xx('H') xx('e') xx('l') xx('l') xx('o') This #define does not _do_ anything. It is just a text replacements definition, i.e. macro. It essentially says to the precompiler: “from now on, whenever you see LIST, followed by something in parentheses, replace that whole thing with the following thing, but at each spot where I say ‘xx’ put whatever was inside those parentheses.” It differs from function calls in that it literally just replaces text with another text, at compile-time, as if you had literally written the other thing, without care for syntax correctness or operator precedence. Now let’s continue and add to the code: void test() {   #define myfun(ch) printf("%c", ch);   LIST(myfun)   #undef myfun } When the precompiler sees this LIST(myfun) - on a non-# line - it knows that LIST is a macro, so it expands the macro as explained above, and gets:   myfun('H') myfun('e') myfun('l') myfun('l') myfun('o') But wait, myfun is also a macro, so for each of these five occurrences, the precompiler expands _that_ macro and gets:   printf("%c", 'H'); printf("%c", 'e'); printf("%c", 'l'); printf("%c", 'l'); printf("%c", 'o'); And only after these simple text-substitution steps performed by the precompiler, does the _actual_ compiler interpret the resulting code. What it compiles ends up being _literally as if_ you had written this: void test() {   printf("%c", 'H'); printf("%c", 'e'); printf("%c", 'l'); printf("%c", 'l'); printf("%c", 'o'); } Now follow this exact same procedure with that LIST_INSTRUCTIONS thing, and you will get the correct outcome. This double macro invocation technique has a name by the way. It is called “x macro”, and traces back to 1960s. en.wikipedia.org/wiki/X_Macro
@BlackTrusty
@BlackTrusty 4 года назад
@@Bisqwit How, thanks for the very instructive reply ! I understand now :)
@DonnysRealm
@DonnysRealm 9 лет назад
Chip8 was my first (sim/em)ulator
@gustavlouw3362
@gustavlouw3362 8 лет назад
BISQWIT! Your fans crave more. You've inspired me to write my own CHIP8.
@ConnorRentzz
@ConnorRentzz 8 лет назад
Just came back to this video and had another question. Would you mind explaining how this line works? p = Vx + Vy; VF = (p>>8); Vx = p; More specifically the "VF = (p>>8)" part. I'm wondering how shifting left (that's left shift right? Never properly learned C) gets you whether or not there has been a carry.
@Bisqwit
@Bisqwit 8 лет назад
The target register is 8 bits wide. If the result of addition does not fit in 8 bits, you will have nonzero result even when you shift out the low-order 8 bits. Think of base 10: Suppose we are adding one-digit values. If you add 4+5, the result is 9. Just one digit. If you add 7+9, you get 16. Two digits. There is carry. In base 2, when you add 11010000 and 00000010, you get 11010010. It fits in 8 bits. No carry. If you add 11010000 and 01000000, you get 100010000. This number is 9 bits wide. If you discard the rightside 8 bits (with >>8), you get 1. This is the carry.
@ConnorRentzz
@ConnorRentzz 8 лет назад
Thanks for the great explanation and fantastic videos, Bisqwit. Eagerly awaiting your next video.
@MichaelLucasSmith
@MichaelLucasSmith 9 лет назад
Nice work.
@tomhijkl
@tomhijkl 7 лет назад
Hi Bisqwit, can you please explain the LIST_INSTRUCTIONS(o) define, I don't understand it. It looks like a function that takes parameter "o" and calls functions "o"(function arguments).
@Bisqwit
@Bisqwit 7 лет назад
Check out en.wikipedia.org/wiki/X_Macro. This is a little known technique in C preprocessor. Example: #define SOMELIST(callback) callback(1,2) callback(3,4) callback(5,6) callback(7,8) #define o(first,second) printf("%d %d ", first, second); SOMELIST(o) #undef o This first expands to: o(1,2) o(3,4) o(5,6) o(7,8) Which expands to: printf("%d %d ", 1, 2); printf("%d %d ", 3, 4); printf("%d %d ", 5, 6); printf("%d %d ", 7, 8); I use this pattern often. It helps avoid having to repeat information in a program, such as names and values used in an enum and later in a switch-case.
@tomhijkl
@tomhijkl 7 лет назад
Thank you for teaching me a new thing :D
Далее
Making a Chip-8 Emulator
9:18
Просмотров 12 тыс.
Новые iPhone 16 и 16 Pro Max
00:42
Просмотров 685 тыс.
Выпускаем трек? #iribaby
00:14
Просмотров 431 тыс.
I designed my own 8-bit computer just to play PONG
17:19
What are EXE files made of?
11:00
Просмотров 144 тыс.
Malware Development: Processes, Threads, and Handles
31:29
Emulation - Computerphile
22:36
Просмотров 201 тыс.
Writing a Really Tiny RISC-V Emulator
19:59
Просмотров 59 тыс.
Cheap Risc-V Supercluster for $2 (DIY, CH32V003)
9:02
Просмотров 246 тыс.
Making A chip8 Emulator in C!
5:56
Просмотров 8 тыс.
New Recipe for Pi - Numberphile
14:29
Просмотров 298 тыс.
CHIP-8 Emulator p1: Intro & Window Setup (C / SDL2)
1:21:04
How to Soldering wire in Factory ?
0:10
Просмотров 3,2 млн
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
Просмотров 73 тыс.