This the multi-page printable view of this section.Click here to print.

Return to the regular view of this page.

CHRIN

Get a character from the input channel

Table of Contents

Function AddressDescription
CHRIN FFCFGet a character from the input channel

This routine gets a byte of data from a channel already set up as the input channel by the CHKIN routine. If CHKIN has NOT been used to define another input channel, then all your data is expected from the keyboard.

The data byte is returned in the accumulator. The Y index register is unchanged and is usually used in a loop to store received characters.

The channel remains open after the call.

Reading from the Keyboard

Input from the keyboard is handled in a special way. First, the cursor is turned on, and blinks until a carriage return is typed on the keyboard. All characters on the line can be retrieved one at a time by calling this routine once for each character. When the carriage return is retrieved, the entire line has been processed. The next time this routine is called, the whole process begins again, i.e., by flashing the cursor.

Example:

.readLine   LDY #0              ; Prepare Y register to store data
.readLoop   JSR CHRIN           ; Get next character
            STA BUF,Y           ; Store in BUF (0x200 89 byte basic input buffer)
            INY
            CMP #0x0D           ; Carriage Return
            BNE readLoop        ; Loop back for next character
            RTS
Example:
readLineLDY#0Prepare Y register to store data
readLoopJSRCHRINGet next character
STABUF,YStore in BUF (0x200 89 byte basic input buffer)
INY
CMP#0x0DCheck for Carriage Return
BNEreadLoopLoop back to the next character
RTS

This example does no bounds checking so if more than 89 characters are read it will overwrite the Kernal workspace in page 2.

Reading from other devices

Here you need to call OPEN and CHKIN first before calling CHRIN.