Comments (163)

If anyone is interested, we have a somewhat active subreddit called /r/EmuDev come check it out

Are you guys all emus or are other flightless birds welcome?

There's a few penguins, but they mostly keep to themselves

I refuse to believe Linux users are keeping quiet about it.

"I run arch btw"

Be very careful, emus are much more dangerous than they seem. If shit goes bad, find help at /r/emuwarflashbacks

Yeah, Dee Reynolds

Don't bother, that sub is 99% dolphins.

Cows are a stretch but I don't think anyone will notice

This had me cracking up like a crackhead

Thank you!

I wrote my own emulator for the DCPU-16 (fictional computer for 0x10^c), and it is a very fullfiling experience while still being fairly low-scope.

10/10, would write an emulator again.

Aww, now I'm sad again. RIP 0x10c.

Eli5 please?

Edit* woops I see that was a clickable link to Wikipedia which is written pretty eli5 ish. Sorry!

To save anyone a click: 0x10^c was a planned space sandbox game by Notch, the guy behind Minecraft. He created a spec for a fictional CPU that would have been in that game. The game has been shelved indefinitely, but several people have made emulators for the CPU anyway.

Notch truly is some kind of wizard, isn't he?

A grand wizard, going off his Twitter activity.

Anyone could do that. What makes notch shine is that he was financially successful and had the resources to invest in a project like that.

Yep, I too wrote 2 emulators for it. One for ComputerCraft (minecraft mod) and one lowlevel one for the Raspberry Pi (bare-metal, so you can make your own DCPU-16 Operating System) (still working oj it actually)

So sad that DCPU-16 Development is dead.

Is your RPi emulator available publicly? If it is I'd love to take a look, I have a spare Pi not doing anything...

DCPU-16 development is not dead, it's merely waiting for the right project/game to incorporate a DCPU-16.

not yet, i've just got basic emulation & display output working; I'll upload it soon though, somewhere @ github.com/ardera

Yeah, although I doubt the whole community will come back to life then.

So... You could write code for a virtual computer that's running inside a virtual computer that's running inside Minecraft on your physical computer?

Exactly ;)

It's virtualization all the way up!

Ultimately CS is all about ass loads of abstraction to do things

[deleted]

There is a llvm port that supports the DCPU-16, unfortunately it's stuck on version 3.2. I tried looking into updating it, and it's non-trivial because the whole codebase assumes 8-bit words, whereas the DCPU uses 16-bit words. The API also changed a lot since 3.2.

Awesome, I'm gonna read up on this. Thanks for sharing.

I wonder what kind of interest there is for something like this, I have a "gameboy emulator written in lisp (clojure)" project I was really into and never really considered finishing it and doing a write up on it (it started as a 'emulator in haskell' project, and really I suppose I could finish that version of it as well)

I've been interested in learning Haskell/functional programming, and even thought about making an emulator in it, but wouldn't it be really hard because of state-based emulators are? Isn't making an emulator in a FP language like trying to fit a square peg in a round hole?

Well Haskell handles state completely fine via the state monad

Not only that, but side effects galore. It strikes me as making a very challenging task extra hard tbqh.

Nah fam, I think it's one of the things Haskell would be brilliant at.

Nope! TBH I think Haskell would be a GREAT language for it.

Hey, so I'm currently taking my time trying to find the words to make a clear, detailed response to this. I am not fully sure if I will finish the response I want so I just wanted to go ahead of time and say; no, it has not felt awkward or painful in any way. The only part where things become inevitably impure and non-functional are 1. when , say, the cartridge is read (note, ONLY the part where it is read, the functions that actually interpret this read information are pure) 2. when graphics are displayed 3. when human input enters the system (but also note, that only the reading of that input; actually applying that input is still pure). The gameboy is represented by a big data structure (recursively made up of data structures to represent each sub component of the gameboy) , and its state changes the same way it would normally; by sending operations (functions) that change the state of the gameboy. The only real difference is that you are always explicit about which version of the gameboy you are talking about; after you update a gameboy, you are explicit about what you do with that specific updated gameboy, and likewise when you try to read the state of the gameboy, you are explicit about which you are reading. If fp truly lacked state, it would lack a program, its reality the opposite; a fp keeps track of state where imperative programming forgets about it and doesn't keep track of where its coming and going even though its probably getting drunk up-state with that hussey Becky who wears too much black makeup.

In an imperative game, if you compiled a list of every state changing operation that gets called throughout the program, it might look like:

player.hp -= 12

..

player.hp -= 12

player.strength *= 2

..

player.Move(1,1,1)
..

..

