From 51ea60fe31db6594d6d6ccc46edfad3c35fc7f54 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Wed, 19 May 2021 22:54:53 -0400 Subject: [PATCH] A bit more code towards building a babel fish translator for markdown. --- md2teach.xcodeproj/project.pbxproj | 6 +- .../xcschemes/xcschememanagement.plist | 4 +- md2teach/babelfish.mk | 4 +- md2teach/babelfish/babelfish_defs.h | 11 ++ md2teach/babelfish/babelfish_types.h | 2 +- md2teach/babelfish/init.c | 84 ------------ md2teach/babelfish/init.s | 26 ++++ md2teach/babelfish/request.c | 129 ++++++++++++++++++ 8 files changed, 175 insertions(+), 91 deletions(-) delete mode 100644 md2teach/babelfish/init.c create mode 100644 md2teach/babelfish/init.s create mode 100644 md2teach/babelfish/request.c diff --git a/md2teach.xcodeproj/project.pbxproj b/md2teach.xcodeproj/project.pbxproj index 1aa2055..e245256 100644 --- a/md2teach.xcodeproj/project.pbxproj +++ b/md2teach.xcodeproj/project.pbxproj @@ -45,9 +45,10 @@ 9D406AC4264A2AD400747EE9 /* babelfish_defs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = babelfish_defs.h; sourceTree = ""; }; 9D406ACB264A2B5800747EE9 /* babelfish_rez.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = babelfish_rez.h; sourceTree = ""; }; 9D406ACD264A2BD300747EE9 /* markdown.rez */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.rez; path = markdown.rez; sourceTree = ""; }; - 9D406AD8264C50E400747EE9 /* init.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = init.c; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.c; }; + 9D406AD8264C50E400747EE9 /* request.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = request.c; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.c; }; 9D406AD9264C50F700747EE9 /* filter.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = filter.s; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9D406B2D2652155B00747EE9 /* babelfish_types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = babelfish_types.h; sourceTree = ""; }; + 9D406B312652D2C800747EE9 /* init.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = init.s; sourceTree = ""; }; 9D6532E42626240800105D50 /* md2teach */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = md2teach; sourceTree = BUILT_PRODUCTS_DIR; }; 9D6532EA2626240800105D50 /* doNotBuild */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = doNotBuild; sourceTree = BUILT_PRODUCTS_DIR; }; 9D6532EC2626240800105D50 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; @@ -111,7 +112,8 @@ 9D406ACB264A2B5800747EE9 /* babelfish_rez.h */, 9D406B2D2652155B00747EE9 /* babelfish_types.h */, 9D406ACD264A2BD300747EE9 /* markdown.rez */, - 9D406AD8264C50E400747EE9 /* init.c */, + 9D406AD8264C50E400747EE9 /* request.c */, + 9D406B312652D2C800747EE9 /* init.s */, 9D406AD9264C50F700747EE9 /* filter.s */, ); path = babelfish; diff --git a/md2teach.xcodeproj/xcuserdata/jrand.xcuserdatad/xcschemes/xcschememanagement.plist b/md2teach.xcodeproj/xcuserdata/jrand.xcuserdatad/xcschemes/xcschememanagement.plist index a1d7f13..38f213f 100644 --- a/md2teach.xcodeproj/xcuserdata/jrand.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/md2teach.xcodeproj/xcuserdata/jrand.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ Binary.xcscheme_^#shared#^_ orderHint - 2 + 1 doNotBuild.xcscheme_^#shared#^_ orderHint - 1 + 2 md2teach.xcscheme_^#shared#^_ diff --git a/md2teach/babelfish.mk b/md2teach/babelfish.mk index bf88885..5092ae6 100644 --- a/md2teach/babelfish.mk +++ b/md2teach/babelfish.mk @@ -185,8 +185,8 @@ $(OBJDIR)/babelfish/markdown.r: $(FILTERTARGET) $(INITTARGET) $(FILTERTARGET): $(OBJDIR)/babelfish/filter.ROOT cd $(OBJDIR); $(LINK) $(LDFLAGS) babelfish/filter keep="$(abspath $@)" -$(INITTARGET): $(OBJDIR)/babelfish/init.root $(OBJDIR)/md4c.a - cd $(OBJDIR); $(LINK) $(LDFLAGS) babelfish/init keep="$(abspath $@)" +$(INITTARGET): $(OBJDIR)/babelfish/init.ROOT $(OBJDIR)/babelfish/request.a $(OBJDIR)/md4c.a + cd $(OBJDIR); $(LINK) $(LDFLAGS) babelfish/init babelfish/request keep="$(abspath $@)" || rm "$(abspath $@)" $(TARGETDIR)/Markdown: $(OBJDIR)/babelfish/markdown.r $(MKDIR) $(TARGETDIR) diff --git a/md2teach/babelfish/babelfish_defs.h b/md2teach/babelfish/babelfish_defs.h index c06c9df..375ea93 100644 --- a/md2teach/babelfish/babelfish_defs.h +++ b/md2teach/babelfish/babelfish_defs.h @@ -46,4 +46,15 @@ #define TrShutDown 0x9102 #define TrRead 0x9103 +#define bfContinue 0 +#define bfDone 0x8000 +#define bfUserAbort 0x8001 +#define bfBadFileErr 0x8002 +#define bfReadErr 0x8003 +#define bfWriteErr 0x8004 +#define bfMemErr 0x8005 + +#define bfTextGetSettings 1 +#define bfTextBody 8 + #endif /* define _GUARD_PROJECTmd2teach_FILEbabelfish_defs_ */ diff --git a/md2teach/babelfish/babelfish_types.h b/md2teach/babelfish/babelfish_types.h index 2559153..f3d4bab 100644 --- a/md2teach/babelfish/babelfish_types.h +++ b/md2teach/babelfish/babelfish_types.h @@ -66,7 +66,7 @@ typedef struct TrTransferRecord Word currentTherm; char * msgPtr; TrDataRecord * dataRecordPtr; - char * filePathPtr; /* C string*/ + GSString255 * filePathPtr; char * fileNamePtr; /* P string */ } TrTransferRecord; diff --git a/md2teach/babelfish/init.c b/md2teach/babelfish/init.c deleted file mode 100644 index 8fbf23f..0000000 --- a/md2teach/babelfish/init.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * init.c - * md2teach - * - * Created by Jeremy Rand on 2021-05-12. - * Copyright (c) 2021 Jeremy Rand. All rights reserved. - * - */ - -#include - -#include -#include - -#include "babelfish/babelfish_defs.h" -#include "babelfish/babelfish_types.h" -#include "md4c.h" - - -#pragma memorymodel 1 -#pragma rtl - - -uint16_t myUserId; - - -void DoStartUp(TrStartUpDataIn * dataIn, TrStartUpDataOut * dataOut) -{ - -} - - -void DoShutDown(TrShutDownDataIn * dataIn, TrShutDownDataOut * dataOut) -{ - -} - - -void DoRead(TrReadDataIn * dataIn, TrReadDataOut * dataOut) -{ - -} - - -#pragma databank 1 -#pragma toolparms 1 - -pascal unsigned MyRequestProc(uint16_t request, uint32_t dataIn, uint32_t dataOut) -{ - switch (request) { - case TrStartUp: - DoStartUp((TrStartUpDataIn *)dataIn, (TrStartUpDataOut *)dataOut); - break; - - case TrShutDown: - DoShutDown((TrShutDownDataIn *)dataIn, (TrShutDownDataOut *)dataOut); - break; - - case TrRead: - DoRead((TrReadDataIn *)dataIn, (TrReadDataOut *)dataOut); - break; - - default: - break; - } - - return 0; -} - -#pragma toolparms 0 - - -int main(void) -{ - static char myName[48]; - - myUserId = MMStartUp(); - sprintf(myName, "Babelfish~Jeremy~MarkdownTrans%04x", myUserId); - AcceptRequests(myName, myUserId, MyRequestProc); - - return 0; -} - -#pragma databank 0 diff --git a/md2teach/babelfish/init.s b/md2teach/babelfish/init.s new file mode 100644 index 0000000..36af84f --- /dev/null +++ b/md2teach/babelfish/init.s @@ -0,0 +1,26 @@ +; +; init.s +; md2teach +; +; Created by Jeremy Rand on 2021-05-17. +; +; + + mcopy init.macros + case on + keep init + +init start + + phb + phk + plb + + + jsl setup + + plb + + rtl + + end diff --git a/md2teach/babelfish/request.c b/md2teach/babelfish/request.c new file mode 100644 index 0000000..d65e671 --- /dev/null +++ b/md2teach/babelfish/request.c @@ -0,0 +1,129 @@ +/* + * init.c + * md2teach + * + * Created by Jeremy Rand on 2021-05-12. + * Copyright (c) 2021 Jeremy Rand. All rights reserved. + * + */ + +#include +#include + +#include +#include +#include + +#include "babelfish/babelfish_defs.h" +#include "babelfish/babelfish_types.h" +#include "md4c.h" + + +#pragma memorymodel 1 + + +static uint16_t myUserId; +static TrTextDataRecord textRecord; + + +void DoStartUp(TrStartUpDataIn * dataIn, TrStartUpDataOut * dataOut) +{ + static recvCount = 0; + TrTransferRecord * xferRecPtr = dataIn->xferRecPtr; + + asm { + stz |lb1 + lb1: nop + nop + }; + + xferRecPtr->dataKinds[0] = TrFormatText; + xferRecPtr->dataKinds[1] = TrFormatNone; + xferRecPtr->dataKinds[2] = TrFormatNone; + xferRecPtr->dataKinds[3] = TrFormatNone; + xferRecPtr->dataKinds[4] = TrFormatNone; + xferRecPtr->dataKinds[5] = TrFormatNone; + xferRecPtr->dataKinds[6] = TrFormatNone; + xferRecPtr->dataKinds[7] = TrFormatNone; + xferRecPtr->fullTherm = 512; + xferRecPtr->currentTherm = 0; + xferRecPtr->dataRecordPtr = (TrDataRecord *)&textRecord; + + textRecord.parmCount = 10; + textRecord.actionCode = bfTextGetSettings; + textRecord.responseCode = 0; + textRecord.textStreamLength = 0; + textRecord.textStreamPtr = NULL; + textRecord.textStreamHandle = NULL; + textRecord.familyId = helvetica; + textRecord.fontSize = 12; + textRecord.foreColor = 0x0000; + textRecord.backColor = 0xffff; + textRecord.position = 0; + + recvCount++; + dataOut->recvCount = recvCount; + dataOut->trResult = bfContinue; +} + + +void DoShutDown(TrShutDownDataIn * dataIn, TrShutDownDataOut * dataOut) +{ + static recvCount = 0; + + recvCount++; + dataOut->recvCount = recvCount; + dataOut->trResult = bfContinue; +} + + +void DoRead(TrReadDataIn * dataIn, TrReadDataOut * dataOut) +{ + static recvCount = 0; + + recvCount++; + dataOut->recvCount = recvCount; + dataOut->trResult = bfContinue; +} + + +#pragma databank 1 +#pragma toolparms 1 + +pascal unsigned MyRequestProc(uint16_t request, uint32_t dataIn, uint32_t dataOut) +{ + switch (request) { + case TrStartUp: + DoStartUp((TrStartUpDataIn *)dataIn, (TrStartUpDataOut *)dataOut); + break; + + case TrShutDown: + DoShutDown((TrShutDownDataIn *)dataIn, (TrShutDownDataOut *)dataOut); + break; + + case TrRead: + DoRead((TrReadDataIn *)dataIn, (TrReadDataOut *)dataOut); + break; + + default: + break; + } + + return 0; +} + +#pragma toolparms 0 +#pragma databank 0 + +void setup(void) +{ + static char myName[48]; + + myUserId = MMStartUp(); + sprintf(myName+1, "Babelfish~Jeremy~MarkdownTrans%04x", myUserId); + *myName = strlen(myName+1); + + AcceptRequests(myName, myUserId, MyRequestProc); + + // return 0; +}