-
Notifications
You must be signed in to change notification settings - Fork 5
/
gemcall.c
249 lines (194 loc) · 4.2 KB
/
gemcall.c
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
/*
* LEVEE, or Captain Video; A vi clone
*
* Copyright (c) 1982-2007 David L Parsons
* All rights reserved.
*
* Redistribution and use in source and binary forms, without or
* without modification, are permitted provided that the above
* copyright notice and this paragraph are duplicated in all such
* forms and that any documentation, advertising materials, and
* other materials related to such distribution and use acknowledge
* that the software was developed by David L Parsons (orc@pell.portland.or.us).
* My name may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/*
* Gemdos (Atari ST) bindings for levee (Alcyon/Sozobon C)
*/
#include "levee.h"
#include "externs.h"
#if OS_ATARI
#include <stdio.h>
#include <atari\osbind.h>
long _STKSIZ = 4096;
long _BLKSIZ = 4096;
extern long gemdos();
FILEDESC
OPEN_OLD(char *file)
{
int fd = gemdos(0x3d,file,/*open mode*/0);
return (fd < 0) ? NOWAY : (FILEDESC)fd;
}
FILEDESC
OPEN_NEW(char *file)
{
int fd = gemdos(0x3c,n,/*permissions*/0);
return (fd < 0) ? NOWAY : (FILEDESC)fd;
}
int
CLOSE_FILE(FILEDESC f)
{
return gemdos(0x3e,(int)f);
}
long
SEEK_POSITION(FILEDESC f, long offset, int mode)
{
return gemdos(0x42,offset,(int)f, mode);
}
int
READ_TEXT(FILEDESC f, void *buffer, int size)
{
return gemdos(0x3f,(int)f,(long)(size),buffer);
}
int
WRITE_TEXT(FILEDESC f, void *buffer,int size)
{
return gemdos(0x40,(int)f,(long)(size),buffer);
}
os_write(s,len)
char *s;
{
return 0;
}
os_initialize()
{
TERMNAME = "Atari ST";
HO = "\033H",
UP = "\033A",
CE = "\033K",
CL = "\033E",
OL = "\033L",
BELL = "\007",
CM = "\033Y??",
UpS = "\033I",
CURoff= "\033f",
CURon = "\033e";
SO = "\033p";
SE = "\033q";
canUPSCROLL = TRUE;
canOL = TRUE;
CA = TRUE;
Erasechar = '\b'; /* ^H */
Eraseline = 21; /* ^U */
return 1;
}
os_cursor(visible)
{
if ( visible ) {
/* turn the cursor on */
asm(" clr.w -(sp) ");
asm(" move.w #1,-(sp) ");
asm(" move.w #21,-(sp) ");
asm(" trap #14 ");
asm(" addq.l #6,sp ");
}
else {
/* turn the cursor off */
asm(" clr.l -(sp) ");
asm(" move.w #21,-(sp) ");
asm(" trap #14 ");
asm(" addq.l #6,sp ");
}
}
os_mktemp(dest, size template)
char *dest;
char *template;
{
char *p;
static char Xes[] = ".XXXXXX";
int required = sizeof(Xes) + strlen(template) + 1;
if (p=getenv("_TMP")) {
unless ( size > strlen(p) + required + 1 ) {
errno = E2BIG;
return 0;
}
strcpy(dest, p);
lastchar = dest[strlen(dest)-1];
if ( lastchar != '\\' && lastchar != ':' )
strcat(dest, "\\");
}
else {
unless (size > required) {
errno = E2BIG;
return 0;
}
s[0] = 0;
}
#if USING_STDIO
sprintf(dest+strlen(dest), "%s%s", template, Xes);
return mktemp(dest) != 0;
#else
strcat(s, template);
strcat(s, ntoa(getpid()));
return 1;
#endif
}
#if ATARI_SOUND
static char sound[] = {
0xA8,0x01,0xA9,0x01,0xAA,0x01,0x00,
0xF8,0x10,0x10,0x10,0x00,0x20,0x03
};
#define SADDR 0xFF8800L
typedef char srdef[4];
static srdef *SOUND = (srdef *)SADDR;
/* Make the Atari ST bell sound by stuffing a chord into the sound chip
*/
static void
ping()
{
register i;
for (i=0; i<sizeof(sound); i++) {
(*SOUND)[0] = i;
(*SOUND)[2] = sound[i];
}
}
#endif
int
os_Beep()
{
#if ATARI_SOUND
Supexec(ping);
return 1;
#else
return 0;
#endif
}
int
cclass(c)
unsigned int c;
{
if (c == '\t' && !list)
return CC_TAB;
if (c == 127 || c < 32 )
return CC_CTRL;
return CC_PRINT;
}
unsigned
getKey()
/* get input from the keyboard. All odd keys (function keys, et al) that
* do not produce a character have their scancode orred with $80 and returned.
*/
{
unsigned c;
long key;
c = (key = Crawcin()) & 0xff;
unless (c)
c = (((unsigned)(key>>16))|0x80) & 0xff;
return c;
} /* getKey */
#endif /*OS_ATARI*/