mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-29 01:49:19 +00:00
55 lines
2.0 KiB
Plaintext
55 lines
2.0 KiB
Plaintext
|
; 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
|
||
|
;char getchr()
|
||
|
GETCHR EQU GETKEY ;Alias to external GETKEY routine
|
||
|
|
||
|
;void putchr(c)
|
||
|
PUTCHR EQU PRCHR ;Alias to external PRCHR Routine
|
||
|
|
||
|
;char getstr(&s)
|
||
|
GETSTR: JSR SETSRC ;Initialize Source String
|
||
|
GETSTL: JSR GETCHR ;Get Keypress
|
||
|
GETSTD: CMP #DELKEY ;If Delete
|
||
|
BNE GETSTE ;Then
|
||
|
TYA ; If Offset is Zero
|
||
|
BEQ GETSTL ; Get Next Character
|
||
|
DEY ; Else Decrement Offset
|
||
|
JSR DELCHR ; Delete Previous Character
|
||
|
JMP GETSTL ; and Get Next Character
|
||
|
GETSTE: CMP #ESCKEY ;Else If Escape
|
||
|
BNE GETSTC ;Then
|
||
|
LDY #$FF ; Return -1
|
||
|
BNE GETSTY
|
||
|
GETSTC: CMP #RTNKEY ;Else If Not Carriage Return
|
||
|
BEQ GETSTX
|
||
|
JSR PUTCHR ; Echo Character
|
||
|
STA (SRCLO),Y ; Store Character at offset
|
||
|
INY ; increment offset and
|
||
|
BPL GETSTL ; loop if less than 128
|
||
|
GETSTX: JSR NEWLIN ;Else Advance Cursor to Next Line
|
||
|
LDA #$00 ; Terminate String
|
||
|
STA (SRCLO),Y ; and
|
||
|
GETSTY: TYA ; Return String Length
|
||
|
RTS
|
||
|
|
||
|
;char outstr(n, &s)
|
||
|
OUTSTR: LDA #$00 ;Set Start Position to 0
|
||
|
;and fall into outsub
|
||
|
;char outsub(n, &s)
|
||
|
OUTSUB: JSR SETSRC ;Initialize Source String
|
||
|
TAY ;Initialize character offset
|
||
|
OUTSUL: LDA (SRCLO),Y ;Read next character in string
|
||
|
BEQ OUTSUX ;If Not 0
|
||
|
JSR PUTCHR ; Print character at offset,
|
||
|
INY ; increment offset, and
|
||
|
BPL OUTSUL ; loop if less than 128
|
||
|
OUTSUX: TAY ;Return number of
|
||
|
RTS ; characters printed
|
||
|
|
||
|
;char putstr(*s)
|
||
|
PUTSTR: JSR OUTSTR ;Write string to screen
|
||
|
JMP NEWLIN ;Call external NEWLINe routine and return
|
||
|
|