[img] Tape Routines without BREAK error
 MDFS::Info.Comp.Spectrum.ProgTips.tape/htm Search  

The Spectrum ROM tape routines provide two main entry points - SA_BYTES and LD_BYTES. These two routines check for SPACE being pressed and generate an error if pressed. It is possible to call the tape routines and have them return instead of generate an error. Each routine starts by stacking SALD_RET which restores the border colour, restores interrupts and generates a BREAK error if SPACE is pressed. By calling just after this is done, the calling routine is returned to if SPACE is pressed. Annoyingly, there is no way of stopping the tape routines from aborting when just SPACE is pressed instead of SHIFT+SPACE.

Saving data

CALL &04C6       ; Call SA_BYTES+4
CALL TapeExit    ; Restore border, check SPACE, enable INTs

; On exit:
;   C    : Ok
;   NC   : SPACE pressed

Loading data

INC D
EX   AF,AF'      ; Set up flags
DEC  D
DI               ; Disable interupts
CALL &0562       ; Call LD_BYTES+12
CALL TapeExit    ; Restore border, check SPACE, enable INTs

; On exit:
;   C    : Ok
;   NC+NZ: loading error or verify error
;   NC+Z : SPACE pressed
After calling LD_BYTES+12 the SPACE key has to be checked to differentiate between a tape error and a BREAK error.

Restore border colour

After calling the tape routines the border colour has to be restored and interrupts enabled. This code also checks the SPACE key as LD_BYTES returns the same flags for BREAK and tape error.
.TapeExit
PUSH AF          ; Save return state
LD   A,(BORDCR)  ; Get border colour
AND  &38
RRCA
RRCA
RRCA
OUT  (&FE),A     ; Set border colour
POP  AF          ; Restore flags
EI               ; Enable interupts
RET  C           ; No error
LD   A,&7F
IN   A,(&FE)     ; Scan B-SPACE
AND  1           ; Check if SPACE pressed
RET              ; NZ=not pressed, Z=pressed

Best viewed with Any Browser Valid HTML 4.0! Hosted by Force9 Internet - Authored by J.G.Harston
Last update: 10-Jul-2005