ZX Spectrum ROM: Computer Initialization and Memory Checking

ZX Land #01

Description of the ROM, Part I

Fragment 1/1

In this series of articles, we will present all the more important routines contained in the permanent memory of our computer. In the first part, we will describe basic routines related to:

  • computer initialization
  • reading the keyboard
  • displaying text
  • displaying numerical values
  • clearing the screen

The first routine is used both to handle the NEW command and to initialize the computer, starting at address

11CB NEW
LD A,7
;set the border colour to 7
LD A,3F
LD I,A
;wait 24 cycles!!!

The memory is now checked:

11DA RAMCHECK
LD H,D
LD L,E
;copy the RAMTOP value for NEW,
;or #FFFF for #0000, into registers HL
11DC RAMFILL
DEC HL
CP H
JR NZ,RAMFILL
11E2 RAMREAD
AND A
SBC HL,DE
ADD HL,DE
INC HL
JR NC,RAMDONE

DEC (HL)
JR Z,RAMDONE
DEC (HL)
JR Z,RAMDONE
11EF RAMDONE
DEC HL
EXX
LD (PRAMT),BC
LD (RASP/PIP),DE
LD (UDG),HL
EXX
;initialize the basic system variables
INC B
JR Z,RAMSET

;check whether the routine was
;called by NEW: NONEW
LD (PRAMT),HL
LD DE,3EAF
LD BC,00A8
EX DE,HL
LDDR
EX DE,HL
;copy the character shapes for
;graphics mode (UDG) into memory
INC HL
LD (UDG),HL
DEC HL

1219 RAMSET
LD (RAMTOP),HL
LD HL,3C00
LD (CHARS),HL
;refresh (set) the RAMTOP value
LD HL,(RAMTOP)
LD (HL),3E
DEC HL
LD SP,HL
;set the stack value
DEC HL
DEC HL
LD (ERRSP),HL
;error handling address

Next, the computer sets other variables needed to start operating, enables interrupts (keyboard scanning, FRAMES), and displays the message “Sinclair ...”.


Reading the keyboard

CALL #028E ;jump to SCANKEY
LD A,D
RET

Executing the jump to address #028E places the code of the pressed key in register D and in the LAST_K variable.


Displaying text

To display text on the screen, you need to open a channel for the PRINT routine.

This is done with the subroutine:

OPEN
RET

You can now print text using:

LD A,"character"

Share your thoughts about the article