-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQLtraps.c
297 lines (245 loc) · 5.84 KB
/
QLtraps.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* (c) UQLX - see COPYRIGHT
*/
#include "QL68000.h"
#include <string.h>
#include "QL.h"
#include "QDOS.h"
#include "QSerial.h"
#include "QInstAddr.h"
#include "boot.h"
#include "QDOS.h"
#include "qx_proto.h"
/*extern int schedCount;*/
extern int HasPTR;
/* external debugging aid */
/* replaced by gdb's "qldbg" command */
#if 0
void qldbg(void)
{
exception=32+14;
extraFlag=true;
nInst2=nInst;
nInst=0;
}
#endif
#if 0
void trap0(void) /* go supervisor */
{ if(!supervisor)
{ supervisor=true;
gUSP=(*sp);
(*sp)=gSSP;
}
}
#else
void trap0(void)
{
exception=32+(code&15);
extraFlag=true;
nInst2=nInst;
nInst=0;
}
#endif
void trap1(void)
{ short op;
op=(short)(*reg)&0x7f;
/* if ((op>3 && op<6) || (op>7 && op<0xc))*/
DECR_SC(); /*schedCount--;*/
if(op>=0x11 && op<=0x15) /* Gestione dell'hardware */
{ switch(op){
#if 0
case 0x10: /* Set or read display mode */
SetDisplayMode();
break;
#endif
case 0x11: /* IPC command */
*reg=0; /**//* neu, .hpr 21.5.99 */
if(!IPC_Command()) goto doTrap;
/* *reg=0; *//**//* raus, .hpr 21.5.99 */
break;
case 0x12: /* set baud rate */
*reg=SetBaudRate((short)reg[1])? 0:-15;
break;
case 0x15: /* adjust clock */
if(!reg[1]) break;
qlClock=(uw32)reg[1];
/*printf("aclk: qlClock set to %ld\n",qlClock);*/
case 0x13: /* read clock */
GetDateTime((uw32*)(reg+1));
/*reg[1]=(w32)((uw32)reg[1]-qlClock);*/
*reg=0;
prep_rtc_emu();
break;
case 0x14: /* set clock */
{
w32 i;
GetDateTime(&i);
qlClock-=i-(uw32)reg[1];
/*printf("sclk: qlClock set to %ld\n",qlClock);*/
*reg=0;
break;
}
}
}
else
{
#if 0
if (reg[0]==-26)
{
/* =============================== */
/* TRAP #1 D0.L=-26 (-$1A) */
/* =============================== */
reg[0]=0;
/* IN: */
/* D1.L opcode */
/* OUT: */
/* D0.L QDOS error code (QDOS systems return -15, as the trap is not defined) */
/* D4-D7/A3-A7 preserved */
/* All other registers: depends on the opcode in D1.L. */
/* Currently there are three opcodes defined: */
switch(reg[1])
{
/* D1.L=0 Get extended trap info */
/* ============================== */
/* IN: no input */
/* OUT: */
/* D0.L=0 (-15 in systems without the trap#1 D0=-26) */
/* D1.L=version of this trap (currently version 0) */
/* D2.L=0 (reserved) */
/* All other registers are preserved */
case 0:
reg[1]=0;
reg[2]=0;
break;
/* This trap is provided for future compatibility. QL software can test for an */
/* emulator using the following opcode (D1.L=1). Version 0 (D1=0) means that */
/* the trap accepts three opcodes in D1.L: 0, 1 and 2. */
/* D1.L=1 Get emulator info */
/* ========================= */
/* IN: no input */
/* OUT: */
/* D0.L=0 (-15 in systems without the trap#1 D0=-26) */
/* D1.L=EMULATOR */
/* D2.L=VERSION */
/* D3.L=VERSION TYPE */
/* All other registers are preserved */
case 1:
/* EMULATOR long word format: */
/* $aabbccdd, where... */
/* dd=emulator type (0=QDOS system (no one at the moment with this trap defined) */
/* 1=Q-emuLator */
/* 2=UQLX */
/* 3=QLAY) */
/* cc=reserved (0) */
/* bb=host platform (0=Win95, 1=DOS, 2=UNIX, 3=Mac) */
/* aa=sub-platform code (for example the UNIX dialect, to be defined if needed) */
/* Example: D1.L=$00030001 means 'Q-emuLator running on Mac' */
reg[1]=0x03020002;
/* VERSION long word format: */
/* $aabbccdd, where... */
/* aa=version major number */
/* bb=version minor number */
/* cc=version minor sub-number */
/* dd=release */
/* The release field is a counter to differentiate releases of the same */
/* version. The release counter is NOT reset when going from alpha to beta or */
/* from beta to a final version. In this way greater version long words always */
/* mean more recent versions. The release counter is reset to 1 for each new */
/* version. */
/* Example: D2.L=$01000308 means 'version 1.0.3, eighth release' */
reg[2]=0x0;
/* VERSION TYPE is 0 for ALPHA, 1 for BETA and 2 for FINAL */
reg[3]=0;
break;
/* D1.L=2 Get emulator name */
/* ========================= */
/* In: */
/* A1=pointer to buffer */
/* D2.L= buffer len */
/* Out: */
/* the buffer pointed by A1 is filled with a short QL string describing the */
/* emulator type and version (for example 'Q-emuLator 1.0.3'). */
/* If the buffer is too small, the string is truncated to the buffer's length */
/* and the function returns the error BUFFER FULL. */
case 2:
strncpy(reg[1]+(Ptr)theROM,release,reg[2]);
if (strlen(release)>reg[2])
reg[0]=QERR_BF;
break;
default:
reg[0]=QERR_BP;
}
return;
}
else
#endif
{
doTrap: exception=33;
extraFlag=true;
nInst2=nInst;
nInst=0;
}
}
}
void trap2(void)
{
DECR_SC();/*schedCount--;*/
// if (reg[0] == 1 )
// printf("trap2: %s\n",aReg[0]+(char*)theROM+2);
exception=34;
extraFlag=true;
nInst2=nInst;
nInst=0;
}
void trap3(void)
{
DECR_SC();/*schedCount--;*/
#ifdef XSCREEN
if (!HasPTR && *reg==0x70)
XPatchPTRENV();
#endif
exception=35;
extraFlag=true;
nInst2=nInst;
nInst=0;
}
extern int script_read_enable;
#ifdef AUTO_BOOT
void btrap3(void)
{
DECR_SC();
if (((w8)reg[0])==1)
{
/*printf("btrap3: a0=%x\n",aReg[0]);*/
*((char*)reg+4+RBO)= BOOT_SELECT;
reg[0]=0;
table[code]=trap3;
script_read_enable=1;
}
else trap3();
}
#endif
#if 0
void trap4(void)
{ w32 a;
a=ReadLong(ReadLong(0x28064))+0x16;
WriteByte(a,ReadByte(a)|0x80);
}
#endif
#if 1
void FastStartup(void)
{
if((Ptr)gPC-(Ptr)theROM-2!=RL(&theROM[1]))
{
exception=4;
extraFlag=true;
nInst2=nInst;
nInst=0;
return;
}
memset((Ptr)theROM+131072l,0,RTOP-131072l);
while(RL((w32*)gPC)!=0x28000l) gPC++;
gPC-=4;
aReg[5]=RTOP;
}
#endif