NES emulator in FreeBASIC

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
Mike C
Posts: 5
Joined: Feb 18, 2019 17:29

NES emulator in FreeBASIC

Post by Mike C »

I ported a NES emulator I wrote in VB6 several years ago over to FreeBASIC. It's admittedly a sloppy port, you'll see some things in here that have been commented out and not removed, things that are kludges to replace VB6-specific features, a lot of data types used have more appropriate alternatives in FB, etc.

It works, though! There are some bugs that manifest in certain games, but for the most part, they are very playable! Most common mappers are supported. The sound emulation is also pretty decent, but not perfect. It uses SDL 1.2 for audio.

It requires a relatively modern computer. To give you an idea of the speed, it uses 60-70% of the CPU time (of a single core) to run in 2x scaling mode on my i7-8700K! Closer to 50% in 1x scaling mode. Yes, that's horrible.

I also tried it on my LattePanda Alpha 864 SBC which is an m3-7Y30 CPU running at 1.6 GHz, where it pegs the CPU time at right around 100% in 2x scaling. Then on a laptop with an i5-3230M @ 2.6 GHz, it uses around 90% CPU at 2x scaling. I haven't tried it on any other systems yet.

Again, these numbers are all just load on a single core.

If anybody feels like taking a crack at cleaning it up and optimizing it a bit, feel free to have a go!

If your system has stuttering or popping in the audio, you may want to try increasing the buffer size. Find the "buffersize = 6400" in audio.bas, and increase it to maybe 8000 or 10000. This will increase the latency, but make the audio sound cleaner.

DOWNLOAD: http://s000.tinyupload.com/index.php?fi ... 6728243033

Just run it at the command prompt, giving it a ROM file on the command line. Or you can drag and drop a NES ROM onto the executable in explorer.

Default controller keys:
B = Z
A = X
Select = Right shift
Start = Enter
Arrow keys for the D-pad

Press F10 to reconfigure a custom key map.
Press F11 to toggle between 1x and 2x scaling.
F1 to F4 saves state to one of the four quick save slots.
F5 to F8 loads them back up.

ImageImageImageImage
Last edited by Mike C on May 27, 2019 1:43, edited 1 time in total.
jepalza
Posts: 149
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: NES emulator in FreeBASIC

Post by jepalza »

Good!! hehe
We should make a special section of "emulators written in basic". I have MANY things that I have done in the past, some better results than others, but they are a good base for those who want to start emulation in Basic.

I have emulators for:
Multitech MPF-1P, Amstrad CPC, ZX Spectrum, Commodore C64, Apple II, CHIP-8, Thomson MO5, TRS80, ZX81, Gameboy and Arcade games like City Connection, Galaxian, Crazy Climber ..... bufff !!! so much

Most of them are ports of VB versions that were obtained from the Internet, but others are 50% mine, except CPU (like Z80)

For example, in the past I made the CPU emulator 6809 in Freebasic for Thomson M05, right here:
viewtopic.php?f=8&t=19080
Post Reply