1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-07 04:29:01 +00:00

Merge pull request #68 from greg-king5/line

Add a stdin console to the Atmos target.
This commit is contained in:
Oliver Schmidt 2013-12-26 06:53:52 -08:00
commit dda8abeab9
3 changed files with 107 additions and 9 deletions

View File

@ -90,6 +90,7 @@ SCREEN := $BB80
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; ROM entries ; ROM entries
GETLINE := $C592
TEXT := $EC21 TEXT := $EC21
HIRES := $EC33 HIRES := $EC33
CURSET := $F0C8 CURSET := $F0C8

View File

@ -1,7 +1,7 @@
; ;
; 2003-03-07, Ullrich von Bassewitz ; 2003-03-07, Ullrich von Bassewitz
; 2011-01-28, Stefan Haubenthal ; 2011-01-28, Stefan Haubenthal
; 2013-07-15, Greg King ; 2013-12-22, Greg King
; ;
; Setup arguments for main ; Setup arguments for main
; ;
@ -40,11 +40,21 @@ L0: lda CFOUND_NAME,y
; ;
ldx #0 ldx #0
L2: lda BASIC_BUF,x L2: lda BASIC_BUF,x
beq done ; no "rem," no args. beq done ; no "rem", no args.
inx inx
cmp #REM cmp #REM
bne L2 bne L2
ldy #1 * 2
; The arguments must be copied to a safe place because BASIC's input buffer
; might be re-used by the stdin console.
ldy #(SCREEN_XSIZE * 2 - 1) - 1
L3: lda BASIC_BUF,y
sta args,y
dey
bpl L3
ldy #1 * 2 ; Point to second argv slot
; Find the next argument ; Find the next argument
@ -65,12 +75,14 @@ found: cmp #'"' ; Is the argument quoted?
lda #' ' ; A space ends the argument lda #' ' ; A space ends the argument
setterm:sta term ; Set end of argument marker setterm:sta term ; Set end of argument marker
; Now store a pointer to the argument into the next slot. Since the BASIC ; Now, store a pointer, to the argument, into the next slot.
; input buffer is located at the zero page, no calculations are necessary.
txa ; Get low byte txa ; Get low byte
add #<BASIC_BUF ; Not at page boundary add #<args
sta argv,y ; argv[y]= &arg sta argv,y ; argv[y]= &arg
lda #>0
adc #>args
sta argv+1,y
iny iny
iny iny
inc __argc ; Found another arg inc __argc ; Found another arg
@ -88,7 +100,7 @@ argloop:lda BASIC_BUF,x
; replace the terminating character by a zero. ; replace the terminating character by a zero.
lda #0 lda #0
sta BASIC_BUF-1,x sta args-1,x
; Check if the maximum number of command line arguments is reached. If not, ; Check if the maximum number of command line arguments is reached. If not,
; parse the next one. ; parse the next one.
@ -103,7 +115,6 @@ done: lda #<argv
ldx #>argv ldx #>argv
sta __argv sta __argv
stx __argv + 1 stx __argv + 1
rts rts
.endproc .endproc
@ -115,7 +126,8 @@ done: lda #<argv
.bss .bss
term: .res 1 term: .res 1
name: .res FNAME_LEN + 1 name: .res FNAME_LEN + 1
args: .res SCREEN_XSIZE * 2 - 1
.data .data
argv: .addr name argv: .addr name
.res MAXARGS * 2 .res MAXARGS * 2, 0

85
libsrc/atmos/read.s Normal file
View File

@ -0,0 +1,85 @@
;
; 2013-12-24, Greg King
;
; int read (int fd, void* buf, unsigned count);
;
; This function is a hack! It lets us get text from the stdin console.
;
.export _read
.constructor initstdin
.import popax
.importzp ptr1, ptr2, ptr3
.macpack generic
.include "atmos.inc"
.proc _read
sta ptr3
stx ptr3+1 ; save count as result
eor #$FF
sta ptr2
txa
eor #$FF
sta ptr2+1 ; Remember -count-1
jsr popax ; get buf
sta ptr1
stx ptr1+1
jsr popax ; get fd and discard
L1: inc ptr2
bnz L2
inc ptr2+1
bze L9 ; no more room in buf
; If there are no more characters in BASIC's input buffer, then get a line from
; the console into that buffer.
L2: ldx text_count
bpl L3
jsr GETLINE
ldx #<(0 - 1)
L3: inx
lda BASIC_BUF,x
bnz L4 ; (zero-terminated buffer)
ldx #<-1
lda #$0A ; return newline char. at end of line
L4: stx text_count
ldy #0
sta (ptr1),y
inc ptr1
bnz L1
inc ptr1+1
bnz L1 ; branch always
; No error, return count.
L9: lda ptr3
ldx ptr3+1
rts
.endproc
;--------------------------------------------------------------------------
; initstdin: Reset the stdin console.
.segment "INIT"
initstdin:
ldx #<-1
stx text_count
rts
;--------------------------------------------------------------------------
.bss
text_count:
.res 1