Close

Additional thoughts about initialization

A project log for Bootstrapping a ROMless Z80 using RS-232

Is it possible to bootstrap a simple ROMless Z80 system using only two wires - e.g. from an RS232 interface? This project explores this.

willstevenswill.stevens 01/13/2024 at 15:420 Comments

Looking at the Z80 opcode table, another way to initialise HL and AF (but not SP) is to connect the data lines up as follows:

D7 = 0
D6 = A4
D5 = A3
D4 = A2
D3 = A1
D2 = 1
D1 = 1
D0 = 0

 This has the effect of executing:

LD B,06h
LD C,0Eh
LD D,16h
LD E,1Eh
LD H,26h
LD L,2Eh
LD (HL),36h
LD A,3Eh
LD B,(HL)
LD C,(HL)
LD D,(HL)
LD E,(HL)
LD H,(HL)
LD L,(HL)
HALT

Leaving SP uninitialised is not necessarily a problem. Although the “memory program” sequence writes to stack, that could be avoided by switching from using NMI to restart execution after HALT to using RESET to do this.

But the stack writes in the “memory program” step do serve a purpose - they are for initialising the whole of memory with harmless instructions, which will execute until the 256-byte block of ‘programmed’ memory is encountered. This memory initialisation is done before the 256-byte block is programmed. If we don’t know where SP is initially, we won’t know whether it accidentally overwrites the 256 block we are programming. But switching TxD from NMI to RESET after all of RAM has been initialised by stack writes will prevent any further stack writes, so the 256-byte block won’t be overwritten.

Discussions