2023-08-12 21:24:41 +00:00
|
|
|
; Prog8 definitions for the Text I/O and Screen routines for the Commodore-128
|
2023-11-06 22:18:24 +00:00
|
|
|
; All routines work with Screencode character encoding, except `print`, `chrout` and `input_chars`,
|
|
|
|
; these work with PETSCII encoding instead.
|
2021-12-21 18:08:33 +00:00
|
|
|
|
|
|
|
%import syslib
|
|
|
|
%import conv
|
2024-03-27 23:04:49 +00:00
|
|
|
%import shared_cbm_textio_functions
|
2021-12-21 18:08:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
txt {
|
2023-12-26 22:37:59 +00:00
|
|
|
%option no_symbol_prefixing, ignore_unused
|
2021-12-21 18:08:33 +00:00
|
|
|
|
|
|
|
const ubyte DEFAULT_WIDTH = 40
|
|
|
|
const ubyte DEFAULT_HEIGHT = 25
|
|
|
|
|
2024-03-27 23:04:49 +00:00
|
|
|
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
|
|
|
|
2021-12-21 18:08:33 +00:00
|
|
|
|
|
|
|
sub clear_screen() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(147)
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub home() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(19)
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub nl() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout('\n')
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub spc() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bell() {
|
|
|
|
chrout(7)
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asmsub column(ubyte col @A) clobbers(A, X, Y) {
|
|
|
|
; ---- set the cursor on the given column (starting with 0) on the current line
|
|
|
|
%asm {{
|
2024-03-16 15:47:40 +00:00
|
|
|
pha
|
2021-12-21 18:08:33 +00:00
|
|
|
sec
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.PLOT
|
2024-03-16 15:47:40 +00:00
|
|
|
pla
|
2021-12-21 18:08:33 +00:00
|
|
|
tay
|
|
|
|
clc
|
2023-04-28 21:13:03 +00:00
|
|
|
jmp cbm.PLOT
|
2021-12-21 18:08:33 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:19:16 +00:00
|
|
|
|
|
|
|
asmsub get_column() -> ubyte @Y {
|
|
|
|
%asm {{
|
|
|
|
sec
|
|
|
|
jmp cbm.PLOT
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub row(ubyte rownum @A) clobbers(A, X, Y) {
|
|
|
|
; ---- set the cursor on the given row (starting with 0) on the current line
|
|
|
|
%asm {{
|
2024-03-16 15:47:40 +00:00
|
|
|
pha
|
2023-11-07 21:19:16 +00:00
|
|
|
sec
|
|
|
|
jsr cbm.PLOT
|
2024-03-16 15:47:40 +00:00
|
|
|
pla
|
2023-11-07 21:19:16 +00:00
|
|
|
tax
|
|
|
|
clc
|
|
|
|
jmp cbm.PLOT
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub get_row() -> ubyte @X {
|
|
|
|
%asm {{
|
|
|
|
sec
|
|
|
|
jmp cbm.PLOT
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_cursor(uword colptr, uword rowptr) {
|
|
|
|
%asm {{
|
|
|
|
sec
|
|
|
|
jsr cbm.PLOT
|
|
|
|
tya
|
|
|
|
ldy #$00
|
|
|
|
sta (colptr),y
|
|
|
|
txa
|
|
|
|
sta (rowptr),y
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-21 18:08:33 +00:00
|
|
|
asmsub fill_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) {
|
|
|
|
; ---- fill the character screen with the given fill character and character color.
|
|
|
|
; (assumes screen and color matrix are at their default addresses)
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
jsr clear_screencolors
|
|
|
|
pla
|
|
|
|
jsr clear_screenchars
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub clear_screenchars (ubyte char @ A) clobbers(Y) {
|
|
|
|
; ---- clear the character screen with the given fill character (leaves colors)
|
|
|
|
; (assumes screen matrix is at the default address)
|
|
|
|
%asm {{
|
|
|
|
ldy #250
|
2023-04-28 21:13:03 +00:00
|
|
|
- sta cbm.Screen+250*0-1,y
|
|
|
|
sta cbm.Screen+250*1-1,y
|
|
|
|
sta cbm.Screen+250*2-1,y
|
|
|
|
sta cbm.Screen+250*3-1,y
|
2021-12-21 18:08:33 +00:00
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub clear_screencolors (ubyte color @ A) clobbers(Y) {
|
|
|
|
; ---- clear the character screen colors with the given color (leaves characters).
|
|
|
|
; (assumes color matrix is at the default address)
|
|
|
|
%asm {{
|
|
|
|
ldy #250
|
2023-04-28 21:13:03 +00:00
|
|
|
- sta cbm.Colors+250*0-1,y
|
|
|
|
sta cbm.Colors+250*1-1,y
|
|
|
|
sta cbm.Colors+250*2-1,y
|
|
|
|
sta cbm.Colors+250*3-1,y
|
2021-12-21 18:08:33 +00:00
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub color (ubyte txtcol) {
|
2023-04-28 21:13:03 +00:00
|
|
|
cbm.COLOR = txtcol
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub lowercase() {
|
2021-12-21 22:26:00 +00:00
|
|
|
c64.VMCSB |= 2
|
2021-12-22 20:20:34 +00:00
|
|
|
c128.VM1 |= 2
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub uppercase() {
|
2021-12-21 22:26:00 +00:00
|
|
|
c64.VMCSB &= ~2
|
2021-12-22 20:20:34 +00:00
|
|
|
c128.VM1 &= ~2
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, X, Y) {
|
2021-12-21 18:08:33 +00:00
|
|
|
; ---- scroll the whole screen 1 character to the left
|
|
|
|
; contents of the rightmost column are unchanged, you should clear/refill this yourself
|
|
|
|
; Carry flag determines if screen color data must be scrolled too
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
bcc _scroll_screen
|
|
|
|
|
|
|
|
+ ; scroll the screen and the color memory
|
|
|
|
ldx #0
|
|
|
|
ldy #38
|
|
|
|
-
|
|
|
|
.for row=0, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row + 1,x
|
|
|
|
sta cbm.Screen + 40*row + 0,x
|
|
|
|
lda cbm.Colors + 40*row + 1,x
|
|
|
|
sta cbm.Colors + 40*row + 0,x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
inx
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
|
|
|
_scroll_screen ; scroll only the screen memory
|
|
|
|
ldx #0
|
|
|
|
ldy #38
|
|
|
|
-
|
|
|
|
.for row=0, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row + 1,x
|
|
|
|
sta cbm.Screen + 40*row + 0,x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
inx
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_right (bool alsocolors @ Pc) clobbers(A,X) {
|
2021-12-21 18:08:33 +00:00
|
|
|
; ---- scroll the whole screen 1 character to the right
|
|
|
|
; contents of the leftmost column are unchanged, you should clear/refill this yourself
|
|
|
|
; Carry flag determines if screen color data must be scrolled too
|
|
|
|
%asm {{
|
|
|
|
bcc _scroll_screen
|
|
|
|
|
|
|
|
+ ; scroll the screen and the color memory
|
|
|
|
ldx #38
|
|
|
|
-
|
|
|
|
.for row=0, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row + 0,x
|
|
|
|
sta cbm.Screen + 40*row + 1,x
|
|
|
|
lda cbm.Colors + 40*row + 0,x
|
|
|
|
sta cbm.Colors + 40*row + 1,x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
|
|
|
_scroll_screen ; scroll only the screen memory
|
|
|
|
ldx #38
|
|
|
|
-
|
|
|
|
.for row=0, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row + 0,x
|
|
|
|
sta cbm.Screen + 40*row + 1,x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_up (bool alsocolors @ Pc) clobbers(A,X) {
|
2021-12-21 18:08:33 +00:00
|
|
|
; ---- scroll the whole screen 1 character up
|
|
|
|
; contents of the bottom row are unchanged, you should refill/clear this yourself
|
|
|
|
; Carry flag determines if screen color data must be scrolled too
|
|
|
|
%asm {{
|
|
|
|
bcc _scroll_screen
|
|
|
|
|
|
|
|
+ ; scroll the screen and the color memory
|
|
|
|
ldx #39
|
|
|
|
-
|
|
|
|
.for row=1, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row,x
|
|
|
|
sta cbm.Screen + 40*(row-1),x
|
|
|
|
lda cbm.Colors + 40*row,x
|
|
|
|
sta cbm.Colors + 40*(row-1),x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
|
|
|
_scroll_screen ; scroll only the screen memory
|
|
|
|
ldx #39
|
|
|
|
-
|
|
|
|
.for row=1, row<=24, row+=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row,x
|
|
|
|
sta cbm.Screen + 40*(row-1),x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_down (bool alsocolors @ Pc) clobbers(A,X) {
|
2021-12-21 18:08:33 +00:00
|
|
|
; ---- scroll the whole screen 1 character down
|
|
|
|
; contents of the top row are unchanged, you should refill/clear this yourself
|
|
|
|
; Carry flag determines if screen color data must be scrolled too
|
|
|
|
%asm {{
|
|
|
|
bcc _scroll_screen
|
|
|
|
|
|
|
|
+ ; scroll the screen and the color memory
|
|
|
|
ldx #39
|
|
|
|
-
|
|
|
|
.for row=23, row>=0, row-=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Colors + 40*row,x
|
|
|
|
sta cbm.Colors + 40*(row+1),x
|
|
|
|
lda cbm.Screen + 40*row,x
|
|
|
|
sta cbm.Screen + 40*(row+1),x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
|
|
|
|
_scroll_screen ; scroll only the screen memory
|
|
|
|
ldx #39
|
|
|
|
-
|
|
|
|
.for row=23, row>=0, row-=1
|
2023-04-28 21:13:03 +00:00
|
|
|
lda cbm.Screen + 40*row,x
|
|
|
|
sta cbm.Screen + 40*(row+1),x
|
2021-12-21 18:08:33 +00:00
|
|
|
.next
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda _screenrows+1,y
|
|
|
|
sta _mod+2
|
|
|
|
txa
|
|
|
|
clc
|
|
|
|
adc _screenrows,y
|
|
|
|
sta _mod+1
|
|
|
|
bcc +
|
|
|
|
inc _mod+2
|
|
|
|
+ pla
|
|
|
|
_mod sta $ffff ; modified
|
|
|
|
rts
|
|
|
|
|
2023-08-14 11:51:15 +00:00
|
|
|
_screenrows .word cbm.Screen + range(0, 1000, 40)
|
2021-12-21 18:08:33 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
|
|
|
|
; ---- get the character in the screen matrix at the given location
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setchr._screenrows+1,y
|
|
|
|
sta _mod+2
|
|
|
|
pla
|
|
|
|
clc
|
|
|
|
adc setchr._screenrows,y
|
|
|
|
sta _mod+1
|
|
|
|
bcc _mod
|
|
|
|
inc _mod+2
|
|
|
|
_mod lda $ffff ; modified
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda _colorrows+1,y
|
|
|
|
sta _mod+2
|
|
|
|
txa
|
|
|
|
clc
|
|
|
|
adc _colorrows,y
|
|
|
|
sta _mod+1
|
|
|
|
bcc +
|
|
|
|
inc _mod+2
|
|
|
|
+ pla
|
|
|
|
_mod sta $ffff ; modified
|
|
|
|
rts
|
|
|
|
|
|
|
|
_colorrows .word $d800 + range(0, 1000, 40)
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setclr._colorrows+1,y
|
|
|
|
sta _mod+2
|
|
|
|
pla
|
|
|
|
clc
|
|
|
|
adc setclr._colorrows,y
|
|
|
|
sta _mod+1
|
|
|
|
bcc _mod
|
|
|
|
inc _mod+2
|
|
|
|
_mod lda $ffff ; modified
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) {
|
2021-12-21 18:08:33 +00:00
|
|
|
; ---- set char+color at the given position on the screen
|
|
|
|
%asm {{
|
|
|
|
lda row
|
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setchr._screenrows+1,y
|
|
|
|
sta _charmod+2
|
|
|
|
adc #$d4
|
|
|
|
sta _colormod+2
|
|
|
|
lda setchr._screenrows,y
|
|
|
|
clc
|
2023-08-28 15:35:53 +00:00
|
|
|
adc col
|
2021-12-21 18:08:33 +00:00
|
|
|
sta _charmod+1
|
|
|
|
sta _colormod+1
|
|
|
|
bcc +
|
|
|
|
inc _charmod+2
|
|
|
|
inc _colormod+2
|
2023-08-28 15:35:53 +00:00
|
|
|
+ lda character
|
2021-12-21 18:08:33 +00:00
|
|
|
_charmod sta $ffff ; modified
|
|
|
|
lda charcolor
|
|
|
|
_colormod sta $ffff ; modified
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub plot (ubyte col @ Y, ubyte row @ X) {
|
2021-12-21 18:08:33 +00:00
|
|
|
%asm {{
|
|
|
|
clc
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp cbm.PLOT
|
2021-12-21 18:08:33 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub width() clobbers(X,Y) -> ubyte @A {
|
|
|
|
; -- returns the text screen width (number of columns)
|
|
|
|
%asm {{
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.SCREEN
|
2021-12-21 18:08:33 +00:00
|
|
|
txa
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub height() clobbers(X, Y) -> ubyte @A {
|
|
|
|
; -- returns the text screen height (number of rows)
|
|
|
|
%asm {{
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.SCREEN
|
2021-12-21 18:08:33 +00:00
|
|
|
tya
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-11-17 19:30:50 +00:00
|
|
|
asmsub waitkey() -> ubyte @A {
|
2023-11-07 21:19:16 +00:00
|
|
|
%asm {{
|
|
|
|
- jsr cbm.GETIN
|
|
|
|
beq -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
2021-12-21 18:08:33 +00:00
|
|
|
}
|