📄 mappernsf.cpp
字号:
// 僉乕儃乕僪忋抜(O5-O8)
DrawBitmap( 31+49*0, 88, KeyBoardBitmap );
DrawBitmap( 31+49*1, 88, KeyBoardBitmap );
DrawBitmap( 31+49*2, 88, KeyBoardBitmap );
DrawBitmap( 31+49*3, 88, KeyBoardBitmap );
// 僉乕儃乕僪壓抜(O1-O4)
DrawBitmap( 31+49*0, 119, KeyBoardBitmap );
DrawBitmap( 31+49*1, 119, KeyBoardBitmap );
DrawBitmap( 31+49*2, 119, KeyBoardBitmap );
DrawBitmap( 31+49*3, 119, KeyBoardBitmap );
// 僉乕儃乕僪偑墴偝傟偰偄傞偺傪昤夋
// Internal APU
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0000)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0001)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0002)) );
// Internal Noise
if( nes->apu->GetChannelFrequency(0x0003) ) {
DrawBitmap( 10, 88, NeonBitmapA );
DrawBitmap( 241, 88, NeonBitmapA );
DrawBitmap( 10, 119, NeonBitmapA );
DrawBitmap( 241, 119, NeonBitmapA );
} else {
DrawBitmap( 10, 88, NeonBitmapC );
DrawBitmap( 241, 88, NeonBitmapC );
DrawBitmap( 10, 119, NeonBitmapC );
DrawBitmap( 241, 119, NeonBitmapC );
}
// Internal DPCM
if( nes->apu->GetChannelFrequency(0x0004) ) {
DrawBitmap( 18, 88, NeonBitmapB );
DrawBitmap( 233, 88, NeonBitmapB );
DrawBitmap( 18, 119, NeonBitmapB );
DrawBitmap( 233, 119, NeonBitmapB );
} else {
DrawBitmap( 18, 88, NeonBitmapC );
DrawBitmap( 233, 88, NeonBitmapC );
DrawBitmap( 18, 119, NeonBitmapC );
DrawBitmap( 233, 119, NeonBitmapC );
}
// VRC6
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0100)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0101)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0102)) );
// VRC7
// Nothing...
// FDS
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0300)) );
// MMC5
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0400)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0401)) );
// N106
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0500)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0501)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0502)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0503)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0504)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0505)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0506)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0507)) );
// FME7
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0600)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0601)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0602)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0610)) ); // Noise
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0611)) ); // Noise
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0612)) ); // Noise
// VRC7
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0700)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0701)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0702)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0703)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0704)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0705)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0706)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0707)) );
DrawKey( GetKeyTable(nes->apu->GetChannelFrequency(0x0708)) );
// TEST
#if NSF_PROFILE
if( nes->IsNsfPlaying() ) {
DWORD total, profile;
total = nes->GetFrameTotalCycles();
profile = nes->GetProfileCycles();
if( maxtotalclk < total ) {
maxtotalclk = total;
}
if( maxprofclk < profile ) {
maxprofclk = profile;
}
if( maxproftotalclk < nes->GetProfileTotalCycles() ) {
maxproftotalclk = nes->GetProfileTotalCycles();
}
if( maxproftotalcnt < nes->GetProfileTotalCount() ) {
maxproftotalcnt = nes->GetProfileTotalCount();
}
tave += total;
pave += profile;
ptave += nes->GetProfileTotalCycles();
avecount++;
sprintf( str, "TOTAL CLK :%8d", total );
DrawString( 16, 160, str, 0x30 );
sprintf( str, "TOTAL MAX :%8d", maxtotalclk );
DrawString( 134, 160, str, 0x30 );
sprintf( str, "TOTAL AVE :%8.2f", tave / (float)avecount );
DrawString( 16, 168, str, 0x30 );
sprintf( str, "PROFILE :%8d", profile );
DrawString( 16, 176, str, 0x30 );
sprintf( str, "PROFILEMAX:%8d", maxprofclk );
DrawString( 134, 176, str, 0x30 );
sprintf( str, "POFILE AVE:%8.2f", pave / (float)avecount );
DrawString( 16, 184, str, 0x30 );
sprintf( str, "PRF/TTL %%:%8.2f", 100.0f * (float)profile / (float)total );
DrawString( 16, 192, str, 0x30 );
sprintf( str, "FRM-P TTL :%8d", nes->GetProfileTotalCycles() );
DrawString( 16, 200, str, 0x30 );
sprintf( str, "F-P TTLMAX:%8d", maxproftotalclk );
DrawString( 134, 200, str, 0x30 );
sprintf( str, "FRM-P CNT :%8d", nes->GetProfileTotalCount() );
DrawString( 16, 208, str, 0x30 );
sprintf( str, "F-P CNTMAX:%8d", maxproftotalcnt );
DrawString( 134, 208, str, 0x30 );
sprintf( str, "F P/T AVE :%8.2f", ptave / (float)avecount );
DrawString( 16, 216, str, 0x30 );
sprintf( str, "F PRF/TTL%%:%8.2f", 100.0f * (float)nes->GetProfileTotalCycles() / (float)total );
DrawString( 16, 224, str, 0x30 );
if( avecount >= 60 ) {
avecount = 0;
tave = 0.0f;
pave = 0.0f;
ptave = 0.0f;
maxtotalclk = 0;
maxprofclk = 0;
maxproftotalclk = 0;
maxproftotalcnt = 0;
}
}
#endif
}
INT MapperNSF::GetKeyTable( INT freq )
{
INT ret = -1;
if( freq < Freq2KeyTbl[0] )
return -1;
for( INT i = 0; i < 12*8+1; i++ ) {
if( freq < Freq2KeyTbl[i] )
return ret;
ret = i;
}
return -1;
}
void MapperNSF::DrawKey( INT key )
{
if( key < 0 || key > 12*8-1 )
return;
if( key < 12*4 ) {
DrawBitmap( 31+(key/12)*49+KeyBitmapOfs[key%12], 119, KeyBitmapTbl[key%12] );
} else {
DrawBitmap( 31+((key-12*4)/12)*49+KeyBitmapOfs[key%12], 88, KeyBitmapTbl[key%12] );
}
}
void MapperNSF::DrawRect( INT x, INT y, INT w, INT h, BYTE col )
{
INT i;
LPBYTE pScn = nes->ppu->GetScreenPtr()+8;
LPBYTE p0, p1;
p0 = pScn+(256+16)*y+x;
p1 = p0+(256+16)*h;
for( i = 0; i < w+1; i++ ) {
*p0++ = col;
*p1++ = col;
}
p0 = pScn+(256+16)*y+x;
p1 = p0+w;
for( i = 0; i < h+1; i++ ) {
*p0 = col;
*p1 = col;
p0 += (256+16);
p1 += (256+16);
}
}
void MapperNSF::DrawFont( INT x, INT y, BYTE chr, BYTE col )
{
INT i;
LPBYTE pFnt;
LPBYTE pPtr;
LPBYTE pScn = nes->ppu->GetScreenPtr()+8;
if( chr < 0x20 || chr > 0x7F )
return;
chr -= 0x20;
pFnt = &Font6x8[chr*8];
pPtr = pScn+(256+16)*y+x;
for( i = 0; i < 8; i++ ) {
if( pFnt[i] & 0x80 ) pPtr[0] = col;
if( pFnt[i] & 0x40 ) pPtr[1] = col;
if( pFnt[i] & 0x20 ) pPtr[2] = col;
if( pFnt[i] & 0x10 ) pPtr[3] = col;
if( pFnt[i] & 0x08 ) pPtr[4] = col;
if( pFnt[i] & 0x04 ) pPtr[5] = col;
pPtr += (256+16);
}
}
void MapperNSF::DrawString( INT x, INT y, LPSTR str, BYTE col )
{
while( *str ) {
DrawFont( x, y, *str, col );
str++;
x += 6;
}
}
void MapperNSF::DrawWave( INT x, INT y, INT col )
{
INT i, j;
INT yp, ypold;
LPBYTE pScn = nes->ppu->GetScreenPtr()+8+(256+16)*y+x;
LPBYTE pPtr;
ypold = 0;
LPSWORD pBuffer = (LPSWORD)nes->apu->GetSoundBuffer();
for( i = 0; i < 192; i++ ) {
yp = -((INT)*pBuffer)/1024;
if( yp < -31 ) yp = -31;
if( yp > 31 ) yp = 31;
if( abs( yp-ypold ) <= 1 || i == 0 ) {
pPtr = pScn+yp*(256+16)+i;
*pPtr = col;
} else {
// Line DDA
INT xpos, ypos;
INT sx, sy;
xpos = 65536*(i-1)+32768;
ypos = ypold;
sy = yp-ypold;
sx = 65536/abs(sy);
for( j = 0; j <= abs(sy); j++ ) {
pPtr = pScn+ypos*(256+16)+(xpos/65536);
*pPtr = col;
ypos += (sy>0)?1:-1;
xpos += sx;
}
}
ypold = yp;
pBuffer++;
}
}
void MapperNSF::DrawBitmap( INT x, INT y, LPBYTE lpBitmap )
{
INT i, j;
INT h, v;
LPBYTE pScn = nes->ppu->GetScreenPtr()+8+(256+16)*y+x;
LPBYTE pPtr;
h = (INT)*lpBitmap++;
v = (INT)*lpBitmap++;
for( j = 0; j < v; j++ ) {
pPtr = pScn;
for( i = 0; i < h; i++ ) {
if( *lpBitmap != 0xFF ) {
*pPtr = *lpBitmap;
}
lpBitmap++;
pPtr++;
}
pScn += 256+16;
}
}
void MapperNSF::StarInitial()
{
for( INT i = 0; i < STAR_MAX; i++ ) {
StarBuf[i].x = ((rand()%(256-10))-(256-10)/2)*256;
StarBuf[i].y = ((rand()%(240-10))-(240-10)/2)*256;
StarBuf[i].z = (rand()%250)+5;
}
}
void MapperNSF::Star()
{
INT x, y, z;
for( INT i = 0; i < STAR_MAX; i++ ) {
if( --StarBuf[i].z < 5 ) {
StarBuf[i].x = ((rand()%(256-10))-(256-10)/2)*256;
StarBuf[i].y = ((rand()%(240-10))-(240-10)/2)*256;
StarBuf[i].z = 255;
}
x = 256/2+(StarBuf[i].x-5/128)/StarBuf[i].z;
y = 240/2+(StarBuf[i].y-5/128)/StarBuf[i].z;
if( x < 3 || x >= 256-8 || y < 3 || y >= 240-8 ) {
StarBuf[i].x = ((rand()%(256-10))-(256-10)/2)*256;
StarBuf[i].y = ((rand()%(240-10))-(240-10)/2)*256;
StarBuf[i].z = 255;
continue;
}
if( StarBuf[i].z > 200 )
z = 0;
else if( StarBuf[i].z > 100 )
z = 1;
else if( StarBuf[i].z > 50 )
z = 2;
else
z = 3;
DrawBitmap( x, y, StarBitmapTbl[z] );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -