home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / ramd.cq / ramd.c
Encoding:
Text File  |  1986-06-04  |  4.8 KB  |  166 lines

  1. cat newramdisk.c
  2. /* RAM    DISK ACCESSORY
  3.    version 1.1 - sept 10, 1985, by Gert Slavenburg, Mountain View, CA.
  4.     for 1Mbyte Atari ST
  5.  
  6.    version 1.1a - sept 11, 1985, mod. by Gyorgy Fekete, College Park, MD.
  7.  
  8.    version 1.1a is almost identical to Gert's original posting.
  9.    I merely changed some parameters around to let 512K ST owners
  10.    get the benefit of a ramdisk. This one is a 97K ramdisk. I tried
  11.    128K on a 512 ST, but it bombs when you run the C compiler and you
  12.    dont punt aes -- Gyorgy 
  13.    PS: the rest of the program is pretty much as before, except
  14.        for the commented changes.
  15.  
  16.    Link this program with accstart,%1,osbind,vdibind,aesbind
  17.    This is the first, experimental version of the RAMdisk. It should
  18.    be installed as a DESK ACCESSORY on the Bootdisk. Before re-booting,
  19.    and thus activating it, the menu entry "install disk" should be used
  20.    to install drive "D" with icon-label "RAMDISK".
  21.    Then re-boot end enjoy.
  22.  
  23.    known bugs :
  24.    1) diskette copy to/from the RAMdisk doesn't work. Don't know why,
  25.       since the BPB's are identical.
  26.    Lots of fun - Gert
  27.  
  28. */
  29.  
  30. #include "portab.h"
  31. #include "obdefs.h"
  32. #include "define.h"
  33. #include "gemdefs.h"
  34. #include "osbind.h"
  35.  
  36. struct bpb
  37. { WORD recsiz,       /* see BIOS:rwabs.c for more info */
  38.        clsiz,
  39.        clsizb,
  40.        rdlen,
  41.        fsiz,
  42.        fatrec,
  43.        datrec,
  44.        numcl,
  45.        bflags;
  46. };
  47.  
  48. /* stupid AES binding arrays - what a drag */
  49.  
  50. int contrl[12];      /* better find out what's REALLY NEEDED */
  51. int intin[128];
  52. int ptsin[128];
  53. int intout[128];
  54. int ptsout[128];
  55.  
  56. /* the variables below are really serious */
  57.  
  58. typedef LONG (*PFL)(); /* define "pointer to function returning a long" */
  59. typedef WORD (*PFW)(); /* define "pointer to function returning a word" */
  60.  
  61. PFL getbpb;            /* pointer to the systems original getbpb function */
  62. PFW mediach;           /* pointer to the systems original mediach */
  63. PFL rwabs;             /* pointer to the systems original rwabs */
  64.  
  65.  
  66. /* Note that we only use one sector per FAT, and there is no boot sector
  67.    on this ramdisk. Observe the differences from Gert's original 1.1
  68.    I am also using 16 bit FAT's as they are fatster than 12 bit FATs.
  69.    bflags = 0 means 12 bit FAT, bflags = 1 means 16 bit FAT.
  70.  
  71.    size is 97 clusters, so we need data for 97 * 1024 + 3 * 512 bytes.
  72.    or 50688 words.
  73.  */
  74. struct bpb rdiskbpb = { 512, 2, 1024, 1,1, 1, 3, 97, 1 };
  75.  
  76.  
  77. int data[50432];       /* 97 clusters + 3 sectors */
  78. LONG RDgetbpb(dev)
  79. WORD dev;
  80. {
  81.    if (dev != 3) 
  82.       return( (*getbpb)(dev) ); /* pass all non-RAMdisk to old handler */
  83.    else
  84.    {  return( &rdiskbpb );      /* return our bpb */
  85.    }
  86. }
  87.  
  88. WORD RDmediach(dev)
  89. WORD dev;
  90. {
  91.    if (dev != 3)
  92.       return((*mediach)(dev)) ; /* pass all non-RAMdisk to old handler */
  93.    else
  94.       return( 0 );              /* RAMDISK media never changes */
  95. }
  96.  
  97. LONG RDrwabs(rw,buf,count,recno,dev)
  98. WORD rw;
  99. int *buf;
  100. WORD count, recno, dev;
  101. {  int i, *p;
  102.  
  103.    if (dev != 3)
  104.       return( (*rwabs)(rw,buf,count,recno,dev) ); /* pass it on */
  105.    else
  106.    { if (rw > 1) rw -=2;  /* we never change media anyway */
  107.      while ( count > 0 )
  108.      {  p = &data[((long) recno) * 256L]; /* typecasts necessary - bug */
  109.         if (rw==0) /* read */
  110.           for (i=0; i<256; i++) *buf++ = *p++;
  111.         else      /* write */
  112.           for (i=0; i<256; i++) *p++ = *buf++;
  113.         count--; recno++;
  114.      }
  115.      return(0L);
  116.    }
  117. }
  118.  
  119. install()     /* take over DISKIO vectors, MUST RUN AS SUPERVISOR */
  120. {
  121.    long *bpbvect = 0x472;
  122.    long *rwvect  = 0x476;
  123.    long *mcvect  = 0x47e;
  124.    long *devset  = 0x4c2;
  125.  
  126.    getbpb  = (PFL) *bpbvect; /* save old vectors */
  127.    mediach = (PFW) *mcvect;
  128.    rwabs   = (PFL) *rwvect;
  129.    *bpbvect = RDgetbpb;      /* install new ones */
  130.    *mcvect  = RDmediach;
  131.    *rwvect  = RDrwabs;
  132.                              /* vectors set-up, include in deviceset : */
  133.    *devset  = (*devset) | (0x8L);
  134.  
  135. }
  136.  
  137. sleep()                      /* sleep forever */
  138. { int i;
  139.   while (1) 
  140.   {  i = evnt_timer(30000,0); /* wait 30 Sec. */
  141.      Bconout(2,7); /* BEEP to show I'm alive */
  142.   }
  143. }
  144.  
  145. main()
  146.   register long int *ip;
  147.   register int cnt;
  148.   
  149.   appl_init();             /* this is needed !!!!!!! */
  150.  
  151. /*
  152.  * You don't really need this. Zeroing out works fine too.
  153.  * 
  154.   Rwabs(0,data,720,0,0);   copy drive A: into RAMdisk data array
  155.  */
  156.   cnt = 25216;
  157.   ip = (long *) data;
  158.   while(cnt--)
  159.     *ip++ = 0;       /* Zero out all things */
  160.   
  161.   xbios(38,install);       /* INSTALL vectors in SUPV MODE */
  162.   sleep();                 /* accessories never end ..... */
  163. }
  164.  
  165. 9: