Add Apple /// Business BASIC file support

This commit is contained in:
David Schmidt 2008-12-16 03:35:37 +00:00
parent f94d519657
commit a4524898f9
9 changed files with 6191 additions and 5924 deletions

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -849,6 +849,7 @@ MainWindow::OnEditPreferences(void)
ps.fFviewPage.fConvPascalCode = fPreferences.GetPrefBool(kPrConvPascalCode);
ps.fFviewPage.fConvApplesoft = fPreferences.GetPrefBool(kPrConvApplesoft);
ps.fFviewPage.fConvInteger = fPreferences.GetPrefBool(kPrConvInteger);
ps.fFviewPage.fConvBusiness = fPreferences.GetPrefBool(kPrConvBusiness);
ps.fFviewPage.fConvGWP = fPreferences.GetPrefBool(kPrConvGWP);
ps.fFviewPage.fConvText8 = fPreferences.GetPrefBool(kPrConvText8);
ps.fFviewPage.fConvAWP = fPreferences.GetPrefBool(kPrConvAWP);
@ -974,6 +975,7 @@ MainWindow::ApplyNow(PrefsSheet* pPS)
fPreferences.SetPrefBool(kPrConvPascalCode, pPS->fFviewPage.fConvPascalCode != 0);
fPreferences.SetPrefBool(kPrConvApplesoft, pPS->fFviewPage.fConvApplesoft != 0);
fPreferences.SetPrefBool(kPrConvInteger, pPS->fFviewPage.fConvInteger != 0);
fPreferences.SetPrefBool(kPrConvBusiness, pPS->fFviewPage.fConvBusiness != 0);
fPreferences.SetPrefBool(kPrConvGWP, pPS->fFviewPage.fConvGWP != 0);
fPreferences.SetPrefBool(kPrConvText8, pPS->fFviewPage.fConvText8 != 0);
fPreferences.SetPrefBool(kPrConvAWP, pPS->fFviewPage.fConvAWP != 0);
@ -2610,6 +2612,10 @@ MainWindow::ConfigureReformatFromPreferences(ReformatHolder* pReformat)
pPreferences->GetPrefBool(kPrConvInteger));
pReformat->SetReformatAllowed(ReformatHolder::kReformatInteger_Hilite,
pPreferences->GetPrefBool(kPrConvInteger));
pReformat->SetReformatAllowed(ReformatHolder::kReformatBusiness,
pPreferences->GetPrefBool(kPrConvBusiness));
pReformat->SetReformatAllowed(ReformatHolder::kReformatBusiness_Hilite,
pPreferences->GetPrefBool(kPrConvBusiness));
pReformat->SetReformatAllowed(ReformatHolder::kReformatSCAssem,
pPreferences->GetPrefBool(kPrConvSCAssem));
pReformat->SetReformatAllowed(ReformatHolder::kReformatMerlin,

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -115,6 +115,7 @@ const Preferences::PrefMap Preferences::fPrefMaps[kPrefNumLastEntry] = {
{ kPrConvCPMText, kBool, kPrefsSect, _T("conv-cpm-text") },
{ kPrConvApplesoft, kBool, kPrefsSect, _T("conv-applesoft") },
{ kPrConvInteger, kBool, kPrefsSect, _T("conv-integer") },
{ kPrConvBusiness, kBool, kPrefsSect, _T("conv-business") },
{ kPrConvGWP, kBool, kPrefsSect, _T("conv-gwp") },
{ kPrConvText8, kBool, kPrefsSect, _T("conv-text8") },
{ kPrConvAWP, kBool, kPrefsSect, _T("conv-awp") },
@ -223,6 +224,7 @@ Preferences::Preferences(void)
SetPrefBool(kPrConvCPMText, true);
SetPrefBool(kPrConvApplesoft, true);
SetPrefBool(kPrConvInteger, true);
SetPrefBool(kPrConvBusiness, true);
SetPrefBool(kPrConvGWP, true);
SetPrefBool(kPrConvText8, true);
SetPrefBool(kPrConvAWP, true);

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -168,6 +168,7 @@ typedef enum {
kPrConvCPMText, // bool
kPrConvApplesoft, // bool
kPrConvInteger, // bool
kPrConvBusiness, // bool
kPrConvGWP, // bool
kPrConvText8, // bool
kPrConvAWP, // bool

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -152,6 +152,7 @@ public:
BOOL fConvPascalCode;
BOOL fConvApplesoft;
BOOL fConvInteger;
BOOL fConvBusiness;
BOOL fConvGWP;
BOOL fConvText8;
BOOL fConvAWP;

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -523,3 +523,230 @@ done:
bail:
return retval;
}
/*
* ===========================================================================
* Apple /// Business BASIC
* ===========================================================================
*/
/*
* Apple /// Business BASIC file format:
*
* <16-bit file length>
* <line> ...
* <EOF marker ($0000)>
*
* Each line consists of:
* <8-bit offset to next line>
* <16-bit line number, usually 0-63999>
* <tokens | characters> ...
* <EOL marker ($00)>
*
* All values are little-endian. Numbers are stored as characters.
*/
/*
* Decide whether or not we want to handle this file.
*/
void
ReformatBusiness::Examine(ReformatHolder* pHolder)
{
ReformatHolder::ReformatApplies applies = ReformatHolder::kApplicNot;
if (pHolder->GetFileType() == kTypeBA3)
applies = ReformatHolder::kApplicYes;
pHolder->SetApplic(ReformatHolder::kReformatBusiness, applies,
ReformatHolder::kApplicNot, ReformatHolder::kApplicNot);
pHolder->SetApplic(ReformatHolder::kReformatBusiness_Hilite, applies,
ReformatHolder::kApplicNot, ReformatHolder::kApplicNot);
if (pHolder->GetOption(ReformatHolder::kOptHiliteBASIC) != 0)
pHolder->SetApplicPreferred(ReformatHolder::kReformatBusiness_Hilite);
else
pHolder->SetApplicPreferred(ReformatHolder::kReformatBusiness);
}
/*
* Values from 128 to 234 are tokens in Business BASIC. Values from 235 to 255
* show up as error messages. The goal here is to produce values that are
* human-readable and/or EXECable, so no attempt has been made to display
* the error values.
*/
static const char gBusinessTokens[128*10] = {
"END\0 FOR\0 NEXT\0 INPUT\0 OUTPUT\0 DIM\0 READ\0 WRITE\0 "
"OPEN\0 CLOSE\0 *error*\0 TEXT\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 WINDOW\0 INVOKE\0 PERFORM\0 *error*\0 *error*\0 "
"FRE\0 HPOS\0 VPOS\0 ERRLIN\0 ERR\0 KBD\0 EOF\0 TIME$\0 "
"DATE$\0 PREFIX$\0 EXFN.\0 EXFN%.\0 OUTREC\0 INDENT\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 POP\0 HOME\0 *error*\0 "
"SUB$(\0 OFF\0 TRACE\0 NOTRACE\0 NORMAL\0 INVERSE\0 SCALE(\0 RESUME\0 "
"*error*\0 LET\0 GOTO\0 IF\0 RESTORE\0 SWAP\0 GOSUB\0 RETURN\0 "
"REM\0 STOP\0 ON\0 *error*\0 LOAD\0 SAVE\0 DELETE\0 RUN\0 "
"RENAME\0 LOCK\0 UNLOCK\0 CREATE\0 EXEC\0 CHAIN\0 *error*\0 *error*\0 "
"*error*\0 CATALOG\0 *error*\0 *error*\0 DATA\0 IMAGE\0 CAT\0 DEF\0 "
"*error*\0 PRINT\0 DEL\0 ELSE\0 CONT\0 LIST\0 CLEAR\0 GET\0 "
"NEW\0 TAB\0 TO\0 SPC(\0 USING\0 THEN\0 *error*\0 MOD\0 "
"STEP\0 AND\0 OR\0 EXTENSION\0DIV\0 *error*\0 FN\0 NOT\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 tf7\0 "
};
static const char gExtendedBusinessTokens[128*10] = {
"TAB(\0 TO\0 SPC(\0 USING\0 THEN\0 *error*\0 MOD\0 STEP\0 "
"AND\0 OR\0 EXTENSION\0DIV\0 *error*\0 FN\0 NOT\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 AS\0 SGN(\0 INT(\0 ABS(\0 "
"*error*\0 TYP(\0 REC(\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 PDL(\0 BUTTON(\0 SQR(\0 "
"RND(\0 LOG(\0 EXP(\0 COS(\0 SIN(\0 TAN(\0 ATN(\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 STR$(\0 HEX$(\0 CHR$(\0 LEN(\0 VAL(\0 "
"ASC(\0 TEN(\0 *error*\0 *error*\0 CONV(\0 CONV&(\0 CONV$(\0 CONV%(\0 "
"LEFT$(\0 RIGHT$(\0 MID$(\0 INSTR$(\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
"*error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 *error*\0 "
};
/*
* Reformat an Apple /// Business BASIC program into a text format that
* mimics the output of the "LIST" command.
*/
int
ReformatBusiness::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
if (srcLen > 65536)
fUseRTF = false;
if (fUseRTF) {
if (id != ReformatHolder::kReformatBusiness_Hilite)
fUseRTF = false;
}
RTFBegin(kRTFFlagColorTable);
/*
* Make sure there's enough here to get started. We want to return an
* "okay" result because we want this treated like a reformatted empty
* BASIC program rather than a non-Applesoft file.
*/
if (length < 2) {
WMSG0(" BAS truncated?\n");
//fExpBuf.CreateWorkBuf();
BufPrintf("\r\n");
goto done;
}
unsigned short fileLength;
fileLength = Read16(&srcPtr, &length);
WMSG1(" BA3 internal file length is: %d\n", fileLength);
while (length > 0) {
unsigned short increment;
unsigned short extendedToken;
unsigned short lineNum;
bool inQuote = false;
bool inRem = false;
increment = Read8(&srcPtr, &length);
WMSG1(" BA3 increment to next line is: %d\n", increment);
if (increment == 0) {
/* ProDOS sticks an extra byte on the end? */
if (length > 1) {
WMSG1(" BAS ended early; len is %d\n", length);
}
break;
}
/* print line number */
RTFSetColor(kLineNumColor);
lineNum = Read16(&srcPtr, &length);
WMSG1(" BA3 line number: %d\n", lineNum);
BufPrintf(" %u ", lineNum);
RTFSetColor(kDefaultColor);
/* print a line */
while (*srcPtr != 0 && length > 0) {
if (*srcPtr & 0x80) {
/* token */
//RTFBoldOn();
RTFSetColor(kKeywordColor);
if (((*srcPtr) & 0x7f) == 0x7f)
{
extendedToken = Read8(&srcPtr, &length);
BufPrintf(" %s ", &gExtendedBusinessTokens[((*srcPtr) & 0x7f) * 10]);
}
else
BufPrintf(" %s ", &gBusinessTokens[((*srcPtr) & 0x7f) * 10]);
//RTFBoldOff();
RTFSetColor(kDefaultColor);
if (*srcPtr == 0xc0) {
// REM -- do rest of line in green
RTFSetColor(kCommentColor);
inRem = true;
}
} else {
/* simple chracter */
if (fUseRTF) {
if (*srcPtr == '"' && !inRem) {
if (!inQuote) {
RTFSetColor(kStringColor);
RTFPrintChar(*srcPtr);
} else {
RTFPrintChar(*srcPtr);
RTFSetColor(kDefaultColor);
}
inQuote = !inQuote;
} else if (*srcPtr == ':' && !inRem && !inQuote) {
RTFSetColor(kColonColor);
RTFPrintChar(*srcPtr);
RTFSetColor(kDefaultColor);
} else {
RTFPrintChar(*srcPtr);
}
} else {
BufPrintf("%c", *srcPtr);
}
}
srcPtr++;
length--;
}
if (inQuote || inRem)
RTFSetColor(kDefaultColor);
inQuote = inRem = false;
srcPtr++;
length--;
if (!length) {
WMSG0(" BAS truncated in mid-line\n");
break;
}
RTFNewPara();
}
done:
RTFEnd();
SetResultBuffer(pOutput);
retval = 0;
//bail:
return retval;
}

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -43,4 +43,22 @@ public:
ReformatOutput* pOutput);
};
/*
* Reformat an Apple /// Business BASIC program into readable text.
*/
class ReformatBusiness : public ReformatText {
public:
ReformatBusiness(void) {}
virtual ~ReformatBusiness(void) {}
virtual void Examine(ReformatHolder* pHolder);
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput);
/* share our token list with others - but this won't really work in its current form... */
enum { kTokenLen = 10, kTokenCount = 107 };
static const char* GetBusinessTokens(void);
};
#endif /*__LR_BASIC__*/

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -50,6 +50,8 @@ ReformatHolder::GetReformatInstance(ReformatID id)
case kReformatApplesoft_Hilite: pReformat = new ReformatApplesoft; break;
case kReformatInteger: pReformat = new ReformatInteger; break;
case kReformatInteger_Hilite: pReformat = new ReformatInteger; break;
case kReformatBusiness: pReformat = new ReformatBusiness; break;
case kReformatBusiness_Hilite: pReformat = new ReformatBusiness; break;
case kReformatSCAssem: pReformat = new ReformatSCAssem; break;
case kReformatMerlin: pReformat = new ReformatMerlin; break;
case kReformatLISA2: pReformat = new ReformatLISA2; break;
@ -141,6 +143,12 @@ ReformatHolder::GetReformatName(ReformatID id)
case kReformatInteger_Hilite:
descr = "Integer BASIC w/Highlighting";
break;
case kReformatBusiness:
descr = "Apple /// Business BASIC";
break;
case kReformatBusiness_Hilite:
descr = "Apple /// Business BASIC w/Highlighting";
break;
case kReformatSCAssem:
descr = "S-C Assembler";
break;

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -76,6 +76,8 @@ public:
kReformatApplesoft_Hilite,
kReformatInteger,
kReformatInteger_Hilite,
kReformatBusiness,
kReformatBusiness_Hilite,
kReformatSCAssem,
kReformatMerlin,
@ -278,6 +280,7 @@ public:
friend class ReformatDisasm16;
friend class ReformatApplesoft;
friend class ReformatInteger;
friend class ReformatBusiness;
friend class ReformatCPMText;
friend class ReformatDirectory;
friend class ReformatDHR;

View File

@ -1,6 +1,6 @@
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* Copyright (C) 2007, 2008 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
@ -36,6 +36,7 @@ public:
kTypeTXT = 0x04,
kTypeBIN = 0x06,
kTypeFOT = 0x08,
kTypeBA3 = 0x09,
kTypeDIR = 0x0f,
kTypeADB = 0x19,
kTypeAWP = 0x1a,