From 0db06f162e48839c2af12f4655cf3814c29037fb Mon Sep 17 00:00:00 2001 From: QuantumFlowQa Date: Thu, 28 Aug 2025 17:53:35 +0200 Subject: [PATCH] Translate Polish comments to English --- main.py | 2 +- src/bus/memory/pla.py | 2 +- src/cpu/cpu.py | 4 +- src/cpu/manager.py | 2 +- tests/integration/bus/conftest.py | 2 +- .../cpu/test_instructions/conftest.py | 11 +- .../cpu/test_instructions/test_arithmetic.py | 88 +++---- .../cpu/test_instructions/test_heap.py | 218 +++++++++--------- 8 files changed, 164 insertions(+), 165 deletions(-) diff --git a/main.py b/main.py index 6215e30..f7d1c4e 100644 --- a/main.py +++ b/main.py @@ -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__": diff --git a/src/bus/memory/pla.py b/src/bus/memory/pla.py index 93b407d..6534fc3 100644 --- a/src/bus/memory/pla.py +++ b/src/bus/memory/pla.py @@ -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 diff --git a/src/cpu/cpu.py b/src/cpu/cpu.py index 8b534f6..57fa244 100644 --- a/src/cpu/cpu.py +++ b/src/cpu/cpu.py @@ -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 diff --git a/src/cpu/manager.py b/src/cpu/manager.py index cc07f86..ee680cb 100644 --- a/src/cpu/manager.py +++ b/src/cpu/manager.py @@ -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: diff --git a/tests/integration/bus/conftest.py b/tests/integration/bus/conftest.py index 8dfd918..bb182cb 100644 --- a/tests/integration/bus/conftest.py +++ b/tests/integration/bus/conftest.py @@ -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)]) diff --git a/tests/integration/cpu/test_instructions/conftest.py b/tests/integration/cpu/test_instructions/conftest.py index 975f500..90c48be 100644 --- a/tests/integration/cpu/test_instructions/conftest.py +++ b/tests/integration/cpu/test_instructions/conftest.py @@ -8,8 +8,7 @@ @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() @@ -17,14 +16,14 @@ def 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): diff --git a/tests/integration/cpu/test_instructions/test_arithmetic.py b/tests/integration/cpu/test_instructions/test_arithmetic.py index 7d374c5..4c64087 100644 --- a/tests/integration/cpu/test_instructions/test_arithmetic.py +++ b/tests/integration/cpu/test_instructions/test_arithmetic.py @@ -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) @@ -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) @@ -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) diff --git a/tests/integration/cpu/test_instructions/test_heap.py b/tests/integration/cpu/test_instructions/test_heap.py index 27fa04a..033dd50 100644 --- a/tests/integration/cpu/test_instructions/test_heap.py +++ b/tests/integration/cpu/test_instructions/test_heap.py @@ -12,248 +12,248 @@ def heap(bus): def test_lda_zero_page_non_zero(bus, heap, time_instruction) -> None: """Tests the lda_zero_page (LDA Zero Page) instruction with a non-zero value.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0x00 # Początkowa wartość A - bus.cpu.status = 0x00 # Wyczyszczenie flag + bus.cpu.a = 0x00 # Initial value of A + bus.cpu.status = 0x00 # Clear flags - bus.ram.data[0x1000] = 0x80 # Adres zero-page - bus.ram.data[0x80] = 0x45 # Wartość w pamięci + bus.ram.data[0x1000] = 0x80 # Zero-page address + bus.ram.data[0x80] = 0x45 # Value in memory - # Wykonanie instrukcji + # Execute instruction heap.lda_zero_page() - # Spodziewane wartości + # Expected values expected_value = 0x45 expected_zero = expected_value == 0 expected_negative = (expected_value & 0x80) != 0 - # Sprawdzenie wyników + # Verify results assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) - assert bus.cpu.cycles == 3, "Instrukcja LDA Zero Page powinna zająć 3 cykle" - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.cycles == 3, "LDA Zero Page instruction should take 3 cycles" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" - # Pomiar czasu + # Measure execution time total_time, avg_time = time_instruction(heap.lda_zero_page, repeat=10000) log.info( - f"[test_lda_zero_page_non_zero] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_zero_page_non_zero] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" ) def test_lda_zero_page_zero(bus, heap, time_instruction) -> None: """Tests the lda_zero_page (LDA Zero Page) instruction with a zero value.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0xFF # Początkowa wartość A - bus.cpu.status = 0x00 # Wyczyszczenie flag + bus.cpu.a = 0xFF # Initial value of A + bus.cpu.status = 0x00 # Clear flags - bus.ram.data[0x1000] = 0x80 # Adres zero-page - bus.ram.data[0x80] = 0x00 # Wartość w pamięci + bus.ram.data[0x1000] = 0x80 # Zero-page address + bus.ram.data[0x80] = 0x00 # Value in memory - # Wykonanie instrukcji + # Execute instruction heap.lda_zero_page() - # Spodziewane wartości + # Expected values expected_value = 0x00 - expected_zero = True # Ponieważ wartość to 0 - expected_negative = False # Ponieważ bit 7 nie jest ustawiony + expected_zero = True # Since value is 0 + expected_negative = False # Since bit 7 is not set - # Sprawdzenie wyników + # Verify results assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) - assert bus.cpu.cycles == 3, "Instrukcja LDA Zero Page powinna zająć 3 cykle" - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.cycles == 3, "LDA Zero Page instruction should take 3 cycles" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" - # Pomiar czasu + # Measure execution time total_time, avg_time = time_instruction(heap.lda_zero_page, repeat=10000) log.info( - f"[test_lda_zero_page_zero] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_zero_page_zero] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" ) def test_lda_zeropage_x_non_zero(bus, heap, time_instruction) -> None: """Tests the lda_zeropage_x (LDA Zero Page,X) instruction with a non-zero value.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0x00 # Początkowa wartość A - bus.cpu.x = 0x05 # Offset w rejestrze X - bus.cpu.status = 0x00 # Wyczyszczenie flag + bus.cpu.a = 0x00 # Initial value of A + bus.cpu.x = 0x05 # Offset in X register + bus.cpu.status = 0x00 # Clear flags - bus.ram.data[0x1000] = 0x80 # Base address w zero-page - effective_address = (0x80 + 0x05) & 0xFF # Przesunięcie X w zero-page - bus.ram.data[effective_address] = 0x45 # Wartość w pamięci + bus.ram.data[0x1000] = 0x80 # Base address in zero page + effective_address = (0x80 + 0x05) & 0xFF # X offset in zero page + bus.ram.data[effective_address] = 0x45 # Value in memory - # Wykonanie instrukcji + # Execute instruction heap.lda_zeropage_x() - # Spodziewane wartości + # Expected values expected_value = 0x45 expected_zero = expected_value == 0 expected_negative = (expected_value & 0x80) != 0 - # Sprawdzenie wyników + # Verify results assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) - assert bus.cpu.cycles == 4, "Instrukcja LDA Zero Page,X powinna zająć 4 cykle" - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.cycles == 4, "LDA Zero Page,X instruction should take 4 cycles" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" - # Pomiar czasu + # Measure execution time total_time, avg_time = time_instruction(heap.lda_zeropage_x, repeat=10000) log.info( - f"[test_lda_zeropage_x_non_zero] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_zeropage_x_non_zero] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" ) def test_lda_zeropage_x_zero(bus, heap, time_instruction) -> None: """Tests the lda_zeropage_x (LDA Zero Page,X) instruction with a zero value.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0xFF # Początkowa wartość A - bus.cpu.x = 0x0A # Offset w rejestrze X - bus.cpu.status = 0x00 # Wyczyszczenie flag + bus.cpu.a = 0xFF # Initial value of A + bus.cpu.x = 0x0A # Offset in X register + bus.cpu.status = 0x00 # Clear flags - bus.ram.data[0x1000] = 0x70 # Base address w zero-page - effective_address = (0x70 + 0x0A) & 0xFF # Przesunięcie X w zero-page - bus.ram.data[effective_address] = 0x00 # Wartość w pamięci + bus.ram.data[0x1000] = 0x70 # Base address in zero page + effective_address = (0x70 + 0x0A) & 0xFF # X offset in zero page + bus.ram.data[effective_address] = 0x00 # Value in memory - # Wykonanie instrukcji + # Execute instruction heap.lda_zeropage_x() expected_value = 0x00 - expected_zero = True # Ponieważ wartość to 0 - expected_negative = False # Ponieważ bit 7 nie jest ustawiony + expected_zero = True # Since value is 0 + expected_negative = False # Since bit 7 is not set assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) - assert bus.cpu.cycles == 4, "Instrukcja LDA Zero Page,X powinna zająć 4 cykle" - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.cycles == 4, "LDA Zero Page,X instruction should take 4 cycles" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" total_time, avg_time = time_instruction(heap.lda_zeropage_x, repeat=10000) log.info( - f"[test_lda_zeropage_x_zero] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_zeropage_x_zero] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" ) def test_lda_indirect_y_no_page_cross(bus, heap, time_instruction) -> None: """Tests the lda_indirect_y (LDA (Indirect),Y) instruction without page crossing.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0x00 # Początkowa wartość A - bus.cpu.y = 0x05 # Offset w rejestrze Y - bus.cpu.status = 0x00 # Wyczyszczenie flag - - bus.ram.data[0x1000] = 0x80 # Zero-page adres wskaźnika - bus.ram.data[0x80] = 0x34 # Low byte adresu docelowego - bus.ram.data[0x81] = 0x12 # High byte adresu docelowego - base_address = (0x12 << 8) | 0x34 # Składanie pełnego adresu - effective_address = (base_address + 0x05) & 0xFFFF # Uwzględnienie Y - bus.ram.data[effective_address] = 0x45 # Wartość w pamięci - - # Wykonanie instrukcji + bus.cpu.a = 0x00 # Initial value of A + bus.cpu.y = 0x05 # Offset in Y register + bus.cpu.status = 0x00 # Clear flags + + bus.ram.data[0x1000] = 0x80 # Zero-page pointer address + bus.ram.data[0x80] = 0x34 # Low byte of target address + bus.ram.data[0x81] = 0x12 # High byte of target address + base_address = (0x12 << 8) | 0x34 # Construct full address + effective_address = (base_address + 0x05) & 0xFFFF # Account for Y + bus.ram.data[effective_address] = 0x45 # Value in memory + + # Execute instruction heap.lda_indirect_y() - # Spodziewane wartości + # Expected values expected_value = 0x45 expected_zero = expected_value == 0 expected_negative = (expected_value & 0x80) != 0 - # Sprawdzenie wyników + # Verify results assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) assert bus.cpu.cycles == 5, ( - "Instrukcja LDA (Indirect),Y powinna zająć 5 cykli bez przekroczenia strony" + "LDA (Indirect),Y instruction should take 5 cycles without page crossing" ) - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" - # Pomiar czasu + # Measure execution time total_time, avg_time = time_instruction(heap.lda_indirect_y, repeat=10000) log.info( - f"[test_lda_indirect_y_no_page_cross] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_indirect_y_no_page_cross] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" ) def test_lda_indirect_y_page_cross(bus, heap, time_instruction) -> None: """Tests the lda_indirect_y (LDA (Indirect),Y) instruction with page crossing.""" bus.cpu.pc = 0x1000 - bus.cpu.a = 0x00 # Początkowa wartość A - bus.cpu.y = 0xF0 # Offset w rejestrze Y, aby wymusić przekroczenie strony - bus.cpu.status = 0x00 # Wyczyszczenie flag - - bus.ram.data[0x1000] = 0x80 # Zero-page adres wskaźnika - bus.ram.data[0x80] = 0xFF # Low byte adresu docelowego - bus.ram.data[0x81] = 0x12 # High byte adresu docelowego - base_address = (0x12 << 8) | 0xFF # Składanie pełnego adresu - effective_address = (base_address + 0xF0) & 0xFFFF # Uwzględnienie Y - bus.ram.data[effective_address] = 0x30 # Wartość w pamięci - - # Wykonanie instrukcji + bus.cpu.a = 0x00 # Initial value of A + bus.cpu.y = 0xF0 # Y register offset to force page crossing + bus.cpu.status = 0x00 # Clear flags + + bus.ram.data[0x1000] = 0x80 # Zero-page pointer address + bus.ram.data[0x80] = 0xFF # Low byte of target address + bus.ram.data[0x81] = 0x12 # High byte of target address + base_address = (0x12 << 8) | 0xFF # Construct full address + effective_address = (base_address + 0xF0) & 0xFFFF # Account for Y + bus.ram.data[effective_address] = 0x30 # Value in memory + + # Execute instruction heap.lda_indirect_y() - # Spodziewane wartości + # Expected values expected_value = 0x30 expected_zero = expected_value == 0 expected_negative = (expected_value & 0x80) != 0 - # Sprawdzenie wyników + # Verify results assert bus.cpu.a == expected_value, ( - f"A powinno być {hex(expected_value)}, ale jest {hex(bus.cpu.a)}" + f"A should be {hex(expected_value)}, but is {hex(bus.cpu.a)}" ) assert (bus.cpu.status & 0x02) == (0x02 if expected_zero else 0x00), ( - "Flaga Zero jest niepoprawna" + "Zero flag incorrect" ) assert (bus.cpu.status & 0x80) == (0x80 if expected_negative else 0x00), ( - "Flaga Negative jest niepoprawna" + "Negative flag incorrect" ) assert bus.cpu.cycles == 6, ( - "Instrukcja LDA (Indirect),Y powinna zająć 6 cykli z przekroczeniem strony" + "LDA (Indirect),Y instruction should take 6 cycles with page crossing" ) - assert bus.cpu.pc == 0x1001, "PC powinno zwiększyć się o 1" + assert bus.cpu.pc == 0x1001, "PC should increment by 1" - # Pomiar czasu + # Measure execution time total_time, avg_time = time_instruction(heap.lda_indirect_y, repeat=10000) log.info( - f"[test_lda_indirect_y_page_cross] Powtórzono 10 000 razy. " - f"Całkowity czas: {total_time:.6f}s, Średni czas: {avg_time:.9f}s" + f"[test_lda_indirect_y_page_cross] Repeated 10,000 times. " + f"Total time: {total_time:.6f}s, Average time: {avg_time:.9f}s" )