ciderpress/reformat/Asm.h

297 lines
7.9 KiB
C
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Reformat assembly-language source code.
*/
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#ifndef REFORMAT_ASM_H
#define REFORMAT_ASM_H
2007-03-27 17:47:10 +00:00
#include "ReformatBase.h"
/*
* Base class for assembly source conversion.
*
* We want to tab to certain offsets, either hard coded or found in the source
* file. To make this work right we want to buffer each line of output. The
* maximum line length is bounded by the editor.
*/
class ReformatAsm : public ReformatText {
public:
ReformatAsm(void) : fOutBuf(), fOutBufIndex(0) {}
virtual ~ReformatAsm(void) {}
2007-03-27 17:47:10 +00:00
void OutputStart(void) {
2007-03-27 17:47:10 +00:00
fOutBufIndex = 0;
memset(fOutBuf, ' ', kMaxLineLen);
}
void OutputFinish(void) {
2007-03-27 17:47:10 +00:00
Output('\0');
}
void Output(char ch) {
if (fOutBufIndex < kMaxLineLen)
fOutBuf[fOutBufIndex++] = ch;
}
void Output(const char* str) {
int len = strlen(str);
if (fOutBufIndex + len > kMaxLineLen)
len = kMaxLineLen - fOutBufIndex;
if (len > 0) {
memcpy(fOutBuf + fOutBufIndex, str, len);
fOutBufIndex += len;
}
}
void OutputTab(int posn) {
if (posn < kMaxLineLen && posn > fOutBufIndex)
fOutBufIndex = posn;
else
Output(' '); // always at least one
}
const char* GetOutBuf(void) const { return fOutBuf; }
2007-03-27 17:47:10 +00:00
private:
enum {
kMaxLineLen = 128,
};
2007-03-27 17:47:10 +00:00
char fOutBuf[kMaxLineLen+1];
int fOutBufIndex;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an S-C Assembler listing into readable text.
*/
class ReformatSCAssem : public ReformatText {
public:
ReformatSCAssem(void) {}
virtual ~ReformatSCAssem(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
/* this gets called by Integer BASIC converter */
static bool IsSCAssem(const ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
};
/*
* Reformat Merlin listing to have tabs.
*/
class ReformatMerlin : public ReformatAsm {
public:
ReformatMerlin(void) {}
virtual ~ReformatMerlin(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
static bool IsMerlin(const ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
};
/*
* Reformat LISA v2 (DOS) sources.
*/
class ReformatLISA2 : public ReformatAsm {
public:
ReformatLISA2(void) {}
virtual ~ReformatLISA2(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
bool IsLISA(const ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
enum {
kOpTab = 9,
kAdTab = 13,
kComTab = 39,
};
2007-03-27 17:47:10 +00:00
void ProcessLine(const uint8_t* buf);
2007-03-27 17:47:10 +00:00
};
/*
* Reformat LISA v3 (ProDOS) sources.
*/
class ReformatLISA3 : public ReformatAsm {
public:
ReformatLISA3(void) : fSymTab(NULL), fSymCount(0) {}
virtual ~ReformatLISA3(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
static bool IsLISA(const ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
private:
typedef enum OperandResult {
kResultUnknown = 0,
kResultFailed,
kResultGotoOutOprtr,
kResultGotoOutOprnd,
} OperandResult;
void ProcessLine(const uint8_t* codePtr, int len);
void ConvertOperand(uint8_t mnemonic, const uint8_t** pCodePtr,
int* pLen);
OperandResult PrintNum(int adrsMode, uint8_t val,
const uint8_t** pCodePtr, int* pLen);
OperandResult PrintComplexOperand(uint8_t opr,
const uint8_t** pCodePtr, int* pLen);
void PrintSymEntry(int ent);
void PrintMnemonic(uint8_t val);
void PrintBin(uint8_t val);
void PrintComment(int adrsMode, const uint8_t* ptr, int len);
enum {
kHeaderLen = 4,
kOpTab = 9,
kAdTab = 18,
kComTab = 40,
};
/* token constants, from LISA.MNEMONICS */
enum {
kLCLTKN = 0xF0,
kLBLTKN = 0xFA,
// 0xFB used to indicate "second half" of symbol table
kMACTKN = 0xFC,
// 0xFD used to indicate "second half" of symbol table
kCMNTTKN = 0xFE,
kSN = 0x00,
kSS = 0xB0,
kGROUP1 = 0x00,
kGROUP2 = 0x0b,
kGROUP3 = 0x11,
kGROUP4 = 0x24,
kGROUP5 = 0x29,
kGROUP6 = 0x34,
kGROUP7 = 0x39,
kGROUP8 = 0x3f,
kGROUP9 = 0x4a,
};
const uint8_t* fSymTab;
uint16_t fSymCount;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat LISA v4/v5 (ProDOS and GS/OS) sources.
*/
class ReformatLISA4 : public ReformatAsm {
public:
ReformatLISA4(void) :
fSymTab(NULL),
fSymCount(0),
fOpTab(0),
fAdTab(0),
fComTab(0),
fCpuType(0)
{}
virtual ~ReformatLISA4(void) { delete[] fSymTab; }
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
static bool IsLISA(const ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
private:
enum {
kHeaderLen = 16,
};
/* token constants, from MNEMONICS.A */
enum {
kBigndec4_tkn = 0x00,
kBignhex4_tkn = 0x01,
kBignbin4_tkn = 0x02,
kBignhexs_tkn = 0x03,
kBignstring_tkn = 0x04,
kDec1_tkn = 0x1a,
kDec2_tkn = 0x1b,
kHex1_tkn = 0x1c,
kHex2_tkn = 0x1d,
kBin1_tkn = 0x1e,
kBin2_tkn = 0x1f,
kBign_tkn = 0x33,
kDec3_tkn = 0x34,
kHex3_tkn = 0x35,
kBin3_tkn = 0x36,
kcABS_tkn = 0x37,
kcLONG_tkn = 0x38,
kMVN_tkn = 0x41,
kMVP_tkn = 0x42,
kMacE_tkn = 0x5e,
kStr31_tkn = 0x7f,
kSS = 0x90,
//kGROUP1_tkns = 0x01,
//kGROUP2_tkns = 0x0c,
kGROUP3_tkns = 0x12,
//kGROUP4_tkns = 0x29,
kGROUP5_tkns = 0x30,
kGROUP6_tkns = 0x43,
//kGROUP7_tkns = 0x4a,
//kGROUP8_tkns = 0x51,
//kGROUP9_tkns = 0x5f,
kLocalTKN = 0xf0,
kLabelTKN = 0xfa,
kMacroTKN = 0xfc,
kErrlnTKN = 0xfd, // "is BlankTKN by itself"
kBlankTKN = 0xfd,
kCommentTKN = 0xfe,
kComntStarTKN = 0xfe,
kComntSemiTKN = 0xff,
};
typedef enum OperandResult {
kResultUnknown = 0,
kResultFailed,
kResultGotoOutOprtr,
kResultGotoOutOprnd,
} OperandResult;
void ProcessLine(const uint8_t* codePtr, int len);
void ConvertOperand(uint8_t mnemonic, const uint8_t** pCodePtr,
int* pLen);
void PrintSymEntry(int ent);
OperandResult PrintNum(uint8_t opr, const uint8_t** pCodePtr,
int* pLen);
OperandResult PrintComplexOperand(uint8_t opr,
const uint8_t** pCodePtr, int* pLen);
void PrintDec(int count, const uint8_t** pCodePtr, int* pLen);
void PrintHex(int count, const uint8_t** pCodePtr, int* pLen);
void PrintBin(int count, const uint8_t** pCodePtr, int* pLen);
const uint8_t** fSymTab;
uint16_t fSymCount;
uint8_t fOpTab;
uint8_t fAdTab;
uint8_t fComTab;
uint8_t fCpuType;
2007-03-27 17:47:10 +00:00
};
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#endif /*REFORMAT_ASM_H*/