Implement the rest of the direct writing of resources to the file. I have tested this under GNO (as opposed to Golden Gate where resource writes are not yet supported) and it does seem to work. I also tested it at 2.8MHz and the large test file takes about 30 seconds to convert. I may look at turning on the optimizer in the compiler to try to get a bit better performance on real HW. I decreased the stack size to 8K for now because 32K was too big for a "real" machine as opposed to the emulated Golden Gate.

This commit is contained in:
Jeremy Rand 2021-05-05 00:23:28 -04:00
parent e4778d0581
commit 34fd580448
7 changed files with 119 additions and 19 deletions

View File

@ -13,6 +13,7 @@
#include <gsos.h> #include <gsos.h>
#include <orca.h> #include <orca.h>
#include <memory.h>
#include <resources.h> #include <resources.h>
#include "io.h" #include "io.h"
@ -157,9 +158,12 @@ MD_SIZE outputPos(void)
static int writeResources(void) static int writeResources(void)
{ {
int result = 0;
#ifndef RESOURCE_WORKAROUND #ifndef RESOURCE_WORKAROUND
int shutdownResources = 0; int shutdownResources = 0;
Word writeResId; Word writeResId;
Word oldResId;
Handle windowPosHandle;
if (!ResourceStatus()) { if (!ResourceStatus()) {
ResourceStartUp(userid()); ResourceStartUp(userid());
@ -171,15 +175,44 @@ static int writeResources(void)
fprintf(stderr, "%s: Unable to create resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); fprintf(stderr, "%s: Unable to create resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
return 1; return 1;
} }
oldResId = GetCurResourceFile();
writeResId = OpenResourceFile(0x8000 | readWriteEnable, NULL, (Pointer)outputFileName); writeResId = OpenResourceFile(0x8000 | readWriteEnable, NULL, (Pointer)outputFileName);
if (toolerror()) { if (toolerror()) {
fprintf(stderr, "%s: Unable to open resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); fprintf(stderr, "%s: Unable to open resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
return 1; return 1;
} }
AddResource(styleHandle(), resChanged, rStyleBlock, STYLE_BLOCK_NUM);
if (toolerror()) {
fprintf(stderr, "%s: Unable to add style resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
goto error;
}
windowPosHandle = NewHandle(sizeof(windowPos), userid(), attrNoPurge, NULL);
if (toolerror()) {
fprintf(stderr, "%s: Unable to allocate memory for window resource for file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
goto error;
}
HLock(windowPosHandle);
PtrToHand((Pointer)windowPos, windowPosHandle, sizeof(windowPos));
AddResource(windowPosHandle, resChanged, R_WINDOW_POSITION, WINDOW_POSITION_NUM);
if (toolerror()) {
fprintf(stderr, "%s: Unable to add window position resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
result = 1;
}
DisposeHandle(windowPosHandle);
error:
CloseResourceFile(writeResId); CloseResourceFile(writeResId);
// Implement more of this... if (oldResId != 0)
SetCurResourceFile(oldResId);
if (shutdownResources) if (shutdownResources)
ResourceShutDown(); ResourceShutDown();
@ -248,7 +281,7 @@ static int writeResources(void)
fclose(rezFile); fclose(rezFile);
#endif #endif
return 0; return result;
} }

View File

@ -27,8 +27,8 @@
// approach should let me measure the worst case stack with a complex // approach should let me measure the worst case stack with a complex
// document. // document.
// //
// Leaving the stack very big for now at 32K. // Leaving the stack very big for now at 8K.
#pragma stacksize 32768 #pragma stacksize 8192
// Globals // Globals
@ -121,5 +121,7 @@ int main(int argc, char * argv[])
putchar('\n'); putchar('\n');
styleShutdown();
return result; return result;
} }

View File

@ -15,7 +15,7 @@ shift
FILE="$1" FILE="$1"
shift shift
BOOTCOPYPATH="$1" BOOTCOPYPATH=""
PROGRAM=`basename "$FILE"` PROGRAM=`basename "$FILE"`
TMPDIR=/tmp/a2gs_mount.$$ TMPDIR=/tmp/a2gs_mount.$$
@ -173,6 +173,16 @@ then
cleanupAndExit cleanupAndExit
fi fi
if [ ! -z "$1" ]
then
cp $CPARGS "$@" "$MOUNTDIR"
if [ $? != 0 ]
then
echo Unable to copy extra files to the disk image.
cleanupAndExit
fi
fi
OLDDIR=`pwd` OLDDIR=`pwd`
for COPYDIR in $COPYDIRS for COPYDIR in $COPYDIRS
do do

View File

@ -193,7 +193,7 @@ executeGUI: all
executeShell: all executeShell: all
$(ORCA) --mem $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt $(ORCA) --mem $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt
make/teachRez $(TARGETDIR)/outfile.txt make/teachRez $(TARGETDIR)/outfile.txt
make/createDiskImage "$(DISKIMAGE)" $(DESTBOOTIMAGE) "$(TARGETDIR)/outfile.txt" make/createDiskImage "$(DISKIMAGE)" $(DESTBOOTIMAGE) "$(TARGETDIR)/$(PGM)" "$(TARGETDIR)/outfile.txt" test.md
make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)" make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)"
$(OBJDIR)/%.a: %.c $(OBJDIR)/%.a: %.c

View File

@ -8,6 +8,11 @@ BASEFILE=`echo $TEACH_FILE | sed 's/\.[^\/]*$//'`
REZ_FILE="${BASEFILE}.rez" REZ_FILE="${BASEFILE}.rez"
R_FILE="${BASEFILE}.r" R_FILE="${BASEFILE}.r"
if [ ! -f "${TEACH_FILE}.rez" ]
then
exit 0
fi
mv "${TEACH_FILE}.rez" "$REZ_FILE" mv "${TEACH_FILE}.rez" "$REZ_FILE"
$ORCA chtyp -l rez "$REZ_FILE" $ORCA chtyp -l rez "$REZ_FILE"

View File

@ -10,6 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <font.h> #include <font.h>
#include <memory.h>
#include <textedit.h> #include <textedit.h>
#include "io.h" #include "io.h"
@ -87,28 +88,33 @@ static uint8_t headerFontSizes[NUM_HEADER_SIZES] = {
18 18
}; };
static tFormat * formatPtr = NULL; static Handle formatHandle = NULL;
static uint32_t allocStyleItems = 0; static uint32_t allocStyleItems = 0;
static MD_SIZE styleChangedAt = 0; static MD_SIZE styleChangedAt = 0;
// Implementation // Implementation
void growStyleItems(void) static tFormat * growStyleItems(void)
{ {
uint32_t newAllocStyleItems = 2 * allocStyleItems; uint32_t newAllocStyleItems = 2 * allocStyleItems;
formatPtr = realloc(formatPtr, sizeof(formatPtr->header) + newAllocStyleItems * sizeof(StyleItem)); HUnlock(formatHandle);
if (formatPtr == NULL) { SetHandleSize(sizeof(tFormatHeader) + newAllocStyleItems * sizeof(StyleItem), formatHandle);
fprintf(stderr, "%s: Out of memory\n", commandName); if (toolerror()) {
fprintf(stderr, "%s: Out of memory, toolerror=0x%x\n", commandName, toolerror());
exit(1); exit(1);
} }
allocStyleItems = newAllocStyleItems; allocStyleItems = newAllocStyleItems;
HLock(formatHandle);
return (tFormat *)(*formatHandle);
} }
int addStyle(int styleListNum, uint16_t fontFamily, uint8_t fontSize, uint8_t fontStyle, uint16_t backgroundColour) int addStyle(int styleListNum, uint16_t fontFamily, uint8_t fontSize, uint8_t fontStyle, uint16_t backgroundColour)
{ {
tFormat * formatPtr = (tFormat *)(*formatHandle);
formatPtr->header.styleList[styleListNum].styleFontID.fidRec.famNum = fontFamily; formatPtr->header.styleList[styleListNum].styleFontID.fidRec.famNum = fontFamily;
formatPtr->header.styleList[styleListNum].styleFontID.fidRec.fontSize = fontSize; formatPtr->header.styleList[styleListNum].styleFontID.fidRec.fontSize = fontSize;
formatPtr->header.styleList[styleListNum].styleFontID.fidRec.fontStyle = fontStyle; formatPtr->header.styleList[styleListNum].styleFontID.fidRec.fontStyle = fontStyle;
@ -123,12 +129,15 @@ int styleInit(void)
{ {
int styleListNum; int styleListNum;
int headerSize; int headerSize;
tFormat * formatPtr;
formatPtr = malloc(sizeof(formatPtr->header) + STARTING_STYLE_ITEMS * sizeof(StyleItem)); formatHandle = NewHandle(sizeof(formatPtr->header) + STARTING_STYLE_ITEMS * sizeof(StyleItem), userid(), attrNoPurge, NULL);
if (formatPtr == NULL) { if (toolerror()) {
fprintf(stderr, "%s: Out of memory\n", commandName); fprintf(stderr, "%s: Out of memory, toolerror=0x%x\n", commandName, toolerror());
return 1; return 1;
} }
HLock(formatHandle);
formatPtr = (tFormat *)(*formatHandle);
allocStyleItems = STARTING_STYLE_ITEMS; allocStyleItems = STARTING_STYLE_ITEMS;
formatPtr->header.version = 0x0000; formatPtr->header.version = 0x0000;
@ -175,6 +184,8 @@ int styleInit(void)
// Add code style // Add code style
styleListNum = addStyle(styleListNum, courier, 12, plainMask, 0xffff); styleListNum = addStyle(styleListNum, courier, 12, plainMask, 0xffff);
HUnlock(formatHandle);
if (styleListNum != TOTAL_STYLES) if (styleListNum != TOTAL_STYLES)
{ {
fprintf(stderr, "%s: Expected %d styles but created %d styles.\n", commandName); fprintf(stderr, "%s: Expected %d styles but created %d styles.\n", commandName);
@ -189,7 +200,13 @@ void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize)
{ {
int32_t styleOffset; int32_t styleOffset;
MD_SIZE currentPos; MD_SIZE currentPos;
int lastStyleIndex = formatPtr->header.numberOfStyles - 1; int lastStyleIndex;
tFormat * formatPtr;
HLock(formatHandle);
formatPtr = (tFormat *)(*formatHandle);
lastStyleIndex = formatPtr->header.numberOfStyles - 1;
switch (styleType) { switch (styleType) {
case STYLE_TYPE_HEADER: case STYLE_TYPE_HEADER:
@ -217,7 +234,10 @@ void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize)
// If the offset requested is the same as the one we already have, then just return. // If the offset requested is the same as the one we already have, then just return.
// Nothing has changed. // Nothing has changed.
if (formatPtr->styleItems[lastStyleIndex].dataOffset == styleOffset) if (formatPtr->styleItems[lastStyleIndex].dataOffset == styleOffset)
{
HUnlock(formatHandle);
return; return;
}
// Check to see if the previous style actually emitted any characters and if not, // Check to see if the previous style actually emitted any characters and if not,
// then just overwrite it with this new style. // then just overwrite it with this new style.
@ -228,6 +248,7 @@ void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize)
if (styleChangedAt == currentPos) { if (styleChangedAt == currentPos) {
formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset; formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset;
HUnlock(formatHandle);
return; return;
} }
@ -235,17 +256,25 @@ void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize)
styleChangedAt = currentPos; styleChangedAt = currentPos;
if (formatPtr->header.numberOfStyles == allocStyleItems) if (formatPtr->header.numberOfStyles == allocStyleItems)
growStyleItems(); formatPtr = growStyleItems();
lastStyleIndex++; lastStyleIndex++;
formatPtr->header.numberOfStyles++; formatPtr->header.numberOfStyles++;
formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset; formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset;
HUnlock(formatHandle);
} }
void closeStyle(void) void closeStyle(void)
{ {
int lastStyleIndex;
tFormat * formatPtr;
uint32_t formatSize;
MD_SIZE currentPos = outputPos(); MD_SIZE currentPos = outputPos();
int lastStyleIndex = formatPtr->header.numberOfStyles - 1;
HLock(formatHandle);
formatPtr = (tFormat *)(*formatHandle);
lastStyleIndex = formatPtr->header.numberOfStyles - 1;
// If the final style was not used, then remove it. Otherwise, update the length of the // If the final style was not used, then remove it. Otherwise, update the length of the
// final style. // final style.
@ -254,14 +283,31 @@ void closeStyle(void)
} else { } else {
formatPtr->styleItems[lastStyleIndex]. dataLength = currentPos - styleChangedAt; formatPtr->styleItems[lastStyleIndex]. dataLength = currentPos - styleChangedAt;
} }
formatSize = sizeof(formatPtr->header) + (sizeof(formatPtr->styleItems) * formatPtr->header.numberOfStyles);
HUnlock(formatHandle);
if (GetHandleSize(formatHandle) != formatSize)
SetHandleSize(formatSize, formatHandle);
}
Handle styleHandle(void)
{
return formatHandle;
} }
uint8_t * stylePtr(void) uint8_t * stylePtr(void)
{ {
return (uint8_t *)formatPtr; HLock(formatHandle);
return (uint8_t *)(*formatHandle);
} }
uint32_t styleSize(void) uint32_t styleSize(void)
{ {
return sizeof(formatPtr->header) + (sizeof(formatPtr->styleItems) * formatPtr->header.numberOfStyles); return GetHandleSize(formatHandle);
}
void styleShutdown(void)
{
DisposeHandle(formatHandle);
} }

View File

@ -9,6 +9,8 @@
#ifndef _GUARD_PROJECTmd2teach_FILEstyle_ #ifndef _GUARD_PROJECTmd2teach_FILEstyle_
#define _GUARD_PROJECTmd2teach_FILEstyle_ #define _GUARD_PROJECTmd2teach_FILEstyle_
#include <types.h>
#include "md4c.h" #include "md4c.h"
@ -32,9 +34,11 @@ typedef enum tStyleType {
// API // API
extern int styleInit(void); extern int styleInit(void);
extern void styleShutdown(void);
extern void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize); extern void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize);
extern void closeStyle(void); extern void closeStyle(void);
Handle styleHandle(void);
uint8_t * stylePtr(void); uint8_t * stylePtr(void);
uint32_t styleSize(void); uint32_t styleSize(void);