Re: BB816 Computer YouTube Series
Posted: Fri Aug 18, 2023 8:23 pm
I've been working on getting the COP signature byte, no use case in mind just a fun challenge. Here is the code I came up with in emulation mode and in native mode.
I don't have the hardware to test it with me yet, which makes me think I need to work on an emulator for the project! I'll report back if any changes are needed.
One thing I'm not 100% sure of is bank crossing behavior. If we end up executing a COP at $FFFF, the next instruction from the CPU's point of view would be $0001, in the same program bank, right? That would make the signature byte $0000 in the same bank, and not in the next bank. I'm wondering because it prevents using stack relative indirect addressing to fetch the signature, since this addressing mode crosses over banks and so you can't just load Y with $FFFF to decrement the program counter.
Anyway, here is the code so far, only the COP sections:
Native mode
Emulation mode
I don't have the hardware to test it with me yet, which makes me think I need to work on an emulator for the project! I'll report back if any changes are needed.
One thing I'm not 100% sure of is bank crossing behavior. If we end up executing a COP at $FFFF, the next instruction from the CPU's point of view would be $0001, in the same program bank, right? That would make the signature byte $0000 in the same bank, and not in the next bank. I'm wondering because it prevents using stack relative indirect addressing to fetch the signature, since this addressing mode crosses over banks and so you can't just load Y with $FFFF to decrement the program counter.
Anyway, here is the code so far, only the COP sections:
Native mode
Code: Select all
; where each register is relative to the stack pointer after interrupt entry
int_native_stack_offset_pb = 13
int_native_stack_offset_pc = 11
int_native_stack_offset_p = 10
int_native_stack_offset_db = 9
int_native_stack_offset_d = 7
int_native_stack_offset_a = 5
int_native_stack_offset_x = 3
int_native_stack_offset_y = 1
+mx_16_bits
lda int_native_stack_offset_pc,s ; get program counter
dec ; decrement it by one to get to signature byte
; note: if COP is at $FFFF, then the signature byte
; is at $0000 in the same bank (TODO: verify with hardware)
tax ; save this address to a 16 bits X
+m_8_bits
lda int_native_stack_offset_pb,s ; get program bank register
phb ; save current data bank register
pha ; and save the new one as data bank register
plb ; so we load signature byte from the right bank
lda+2 0,x ; load the 8 bit signature, from the right bank and with
; a 16 bit offset address
+x_8_bits
plb ; restore original data bank
and # $ff ; ensure flags are set by the value of A
Code: Select all
; where each register is relative to the stack pointer after interrupt entry
int_emu_stack_offset_pc = 5
int_emu_stack_offset_p = 4
int_emu_stack_offset_a = 3
int_emu_stack_offset_x = 2
int_emu_stack_offset_y = 1
lda int_emu_stack_offset_pc+1,s ; high byte program counter
tax
lda int_emu_stack_offset_pc,s ; low byte program counter
bne + ; decrement it by one to get to signature byte address
dex
+ dec
phx ; push new address to the stack
pha
ldy # 0
lda (1,s),y ; load signature byte
ply ; reset stack pointer
ply
and # $ff ; ensure flags are set by the value of A