o cleanup

This commit is contained in:
optixx
2009-04-22 20:04:28 +02:00
parent 55e3468f74
commit 0c378a9f7c
1078 changed files with 0 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,345 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef __UNIXSDL__
#include "../gblhdr.h"
#else
#include <math.h>
#include <stdlib.h>
#endif
#ifdef PI
#undef PI
#endif
#define PI 3.1415926535897932384626433832795
#define Cos(a) ((double) CosTable[a])
#define Sin(a) ((double) SinTable[a])
#define Tan(a) (CosTable[a]?((((int)SinTable[a])<<16)/CosTable[a]):(int)0x80000000)
short SinTable[512] = {
0, 402, 804, 1206, 1607, 2009, 2410, 2811,
3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997,
6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126,
9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167,
12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090,
15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869,
18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475,
20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884,
23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073,
25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020,
27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707,
28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117,
30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237,
31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057,
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765,
32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647,
32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214,
32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471,
31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425,
30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086,
28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466,
27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583,
25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453,
23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097,
20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537,
18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800,
15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910,
12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896,
9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786,
6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611,
3211, 2811, 2410, 2009, 1607, 1206, 804, 402,
0, -402, -804, -1206, -1607, -2009, -2410, -2811,
-3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997,
-6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126,
-9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167,
-12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090,
-15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869,
-18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475,
-20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884,
-23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073,
-25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020,
-27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707,
-28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117,
-30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237,
-31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057,
-32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568,
-32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765,
-32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647,
-32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214,
-32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471,
-31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425,
-30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086,
-28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466,
-27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583,
-25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453,
-23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097,
-20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537,
-18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800,
-15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910,
-12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896,
-9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786,
-6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611,
-3211, -2811, -2410, -2009, -1607, -1206, -804, -402
};
short CosTable[512] = {
32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647,
32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214,
32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471,
31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425,
30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086,
28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466,
27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583,
25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453,
23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097,
20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537,
18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800,
15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910,
12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896,
9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786,
6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611,
3211, 2811, 2410, 2009, 1607, 1206, 804, 402,
0, -402, -804, -1206, -1607, -2009, -2410, -2811,
-3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997,
-6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126,
-9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167,
-12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090,
-15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869,
-18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475,
-20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884,
-23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073,
-25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020,
-27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707,
-28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117,
-30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237,
-31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057,
-32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568,
-32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765,
-32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647,
-32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214,
-32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471,
-31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425,
-30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086,
-28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466,
-27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583,
-25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453,
-23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097,
-20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537,
-18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800,
-15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910,
-12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896,
-9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786,
-6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611,
-3211, -2811, -2410, -2009, -1607, -1206, -804, -402,
0, 402, 804, 1206, 1607, 2009, 2410, 2811,
3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997,
6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126,
9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167,
12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090,
15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869,
18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475,
20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884,
23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073,
25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020,
27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707,
28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117,
30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237,
31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057,
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765
};
short C4WFXVal;
short C4WFYVal;
short C4WFZVal;
short C4WFX2Val;
short C4WFY2Val;
short C4WFDist;
short C4WFScale;
double tanval;
double c4x,c4y,c4z;
double c4x2,c4y2,c4z2;
void C4TransfWireFrame()
{
c4x=(double)C4WFXVal;
c4y=(double)C4WFYVal;
c4z=(double)C4WFZVal-0x95;
// Rotate X
tanval=-(double)C4WFX2Val*PI*2/128;
c4y2=c4y*cos(tanval)-c4z*sin(tanval);
c4z2=c4y*sin(tanval)+c4z*cos(tanval);
// Rotate Y
tanval=-(double)C4WFY2Val*PI*2/128;
c4x2=c4x*cos(tanval)+c4z2*sin(tanval);
c4z=c4x*-sin(tanval)+c4z2*cos(tanval);
// Rotate Z
tanval=-(double)C4WFDist*PI*2/128;
c4x=c4x2*cos(tanval)-c4y2*sin(tanval);
c4y=c4x2*sin(tanval)+c4y2*cos(tanval);
// Scale
C4WFXVal=(short)(c4x*C4WFScale/(0x90*(c4z+0x95))*0x95);
C4WFYVal=(short)(c4y*C4WFScale/(0x90*(c4z+0x95))*0x95);
}
void C4TransfWireFrame2()
{
c4x=(double)C4WFXVal;
c4y=(double)C4WFYVal;
c4z=(double)C4WFZVal;
// Rotate X
tanval=-(double)C4WFX2Val*PI*2/128;
c4y2=c4y*cos(tanval)-c4z*sin(tanval);
c4z2=c4y*sin(tanval)+c4z*cos(tanval);
// Rotate Y
tanval=-(double)C4WFY2Val*PI*2/128;
c4x2=c4x*cos(tanval)+c4z2*sin(tanval);
c4z=c4x*-sin(tanval)+c4z2*cos(tanval);
// Rotate Z
tanval=-(double)C4WFDist*PI*2/128;
c4x=c4x2*cos(tanval)-c4y2*sin(tanval);
c4y=c4x2*sin(tanval)+c4y2*cos(tanval);
// Scale
C4WFXVal=(short)(c4x*C4WFScale/0x100);
C4WFYVal=(short)(c4y*C4WFScale/0x100);
}
void C4CalcWireFrame()
{
C4WFXVal=C4WFX2Val-C4WFXVal;
C4WFYVal=C4WFY2Val-C4WFYVal;
if (abs(C4WFXVal)>abs(C4WFYVal)){
C4WFDist=abs(C4WFXVal)+1;
C4WFYVal=(short)((256*(long)C4WFYVal)/abs(C4WFXVal));
if (C4WFXVal<0) C4WFXVal=-256;
else C4WFXVal=256;
}
else
if (C4WFYVal!=0) {
C4WFDist=abs(C4WFYVal)+1;
C4WFXVal=(short)((256*(long)C4WFXVal)/abs(C4WFYVal));
if (C4WFYVal<0) C4WFYVal=-256;
else C4WFYVal=256;
}
else C4WFDist=0;
}
short C41FXVal;
short C41FYVal;
short C41FAngleRes;
short C41FDist;
short C41FDistVal;
void C4Op1F()
{
if (C41FXVal == 0) {
if (C41FYVal>0) C41FAngleRes=0x80;
else C41FAngleRes=0x180;
}
else {
tanval = ((double)C41FYVal)/((double)C41FXVal);
C41FAngleRes=(short)(atan(tanval)/(PI*2)*512);
C41FAngleRes=C41FAngleRes;
if (C41FXVal<0) C41FAngleRes+=0x100;
C41FAngleRes&=0x1FF;
}
}
void C4Op15()
{
tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)*
((double)C41FXVal));
C41FDist=(short)tanval;
}
void C4Op0D()
{
tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)*
((double)C41FXVal));
tanval=(double)C41FDistVal/tanval;
C41FYVal=(short)(((double)C41FYVal*tanval)*0.99);
C41FXVal=(short)(((double)C41FXVal*tanval)*0.98);
}
#define READ_WORD(s) (*(unsigned short *) (s))
void C4Op22()
{
extern unsigned char *C4Ram;
short angle1 = READ_WORD(C4Ram+0x1f8c) & 0x1ff;
short angle2 = READ_WORD(C4Ram+0x1f8f) & 0x1ff;
int tan1 = Tan(angle1);
int tan2 = Tan(angle2);
short y = READ_WORD(C4Ram+0x1f83) - READ_WORD(C4Ram+0x1f89);
short left, right;
int j;
for (j = 0; j < 225; j++, y++)
{
if (y >= 0)
{
left = (((int)tan1*y) >> 16) - READ_WORD(C4Ram+0x1f80) + READ_WORD(C4Ram+0x1f86);
right = (((int)tan2*y) >> 16) - READ_WORD(C4Ram+0x1f80) + READ_WORD(C4Ram+0x1f86) + READ_WORD(C4Ram+0x1f93);
if(left<0 && right<0)
{
left = 1;
right = 0;
}
else if (left < 0)
{
left = 0;
}
else if (right < 0)
{
right = 0;
}
if (left > 255 && right > 255)
{
left = 255;
right = 254;
}
else if (left > 255)
{
left = 255;
}
else if (right > 255)
{
right = 255;
}
}
else
{
left = 1;
right = 0;
}
C4Ram[j+0x800] = (unsigned char)left;
C4Ram[j+0x900] = (unsigned char)right;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,879 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM regaccessbankr8,regaccessbankr16,regaccessbankw8,regaccessbankw16
EXTSYM DSPOp0A,Op0AA,Op0AB,Op0AC,Op0AD,Op0AVS,DSPOp10,DSPOp00,Op00Multiplicand
EXTSYM Op00Multiplier,Op00Result,DSPOp0F,Op0FPass
EXTSYM DSPOp04,Op04Angle,Op04Cos,Op04Radius,Op04Sin
EXTSYM DSPOp28,Op28R,Op28X,Op28Y,Op28Z
EXTSYM DSPOp0C,Op0CA,Op0CX1,Op0CX2,Op0CY1,Op0CY2
EXTSYM DSPOp02,Op02AAS,Op02AZS,Op02CX,Op02CY,Op02FX,Op02FY
EXTSYM Op02FZ,Op02LES,Op02LFE,Op02VOF,Op02VVA
EXTSYM DSPOp06,Op06X,Op06Y,Op06Z,Op06H,Op06V,Op06M
EXTSYM DSPOp0E,Op0EH,Op0EV,Op0EX,Op0EY
EXTSYM Op01m,Op01Zr,Op01Xr,Op01Yr,DSPOp01
EXTSYM Op11m,Op11Zr,Op11Xr,Op11Yr,DSPOp11
EXTSYM Op21m,Op21Zr,Op21Xr,Op21Yr,DSPOp21
EXTSYM Op0DX,Op0DY,Op0DZ,Op0DF,Op0DL,Op0DU,DSPOp0D
EXTSYM Op1DX,Op1DY,Op1DZ,Op1DF,Op1DL,Op1DU,DSPOp1D
EXTSYM Op2DX,Op2DY,Op2DZ,Op2DF,Op2DL,Op2DU,DSPOp2D
EXTSYM Op03X,Op03Y,Op03Z,Op03F,Op03L,Op03U,DSPOp03
EXTSYM Op13X,Op13Y,Op13Z,Op13F,Op13L,Op13U,DSPOp13
EXTSYM Op23X,Op23Y,Op23Z,Op23F,Op23L,Op23U,DSPOp23
EXTSYM Op14Zr,Op14Xr,Op14Yr,Op14U,Op14F,Op14L
EXTSYM Op14Zrr,Op14Xrr,Op14Yrr,DSPOp14
EXTSYM Op0BX,Op0BY,Op0BZ,Op0BS,DSPOp0B
EXTSYM Op1BX,Op1BY,Op1BZ,Op1BS,DSPOp1B
EXTSYM Op2BX,Op2BY,Op2BZ,Op2BS,DSPOp2B
EXTSYM Op08X,Op08Y,Op08Z,Op08Ll,Op08Lh,DSPOp08
EXTSYM Op18X,Op18Y,Op18Z,Op18R,Op18D,DSPOp18
EXTSYM Op1CX,Op1CY,Op1CZ,Op1CXBR,Op1CYBR,Op1CZBR,Op1CXAR,Op1CYAR,Op1CZAR,DSPOp1C
EXTSYM Op10Exponent,Op10ExponentR,Op10Coefficient,Op10CoefficientR
SECTION .bss
NEWSYM dsp1ptr, resd 1
NEWSYM dsp1array, resb 4096
SECTION .text
;*******************************************************
; DSP1 Read Functions
;*******************************************************
NEWSYM DSP1Read8b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankr8
.dsp1area
mov al,80h
ret
NEWSYM DSP1Read16b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankr16
.dsp1area
or ecx,08000h
cmp ecx,0C000h
jae .doC000
cmp byte[DSP1RLeft],0
jne .movestuff
xor ax,ax
ret
.doC000
mov ax,08000h
cmp byte[DSP1WLeft],0
je .notwleft
mov ax,0C000h
.notwleft
ret
.movestuff
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrR]
mov ax,[DSP1RET+ebx*2]
pop ebx
inc byte[DSP1CPtrR]
dec byte[DSP1RLeft]
jz .nomore
.goback
ret
.nomore
cmp byte[DSP1COp],0Ah
jne .goback
push eax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
mov byte[DSP1CPtrR],0
pop eax
ret
NEWSYM DSP1Read8b
; mov byte[debstop],1
cmp ecx,7000h
jae .do7000
xor al,al
ret
.do7000
mov al,80h
test ecx,1
jz .no1
mov al,80h
.no1
ret
NEWSYM DSP1Read16b
; mov byte[debstop],1
cmp ecx,7000h
jae .do7000
cmp byte[DSP1RLeft],0
jne .movestuff
xor ax,ax
ret
.do7000
mov ax,8000h
cmp byte[DSP1WLeft],0
je .notwleft
mov ax,0C000h
.notwleft
; test ecx,01h
; jz .norev
; mov ax,0080h
;.norev
ret
.movestuff
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrR]
mov ax,[DSP1RET+ebx*2]
pop ebx
inc byte[DSP1CPtrR]
dec byte[DSP1RLeft]
jz .nomore
.goback
ret
.nomore
cmp byte[DSP1COp],0Ah
jne .goback
push eax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
mov byte[DSP1CPtrR],0
pop eax
ret
%macro DSP1WriteInit 2
cmp al,%1
jne %%no
mov byte[DSP1WLeft],%2
%%no
%endmacro
NEWSYM DSP1Write8b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankw8
.dsp1area
call DSP1Write8b
ret
NEWSYM DSP1Write16b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankw16
.dsp1area
call DSP1Write16b
ret
NEWSYM DSP1Write8b
push ebx
xor ebx,ebx
mov bl,al
mov byte[DSPFuncUsed+ebx],1
pop ebx
mov [DSP1COp],al
mov byte[DSP1CPtrW],0
DSP1WriteInit 00h, 2 ; 16-bit multiply
DSP1WriteInit 10h, 2 ; Inverse
DSP1WriteInit 04h, 2 ; Trigonometric
DSP1WriteInit 08h, 3 ; Vector Size
DSP1WriteInit 18h, 4 ; Vector Size Comparison
DSP1WriteInit 28h, 3 ; Vector Absolute Value
DSP1WriteInit 0Ch, 3 ; Coordinate Rotation
DSP1WriteInit 1Ch, 6 ; 3D Coordinate Rotation
DSP1WriteInit 02h, 7 ; Vector Size
DSP1WriteInit 0Ah, 1 ; Raster Data Calculation via DMA
DSP1WriteInit 1Ah, 1 ; Raster Data Calculation w/o DMA
DSP1WriteInit 06h, 3 ; Object Projection Calculation
DSP1WriteInit 0Eh, 2 ; Coordinate Calculation of a point onscreen
DSP1WriteInit 01h, 4 ; Set Attitude Matrix A
DSP1WriteInit 11h, 4 ; Set Attitude Matrix B
DSP1WriteInit 21h, 4 ; Set Attitude Matrix C
DSP1WriteInit 0Dh, 3 ; Convert from global to object coords Matrix A
DSP1WriteInit 1Dh, 3 ; Convert from global to object coords Matrix B
DSP1WriteInit 2Dh, 3 ; Convert from global to object coords Matrix C
DSP1WriteInit 03h, 3 ; Convert from object to global coords Matrix A
DSP1WriteInit 13h, 3 ; Convert from object to global coords Matrix B
DSP1WriteInit 23h, 3 ; Convert from object to global coords Matrix C
DSP1WriteInit 0Bh, 3 ; Calculation of inner product Matrix A
DSP1WriteInit 1Bh, 3 ; Calculation of inner product Matrix B
DSP1WriteInit 2Bh, 3 ; Calculation of inner product Matrix C
DSP1WriteInit 14h, 6 ; 3D angle rotation
DSP1WriteInit 0Fh, 1 ; DSP RAM Check
ret
%macro DSP1WriteProc 2
cmp byte[DSP1COp],%1
jne %%no
pushad
call %2
popad
%%no
%endmacro
NEWSYM DSP1Write16b
; mov byte[debstop],1
cmp byte[DSP1WLeft],0
jne .yesleft
ret
.yesleft
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrW]
mov [DSP1VARS+ebx*2],ax
pop ebx
inc byte[DSP1CPtrW]
dec byte[DSP1WLeft]
jz .ProcessDSP1
ret
.ProcessDSP1
mov byte[DSP1CPtrR],0
mov byte[DSP1RLeft],0
DSP1WriteProc 00h, DSP1_00 ; 16-bit multiply
DSP1WriteProc 10h, DSP1_10 ; Inverse
DSP1WriteProc 04h, DSP1_04 ; Trigonometric
DSP1WriteProc 08h, DSP1_08 ; Vector Size
DSP1WriteProc 18h, DSP1_18 ; Vector Size Comparison
DSP1WriteProc 28h, DSP1_28 ; Vector Absolute Value
DSP1WriteProc 0Ch, DSP1_0C ; Coordinate Rotation
DSP1WriteProc 1Ch, DSP1_1C ; 3D Coordinate Rotation
DSP1WriteProc 02h, DSP1_02 ; Vector Size
DSP1WriteProc 0Ah, DSP1_0A ; Raster Data Calculation via DMA
DSP1WriteProc 1Ah, DSP1_0A ; Raster Data Calculation w/o DMA
DSP1WriteProc 06h, DSP1_06 ; Object Projection Calculation
DSP1WriteProc 0Eh, DSP1_0E ; Coordinate Calculation of a point onscreen
DSP1WriteProc 01h, DSP1_01 ; Set Attitude Matrix A
DSP1WriteProc 11h, DSP1_11 ; Set Attitude Matrix B
DSP1WriteProc 21h, DSP1_21 ; Set Attitude Matrix C
DSP1WriteProc 0Dh, DSP1_0D ; Convert from global to object coords Matrix A
DSP1WriteProc 1Dh, DSP1_1D ; Convert from global to object coords Matrix B
DSP1WriteProc 2Dh, DSP1_2D ; Convert from global to object coords Matrix C
DSP1WriteProc 03h, DSP1_03 ; Convert from object to global coords Matrix A
DSP1WriteProc 13h, DSP1_13 ; Convert from object to global coords Matrix B
DSP1WriteProc 23h, DSP1_23 ; Convert from object to global coords Matrix C
DSP1WriteProc 0Bh, DSP1_0B ; Calculation of inner product Matrix A
DSP1WriteProc 1Bh, DSP1_1B ; Calculation of inner product Matrix B
DSP1WriteProc 2Bh, DSP1_2B ; Calculation of inner product Matrix C
DSP1WriteProc 14h, DSP1_14 ; 3D angle rotation
DSP1WriteProc 0Fh, DSP1_0F ; DSP RAM Check
ret
SECTION .bss
NEWSYM DSP1COp, resb 1
NEWSYM DSP1RLeft, resb 1
NEWSYM DSP1WLeft, resb 1
NEWSYM DSP1CPtrW, resb 1
NEWSYM DSP1CPtrR, resb 1
NEWSYM DSP1VARS, resw 16
NEWSYM DSP1RET, resw 16
NEWSYM DSPDet, resb 1
NEWSYM DSPFuncUsed, resb 256
SECTION .text
;*******************************************************
; DSP1 Conversion Functions
;*******************************************************
DSP1_00: ; 16-bit multiply
or byte[DSPDet],01h
push eax
mov ax,[DSP1VARS]
mov [Op00Multiplicand],ax
mov ax,[DSP1VARS+2]
mov [Op00Multiplier],ax
pushad
call DSPOp00
popad
mov ax,[Op00Result]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_10: ; Inverse
push eax
mov ax,[DSP1VARS]
mov [Op10Coefficient],ax
mov ax,[DSP1VARS+2]
mov [Op10Exponent],ax
pushad
call DSPOp10
popad
mov ax,[Op10CoefficientR]
mov [DSP1RET],ax
mov ax,[Op10ExponentR]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_04: ; Trigonometric
or byte[DSPDet],02h
push eax
mov ax,[DSP1VARS]
mov [Op04Angle],ax
mov ax,[DSP1VARS+2]
mov [Op04Radius],ax
pushad
call DSPOp04
popad
mov ax,[Op04Sin]
mov [DSP1RET],ax
mov ax,[Op04Cos]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_08: ; Vector Size
push eax
mov ax,[DSP1VARS]
mov [Op08X],ax
mov ax,[DSP1VARS+2]
mov [Op08Y],ax
mov ax,[DSP1VARS+4]
mov [Op08Z],ax
pushad
call DSPOp08
popad
mov ax,[Op08Ll]
mov [DSP1RET],ax
mov ax,[Op08Lh]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_18: ; Vector Size Comparison
push eax
mov ax,[DSP1VARS]
mov [Op18X],ax
mov ax,[DSP1VARS+2]
mov [Op18Y],ax
mov ax,[DSP1VARS+4]
mov [Op18Z],ax
mov ax,[DSP1VARS+6]
mov [Op18R],ax
pushad
call DSPOp18
popad
mov ax,[Op18D]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_28: ; Vector Absolute Value
or byte[DSPDet],04h
push eax
mov ax,[DSP1VARS]
mov [Op28X],ax
mov ax,[DSP1VARS+2]
mov [Op28Y],ax
mov ax,[DSP1VARS+4]
mov [Op28Z],ax
pushad
call DSPOp28
popad
mov ax,[Op28R]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_0C: ; Coordinate Rotation
or byte[DSPDet],08h
push eax
mov ax,[DSP1VARS]
mov [Op0CA],ax
mov ax,[DSP1VARS+2]
mov [Op0CX1],ax
mov ax,[DSP1VARS+4]
mov [Op0CY1],ax
pushad
call DSPOp0C
popad
mov ax,[Op0CX2]
mov [DSP1RET],ax
mov ax,[Op0CY2]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_1C: ; 3D Coordinate Rotation
push eax
mov ax,[DSP1VARS]
mov [Op1CZ],ax
mov ax,[DSP1VARS+2]
mov [Op1CY],ax
mov ax,[DSP1VARS+4]
mov [Op1CX],ax
mov ax,[DSP1VARS+6]
mov [Op1CXBR],ax
mov ax,[DSP1VARS+8]
mov [Op1CYBR],ax
mov ax,[DSP1VARS+10]
mov [Op1CZBR],ax
pushad
call DSPOp1C
popad
mov ax,[Op1CXAR]
mov [DSP1RET],ax
mov ax,[Op1CYAR]
mov [DSP1RET+2],ax
mov ax,[Op1CZAR]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_02: ; Vector Size
or byte[DSPDet],10h
push eax
mov ax,[DSP1VARS]
mov [Op02FX],ax
mov ax,[DSP1VARS+2]
mov [Op02FY],ax
mov ax,[DSP1VARS+4]
mov [Op02FZ],ax
mov ax,[DSP1VARS+6]
mov [Op02LFE],ax
mov ax,[DSP1VARS+8]
mov [Op02LES],ax
mov ax,[DSP1VARS+10]
mov [Op02AAS],ax
mov ax,[DSP1VARS+12]
mov [Op02AZS],ax
pushad
call DSPOp02
popad
mov ax,[Op02VOF]
mov [DSP1RET],ax
mov ax,[Op02VVA]
mov [DSP1RET+2],ax
mov ax,[Op02CX]
mov [DSP1RET+4],ax
mov ax,[Op02CY]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
pop eax
ret
mov eax,dsp1array
add eax,[dsp1ptr]
push ebx
mov byte[eax],02h
mov bx,[Op02FX]
mov [eax+1],bx
mov bx,[Op02FY]
mov [eax+3],bx
mov bx,[Op02FZ]
mov [eax+5],bx
mov bx,[Op02LFE]
mov [eax+7],bx
mov bx,[Op02LES]
mov [eax+9],bx
mov bx,[Op02AAS]
mov [eax+11],bx
mov bx,[Op02AZS]
mov [eax+13],bx
mov bx,[Op02VOF]
mov [eax+15],bx
mov bx,[Op02VVA]
mov [eax+17],bx
mov bx,[Op02CX]
mov [eax+19],bx
mov bx,[Op02CY]
mov [eax+21],bx
pop ebx
add dword[dsp1ptr],23
DSP1_0A: ; Raster Data Calculation via DMA
mov byte[DSP1COp],0Ah
or byte[DSPDet],20h
push eax
mov ax,[DSP1VARS]
mov [Op0AVS],ax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
pop eax
ret
DSP1_06: ; Object Projection Calculation
or byte[DSPDet],40h
push eax
mov ax,[DSP1VARS]
mov [Op06X],ax
mov ax,[DSP1VARS+2]
mov [Op06Y],ax
mov ax,[DSP1VARS+4]
mov [Op06Z],ax
pushad
call DSPOp06
popad
mov ax,[Op06H]
mov [DSP1RET],ax
mov ax,[Op06V]
mov [DSP1RET+2],ax
mov ax,[Op06M]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
mov eax,dsp1array
add eax,[dsp1ptr]
push ebx
mov byte[eax],06h
mov bx,[Op06X]
mov [eax+1],bx
mov bx,[Op06Y]
mov [eax+3],bx
mov bx,[Op06Z]
mov [eax+5],bx
mov bx,[Op06H]
mov [eax+7],bx
mov bx,[Op06V]
mov [eax+9],bx
mov bx,[Op06M]
mov [eax+11],bx
pop ebx
add dword[dsp1ptr],13
DSP1_0E: ; Coordinate Calculation of a point onscreen
push eax
mov ax,[DSP1VARS]
mov [Op0EH],ax
mov ax,[DSP1VARS+2]
mov [Op0EV],ax
pushad
call DSPOp0E
popad
mov ax,[Op0EX]
mov [DSP1RET],ax
mov ax,[Op0EY]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_01: ; Set Attitude Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op01m],ax
mov ax,[DSP1VARS+2]
mov [Op01Zr],ax
mov ax,[DSP1VARS+4]
mov [Op01Yr],ax
mov ax,[DSP1VARS+6]
mov [Op01Xr],ax
pushad
call DSPOp01
popad
pop eax
ret
DSP1_11: ; Set Attitude Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op11m],ax
mov ax,[DSP1VARS+2]
mov [Op11Zr],ax
mov ax,[DSP1VARS+4]
mov [Op11Yr],ax
mov ax,[DSP1VARS+6]
mov [Op11Xr],ax
pushad
call DSPOp11
popad
pop eax
ret
DSP1_21: ; Set Attitude Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op21m],ax
mov ax,[DSP1VARS+2]
mov [Op21Zr],ax
mov ax,[DSP1VARS+4]
mov [Op21Yr],ax
mov ax,[DSP1VARS+6]
mov [Op21Xr],ax
pushad
call DSPOp21
popad
pop eax
ret
DSP1_0D: ; Convert from global to object coords Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op0DX],ax
mov ax,[DSP1VARS+2]
mov [Op0DY],ax
mov ax,[DSP1VARS+4]
mov [Op0DZ],ax
pushad
call DSPOp0D
popad
mov ax,[Op0DF]
mov [DSP1RET],ax
mov ax,[Op0DL]
mov [DSP1RET+2],ax
mov ax,[Op0DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_0F: ; DSP RAM Test
push eax
mov ax,[DSP1VARS]
pushad
call DSPOp0F
popad
mov ax,[Op0FPass]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_1D: ; Convert from global to object coords Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op1DX],ax
mov ax,[DSP1VARS+2]
mov [Op1DY],ax
mov ax,[DSP1VARS+4]
mov [Op1DZ],ax
pushad
call DSPOp1D
popad
mov ax,[Op1DF]
mov [DSP1RET],ax
mov ax,[Op1DL]
mov [DSP1RET+2],ax
mov ax,[Op1DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_2D: ; Convert from global to object coords Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op2DX],ax
mov ax,[DSP1VARS+2]
mov [Op2DY],ax
mov ax,[DSP1VARS+4]
mov [Op2DZ],ax
pushad
call DSPOp2D
popad
mov ax,[Op2DF]
mov [DSP1RET],ax
mov ax,[Op2DL]
mov [DSP1RET+2],ax
mov ax,[Op2DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_03: ; Convert from object to global coords Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op03F],ax
mov ax,[DSP1VARS+2]
mov [Op03L],ax
mov ax,[DSP1VARS+4]
mov [Op03U],ax
pushad
call DSPOp03
popad
mov ax,[Op03X]
mov [DSP1RET],ax
mov ax,[Op03Y]
mov [DSP1RET+2],ax
mov ax,[Op03Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_13: ; Convert from object to global coords Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op13F],ax
mov ax,[DSP1VARS+2]
mov [Op13L],ax
mov ax,[DSP1VARS+4]
mov [Op13U],ax
pushad
call DSPOp13
popad
mov ax,[Op13X]
mov [DSP1RET],ax
mov ax,[Op13Y]
mov [DSP1RET+2],ax
mov ax,[Op13Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_23: ; Convert from object to global coords Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op23F],ax
mov ax,[DSP1VARS+2]
mov [Op23L],ax
mov ax,[DSP1VARS+4]
mov [Op23U],ax
pushad
call DSPOp23
popad
mov ax,[Op23X]
mov [DSP1RET],ax
mov ax,[Op23Y]
mov [DSP1RET+2],ax
mov ax,[Op23Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_0B: ; Calculation of inner product Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op0BX],ax
mov ax,[DSP1VARS+2]
mov [Op0BY],ax
mov ax,[DSP1VARS+4]
mov [Op0BZ],ax
pushad
call DSPOp0B
popad
mov ax,[Op0BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_1B: ; Calculation of inner product Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op1BX],ax
mov ax,[DSP1VARS+2]
mov [Op1BY],ax
mov ax,[DSP1VARS+4]
mov [Op1BZ],ax
pushad
call DSPOp1B
popad
mov ax,[Op1BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_2B: ; Calculation of inner product Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op2BX],ax
mov ax,[DSP1VARS+2]
mov [Op2BY],ax
mov ax,[DSP1VARS+4]
mov [Op2BZ],ax
pushad
call DSPOp2B
popad
mov ax,[Op2BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_14: ; 3D angle rotation
push eax
mov ax,[DSP1VARS]
mov [Op14Zr],ax
mov ax,[DSP1VARS+2]
mov [Op14Xr],ax
mov ax,[DSP1VARS+4]
mov [Op14Yr],ax
mov ax,[DSP1VARS+6]
mov [Op14U],ax
mov ax,[DSP1VARS+8]
mov [Op14F],ax
mov ax,[DSP1VARS+10]
mov [Op14L],ax
pushad
call DSPOp14
popad
mov ax,[Op14Zrr]
mov [DSP1RET],ax
mov ax,[Op14Xrr]
mov [DSP1RET+2],ax
mov ax,[Op14Yrr]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret

View File

@@ -0,0 +1,608 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; Apr 29, 2004
; DSP2 support code written by kentaro-k.21 <danmasu-lj@infoseek.jp>
; coding hints are based on DSP2 function overview at http://users.tpg.com.au/trauma/dsp/dsp2.html maintained by Overload.
; i have stolen the useful technical info there to implement DSP2 codes without any permission from its author.
; i do NOT know and peep the s9x source codes for either DSP2 or any purpose.
; May 02, 2004
; bug fix for Dungeon Master.
; Command 05h fixed.
; when you got the magic missile damage such as fireball, DSP2 support in prior version entered halt state.
%include "macros.mac"
DSP2F_HALT equ 1
DSP2F_AUTO_BUFFER_SHIFT equ 2
DSP2F_NO_ADDR_CHK equ 4
;*******************************************************
; .bss section
;*******************************************************
SECTION .bss
NEWSYM dsp2buffer, resb 256
NEWSYM dsp2enforcerQueue, resb 8*512
NEWSYM dsp2enforcer, resb 8
;*******************************************************
; .data section
;*******************************************************
SECTION .data
NEWSYM dsp2f03KeyLo, db 0 ; Current transparent-color in lower-byte
NEWSYM dsp2f03KeyHi, db 0 ; Current transparent-color in higher-byte
NEWSYM dsp2enforcerReaderCursor, dd 0 ; T/O
NEWSYM dsp2enforcerWriterCursor, dd 1 ; T/O
NEWSYM dsp2state, dd 1 ; Flags: 1=HALT, 2=AUTO_BUFFER_SHIFT, 4=NO_ADDR_CHK
NEWSYM dsp2input, dd 0 ; Saving input 8-bit data
NEWSYM dsp2inputTemp, dd 0 ; Temporary variable
NEWSYM dsp2f0dSizeOrg, dd 0 ; Command 0D, Original BMP width
NEWSYM dsp2f0dSizeNew, dd 0 ; Command 0D, New BMP width
NEWSYM dsp2f01TblByte ; Conversion table for Command 01
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
NEWSYM dsp2f01TblBitMask ; Conversion table for Command 01
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
;*******************************************************
; .text section
;*******************************************************
SECTION .text
;*******************************************************
;
;*******************************************************
%macro CommandJmp 2
cmp al,%1
je near %2
%endmacro
%macro DevWriteX 1
%ifdef _USE_DEV
pushad
mov dword[_DSP2Dev_arg],%1
call _DevWriteX
popad
%endif
%endmacro
%macro EnterInsideCommand 1
DevWriteX %1
%endmacro
%macro QueueInsideCommand 1
DevWriteX %1+0ffff0000h
%endmacro
%macro LeaveInsideCommand 0
%ifdef _USE_DEV
pushad
call _Leave
popad
%endif
%endmacro
;*******************************************************
;
;*******************************************************
NEWSYM InitDSP2
.enter
mov dword[dsp2state],0
mov dword[dsp2enforcerQueue+8*0+0],0
mov dword[dsp2enforcerQueue+8*0+4],8000h
mov dword[dsp2enforcerReaderCursor],0
mov dword[dsp2enforcerWriterCursor],1
.leave
ret
;*******************************************************
;
;*******************************************************
NEWSYM DSP2Read8b
.enter
test byte[dsp2state],DSP2F_HALT
jnz .halt
test cx,8000h
jz .undef
test cx,7000h
jnz .undef
and ecx,255
mov al,[dsp2buffer+ecx]
xor ecx,ecx
test byte[dsp2state],DSP2F_AUTO_BUFFER_SHIFT
jnz .shiftbuffer
jmp .leave
.shiftbuffer
sar dword[dsp2buffer],8
jmp .leave
.halt
.undef
xor eax,eax
.leave
ret
NEWSYM DSP2Read16b
.enter
xor eax,eax
.leave
ret
;*******************************************************
;
;*******************************************************
NEWSYM _DSP2Add2Queue
.enter
push eax
push ebx
; *** Locates the write cursor
mov eax,[dsp2enforcerWriterCursor]
lea ebx,[dsp2enforcerQueue+eax*8]
inc eax
and eax,511
mov [dsp2enforcerWriterCursor],eax
; *** Copies the local inside command into his queue
mov eax,[dsp2enforcer]
mov [ebx],eax
mov eax,[dsp2enforcer+4]
mov [ebx+4],eax
pop ebx
pop eax
.leave
ret
NEWSYM DSP2Write8b
.enter
; Tests halt flag
test byte[dsp2state],DSP2F_HALT
jnz near .halt
; *** Locates current predicator store
mov [dsp2input],al
mov eax,[dsp2enforcerReaderCursor]
lea ebx,[dsp2enforcerQueue+8*eax]
; *** Copies inside command box into box in order to spare indirection cost
mov eax,[ebx]
mov [dsp2enforcer],eax
mov eax,[ebx+4]
mov [dsp2enforcer+4],eax
xor ebx,ebx
; *** About some commands need to be relaxed the write address check
test byte[dsp2state],DSP2F_NO_ADDR_CHK
jnz .noaddrchk
; *** Tests whether cx points expected address
cmp [dsp2enforcer+4],cx
jne near .gohalt
.noaddrchk
; *** Reads next inside command should be proceeded
mov al,[dsp2enforcer]
; *** Branches to inside commands respectively
CommandJmp 00h,.w00
CommandJmp 01h,.w01
CommandJmp 02h,.w02
CommandJmp 03h,.w03
CommandJmp 04h,.w04
CommandJmp 05h,.w05
CommandJmp 06h,.w06
CommandJmp 07h,.w07
CommandJmp 08h,.w08
CommandJmp 09h,.w09
CommandJmp 0Ah,.w0A
CommandJmp 0Bh,.w0B
jmp .gohalt
.w0B ; ---
EnterInsideCommand 0Bh
mov al,[dsp2input]
xor ecx,ecx
mov cl,[dsp2enforcer+1]
mov [dsp2buffer+ecx],al
jmp .done
.w0A ; ---
EnterInsideCommand 0Ah
mov al,[dsp2input]
sar al,1
mov [dsp2f0dSizeNew],al
test al,al
jz near .gohalt
xor ecx,ecx
xor eax,eax
mov bl,[dsp2f0dSizeNew]
mov bh,[dsp2f0dSizeOrg]
.w0Aploop
mov al,cl
mul bl
div bh
mov dword[dsp2enforcer+0],0Bh
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],al
mov [dsp2enforcer+4],cl
call _DSP2Add2Queue
inc cl
cmp cl,[dsp2f0dSizeOrg]
jne .w0Aploop
xor ebx,ebx
jmp .queueincoming
.w09 ; ---
EnterInsideCommand 9
mov al,[dsp2input]
sar al,1
mov [dsp2f0dSizeOrg],al
test al,al
jz near .gohalt
mov dword[dsp2enforcer+0],0Ah
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w08 ; ---
EnterInsideCommand 8
xor eax,eax
mov al,[dsp2enforcer+1]
mov cl,[dsp2input]
mov [dsp2buffer+eax],cl
cmp al,3
jne .w08done
mov al,[dsp2buffer]
mul byte[dsp2buffer+2]
mov [dsp2buffer],eax
or byte[dsp2state],DSP2F_AUTO_BUFFER_SHIFT
.w08done
jmp .done
.w07 ; ---
EnterInsideCommand 7
mov cl,[dsp2input]
rol cl,4
xor eax,eax
mov al,[dsp2enforcer+1]
mov [dsp2buffer+eax],cl
jmp .done
.w06 ; ---
EnterInsideCommand 6
cmp byte[dsp2input],0
je near .gohalt
xor eax,eax
xor ecx,ecx
mov cl,[dsp2input]
.w06ploop
dec cl
mov dword[dsp2enforcer+0],7
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],cl
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
test cl,cl
jnz .w06ploop
jmp .queueincoming
.w05 ; ---
EnterInsideCommand 5
xor eax,eax
mov al,[dsp2enforcer+4]
mov cl,[dsp2buffer+eax]
mov ch,[dsp2input]
and ch,0f0h
cmp ch,[dsp2f03KeyHi]
je .w05pnohi
and cl,0fh
or cl,ch
.w05pnohi
mov ch,[dsp2input]
and ch,0fh
cmp ch,[dsp2f03KeyLo]
je .w05pnolo
and cl,0f0h
or cl,ch
.w05pnolo
mov [dsp2buffer+eax],cl
jmp .done
.w04 ; ---
EnterInsideCommand 4
xor eax,eax
mov al,[dsp2enforcer+4]
mov cl,[dsp2input]
mov [dsp2buffer+eax],cl
xor ecx,ecx
jmp .done
.w03 ; ---
EnterInsideCommand 3
cmp byte[dsp2input],0
je near .gohalt
xor eax,eax
.w03aloop
mov dword[dsp2enforcer+0],4
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,[dsp2input]
jne .w03aloop
xor eax,eax
.w03bloop
mov dword[dsp2enforcer+0],5
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,[dsp2input]
jne .w03bloop
xor ecx,ecx
jmp .queueincoming
.w02 ; ---
EnterInsideCommand 2
mov al,[dsp2input]
and al,0fh
mov [dsp2f03KeyLo],al
sal al,4
mov [dsp2f03KeyHi],al
jmp .done
.w01 ; ---
EnterInsideCommand 1
xor ecx,ecx
mov cl,[dsp2enforcer+4]
sal ecx,3
mov al,[dsp2input]
mov [dsp2inputTemp],al
xor ebx,ebx
.w01ploop
mov bl,[dsp2f01TblByte+ecx]
mov al,[dsp2f01TblBitMask+ecx]
test byte[dsp2inputTemp],1h
jz .w01pclear
or [dsp2buffer+ebx],al
jmp .w01pok
.w01pclear
not al
and [dsp2buffer+ebx],al
.w01pok
sar byte[dsp2inputTemp],1
inc ecx
test cl,7
jnz .w01ploop
xor ebx,ebx
xor ecx,ecx
jmp .done
.w00 ; ---
EnterInsideCommand 0
and byte[dsp2state],~(DSP2F_AUTO_BUFFER_SHIFT|DSP2F_NO_ADDR_CHK)
mov al,[dsp2input]
CommandJmp 01h,.w00p01
CommandJmp 03h,.w00p03
CommandJmp 05h,.w00p05
CommandJmp 06h,.w00p06
CommandJmp 09h,.w00p09
CommandJmp 0Dh,.w00p0D
CommandJmp 0Fh,.w00p0F
jmp .gohalt
.w00p0D ; ----
QueueInsideCommand 0Dh
mov dword[dsp2enforcer+0],9
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p09 ; ----
QueueInsideCommand 09h
xor eax,eax
mov al,4
.w00p09loop
mov dword[dsp2enforcer+0],8
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],ah
call _DSP2Add2Queue
inc ah
dec al
jnz .w00p09loop
jmp .queueincoming
.w00p06 ; ----
QueueInsideCommand 06h
mov dword[dsp2enforcer+0],6
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p05 ; ----
or byte[dsp2state],DSP2F_NO_ADDR_CHK
QueueInsideCommand 05h
mov dword[dsp2enforcer+0],3
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p03 ; ----
QueueInsideCommand 03h
mov dword[dsp2enforcer+0],2
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .queueincoming
.w00p01 ; ----
QueueInsideCommand 01h
xor eax,eax
.w00p01loop
mov dword[dsp2enforcer+0],1
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,32
jne .w00p01loop
xor ecx,ecx
jmp .queueincoming
.w00p0F ; ----
QueueInsideCommand 0Fh
.queueincoming
mov dword[dsp2enforcer+0],0
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.done
LeaveInsideCommand
mov eax,[dsp2enforcerReaderCursor]
inc eax
and eax,511
mov [dsp2enforcerReaderCursor],eax
xor eax,eax
jmp .leave
.gohalt
QueueInsideCommand 0ffh
or byte[dsp2state],DSP2F_HALT
.halt
xor eax,eax
.leave
ret
NEWSYM DSP2Write16b
.enter
xor eax,eax
.leave
ret

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM dsp3_address,dsp3_byte,DSP3GetByte,DSP3SetByte
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jz %1
%endmacro
NEWSYM DSP3Read8b
RouteAccess regaccessbankr8
mov [dsp3_address],cx
pushad
call DSP3GetByte
popad
mov al,[dsp3_byte]
ret
NEWSYM DSP3Write8b
RouteAccess regaccessbankw8
mov [dsp3_address],cx
mov [dsp3_byte],al
pushad
call DSP3SetByte
popad
ret
NEWSYM DSP3Read16b
RouteAccess regaccessbankr16
mov [dsp3_address],cx
pushad
call DSP3GetByte
mov al,[dsp3_byte]
mov [dsp3temp],al
inc word[dsp3_address]
call DSP3GetByte
popad
mov al,[dsp3temp]
mov ah,[dsp3_byte]
ret
NEWSYM DSP3Write16b
RouteAccess regaccessbankw16
mov [dsp3_address],cx
mov [dsp3_byte],al
mov [dsp3temp],ah
pushad
call DSP3SetByte
mov ah,[dsp3temp]
mov [dsp3_byte],ah
inc word[dsp3_address]
call DSP3SetByte
popad
ret
SECTION .bss
NEWSYM dsp3temp, resb 1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
#ifndef DSP4EMU_H
#define DSP4EMU_H
typedef unsigned char bool8;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int16;
typedef long int32;
#define FALSE 0
#define TRUE 1
struct DSP4_t
{
bool8 waiting4command;
bool8 half_command;
uint16 command;
uint32 in_count;
uint32 in_index;
uint32 out_count;
uint32 out_index;
uint8 parameters[512];
uint8 output[512];
};
extern struct DSP4_t DSP4;
struct DSP4_vars_t
{
// op control
int8 DSP4_Logic; // controls op flow
// projection format
int16 lcv; // loop-control variable
int16 distance; // z-position into virtual world
int16 raster; // current raster line
int16 segments; // number of raster lines drawn
// 1.15.16 or 1.15.0 [sign, integer, fraction]
int32 world_x; // line of x-projection in world
int32 world_y; // line of y-projection in world
int32 world_dx; // projection line x-delta
int32 world_dy; // projection line y-delta
int16 world_ddx; // x-delta increment
int16 world_ddy; // y-delta increment
int32 world_xenv; // world x-shaping factor
int16 world_yofs; // world y-vertical scroll
int16 view_x1; // current viewer-x
int16 view_y1; // current viewer-y
int16 view_x2; // future viewer-x
int16 view_y2; // future viewer-y
int16 view_dx; // view x-delta factor
int16 view_dy; // view y-delta factor
int16 view_xofs1; // current viewer x-vertical scroll
int16 view_yofs1; // current viewer y-vertical scroll
int16 view_xofs2; // future viewer x-vertical scroll
int16 view_yofs2; // future viewer y-vertical scroll
int16 view_yofsenv; // y-scroll shaping factor
int16 view_turnoff_x; // road turnoff data
int16 view_turnoff_dx; // road turnoff delta factor
// drawing area
int16 viewport_cx; // x-center of viewport window
int16 viewport_cy; // y-center of render window
int16 viewport_left; // x-left of viewport
int16 viewport_right; // x-right of viewport
int16 viewport_top; // y-top of viewport
int16 viewport_bottom; // y-bottom of viewport
// sprite structure
int16 sprite_x; // projected x-pos of sprite
int16 sprite_y; // projected y-pos of sprite
int16 sprite_attr; // obj attributes
bool8 sprite_size; // sprite size: 8x8 or 16x16
int16 sprite_clipy; // visible line to clip pixels off
int16 sprite_count;
// generic projection variables designed for
// two solid polygons + two polygon sides
int16 poly_clipLf[2][2]; // left clip boundary
int16 poly_clipRt[2][2]; // right clip boundary
int16 poly_ptr[2][2]; // HDMA structure pointers
int16 poly_raster[2][2]; // current raster line below horizon
int16 poly_top[2][2]; // top clip boundary
int16 poly_bottom[2][2]; // bottom clip boundary
int16 poly_cx[2][2]; // center for left/right points
int16 poly_start[2]; // current projection points
int16 poly_plane[2]; // previous z-plane distance
// OAM
int16 OAM_attr[16]; // OAM (size,MSB) data
int16 OAM_index; // index into OAM table
int16 OAM_bits; // offset into OAM table
int16 OAM_RowMax; // maximum number of tiles per 8 aligned pixels (row)
int16 OAM_Row[32]; // current number of tiles per row
};
extern struct DSP4_vars_t DSP4_vars;
#endif

