From 16932e90f7514a767098a8044e06536972cd447e Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sun, 4 Feb 2018 13:01:07 -0800 Subject: [PATCH] change opensys to allocate number of I/O buffers for open --- src/inc/fileio.plh | 2 +- src/libsrc/fileio.pla | 104 ++++++++++++++++++++++++++++------------ src/toolsrc/codegen.pla | 2 +- src/toolsrc/lex.pla | 4 +- src/toolsrc/plasm.pla | 2 +- 5 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/inc/fileio.plh b/src/inc/fileio.plh index d759ecc..699a514 100644 --- a/src/inc/fileio.plh +++ b/src/inc/fileio.plh @@ -38,7 +38,7 @@ import fileio word setpfx word getfileinfo word geteof - word openbuf + word iobufalloc word open word close word read diff --git a/src/libsrc/fileio.pla b/src/libsrc/fileio.pla index b96ee59..db299a2 100644 --- a/src/libsrc/fileio.pla +++ b/src/libsrc/fileio.pla @@ -27,7 +27,7 @@ struc t_fileio word setpfx word getfileinfo word geteof - word openbuf + word iobufalloc word open word close word read @@ -38,14 +38,14 @@ struc t_fileio word readblock word writeblock end -predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2openbuf(path, iobuf), a2open(path), a23close(refnum) +predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2iobufs(iobufs), a2open(path), a2close(refnum) predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path) predef a2newline(refnum, emask, nlchar), a2readblock(unit, buf, block), a2writeblock(unit, buf, block) // // Exported function table. // word fileio[] -word = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2openbuf, @a2open, @a23close +word = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2iobufs, @a2open, @a2close word = @a23read, @a2write, @a2create, @a23destroy word = @a2newline, @a2readblock, @a2writeblock // @@ -53,6 +53,12 @@ word = @a2newline, @a2readblock, @a2writeblock // export byte perr // +// I/O buffers +// +const MAX_IOBUFS = 4 +byte iobuf_ref[MAX_IOBUFS] +word iobuf_addr[MAX_IOBUFS] = sysbuf +// // ProDOS/SOS routines // def a1getpfx(path) @@ -128,34 +134,54 @@ def a1open(path) *CFFA1FileName = path return 0 end -def a2openbuf(path, iobuf) - byte params[6] - params.0 = 3 - params:1 = path - params:3 = iobuf - params.5 = 0 - perr = syscall($C8, @params) - return params.5 +def a2iobufs(iobufs) + byte i + word freebuf, bufaddr + + if iobufs > MAX_IOBUFS + iobufs = MAX_IOBUFS + fin + if iobufs + iobufs-- // Subtract off system I/O buffer + if iobufs + bufaddr = heapallocalign(1024 * iobufs, 8, @freebuf) + for i = 1 to MAX_IOBUFS-1 + if not iobuf_addr[i] + iobuf_addr[i] = bufaddr + bufaddr = bufaddr + 1024 + iobufs-- + if not iobufs + return freebuf + fin + fin + next + return freebuf + fin + else + for i = 1 to MAX_IOBUFS-1 + iobuf_addr[i] = 0 // Free I/O buffers if 0 passed in + next + fin + return 0 +end +def a13iobufs(iobufs) + return 0 end def a2open(path) - byte params[6] - params.0 = 3 - params:1 = path - params:3 = sysbuf - params.5 = 0 - perr = syscall($C8, @params) - return params.5 -end -def a3openbuf(path, iobuf) - byte params[7] - - params.0 = 4 - params:1 = path - params.3 = 0 - params:4 = iobuf - params.6 = 0 - perr = syscall($C8, @params) - return params.3 + byte i, params[6] + + for i = 0 to MAX_IOBUFS-1 + if iobuf_addr[i] and not iobuf_ref[i] + params.0 = 3 + params:1 = path + params:3 = iobuf_addr[i] + params.5 = 0 + perr = syscall($C8, @params) + iobuf_ref[i] = params.5 + return params.5 + fin + next + return 0 end def a3open(path) byte params[7] @@ -171,7 +197,22 @@ end def a1close(refnum) return perr end -def a23close(refnum) +def a2close(refnum) + byte i, params[2] + + for i = 0 to MAX_IOBUFS-1 + if refnum == iobuf_ref[i] + iobuf_ref[i] = 0 + params.0 = 1 + params.1 = refnum + perr = syscall($CC, @params) + return perr + fin + next + perr = $45 + return perr +end +def a3close(refnum) byte params[2] params.0 = 1 @@ -318,7 +359,9 @@ when MACHID & MACHID_MODEL is MACHID_III fileio:getpfx = @a3getpfx fileio:getfileinfo = @a3getfileinfo + fileio:iobufalloc = @a13iobufs fileio:open = @a3open + fileio:close = @a3close fileio:write = @a3write fileio:create = @a3create fileio:newline = @a3newline @@ -330,6 +373,7 @@ when MACHID & MACHID_MODEL fileio:setpfx = @a1setpfx fileio:getfileinfo = @a1getfileinfo fileio:geteof = @a1geteof + fileio:iobufalloc = @a13iobufs fileio:open = @a1open fileio:close = @a1close fileio:read = @a1read diff --git a/src/toolsrc/codegen.pla b/src/toolsrc/codegen.pla index ecda769..299fd2c 100644 --- a/src/toolsrc/codegen.pla +++ b/src/toolsrc/codegen.pla @@ -508,7 +508,7 @@ def init_idglobal#0 fixup_addr = heapalloc(fixup_num*2) idglobal_tbl = heapalloc(globalbufsz) idlocal_tbl = heapalloc(localbufsz) - codebufsz = heapavail - 4096 + codebufsz = heapavail - 2048 codebuff = heapalloc(codebufsz) codeptr = codebuff lastglobal = idglobal_tbl diff --git a/src/toolsrc/lex.pla b/src/toolsrc/lex.pla index 159d86a..2a6474c 100644 --- a/src/toolsrc/lex.pla +++ b/src/toolsrc/lex.pla @@ -343,8 +343,7 @@ def nextln if incref; puts("Nested INCLUDEs not allowed\n"); exit_err(0); fin if scan <> STR_TKN; puts("Missing INCLUDE file\n"); exit_err(0); fin strcpy(@incfile, constval) - sysincbuf = heapallocalign(1024, 8, @sysincfre) - incref = fileio:openbuf(@incfile, sysincbuf) + incref = fileio:open(@incfile) if not incref puts("Unable to open INCLUDE file: ") puts(@incfile) @@ -362,7 +361,6 @@ def nextln else if refnum == incref fileio:close(incref) - heaprelease(sysincfre) incref = 0 refnum = srcref parsefile = @srcfile diff --git a/src/toolsrc/plasm.pla b/src/toolsrc/plasm.pla index 17b2fe3..31572f4 100644 --- a/src/toolsrc/plasm.pla +++ b/src/toolsrc/plasm.pla @@ -278,7 +278,6 @@ byte outflags byte refnum, srcref, incref byte[32] srcfile, incfile, relfile word parsefile // Pointer to current file -word sysincbuf, sysincfre // System I/O buffer for include files word srcline // Saved source line number // // Scanner variables @@ -464,6 +463,7 @@ if ^arg fin fin if srcfile and relfile + fileio:iobufalloc(2) // Reserve two I/O buffers srcref = fileio:open(@srcfile) if srcref fileio:newline(srcref, $7F, $0D)