Close

Chip8 means I need a SPAM-1 "C" Compiler after all

A project log for SPAM-1 - 8 Bit CPU

8 Bit CPU in 7400 with full Verilog simulator and toolchain

john-lonerganJohn Lonergan 01/03/2021 at 22:220 Comments

It is with some regret that I have to admit that a cross compilation from Chip 8 is tricky.

Looks like I have to write an interpreter / emulator after all. This is necessary because of the need to mess around with direct memory addresses in Chip-8. 

I'm going to write interpreter in SPAM "C"  and what this means is that I'm back working on the SPAM "C" compiler. The big change is that I need to upgrade the SPAM "C" compiler from 8 bit to 16 bit Integers. I spent age's trying to decide whether and how to support 8 and 16 bit ints but in the end decided to switch entirely to 16 bits and then work out how to add 8 buts back into the necessary ops. The shorter int would be used most of the time in programs like Chip8 emulation however 16 bits it also needed as the Chip8 program counter is 12 bits and the Chip8 Index register is also 12 bits. So if I do everthing as 16 bits to start with then I can optimise 8 bits back into the compiler. For now I'm declaring everything as "uint16".

It's a bit of a bummer as the ALU can do all 8 bit maths ops in a single clock cycle but even a 16 bit shift takes many more cycles and I haven't yet worked out a 16 bit multiply or divide.

I will add maths ops to SPAM 'C' as the needs of the Chip8 emulator dictate.

In retrospec I'l have to review whether I should have trier retargeting GCC at SPAM-1. I did read around this but the documentation I found suggested that it was a hard thing to do. On the other hand building SPAM 'C' isn't a walk in the park either. It's been educational but also a lot of head scratching and late nights.

----

Later ...

I spent a while reading up on retargeting a compiler to SPAM-1. One page ...

https://stackoverflow.com/questions/8696229/how-to-create-a-c-compiler-for-custom-cpu

led me here ...

http://www.compilers.de/vbcc.html

I will check this out too.

Decisions decisions.

Discussions