1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-30 06:29:48 +00:00

Change last_addr field to eff_addr

This commit is contained in:
Peter Evans 2018-01-12 13:57:48 -06:00
parent e56ed9ea43
commit 7d6886a3a8
16 changed files with 57 additions and 58 deletions

View File

@ -56,7 +56,6 @@
*/
#define APPLE2_BANK_OFFSET 0xD000
extern SEGMENT_READER(apple2_mem_read_bank);
extern SEGMENT_WRITER(apple2_mem_write_bank);
extern int apple2_mem_init_peripheral_rom(apple2 *);

View File

@ -68,7 +68,7 @@ typedef struct {
* memory. Another way of thinking of this is, this address is where
* we found the value we care about.
*/
vm_16bit last_addr;
vm_16bit eff_addr;
/*
* Our program counter register; this is what we'll use to determine

View File

@ -58,11 +58,11 @@ static int addr_modes[] = {
/*
* This will both define the `eff_addr` variable (which is the effective
* address) and assign that value to the `last_addr` field of the cpu.
* address) and assign that value to the `eff_addr` field of the cpu.
*/
#define EFF_ADDR(addr) \
vm_16bit eff_addr = addr; \
cpu->last_addr = eff_addr
cpu->eff_addr = eff_addr
/*
* A tiny convenience macro to help us define address resolver

View File

@ -59,8 +59,8 @@ DEFINE_INST(cpy)
*/
DEFINE_INST(dec)
{
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper - 1);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper - 1);
mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, oper - 1);
}
}
@ -90,8 +90,8 @@ DEFINE_INST(dey)
*/
DEFINE_INST(inc)
{
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper + 1);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper + 1);
mos6502_modify_status(cpu, MOS_NEGATIVE | MOS_ZERO, oper + 1);
}
}

View File

