home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / assembly / ramdisk / ramdisk.s
Encoding:
Text File  |  1993-12-07  |  6.8 KB  |  304 lines

  1. * ramdisk.s
  2.  
  3. *------------------------------------------------------------------------
  4. *                                    :
  5. *    ST RAMDISK driver (M:)                        :
  6. *    Copyright 1986,1987 Atari Corp.                    :
  7. *                                    :
  8. *    This program is *not* public domain, but you may give it away    :
  9. *    to anyone who wants it.  You may not sell it.            :
  10. *                                    :
  11. *----------------                            :
  12. *    You need MADMAC to assemble this:                :
  13. *                                    :
  14. *        mac -p ramdisk.s                    :
  15. *        or:                                :
  16. *        mac -p -Dramdisk_size=NNN ramdisk.s            :
  17. *                                    :
  18. *    where 'NNN' is from 1 to 999, the size of the ramdisk.        :
  19. *                                    :
  20. *----------------                            :
  21. *    Stick this program in the \AUTO folder of the boot volume.  Or,    :
  22. *    you can simply double-click it after the desktop comes up. This    :
  23. *    is a pretty vanilla ramdisk --- more embellishments would be    :
  24. *    easy.                                :
  25. *                                    :
  26. *----------------                            :
  27. *  9-Aug-1985 lmd    Hacked it up                    :
  28. *  9-Jan-1986 lmd    Fixed sign-extension problem in _rw: and added    :
  29. *            conditional assembly for two kinds of ramdisk.    :
  30. *  9-Jan-1986 lmd    Make it "M:"                    :
  31. * 16-Apr-1986 lmd    Made it easier to adjust size of ramdisk. Print    :
  32. *            correct size of ramdisk.            :
  33. * 22-Sep-1986 lmd    Handle reads/writes to odd buffer locations.    :
  34. *  6-Feb-1987 lmd    Fixed FAT count, added 2 to account for unused    :
  35. *            clusters 0 and 1.                :
  36. *  9-Mar-1987 lmd    Fixed 'stack' equate (realsize*1024)        :
  37. *                                    :
  38. *------------------------------------------------------------------------
  39.  
  40.  
  41. *+
  42. * Define the size of the ramdisk here:
  43. *
  44. * (12k overhead)
  45. *-
  46. ramdisk_size    equ    360        ; perceived size, in K
  47.  
  48.  
  49. *+
  50. *  OS variables and vectors;
  51. *  (stuff we have to subvert.)
  52. *
  53. *-
  54. hdv_init    equ    $46a        ; hdv_init()
  55. hdv_bpb        equ    $472        ; hdv_bpb(dev)
  56. hdv_rw        equ    $476        ; hdv_rw(rw, buf, count, recno, dev)
  57. hdv_boot    equ    $47a        ; hdv_boot()
  58. hdv_mediach    equ    $47e        ; hdv_mediach(dev)
  59. _drvbits    equ    $4c2        ; block device bitVector
  60. _dskbufp    equ    $4c6        ; pointer to common disk buffer
  61. realsize    equ    ramdisk_size+12    ; *REAL* size of the disk
  62.  
  63.  
  64. *+
  65. *  Install driver;
  66. *  setup ramdisk, then
  67. *  terminate and stay resident.
  68. *
  69. *-
  70.     move.l    4(sp),a4        ; a4 -> our basepage
  71.     lea    stack,a7        ; new user stack
  72.     clr.l    -(sp)            ; get superuser mode
  73.     move.w    #$20,-(sp)
  74.     trap    #1
  75.     addq    #6,sp
  76.     move.l    d0,-(sp)        ; save old SSP on stack
  77.  
  78.     bset.b    #4,_drvbits+2        ; set bit for M:
  79.     clr.l    a5            ; easy zero-based pointer
  80.     move.l    hdv_bpb(a5),o_bpb    ; save old disk vectors
  81.     move.l    hdv_rw(a5),o_rw
  82.     move.l    hdv_mediach(a5),o_mediach
  83.     move.l    #hbpb,hdv_bpb(a5)    ; install ramdisk's vectors
  84.     move.l    #hrw,hdv_rw(a5)
  85.     move.l    #hmediach,hdv_mediach(a5)
  86.  
  87.     move.w    #$20,-(sp)        ; back to user mode
  88.     trap    #1            ; (SSP already on the stack)
  89.     addq    #6,sp
  90.  
  91. *--- clear first 8K of ramdisk:
  92.     lea    ramdisk(pc),a0
  93.     move.w    #$400-1,d0
  94. clrit:    clr.l    (a0)+
  95.     clr.l    (a0)+
  96.     dbra    d0,clrit
  97.  
  98. *--- compute size of memory we want to keep:
  99.     move.l    $c(a4),d3        ; d3 = size of text
  100.     add.l    $14(a4),d3        ; d3 += size of data
  101.     add.l    $1c(a4),d3        ; d3 += size of bss
  102.     add.l    #$0100,d3        ; d3 += size of basepage
  103.     add.l    #realsize*1024,d3    ; d3 += size of ramdisk
  104.  
  105.     pea    message(pc)        ; print something informative
  106.     move.w    #9,-(sp)
  107.     trap    #1
  108.     addq    #6,sp
  109.  
  110. *--- terminate and stay resident
  111.     clr.w    -(sp)            ; return code of zero
  112.     move.l    d3,-(sp)        ; # bytes to keep
  113.     move.w    #$31,-(sp)        ; Ptermres()
  114.     trap    #1            ; do it
  115.     illegal                ; "cannot happen"
  116.  
  117.  
  118.  
  119. *+
  120. * LONG hbpb(dev) - return ptr to BPB (or NULL)
  121. *
  122. * Passed:    dev    4(sp).W
  123. *
  124. *-
  125. hbpb:
  126.     move.w    4(sp),d0        ; d0 = devno
  127.     move.l    o_bpb,a0        ; a0 -> pass-through vector
  128.     lea    _bpb(pc),a1        ; a1 -> our handler
  129.     bra    check_dev        ; do it
  130.  
  131.  
  132. *+
  133. * LONG rw(rw, buf, count, recno, dev)
  134. *
  135. * Passed:    dev    $e(sp).W
  136. *        recno    $c(sp).W
  137. *        count    $a(sp).W
  138. *        buf    6(sp).L
  139. *        rw    4(sp).W
  140. *
  141. *-
  142. hrw:
  143.     move.w    $e(sp),d0        ; d0 = devno
  144.     move.l    o_rw,a0            ; a0 -> pass-through vector
  145.     lea    _rw(pc),a1        ; a1 -> our handler
  146.     bra    check_dev        ; do it
  147.  
  148.  
  149. *+
  150. * LONG mediach(dev)
  151. *
  152. * Passed:    dev    4(sp).W
  153. *
  154. *-
  155. hmediach:
  156.     move.w    4(sp),d0        ; d0 = devno
  157.     move.l    o_mediach,a0        ; a0 -> pass-through vector
  158.     lea    _mediach(pc),a1        ; a1 -> our handler
  159.  
  160.  
  161. *+
  162. * check_dev - use handler, or pass vector through
  163. *
  164. * Passed:    d0.w = device#
  165. *        a0 ->  old handler
  166. *        a1 ->  new handler
  167. *        a5 ->  $0000 (zero-page ptr)
  168. *
  169. * Jumps-to:    (a1) if dev in range for this handler
  170. *        (a0) otherwise
  171. *
  172. *-
  173. check_dev:
  174.     cmp.w    #12,d0            ; M:?
  175.     bne    chkd_f            ; (no)
  176.     move.l    a1,a0            ; yes -- follow success vector
  177. chkd_f:    jmp    (a0)            ; do it
  178.  
  179.  
  180.  
  181. *+
  182. * _bpb - return BPB for RAMDISK
  183. *  Synopsis:    LONG _bpb(dev)
  184. *        WORD dev;
  185. *
  186. *  Returns:    NULL, or a pointer to the BPB buffer
  187. *
  188. *-
  189. _bpb:
  190.     move.l    #thebpb,d0
  191.     rts
  192.  
  193.  
  194. *+
  195. * _rw - read/write ramdisk sectors
  196. *  Synopsis:    _rw(rw, buf, count, recno, dev)
  197. *
  198. *  Passed:    dev    $e(sp).W
  199. *        recno    $c(sp).W
  200. *        count    $a(sp).W
  201. *        buf    6(sp).L
  202. *        rw    4(sp).W
  203. *
  204. *-
  205. _rw:
  206.     lea    ramdisk(pc),a0        ; a0 -> base of ramdisk
  207.     moveq    #0,d0
  208.     move.w    $c(sp),d0        ; d0 = sect# << 9
  209.     lsl.l    #8,d0
  210.     lsl.l    #1,d0
  211.     add.l    d0,a0            ; a0 -> ramdisk mem
  212.  
  213.     moveq    #0,d2            ; d2 = byte count / 32
  214.     move.w    $a(sp),d2
  215.     lsl.l    #4,d2            ; log2(512 / 32) = 4
  216.  
  217.     move.l    6(sp),a1        ; a1 -> buffer
  218.     tst.w    4(sp)            ; if (rw) exchange(a0, a1)
  219.     beq.s    rw_1
  220.     exg    a0,a1            ; swap src & dest
  221.  
  222. rw_1:    move.l    a1,d0            ; if (odd operation)
  223.     btst    #0,d0            ;    then do it slowly
  224.     bne.s    rw_odd
  225.  
  226. rw_2:    move.l    (a0)+,(a1)+        ; move 32 bytes
  227.     move.l    (a0)+,(a1)+
  228.     move.l    (a0)+,(a1)+
  229.     move.l    (a0)+,(a1)+
  230.     move.l    (a0)+,(a1)+
  231.     move.l    (a0)+,(a1)+
  232.     move.l    (a0)+,(a1)+
  233.     move.l    (a0)+,(a1)+
  234.     subq.l    #1,d2            ; while (--d2)
  235.     bmi.s    rw_q
  236.     bne.w    rw_2
  237.     bra.s    rw_q
  238.  
  239. rw_odd:    lsl.w    #3,d2            ; d2 *= 8 (== count/4)
  240. rw_3:    move.b    (a0)+,(a1)+
  241.     move.b    (a0)+,(a1)+
  242.     move.b    (a0)+,(a1)+
  243.     move.b    (a0)+,(a1)+
  244.     subq.l    #1,d2            ; while (--d2)
  245.     bmi.s    rw_q
  246.     bne.w    rw_3
  247.  
  248. rw_q:    clr.l    d0            ; return OK
  249.     rts
  250.  
  251.  
  252. *+
  253. * _mediach - return FALSE media change (RAMDISK never changes)
  254. * Synopsis:    _mediach(dev)
  255. *        WORD dev;
  256. *
  257. * Returns:    0L
  258. *
  259. *-
  260. _mediach:
  261.     clr.l    d0
  262.     rts
  263.  
  264.  
  265. *+
  266. *  BPB for ramdisk
  267. *
  268. *-
  269. thebpb:
  270.     dc.w    512            ; #bytes/sector
  271.     dc.w    2            ; #sectors/cluster
  272.     dc.w    1024            ; #bytes/cluster
  273.     dc.w    4            ; rdlen (64 files)
  274.     dc.w    4            ; fat size
  275.     dc.w    4            ; 2nd FAT start
  276.     dc.w    12            ; 1st cluster start
  277.     dc.w    realsize-12+2        ; #clusters on media
  278.     dc.w    1            ; flags (16-bit FATs)
  279.  
  280.  
  281.  
  282. o_init:        dc.l    0        ; old hdv_init
  283. o_bpb:        dc.l    0        ; old hdv_bpb
  284. o_rw:        dc.l    0        ; old hdv_rw
  285. o_mediach:    dc.l    0        ; old hdv_mediach
  286.  
  287. rds100        equ    ramdisk_size/100
  288. rds10        equ    (ramdisk_size-(rds100*100))/10
  289. rds1        equ    (ramdisk_size-((rds100*100)+(rds10*10)))
  290.  
  291. message:
  292. siz100:        dc.b    rds100+'0'
  293. siz10:        dc.b    rds10+'0'
  294. siz1:        dc.b    rds1+'0'
  295.         dc.b    'K RAMDISK installed as M:'
  296.         dc.b    13,10
  297.         dc.b    'version 22-Sep-1986 lmd.'
  298.         dc.b    13,10
  299.         dc.b    0
  300.  
  301.     even
  302. ramdisk:    dc.w    0        ; beginning of Ramdisk
  303. stack        equ    ramdisk+(realsize*1024)
  304. əəəəəəə