2018-01-28 18:30:49 +00:00
|
|
|
; C02 library stdio.h02 assembly language subroutines
|
2018-07-08 05:38:36 +00:00
|
|
|
; Requires external routines GETKEY, PRCHR, DELCHR, NEWLIN, and SETSRC
|
2020-10-13 16:42:03 +00:00
|
|
|
; external zero page location SRCPTR
|
2018-01-28 18:30:49 +00:00
|
|
|
; and external constants DELKEY, ESCKEY, and RTNKEY
|
2018-07-30 00:40:31 +00:00
|
|
|
|
2020-10-13 16:42:03 +00:00
|
|
|
SUBROUTINE STDIO
|
|
|
|
|
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
|
2019-03-23 01:18:49 +00:00
|
|
|
GETC EQU GETCHR ;Alias to external GETCHR 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
|
2019-03-23 01:18:49 +00:00
|
|
|
PUTC EQU PUTCHR ;Alias to external PUTCHR 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
|
2020-10-13 16:42:03 +00:00
|
|
|
;Sets: SRCPTR = Address of String
|
2019-03-23 01:18:49 +00:00
|
|
|
;Uses: TEMP3
|
|
|
|
;Affects: X,N,Z,C
|
2018-07-30 00:40:31 +00:00
|
|
|
;Returns: A,Y = Number of Characters in String
|
|
|
|
GETS: JSR SETSRC ;Initialize Source String
|
2020-10-13 16:42:03 +00:00
|
|
|
.GSLOOP STY TEMP3 ;Save Y Index
|
2019-03-23 01:18:49 +00:00
|
|
|
JSR GETC ;Get Keypress
|
2018-07-30 00:40:31 +00:00
|
|
|
CMP #DELKEY ;If Delete
|
2020-10-13 16:42:03 +00:00
|
|
|
BNE .GSESC ;Then
|
2018-07-30 00:40:31 +00:00
|
|
|
TYA ; If Offset is Zero
|
2020-10-13 16:42:03 +00:00
|
|
|
BEQ .GSLOOP ; Get Next Character
|
2018-07-30 00:40:31 +00:00
|
|
|
DEY ; Else Decrement Offset
|
|
|
|
JSR DELCHR ; Delete Previous Character
|
2020-10-13 16:42:03 +00:00
|
|
|
JMP .GSLOOP ; and Get Next Character
|
|
|
|
.GSESC CMP #ESCKEY ;Else If Escape
|
|
|
|
BNE .GSCR ;Then
|
2018-07-30 00:40:31 +00:00
|
|
|
LDY #$FF ; Return -1
|
2020-10-13 16:42:03 +00:00
|
|
|
BNE .GSRTNY
|
|
|
|
.GSCR CMP #RTNKEY ;Else If Not Carriage Return
|
|
|
|
BEQ .GSDONE
|
2018-07-30 00:40:31 +00:00
|
|
|
JSR PUTC ; Echo Character
|
2019-03-23 01:18:49 +00:00
|
|
|
LDY TEMP3 ;Restore Y Index
|
2020-10-13 16:42:03 +00:00
|
|
|
STA (SRCPTR),Y ; Store Character at offset
|
2018-07-30 00:40:31 +00:00
|
|
|
INY ; increment offset and
|
2020-10-13 16:42:03 +00:00
|
|
|
BPL .GSLOOP ; loop if less than 128
|
|
|
|
.GSDONE JSR NEWLIN ;Else Advance Cursor to Next Line
|
2019-03-23 01:18:49 +00:00
|
|
|
LDY TEMP3 ;Restore Y Index
|
2018-07-30 00:40:31 +00:00
|
|
|
LDA #$00 ; Terminate String
|
2020-10-13 16:42:03 +00:00
|
|
|
STA (SRCPTR),Y ; and
|
|
|
|
.GSRTNY 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
|
2018-02-02 21:33:57 +00:00
|
|
|
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
|
2020-10-13 16:42:03 +00:00
|
|
|
;Sets: SRCPTR = Address of String
|
2018-07-30 00:40:31 +00:00
|
|
|
;Calls: PUTC
|
|
|
|
;Affects: N,Z,C
|
|
|
|
;Returns: A,Y = Number of Characters in String
|
2018-02-02 21:33:57 +00:00
|
|
|
PUTSUB: JSR SETSRC ;Initialize Source String
|
2018-01-28 18:30:49 +00:00
|
|
|
TAY ;Initialize character offset
|
2020-10-13 16:42:03 +00:00
|
|
|
.PSLOOP LDA (SRCPTR),Y ;Read next character in string
|
|
|
|
BEQ .PSDONE ;If Not 0
|
2018-02-02 21:33:57 +00:00
|
|
|
JSR PUTC ; Print character at offset,
|
2018-01-28 18:30:49 +00:00
|
|
|
INY ; increment offset, and
|
2020-10-13 16:42:03 +00:00
|
|
|
BPL .PSLOOP ; loop if less than 128
|
|
|
|
.PSDONE 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
|
2018-02-02 21:33:57 +00:00
|
|
|
PUTLN: JSR PUTS ;Write string to screen
|
2018-07-19 04:27:50 +00:00
|
|
|
JMP NEWLIN ;Execute external NEWLINe routine and return
|
2020-10-13 16:42:03 +00:00
|
|
|
|
|
|
|
ENDSUBROUTINE
|