180. Direccionamiento indirecto para jmp
Añadir direccionamiento Indirecto para JMP.
Lección 180 de 356 · tests/chapter_01_cpu/test_180_indirect_addressing_for_jmp.py
Crea una función dentro de emulator/cpu/addressing_modes.py:
def indirect(cpu):
...Por qué existe este paso
JMP necesita este modo de direccionamiento especial para resolver un destino indirecto a partir del puntero de 16 bits codificado por `JMP ($hhhh)`.
Orientación para el estudiante
Esto es diferente de indirect_x(cpu) e indirect_y(cpu).
JMP indirecto usa un operando de 16 bits como puntero en cualquier parte de la memoria
JMP ($0200)Paso a paso
1. Fetch the 16-bit pointer operand from the instruction stream.
Example bytes: 00 02 -> pointer address $0200.
2. Read the low byte of the target from memory[pointer].
Example: memory[$0200] = $34.
3. Read the high byte of the target from memory[pointer + 1].
Example: memory[$0201] = $12.
4. Return the final target address.
Example: $1234.Fallo de hardware importante
El 6502 tiene un fallo de límite de página en JMP indirecto.
Si el puntero termina en $FF, el byte alto se lee de la misma página en lugar de la siguiente:
JMP ($02FF)La CPU real lee
low = memory[$02FF]
high = memory[$0200]NO lee el byte alto de $0300.
Forma de implementación útil
ptr = cpu.fetch_word()
low = cpu.bus.read(ptr)
high_addr = (ptr & 0xFF00) | ((ptr + 1) & 0x00FF)
high = cpu.bus.read(high_addr)
return low | (high << 8)Ejecutar esta lección
uv run pytest tests/chapter_01_cpu/test_180_indirect_addressing_for_jmp.py -v