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
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main() -> None:
try:
emulator.run()
except KeyboardInterrupt:
log.info("Emulator zakończony przez użytkownika.")
log.info("Emulator terminated by user.")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/bus/memory/pla.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def decode_address(
"""
Decodes the address and returns the module responsible for handling the request.
"""
result = self.bus.ram # Domyślnie RAM, jeśli żaden warunek nie pasuje
result = self.bus.ram # Default to RAM if no condition matches

if 0xE000 <= address <= 0xFFFF and self.is_kernel_rom_visible:
result = self.bus.kernel_rom
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def execute_next_instruction(self) -> None:

def format_status_for_log(self) -> list[tuple[str, int]]:
"""
Formats the status register w układzie NV-BDIZC (typowe w 6502).
Indeks bitów: 7=N, 6=V, 5=U, 4=B, 3=D, 2=I, 1=Z, 0=C
Formats the status register in the NV-BDIZC layout (typical for the 6502).
Bit indices: 7=N, 6=V, 5=U, 4=B, 3=D, 2=I, 1=Z, 0=C
"""
n = (self.status >> 7) & 1
v = (self.status >> 6) & 1
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, cpu: "CPU") -> None:
}

def execute(self, opcode: int) -> None:
"""Wykonuje instrukcję na podstawie opcode."""
"""Executes an instruction based on the opcode."""
if opcode in self.instructions:
self.instructions[opcode]()
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/bus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.fixture
def bus(monkeypatch):
"""Inicjalizuje magistralę w trybie testowym z zaślepkami ROM."""
"""Initializes the bus in test mode with ROM stubs."""

def fake_post_init(self):
self.data = bytes([i % 256 for i in range(self.size)])
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/cpu/test_instructions/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
@pytest.fixture
def bus():
"""
Prosta atrapa CPU, zawiera minimalną logikę potrzebną do testowania
instrukcji skoku.
Simple CPU stub containing minimal logic required to test jump instructions.
"""
return Bus()


@pytest.fixture
def time_instruction():
"""
Fixture zwraca funkcję pomocniczą do pomiaru czasu wykonania dowolnej instrukcji/funkcji.
Możemy ją wywołać wielokrotnie, aby uzyskać miarodajny pomiar.
Fixture returning a helper function to measure execution time of any instruction/function.
It can be called multiple times to obtain a reliable measurement.
"""

def _time_instruction(func, repeat=1, *args, **kwargs):
"""
Uruchamia 'func(*args, **kwargs)' 'repeat' razy i zwraca łączny czas w sekundach.
Dodatkowo zwraca średni czas (czas_całkowity / repeat).
Runs 'func(*args, **kwargs)' 'repeat' times and returns the total time in seconds.
Additionally returns the average time (total_time / repeat).
"""
start = time.perf_counter()
for _ in range(repeat):
Expand Down
88 changes: 44 additions & 44 deletions tests/integration/cpu/test_instructions/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ def arithmetic(bus):

def test_sbc_immediate(bus, arithmetic, time_instruction) -> None:
"""Tests the sbc_immediate instruction and measures its execution time."""
# Ustawienia początkowe CPU i pamięci
# Initial CPU and memory setup
bus.cpu.pc = 0x1000
bus.cpu.a = 0x50 # Akumulator początkowo 0x50
bus.cpu.a = 0x50 # Accumulator initially 0x50
bus.cpu.status = (bus.cpu.status | 0x01) & ~(
1 << 3
) # Ustawienie Carry, wyczyszczenie Decimal Mode
bus.ram.data[0x1000] = 0x20 # Wartość do odjęcia
) # Set Carry, clear Decimal Mode
bus.ram.data[0x1000] = 0x20 # Value to subtract

# Test dla trybu binarnego (Decimal Mode = False)
# Test for binary mode (Decimal Mode = False)
arithmetic.sbc_immediate()

# Sprawdzanie wyniku
# Verify result
assert bus.cpu.a == 0x30, (
"Akumulator powinien wynosić 0x30 po SBC w trybie binarnym"
"Accumulator should be 0x30 after SBC in binary mode"
)
assert (bus.cpu.status & 0x01) == 0x01, (
"Flaga Carry powinna być ustawiona, gdy wynik jest nieujemny"
"Carry flag should be set when result is non-negative"
)
assert (bus.cpu.status & 0x02) == 0x00, (
"Flaga Zero nie powinna być ustawiona, gdy wynik nie jest równy zero"
"Zero flag should not be set when result is non-zero"
)
assert (bus.cpu.status & 0x80) == 0x00, (
"Flaga Negative nie powinna być ustawiona, gdy wynik nie jest ujemny"
"Negative flag should not be set when result is not negative"
)
assert (bus.cpu.status & 0x40) == 0x00, (
"Flaga Overflow nie powinna być ustawiona, gdy nie wystąpiło przepełnienie"
"Overflow flag should not be set when no overflow occurred"
)

total_time, avg_time = time_instruction(arithmetic.sbc_immediate, repeat=10000)
Expand All @@ -49,35 +49,35 @@ def test_sbc_immediate(bus, arithmetic, time_instruction) -> None:

