summaryrefslogtreecommitdiff
path: root/Bobi.c
blob: 63732bea52ec120b6f0f240193b4caeace8b62cd (plain)
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
**  Bobi - The Ultimate Amiga Bob Manipulator
**
**  Bobi.c - Hautprogramm
**
**  COPYRIGHT (C) 1989-1993 BY CHRISTIAN A. WEBER, ZUERICH, SWITZERLAND.
**  ALL RIGHTS RESERVED. NO PART OF THIS SOFTWARE MAY BE COPIED, REPRODUCED,
**  OR TRANSMITTED IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN
**  PERMISSION OF THE AUTHOR. NO WARRANTY. USE AT YOUR OWN RISK.
**
**  Modification History
**  --------------------
**
**  05-Mar-89  CHW   V2.01   Project started
**  11-Jun-89  CHW   V2.15   InsertBobs added
**  15-Jun-89  CHW   V2.16   SaveOffsets() added
**  25-Jun-89  CHW   V2.20   An ch.lib angepasst
**  04-Jul-89  CHW   V2.22   Generate Code Window versch?nert
**  07-Jul-89  CHW   V2.24   AutoResizeBob() implementiert
**  26-Jul-89  CHW   V2.30   Sprites, neues BobData-Format etc.
**  05-Nov-89  CHW   V2.36   bod_Flags implementiert, Lattice 5.04
**  07-Nov-89  CHW   V2.37   CollisionRects gr?sser als Bob m?glich
**  12-Nov-89  CHW   V2.38   Generiert EQU-Headerfile f?r RawData
**  17-Nov-89  CHW   V2.39   Default-Pfade werden aus '.bobi' gelesen
**  23-Nov-89  CHW   V2.40   Aufger?umt, Bobsize nicht mehr begrenzt,
**                           SetMainOrg() implementiert, 2 bugs fixed
**  30-Nov-89  CHW   V2.42   About() verbessert, Collision auto on
**  03-Dec-89  CHW   V2.43   Zoom funktioniert jetzt mit Clipping
**  14-Dec-89  CHW   V2.44   LayerMode- & CustomBitmap-Bug fixed
**  20-Jan-90  CHW   V2.99   ToolWindow implemented, LevelEd support added
**  04-Mar-90  CHW   V2.99c  DecodeAnim benutzt iff.library
**  09-Mar-90  CHW   V2.99d  Save Sprite OK f?r width < 16
**  03-Apr-90  CHW   V2.99e  Pfad bleibt erhalten (f?r CHH)
**  17-Jul-90  CHW   V2.99f  Default-Font definiert, Screen-Width var.
**  12-Feb-91  CHW   V2.99i  Bei Sprites wird auch eine BobData-
**                           Struktur definiert
**  18-Feb-92  CHW   V2.99j  Ich kann's wieder compilieren :-)
**  12-Apr-92  CHW   V2.99m  Picture-Screen scrollt unter 2.0
**  12-Apr-92  CHW   V2.99n  BitMap<->ByteMap k?nnen auch <5 Planes,
**                           deshalb haben Bobs jetzt nicht immer >=5 Pl.
**  20-May-92  CHW   V2.99o  GenerateCode-ARexx-Befehl eingebaut
**  06-Jun-92  CHW   V2.99p  Default-Org funktioniert jetzt
**  11-Jul-92  CHW   V2.99q  Main-Screen ist jetzt Halfbrite
**  02-Nov-93  CHW   V3.0    Compiliert mit sc6, ASL-Filerequester
**  13-Jun-20  CHW   V3.1    Kann beim Startup Bob-File laden (CLI+WB)
*/

#include <proto/exec.h>
#include <exec/libraries.h>
#include <proto/graphics.h>
#include <graphics/gfxbase.h>
#include <proto/intuition.h>
#include <intuition/intuitionbase.h>
#include <proto/dos.h>
#include <workbench/startup.h>

#include <string.h>
#include <libraries/iff.h>

#include "Bobi_rev.h"
#include "Bobi.h"
#include "BobStructure.h"
#include "MainWindow.h"

extern void exit(LONG);
extern void HandleImsg(struct IntuiMessage *, struct Menu *);

#define ns NewScreenStructure

extern struct Process *ProcessBase;		/* Zeiger auf unseren Prozess, siehe Startup.o */

struct Library *MathBase, *MathTransBase;


/****************************************************************************
**	Globale Variable
*/

struct Library	*AslBase, *IFFBase;

struct Screen	*mainscreen;
struct Window	*mainwindow, *toolwindow;
struct RastPort	*mainrastport, *toolrastport;

struct Screen	*picturescreen;
struct Window	*picturewindow;

struct MyBob	*BobTable[MAXNUMBOBS+3];

char idstring_versiontag[7] = { '\0', '$', 'V', 'E', 'R', ':', ' ' };
char idstring[] = VERS " (" DATE ")";		/* Wird ?berall verwendet */


WORD options;				/* Globale Optionen, siehe GO_ Bobi.h */
BYTE defaultorg;			/* 0=OL, 1=OM, 2=OR, 3=ML, 4=M, 5=MR, usw. */
WORD numbobs;				/* Momentane Anzahl benutzte Bobs */
WORD actbobnum;				/* Nummer des aktuellen Bobs */

UWORD mainpalette[64];		/* Palette des Bobi-Screens */
UWORD picturepalette[64];	/* Palette des geladenen Bildes */

char outputname[80];		/* Name des zu generierenden Files */
char sectionname[80];		/* Name der Section des zu generierenden Files */
WORD outputflags;			/* Sprache und so */

WORD mainwidth,mainheight;	/* Ausmasse des Screens */
WORD mainx0,mainy0;			/* Globaler Nullpunkt der Bobs */

WORD firstanimbob,lastanimbob,animspeed,animflags;

struct TextAttr MyScreenTextAttr =
{
	(STRPTR)"topaz.font", TOPAZ_EIGHTY, 0, 0
};

ULONG rexxsigmask;			/* ARexx Signal Bit Maske */


/****************************************************************************
**	L?scht alle Bobs
*/

void ClearAll()
{
	register long i;

	for(i=0; i<numbobs; ++i)
	{
		FreeBob(BobTable[i]);
		BobTable[i]=0;
	}
	numbobs   = 0;
	actbobnum = 0;
	SetGlobalOptions(GOF_LAYERMODE|GOF_BOBBORDERS|GOF_COLLISIONRECT,7);
	outputflags = 0;
	if(mainwindow) RefreshBobNum();

	firstanimbob=lastanimbob=animspeed=0;
	SetAnimFlags(AF_FORWARD);

	strcpy(outputname,"RAM:TestBobs.S");
	strcpy(sectionname,"BobData");
	strcpy(LabelGadgetSIBuff,"Bob%ld");
	if(!picturescreen)
	{
		CopyMem(Palette,mainpalette,PaletteColorCount*2);
		if(mainscreen) LoadPalette(mainpalette);
	}
}	


/****************************************************************************
**	Alles freigeben und evtl. Programm verlassen
*/

void Cleanup(BOOL reallyquit)
{
	if(reallyquit)
	{
		CloseARexx();		/* Rexx-Stuff freigeben */
		ClearAll();			/* Alle Bobs freigeben */
	}

	CloseScreenFunc();					/* Geladenes Bild freigeben */

	if(toolwindow)
	{
		ToolNW.TopEdge=toolwindow->TopEdge;
		ClearMenuStrip(toolwindow);
		CloseWindow(toolwindow);
		toolwindow=0; toolrastport=0;
	}

	if(mainwindow)
	{
		ClearMenuStrip(mainwindow);
		ProcessBase->pr_WindowPtr=0;
		CloseWindow(mainwindow);
		mainwindow=0; mainrastport=0;
	}

	if(mainscreen)
	{
		CloseScreen(mainscreen);
		mainscreen = NULL;
	}

	if(reallyquit)
	{
		if(IFFBase)
		{
			CloseLibrary(IFFBase);
			IFFBase = NULL;
		}

		if (AslBase)
		{
			CloseLibrary(AslBase);
			AslBase = NULL;
		}

		if(MathTransBase)
		{
			CloseLibrary(MathTransBase);
			MathTransBase = NULL;
		}

		if(MathBase)
		{
			CloseLibrary(MathBase);
			MathBase = NULL;
		}

		if(IntuitionBase)
		{
			CloseLibrary((struct Library *)IntuitionBase);
			IntuitionBase = NULL;
		}

		if(GfxBase)
		{
			CloseLibrary((struct Library *)GfxBase);
			GfxBase = NULL;
		}
		exit(0);
	}
}


/****************************************************************************
**	Fehlertext ausgeben und Programm verlassen
*/

void Fail(char *reason)
{
	char buf[200];
	sprintf(buf,"%s:\n%s\nPlease consult your manual.",idstring,reason);
	ShowRequest(buf,0,"OKAY",0x8000);
	Cleanup(TRUE);
}


/****************************************************************************
**	Gerufen bei Control-C-Signal
*/

void __stdargs __saveds _abort(void)
{
	if(CloseARexx())	/* D?rfen wir Quit machen ? */
	{
		Fail("*** BREAK  -  Bobi aborted.");
	}
}


/****************************************************************************
**	Screen und Window ?ffnen
*/

void OpenMain()
{
	ns.Width  = GfxBase->NormalDisplayColumns>>1;	/* /2 weil Lo-Res */
	ns.Height = STDSCREENHEIGHT;
	ns.Font   = &MyScreenTextAttr;
	ns.DefaultTitle = idstring;

	if(!(mainscreen = OpenScreen(&ns)))
	{
		Fail("Can't open screen");
	}
	LoadPalette(Palette);

	MainNW.Screen = mainscreen;
	MainNW.Width  = mainwidth  = mainscreen->Width;
	MainNW.Height = mainheight = mainscreen->Height;
	if(!(mainwindow = OpenWindow(&MainNW)))
	{
		Fail("Can't open window");
	}
	ProcessBase->pr_WindowPtr = (APTR)mainwindow;
	mainrastport = mainwindow->RPort;
	DrawRect(mainrastport,mainwidth-26,23,mainwidth-1,mainheight-13,1);

	ToolWindowFunc();		/* ToolWindow ?ffnen falls enabled */
}


/****************************************************************************
**	Hauptprogramm
*/

LONG Main(LONG arglen, char *argline)
{
	struct WBStartup *startup = (struct WBStartup *)argline;
	char filename[200] = "\0";	/* File beim Start laden? */

	LONG mainidcmpflags = MainNW.IDCMPFlags;
	LONG toolidcmpflags = ToolNW.IDCMPFlags;

	ToolNW.TopEdge=10000;	/* ToolWindow ganz unten */

	if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L)))
		return 0;

	if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L)))
		return 0;

	if(!(AslBase = OpenLibrary("asl.library", 0L)))
		Fail("Can't open asl.library");

	if(!(IFFBase = OpenLibrary(IFFNAME,0L)))
		Fail("Can't open iff.library");

	if(!(MathBase = OpenLibrary("mathffp.library",0L)))
		Fail("Can't open mathffp.library");

	if(!(MathTransBase = OpenLibrary("mathtrans.library",0L)))
		Fail("Can't open mathtrans.library");

	if(IFFBase->lib_Version < IFFVERSION)
		Fail("Your iff.library is too old");

	rexxsigmask=InitARexx();

	LoadConfigFile(".bobi");
	ClearAll();
	mainx0=MAXX/2; mainy0=(MAXY*2)/3;

	OpenMain();


	/*
	**	Wenn ein Argument angegben wurde, Bobs laden
	*/
	if (arglen > 0)		/* Start vom CLI */
	{
		strncpy(filename, argline, arglen);
		filename[arglen-1] = '\0';
	}
	else if (startup->sm_NumArgs > 1)	/* Started with some arguments */
	{
		struct WBArg *arg = startup->sm_ArgList+1;

		if (arg->wa_Lock)
			CurrentDir(arg->wa_Lock);

		if (arg->wa_Name && *arg->wa_Name)
			strcpy(filename, arg->wa_Name);
	}

	if (*filename)
		LoadBobs(filename);


	/*
	**	Tada! Die Hauptschleife
	*/
	for(;;)
	{
		struct IntuiMessage msgcopy,*msg;

		SetMenuStrip(mainwindow,&MenuList1);
		if(toolwindow) SetMenuStrip(toolwindow,&MenuList1);
		actbobnum=ReadBobNum();
		ShowFrame(actbobnum);
		ModifyIDCMP(mainwindow,mainidcmpflags|MENUVERIFY);
		if(toolwindow) ModifyIDCMP(toolwindow,toolidcmpflags|MENUVERIFY);

		for(;;)
		{
			if(toolwindow && (mainwindow->Flags & WINDOWACTIVE))
				ActivateWindow(toolwindow);
			if(msg=(struct IntuiMessage *)GetMsg(mainwindow->UserPort)) break;
			if(toolwindow)
				if(msg=(struct IntuiMessage *)GetMsg(toolwindow->UserPort))
					break;

			if(toolwindow) Wait(SIGMASK(mainwindow)|SIGMASK(toolwindow)|rexxsigmask);
			else Wait(SIGMASK(mainwindow)|rexxsigmask);
			RexxMsgHandler();
		}

		CopyMem(msg,&msgcopy,sizeof(msgcopy));
		ReplyMsg((struct Message *)msg);
		if(msgcopy.Class == MENUVERIFY)
		{
			LoadPalette(Palette);					/* Default-Farben */
		}
		else
		{
			ModifyIDCMP(mainwindow,mainidcmpflags);		/* MENUVERIFY off */
			if(toolwindow) ModifyIDCMP(toolwindow,toolidcmpflags);
			GetGlobalOptions();						/* options updaten */
			HandleImsg(&msgcopy,&MenuList1);
		}
	}

	return 0;
}