Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/cpu/cpu650x.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static void PLA(void)

static void PLP(void)
{
CPU.P.reg = S_POP();
CPU.P.reg = (S_POP() | EXP_FLAG_MASK) & (uint8_t)(~BRK_FLAG_MASK);
}

static void ROL(void)
Expand Down Expand Up @@ -622,7 +622,7 @@ static void RTI(void)
uint16_t addr;
uint8_t pch, pcl;

CPU.P.reg = S_POP();
CPU.P.reg = (S_POP() | EXP_FLAG_MASK) & (uint8_t)(~BRK_FLAG_MASK);
pcl = S_POP();
pch = S_POP();
addr = (((uint16_t)pch << 8) & 0xff00) | ((uint16_t)pcl & 0x00ff);
Expand Down Expand Up @@ -1007,7 +1007,8 @@ static int fetch_operand(enum _addr_modes mode)

switch (mode) {
case mIMP:
/* Nothing to do */
/* Performs a dummy fetch */
sbus_read(CPU.PC);
break;

case mIMM:
Expand Down Expand Up @@ -1074,6 +1075,12 @@ static int fetch_operand(enum _addr_modes mode)
if ((addr & 0xff00) != bah)
cross = 1;

/* We need to perform a dummy read when page crossing for read
* instructions (differentiated by the add cycles == 0).
*/
if (cross || op_codes[opcode].add_cycles == 0)
sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff)));

/* Fetches the data */
fetched_addr = addr;
break;
Expand All @@ -1088,6 +1095,10 @@ static int fetch_operand(enum _addr_modes mode)
if ((addr & 0xff00) != bah)
cross = 1;

/* Dummy read as in abs,x */
if (cross || op_codes[opcode].add_cycles == 0)
sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff)));

/* Fetches the data */
fetched_addr = addr;
break;
Expand All @@ -1111,6 +1122,10 @@ static int fetch_operand(enum _addr_modes mode)
if ((addr & 0xff00) != bah)
cross = 1;

/* Dummy read as in abs,x */
if (cross || op_codes[opcode].add_cycles == 0)
sbus_read((uint16_t)((bah & 0xff00) | (addr & 0x00ff)));

fetched_addr = addr;
break;
}
Expand Down Expand Up @@ -1254,7 +1269,7 @@ void cpu_reset(void)
CPU.X = 0;
CPU.Y = 0;
CPU.S = 0xfd;
CPU.P.reg = 0x34;
CPU.P.reg = 0x24;

/* Fetch initial vectors */
adl = sbus_read(0xfffc);
Expand Down
Loading