home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Computing 59
/
ac059.adf
/
SupportFiles
/
afiles.a
/
afiles.a
Wrap
Text File
|
1993-02-05
|
6KB
|
203 lines
;File commands
;assembly source code
INCLUDE "EXEC/TYPES.I"
INCLUDE "LIBRARIES/DOS.I"
INCLUDE "EXEC/MEMORY.I"
;External references
;the amiga linker will link these to the program
XREF _AbsExecBase ;exec library address
;always stored in the same location
XREF _LVOOpenLibrary ;exec library routines
XREF _LVOCloseLibrary
XREF _LVOAllocMem
XREF _LVOFreeMem
XREF _LVODelay ;dos library routines
XREF _LVOOutput
XREF _LVOWrite
XREF _LVORead
XREF _LVOOpen
XREF _LVOClose
CSECT text,code ;this directive is used by the Lattice Assembler
main:
jsr openlibraries ;open the libraries,if possible
tst.l d0
beq exit2 ;exit if there is an error
jsr memorybuffer ;allocate memory
tst.l d0 ;exit if there is an error
beq exit
move.l dosbase,a6
jsr readfile ;read the file,if possible
tst.l d0
beq exit
jsr writefile ;write the file
move.l buffer,d2 ;display the memory buffer contents
move.l #152,d3
jsr message
move.l #100,d1
jsr _LVODelay(a6) ;delay for a few seconds
move.l #filesok,d2 ;success message
move.l #15,d3
exit:
jsr cleanup ;tidy up loose ends
exit2:
rts
openlibraries:
move.l _AbsExecBase,a6 ;exec library address
lea dosname,a1 ;pointer to string containing dos library name
clr.l d0 ;any version
jsr _LVOOpenLibrary(a6) ;open the dos library
movem.l d0,dosbase ;and store the returned pointer
tst.l d0 ;check for success
bne ok1 ;branch if successful
move.l #nolib,d2
move.l #17,d3
rts
ok1:
move.l dosbase,a6 ;dos library address
jsr _LVOOutput(a6) ;obtain a filehandle for output to the console
movem.l d0,consolefilehandle ;output file handle
rts
memorybuffer: ;allocate a block of memory
move.l _AbsExecBase,a6
move.l #152,d0 ;152 bytes
clr.l d1
bset #MEMF_PUBLIC,d1 ;memory requirements
bset #MEMF_CLEAR,d1
jsr _LVOAllocMem(a6)
movem.l d0,buffer ;store the pointer to the memory block
bne ok2
move.l #nomem,d2 ;failure message
move.l #17,d3
ok2:
rts
cleanup: ;tidy up
jsr message ;display message on screen
move.l inputfilehandle,d1 ;close files, if open
beq noinfile
jsr _LVOClose(a6)
noinfile:
move.l outputfilehandle,d1
beq nooutfile
jsr _LVOClose(a6)
nooutfile:
move.l _AbsExecBase,a6 ;free memory, if allocated
move.l buffer,a1
beq nomem2
move.l #152,d0
jsr _LVOFreeMem(a6)
nomem2:
move.l dosbase,a1 ;dos library pointer
jsr _LVOCloseLibrary(a6) ;close the library
nodoslib:
rts
message:
move.l dosbase,a6 ;dos library address
move.l consolefilehandle,d1 ;output file handle
jsr _LVOWrite(a6) ;write to the console
rts
readfile: ;read a file
move.l dosbase,a6
move.l #filename,d1 ;open the file if possible
move.l #MODE_OLDFILE,d2 ;must be an existing file
jsr _LVOOpen(a6)
movem.l d0,inputfilehandle ;store a pointer to the filehandle
move.l d0,d1
bne handleok
clr.l d0
move.l #nofile,d2 ;failure message
move.l #28,d3
rts
handleok: ;read file, if file is open
move.l buffer,d2 ;memory buffer for file contents
move.l #152,d3 ;number of bytes
jsr _LVORead(a6)
tst.l d0
bne bytesok
move.l #nobytes,d2 ;failure message
move.l #28,d3
bytesok:
rts
writefile: ;write a file
move.l #filename2,d1 ;name of the file
move.l #MODE_NEWFILE,d2 ;overwrite any existing file of that name
jsr _LVOOpen(a6) ;open the file
movem.l d0,outputfilehandle ;store pointer to the file handle
move.l d0,d1
bne handleok2 ;failure message
move.l #nofile2,d2
move.l #29,d3
rts
handleok2:
move.l #newcontents,d2 ;pointer to data to be written
move.l #20,d3 ;20 bytes
jsr _LVOWrite(a6) ;write to the file
move.l outputfilehandle,d1
move.l buffer,d2 ;pointer to data to be written
move.l #152,d3 ;152 bytes
jsr _LVOWrite(a6) ;write to the file
rts
CSECT data ;directive 'SECTION DATA,data' is used by
;Metacomco Assembler
dosname:
dc.b 'dos.library',0 ;name of dos library
ds.w 0 ;word alignment
dosbase: ;pointer to Dos Library base
dc.l 0
consolefilehandle: ;file handle for console output
dc.l 0
buffer: ;memory buffer
dc.l 0
inputfilehandle: ;file handle for input file
dc.l 0
outputfilehandle: ;file handle for output file
dc.l 0
bytes: ;number of bytes read
dc.l 0
filename: ;file names of text files
dc.b 'limerick',0
ds.w 0
filename2:
dc.b 'limerick2',0
ds.w 0
newcontents: ;messages
dc.b 'This is a new file',13,0
ds.w 0
nolib:
dc.b 'No dos library',10,13,0
ds.w 0
nomem:
dc.b 'No free memory',10,13,0
ds.w 0
filesok:
dc.b 'Files are ok ',10,13,0
ds.w 0
nofile:
dc.b 'Unable to open input file',10,13,0
ds.w 0
nobytes:
dc.b 'Unable to read input file',10,13,0
ds.w 0
nofile2:
dc.b 'Unable to open output file',10,13,0
ds.w 0
END