]> git.sur5r.net Git - cc65/commitdiff
Added a simplistic read() that gives a stdin console on the Atmos.
authorGreg King <gregdk@users.sf.net>
Tue, 24 Dec 2013 10:18:04 +0000 (05:18 -0500)
committerGreg King <gregdk@users.sf.net>
Tue, 24 Dec 2013 10:18:04 +0000 (05:18 -0500)
asminc/atmos.inc
libsrc/atmos/read.s [new file with mode: 0644]

index 6534a2ef08fca9e896fd545d8d264bd29b7ef0c3..4c3c442faf36a2ff2efc2ad2404dadd3ca603224 100644 (file)
@@ -90,6 +90,7 @@ SCREEN          := $BB80
 ; ---------------------------------------------------------------------------
 ; ROM entries
 
+GETLINE         := $C592
 TEXT            := $EC21
 HIRES           := $EC33
 CURSET          := $F0C8
diff --git a/libsrc/atmos/read.s b/libsrc/atmos/read.s
new file mode 100644 (file)
index 0000000..e6e1f7e
--- /dev/null
@@ -0,0 +1,70 @@
+;
+; 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
+
+        .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
+
+.data
+
+text_count:
+        .byte   <-1
+