mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
text editor configs
This commit is contained in:
parent
bec2224c3d
commit
ee7f9d457d
22
compiler/res/.editorconfig
Normal file
22
compiler/res/.editorconfig
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 120
|
||||||
|
tab_width = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
ij_smart_tabs = true
|
||||||
|
|
||||||
|
[*.p8]
|
||||||
|
tab_width = 4
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.asm]
|
||||||
|
tab_width = 8
|
||||||
|
indent_size = 8
|
||||||
|
indent_style = tab
|
@ -1,8 +1,6 @@
|
|||||||
; Prog8 definitions for number conversions routines.
|
; Number conversions routines.
|
||||||
;
|
;
|
||||||
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
;
|
|
||||||
; indent format: TABS, size=8
|
|
||||||
|
|
||||||
|
|
||||||
conv {
|
conv {
|
||||||
@ -11,20 +9,20 @@ conv {
|
|||||||
|
|
||||||
asmsub ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
asmsub ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @A, ubyte @X {
|
||||||
; ---- A to decimal string in Y/A/X (100s in Y, 10s in A, 1s in X)
|
; ---- A to decimal string in Y/A/X (100s in Y, 10s in A, 1s in X)
|
||||||
%asm {{
|
%asm {{
|
||||||
ldy #uword2decimal.ASCII_0_OFFSET
|
ldy #uword2decimal.ASCII_0_OFFSET
|
||||||
bne uword2decimal.hex_try200
|
bne uword2decimal.hex_try200
|
||||||
rts
|
rts
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub uword2decimal (uword value @AY) -> ubyte @Y, ubyte @A, ubyte @X {
|
asmsub 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 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
|
||||||
|
|
||||||
%asm {{
|
%asm {{
|
||||||
|
|
||||||
;Convert 16 bit Hex to Decimal (0-65535) Rev 2
|
;Convert 16 bit Hex to Decimal (0-65535) Rev 2
|
||||||
;By Omegamatrix Further optimizations by tepples
|
;By Omegamatrix Further optimizations by tepples
|
||||||
@ -241,7 +239,7 @@ asmsub uword2hex (uword value @AY) clobbers(A,Y) {
|
|||||||
sta output+2
|
sta output+2
|
||||||
sty output+3
|
sty output+3
|
||||||
rts
|
rts
|
||||||
output .text "0000", $00 ; 0-terminated output buffer (to make printing easier)
|
output .text "0000", $00 ; 0-terminated output buffer (to make printing easier)
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,38 +247,38 @@ output .text "0000", $00 ; 0-terminated output buffer (to make printing ea
|
|||||||
; ---- string conversion to numbers -----
|
; ---- string conversion to numbers -----
|
||||||
|
|
||||||
asmsub any2uword(str string @AY) -> uword @AY {
|
asmsub any2uword(str string @AY) -> uword @AY {
|
||||||
; -- returns the number value of the given string
|
; -- returns the number value of the given string
|
||||||
; the string may be in decimal, hex or binary format
|
; the string may be in decimal, hex or binary format
|
||||||
; (the latter two require a $ or % prefix to be recognised)
|
; (the latter two require a $ or % prefix to be recognised)
|
||||||
; (any non-digit character will terminate the number string that is parsed)
|
; (any non-digit character will terminate the number string that is parsed)
|
||||||
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
pha
|
pha
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
sty P8ZP_SCRATCH_W1+1
|
sty P8ZP_SCRATCH_W1+1
|
||||||
ldy #0
|
ldy #0
|
||||||
lda (P8ZP_SCRATCH_W1)
|
lda (P8ZP_SCRATCH_W1)
|
||||||
ldy P8ZP_SCRATCH_W1+1
|
ldy P8ZP_SCRATCH_W1+1
|
||||||
cmp #'$'
|
cmp #'$'
|
||||||
beq _hex
|
beq _hex
|
||||||
cmp #'%'
|
cmp #'%'
|
||||||
beq _bin
|
beq _bin
|
||||||
pla
|
pla
|
||||||
jmp str2uword
|
jmp str2uword
|
||||||
_hex pla
|
_hex pla
|
||||||
jmp hex2uword
|
jmp hex2uword
|
||||||
_bin pla
|
_bin pla
|
||||||
jmp bin2uword
|
jmp bin2uword
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline asmsub str2ubyte(str string @AY) clobbers(Y) -> ubyte @A {
|
inline asmsub str2ubyte(str string @AY) clobbers(Y) -> ubyte @A {
|
||||||
; -- returns in A the unsigned byte value of the string number argument in AY
|
; -- returns in A the unsigned byte value of the string number argument in AY
|
||||||
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
||||||
; (any non-digit character will terminate the number string that is parsed)
|
; (any non-digit character will terminate the number string that is parsed)
|
||||||
; result in A, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in A, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.str2uword
|
jsr conv.str2uword
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +286,9 @@ inline asmsub str2byte(str string @AY) clobbers(Y) -> ubyte @A {
|
|||||||
; -- returns in A the signed byte value of the string number argument in AY
|
; -- returns in A the signed byte value of the string number argument in AY
|
||||||
; the number may be preceded by a + or - sign but may NOT contain spaces
|
; the number may be preceded by a + or - sign but may NOT contain spaces
|
||||||
; (any non-digit character will terminate the number string that is parsed)
|
; (any non-digit character will terminate the number string that is parsed)
|
||||||
; result in A, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in A, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr conv.str2word
|
jsr conv.str2word
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,11 +296,11 @@ asmsub str2uword(str string @AY) -> uword @AY {
|
|||||||
; -- returns the unsigned word value of the string number argument in AY
|
; -- returns the unsigned word value of the string number argument in AY
|
||||||
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
||||||
; (any non-digit character will terminate the number string that is parsed)
|
; (any non-digit character will terminate the number string that is parsed)
|
||||||
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
_result = P8ZP_SCRATCH_W1
|
_result = P8ZP_SCRATCH_W1
|
||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
sty P8ZP_SCRATCH_W2+1
|
sty P8ZP_SCRATCH_W2+1
|
||||||
ldy #0
|
ldy #0
|
||||||
sty _result
|
sty _result
|
||||||
sty _result+1
|
sty _result+1
|
||||||
@ -313,7 +311,7 @@ _loop
|
|||||||
sbc #48
|
sbc #48
|
||||||
bpl _digit
|
bpl _digit
|
||||||
_done
|
_done
|
||||||
sty cx16.r15
|
sty cx16.r15
|
||||||
lda _result
|
lda _result
|
||||||
ldy _result+1
|
ldy _result+1
|
||||||
rts
|
rts
|
||||||
@ -357,7 +355,7 @@ asmsub str2word(str string @AY) -> word @AY {
|
|||||||
; -- returns the signed word value of the string number argument in AY
|
; -- returns the signed word value of the string number argument in AY
|
||||||
; the number may be preceded by a + or - sign but may NOT contain spaces
|
; the number may be preceded by a + or - sign but may NOT contain spaces
|
||||||
; (any non-digit character will terminate the number string that is parsed)
|
; (any non-digit character will terminate the number string that is parsed)
|
||||||
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
_result = P8ZP_SCRATCH_W1
|
_result = P8ZP_SCRATCH_W1
|
||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
@ -380,7 +378,7 @@ _parse lda (P8ZP_SCRATCH_W2),y
|
|||||||
sbc #48
|
sbc #48
|
||||||
bpl _digit
|
bpl _digit
|
||||||
_done
|
_done
|
||||||
sty cx16.r15
|
sty cx16.r15
|
||||||
lda _negative
|
lda _negative
|
||||||
beq +
|
beq +
|
||||||
sec
|
sec
|
||||||
@ -394,7 +392,7 @@ _done
|
|||||||
ldy _result+1
|
ldy _result+1
|
||||||
rts
|
rts
|
||||||
_digit
|
_digit
|
||||||
cmp #10
|
cmp #10
|
||||||
bcs _done
|
bcs _done
|
||||||
; add digit to result
|
; add digit to result
|
||||||
pha
|
pha
|
||||||
@ -413,102 +411,102 @@ _negative .byte 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
asmsub hex2uword(str string @AY) -> uword @AY {
|
asmsub hex2uword(str string @AY) -> uword @AY {
|
||||||
; -- hexadecimal string (with or without '$') to uword.
|
; -- hexadecimal string (with or without '$') to uword.
|
||||||
; string may be in petscii or c64-screencode encoding.
|
; string may be in petscii or c64-screencode encoding.
|
||||||
; stops parsing at the first character that's not a hex digit (except leading $)
|
; stops parsing at the first character that's not a hex digit (except leading $)
|
||||||
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
sty P8ZP_SCRATCH_W2+1
|
sty P8ZP_SCRATCH_W2+1
|
||||||
ldy #0
|
ldy #0
|
||||||
sty P8ZP_SCRATCH_W1
|
sty P8ZP_SCRATCH_W1
|
||||||
sty P8ZP_SCRATCH_W1+1
|
sty P8ZP_SCRATCH_W1+1
|
||||||
sty cx16.r15+1
|
sty cx16.r15+1
|
||||||
lda (P8ZP_SCRATCH_W2),y
|
lda (P8ZP_SCRATCH_W2),y
|
||||||
beq _stop
|
beq _stop
|
||||||
cmp #'$'
|
cmp #'$'
|
||||||
bne _loop
|
bne _loop
|
||||||
iny
|
iny
|
||||||
_loop
|
_loop
|
||||||
lda #0
|
lda #0
|
||||||
sta P8ZP_SCRATCH_B1
|
sta P8ZP_SCRATCH_B1
|
||||||
lda (P8ZP_SCRATCH_W2),y
|
lda (P8ZP_SCRATCH_W2),y
|
||||||
beq _stop
|
beq _stop
|
||||||
cmp #7 ; screencode letters A-F are 1-6
|
cmp #7 ; screencode letters A-F are 1-6
|
||||||
bcc _add_letter
|
bcc _add_letter
|
||||||
cmp #'g'
|
cmp #'g'
|
||||||
bcs _stop
|
bcs _stop
|
||||||
cmp #'a'
|
cmp #'a'
|
||||||
bcs _add_letter
|
bcs _add_letter
|
||||||
cmp #'0'
|
cmp #'0'
|
||||||
bcc _stop
|
bcc _stop
|
||||||
cmp #'9'+1
|
cmp #'9'+1
|
||||||
bcs _stop
|
bcs _stop
|
||||||
_calc
|
_calc
|
||||||
asl P8ZP_SCRATCH_W1
|
asl P8ZP_SCRATCH_W1
|
||||||
rol P8ZP_SCRATCH_W1+1
|
rol P8ZP_SCRATCH_W1+1
|
||||||
asl P8ZP_SCRATCH_W1
|
asl P8ZP_SCRATCH_W1
|
||||||
rol P8ZP_SCRATCH_W1+1
|
rol P8ZP_SCRATCH_W1+1
|
||||||
asl P8ZP_SCRATCH_W1
|
asl P8ZP_SCRATCH_W1
|
||||||
rol P8ZP_SCRATCH_W1+1
|
rol P8ZP_SCRATCH_W1+1
|
||||||
asl P8ZP_SCRATCH_W1
|
asl P8ZP_SCRATCH_W1
|
||||||
rol P8ZP_SCRATCH_W1+1
|
rol P8ZP_SCRATCH_W1+1
|
||||||
and #$0f
|
and #$0f
|
||||||
clc
|
clc
|
||||||
adc P8ZP_SCRATCH_B1
|
adc P8ZP_SCRATCH_B1
|
||||||
ora P8ZP_SCRATCH_W1
|
ora P8ZP_SCRATCH_W1
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
iny
|
iny
|
||||||
bne _loop
|
bne _loop
|
||||||
_stop
|
_stop
|
||||||
sty cx16.r15
|
sty cx16.r15
|
||||||
lda P8ZP_SCRATCH_W1
|
lda P8ZP_SCRATCH_W1
|
||||||
ldy P8ZP_SCRATCH_W1+1
|
ldy P8ZP_SCRATCH_W1+1
|
||||||
rts
|
rts
|
||||||
_add_letter
|
_add_letter
|
||||||
pha
|
pha
|
||||||
lda #9
|
lda #9
|
||||||
sta P8ZP_SCRATCH_B1
|
sta P8ZP_SCRATCH_B1
|
||||||
pla
|
pla
|
||||||
jmp _calc
|
jmp _calc
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub bin2uword(str string @AY) -> uword @AY {
|
asmsub bin2uword(str string @AY) -> uword @AY {
|
||||||
; -- binary string (with or without '%') to uword.
|
; -- binary string (with or without '%') to uword.
|
||||||
; stops parsing at the first character that's not a 0 or 1. (except leading %)
|
; stops parsing at the first character that's not a 0 or 1. (except leading %)
|
||||||
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
; result in AY, number of characters processed also remains in cx16.r15 if you want to use it!! (0 = error)
|
||||||
%asm {{
|
%asm {{
|
||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
sty P8ZP_SCRATCH_W2+1
|
sty P8ZP_SCRATCH_W2+1
|
||||||
ldy #0
|
ldy #0
|
||||||
sty P8ZP_SCRATCH_W1
|
sty P8ZP_SCRATCH_W1
|
||||||
sty P8ZP_SCRATCH_W1+1
|
sty P8ZP_SCRATCH_W1+1
|
||||||
sty cx16.r15+1
|
sty cx16.r15+1
|
||||||
lda (P8ZP_SCRATCH_W2),y
|
lda (P8ZP_SCRATCH_W2),y
|
||||||
beq _stop
|
beq _stop
|
||||||
cmp #'%'
|
cmp #'%'
|
||||||
bne _loop
|
bne _loop
|
||||||
iny
|
iny
|
||||||
_loop
|
_loop
|
||||||
lda (P8ZP_SCRATCH_W2),y
|
lda (P8ZP_SCRATCH_W2),y
|
||||||
cmp #'0'
|
cmp #'0'
|
||||||
bcc _stop
|
bcc _stop
|
||||||
cmp #'2'
|
cmp #'2'
|
||||||
bcs _stop
|
bcs _stop
|
||||||
_first asl P8ZP_SCRATCH_W1
|
_first asl P8ZP_SCRATCH_W1
|
||||||
rol P8ZP_SCRATCH_W1+1
|
rol P8ZP_SCRATCH_W1+1
|
||||||
and #1
|
and #1
|
||||||
ora P8ZP_SCRATCH_W1
|
ora P8ZP_SCRATCH_W1
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
iny
|
iny
|
||||||
bne _loop
|
bne _loop
|
||||||
_stop
|
_stop
|
||||||
sty cx16.r15
|
sty cx16.r15
|
||||||
lda P8ZP_SCRATCH_W1
|
lda P8ZP_SCRATCH_W1
|
||||||
ldy P8ZP_SCRATCH_W1+1
|
ldy P8ZP_SCRATCH_W1+1
|
||||||
rts
|
rts
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
; routine to draw the Commander X16's log in petscii.
|
||||||
|
|
||||||
%import textio
|
%import textio
|
||||||
|
|
||||||
cx16logo {
|
cx16logo {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
; C64 and Cx16 disk drive I/O routines.
|
||||||
|
;
|
||||||
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
|
|
||||||
%import textio
|
%import textio
|
||||||
%import syslib
|
%import syslib
|
||||||
|
|
||||||
; Note: this code is compatible with C64 and CX16.
|
|
||||||
|
|
||||||
diskio {
|
diskio {
|
||||||
|
|
||||||
sub directory(ubyte drivenumber) -> ubyte {
|
sub directory(ubyte drivenumber) -> ubyte {
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
; Prog8 internal Math library routines - always included by the compiler
|
; Internal Math library routines - always included by the compiler
|
||||||
; Generic machine independent 6502 code.
|
; Generic machine independent 6502 code.
|
||||||
;
|
;
|
||||||
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
;
|
;
|
||||||
; indent format: TABS, size=8
|
|
||||||
|
|
||||||
|
|
||||||
; some more interesting routines can be found here:
|
; some more interesting routines can be found here:
|
||||||
; http://6502org.wikidot.com/software-math
|
; http://6502org.wikidot.com/software-math
|
||||||
; http://codebase64.org/doku.php?id=base:6502_6510_maths
|
; http://codebase64.org/doku.php?id=base:6502_6510_maths
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
; Prog8 internal Math library routines - always included by the compiler
|
; Internal Math library routines - always included by the compiler
|
||||||
;
|
;
|
||||||
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
;
|
|
||||||
; indent format: TABS, size=8
|
|
||||||
|
|
||||||
math {
|
math {
|
||||||
%asminclude "library:math.asm", ""
|
%asminclude "library:math.asm", ""
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
; Prog8 internal library routines - always included by the compiler
|
; Internal library routines - always included by the compiler
|
||||||
; Generic machine independent 6502 code.
|
; Generic machine independent 6502 code.
|
||||||
;
|
;
|
||||||
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
;
|
|
||||||
; indent format: TABS, size=8
|
|
||||||
|
|
||||||
|
|
||||||
read_byte_from_address_on_stack .proc
|
read_byte_from_address_on_stack .proc
|
||||||
@ -1021,33 +1019,33 @@ _arg_s2 .word 0
|
|||||||
strcmp_mem .proc
|
strcmp_mem .proc
|
||||||
; -- compares strings in s1 (AY) and s2 (P8ZP_SCRATCH_W2).
|
; -- compares strings in s1 (AY) and s2 (P8ZP_SCRATCH_W2).
|
||||||
; Returns -1,0,1 in A, depeding on the ordering. Clobbers Y.
|
; Returns -1,0,1 in A, depeding on the ordering. Clobbers Y.
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
sty P8ZP_SCRATCH_W1+1
|
sty P8ZP_SCRATCH_W1+1
|
||||||
_loop ldy #0
|
_loop ldy #0
|
||||||
lda (P8ZP_SCRATCH_W1),y
|
lda (P8ZP_SCRATCH_W1),y
|
||||||
bne +
|
bne +
|
||||||
lda (P8ZP_SCRATCH_W2),y
|
lda (P8ZP_SCRATCH_W2),y
|
||||||
bne _return_minusone
|
bne _return_minusone
|
||||||
beq _return
|
beq _return
|
||||||
+ lda (P8ZP_SCRATCH_W2),y
|
+ lda (P8ZP_SCRATCH_W2),y
|
||||||
sec
|
sec
|
||||||
sbc (P8ZP_SCRATCH_W1),y
|
sbc (P8ZP_SCRATCH_W1),y
|
||||||
bmi _return_one
|
bmi _return_one
|
||||||
bne _return_minusone
|
bne _return_minusone
|
||||||
inc P8ZP_SCRATCH_W1
|
inc P8ZP_SCRATCH_W1
|
||||||
bne +
|
bne +
|
||||||
inc P8ZP_SCRATCH_W1+1
|
inc P8ZP_SCRATCH_W1+1
|
||||||
+ inc P8ZP_SCRATCH_W2
|
+ inc P8ZP_SCRATCH_W2
|
||||||
bne _loop
|
bne _loop
|
||||||
inc P8ZP_SCRATCH_W2+1
|
inc P8ZP_SCRATCH_W2+1
|
||||||
bne _loop
|
bne _loop
|
||||||
_return_one
|
_return_one
|
||||||
lda #1
|
lda #1
|
||||||
_return rts
|
_return rts
|
||||||
_return_minusone
|
_return_minusone
|
||||||
lda #-1
|
lda #-1
|
||||||
rts
|
rts
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
|
|
||||||
sign_extend_stack_byte .proc
|
sign_extend_stack_byte .proc
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
; Prog8 internal library routines - always included by the compiler
|
; Internal library routines - always included by the compiler
|
||||||
;
|
;
|
||||||
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
;
|
|
||||||
; indent format: TABS, size=8
|
|
||||||
|
|
||||||
prog8_lib {
|
prog8_lib {
|
||||||
%asminclude "library:prog8_lib.asm", ""
|
%asminclude "library:prog8_lib.asm", ""
|
||||||
%asminclude "library:prog8_funcs.asm", ""
|
%asminclude "library:prog8_funcs.asm", ""
|
||||||
|
|
||||||
uword @zp retval_interm_w ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)
|
uword @zp retval_interm_w ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)
|
||||||
ubyte @zp retval_interm_b ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)
|
ubyte @zp retval_interm_b ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)
|
||||||
|
|
||||||
asmsub pattern_match(str string @AY, str pattern @R0) clobbers(Y) -> ubyte @A {
|
asmsub pattern_match(str string @AY, str pattern @R0) clobbers(Y) -> ubyte @A {
|
||||||
%asm {{
|
%asm {{
|
||||||
; pattern matching of a string.
|
; pattern matching of a string.
|
||||||
; Input: cx16.r0: A NUL-terminated, <255-length pattern
|
; Input: cx16.r0: A NUL-terminated, <255-length pattern
|
||||||
; AY: A NUL-terminated, <255-length string
|
; AY: A NUL-terminated, <255-length string
|
||||||
@ -42,43 +40,43 @@ str = P8ZP_SCRATCH_W1
|
|||||||
|
|
||||||
|
|
||||||
_match
|
_match
|
||||||
ldx #$00 ; x is an index in the pattern
|
ldx #$00 ; x is an index in the pattern
|
||||||
ldy #$ff ; y is an index in the string
|
ldy #$ff ; y is an index in the string
|
||||||
modify_pattern1
|
modify_pattern1
|
||||||
next lda $ffff,x ; look at next pattern character MODIFIED
|
next lda $ffff,x ; look at next pattern character MODIFIED
|
||||||
cmp #'*' ; is it a star?
|
cmp #'*' ; is it a star?
|
||||||
beq star ; yes, do the complicated stuff
|
beq star ; yes, do the complicated stuff
|
||||||
iny ; no, let's look at the string
|
iny ; no, let's look at the string
|
||||||
cmp #'?' ; is the pattern caracter a ques?
|
cmp #'?' ; is the pattern caracter a ques?
|
||||||
bne reg ; no, it's a regular character
|
bne reg ; no, it's a regular character
|
||||||
lda (str),y ; yes, so it will match anything
|
lda (str),y ; yes, so it will match anything
|
||||||
beq fail ; except the end of string
|
beq fail ; except the end of string
|
||||||
reg cmp (str),y ; are both characters the same?
|
reg cmp (str),y ; are both characters the same?
|
||||||
bne fail ; no, so no match
|
bne fail ; no, so no match
|
||||||
inx ; yes, keep checking
|
inx ; yes, keep checking
|
||||||
cmp #0 ; are we at end of string?
|
cmp #0 ; are we at end of string?
|
||||||
bne next ; not yet, loop
|
bne next ; not yet, loop
|
||||||
found rts ; success, return with c=1
|
found rts ; success, return with c=1
|
||||||
|
|
||||||
star inx ; skip star in pattern
|
star inx ; skip star in pattern
|
||||||
modify_pattern2
|
modify_pattern2
|
||||||
cmp $ffff,x ; string of stars equals one star MODIFIED
|
cmp $ffff,x ; string of stars equals one star MODIFIED
|
||||||
beq star ; so skip them also
|
beq star ; so skip them also
|
||||||
stloop txa ; we first try to match with * = ""
|
stloop txa ; we first try to match with * = ""
|
||||||
pha ; and grow it by 1 character every
|
pha ; and grow it by 1 character every
|
||||||
tya ; time we loop
|
tya ; time we loop
|
||||||
pha ; save x and y on stack
|
pha ; save x and y on stack
|
||||||
jsr next ; recursive call
|
jsr next ; recursive call
|
||||||
pla ; restore x and y
|
pla ; restore x and y
|
||||||
tay
|
tay
|
||||||
pla
|
pla
|
||||||
tax
|
tax
|
||||||
bcs found ; we found a match, return with c=1
|
bcs found ; we found a match, return with c=1
|
||||||
iny ; no match yet, try to grow * string
|
iny ; no match yet, try to grow * string
|
||||||
lda (str),y ; are we at the end of string?
|
lda (str),y ; are we at the end of string?
|
||||||
bne stloop ; not yet, add a character
|
bne stloop ; not yet, add a character
|
||||||
fail clc ; yes, no match found, return with c=0
|
fail clc ; yes, no match found, return with c=0
|
||||||
rts
|
rts
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
compiler/res/prog8lib/string.p8
Normal file
9
compiler/res/prog8lib/string.p8
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
; 0-terminated string manipulation routines.
|
||||||
|
;
|
||||||
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
|
|
||||||
|
|
||||||
|
string {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,48 +1,50 @@
|
|||||||
|
; utility debug code to print the X (evalstack) and SP (cpu stack) registers.
|
||||||
|
|
||||||
%import textio
|
%import textio
|
||||||
|
|
||||||
test_stack {
|
test_stack {
|
||||||
|
|
||||||
asmsub test() {
|
asmsub test() {
|
||||||
%asm {{
|
%asm {{
|
||||||
stx _saveX
|
stx _saveX
|
||||||
lda #13
|
lda #13
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'-'
|
lda #'-'
|
||||||
ldy #12
|
ldy #12
|
||||||
- jsr txt.chrout
|
- jsr txt.chrout
|
||||||
dey
|
dey
|
||||||
bne -
|
bne -
|
||||||
lda #13
|
lda #13
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'x'
|
lda #'x'
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'='
|
lda #'='
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda _saveX
|
lda _saveX
|
||||||
jsr txt.print_ub
|
jsr txt.print_ub
|
||||||
lda #' '
|
lda #' '
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'s'
|
lda #'s'
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'p'
|
lda #'p'
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'='
|
lda #'='
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
tsx
|
tsx
|
||||||
txa
|
txa
|
||||||
jsr txt.print_ub
|
jsr txt.print_ub
|
||||||
lda #13
|
lda #13
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
lda #'-'
|
lda #'-'
|
||||||
ldy #12
|
ldy #12
|
||||||
- jsr txt.chrout
|
- jsr txt.chrout
|
||||||
dey
|
dey
|
||||||
bne -
|
bne -
|
||||||
lda #13
|
lda #13
|
||||||
jsr txt.chrout
|
jsr txt.chrout
|
||||||
ldx _saveX
|
ldx _saveX
|
||||||
rts
|
rts
|
||||||
_saveX .byte 0
|
_saveX .byte 0
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
examples/.editorconfig
Normal file
22
examples/.editorconfig
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 120
|
||||||
|
tab_width = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
ij_smart_tabs = true
|
||||||
|
|
||||||
|
[*.p8]
|
||||||
|
tab_width = 4
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.asm]
|
||||||
|
tab_width = 8
|
||||||
|
indent_size = 8
|
||||||
|
indent_style = tab
|
Loading…
Reference in New Issue
Block a user