Prev: 01194 Up: Map Next: 01343
01218: THE 'SA-BYTES' SUBROUTINE
Used by the routine at SA_CONTRL.
This subroutine is called to save the header information and later the actual program/data block to tape.
Input
A 0 (header block) or 255 (data block)
DE Block length
IX Start address
SA_BYTES 01218 LD HL,1343 Pre-load the machine stack with the address SA_LD_RET.
01221 PUSH HL
01222 LD HL,8064 This constant will give a leader of about 5 seconds for a 'header'.
01225 BIT 7,A Jump forward if saving a header.
01227 JR Z,SA_FLAG
01229 LD HL,3224 This constant will give a leader of about 2 seconds for a program/data block.
SA_FLAG 01232 EX AF,AF' The flag is saved.
01233 INC DE The 'length' is incremented and the 'base address' reduced to allow for the flag.
01234 DEC IX
01236 DI The maskable interrupt is disabled during the save.
01237 LD A,2 Signal 'MIC on' and border to be red.
01239 LD B,A Give a value to B.
A loop is now entered to create the pulses of the leader. Both the 'MIC on' and the 'MIC off' pulses are 2,168 T states in length. The colour of the border changes from red to cyan with each 'edge'.
Note: an 'edge' will be a transition either from 'on' to 'off', or from 'off' to 'on'.
SA_LEADER 01240 DJNZ SA_LEADER The main timing period.
01242 OUT (254),A MIC on/off, border red/cyan, on each pass.
01244 XOR 15
01246 LD B,164 The main timing constant.
01248 DEC L Decrease the low counter.
01249 JR NZ,SA_LEADER Jump back for another pulse.
01251 DEC B Allow for the longer path (reduce by 13 T states).
01252 DEC H Decrease the high counter.
01253 JP P,SA_LEADER Jump back for another pulse until completion of the leader.
A sync pulse is now sent.
01256 LD B,47
SA_SYNC_1 01258 DJNZ SA_SYNC_1 MIC off for 667 T states from 'OUT to OUT'.
01260 OUT (254),A MIC on and red.
01262 LD A,13 Signal 'MIC off and cyan'.
01264 LD B,55 MIC on for 735 T States from 'OUT to OUT'.
SA_SYNC_2 01266 DJNZ SA_SYNC_2
01268 OUT (254),A Now MIC off and border cyan.
The header v. program/data flag will be the first byte to be saved.
01270 LD BC,15118 59 is a timing constant; 14 signals 'MIC off and yellow'.
01273 EX AF,AF' Fetch the flag and pass it to the L register for 'sending'.
01274 LD L,A
01275 JP SA_START Jump forward into the saving loop.
The byte saving loop is now entered. The first byte to be saved is the flag; this is followed by the actual data bytes and the final byte sent is the parity byte that is built up by considering the values of all the earlier bytes.
SA_LOOP 01278 LD A,D The 'length' counter is tested and the jump taken when it has reached zero.
01279 OR E
01280 JR Z,SA_PARITY
01282 LD L,(IX+0) Fetch the next byte that is to be saved.
SA_LOOP_P 01285 LD A,H Fetch the current 'parity'.
01286 XOR L Include the present byte.
SA_START 01287 LD H,A Restore the 'parity'. Note that on entry here the 'flag' value initialises 'parity'.
01288 LD A,1 Signal 'MIC on and blue'.
01290 SCF Set the carry flag. This will act as a 'marker' for the 8 bits of a byte.
01291 JP SA_8_BITS Jump forward.
When it is time to send the 'parity' byte then it is transferred to the L register for saving.
SA_PARITY 01294 LD L,H Get final 'parity' value.
01295 JR SA_LOOP_P Jump back.
The following inner loop produces the actual pulses. The loop is entered at SA_BIT_1 with the type of the bit to be saved indicated by the carry flag. Two passes of the loop are made for each bit thereby making an 'off pulse' and an 'on pulse'. The pulses for a reset bit are shorter by 855 T states.
SA_BIT_2 01297 LD A,C Come here on the second pass and fetch 'MIC off and yellow'.
01298 BIT 7,B Set the zero flag to show 'second pass'.
SA_BIT_1 01300 DJNZ SA_BIT_1 The main timing loop; always 801 T states on a second pass.
01302 JR NC,SA_OUT Jump, taking the shorter path, if saving a '0'.
01304 LD B,66 However if saving a '1' then add 855 T states.
SA_SET 01306 DJNZ SA_SET
SA_OUT 01308 OUT (254),A On the first pass 'MIC on and blue' and on the second pass 'MIC off and yellow'.
01310 LD B,62 Set the timing constant for the second pass.
01312 JR NZ,SA_BIT_2 Jump back at the end of the first pass; otherwise reclaim 13 T states.
01314 DEC B
01315 XOR A Clear the carry flag and set A to hold 1 (MIC on and blue) before continuing into the '8 bit loop'.
01316 INC A
The '8 bit loop' is entered initially with the whole byte in the L register and the carry flag set. However it is re-entered after each bit has been saved until the point is reached when the 'marker' passes to the carry flag leaving the L register empty.
SA_8_BITS 01317 RL L Move bit 7 to the carry and the 'marker' leftwards.
01319 JP NZ,SA_BIT_1 Save the bit unless finished with the byte.
01322 DEC DE Decrease the 'counter'.
01323 INC IX Advance the 'base address'.
01325 LD B,49 Set the timing constant for the first bit of the next byte.
01327 LD A,127 Return (to SA_LD_RET) if the BREAK key is being pressed.
01329 IN A,(254)
01331 RRA
01332 RET NC
01333 LD A,D Otherwise test the 'counter' and jump back even if it has reached zero (so as to send the 'parity' byte).
01334 INC A
01335 JP NZ,SA_LOOP
01338 LD B,59 Exit when the 'counter' reaches 65535. But first give a short delay.
SA_DELAY 01340 DJNZ SA_DELAY
01342 RET
Note: a reset bit will give a 'MIC off' pulse of 855 T states followed by a 'MIC on' pulse of 855 T states, whereas a set bit will give pulses of exactly twice as long. Note also that there are no gaps either between the sync pulse and the first bit of the flag, or between bytes.
Prev: 01194 Up: Map Next: 01343