Skip to content

Commit

Permalink
Merge pull request #10 from shuichitakano/feature/optimize
Browse files Browse the repository at this point in the history
最適化など
  • Loading branch information
shuichitakano authored Sep 15, 2021
2 parents f3786de + 9e0c560 commit ae4003c
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 310 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ PRIVATE
hardware_pwm
hardware_flash
dvi
util
infones

tinyusb_host
Expand All @@ -57,6 +58,7 @@ PRIVATE
)

add_subdirectory(pico_lib/dvi)
add_subdirectory(pico_lib/util)
add_subdirectory(infones)

pico_add_extra_outputs(picones)
Expand Down
37 changes: 32 additions & 5 deletions infones/InfoNES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
#include <pico.h>
#include <tuple>

#include <util/work_meter.h>

constexpr uint16_t makeTag(int r, int g, int b)
{
return (r << 10) | (g << 5) | (b);
}
enum
{
MARKER_START = makeTag(0, 31, 31),
MARKER_CPU = makeTag(0, 31, 0),
MARKER_SOUND = makeTag(31, 31, 0),
MARKER_BG = makeTag(0, 0, 31),
MARKER_SPRITE = makeTag(31, 0, 0),
};

/*-------------------------------------------------------------------*/
/* NES resources */
/*-------------------------------------------------------------------*/
Expand All @@ -62,10 +77,11 @@ BYTE *ROM;
BYTE *SRAMBANK;

/* ROM BANK ( 8Kb * 4 ) */
BYTE *ROMBANK0;
BYTE *ROMBANK1;
BYTE *ROMBANK2;
BYTE *ROMBANK3;
BYTE *ROMBANK[4];
// BYTE *ROMBANK0;
// BYTE *ROMBANK1;
// BYTE *ROMBANK2;
// BYTE *ROMBANK3;

/*-------------------------------------------------------------------*/
/* PPU resources */
Expand Down Expand Up @@ -603,6 +619,8 @@ void __not_in_flash_func(InfoNES_Cycle)()
// Emulation loop
for (;;)
{
util::WorkMeterMark(MARKER_START);

// Set a flag if a scanning line is a hit in the sprite #0
if (SpriteJustHit == PPU_Scanline &&
PPU_ScanTable[PPU_Scanline] == SCAN_ON_SCREEN)
Expand Down Expand Up @@ -639,6 +657,8 @@ void __not_in_flash_func(InfoNES_Cycle)()
APU_Reg[0x4015] |= 0x40;
}

util::WorkMeterMark(MARKER_CPU);

// A mapper function in H-Sync
MapperHSync();

Expand Down Expand Up @@ -667,6 +687,7 @@ int __not_in_flash_func(InfoNES_HSync)()
*/

InfoNES_pAPUHsync(!APU_Mute);
util::WorkMeterMark(MARKER_SOUND);

// int tmpv = (PPU_Addr >> 12) + ((PPU_Addr >> 5) << 3);
// tmpv -= PPU_Scanline >= 240 ? 0 : PPU_Scanline;
Expand All @@ -685,11 +706,13 @@ int __not_in_flash_func(InfoNES_HSync)()
{
InfoNES_PreDrawLine(PPU_Scanline);
InfoNES_DrawLine();
InfoNES_PostDrawLine();
InfoNES_PostDrawLine(PPU_Scanline);
}
// todo: 描画しないラインにもスプライトオーバーレジスタとかは反映する必要がある
}

util::WorkMeterReset(); // 計測起点はここ

/*-------------------------------------------------------------------*/
/* Set new scroll values */
/*-------------------------------------------------------------------*/
Expand Down Expand Up @@ -1152,6 +1175,8 @@ void __not_in_flash_func(InfoNES_DrawLine)()
}
}

util::WorkMeterMark(MARKER_BG);

/*-------------------------------------------------------------------*/
/* Render a sprite */
/*-------------------------------------------------------------------*/
Expand Down Expand Up @@ -1412,6 +1437,8 @@ void __not_in_flash_func(InfoNES_DrawLine)()

if (nSprCnt >= 8)
PPU_R2 |= R2_MAX_SP; // Set a flag of maximum sprites on scanline

util::WorkMeterMark(MARKER_SPRITE);
}
}

Expand Down
13 changes: 9 additions & 4 deletions infones/InfoNES.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ extern BYTE *ROM;
extern BYTE *SRAMBANK;

/* ROM BANK ( 8Kb * 4 ) */
extern BYTE *ROMBANK0;
extern BYTE *ROMBANK1;
extern BYTE *ROMBANK2;
extern BYTE *ROMBANK3;
extern BYTE *ROMBANK[4];
// extern BYTE *ROMBANK0;
// extern BYTE *ROMBANK1;
// extern BYTE *ROMBANK2;
// extern BYTE *ROMBANK3;
#define ROMBANK0 (ROMBANK[0])
#define ROMBANK1 (ROMBANK[1])
#define ROMBANK2 (ROMBANK[2])
#define ROMBANK3 (ROMBANK[3])

/*-------------------------------------------------------------------*/
/* PPU resources */
Expand Down
2 changes: 1 addition & 1 deletion infones/InfoNES_System.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ int InfoNES_GetSoundBufferSize();
void InfoNES_MessageBox(const char *pszMsg, ...);

void InfoNES_PreDrawLine(int line);
void InfoNES_PostDrawLine();
void InfoNES_PostDrawLine(int line);

#endif /* !InfoNES_SYSTEM_H_INCLUDED */
Loading

0 comments on commit ae4003c

Please sign in to comment.