The Need for RAM Testing
Before running any critical code, especially on vintage or newly built Z80 hardware, you must verify that the Random Access Memory (RAM) is working correctly. Faulty RAM chips can lead to unpredictable crashes and data corruption.
Goal: To ensure every memory cell can reliably store both a logic ‘0’ and a logic ‘1’.
The Simplest Test: The Fill Test
The fastest, simplest test is to fill the entire memory block with a single value (e.g., 00H
or FFH
) and then read it back to verify. However, this test is weak because a faulty address line might cause two memory locations to point to the same physical chip, and this test wouldn’t catch it.
The Standard: The Walking Bit Test
The Walking Bit Test is a highly effective diagnostic that ensures each memory address is unique and every bit within every byte is fully functional.
The Principle: For every memory byte, you write a pattern with a single ‘1’ bit, shift the ‘1’ bit one position, write the new pattern, and repeat 8 times.
Steps for a Single Byte:
- Initialize: Start with the pattern
01H
(00000001b). - Write: Store the current pattern at the memory location
(HL)
. - Verify: Read the byte back from `(HL)′ and compare it to the pattern. If they don’t match, the RAM fails.
- Advance: Shift the pattern left by one bit (`RLC A′).
- Repeat: Loop 8 times until the ‘1’ bit has walked across all 8 positions.
The Z80 Walking Bit Routine (Conceptual)
This routine must loop through every byte in the target memory range (e.g., from 4000H′ to
FFFFH′) and perform the 8-bit walking test on each address.
The Outer Loop:
MEM_START EQU 4000H
MEM_END EQU FFFFH
START_TEST:
LD HL, MEM_START ; HL = Current Address
ADDR_LOOP:
PUSH HL ; Save address for the inner loop
CALL WALKING_BIT_TEST ; Perform the 8-step test at (HL)
POP HL ; Restore HL
INC HL ; Move to the next byte
; Check if HL has passed the MEM_END address
LD A, H
CP HIGH(MEM_END) ; Compare high byte
JP NZ, ADDR_LOOP ; Continue if not finished
RET ; Test complete
Testing Address Lines
The final stage of memory testing involves writing a sequence of data (e.g., 55H′ then
AAH′) across the entire memory map to verify that every address line is functioning. If an address line is stuck, this pattern will fail quickly, confirming a hardware fault.