2020-08-27 16:10:22 +00:00
|
|
|
; Prog8 definitions for the Text I/O and Screen routines for the Commodore-64
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-09-20 21:49:36 +00:00
|
|
|
%import syslib
|
2020-08-26 18:52:38 +00:00
|
|
|
%import conv
|
2018-10-01 18:05:32 +00:00
|
|
|
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
txt {
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2023-06-29 22:29:50 +00:00
|
|
|
%option no_symbol_prefixing
|
|
|
|
|
2020-09-19 22:17:33 +00:00
|
|
|
const ubyte DEFAULT_WIDTH = 40
|
|
|
|
const ubyte DEFAULT_HEIGHT = 25
|
|
|
|
|
|
|
|
|
2020-09-21 17:23:21 +00:00
|
|
|
sub clear_screen() {
|
2020-12-14 13:28:53 +00:00
|
|
|
txt.chrout(147)
|
2020-08-30 17:31:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 21:51:09 +00:00
|
|
|
sub home() {
|
|
|
|
txt.chrout(19)
|
|
|
|
}
|
|
|
|
|
2021-01-08 15:20:56 +00:00
|
|
|
sub nl() {
|
|
|
|
txt.chrout('\n')
|
|
|
|
}
|
|
|
|
|
2021-01-14 21:51:09 +00:00
|
|
|
sub spc() {
|
|
|
|
txt.chrout(' ')
|
2021-01-08 15:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 21:47:49 +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 {{
|
|
|
|
sec
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.PLOT
|
2021-02-10 21:47:49 +00:00
|
|
|
tay
|
|
|
|
clc
|
2023-04-28 21:13:03 +00:00
|
|
|
jmp cbm.PLOT
|
2021-02-10 21:47:49 +00:00
|
|
|
}}
|
|
|
|
}
|
2021-01-14 21:51:09 +00:00
|
|
|
|
2020-09-21 19:39:36 +00:00
|
|
|
asmsub fill_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) {
|
2020-08-30 17:31:20 +00:00
|
|
|
; ---- fill the character screen with the given fill character and character color.
|
2019-01-06 01:11:16 +00:00
|
|
|
; (assumes screen and color matrix are at their default addresses)
|
2018-10-01 18:05:32 +00:00
|
|
|
|
|
|
|
%asm {{
|
2019-01-06 01:11:16 +00:00
|
|
|
pha
|
|
|
|
tya
|
|
|
|
jsr clear_screencolors
|
|
|
|
pla
|
|
|
|
jsr clear_screenchars
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-08 21:00:18 +00:00
|
|
|
asmsub clear_screenchars (ubyte char @ A) clobbers(Y) {
|
2019-01-06 01:11:16 +00:00
|
|
|
; ---- clear the character screen with the given fill character (leaves colors)
|
|
|
|
; (assumes screen matrix is at the default address)
|
|
|
|
%asm {{
|
2020-12-06 00:07:57 +00:00
|
|
|
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
|
2020-12-06 00:07:57 +00:00
|
|
|
dey
|
|
|
|
bne -
|
2018-10-01 18:05:32 +00:00
|
|
|
rts
|
|
|
|
}}
|
2019-01-06 01:11:16 +00:00
|
|
|
}
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-09-21 19:39:36 +00:00
|
|
|
asmsub clear_screencolors (ubyte color @ A) clobbers(Y) {
|
2019-01-06 01:11:16 +00:00
|
|
|
; ---- clear the character screen colors with the given color (leaves characters).
|
|
|
|
; (assumes color matrix is at the default address)
|
|
|
|
%asm {{
|
2020-12-06 00:07:57 +00:00
|
|
|
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
|
2020-12-06 00:07:57 +00:00
|
|
|
dey
|
|
|
|
bne -
|
2019-01-06 01:11:16 +00:00
|
|
|
rts
|
|
|
|
}}
|
2018-10-01 18:05:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 22:15:18 +00:00
|
|
|
sub color (ubyte txtcol) {
|
2023-04-28 21:13:03 +00:00
|
|
|
cbm.COLOR = txtcol
|
2020-08-29 22:15:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 20:37:24 +00:00
|
|
|
sub lowercase() {
|
|
|
|
c64.VMCSB |= 2
|
|
|
|
}
|
|
|
|
|
|
|
|
sub uppercase() {
|
|
|
|
c64.VMCSB &= ~2
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_left (bool alsocolors @ Pc) clobbers(A, X, Y) {
|
2018-10-01 18:05:32 +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
|
2020-03-24 01:42:32 +00:00
|
|
|
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-12-06 00:07:57 +00:00
|
|
|
bcc _scroll_screen
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
+ ; scroll the screen and the color memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #0
|
|
|
|
ldy #38
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
inx
|
|
|
|
dey
|
|
|
|
bpl -
|
2020-12-06 00:07:57 +00:00
|
|
|
rts
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
_scroll_screen ; scroll only the screen memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #0
|
|
|
|
ldy #38
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
inx
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_right (bool alsocolors @ Pc) clobbers(A,X) {
|
2018-10-01 18:05:32 +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 {{
|
2020-12-06 00:07:57 +00:00
|
|
|
bcc _scroll_screen
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
+ ; scroll the screen and the color memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #38
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
2020-12-06 00:07:57 +00:00
|
|
|
rts
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
_scroll_screen ; scroll only the screen memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #38
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_up (bool alsocolors @ Pc) clobbers(A,X) {
|
2018-10-01 18:05:32 +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 {{
|
2020-12-06 00:07:57 +00:00
|
|
|
bcc _scroll_screen
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
+ ; scroll the screen and the color memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #39
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
2020-12-06 00:07:57 +00:00
|
|
|
rts
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
_scroll_screen ; scroll only the screen memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #39
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub scroll_down (bool alsocolors @ Pc) clobbers(A,X) {
|
2018-10-01 18:05:32 +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 {{
|
2020-12-06 00:07:57 +00:00
|
|
|
bcc _scroll_screen
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
+ ; scroll the screen and the color memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #39
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
2020-12-06 00:07:57 +00:00
|
|
|
rts
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2020-12-06 00:07:57 +00:00
|
|
|
_scroll_screen ; scroll only the screen memory
|
2018-10-01 18:05:32 +00:00
|
|
|
ldx #39
|
|
|
|
-
|
2020-12-06 00:07:57 +00:00
|
|
|
.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
|
2020-12-06 00:07:57 +00:00
|
|
|
.next
|
2018-10-01 18:05:32 +00:00
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-04-28 21:13:03 +00:00
|
|
|
romsub $FFD2 = chrout(ubyte char @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse.
|
2020-09-19 20:10:33 +00:00
|
|
|
|
2019-07-08 21:00:18 +00:00
|
|
|
asmsub print (str text @ AY) clobbers(A,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print null terminated string from A/Y
|
2018-10-01 18:05:32 +00:00
|
|
|
; note: the compiler contains an optimization that will replace
|
|
|
|
; a call to this subroutine with a string argument of just one char,
|
2023-04-28 21:13:03 +00:00
|
|
|
; by just one call to cbm.CHROUT of that single char.
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
|
|
|
sty P8ZP_SCRATCH_REG
|
2018-10-01 18:05:32 +00:00
|
|
|
ldy #0
|
2020-08-25 17:44:08 +00:00
|
|
|
- lda (P8ZP_SCRATCH_B1),y
|
2018-10-01 18:05:32 +00:00
|
|
|
beq +
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.ubyte2decimal
|
2018-10-01 18:05:32 +00:00
|
|
|
pha
|
|
|
|
tya
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
pla
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2019-09-22 23:58:01 +00:00
|
|
|
txa
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the ubyte in A in decimal form, without left padding 0s
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.ubyte2decimal
|
2018-12-14 22:15:44 +00:00
|
|
|
_print_byte_digits
|
2018-10-01 18:05:32 +00:00
|
|
|
pha
|
|
|
|
cpy #'0'
|
2019-09-22 23:58:01 +00:00
|
|
|
beq +
|
|
|
|
tya
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2020-03-22 00:49:05 +00:00
|
|
|
pla
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2020-03-22 00:49:05 +00:00
|
|
|
jmp _ones
|
2019-09-22 23:58:01 +00:00
|
|
|
+ pla
|
|
|
|
cmp #'0'
|
2020-03-22 00:49:05 +00:00
|
|
|
beq _ones
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2020-03-22 00:49:05 +00:00
|
|
|
_ones txa
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
2019-01-12 15:13:40 +00:00
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the byte in A in decimal form, without left padding 0s
|
|
|
|
%asm {{
|
|
|
|
pha
|
|
|
|
cmp #0
|
|
|
|
bpl +
|
|
|
|
lda #'-'
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-12-14 22:15:44 +00:00
|
|
|
+ pla
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.byte2decimal
|
2020-09-13 18:52:29 +00:00
|
|
|
jmp print_ub._print_byte_digits
|
2018-12-14 22:15:44 +00:00
|
|
|
}}
|
|
|
|
}
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
|
|
|
bcc +
|
|
|
|
pha
|
|
|
|
lda #'$'
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
pla
|
2020-08-26 18:52:38 +00:00
|
|
|
+ jsr conv.ubyte2hex
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
tya
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
2019-01-12 12:34:45 +00:00
|
|
|
; ---- print the ubyte in A in binary form (if Carry is set, a radix prefix '%' is printed as well)
|
|
|
|
%asm {{
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_B1
|
2019-01-12 12:34:45 +00:00
|
|
|
bcc +
|
|
|
|
lda #'%'
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2019-01-12 12:34:45 +00:00
|
|
|
+ ldy #8
|
|
|
|
- lda #'0'
|
2020-08-25 17:44:08 +00:00
|
|
|
asl P8ZP_SCRATCH_B1
|
2019-01-12 12:34:45 +00:00
|
|
|
bcc +
|
|
|
|
lda #'1'
|
2023-04-28 21:13:03 +00:00
|
|
|
+ jsr cbm.CHROUT
|
2019-01-12 12:34:45 +00:00
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) {
|
2019-01-12 12:34:45 +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) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the uword in A/Y in hexadecimal form (4 digits)
|
2018-10-01 18:05:32 +00:00
|
|
|
; (if Carry is set, a radix prefix '$' is printed as well)
|
|
|
|
%asm {{
|
2018-12-14 22:15:44 +00:00
|
|
|
pha
|
2018-10-01 18:05:32 +00:00
|
|
|
tya
|
2018-12-20 22:28:03 +00:00
|
|
|
jsr print_ubhex
|
2018-12-14 22:15:44 +00:00
|
|
|
pla
|
2018-10-01 18:05:32 +00:00
|
|
|
clc
|
2018-12-20 22:28:03 +00:00
|
|
|
jmp print_ubhex
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.uword2decimal
|
2019-01-10 18:11:45 +00:00
|
|
|
ldy #0
|
2020-08-26 18:52:38 +00:00
|
|
|
- lda conv.uword2decimal.decTenThousands,y
|
2019-09-22 23:58:01 +00:00
|
|
|
beq +
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2019-01-10 18:11:45 +00:00
|
|
|
iny
|
|
|
|
bne -
|
2023-07-15 13:18:26 +00:00
|
|
|
+ rts
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
2018-12-14 22:15:44 +00:00
|
|
|
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
2018-10-01 18:05:32 +00:00
|
|
|
%asm {{
|
2020-08-26 18:52:38 +00:00
|
|
|
jsr conv.uword2decimal
|
2018-10-01 18:05:32 +00:00
|
|
|
ldy #0
|
2020-08-26 18:52:38 +00:00
|
|
|
- lda conv.uword2decimal.decTenThousands,y
|
2019-09-22 23:58:01 +00:00
|
|
|
beq _allzero
|
2018-10-01 18:05:32 +00:00
|
|
|
cmp #'0'
|
2019-09-22 23:58:01 +00:00
|
|
|
bne _gotdigit
|
2018-10-01 18:05:32 +00:00
|
|
|
iny
|
2019-09-22 23:58:01 +00:00
|
|
|
bne -
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2019-09-22 23:58:01 +00:00
|
|
|
_gotdigit
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
iny
|
2020-08-26 18:52:38 +00:00
|
|
|
lda conv.uword2decimal.decTenThousands,y
|
2019-09-22 23:58:01 +00:00
|
|
|
bne _gotdigit
|
2018-10-01 18:05:32 +00:00
|
|
|
rts
|
2019-09-22 23:58:01 +00:00
|
|
|
_allzero
|
|
|
|
lda #'0'
|
2023-04-28 21:13:03 +00:00
|
|
|
jmp cbm.CHROUT
|
2018-10-01 18:05:32 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
2019-03-21 21:36:46 +00:00
|
|
|
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
2018-12-14 22:15:44 +00:00
|
|
|
%asm {{
|
|
|
|
cpy #0
|
|
|
|
bpl +
|
|
|
|
pha
|
|
|
|
lda #'-'
|
2023-04-28 21:13:03 +00:00
|
|
|
jsr cbm.CHROUT
|
2018-12-14 22:15:44 +00:00
|
|
|
tya
|
|
|
|
eor #255
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
eor #255
|
|
|
|
clc
|
|
|
|
adc #1
|
|
|
|
bcc +
|
|
|
|
iny
|
2018-12-20 22:28:03 +00:00
|
|
|
+ jmp print_uw
|
2018-12-14 22:15:44 +00:00
|
|
|
}}
|
|
|
|
}
|
2018-10-01 18:05:32 +00:00
|
|
|
|
2019-07-08 21:00:18 +00:00
|
|
|
asmsub input_chars (uword buffer @ AY) clobbers(A) -> ubyte @ Y {
|
2019-03-15 22:10:26 +00:00
|
|
|
; ---- Input a string (max. 80 chars) from the keyboard. Returns length in Y. (string is terminated with a 0 byte as well)
|
2018-12-10 08:25:38 +00:00
|
|
|
; It assumes the keyboard is selected as I/O channel!
|
2018-10-01 18:05:32 +00:00
|
|
|
|
|
|
|
%asm {{
|
2020-08-25 17:44:08 +00:00
|
|
|
sta P8ZP_SCRATCH_W1
|
|
|
|
sty P8ZP_SCRATCH_W1+1
|
2018-10-01 18:05:32 +00:00
|
|
|
ldy #0 ; char counter = 0
|
2023-04-28 21:13:03 +00:00
|
|
|
- jsr cbm.CHRIN
|
2018-10-01 18:05:32 +00:00
|
|
|
cmp #$0d ; return (ascii 13) pressed?
|
|
|
|
beq + ; yes, end.
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ; else store char in buffer
|
2018-10-01 18:05:32 +00:00
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
+ lda #0
|
2020-08-25 17:44:08 +00:00
|
|
|
sta (P8ZP_SCRATCH_W1),y ; finish string with 0 byte
|
2018-10-01 18:05:32 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:10:33 +00:00
|
|
|
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
|
2018-12-18 00:43:04 +00:00
|
|
|
%asm {{
|
2020-09-19 20:10:33 +00:00
|
|
|
pha
|
|
|
|
tya
|
2018-12-18 00:43:04 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda _screenrows+1,y
|
|
|
|
sta _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
txa
|
2018-12-18 00:43:04 +00:00
|
|
|
clc
|
2020-09-19 20:10:33 +00:00
|
|
|
adc _screenrows,y
|
2018-12-18 00:43:04 +00:00
|
|
|
sta _mod+1
|
|
|
|
bcc +
|
|
|
|
inc _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
+ pla
|
2018-12-18 00:43:04 +00:00
|
|
|
_mod sta $ffff ; modified
|
|
|
|
rts
|
2019-01-12 15:13:40 +00:00
|
|
|
|
2018-12-18 00:43:04 +00:00
|
|
|
_screenrows .word $0400 + range(0, 1000, 40)
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:10:33 +00:00
|
|
|
asmsub getchr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
|
2019-02-21 00:31:33 +00:00
|
|
|
; ---- get the character in the screen matrix at the given location
|
|
|
|
%asm {{
|
2020-09-19 20:10:33 +00:00
|
|
|
pha
|
|
|
|
tya
|
2019-02-21 00:31:33 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setchr._screenrows+1,y
|
|
|
|
sta _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
pla
|
2019-02-21 00:31:33 +00:00
|
|
|
clc
|
2020-09-19 20:10:33 +00:00
|
|
|
adc setchr._screenrows,y
|
2019-02-21 00:31:33 +00:00
|
|
|
sta _mod+1
|
|
|
|
bcc _mod
|
|
|
|
inc _mod+2
|
|
|
|
_mod lda $ffff ; modified
|
2019-03-05 22:10:00 +00:00
|
|
|
rts
|
2019-02-21 00:31:33 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:10:33 +00:00
|
|
|
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
|
2018-12-18 00:43:04 +00:00
|
|
|
%asm {{
|
2020-09-19 20:10:33 +00:00
|
|
|
pha
|
|
|
|
tya
|
2018-12-18 00:43:04 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda _colorrows+1,y
|
|
|
|
sta _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
txa
|
2018-12-18 00:43:04 +00:00
|
|
|
clc
|
2020-09-19 20:10:33 +00:00
|
|
|
adc _colorrows,y
|
2018-12-18 00:43:04 +00:00
|
|
|
sta _mod+1
|
|
|
|
bcc +
|
|
|
|
inc _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
+ pla
|
2018-12-18 00:43:04 +00:00
|
|
|
_mod sta $ffff ; modified
|
|
|
|
rts
|
2019-01-12 15:13:40 +00:00
|
|
|
|
2018-12-18 00:43:04 +00:00
|
|
|
_colorrows .word $d800 + range(0, 1000, 40)
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:10:33 +00:00
|
|
|
asmsub getclr (ubyte col @A, ubyte row @Y) clobbers(Y) -> ubyte @ A {
|
2019-02-21 00:31:33 +00:00
|
|
|
; ---- get the color in the screen color matrix at the given location
|
|
|
|
%asm {{
|
2020-09-19 20:10:33 +00:00
|
|
|
pha
|
|
|
|
tya
|
2019-02-21 00:31:33 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setclr._colorrows+1,y
|
|
|
|
sta _mod+2
|
2020-09-19 20:10:33 +00:00
|
|
|
pla
|
2019-02-21 00:31:33 +00:00
|
|
|
clc
|
2020-09-19 20:10:33 +00:00
|
|
|
adc setclr._colorrows,y
|
2019-02-21 00:31:33 +00:00
|
|
|
sta _mod+1
|
|
|
|
bcc _mod
|
|
|
|
inc _mod+2
|
|
|
|
_mod lda $ffff ; modified
|
2019-03-05 22:10:00 +00:00
|
|
|
rts
|
2019-02-21 00:31:33 +00:00
|
|
|
}}
|
|
|
|
}
|
2019-01-12 15:13:40 +00:00
|
|
|
|
2020-08-29 22:15:18 +00:00
|
|
|
sub setcc (ubyte column, ubyte row, ubyte char, ubyte charcolor) {
|
2018-12-18 00:43:04 +00:00
|
|
|
; ---- set char+color at the given position on the screen
|
|
|
|
%asm {{
|
2019-08-04 16:40:50 +00:00
|
|
|
lda row
|
2018-12-18 00:43:04 +00:00
|
|
|
asl a
|
|
|
|
tay
|
|
|
|
lda setchr._screenrows+1,y
|
|
|
|
sta _charmod+2
|
|
|
|
adc #$d4
|
|
|
|
sta _colormod+2
|
|
|
|
lda setchr._screenrows,y
|
|
|
|
clc
|
2019-08-04 16:40:50 +00:00
|
|
|
adc column
|
2018-12-18 00:43:04 +00:00
|
|
|
sta _charmod+1
|
|
|
|
sta _colormod+1
|
|
|
|
bcc +
|
|
|
|
inc _charmod+2
|
|
|
|
inc _colormod+2
|
2019-08-04 16:40:50 +00:00
|
|
|
+ lda char
|
2018-12-18 00:43:04 +00:00
|
|
|
_charmod sta $ffff ; modified
|
2020-08-29 22:15:18 +00:00
|
|
|
lda charcolor
|
2018-12-18 00:43:04 +00:00
|
|
|
_colormod sta $ffff ; modified
|
|
|
|
rts
|
2019-01-12 15:13:40 +00:00
|
|
|
}}
|
2018-12-18 00:43:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 13:18:26 +00:00
|
|
|
asmsub plot (ubyte col @ Y, ubyte row @ X) {
|
2018-12-19 01:51:22 +00:00
|
|
|
%asm {{
|
|
|
|
clc
|
2023-07-15 13:18:26 +00:00
|
|
|
jmp cbm.PLOT
|
2018-12-19 01:51:22 +00:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-09-19 21:23:32 +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
|
2020-09-19 21:23:32 +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
|
2020-09-19 21:23:32 +00:00
|
|
|
tya
|
|
|
|
rts
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-08-27 16:10:22 +00:00
|
|
|
}
|