Skip to content

Commit

Permalink
sound and extreme overclocking
Browse files Browse the repository at this point in the history
  • Loading branch information
xrip committed Oct 6, 2023
1 parent 22b3fd3 commit e5abfd9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ add_executable(sms

pico_set_program_name(sms "sms Emulator for MURMULATOR devboard")
pico_set_program_version(sms "v0.1")

pico_define_boot_stage2(slower_boot2 ${PICO_DEFAULT_BOOT_STAGE2_FILE})
target_compile_definitions(slower_boot2 PRIVATE PICO_FLASH_SPI_CLKDIV=4)
pico_set_boot_stage2(${PROJECT_NAME} slower_boot2)

target_include_directories(sms PRIVATE TotalSMS)

Expand Down
4 changes: 2 additions & 2 deletions drivers/vga/vga_vmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ void VgaCfgDef(sVgaCfg* cfg)
cfg->height = 480; // height in lines
cfg->wfull = 0; // width of full screen, corresponding to 'hfull' time (0=use 'width' parameter)
cfg->video = &VideoVGA; // used video timings
cfg->freq = 288000; // required minimal system frequency in kHz (real frequency can be higher)
cfg->fmax = 288000; // maximal system frequency in kHz (limit resolution if needed)
cfg->freq = 396*1000; // required minimal system frequency in kHz (real frequency can be higher)
cfg->fmax = 396*1000; // maximal system frequency in kHz (limit resolution if needed)
cfg->dbly = False; // double in Y direction
cfg->lockfreq = True; // lock required frequency, do not change it
}
Expand Down
24 changes: 18 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "pico/multicore.h"
#include "sms.h"
#include "vga.h"

#define ENABLE_SOUND 1
#if ENABLE_SOUND
#include "audio.h"
#endif
Expand Down Expand Up @@ -72,7 +72,7 @@ void load_cart_rom_file(char *filename) {
FIL fil;
FRESULT fr;

size_t bufsize = sizeof SCREEN;
size_t bufsize = sizeof(SCREEN)&0xfffff000;
BYTE *buffer = (BYTE *) SCREEN;
auto ofs = FLASH_TARGET_OFFSET;

Expand Down Expand Up @@ -207,6 +207,9 @@ void rom_file_selector() {
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
if ((nespad_state & DPAD_SELECT) != 0) {
break;
}
if ((nespad_state & DPAD_A) != 0 || (nespad_state & DPAD_B) != 0 || (nespad_state & DPAD_START) != 0) {
/* copy the rom from the SD card to flash and start the game */
char pathname[255];
Expand Down Expand Up @@ -375,7 +378,7 @@ static void core_vblank_callback(void *user) {

#if ENABLE_SOUND
i2s_config_t i2s_config;
#define AUDIO_FREQ (44100)
#define AUDIO_FREQ (22050)
#define SAMPLES 4096
static struct SMS_ApuSample sms_audio_samples[SAMPLES];

Expand All @@ -388,12 +391,21 @@ __attribute__((always_inline)) inline void core_audio_callback(void* user, struc
#endif

int main() {
vreg_set_voltage(VREG_VOLTAGE_1_15);
set_sys_clock_khz(288000, true);
/* Overclock. */
hw_set_bits(&vreg_and_chip_reset_hw->vreg, VREG_AND_CHIP_RESET_VREG_VSEL_BITS);
sleep_ms(33);

set_sys_clock_khz(396 * 1000, true);

gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);

for (int i = 0; i < 6; i++) {
sleep_ms(33);
gpio_put(PICO_DEFAULT_LED_PIN, true);
sleep_ms(33);
gpio_put(PICO_DEFAULT_LED_PIN, false);
}
#if !NDEBUG
stdio_init_all();
#endif
Expand All @@ -414,7 +426,7 @@ int main() {
#if ENABLE_SOUND
i2s_config = i2s_get_default_config();
i2s_config.sample_freq = AUDIO_FREQ;
i2s_config.dma_trans_count = i2s_config.sample_freq / 20;
i2s_config.dma_trans_count = sizeof(sms_audio_samples)/sizeof(sms_audio_samples[0]);
i2s_volume(&i2s_config, 0);
i2s_init(&i2s_config);
SMS_set_apu_callback(&sms, core_audio_callback, sms_audio_samples, sizeof(sms_audio_samples)/sizeof(sms_audio_samples[0]), AUDIO_FREQ);
Expand Down

0 comments on commit e5abfd9

Please sign in to comment.