home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Shareware Masterblend
/
cdsharewaremasterblend.iso
/
utils
/
adj-ramd
/
adjram30.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-09-09
|
36KB
|
1,110 lines
/* Adjustable Ram Disk
(c) Copyright 1986 by Gary Cramblitt. All Rights Reserved.
v2.2 1 Jul 86 Initial version
v2.3 24 Aug 86 Bug. FAT media byte not updated properly.
v2.4 29 Aug 86 If current drive is memory disk drive, reset current
directory on exit.
v2.5 30 Aug 86 Increase FAT to permit max size of 2043K;
Increase size of root directory to 128 entries;
Start code for /E option (Expanded Memory Support)
v3.0 30 Aug 86 Finish code for /E option.
For program usage, see the last routine.
This program is coded in DeSmet C v2.4. Any function beginning
with underscore (_) is a non-standard routine from the DeSmet library.
They are:
_showcs()
Synopsis: unsigned _showcs()
Returns the current value of CS.
_showds()
Synopsis: unsigned _showds()
Returns the current value of DS (= SS in DeSmet C).
_peek()
Synopsis: char _peek(offset,segment)
char *offset;
unsigned segment;
Returns the byte at specified far address.
_doint()
Synopsis: set any or all of the externs
_rax,_rbx,_rcx,_rdx,_rsi,_rdi,_res,_rds
followed by
_doint(interrupt number);
Performs the specified interrupt with the specified
registers set from the externs.
After the call, _rax, etc. can be used. _carryf
and _zerof are extern char variables set to 1 if
the carry or zero flag is set.
In addition, the following routines are semi_standard, and may have
slightly different implementations with your compiler:
strncmp()
Synopsis: char *strncmp(leftstring,rightstring,max)
char *leftstring, *rightstring
int max
strncmp() compares up to a specified number of chars
in two strings. It returns 0 if the specified number
of characters in the string are the same.
free()
Synopsis: int free(pointer)
char *pointer
free memory previously allocated (by calloc). Called
"cfree" in K&R.
*/
/* ==== Definitions ==== */
/* ---- Overall Definitions ---- */
#define true 1
#define false 0
#define max_size 2043 /* max memory disk size */
/*
---- To compile without LOTUS/INTEL/Microsoft Expanded Memory
support, change the "1" to "0" in the next statement. This
will save about 2500 bytes in the .EXE file.
*/
#define em_support 1 /* compile for EM support */
/*
The following symbols must correspond to the same symbols in
file amdisk.asm. If one is changed, so must the other.
This is because the first memory block may not be
deallocated.
*/
#define min_size 64 /* minimum 64K = 128 sectors */
#define sec_per_blk 64 /* increment in 32K blocks */
/*
---- Disk definitions. Note: These constants should be made into
variables or functions if this program's algorithms need to
be generalized to disks of any type, especially high density disks.
Since this program works only in conjunction with amdisk.asm,
is OK to make them constants here.
*/
#define bytes_per_sec 512 /* 512 bytes per sector */
#define par_per_sec (512/16)
/* 32 paragraphs per sector */
#define sec_per_K (1024/512)
/* sectors per 1024 bytes */
#define dir_per_sec (512/sizeof(struct dir_entry))
/* directory entries per sector */
#define em_pag_per_blk 2 /* two 16K EM pages per mem block */
/* ---- Program Segment Prefix ---- */
#define environment_segment 0x2c /* segment address of the environment */
/* ---- DOS interrupts ---- */
#define dosi_dosf 0x21 /* DOS function interrupt */
#define dosi_dsk_read 0x25 /* DOS absolute disk read interrupt */
#define dosi_dsk_write 0x26 /* DOS absolute disk write interrupt */
/* ---- User interrupts ---- */
#define usri_emm 0x67 /* LOTUS/INTEL/Microsoft Expanded
Memory Manager */
/* ---- DOS functions ---- */
#define dosf_seldisk 0x0e /* set default disk */
#define dosf_getdisk 0x19 /* get current default disk */
#define dosf_getver 0x30 /* get DOS version number */
#define dosf_keepprc 0x31 /* keep process (term and stay resident) */
#define dosf_drvfre 0x36 /* get disk free space */
#define dosf_chdir 0x3b /* set default directory */
#define dosf_openh 0x3d /* open file handle */
#define dosf_closeh 0x3e /* close file handle */
#define dosf_ioctl 0x44 /* IOCTL */
#define dosf_cwd 0x47 /* get current directory */
#define dosf_alloc 0x48 /* allocate memory block */
#define dosf_dealloc 0x49 /* deallocate memory block */
#define dosf_setblk 0x4a /* modify memory block */
/* ---- LOTUS/INTEL/Microsoft Expanded Memory Manager functions ---- */
#define emm_status 0x40 /* get manager status */
#define emm_get_PFseg 0x41 /* get page frame segment */
#define emm_get_pages 0x42 /* get number of pages */
#define emm_get_handle 0x43 /* get handle and allocate memory */
#define emm_map_memory 0x44 /* map memory */
#define emm_fre_handle 0x45 /* free handle and memory */
#define emm_get_ver 0x46 /* get EMM version */
#define emm_sav_map 0x47 /* save mapping context */
#define emm_res_map 0x48 /* restore mapping context */
#define emm_num_handles 0x4b /* get number of EMM handles */
#define emm_hdl_pages 0x4c /* get pages owned by handle */
#define emm_all_pages 0x4d /* get pages for all handles */
#define emm_pag_map 0x4e /* get or set page map */
#define nor_flg 0 /* memory block is in normal memory */
#define em_flg 1 /* memory block is in expaned memory */
/*
---- DOS Errors ----
These codes are returned by program and can be tested with DOS
IF statement.
*/
#define dose_noerr 0 /* no error */
#define dose_invfunc 1 /* invalid function */
#define dose_arena 7 /* arena trashed */
#define dose_noram 8 /* not enough memory */
#define dose_invdrv 15 /* invalid drive */
/* ---- Directory definitions ---- */
#define never_used 0 /* directory entry never used */
#define erased 0xe5 /* file has been erased */
#define dir_bit 0x10 /* this bit indicates subdirectory */
/* ---- FAT definitions ---- */
#define available 0 /* cluster is available for use */
#define bad 0xff7 /* cluster is bad */
#define last_low 0xff8 /* last cluster for the file */
#define last_high 0xfff /* last cluster for the file */
extern unsigned _rax, _rbx, _rcx, _rdx, _rsi, _rdi, _res, _rds;
extern char _carryf, _zerof;
/* ---- Directory entry ---- */
struct dir_entry {
union dir_name {
char name[8];
unsigned char status;
} u_name;
char ext[3];
unsigned char attr;
unsigned char reserved[10];
unsigned int time;
unsigned int date;
unsigned int first_cluster;
unsigned long size;
};
/* ==== Global Data Storage ==== */
unsigned int pgm_seg; /* CS at start of program saved here */
int drive_number; /* memory disk drive number A=0, B=1, etc */
int mdisk_size; /* user's desired memory disk size in K */
int mdisk_secs; /* user's desired memory disk size in sectors */
int mdisk_chg; /* the difference between disk's current size
and the desired size (in sectors) */
int free_secs; /* unused sectors in the memory disk */
int first_dir_sector;
int last_dir_sector; /* loc of directory */
int first_fat_sector;
int last_fat_sector; /* loc of FAT */
int free_cluster; /* ptr to first free cluster */
int first_data_sector; /* first sector after the last FAT */
/* ---- Memory Disk Boot Record ---- */
struct boot_record {
unsigned char jmp[3]; /* non-bootable (no jump instruction ) */
char ident[8]; /* identification */
unsigned int bytes_in_sector;/* bytes/sector */
unsigned char sec_per_cluster;/* sectors/cluster */
unsigned int bpb_reserved; /* reserved sectors */
unsigned char bpb_fats; /* number of FAT's */
unsigned int bpb_root; /* directory entries in root */
unsigned int bpb_total; /* total number of sectors */
unsigned char bpb_media; /* media byte = number of mem blocks */
unsigned int bpb_fat_size; /* sectors/FAT */
unsigned int sec_per_track; /* sectors/track */
unsigned int heads; /* number of heads */
unsigned int hidden; /* hidden se