2020-08-27 16:10:22 +00:00
|
|
|
; Prog8 definitions for the Text I/O and Screen routines for the CommanderX16
|
2020-08-25 23:56:26 +00:00
|
|
|
;
|
|
|
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
|
|
|
;
|
|
|
|
; indent format: TABS, size=8
|
|
|
|
|
|
|
|
|
|
|
|
%import cx16lib
|
2020-08-26 18:52:38 +00:00
|
|
|
%import conv
|
2020-08-25 23:56:26 +00:00
|
|
|
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
txt {
|
2020-08-25 23:56:26 +00:00
|
|
|
|
2020-08-29 21:55:26 +00:00
|
|
|
asmsub clear_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) {
|
2020-08-25 23:56:26 +00:00
|
|
|
; ---- clear the character screen with the given fill character and character color.
|
|
|
|
|
|
|
|
%asm {{
|
|
|
|
brk ; TODO
|
|
|
|
}}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-08-26 17:34:12 +00:00
|
|
|
; by just one call to c64.CHROUT of that single char.
|
2020-08-25 23:56:26 +00:00
|
|
|
%asm {{
|
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
sty P8ZP_SCRATCH_REG
|
|
|
|
ldy #0
|
|
|
|
- lda (P8ZP_SCRATCH_B1),y
|
|
|
|
beq +
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_ub0 (ubyte value @ A) clobbers(A,Y) {
|
|
|
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.ubyte2decimal
|
2020-08-25 23:56:26 +00:00
|
|
|
pha
|
|
|
|
tya
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
pla
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
txa
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_ub (ubyte value @ A) clobbers(A,Y) {
|
|
|
|
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.ubyte2decimal
|
2020-08-25 23:56:26 +00:00
|
|
|
_print_byte_digits
|
|
|
|
pha
|
|
|
|
cpy #'0'
|
|
|
|
beq +
|
|
|
|
tya
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
pla
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
jmp _ones
|
|
|
|
+ pla
|
|
|
|
cmp #'0'
|
|
|
|
beq _ones
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
_ones txa
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_b (byte value @ A) clobbers(A,Y) {
|
|
|
|
; ---- print the byte in A in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-25 23:56:26 +00:00
|
|
|
pha
|
|
|
|
cmp #0
|
|
|
|
bpl +
|
|
|
|
lda #'-'
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
+ pla
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.byte2decimal
|
2020-08-25 23:56:26 +00:00
|
|
|
jsr print_ub._print_byte_digits
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_ubhex (ubyte value @ A, ubyte prefix @ Pc) clobbers(A,Y) {
|
|
|
|
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-25 23:56:26 +00:00
|
|
|
bcc +
|
|
|
|
pha
|
|
|
|
lda #'$'
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
pla
|
2020-08-26 18:52:38 +00:00
|
|
|
+ jsr conv.ubyte2hex
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
tya
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_ubbin (ubyte value @ A, ubyte prefix @ Pc) clobbers(A,Y) {
|
|
|
|
; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well)
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-25 23:56:26 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
bcc +
|
|
|
|
lda #'%'
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
+ ldy #8
|
|
|
|
- lda #'0'
|
|
|
|
asl P8ZP_SCRATCH_B1
|
|
|
|
bcc +
|
|
|
|
lda #'1'
|
2020-08-26 17:34:12 +00:00
|
|
|
+ jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
dey
|
|
|
|
bne -
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_uwbin (uword value @ AY, ubyte prefix @ Pc) clobbers(A,Y) {
|
|
|
|
; ---- 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
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_uwhex (uword value @ AY, ubyte prefix @ Pc) clobbers(A,Y) {
|
|
|
|
; ---- 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
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_uw0 (uword value @ AY) clobbers(A,Y) {
|
|
|
|
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.uword2decimal
|
2020-08-25 23:56:26 +00:00
|
|
|
ldy #0
|
2020-08-26 18:52:38 +00:00
|
|
|
- lda conv.uword2decimal.decTenThousands,y
|
2020-08-25 23:56:26 +00:00
|
|
|
beq +
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
iny
|
|
|
|
bne -
|
2020-08-28 20:11:33 +00:00
|
|
|
+ plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_uw (uword value @ AY) clobbers(A,Y) {
|
|
|
|
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.uword2decimal
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
ldy #0
|
2020-08-26 18:52:38 +00:00
|
|
|
- lda conv.uword2decimal.decTenThousands,y
|
2020-08-25 23:56:26 +00:00
|
|
|
beq _allzero
|
|
|
|
cmp #'0'
|
|
|
|
bne _gotdigit
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
|
|
|
|
_gotdigit
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
iny
|
2020-08-26 18:52:38 +00:00
|
|
|
lda conv.uword2decimal.decTenThousands,y
|
2020-08-25 23:56:26 +00:00
|
|
|
bne _gotdigit
|
|
|
|
rts
|
|
|
|
_allzero
|
|
|
|
lda #'0'
|
2020-08-26 17:34:12 +00:00
|
|
|
jmp c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmsub print_w (word value @ AY) clobbers(A,Y) {
|
|
|
|
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
|
|
%asm {{
|
|
|
|
cpy #0
|
|
|
|
bpl +
|
|
|
|
pha
|
|
|
|
lda #'-'
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.CHROUT
|
2020-08-25 23:56:26 +00:00
|
|
|
tya
|
|
|
|
eor #255
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
eor #255
|
|
|
|
clc
|
|
|
|
adc #1
|
|
|
|
bcc +
|
|
|
|
iny
|
|
|
|
+ jmp print_uw
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-08-29 21:55:26 +00:00
|
|
|
ubyte[16] color_to_charcode = [$90,$05,$1c,$9f,$9c,$1e,$1f,$9e,$81,$95,$96,$97,$98,$99,$9a,$9b]
|
|
|
|
|
|
|
|
sub color (ubyte txtcol) {
|
|
|
|
c64.CHROUT(color_to_charcode[txtcol & 15])
|
|
|
|
}
|
|
|
|
|
|
|
|
sub color2 (ubyte txtcol, ubyte bgcol) {
|
|
|
|
c64.CHROUT(color_to_charcode[bgcol & 15])
|
|
|
|
c64.CHROUT(1) ; switch fg and bg colors
|
|
|
|
c64.CHROUT(color_to_charcode[txtcol & 15])
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setc (ubyte column, ubyte row, ubyte char) {
|
|
|
|
; ---- set char at the given position on the screen
|
|
|
|
%asm {{
|
|
|
|
phx
|
|
|
|
ldy column
|
|
|
|
ldx row
|
|
|
|
clc
|
|
|
|
jsr c64.PLOT
|
|
|
|
plx
|
|
|
|
lda char
|
|
|
|
jmp c64.CHROUT
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-08-25 23:56:26 +00:00
|
|
|
asmsub plot (ubyte col @ Y, ubyte row @ A) clobbers(A) {
|
|
|
|
; ---- safe wrapper around PLOT kernel routine, to save the X register.
|
|
|
|
%asm {{
|
2020-08-28 20:11:33 +00:00
|
|
|
phx
|
2020-08-25 23:56:26 +00:00
|
|
|
tax
|
|
|
|
clc
|
2020-08-26 17:34:12 +00:00
|
|
|
jsr c64.PLOT
|
2020-08-28 20:11:33 +00:00
|
|
|
plx
|
2020-08-25 23:56:26 +00:00
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
}
|