View File

@@ -0,0 +1,83 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM dsp4_address,dsp4_byte,DSP4GetByte,DSP4SetByte
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jz %1
test ecx,4000h
jz .dsp4continue
ret
.dsp4continue
%endmacro
NEWSYM DSP4Read8b
RouteAccess regaccessbankr8
mov [dsp4_address],cx
pushad
call DSP4GetByte
popad
mov al,[dsp4_byte]
ret
NEWSYM DSP4Write8b
RouteAccess regaccessbankw8
mov [dsp4_address],cx
mov [dsp4_byte],al
pushad
call DSP4SetByte
popad
ret
NEWSYM DSP4Read16b
RouteAccess regaccessbankr16
mov [dsp4_address],cx
pushad
call DSP4GetByte
mov al,[dsp4_byte]
mov [dsp4temp],al
inc word[dsp4_address]
call DSP4GetByte
popad
mov al,[dsp4temp]
mov ah,[dsp4_byte]
ret
NEWSYM DSP4Write16b
RouteAccess regaccessbankw16
mov [dsp4_address],cx
mov [dsp4_byte],al
mov [dsp4temp],ah
pushad
call DSP4SetByte
mov ah,[dsp4temp]
mov [dsp4_byte],ah
inc word[dsp4_address]
call DSP4SetByte
popad
ret
SECTION .bss
NEWSYM dsp4temp, resb 1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,827 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro FETCHPIPE 0
; mov edx,[SfxPBR]
; mov edx,[SfxMemTable+edx*4]
; mov edx,[SfxCPB]
; mov edx,[SfxR15]
mov cl,[ebp]
%endmacro
%macro UpdateR14 0
; mov edx,[SfxROMBR]
; mov edx,[SfxMemTable+edx*4]
mov eax,[SfxCROM]
; and dword[SfxR14],0FFFFh
add eax,[SfxR14]
mov [SfxRomBuffer],eax
%endmacro
%macro CLRFLAGS 0
;and dword[SfxSFR],0FFFFh-0100h-0200h-1000h ; Clear ALT1,ALT2 and B Flags
; xor ch,ch
; mov dword[SfxB],0 ; Clear B Flag
; mov esi,SfxR0
; mov edi,SfxR0
%endmacro
%macro TORN 1 ; V
FETCHPIPE
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov edi,SfxR0
ret
%endmacro
%macro WITH 1 ; Verified.
FETCHPIPE
mov esi,SfxR0+%1*4
mov edi,SfxR0+%1*4
mov dword[SfxB],1
inc ebp ; Increase program counter
call [FxTablec+ecx*4]
mov esi,SfxR0
mov edi,SfxR0
mov dword[SfxB],0 ; Clear B Flag
ret
%endmacro
%macro STWRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
add dword[SfxLastRamAdr],ebx ; Save last ram address
mov edx,[esi] ; Read Source
FETCHPIPE
mov [ebx+eax],dl ; Store Word
xor eax,1
inc ebp ; Increase program counter
mov [ebx+eax],dh ; Store Word
CLRFLAGS
ret
%endmacro
%macro STBRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
mov ebx,[esi] ; Read Source
mov [eax],bl ; Store Byte
CLRFLAGS
inc ebp ; Increase program counter
ret
%endmacro
%macro LDWRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
FETCHPIPE
mov dl,[ebx+eax] ; Store Word
add dword[SfxLastRamAdr],ebx ; Save last ram address
xor eax,1
and edx,0FFFFh
inc ebp ; Increase program counter
mov dh,[ebx+eax] ; Store Word
mov [edi],edx ; Read Source
CLRFLAGS
ret
%endmacro
%macro LDBRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
xor ebx,ebx
mov [SfxLastRamAdr],eax ; Save last ram address
mov bl,[eax] ; Read Byte
inc ebp ; Increase program counter
mov [edi],ebx ; Store Result
CLRFLAGS
ret
%endmacro
; test byte[SfxPOR],01h
; jnz .nozerocheck
; test byte[SfxPOR],02h
; jz .nodither
; **** Can pre-calculate [SfxSCBR] << 10 + [sfxramdata]
; Pre-calculate fxbit values from color register
%macro drawpix4b 0
and [eax],edx
and [eax+16],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax], ebx
and edx,[fxbit23pcal]
or [eax+16], edx
%endmacro
%macro drawpix4bd 0
and [eax],edx
and [eax+16],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax], ebx
and edx,[fxbit67pcal]
or [eax+16], edx
%endmacro
%macro drawpix2b 0
and [eax],edx
xor edx,0FFFFFFFFh
and edx,[fxbit01pcal]
or [eax], edx
%endmacro
%macro drawpix2bd 0
and [eax],edx
xor edx,0FFFFFFFFh
and edx,[fxbit45pcal]
or [eax], edx
%endmacro
%macro drawpix8b 0
and [eax],edx
and [eax+16],edx
and [eax+32],edx
and [eax+48],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax], ebx
mov ebx,[fxbit23pcal]
and ebx,edx
or [eax+16], ebx
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax+32], ebx
and edx,[fxbit67pcal]
or [eax+48], edx
%endmacro
%macro drawpix8bd 0
and [eax],edx
and [eax+16],edx
and [eax+32],edx
and [eax+48],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax], ebx
mov ebx,[fxbit67pcal]
and ebx,edx
or [eax+16], ebx
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax+32], ebx
and edx,[fxbit23pcal]
or [eax+48], edx
%endmacro
%macro plotb 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
%2
%endmacro
%macro plotbz 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
test byte[SfxCOLR],%5
jz .nodraw
%2
%endmacro
%macro plotbd 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
mov bl,[SfxR1]
xor bl,[SfxR2]
test bl,01h
jz .nodither4b
%4
inc word[SfxR1]
%1
.nodither4b
%2
%endmacro
%macro plotbzd 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
test byte[SfxCOLR],%5
jz near .nodraw
mov bl,[SfxR1]
xor bl,[SfxR2]
test bl,01h
jz .nodither4b
%4
inc word[SfxR1]
%1
.nodither4b
%2
%endmacro
%macro plotlines4b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix4b, 5, drawpix4bd, 0Fh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines4bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 FXReturn, drawpix4b, 5, drawpix4bd, 0Fh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines2b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 ret, drawpix2b, 4, drawpix2bd, 03h
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines2bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 FXReturn, drawpix2b, 4, drawpix2bd, 03h
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines8b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix8b, 6, drawpix8bd, 0FFh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines8bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 FXReturn, drawpix8b, 6, drawpix8bd, 0FFh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines8bl 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix8b, 6, drawpix8bd, 0Fh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines8bbl 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 FXReturn, drawpix8b, 6, drawpix8bd, 0Fh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro ADDRN 1 ; V
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
FETCHPIPE
add ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADCRN 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
shr byte[SfxCarry],1
adc ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADIRN 1 ; V
mov eax, [esi] ; Read Source
FETCHPIPE
add ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADCIRN 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
shr byte[SfxCarry],1
adc ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro SUBRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro SBCRN 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
cmp byte[SfxCarry],1
sbb ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro SUBIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
sub ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro CMPRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
mov [SfxSignZero],eax
CLRFLAGS
inc ebp ; Increase program counter
ret
%endmacro
%macro ANDRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read RN
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro BICRN 1 ; V
mov ebx,[SfxR0+%1*4] ; Read RN
mov eax,[esi] ; Read Source
xor ebx,0FFFFh
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ANDIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro BICIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro MULTRN 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro UMULTRN 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro MULTIRN 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro UMULTIRN 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro LINK 1 ; Verified.
mov eax,ebp
sub eax,[SfxCPB]
add eax,%1
FETCHPIPE
mov [SfxR11],ax
CLRFLAGS
inc ebp
ret
%endmacro
%macro JMPRN 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read RN
mov ebp,[SfxCPB]
add ebp,eax
CLRFLAGS
ret
%endmacro
%macro LJMPRN 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4]
and eax,07Fh
mov [SfxPBR],al
; mov byte[fxtrace+eax],1
mov eax,[SfxMemTable+eax*4]
mov [SfxCPB],eax
mov ebp,eax
add ebp,[esi] ; Read RN
mov dword[SfxCacheActive],0
push ecx
call FxOp02
pop ecx
dec ebp
ret
%endmacro
%macro IBTRN 1 ; V
movsx eax,byte[ebp]
mov cl,[ebp+1]
add ebp,2
mov [SfxR0+%1*4],ax
CLRFLAGS
ret
%endmacro
%macro LMSRN 1 ; Verified.
xor eax,eax
mov al,[ebp]
add eax,eax
inc ebp
add eax,[SfxRAMMem]
mov cl,[ebp]
mov [SfxLastRamAdr],eax
mov ebx,[eax] ; Read word from ram
inc ebp
mov [SfxR0+%1*4],bx ; Write data
CLRFLAGS
ret
%endmacro
%macro SMSRN 1 ; Verified.
xor eax,eax
mov al,[ebp]
inc ebp
add eax,eax
mov cl,[ebp]
add eax,[SfxRAMMem]
mov ebx,[SfxR0+%1*4] ; Read data
mov [SfxLastRamAdr],eax
inc ebp
mov [eax],bx ; Write word to ram
CLRFLAGS
ret
%endmacro
%macro FROMRN 1 ; V
FETCHPIPE
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
ret
%endmacro
%macro ORRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
or eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro XORRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
xor eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro ORI 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
or eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro XORI 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
xor eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro INCRN 1 ; Verified
inc word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
ret
%endmacro
%macro DECRN 1 ; Verified
dec word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxR0+%1*4],eax
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
ret
%endmacro
%macro IWTRN 1 ; aka LEA ; Verified.
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
add ebp,3
mov [SfxR0+%1*4],eax
CLRFLAGS
ret
%endmacro
%macro LMRN 1 ; Verified!
xor eax,eax
mov cl,[ebp+2]
mov ax,[ebp]
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov dl,[eax+ebx]
xor eax,1
add ebp,3
mov dh,[eax+ebx]
mov [SfxR0+%1*4],dx ; Store Word
CLRFLAGS
ret
%endmacro
%macro SMRN 1 ; Verified
mov ebx,[SfxR0+%1*4]
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
mov dx,bx
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov [eax+ebx],dl
xor eax,1
add ebp,3
mov [eax+ebx],dh
CLRFLAGS
ret
%endmacro
%macro PackEsiEdi 0
mov eax,[SfxSREG]
shl eax,2
add eax,SfxR0
mov esi,eax
mov eax,[SfxDREG]
shl eax,2
add eax,SfxR0
mov edi,eax
mov eax,[SfxRAMBR]
shl eax,16
add eax,[sfxramdata]
mov [SfxRAMMem],eax
%endmacro
%macro UnPackEsiEdi 0
mov eax,esi
sub eax,SfxR0
shr eax,2
mov [SfxSREG],eax
mov eax,edi
sub eax,SfxR0
shr eax,2
mov [SfxDREG],eax
%endmacro

View File

@@ -0,0 +1,615 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM FxTable,FxTableb,FxTablec,SfxB,SfxCPB,SfxCROM,SfxCarry,SfxOverflow
EXTSYM SfxR0,SfxR14,SfxR15,SfxRomBuffer,SfxSignZero,withr15sk
%include "chips/fxemu2.mac"
%include "chips/fxemu2b.mac"
SECTION .text
NEWSYM FxOpb05 ; BRA branch always ; Verified.
movsx eax,byte[ebp]
mov cl,[ebp+1]
inc ebp
add ebp,eax
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb06 ; BGE branch on greater or equals ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb07 ; BLT branch on lesss than ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb08 ; BNE branch on not equal ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb09 ; BEQ branch on equal (z=1) ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0A ; BPL branch on plus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0B ; BMI branch on minus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0C ; BCC branch on carry clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0D ; BCS branch on carry set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0E ; BVC branch on overflow clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0F ; BVS branch on overflow set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb10 ; TO RN set register n as destination register
TORNb 0
NEWSYM FxOpb11 ; TO RN set register n as destination register
TORNb 1
NEWSYM FxOpb12 ; TO RN set register n as destination register
TORNb 2
NEWSYM FxOpb13 ; TO RN set register n as destination register
TORNb 3
NEWSYM FxOpb14 ; TO RN set register n as destination register
TORNb 4
NEWSYM FxOpb15 ; TO RN set register n as destination register
TORNb 5
NEWSYM FxOpb16 ; TO RN set register n as destination register
TORNb 6
NEWSYM FxOpb17 ; TO RN set register n as destination register
TORNb 7
NEWSYM FxOpb18 ; TO RN set register n as destination register
TORNb 8
NEWSYM FxOpb19 ; TO RN set register n as destination register
TORNb 9
NEWSYM FxOpb1A ; TO RN set register n as destination register
TORNb 10
NEWSYM FxOpb1B ; TO RN set register n as destination register
TORNb 11
NEWSYM FxOpb1C ; TO RN set register n as destination register
TORNb 12
NEWSYM FxOpb1D ; TO RN set register n as destination register
TORNb 13
NEWSYM FxOpb1E ; TO RN set register n as destination register
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi,SfxR0+14*4
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov dword[withr15sk],1
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov edi,SfxR0
UpdateR14
ret
.VersionB
mov eax,[esi] ; Read Source
mov dword[withr15sk],1
mov [SfxR0+14*4],eax ; Write
CLRFLAGS
UpdateR14
inc ebp ; Increase program counter
ret
NEWSYM FxOpb1F ; TO RN set register n as destination register
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi,SfxR0+15*4
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov ebp,[SfxCPB]
mov dword[withr15sk],1
add ebp,[SfxR15]
mov edi,SfxR0
ret
.VersionB
mov eax,[esi] ; Read Source
mov ebp,[SfxCPB]
mov dword[withr15sk],1
add ebp,eax
CLRFLAGS
ret
NEWSYM FxOpb3D ; ALT1 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,01h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
xor ch,ch
ret
NEWSYM FxOpb3E ; ALT2 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,02h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTable+ecx*4]
xor ch,ch
ret
NEWSYM FxOpb3F ; ALT3 set alt3 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,03h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTable+ecx*4]
xor ch,ch
ret
NEWSYM FxOpbB0 ; FROM rn set source register
FROMRNb 0
NEWSYM FxOpbB1 ; FROM rn set source register
FROMRNb 1
NEWSYM FxOpbB2 ; FROM rn set source register
FROMRNb 2
NEWSYM FxOpbB3 ; FROM rn set source register
FROMRNb 3
NEWSYM FxOpbB4 ; FROM rn set source register
FROMRNb 4
NEWSYM FxOpbB5 ; FROM rn set source register
FROMRNb 5
NEWSYM FxOpbB6 ; FROM rn set source register
FROMRNb 6
NEWSYM FxOpbB7 ; FROM rn set source register
FROMRNb 7
NEWSYM FxOpbB8 ; FROM rn set source register
FROMRNb 8
NEWSYM FxOpbB9 ; FROM rn set source register
FROMRNb 9
NEWSYM FxOpbBA ; FROM rn set source register
FROMRNb 10
NEWSYM FxOpbBB ; FROM rn set source register
FROMRNb 11
NEWSYM FxOpbBC ; FROM rn set source register
FROMRNb 12
NEWSYM FxOpbBD ; FROM rn set source register
FROMRNb 13
NEWSYM FxOpbBE ; FROM rn set source register
FROMRNb 14
NEWSYM FxOpbBF ; FROM rn set source register
test dword[SfxB],1
jnz .VersionB
mov esi,SfxR0+15*4
inc ebp ; Increase program counter
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov esi,SfxR0
ret
.VersionB
FETCHPIPE
mov eax,ebp
sub eax,[SfxCPB]
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
NEWSYM FxOpc05 ; BRA branch always ; Verified.
movsx eax,byte[ebp]
mov cl,[ebp+1]
inc ebp
add ebp,eax
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc06 ; BGE branch on greater or equals ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc07 ; BLT branch on lesss than ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc08 ; BNE branch on not equal ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc09 ; BEQ branch on equal (z=1) ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0A ; BPL branch on plus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0B ; BMI branch on minus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0C ; BCC branch on carry clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0D ; BCS branch on carry set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0E ; BVC branch on overflow clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0F ; BVS branch on overflow set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc10 ; TO RN set register n as destination register
TORNc 0
NEWSYM FxOpc11 ; TO RN set register n as destination register
TORNc 1
NEWSYM FxOpc12 ; TO RN set register n as destination register
TORNc 2
NEWSYM FxOpc13 ; TO RN set register n as destination register
TORNc 3
NEWSYM FxOpc14 ; TO RN set register n as destination register
TORNc 4
NEWSYM FxOpc15 ; TO RN set register n as destination register
TORNc 5
NEWSYM FxOpc16 ; TO RN set register n as destination register
TORNc 6
NEWSYM FxOpc17 ; TO RN set register n as destination register
TORNc 7
NEWSYM FxOpc18 ; TO RN set register n as destination register
TORNc 8
NEWSYM FxOpc19 ; TO RN set register n as destination register
TORNc 9
NEWSYM FxOpc1A ; TO RN set register n as destination register
TORNc 10
NEWSYM FxOpc1B ; TO RN set register n as destination register
TORNc 11
NEWSYM FxOpc1C ; TO RN set register n as destination register
TORNc 12
NEWSYM FxOpc1D ; TO RN set register n as destination register
TORNc 13
NEWSYM FxOpc1E ; TO RN set register n as destination register
FETCHPIPE
mov eax,[esi] ; Read Source
mov [SfxR0+14*4],eax ; Write
CLRFLAGS
UpdateR14
inc ebp ; Increase program counter
ret
NEWSYM FxOpc1F ; TO RN set register n as destination register
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebp,[SfxCPB]
mov [SfxR15],eax
add ebp,eax
CLRFLAGS
ret
NEWSYM FxOpc3D ; ALT1 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,01h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpc3E ; ALT2 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,02h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpc3F ; ALT3 set alt3 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,03h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpcB0 ; FROM rn set source register
FROMRNc 0
NEWSYM FxOpcB1 ; FROM rn set source register
FROMRNc 1
NEWSYM FxOpcB2 ; FROM rn set source register
FROMRNc 2
NEWSYM FxOpcB3 ; FROM rn set source register
FROMRNc 3
NEWSYM FxOpcB4 ; FROM rn set source register
FROMRNc 4
NEWSYM FxOpcB5 ; FROM rn set source register
FROMRNc 5
NEWSYM FxOpcB6 ; FROM rn set source register
FROMRNc 6
NEWSYM FxOpcB7 ; FROM rn set source register
FROMRNc 7
NEWSYM FxOpcB8 ; FROM rn set source register
FROMRNc 8
NEWSYM FxOpcB9 ; FROM rn set source register
FROMRNc 9
NEWSYM FxOpcBA ; FROM rn set source register
FROMRNc 10
NEWSYM FxOpcBB ; FROM rn set source register
FROMRNc 11
NEWSYM FxOpcBC ; FROM rn set source register
FROMRNc 12
NEWSYM FxOpcBD ; FROM rn set source register
FROMRNc 13
NEWSYM FxOpcBE ; FROM rn set source register
FROMRNc 14
NEWSYM FxOpcBF ; FROM rn set source register
FETCHPIPE
mov eax,ebp
sub eax,[SfxCPB]
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret

View File

@@ -0,0 +1,92 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro TORNb 1 ; V
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
mov eax,ebp
sub eax,[SfxCPB]
mov dword[withr15sk],1
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov edi,SfxR0
ret
.VersionB
mov eax,[esi] ; Read Source
mov dword[withr15sk],1
inc ebp ; Increase program counter
mov [SfxR0+%1*4],eax ; Write
CLRFLAGS
ret
%endmacro
%macro FROMRNb 1 ; V
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
ret
.VersionB
mov eax,[SfxR0+%1*4] ; Read
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
%endmacro
%macro TORNc 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
inc ebp ; Increase program counter
mov [SfxR0+%1*4],eax ; Write
CLRFLAGS
ret
%endmacro
%macro FROMRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
%endmacro

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,532 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro FXReturn 0
dec dword[NumberOfOpcodes]
;pushad
js %%endloop
;call WriteLine
;popad
%%blah
jmp [FxTabled+ecx*4]
%%endloop
jmp FXEndLoop
ALIGN32
%endmacro
%macro FXReturn2 0
dec dword[NumberOfOpcodes]
js %%endloop
jmp [FxTabled+ecx*4]
%%endloop
jmp FXEndLoop
ALIGN32
%endmacro
%macro TORNd 1 ; V
FETCHPIPE
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov edi,SfxR0
FXReturn
%endmacro
%macro WITHc 1 ; Verified.
FETCHPIPE
mov esi,SfxR0+%1*4
mov edi,SfxR0+%1*4
mov dword[SfxB],1
inc ebp ; Increase program counter
call [FxTablec+ecx*4]
mov esi,SfxR0
mov edi,SfxR0
mov dword[SfxB],0 ; Clear B Flag
FXReturn
%endmacro
%macro STWRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
add dword[SfxLastRamAdr],ebx ; Save last ram address
mov edx,[esi] ; Read Source
FETCHPIPE
mov [ebx+eax],dl ; Store Word
xor eax,1
inc ebp ; Increase program counter
mov [ebx+eax],dh ; Store Word
CLRFLAGS
FXReturn
%endmacro
%macro STBRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
mov ebx,[esi] ; Read Source
mov [eax],bl ; Store Byte
CLRFLAGS
inc ebp ; Increase program counter
FXReturn
%endmacro
%macro LDWRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
FETCHPIPE
mov dl,[ebx+eax] ; Store Word
add dword[SfxLastRamAdr],ebx ; Save last ram address
xor eax,1
and edx,0FFFFh
inc ebp ; Increase program counter
mov dh,[ebx+eax] ; Store Word
mov [edi],edx ; Read Source
CLRFLAGS
FXReturn
%endmacro
%macro LDBRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
xor ebx,ebx
mov [SfxLastRamAdr],eax ; Save last ram address
mov bl,[eax] ; Read Byte
inc ebp ; Increase program counter
mov [edi],ebx ; Store Result
CLRFLAGS
FXReturn
%endmacro
%macro ADDRNc 1 ; V
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
FETCHPIPE
add ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADCRNc 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
shr byte[SfxCarry],1
adc ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADIRNc 1 ; V
mov eax, [esi] ; Read Source
FETCHPIPE
add ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADCIRNc 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
shr byte[SfxCarry],1
adc ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro SUBRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro SBCRNc 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
cmp byte[SfxCarry],1
sbb ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro SUBIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
sub ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro CMPRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
mov [SfxSignZero],eax
CLRFLAGS
inc ebp ; Increase program counter
FXReturn
%endmacro
%macro ANDRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read RN
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro BICRNc 1 ; V
mov ebx,[SfxR0+%1*4] ; Read RN
mov eax,[esi] ; Read Source
xor ebx,0FFFFh
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ANDIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro BICIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro MULTRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro UMULTRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro MULTIRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro UMULTIRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro LINKc 1 ; Verified.
mov eax,ebp
sub eax,[SfxCPB]
add eax,%1
FETCHPIPE
mov [SfxR11],ax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro JMPRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read RN
mov ebp,[SfxCPB]
add ebp,eax
CLRFLAGS
FXReturn
%endmacro
%macro LJMPRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4]
and eax,07Fh
mov [SfxPBR],al
; mov byte[fxtrace+eax],1
mov eax,[SfxMemTable+eax*4]
mov [SfxCPB],eax
mov ebp,eax
add ebp,[esi] ; Read RN
mov dword[SfxCacheActive],0
push ecx
call FxOp02
pop ecx
dec ebp
FXReturn
%endmacro
%macro IBTRNc 1 ; V
movsx eax,byte[ebp]
mov cl,[ebp+1]
add ebp,2
mov [SfxR0+%1*4],ax
CLRFLAGS
FXReturn
%endmacro
%macro LMSRNc 1 ; Verified.
xor eax,eax
mov al,[ebp]
add eax,eax
inc ebp
add eax,[SfxRAMMem]
mov cl,[ebp]
mov [SfxLastRamAdr],eax
mov ebx,[eax] ; Read word from ram
inc ebp
mov [SfxR0+%1*4],bx ; Write data
CLRFLAGS
FXReturn
%endmacro
%macro SMSRNc 1 ; Verified.
xor eax,eax
mov al,[ebp]
inc ebp
add eax,eax
mov cl,[ebp]
add eax,[SfxRAMMem]
mov ebx,[SfxR0+%1*4] ; Read data
mov [SfxLastRamAdr],eax
inc ebp
mov [eax],bx ; Write word to ram
CLRFLAGS
FXReturn
%endmacro
%macro FROMRNd 1 ; V
FETCHPIPE
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
FXReturn
%endmacro
%macro ORRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
or eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro XORRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
xor eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro ORIc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
or eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro XORIc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
xor eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro INCRNc 1 ; Verified
inc word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro DECRNc 1 ; Verified
dec word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxR0+%1*4],eax
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro IWTRNc 1 ; aka LEA ; Verified.
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
add ebp,3
mov [SfxR0+%1*4],eax
CLRFLAGS
FXReturn
%endmacro
%macro LMRNc 1 ; Verified!
xor eax,eax
mov cl,[ebp+2]
mov ax,[ebp]
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov dl,[eax+ebx]
xor eax,1
add ebp,3
mov dh,[eax+ebx]
mov [SfxR0+%1*4],dx ; Store Word
CLRFLAGS
FXReturn
%endmacro
%macro SMRNc 1 ; Verified
mov ebx,[SfxR0+%1*4]
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
mov dx,bx
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov [eax+ebx],dl
xor eax,1
add ebp,3
mov [eax+ebx],dh
CLRFLAGS
FXReturn
%endmacro

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
typedef unsigned char bool8;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int16;
typedef long int32;
//C++ in C
typedef unsigned char bool;
#define true 1
#define false 0
static uint8 *OBC1_RAM = 0;
int OBC1_Address;
int OBC1_BasePtr;
int OBC1_Shift;
uint16 obc1_address;
uint8 obc1_byte;
void GetOBC1 ()
{
switch(obc1_address) {
case 0x7ff0:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)];
break;
case 0x7ff1:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1];
break;
case 0x7ff2:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2];
break;
case 0x7ff3:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3];
break;
case 0x7ff4:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
break;
default:
obc1_byte = OBC1_RAM[obc1_address & 0x1fff];
}
}
void SetOBC1 ()
{
switch(obc1_address) {
case 0x7ff0:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)] = obc1_byte;
break;
}
case 0x7ff1:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1] = obc1_byte;
break;
}
case 0x7ff2:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2] = obc1_byte;
break;
}
case 0x7ff3:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3] = obc1_byte;
break;
}
case 0x7ff4:
{
unsigned char Temp;
Temp = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
Temp = (Temp & ~(3 << OBC1_Shift)) | ((obc1_byte & 3) << OBC1_Shift);
OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200] = Temp;
break;
}
case 0x7ff5:
{
if (obc1_byte & 1)
OBC1_BasePtr = 0x1800;
else
OBC1_BasePtr = 0x1c00;
break;
}
case 0x7ff6:
{
OBC1_Address = obc1_byte & 0x7f;
OBC1_Shift = (obc1_byte & 3) << 1;
break;
}
}
OBC1_RAM[obc1_address & 0x1fff] = obc1_byte;
}
extern unsigned char *romdata;
void InitOBC1()
{
OBC1_RAM = romdata+0x400000;
if (OBC1_RAM[0x1ff5] & 1)
OBC1_BasePtr = 0x1800;
else
OBC1_BasePtr = 0x1c00;
OBC1_Address = OBC1_RAM[0x1ff6] & 0x7f;
OBC1_Shift = (OBC1_RAM[0x1ff6] & 3) << 1;
}

View File

@@ -0,0 +1,82 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM obc1_address,obc1_byte,SetOBC1,GetOBC1
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
EXTSYM memaccessbankr16,memaccessbankr8,memaccessbankw16,memaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jnz memaccessbank%1
cmp ecx,6000h
jb regaccessbank%1
%endmacro
NEWSYM OBC1Read8b
RouteAccess r8
mov [obc1_address],cx
pushad
call GetOBC1
popad
mov al,[obc1_byte]
ret
NEWSYM OBC1Write8b
RouteAccess w8
mov [obc1_address],cx
mov [obc1_byte],al
pushad
call SetOBC1
popad
ret
NEWSYM OBC1Read16b
RouteAccess r16
mov [obc1_address],cx
pushad
call GetOBC1
mov al,[obc1_byte]
mov [obc1temp],al
inc word[obc1_address]
call GetOBC1
popad
mov al,[obc1temp]
mov ah,[obc1_byte]
ret
NEWSYM OBC1Write16b
RouteAccess w16
mov [obc1_address],cx
mov [obc1_byte],al
mov [obc1temp],ah
pushad
call SetOBC1
mov ah,[obc1temp]
mov [obc1_byte],ah
inc word[obc1_address]
call SetOBC1
popad
ret
SECTION .bss
NEWSYM obc1temp, resb 1

View File

@@ -0,0 +1,363 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM initaddrl,wramdata,IRAM,SA1DoIRQ,SNSRegP,SNSRegPCS
EXTSYM SA1Ptr,SNSPtr,snesmap2,SA1tablead,SA1xpb,SA1RegP,wramdataa,SA1TimerVal
EXTSYM SA1RegPCS,SA1BWPtr,SNSBWPtr,CurBWPtr,SA1NMIV,SA1IRQV
EXTSYM membank0w8,SA1LBound,SA1UBound,SA1SH,SA1SHb,stackor,stackand,snesmmap
EXTSYM SA1xs,SA1IRQExec,SA1Message,Sflagnz,Sflagc,Sflago
; In exec loop, jump to execloop if SA1Status != 0
; *** Disable spc700 if possible ***
SECTION .bss
NEWSYM SA1Status, resb 1 ; 0 = 65816, 1 = SA1A, 2 = SA1B
NEWSYM CurrentExecSA1, resb 1
NEWSYM CurrentCPU, resb 1
;ALIGN32
NEWSYM prevedi, resd 1
SECTION .text
%macro SA1Debugb 0
pushad
sub esi,[initaddrl]
mov [SA1xpc],esi
call nextopcodesa1
popad
mov bl,[esi]
xor dh,dh
inc esi
call dword near [edi+ebx*4]
dec esi
%endmacro
%macro SA1Debug 0
; debug version
test byte[debugds],01h
jz near .nodebug
cmp byte[debuggeron],0
je near .nodebug
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
jmp .debug
.nodebug
%endmacro
NEWSYM SA1Swap
mov ecx,[SA1BWPtr]
mov eax,[SA1Ptr] ; small speed hack
test byte[SA1DoIRQ],1
jnz near .sa1exec3
cmp byte[IRAM],0
jne .sa1exec2
cmp dword[eax],0FCF000A5h
je near .nosa1exec
cmp dword[eax-2],0FCF000A5h
je near .nosa1exec
.sa1exec2
cmp byte[SA1SHb],1
je near .nosa1execb
cmp word[ecx+72A4h],0
jnz .sa1exec
cmp dword[eax],0F072A4ADh
je near .nosa1execb
.sa1exec
cmp byte[IRAM+72h],0
jne .sa1exec3
cmp dword[eax],0F03072ADh
je near .nosa1execb
.sa1exec3
.yesdebugr
xor ecx,ecx
; store all snes 65816 stuff
mov [SNSRegP],dl
mov eax,[initaddrl]
mov [prevedi],edi
mov [SNSRegPCS],eax
mov [SNSPtr],esi
; restore all sa1 65816 stuff
mov dl,[SA1RegP]
mov eax,[SA1RegPCS]
mov [initaddrl],eax
mov eax,[SA1BWPtr]
mov [CurBWPtr],eax
mov esi,[SA1Ptr]
mov dword[snesmap2],IRAM
mov dword[wramdata],IRAM
; Check if IRQ is executed on SA-1
xor eax,eax
mov al,dl
add dh,20
mov edi,[SA1tablead+eax*4]
mov byte[SA1Status],1
test dword[SA1DoIRQ],0FF000003h
jnz near .switchirq
.returnirq
; SA1Debug
; cmp byte[SA1SH],1
; je near .speedhack
; non debug version
mov bl,[esi]
inc esi
call dword near [edi+ebx*4]
dec esi
.debug
; store all sa1 65816 stuff
mov [SA1RegP],dl
mov eax,[initaddrl]
mov [SA1RegPCS],eax
mov [SA1Ptr],esi
; restore all snes 65816 stuff
mov dl,[SNSRegP]
mov eax,[SNSRegPCS]
mov [initaddrl],eax
mov eax,[SNSBWPtr]
mov [CurBWPtr],eax
mov dword[wramdata],wramdataa
mov esi,[SNSPtr]
mov eax,[wramdata]
mov [snesmap2],eax
mov edi,[prevedi]
xor eax,eax
add dh,11
inc byte[CurrentExecSA1]
mov byte[SA1Status],0
add dword[SA1TimerVal],23
ret
.speedhack
add dh,90
mov bl,[esi]
inc esi
call dword near [edi+ebx*4]
dec esi
; store all sa1 65816 stuff
mov [SA1RegP],dl
mov eax,[initaddrl]
mov [SA1RegPCS],eax
mov [SA1Ptr],esi
; restore all snes 65816 stuff
mov dl,[SNSRegP]
mov eax,[SNSRegPCS]
mov [initaddrl],eax
mov eax,[SNSBWPtr]
mov [CurBWPtr],eax
mov dword[wramdata],wramdataa
mov esi,[SNSPtr]
mov eax,[wramdata]
mov [snesmap2],eax
mov edi,[prevedi]
xor eax,eax
add byte[CurrentExecSA1],4
mov byte[SA1Status],0
add dword[SA1TimerVal],23
xor dh,dh
mov dh,18
cmp esi,dword[SA1LBound]
jb .stoph
cmp esi,dword[SA1UBound]
ja .stoph
ret
.stoph
mov byte[SA1SH],0
ret
.nosa1execb
xor ecx,ecx
add dh,15
add byte[CurrentExecSA1],2
mov byte[SA1Status],0
ret
.nosa1exec
xor ecx,ecx
add dh,18
add byte[CurrentExecSA1],2
mov byte[SA1Status],0
ret
.switchirq
test dword[SA1DoIRQ],3
jz .notirq
test dword[SA1DoIRQ],1
jz .nmi
and byte[SA1DoIRQ],0FEh
call SA1switchtovirq
jmp .returnirq
.nmi
and byte[SA1DoIRQ],0FDh
call SA1switchtonmi
jmp .returnirq
.notirq
dec byte[SA1DoIRQ+3]
jz .hack
jmp .returnirq
.hack
or byte[SA1DoIRQ],8
jmp .returnirq
SECTION .bss
NEWSYM SA1xpc, resd 1
SECTION .text
%macro makedl 0
and dl,00111100b
test dword[Sflagnz],18000h
jz %%noneg
or dl,80h
%%noneg
test dword[Sflagnz],0FFFFh
jnz %%nozero
or dl,02h
%%nozero
test dword[Sflagc],0FFh
jz %%nocarry
or dl,01h
%%nocarry
test dword[Sflago],0FFh
jz %%nov
or dl,40h
%%nov
%endmacro
NEWSYM SA1switchtonmi
mov al,[SA1Message]
mov [SA1Message+2],al
mov byte[SA1IRQExec+2],1
mov ebx,esi
sub ebx,[initaddrl]
mov [SA1xpc],bx
xor ecx,ecx
mov cx,[SA1xs]
mov al,[SA1xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [SA1xs],cx
xor ebx,ebx
mov [SA1xpb],bl
xor eax,eax
mov ax,[SA1NMIV]
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
NEWSYM SA1switchtovirq
mov al,[SA1Message]
mov [SA1Message+2],al
mov byte[SA1IRQExec+1],1
mov ebx,esi
sub ebx,[initaddrl]
mov [SA1xpc],bx
xor ecx,ecx
mov cx,[SA1xs]
mov al,[SA1xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [SA1xs],cx
xor ebx,ebx
mov [SA1xpb],bl
xor eax,eax
mov ax,[SA1IRQV]
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
ret

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,271 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*******************************************************************************
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive and John Weidman
*******************************************************************************/
/* S-DD1 decompressor
*
* Based on code and documentation by Andreas Naive, who deserves a great deal
* of thanks and credit for figuring this out.
*
* Andreas says:
* The author is greatly indebted with The Dumper, without whose help and
* patience providing him with real S-DD1 data the research had never been
* possible. He also wish to note that in the very beggining of his research,
* Neviksti had done some steps in the right direction. By last, the author is
* indirectly indebted to all the people that worked and contributed in the
* S-DD1 issue in the past.
*/
#include <string.h>
#ifndef __GNUC__
#define INLINE
#else
#define INLINE static inline
#endif
static int valid_bits;
static unsigned short in_stream;
static unsigned char *in_buf;
static unsigned char bit_ctr[8];
static unsigned char context_states[32];
static int context_MPS[32];
static int bitplane_type;
static int high_context_bits;
static int low_context_bits;
static int prev_bits[8];
static struct {
unsigned char code_size;
unsigned char MPS_next;
unsigned char LPS_next;
} evolution_table[] = {
/* 0 */ { 0,25,25},
/* 1 */ { 0, 2, 1},
/* 2 */ { 0, 3, 1},
/* 3 */ { 0, 4, 2},
/* 4 */ { 0, 5, 3},
/* 5 */ { 1, 6, 4},
/* 6 */ { 1, 7, 5},
/* 7 */ { 1, 8, 6},
/* 8 */ { 1, 9, 7},
/* 9 */ { 2,10, 8},
/* 10 */ { 2,11, 9},
/* 11 */ { 2,12,10},
/* 12 */ { 2,13,11},
/* 13 */ { 3,14,12},
/* 14 */ { 3,15,13},
/* 15 */ { 3,16,14},
/* 16 */ { 3,17,15},
/* 17 */ { 4,18,16},
/* 18 */ { 4,19,17},
/* 19 */ { 5,20,18},
/* 20 */ { 5,21,19},
/* 21 */ { 6,22,20},
/* 22 */ { 6,23,21},
/* 23 */ { 7,24,22},
/* 24 */ { 7,24,23},
/* 25 */ { 0,26, 1},
/* 26 */ { 1,27, 2},
/* 27 */ { 2,28, 4},
/* 28 */ { 3,29, 8},
/* 29 */ { 4,30,12},
/* 30 */ { 5,31,16},
/* 31 */ { 6,32,18},
/* 32 */ { 7,24,22}
};
static unsigned char run_table[128] = {
128, 64, 96, 32, 112, 48, 80, 16, 120, 56, 88, 24, 104, 40, 72,
8, 124, 60, 92, 28, 108, 44, 76, 12, 116, 52, 84, 20, 100, 36,
68, 4, 126, 62, 94, 30, 110, 46, 78, 14, 118, 54, 86, 22, 102,
38, 70, 6, 122, 58, 90, 26, 106, 42, 74, 10, 114, 50, 82, 18,
98, 34, 66, 2, 127, 63, 95, 31, 111, 47, 79, 15, 119, 55, 87,
23, 103, 39, 71, 7, 123, 59, 91, 27, 107, 43, 75, 11, 115, 51,
83, 19, 99, 35, 67, 3, 125, 61, 93, 29, 109, 45, 77, 13, 117,
53, 85, 21, 101, 37, 69, 5, 121, 57, 89, 25, 105, 41, 73, 9,
113, 49, 81, 17, 97, 33, 65, 1
};
INLINE unsigned char GetCodeword(int bits){
unsigned char tmp;
if(!valid_bits){
in_stream|=*(in_buf++);
valid_bits=8;
}
in_stream<<=1;
valid_bits--;
in_stream^=0x8000;
if(in_stream&0x8000) return 0x80+(1<<bits);
tmp=(in_stream>>8) | (0x7f>>bits);
in_stream<<=bits;
valid_bits-=bits;
if(valid_bits<0){
in_stream |= (*(in_buf++))<<(-valid_bits);
valid_bits+=8;
}
return run_table[tmp];
}
INLINE unsigned char GolombGetBit(int code_size){
if(!bit_ctr[code_size]) bit_ctr[code_size]=GetCodeword(code_size);
bit_ctr[code_size]--;
if(bit_ctr[code_size]==0x80){
bit_ctr[code_size]=0;
return 2; /* secret code for 'last zero'. ones are always last. */
}
return (bit_ctr[code_size]==0)?1:0;
}
INLINE unsigned char ProbGetBit(unsigned char context){
unsigned char state=context_states[context];
unsigned char bit=GolombGetBit(evolution_table[state].code_size);
if(bit&1){
context_states[context]=evolution_table[state].LPS_next;
if(state<2){
context_MPS[context]^=1;
return context_MPS[context]; /* just inverted, so just return it */
} else{
return context_MPS[context]^1; /* we know bit is 1, so use a constant */
}
} else if(bit){
context_states[context]=evolution_table[state].MPS_next;
/* zero here, zero there, no difference so drop through. */
}
return context_MPS[context]; /* we know bit is 0, so don't bother xoring */
}
INLINE unsigned char GetBit(unsigned char cur_bitplane){
unsigned char bit;
bit=ProbGetBit(((cur_bitplane&1)<<4)
| ((prev_bits[cur_bitplane]&high_context_bits)>>5)
| (prev_bits[cur_bitplane]&low_context_bits));
prev_bits[cur_bitplane] <<= 1;
prev_bits[cur_bitplane] |= bit;
return bit;
}
static unsigned char cur_plane;
static unsigned char num_bits;
static unsigned char next_byte;
void SDD1_init(unsigned char *in){
bitplane_type=in[0]>>6;
switch(in[0]&0x30){
case 0x00:
high_context_bits=0x01c0;
low_context_bits =0x0001;
break;
case 0x10:
high_context_bits=0x0180;
low_context_bits =0x0001;
break;
case 0x20:
high_context_bits=0x00c0;
low_context_bits =0x0001;
break;
case 0x30:
high_context_bits=0x0180;
low_context_bits =0x0003;
break;
}
in_stream=(in[0]<<11) | (in[1]<<3);
valid_bits=5;
in_buf=in+2;
memset(bit_ctr, 0, sizeof(bit_ctr));
memset(context_states, 0, sizeof(context_states));
memset(context_MPS, 0, sizeof(context_MPS));
memset(prev_bits, 0, sizeof(prev_bits));
cur_plane=0;
num_bits=0;
}
unsigned char SDD1_get_byte(void){
unsigned char bit;
unsigned char byte=0;
switch(bitplane_type){
case 0:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(0)) byte |= bit;
if(GetBit(1)) next_byte |= bit;
}
return byte;
} else {
return next_byte;
}
case 1:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(cur_plane)) byte |= bit;
if(GetBit(cur_plane+1)) next_byte |= bit;
}
return byte;
} else {
if(!num_bits) cur_plane = (cur_plane+2)&7;
return next_byte;
}
case 2:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(cur_plane)) byte |= bit;
if(GetBit(cur_plane+1)) next_byte |= bit;
}
return byte;
} else {
if(!num_bits) cur_plane ^= 2;
return next_byte;
}
case 3:
for(cur_plane=0, bit=1; bit; bit<<=1, cur_plane++){
if(GetBit(cur_plane)) byte |= bit;
}
return byte;
default:
/* should never happen */
return 0;
}
}

View File

