CHIP-8 Simulator BBC/Master

Post Reply
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

As some of you may have seen there's a thread in 8bit acorn software: other about a CHIP-8 emulator (viewtopic.php?f=2&t=23241), spurred on by this I decided that it should be possible to create one that works on the BBC Micro (no Electron since it's in Mode 7).

The first release in that thread was rather bare bones and wasn't 100% working correctly, I've fixed most of the major issues with that version, and added a few improvements, firstly you can now specify the ROM image to load on the command line, and secondly you can reset the current ROM by pressing F9.

Controls are a little strange because it uses a HEX keypad, however lots of games use it as a direction pad so it makes more sense to map it to a grid of keys as follows:

Code: Select all

Original   Simulator
1 2 3 C -> 1 2 3 4
4 5 6 D -> Q W E R
7 8 9 E -> A S D F
A 0 B F -> Z X C V
The disk image provided has a selection of ROM images, most have been tested and generally they work although a few may still exhibit issues, to run a game simple type:

Code: Select all

*CHIP8 G.<gamename>
The game image isn't loaded directly into the simulator's RAM, but into memory below, it's then copied into RAM on reset so the original copy remains intact.

Pressing F0 will enter debugging mode which allows any keypress to single step through the code.

The graphics may be a little flickery, this is because the CHIP-8 systems run on a 60hz timer, including VSync and all sprite draw routines wait on that vsync, I felt that if I tried to wait for the 50hz BBC vsync then games would run noticably slower. A better solution might be to write the graphics to an offscreen buffer and copy that during the normal BBC vsync, but that would require a much more complex solution.

I will make the source available for the simulator shortly once I've sorted out everything.
Attachments
chip8.ssd
(17 KiB) Downloaded 66 times
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
nicolagiacobbe
Posts: 215
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by nicolagiacobbe »

Thanks Dudley,
that's exactly what I was after and it was quick too. I am in awe.
Would you mind to tell us the route that led to writing the software, the choices, the ideas and all that? I am sure would result in an interesting read.
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

Okay, after posting I spotted an issue with the BCD decoder, I've just fixed it and made a new version.
chip8.ssd
(17 KiB) Downloaded 42 times
This version is the same in other respects except the BCD decoder fix.
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

Another version, I've added sound to the simulator, I think this may have broken a couple of the games, but most of them are working alright.
Attachments
chip8.ssd
(17.25 KiB) Downloaded 53 times
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
RobC
Posts: 3816
Joined: Sat Sep 01, 2007 10:41 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by RobC »

Excellent work =D>

I think Dave/Arcadian was having problems with every key causing a reset. I get the same issue in B-Em but it works fine in BeebEm.
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

I think there's an issue with interrupts and the keyboard reading routine, I'm going to change the keyread routine to disable interrupts, I think adding sound may have broken it since it now updates the volume during the timer interrupt now. I should be able to do a new build later today, this version should hopefully fix the input issues.
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

Okay, I've added SEI/CLI around the keyboard reading code, so it wont be interrupted by the 60hz timer interrupt.

I decided that since there was some space on the disk image, I would add the readme file from the original chip8 source that I got the game roms from.
This is formatted for 80 columns, so I made a !BOOT file which changes to mode 3, turns on paging, and the shows the contents of the file. This includes the keys for the games, of course they're described in CHIP8 keypad layout (except a few which reference PC keys)

You can read the file type doing

Code: Select all

*TYPE GAMES
if you want to view the file directly.

I may make a master version which will use the numeric keypad for input, this should be a fairly simple change, and should also fit on the disk image along with the BBC version.
Attachments
chip8.ssd
(23.5 KiB) Downloaded 45 times
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
User avatar
tricky
Posts: 7694
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by tricky »

I think that you said at the Dev night that you wait for vsync after drawing each sprite, but I must have missed that in the docs as I didn't remember it.
User avatar
dudleysoft71
Posts: 298
Joined: Tue May 26, 2020 6:56 pm
Contact:

Re: CHIP-8 Simulator BBC/Master

Post by dudleysoft71 »

I found a disassembly of the original interpreter, which shows how each instrument works, and the sprite routine waits for vsync before rendering to reduce flickering.

Here's the appropriate part of the disassembly
Screenshot_20210911-215627_Drive.jpg
James Watson - DudleySoft

BBC Model B 32K - PiTubeDirect, Pi1Mhz, Smally Mouse, Gotek, DFS/ADFS, 4xSWRAM.
Post Reply

Return to “miscellaneous new bbc and electron games”