DSP3 Gamepaks
SDガンダムGX (SD Gundam GX)
DSP3 Status Register
|
The following information should be used in addition
to the information specified for the DSP1 Status Register.
|
The User Flag 1 (USF1) indicates the type of request required by the DSP
Program (Used with specified commands only).
"0" : Program is requesting Data Register read.
"1" : Program is requesting Data Register write.
DSP3 Memory Mapping
|
PCB
|
Mode
|
Memory Size
|
Bank
|
Data Register (DR)
|
Status Register (SR)
|
|
SHVC-1B3B-01
|
20H
|
8M MASKROM 64K SRAM
|
20H ~ 3FH
|
8000H ~ BFFFH
|
C000H ~ FFFFH
|
DSP3 Commands
|
The DSP functions inherently similiar to the DSP1 with
respect to command parsing and execution. On completion of a valid command
the Data Register should contain the value 0x80.
|
| Command |
Description |
Status |
|
02H
|
Unknown
|
|
|
03H
|
Calculate Cell Offset
|
Bit Perfect
|
|
06H
|
Set Board Dimensions
|
Bit Perfect
|
|
07H
|
Calculate Adjacent Cell
|
|
|
18H
|
Convert Bitmap to Bitplane
|
Bit Perfect
|
|
1EH
|
Calculate Path of Least Travel
|
|
|
38H
|
Decode Shannon-Fano Bitstream [USF1]
|
Bit Perfect
|
|
3EH
|
Set Start Cell
|
Bit Perfect
|
|
0FH
|
Memory Test
|
|
1FH
|
Transfer DATA ROM
|
|
2FH
|
ROM Version
|
DSP3 Source Code Contributors
The Dumper (Electrical Engineering), Overload (Computer Science)
// dsp3.cpp
uint8 StartRow;
uint8 StartColumn;
uint8 NumberOfRows;
uint8 NumberOfColumns;
03H - Calculate Cell Offset (Bit Perfect)
|
Input
|
byte(03H) byte(Column) byte(Row)
|
|
Output
|
integer(Offset)
|
void DSP3_CellOfs(uint8 Column, uint8 Row, int16 &Offset)
{
Offset = ((NumberOfColumns * Row) + Column) << 1;
Offset >>= 1;
}
06H - Set Board Dimensions (Bit Perfect)
|
Input
|
byte(06H) byte(Columns) byte(Rows)
|
|
Output
|
None
|
void DSP3_GridSize(uint8 Columns, uint8 Rows)
{
NumberOfColumns = Columns;
NumberOfRows = Rows;
}
07H - Calculate Adjacent Cell
|
Input
|
byte(07H) byte(Position) byte(Column) byte(Row)
|
|
Output
|
byte(Column) byte(Row) integer(Offset)
|
|
|
|
|
Calculates the coordinates and the offset of an adjacent cell.
|
void DSP3_NextCell(uint8 Position, uint8 &Column, uint8 &Row, int16 &Offset)
{
uint16 dataOfs = ((Position << 1) + 0x03b2) & 0x03ff;
nRow = DSP3_DataROM[dataOfs];
nColumn = DSP3_DataROM[dataOfs + 1];
if (Column & 1) nRow += (nColumn & 1);
uint8 nColumn += Column;
uint8 nRow += Row;
if (nColumn < 0)
nColumn += NumberOfColumns;
else
if (nColumn >= NumberOfColumns)
nColumn -= NumberOfColumns;
if (nRow < 0)
nRow += NumberOfRows;
else
if (nRow >= NumberOfRows)
nRow -= NumberOfRows;
Column = nColumn | ((nRow >> 8) & 0xff);
Row = nRow;
Offset = ((NumberOfColumns * nRow) + nColumn) << 1;
Offset >>= 1;
}
18H - Convert Bitmap to Bitplane (Bit Perfect)
|
Input
|
byte(18H) integer(Count) byte(Bitmap[8])
|
|
Output
|
byte(Bitplane[8])
|
|
|
|
|
Count
|
The number of times this command is repeated
|
void DSP3_Convert(uint8 Bitmap[8], uint8 Bitplane[8])
{
for (short i=0; i < 8; i++)
for (short j=0; j < 8; j++)
{
Bitplane[j] <<= 1;
Bitplane[j] |= (Bitmap[i] >> j) & 1;
}
}
1EH - Calculate Path of Least Travel
38H - Decode Shannon-Fano Bitstream [USF1] (Bit Perfect)
|
Input
|
byte(38H) integer(Symbols) integer(Count) integer[Undefined]
|
|
Output
|
integer[Undefined]
|
|
|
|
|
Symbols
|
The number of symbols in the Shannon-Fano tree.
|
|
Count
|
The number of symbols output before the command terminates.
|
|
Three bitstreams follow the two parameters specified and are used in
conjunction to decode the output codes. The first stream is used to build the
symbol table. All decoded symbols are 9 bits in length and are specifically a
free or Lempel-Ziv code (Bit 8 set denotes an LZ code). Four main codes are
used to decode the symbol table. Each code is used to build the next symbol in
the table. Where bits are required they will follow in the stream. Once the
number of symbols specified has been decoded the end of stream is determined.
|
(0,0) Load new symbol (9 bits)
(0,1) Add 1 to the current symbol
(1,0) Add 2 + (1 bit) to the current symbol
(1,1) Add 4 + (4 bits) to the current symbol
Note: LZ Codes need to be reformated for output (e.g. 0x0100 = LZ (2) = 0x8002)
The next short stream of 13 or 25 bits is used to build the Shannon-Fano Tree.
The first bit of the stream is used to specify the number of base-level parent
nodes, either 2 or 3 respectively. Three bits follow for each of the base-level
children which determine the number of extended-level parent nodes. The data
stream follows last.
Example (2nd Level Parents)
|
Bitstream: (0) 000,000,001,010
(0,0,x) 1 Parent (Base), 0 Parent (Extended), 2 Child
(0,1,x) 1 Parent (Base), 0 Parent (Extended), 2 Child
(1,0,x,x) 1 Parent (Base), 1 Parent (Extended), 4 Child
(1,1,x,x,x) 1 Parent (Base), 2 Parent (Extended), 8 Child
|
Example (3rd Level Parents)
|
Bitstream: (1) 000,001,001,010,011,100,101,110
(0,0,0,x) 1 Parent (Base), 0 Parent (Extended), 2 Child
(0,0,1,x,x) 1 Parent (Base), 1 Parent (Extended), 4 Child
(0,1,0,x,x) 1 Parent (Base), 1 Parent (Extended), 4 Child
(0,1,1,x,x,x) 1 Parent (Base), 2 Parent (Extended), 8 Child
(1,0,0,x,x,x,x) 1 Parent (Base), 3 Parent (Extended), 16 Child
(1,0,1,x,x,x,x,x) 1 Parent (Base), 4 Parent (Extended), 32 Child
(1,1,0,x,x,x,x,x,x) 1 Parent (Base), 5 Parent (Extended), 64 Child
(1,1,1,x,x,x,x,x,x,x) 1 Parent (Base), 6 Parent (Extended), 128 Child
|
The easist way to read the encoded data stream is to build an offset table for
the symbols. The offset table can be constructed by adding the number of
childless nodes for each base-level branch to the previous offset starting with
an offset of 0.
|
// BaseNodes is the number of base-level parent nodes
// ParentExt is the number of extended-level parent nodes for each base-level child node
BaseOffset[0] = 0;
for (int Branch = 1; Branch < (1 << BaseNodes); Branch++);
BaseOffset[Branch] = BaseOffset[Branch - 1] + (1 << (ParentExt[Branch - 1] + 1));
First read the number of base-level bits and use this value to obtain the
coresponding offset and number of extended-level bits to be read. Read the
extended-level bits (plus 1 for childless nodes) and add this value to the
base-level offset. Obtain the coresponding symbol from the table. In the case
where a symbol representing an LZ Code is obtained, an offset shall follow. The
length of the offset is either 8 or 12 bits and is determined by the next bit
in the stream. Once the number of output symbols has been reached the command
will terminate.
Sample stream partially decoded
|
3EH - Set Start Cell (Bit Perfect)
|
Input
|
byte(3EH) byte(Column) byte(Row)
|
|
Output
|
integer(Offset)
|
void DSP3_StartCell(uint8 Column, uint8 Row, int16 &Offset)
{
DSP3_CellOfs(Column, Row, Offset);
StartColumn = Column;
StartRow = Row;
}
0FH - Memory Test
|
Input
|
byte(0FH) integer(Undefined)
|
|
Output
|
integer(Result)
|
|
Used to test internal RAM, will return 0 if completed successfully
|
short DSP3_MemoryTest()
{
return 0x0000;
}
1FH - Transfer DATA ROM
|
Input
|
byte(1FH) integer(Undefined)
|
|
Output
|
integer[1024]
|
|
Transfers the entire contents of the Data ROM
|
const short DATAROM[1024] = {
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100,
0x0000, 0x000f, 0x0400, 0x0200, 0x0140, 0x0400, 0x0200, 0x0040,
0x007d, 0x007e, 0x007e, 0x007b, 0x007c, 0x007d, 0x007b, 0x007c,
0x0002, 0x0020, 0x0030, 0x0000, 0x000d, 0x0019, 0x0026, 0x0032,
0x003e, 0x004a, 0x0056, 0x0062, 0x006d, 0x0079, 0x0084, 0x008e,
0x0098, 0x00a2, 0x00ac, 0x00b5, 0x00be, 0x00c6, 0x00ce, 0x00d5,
0x00dc, 0x00e2, 0x00e7, 0x00ec, 0x00f1, 0x00f5, 0x00f8, 0x00fb,
0x00fd, 0x00ff, 0x0100, 0x0100, 0x0100, 0x00ff, 0x00fd, 0x00fb,
0x00f8, 0x00f5, 0x00f1, 0x00ed, 0x00e7, 0x00e2, 0x00dc, 0x00d5,
0x00ce, 0x00c6, 0x00be, 0x00b5, 0x00ac, 0x00a2, 0x0099, 0x008e,
0x0084, 0x0079, 0x006e, 0x0062, 0x0056, 0x004a, 0x003e, 0x0032,
0x0026, 0x0019, 0x000d, 0x0000, 0xfff3, 0xffe7, 0xffdb, 0xffce,
0xffc2, 0xffb6, 0xffaa, 0xff9e, 0xff93, 0xff87, 0xff7d, 0xff72,
0xff68, 0xff5e, 0xff54, 0xff4b, 0xff42, 0xff3a, 0xff32, 0xff2b,
0xff25, 0xff1e, 0xff19, 0xff14, 0xff0f, 0xff0b, 0xff08, 0xff05,
0xff03, 0xff01, 0xff00, 0xff00, 0xff00, 0xff01, 0xff03, 0xff05,
0xff08, 0xff0b, 0xff0f, 0xff13, 0xff18, 0xff1e, 0xff24, 0xff2b,
0xff32, 0xff3a, 0xff42, 0xff4b, 0xff54, 0xff5d, 0xff67, 0xff72,
0xff7c, 0xff87, 0xff92, 0xff9e, 0xffa9, 0xffb5, 0xffc2, 0xffce,
0xffda, 0xffe7, 0xfff3, 0x002b, 0x007f, 0x0020, 0x00ff, 0xff00,
0xffbe, 0x0000, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0x0045,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffc5, 0x0003, 0x0004, 0x0005, 0x0047, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
0x0009, 0x004a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x004e, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
0x0012, 0x0013, 0x0014, 0x0053, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
0x0059, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0x0060, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
0x002b, 0x002c, 0x0068, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0071,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
0x003e, 0x003f, 0x0040, 0x0041, 0x007b, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
0x000b, 0x0044, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0050, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x005d, 0x0000, 0x0000, 0x0000, 0x0000,
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
0x006b, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0044, 0x0000, 0x0000,
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
0x001f, 0x0020, 0x0054, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0065,
0xffbe, 0x0000, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffc1, 0x0001, 0x0002, 0xfead,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffc5, 0x0003, 0x0004, 0x0005, 0xfeaf, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffca, 0x0006, 0x0007, 0x0008,
0x0009, 0xfeb2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffd0, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0xfeb6, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffd7, 0x000f, 0x0010, 0x0011,
0x0012, 0x0013, 0x0014, 0xfebb, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffdf, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b,
0xfec1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffe8, 0x001c, 0x001d, 0x001e,
0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 0xfec8, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xfff2, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a,
0x002b, 0x002c, 0xfed0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xfffd, 0x002d, 0x002e, 0x002f,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0xfed9,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffc7, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d,
0x003e, 0x003f, 0x0040, 0x0041, 0xfee3, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xffd4, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
0x000b, 0xfeac, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xffe2, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012,
0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0xfeb8, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xfff1, 0x0019, 0x001a, 0x001b,
0x001c, 0x001d, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0xfec5, 0x0000, 0x0000, 0x0000, 0x0000,
0xffcb, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d,
0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
0xfed3, 0x0000, 0x0000, 0x0000, 0xffdc, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0xfeac, 0x0000, 0x0000,
0xffee, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016,
0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
0x001f, 0x0020, 0xfebc, 0x0000, 0xffee, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b,
0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0xfecd,
0x0154, 0x0218, 0x0110, 0x00b0, 0x00cc, 0x00b0, 0x0088, 0x00b0,
0x0044, 0x00b0, 0x0000, 0x00b0, 0x00fe, 0xff07, 0x0002, 0x00ff,
0x00f8, 0x0007, 0x00fe, 0x00ee, 0x07ff, 0x0200, 0x00ef, 0xf800,
0x0700, 0x00ee, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0001,
0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff,
0xffff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000,
0x0000, 0xffff, 0xffff, 0x0000, 0xffff, 0x0001, 0x0000, 0x0001,
0x0001, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
0xffff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0xffff,
0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0044, 0x0088, 0x00cc,
0x0110, 0x0154, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
2FH - ROM Version
|
Input
|
byte(2FH) integer(Undefined)
|
|
Output
|
integer(Version)
|
|
short DSP3_Version()
{
return 0x0300;
}
Copyright 2003-2011 Snes9x DSP Team. Maintained by
Overload