tweaks to c64 txtio

This commit is contained in:
Irmen de Jong 2020-09-19 22:10:33 +02:00
parent f9ba09ac4d
commit 0f7454059c
4 changed files with 90 additions and 79 deletions

View File

@ -209,6 +209,8 @@ _scroll_screen ; scroll the screen memory
}}
}
romsub $FFD2 = chrout(ubyte char @ A) ; for consistency. You can also use c64.CHROUT directly ofcourse.
asmsub print (str text @ AY) clobbers(A,Y) {
; ---- print null terminated string from A/Y
; note: the compiler contains an optimization that will replace
@ -432,21 +434,22 @@ asmsub input_chars (uword buffer @ AY) clobbers(A) -> ubyte @ Y {
}}
}
asmsub setchr (ubyte col @Y, ubyte row @A) clobbers(A) {
; ---- set the character in SCRATCH_ZPB1 on the screen matrix at the given position
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
; ---- sets the character in the screen matrix at the given position
%asm {{
sty P8ZP_SCRATCH_REG
pha
tya
asl a
tay
lda _screenrows+1,y
sta _mod+2
lda _screenrows,y
txa
clc
adc P8ZP_SCRATCH_REG
adc _screenrows,y
sta _mod+1
bcc +
inc _mod+2
+ lda P8ZP_SCRATCH_B1
+ pla
_mod sta $ffff ; modified
rts
@ -454,17 +457,18 @@ _screenrows .word $0400 + range(0, 1000, 40)
}}
}
asmsub getchr (ubyte col @Y, ubyte row @A) clobbers(Y) -> ubyte @ A {
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the character in the screen matrix at the given location
%asm {{
sty P8ZP_SCRATCH_B1
pha
tya
asl a
tay
lda setchr._screenrows+1,y
sta _mod+2
lda setchr._screenrows,y
pla
clc
adc P8ZP_SCRATCH_B1
adc setchr._screenrows,y
sta _mod+1
bcc _mod
inc _mod+2
@ -473,21 +477,22 @@ _mod lda $ffff ; modified
}}
}
asmsub setclr (ubyte col @Y, ubyte row @A) clobbers(A) {
; ---- set the color in SCRATCH_ZPB1 on the screen matrix at the given position
asmsub setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers(A, Y) {
; ---- set the color in A on the screen matrix at the given position
%asm {{
sty P8ZP_SCRATCH_REG
pha
tya
asl a
tay
lda _colorrows+1,y
sta _mod+2
lda _colorrows,y
txa
clc
adc P8ZP_SCRATCH_REG
adc _colorrows,y
sta _mod+1
bcc +
inc _mod+2
+ lda P8ZP_SCRATCH_B1
+ pla
_mod sta $ffff ; modified
rts
@ -495,17 +500,18 @@ _colorrows .word $d800 + range(0, 1000, 40)
}}
}
asmsub getclr (ubyte col @Y, ubyte row @A) clobbers(Y) -> ubyte @ A {
asmsub getclr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
; ---- get the color in the screen color matrix at the given location
%asm {{
sty P8ZP_SCRATCH_B1
pha
tya
asl a
tay
lda setclr._colorrows+1,y
sta _mod+2
lda setclr._colorrows,y
pla
clc
adc P8ZP_SCRATCH_B1
adc setclr._colorrows,y
sta _mod+1
bcc _mod
inc _mod+2

View File

@ -259,6 +259,9 @@ asmsub init_system() {
jsr c64.IOINIT
jsr c64.RESTOR
jsr c64.CINT
lda #$9e ; yellow
jsr c64.CHROUT
; TODO select black background color
lda #0
tax
tay

View File

@ -96,6 +96,8 @@ sub color2 (ubyte txtcol, ubyte bgcol) {
c64.CHROUT(color_to_charcode[txtcol & 15])
}
romsub $FFD2 = chrout(ubyte char @ A) ; for consistency. You can also use c64.CHROUT directly ofcourse.
asmsub print (str text @ AY) clobbers(A,Y) {
; ---- print null terminated string from A/Y
; note: the compiler contains an optimization that will replace
@ -298,7 +300,28 @@ asmsub print_w (word value @ AY) clobbers(A,Y) {
}}
}
; TODO implement the "missing" txtio subroutines: input_chars, setchr, getchr, setclr, getclr, scroll_left_full, (also right, up, down)
asmsub input_chars (uword buffer @ AY) clobbers(A) -> ubyte @ Y {
; ---- Input a string (max. 80 chars) from the keyboard. Returns length in Y. (string is terminated with a 0 byte as well)
; It assumes the keyboard is selected as I/O channel!
%asm {{
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
ldy #0 ; char counter = 0
- jsr c64.CHRIN
cmp #$0d ; return (ascii 13) pressed?
beq + ; yes, end.
sta (P8ZP_SCRATCH_W1),y ; else store char in buffer
iny
bne -
+ lda #0
sta (P8ZP_SCRATCH_W1),y ; finish string with 0 byte
rts
}}
}
; TODO implement the "missing" txtio subroutines: getchr, setclr, getclr, scroll_left_full, (also right, up, down)
sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) {
; ---- set char+color at the given position on the screen

View File

@ -1,8 +1,10 @@
%import c64lib
%import c64graphics
;%import c64lib
;%import c64graphics
%import c64textio
%import c64flt
;%import c64flt
;%option enable_floats
;%target cx16
;%import cx16textio
%zeropage basicsafe
@ -10,64 +12,41 @@ main {
sub start() {
ubyte i1=0
ubyte i2=1
txt.setchr(5, 5, '*')
txt.setchr(6, 5, '*')
txt.setchr(7, 5, '*')
txt.setchr(7, 6, '+')
txt.setchr(7, 7, '+')
byte b1 = 11
byte b2 = 22
word w1 = 1111
word w2 = 2222
float f1 = 1.111
float f2 = 2.222
txt.setclr(5, 5, 1)
txt.setclr(6, 5, 2)
txt.setclr(7, 5, 3)
txt.setclr(7, 6, 4)
txt.setclr(7, 7, 5)
byte[] barr = [1,2]
word[] warr = [1111,2222]
float[] farr= [1.111, 2.222]
txt.plot(15,10)
txt.chrout('!')
@($c000) = 11
@($c001) = 22
txt.print_ub(txt.getchr(4,5))
txt.chrout(',')
txt.print_ub(txt.getchr(5,5))
txt.chrout(',')
txt.print_ub(txt.getchr(6,5))
txt.chrout(',')
txt.print_ub(txt.getchr(7,5))
txt.chrout(',')
txt.print_ub(txt.getchr(8,5))
txt.chrout('\n')
txt.print_ub(txt.getclr(4,5))
txt.chrout(',')
txt.print_ub(txt.getclr(5,5))
txt.chrout(',')
txt.print_ub(txt.getclr(6,5))
txt.chrout(',')
txt.print_ub(txt.getclr(7,5))
txt.chrout(',')
txt.print_ub(txt.getclr(8,5))
txt.chrout('\n')
swap(b1,b2)
swap(w1,w2)
swap(f1,f2)
swap(@($c000), @($c001))
swap(barr[i1], barr[i2])
swap(warr[i1], warr[i2])
swap(farr[i1], farr[i2])
txt.print_b(b1)
c64.CHROUT(',')
txt.print_b(b2)
c64.CHROUT('\n')
txt.print_w(w1)
c64.CHROUT(',')
txt.print_w(w2)
c64.CHROUT('\n')
c64flt.print_f(f1)
c64.CHROUT(',')
c64flt.print_f(f2)
c64.CHROUT('\n')
txt.print_b(barr[0])
c64.CHROUT(',')
txt.print_b(barr[1])
c64.CHROUT('\n')
txt.print_w(warr[0])
c64.CHROUT(',')
txt.print_w(warr[1])
c64.CHROUT('\n')
c64flt.print_f(farr[0])
c64.CHROUT(',')
c64flt.print_f(farr[1])
c64.CHROUT('\n')
txt.print_ub(@($c000))
c64.CHROUT(',')
txt.print_ub(@($c001))
c64.CHROUT('\n')
}
}