Prev: EA2E Up: Map Next: EB4C
EAAE: Sample Tape
Used by the routine at Control_Loading.
Custom turbo sampler. Before sampling it compares the loader's additive checksum in *Running_Checksum_Total against the expected value in *Expected_Checksum.
Input
IX Destination address for the block
DE Block length
A Expected flag byte; carry set to load, reset to verify
Output
F Carry is set on success
Refuse to load if the self-check total is wrong.
Sample_Tape EAAE PUSH DE Stash DE and AF on the stack.
EAAF PUSH AF
EAB0 LD HL,($E9E7) Jump to START if *Expected_Checksum does not equal *Running_Checksum_Total.
EAB3 LD DE,($E9E5)
EAB7 SCF
EAB8 CCF
EAB9 SBC HL,DE
EABB JP NZ,$0000
EABE POP AF Restore AF and DE from the stack.
EABF POP DE
Preserve the flag byte and blank the border.
EAC0 INC D Preserve the flag byte in AF'.
EAC1 EX AF,AF'
EAC2 DEC D
EAC3 DI Disable interrupts.
EAC4 LD A,$00 Set the border to black via port FE.
EAC6 OUT ($FE),A
EAC8 LD HL,$053F Set the initial timing budget in HL to 053F.
Seed the EAR/border state in C from the current EAR bit.
EACB IN A,($FE) Read the EAR port.
EACD RRA Rotate the EAR bit into bit 0 of A.
EACE AND %00100000 Keep only the EAR bit.
EAD0 OR %00000010 Set the blue border bit.
EAD2 LD C,A Copy the EAR/border state into C and set the zero flag.
EAD3 CP A
Wait for the pilot tone.
Sample_Tape_WaitPilot EAD4 RET NZ Return if the zero flag is reset (BREAK was pressed).
Listen for a pair of edges that look like the pilot.
Sample_Tape_PilotPair EAD5 CALL Sample_Edge_Wait Jump back to Sample_Tape_WaitPilot if Sample_Edge_Wait resets the carry flag.
EAD8 JR NC,Sample_Tape_WaitPilot
EADA LD HL,$0415 Set the leader timing budget in HL to 0415.
Exhaust the leader timing budget while edges continue to arrive.
Sample_Tape_LeaderDelay EADD DJNZ Sample_Tape_LeaderDelay Decrease B and loop until it is zero.
EADF DEC HL Decrease HL.
EAE0 LD A,H Jump back to Sample_Tape_LeaderDelay if HL is non-zero.
EAE1 OR L
EAE2 JR NZ,Sample_Tape_LeaderDelay
EAE4 CALL Sample_Edge Jump back to Sample_Tape_WaitPilot if Sample_Edge resets the carry flag.
EAE7 JR NC,Sample_Tape_WaitPilot
Confirm a long enough run of short pilot pulses.
Sample_Tape_PilotPulse EAE9 LD B,$9C Set the pulse timing constant in B to 9C.
EAEB CALL Sample_Edge Jump back to Sample_Tape_WaitPilot if Sample_Edge resets the carry flag.
EAEE JR NC,Sample_Tape_WaitPilot
EAF0 LD A,$A6 Jump back to Sample_Tape_PilotPair if B is at least A6.
EAF2 CP B
EAF3 JR NC,Sample_Tape_PilotPair
EAF5 INC H Increase H by one and jump back to Sample_Tape_PilotPulse until it wraps.
EAF6 JR NZ,Sample_Tape_PilotPulse
Wait for the sync pulse that ends the pilot.
Sample_Tape_Sync EAF8 LD B,$C9 Set the sync timing constant in B to C9.
EAFA CALL Sample_Edge_Wait Jump back to Sample_Tape_WaitPilot if Sample_Edge_Wait resets the carry flag.
EAFD JR NC,Sample_Tape_WaitPilot
EAFF LD A,B Jump back to Sample_Tape_Sync if B is at least D4.
EB00 CP $D4
EB02 JR NC,Sample_Tape_Sync
EB04 CALL Sample_Edge_Wait Call Sample_Edge_Wait and return if the carry flag is reset.
EB07 RET NC
Flip the border colour and start the byte-load loop.
EB08 LD A,C Fetch the EAR/border state from C.
EB09 XOR %00000011 Toggle the border colour bits.
EB0B LD C,A Store the updated EAR/border state in C.
EB0C LD H,$00 Clear the parity byte in H.
First-byte B timing, patched by Patch_Timing.
Sample_Tape_First_Byte_Timing EB0E LD B,$B0 Set B to the patched first-byte timing constant.
EB10 JR Sample_Tape_SampleByte Jump to Sample_Tape_SampleByte.
Handle each loaded byte under the preserved flag in AF'.
Sample_Tape_NextByte EB12 EX AF,AF' Switch to AF'.
EB13 JR NZ,Sample_Tape_FlagByte Jump to Sample_Tape_FlagByte if the flag byte is not zero.
EB15 JR NC,Sample_Tape_VerifyByte Jump to Sample_Tape_VerifyByte if the carry flag is reset (verify mode).
EB17 LD (IX+$00),L Store the assembled byte in *IX+00.
EB1A JR Sample_Tape_Advance Jump to Sample_Tape_Advance.
Compare the assembled byte against the expected flag byte.
Sample_Tape_FlagByte EB1C RL C Rotate the stored flag bits in C.
EB1E XOR L Return if the assembled byte does not match.
EB1F RET NZ
EB20 LD A,C Restore C from the rotated value.
EB21 RRA
EB22 LD C,A
EB23 INC DE Advance DE past the flag byte.
EB24 JR Sample_Tape_Continue Jump to Sample_Tape_Continue.
Verify the assembled byte against *IX.
Sample_Tape_VerifyByte EB26 LD A,(IX+$00) Return if *IX+00 does not match the assembled byte.
EB29 XOR L
EB2A RET NZ
Advance the destination and continue for the remaining length.
Sample_Tape_Advance EB2B INC IX Advance IX.
Prepare the timing constant for the next byte.
Sample_Tape_Continue EB2D DEC DE Decrease the remaining length.
EB2E EX AF,AF' Switch back to AF'.
Next-byte B timing, patched by Patch_Timing.
Sample_Tape_Next_Byte_Timing EB2F LD B,$B2 Set B to the patched next-byte timing constant.
Sample eight edges to assemble the next byte into L.
Sample_Tape_SampleByte EB31 LD L,$01 Seed the assembled byte in L with 01.
Sample one bit into L.
Sample_Tape_SampleBit EB33 CALL Sample_Edge Call Sample_Edge and return if the carry flag is reset.
EB36 RET NC
Bit-threshold comparison, patched by Patch_Timing.
Sample_Tape_Bit_Threshold EB37 LD A,$CB Compare B with the patched bit-threshold.
EB39 CP B
EB3A RL L Rotate that comparison result into L.
Bit-loop B timing, patched by Patch_Timing.
Sample_Tape_Bit_Loop EB3C LD B,$B0 Set B to the patched bit-loop timing constant.
EB3E JP NC,Sample_Tape_SampleBit Jump back to Sample_Tape_SampleBit until eight bits are in.
EB41 LD A,H Mix the assembled byte into the running parity in H.
EB42 XOR L
EB43 LD H,A
EB44 LD A,D Jump back to Sample_Tape_NextByte until the remaining length in DE is zero.
EB45 OR E
EB46 JR NZ,Sample_Tape_NextByte
EB48 LD A,H Compare the parity byte with 01.
EB49 CP $01
EB4B RET Return.
Prev: EA2E Up: Map Next: EB4C