DSP2 Gamepaks
Dungeon Master
DSP2 Status Register
|
The status register is a 16-bit register which holds
the status bits needed by the DSP to transfer data to and from external
devices. Only the upper 8 bits can be read from an external device.
|
The Request for Master (RQM) indicates that the DSP is requesting host CPU for
data read/write.
"0" : Internal Data Register transfer.
"1" : External Data Register transfer.
DSP2 Memory Mapping
|
PCB
|
Mode
|
Memory Size
|
Bank
|
Data Register (DR)
|
Status Register (SR)
|
|
SHVC-1B5B-01
|
20H
|
8M MASKROM
256K SRAM
|
20H ~ 3FH
|
8000H ~ BFFFH
|
C000H ~ FFFFH
|
DSP2 Commands
|
01H
|
Convert Bitmap to Bitplane Tile (Bit Perfect)
|
|
03H
|
Set Transparent Color (Bit Perfect)
|
|
05H
|
Replace Bitmap using Transparent Color (Bit Perfect)
|
|
06H
|
Reverse Bitmap (Bit Perfect)
|
|
07H
|
Add (Bit Perfect)
|
|
08H
|
Subtract (Bit Perfect)
|
|
09H
|
Multiply (Bit Perfect)
|
|
0DH
|
Scale Bitmap
|
Source Code Contributors
Reverse Engineered by Overload (Computer Science)
unsigned char xColor;
01H - Convert Bitmap to Bitplane Tile (Bit Perfect)
|
Input
|
byte(01H) byte(Bitmap[32])
|
|
Output
|
byte(Bitplane[32])
|
void DSP2_Convert(unsigned char Bitmap[32], unsigned char Bitplane[32])
{
int Offset = 0;
for (int i = 0; i < 16; i += 2)
{
unsigned char P0, P1, P2, P3;
for (int j = 0; j < 4; j++)
{
unsigned char Data = Bitmap[Offset];
P0 = (P0 << 2) + (Data & 0x01); Data >>= 1;
P1 = (P1 << 2) + (Data & 0x01); Data >>= 1;
P2 = (P2 << 2) + (Data & 0x01); Data >>= 1;
P3 = (P3 << 2) + (Data & 0x01);
P0 += (Data & 0x02); Data >>= 1;
P1 += (Data & 0x02); Data >>= 1;
P2 += (Data & 0x02); Data >>= 1;
P3 += (Data & 0x02);
Offset++;
}
Bitplane[i + 0x00] = P0;
Bitplane[i + 0x01] = P1;
Bitplane[i + 0x10] = P2;
Bitplane[i + 0x11] = P3;
}
}
03H - Set Transparent Color (Bit Perfect)
|
Input
|
byte(03H) byte(Color)
|
|
Output
|
None
|
void DSP2_SetTransparent(unsigned char Color)
{
xColor = Color & 0x0f;
}
05H - Replace Bitmap using Transparent Color (Bit Perfect)
|
Input
|
byte(05H) byte(n) byte(Bitmap1[n]) byte(Bitmap2[n])
|
|
Output
|
byte(Bitmap[n])
|
void DSP2_Replace(unsigned char Count, unsigned char Bitmap[255], unsigned char xBitmap[255], unsigned char nBitmap[255])
{
for (int i = 0; i < Count; i++)
{
unsigned char data = xBitmap[i];
if ((data & 0x0f) == xColor)
data = (data & 0xf0) + (Bitmap[i] & 0x0f);
if ((data >> 4) == xColor)
data = (data & 0x0f) + (Bitmap[i] & 0xf0);
nBitmap[i] = data;
}
}
06H - Reverse Bitmap (Bit Perfect)
|
Input
|
byte(06H) byte(n) byte(Bitmap[n])
|
|
Output
|
byte(Bitmap[n])
|
void DSP2_Reverse(unsigned char Count, unsigned char Bitmap[255], unsigned char nBitmap[255])
{
for (int i = 0; i < Count; i++)
{
unsigned char data = Bitmap[Count - i - 1];
nBitmap[i] = (data >> 4) + (data << 4);
}
}
07H - Add (Bit Perfect)
|
Input
|
byte(07H) double(A) double(B)
|
|
Output
|
double(Sum)
|
void DSP2_Add(int A, int B, int &Sum)
{
Sum = A + B;
}
08H - Subtract (Bit Perfect)
|
Input
|
byte(08H) double(A) double(B)
|
|
Output
|
double(Difference)
|
void DSP2_Subtract(int A, int B, int &Difference)
{
Difference = A - B;
}
09H - Multiply (Bit Perfect)
|
Input
|
byte(09H) integer(Multiplicand) integer(Multiplier)
|
|
Output
|
double(Product)
|
void DSP2_Multiply(short Multiplicand, short Multiplier, int &Product)
{
int mn = Multiplicand * Multiplier << 1;
// Bug is present in Dungeon Master (J) (1.0)
short n = mn;
unsigned short m = mn >> 16;
n >>= 1;
m >>= 1;
Product = (m << 16) + (n & 0xffff);
}
0DH - Scale Bitmap
|
Input
|
byte(0DH) byte(n) byte(m) byte(Bitmap[(n+1) / 2])
|
|
Output
|
byte(Bitmap[(m+1) / 2])
|
0FH - Process Command
|
Input
|
byte(0FH) byte(Command) . . .
|
|
Output
|
None
|
This code must be sent to start the command processor.
Copyright 2002-2004 Snes9x DSP Team. Maintained by
Overload