; DE Number of passes to make through the sound generation loop
; HL Loop delay parameter
;RTCIO .EQU $70
RTCVAL.EQU0
;
SPK_BEEPER:
PUSHIX
DI; Disable the interrupt for the duration of a 'beep'.
LDA,L; Save L temporarily.
SRLL; Each '1' in the L register is to count 4 T states, but take INT (L/4) and count 16 T states instead.
DI; Disable the interrupt for the duration of a 'beep'.
LDA,L; Save L temporarily.
SRLL; Each '1' in the L register is to count 4 T states, but take INT (L/4) and count 16 T states instead.
SRLL
CPL; Go back to the original value in L and find how many were lost by taking 3-(A mod 4).
CPL; Go back to the original value in L and find how many were lost by taking 3-(A mod 4).
AND$03
LDC,A
LDB,$00
LDIX,SPK_DLYADJ; The base address of the timing loop.
ADDIX,BC; Alter the length of the timing loop. Use an earlier starting point for each '1' lost by taking INT (L/4).
LDA,(RTCVAL); Fetch the present border colour from BORDCR and move it to bits 2, 1 and 0 of the A register.
LDIX,SPK_DLYADJ; The base address of the timing loop.
ADDIX,BC; Alter the length of the timing loop. Use an earlier starting point for each '1' lost by taking INT (L/4).
LDA,(RTCVAL); Fetch the present border colour from BORDCR and move it to bits 2, 1 and 0 of the A register.
;
; The HL register holds the 'length of the timing loop' with 16 T states being used for each '1' in the L register and 1024 T states for each '1' in the H register.
;
SPK_DLYADJ:
NOP; Add 4 T states for each earlier entry point that is used.
NOP; Add 4 T states for each earlier entry point that is used.
NOP
NOP
INCB; The values in the B and C registers will come from the H and L registers - see below.
INCB; The values in the B and C registers will come from the H and L registers - see below.
INCC
BE_H_L_LP:
DECC; The 'timing loop', i.e. BC*4 T states. (But note that at the half-cycle point, C will be equal to L+1.)
DECC; The 'timing loop', i.e. BC*4 T states. (But note that at the half-cycle point, C will be equal to L+1.)
JRNZ,BE_H_L_LP
LDC,$3F
DECB
JPNZ,BE_H_L_LP
;
; The loudspeaker is now alternately activated and deactivated.
;
XOR%00000100; Flip bit 2.
OUT(RTCIO),A; Perform the 'OUT' operation, leaving other bits unchanged.
LDB,H; Reset the B register.
LDC,A; Save the A register.
BIT4,A; Jump if at the half-cycle point.
XOR%00000100; Flip bit 2. The loudspeaker is now alternately activated and deactivated.
OUT(RTCIO),A; Perform the 'OUT' operation, leaving other bits unchanged.
LDB,H; Reset the B register.
LDC,A; Save the A register.
BIT4,A; Jump if at the half-cycle point.
JRNZ,BE_AGAIN
;
; After a full cycle the DE register pair is tested.
;
LDA,D; Jump forward if the last complete pass has been made already.
LDA,D; After a full cycle the DE register pair is tested.
ORE
JRZ,BE_END
LDA,C; Fetch the saved value.
LDC,L; Reset the C register.
DECDE; Decrease the pass counter.
JP(IX); Jump back to the required starting location of the loop.
;
; The parameters for the second half-cycle are set up.
JRZ,BE_END; Jump forward if the last complete pass has been made already.
LDA,C; Fetch the saved value.
LDC,L; Reset the C register.
DECDE; Decrease the pass counter.
JP(IX); Jump back to the required starting location of the loop.
;
BE_AGAIN:
LDC,L; Reset the C register.
INCC; Add 16 T states as this path is shorter.
JP(IX); Jump back.
BE_END:
EI
BE_AGAIN:; The parameters for the second half-cycle are set up.
LDC,L; Reset the C register.
INCC; Add 16 T states as this path is shorter.
JP(IX); Jump back.
BE_END:EI
POPIX
RET
;
RTCVAL.DB0
;
; SETUP THE ONE SECOND TONE DURATION TABLE BASED ON PROCESSOR SPEED AND TONE FREQUENCY