mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
added cx16diskio with load() and load_raw() that are HIMEM bank-aware
This commit is contained in:
parent
0018dc6ce7
commit
900cdd3fa1
38
compiler/res/prog8lib/cx16/cx16diskio.p8
Normal file
38
compiler/res/prog8lib/cx16/cx16diskio.p8
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
; Cx16 specific disk drive I/O routines.
|
||||||
|
;
|
||||||
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
||||||
|
|
||||||
|
%import diskio
|
||||||
|
|
||||||
|
cx16diskio {
|
||||||
|
|
||||||
|
; Use kernal LOAD routine to load the given program file in memory.
|
||||||
|
; This mimimics Basic's LOAD "filename",drive / LOAD "filename",drive,1
|
||||||
|
; If you don't give an address_override, the location in memory is taken from the 2-byte file header.
|
||||||
|
; If you specify a custom address_override, the first 2 bytes in the file are ignored
|
||||||
|
; and the rest is loaded at the given location in memory.
|
||||||
|
; Returns the number of bytes loaded (truncated to 16 bits, if the file is larger than 64 Kb,
|
||||||
|
; you'll have to compensate yourself by checking the ram banks).
|
||||||
|
sub load(ubyte drivenumber, uword filenameptr, ubyte bank, uword address_override) -> uword {
|
||||||
|
cx16.rambank(bank)
|
||||||
|
uword size = diskio.load(drivenumber, filenameptr, address_override)
|
||||||
|
if size
|
||||||
|
return size + $2000 * (cx16.getrambank() - bank)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
; Use kernal LOAD routine to load the given file in memory.
|
||||||
|
; INCLUDING the first 2 bytes in the file: no program header is assumed in the file.
|
||||||
|
; This is different from Basic's LOAD instruction which always skips the first two bytes.
|
||||||
|
; The load address is mandatory. Returns the number of bytes loaded.
|
||||||
|
; Returns the number of bytes loaded (truncated to 16 bits, if the file is larger than 64 Kb,
|
||||||
|
; you'll have to compensate yourself by checking the ram banks).
|
||||||
|
sub load_raw(ubyte drivenumber, uword filenameptr, ubyte bank, uword address) -> uword {
|
||||||
|
cx16.rambank(bank)
|
||||||
|
uword size = diskio.load_raw(drivenumber, filenameptr, address)
|
||||||
|
if size
|
||||||
|
return size + $2000 * (cx16.getrambank() - bank)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -440,7 +440,9 @@ io_error:
|
|||||||
; and the rest is loaded at the given location in memory.
|
; and the rest is loaded at the given location in memory.
|
||||||
; Returns the number of bytes loaded.
|
; Returns the number of bytes loaded.
|
||||||
; NOTE: when the load is larger than 64Kb and/or spans multiple RAM banks
|
; NOTE: when the load is larger than 64Kb and/or spans multiple RAM banks
|
||||||
; (which is possible on the Commander X16), the returned size is not correct.
|
; (which is possible on the Commander X16), the returned size is not correct,
|
||||||
|
; because it doesn't take the number of ram banks into account.
|
||||||
|
; Consider using cx16diskio.load() instead.
|
||||||
sub load(ubyte drivenumber, uword filenameptr, uword address_override) -> uword {
|
sub load(ubyte drivenumber, uword filenameptr, uword address_override) -> uword {
|
||||||
c64.SETNAM(string.length(filenameptr), filenameptr)
|
c64.SETNAM(string.length(filenameptr), filenameptr)
|
||||||
ubyte secondary = 1
|
ubyte secondary = 1
|
||||||
@ -474,16 +476,21 @@ io_error:
|
|||||||
; This is different from Basic's LOAD instruction which always skips the first two bytes.
|
; This is different from Basic's LOAD instruction which always skips the first two bytes.
|
||||||
; The load address is mandatory. Returns the number of bytes loaded.
|
; The load address is mandatory. Returns the number of bytes loaded.
|
||||||
; NOTE: when the load is larger than 64Kb and/or spans multiple RAM banks
|
; NOTE: when the load is larger than 64Kb and/or spans multiple RAM banks
|
||||||
; (which is possible on the Commander X16), the returned size is not correct.
|
; (which is possible on the Commander X16), the returned size is not correct,
|
||||||
|
; because it doesn't take the number of ram banks into account.
|
||||||
|
; Consider using cx16diskio.load_raw() instead.
|
||||||
sub load_raw(ubyte drivenumber, uword filenameptr, uword address) -> uword {
|
sub load_raw(ubyte drivenumber, uword filenameptr, uword address) -> uword {
|
||||||
if not f_open(drivenumber, filenameptr)
|
if not f_open(drivenumber, filenameptr)
|
||||||
return 0
|
return 0
|
||||||
uword read = f_read(address, 2)
|
uword size = f_read(address, 2)
|
||||||
f_close()
|
f_close()
|
||||||
if read!=2
|
if size!=2
|
||||||
return 0
|
return 0
|
||||||
address += 2
|
address += 2
|
||||||
return 2+load(drivenumber, filenameptr, address)
|
size = load(drivenumber, filenameptr, address)
|
||||||
|
if size
|
||||||
|
return size+2
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delete(ubyte drivenumber, uword filenameptr) {
|
sub delete(ubyte drivenumber, uword filenameptr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user