Games
Development
My Blog
About Me
Forums
Subscribe

Check out the Archive for more blog entries.

The RetroBox CPU

April 27, 2008

Time for the next piece on the RetroBox. If you don't know what that is, start here, then go read this. This entry will be quite technical, so if you're not the programmer type, you might want to skip it.

 

The RetroBox Processor

So, I've decided what sort of things the RetroBox processor (RBCPU for short) will be capable of. Basically, it will be able to operate on bytes (8-bit), words (16-bit), longwords (32-bit) and floats (32-bit).

When it comes to registers, the RetroBox will have 32 integer data registers, named d0 to d31, each 32 bits,  and 32 integer address registers, named a0 to a31, also 32 bits each. There's no real difference between the data and address registers, other than the name, and they can be used in the same way (I just find it handy to make a distinction between data and address values when writing assembler). In addition to these integer registers, there will be 32 floating point registers, named f0 to f31.

Also, there will be a 32 bit instruction pointer named IP, and a 32 bit stack pointer named SP. Those shouldn't be used for general purpose stuff, but can be useful to implement some tricks, I'm sure :-)

 

The Instruction Set

Here's a list of the machine code instructions which will be available on the RBCPU. There's only 38 of them, but I think that's all it's going to need. And as you'll see, each instruction will be quite powerful in regards to what it can operate on.

NOP - no operation
JSR - jump to subroutine
JMP - unconditional jump
RET - return from subroutine
SYS - make a system call (used for things like sprites and the blitter operations)
MOVE - move values between memory/registers
ADD - addition
SUB - subtraction
NEG - change the sign
MULS - signed integer multiplication
MULU - unsigned integer multiplication
MUL - floating point multiplication
DIVS - signed division
DIVU - unsigned division
DIV - floating point division
ITOF - convert integer to float
FTOI - convert float to integer
CMP - compare two values
JE - jump if the last compared values were equal
JNE - jump if the last compared values were not equal
JGE - jump if the first of the last compared values were greater than or equal to the second
JLE - jump if the first of the last compared values were less than or equal to the second
JG - jump if the first of the last compared values were greater than the second
JL - jump if the first of the last compared values were less than the second
TST - test a value for zero
JZ - jump if the last tested value were zero
JNZ - jump if the last tested value were non-zero
PUSH - push value onto the top of the stack
POP - pop a value off the top of the stack
AND - bitwise and
OR - bitwise or
XOR - bitwise xor
NOT - bitwise not
BSET - set specified bit
BCLR - clear specified bit
BTST - test specified bit
ROL - bitwise shift left
ROR - bitwise shift right

The assembler will be strongly typed, so most of the instructions above will have a suffix of .b, .w, .l or .f to signify which type to operate on. Also, the operands for most operations can be either a memory adress or a register (so no need to always shuffle things into registers before doing anything). For example, all of these variations are possible when using the move operation on the byte datatype:

  • move.b d0,d1    ; Move the content of register d0 into the register d1
  • move.b @a0,d0   ; Move the content of the memory address pointed to by register a0 into the register d0
  • move.b 42,d0    ; Move the literal value 42 into the register d0
  • move.b @$30000,d0     ; Move the content of the hexadecimal memory address 30000 into the register d0
  • move.b d0,@a0    ; Move the content of register d0 into the location of the memory address pointed to by register a0
  • move.b @a0,@a1    ; Move the content of the memory address pointed to by register a0 into the location of the memory address pointed to by register a1
  • move.b %101010,@a0    ; Move the literal value 42 (expressed in binary) into the location of the memory address pointed to by register a0
  • move.b @$30000,@a0   ; Move the content of the hexadecimal memory address 30000 into the location of the memory address pointed to by register a0
  • move.b d0,@$20000    ; Move the content of register d0 into the location of the hexadecimal memory address 20000
  • move.b @a0,@$20000    ; Move the content of the memory address pointed to by register a0  into the location of the hexadecimal memory address 20000
  • move.b $2a,@$20000    ; Move the literal value 42 (expressed in hex) into the location of the hexadecimal memory address 20000
  • move.b @$30000,@$20000    ;  Move the content of the hexadecimal memory address 30000 into the location of the hexadecimal memory address 20000

And the same goes for most other instructions as well, and for all the other datatypes. So as you can see, the instructions are quite powerful, and allows for the low-level control you need.

I wanted to keep the RBCPU relatively simple, but at the same time make assembler programming for the RetroBox a viable option, and I'm hoping that this instruction set will enable that. There will of course be a high level language as well, but for raw speed, you'll want to use ASM.

Ok, a bit technical this time, but sometimes it has to be :-) Next time, I'll show you some tasty screenshots of my TV-screen emulation filter, which is what will make the RetroBox pixels look sooo yummy! :D


Archive

Launching mattiasgustavsson.com - August 18, 2008
The Pixie Game Engine - July 2, 2008
Marvin Maggot - May 26, 2008
retrogamedev.org - May 19, 2008
Blur and Bleed: Running Games on a TV - May 3, 2008
The RetroBox CPU - April 27, 2008
RetroBox - The Specification - April 24, 2008
Starting something new: A Retro Project - April 19, 2008
Bloodlines & Not finishing on time - March 30, 2008
Midwinter Rites - December 25, 2007
Baby Viking and the Alien Invasion - December 18, 2007
Trolls are not very nice people - December 4, 2007
Another enemy: Orc - November 28, 2007
The Amazing Adventures of Kassandra - November 20, 2007
First enemy: Goblin - November 12, 2007
Player Characters - November 5, 2007
Site is up! - October 22, 2007