home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / hwloader.lha / .source / hwloader.asm
Encoding:
Assembly Source File  |  1980-02-07  |  6.7 KB  |  300 lines

  1.  
  2.         include    'includes:misc/_hardware.i'
  3.         
  4. ;-------------- AmigaDOS FileLoader v5.00
  5.  
  6.         lea    MFMBuffer,a2
  7.         bsr.b    InitDrives
  8.  
  9.         lea    Filename(pc),a0
  10.         lea    Buffer,a1
  11.         bsr.b    LoadDOSFile
  12.         rts
  13.  
  14. ;-------------- AmigaDOS-FileLoader (OFS) Definitions -------------------------
  15. ;
  16. ;        Version 5.00 - (CIAA TIMING VERSION)
  17. ;        Written & Developed by 2-Cool of LSD!
  18. ;        Copyright © 1992-1993. All Rights Are Reserved.
  19. ;
  20. ; _LVOInitDrives
  21. ; ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  22. ; Save MFM Bufferptr for loader usage & steps drives to track zero.
  23. ;
  24. ; INPUTS:    a0=MFMBuffer (Ptr)
  25. ;
  26. ; OUTPUTS:    None.
  27. ;
  28. ; _LVOLoadDOSFile
  29. ; ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  30. ; Load an AmigaDOS (OFS) File into your buffer (without stepping to track 0)
  31. ; You *MUST* call '_LVOInitDrives' BEFORE you access this routine!
  32. ;
  33. ; INPUTS:    a0=Filename (Ptr)
  34. ;        a1=Load Buffer (Ptr)
  35. ;
  36. ; OUTPUTS:    a0=Load Buffer (Ptr)
  37. ;        d0=Result Code (-1=LoadError, 0=LoadedOk)
  38. ;        d1=Filelength
  39. ;------------------------------------------------------------------------------
  40.  
  41. InitDrives:    lea    MFMPtr(pc),a1        ;mfm buffer ptr
  42.         move.l    a2,(a1)            ;save MFM Ptr
  43.         move.w    #$7fff,intena+_custom
  44.         rts
  45.  
  46. LoadDOSFile:    push    d2-d7/a0-a6        ;preserve registers
  47.         lea    (ciabprb).l,a5        ;ciab ptr
  48.         bclr    #7,(a5)
  49.         lea    VarBase(pc),a6        ;varbase ptr
  50.         bset    #3,(a5)
  51.         exg    a1,a0
  52.  
  53.         move.l    a0,-(sp)        ;save loadptr
  54.         st    (a6)
  55.         move.l    a0,LoadAdr-VarBase(a6)
  56.         st    FileSize-VarBase(a6)
  57.         bclr    #3,(a5)
  58.         move.l    #880,d0            ;load rootblock
  59.         bsr.w    LoadSect
  60.  
  61.         movea.l    a1,a2
  62.         moveq    #-1,d3
  63. GetNameLen:    addq.l    #1,d3
  64.         tst.b    (a2)+            ;get filename length (bytes)
  65.         bne.s    GetNameLen
  66.  
  67.         moveq    #0,d2
  68.         move.l    d3,d4            ;make copy of namelen
  69.         move.l    d3,d6
  70.         movea.l    a1,a3
  71.  
  72. CalcHash:    mulu.w    #13,d3
  73.         move.b    (a1)+,d2        ;get char from filename
  74.         add.w    d2,d3
  75.         andi.w    #$7FF,d3
  76.         subq.w    #1,d4
  77.         bne.s    CalcHash
  78.  
  79.         divu.w    #72,d3
  80.         swap    d3
  81.         lsl.w    #2,d3
  82.         moveq    #0,d5
  83.         move.l    6*4(a0,d3.w),d0
  84.         beq.w    DriveOFF
  85.         
  86. File_Loop:    bsr.w    LoadSect
  87.  
  88.         moveq    #0,d5
  89.         lea    432(a0),a1        ;ptr to filename in block
  90.         cmp.b    (a1)+,d6
  91.         bne.s    NextSect
  92.  
  93.         movea.l    a3,a2
  94.         move.w    d6,d3
  95.         subq.w    #1,d3            ;a2=filename ptr
  96. check_name:    cmpm.b    (a1)+,(a2)+        ; are they equal?
  97.         dbne    d3,check_name        ; check whole filename
  98.         bne.s    NextSect
  99.         
  100.         move.l    324(a0),d0        ;get blocklength (bytes)
  101.         add.l    LoadAdr(pc),d0        ;add destadr ptr
  102.         move.l    d0,FileSize-VarBase(a6)    ;save filesize
  103. ReadLoop:    move.l    16(a0),d0
  104.         beq.s    DriveOFF
  105.         bsr.w    LoadSect
  106.  
  107.         lea    24(a0),a1        ;a1=ptr to blockdata
  108.         movea.l    LoadAdr(pc),a2        ;get current pos
  109.         move.l    FileSize(pc),d0
  110.         move.l    #488-1,d7        ;488 bytes per block
  111. copyloop:    move.b    (a1)+,(a2)+        ;copy block into buffer
  112.         cmpa.l    d0,a2            ;copy done?
  113.         dbeq    d7,copyloop
  114.         move.l    a2,LoadAdr-VarBase(a6)    ;save current pos
  115.         bra.s    ReadLoop
  116.  
  117. NextSect:    move.l    496(a0),d0        ;is there another sector?
  118.         bne.b    File_Loop
  119.  
  120. DriveOFF:    bset    #7,(a5)
  121.         moveq    #0,d0            ;clear errorcode
  122.         bset    #3,(a5)
  123.         tst.l    d5
  124.         bne.s    LoadOk
  125.         moveq    #-1,d0            ;set errorcode
  126. LoadOk:        bclr    #3,(a5)
  127.         movea.l    (sp)+,a0        ;restore loadptr
  128.  
  129.         move.l    FileSize-VarBase(a6),d1    ;save filesize
  130.         suba.l    a0,d1
  131.         pull    d2-d7/a0-a6        ;restore registers
  132.         rts
  133.  
  134. ;-------------- Wait 3ms
  135.  
  136. Wait3ms:    bclr    #0,(a5)
  137.         bset    #0,(a5)
  138.  
  139. wait_3m:    move.b    #0,$500(a5)
  140.         move.b    #$12,$600(a5)
  141.         move.b    #$19,$E00(a5)
  142. time_out:    btst    #0,$E00(a5)
  143.         bne.s    time_out
  144. wait_diskready:    btst    #5,$F01(a5)        ;disk ready
  145.         bne.s    wait_diskready
  146.         rts
  147.  
  148. MoveIn:        bset    #1,(a5)
  149.         bsr.s    Wait3ms
  150. FindZero:    btst    #4,$F01(a5)        ;found track 0?
  151.         bne.s    MoveIn
  152.         sf    (a6)
  153. CheckTrk0:    tst.b    (a6)
  154.         bmi.s    FindZero
  155.  
  156. FindTrack:    cmp.b    (a6),d2
  157.         beq.s    wait_diskready
  158.         bcc.s    MoveOut
  159.         bset    #1,(a5)
  160.         subq.b    #1,(a6)
  161.         bra.s    FindLoop
  162.  
  163. MoveOut:    bclr    #1,(a5)
  164.         addq.b    #1,(a6)
  165. FindLoop:    bsr.s    Wait3ms
  166.         bra.s    FindTrack
  167.  
  168. SectorError:    moveq    #0,d5            ;d5=0 (an error occured)
  169.         addq.l    #4,sp            ;fix stack
  170.         bra.b    DriveOFF
  171.  
  172. ;-------------- Load any sector 0-1760
  173.  
  174. LoadSect:    cmp.w    #1760-1,d0        ;maximum block
  175.         bgt.s    SectorError
  176.  
  177.         move.l    MFMPtr(pc),a4        ;mfm trackbuffer ptr
  178.         move.l    d0,d2
  179.         ext.l    d2
  180.         divu.w    #11,d2            ;11 sectors per track
  181.         move.l    d2,d4
  182.         swap    d4
  183.         cmp.w    TrackNum-VarBase(a6),d2    ;got right track?
  184.         beq.s    DecodeMFM
  185.  
  186.         move.w    d2,TrackNum-VarBase(a6)
  187.         bset    #2,(a5)            ;set hi
  188.         btst    #0,d2            ;high or low side?
  189.         beq.s    TrackLow
  190.         bclr    #2,(a5)            ;set low
  191. TrackLow:    lsr.w    #1,d2
  192.         bsr.b    CheckTrk0
  193.         move.w    #5,RetryCount-VarBase(a6) ;retry load 5 times
  194.         bra.s    ReadTrack
  195.  
  196. LoadError:    subq.w    #1,RetryCount-VarBase(a6) ;decrease load count
  197.         bne.s    ReadTrack
  198.         moveq    #-1,d2
  199.         move.l    d2,(a6)
  200.         bra.s    LoadSect
  201.  
  202. ;-------------- Read tracks
  203.  
  204. ReadTrack:    btst    #2,$bfe001        ; disk in drive?
  205.         beq.s    LoadError
  206.  
  207.         move.l    MFMPtr(pc),a4        ;track buffer ptr
  208.         lea    _custom+dskpth,a0    ;custom+dskpth
  209.         move.l    a4,(a0)+        ;dskpth
  210.         move.w    #$8210,dmacon-$24(a0)    ;    ;dmacon
  211.         move.l    #$00027F00,intreq-$24(a0)    ;intreq,
  212.         move.w    #$9500,adkcon-$24(a0)    ;    ;adkcon
  213.         move.w    #$4489,dsksync-$24(a0)    ;    ;dsksync
  214.         move.w    #$9A00,(a0)        ;dsklen    ;tracklength
  215.         move.w    #$9A00,(a0)        ;dsklen    ;must do *TWICE* to trigger
  216.  
  217.         move.l    #$A0000,d7        ;countdown timer
  218. wait_dma:    subq.l    #1,d7            ;decrease dmawait counter
  219.         beq.s    LoadError
  220.         btst    #1,$1f-$24(a0)        ;diskblock done (intreq)
  221.         beq.s    wait_dma
  222.         
  223. ;-------------- Decode MFM
  224.  
  225. DecodeMFM:    lea    12800(a4),a2        ;a2=decode buffer
  226.         movea.l    a2,a0            ;make copy of ptr
  227.         move.l    #$55555555,d5
  228.         moveq    #11-1,d1        ;decode 11 blocks
  229. NoGapFound:    cmpi.w    #$4489,(a4)+        ;search for next sync
  230.         bne.s    NoGapFound
  231.         cmpi.w    #$4489,(a4)
  232.         beq.s    NoGapFound
  233.         movem.l    (a4),d2/d3
  234.         bsr.s    DecodeLong
  235.         lsr.w    #8,d2
  236.         cmp.w    d4,d2            ;compare checksums
  237.         beq.s    Dloop1
  238.         lea    1080(a4),a4        ;ptr to next sync
  239.         dbra    d1,NoGapFound        ;do all 11 sectors in track
  240.         bra.w    LoadError
  241.  
  242. Dloop1:        swap    d2
  243.         cmp.b    TrackCMP-VarBase(a6),d2    ;is it the right track?
  244.         bne.w    LoadError
  245.         lea    48(a4),a4        ;skip the rest
  246.         movem.l    (a4)+,d2-d3
  247.         bsr.s    DecodeLong
  248.         moveq    #0,d3
  249.         move.w    #256-1,d7
  250. dloop:        move.l    (a4)+,d4
  251.         eor.l    d4,d3            ;calculate checksum
  252.         dbra    d7,dloop
  253.         and.l    d5,d3
  254.         cmp.l    d3,d2            ;is checksum vaild?
  255.         bne.w    LoadError
  256.  
  257.         lea    -1024(a4),a4
  258.         moveq    #128-1,d7        ;decode 2*128 longwords
  259. decodenext:    move.l    512(a4),d3        ;decode datablock
  260.         move.l    (a4)+,d2
  261.         and.l    d5,d2
  262.         add.l    d2,d2
  263.         and.l    d5,d3
  264.         or.l    d3,d2
  265.         move.l    d2,(a2)+        ;store longword in buffer
  266.         dbra    d7,decodenext
  267.         rts
  268.  
  269. DecodeLong:    and.l    d5,d2
  270.         add.l    d2,d2
  271.         and.l    d5,d3
  272.         or.l    d3,d2
  273.         rts
  274. EndLoad
  275.  
  276. LoadSize    =    EndLoad-LoadDOSFile
  277.  
  278. VarBase:    dc.w    0
  279. TrackNum:    dc.b    0
  280. TrackCMP:    dc.b    0
  281. LoadAdr:    dc.l    0
  282. FileSize:    dc.l    0
  283. RetryCount:    dc.l    0
  284. MFMPtr:        dc.l    0            ;ptr to MFM Track Buffer
  285.  
  286. Filename:    dc.b    '1',0
  287. MFMBuffer    ds.b    126*512            ;26 sectors buffer (13k approx)
  288. Buffer        ds.b    200*1024
  289.  
  290.         printt    'AmigaDOS-File Loader v5.00 (Hardware version)    - Written By 2-Cool of LSD!'
  291.         printt    '¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯'
  292.         printt    'Copyright © 1992-1993 IDS - InterSect Development Software.'
  293.         printt    'All Rights are Reserved.'
  294.         printt    ''
  295.         printt    'DOSLoader size (in bytes) : '
  296.         printv    LoadSize
  297.         printt    ''
  298.  
  299.         end
  300.