-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.c
379 lines (312 loc) · 9.27 KB
/
init.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/* Unusual Suspects
Main program initialization */
#include "includes.prl"
#include "common.h"
#include "protos.h"
/***** Static function declarations *****/
static void init_conerr(UBYTE *str);
/***** External variables *****/
/* Library pointers */
extern struct ExecBase *SysBase;
extern struct DosLibrary *DOSBase;
struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;
// struct Library *DiskfontBase;
struct Library *PTReplayBase;
PLANEPTR theRaster;
struct RastPort theRP;
struct RastPort theRP_5bpl;
struct RastPort theRP_4bpl;
struct RastPort theRP_3bpl;
struct RastPort theRP_2bpl;
struct RastPort theRP_1bpl;
struct BitMap theBitMap;
struct BitMap theBitMap_5bpl;
struct BitMap theBitMap_4bpl;
struct BitMap theBitMap_3bpl;
struct BitMap theBitMap_2bpl;
struct BitMap theBitMap_1bpl;
struct NewScreen theScreenEHB =
{
0, 0, 320, SCR_HEIGHT, 6, 0, 1, 0 | EXTRA_HALFBRITE,
CUSTOMSCREEN | CUSTOMBITMAP | SCREENQUIET, NULL, NULL, NULL, &theBitMap
};
struct NewScreen theScreen32 =
{
0, 0, 320, SCR_HEIGHT, 5, 0, 1, 0,
CUSTOMSCREEN | CUSTOMBITMAP | SCREENQUIET, NULL, NULL, NULL, &theBitMap
};
struct NewScreen theScreen16 =
{
0, 0, 320, SCR_HEIGHT, 4, 0, 1, 0,
CUSTOMSCREEN | CUSTOMBITMAP | SCREENQUIET, NULL, NULL, NULL, &theBitMap
};
int current_screen_depth = 0,
prev_screen_depth = 0;
struct Screen *mainScreen;
struct ViewPort *mainVP;
// struct TextFont *writerFont;
// struct TextAttr writerAttr =
// { (STRPTR)"futuraB.font", 32, 0, 0 };
/***** Global functions *****/
/* Open all needed global resources */
BOOL init_open_libs(void)
{
printf("init_open_libs()\n");
/* Check for at least release 3.0 */
if (SysBase->LibNode.lib_Version < 33)
{
init_conerr((UBYTE *)"This program requires Amiga Kickstart Release 1.2+\n");
return (FALSE);
}
/* Open needed libraries */
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary((UBYTE *)"intuition.library", _LIB_VERSION)))
{
init_conerr((UBYTE *)"Unable to open intuition.library version 33\n");
return (FALSE);
}
if (!(GfxBase = (struct GfxBase *)
OpenLibrary((UBYTE *)"graphics.library", _LIB_VERSION)))
{
init_conerr((UBYTE *)"Unable to open graphics.library version 33\n");
return (FALSE);
}
// if (!(DiskfontBase = OpenLibrary((UBYTE *)"diskfont.library", _LIB_VERSION)))
// {
// init_conerr((UBYTE *)"Unable to open diskfont.library version 33\n");
// return (FALSE);
// }
if (SysBase->LibNode.lib_Version >= 36)
if (!AssignPath("Libs","Libs"))
init_conerr((UBYTE *)"Failed to Assign the local Libs drawer. Please copy ptreplay.library into your Libs: drawer.\n");
if (!(PTReplayBase = OpenLibrary((UBYTE *)"ptreplay.library", 0)))
{
init_conerr((UBYTE *)"Unable to open ptreplay.library\n");
return (FALSE);
}
// return (FALSE);
return (TRUE);
}
BOOL Init16ColorsScreen(void)
{
PLANEPTR temp;
UWORD i;
struct Screen *tmp_mainScreen = NULL;
PLANEPTR tmp_theRaster = NULL;
printf("Init16ColorsScreen()\n");
if (mainScreen) tmp_mainScreen = mainScreen;
if (theRaster) tmp_theRaster = theRaster;
InitBitMap(&theBitMap, 4, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_3bpl, 3, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_2bpl, 2, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_1bpl, 1, 384, SCR_HEIGHT);
if (!(theRaster = AllocRaster(384 * 4, SCR_HEIGHT)))
{
init_conerr((UBYTE *)"Unable to allocate screen memory\n");
return (FALSE);
}
temp = theRaster;
for (i = 0; i < 4; i ++)
{
theBitMap.Planes[i] = temp;
theBitMap_3bpl.Planes[i] = temp;
theBitMap_2bpl.Planes[i] = temp;
theBitMap_1bpl.Planes[i] = temp;
temp += (48 * SCR_HEIGHT);
}
InitRastPort(&theRP);
InitRastPort(&theRP_3bpl);
InitRastPort(&theRP_2bpl);
InitRastPort(&theRP_1bpl);
theRP.BitMap = &theBitMap;
theRP_3bpl.BitMap = &theBitMap_3bpl;
theRP_2bpl.BitMap = &theBitMap_2bpl;
theRP_1bpl.BitMap = &theBitMap_1bpl;
SetRast(&theRP, 0);
if (!(mainScreen = OpenScreen(&theScreen16)))
{
init_conerr((UBYTE *)"Unable to open main screen\n");
return (FALSE);
}
mainVP = &mainScreen->ViewPort;
for (i = 0; i < 16; i ++)
SetRGB4(&mainScreen->ViewPort, i, 0, 0, 0);
prev_screen_depth = current_screen_depth;
current_screen_depth = 4;
/* Close screen */
if (tmp_mainScreen)
{
CloseScreen(tmp_mainScreen);
tmp_mainScreen = NULL;
}
if (tmp_theRaster)
{
FreeRaster(tmp_theRaster, prev_screen_depth * 384, SCR_HEIGHT);
tmp_theRaster = NULL;
}
return (TRUE);
}
BOOL Init32ColorsScreen(void)
{
PLANEPTR temp;
UWORD i;
struct Screen *tmp_mainScreen = NULL;
PLANEPTR tmp_theRaster = NULL;
printf("Init32ColorsScreen()\n");
if (mainScreen) tmp_mainScreen = mainScreen;
if (theRaster) tmp_theRaster = theRaster;
InitBitMap(&theBitMap, 5, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_4bpl, 4, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_3bpl, 3, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_2bpl, 2, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_1bpl, 1, 384, SCR_HEIGHT);
if (!(theRaster = AllocRaster(384 * 5, SCR_HEIGHT)))
{
init_conerr((UBYTE *)"Unable to allocate screen memory\n");
return (FALSE);
}
temp = theRaster;
for (i = 0; i < 5; i ++)
{
theBitMap.Planes[i] = temp;
theBitMap_4bpl.Planes[i] = temp;
theBitMap_3bpl.Planes[i] = temp;
theBitMap_2bpl.Planes[i] = temp;
theBitMap_1bpl.Planes[i] = temp;
temp += (48 * SCR_HEIGHT);
}
InitRastPort(&theRP);
InitRastPort(&theRP_4bpl);
InitRastPort(&theRP_3bpl);
InitRastPort(&theRP_2bpl);
InitRastPort(&theRP_1bpl);
theRP.BitMap = &theBitMap;
theRP_4bpl.BitMap = &theBitMap_4bpl;
theRP_3bpl.BitMap = &theBitMap_3bpl;
theRP_2bpl.BitMap = &theBitMap_2bpl;
theRP_1bpl.BitMap = &theBitMap_1bpl;
SetRast(&theRP, 0);
if (!(mainScreen = OpenScreen(&theScreen32)))
{
init_conerr((UBYTE *)"Unable to open main screen\n");
return (FALSE);
}
mainVP = &mainScreen->ViewPort;
for (i = 0; i < 32; i ++)
SetRGB4(&mainScreen->ViewPort, i, 0, 0, 0);
prev_screen_depth = current_screen_depth;
current_screen_depth = 5;
/* Close screen */
if (tmp_mainScreen)
{
CloseScreen(tmp_mainScreen);
tmp_mainScreen = NULL;
}
if (tmp_theRaster)
{
FreeRaster(tmp_theRaster, prev_screen_depth * 384, SCR_HEIGHT);
tmp_theRaster = NULL;
}
return (TRUE);
}
BOOL InitEHBScreen(void)
{
PLANEPTR temp;
UWORD i;
struct Screen *tmp_mainScreen = NULL;
PLANEPTR tmp_theRaster = NULL;
if (mainScreen) tmp_mainScreen = mainScreen;
if (theRaster) tmp_theRaster = theRaster;
printf("InitEHBScreen()\n");
InitBitMap(&theBitMap, 6, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_5bpl, 5, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_4bpl, 4, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_3bpl, 3, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_2bpl, 2, 384, SCR_HEIGHT);
InitBitMap(&theBitMap_1bpl, 1, 384, SCR_HEIGHT);
if (!(theRaster = AllocRaster(384 * 6, SCR_HEIGHT)))
{
init_conerr((UBYTE *)"Unable to allocate screen memory\n");
return (FALSE);
}
temp = theRaster;
for (i = 0; i < 6; i ++)
{
theBitMap.Planes[i] = temp;
theBitMap_5bpl.Planes[i] = temp;
theBitMap_4bpl.Planes[i] = temp;
theBitMap_3bpl.Planes[i] = temp;
theBitMap_2bpl.Planes[i] = temp;
theBitMap_1bpl.Planes[i] = temp;
temp += (48 * SCR_HEIGHT);
}
InitRastPort(&theRP);
InitRastPort(&theRP_5bpl);
InitRastPort(&theRP_4bpl);
InitRastPort(&theRP_3bpl);
InitRastPort(&theRP_2bpl);
InitRastPort(&theRP_1bpl);
theRP.BitMap = &theBitMap;
theRP_5bpl.BitMap = &theBitMap_5bpl;
theRP_4bpl.BitMap = &theBitMap_4bpl;
theRP_3bpl.BitMap = &theBitMap_3bpl;
theRP_2bpl.BitMap = &theBitMap_2bpl;
theRP_1bpl.BitMap = &theBitMap_1bpl;
SetRast(&theRP, 0);
if (!(mainScreen = OpenScreen(&theScreenEHB)))
{
init_conerr((UBYTE *)"Unable to open main screen\n");
return (FALSE);
}
mainVP = &mainScreen->ViewPort;
for (i = 0; i < 32; i ++)
SetRGB4(&mainScreen->ViewPort, i, 0, 0, 0);
prev_screen_depth = current_screen_depth;
current_screen_depth = 6;
/* Close previous screen */
if (tmp_mainScreen)
{
CloseScreen(tmp_mainScreen);
tmp_mainScreen = NULL;
}
if (tmp_theRaster)
{
FreeRaster(tmp_theRaster, prev_screen_depth * 384, SCR_HEIGHT);
tmp_theRaster = NULL;
}
return (TRUE);
}
void init_close_video(void)
{
printf("init_close_video()\n");
if (mainScreen) CloseScreen(mainScreen);
if (theRaster) FreeRaster(theRaster, current_screen_depth * 384, SCR_HEIGHT);
}
/* Close all global resources opened */
void init_close_libs(void)
{
printf("init_close_libs()\n");
/* Close opened libraries */
if (PTReplayBase) CloseLibrary(PTReplayBase);
// if (DiskfontBase) CloseLibrary(DiskfontBase);
if (GfxBase) CloseLibrary((struct Library *)GfxBase);
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
}
/***** Static functions *****/
/* Display an error message in a small console window */
static void init_conerr(UBYTE *str)
{
BPTR fileHandle; /* Console window filehandle */
printf("init_conerr()\n");
/* Open small console window */
if (!(fileHandle = Open((UBYTE *)"CON:50/50/500/100/Picnic Editor error",
MODE_OLDFILE)))
return;
/* Write message in window */
Write(fileHandle, str, strlen((char *)str));
/* Wait for 3 seconds */
Delay(150);
/* Close window */
Close(fileHandle);
}