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:
parent
e4778d0581
commit
34fd580448
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <gsos.h>
|
||||
#include <orca.h>
|
||||
#include <memory.h>
|
||||
#include <resources.h>
|
||||
|
||||
#include "io.h"
|
||||
|
@ -157,9 +158,12 @@ MD_SIZE outputPos(void)
|
|||
|
||||
static int writeResources(void)
|
||||
{
|
||||
int result = 0;
|
||||
#ifndef RESOURCE_WORKAROUND
|
||||
int shutdownResources = 0;
|
||||
Word writeResId;
|
||||
Word oldResId;
|
||||
Handle windowPosHandle;
|
||||
|
||||
if (!ResourceStatus()) {
|
||||
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());
|
||||
return 1;
|
||||
}
|
||||
|
||||
oldResId = GetCurResourceFile();
|
||||
|
||||
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());
|
||||
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);
|
||||
|
||||
// Implement more of this...
|
||||
if (oldResId != 0)
|
||||
SetCurResourceFile(oldResId);
|
||||
|
||||
if (shutdownResources)
|
||||
ResourceShutDown();
|
||||
|
@ -248,7 +281,7 @@ static int writeResources(void)
|
|||
fclose(rezFile);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
// approach should let me measure the worst case stack with a complex
|
||||
// document.
|
||||
//
|
||||
// Leaving the stack very big for now at 32K.
|
||||
#pragma stacksize 32768
|
||||
// Leaving the stack very big for now at 8K.
|
||||
#pragma stacksize 8192
|
||||
|
||||
|
||||
// Globals
|
||||
|
@ -121,5 +121,7 @@ int main(int argc, char * argv[])
|
|||
|
||||
putchar('\n');
|
||||
|
||||
styleShutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ shift
|
|||
FILE="$1"
|
||||
shift
|
||||
|
||||
BOOTCOPYPATH="$1"
|
||||
BOOTCOPYPATH=""
|
||||
|
||||
PROGRAM=`basename "$FILE"`
|
||||
TMPDIR=/tmp/a2gs_mount.$$
|
||||
|
@ -173,6 +173,16 @@ then
|
|||
cleanupAndExit
|
||||
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`
|
||||
for COPYDIR in $COPYDIRS
|
||||
do
|
||||
|
|
|
@ -193,7 +193,7 @@ executeGUI: all
|
|||
executeShell: all
|
||||
$(ORCA) --mem $(TARGETDIR)/$(PGM) -d test.md $(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)"
|
||||
|
||||
$(OBJDIR)/%.a: %.c
|
||||
|
|
|
@ -8,6 +8,11 @@ BASEFILE=`echo $TEACH_FILE | sed 's/\.[^\/]*$//'`
|
|||
REZ_FILE="${BASEFILE}.rez"
|
||||
R_FILE="${BASEFILE}.r"
|
||||
|
||||
if [ ! -f "${TEACH_FILE}.rez" ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mv "${TEACH_FILE}.rez" "$REZ_FILE"
|
||||
|
||||
$ORCA chtyp -l rez "$REZ_FILE"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <font.h>
|
||||
#include <memory.h>
|
||||
#include <textedit.h>
|
||||
|
||||
#include "io.h"
|
||||
|
@ -87,28 +88,33 @@ static uint8_t headerFontSizes[NUM_HEADER_SIZES] = {
|
|||
18
|
||||
};
|
||||
|
||||
static tFormat * formatPtr = NULL;
|
||||
static Handle formatHandle = NULL;
|
||||
static uint32_t allocStyleItems = 0;
|
||||
static MD_SIZE styleChangedAt = 0;
|
||||
|
||||
|
||||
// Implementation
|
||||
|
||||
void growStyleItems(void)
|
||||
static tFormat * growStyleItems(void)
|
||||
{
|
||||
uint32_t newAllocStyleItems = 2 * allocStyleItems;
|
||||
|
||||
formatPtr = realloc(formatPtr, sizeof(formatPtr->header) + newAllocStyleItems * sizeof(StyleItem));
|
||||
if (formatPtr == NULL) {
|
||||
fprintf(stderr, "%s: Out of memory\n", commandName);
|
||||
HUnlock(formatHandle);
|
||||
SetHandleSize(sizeof(tFormatHeader) + newAllocStyleItems * sizeof(StyleItem), formatHandle);
|
||||
if (toolerror()) {
|
||||
fprintf(stderr, "%s: Out of memory, toolerror=0x%x\n", commandName, toolerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
allocStyleItems = newAllocStyleItems;
|
||||
HLock(formatHandle);
|
||||
return (tFormat *)(*formatHandle);
|
||||
}
|
||||
|
||||
|
||||
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.fontSize = fontSize;
|
||||
formatPtr->header.styleList[styleListNum].styleFontID.fidRec.fontStyle = fontStyle;
|
||||
|
@ -123,12 +129,15 @@ int styleInit(void)
|
|||
{
|
||||
int styleListNum;
|
||||
int headerSize;
|
||||
tFormat * formatPtr;
|
||||
|
||||
formatPtr = malloc(sizeof(formatPtr->header) + STARTING_STYLE_ITEMS * sizeof(StyleItem));
|
||||
if (formatPtr == NULL) {
|
||||
fprintf(stderr, "%s: Out of memory\n", commandName);
|
||||
formatHandle = NewHandle(sizeof(formatPtr->header) + STARTING_STYLE_ITEMS * sizeof(StyleItem), userid(), attrNoPurge, NULL);
|
||||
if (toolerror()) {
|
||||
fprintf(stderr, "%s: Out of memory, toolerror=0x%x\n", commandName, toolerror());
|
||||
return 1;
|
||||
}
|
||||
HLock(formatHandle);
|
||||
formatPtr = (tFormat *)(*formatHandle);
|
||||
allocStyleItems = STARTING_STYLE_ITEMS;
|
||||
|
||||
formatPtr->header.version = 0x0000;
|
||||
|
@ -175,6 +184,8 @@ int styleInit(void)
|
|||
// Add code style
|
||||
styleListNum = addStyle(styleListNum, courier, 12, plainMask, 0xffff);
|
||||
|
||||
HUnlock(formatHandle);
|
||||
|
||||
if (styleListNum != TOTAL_STYLES)
|
||||
{
|
||||
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;
|
||||
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) {
|
||||
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.
|
||||
// Nothing has changed.
|
||||
if (formatPtr->styleItems[lastStyleIndex].dataOffset == styleOffset)
|
||||
{
|
||||
HUnlock(formatHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if the previous style actually emitted any characters and if not,
|
||||
// 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) {
|
||||
formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset;
|
||||
HUnlock(formatHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -235,17 +256,25 @@ void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize)
|
|||
styleChangedAt = currentPos;
|
||||
|
||||
if (formatPtr->header.numberOfStyles == allocStyleItems)
|
||||
growStyleItems();
|
||||
formatPtr = growStyleItems();
|
||||
|
||||
lastStyleIndex++;
|
||||
formatPtr->header.numberOfStyles++;
|
||||
formatPtr->styleItems[lastStyleIndex].dataOffset = styleOffset;
|
||||
HUnlock(formatHandle);
|
||||
}
|
||||
|
||||
void closeStyle(void)
|
||||
{
|
||||
int lastStyleIndex;
|
||||
tFormat * formatPtr;
|
||||
uint32_t formatSize;
|
||||
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
|
||||
// final style.
|
||||
|
@ -254,14 +283,31 @@ void closeStyle(void)
|
|||
} else {
|
||||
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)
|
||||
{
|
||||
return (uint8_t *)formatPtr;
|
||||
HLock(formatHandle);
|
||||
return (uint8_t *)(*formatHandle);
|
||||
}
|
||||
|
||||
uint32_t styleSize(void)
|
||||
{
|
||||
return sizeof(formatPtr->header) + (sizeof(formatPtr->styleItems) * formatPtr->header.numberOfStyles);
|
||||
return GetHandleSize(formatHandle);
|
||||
}
|
||||
|
||||
void styleShutdown(void)
|
||||
{
|
||||
DisposeHandle(formatHandle);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef _GUARD_PROJECTmd2teach_FILEstyle_
|
||||
#define _GUARD_PROJECTmd2teach_FILEstyle_
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include "md4c.h"
|
||||
|
||||
|
||||
|
@ -32,9 +34,11 @@ typedef enum tStyleType {
|
|||
// API
|
||||
|
||||
extern int styleInit(void);
|
||||
extern void styleShutdown(void);
|
||||
extern void setStyle(tStyleType styleType, uint16_t textMask, uint16_t headerSize);
|
||||
extern void closeStyle(void);
|
||||
|
||||
Handle styleHandle(void);
|
||||
uint8_t * stylePtr(void);
|
||||
uint32_t styleSize(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue