Marmmodore-1K or Marmmodore-1000 is a fantasy 8 bit computer developed for the JS1K contest of 2016. It’s inspired by the MOS 6502 chip and the Commodore 64. It comes with a very primitive assembler and it has very limited set of instructions. 17 to be exact.
You can try out the code here DEMO.
1) 1000 Bytes of RAM
2) It uses the last 512 bytes of RAM as frame buffer and stack.
3) The frame buffer starts at address $02E8 (744) and ends at $03E7 (999). The stack goes from $01E8 (488) to $02E7 (743).
4) Keyboard input is stored at address $01E7 (487).
5) 17 CPU instructions.
ADd Pops the 2 last elements on the stack and adds them. Then stores the vale on the accumulator.
SuBtract Pops the 2 last elements on the stack and subracts them. Then stores the vale on the accumulator.
PusH Pushes the accumulator into the stack
PoP Pops the last element of the stack in the accumulator.
Memory to Accumulator Loads value from memory into the accumulator using 16 bit address
Store Accumulator Stores accumulator value into memory using 16 bit address
Load Accumulator Loads 8 bit value into accumulator
INcrement Increments the accumulator
DEcrement Decrements the accumulator
JumP Equivalent to GOTO or JUMP. It'll set program counter to the 16 bit address argument.
Store accumulator with stack Offset This is an indexed store. It's like "ma" instruction but it uses the las element on the stack as an offset. It's something like mov a, $FFFF + stack.pop()
ComPare Compares the accumulator with 8 bit value and pushes the result into the stack
Jump if Equal Branches if last element on the stack is 0
Jump if Not equal Branches if last element on the stack is not 0
Jump if Lower than Branches if last element on the stack is lower than 0
Jump if Greater than Branches if last element on the stack is greater than 0
BReak Breaks the execution of the program.
1) This will print 256 colors in the screen.
2) This will get the keyboard input and store it on the frame buffer. It’ll do it for each pixel.
The JS1K code
Here you can see the extreme compression of the code. I used a mix of Google’s Closure Compiler and RegPack to do this “crushing of the code”.
This code is exactly 1024 Bytes or 1KB which is the main limit of the JS1K contest.
The uncompressed code looks like this. It’s much more clear with all the comments.