2022-02-21 22:38:53 +00:00
|
|
|
; Prog8 definitions for the Text I/O and Screen routines for the Atari 800XL
|
2023-11-17 15:35:33 +00:00
|
|
|
; Reference: https://www.atariarchives.org/mapping/appendix12.php
|
2022-02-21 22:38:53 +00:00
|
|
|
|
|
|
|
%import syslib
|
|
|
|
%import conv
|
|
|
|
|
|
|
|
txt {
|
|
|
|
|
2023-12-26 22:37:59 +00:00
|
|
|
%option no_symbol_prefixing, ignore_unused
|
2023-06-29 22:29:50 +00:00
|
|
|
|
2022-02-21 22:38:53 +00:00
|
|
|
const ubyte DEFAULT_WIDTH = 40
|
2022-02-25 22:48:39 +00:00
|
|
|
const ubyte DEFAULT_HEIGHT = 24
|
2022-02-21 22:38:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub clear_screen() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(125)
|
2022-02-21 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub nl() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout('\n')
|
2022-02-21 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub spc() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bell() {
|
|
|
|
chrout($fd)
|
2022-02-21 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-07 21:19:16 +00:00
|
|
|
sub column(ubyte col) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- set the cursor on the given column (starting with 0) on the current line
|
2023-11-17 19:30:50 +00:00
|
|
|
atari.COLCRS = col
|
2023-11-07 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_column() -> ubyte {
|
2023-11-17 19:30:50 +00:00
|
|
|
return atari.COLCRS as ubyte
|
2023-11-07 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub row(ubyte rownum) {
|
|
|
|
; ---- set the cursor on the given row (starting with 0) on the current line
|
2023-11-17 19:30:50 +00:00
|
|
|
atari.ROWCRS = rownum
|
2023-11-07 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_row() -> ubyte {
|
2023-11-17 19:30:50 +00:00
|
|
|
return atari.ROWCRS
|
2022-02-21 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- fill the character screen with the given fill character and character color.
|
|
|
|
; (assumes screen and color matrix are at their default addresses)
|
|
|
|
; TODO
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
asmsub clear_screenchars (ubyte character @ A) clobbers(Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- clear the character screen with the given fill character (leaves colors)
|
|
|
|
; (assumes screen matrix is at the default address)
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
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)
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub color (ubyte txtcol) {
|
|
|
|
; TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
sub lowercase() {
|
|
|
|
; TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
sub uppercase() {
|
|
|
|
; TODO
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:59:30 +00:00
|
|
|
asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, Y) {
|
2022-02-21 22:38:53 +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
|
|
|
|
; TODO
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:59:30 +00:00
|
|
|
asmsub scroll_right (bool alsocolors @ Pc) clobbers(A) {
|
2022-02-21 22:38:53 +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
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:59:30 +00:00
|
|
|
asmsub scroll_up (bool alsocolors @ Pc) clobbers(A) {
|
2022-02-21 22:38:53 +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
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:59:30 +00:00
|
|
|
asmsub scroll_down (bool alsocolors @ Pc) clobbers(A) {
|
2022-02-21 22:38:53 +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
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
asmsub chrout(ubyte character @ A) {
|
2022-02-23 15:42:22 +00:00
|
|
|
%asm {{
|
|
|
|
sta _tmp_outchar+1
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
pha
|
|
|
|
_tmp_outchar
|
|
|
|
lda #0
|
2023-11-17 19:30:50 +00:00
|
|
|
jsr atari.outchar
|
2022-02-23 15:42:22 +00:00
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
2022-02-21 22:38:53 +00:00
|
|
|
|
|
|
|
asmsub print (str text @ AY) clobbers(A,Y) {
|
|
|
|
; ---- print null terminated string from A/Y
|
|
|
|
; note: the compiler contains an optimization that will replace
|
|
|
|
; a call to this subroutine with a string argument of just one char,
|
|
|
|
; by just one call to CHROUT of that single char.
|
|
|
|
%asm {{
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
sty P8ZP_SCRATCH_REG
|
|
|
|
ldy #0
|
|
|
|
- lda (P8ZP_SCRATCH_B1),y
|
|
|
|
beq +
|
|
|
|
jsr chrout
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
|
|
%asm {{
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr conv.internal_ubyte2decimal
|
2022-02-21 22:38:53 +00:00
|
|
|
pha
|
|
|
|
tya
|
|
|
|
jsr chrout
|
|
|
|
txa
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr chrout
|
|
|
|
pla
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp chrout
|
2022-02-21 22:38:53 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr conv.internal_ubyte2decimal
|
2022-02-21 22:38:53 +00:00
|
|
|
_print_byte_digits
|
|
|
|
pha
|
|
|
|
cpy #'0'
|
|
|
|
beq +
|
|
|
|
tya
|
|
|
|
jsr chrout
|
2024-03-27 23:04:49 +00:00
|
|
|
txa
|
2022-02-21 22:38:53 +00:00
|
|
|
jsr chrout
|
|
|
|
jmp _ones
|
2024-03-27 23:04:49 +00:00
|
|
|
+ cpx #'0'
|
2022-02-21 22:38:53 +00:00
|
|
|
beq _ones
|
2024-03-27 23:04:49 +00:00
|
|
|
txa
|
2022-02-21 22:38:53 +00:00
|
|
|
jsr chrout
|
2024-03-27 23:04:49 +00:00
|
|
|
_ones pla
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp chrout
|
2022-02-21 22:38:53 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the byte in A in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
cmp #0
|
|
|
|
bpl +
|
|
|
|
lda #'-'
|
|
|
|
jsr chrout
|
|
|
|
+ pla
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr conv.internal_byte2decimal
|
2022-02-21 22:38:53 +00:00
|
|
|
jmp print_ub._print_byte_digits
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
|
|
%asm {{
|
|
|
|
bcc +
|
|
|
|
pha
|
|
|
|
lda #'$'
|
|
|
|
jsr chrout
|
|
|
|
pla
|
2024-03-27 23:04:49 +00:00
|
|
|
+ jsr conv.internal_ubyte2hex
|
2022-02-21 22:38:53 +00:00
|
|
|
jsr chrout
|
|
|
|
tya
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp chrout
|
2022-02-21 22:38:53 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well)
|
|
|
|
%asm {{
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
bcc +
|
|
|
|
lda #'%'
|
|
|
|
jsr chrout
|
|
|
|
+ ldy #8
|
|
|
|
- lda #'0'
|
|
|
|
asl P8ZP_SCRATCH_B1
|
|
|
|
bcc +
|
|
|
|
lda #'1'
|
|
|
|
+ jsr chrout
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the uword in A/Y in binary form (if Carry is set, a radix prefix '%' is printed as well)
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
jsr print_ubbin
|
|
|
|
pla
|
|
|
|
clc
|
|
|
|
jmp print_ubbin
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the uword in A/Y in hexadecimal form (4 digits)
|
|
|
|
; (if Carry is set, a radix prefix '$' is printed as well)
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
jsr print_ubhex
|
|
|
|
pla
|
|
|
|
clc
|
|
|
|
jmp print_ubhex
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
|
|
%asm {{
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr conv.internal_uword2decimal
|
2022-02-21 22:38:53 +00:00
|
|
|
ldy #0
|
2024-03-27 23:04:49 +00:00
|
|
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
2022-02-21 22:38:53 +00:00
|
|
|
beq +
|
|
|
|
jsr chrout
|
|
|
|
iny
|
|
|
|
bne -
|
2023-07-15 13:18:26 +00:00
|
|
|
+ rts
|
2022-02-21 22:38:53 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
2024-03-27 23:04:49 +00:00
|
|
|
jsr conv.internal_uword2decimal
|
2022-02-21 22:38:53 +00:00
|
|
|
ldy #0
|
2024-03-27 23:04:49 +00:00
|
|
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
2022-02-21 22:38:53 +00:00
|
|
|
beq _allzero
|
|
|
|
cmp #'0'
|
|
|
|
bne _gotdigit
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
|
|
|
|
_gotdigit
|
|
|
|
jsr chrout
|
|
|
|
iny
|
2024-03-27 23:04:49 +00:00
|
|
|
lda conv.internal_uword2decimal.decTenThousands,y
|
2022-02-21 22:38:53 +00:00
|
|
|
bne _gotdigit
|
|
|
|
rts
|
|
|
|
_allzero
|
|
|
|
lda #'0'
|
|
|
|
jmp chrout
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
|
|
%asm {{
|
|
|
|
cpy #0
|
|
|
|
bpl +
|
|
|
|
pha
|
|
|
|
lda #'-'
|
|
|
|
jsr chrout
|
|
|
|
tya
|
|
|
|
eor #255
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
eor #255
|
|
|
|
clc
|
|
|
|
adc #1
|
|
|
|
bcc +
|
|
|
|
iny
|
|
|
|
+ jmp print_uw
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
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!
|
|
|
|
; TODO
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
ldy #0
|
|
|
|
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
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
|
|
|
|
; ---- get the character in the screen matrix at the given location
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
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
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub getclr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
|
|
|
|
; ---- get the color in the screen color matrix at the given location
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-08-28 15:35:53 +00:00
|
|
|
sub setcc (ubyte col, ubyte row, ubyte char, ubyte charcolor) {
|
2022-02-21 22:38:53 +00:00
|
|
|
; ---- set char+color at the given position on the screen
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:19:16 +00:00
|
|
|
sub plot(ubyte col, ubyte rownum) {
|
2023-11-17 19:30:50 +00:00
|
|
|
column(col)
|
|
|
|
row(rownum)
|
2023-11-07 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_cursor(uword colptr, uword rowptr) {
|
2023-11-17 19:30:50 +00:00
|
|
|
@(colptr) = get_column()
|
|
|
|
@(rowptr) = get_row()
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub waitkey() -> ubyte @A {
|
|
|
|
%asm {{
|
|
|
|
jmp atari.waitkey
|
|
|
|
}}
|
2022-02-21 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asmsub width() clobbers(X,Y) -> ubyte @A {
|
|
|
|
; -- returns the text screen width (number of columns)
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub height() clobbers(X, Y) -> ubyte @A {
|
|
|
|
; -- returns the text screen height (number of rows)
|
|
|
|
; TODO
|
|
|
|
%asm {{
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|