📄 ramdisk.c
字号:
{
driveno = driveno;
command = command;
buffer = buffer;
return(NO);
}
/************************************************************************
* FUNCTION
*
* pc_rd_raw_open
*
* DESCRIPTION
*
* This function doesn't do anything for the RAM Disk. It is
* included for devtable consistency.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
INT pc_rd_raw_open(UINT16 driveno)
{
driveno = driveno;
return(NO);
}
/************************************************************************
* FUNCTION
*
* pc_rd_open
*
* DESCRIPTION
*
* This function prepares the RAM Disk for usage by allocating the
* pages necesary for usage.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* driveno The number assigned to the
* RAM Disk (not used)
*
* OUTPUTS
*
* YES Successful Completion.
* NO Couldn't allocate all of the
* pages.
*
*************************************************************************/
INT pc_rd_open(UINT16 driveno)
{
UINT16 i;
UINT16 j;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
/* If the ramdisk is not initialized, do it now */
if (!rd_pages[0])
{
for (i = 0; i < NUM_RAMDISK_PAGES; i++)
{
rd_pages[i] = rd_alloc_page();
if (!rd_pages[i])
{
for (j = 0; j < i; j++)
{
rd_free_page(rd_pages[j]);
rd_pages[j] = 0;
}
return(NO);
}
}
}
rd_opencount += 1;
return(YES);
}
/************************************************************************
* FUNCTION
*
* pc_rd_close
*
* DESCRIPTION
*
* This function deallocates all of the pages associated with the
* RAM Disk. The actual code here is commented out since we
* probably don't want to loose the data on a close.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* driveno The number assigned to the
* RAM Disk (not used)
*
* OUTPUTS
*
* YES Successful Completion.
* NO Couldn't allocate all of the
* pages.
*
*************************************************************************/
INT pc_rd_close(UINT16 driveno)
{
int i;
if (rd_opencount)
--rd_opencount;
if (!rd_opencount)
{
for (i = 0; i < NUM_RAMDISK_PAGES; i++)
{
rd_free_page(rd_pages[i]);
rd_pages[i] = 0;
}
}
driveno = driveno;
return(YES);
}
/************************************************************************
* FUNCTION
*
* pc_rd_io
*
* DESCRIPTION
*
* This function reads or writes data from and to the RAM Disk
* based on the 'reading' parameter.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* driveno The number assigned to the
* RAM Disk (not used)
* block The block number to read or
* write
* buffer Pointer to the data to be
* placed from a read or
* stored on a write
* count Number of bytes to be read
* or written
* reading Indicates whether or not we
* are reading or writing
*
* OUTPUTS
*
* YES Successful Completion.
* NO Block number is out of range.
*
*************************************************************************/
INT pc_rd_io(UINT16 driveno, UINT32 block, VOID *buffer, UINT32 count,
INT reading)
{
UINT8 *p;
UINT32 ltemp;
UINT16 page_number;
UINT16 byte_number;
INT16 i;
UINT8 *pbuffer;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
pbuffer = (UINT8 *)buffer;
while (count)
{
/* Get the page number */
ltemp = block / RAMDISK_PAGE_SIZE;
page_number = (UINT16) ltemp;
/* Check. This shouldn't happen */
if ( (page_number >= NUM_RAMDISK_PAGES) || !rd_pages[page_number] )
return(NO);
/* Get the offset */
ltemp = block % RAMDISK_PAGE_SIZE;
byte_number = (UINT16) (ltemp*512);
p = rd_pages[page_number];
p += byte_number;
if (reading)
{
for (i = 0; i < 512; i++)
*pbuffer++ = *p++;
}
else
{
for (i = 0; i < 512; i++)
*p++ = *pbuffer++;
}
count--;
block++;
}
return(YES);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -