Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
pull_request:

jobs:
build-and-test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libncurses-dev

- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew update
brew install ncurses

- name: Build (root)
run: make
4 changes: 2 additions & 2 deletions include/mem6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void initializeMem6502 (MEM6502 *memory);
// Frees 65 Kilobytes of RAM.
void freeMem6502 (MEM6502 *memory);

void cpu_read (Bus6502 *bus, const MEM6502 *memory, Word address, CPU6502 *cpu);
void cpu_write (Bus6502 *bus, MEM6502 *memory, Word address, Byte data, CPU6502 *cpu);
void cpu_read (Bus6502 *bus, const MEM6502 *memory, Word address);
void cpu_write (Bus6502 *bus, MEM6502 *memory, Word address, Byte data);

#endif // MEM6502_H
6 changes: 2 additions & 4 deletions src/bus/mem6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ WriteByte (Word Value, MEM6502 *mem, DWord Address)

}

void cpu_read(Bus6502 *bus, const MEM6502 *memory, Word addr, CPU6502 *cpu)
void cpu_read(Bus6502 *bus, const MEM6502 *memory, Word addr)
{
AccessType accessType = cpu->CurrentAccess;
bus->address = addr;
bus->rw = true;

Expand Down Expand Up @@ -123,9 +122,8 @@ void cpu_read(Bus6502 *bus, const MEM6502 *memory, Word addr, CPU6502 *cpu)
bus->data = 0xFF;
}

void cpu_write(Bus6502 *bus, MEM6502 *memory, Word addr, Byte data, CPU6502 *cpu)
void cpu_write(Bus6502 *bus, MEM6502 *memory, Word addr, Byte data)
{
AccessType accessType = cpu->CurrentAccess;
bus->address = addr;
bus->data = data;
bus->rw = false;
Expand Down
14 changes: 7 additions & 7 deletions src/cpu/Instructions/ADC/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static inline void
ADC_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);

Byte Before = cpu->A;
cpu->A += bus->data + cpu->Flag.C;
Expand All @@ -77,7 +77,7 @@ ADC_ZPX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
ZeroPageAddr += cpu->X;

cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);

Byte Before = cpu->A;
cpu->A += bus->data + cpu->Flag.C;
Expand All @@ -97,7 +97,7 @@ ADC_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);

cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte Before = cpu->A;
cpu->A += bus->data + cpu->Flag.C;
ADCSetStatus (cpu, Before, bus->data);
Expand All @@ -124,7 +124,7 @@ ADC_ABSX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, NewAddress, cpu);
cpu_read (bus, memory, NewAddress);
Byte Before = cpu->A;
cpu->A += bus->data + cpu->Flag.C;
ADCSetStatus (cpu, Before, bus->data);
Expand All @@ -151,7 +151,7 @@ ADC_ABSY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, NewAddress, cpu);
cpu_read (bus, memory, NewAddress);
Byte Before = cpu->A;
cpu->A += bus->data + cpu->Flag.C;
ADCSetStatus (cpu, Before, bus->data);
Expand All @@ -175,7 +175,7 @@ ADC_INDX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Byte hi = memory->Data[(Byte)(zp + 1)];
Word addr = (hi << 8) | lo;

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
Byte Value = bus->data;
Byte Before = cpu->A;

Expand Down Expand Up @@ -207,7 +207,7 @@ ADC_INDY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
Byte Value = bus->data;
Byte Before = cpu->A;

Expand Down
14 changes: 7 additions & 7 deletions src/cpu/Instructions/AND/and.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static inline void
AND_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
cpu->A &= bus->data;
ANDSetStatus (cpu);
spend_cycles (3);
Expand All @@ -74,7 +74,7 @@ AND_ZPX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
ZeroPageAddr += cpu->X;
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
cpu->A &= bus->data;

ANDSetStatus (cpu);
Expand All @@ -91,7 +91,7 @@ static inline void
AND_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
cpu->A &= bus->data;

ANDSetStatus (cpu);
Expand Down Expand Up @@ -121,7 +121,7 @@ AND_ABSX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
cpu->A &= bus->data;
ANDSetStatus (cpu);
spend_cycles (4);
Expand Down Expand Up @@ -149,7 +149,7 @@ AND_ABSY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
cpu->A &= bus->data;
ANDSetStatus (cpu);
spend_cycles (4);
Expand All @@ -172,7 +172,7 @@ AND_INDX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Byte hi = memory->Data[(Byte)(zp + 1)];
Word addr = (hi << 8) | lo;

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
cpu->A &= bus->data;
ANDSetStatus (cpu);
spend_cycles (6);
Expand Down Expand Up @@ -200,7 +200,7 @@ AND_INDY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
cpu->A &= bus->data;
ANDSetStatus (cpu);
spend_cycles (5);
Expand Down
8 changes: 4 additions & 4 deletions src/cpu/Instructions/ASL/asl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static inline void
ASL_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte zero_page_addr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, zero_page_addr, cpu);
cpu_read (bus, memory, zero_page_addr);
Byte value = bus->data;

cpu->A = value << 1;
Expand All @@ -91,7 +91,7 @@ ASL_ZPX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
zero_page_addr += cpu->X;


cpu_read (bus, memory, zero_page_addr, cpu);
cpu_read (bus, memory, zero_page_addr);
Byte value = bus->data;
cpu->A = value << 1;
;
Expand All @@ -110,7 +110,7 @@ static inline void
ASL_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, absolute, cpu);
cpu_read (bus, memory, absolute);
Byte value = bus->data;

cpu->A = value << 1;
Expand All @@ -132,7 +132,7 @@ ASL_ABSX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Word absolute = FetchWord (bus, memory, cpu);
absolute += cpu->X;

cpu_read (bus, memory, absolute, cpu);
cpu_read (bus, memory, absolute);
Byte value = bus->data;
cpu->A = value << 1;
;
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/Instructions/BIT/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static inline void
BIT_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
BITSetStatus (bus->data, cpu);
spend_cycles (3);
}
Expand All @@ -61,7 +61,7 @@ static inline void
BIT_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
BITSetStatus (bus->data, cpu);
spend_cycles (4);
}
Expand Down
14 changes: 7 additions & 7 deletions src/cpu/Instructions/CMP/cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline void
CMP_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (3);
Expand All @@ -68,7 +68,7 @@ CMP_ZPX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
ZeroPageAddr += cpu->X;

cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (4);
Expand All @@ -83,7 +83,7 @@ static inline void
CMP_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (4);
Expand All @@ -107,7 +107,7 @@ CMP_ABSX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, NewAddress, cpu);
cpu_read (bus, memory, NewAddress);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (4);
Expand All @@ -131,7 +131,7 @@ CMP_ABSY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, NewAddress, cpu);
cpu_read (bus, memory, NewAddress);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (4);
Expand All @@ -154,7 +154,7 @@ CMP_INDX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Byte hi = memory->Data[(Byte)(zp + 1)];
Word addr = (hi << 8) | lo;

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (6);
Expand Down Expand Up @@ -184,7 +184,7 @@ CMP_INDY (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
spend_cycle ();
}

cpu_read (bus, memory, addr, cpu);
cpu_read (bus, memory, addr);
Byte Result = cpu->A - bus->data;
CMPSetStatus (Result, cpu);
spend_cycles (5);
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/Instructions/CPX/cpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline void
CPX_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte Result = cpu->X - bus->data;
CPXSetStatus (Result, cpu);
spend_cycles (3);
Expand All @@ -66,7 +66,7 @@ static inline void
CPX_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte Result = cpu->X - bus->data;
CPXSetStatus (Result, cpu);
spend_cycles (4);
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/Instructions/CPY/cpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline void
CPY_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);
cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte Result = cpu->Y - bus->data;
CPYSetStatus (Result, cpu);
spend_cycles (3);
Expand All @@ -66,7 +66,7 @@ static inline void
CPY_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);
cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte Result = cpu->Y - bus->data;
CPYSetStatus (Result, cpu);
spend_cycles (4);
Expand Down
16 changes: 8 additions & 8 deletions src/cpu/Instructions/DEC/dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ DEC_ZP (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Byte ZeroPageAddr = FetchByte (bus, memory, cpu);

cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte DecrementValue = bus->data - 1;

cpu_write (bus, memory, ZeroPageAddr, DecrementValue, cpu);
cpu_write (bus, memory, ZeroPageAddr, DecrementValue);
DECSetStatus (DecrementValue, cpu);
spend_cycles (5);
}
Expand All @@ -63,10 +63,10 @@ DEC_ZPX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
ZeroPageAddr += cpu->X;


cpu_read (bus, memory, ZeroPageAddr, cpu);
cpu_read (bus, memory, ZeroPageAddr);
Byte DecrementValue = bus->data - 1;

cpu_write (bus, memory, ZeroPageAddr, DecrementValue, cpu);
cpu_write (bus, memory, ZeroPageAddr, DecrementValue);
DECSetStatus (DecrementValue, cpu);
spend_cycles (6);
}
Expand All @@ -82,10 +82,10 @@ DEC_ABS (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
{
Word Absolute = FetchWord (bus, memory, cpu);

cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte DecrementValue = bus->data - 1;

cpu_write (bus, memory, Absolute, DecrementValue, cpu);
cpu_write (bus, memory, Absolute, DecrementValue);
DECSetStatus (DecrementValue, cpu);
spend_cycles (6);
}
Expand All @@ -103,10 +103,10 @@ DEC_ABSX (Bus6502 *bus, MEM6502 *memory, CPU6502 *cpu)
Absolute += cpu->X;


cpu_read (bus, memory, Absolute, cpu);
cpu_read (bus, memory, Absolute);
Byte DecrementValue = bus->data - 1;

cpu_write (bus, memory, Absolute, DecrementValue, cpu);
cpu_write (bus, memory, Absolute, DecrementValue);
DECSetStatus (DecrementValue, cpu);
spend_cycles (6);
}
Expand Down
Loading