| Routines

08673: THE 'COLOUR ITEM' ROUTINES

This set of routines can be readily divided into two parts: i. The embedded colour item' handler. ii. The 'colour system variable' handler. i. Embedded colour items are handled by calling PRINT_A_1 as required. A loop is entered to handle each item in turn. The entry point is at CO_TEMP_2.
CO_TEMP_1 | 08673 | RST 32 | Consider the next character in the BASIC statement.
This entry point is used by the routine at CLASS_09.
CO_TEMP_2 | 08674 | CALL CO_TEMP_3 | Jump forward to see if the present code represents an embedded 'temporary' colour item. Return carry set if not a colour item.
| 08677 | RET C
| 08678 | RST 24 | Fetch the present character.
| 08679 | CP "," | Jump back if it is either a ',' or a ';'; otherwise there has been an error.
| 08681 | JR Z,CO_TEMP_1
| 08683 | CP ";"
| 08685 | JR Z,CO_TEMP_1
| 08687 | JP REPORT_C | Exit via 'report C'.
This entry point is used by the routine at PR_ITEM_1.
CO_TEMP_3 | 08690 | CP 217 | Return with the carry flag set if the code is not in the range 217 to 222 (INK to OVER).
| 08692 | RET C
| 08693 | CP 223
| 08695 | CCF
| 08696 | RET C
| 08697 | PUSH AF | The colour item code is preserved whilst CH-ADD is advanced to address the parameter that follows it.
| 08698 | RST 32
| 08699 | POP AF
This entry point is used by the routine at CLASS_07. The colour item code and the parameter are now 'printed' by calling PRINT_A_1 on two occasions.
CO_TEMP_4 | 08700 | SUB 201 | The token range (217 to 222) is reduced to the control character range (16 to 21).
| 08702 | PUSH AF | The control character code is preserved whilst the parameter is moved to the calculator stack.
| 08703 | CALL CLASS_06
| 08706 | POP AF
| 08707 | AND A | A return is made at this point if syntax is being checked.
| 08708 | CALL UNSTACK_Z
| 08711 | PUSH AF | The control character code is preserved whilst the parameter is moved to the D register.
| 08712 | CALL FIND_INT1
| 08715 | LD D,A
| 08716 | POP AF
| 08717 | RST 16 | The control character is sent out.
| 08718 | LD A,D | Then the parameter is fetched and sent out before returning.
| 08719 | RST 16
| 08720 | RET
This entry point is used by the routine at PO_TV_2. ii. The colour system variables - ATTR-T, MASK-T and P-FLAG - are altered as required. On entry the control character code is in the A register and the parameter is in the D register. Note that all changes are to the 'temporary' system variables.
CO_TEMP_5 | 08721 | SUB 17 | Reduce the range and jump forward with INK and PAPER.
| 08723 | ADC A,0
| 08725 | JR Z,CO_TEMP_7
| 08727 | SUB 2 | Reduce the range once again and jump forward with FLASH and BRIGHT.
| 08729 | ADC A,0
| 08731 | JR Z,CO_TEMP_C
The colour control code will now be 1 for INVERSE and 2 for OVER and the system variable P-FLAG is altered accordingly.
| 08733 | CP 1 | Prepare to jump with OVER.
| 08735 | LD A,D | Fetch the parameter.
| 08736 | LD B,1 | Prepare the mask for OVER.
| 08738 | JR NZ,CO_TEMP_6 | Now jump.
| 08740 | RLCA | Bit 2 of the A register is to be reset for INVERSE 0 and set for INVERSE 1; the mask is to have bit 2 set.
| 08741 | RLCA
| 08742 | LD B,4
CO_TEMP_6 | 08744 | LD C,A | Save the A register whilst the range is tested.
| 08745 | LD A,D | The correct range for INVERSE and OVER is only '0-1'.
| 08746 | CP 2
| 08748 | JR NC,REPORT_K
| 08750 | LD A,C | Restore the A register.
| 08751 | LD HL,23697 | It is P-FLAG that is to be changed.
| 08754 | JR CO_CHANGE | Exit via CO_CHANGE and alter P-FLAG using B as a mask, i.e. bit 0 for OVER and bit 2 for INVERSE.
PAPER and INK are dealt with by the following routine. On entry the carry flag is set for INK.
CO_TEMP_7 | 08756 | LD A,D | Fetch the parameter.
| 08757 | LD B,7 | Prepare the mask for INK.
| 08759 | JR C,CO_TEMP_8 | Jump forward with INK.
| 08761 | RLCA | Multiply the parameter for PAPER by eight.
| 08762 | RLCA
| 08763 | RLCA
| 08764 | LD B,56 | Prepare the mask for PAPER.
CO_TEMP_8 | 08766 | LD C,A | Save the parameter in the C register whilst the range of the parameter is tested.
| 08767 | LD A,D | Fetch the original value.
| 08768 | CP 10 | Only allow PAPER/INK a range of '0' to '9'.
| 08770 | JR C,CO_TEMP_9
This entry point is used by the routine at BORDER. Report K - Invalid colour.
REPORT_K | 08772 | RST 8 | Call the error handling routine.
| 08773 | DEFB 19
Continue to handle PAPER and INK.
CO_TEMP_9 | 08774 | LD HL,23695 | Prepare to alter ATTR-T, MASK-T and P-FLAG.
| 08777 | CP 8 | Jump forward with PAPER/INK '0' to '7'.
| 08779 | JR C,CO_TEMP_B
| 08781 | LD A,(HL) | Fetch the current value of ATTR-T and use it unchanged, by jumping forward, with PAPER/INK '8'.
| 08782 | JR Z,CO_TEMP_A
| 08784 | OR B | But for PAPER/INK '9' the PAPER and INK colours have to be black and white.
| 08785 | CPL
| 08786 | AND 36
| 08788 | JR Z,CO_TEMP_A | Jump for black INK/PAPER, but continue for white INK/PAPER.
| 08790 | LD A,B
CO_TEMP_A | 08791 | LD C,A | Move the value to the C register.
The mask (B) and the value (C) are now used to change ATTR-T.
CO_TEMP_B | 08792 | LD A,C | Move the value.
| 08793 | CALL CO_CHANGE | Now change ATTR-T as needed.
Next MASK-T is considered.
| 08796 | LD A,7 | The bits of MASK-T are set only when using PAPER/INK '8' or '9'.
| 08798 | CP D
| 08799 | SBC A,A
| 08800 | CALL CO_CHANGE | Now change MASK-T as needed.
Next P-FLAG is considered.
| 08803 | RLCA | The appropriate mask is built up in the B register in order to change bits 4 and 6 as necessary.
| 08804 | RLCA
| 08805 | AND 80
| 08807 | LD B,A
| 08808 | LD A,8 | The bits of P-FLAG are set only when using PAPER/INK '9'. Continue into CO_CHANGE to manipulate P-FLAG.
| 08810 | CP D
| 08811 | SBC A,A
The following subroutine is used to 'impress' upon a system variable the 'nature' of the bits in the A register. The B register holds a mask that shows which bits are to be 'copied over' from A to (HL).
CO_CHANGE | 08812 | XOR (HL) | The bits, specified by the mask in the B register, are changed in the value and the result goes to form the system variable.
| 08813 | AND B
| 08814 | XOR (HL)
| 08815 | LD (HL),A
| 08816 | INC HL | Move on to address the next system variable.
| 08817 | LD A,B | Return with the mask in the A register.
| 08818 | RET
FLASH and BRIGHT are handled by the following routine.
CO_TEMP_C | 08819 | SBC A,A | The zero flag will be set for BRIGHT.
| 08820 | LD A,D | The parameter is fetched and rotated.
| 08821 | RRCA
| 08822 | LD B,128 | Prepare the mask for FLASH.
| 08824 | JR NZ,CO_TEMP_D | Jump forward with FLASH.
| 08826 | RRCA | Rotate an extra time and prepare the mask for BRIGHT.
| 08827 | LD B,64
CO_TEMP_D | 08829 | LD C,A | Save the value in the C register.
| 08830 | LD A,D | Fetch the parameter and test its range; only '0', '1' and '8' are allowable.
| 08831 | CP 8
| 08833 | JR Z,CO_TEMP_E
| 08835 | CP 2
| 08837 | JR NC,REPORT_K
The system variable ATTR-T can now be altered.
CO_TEMP_E | 08839 | LD A,C | Fetch the value.
| 08840 | LD HL,23695 | This is ATTR-T.
| 08843 | CALL CO_CHANGE | Now change the system variable.
The value in MASK-T is now considered.
| 08846 | LD A,C | The value is fetched anew.
| 08847 | RRCA | The set bit of FLASH/BRIGHT '8' (bit 3) is moved to bit 7 (for FLASH) or bit 6 (for BRIGHT).
| 08848 | RRCA
| 08849 | RRCA
| 08850 | JR CO_CHANGE | Exit via CO_CHANGE.