CPU reference
Closed this issue · 1 comments
fengb commented
Currently, we save a CPU reference by adhoc pointer arithmetic:
- https://github.com/fengb/fundude/blob/067e9b5/src/zasm.c#L25
- https://github.com/fengb/fundude/blob/067e9b5/src/zasm.c#L79
This is currently only done in the disassembly layer, but switching to function dispatch will require more references. This can easily become super unwieldy and confusing, especially when translating to Zig.
Theoretical replacement
Fixed array buffers. This forces offsets to be consistent, at the cost of some slight API discomfort (until we move to Zig?)
const Reg16: enum(u3) {
AF = 0,
BC = 1,
DE = 2,
HL = 3,
SP = 4,
PC = 5,
};
const Reg8: enum(u3) {
F = 0,
A = 1,
C = 2,
B = 3,
E = 4,
D = 5,
L = 6,
H = 7,
};
const Flags: packed struct {
_pad: u4,
C: bool,
H: bool,
N: bool,
Z: bool,
};
const Cpu: packed union {
r16: [6]u16, // candidate for enum array: https://github.com/ziglang/zig/issues/793
r8: [8]u8,
// Is this even a good idea? lol
magic: packed struct {
flags: Flags,
}
};