def test_sbc_absolute_x(bus, arithmetic, time_instruction) -> None:
"""Tests the sbc_absolute_x instruction and measures its execution time."""
# Ustawienia początkowe CPU i pamięci
bus.cpu.pc = 0x1000 # Ustawienie PC na adres 0x1000
bus.cpu.x = 0x10 # Ustawienie rejestru X na 0x10
bus.cpu.a = 0x50 # Akumulator początkowo 0x50
# Initial CPU and memory setup
bus.cpu.pc = 0x1000 # Set PC to address 0x1000
bus.cpu.x = 0x10 # Set X register to 0x10
bus.cpu.a = 0x50 # Accumulator initially 0x50
bus.cpu.status = (bus.cpu.status | 0x01) & ~(
1 << 3
) # Ustawienie Carry, wyczyszczenie Decimal Mode
bus.ram.data[0x1000] = 0x00 # LSB adresu docelowego
bus.ram.data[0x1001] = 0x20 # MSB adresu docelowego (adres docelowy to 0x2000)
bus.ram.data[0x2010] = 0x20 # Wartość w pamięci pod adresem 0x2000 + X (0x2010)
) # Set Carry, clear Decimal Mode
bus.ram.data[0x1000] = 0x00 # LSB of target address
bus.ram.data[0x1001] = 0x20 # MSB of target address (target address is 0x2000)
bus.ram.data[0x2010] = 0x20 # Value in memory at address 0x2000 + X (0x2010)

# Test dla trybu binarnego (Decimal Mode = False)
# Test for binary mode (Decimal Mode = False)
arithmetic.sbc_absolute_x()

# Sprawdzanie wyniku
# Verify result
assert bus.cpu.a == 0x30, (
"Akumulator powinien wynosić 0x30 po SBC w trybie binarnym"
"Accumulator should be 0x30 after SBC in binary mode"
)
assert (bus.cpu.status & 0x01) == 0x01, (
"Flaga Carry powinna być ustawiona, gdy wynik jest nieujemny"
"Carry flag should be set when result is non-negative"
)
assert (bus.cpu.status & 0x02) == 0x00, (
"Flaga Zero nie powinna być ustawiona, gdy wynik nie jest równy zero"
"Zero flag should not be set when result is non-zero"
)
assert (bus.cpu.status & 0x80) == 0x00, (
"Flaga Negative nie powinna być ustawiona, gdy wynik nie jest ujemny"
"Negative flag should not be set when result is not negative"
)
assert (bus.cpu.status & 0x40) == 0x00, (
"Flaga Overflow nie powinna być ustawiona, gdy nie wystąpiło przepełnienie"
"Overflow flag should not be set when no overflow occurred"
)

total_time, avg_time = time_instruction(arithmetic.sbc_absolute_x, repeat=10000)
Expand All @@ -90,35 +90,35 @@ def test_sbc_absolute_x(bus, arithmetic, time_instruction) -> None:

def test_sbc_absolute_y(bus, arithmetic, time_instruction) -> None:
"""Tests the sbc_absolute_y instruction and measures its execution time."""
# Ustawienia początkowe CPU i pamięci
bus.cpu.pc = 0x1000 # Ustawienie PC na adres 0x1000
bus.cpu.y = 0x10 # Ustawienie rejestru Y na 0x10
bus.cpu.a = 0x50 # Akumulator początkowo 0x50
# Initial CPU and memory setup
bus.cpu.pc = 0x1000 # Set PC to address 0x1000
bus.cpu.y = 0x10 # Set Y register to 0x10
bus.cpu.a = 0x50 # Accumulator initially 0x50
bus.cpu.status = (bus.cpu.status | 0x01) & ~(
1 << 3
) # Ustawienie Carry, wyczyszczenie Decimal Mode
bus.ram.data[0x1000] = 0x00 # LSB adresu bazowego
bus.ram.data[0x1001] = 0x20 # MSB adresu bazowego (adres bazowy to 0x2000)
bus.ram.data[0x2010] = 0x20 # Wartość w pamięci pod adresem 0x2000 + Y (0x2010)
) # Set Carry, clear Decimal Mode
bus.ram.data[0x1000] = 0x00 # LSB of base address
bus.ram.data[0x1001] = 0x20 # MSB of base address (base address is 0x2000)
bus.ram.data[0x2010] = 0x20 # Value in memory at address 0x2000 + Y (0x2010)

# Test dla trybu binarnego (Decimal Mode = False)
# Test for binary mode (Decimal Mode = False)
arithmetic.sbc_absolute_y()

# Sprawdzanie wyniku
# Verify result
assert bus.cpu.a == 0x30, (
"Akumulator powinien wynosić 0x30 po SBC w trybie binarnym"
"Accumulator should be 0x30 after SBC in binary mode"
)
assert (bus.cpu.status & 0x01) == 0x01, (
"Flaga Carry powinna być ustawiona, gdy wynik jest nieujemny"
"Carry flag should be set when result is non-negative"
)
assert (bus.cpu.status & 0x02) == 0x00, (
"Flaga Zero nie powinna być ustawiona, gdy wynik nie jest równy zero"
"Zero flag should not be set when result is non-zero"
)
assert (bus.cpu.status & 0x80) == 0x00, (
"Flaga Negative nie powinna być ustawiona, gdy wynik nie jest ujemny"
"Negative flag should not be set when result is not negative"
)
assert (bus.cpu.status & 0x40) == 0x00, (
"Flaga Overflow nie powinna być ustawiona, gdy nie wystąpiło przepełnienie"
"Overflow flag should not be set when no overflow occurred"
)

total_time, avg_time = time_instruction(arithmetic.sbc_absolute_y, repeat=10000)
Expand Down
Loading