1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-26 13:49:21 +00:00
C02/include/stdio.a02

81 lines
2.9 KiB
Plaintext
Raw Normal View History

2018-01-28 18:30:49 +00:00
; C02 library stdio.h02 assembly language subroutines
; Requires external routines GETKEY, PRCHR, DELCHR, NEWLIN, and SETSRC
2018-01-28 18:30:49 +00:00
; external zero page locations SRCLO and SRCHI
; and external constants DELKEY, ESCKEY, and RTNKEY
2018-07-30 00:40:31 +00:00
;char getc() - GET Character from keyborad
;Sets: System Dependent
;Uses: System Dependent
;Affects: System Dependent
;Returns: A = Character Code of Key
GETC EQU GETKEY ;Alias to external GETKEY routine
2018-01-28 18:30:49 +00:00
2018-07-30 00:40:31 +00:00
;void putc(c) - PUT Character to screen
;Args: Character code to display
;Sets: System Dependent
;Uses: System Dependent
;Affects: System Dependent
;Returns: System Dependent
PUTC EQU PRCHR ;Alias to external PRCHR Routine
2018-01-28 18:30:49 +00:00
2018-07-30 00:40:31 +00:00
;char gets(&s) - GET String input from keyboard
;Args: Y,X = Address of String
;Sets: SRCLO,SRCLHI = Address of String
;Affects: N,Z,C
;Returns: A,Y = Number of Characters in String
GETS: JSR SETSRC ;Initialize Source String
GETSL: JSR GETC ;Get Keypress
CMP #DELKEY ;If Delete
BNE GETSE ;Then
TYA ; If Offset is Zero
BEQ GETSL ; Get Next Character
DEY ; Else Decrement Offset
JSR DELCHR ; Delete Previous Character
JMP GETSL ; and Get Next Character
GETSE: CMP #ESCKEY ;Else If Escape
BNE GETSC ;Then
LDY #$FF ; Return -1
BNE GETSY
2018-07-30 00:40:31 +00:00
GETSC: CMP #RTNKEY ;Else If Not Carriage Return
BEQ GETSX
2018-07-30 00:40:31 +00:00
JSR PUTC ; Echo Character
STA (SRCLO),Y ; Store Character at offset
INY ; increment offset and
BPL GETSL ; loop if less than 128
GETSX: JSR NEWLIN ;Else Advance Cursor to Next Line
LDA #$00 ; Terminate String
STA (SRCLO),Y ; and
GETSY: TYA ; Return String Length
2018-01-28 18:30:49 +00:00
RTS
2018-07-30 00:40:31 +00:00
;char puts(&s) - PUT String to screen
;Args: Y,X = Address of String
;Calls: PUTS
;Affects: N,Z,C
;Returns: A,Y = Number of Characters in String
PUTS: LDA #$00 ;Set Start Position to 0
;and fall into putsub
2018-07-30 00:40:31 +00:00
;char putsub(n, &s) - PUT SUBstring to screen
;Args: A = Starting Position in String
; Y,X = Address of String
;Sets: SRCLO,SRCLHI = Address of String
;Calls: PUTC
;Affects: N,Z,C
;Returns: A,Y = Number of Characters in String
PUTSUB: JSR SETSRC ;Initialize Source String
2018-01-28 18:30:49 +00:00
TAY ;Initialize character offset
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
BPL PUTSUL ; loop if less than 128
2018-07-19 04:27:50 +00:00
PUTSUX: TYA ;Return number of
2018-01-28 18:30:49 +00:00
RTS ; characters printed
2018-07-30 00:40:31 +00:00
;char putln(&s) - PUT LiNe to screen
;Args: Y,X = Address of String
;Calls: PUTS and NEWLIN
PUTLN: JSR PUTS ;Write string to screen
2018-07-19 04:27:50 +00:00
JMP NEWLIN ;Execute external NEWLINe routine and return