1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
/*-----------------------------------------------------------------*-C-*---
* File: handc/platform/dos/osglue.c
*
* Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
* as part of the RScheme project, licensed for free use.
* See <http://www.rscheme.org/> for the latest information.
*
* File version: 1.3
* File mod date: 1997.11.29 23:10:47
* System build: v0.7.2, 97.12.21
*
* Purpose: Low-level OS glue for DOS
*------------------------------------------------------------------------*/
#include "scheme.h"
#include "intrs.h"
#include "regs.h"
#include "runtime.h"
#include "osglue.h"
#include <stdlib.h>
#include <string.h>
#define MAX_SIG (10)
rs_bool rssig_ready = NO;
struct sig_queue {
rs_bool *ready;
rs_bool enable;
unsigned num_sig;
int sig_queue[MAX_SIG];
};
static void sig_add( struct sig_queue *q, int id );
static struct sig_queue the_sig_queue;
static void osglue_error( const char *fn, int rc )
{
scheme_error( "OS glue error in ~s: rc ~d",
2, make_string(fn), int2fx(rc) );
}
const char *os_getenv( const char *key )
{
return NULL;
}
static char *make_dospath( char *temp, const char *path )
{
while (*path)
{
if (*path == '/')
*temp++ = '\\';
else
*temp++ = *path++;
}
return temp;
}
/* check to see if a file exists */
rs_bool os_file_exists_p( const char *path )
{
FILE *f;
char temp[1000];
f = fopen( make_dospath( temp, path ), "r" );
if (f)
{
fclose(f);
return YES;
}
else
return NO;
}
/* convert a unix-standard pathname to local OS format */
obj os_path( obj path )
{
char temp[1000];
return make_string( make_dospath( temp, string_text(path) ) );
}
/* open a file using unix-std pathnames */
FILE *os_fopen( const char *path, const char *mode )
{
char temp[1000];
return fopen( make_dospath( temp, path ), mode );
}
UINT_32 os_sleep( UINT_32 msec )
{
unsigned t = (msec + 500) / 1000;
sleep( t );
return t * 1000;
}
void init_os( void )
{
the_sig_queue.num_sig = 0;
the_sig_queue.enable = YES;
the_sig_queue.ready = &rssig_ready;
}
static obj cis( const char *str, obj rest )
{
return cons( intern( make_string(str) ), rest );
}
obj os_type( void )
{
return cis( "dos", NIL_OBJ );
}
obj os_getwd( void )
{
scheme_error( "os_getwd: not implemented", 0 );
}
void os_setwd( const char *path )
{
scheme_error( "os_setwd: not implemented", 0 );
}
#define BEGIN_CRITICAL() do { /* what to do..? */
#define END_CRITICAL() } while (0)
static obj sig_flush( struct sig_queue *q )
{
int siginfo;
obj lst = NIL_OBJ;
if (q->num_sig)
{
unsigned n;
BEGIN_CRITICAL();
n = q->num_sig;
if (n > MAX_SIG)
{
lst = cons( lookup_symbol( "signal-queue-overflow" ), lst );
n = MAX_SIG;
}
while (n > 0)
{
lst = cons( int2fx( q->sig_queue[--n] ), lst );
}
q->num_sig = 0;
*(q->ready) = NO;
END_CRITICAL();
}
return lst;
}
obj os_flush_sig_queue( void )
{
return sig_flush( &the_sig_queue );
}
static void sig_add( struct sig_queue *q, int id )
{
BEGIN_CRITICAL();
if (q->num_sig >= MAX_SIG)
{
q->sig_queue[q->num_sig] = id;
}
else
{
fprintf( stderr, "\ninterrupts not being handled in a timely manner\n" );
fprintf( stderr, "** aborting scheme process **\n" );
abort();
}
q->num_sig++;
if (q->enable)
*q->ready = YES;
END_CRITICAL();
}
void os_enqueue_sig( int id )
{
sig_add( &the_sig_queue, id );
}
rs_bool os_set_sigenable( rs_bool flag )
{
rs_bool old;
BEGIN_CRITICAL();
old = the_sig_queue.enable;
the_sig_queue.enable = flag;
if (flag)
{
if (the_sig_queue.num_sig)
*the_sig_queue.ready = YES;
}
else
{
*the_sig_queue.ready = NO;
}
END_CRITICAL();
return old;
}
/* the NOT-real-time timer... */
UINT_32 system_timeout;
UINT_32 os_halt_timer( void )
{
UINT_32 ms;
ms = system_timeout / 128;
system_timeout = 0;
if (ms == 0)
{
unsigned i;
rs_bool qd = NO;
/* make sure it's been queued */
for (i=0; i<the_sig_queue.num_sig; i++)
if (the_sig_queue.sig_queue[i] == RSSIG_TIMEOUT)
{
qd = YES;
break;
}
if (!qd)
os_enqueue_sig( RSSIG_TIMEOUT );
}
return ms;
}
void os_set_timer( UINT_32 msec )
{
system_timeout = msec * 128;
}
UINT_32 os_get_time_remaining( void )
{
return system_timeout / 128;
}
|