add NDAStartUpTools / ShutDownTools.

This commit is contained in:
Kelvin Sherlock 2018-11-19 22:25:56 -05:00
parent 30799b1e96
commit b3ae3bc115
3 changed files with 332 additions and 134 deletions

View File

@ -6,7 +6,7 @@ COPYFORK = iix copyfork
LDFLAGS =
LDLIBS =
CFLAGS += $(DEFINES) -v #-O
OBJS = qserver.a macroman.a common.a config.a
OBJS = qserver.a macroman.a common.a config.a tools.a
qserver: $(OBJS) qserver.r
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
@ -19,6 +19,7 @@ config.a: config.c qserver.h
macroman.a: macroman.c macroman.h
qserver.a: qserver.c qserver.h
qserver.r: qserver.rez qserver.h
tools.a : tools.c
clean:
$(RM) *.a *.root *.r

155
qserver.c
View File

@ -25,6 +25,10 @@
#include "qserver.h"
unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef);
void NDAShutDownTools(StartStopRecord *ssRef);
Handle LoadQuote(word mID, Word rfile);
Word LoadConfig(Word MemID);
@ -42,17 +46,6 @@ WindowPtr MyWindow;
Boolean FlagTCP;
Boolean FlagQS;
Boolean FlagQDAux;
Boolean FlagFM;
Boolean FlagTE;
Boolean FlagSF;
Boolean FlagLoadTCP;
Handle HandleFM;
Handle HandleTE;
Handle HandleSF;
Word MyID;
Word MyRID;
Word Ipid;
@ -450,119 +443,21 @@ void DrawWindow(void)
DrawControls(GetPort());
}
// returns 1 on success, 0 on error.
Word LoadNDATools(Word MyID)
{
if (!QDAuxStatus() || _toolErr)
{
LoadOneTool(0x12,0);
if (!_toolErr) QDAuxStartUp();
if (_toolErr)
{
AlertWindow(awCString, NULL,
(Ref)"24~Unable to start QuickDraw Aux.~^Too Bad");
return 0;
}
FlagQDAux = true;
}
if (!FMStatus() || _toolErr)
{
Handle h;
LoadOneTool(0x1b, 0);
if (!_toolErr) HandleFM = NewHandle(0x0100, MyID, 0xc005, 0);
if (!_toolErr) FMStartUp(MyID, (Word)*HandleFM);
if (_toolErr)
{
if (HandleFM) DisposeHandle(HandleFM);
AlertWindow(awCString, NULL,
(Ref)"24~Unable to start Font Manager.~^Too Bad");
return 0;
}
FlagFM = true;
}
if (!TEStatus() || _toolErr)
{
LoadOneTool(0x22,0x0);
if (!_toolErr) HandleTE = NewHandle(0x0100, MyID, 0xc005, 0);
if (!_toolErr) TEStartUp(MyID, (Word)*HandleTE);
if (_toolErr)
{
if (HandleTE) DisposeHandle(HandleTE);
AlertWindow(awCString, NULL,
(Ref)"24~Unable to start Text Edit.~^Too Bad");
return 0;
}
FlagTE = true;
}
if (!SFStatus() || _toolErr)
{
LoadOneTool(0x17,0);
if (!_toolErr) HandleSF = NewHandle(0x0100, MyID, 0xc005, 0);
if (!_toolErr) SFStartUp(MyID, (Word)*HandleSF);
if (_toolErr)
{
if (HandleSF) DisposeHandle(HandleSF);
AlertWindow(awCString, NULL,
(Ref)"24~Unable to start Standard Filer.~^Too Bad");
return 0;
}
FlagSF = true;
}
if (!TCPIPStatus() || _toolErr)
{
LoadOneTool(0x36,0x0200);
if (!_toolErr) TCPIPStartUp();
if (_toolErr)
{
AlertWindow(awCString, NULL,
(Ref)"24~Unable to start Marinetti.~^Too Bad");
return 0;
}
FlagLoadTCP = true;
}
return 1;
}
void UnloadNDATools(void)
{
if (FlagLoadTCP && !TCPIPGetConnectStatus())
{
TCPIPShutDown();
UnloadOneTool(0x36);
}
if (FlagSF)
{
SFShutDown();
UnloadOneTool(0x17);
DisposeHandle(HandleSF);
}
if (FlagTE)
{
TEShutDown();
UnloadOneTool(0x22);
DisposeHandle(HandleTE);
}
if (FlagFM)
{
FMShutDown();
UnloadOneTool(0x1b);
DisposeHandle(HandleFM);
}
if (FlagQDAux)
{
QDAuxShutDown();
UnloadOneTool(0x12);
}
}
static StartStopRecord ss = {
0, 0, 0, 0,
4,
{
0x12, 0x0000, /* QD Aux */
0x17, 0x0000, /* Std File */
0x1b, 0x0000, /* Font Manager */
0x22, 0x0000, /* Text Edit */
0x36, 0x0300, /* TCP */
}
};
@ -571,7 +466,10 @@ GrafPortPtr NDAOpen(void)
Boolean ok = true;
const char *err = NULL;
if (!LoadNDATools(MyID)) return NULL;
if (NDAStartUpTools(MyID, &ss)) {
NDAShutDownTools(&ss);
return NULL;
}
LoadConfig(MyID);
@ -658,15 +556,6 @@ void NDAInit(Word code)
MyWindow = NULL;
FlagTCP = false;
FlagQS = false;
FlagQDAux = false;
FlagFM = false;
FlagTE = false;
FlagSF = false;
HandleFM = NULL;
HandleTE = NULL;
HandleSF = NULL;
FlagLoadTCP = false;
MyID = MMStartUp();
Ipid = 0;
@ -674,7 +563,7 @@ void NDAInit(Word code)
}
else
{
UnloadNDATools();
NDAShutDownTools(&ss);
}
}

308
tools.c Normal file
View File

@ -0,0 +1,308 @@
/* IIgs TN #53:
The greatest conflict between applications and desk accessories, especially NDAs, is the use of system tool sets. The Apple IIgs Toolbox Reference, Volume 1, defines the minimum collection of tools sets available to an NDA. The Desk Manager requires that an application start the following tool sets before calling DeskStartUp:
Tool Locator (#1)
Memory Manager (#2)
Miscellaneous Tools (#3)
QuickDraw II (#4)
Event Manager (#6)
Window Manager (#14)
Menu Manager (#15)
Control Manager (#16)
LineEdit (#20)
Dialog Manager (#21)
Scrap Manager (#22)
NDAs may assume that these tools are all present and running, so they do not need to check for their presence. NDAs can also use the following tool sets without special consideration for starting them up:
Desk Manager
Scheduler
Apple Desktop Bus
Integer Math.
*/
#pragma lint -1
#pragma noroot
#pragma optimize -1
#include <locator.h>
#include <memory.h>
#include <intmath.h>
extern pascal void ListStartUp(void) inline(0x021C,dispatcher);
extern pascal void ListShutDown(void) inline(0x031C,dispatcher);
extern pascal Word ListVersion(void) inline(0x041C,dispatcher);
extern pascal Boolean ListStatus(void) inline(0x061C,dispatcher);
extern pascal void TCPIPStartUp (void) inline(0x0236,dispatcher);
extern pascal void TCPIPShutDown (void) inline(0x0336,dispatcher);
extern pascal Word TCPIPVersion (void) inline(0x0436,dispatcher);
extern pascal Boolean TCPIPStatus (void) inline(0x0636,dispatcher);
extern pascal Long TCPIPLongVersion (void) inline(0x0836,dispatcher);
extern pascal Boolean TCPIPGetConnectStatus (void) inline(0x0936,dispatcher);
extern pascal void SANEStartUp(Word) inline(0x020A,dispatcher);
extern pascal void SANEShutDown(void) inline(0x030A,dispatcher);
extern pascal Word SANEVersion(void) inline(0x040A,dispatcher);
extern pascal Word SANEStatus(void) inline(0x060A,dispatcher);
extern pascal void TEStartUp(Word, Word) inline(0x0222,dispatcher);
extern pascal void TEShutDown(void) inline(0x0322,dispatcher);
extern pascal Word TEVersion(void) inline(0x0422,dispatcher);
extern pascal Word TEStatus(void) inline(0x0622,dispatcher);
extern pascal void PMStartUp(Word, Word) inline(0x0213,dispatcher);
extern pascal void PMShutDown(void) inline(0x0313,dispatcher);
extern pascal Word PMVersion(void) inline(0x0413,dispatcher);
extern pascal Boolean PMStatus(void) inline(0x0613,dispatcher);
extern pascal void FMStartUp(Word, Word) inline(0x021B,dispatcher);
extern pascal void FMShutDown(void) inline(0x031B,dispatcher);
extern pascal Word FMVersion(void) inline(0x041B,dispatcher);
extern pascal Boolean FMStatus(void) inline(0x061B,dispatcher);
extern pascal void QDAuxStartUp(void) inline(0x0212,dispatcher);
extern pascal void QDAuxShutDown(void) inline(0x0312,dispatcher);
extern pascal Word QDAuxVersion(void) inline(0x0412,dispatcher);
extern pascal Boolean QDAuxStatus(void) inline(0x0612,dispatcher);
extern pascal void SFStartUp(Word, Word) inline(0x0217,dispatcher);
extern pascal void SFShutDown(void) inline(0x0317,dispatcher);
extern pascal Word SFVersion(void) inline(0x0417,dispatcher);
extern pascal Boolean SFStatus(void) inline(0x0617,dispatcher);
extern pascal void MCStartUp(Word) inline(0x0226,dispatcher);
extern pascal void MCShutDown(void) inline(0x0326,dispatcher);
extern pascal Word MCVersion(void) inline(0x0426,dispatcher);
extern pascal Boolean MCStatus(void) inline(0x0626,dispatcher);
static void DisplayMissing(unsigned tool) {
static char msg1[] = "\pThis application needs Tool000";
static char msg2[] = "\pin the System:Tools folder.";
static char ok[] = "\pContinue";
Int2Dec(tool, msg1+28, 3, 0);
msg1[30] |= 0x10; /* ' ' -> '0' */
TLMountVolume(0, 0, msg1, msg2, NULL, ok);
}
unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
unsigned i;
unsigned dp = 0;
unsigned char *dptr = 0;
unsigned errors = 0;
ssRef->resFileID = 0;
ssRef->dPageHandle = 0;
/*
todo:
25 - note synth
26 - note seq
29 - ACE
30 - resource manager
32 - MIDI
33 - VOC
35 - MidiSynth
37 - Animation
*/
/* check which ones are already loaded */
for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber;
tn &= 0x00ff;
switch(tn) {
case 0x0a:
if (SANEStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
break;
case 0x12:
if (QDAuxStatus() && !_toolErr) tn |= 0x8000;
break;
case 0x13:
if (PMStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0200;
break;
case 0x17:
if (SFStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
break;
case 0x1b:
if (FMStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
break;
case 0x1c:
if (ListStatus() && !_toolErr) tn |= 0x8000;
break;
case 0x22:
if (TEStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
break;
#if 0
case 0x23:
if (MIDIStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0300;
break;
#endif
case 0x26:
if (MCStatus() && !_toolErr) tn |= 0x8000;
break;
case 0x36:
if (TCPIPStatus() && !_toolErr) tn |= 0x8000;
break;
default:
tn = 0;
}
ssRef->theTools[i].toolNumber = tn;
}
if (dp) {
Handle h = NewHandle(dp, memID, 0xc005, 0);
if (_toolErr) return 0;
dptr = *(unsigned char **)h;
ssRef->dPageHandle = h;
}
for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber;
unsigned version = ssRef->theTools[i].minVersion;
if (tn == 0) continue;
if (tn & 0x8000) continue;
LoadOneTool(tn, version);
if (_toolErr) {
DisplayMissing(tn);
tn |= 0x4000;
ssRef->theTools[i].toolNumber = tn;
++errors;
continue;
}
_toolErr = 0;
switch(tn) {
case 0x0a:
SANEStartUp((Word)dptr);
dptr += 0x0100;
break;
case 0x12:
QDAuxStartUp();
break;
case 0x13:
PMStartUp(memID, (Word)dptr);
dptr += 0x0200;
break;
case 0x17:
SFStartUp(memID, (Word)dptr);
dptr += 0x0100;
break;
case 0x1b:
if (FMStatus() && !_toolErr) tn |= 0x8000;
dptr += 0x0100;
break;
case 0x1c:
ListStartUp();
break;
case 0x22:
TEStartUp(memID, (Word)dptr);
dptr += 0x0100;
break;
#if 0
case 0x23:
MIDIStartUp(memID, (Word)dptr);
dptr += 0x0300;
break;
#endif
case 0x26:
MCStartUp(memID);
break;
case 0x36:
TCPIPStartUp();
break;
}
if (_toolErr) {
++errors;
tn |= 0x2000;
} else {
tn |= 0x1000;
}
ssRef->theTools[i].toolNumber = tn;
}
exit:
return errors;
}
void NDAShutDownTools(StartStopRecord *ssRef){
unsigned i;
for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber;
if (!(tn & 0x1000)) continue;
switch(tn & 0xff) {
case 0x0a:
SANEShutDown();
break;
case 0x12:
QDAuxShutDown();
break;
case 0x13:
PMShutDown();
break;
case 0x17:
SFShutDown();
break;
case 0x1b:
FMShutDown();
break;
case 0x1c:
ListShutDown();
break;
case 0x22:
TEShutDown();
break;
case 0x26:
MCShutDown();
break;
case 0x36:
if (TCPIPGetConnectStatus() == 0)
TCPIPShutDown();
break;
}
}
if (ssRef->dPageHandle)
DisposeHandle(ssRef->dPageHandle);
}