I usually hear the difference between this done imperatively or functionally is "imperatively, you will just alter a value, but functionally, you will return an entirely new being with its values slightly altered". If you are worried are performance, and are thinking about the lowest level (how much memory does this use? how fast is this, etc), then these two things are distinct are the former is superior. If you are speaking at the logical level, however, then there is no difference; to imperatively alter a value IS to return an entirely new version of the player, the only difference is the old version is thrown away and it is unclear who is using the new version. Because it is thrown away, you are never explicit about which version of the player you are using; if you say "num = player.hp" , which version of the player are we talking about? The hp of v.0.0, who was just created, or v.0.1, who was punched? The problem is "player" only says to you "the most up to date version of player".

In a program, data will go through a series of changes because different functions will take an old version of the data, produce a changed version, and return that to another function. With imperative programming, this does not change, what unfortunately changes is both input (where the old version of data came from) AND output (where the new version will go) is implicit and obfuscated.

If you are worried are performance, and are thinking about the lowest level (how much memory does this use? how fast is this, etc), then these two things are distinct are the former is superior.

Did you run into this problem when programming your gameboy emulators? Did you stop because of this or other reasons? Thank you for your write up, I appreciate it. Learning FP has been a tricky experience so far. I'm not good enough at it to write an emulator, but I will keep these kinds of concepts in mind when I write the FP chess engine that I have started to work on.

Are your emulators open source or do you have a github page? I'd love to check out some of your FP stuff.

Carmack found Wolf 3D easy enough to port to Haskell.

He ported a game, he didn't write a whole computer emulator.

Small thing... I like the font and the style of the page enough to actually want to use this to make an emulator. Small things like that go a long way.

This is how i feel about minimalistic and clean website opposed to bloated pages

http://motherfuckingwebsite.com

The pages are actually fucking .html files

That's where it got me too. Ended up reading through it for a solid hour and a half without even realizing it just because each section is so compact and digestible.

Never thought I'd want to, much less actually get around to, writing a fucking emulator of all things, but here we are.

Few ~~likes~~ upvotes... And gold?

It only takes one person.

Is it contagious?

cough

bless you

Thanks. For a second I thought I might have caught something.

Nope, only desperation.

Is desperation contagious?

On Reddit? Abso-fuckin-lutely!

Don't think so. Either it is not, or people around me are imunne to mine.

Do you feel cold and lost in desperation? You build up hope but failures all you've known. Remember all the sadness and frustation. And let it go, let it go.

Ha! Ha! /Nelson

!redditsilver

You must have a strong immune system. You only got a little silver.

You're supposed to cough after I've got your sack in my hand.

You just must tried to do that. Didn't you :D

The Midas touch.

It's like a fever of some kind.

Gotta be careful, don't want to catch it.

Probably not.

Maybe not for you

I accept my fate.

Can I get on the gold train too?

Even if I don't, there's a chance the next comment in the chain gets gold, and we all can laugh at my misfortune.

Best I can do is

!redditgarlic

Here's your Reddit Garlic, ePaint!

/u/ePaint has received garlic 1 time. (given by /u/haruhiism)

^I'm ^^a ^^^bot ^^^^for ^^^^questions ^^^^^contact ^^^^^/u/flying_wotsit

This is better than gold, imo

NO GOLD FOR YOU!!

"likes" ??? Upvotes.

r/unwantedfacebook

I'm so sad that this isn't a real subreddit

I had a comment in Ask Reddit on a different account that had 100 upvotes, gold and got me banned. I call it the trifecta.

What the hell did you post to get banned from Ask Reddit?

My political leanings are the opposite of most of Reddit. 3 words: "I'm with Her" as a sarcastic response to a question.

I think reddit's more on your side these days. See: /u/spez or /r/the_donald

This sounds really funny!

Got a link by any chance.....?

I got gold with one upvote once. lol

I feel like I’m the only person to never get gold on here.

Are you trying to get reddit gold? Because that's how you get reddit gold

Haha nah. I got over 1300 upvotes once. I think that’s my best accomplishment to date.

On a related note I do want to follow this guide. Working on getting back into programming. I was a programmer for a terrible company for 4 years and recently left. This seems like a decent project to get back into it with.

One of my comments on r/dayz has negative votes and 2 golds haha, I was so surprised

If I may plug my own series on writing an emulator, while we're here: http://imrannazar.com/GameBoy-Emulation-in-JavaScript

Still haven't finished it, all these years later, but maybe I'll get time after hell freezes over.

Hey! I’ve been referencing your guide a lot as I build my own Gameboy emulator, so thank you for your help!

One thing I wanted to ask about is your opcode table. On 0xF2, you mention this instruction has been removed. However, on other Gameboy opcode tables I’ve seen this instruction is LD A,(C). Was this a mistake or are there different interpretations on whether this opcode is implemented?

