mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +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
|
||||
|
||||
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
|
||||
while num_bytes!=0 {
|
||||
readsize = 255
|
||||
@ -357,12 +368,6 @@ byte_read_loop: ; fallback if MACPTR isn't supported on the device
|
||||
sta m_in_buffer+2
|
||||
}}
|
||||
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 {{
|
||||
jsr cbm.CHRIN
|
||||
m_in_buffer sta $ffff
|
||||
@ -371,6 +376,13 @@ m_in_buffer sta $ffff
|
||||
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++
|
||||
num_bytes--
|
||||
}
|
||||
|
@ -303,8 +303,19 @@ close_end:
|
||||
return 0
|
||||
|
||||
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 {{
|
||||
lda bufferpointer
|
||||
sta m_in_buffer+1
|
||||
@ -312,12 +323,6 @@ close_end:
|
||||
sta m_in_buffer+2
|
||||
}}
|
||||
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 {{
|
||||
jsr cbm.CHRIN
|
||||
m_in_buffer sta $ffff
|
||||
@ -326,6 +331,13 @@ m_in_buffer sta $ffff
|
||||
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++
|
||||
num_bytes--
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ TODO
|
||||
|
||||
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
|
||||
|
||||
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 diskio
|
||||
%option no_sysinit
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
ubyte @shared index
|
||||
bool @shared success = index==0 or index==255
|
||||
if success
|
||||
txt.print("yo")
|
||||
if index==0 or index==255
|
||||
txt.print("yo")
|
||||
txt.print("----with read 1:\n")
|
||||
testread1()
|
||||
txt.print("----with readline:\n")
|
||||
testreadline()
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user