@@ -0,0 +1,566 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//http://users.tpg.com.au/trauma/dsp/st010.html
#ifdef __UNIXSDL__
#include "gblhdr.h"
#else
#include <math.h> //sqrt()
#include <stdlib.h> //abs()
#endif
#define SRAM setaramdata
extern unsigned char *setaramdata;
void ST010DoCommand(void);
//C++ style code in C
#define bool unsigned char
#define true 1
#define false 0
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
// Mode 7 scaling constants for all raster lines
const int16 ST010_M7Scale[176] = {
0x0380, 0x0325, 0x02da, 0x029c, 0x0268, 0x023b, 0x0215, 0x01f3,
0x01d5, 0x01bb, 0x01a3, 0x018e, 0x017b, 0x016a, 0x015a, 0x014b,
0x013e, 0x0132, 0x0126, 0x011c, 0x0112, 0x0109, 0x0100, 0x00f8,
0x00f0, 0x00e9, 0x00e3, 0x00dc, 0x00d6, 0x00d1, 0x00cb, 0x00c6,
0x00c1, 0x00bd, 0x00b8, 0x00b4, 0x00b0, 0x00ac, 0x00a8, 0x00a5,
0x00a2, 0x009e, 0x009b, 0x0098, 0x0095, 0x0093, 0x0090, 0x008d,
0x008b, 0x0088, 0x0086, 0x0084, 0x0082, 0x0080, 0x007e, 0x007c,
0x007a, 0x0078, 0x0076, 0x0074, 0x0073, 0x0071, 0x006f, 0x006e,
0x006c, 0x006b, 0x0069, 0x0068, 0x0067, 0x0065, 0x0064, 0x0063,
0x0062, 0x0060, 0x005f, 0x005e, 0x005d, 0x005c, 0x005b, 0x005a,
0x0059, 0x0058, 0x0057, 0x0056, 0x0055, 0x0054, 0x0053, 0x0052,
0x0051, 0x0051, 0x0050, 0x004f, 0x004e, 0x004d, 0x004d, 0x004c,
0x004b, 0x004b, 0x004a, 0x0049, 0x0048, 0x0048, 0x0047, 0x0047,
0x0046, 0x0045, 0x0045, 0x0044, 0x0044, 0x0043, 0x0042, 0x0042,
0x0041, 0x0041, 0x0040, 0x0040, 0x003f, 0x003f, 0x003e, 0x003e,
0x003d, 0x003d, 0x003c, 0x003c, 0x003b, 0x003b, 0x003a, 0x003a,
0x003a, 0x0039, 0x0039, 0x0038, 0x0038, 0x0038, 0x0037, 0x0037,
0x0036, 0x0036, 0x0036, 0x0035, 0x0035, 0x0035, 0x0034, 0x0034,
0x0034, 0x0033, 0x0033, 0x0033, 0x0032, 0x0032, 0x0032, 0x0031,
0x0031, 0x0031, 0x0030, 0x0030, 0x0030, 0x0030, 0x002f, 0x002f,
0x002f, 0x002e, 0x002e, 0x002e, 0x002e, 0x002d, 0x002d, 0x002d,
0x002d, 0x002c, 0x002c, 0x002c, 0x002c, 0x002b, 0x002b, 0x002b
};
const int16 ST010_SinTable[256] = {
0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2,
0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,
0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,
0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,
0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6,
0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504,
0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3,
0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5,
0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d,
0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b,
0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23,
0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3,
0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,
0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df,
0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b,
0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324,
0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2,
-0x18f9, -0x1c0b, -0x1f1a, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11,
-0x30fb, -0x33df, -0x36ba, -0x398d, -0x3c56, -0x3f17, -0x41ce, -0x447a,
-0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842,
-0x5a82, -0x5cb3, -0x5ed7, -0x60ec, -0x62f1, -0x64e8, -0x66cf, -0x68a6,
-0x6a6d, -0x6c23, -0x6dc9, -0x6f5e, -0x70e2, -0x7254, -0x73b5, -0x7504,
-0x7641, -0x776b, -0x7884, -0x7989, -0x7a7c, -0x7b5c, -0x7c29, -0x7ce3,
-0x7d89, -0x7e1d, -0x7e9c, -0x7f09, -0x7f61, -0x7fa6, -0x7fd8, -0x7ff5,
-0x7fff, -0x7ff5, -0x7fd8, -0x7fa6, -0x7f61, -0x7f09, -0x7e9c, -0x7e1d,
-0x7d89, -0x7ce3, -0x7c29, -0x7b5c, -0x7a7c, -0x7989, -0x7883, -0x776b,
-0x7641, -0x7504, -0x73b5, -0x7254, -0x70e2, -0x6f5e, -0x6dc9, -0x6c23,
-0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f1, -0x60eb, -0x5ed7, -0x5cb3,
-0x5a82, -0x5842, -0x55f5, -0x539a, -0x5133, -0x4ebf, -0x4c3f, -0x49b3,
-0x471c, -0x447a, -0x41cd, -0x3f17, -0x3c56, -0x398c, -0x36b9, -0x33de,
-0x30fb, -0x2e10, -0x2b1f, -0x2826, -0x2527, -0x2223, -0x1f19, -0x1c0b,
-0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324};
const unsigned char ST010_ArcTan[32][32] = {
{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
{ 0x80, 0xa0, 0xad, 0xb3, 0xb6, 0xb8, 0xb9, 0xba, 0xbb, 0xbb, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd,
0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf},
{ 0x80, 0x93, 0xa0, 0xa8, 0xad, 0xb0, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xbb,
0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd},
{ 0x80, 0x8d, 0x98, 0xa0, 0xa6, 0xaa, 0xad, 0xb0, 0xb1, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb7, 0xb8,
0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc},
{ 0x80, 0x8a, 0x93, 0x9a, 0xa0, 0xa5, 0xa8, 0xab, 0xad, 0xaf, 0xb0, 0xb2, 0xb3, 0xb4, 0xb5, 0xb5,
0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb},
{ 0x80, 0x88, 0x90, 0x96, 0x9b, 0xa0, 0xa4, 0xa7, 0xa9, 0xab, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
0xb4, 0xb4, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9},
{ 0x80, 0x87, 0x8d, 0x93, 0x98, 0x9c, 0xa0, 0xa3, 0xa6, 0xa8, 0xaa, 0xac, 0xad, 0xae, 0xb0, 0xb0,
0xb1, 0xb2, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8},
{ 0x80, 0x86, 0x8b, 0x90, 0x95, 0x99, 0x9d, 0xa0, 0xa3, 0xa5, 0xa7, 0xa9, 0xaa, 0xac, 0xad, 0xae,
0xaf, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7},
{ 0x80, 0x85, 0x8a, 0x8f, 0x93, 0x97, 0x9a, 0x9d, 0xa0, 0xa2, 0xa5, 0xa6, 0xa8, 0xaa, 0xab, 0xac,
0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb5},
{ 0x80, 0x85, 0x89, 0x8d, 0x91, 0x95, 0x98, 0x9b, 0x9e, 0xa0, 0xa0, 0xa4, 0xa6, 0xa7, 0xa9, 0xaa,
0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4},
{ 0x80, 0x84, 0x88, 0x8c, 0x90, 0x93, 0x96, 0x99, 0x9b, 0x9e, 0xa0, 0xa2, 0xa4, 0xa5, 0xa7, 0xa8,
0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3},
{ 0x80, 0x84, 0x87, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5, 0xa6,
0xa7, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2},
{ 0x80, 0x83, 0x87, 0x8a, 0x8d, 0x90, 0x93, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1},
{ 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x94, 0x96, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa2, 0xa3,
0xa4, 0xa5, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xaf, 0xb0},
{ 0x80, 0x83, 0x86, 0x89, 0x8b, 0x8e, 0x90, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa1,
0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xad, 0xad, 0xae, 0xae, 0xaf},
{ 0x80, 0x83, 0x85, 0x88, 0x8b, 0x8d, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9b, 0x9d, 0x9f, 0xa0,
0xa1, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xab, 0xab, 0xac, 0xad, 0xad, 0xae},
{ 0x80, 0x83, 0x85, 0x88, 0x8a, 0x8c, 0x8f, 0x91, 0x93, 0x95, 0x97, 0x99, 0x9a, 0x9c, 0x9d, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa5, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xab, 0xac, 0xad},
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x97, 0x99, 0x9b, 0x9c, 0x9d,
0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac},
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8b, 0x8d, 0x8f, 0x91, 0x93, 0x95, 0x96, 0x98, 0x99, 0x9b, 0x9c,
0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x9a, 0x9b,
0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x99, 0x9a,
0x9b, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8f, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x99,
0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8},
{ 0x80, 0x82, 0x84, 0x86, 0x87, 0x89, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x98,
0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7},
{ 0x80, 0x82, 0x84, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x8f, 0x91, 0x92, 0x94, 0x95, 0x96, 0x98,
0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6},
{ 0x80, 0x82, 0x83, 0x85, 0x87, 0x88, 0x8a, 0x8c, 0x8d, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa4},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x89, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x95,
0x96, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x87, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93, 0x95,
0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3},
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x89, 0x8a, 0x8b, 0x8d, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2},
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x88, 0x8a, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1, 0xa1},
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8b, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93,
0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1},
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92,
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0}};
short ST010_Sin(short Theta)
{
return ST010_SinTable[(Theta >> 8) & 0xff];
}
short ST010_Cos(short Theta)
{
return ST010_SinTable[((Theta + 0x4000) >> 8) & 0xff];
}
void ST010_OP01(short x0, short y0, short *x1, short *y1, short *Quadrant, short *Theta)
{
if ((x0 < 0) && (y0 < 0))
{
*x1 = -x0;
*y1 = -y0;
*Quadrant = -0x8000;
}
else if (x0 < 0)
{
*x1 = y0;
*y1 = -x0;
*Quadrant = -0x4000;
}
else if (y0 < 0)
{
*x1 = -y0;
*y1 = x0;
*Quadrant = 0x4000;
}
else
{
*x1 = x0;
*y1 = y0;
*Quadrant = 0x0000;
}
while ((*x1 > 0x1f) || (*y1 > 0x1f))
{
if (*x1 > 1) *x1 >>= 1;
if (*y1 > 1) *y1 >>= 1;
}
if (*y1 == 0) *Quadrant += 0x4000;
*Theta = (ST010_ArcTan[*y1][*x1] << 8) ^ *Quadrant;
}
void ST010_Scale(short Multiplier, short X0, short Y0, int *X1, int *Y1)
{
*X1 = X0 * Multiplier << 1;
*Y1 = Y0 * Multiplier << 1;
}
void ST010_Multiply(short Multiplicand, short Multiplier, int *Product)
{
*Product = Multiplicand * Multiplier << 1;
}
void ST010_Rotate(short Theta, short X0, short Y0, short *X1, short *Y1)
{
*X1 = (Y0 * ST010_Sin(Theta) >> 15) + (X0 * ST010_Cos(Theta) >> 15);
*Y1 = (Y0 * ST010_Cos(Theta) >> 15) - (X0 * ST010_Sin(Theta) >> 15);
}
void ST010_SortDrivers(uint16 Positions, uint16 Places[32], uint16 Drivers[32])
{
bool Sorted;
uint16 Temp;
if (Positions > 1)
{
do
{
int i;
Sorted = true;
for (i = 0; i < Positions - 1; i++)
{
if (Places[i] < Places[i + 1])
{
Temp = Places[i + 1];
Places[i + 1] = Places[i];
Places[i] = Temp;
Temp = Drivers[i + 1];
Drivers[i + 1] = Drivers[i];
Drivers[i] = Temp;
Sorted = false;
}
}
Positions--;
} while (!Sorted);
}
}
#define ST010_WORD(offset) (*((short *)(SRAM+offset)))
//#define ST010_WORD(offset) (SRAM[offset + 1] << 8) | SRAM[offset]
void ST010DoCommand(void)
{
switch(SRAM[0x20])
{
/*
Calculate track data based on direction coords
Input
0x0000-0x0001 : DX (signed)
0x0002-0x0003 : DY (signed)
Output
0x0010-0x0011 : Angle (signed)
*/
case 0x01:
{
SRAM[0x0006] = SRAM[0x0002];
SRAM[0x0007] = SRAM[0x0003];
ST010_OP01(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)SRAM, (short *)&SRAM[2], (short *)&SRAM[4], (short *)&SRAM[0x10]);
}
break;
//Sorts a bunch of values by weight
case 0x02:
{
ST010_SortDrivers(*(short*)&SRAM[0x0024], (uint16*)&SRAM[0x0040], (uint16*)&SRAM[0x0080]);
}
break;
/*
Two Dimensional Coordinate Scale
Input
0x0000-0x0001 : X0 (signed)
0x0002-0x0003 : Y0 (signed)
0x0004-0x0005 : Multiplier (signed)
Output
0x0010-0x0013 : X1 (signed)
0x0014-0x0017 : Y1 (signed)
*/
case 0x03:
{
ST010_Scale(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10], (int *)&SRAM[0x14]);
}
break;
//Calculate the vector length of (x,y)
case 0x04:
{
int16 square, x,y;
x=*((int16*)SRAM);
y=*((int16*)&SRAM[2]);
square=(int16)sqrt((double)(y*y+x*x));
*((int16*)&SRAM[0x10])=square;
break;
}
//Calculate AI orientation based on specific guidelines
case 0x05:
{
int dx,dy;
int16 a1,b1,c1;
uint16 o1;
bool wrap=false;
//Target (x,y) coordinates
int16 ypos_max = ST010_WORD(0x00C0);
int16 xpos_max = ST010_WORD(0x00C2);
//Current coordinates and direction
int32 ypos = SRAM[0xC4]|(SRAM[0xC5]<<8)|(SRAM[0xC6]<<16)|(SRAM[0xC7]<<24);
int32 xpos = SRAM[0xC8]|(SRAM[0xC9]<<8)|(SRAM[0xCA]<<16)|(SRAM[0xCB]<<24);
uint16 rot = SRAM[0xCC]|(SRAM[0xCD]<<8);
//Physics
uint16 speed = ST010_WORD(0x00D4);
uint16 accel = ST010_WORD(0x00D6);
uint16 speed_max = ST010_WORD(0x00D8);
//Special condition acknowledgment
int16 system = ST010_WORD(0x00DA);
int16 flags = ST010_WORD(0x00DC);
//New target coordinates
int16 ypos_new = ST010_WORD(0x00DE);
int16 xpos_new = ST010_WORD(0x00E0);
//Backup speed
uint16 old_speed = speed;
//Mask upper bit
xpos_new &= 0x7FFF;
//Get the current distance
dx = xpos_max-(xpos>>16);
dy = ypos_max-(ypos>>16);
//Quirk: clear and move in9
SRAM[0xD2]=0xFF;
SRAM[0xD3]=0xFF;
SRAM[0xDA]=0;
SRAM[0xDB]=0;
//Grab the target angle
ST010_OP01(dy,dx,&a1,&b1,&c1,(int16 *)&o1);
//Check for wrapping
if (abs(o1-rot)>0x8000)
{
o1+=0x8000;
rot+=0x8000;
wrap=true;
}
//Special case
if (abs(o1-rot)==0x8000)
{
speed = 0x100;
}
//Slow down for sharp curves
else if (abs(o1-rot)>=0x1000)
{
uint32 slow = abs(o1-rot);
slow >>= 4; //Scaling
speed -= slow;
}
//Otherwise accelerate
else
{
speed += accel;
if (speed > speed_max)
{
//Clip speed
speed = speed_max;
}
}
//Prevent negative/positive overflow
if( abs(old_speed-speed)>0x8000)
{
if (old_speed<speed) { speed=0; }
else { speed=0xff00; }
}
//Adjust direction by so many degrees
//Be careful of negative adjustments
if ((o1>rot && (o1-rot)>0x80) || (o1<rot && (rot-o1)>=0x80))
{
if (o1<rot) { rot-=0x280; }
else if (o1>rot) { rot+=0x280; }
}
//Turn off wrapping
if (wrap) { rot-=0x8000; }
//Now check the distances (store for later)
dx = (xpos_max<<16)-xpos;
dy = (ypos_max<<16)-ypos;
dx>>=16;
dy>>=16;
//If we're in so many units of the target, signal it
if ((system && (dy<=6 && dy>=-8) && (dx<=126 && dx>=-128)) ||
(!system && (dx<=6 && dx>=-8) && (dy<=126 && dy>=-128)))
{
//Announce our new destination and flag it
xpos_max = xpos_new&0x7FFF;
ypos_max = ypos_new;
flags |= 0x08;
}
//Update position
xpos -= (ST010_Cos(rot) * 0x400 >> 15) * (speed >> 8) << 1;
ypos -= (ST010_Sin(rot) * 0x400 >> 15) * (speed >> 8) << 1;
//Quirk: mask upper byte
xpos &= 0x1FFFFFFF;
ypos &= 0x1FFFFFFF;
SRAM[0x00C0]=(uint8)(ypos_max);
SRAM[0x00C1]=(uint8)(ypos_max >> 8);
SRAM[0x00C2]=(uint8)(xpos_max);
SRAM[0x00C3]=(uint8)(xpos_max >> 8);
SRAM[0x00C4]=(uint8)(ypos);
SRAM[0x00C5]=(uint8)(ypos >> 8);
SRAM[0x00C6]=(uint8)(ypos >> 16);
SRAM[0x00C7]=(uint8)(ypos >> 24);
SRAM[0x00C8]=(uint8)(xpos);
SRAM[0x00C9]=(uint8)(xpos >> 8);
SRAM[0x00CA]=(uint8)(xpos >> 16);
SRAM[0x00CB]=(uint8)(xpos >> 24);
SRAM[0x00CC]=(uint8)(rot);
SRAM[0x00CD]=(uint8)(rot >> 8);
SRAM[0x00D4]=(uint8)(speed);
SRAM[0x00D5]=(uint8)(speed >> 8);
SRAM[0x00DC]=(uint8)(flags);
SRAM[0x00DD]=(uint8)(flags >> 8);
}
break;
/*
16-bit Multiplication
Input
0x0000-0x0001 : Multiplcand (signed)
0x0002-0x0003 : Multiplier (signed)
Output
0x0010-0x0013 : Product (signed)
*/
case 0x06:
{
ST010_Multiply(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10]);
}
break;
/*
Mode 7 Raster Data Calculation
Input
0x0000-0x0001 : Angle (signed)
Output
0x00f0-0x024f : Mode 7 Matrix A
0x0250-0x03af : Mode 7 Matrix B
0x03b0-0x050f : Mode 7 Matrix C
0x0510-0x066f : Mode 7 Matrix D
*/
case 0x07:
{
int16 data;
int32 offset = 0;
int16 Theta = ST010_WORD(0x0000);
int32 line;
for (line = 0; line < 176; line++)
{
//Calculate Mode 7 Matrix A/D data
data = ST010_M7Scale[line] * ST010_Cos(Theta) >> 15;
SRAM[0x00f0 + offset]=(uint8)(data);
SRAM[0x00f1 + offset]=(uint8)(data >> 8);
SRAM[0x0510 + offset]=(uint8)(data);
SRAM[0x0511 + offset]=(uint8)(data >> 8);
//Calculate Mode 7 Matrix B/C data
data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15;
SRAM[0x0250 + offset]=(uint8)(data);
SRAM[0x0251 + offset]=(uint8)(data >> 8);
if (data) { data = ~data; }
SRAM[0x03b0 + offset]=(uint8)(data);
SRAM[0x03b1 + offset]=(uint8)(data >> 8);
offset += 2;
}
//Shift Angle for use with Lookup table
SRAM[0x00] = SRAM[0x01];
SRAM[0x01] = 0x00;
}
break;
/*
Two dimensional Coordinate Rotation
Input
0x0000-0x0001 : X0 (signed)
0x0002-0x0003 : Y0 (signed)
0x0004-0x0005 : Angle (signed)
Output
0x0010-0x0011 : X1 (signed)
0x0012-0x0013 : Y1 (signed)
*/
case 0x08:
{
ST010_Rotate(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)&SRAM[0x10], (short *)&SRAM[0x12]);
}
break;
default: break;
}
//Lower signal: op processed
SRAM[0x20]=0;
SRAM[0x21]=0;
}

