mirror of
https://github.com/irmen/prog8.git
synced 2024-07-24 22:29:15 +00:00
fix diskio.f_readline() that skipped first char. It also doesn't leave the end of line char in the string now.
This commit is contained in:
parent
72b4198301
commit
506ac8014c
@ -293,23 +293,32 @@ _in_buffer sta $ffff
|
|||||||
|
|
||||||
asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y {
|
asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y {
|
||||||
; Routine to read text lines from a text file. Lines must be less than 255 characters.
|
; Routine to read text lines from a text file. Lines must be less than 255 characters.
|
||||||
; Reads characters from the input file until (and including) a newline or return character (or EOF).
|
; Reads characters from the input file UNTIL a newline or return character (or EOF).
|
||||||
; The line read will be 0-terminated in the buffer. The length of the line is returned in Y.
|
; The line read will be 0-terminated in the buffer (and not contain the end of line character).
|
||||||
|
; The length of the line is returned in Y.
|
||||||
%asm {{
|
%asm {{
|
||||||
sta P8ZP_SCRATCH_W1
|
sta P8ZP_SCRATCH_W1
|
||||||
sty P8ZP_SCRATCH_W1+1
|
sty P8ZP_SCRATCH_W1+1
|
||||||
ldx #11
|
ldx #11
|
||||||
jsr c64.CHKIN ; use channel 11 again for input
|
jsr c64.CHKIN ; use channel 11 again for input
|
||||||
ldy #0
|
ldy #0
|
||||||
|
lda have_first_byte
|
||||||
|
beq _loop
|
||||||
|
lda #0
|
||||||
|
sta have_first_byte
|
||||||
|
lda first_byte
|
||||||
|
sta (P8ZP_SCRATCH_W1),y
|
||||||
|
iny
|
||||||
_loop jsr c64.CHRIN
|
_loop jsr c64.CHRIN
|
||||||
sta (P8ZP_SCRATCH_W1),y
|
sta (P8ZP_SCRATCH_W1),y
|
||||||
beq _end
|
beq _end
|
||||||
iny
|
iny
|
||||||
cmp #$0a
|
cmp #$0a
|
||||||
beq _zero_end
|
beq _line_end
|
||||||
cmp #$0d
|
cmp #$0d
|
||||||
bne _loop
|
bne _loop
|
||||||
_zero_end lda #0
|
_line_end dey ; get rid of the trailing end-of-line char
|
||||||
|
lda #0
|
||||||
sta (P8ZP_SCRATCH_W1),y
|
sta (P8ZP_SCRATCH_W1),y
|
||||||
_end rts
|
_end rts
|
||||||
}}
|
}}
|
||||||
|
@ -1,23 +1,62 @@
|
|||||||
%target cx16
|
%target cx16
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%import textio
|
%import textio
|
||||||
|
%import diskio
|
||||||
%import string
|
%import string
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
; TODO : NOTE: treat $0a (10 - line feed) and $0c (13 - normal petscii Return) both as line separators
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.lowercase()
|
txt.lowercase()
|
||||||
txt.print("\nAssembler.\nEmpty line to stop.\n")
|
txt.print("\nAssembler.\nEmpty line to stop.\n")
|
||||||
|
|
||||||
textparse.user_input()
|
; user_input()
|
||||||
|
file_input()
|
||||||
|
|
||||||
; test_stack.test()
|
; test_stack.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub user_input() {
|
||||||
|
repeat {
|
||||||
|
ubyte input_length = 0
|
||||||
|
txt.chrout('A')
|
||||||
|
txt.print_uwhex(textparse.program_counter, 1)
|
||||||
|
txt.print(": ")
|
||||||
|
; simulate user always having at least one space at the start
|
||||||
|
textparse.input_line[0] = ' '
|
||||||
|
input_length = txt.input_chars(&textparse.input_line+1)
|
||||||
|
txt.nl()
|
||||||
|
|
||||||
|
if not input_length {
|
||||||
|
txt.print("exit\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
textparse.process_line()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub file_input() {
|
||||||
|
if diskio.f_open(8, "romdis.asm") {
|
||||||
|
uword line=0
|
||||||
|
repeat 5 {
|
||||||
|
if diskio.f_readline(textparse.input_line) {
|
||||||
|
line++
|
||||||
|
txt.print_uw(line)
|
||||||
|
txt.chrout(':')
|
||||||
|
txt.print(textparse.input_line)
|
||||||
|
txt.nl()
|
||||||
|
textparse.process_line()
|
||||||
|
if c64.READST() ; TODO also check STOP key
|
||||||
|
break
|
||||||
|
} else
|
||||||
|
break
|
||||||
|
}
|
||||||
|
diskio.f_close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textparse {
|
textparse {
|
||||||
@ -28,31 +67,16 @@ textparse {
|
|||||||
uword[3] word_addrs
|
uword[3] word_addrs
|
||||||
uword program_counter = $4000
|
uword program_counter = $4000
|
||||||
|
|
||||||
sub user_input() {
|
sub process_line() {
|
||||||
repeat {
|
string.lower(input_line)
|
||||||
ubyte input_length = 0
|
|
||||||
txt.chrout('A')
|
|
||||||
txt.print_uwhex(program_counter, 1)
|
|
||||||
txt.print(": ")
|
|
||||||
; simulate user always having at least one space at the start
|
|
||||||
input_line[0] = ' '
|
|
||||||
input_length = txt.input_chars(&input_line+1)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
if not input_length {
|
|
||||||
txt.print("exit\n")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
preprocess_assignment_spacing()
|
preprocess_assignment_spacing()
|
||||||
split_input()
|
split_input()
|
||||||
; debug_print_words()
|
debug_print_words()
|
||||||
|
|
||||||
if word_addrs[1] and @(word_addrs[1])=='='
|
if word_addrs[1] and @(word_addrs[1])=='='
|
||||||
do_assign()
|
do_assign()
|
||||||
else
|
else
|
||||||
do_label_or_instr()
|
do_label_or_instr()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub do_assign() {
|
sub do_assign() {
|
||||||
@ -71,7 +95,12 @@ textparse {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txt.print("?invalid operand\n")
|
txt.print("?invalid operand (assign)\n")
|
||||||
|
txt.print(" nlen=")
|
||||||
|
txt.print_ub(nlen)
|
||||||
|
txt.print(" word=")
|
||||||
|
txt.print(word_addrs[2])
|
||||||
|
txt.nl()
|
||||||
}
|
}
|
||||||
|
|
||||||
sub do_label_or_instr() {
|
sub do_label_or_instr() {
|
||||||
@ -84,12 +113,10 @@ textparse {
|
|||||||
label_ptr = word_addrs[0]
|
label_ptr = word_addrs[0]
|
||||||
instr_ptr = word_addrs[1]
|
instr_ptr = word_addrs[1]
|
||||||
operand_ptr = word_addrs[2]
|
operand_ptr = word_addrs[2]
|
||||||
lowercase(operand_ptr)
|
|
||||||
} else if word_addrs[1] {
|
} else if word_addrs[1] {
|
||||||
if starts_with_whitespace {
|
if starts_with_whitespace {
|
||||||
instr_ptr = word_addrs[0]
|
instr_ptr = word_addrs[0]
|
||||||
operand_ptr = word_addrs[1]
|
operand_ptr = word_addrs[1]
|
||||||
lowercase(operand_ptr)
|
|
||||||
} else {
|
} else {
|
||||||
label_ptr = word_addrs[0]
|
label_ptr = word_addrs[0]
|
||||||
instr_ptr = word_addrs[1]
|
instr_ptr = word_addrs[1]
|
||||||
@ -154,7 +181,7 @@ textparse {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txt.print("?invalid operand\n")
|
txt.print("?invalid operand (instr)\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txt.print("?invalid instruction\n")
|
txt.print("?invalid instruction\n")
|
||||||
@ -216,9 +243,6 @@ textparse {
|
|||||||
parsed_len = conv.any2uword(operand_ptr)
|
parsed_len = conv.any2uword(operand_ptr)
|
||||||
if parsed_len {
|
if parsed_len {
|
||||||
operand_ptr += parsed_len
|
operand_ptr += parsed_len
|
||||||
txt.print("abs-restoperand=")
|
|
||||||
txt.print(operand_ptr)
|
|
||||||
txt.nl()
|
|
||||||
if msb(cx16.r15) {
|
if msb(cx16.r15) {
|
||||||
; absolute or abs indirects
|
; absolute or abs indirects
|
||||||
if @(operand_ptr)==0
|
if @(operand_ptr)==0
|
||||||
@ -307,16 +331,6 @@ _is_2_entry
|
|||||||
txt.nl()
|
txt.nl()
|
||||||
}
|
}
|
||||||
|
|
||||||
sub lowercase(uword st) {
|
|
||||||
; TODO optimize in asm
|
|
||||||
ubyte char = @(st)
|
|
||||||
while char {
|
|
||||||
@(st) = char & 127
|
|
||||||
st++
|
|
||||||
char = @(st)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub dummy(uword operand_ptr) -> uword {
|
sub dummy(uword operand_ptr) -> uword {
|
||||||
uword a1=rndw()
|
uword a1=rndw()
|
||||||
uword a6=a1+operand_ptr
|
uword a6=a1+operand_ptr
|
||||||
@ -396,7 +410,7 @@ _is_2_entry
|
|||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
@(dest)=0
|
@(dest)=0
|
||||||
string.copy(input_line2, src)
|
void string.copy(input_line2, src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,32 +8,33 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
str s1 = "12345 abcdef..uvwxyz ()!@#$%;:&*()-=[]<>\xff\xfa\xeb\xc0\n"
|
ubyte[40] input_line
|
||||||
str s2 = "12345 ABCDEF..UVWXYZ ()!@#$%;:&*()-=[]<>\xff\xfa\xeb\xc0\n"
|
|
||||||
str s3 = "12345 \x61\x62\x63\x64\x65\x66..\x75\x76\x77\x78\x79\x7a ()!@#$%;:&*()-=[]<>\xff\xfa\xeb\xc0\n"
|
|
||||||
|
|
||||||
txt.lowercase()
|
if diskio.f_open(8, "romdis.asm") {
|
||||||
|
uword line=0
|
||||||
txt.print(s1)
|
repeat 5 {
|
||||||
txt.print(s2)
|
ubyte length = diskio.f_readline(input_line)
|
||||||
txt.print(s3)
|
if length {
|
||||||
|
line++
|
||||||
string.lower(s1)
|
txt.print_uw(line)
|
||||||
string.lower(s2)
|
txt.chrout(':')
|
||||||
string.lower(s3)
|
txt.print_ub(length)
|
||||||
txt.print(s1)
|
txt.print(":[")
|
||||||
txt.print(s2)
|
ubyte xx
|
||||||
txt.print(s3)
|
for xx in 0 to length-1 {
|
||||||
|
txt.print_ubhex(input_line[xx], 1)
|
||||||
string.upper(s1)
|
txt.chrout(' ')
|
||||||
string.upper(s2)
|
}
|
||||||
string.upper(s3)
|
; txt.print(&input_line)
|
||||||
|
txt.print("]\n")
|
||||||
txt.print(s1)
|
; textparse.process_line()
|
||||||
txt.print(s2)
|
if c64.READST() ; TODO also check STOP key
|
||||||
txt.print(s3)
|
break
|
||||||
|
} else
|
||||||
txt.nl()
|
break
|
||||||
|
}
|
||||||
|
diskio.f_close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user