You all probably know that I like low level things in programming. I’ve covered compilers extensively. I’ve dealt with some embedded systems work which was fun. I’ve learned a lot though this, but, in the process, I stopped using Realbasic, using C, C++, and assembly instead, depending on what the task required.
Realbasic, as a language, just seem intuitive to understand to me. You don’t have strange things like the ternary operator in C, or strange macros, or pointer craziness. I know from experience, that going through that is helpful and sometimes you have to, but RB seems to be really good about some things.
Because RB is so nice about some things, yet so different than some other languages, I occasionally will translate a piece of code to RB, from, say, C. This proves challenging enough that it requires both good knowledge of C and RB, and it also forces me to understand the code that I’m writing more than just reading it.
One thing that I had been looking at was how to play video game music, specifically on a small embedded system I have. But that was proving overwhelming. I didn’t know how the sound systems worked or how to emulate them. So I took a step back. I thought about how emulators worked. This got really interesting, and I figured, hey, maybe I can do this.
So I went out and found some an open source Gameboy emulator written in C++. I chose a gameboy emulator for several reasons. First, the system is old and slow, so speed issues would be reduced, even maybe to the point where I’d need to slow down. Newer systems might run to fast for mine to keep up. Hey, it’s my first time out. Second, the gameboy has a builtin screen, so video output gets written in specific ways to display directly to a screen. An NES might have to have additional layers to convert it from an analog TV signal to something to draw. Finally, I was told that the almighty SNES had some crazy special modes that hurt people’s heads to manage. Again, it’s my first time out.
I found a nice emulator (I haven’t actually run it) written in object oriented C++. This makes it easy to understand and translate into RB. There’s a GameBoy class that has a Cartridge, a CPU, and buttons, the CPU has some memory, a ROM, some timers, and such. It just breaks down really well. Probably not optimized like other emulators would have to be, but this is how I would probably make an emulator starting out, replicating the real thing in code.
I’m in the process of porting the CPU code to RB right now, and let me tell you, it’s a lot to it. Just because there is one “add” keyword in the assembly doesn’t mean there is one “add” opcode. Depending on where the data for the add operation is coming from, the opcode changes. So then you have 16 different add functions, which then call another function that actually does the adding.
I think I’ll post sections of the code as I finish them on a new project page. The project that I’m basing mine on can be found here. It’s called Mario there. I’m open to suggestions for a name for this project, though.