View File

@@ -0,0 +1,585 @@
// ST-011 SNES DSP adapted from Morita Shogi 64
//
// notes:
// - the SNES uses DMA to/from 60:0000 and maybe 68:0xxx
// - some code redundancy (helper subroutines for movement projection)
//
// - OPS04/05 have unknown output values (!)
// - OPS06/07 have unknown purposes
//
// - plenty of missing opcodes that don't show up in the only known binary log (st011-demo)
// (play the game until captured/promoted pieces, king checked, endgame)
// - minus emulation cycles (busy signals), bit-perfect to 'st011-demo'
//#define DEBUG_DSP
#ifdef DEBUG_DSP
#include <stdio.h>
int debug1, debug2;
int line_count;
#endif
void (*RunST011)();
void ST011_Command();
unsigned char ST011_DR;
unsigned char ST011_SR;
int ST011_input_length;
#define ST011_ram setaramdata
extern unsigned char *setaramdata;
#define ST011_board ( ST011_ram+0x130 )
int ST011_dma_count;
int ST011_dma_index;
int ST011_king1;
int ST011_king2;
// (x,y)
#define MOVE_UUL -1,-20
#define MOVE_UL -1,-10
#define MOVE_ULAll -9,- 9
#define MOVE_U 0,-10
#define MOVE_UAll 0,- 9
#define MOVE_UR 1,-10
#define MOVE_URAll 9,- 9
#define MOVE_UUR 1,-20
#define MOVE_L -1, 0
#define MOVE_LAll -9, 0
#define MOVE_R 1, 0
#define MOVE_RAll 9, 0
#define MOVE_DDL -1, 20
#define MOVE_DL -1, 10
#define MOVE_DLAll -9, 9
#define MOVE_D 0, 10
#define MOVE_DAll 0, 9
#define MOVE_DR 1, 10
#define MOVE_DRAll 9, 9
#define MOVE_DDR 1, 20
#define MOVE_STOP 127,127
#define MOVE_NOP 0, 0
const int ST011_move_table[8*2][9*2] =
{
// Pawn: one step forward
// - Promoted: same as Gold
{ MOVE_D, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Lance: all steps forward
// - Promoted: same as Gold
{ MOVE_DAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Knight: one step side, two forward
// - Promoted: same as Gold
{ MOVE_DDR, MOVE_DDL, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Silver general: one any diagonal, one step forward
// - Promoted: same as Gold
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_UR, MOVE_UL, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Gold general: one any forward, one sideways or one backward
// - Promoted: N/A
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
{ MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
// Bishop: any diagonal
// - Promoted: Bishop + King
{ MOVE_DRAll, MOVE_DLAll, MOVE_URAll, MOVE_ULAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DRAll, MOVE_D, MOVE_DLAll, MOVE_R, MOVE_L, MOVE_URAll, MOVE_U, MOVE_ULAll, MOVE_STOP },
// Rook: any vertical, horizontal
// - Promoted: Rook + King
{ MOVE_DAll, MOVE_RAll, MOVE_LAll, MOVE_UAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_DAll, MOVE_DL, MOVE_RAll, MOVE_LAll, MOVE_UR, MOVE_UAll, MOVE_UL, MOVE_STOP },
// King: one any direction
// - Promoted: N/A
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_UR, MOVE_U, MOVE_UL, MOVE_STOP },
{ MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
};
void ST011_Reset()
{
RunST011 = &ST011_Command;
ST011_SR=0xff;
}
void ST011_OP01_A()
{
if( ST011_dma_count-- )
{
ST011_board[ ST011_dma_index++ ] = ST011_DR;
}
if( ST011_dma_count == 0 )
{
#ifdef DEBUG_DSP
int lcv1, lcv2;
#endif
int lcv;
for( lcv = 0; lcv < 11; lcv++ )
{
ST011_board[ lcv ] = 0;
}
for( lcv = 11; lcv < 21; lcv++ )
{
ST011_board[ lcv ] = 0x80;
}
ST011_king1 = ST011_board[ 126+21 ];
ST011_king2 = ST011_board[ 127+21 ];
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
#ifdef DEBUG_DSP
// Debug
printf( "OP01\n" );
for( lcv1 = 0; lcv1 < 9; lcv1++ )
{
for( lcv2 = 0; lcv2 < 10; lcv2++ )
{
printf( "%02x ", ST011_board[ lcv1*10 + lcv2 + 21 ] );
}
printf( "\n" );
}
printf( "OP01 END\n\n" );
#endif
}
}
void ST011_OP01()
{
ST011_dma_count = 128;
ST011_dma_index = 0+21;
RunST011 = &ST011_OP01_A;
ST011_SR = 0xa4;
}
void ST011_OP02_A()
{
if( ST011_dma_count-- )
{
ST011_DR = ST011_ram[ ST011_dma_index-- ];
}
if( ST011_dma_count == 0 )
{
#ifdef DEBUG_DSP
int lcv1, lcv2;
#endif
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
#ifdef DEBUG_DSP
// Debug
#define OP02_ROW 10
printf( "OP02\n" );
for( lcv1 = 0; lcv1 < 0x83 / OP02_ROW; lcv1++ )
{
for( lcv2 = 0; lcv2 < OP02_ROW; lcv2++ )
{
printf( "%02x ", ST011_ram[ debug1 - lcv1 * OP02_ROW - lcv2 ] );
}
printf( "\n" );
}
printf( "OP02 END\n\n" );
#endif
}
}
void ST011_OP02()
{
switch( ST011_input_length-- )
{
case 4: ST011_dma_index = ST011_DR; break;
case 3: ST011_dma_index |= ST011_DR << 8; break;
case 2: ST011_dma_count = ST011_DR; break;
case 1:
ST011_dma_count |= ST011_DR << 8;
#ifdef DEBUG_DSP
debug1 = ST011_dma_index;
debug2 = 0;
#endif
RunST011 = &ST011_OP02_A;
ST011_SR = 0xa4;
break;
}
}
void ST011_Project_Moves( int color )
{
int row, col, lcv, index;
int dir;
index = 0x121;
for( lcv = 0; lcv < 0x83; lcv++ )
{
ST011_ram[ index-- ] = 0;
}
index = 0x121 - 21;
if( color == 0x20 )
{
dir = 1;
}
else
{
dir = -1;
}
for( row = 0; row < 9; row++ )
{
for( col = 0; col < 10; col++ )
{
int shogi_piece;
int piece_id;
int lcv_steps, lcv_move;
int move_list[ 9*2 ];
shogi_piece = ST011_board[ row*10+col+21 ];
piece_id = shogi_piece & 0x1f;
if( col == 9 ) continue;
if( shogi_piece == 0x00 ) continue;
if( ( shogi_piece & ~0x1f ) != color ) continue;
for( lcv = 0; lcv < 9*2; lcv++ )
{
move_list[ lcv ] = ST011_move_table[ piece_id >> 1 ][ lcv ];
}
lcv_move = 0;
while( move_list[ lcv_move ] != 0x7f )
{
int pos_x, pos_y;
lcv_steps = 1;
if( move_list[ lcv_move ] == 9 || move_list[ lcv_move ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move ] == 9 )
{
move_list[ lcv_move ] = 1;
}
else
{
move_list[ lcv_move ] = -1;
}
}
if( move_list[ lcv_move+1 ] == 9 || move_list[ lcv_move+1 ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move+1 ] == 9 )
{
move_list[ lcv_move+1 ] = 1;
}
else
{
move_list[ lcv_move+1 ] = -1;
}
}
else
{
move_list[ lcv_move+1 ] /= 10;
}
pos_x = col;
pos_y = row;
while( lcv_steps-- )
{
pos_x += move_list[ lcv_move+0 ];
pos_y += ( move_list[ lcv_move+1 ] * dir );
ST011_ram[ index - pos_y*10 - pos_x ] = 0x80;
if( ST011_board[ pos_y*10 + pos_x + 21 ] ) break;
}
lcv_move += 2;
}
} // end col
} // end row
}
int ST011_Project_Valid_Moves( int color )
{
int row, col, lcv, index;
int dir;
index = 0x556;
if( color == 0x20 )
{
dir = 1;
}
else
{
dir = -1;
}
for( row = 0; row < 9; row++ )
{
for( col = 0; col < 10; col++ )
{
int shogi_piece;
int piece_id;
int lcv_steps, lcv_move;
int move_list[ 9*2 ];
shogi_piece = ST011_board[ row*10+col+21 ];
piece_id = shogi_piece & 0x1f;
if( col == 9 ) continue;
if( shogi_piece == 0x00 ) continue;
if( ( shogi_piece & ~0x1f ) != color ) continue;
for( lcv = 0; lcv < 9*2; lcv++ )
{
move_list[ lcv ] = ST011_move_table[ piece_id >> 1 ][ lcv ];
}
lcv_move = 0;
while( move_list[ lcv_move ] != 0x7f )
{
int pos_x, pos_y;
lcv_steps = 1;
if( move_list[ lcv_move ] == 9 || move_list[ lcv_move ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move ] == 9 )
{
move_list[ lcv_move ] = 1;
}
else
{
move_list[ lcv_move ] = -1;
}
}
if( move_list[ lcv_move+1 ] == 9 || move_list[ lcv_move+1 ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move+1 ] == 9 )
{
move_list[ lcv_move+1 ] = 1;
}
else
{
move_list[ lcv_move+1 ] = -1;
}
}
else
{
move_list[ lcv_move+1 ] /= 10;
}
pos_x = col;
pos_y = row;
while( lcv_steps-- )
{
pos_x += move_list[ lcv_move+0 ];
pos_y += ( move_list[ lcv_move+1 ] * dir );
if( pos_x < 0 ) break;
if( pos_x > 8 ) break;
if( pos_y < 0 ) break;
if( pos_y > 8 ) break;
if( ( ST011_board[ pos_y*10 + pos_x + 21 ] & ~0x1f ) == color ) break;
ST011_ram[ index + 0x000 ] = 21 + row*10 + col;
ST011_ram[ index + 0x001 ] = 0;
ST011_ram[ index + 0x418 ] = 21 + pos_y*10 + pos_x;
ST011_ram[ index + 0x419 ] = 0;
if( pos_y >= 6 )
{
ST011_ram[ index + 0x418 ] |= 0x80;
}
index += 2;
if( ST011_board[ pos_y*10+pos_x+21 ] ) break;
}
lcv_move += 2;
}
} // end col
} // end row
return ( index-0x556 ) >> 1;
}
void ST011_OP04()
{
ST011_Project_Moves( 0x40 );
// unknown outputs
ST011_ram[ 0x12c ] = 0;
ST011_ram[ 0x12d ] = 0;
ST011_ram[ 0x12e ] = 0;
ST011_ram[ 0x12f ] = 0;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_OP05()
{
ST011_Project_Moves( 0x20 );
// unknown outputs
ST011_ram[ 0x12c ] = 0;
ST011_ram[ 0x12d ] = 0;
ST011_ram[ 0x12e ] = 0;
ST011_ram[ 0x12f ] = 0;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_OP0E()
{
int valid_moves;
valid_moves = ST011_Project_Valid_Moves( 0x20 );
ST011_ram[ 0x12c ] = valid_moves & 0xff;
ST011_ram[ 0x12d ] = ( valid_moves >> 8 ) & 0xff;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_Command()
{
#ifdef DEBUG_DSP
printf( "OP%02X @ line %d\n", ST011_DR, line_count );
#endif
// busy
ST011_SR = 0x84;
switch( ST011_DR )
{
// Download shogi playboard to on-board memory
case 0x01:
ST011_OP01();
break;
// Upload shogi analysis data to outside memory
case 0x02:
ST011_input_length = 4;
RunST011 = ST011_OP02;
break;
// Project all moves of player color $40
case 0x04:
ST011_OP04();
break;
// Project all moves of player color $20
case 0x05:
ST011_OP05();
break;
// Unknown - seems to set flags $00,$20,$40,..$e0 for restricted movement lists
case 0x06:
//ST011_OP06();
ST011_SR = 0xc4;
break;
// Unknown - seems to set flags $00,$20,$40,..$e0 for restricted movement lists
case 0x07:
//ST011_OP07();
ST011_SR = 0xc4;
break;
// List valid moves of player color $20
case 0x0E:
ST011_OP0E();
break;
default:
#ifdef DEBUG_DSP
printf( "Unknown OP @ line %d\n", line_count );
#endif
break;
}
}
unsigned short seta11_address;
unsigned char seta11_byte;
void ST011_MapR_68()
{
if (seta11_address < 0x1000)
{
ST011_DR = ST011_ram[seta11_address & 0xfff];
}
seta11_byte = ST011_DR;
}
void ST011_MapW_68()
{
ST011_DR = seta11_byte;
if (seta11_address < 0x1000)
{
ST011_ram[seta11_address & 0xfff] = ST011_DR;
}
}
void ST011_MapR_60()
{
if (seta11_address == 0)
{
RunST011();
}
if (seta11_address == 1)
{
seta11_byte = ST011_SR;
return;
}
seta11_byte = ST011_DR;
}
void ST011_MapW_60()
{
ST011_DR = seta11_byte;
if (seta11_address == 0)
{
RunST011();
}
}

View File

@@ -0,0 +1,667 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM SfxB,SfxBRAMR,SfxCBR,SfxCFGR,SfxCLSR,SfxCPB,SfxCROM
EXTSYM SfxCarry,SfxMemTable,SfxOverflow,SfxPBR,SfxPIPE,SfxR0,SfxR1,SfxR10
EXTSYM SfxR11,SfxR12,SfxR13,SfxR14,SfxR15,SfxR2,SfxR3,SfxR4,SfxR5,SfxR6
EXTSYM SfxR7,SfxR8,SfxR9,SfxRAMBR,SfxRAMMem,SfxROMBR,SfxSCBR,SfxSCMR,SfxSFR
EXTSYM SfxSignZero,SfxnRamBanks,regptr,regptw,sfxramdata,ChangeOps
EXTSYM SfxPOR,sfxclineloc,UpdatePORSCMR,UpdateCLSR,UpdateSCBRCOLR,SfxAC
EXTSYM sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc,SFXProc
%include "cpu/regs.mac"
%include "cpu/regsw.mac"
%macro AssembleSFXFlags 0
and word[SfxSFR],8F60h
test byte[SfxCarry],1
jz .nosfxcarry
or word[SfxSFR],04h
.nosfxcarry
cmp word[SfxSignZero],0
jne .nozero
or word[SfxSFR],02h
.nozero
test word[SfxSignZero],8000h
jz .noneg
or word[SfxSFR],08h
.noneg
cmp byte[SfxOverflow],0
je .noof
or word[SfxSFR],10h
.noof
cmp byte[SfxB],0
je .bzero
or word[SfxSFR],1000h
.bzero
%endmacro
SECTION .text
NEWSYM initsfxregsr
setreg 3000h*4,reg3000r
setreg 3001h*4,reg3001r
setreg 3002h*4,reg3002r
setreg 3003h*4,reg3003r
setreg 3004h*4,reg3004r
setreg 3005h*4,reg3005r
setreg 3006h*4,reg3006r
setreg 3007h*4,reg3007r
setreg 3008h*4,reg3008r
setreg 3009h*4,reg3009r
setreg 300Ah*4,reg300Ar
setreg 300Bh*4,reg300Br
setreg 300Ch*4,reg300Cr
setreg 300Dh*4,reg300Dr
setreg 300Eh*4,reg300Er
setreg 300Fh*4,reg300Fr
setreg 3010h*4,reg3010r
setreg 3011h*4,reg3011r
setreg 3012h*4,reg3012r
setreg 3013h*4,reg3013r
setreg 3014h*4,reg3014r
setreg 3015h*4,reg3015r
setreg 3016h*4,reg3016r
setreg 3017h*4,reg3017r
setreg 3018h*4,reg3018r
setreg 3019h*4,reg3019r
setreg 301Ah*4,reg301Ar
setreg 301Bh*4,reg301Br
setreg 301Ch*4,reg301Cr
setreg 301Dh*4,reg301Dr
setreg 301Eh*4,reg301Er
setreg 301Fh*4,reg301Fr
setreg 3030h*4,reg3030r
setreg 3031h*4,reg3031r
setreg 3032h*4,reg3032r
setreg 3033h*4,reg3033r
setreg 3034h*4,reg3034r
setreg 3035h*4,reg3035r
setreg 3036h*4,reg3036r
setreg 3037h*4,reg3037r
setreg 3038h*4,reg3038r
setreg 3039h*4,reg3039r
setreg 303Ah*4,reg303Ar
setreg 303Bh*4,reg303Br
setreg 303Ch*4,reg303Cr
setreg 303Dh*4,reg303Dr
setreg 303Eh*4,reg303Er
setreg 303Fh*4,reg303Fr
; set 3100-31FF to cacheregr
mov edi,3100h*4
add edi,[regptr]
mov eax,cacheregr
mov ecx,200h
.loop
mov [edi],eax
add edi,4
dec ecx
jnz .loop
ret
NEWSYM initsfxregsw
setregw 3000h*4,reg3000w
setregw 3001h*4,reg3001w
setregw 3002h*4,reg3002w
setregw 3003h*4,reg3003w
setregw 3004h*4,reg3004w
setregw 3005h*4,reg3005w
setregw 3006h*4,reg3006w
setregw 3007h*4,reg3007w
setregw 3008h*4,reg3008w
setregw 3009h*4,reg3009w
setregw 300Ah*4,reg300Aw
setregw 300Bh*4,reg300Bw
setregw 300Ch*4,reg300Cw
setregw 300Dh*4,reg300Dw
setregw 300Eh*4,reg300Ew
setregw 300Fh*4,reg300Fw
setregw 3010h*4,reg3010w
setregw 3011h*4,reg3011w
setregw 3012h*4,reg3012w
setregw 3013h*4,reg3013w
setregw 3014h*4,reg3014w
setregw 3015h*4,reg3015w
setregw 3016h*4,reg3016w
setregw 3017h*4,reg3017w
setregw 3018h*4,reg3018w
setregw 3019h*4,reg3019w
setregw 301Ah*4,reg301Aw
setregw 301Bh*4,reg301Bw
setregw 301Ch*4,reg301Cw
setregw 301Dh*4,reg301Dw
setregw 301Eh*4,reg301Ew
setregw 301Fh*4,reg301Fw
setregw 3030h*4,reg3030w
setregw 3031h*4,reg3031w
setregw 3032h*4,reg3032w
setregw 3033h*4,reg3033w
setregw 3034h*4,reg3034w
setregw 3035h*4,reg3035w
setregw 3036h*4,reg3036w
setregw 3037h*4,reg3037w
setregw 3038h*4,reg3038w
setregw 3039h*4,reg3039w
setregw 303Ah*4,reg303Aw
setregw 303Bh*4,reg303Bw
setregw 303Ch*4,reg303Cw
setregw 303Dh*4,reg303Dw
setregw 303Eh*4,reg303Ew
setregw 303Fh*4,reg303Fw
; set 3100-31FF to cacheregw
mov edi,3100h*4
add edi,[regptw]
mov eax,cacheregw
mov ecx,200h
.loop
mov [edi],eax
add edi,4
dec ecx
jnz .loop
ret
NEWSYM cacheregr
or byte[cachewarning],1
ret
NEWSYM cacheregw
or byte[cachewarning],2
ret
SECTION .bss
NEWSYM cachewarning, resb 1
SECTION .text
; SFX Registers
NEWSYM reg3000r
mov al,[SfxR0]
ret
NEWSYM reg3001r
mov al,[SfxR0+1]
ret
NEWSYM reg3002r
mov al,[SfxR1]
ret
NEWSYM reg3003r
mov al,[SfxR1+1]
ret
NEWSYM reg3004r
mov al,[SfxR2]
ret
NEWSYM reg3005r
mov al,[SfxR2+1]
ret
NEWSYM reg3006r
mov al,[SfxR3]
ret
NEWSYM reg3007r
mov al,[SfxR3+1]
ret
NEWSYM reg3008r
mov al,[SfxR4]
ret
NEWSYM reg3009r
mov al,[SfxR4+1]
ret
NEWSYM reg300Ar
mov al,[SfxR5]
ret
NEWSYM reg300Br
mov al,[SfxR5+1]
ret
NEWSYM reg300Cr
mov al,[SfxR6]
ret
NEWSYM reg300Dr
mov al,[SfxR6+1]
ret
NEWSYM reg300Er
mov al,[SfxR7]
ret
NEWSYM reg300Fr
mov al,[SfxR7+1]
ret
NEWSYM reg3010r
mov al,[SfxR8]
ret
NEWSYM reg3011r
mov al,[SfxR8+1]
ret
NEWSYM reg3012r
mov al,[SfxR9]
ret
NEWSYM reg3013r
mov al,[SfxR9+1]
ret
NEWSYM reg3014r
mov al,[SfxR10]
ret
NEWSYM reg3015r
mov al,[SfxR10+1]
ret
NEWSYM reg3016r
mov al,[SfxR11]
ret
NEWSYM reg3017r
mov al,[SfxR11+1]
ret
NEWSYM reg3018r
mov al,[SfxR12]
ret
NEWSYM reg3019r
mov al,[SfxR12+1]
ret
NEWSYM reg301Ar
mov al,[SfxR13]
ret
NEWSYM reg301Br
mov al,[SfxR13+1]
ret
NEWSYM reg301Cr
mov al,[SfxR14]
ret
NEWSYM reg301Dr
mov al,[SfxR14+1]
ret
NEWSYM reg301Er
mov al,[SfxR15]
ret
NEWSYM reg301Fr
mov al,[SfxR15+1]
ret
; Other SFX stuff
NEWSYM reg3030r
AssembleSFXFlags
mov al,[SfxSFR]
ret
NEWSYM reg3031r
cmp byte[SfxAC],1
je .alwaysclear
cmp dword[ChangeOps],-350*240
jl .noclear
.alwaysclear
and byte[SfxSFR+1],07fh ; clear IRQ flag
jmp .cleared
.noclear
cmp dword[ChangeOps],-350*240*4
jge .clear
mov dword[ChangeOps],-350*240*4
jmp .cleared
.clear
add dword[ChangeOps],350*240
.cleared
mov al,[SfxSFR+1]
ret
SECTION .bss
.test resb 1
SECTION .text
NEWSYM reg3032r ; Unused
xor al,al
ret
NEWSYM reg3033r ; BRAMR Backup Ram Read only on/off (bits 1-15 unused)
mov al,[SfxBRAMR]
ret
NEWSYM reg3034r ; PBR (Program Bank)
mov al,[SfxPBR]
ret
NEWSYM reg3035r ; Unused
xor al,al
ret
NEWSYM reg3036r ; ROMBR (Gamepak Rom Bank Register)
mov al,[SfxROMBR]
ret
NEWSYM reg3037r ; CFGR (Control Flags Register)
mov al,[SfxCFGR]
ret
NEWSYM reg3038r ; SCBR (Screen Bank Register)
mov al,[SfxSCBR]
ret
NEWSYM reg3039r ; CLSR (Clock Speed Register)
mov al,[SfxCLSR]
ret
NEWSYM reg303Ar ; SCMR (Screen Mode Register)
mov al,[SfxSCMR]
test byte[SfxPOR],10h
jnz .objmode
mov al,[SfxSCMR]
and al,00100100b ; 4 + 32
cmp al,4
je .lines160
cmp al,32
je .lines192
cmp al,36
je .objmode
mov eax,[sfx128lineloc]
jmp .donelines
.lines160
mov eax,[sfx160lineloc]
jmp .donelines
.lines192
mov eax,[sfx192lineloc]
jmp .donelines
.objmode
mov eax,[sfxobjlineloc]
.donelines
mov [sfxclineloc],eax
ret
NEWSYM reg303Br ; VCR (Version Code Register)
mov al,20h
ret
NEWSYM reg303Cr ; RAMBR (Ram bank register)
mov al,[SfxRAMBR]
ret
NEWSYM reg303Dr ; Unused
xor al,al
ret
NEWSYM reg303Er ; CBR (Cache Base Register), lower byte
mov al,[SfxCBR]
ret
NEWSYM reg303Fr ; CBR (Cache Base Register), upper byte
mov al,[SfxCBR+1]
ret
; SFX Write Registers
NEWSYM reg3000w
mov [SfxR0],al
ret
NEWSYM reg3001w
mov [SfxR0+1],al
ret
NEWSYM reg3002w
mov [SfxR1],al
ret
NEWSYM reg3003w
mov [SfxR1+1],al
ret
NEWSYM reg3004w
mov [SfxR2],al
ret
NEWSYM reg3005w
mov [SfxR2+1],al
ret
NEWSYM reg3006w
mov [SfxR3],al
ret
NEWSYM reg3007w
mov [SfxR3+1],al
ret
NEWSYM reg3008w
mov [SfxR4],al
ret
NEWSYM reg3009w
mov [SfxR4+1],al
ret
NEWSYM reg300Aw
mov [SfxR5],al
ret
NEWSYM reg300Bw
mov [SfxR5+1],al
ret
NEWSYM reg300Cw
mov [SfxR6],al
ret
NEWSYM reg300Dw
mov [SfxR6+1],al
ret
NEWSYM reg300Ew
mov [SfxR7],al
ret
NEWSYM reg300Fw
mov [SfxR7+1],al
ret
NEWSYM reg3010w
mov [SfxR8],al
ret
NEWSYM reg3011w
mov [SfxR8+1],al
ret
NEWSYM reg3012w
mov [SfxR9],al
ret
NEWSYM reg3013w
mov [SfxR9+1],al
ret
NEWSYM reg3014w
mov [SfxR10],al
ret
NEWSYM reg3015w
mov [SfxR10+1],al
ret
NEWSYM reg3016w
mov [SfxR11],al
ret
NEWSYM reg3017w
mov [SfxR11+1],al
ret
NEWSYM reg3018w
mov [SfxR12],al
ret
NEWSYM reg3019w
mov [SfxR12+1],al
ret
NEWSYM reg301Aw
mov [SfxR13],al
ret
NEWSYM reg301Bw
mov [SfxR13+1],al
ret
NEWSYM reg301Cw
mov [SfxR14],al
ret
NEWSYM reg301Dw
mov [SfxR14+1],al
ret
NEWSYM reg301Ew
mov [SfxR15],al
ret
NEWSYM reg301Fw
mov [SfxR15+1],al
; start execution
push edx
mov edx,[SfxPBR]
mov edx,[SfxMemTable+edx*4]
add edx,[SfxR15]
mov dl,[edx]
mov [SfxPIPE],dl
pop edx
inc word[SfxR15]
or byte[SfxSFR],20h
or dword[SfxSFR],08000h ; Set IRQ Flag
mov dword[SFXProc],1
; call StartSFXret
ret
; Other SFX stuff
NEWSYM reg3030w
mov [SfxSFR],al
mov byte[SfxAC],1
mov dh,10
ret
NEWSYM reg3031w
mov [SfxSFR+1],al
ret
NEWSYM reg3032w ; Unused
ret
NEWSYM reg3033w ; BRAMR Backup Ram Read only on/off (bits 1-15 unused)
and al,0FEh
mov [SfxBRAMR],al
ret
NEWSYM reg3034w ; PBR (Program Bank)
mov [SfxPBR],al
xor ebx,ebx
mov bl,al
mov ebx,[SfxMemTable+ebx*4]
mov [SfxCPB],ebx
ret
NEWSYM reg3035w ; Unused
ret
NEWSYM reg3036w ; ROMBR (Gamepak Rom Bank Register)
mov [SfxROMBR],al
xor ebx,ebx
mov bl,al
mov ebx,[SfxMemTable+ebx*4]
mov [SfxCROM],ebx
ret
NEWSYM reg3037w ; CFGR (Control Flags Register)
mov [SfxCFGR],al
ret
NEWSYM reg3038w ; SCBR (Screen Bank Register)
mov [SfxSCBR],al
call UpdateSCBRCOLR
ret
NEWSYM reg3039w ; CLSR (Clock Speed Register)
and al,0FEh
mov [SfxCLSR],al
call UpdateCLSR
ret
NEWSYM reg303Aw ; SCMR (Screen Mode Register)
mov [SfxSCMR],al
call UpdatePORSCMR
ret
NEWSYM reg303Bw ; VCR (Version Code Register)
ret
NEWSYM reg303Cw ; RAMBR (Ram bank register)
mov bl,[SfxnRamBanks]
dec bl
and al,bl
mov ebx,[SfxnRamBanks]
dec ebx
and eax,ebx
mov [SfxRAMBR],eax
xor ebx,ebx
mov bl,al
shl ebx,16
add ebx,[sfxramdata]
mov [SfxRAMMem],ebx
ret
NEWSYM reg303Dw ; Unused
ret
NEWSYM reg303Ew ; CBR (Cache Base Register), lower byte
mov [SfxCBR],al
ret
NEWSYM reg303Fw ; CBR (Cache Base Register), upper byte
mov [SfxCBR+1],al
ret
NEWSYM sfxaccessbankr8
mov ebx,[sfxramdata]
mov al,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8
mov ebx,[sfxramdata]
mov [ebx+ecx],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16
mov ebx,[sfxramdata]
mov ax,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16
mov ebx,[sfxramdata]
mov [ebx+ecx],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8b
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8b
mov ebx,[sfxramdata]
mov [ebx+ecx+65536],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16b
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16b
mov ebx,[sfxramdata]
mov [ebx+ecx+65536],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8c
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536*2]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8c
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*2],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16c
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536*2]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16c
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*2],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8d
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536*3]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8d
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*3],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16d
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536*3]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16d
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*3],ax
xor ebx,ebx
ret

