diff --git a/md2teach/io.c b/md2teach/io.c index e37e299..001d1a8 100644 --- a/md2teach/io.c +++ b/md2teach/io.c @@ -12,13 +12,25 @@ #include #include +#include +#include #include "io.h" #include "main.h" +// Defines + +// This enables a workaround for creating the resources by writing a .rez file rather than +// writing it directly. At the moment, Golden Gate does not support writing resources +// but this will let me test it without that capability. +#define RESOURCE_WORKAROUND + + // Globals +static GSString255 outputFileName; +static Word writeResId; static IORecGS writeRec; static char writeBuffer[4096]; static int32_t writeBufferOffset = 0; @@ -41,7 +53,6 @@ static void flushBuffer(void) int openOutputFile(const char * filename) { - GSString255 outputFileName; CreateRecGS createRec; NameRecGS destroyRec; OpenRecGS openRec; @@ -82,6 +93,7 @@ int openOutputFile(const char * filename) writeRec.pCount = 4; writeRec.refNum = openRec.refNum; writeRec.dataBuffer = writeBuffer; + return 0; } @@ -117,12 +129,38 @@ MD_SIZE outputPos(void) void closeOutputFile(void) { RefNumRecGS closeRec; + int shutdownResources = 0; if (writeBufferOffset > 0) flushBuffer(); closeRec.pCount = 1; closeRec.refNum = writeRec.refNum; CloseGS(&closeRec); + + if (!ResourceStatus()) { + ResourceStartUp(userid()); + shutdownResources = 1; + } + +#ifdef RESOURCE_WORKAROUND + CreateResourceFile(0x5445, 0x50, destroyEnable | renameEnable | readWriteEnable, (Pointer)outputFileName); + if (toolerror()) { + fprintf(stderr, "%s: Unable to create resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); + } + writeResId = OpenResourceFile(0x8000 | readWriteEnable, NULL, (Pointer)outputFileName); + if (toolerror()) { + fprintf(stderr, "%s: Unable to open resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); + } else { + CloseResourceFile(writeResId); + } + + // Implement more of this... + + if (shutdownResources) + ResourceShutDown(); +#else + // Implement the workaround here... +#endif } diff --git a/md2teach/main.c b/md2teach/main.c index 358d036..c3a6cf7 100644 --- a/md2teach/main.c +++ b/md2teach/main.c @@ -33,7 +33,6 @@ // Globals -void * lowestStackSeen; char * commandName; int debugEnabled = 0; @@ -89,8 +88,6 @@ int main(int argc, char * argv[]) MD_CHAR * inputBuffer; int index; - lowestStackSeen = &result; - index = parseArgs(argc, argv); if (index < 0) exit(1); @@ -113,7 +110,6 @@ int main(int argc, char * argv[]) if (debugEnabled) { fprintf(stderr, "Parser result: %d\n", result); - fprintf(stderr, "Most stack used: %lu\n", ((unsigned long)&result) - ((unsigned long)lowestStackSeen)); } if (result != 0) diff --git a/md2teach/main.h b/md2teach/main.h index 585131b..6f1f43e 100644 --- a/md2teach/main.h +++ b/md2teach/main.h @@ -11,7 +11,6 @@ #pragma memorymodel 1 extern char * commandName; -extern void * lowestStackSeen; extern int debugEnabled; diff --git a/md2teach/make/tail.mk b/md2teach/make/tail.mk index 951d0b7..57e81fd 100644 --- a/md2teach/make/tail.mk +++ b/md2teach/make/tail.mk @@ -191,7 +191,7 @@ executeGUI: all make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)" executeShell: all - $(ORCA) $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt + $(ORCA) --mem $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt make/createDiskImage "$(DISKIMAGE)" $(DESTBOOTIMAGE) "$(TARGETDIR)/outfile.txt" make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)" diff --git a/md2teach/translate.c b/md2teach/translate.c index b0d2580..a7dc933 100644 --- a/md2teach/translate.c +++ b/md2teach/translate.c @@ -323,10 +323,6 @@ static int enterBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata) newBlock->next = blockList; blockList = newBlock; - if ((detail != NULL) && - (detail < lowestStackSeen)) - lowestStackSeen = detail; - switch (type) { case MD_BLOCK_DOC: if (debugEnabled) @@ -501,10 +497,6 @@ static int leaveBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata) blockList = oldBlock->next; free(oldBlock); - if ((detail != NULL) && - (detail < lowestStackSeen)) - lowestStackSeen = detail; - switch (type) { case MD_BLOCK_DOC: break; @@ -559,10 +551,6 @@ static int leaveBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata) static int enterSpanHook(MD_SPANTYPE type, void * detail, void * userdata) { - if ((detail != NULL) && - (detail < lowestStackSeen)) - lowestStackSeen = detail; - switch (type) { case MD_SPAN_EM: if (debugEnabled) @@ -609,10 +597,6 @@ static int enterSpanHook(MD_SPANTYPE type, void * detail, void * userdata) static int leaveSpanHook(MD_SPANTYPE type, void * detail, void * userdata) { - if ((detail != NULL) && - (detail < lowestStackSeen)) - lowestStackSeen = detail; - switch (type) { case MD_SPAN_EM: textStyleMask &= ~STYLE_TEXT_MASK_EMPHASIZED;