| Routines

1601: THE 'CHAN-OPEN' SUBROUTINE

Used by the routines at SAVE_ETC, SA_CONTRL, PO_SCR, CLS, CL_ALL, ED_EDIT, ED_UP, MAIN_EXEC, LIST, LPRINT, STR_ALTER, INPUT, str and read_in. This subroutine is called with the A register holding a valid stream number - normally +FD to +03. Then depending on the stream data a particular channel will be made the current channel.
Input
A | Stream number
CHAN_OPEN | 1601 | ADD A,A | The value in the A register is doubled and then increased by +16.
| 1602 | ADD A,$16
| 1604 | LD L,A | The result is moved to L.
| 1605 | LD H,$5C | The address 5C16 is the base address for stream +00.
| 1607 | LD E,(HL) | Fetch the first two bytes of the required stream's data.
| 1608 | INC HL
| 1609 | LD D,(HL)
| 160A | LD A,D | Give an error if both bytes are zero; otherwise jump forward.
| 160B | OR E
| 160C | JR NZ,CHAN_OP_1
This entry point is used by the routine at STR_ALTER. Report O - Invalid stream.
REPORT_O | 160E | RST $08 | Call the error handling routine.
| 160F | DEFB $17
Using the stream data now find the base address of the channel information associated with that stream.
CHAN_OP_1 | 1610 | DEC DE | Reduce the stream data.
| 1611 | LD HL,($5C4F) | The base address of the whole channel information area (CHANS).
| 1614 | ADD HL,DE | Form the required address in this area.
This routine continues into CHAN_FLAG.