• --==<Rik's Blog>==--

  • by daytona400f

random musings

Nov
30

C128 RS232: get a line in ML

C128 RS232: get a line in ML

Wrote this up last night in CBM Program Studio. It builds a string of chars from Commodore Server, from the userport, and then exits when CS sends a CHR$(4).  it also gets rid of any formatting like CR and LF.  It stores the chars starting at $1301.   $1300 is the counter, so the string is limited to 255 bytes. This program assumes you've already opened the rs232 port in BASIC.   (open2,2,2,chr$(10) --2400 baud --the basic line to run this is included below)  

I would like a way to check if there is RS232 data waiting, and exit the code is there isnt. Not sure how to do this tho... That way I could call this routine from BASIC, if there is data, grab it, if there isnt, exit routine.   ideas?

*=$0b00

; $0B00 or $1300 are good locations to stash code. stay in BANK15, or suffer
; USE BLOAD "filename"
; 10 bank 15:open 2,2,2,chr$(10):print#2,"asd":sysdec("0b00") -tickle CS so it sends us data

CLRCH = $FFCC   ; reset normal I/O sources: input from the keyboard and output to the screen. (CLRCHM on 64)
BSOUT = $FFD2   ; Character to send in .A to current output device
CHKIN =  $FFC6  ; specifies a logical file as the source of GETIN input
GETIN =  $FFE4  ; retrieves a character from the current input device in .A
CKOUT = $FFC9   ; specify Output file in .X
CSCT = $1300
CSDATA = $1301

START
        LDX #$00    ;reset counter to 0
        STX CSCT    ;store reset
        LDX #$02    ;set device to rs232
        JSR CHKIN   ;02 = rs232
READ_STATUS
        JSR GETIN             ; retrieves a character from RS232 and store in .A
CHECK_INCOMING
        CMP #$00              ;Nothing?
        BEQ READ_STATUS      
        CMP #$04              ; if CS EOT char. chr$(4)  exit program
        BEQ END
        CMP #$0A              ; no pesky line feeds
        BEQ READ_STATUS
        CMP #$0D              ; carriage return
        BEQ READ_STATUS       
        JSR BSOUT             ; Send .A to screen 
STORE_INCOMING
       LDX CSCT              ;load up current position for saving chars
       STA CSDATA,x
       INX
       STX CSCT             ;store new position
       JMP READ_STATUS
END
    JSR CLRCH ; reset normal I/O or returning to BASIC is a bummer. 
    RTS

Leave a Comment

You must be signed-in to post comments.

Responses