[Coco] ML Disk I/O examples?
devries.bob at gmail.com
Mon Apr 16 18:25:33 EDT 2007
In my opinion, be it humble or not, the question about reading and writing
files in disk Basic using assembler was not addressed very well. Here's my 2
cents for what it's worth:
The ROM routine to open a file for input is $CA07 (DECB 1.0 = $C959)
The ROM routine to open a file for output is $CA04 (DECB 1.0 = $C956)
To use these routines, the following memory locations must have their
DNAMBF $094C is an 8 char buffer for the filename. Remember to pad with
spaces to 8 characters.
DEXTBF $0954 is a 3 char buffer for the extension, padded as above.
For output files, these must also be set:
DFLTYP $0957 File type flag (0 = BASIC, 1 = DATA, 2 = BINARY, 3 = TEXT
DASCFL $0958 Ascii flag (0 for binary data, $FF for text)
The two preceding locations will be filled automatically by the open routine
if opened for input.
To write to the file, put the character in the A accumulator and jump to
subroutine $CC24 (DECB 1.0 = $CB52)
To read from the file, jump to subroutine $C5C4 (DECB 1.0 = $C957) and
expect the char in A.
To close the file, jump to subroutine $CAF9 (DECB 1.0 = $CA4B)
It is good to put your own error vector in place at $018E. Currently, that
has a jump to $C6E4 (DECB = $C6B7).
So, as an example, say you want to write the data (only) of the first 4
PMODE graphics screens to a disk file called PGRAPHICS.DAT. The data is
$1800 bytes long, and it resides in memory starting at $0E00.
Please excuse the hard coding, it *is* an example only.
If there are any mistakes, please point them out. My assembler is a mite
;routine to write $1800 bytes to a disk file "GRAPHICS.DAT"
DNAMBF equ $094C
DEXTBF equ $0954
DFLTYP equ $0957
DASCFL equ $0958
OPENO equ $CA04
CONSOUT equ $CC24
FCLOSE equ $CAF9
ERRVEC equ $018E
;end of equates
vector lda [ERRVEC]
lda #$7E ;jump instruction
picfil leax filename,pcr ;point to filename
ldb #8 ;8 characters
namlop lda ,x+
leax exten,pcr ;point to extension
ldb #3 ;3 characters
extlop lda ,x+
;name is now stored
;file type and ascii flag stored
;the file number will be stored in DEVNUM ($006E)
wrtlop lda ,x+
;file data has been written
error jsr FCLOSE
;and file is closed
;restored error vector
;return to BASIC
filename fcc /GRAPHICS/
exten fcc /DAT/
errvec1 rmb 1
errvec2 rmb 2
Regards, Bob Devries, Dalby, Queensland, Australia
Isaiah 50:4 The sovereign Lord has given me
the capacity to be his spokesman,
so that I know how to help the weary.
my blog: http://bdevries.invigorated.org/
More information about the Coco