mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
Optimize diskio.f_read for size=1, also improve ST check
This commit is contained in:
parent
55dbd095ed
commit
8fa14a10e2
@ -327,8 +327,19 @@ close_end:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
reset_read_channel()
|
reset_read_channel()
|
||||||
list_blocks = 0 ; we reuse this variable for the total number of bytes read
|
if num_bytes==1 {
|
||||||
|
; optimize for reading just a single byte
|
||||||
|
@(bufferpointer) = cbm.CHRIN()
|
||||||
|
cx16.r0L = cbm.READST()
|
||||||
|
if cx16.r0L!=0 {
|
||||||
|
f_close()
|
||||||
|
if cx16.r0L & $40 == 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
list_blocks = 0 ; we reuse this variable for the total number of bytes read
|
||||||
uword readsize
|
uword readsize
|
||||||
while num_bytes!=0 {
|
while num_bytes!=0 {
|
||||||
readsize = 255
|
readsize = 255
|
||||||
@ -357,12 +368,6 @@ byte_read_loop: ; fallback if MACPTR isn't supported on the device
|
|||||||
sta m_in_buffer+2
|
sta m_in_buffer+2
|
||||||
}}
|
}}
|
||||||
while num_bytes!=0 {
|
while num_bytes!=0 {
|
||||||
if cbm.READST()!=0 {
|
|
||||||
f_close()
|
|
||||||
if cbm.READST() & $40 !=0 ; eof?
|
|
||||||
return list_blocks ; number of bytes read
|
|
||||||
return 0 ; error.
|
|
||||||
}
|
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr cbm.CHRIN
|
jsr cbm.CHRIN
|
||||||
m_in_buffer sta $ffff
|
m_in_buffer sta $ffff
|
||||||
@ -371,6 +376,13 @@ m_in_buffer sta $ffff
|
|||||||
inc m_in_buffer+2
|
inc m_in_buffer+2
|
||||||
+
|
+
|
||||||
}}
|
}}
|
||||||
|
cx16.r0L = cbm.READST()
|
||||||
|
if cx16.r0L!=0 {
|
||||||
|
f_close()
|
||||||
|
if cx16.r0L & $40 !=0 ; eof?
|
||||||
|
return list_blocks ; number of bytes read
|
||||||
|
return 0 ; error.
|
||||||
|
}
|
||||||
list_blocks++
|
list_blocks++
|
||||||
num_bytes--
|
num_bytes--
|
||||||
}
|
}
|
||||||
|
@ -303,8 +303,19 @@ close_end:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
reset_read_channel()
|
reset_read_channel()
|
||||||
list_blocks = 0 ; we reuse this variable for the total number of bytes read
|
if num_bytes==1 {
|
||||||
|
; slightly optimized path for reading just a single byte
|
||||||
|
@(bufferpointer) = cbm.CHRIN()
|
||||||
|
cx16.r0L = cbm.READST()
|
||||||
|
if cx16.r0L!=0 {
|
||||||
|
f_close()
|
||||||
|
if cx16.r0L & $40 == 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
list_blocks = 0 ; we reuse this variable for the total number of bytes read
|
||||||
%asm {{
|
%asm {{
|
||||||
lda bufferpointer
|
lda bufferpointer
|
||||||
sta m_in_buffer+1
|
sta m_in_buffer+1
|
||||||
@ -312,12 +323,6 @@ close_end:
|
|||||||
sta m_in_buffer+2
|
sta m_in_buffer+2
|
||||||
}}
|
}}
|
||||||
while num_bytes!=0 {
|
while num_bytes!=0 {
|
||||||
if cbm.READST()!=0 {
|
|
||||||
f_close()
|
|
||||||
if cbm.READST() & $40 !=0 ; eof?
|
|
||||||
return list_blocks ; number of bytes read
|
|
||||||
return 0 ; error.
|
|
||||||
}
|
|
||||||
%asm {{
|
%asm {{
|
||||||
jsr cbm.CHRIN
|
jsr cbm.CHRIN
|
||||||
m_in_buffer sta $ffff
|
m_in_buffer sta $ffff
|
||||||
@ -326,6 +331,13 @@ m_in_buffer sta $ffff
|
|||||||
inc m_in_buffer+2
|
inc m_in_buffer+2
|
||||||
+
|
+
|
||||||
}}
|
}}
|
||||||
|
cx16.r0L = cbm.READST()
|
||||||
|
if cx16.r0L!=0 {
|
||||||
|
f_close()
|
||||||
|
if cx16.r0L & $40 !=0 ; eof?
|
||||||
|
return list_blocks ; number of bytes read
|
||||||
|
return 0 ; error.
|
||||||
|
}
|
||||||
list_blocks++
|
list_blocks++
|
||||||
num_bytes--
|
num_bytes--
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@ TODO
|
|||||||
|
|
||||||
Fix diskio (cx16, possibly other cbm targets too?) when opening write file , read file stops working
|
Fix diskio (cx16, possibly other cbm targets too?) when opening write file , read file stops working
|
||||||
|
|
||||||
|
add a -plain option to turn off text output coloring and unicode symbols in error messages (footguns)
|
||||||
make a compiler switch to disable footgun warnings -ignorefootguns
|
make a compiler switch to disable footgun warnings -ignorefootguns
|
||||||
|
|
||||||
update zsmkit to newest version that includes the on_deck routines
|
update zsmkit to newest version that includes the on_deck routines when stabilized
|
||||||
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -1,14 +1,40 @@
|
|||||||
%import textio
|
%import textio
|
||||||
|
%import diskio
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte @shared index
|
txt.print("----with read 1:\n")
|
||||||
bool @shared success = index==0 or index==255
|
testread1()
|
||||||
if success
|
txt.print("----with readline:\n")
|
||||||
txt.print("yo")
|
testreadline()
|
||||||
if index==0 or index==255
|
}
|
||||||
txt.print("yo")
|
|
||||||
|
sub testread1() {
|
||||||
|
if not diskio.f_open("lines.txt")
|
||||||
|
return
|
||||||
|
defer diskio.f_close()
|
||||||
|
|
||||||
|
str buffer = " "
|
||||||
|
while 1==diskio.f_read(&buffer, 1) {
|
||||||
|
txt.chrout(buffer[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testreadline() {
|
||||||
|
if not diskio.f_open("lines.txt")
|
||||||
|
return
|
||||||
|
defer diskio.f_close()
|
||||||
|
|
||||||
|
str buffer = " "*80
|
||||||
|
ubyte length, status
|
||||||
|
do {
|
||||||
|
length, status = diskio.f_readline(&buffer)
|
||||||
|
if length!=0 {
|
||||||
|
txt.print(buffer)
|
||||||
|
txt.nl()
|
||||||
|
}
|
||||||
|
} until status!=0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user