1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-22 15:31:12 +00:00

Attempt to emulate the BRK instruction.

This commit is contained in:
Radosław Kujawa 2017-01-31 00:31:28 +01:00
parent b21d884f8b
commit 44f723b016
3 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,5 @@
opcode_id,mnemonic,addressing,size,emulation,modify_pc
OP_BRK,"brk",IMPLIED,1,NULL,false
OP_BRK,"brk",IMPLIED,2,emul_brk,true
OP_ORA_IZPX,"ora",IZPX,2,emul_ora,false
OP_NOPI_3,"nop",IMMEDIATE,2,NULL,false
OP_NOPI_4,"nop",IMPLIED,1,NULL,false

1 opcode_id mnemonic addressing size emulation modify_pc
2 OP_BRK brk IMPLIED 1 2 NULL emul_brk false true
3 OP_ORA_IZPX ora IZPX 2 emul_ora false
4 OP_NOPI_3 nop IMMEDIATE 2 NULL false
5 OP_NOPI_4 nop IMPLIED 1 NULL false

View File

@ -240,6 +240,33 @@ emul_bra(rk65c02emu_t *e, void *id, instruction_t *i)
program_counter_branch(e, (int8_t) i->op1);
}
/* BRK - break! or rather, jump to break vector */
void
emul_brk(rk65c02emu_t *e, void *id, instruction_t *i)
{
uint16_t retaddr;
retaddr = e->regs.PC + 2;
/* push return address to the stack */
stack_push(e, retaddr >> 8);
stack_push(e, retaddr & 0xFF);
/* push processor status to the stack with break flag set */
stack_push(e, e->regs.P | P_BREAK);
/*
* The IRQ disable is set, decimal flags is cleared _after_ pushing
* the P register to the stack.
*/
e->regs.P |= P_IRQ_DISABLE;
e->regs.P &= ~P_DECIMAL;
/* load address from IRQ vector into program counter */
e->regs.PC = bus_read_1(&e->bus, VECTOR_IRQ);
e->regs.PC |= bus_read_1(&e->bus, VECTOR_IRQ + 1) << 8;
}
/* BVC - branch on overflow clear */
void
emul_bvc(rk65c02emu_t *e, void *id, instruction_t *i)
@ -568,7 +595,7 @@ emul_pla(rk65c02emu_t *e, void *id, instruction_t *i)
instruction_status_adjust_negative(e, e->regs.A);
}
/* PLA - pull from stack to processor flags */
/* PLP - pull from stack to processor flags */
void
emul_plp(rk65c02emu_t *e, void *id, instruction_t *i)
{

View File

@ -42,6 +42,8 @@ struct reg_state {
#define STACK_START 0x0100
#define STACK_END 0x01FF
#define VECTOR_IRQ 0xFFFE /* also used for BRK */
#define BIT(val,n) ((val) & (1 << (n)))
typedef struct reg_state reg_state_t;