ForumsCodeASMdoslibrary load save RSS



Anyone have any examples of asm for DOSLIBRARY loading files and saving files


aLpHa oNe

Simply use the functions OPEN, CLOSE, READ, WRITE. :-)

Added 16 minutes later:

Typed in some lines, not tested...

move.l 4.w,a6
lea doslib(pc),a1
jsr -408(a6)
move.l d0,a6

move.l #file,d1
move.l #1006,d2; Mode NEWFILE
jsr -30(a6); Open()
beq.b endit

move.l d0,handle
move.l d0,d1; Filehandle
move.l #buffer,d2; Buffer to write
move.l #17,d3; Size
jsr -48(a6); Write()

move.l handle(pc),d1
jsr -36(a6) ; Close
endit: rts

file: dc.b"dh1:myfile",0
handle: dc.l0
buffer: dc.b"flashtro rules!!!",0
doslib: dc.b"dos.library",0

This post was edited by aLpHa oNe (2015-07-19 15:11, 1 year ago)


Here are the dos load/save routines I coded years ago for a Lightwave converter. You need to provide the ptr to your variables in register a5 and DOSbase must already be opened before calling any of these routines. The file loader will also auto-allocate the needed space if a1 = 0. Since I used AllocVec for this it will require OS 2.0+ in that case.

*** LOAD FILE                ***

; IN:    a0: File Name
;    a1: File Buffer or 0 for Auto Buffer Allocation
;    d0: Access Mode
;    d1: File Length or 0 for AutoLength

; OUT:    d0: Error Flag (0=Error, 1=OK)
;    d1: Ptr to allocated Memory (Auto Allocation only)
;    d2: File Length (Auto Length only)

    move.l    DOSbase(a5),a6
    moveq    #0,d6
    move.l    d1,d5            ; save FileLength
    move.l    a1,a4            ; save FileBuffer
    move.l    a0,d1            ; get FileName
    move.l    d0,d2            ; get Access Mode
    jsr    _LVOOpen(a6)
    move.l    d0,d7            ; save FileHandle
    beq.b    .error
    move.l    d0,d1
    move.l    d5,d3            ; get FileLength
    bne.b    .noLen
    bsr.b    .GetLen            ; calculate FileLength
    move.l    d7,d1            ; restore FileHandle
    move.l    d0,d3            ; get calculated FileLength
    move.l    d0,d5            ; save FileLength
.noLen    move.l    a4,d2            ; get FileBuffer
    bne.b    .noBuf
    bsr.b    .Alloc
    move.l    d0,d6            ; save MemPtr
    bne.b    .memok
    move.l    d7,d1
    jsr    _LVOClose(a6)
    bra.b    .error
.memok    move.l    d0,d2            ; get FileBuffer
.noBuf    jsr    _LVORead(a6)
    move.l    d7,d1            ; get FilePtr
    jsr    _LVOClose(a6)
    moveq    #1,d0            ; no Errors
    move.l    d6,d1            ; return MemPtr
    move.l    d5,d2            ; return FileLength

.error    move.l    d0,d1            ; clear Memory ptr
    move.l    d0,d2            ; clear File length
; returns Length of File in d0
.GetLen    moveq    #1,d3            ; OFFSET_END
    bsr.b    .seek
    moveq    #-1,d3            ; OFFSET_BEGINNING
.seek    move.l    d7,d1            ; FileHandle
    moveq    #0,d2            ; Seek Offset
    jmp    -66(a6)            ; Seek()

; returns allocated Memory in d0
.Alloc    movem.l    d1/a6,-(a7)        ; save DOSbase
    move.l    $4.w,a6
    move.l    d5,d0            ; get Alloc size
    addq.l    #1,d0            ; +1 for the Null Byte
    move.l    #$10000,d1        ; MEMF_CLEAR
    jsr    _LVOAllocVec(a6)
    movem.l    (a7)+,d1/a6        ; restore DOSbase

*** SAVE FILE                ***

; IN:    a0: File Name
;    a1: File Buffer
;    d0: File Length

; OUT:    d0: Error Flag (0=Error, 1=OK)

    move.l    a0,a4            ; save filename
    move.l    DOSbase(a5),a6
    move.l    a1,d5            ; save FileBuffer
    move.l    d0,d6            ; save FileLength
    move.l    a0,d1            ; get FileName
    move.l    #1006,d2        ; MODE_NEWFILE
    jsr    _LVOOpen(a6)
    move.l    d0,d7            ; save FileHandle
    beq.b    .error
    move.l    d0,d1            ; FileHandle
    move.l    d5,d2            ; FileBuffer
    move.l    d6,d3            ; FileLength
    jsr    _LVOWrite(a6)
    move.l    d7,d1            ; get FileHandle
    jsr    _LVOClose(a6)

    moveq    #1,d0            ; no Errors
.error    rts

DOSname        dc.b    "dos.library",0



Putting the FileHandle and the FileBuffer in the data registers seemed wrong. AmigaDos 1.x was a mess


Great stuff. It has made my job of ripping over 100 files from a disk and saving them to hdd sooo much easier. Thanks


In that case I could've given you my file ripper code where I use these routines too. :P Anyway, glad you could make use of these routines!