@ -38,8 +38,8 @@ DEFINE_INST(asl)
oper <<= 1;
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper);
} else {
cpu->A = oper;
}
@ -97,8 +97,8 @@ DEFINE_INST(lsr)
oper >>= 1;
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper);
} else {
cpu->A = oper;
}
@ -136,8 +136,8 @@ DEFINE_INST(rol)
oper |= 0x01;
}
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper);
} else {
cpu->A = oper;
}
@ -163,8 +163,8 @@ DEFINE_INST(ror)
oper |= 0x80;
}
if (cpu->last_addr) {
mos6502_set(cpu, cpu->last_addr, oper);
if (cpu->eff_addr) {
mos6502_set(cpu, cpu->eff_addr, oper);
} else {
cpu->A = oper;
}

View File

@ -14,7 +14,7 @@
* program counter to the last effective address.
*/
#define JUMP_IF(cond) \
if (cond) cpu->PC = cpu->last_addr; else cpu->PC += 2
if (cond) cpu->PC = cpu->eff_addr; else cpu->PC += 2
/*
* Branch if the carry flag is clear.

View File

@ -157,7 +157,7 @@ mos6502_create(vm_segment *rmem, vm_segment *wmem)
mos6502_set_memory(cpu, rmem, wmem);
cpu->last_addr = 0;
cpu->eff_addr = 0;
cpu->PC = 0;
cpu->A = 0;
cpu->X = 0;
@ -293,7 +293,7 @@ mos6502_cycles(mos6502 *cpu, vm_8bit opcode)
addr_mode = mos6502_addr_mode(opcode);
// Mainly we care about the lo byte of the last effective address
lo_addr = cpu->last_addr & 0xFF;
lo_addr = cpu->eff_addr & 0xFF;
// Ok, here's the deal: if you are using an address mode that uses
// any of the index registers, you need to return an additional
@ -359,7 +359,7 @@ mos6502_execute(mos6502 *cpu)
// instruction handler cares about (if it cares about any such
// value). For example, the operand could be the literal value that
// you pass into an instruction via immediate mode. As a
// side-effect, resolver will set the last_addr field in cpu to the
// side-effect, resolver will set the eff_addr field in cpu to the
// effective address where the operand can be found in memory, or
// zero if that does not apply (such as in immediate mode).
//

View File

@ -26,7 +26,7 @@ DEFINE_INST(brk)
*/
DEFINE_INST(jmp)
{
cpu->PC = cpu->last_addr;
cpu->PC = cpu->eff_addr;
}
/*
@ -37,7 +37,7 @@ DEFINE_INST(jmp)
DEFINE_INST(jsr)
{
mos6502_push_stack(cpu, cpu->PC + 3);
cpu->PC = cpu->last_addr;
cpu->PC = cpu->eff_addr;
}
/*

View File

@ -75,7 +75,7 @@ DEFINE_INST(plp)
*/
DEFINE_INST(sta)
{
mos6502_set(cpu, cpu->last_addr, cpu->A);
mos6502_set(cpu, cpu->eff_addr, cpu->A);
}
/*
@ -83,7 +83,7 @@ DEFINE_INST(sta)
*/
DEFINE_INST(stx)
{
mos6502_set(cpu, cpu->last_addr, cpu->X);
mos6502_set(cpu, cpu->eff_addr, cpu->X);
}
/*
@ -91,7 +91,7 @@ DEFINE_INST(stx)
*/
DEFINE_INST(sty)
{
mos6502_set(cpu, cpu->last_addr, cpu->Y);
mos6502_set(cpu, cpu->eff_addr, cpu->Y);
}
/*

View File

@ -107,7 +107,7 @@ Test(mos6502_addr, addr_mode_rel_positive)
cpu->PC = 123;
SET_PC_BYTE(cpu, 1, 88);
cr_assert_eq(mos6502_resolve_rel(cpu), 0);
cr_assert_eq(cpu->last_addr, 213);
cr_assert_eq(cpu->eff_addr, 213);
}
Test(mos6502_addr, addr_mode_rel_negative)
@ -115,7 +115,7 @@ Test(mos6502_addr, addr_mode_rel_negative)
cpu->PC = 123;
SET_PC_BYTE(cpu, 1, 216);
cr_assert_eq(mos6502_resolve_rel(cpu), 0);
cr_assert_eq(cpu->last_addr, 85);
cr_assert_eq(cpu->eff_addr, 85);
}
Test(mos6502_addr, addr_mode_zpg)

View File

@ -64,7 +64,7 @@ Test(mos6502_arith, dec)
mos6502_handle_dec(cpu, 0);
cr_assert_neq(cpu->A, 4);
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_set(cpu, 123, 44);
// Note _also_ that DEC expects the number to be decremented will be
@ -90,7 +90,7 @@ Test(mos6502_arith, dey)
Test(mos6502_arith, inc)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_inc(cpu, 55);
cr_assert_eq(mos6502_get(cpu, 123), 56);
}

View File

@ -22,7 +22,7 @@ Test(mos6502_bits, asl)
mos6502_handle_asl(cpu, 5);
cr_assert_eq(cpu->A, 10);
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_asl(cpu, 22);
cr_assert_eq(mos6502_get(cpu, 123), 44);
}
@ -73,7 +73,7 @@ Test(mos6502_bits, lsr)
cr_assert_eq(cpu->A, 2);
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_lsr(cpu, 22);
cr_assert_eq(mos6502_get(cpu, 123), 11);
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
@ -95,7 +95,7 @@ Test(mos6502_bits, rol)
mos6502_handle_rol(cpu, 8);
cr_assert_eq(cpu->A, 16);
cpu->last_addr = 234;
cpu->eff_addr = 234;
mos6502_handle_rol(cpu, 128);
cr_assert_eq(mos6502_get(cpu, 234), 1);
}
@ -105,7 +105,7 @@ Test(mos6502_bits, ror)
mos6502_handle_ror(cpu, 64);
cr_assert_eq(cpu->A, 32);
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_ror(cpu, 1);
cr_assert_eq(mos6502_get(cpu, 123), 128);
}

View File

@ -8,96 +8,96 @@ TestSuite(mos6502_branch, .init = setup, .fini = teardown);
Test(mos6502_branch, bcc)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bcc(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= MOS_CARRY;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bcc(cpu, 0);
cr_assert_neq(cpu->PC, 127);
}
Test(mos6502_branch, bcs)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bcs(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= MOS_CARRY;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bcs(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, beq)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_beq(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= MOS_ZERO;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_beq(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, bmi)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bmi(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= MOS_NEGATIVE;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bmi(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}
Test(mos6502_branch, bne)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bne(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= MOS_ZERO;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bne(cpu, 0);
cr_assert_neq(cpu->PC, 127);
}
Test(mos6502_branch, bpl)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bpl(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= MOS_NEGATIVE;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bpl(cpu, 0);
cr_assert_neq(cpu->PC, 127);
}
Test(mos6502_branch, bvc)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bvc(cpu, 0);
cr_assert_eq(cpu->PC, 123);
cpu->P |= MOS_OVERFLOW;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bvc(cpu, 0);
cr_assert_neq(cpu->PC, 127);
}
Test(mos6502_branch, bvs)
{
cpu->last_addr = 123;
cpu->eff_addr = 123;
mos6502_handle_bvs(cpu, 0);
cr_assert_neq(cpu->PC, 123);
cpu->P |= MOS_OVERFLOW;
cpu->last_addr = 125;
cpu->eff_addr = 125;
mos6502_handle_bvs(cpu, 0);
cr_assert_eq(cpu->PC, 125);
}

View File

@ -79,7 +79,7 @@ Test(mos6502, cycles)
// In this case, we aren't cross a page boundary, and the number of
// cycles should stay at 4
cpu->last_addr = 0x5070;
cpu->eff_addr = 0x5070;
cpu->X = 23;
cr_assert_eq(mos6502_cycles(cpu, 0x1D), 4);

View File

@ -22,7 +22,7 @@ Test(mos6502_exec, brk)
Test(mos6502_exec, jmp)
{
cpu->PC = 123;
cpu->last_addr = 234;
cpu->eff_addr = 234;
mos6502_handle_jmp(cpu, 0);
cr_assert_eq(cpu->PC, 234);
@ -31,7 +31,7 @@ Test(mos6502_exec, jmp)
Test(mos6502_exec, jsr)
{
cpu->PC = 123;
cpu->last_addr = 235;
cpu->eff_addr = 235;
mos6502_handle_jsr(cpu, 0);
cr_assert_eq(cpu->PC, 235);

View File

@ -61,25 +61,25 @@ Test(mos6502_loadstor, plp)
Test(mos6502_loadstor, sta)
{
cpu->A = 123;
cpu->last_addr = 555;
cpu->eff_addr = 555;
mos6502_handle_sta(cpu, 0);
cr_assert_eq(mos6502_get(cpu, cpu->last_addr), cpu->A);
cr_assert_eq(mos6502_get(cpu, cpu->eff_addr), cpu->A);
}
Test(mos6502_loadstor, stx)
{
cpu->X = 222;
cpu->last_addr = 444;
cpu->eff_addr = 444;
mos6502_handle_stx(cpu, 0);
cr_assert_eq(mos6502_get(cpu, cpu->last_addr), cpu->X);
cr_assert_eq(mos6502_get(cpu, cpu->eff_addr), cpu->X);
}
Test(mos6502_loadstor, sty)
{
cpu->Y = 111;
cpu->last_addr = 253;
cpu->eff_addr = 253;
mos6502_handle_sty(cpu, 0);
cr_assert_eq(mos6502_get(cpu, cpu->last_addr), cpu->Y);
cr_assert_eq(mos6502_get(cpu, cpu->eff_addr), cpu->Y);
}
Test(mos6502_loadstor, tax)