Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ---------------------------------
- ; THE 'CASSETTE INTERFACE' ROUTINES
- ; ---------------------------------
- ; ---
- ; save to tape
- ; On entry: HL=address of block to save
- ; DE=size of block to save
- ; C =flag (00h = long pilot tone, FFh = short pilot tone)
- ; (actually, the routine only checks the 7th bit of C to determine which length of pilot tone to apply)
- ; ---
- L1820: PUSH IY
- PUSH HL
- POP IY ; IY = address of block
- LD HL,L1892
- PUSH HL ; 1892h is the return address for this routine
- LD HL,$E000
- BIT 7,C ; If C=00h
- JR Z,L1832 ; HL remains with value E000h
- LD H,$FC ; else, HL = FC00h
- L1832: INC DE ; make the block 1-byte longer because the first byte to output is already held in C, not in memory.
- DEC IY
- DI
- XOR A ; bit 3 of A will toggle between 0 and 1. We start with a low pulse.
- L1837: LD B,$97 ; Here begins the loop that outputs the pilot tone. Number of half-periods is 65536-HL.
- L1839: DJNZ L1839 ; 1963 t-states delay (length of a half-period)
- OUT ($FE),A
- XOR $08 ; Toggle MIC bit
- INC L
- JR NZ,L1843 ; Next half period
- INC H
- L1843: JR NZ,L1837 ; Until we reach 0000h in HL.
- LD B,$2B
- L1847: DJNZ L1847 ; First (high) sync pulse: 559 t-states
- OUT ($FE),A ; Set MIC to low.
- LD L,C ; L holds now the flag byte.
- LD BC,$3B08
- L184F: DJNZ L184F ; Second (low) sync pulse: 767 t-states
- LD A,C
- OUT ($FE),A ; Set MIC to high.
- LD B,$38
- JP L188A ;
- L1859: LD A,C
- BIT 7,B
- L185C: DJNZ L185C ; Delay a half-period of a 0 pulse (728 t-states)
- JR NC,L1864 ; If the bit being written is 0, don't add more delay and go right to the OUT part.
- LD B,$3D
- L1862: DJNZ L1862 ; if it was a 1, then add a delay so the total delay is the half-period of a 1 pulse (1521 t-states)
- L1864: OUT ($FE),A ; toogle MIC output.
- LD B,$3A
- JP NZ,L1859 ; Go to the head of the loop for writting bits
- DEC B
- XOR A
- ;Loop to output the eight bits of a byte
- L186D: RL L ; CF = bit 7 of L. CF holds the bit about to be written to the tape.
- JP NZ,L185C ; As long as L is not zero, there will be bits waiting for be outputted.
- DEC DE ; No more bits to transfer, so count one less byte in the byte counter...
- INC IY ; ... and point IY to the next byte to read.
- LD B,$2E
- LD A,$7F
- IN A,($FE) ; Time to check for SPACE(BREAK) pressed
- RRA
- RET NC ; jump to 1892h if so.
- LD A,D ; have we written all the bytes, *including* checksum?
- CP $FF
- RET NC ; jump to 1892h if so.
- OR E
- JR Z,L188F ; go write the checksum on tape if all the data bytes have been written.
- LD L,(IY+$00) ; if not, there's data left to write. Read in the next byte
- L1887: LD A,H ;
- XOR L ; Update the checksum byte (H)
- LD H,A ;
- L188A: XOR A ; and go again to write bits.
- SCF ; CF=1, so the first RL L executed will put a '1' in bit 0.
- JP L186D ; JUMP back
- ; ---
- L188F: LD L,H ; Load L with the checksum byte
- JR L1887 ; and go again to write bits.
- ; RETURN ADDRESS FOR THE SAVE ROUTINE.....
- L1892: POP IY ; restore the original IY value so that
- ; words can be used gain.
- EX AF,AF' ;;
- LD B,$3B ; end pulse: 767 t-states
- L1897: DJNZ L1897 ; self-loop for delay. Pulse high
- XOR A
- OUT ($FE),A ; MIC output to low.
- LD A,$7F ; read the port $7FFE
- IN A,($FE) ; keyrows SPACE to V.
- RRA
- EI ; Enable Interrupts.
- JP NC,L04F0 ; jump if SPACE pressed to Error 3
- ; 'BREAK pressed'.
- EX AF,AF' ;;
- RET ; return.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement