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

  • by daytona400f

random musings


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 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

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

Leave a Comment

You must be signed-in to post comments.