home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / diskutil / acache / acache.s < prev   
Encoding:
Text File  |  1988-02-09  |  4.6 KB  |  202 lines

  1. * acache v 1.1
  2. * by Harm Jetten, 870412
  3. * caches disk sectors for drive A:
  4. * assemble with HiSoft DevpacST
  5. * put acache.prg in your AUTO folder
  6.  
  7. nsects    equ    16        number of disk sectors cached
  8. ageing    equ    2*nsects    offset from sector number in map
  9. magic    equ    'CACH'        identification of this program
  10.  
  11.     include gemdos.s
  12.  
  13. start:    pea    rpvec(pc)    go replace r/w vector
  14.     call_ebios supexec
  15.     addq.l    #6,sp
  16.  
  17.     tst.b    d2        this was first time cache is called ?
  18.     bne.s    putmsg
  19.     call_bdos p_term_old    if not, return, exit code is 0
  20.  
  21. putmsg:    pea    strins(pc)    announce disk cache installed
  22.     call_bdos c_conws
  23.     addq.l    #6,sp
  24.  
  25.     bsr    clrmap        clear cache map
  26.     lea    end(pc),a0    calculate amount of
  27.     sub.l    4(sp),a0    memory to keep resident
  28.     clr    -(sp)        exit code is 0
  29.     move.l    a0,-(sp)
  30.     call_bdos p_termres
  31.  
  32.  
  33. * replace old r/w vector with cache vector
  34.  
  35. rpvec:    lea    hdv_rw,a1    get vector
  36.     move.l    (a1),a0
  37.     cmp.l    #magic,-8(a0)    are we installed already ?
  38.     sne.b    d2        set if not installed yet
  39.     beq.s    rpret
  40.     lea    acache(pc),a0
  41.     move.l    (a1),-4(a0)    save old r/w vector
  42.     move.l    a0,(a1)        install acache in vector
  43. rpret:    rts
  44.  
  45.  
  46. * copy a sector from a0 to a1
  47.  
  48. cpysec:    move.l    a0,d0        see if a0 or a1 are odd
  49.     btst.l    #0,d0
  50.     bne.s    cpyslo
  51.     move.l    a1,d0
  52.     btst.l    #0,d0
  53.     bne.s    cpyslo
  54.  
  55.     moveq    #31,d0        fast copy, 32 * 16 bytes
  56. cpyflp:    move.l    (a0)+,(a1)+
  57.     move.l    (a0)+,(a1)+
  58.     move.l    (a0)+,(a1)+
  59.     move.l    (a0)+,(a1)+
  60.     dbra    d0,cpyflp
  61.     rts
  62.  
  63. cpyslo:    moveq    #127,d0        slow copy, 128 * 4 bytes
  64. cpyslp:    move.b    (a0)+,(a1)+
  65.     move.b    (a0)+,(a1)+
  66.     move.b    (a0)+,(a1)+
  67.     move.b    (a0)+,(a1)+
  68.     dbra    d0,cpyslp
  69.     rts
  70.  
  71.  
  72. * clear all entries in cache map
  73.  
  74. clrmap:    lea    map(pc),a0
  75.     moveq    #nsects-1,d2
  76. clrmab:    clr.l    (a0)+
  77.     dbra    d2,clrmab
  78.     rts
  79.  
  80.  
  81. * cache r/w handler 
  82.  
  83. id:    dc.l    magic        our identification
  84. oldvec:    dc.l    0        save old r/w vector here
  85.  
  86. acache:    tst    14(sp)        drive must be A:
  87.     beq.s    drva
  88. toold:    move.l    oldvec(pc),a0    jump to old r/w driver
  89.     jmp    (a0)
  90.  
  91. drva:    tst    12(sp)        check if accessing boot sector
  92.     bne.s    noboot
  93.     bsr    clrmap        wipe out map
  94.     bra.s    toold
  95.  
  96. noboot:    move.l    hdv_mediach,a3    check if media changed
  97.     clr    -(sp)        on drive A:
  98.     jsr    (a3)
  99.     addq.l    #2,sp
  100.     tst.l    d0
  101.     beq.s    nochg
  102.     bsr    clrmap        wipe out map, continue
  103.  
  104. nochg:    tst    4(sp)        check request type (rd/wr)
  105.     bne.s    nocach
  106.  
  107.     cmp    #1,10(sp)    check only one sector to read
  108.     bne.s    nocach
  109.  
  110.     move    12(sp),d6    get logical sector number
  111.  
  112.     lea    map+ageing(pc),a3  sector present in cache ?
  113.     moveq    #nsects-1,d2
  114. srchlp: cmp    -(a3),d6
  115.     beq.s    found
  116.     subq    #1,ageing(a3)    leak ageing field
  117.     bgt.s    srchnx
  118.     addq    #1,ageing(a3)    oops, if it was 0 or 1 leave it
  119. srchnx:    dbra    d2,srchlp
  120.  
  121.     lea    map+2*ageing(pc),a3  search for oldest sector
  122.     move    #32767,d1
  123.     moveq    #nsects-1,d2
  124. repllp: cmp    -(a3),d1
  125.     blt.s    replnx
  126.     move.l    a3,a0        new lowest ageing ptr
  127.     move    (a3),d1        new lowest ageing value
  128. replnx:    dbra    d2,repllp
  129.  
  130.     move    d6,-ageing(a0)    replace oldest sector number
  131.     clr    (a0)        0 ageing means not valid yet
  132.     bra.s    nocach
  133.  
  134. found:    add    #ageing,a3
  135.     tst    (a3)        ageing of 0 is invalid
  136.     beq.s    nocach
  137.  
  138.     move    #32767,(a3)    update sector ageing field 
  139.     move    d2,d1        save this index 
  140.     beq.s    calcad
  141.     subq    #1,d2
  142. restlp:    subq    #1,-(a3)    leak remaining fields
  143.     bgt.s    restnx
  144.     addq    #1,(a3)        oops, if it was 0 or 1 leave it
  145. restnx:    dbra    d2,restlp
  146.  
  147. calcad:    move.l    6(sp),a1    user buffer address
  148.     lea    cachbuf(pc),a0
  149.     mulu    #512,d1
  150.     add.l    d1,a0        address of cached sector
  151.  
  152.     bsr    cpysec        copy cached sector to user buffer
  153.  
  154.     clr.l    d0        return success
  155.     rts
  156.     
  157. nocach:    lea    rsave(pc),a0
  158.     move.l    (sp)+,(a0)    save original return address
  159.     pea    ownret(pc)    replace with our own return address
  160.     bra    toold        execute the request
  161. ownret:    move.l    rsave(pc),-(sp)    put back original
  162.     tst.l    d0
  163.     bne.s    return        return if request failed
  164.     
  165.     lea    map+ageing(pc),a3  check if cached sectors need updating
  166.     move    12(sp),d6    get first logical sector number
  167.     move    10(sp),d5
  168.     add    d6,d5        get last+1 logical sector number
  169.     moveq    #nsects-1,d2
  170. updtlp: cmp    -(a3),d6    cached sector number in range ?
  171.     bgt.s    updtnx
  172.     cmp    (a3),d5
  173.     ble.s    updtnx
  174.  
  175.     move    #32767,ageing(a3)  update sector ageing field 
  176.     
  177.     move.l    6(sp),a0    start of user buf
  178.     move    (a3),d1
  179.     sub    d6,d1        number of sectors from start of user buf
  180.     mulu    #512,d1
  181.     add.l    d1,a0        address of the sector in user buf
  182.  
  183.     lea    cachbuf(pc),a1
  184.     move    d2,d1
  185.     mulu    #512,d1
  186.     add.l    d1,a1        address of cached sector
  187.  
  188.     bsr    cpysec        copy user sector to cache
  189.  
  190. updtnx:    dbra    d2,updtlp
  191.  
  192.     clr.l    d0        return success
  193. return:    rts
  194.  
  195. strins:    dc.b    13,10," acache v 1.1 installed",13,10,0
  196.     even
  197.  
  198. rsave:    dsbss.l    1        for return address
  199. map:    dsbss.l nsects        the cache map (sector nr, ageing)
  200. cachbuf:dsbss.b 512*nsects    the cached sector buffer
  201. end:    dsbss.b 0        used for resident memory calculation
  202.