I’ve been thinking more about initialization, and I think that it is sufficient to initialise A, and leave initialization of everything else to the first boot program written to RAM. Then write a second boot program (i.e. any 256-byte program) after that. The rationale is that:
- It doesn’t matter which 256-byte block of RAM the first boot program is written to, because the rest of RAM is filled with harmless instructions.
- Initialization of H,L and SP can be done with 3 single-byte instructions (assuming A is already initialised). So a repeating pattern of those 3 instructions + HALT can be the first boot program.
- Because the 4 instructions are repeated again and again, it doesn’t matter where in the 256 byte block they are (so the initial value of L doesn’t matter) and it doesn’t matter what gets overwritten by the stack, so long as at least one instance of each instruction is executed.
The sequence to initialise A is:
3E 00111110 LD A,n 2E 00101110 76 01110110 HALT 76 01110110 HALT
This sequence only needs to be executed once.
The programming sequence is:
3D 00111101 DEC A 2C 00101100 INC L 77 01110111 LD (HL),A 76 01110110 HALT followed by this after NMI (PC=0066h) F7 11110111 RST 30h
The sequences only differ in how D1 and D0 are configured.
For the programming sequence the configuration is:
D7=A2 D6=A1 D5=1 D4=A1 or /A0 D3=/A1 D2=1 D1=A1 D0=/A0
For the initialisation sequence it is as above except D1=1, D0=0. So a DPDT can be used to switch between the two.
So the complete sequence of steps required to bootstrap the system will be:
- Disable /OE on RAM with a manual switch
- Ensure DPDT switch is set to ‘initialise’
- Start running host program on PC that sets up serial port (using fastest available baud rate) and sets RTS signal coming into the Z80 system to zero.
- Power on the Z80 system
- Wait for a second
- Switch the DPDT to ‘memory program’
- Tell the host program to program the first boot program.
- When programming has finished, reenable /OE.
- Tell the host program to send several NMIs to ensure that the 4 byte sequence of the first boot program is executed at least once.
- Disable /OE again
- Switch the DPDT to ‘memory program’
- Tell the host program to program the second boot program (i.e any 256 byte program)
- When programming has finished, reenable /OE.
- Tell the host program to send an NMI to start executing the second boot program.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.