📄 miniexec.c
字号:
/*
* EBS - RTFS (Real Time File Manager)
*
* Copyright EBS Inc. 1996
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*/
/* miniexec.c - Miscelaneous system specific functions for rtfs
*
* These routines provide executive services for RTFS
*/
/*
+++ The following functions must be provided
+++
+++ void pc_report_error(int error_number)
+++ DATESTR *pc_getsysdate(DATESTR *pd)
+++ byte os_floppy_type(int driveno)
+++
*/
// This is used only in RTIP enviroment
// Not used in ERTFS_STAND_ALONE mode
#include <pcdisk.h>
/******************************************************************************
pc_report_error() - Report internal error: (MUST BE USER SUPPLIED !)
Summary
Description
When the system detects an error needs it calls this routine with
PCERR_????? as an argument. In the reference port we call printf
to report the error. You may do anything you like with these
errors.
Returns
Returns NOTHING.
*****************************************************************************/
/*
#define PCERR_FAT_FLUSH 0 Cant flush FAT
#define PCERR_INITMEDI 1 Not a DOS disk:pc_dskinit
#define PCERR_INITDRNO 2 Invalid driveno to pc_dskinit
#define PCERR_INITCORE 3 Out of core:pc_dskinit
#define PCERR_INITDEV 4 Can't initialize device:pc_dskinit
#define PCERR_INITREAD 5 Can't read block 0:pc_dskinit
#define PCERR_BLOCKCLAIM 6 PANIC: Buffer Claim
#define PCERR_BLOCKLOCK 7 Warning: freeing a locked buffer
#define PCERR_REMINODE 8 Trying to remove inode with open > 1
#define PCERR_FATREAD 9 "IO Error While Failed Reading FAT"
#define PCERR_DROBJALLOC 10 "Memory Failure: Out of DROBJ Structures"
#define PCERR_FINODEALLOC 11 "Memory Failure: Out of FINODE Structures"
*/
void pc_report_error(int error_number) /*__fn__*/
{
#if (!defined(ERTFS_SA))
DEBUG_ERROR("Error Number", EBS_INT1, error_number, 0);
#elif (SUPPORTS_CONSOLE)
tm_printf("Error %d\n", error_number);
#endif
}
/*
*****************************************************************************
PC_GETSYSDATE - Get the current system time and date (USER SUPPLIED)
Summary
#include <pcdisk.h>
DATESTR *pc_getsysdate(pd)
DATESTR *pd; put result here
Description
When the system needs to date stamp a file it will call this routine
to get the current time and date. YOU must modify the shipped routine
to support your hardware's time and date routines. If you don't modify
this routine the file date on all files will be the same.
The source for this routine is in file pc_udate.c and is self explanatory.
NOTE: Be sure to retain the property of returning its argument. The
package depends on it.
Returns
The argument it was passed. A structure containing date and time info.
Example:
#include <pcdisk.h>
DATESTR crdate;
Load the inode copy name,ext,attr,cluster, size,datetime
pc_init_inode( pobj->finode, filename, fileext,
attr, cluster, 0L ,pc_getsysdate(&crdate) );
*****************************************************************************
*/
#if (RTFS_WRITE)
#if (DOS)
#include <time.h>
#endif
#if (SMX)
// ********************************************************************
#include <time.h>
#define PST 1 // Pacific Standard Time
// Not needed for HIGHC and not needed for UNDOS, since unDOS provides
// this functionality.
#if !__HIGHC__ && !defined(UNDOS)
// USER: set as appropriate. Note that the routines below do not account
// for daylight savings time. See isDST() below.
#if (PST)
#define DefaultTimeZone 8L /* PST */
#define DefaultTZname "PST" /* Default normal time zone name */
#define DefaultDSTname "PDT" /* Default daylight savings zone name */
#else
#define DefaultTimeZone 5L /* EST */
#define DefaultTZname "EST" /* Default normal time zone name */
#define DefaultDSTname "EDT" /* Default daylight savings zone name */
#endif
#define TZSEC (DefaultTimeZone * 60L * 60L)
#if __cplusplus
extern "C" {
#endif
#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x410) /* 0x410 means BC v3.10 (weird) */
#define _daylight daylight
#define _timezone timezone
char *const tzname[2] = {DefaultTZname, DefaultDSTname}; /* needed by strftime() which is in ctime.c for BC v3.1 */
#endif
#if defined(_MSC_VER) && !defined(FM)
int __near __cdecl _daylight; /* non-zero if daylight savings time is used */
long __near __cdecl _timezone = TZSEC; /* difference in seconds between GMT and local time */
#else
int _daylight;
long _dstbias = -3600L; /* DST offset in seconds */
long _timezone = TZSEC;
#endif
// The following renames have to be here, before the definitions of
// the functions, because we want them and all calls to them to be
// translated to the correct names for the compilers.
#if defined(__BORLANDC__)
#if defined(FM)
#define isDST _isDST
#else
#define isDST _ISDST
#endif
#else // MSC
#define isDST _isindst
#define tzset __tzset
#endif
#ifndef FM
#ifdef __BORLANDC__
#pragma codeseg _TEXT
#else
#pragma code_seg ("_TEXT")
#endif
#endif
int isDST(...); /* simple names! */
void tzset(void);
#ifndef FM
#ifdef __BORLANDC__
#pragma codeseg
#else
#pragma code_seg ()
#endif
#endif
#if __cplusplus
}
#endif
#endif // !__HIGHC__ && !UNDOS
#endif // SMX
#if (SMX)
// ********************************************************************
/* get date and time from the host system */
DATESTR *pc_getsysdate(DATESTR *pd) /*__fn__*/
{
word year; /* relative to 1980, for pc */
word month; /* 1 - 12 */
word day; /* 1 - 31 */
word hour;
word minute;
word sec; /* Note: seconds are 2 second/per. ie 3 == 6 seconds */
/* Use critical region in case OS time date function isn't re-entrant */
/* PC_ENTER_CRITICAL() No need for smx */
/* get the time and date */
/* USER: The goal of this routine is to set pd->time and pd->date to
meaningful values. If you are lucky enough to have a hardware clock
that will easily return year, month, day, etc, then you can add the
call necessary to get the time from it, then assign the variables
appropriately below. If not, the technique is to use the smx stimex
variable (which is just a seconds counter) and somehow convert its
value into the correct time. The difficulty in this is accounting
for daylight savings, leap years, and time zones. This is what the
C library localtime() does. This routine is surprisingly complicated!
The problem with localtime() is that it is operating system dependent.
If running the smxFile demo on a PC under DOS, there should be no
problem. For 32-bit flat mode, localtime() depends on a Windows DLL.
The tzset() and _isindst() functions below this function replace
those in the C library to remove the DLL dependency (but they need
a lot of work if you want them to determine if in Daylight Savings
time, etc). Possibly 3rd party time conversion functions are available
that can be used instead. Note that if all you care about is whether
one file is newer than another, you may just want to forget about
converting stimex and just view the file's time and date stamp as a
serial number.
*/
#if 0
// hard-coded date 1/1/96 1:01am
hour = (word) 1;
minute = (word) 1;
sec = (word) 0;
year = (word) (96-80); /* -80 is a pc correction -- years rel to 1980 */
month = (word) 1;
day = (word) 1;
#else
// C library localtime() is used to convert stimex to meaningful
// date and time
dword t;
struct tm *timeptr;
t = get_stime();
timeptr = localtime((time_t *) &t);
hour = (word) timeptr->tm_hour;
minute = (word) timeptr->tm_min;
sec = (word) (timeptr->tm_sec/2);
year = (word) (timeptr->tm_year - 80); /* tm_year rel to 1900, pc wants rel to 1980 (1996 -> 16) */
month = (word) (timeptr->tm_mon+1);
day = (word) timeptr->tm_mday;
#endif
pd->time = (word) ( (hour << 11) | (minute << 5) | sec);
pd->date = (word) ( (year << 9) | (month << 5) | day);
/* PC_EXIT_CRITICAL() No need for smx */
return (pd);
}
#else
/* get date and time from the host system */
DATESTR *pc_getsysdate(DATESTR *pd) /*__fn__*/
{
word year; /* relative to 1980 */
word month; /* 1 - 12 */
word day; /* 1 - 31 */
word hour;
word minute;
word sec; /* Note: seconds are 2 second/per. ie 3 == 6 seconds */
#if (DOS)
/* This code will work if yoiu have ANSI time functions. otherwise get
rid of it and look below where the time is wired to 3/28/8.
You may modify that code to work in your environment. */
struct tm *timeptr;
time_t timer;
time(&timer);
timeptr = localtime(&timer);
hour = (word) timeptr->tm_hour;
minute = (word) timeptr->tm_min;
sec = (word) (timeptr->tm_sec/2);
/* Date comes back relative to 1900 (eg 93). The pc wants it relative to
1980. so subtract 80 */
year = (word) (timeptr->tm_year-80);
month = (word) (timeptr->tm_mon+1);
day = (word) timeptr->tm_mday;
#else
/* This code is useless but very generic */
/* Hardwire for now */
/* 7:37:28 PM */
hour = 19;
minute = 37;
sec = 14;
/* 3-28-88 */
year = 8; /* relative to 1980 */
month = 3; /* 1 - 12 */
day = 28; /* 1 - 31 */
#endif
pd->time = (word) ( (hour << 11) | (minute << 5) | sec);
pd->date = (word) ( (year << 9) | (month << 5) | day);
return (pd);
}
#endif // SMX
#if (SMX)
// ********************************************************************
// Not needed for HIGHC and not needed for UNDOS, since unDOS provides
// this functionality.
#if !__HIGHC__ && !defined(UNDOS)
/* These routines are called by the C library localtime() function.
They were put here since the tzset() in the library calls a
Windows DLL. (DLL's are not supported by pmEasy.) You may wish
to set timezone to 0 and set stime to local time, rather than
GMT. Note that the routines below do not correct for daylight
savings time. They assume always standard time. */
#ifndef FM
#ifdef __BORLANDC__
#pragma codeseg _TEXT
#else
#pragma code_seg ("_TEXT")
#endif
#endif
void tzset(void)
{
/* This normally asks the operating system what timezone we are
in. Instead, simply set DefaultTimeZone above. */
}
#if (!defined(__WATCOMC__)) // WC doesn't like ... without any arguments.
int isDST(...)
{
/* This routine is hardcoded to always say standard time (not
daylight savings). Code to determine this is much more complicated.
If you add code to calculate daylight savings, the time produced
by this whole mess might actually be right! */
_daylight = 0; /* non-zero means daylight savings */
return (_daylight);
}
#endif
#ifndef FM
// put code segment back to default for this module:
#ifdef __BORLANDC__
#pragma codeseg
#else
#pragma code_seg ()
#endif
#endif
#endif // !__HIGHC__ && !UNDOS
#if __HIGHC__ && !defined(UNDOS)
#if __cplusplus
extern "C" {
#endif
// Called by tzset(). If NULL is returned, default timezone of library
// is used, which happens to be PST8PDT"
char * _mwgetenv2(const char *varname)
{
return NULL;
}
#if __cplusplus
}
#endif
#endif // __HIGHC__ && !UNDOS
#endif // SMX
#endif // RTFS_WRITE
#if (USE_FLOPPY)
// ********************************************************************
/*
* Name:
* os_floppy_type() Return the hardware drive number
*
* Summary:
* byte os_floppy_type(word driveno)
*
* Inputs:
* None
*
* Returns:
* DT_NONE No drive
* DT_360 360 K 5.25" drive
* DT_12 1.2 M 5.25" drive
* DT_720 720 K 3.50" drive
* DT_144 1.44M 3.50" drive
* DT_288 2.88M 3.50" drive
*
* Nothing
*
* Description:
* Returns the drive type at driveno.
*
*
* Porting considerations:
* On the PC AT the drive types are stored in CMOS RAM. We return these
* values. On a non AT platforms you need to find an alternate method.
*/
/* AT specific code. */
static byte read_cmos(word address) /* __fn__ */
{
OUTBYTE(0x70,(word) (address | 0x80));
return((byte)INBYTE(0x71));
}
byte os_floppy_type(int driveno) /*__fn__*/
{
byte utemp;
/* Read the CMOS */
utemp = read_cmos(0x90);
if (driveno)
return((byte)(utemp&0x0f));
else
return((byte) (utemp >> 4));
}
#endif // USE_FLOPPY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -