diff --git a/Make.engine b/Make.engine index e279c50..9087324 100644 --- a/Make.engine +++ b/Make.engine @@ -16,12 +16,12 @@ OPS_OBJS=ops/abCOp.o ops/abCOpAdd.o ops/abCOpSubtr.o ops/abCOpMult.o \ SHELL_OBJS=abCMain.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS) -NDA_OBJS=abCNDA.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS) -NDA_RES=abCNDA.r +NDA_OBJS=abCalcNDA.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS) +NDA_RES=abCalcNDA.r abCMain.o: abCalc.h abCStack.h expr/abCExpr.h ops/abCOp.h abCError.h -abCNDA.o: abCNDA.defs -abCNDA.r: abCNDA.defs +abCalcNDA.o: abCalcNDA.defs abCalc.h +abCalcNDA.r: abCalcNDA.defs abCalc.o: abCalc.h expr/abCExpr.h abCMode.h expr/abCExpReal.h expr/abCExprInt.h \ abCStack.h ops/abCOp.h abCError.h diff --git a/Makefile b/Makefile index 469ac45..10dc8d3 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,20 @@ all: $(SHELL_NAME) $(NDA_NAME) CFLAGS=-D ABCALC_GSOS -$(SHELL_NAME): fixtype $(SHELL_OBJS) +$(SHELL_NAME): $(SHELL_OBJS) occ -o $(SHELL_NAME) $(SHELL_OBJS) -$(NDA_NAME): fixtype $(NDA_OBJS) $(NDA_NAME).r - cp $(NDA_NAME).r $(NDA_NAME) +$(NDA_NAME): $(NDA_OBJS) $(NDA_NAME).r + cp -f $(NDA_NAME).r $(NDA_NAME) occ -o $(NDA_NAME) $(NDA_OBJS) chtyp -t nda $(NDA_NAME) +abCalcMain.o: abCalcMain.c + occ $(CFLAGS) -c -o $@ $< + +$(NDA_NAME).o: $(NDA_NAME).c + occ $(CFLAGS) -c -o $@ $< + clean: cp -p rm -f $(SHELL_NAME) $(SHELL_OBJS) $(SHELL_NAME).root cp -p rm -f $(NDA_NAME) $(NDA_OBJS) $(NDA_NAME).r $(NDA_NAME).root @@ -27,13 +33,18 @@ clean: cp -p rm -f expr/*.root cp -p rm -f ops/*.root -fixtype: - chtyp -l CC *.c *.h +fixfiles: + tr '\\012' '\\015' < abCalcNDA.defs > /tmp/blah + cp -f /tmp/blah abCalcNDA.defs + tr '\\012' '\\015' < abCalcNDA.rez > /tmp/blah + cp -f /tmp/blah abCalcNDA.rez + chtyp -l CC *.c *.h *.defs + chtyp -l REZ *.rez chtyp -l CC expr/*.c expr/*.h chtyp -l CC ops/*.c ops/*.h %.o: %.c - occ $(CFLAGS) -c $< + occ $(CFLAGS) -c -o $@ $< %.r: %.rez - compile $< keep=$@ + occ -o $@ $< diff --git a/abCalcNDA.c b/abCalcNDA.c index 9940b6f..bd7f387 100644 --- a/abCalcNDA.c +++ b/abCalcNDA.c @@ -4,70 +4,147 @@ */ -#pragma nda NDAOpen NDAClose NDAAction NDAInit 60 0x03FF " abCalc\\H**" +#pragma nda NDAOpen NDAClose NDAAction NDAInit 0 0xFFFF " abCalc\\H**" -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "abCalcNDA.defs" +#include "abCalc.h" -static BOOLEAN gCalcActive; -static GrafPortPtr gCalcWinPtr; +static BOOLEAN gCalcActive = FALSE; +static GrafPortPtr gCalcWinPtr = NULL; +static unsigned int gUserId; +static unsigned int gResourceId; void NDAClose(void) { if (gCalcActive) { CloseWindow(gCalcWinPtr); + gCalcWinPtr = NULL; gCalcActive = FALSE; } + CloseResourceFile(gResourceId); + ResourceShutDown(); } void NDAInit(int code) { - if (code == 1) + if (code) { gCalcActive = FALSE; - else if (gCalcActive) + gUserId = MMStartUp(); + } else if (gCalcActive) { NDAClose(); + } } +#pragma databank 1 +void DrawContents(void) +{ + PenNormal(); + DrawControls(GetPort()); +} +#pragma databank 0 + + GrafPortPtr NDAOpen(void) { - GrafPortPtr wPtr; + Pointer pathToSelf; + unsigned int oldResourceApp; + LevelRecGS levelDCB; + unsigned int oldLevel; + SysPrefsRecGS prefsDCB; + unsigned int oldPrefs; - wPtr = NULL; - if (!clockActive) { - if (OpenResourceFork()) { - gCalcWinPtr = NewWindow2("\p abCalc ", 0, NULL, NULL, 0x02, wrNum, rWindParam1); - if (toolerror() == 0) { - SetSysWindow(gCalcWinPtr); - clockActive = TRUE; - wPtr = clockWinPtr; - } - CloseResourceFork(); - } - } - return wPtr; + if (gCalcActive) + return NULL; + + oldResourceApp = GetCurResourceApp(); + ResourceStartUp(gUserId); + pathToSelf = LGetPathname2(gUserId, 1); + + levelDCB.pCount = 2; + GetLevelGS(&levelDCB); + oldLevel = levelDCB.level; + levelDCB.level = 0; + SetLevelGS(&levelDCB); + + prefsDCB.pCount = 1; + GetSysPrefsGS(&prefsDCB); + oldPrefs = prefsDCB.preferences; + prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000; + SetSysPrefsGS(&prefsDCB); + + gResourceId = OpenResourceFile(readEnable, NULL, pathToSelf); + + gCalcWinPtr = NewWindow2("\p abCalc ", 0, DrawContents, NULL, refIsResource, + abCalcWinNum, rWindParam1); + + SetSysWindow(gCalcWinPtr); + ShowWindow(gCalcWinPtr); + SelectWindow(gCalcWinPtr); + + gCalcActive = TRUE; + + prefsDCB.preferences = oldPrefs; + SetSysPrefsGS(&prefsDCB); + + levelDCB.level = oldLevel; + SetLevelGS(&levelDCB); + + SetCurResourceApp(oldResourceApp); + + return gCalcWinPtr; } -BOOLEAN NDAAction(int code, EventRecord *sysEvent) +BOOLEAN NDAAction(EventRecord *sysEvent, int code) { int event; static EventRecord localEvent; + unsigned int eventCode; - switch (code) { - case eventAction: - localEvent.what = sysEvent->what; - localEvent.message = sysEvent->message; - localEvent.when = sysEvent->when; - localEvent.where = sysEvent->where; - localEvent.modifiers = sysEvent->modifiers; - event = TaskMasterDA(0, &localEvent); - break; - case runAction: - break; + if (code == runAction) + return FALSE; + + if (code == eventAction) { + BlockMove((Pointer)sysEvent, (Pointer)&localEvent, 16); + localEvent.wmTaskMask = 0x001FFFFF; + eventCode = TaskMasterDA(0, &localEvent); + switch(eventCode) { + case updateEvt: + BeginUpdate(gCalcWinPtr); + DrawContents(); + EndUpdate(gCalcWinPtr); + break; + + case wInControl: + break; + } } + return FALSE; } + + +/* I shouldn't need a main() but the linker seems to want one when I + link multiple objects together in the final link step. If I only + have a single object, there is no problem. There is probable a + compile incantation which will avoid this but for now... */ +int main(void) +{ + return 0; +} diff --git a/abCalcNDA.defs b/abCalcNDA.defs index b60700d..9152107 100644 --- a/abCalcNDA.defs +++ b/abCalcNDA.defs @@ -1,7 +1,40 @@ -/* - abCalcNDA.defs - By: Jeremy Rand - */ +/* */ +/* abCalcNDA.defs */ +/* By: Jeremy Rand */ +/* */ -#define ABCALC_WINDOW_NUM 1001 -#define ABCALC_LINED_COLORS 1002 +#define abCalcWinNum 1001 +#define abCalcLinedColors 1002 + +#define abCalcControlList 1003 + + +#define abCalcBtn0 2001 +#define abCalcBtn0Str 2002 + +#define abCalcBtn1 2003 +#define abCalcBtn1Str 2004 + +#define abCalcBtn2 2005 +#define abCalcBtn2Str 2006 + +#define abCalcBtn3 2007 +#define abCalcBtn3Str 2008 + +#define abCalcBtn4 2009 +#define abCalcBtn4Str 2010 + +#define abCalcBtn5 2011 +#define abCalcBtn5Str 2012 + +#define abCalcBtn6 2013 +#define abCalcBtn6Str 2014 + +#define abCalcBtn7 2015 +#define abCalcBtn7Str 2016 + +#define abCalcBtn8 2017 +#define abCalcBtn8Str 2018 + +#define abCalcBtn9 2019 +#define abCalcBtn9Str 2020 diff --git a/abCalcNDA.rez b/abCalcNDA.rez index 8492e0f..487e576 100644 --- a/abCalcNDA.rez +++ b/abCalcNDA.rez @@ -1,19 +1,19 @@ -/* - abCalcNDA.h - By: Jeremy Rand - */ +/* */ +/* abCalcNDA.h */ +/* By: Jeremy Rand */ +/* */ #include "types.rez" #include "abCalcNda.defs" -resource rWindParam1 (ABCALC_WINDOW_NUM) { +resource rWindParam1 (abCalcWinNum) { $C0A5, /* wFrameBits */ nil, /* wTitle */ 0, /* wRefCon */ {0,0,0,0}, /* ZoomRect */ - ABCALC_LINED_COLORS, /* wColor ID */ + abCalcLinedColors, /* wColor ID */ {0,0}, /* Origin */ {0,0}, /* data size */ {0,0}, /* max height-width */ @@ -21,17 +21,38 @@ resource rWindParam1 (ABCALC_WINDOW_NUM) { {0,0}, /* page ver horiz */ 0, /* winfoRefcon */ 0, /* wInfoHeight */ - {50,50,62,200}, /* wposition */ + {10,10,180,630}, /* wposition */ infront, /* wPlane */ - nil, /* wStorage */ - $0800 /* wInVerb */ - }; + abCalcControlList, /* wStorage */ + $0809 /* wInVerb */ +}; -resource rWindColor (ABCALC_LINED_COLORS) { +resource rWindColor (abCalcLinedColors) { 0x0000, /* frameColor */ 0x0F00, /* titleColor */ 0x020F, /* tbarColor */ 0xF0F0, /* growColor */ 0x00F0, /* infoColor */ - }; +}; + + +resource rControlList (abCalcControlList) { + { + abCalcBtn0 + } +}; + + +resource rControlTemplate (abCalcBtn0) { + abCalcBtn0, + {8, 130, 0, 0}, + SimpleButtonControl {{ + $0002, + $3002, + 0, + abCalcBtn0Str + }}; +}; +resource rPString (abCalcBtn0Str, noCrossBank) { "0" }; +