mirror of
https://github.com/irmen/prog8.git
synced 2024-09-30 00:55:52 +00:00
Merge branch 'master' into multi-assign
# Conflicts: # docs/source/todo.rst # examples/test.p8
This commit is contained in:
commit
4700a239b9
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
%import syslib
|
%import syslib
|
||||||
%import conv
|
%import conv
|
||||||
%import shared_textio_functions
|
|
||||||
|
|
||||||
txt {
|
txt {
|
||||||
|
|
||||||
@ -168,13 +167,13 @@ asmsub print (str text @ AY) clobbers(A,Y) {
|
|||||||
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
||||||
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.ubyte2decimal
|
jsr conv.internal_ubyte2decimal
|
||||||
pha
|
pha
|
||||||
tya
|
tya
|
||||||
jsr chrout
|
jsr chrout
|
||||||
pla
|
|
||||||
jsr chrout
|
|
||||||
txa
|
txa
|
||||||
|
jsr chrout
|
||||||
|
pla
|
||||||
jmp chrout
|
jmp chrout
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -182,21 +181,21 @@ asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
|||||||
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
||||||
; ---- print the ubyte in A in decimal form, without left padding 0s
|
; ---- print the ubyte in A in decimal form, without left padding 0s
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.ubyte2decimal
|
jsr conv.internal_ubyte2decimal
|
||||||
_print_byte_digits
|
_print_byte_digits
|
||||||
pha
|
pha
|
||||||
cpy #'0'
|
cpy #'0'
|
||||||
beq +
|
beq +
|
||||||
tya
|
tya
|
||||||
jsr chrout
|
jsr chrout
|
||||||
pla
|
txa
|
||||||
jsr chrout
|
jsr chrout
|
||||||
jmp _ones
|
jmp _ones
|
||||||
+ pla
|
+ cpx #'0'
|
||||||
cmp #'0'
|
|
||||||
beq _ones
|
beq _ones
|
||||||
|
txa
|
||||||
jsr chrout
|
jsr chrout
|
||||||
_ones txa
|
_ones pla
|
||||||
jmp chrout
|
jmp chrout
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -210,7 +209,7 @@ asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
|||||||
lda #'-'
|
lda #'-'
|
||||||
jsr chrout
|
jsr chrout
|
||||||
+ pla
|
+ pla
|
||||||
jsr conv.byte2decimal
|
jsr conv.internal_byte2decimal
|
||||||
jmp print_ub._print_byte_digits
|
jmp print_ub._print_byte_digits
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@ -223,7 +222,7 @@ asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|||||||
lda #'$'
|
lda #'$'
|
||||||
jsr chrout
|
jsr chrout
|
||||||
pla
|
pla
|
||||||
+ jsr conv.ubyte2hex
|
+ jsr conv.internal_ubyte2hex
|
||||||
jsr chrout
|
jsr chrout
|
||||||
tya
|
tya
|
||||||
jmp chrout
|
jmp chrout
|
||||||
@ -277,9 +276,9 @@ asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,Y) {
|
|||||||
asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
||||||
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.uword2decimal
|
jsr conv.internal_uword2decimal
|
||||||
ldy #0
|
ldy #0
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
beq +
|
beq +
|
||||||
jsr chrout
|
jsr chrout
|
||||||
iny
|
iny
|
||||||
@ -291,9 +290,9 @@ asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
|||||||
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
||||||
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.uword2decimal
|
jsr conv.internal_uword2decimal
|
||||||
ldy #0
|
ldy #0
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
beq _allzero
|
beq _allzero
|
||||||
cmp #'0'
|
cmp #'0'
|
||||||
bne _gotdigit
|
bne _gotdigit
|
||||||
@ -303,7 +302,7 @@ asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
|||||||
_gotdigit
|
_gotdigit
|
||||||
jsr chrout
|
jsr chrout
|
||||||
iny
|
iny
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
bne _gotdigit
|
bne _gotdigit
|
||||||
rts
|
rts
|
||||||
_allzero
|
_allzero
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
%import syslib
|
%import syslib
|
||||||
%import conv
|
%import conv
|
||||||
%import shared_textio_functions
|
%import shared_cbm_textio_functions
|
||||||
|
|
||||||
|
|
||||||
txt {
|
txt {
|
||||||
@ -13,6 +13,8 @@ txt {
|
|||||||
const ubyte DEFAULT_WIDTH = 40
|
const ubyte DEFAULT_WIDTH = 40
|
||||||
const ubyte DEFAULT_HEIGHT = 25
|
const ubyte DEFAULT_HEIGHT = 25
|
||||||
|
|
||||||
|
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
||||||
|
|
||||||
|
|
||||||
sub clear_screen() {
|
sub clear_screen() {
|
||||||
chrout(147)
|
chrout(147)
|
||||||
@ -288,216 +290,6 @@ _scroll_screen ; scroll only the screen memory
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
romsub $FFD2 = chrout(ubyte char @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
|
||||||
|
|
||||||
asmsub print (str text @ AY) clobbers(A,Y) {
|
|
||||||
; ---- print null terminated string, in PETSCII encoding, 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 cbm.CHROUT of that single char.
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_B1
|
|
||||||
sty P8ZP_SCRATCH_REG
|
|
||||||
ldy #0
|
|
||||||
- lda (P8ZP_SCRATCH_B1),y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
pha
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
_print_byte_digits
|
|
||||||
pha
|
|
||||||
cpy #'0'
|
|
||||||
beq +
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
jmp _ones
|
|
||||||
+ pla
|
|
||||||
cmp #'0'
|
|
||||||
beq _ones
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
_ones txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the byte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
pha
|
|
||||||
cmp #0
|
|
||||||
bpl +
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
+ pla
|
|
||||||
jsr conv.byte2decimal
|
|
||||||
jmp print_ub._print_byte_digits
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
||||||
%asm {{
|
|
||||||
bcc +
|
|
||||||
pha
|
|
||||||
lda #'$'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
+ jsr conv.ubyte2hex
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
tya
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- 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 cbm.CHROUT
|
|
||||||
+ ldy #8
|
|
||||||
- lda #'0'
|
|
||||||
asl P8ZP_SCRATCH_B1
|
|
||||||
bcc +
|
|
||||||
lda #'1'
|
|
||||||
+ jsr cbm.CHROUT
|
|
||||||
dey
|
|
||||||
bne -
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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, bool prefix @ Pc) clobbers(A,X,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,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq _allzero
|
|
||||||
cmp #'0'
|
|
||||||
bne _gotdigit
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
|
|
||||||
_gotdigit
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
|
||||||
bne _gotdigit
|
|
||||||
rts
|
|
||||||
_allzero
|
|
||||||
lda #'0'
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
||||||
%asm {{
|
|
||||||
cpy #0
|
|
||||||
bpl +
|
|
||||||
pha
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.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, in PETSCII encoding.
|
|
||||||
; 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 cbm.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
|
|
||||||
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
|
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
|
; ---- sets the character in the screen matrix at the given position
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
%import syslib
|
%import syslib
|
||||||
%import conv
|
%import conv
|
||||||
%import shared_textio_functions
|
%import shared_cbm_textio_functions
|
||||||
|
|
||||||
txt {
|
txt {
|
||||||
|
|
||||||
@ -13,6 +13,7 @@ txt {
|
|||||||
const ubyte DEFAULT_WIDTH = 40
|
const ubyte DEFAULT_WIDTH = 40
|
||||||
const ubyte DEFAULT_HEIGHT = 25
|
const ubyte DEFAULT_HEIGHT = 25
|
||||||
|
|
||||||
|
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
||||||
|
|
||||||
sub clear_screen() {
|
sub clear_screen() {
|
||||||
chrout(147)
|
chrout(147)
|
||||||
@ -292,216 +293,6 @@ _scroll_screen ; scroll only the screen memory
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
|
||||||
|
|
||||||
asmsub print (str text @ AY) clobbers(A,Y) {
|
|
||||||
; ---- print null terminated string, in PESCII encoding, 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 cbm.CHROUT of that single char.
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_B1
|
|
||||||
sty P8ZP_SCRATCH_REG
|
|
||||||
ldy #0
|
|
||||||
- lda (P8ZP_SCRATCH_B1),y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
pha
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
_print_byte_digits
|
|
||||||
pha
|
|
||||||
cpy #'0'
|
|
||||||
beq +
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
jmp _ones
|
|
||||||
+ pla
|
|
||||||
cmp #'0'
|
|
||||||
beq _ones
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
_ones txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the byte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
pha
|
|
||||||
cmp #0
|
|
||||||
bpl +
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
+ pla
|
|
||||||
jsr conv.byte2decimal
|
|
||||||
jmp print_ub._print_byte_digits
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
||||||
%asm {{
|
|
||||||
bcc +
|
|
||||||
pha
|
|
||||||
lda #'$'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
+ jsr conv.ubyte2hex
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
tya
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- 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 cbm.CHROUT
|
|
||||||
+ ldy #8
|
|
||||||
- lda #'0'
|
|
||||||
asl P8ZP_SCRATCH_B1
|
|
||||||
bcc +
|
|
||||||
lda #'1'
|
|
||||||
+ jsr cbm.CHROUT
|
|
||||||
dey
|
|
||||||
bne -
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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, bool prefix @ Pc) clobbers(A,X,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,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq _allzero
|
|
||||||
cmp #'0'
|
|
||||||
bne _gotdigit
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
|
|
||||||
_gotdigit
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
|
||||||
bne _gotdigit
|
|
||||||
rts
|
|
||||||
_allzero
|
|
||||||
lda #'0'
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
||||||
%asm {{
|
|
||||||
cpy #0
|
|
||||||
bpl +
|
|
||||||
pha
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.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, in PETSCII encoding.
|
|
||||||
; 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 cbm.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
|
|
||||||
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
|
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
|
; ---- sets the character in the screen matrix at the given position
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -8,97 +8,79 @@ conv {
|
|||||||
|
|
||||||
str @shared string_out = "????????????????" ; result buffer for the string conversion routines
|
str @shared string_out = "????????????????" ; result buffer for the string conversion routines
|
||||||
|
|
||||||
asmsub str_ub0 (ubyte value @ A) clobbers(X) -> str @AY {
|
asmsub str_ub0(ubyte value @A) clobbers(X) -> str @AY {
|
||||||
; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total)
|
; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.ubyte2decimal
|
jsr internal_ubyte2decimal
|
||||||
sty string_out
|
sty conv.string_out
|
||||||
sta string_out+1
|
stx conv.string_out+1
|
||||||
stx string_out+2
|
sta conv.string_out+2
|
||||||
lda #0
|
lda #0
|
||||||
sta string_out+3
|
sta conv.string_out+3
|
||||||
lda #<string_out
|
lda #<conv.string_out
|
||||||
ldy #>string_out
|
ldy #>conv.string_out
|
||||||
rts
|
rts
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub str_ub (ubyte value @ A) clobbers(X) -> str @AY {
|
asmsub str_ub(ubyte value @A) clobbers(X) -> str @AY {
|
||||||
; ---- convert the ubyte in A in decimal string form, without left padding 0s
|
; ---- convert the ubyte in A in decimal string form, without left padding 0s
|
||||||
%asm {{
|
%asm {{
|
||||||
ldy #0
|
jsr internal_ubyte2decimal
|
||||||
sty P8ZP_SCRATCH_B1
|
cpy #'0'
|
||||||
jsr ubyte2decimal ; result in Y/A/X (100s, 10s, 1s).
|
beq +
|
||||||
; hundreds?
|
sty conv.string_out
|
||||||
cpy #'0'
|
stx conv.string_out+1
|
||||||
beq +
|
sta conv.string_out+2
|
||||||
sty string_out
|
lda #0
|
||||||
sta string_out+1
|
sta conv.string_out+3
|
||||||
stx string_out+2
|
jmp _done
|
||||||
lda #0
|
+ cpx #'0'
|
||||||
sta string_out+3
|
beq +
|
||||||
jmp _done
|
stx conv.string_out
|
||||||
; tens?
|
sta conv.string_out+1
|
||||||
+ cmp #'0'
|
lda #0
|
||||||
beq +
|
sta conv.string_out+2
|
||||||
sta string_out
|
jmp _done
|
||||||
stx string_out+1
|
+ sta conv.string_out
|
||||||
lda #0
|
lda #0
|
||||||
sta string_out+2
|
sta conv.string_out+1
|
||||||
jmp _done
|
_done lda #<conv.string_out
|
||||||
+ ; ones.
|
ldy #>conv.string_out
|
||||||
stx string_out
|
rts
|
||||||
lda #0
|
}}
|
||||||
sta string_out+1
|
}
|
||||||
_done lda #<string_out
|
|
||||||
ldy #>string_out
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub str_b (byte value @ A) clobbers(X) -> str @AY {
|
asmsub str_b(byte value @A) clobbers(X) -> str @AY {
|
||||||
; ---- convert the byte in A in decimal string form, without left padding 0s
|
; ---- convert the byte in A in decimal string form, without left padding 0s
|
||||||
%asm {{
|
%asm {{
|
||||||
ldy #0
|
cmp #0
|
||||||
cmp #0
|
bpl str_ub
|
||||||
bpl +
|
eor #255
|
||||||
ldy #'-'
|
clc
|
||||||
sty string_out
|
adc #1
|
||||||
ldy #1
|
jsr str_ub
|
||||||
+ sty P8ZP_SCRATCH_REG
|
; insert a minus sign at the start
|
||||||
jsr conv.byte2decimal ; result in Y/A/X (100s, 10s, 1s). and in uword2decimal.decHundreds, decTens, decOnes.
|
lda #0
|
||||||
; hundreds?
|
sta conv.string_out+4
|
||||||
cpy #'0'
|
lda conv.string_out+2
|
||||||
bne _out_hundreds
|
sta conv.string_out+3
|
||||||
ldy P8ZP_SCRATCH_REG
|
lda conv.string_out+1
|
||||||
cmp #'0'
|
sta conv.string_out+2
|
||||||
bne _out_tens
|
lda conv.string_out
|
||||||
beq _out_ones
|
sta conv.string_out+1
|
||||||
_out_hundreds
|
lda #'-'
|
||||||
ldy P8ZP_SCRATCH_REG
|
sta conv.string_out
|
||||||
lda uword2decimal.decHundreds
|
lda #<conv.string_out
|
||||||
sta string_out,y
|
ldy #>conv.string_out
|
||||||
iny
|
rts
|
||||||
_out_tens
|
}}
|
||||||
lda uword2decimal.decTens
|
}
|
||||||
sta string_out,y
|
|
||||||
iny
|
|
||||||
_out_ones
|
|
||||||
lda uword2decimal.decOnes
|
|
||||||
sta string_out,y
|
|
||||||
iny
|
|
||||||
lda #0
|
|
||||||
sta string_out,y
|
|
||||||
lda #<string_out
|
|
||||||
ldy #>string_out
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub str_ubhex (ubyte value @ A) clobbers(X) -> str @AY {
|
asmsub str_ubhex (ubyte value @ A) clobbers(X) -> str @AY {
|
||||||
; ---- convert the ubyte in A in hex string form
|
; ---- convert the ubyte in A in hex string form
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.ubyte2hex
|
jsr internal_ubyte2hex
|
||||||
sta string_out
|
sta string_out
|
||||||
sty string_out+1
|
sty string_out+1
|
||||||
lda #0
|
lda #0
|
||||||
@ -158,11 +140,11 @@ asmsub str_uwhex (uword value @ AY) -> str @AY {
|
|||||||
%asm {{
|
%asm {{
|
||||||
pha
|
pha
|
||||||
tya
|
tya
|
||||||
jsr conv.ubyte2hex
|
jsr internal_ubyte2hex
|
||||||
sta string_out
|
sta string_out
|
||||||
sty string_out+1
|
sty string_out+1
|
||||||
pla
|
pla
|
||||||
jsr conv.ubyte2hex
|
jsr internal_ubyte2hex
|
||||||
sta string_out+2
|
sta string_out+2
|
||||||
sty string_out+3
|
sty string_out+3
|
||||||
lda #0
|
lda #0
|
||||||
@ -176,9 +158,9 @@ asmsub str_uwhex (uword value @ AY) -> str @AY {
|
|||||||
asmsub str_uw0 (uword value @ AY) clobbers(X) -> str @AY {
|
asmsub str_uw0 (uword value @ AY) clobbers(X) -> str @AY {
|
||||||
; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total)
|
; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.uword2decimal
|
jsr conv.internal_uword2decimal
|
||||||
ldy #0
|
ldy #0
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
sta string_out,y
|
sta string_out,y
|
||||||
beq +
|
beq +
|
||||||
iny
|
iny
|
||||||
@ -193,11 +175,11 @@ asmsub str_uw0 (uword value @ AY) clobbers(X) -> str @AY {
|
|||||||
asmsub str_uw (uword value @ AY) clobbers(X) -> str @AY {
|
asmsub str_uw (uword value @ AY) clobbers(X) -> str @AY {
|
||||||
; ---- convert the uword in A/Y in decimal string form, without left padding 0s
|
; ---- convert the uword in A/Y in decimal string form, without left padding 0s
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.uword2decimal
|
jsr conv.internal_uword2decimal
|
||||||
ldx #0
|
ldx #0
|
||||||
_output_digits
|
_output_digits
|
||||||
ldy #0
|
ldy #0
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
- lda internal_uword2decimal.decTenThousands,y
|
||||||
beq _allzero
|
beq _allzero
|
||||||
cmp #'0'
|
cmp #'0'
|
||||||
bne _gotdigit
|
bne _gotdigit
|
||||||
@ -206,7 +188,7 @@ _output_digits
|
|||||||
_gotdigit sta string_out,x
|
_gotdigit sta string_out,x
|
||||||
inx
|
inx
|
||||||
iny
|
iny
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
lda internal_uword2decimal.decTenThousands,y
|
||||||
bne _gotdigit
|
bne _gotdigit
|
||||||
_end lda #0
|
_end lda #0
|
||||||
sta string_out,x
|
sta string_out,x
|
||||||
@ -238,7 +220,7 @@ asmsub str_w (word value @ AY) clobbers(X) -> str @AY {
|
|||||||
adc #1
|
adc #1
|
||||||
bcc +
|
bcc +
|
||||||
iny
|
iny
|
||||||
+ jsr conv.uword2decimal
|
+ jsr conv.internal_uword2decimal
|
||||||
ldx #1
|
ldx #1
|
||||||
bne str_uw._output_digits
|
bne str_uw._output_digits
|
||||||
rts
|
rts
|
||||||
@ -533,17 +515,25 @@ _stop
|
|||||||
|
|
||||||
; ----- low level number conversions to decimal strings ----
|
; ----- low level number conversions to decimal strings ----
|
||||||
|
|
||||||
asmsub ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
asmsub internal_ubyte2decimal(ubyte value @A) -> ubyte @Y, ubyte @X, ubyte @A {
|
||||||
; ---- A to decimal string in Y/A/X (100s in Y, 10s in A, 1s in X)
|
%asm {{
|
||||||
%asm {{
|
ldy #'0'-1
|
||||||
ldy #uword2decimal.ASCII_0_OFFSET
|
ldx #'9'+1
|
||||||
jmp uword2decimal.hex_try200
|
sec
|
||||||
}}
|
- iny
|
||||||
|
sbc #100
|
||||||
|
bcs -
|
||||||
|
- dex
|
||||||
|
adc #10
|
||||||
|
bmi -
|
||||||
|
adc #'0'-1
|
||||||
|
rts
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub uword2decimal (uword value @AY) -> ubyte @Y, ubyte @A, ubyte @X {
|
asmsub internal_uword2decimal (uword value @AY) -> ubyte @Y, ubyte @A, ubyte @X {
|
||||||
; ---- convert 16 bit uword in A/Y to decimal
|
; ---- convert 16 bit uword in A/Y to decimal
|
||||||
; output in uword2decimal.decTenThousands, decThousands, decHundreds, decTens, decOnes
|
; output in internal_uword2decimal.decTenThousands, decThousands, decHundreds, decTens, decOnes
|
||||||
; (these are terminated by a zero byte so they can be easily printed)
|
; (these are terminated by a zero byte so they can be easily printed)
|
||||||
; also returns Y = 100's, A = 10's, X = 1's
|
; also returns Y = 100's, A = 10's, X = 1's
|
||||||
|
|
||||||
@ -716,7 +706,7 @@ decOnes .byte 0
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
asmsub internal_byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
||||||
; ---- A (signed byte) to decimal string in Y/A/X (100s in Y, 10s in A, 1s in X)
|
; ---- A (signed byte) to decimal string in Y/A/X (100s in Y, 10s in A, 1s in X)
|
||||||
; note: if the number is negative, you have to deal with the '-' yourself!
|
; note: if the number is negative, you have to deal with the '-' yourself!
|
||||||
%asm {{
|
%asm {{
|
||||||
@ -725,11 +715,11 @@ asmsub byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
|||||||
eor #255
|
eor #255
|
||||||
clc
|
clc
|
||||||
adc #1
|
adc #1
|
||||||
+ jmp ubyte2decimal
|
+ jmp internal_ubyte2decimal
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub ubyte2hex (ubyte value @A) clobbers(X) -> ubyte @A, ubyte @Y {
|
asmsub internal_ubyte2hex (ubyte value @A) clobbers(X) -> ubyte @A, ubyte @Y {
|
||||||
; ---- A to hex petscii string in AY (first hex char in A, second hex char in Y)
|
; ---- A to hex petscii string in AY (first hex char in A, second hex char in Y)
|
||||||
%asm {{
|
%asm {{
|
||||||
pha
|
pha
|
||||||
@ -749,7 +739,7 @@ _hex_digits .text "0123456789abcdef" ; can probably be reused for other stuff as
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub uword2hex (uword value @AY) clobbers(A,Y) {
|
asmsub internal_uword2hex (uword value @AY) clobbers(A,Y) {
|
||||||
; ---- convert 16 bit uword in A/Y into 4-character hexadecimal string 'uword2hex.output' (0-terminated)
|
; ---- convert 16 bit uword in A/Y into 4-character hexadecimal string 'uword2hex.output' (0-terminated)
|
||||||
%asm {{
|
%asm {{
|
||||||
sta P8ZP_SCRATCH_REG
|
sta P8ZP_SCRATCH_REG
|
||||||
|
@ -525,6 +525,39 @@ io_error:
|
|||||||
goto done
|
goto done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; similar to above, but instead of fetching the entire string, it only fetches the status code and returns it as ubyte
|
||||||
|
; in case of IO error, returns 255 (CMDR-DOS itself is physically unable to return such a value)
|
||||||
|
sub status_code() -> ubyte {
|
||||||
|
if cbm.READST()==128 {
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
|
cbm.SETNAM(0, list_filename)
|
||||||
|
cbm.SETLFS(15, drivenumber, 15)
|
||||||
|
void cbm.OPEN() ; open 15,8,15
|
||||||
|
if_cs
|
||||||
|
goto io_error
|
||||||
|
void cbm.CHKIN(15) ; use #15 as input channel
|
||||||
|
|
||||||
|
list_filename[0] = cbm.CHRIN()
|
||||||
|
list_filename[1] = cbm.CHRIN()
|
||||||
|
list_filename[2] = 0
|
||||||
|
|
||||||
|
while cbm.READST()==0 {
|
||||||
|
void cbm.CHRIN()
|
||||||
|
}
|
||||||
|
|
||||||
|
cbm.CLRCHN() ; restore default i/o devices
|
||||||
|
cbm.CLOSE(15)
|
||||||
|
return conv.str2ubyte(list_filename)
|
||||||
|
|
||||||
|
io_error:
|
||||||
|
cbm.CLRCHN()
|
||||||
|
cbm.CLOSE(15)
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; saves a block of memory to disk, including the default 2 byte prg header.
|
; saves a block of memory to disk, including the default 2 byte prg header.
|
||||||
sub save(uword filenameptr, uword startaddress, uword savesize) -> bool {
|
sub save(uword filenameptr, uword startaddress, uword savesize) -> bool {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
%import syslib
|
%import syslib
|
||||||
%import conv
|
%import conv
|
||||||
%import shared_textio_functions
|
%import shared_cbm_textio_functions
|
||||||
|
|
||||||
txt {
|
txt {
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ const ubyte DEFAULT_HEIGHT = 60
|
|||||||
const ubyte VERA_TEXTMATRIX_BANK = 1
|
const ubyte VERA_TEXTMATRIX_BANK = 1
|
||||||
const uword VERA_TEXTMATRIX_ADDR = $b000
|
const uword VERA_TEXTMATRIX_ADDR = $b000
|
||||||
|
|
||||||
|
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
||||||
|
|
||||||
|
|
||||||
sub clear_screen() {
|
sub clear_screen() {
|
||||||
chrout(147)
|
chrout(147)
|
||||||
@ -431,215 +433,6 @@ _nextline
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
|
||||||
|
|
||||||
asmsub print (str text @ AY) clobbers(A,Y) {
|
|
||||||
; ---- print null terminated string, in PETSCII encoding, 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 cbm.CHROUT of that single char.
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_B1
|
|
||||||
sty P8ZP_SCRATCH_REG
|
|
||||||
ldy #0
|
|
||||||
- lda (P8ZP_SCRATCH_B1),y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
pha
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
_print_byte_digits
|
|
||||||
pha
|
|
||||||
cpy #'0'
|
|
||||||
beq +
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
bra _ones
|
|
||||||
+ pla
|
|
||||||
cmp #'0'
|
|
||||||
beq _ones
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
_ones txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the byte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
pha
|
|
||||||
cmp #0
|
|
||||||
bpl +
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
+ pla
|
|
||||||
jsr conv.byte2decimal
|
|
||||||
bra print_ub._print_byte_digits
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
||||||
%asm {{
|
|
||||||
bcc +
|
|
||||||
pha
|
|
||||||
lda #'$'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
+ jsr conv.ubyte2hex
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
tya
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- 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 cbm.CHROUT
|
|
||||||
+ ldy #8
|
|
||||||
- lda #'0'
|
|
||||||
asl P8ZP_SCRATCH_B1
|
|
||||||
bcc +
|
|
||||||
lda #'1'
|
|
||||||
+ jsr cbm.CHROUT
|
|
||||||
dey
|
|
||||||
bne -
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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
|
|
||||||
bra print_ubbin
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uwhex (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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
|
|
||||||
bra print_ubhex
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq _allzero
|
|
||||||
cmp #'0'
|
|
||||||
bne _gotdigit
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
|
|
||||||
_gotdigit
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
|
||||||
bne _gotdigit
|
|
||||||
rts
|
|
||||||
_allzero
|
|
||||||
lda #'0'
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
||||||
%asm {{
|
|
||||||
cpy #0
|
|
||||||
bpl +
|
|
||||||
pha
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
tya
|
|
||||||
eor #255
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
eor #255
|
|
||||||
ina
|
|
||||||
bne +
|
|
||||||
iny
|
|
||||||
+ bra print_uw
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub input_chars (uword buffer @ AY) clobbers(A) -> ubyte @ Y {
|
|
||||||
; ---- Input a string (max. 80 chars) from the keyboard, in PETSCII encoding.
|
|
||||||
; 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 cbm.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
|
|
||||||
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A) {
|
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A) {
|
||||||
; ---- sets the character in the screen matrix at the given position
|
; ---- sets the character in the screen matrix at the given position
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -460,6 +460,38 @@ io_error:
|
|||||||
goto done
|
goto done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; similar to above, but instead of fetching the entire string, it only fetches the status code and returns it as ubyte
|
||||||
|
; in case of IO error, returns 255 (CBM-DOS itself is physically unable to return such a value)
|
||||||
|
sub status_code() -> ubyte {
|
||||||
|
if cbm.READST()==128 {
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
|
cbm.SETNAM(0, list_filename)
|
||||||
|
cbm.SETLFS(15, drivenumber, 15)
|
||||||
|
void cbm.OPEN() ; open 15,8,15
|
||||||
|
if_cs
|
||||||
|
goto io_error
|
||||||
|
void cbm.CHKIN(15) ; use #15 as input channel
|
||||||
|
|
||||||
|
list_filename[0] = cbm.CHRIN()
|
||||||
|
list_filename[1] = cbm.CHRIN()
|
||||||
|
list_filename[2] = 0
|
||||||
|
|
||||||
|
while cbm.READST()==0 {
|
||||||
|
void cbm.CHRIN()
|
||||||
|
}
|
||||||
|
|
||||||
|
cbm.CLRCHN() ; restore default i/o devices
|
||||||
|
cbm.CLOSE(15)
|
||||||
|
return conv.str2ubyte(list_filename)
|
||||||
|
|
||||||
|
io_error:
|
||||||
|
cbm.CLRCHN()
|
||||||
|
cbm.CLOSE(15)
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
sub save(uword filenameptr, uword start_address, uword savesize) -> bool {
|
sub save(uword filenameptr, uword start_address, uword savesize) -> bool {
|
||||||
cbm.SETNAM(string.length(filenameptr), filenameptr)
|
cbm.SETNAM(string.length(filenameptr), filenameptr)
|
||||||
cbm.SETLFS(1, drivenumber, 0)
|
cbm.SETLFS(1, drivenumber, 0)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
%import syslib
|
%import syslib
|
||||||
%import conv
|
%import conv
|
||||||
%import shared_textio_functions
|
%import shared_cbm_textio_functions
|
||||||
|
|
||||||
txt {
|
txt {
|
||||||
%option no_symbol_prefixing, ignore_unused
|
%option no_symbol_prefixing, ignore_unused
|
||||||
@ -12,6 +12,8 @@ txt {
|
|||||||
const ubyte DEFAULT_WIDTH = 40
|
const ubyte DEFAULT_WIDTH = 40
|
||||||
const ubyte DEFAULT_HEIGHT = 25
|
const ubyte DEFAULT_HEIGHT = 25
|
||||||
|
|
||||||
|
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
||||||
|
|
||||||
|
|
||||||
sub clear_screen() {
|
sub clear_screen() {
|
||||||
chrout(147)
|
chrout(147)
|
||||||
@ -145,216 +147,6 @@ asmsub scroll_down () clobbers(A,X) {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
romsub $FFD2 = chrout(ubyte character @ A) ; for consistency. You can also use cbm.CHROUT directly ofcourse. Note: takes a PETSCII encoded character.
|
|
||||||
|
|
||||||
asmsub print (str text @ AY) clobbers(A,Y) {
|
|
||||||
; ---- print null terminated string, in PETSCII encoding, 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 cbm.CHROUT of that single char.
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_B1
|
|
||||||
sty P8ZP_SCRATCH_REG
|
|
||||||
ldy #0
|
|
||||||
- lda (P8ZP_SCRATCH_B1),y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
pha
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.ubyte2decimal
|
|
||||||
_print_byte_digits
|
|
||||||
pha
|
|
||||||
cpy #'0'
|
|
||||||
beq +
|
|
||||||
tya
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
jmp _ones
|
|
||||||
+ pla
|
|
||||||
cmp #'0'
|
|
||||||
beq _ones
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
_ones txa
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
|
||||||
; ---- print the byte in A in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
pha
|
|
||||||
cmp #0
|
|
||||||
bpl +
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
+ pla
|
|
||||||
jsr conv.byte2decimal
|
|
||||||
jmp print_ub._print_byte_digits
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
|
||||||
%asm {{
|
|
||||||
bcc +
|
|
||||||
pha
|
|
||||||
lda #'$'
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
pla
|
|
||||||
+ jsr conv.ubyte2hex
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
tya
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
|
||||||
; ---- 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 cbm.CHROUT
|
|
||||||
+ ldy #8
|
|
||||||
- lda #'0'
|
|
||||||
asl P8ZP_SCRATCH_B1
|
|
||||||
bcc +
|
|
||||||
lda #'1'
|
|
||||||
+ jsr cbm.CHROUT
|
|
||||||
dey
|
|
||||||
bne -
|
|
||||||
rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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, bool prefix @ Pc) clobbers(A,X,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,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq +
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
|
||||||
%asm {{
|
|
||||||
jsr conv.uword2decimal
|
|
||||||
ldy #0
|
|
||||||
- lda conv.uword2decimal.decTenThousands,y
|
|
||||||
beq _allzero
|
|
||||||
cmp #'0'
|
|
||||||
bne _gotdigit
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
|
|
||||||
_gotdigit
|
|
||||||
jsr cbm.CHROUT
|
|
||||||
iny
|
|
||||||
lda conv.uword2decimal.decTenThousands,y
|
|
||||||
bne _gotdigit
|
|
||||||
rts
|
|
||||||
_allzero
|
|
||||||
lda #'0'
|
|
||||||
jmp cbm.CHROUT
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
|
||||||
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
|
||||||
%asm {{
|
|
||||||
cpy #0
|
|
||||||
bpl +
|
|
||||||
pha
|
|
||||||
lda #'-'
|
|
||||||
jsr cbm.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, in PETSCII encoding.
|
|
||||||
; 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 cbm.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
|
|
||||||
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers(A, Y) {
|
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
|
; ---- sets the character in the screen matrix at the given position
|
||||||
%asm {{
|
%asm {{
|
||||||
|
251
compiler/res/prog8lib/shared_cbm_textio_functions.p8
Normal file
251
compiler/res/prog8lib/shared_cbm_textio_functions.p8
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
txt {
|
||||||
|
; the textio functions common across CBM-compatible compiler targets (c64, c128, pet32 and cx16)
|
||||||
|
|
||||||
|
%option merge, no_symbol_prefixing, ignore_unused
|
||||||
|
|
||||||
|
asmsub print (str text @ AY) clobbers(A,Y) {
|
||||||
|
; ---- print null terminated string, in PETSCII encoding, 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 cbm.CHROUT of that single char.
|
||||||
|
%asm {{
|
||||||
|
sta P8ZP_SCRATCH_B1
|
||||||
|
sty P8ZP_SCRATCH_REG
|
||||||
|
ldy #0
|
||||||
|
- lda (P8ZP_SCRATCH_B1),y
|
||||||
|
beq +
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
iny
|
||||||
|
bne -
|
||||||
|
+ rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_ubhex (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
||||||
|
; ---- print the ubyte in A in hex form (if Carry is set, a radix prefix '$' is printed as well)
|
||||||
|
%asm {{
|
||||||
|
bcc +
|
||||||
|
pha
|
||||||
|
lda #'$'
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
pla
|
||||||
|
+ jsr conv.internal_ubyte2hex
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
tya
|
||||||
|
jmp cbm.CHROUT
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_ubbin (ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y) {
|
||||||
|
; ---- 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 cbm.CHROUT
|
||||||
|
+ ldy #8
|
||||||
|
- lda #'0'
|
||||||
|
asl P8ZP_SCRATCH_B1
|
||||||
|
bcc +
|
||||||
|
lda #'1'
|
||||||
|
+ jsr cbm.CHROUT
|
||||||
|
dey
|
||||||
|
bne -
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_uwbin (uword value @ AY, bool prefix @ Pc) clobbers(A,X,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, bool prefix @ Pc) clobbers(A,X,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,X,Y) {
|
||||||
|
; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total)
|
||||||
|
%asm {{
|
||||||
|
jsr conv.internal_uword2decimal
|
||||||
|
ldy #0
|
||||||
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
|
beq +
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
iny
|
||||||
|
bne -
|
||||||
|
+ rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_uw (uword value @ AY) clobbers(A,X,Y) {
|
||||||
|
; ---- print the uword in A/Y in decimal form, without left padding 0s
|
||||||
|
%asm {{
|
||||||
|
jsr conv.internal_uword2decimal
|
||||||
|
ldy #0
|
||||||
|
- lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
|
beq _allzero
|
||||||
|
cmp #'0'
|
||||||
|
bne _gotdigit
|
||||||
|
iny
|
||||||
|
bne -
|
||||||
|
_gotdigit jsr cbm.CHROUT
|
||||||
|
iny
|
||||||
|
lda conv.internal_uword2decimal.decTenThousands,y
|
||||||
|
bne _gotdigit
|
||||||
|
rts
|
||||||
|
_allzero lda #'0'
|
||||||
|
jmp cbm.CHROUT
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_w (word value @ AY) clobbers(A,X,Y) {
|
||||||
|
; ---- print the (signed) word in A/Y in decimal form, without left padding 0's
|
||||||
|
%asm {{
|
||||||
|
cpy #0
|
||||||
|
bpl +
|
||||||
|
pha
|
||||||
|
lda #'-'
|
||||||
|
jsr cbm.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, in PETSCII encoding.
|
||||||
|
; 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 cbm.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
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub petscii2scr(ubyte petscii_char @A) -> ubyte @A {
|
||||||
|
; -- convert petscii character to screencode
|
||||||
|
%asm {{
|
||||||
|
sta P8ZP_SCRATCH_REG
|
||||||
|
lsr a
|
||||||
|
lsr a
|
||||||
|
lsr a
|
||||||
|
lsr a
|
||||||
|
lsr a
|
||||||
|
tax
|
||||||
|
lda _offsets,x
|
||||||
|
eor P8ZP_SCRATCH_REG
|
||||||
|
rts
|
||||||
|
_offsets .byte 128, 0, 64, 32, 64, 192, 128, 128
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub petscii2scr_str(str petscii_string @AY) {
|
||||||
|
; -- convert petscii string to screencodes string
|
||||||
|
%asm {{
|
||||||
|
sta P8ZP_SCRATCH_W1
|
||||||
|
sty P8ZP_SCRATCH_W1+1
|
||||||
|
ldy #0
|
||||||
|
- lda (P8ZP_SCRATCH_W1),y
|
||||||
|
beq +
|
||||||
|
jsr petscii2scr
|
||||||
|
sta (P8ZP_SCRATCH_W1),y
|
||||||
|
iny
|
||||||
|
bne -
|
||||||
|
+ rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub print_bool(bool value) {
|
||||||
|
if value
|
||||||
|
txt.print("true")
|
||||||
|
else
|
||||||
|
txt.print("false")
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_ub0 (ubyte value @ A) clobbers(A,X,Y) {
|
||||||
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
||||||
|
%asm {{
|
||||||
|
jsr conv.internal_ubyte2decimal
|
||||||
|
pha
|
||||||
|
tya
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
txa
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
pla
|
||||||
|
jmp cbm.CHROUT
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_ub (ubyte value @ A) clobbers(A,X,Y) {
|
||||||
|
; ---- print the ubyte in A in decimal form, without left padding 0s
|
||||||
|
%asm {{
|
||||||
|
jsr conv.internal_ubyte2decimal
|
||||||
|
_print_byte_digits
|
||||||
|
pha
|
||||||
|
cpy #'0'
|
||||||
|
beq +
|
||||||
|
tya
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
txa
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
jmp _ones
|
||||||
|
+ cpx #'0'
|
||||||
|
beq _ones
|
||||||
|
txa
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
_ones pla
|
||||||
|
jmp cbm.CHROUT
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub print_b (byte value @ A) clobbers(A,X,Y) {
|
||||||
|
; ---- print the byte in A in decimal form, without left padding 0s
|
||||||
|
%asm {{
|
||||||
|
pha
|
||||||
|
cmp #0
|
||||||
|
bpl +
|
||||||
|
lda #'-'
|
||||||
|
jsr cbm.CHROUT
|
||||||
|
+ pla
|
||||||
|
jsr conv.internal_byte2decimal
|
||||||
|
jmp print_ub._print_byte_digits
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,46 +0,0 @@
|
|||||||
txt {
|
|
||||||
; the textio functions shared across compiler targets
|
|
||||||
%option merge, no_symbol_prefixing, ignore_unused
|
|
||||||
|
|
||||||
asmsub petscii2scr(ubyte petscii_char @A) -> ubyte @A {
|
|
||||||
; -- convert petscii character to screencode
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_REG
|
|
||||||
lsr a
|
|
||||||
lsr a
|
|
||||||
lsr a
|
|
||||||
lsr a
|
|
||||||
lsr a
|
|
||||||
tax
|
|
||||||
lda _offsets,x
|
|
||||||
eor P8ZP_SCRATCH_REG
|
|
||||||
rts
|
|
||||||
_offsets .byte 128, 0, 64, 32, 64, 192, 128, 128
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
asmsub petscii2scr_str(str petscii_string @AY) {
|
|
||||||
; -- convert petscii string to screencodes string
|
|
||||||
%asm {{
|
|
||||||
sta P8ZP_SCRATCH_W1
|
|
||||||
sty P8ZP_SCRATCH_W1+1
|
|
||||||
ldy #0
|
|
||||||
- lda (P8ZP_SCRATCH_W1),y
|
|
||||||
beq +
|
|
||||||
jsr petscii2scr
|
|
||||||
sta (P8ZP_SCRATCH_W1),y
|
|
||||||
iny
|
|
||||||
bne -
|
|
||||||
+ rts
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub print_bool(bool value) {
|
|
||||||
if value
|
|
||||||
txt.print("true")
|
|
||||||
else
|
|
||||||
txt.print("false")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -145,6 +145,12 @@ diskio {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub status_code() -> ubyte {
|
||||||
|
; -- return status code instead of whole CBM-DOS status string. (in this case always 255, which means 'unable to return sensible value')
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub save(uword filenameptr, uword start_address, uword savesize) -> bool {
|
sub save(uword filenameptr, uword start_address, uword savesize) -> bool {
|
||||||
%ir {{
|
%ir {{
|
||||||
load.b r65532,0
|
load.b r65532,0
|
||||||
|
@ -42,7 +42,7 @@ main {
|
|||||||
"textio",
|
"textio",
|
||||||
"syslib",
|
"syslib",
|
||||||
"conv",
|
"conv",
|
||||||
"shared_textio_functions",
|
"shared_cbm_textio_functions",
|
||||||
"floats",
|
"floats",
|
||||||
"shared_floats_functions",
|
"shared_floats_functions",
|
||||||
"math",
|
"math",
|
||||||
@ -101,7 +101,7 @@ main {
|
|||||||
listOf(
|
listOf(
|
||||||
internedStringsModuleName,
|
internedStringsModuleName,
|
||||||
filenameBase,
|
filenameBase,
|
||||||
"textio", "syslib", "conv", "shared_textio_functions", "floats", "shared_floats_functions", "math", "prog8_lib"
|
"textio", "syslib", "conv", "shared_cbm_textio_functions", "floats", "shared_floats_functions", "math", "prog8_lib"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
options.floats shouldBe true
|
options.floats shouldBe true
|
||||||
|
Loading…
Reference in New Issue
Block a user