As I recall (and it's only vaguely), there are differing opinions as to whether that's an instruction that's usable/undocumented/etc.

It's been such a long time, though...

Yeah, I see some opcode tables with it and some without. I’ll probably go ahead and implement it just in case since it’s relatively simple. Thanks again!

A general rule for console emulation, anything "undocumented" will be extensively used by any non first-party games

I knew I'd find you here

“Latest commit: almost 8 years ago”

Woah

Reminds me a bit of CubeWorld

Holy shit I remember that game! So it never got released huh? It's a shame, it looked pretty cool

It got released for like a week, then never again. No updates in 8 years.

Oh wow, i was reading that guide back around 2014/15 when I was writing mine.

You should finish it!

Hi, I obsessively went through your work during a semester undergrad and it provided me with a passion project during an arguably dark time of my life. I don't know if this means anything, but thank you for writing this series. I really enjoyed how articulate you are and the thought you put into breaking down the complexity for people with very little prior knowledge.

I really appreciated your guide! It’s very approachable.

Your series has helped me a lot when I wrote my own GB emulator in C# few years ago. Thanks buddy!

As someone who just wrote their first emulator (6502 to learn rust), this is something I recommend everyone do.

It starts with "oh god how do I do this" and becomes "oh god it's working".

You'll be amazed by what you can do :)

WOW. So THAT'S why we need to learn assembly as a part of the Computer Science program!

Learning assembly is useful mainly so that you know why the stack exists, what pointers are actually doing, etc.

Otherwise students write C trying to avoid pointers, etc.

mainly so that you know why the stack exists

Not only that.. but it helps you think about memory in a different way.

Too many people in higher languages talk about "allocating on the stack" which at first glance sounds like just as much "work" as allocating on the heap, and you may wonder what the difference is or why it matters.

Once you know how it works, you realize that allocating and deallocating on the stack are free.

Then when you see how clearing a stack frame magically frees all your locals, you might see how that's related to memory pools and so on and so on.

No free lunch. It's not really free to allocate on the stack. That's why recursion has depth limits.

It's obviously not free with respect to memory usage. But compared to a malloc and free a simple add and subtract operation is virtually freed regarding runtime.

It's not even an add or subtract. It's automatically setup and torn down as part of the stack frame.

In most cases were parameters are passed or local variablea are needed the compiler will add to the stack pointer and subtract again to clear the stack frame.

Yeah, but it does that regardless of whether there are local variables or parameters at all.

So we agree that there's usually an add and a subtract.

It's absolutely free to allocate on the stack.. you just can't exceed the stack size, which is about a megabyte.

So it's to get you to write better C, too. I thought Assembly was for developing and making malware on a hardware level!

And a good assembly course will even teach you to write better anything. Minimizing cache misses is a relatively easy way to increase performance massively, and can be done in just about any language.

About to start interviewing for jobs, I've known it couldn't hurt to look back at assembly and this actually looks like it'll be a nice concise reference.

[deleted]

Thanks for this! My university assembly course covered MIPS and we never really got into any ARM or x86 and I've been looking for a book that would be a good jumping off point for both ever since. Plus it'll be a good refresher

You didn't learn 6502 and 68k asm at uni ?

I need to take that class again.

I'm trying to determine whether this is sarcastic or not.

It would depend on your program, and when.

When I was in my CS program, the basic programming course was taught in Pascal, the next course was in C++, and then a course in assembly. This was heavy on 68000 and Alpha, but we also got some x86. After that you got into the compilers/OS/theory of computation courses. There was an elective in digital electronics where you ended up building a 6502-based computer which I enjoyed.

This was in the late 90s, so, I'm old. I did at least get to skip the Pascal course and start with second term stuff.

Still, get out of my register. :D

I am going to start an emulator project soon, gonna keep this as a reference.

Making a emulator of real hardware is hard, better design my own CPU

Edit: actually I’ve already did it out of that exact reason, I even made an assembler for it; only need a C compiler…

Maybe i'll make an x86 emulator... hmmm

It's probably a thing.

Intel could use an x86 emulator to test out new opcodes or changes to their architecture before attempting it in silicon.

It probably wouldn't be written quite the same as these emulators (these capture the functionality, but not the hardware). But they probably have one and it's probably very useful.

Just about any Intel processor these days is some sort of X86 emulation on top of a semi-RISC hardware. Their processor devs could probably whip up some microcode and run new instructions on real silicon before I've even had my second coffee for the day.

Several already exist. DOSBox, which you may be familiar with if you like to play older PC games, uses a full x86 emulator for example.

bochs, qemu and dosbox are all find and good, but the really impressive thing is to run Windows 95 on a Javascript x86 emulator.

EDIT: Damn, I didn't expect good old mspain to give me nostalgia like that.

I remember playing Solitaire for a good 9 hours when I should have been sleeping during high-school. Good times.

[deleted]

Bochs, Qemu, VMWare, DosBOX...

VMware isn't an emulator, is it? It uses the built in VMMRUN command to use SVM

Once it was.

[deleted]

[deleted]

Yeah, it's cumbersome dealing with bits in java. Must be that.

Java handles bit fiddling just fine.

The VJ software I have written (aka Chaoslab) can handle 1280 x 720 x 16 videos with an additional 1280 x 720 x 7 filters to mix all that video into one output. All of that at x25 frames a second no problem with software rendering.

For a total of 529,920,000 RGBA pixels (2TB) processed a second.

In Java.

Hey look another really cool lesson Ill bookmark and probably never read.

This is a fun idea for a project! Thanks for this.

Want to really learn how a CPU works? Writing an emulator is the best way to learn about it.

I don't know, building a breadboard computer would be a contender.

  1. Why the hell would anyone want to do this?
  2. That's so freaking cool.
  1. Sense of pride and accomplishment
  2. agreed.

seriously tho, One of my dream hobbies was to contribute some graphics stuff for Dolphin, so this may be a great read for me later on when I feel more comfortable with the High Level* fundamnetals

^(*I find it very weird to refer to OpenGL/Vulkan as "high level", even if it is true-ish in this context)

I suppose it's also a nice break from the usual boring coding that we do on a daily business.

Very interesting, gonna take a look at it when I get off work.

This is awesome content, thank you for sharing this!

I learned a great deal from my instructor's personal emulator he had written in the 90s for the Motorola 6800. So much so, that I understood it is a memory intensive processor vs. a register intensive version like the Intel 8080. I started an emulator in C, with opcode decoding and function pointers to the corresponding behavior, for the 8080 but never finished. Some really cool learning from an *awesome* person. Thank you Mike Fagan. (BTW Op, nice link, thank you.)

Can even a junior / beginner dev work on this project or emulators in general? Or one need to cover some prerequisite?

( Also for web development can anyone recommend any interesting project related to this topic)

Thanks.

Yeah fam, you can absolutely start emulating simple systems pretty early on. Start with a simple, half-a-century-old CPU design with few features, for example. It's MUCH easier if there is ample documentation for the cpu, whether schematic diagrams from the manufacturer, reference manuals, or reverse engienering work.

This is great. I’ll test it later this week

Seems like an awesome way to burn a few weekends.

Thank you!

I imagine this would be a good portfolio piece for a fresh graduate looking to get into game programming.

This is cool so I'ma try this some day.

This is really cool, thanks for posting. Will keep me occupied for a while!

Definitely recommend using emulators to learn a language. I learnt Haskell by writing hnes

Cool I was just wondering about this yesterday

I would love an emulator for the Hitachi HD6303 8-bit CPU (like Motorola 6801). I've been told to look at MAME, but not sure how to proceed as I don't need to emulate an arcade game.

Thx!

Can anyone recommend me some online, paid courses to get into what's needed for emulation? I've been programming for years in php and recently got into c#. I've found an assembly course on coursera but after that, I wouldn't know where to go next (can't really find anything on systems architecture, advanced c# techniques, etc).

I've also try to follow the tutorials on emu101 from time to time but I would really like to go the way of understanding machines, and not just the code for a specific emu. With this, I mean that I would be happy if I could understand things like CPU manuals, or the NES emu wiki and plan an emu from real knowledge.

Thank you!

Can someone tell me how much time it takes to do it?

I’m currently writing an NES emulator in Java. Maybe 33% done by my estimate.

It takes a lot of time, so be prepared for the long haul

Surprisingly, it can actually be quicker to implement a (simple) physical CPU in an FPGA than to emulate it.

How long have you been working on it?

So I have a family, and that means I don’t get to dedicate as much time as I’d like. So it’s been probably the last three weeks if I’m not mistaken

I did this about 15 years ago, it took a few weeks, I hit brick walls at the PPU and sound emulation.

PPU is my current brick wall, but I think I’m starting to feel comfortable with it. We’ll see

It took me almost 2 weeks to knock it out ,

Also watch out for timings plenty of opcodes take more than one clock cycle

Oh yeah, I have the opcode cycles baked in already. The CPU part is done (because it was an easy place to start). Some of the other odds and ends are done.

I think I’m now understanding the PPU basic loop, so that now I can code it. It’s a very odd beast, but I imagine emulating any graphics chip is a challenge

Depends on how good you are and how far you want to go. Could be days, could be decades.