Module defs

Module defs 

Source
Expand description

Microcode is a set of simple instructions designed specifically for implementing the opcodes on the gbz80 processor used on the gameboy. These instructions operate on a stack of bytes called the microcode stack, which is separate from the gameboy’s stack. Each microcode operation pops some values off of the stack, computes a result, and pushes its results onto the stack.

Most microcode operations are pure functions, meaning they only operate on the microcode stack. The functionality of those operations is defined directly in this crate. For operations which are not-pure, such as skips which execute part of the microcode only conditionally or operations which act directly on the gbz80 CPU in some way, the behavior of those operations is defined externally.

Functions§

adc
Perform an 8 bit add-carry.
add
Perform an 8 bit add.
add16
Performs a 16 bit add with flags. Pops two 16 bit args off the stack (lhs on top, rhs below it), adds them, and pushes the result followed by the flags on top. The returned flags will have 00HC set based on the upper byte of the operation (as if it was performed by running the pseudo-instructions add l,<arg-low>; adc h,<arg-high>.
and
Perform a microcode and.
append
Append an 8-bit value to the microcode stack. (Essentially provides a constant value).
compliment
Complement the value on top of the stack.
dec16
Decrements a 16 bit value.
decmial_adjust
Helper for doing binary-coded-decimal. Adjusts the hex didgits to keep both nybbles in range 0..=9 by adding 0x06 and/or 0x60 to push the digit to the next nybble. Depends on the carry/halfcarry flags.
discard8
Discard an 8 bit value from the microcode stack.
discard16
Discard a 16 bit value from the microcode stack.
dup
Takes one u16 from the stack and pushes 2 copies of it onto the stack.
inc16
Increments a 16 bit value.
intersperse
Takes a u16 address off the stack followed by a u16 value, then splits the value into separate bytes and pushes them on the stack in the order: u8 high, u16 addr, u8 low, u16 addr. This is useful for performing a 16 bit write where the low byte is written first.
not
Boolean not. Note this is an interanl microcode operation, not a gameboy ALU operation.
offset_addr
Pops a 16 bit address off the stack followed by an 8 bit offset below it. Applies address offsetting and pushes the new address followed by the flags on top.
or
Perform a microcde or
reset_bit
Clears a paricular bit in the output.
rotate_left8
Rotate the value left by 8 bits.
rotate_left9
Rotate the value left by 9 bits, rotating through the carry flag.
rotate_right8
Rotate the value right by 8 bits.
rotate_right9
Rotate the value right by 9 bits, rotating through the carry flag.
sbc
Perform an 8 bit sub-carry.
set_bit
Sets a paricular bit in the output.
shift_left
Shift the value left by one bit.
shift_right
Shift the value right by one bit.
shift_right_sign_ext
Shift the value right by one bit, performing sign-extension.
stop
Panics if the stop instruction is reached. This should probably become an extern if stop is ever implemented.
sub
Perform an 8 bit sub.
swap
Swaps the lower and upper nybble of the byte.
swap816
Pop a u8 and a u16 off the microcode stack and push them in reverse order (u16 on top, u8 below it).
test_bit
Tests if a particular bit is set in the output.
xor
Perform a microcde xor