📄 dsp3emu.cpp
字号:
break;
}
case 6:
{
DSP3_DR = DSP3_X;
break;
}
case 7:
{
DSP3_DR = DSP3_Y;
DSP3_Index = 0;
break;
}
}
}
uint8 DSP3_Bitmap[8];
uint8 DSP3_Bitplane[8];
uint16 DSP3_BMIndex;
uint16 DSP3_BPIndex;
uint16 DSP3_Count;
void DSP3_Convert_A()
{
if (DSP3_BMIndex < 8)
{
DSP3_Bitmap[DSP3_BMIndex++] = (uint8) (DSP3_DR);
DSP3_Bitmap[DSP3_BMIndex++] = (uint8) (DSP3_DR >> 8);
if (DSP3_BMIndex == 8)
{
for (short i=0; i < 8; i++)
for (short j=0; j < 8; j++)
{
DSP3_Bitplane[j] <<= 1;
DSP3_Bitplane[j] |= (DSP3_Bitmap[i] >> j) & 1;
}
DSP3_BPIndex = 0;
DSP3_Count--;
}
}
if (DSP3_BMIndex == 8)
{
if (DSP3_BPIndex == 8)
{
if (!DSP3_Count) DSP3_Reset();
DSP3_BMIndex = 0;
}
else
{
DSP3_DR = DSP3_Bitplane[DSP3_BPIndex++];
DSP3_DR |= DSP3_Bitplane[DSP3_BPIndex++] << 8;
}
}
}
void DSP3_Convert()
{
DSP3_Count = DSP3_DR;
DSP3_BMIndex = 0;
SetDSP3 = &DSP3_Convert_A;
}
bool DSP3_GetBits(uint8 Count)
{
if (!DSP3_BitsLeft)
{
DSP3_BitsLeft = Count;
DSP3_ReqBits = 0;
}
do {
if (!DSP3_BitCount)
{
DSP3_SR = 0xC0;
return false;
}
DSP3_ReqBits <<= 1;
if (DSP3_ReqData & 0x8000) DSP3_ReqBits++;
DSP3_ReqData <<= 1;
DSP3_BitCount--;
DSP3_BitsLeft--;
} while (DSP3_BitsLeft);
return true;
}
void DSP3_Decode_Data()
{
if (!DSP3_BitCount)
{
if (DSP3_SR & 0x40)
{
DSP3_ReqData = DSP3_DR;
DSP3_BitCount += 16;
}
else
{
DSP3_SR = 0xC0;
return;
}
}
if (DSP3_LZCode == 1)
{
if (!DSP3_GetBits(1))
return;
if (DSP3_ReqBits)
DSP3_LZLength = 12;
else
DSP3_LZLength = 8;
DSP3_LZCode++;
}
if (DSP3_LZCode == 2)
{
if (!DSP3_GetBits(DSP3_LZLength))
return;
DSP3_LZCode = 0;
DSP3_Outwords--;
if (!DSP3_Outwords) SetDSP3 = &DSP3_Reset;
DSP3_SR = 0x80;
DSP3_DR = DSP3_ReqBits;
return;
}
if (DSP3_BaseCode == 0xffff)
{
if (!DSP3_GetBits(DSP3_BaseLength))
return;
DSP3_BaseCode = DSP3_ReqBits;
}
if (!DSP3_GetBits(DSP3_CodeLengths[DSP3_BaseCode]))
return;
DSP3_Symbol = DSP3_Codes[DSP3_CodeOffsets[DSP3_BaseCode] + DSP3_ReqBits];
DSP3_BaseCode = 0xffff;
if (DSP3_Symbol & 0xff00)
{
DSP3_Symbol += 0x7f02;
DSP3_LZCode++;
}
else
{
DSP3_Outwords--;
if (!DSP3_Outwords)
SetDSP3 = &DSP3_Reset;
}
DSP3_SR = 0x80;
DSP3_DR = DSP3_Symbol;
}
void DSP3_Decode_Tree()
{
if (!DSP3_BitCount)
{
DSP3_ReqData = DSP3_DR;
DSP3_BitCount += 16;
}
if (!DSP3_BaseCodes)
{
DSP3_GetBits(1);
if (DSP3_ReqBits)
{
DSP3_BaseLength = 3;
DSP3_BaseCodes = 8;
}
else
{
DSP3_BaseLength = 2;
DSP3_BaseCodes = 4;
}
}
while (DSP3_BaseCodes)
{
if (!DSP3_GetBits(3))
return;
DSP3_ReqBits++;
DSP3_CodeLengths[DSP3_Index] = (uint8) DSP3_ReqBits;
DSP3_CodeOffsets[DSP3_Index] = DSP3_Symbol;
DSP3_Index++;
DSP3_Symbol += 1 << DSP3_ReqBits;
DSP3_BaseCodes--;
}
DSP3_BaseCode = 0xffff;
DSP3_LZCode = 0;
SetDSP3 = &DSP3_Decode_Data;
if (DSP3_BitCount) DSP3_Decode_Data();
}
void DSP3_Decode_Symbols()
{
DSP3_ReqData = DSP3_DR;
DSP3_BitCount += 16;
do {
if (DSP3_BitCommand == 0xffff)
{
if (!DSP3_GetBits(2)) return;
DSP3_BitCommand = DSP3_ReqBits;
}
switch (DSP3_BitCommand)
{
case 0:
{
if (!DSP3_GetBits(9)) return;
DSP3_Symbol = DSP3_ReqBits;
break;
}
case 1:
{
DSP3_Symbol++;
break;
}
case 2:
{
if (!DSP3_GetBits(1)) return;
DSP3_Symbol += 2 + DSP3_ReqBits;
break;
}
case 3:
{
if (!DSP3_GetBits(4)) return;
DSP3_Symbol += 4 + DSP3_ReqBits;
break;
}
}
DSP3_BitCommand = 0xffff;
DSP3_Codes[DSP3_Index++] = DSP3_Symbol;
DSP3_Codewords--;
} while (DSP3_Codewords);
DSP3_Index = 0;
DSP3_Symbol = 0;
DSP3_BaseCodes = 0;
SetDSP3 = &DSP3_Decode_Tree;
if (DSP3_BitCount) DSP3_Decode_Tree();
}
void DSP3_Decode_A()
{
DSP3_Outwords = DSP3_DR;
SetDSP3 = &DSP3_Decode_Symbols;
DSP3_BitCount = 0;
DSP3_BitsLeft = 0;
DSP3_Symbol = 0;
DSP3_Index = 0;
DSP3_BitCommand = 0xffff;
DSP3_SR = 0xC0;
}
void DSP3_Decode()
{
DSP3_Codewords = DSP3_DR;
SetDSP3 = &DSP3_Decode_A;
}
void DSP3_Command()
{
if (DSP3_DR < 0x40)
{
switch (DSP3_DR)
{
case 0x02: SetDSP3 = &DSP3_Coordinate; break;
case 0x03: SetDSP3 = &DSP3_OP03; break;
case 0x06: SetDSP3 = &DSP3_OP06; break;
case 0x07: SetDSP3 = &DSP3_OP07; return;
case 0x0f: SetDSP3 = &DSP3_TestMemory; break;
case 0x18: SetDSP3 = &DSP3_Convert; break;
case 0x1f: SetDSP3 = &DSP3_MemoryDump; break;
case 0x2f: SetDSP3 = &DSP3_MemorySize; break;
case 0x38: SetDSP3 = &DSP3_Decode; break;
}
DSP3_SR = 0x0080;
DSP3_Index = 0;
}
}
void DSP3_Reset()
{
DSP3_DR = 0x0080;
DSP3_SR = 0x0084;
SetDSP3 = &DSP3_Command;
}
void DSP3SetByte(uint8 byte, uint16 address)
{
if ((address & 0xC000) == 0x8000)
{
if (DSP3_SR & 0x04)
{
DSP3_DR = (DSP3_DR & 0xff00) + byte;
(*SetDSP3)();
}
else
{
DSP3_SR ^= 0x10;
if (DSP3_SR & 0x10)
DSP3_DR = (DSP3_DR & 0xff00) + byte;
else
{
DSP3_DR = (DSP3_DR & 0x00ff) + (byte << 8);
(*SetDSP3)();
}
}
}
}
uint8 DSP3GetByte(uint16 address)
{
if ((address & 0xC000) == 0x8000)
{
uint8 byte;
if (DSP3_SR & 0x04)
{
byte = (uint8) DSP3_DR;
(*SetDSP3)();
}
else
{
DSP3_SR ^= 0x10;
if (DSP3_SR & 0x10)
byte = (uint8) (DSP3_DR);
else
{
byte = (uint8) (DSP3_DR >> 8);
(*SetDSP3)();
}
}
return byte;
}
return (uint8) DSP3_SR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -