*********************************************************
* Loads a file into a given address.                    *
* IN:  a0 - Pointer to file name.                       *
*      a1 - Pointer to the memory location.             *
*                                                       *
* OUT: d0 - Result, anything above 0 = FAIL.            *
*                                                       *
* Does not destroy any register content.                *
*********************************************************
_LoadData:         Movem.l   d1-d7/a0-a6,-(a7)

                   Move.l    a1,lf_MemPointer
                   Move.l    a0,lf_FileName
                   Move.l    #1,lf_Result

                   Lea       Custom,a5
                   Move.w    dmaconr(a5),DemoDMA
                   Move.w    #DMAF_SETCLR!DMAF_BLITTER!DMAF_DISK,dmacon(a5)

                   ;Move.l    _VBR,a0
                   ;Move.l    $6c(a0),DemoLev3
                   ;Move.l    OldLev3,$6c(a0)

                   ;Move.w    intenar(a5),DemoInts
                   ;Move.w    OldInt,d7
                   ;Bset      #15,d7
                   ;Move.w    d7,intena(a5)

                   ;----------------------------

                   Move.l    _DosBase,a6
                   Move.l    lf_FileName,d1
                   Move.l    #SHARED_LOCK,d2
                   Jsr       _LVOLock(a6)
                   Move.l    d0,lf_FileLock
                   Beq       .lf_exit

                   ;-----------------------

                   Move.l    _ExecBase,a6
                   Move.l    #260,d0
                   Move.l    #MEMF_CLEAR,d1
                   Jsr       _LVOAllocMem(a6)
                   Move.l    d0,lf_InfoBlock
                   Beq       .lf_unlock

                   ;-----------------------

                   Move.l    _DosBase,a6
                   Move.l    lf_FileLock,d1
                   Move.l    lf_InfoBlock,d2
                   Jsr       _LVOExamine(a6)
                   Tst.l     d0
                   Beq       .lf_freemem

                   ;------------------------

                   Move.l    lf_InfoBlock,a1
                   Move.l    fib_DirEntryType(a1),d0
                   Tst.l     d0
                   bpl       .lf_freemem
                   Move.l    fib_Size(a1),lf_FileSize

                   ;---------------------------------

                   Move.l    lf_FileLock,d1
                   Jsr       _LVOOpenFromLock(a6)
                   Move.l    d0,lf_FileHandle
                   Beq       .lf_freemem

                   ;---------------------------------

                   Move.l    _DosBase,a6
                   Move.l    lf_FileHandle,d1
                   Move.l    lf_MemPointer,d2
                   Move.l    lf_FileSize,d3
                   Jsr       _LVORead(a6)
                   Cmp.l     #-1,d0
                   Beq       .lf_close

                   ;--------------------------------

                   Move.l    #0,lf_Result

                   ;--------------------------------

.lf_close          Move.l    _DosBase,a6
                   Move.l    lf_FileHandle,d1
                   Jsr       _LVOClose(a6)

.lf_freemem        Move.l    _ExecBase,a6
                   Move.l    lf_InfoBlock,a1
                   Move.l    #260,d0
                   Jsr       _LVOFreeMem(a6)

.lf_unlock         Move.l    _DosBase,a6
                   Move.l    lf_FileLock,d1
                   Jsr       _LVOUnLock(a6)

                   ;----------------------------

.lf_exit           Move.l    _GfxBase,a6
                   Jsr       _LVOWaitBlit(a6)

                   ;Lea       Custom,a5
                   ;Move.w    DemoInts,d7
                   ;Not.w     d7
                   ;Bclr      #15,d7
                   ;And.w     #%1111100001111111,d7
                   ;Move.w    d7,intena(a5)

                   ;Move.l    _VBR,a0
                   ;Move.l    DemoLev3,$6c(a0)

                   Move.w    DemoDMA,d7
                   Not.w     d7
                   Bclr      #15,d7
                   And.w     #%1111111111110000,d7
                   Move.w    d7,dmacon(a5)

                   Move.l    lf_Result,d0
                   Movem.l   (a7)+,d1-d7/a0-a6
                   Rts

lf_FileHandle:     Dc.l      0
lf_FileLock:       Dc.l      0
lf_FileSize:       Dc.l      0
lf_MemPointer:     Dc.l      0
lf_InfoBlock:      Dc.l      0
lf_FileName:       Dc.l      0
lf_Result:         Dc.l      0
DemoInts:          Dc.w      0
DemoDMA:           Dc.w      0
DemoLev3:          Dc.l      0
