2018-01-28 18:30:49 +00:00
|
|
|
; C02 library stdio.h02 assembly language subroutines
|
|
|
|
; Requires external routines GETKEY, prchr, delchr, and NEWLIN
|
|
|
|
; external zero page locations SRCLO and SRCHI
|
|
|
|
; and external constants DELKEY, ESCKEY, and RTNKEY
|
2018-02-02 21:33:57 +00:00
|
|
|
;char getc()
|
|
|
|
GETC EQU GETKEY ;Alias to external GETKEY routine
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-02-02 21:33:57 +00:00
|
|
|
;void putc(c)
|
|
|
|
PUTC EQU PRCHR ;Alias to external PRCHR Routine
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2018-02-02 21:33:57 +00:00
|
|
|
;char gets(&s)
|
|
|
|
GETS: JSR SETSRC ;Initialize Source String
|
|
|
|
GETSL: JSR GETC ;Get Keypress
|
|
|
|
CMP #DELKEY ;If Delete
|
|
|
|
BNE GETSE ;Then
|
2018-01-28 18:30:49 +00:00
|
|
|
TYA ; If Offset is Zero
|
2018-02-02 21:33:57 +00:00
|
|
|
BEQ GETSL ; Get Next Character
|
2018-01-28 18:30:49 +00:00
|
|
|
DEY ; Else Decrement Offset
|
|
|
|
JSR DELCHR ; Delete Previous Character
|
2018-02-02 21:33:57 +00:00
|
|
|
JMP GETSL ; and Get Next Character
|
|
|
|
GETSE: CMP #ESCKEY ;Else If Escape
|
|
|
|
BNE GETSC ;Then
|
2018-01-28 18:30:49 +00:00
|
|
|
LDY #$FF ; Return -1
|
2018-02-02 21:33:57 +00:00
|
|
|
BNE GETSY
|
|
|
|
GETSC: CMP #RTNKEY ;Else If Not Carriage Return
|
|
|
|
BEQ GETSX
|
|
|
|
JSR PUTC ; Echo Character
|
2018-01-28 18:30:49 +00:00
|
|
|
STA (SRCLO),Y ; Store Character at offset
|
|
|
|
INY ; increment offset and
|
2018-02-02 21:33:57 +00:00
|
|
|
BPL GETSL ; loop if less than 128
|
|
|
|
GETSX: JSR NEWLIN ;Else Advance Cursor to Next Line
|
2018-01-28 18:30:49 +00:00
|
|
|
LDA #$00 ; Terminate String
|
|
|
|
STA (SRCLO),Y ; and
|
2018-02-02 21:33:57 +00:00
|
|
|
GETSY: TYA ; Return String Length
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS
|
|
|
|
|
2018-02-02 21:33:57 +00:00
|
|
|
;char puts(n, &s)
|
|
|
|
PUTS: LDA #$00 ;Set Start Position to 0
|
|
|
|
;and fall into putsub
|
|
|
|
;char putsub(n, &s)
|
|
|
|
PUTSUB: JSR SETSRC ;Initialize Source String
|
2018-01-28 18:30:49 +00:00
|
|
|
TAY ;Initialize character offset
|
2018-02-02 21:33:57 +00:00
|
|
|
PUTSUL: LDA (SRCLO),Y ;Read next character in string
|
|
|
|
BEQ PUTSUX ;If Not 0
|
|
|
|
JSR PUTC ; Print character at offset,
|
2018-01-28 18:30:49 +00:00
|
|
|
INY ; increment offset, and
|
2018-02-02 21:33:57 +00:00
|
|
|
BPL PUTSUL ; loop if less than 128
|
|
|
|
PUTSUX: TAY ;Return number of
|
2018-01-28 18:30:49 +00:00
|
|
|
RTS ; characters printed
|
|
|
|
|
2018-02-02 21:33:57 +00:00
|
|
|
;char putln(&s)
|
|
|
|
PUTLN: JSR PUTS ;Write string to screen
|
2018-01-28 18:30:49 +00:00
|
|
|
JMP NEWLIN ;Call external NEWLINe routine and return
|