View File

@@ -0,0 +1,133 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM setaramdata,ST010DoCommand
SECTION .data
NEWSYM SetaCmdEnable, dd 0 ; Seta ST010/ST011 command enable register. Maybe also status.
SECTION .text
;; TODO - should return ROM for > 8000h
NEWSYM setaaccessbankr8
mov ebx,[setaramdata]
and ecx,0fffh
mov al,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM setaaccessbankw8
test ecx,8000h
jnz .nosetenablew8 ; ignore ROM writes
and ecx,0fffh
mov ebx,[setaramdata]
mov [ebx+ecx],al
cmp byte[ebx+021h], 80h
jnz .nosetenablew8
pushad
call ST010DoCommand
popad
.nosetenablew8
xor ebx,ebx
ret
;; We ignore the case where it wraps into ROM reads - should never happen
NEWSYM setaaccessbankr16
mov ebx,[setaramdata]
and ecx,0fffh
mov ax,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM setaaccessbankw16
test ecx,8000h
jnz .nosetenablew16 ; ignore ROM writes
cmp ecx,7fffh
jne .noromw16
mov [setaramdata+0fffh],al ; only write ram part in, not rom part
jmp short .nosetenablew16
.noromw16
and ecx,0fffh
mov ebx,[setaramdata]
cmp ecx,0fffh
jne .nowrapw16
mov [ebx+ecx],al
xchg ah,al
mov [ebx],al
jmp short .nosetenablew16
.nowrapw16
mov [ebx+ecx],ax
cmp byte[ebx+021h], 80h
jnz .nosetenablew16
pushad
call ST010DoCommand
popad
.nosetenablew16
xor ebx,ebx
ret
NEWSYM setaaccessbankr8a
xor al,al
cmp ecx,4000h
jae .nosetenabler8a
and ecx, 3
mov al,[SetaCmdEnable+ecx]
.nosetenabler8a
xor ebx,ebx
ret
NEWSYM setaaccessbankw8a
cmp ecx,4000h
jae .nosetenablew8a
and ecx, 03h
mov [SetaCmdEnable+ecx],al
.nosetenablew8a
xor ebx,ebx
ret
NEWSYM setaaccessbankr16a
xor ax,ax
cmp ecx,4000h
jae .nosetenabler16a
and ecx,3
mov al,[SetaCmdEnable+ecx]
xchg ah,al
inc ecx
and ecx,3
mov al,[SetaCmdEnable+ecx]
.nosetenabler16a
xor ebx,ebx
ret
NEWSYM setaaccessbankw16a
cmp ecx,4000h
jae .nosetenablew16a
mov ebx,[setaramdata]
and ecx,3
mov [ebx+ecx],al
xchg ah,al
inc ecx
and ecx,3
mov [ebx+ecx],al
.nosetenablew16a
xor ebx,ebx
ret

View File

@@ -0,0 +1,136 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM seta11_address,seta11_byte,setaramdata,ST011_DR
EXTSYM ST011_MapR_60,ST011_MapW_60,ST011_MapW_68;ST011_MapR_68
SECTION .text
NEWSYM Seta11Read8_68
mov ebx,[setaramdata]
and ecx,0fffh
mov al,[ebx+ecx]
mov [ST011_DR],al
xor ebx,ebx
ret
NEWSYM Seta11Write8_68
test ecx,8000h
jnz .nosetenablew8 ; ignore ROM writes
mov [seta11_address],cx
mov [seta11_byte],al
pushad
call ST011_MapW_68
popad
.nosetenablew8
ret
NEWSYM Seta11Read16_68
mov ebx,[setaramdata]
and ecx,0fffh
mov ax,[ebx+ecx]
mov [ST011_DR],ah
xor ebx,ebx
ret
NEWSYM Seta11Write16_68
test ecx,8000h
jnz .nosetenablew16 ; ignore ROM writes
mov [seta11_address],cx
mov [seta11_byte],al
mov [seta11temp],ah
pushad
call ST011_MapW_68
mov ah,[seta11temp]
mov [seta11_byte],ah
inc word[seta11_address]
call ST011_MapW_68
popad
.nosetenablew16
ret
NEWSYM Seta11Read8_60
xor al,al
cmp ecx,4000h
jae .nosetenabler8
and ecx,3
mov [seta11_address],cx
pushad
call ST011_MapR_60
popad
mov al,[seta11_byte]
.nosetenabler8
ret
NEWSYM Seta11Write8_60
cmp ecx,4000h
jae .nosetenablew8
and ecx,3
mov [seta11_address],cx
mov [seta11_byte],al
pushad
call ST011_MapW_60
popad
.nosetenablew8
ret
NEWSYM Seta11Read16_60
xor ax,ax
cmp ecx,4000h
jae .nosetenabler16
and ecx,3
mov [seta11_address],cx
pushad
call ST011_MapR_60
mov al,[seta11_byte]
mov [seta11temp],al
inc word[seta11_address]
and word[seta11_address],3
call ST011_MapR_60
popad
mov al,[seta11temp]
mov ah,[seta11_byte]
.nosetenabler16
ret
NEWSYM Seta11Write16_60
cmp ecx,4000h
jae .nosetenablew16
and ecx,3
mov [seta11_address],cx
mov [seta11_byte],al
mov [seta11temp],ah
pushad
call ST011_MapW_60
mov ah,[seta11temp]
mov [seta11_byte],ah
inc word[seta11_address]
and word[seta11_address],3
call ST011_MapW_60
popad
.nosetenablew16
ret
SECTION .bss
NEWSYM seta11temp, resb 1