home *** CD-ROM | disk | FTP | other *** search
- cat newramdisk.c
- /* RAM DISK ACCESSORY
- version 1.1 - sept 10, 1985, by Gert Slavenburg, Mountain View, CA.
- for 1Mbyte Atari ST
-
- version 1.1a - sept 11, 1985, mod. by Gyorgy Fekete, College Park, MD.
-
- version 1.1a is almost identical to Gert's original posting.
- I merely changed some parameters around to let 512K ST owners
- get the benefit of a ramdisk. This one is a 97K ramdisk. I tried
- 128K on a 512 ST, but it bombs when you run the C compiler and you
- dont punt aes -- Gyorgy
- PS: the rest of the program is pretty much as before, except
- for the commented changes.
-
- Link this program with accstart,%1,osbind,vdibind,aesbind
- This is the first, experimental version of the RAMdisk. It should
- be installed as a DESK ACCESSORY on the Bootdisk. Before re-booting,
- and thus activating it, the menu entry "install disk" should be used
- to install drive "D" with icon-label "RAMDISK".
- Then re-boot end enjoy.
-
- known bugs :
- 1) diskette copy to/from the RAMdisk doesn't work. Don't know why,
- since the BPB's are identical.
- Lots of fun - Gert
-
- */
-
- #include "portab.h"
- #include "obdefs.h"
- #include "define.h"
- #include "gemdefs.h"
- #include "osbind.h"
-
- struct bpb
- { WORD recsiz, /* see BIOS:rwabs.c for more info */
- clsiz,
- clsizb,
- rdlen,
- fsiz,
- fatrec,
- datrec,
- numcl,
- bflags;
- };
-
- /* stupid AES binding arrays - what a drag */
-
- int contrl[12]; /* better find out what's REALLY NEEDED */
- int intin[128];
- int ptsin[128];
- int intout[128];
- int ptsout[128];
-
- /* the variables below are really serious */
-
- typedef LONG (*PFL)(); /* define "pointer to function returning a long" */
- typedef WORD (*PFW)(); /* define "pointer to function returning a word" */
-
- PFL getbpb; /* pointer to the systems original getbpb function */
- PFW mediach; /* pointer to the systems original mediach */
- PFL rwabs; /* pointer to the systems original rwabs */
-
-
- /* Note that we only use one sector per FAT, and there is no boot sector
- on this ramdisk. Observe the differences from Gert's original 1.1
- I am also using 16 bit FAT's as they are fatster than 12 bit FATs.
- bflags = 0 means 12 bit FAT, bflags = 1 means 16 bit FAT.
-
- size is 97 clusters, so we need data for 97 * 1024 + 3 * 512 bytes.
- or 50688 words.
- */
- struct bpb rdiskbpb = { 512, 2, 1024, 1,1, 1, 3, 97, 1 };
-
-
- int data[50432]; /* 97 clusters + 3 sectors */
- LONG RDgetbpb(dev)
- WORD dev;
- {
- if (dev != 3)
- return( (*getbpb)(dev) ); /* pass all non-RAMdisk to old handler */
- else
- { return( &rdiskbpb ); /* return our bpb */
- }
- }
-
- WORD RDmediach(dev)
- WORD dev;
- {
- if (dev != 3)
- return((*mediach)(dev)) ; /* pass all non-RAMdisk to old handler */
- else
- return( 0 ); /* RAMDISK media never changes */
- }
-
- LONG RDrwabs(rw,buf,count,recno,dev)
- WORD rw;
- int *buf;
- WORD count, recno, dev;
- { int i, *p;
-
- if (dev != 3)
- return( (*rwabs)(rw,buf,count,recno,dev) ); /* pass it on */
- else
- { if (rw > 1) rw -=2; /* we never change media anyway */
- while ( count > 0 )
- { p = &data[((long) recno) * 256L]; /* typecasts necessary - bug */
- if (rw==0) /* read */
- for (i=0; i<256; i++) *buf++ = *p++;
- else /* write */
- for (i=0; i<256; i++) *p++ = *buf++;
- count--; recno++;
- }
- return(0L);
- }
- }
-
- install() /* take over DISKIO vectors, MUST RUN AS SUPERVISOR */
- {
- long *bpbvect = 0x472;
- long *rwvect = 0x476;
- long *mcvect = 0x47e;
- long *devset = 0x4c2;
-
- getbpb = (PFL) *bpbvect; /* save old vectors */
- mediach = (PFW) *mcvect;
- rwabs = (PFL) *rwvect;
- *bpbvect = RDgetbpb; /* install new ones */
- *mcvect = RDmediach;
- *rwvect = RDrwabs;
- /* vectors set-up, include in deviceset : */
- *devset = (*devset) | (0x8L);
-
- }
-
- sleep() /* sleep forever */
- { int i;
- while (1)
- { i = evnt_timer(30000,0); /* wait 30 Sec. */
- Bconout(2,7); /* BEEP to show I'm alive */
- }
- }
-
- main()
- {
- register long int *ip;
- register int cnt;
-
- appl_init(); /* this is needed !!!!!!! */
-
- /*
- * You don't really need this. Zeroing out works fine too.
- *
- Rwabs(0,data,720,0,0); copy drive A: into RAMdisk data array
- */
- cnt = 25216;
- ip = (long *) data;
- while(cnt--)
- *ip++ = 0; /* Zero out all things */
-
- xbios(38,install); /* INSTALL vectors in SUPV MODE */
- sleep(); /* accessories never end ..... */
- }
-
- 9: