lazyboNES Emulator Famicom BASIC Support
A new feature has been added in the lazyboNES emulator which has nothing to do with playing Super Mario Bros in a Linux terminal. It is now possible to run the Famicom Family BASIC cartridges, which means there is support to emulate both the HVC-007 "Famicom Keyboard" and the HVC-008 "Famicom Data Recorder". The changes have been implemented in version 0.8 that can be downloaded here or from the public Git repositories.
A new command line option is required to activate the "BASIC mode" since the keyboard overrides the keyboard-based controller and the graphics map is completely different from SMB. The HVC-007 keyboard is supported in both curses and SDL but behaves slightly different. Curses maps to the character value while SDL uses scancodes. The HVC-008 cassette data recorder is accessed through the debugger and it is possible to both load or save WAV files in mono unsigned 8-bit 44100 Hz format. The WAV file can also be played back to a real Famicom system! Correspondingly a WAV file recorded from a real Famicom (in that format) can also be loaded by lazyboNES!
It is also possible to inject a text file as keyboard input from the debugger, this is meant to easily load BASIC programs from text files. Note however that the Famicom BASIC is quite limited compared to other variants, here are some of the limitations I found when trying to port existing BASIC programs from other platforms:
* Strings can just be 31 characters long.
* LET statement is not supported, but it can be skipped.
* DEF statement is missing so new functions cannot be defined.
* INT() function does not exist.
* Screen column output is just 28 characters.
* Only 2K or 4K of RAM available depending on the cartridge version.
However, Famicom BASIC is geared towards making simple games using the Famicom's unique tile graphics and sound support. A few of these games made by "Hawk" can be found at the wayback machine. These are in a bit-stream format called "tpr" which is used by the NesterJ emulator.
Here is a simple Python script to convert those "tpr" files into WAV files:
#!/usr/bin/python3 def tpr2wav(in_file, out_file): fh = open(in_file, "rb") tpr = fh.read() fh.close() fh = open(out_file, "wb") # Generate dummy WAV header. fh.write(bytes.fromhex('52 49 46 46 ff ff ff ff 57 41 56 45 66 6d 74 20')) fh.write(bytes.fromhex('10 00 00 00 01 00 01 00 44 ac 00 00 44 ac 00 00')) fh.write(bytes.fromhex('01 00 08 00 64 61 74 61 ff ff ff ff 00 00 00 00')) for byte in tpr: # Use and invert 2 bits from each byte. for bit_no in range(0,8,4): if (byte >> bit_no) & 1: fh.write(b'\x00') else: fh.write(b'\xFF') fh.close() if __name__ == "__main__": import sys if len(sys.argv) < 3: print("Usage: %s <in-tpr-file> <out-wav-file>" % (sys.argv[0])) sys.exit(1) tpr2wav(sys.argv[1], sys.argv[2])
The resulting WAV files can be loaded by lazyboNES or played back to a real Famicom system.
For a demonstration check this video.