Skip to content

Commit

Permalink
Merge branch 'punesemu:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoyo authored Jan 6, 2024
2 parents 9b2927f + 48a1ad2 commit 6dde407
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 78 deletions.
175 changes: 126 additions & 49 deletions src/core/fds.c

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions src/core/fds.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "common.h"

enum fds_formats { FDS_FORMAT_RAW, FDS_FORMAT_FDS };
enum fds_formats { FDS_TYPE_RAW, FDS_TYPE_FDS };
enum fds_write_mode { FDS_WR_DIFF_FILE, FDS_WR_ORIGINAL_FILE };
enum fds_operations { FDS_OP_NONE, FDS_OP_READ, FDS_OP_WRITE };
enum fds_disk_operations {
Expand All @@ -46,18 +46,24 @@ enum fds_block_type {
enum fds_misc {
FDS_DISK_GAP = 0x00,
FDS_DISK_BLOCK_MARK = 0x80,
// Aspic (1988)(Bothtec)(J) necessita di almeno 1500 ms
// Pulsar no Hikari - Space Wars Simulation (Japan) di almeno 1600 ms
FDS_OP_SIDE_MS_DELAY = 1600,
FDS_AUTOINSERT_R4032_MAX_CHECKS = 7,
FDS_MIN_LAG_FRAMES = 20,
FDS_IMAGE_SIDE_SIZE = 75500,
DISK_FDS_SIDE_SIZE = 65500,
DISK_QD_SIDE_SIZE = 65536
};

// 147 cicli (secondo vari test è questo il numero preciso)
#define FDS_8BIT_MS_DELAY 0.0825f
// https://www.chrismcovell.com/fds-lister.html
// The theoretical ideal data rate for FDS disks is said to be 96400 bits per second, or 12050 bytes/sec.
// Inverted, that's 1 byte every 82.988 microseconds. With the Famicom CPU having a clock period of 559 ns/cycle,
// there should be a new byte coming in to the FDS RAM adaptor every 148.46 (~hex $94) CPU clock cycles.
// At an average of 1 byte every 147-150 CPU cycles that I get on my newly-"calibrated" disk drive, that comes pretty
// close to the ideal data rate of 148 listed above.
#define FDS_8BIT_MS_DELAY 0.082988f
// Aspic (1988)(Bothtec)(J) necessita di almeno 1500 ms
// Pulsar no Hikari - Space Wars Simulation (Japan) di almeno 1600 ms
#define FDS_OP_SIDE_MS_DELAY 1600.0f

#define fds_auto_insert_enabled() (cfg->fds_switch_side_automatically & !fds.auto_insert.disabled & !fds.bios.first_run)
#define fds_reset_envelope_counter(env) (fds.snd.envelope.speed << 3) * (fds.snd.env.speed + 1)
#define fds_sweep_bias(val) (SBYTE)((val & 0x7F) << 1) / 2;
Expand Down Expand Up @@ -228,7 +234,8 @@ EXTERNC void fds_init(void);
EXTERNC void fds_quit(void);
EXTERNC BYTE fds_load_rom(BYTE format);
EXTERNC BYTE fds_load_bios(void);
EXTERNC BYTE fds_change_disk(uTCHAR *path);
EXTERNC BYTE fds_create_empty_disk(BYTE format, BYTE type, BYTE double_side, uTCHAR *file);
EXTERNC BYTE fds_change_disk(uTCHAR *file);
EXTERNC void fds_info(void);
EXTERNC void fds_info_side(BYTE side);
EXTERNC void fds_disk_op(WORD type, BYTE side_to_insert, BYTE quiet);
Expand Down
23 changes: 14 additions & 9 deletions src/core/mappers/mapper_FDS.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ void map_init_FDS(void) {
EXTCL_CPU_EVERY_CYCLE(FDS);
EXTCL_APU_TICK(FDS);

memset (&fds.auto_insert, 0x00, sizeof(fds.auto_insert));
fds.auto_insert.r4032.checks = 0;
fds.auto_insert.r4032.frames = 0;
fds.auto_insert.delay.dummy = 0;
fds.auto_insert.rE445.in_run = FALSE;
fds.auto_insert.in_game = FALSE;

fds.drive.transfer_reset = 0x02;
fds.drive.io_mode = 0x04;
fds.drive.drive_ready = 0x40;
Expand Down Expand Up @@ -108,7 +113,7 @@ BYTE extcl_cpu_rd_mem_FDS(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
BYTE finded = TRUE;

position = (a * fds_disk_side_size(fds.info.format));
if (fds.info.type == FDS_FORMAT_FDS) {
if (fds.info.type == FDS_TYPE_FDS) {
position += 16;
}
if ((position + fds_disk_side_size(fds.info.format)) > fds.info.total_size) {
Expand Down Expand Up @@ -174,13 +179,13 @@ BYTE extcl_cpu_rd_mem_FDS(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
address = nes[nidx].c.cpu.PC.w - 1;
}
break;
case 0xF46E:
// License check
if (cfg->fds_fast_forward) {
nes[nidx].c.cpu.PC.w += 2;
address = nes[nidx].c.cpu.PC.w - 1;
}
break;
// case 0xF46E:
// // License check
// if (cfg->fds_fast_forward) {
// nes[nidx].c.cpu.PC.w += 2;
// address = nes[nidx].c.cpu.PC.w - 1;
// }
// break;
}
return (prgrom_rd(nidx, address));
}
Expand Down
13 changes: 6 additions & 7 deletions src/core/recording.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg1(void) {
AVCPBProperties *props = NULL;

props = (AVCPBProperties *)av_stream_new_side_data(video->avs, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props));
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
props->max_bitrate = 0;
props->min_bitrate = 0;
props->avg_bitrate = 0;
Expand All @@ -905,15 +905,15 @@ static BYTE ffmpeg_video_add_stream_format_mpeg1(void) {
sd = av_packet_side_data_new(&video->avs->codecpar->coded_side_data,
&video->avs->codecpar->nb_coded_side_data, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props), 0);
props = (AVCPBProperties *)sd->data;
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
props->max_bitrate = 0;
props->min_bitrate = 0;
props->avg_bitrate = 0;
props->vbv_delay = UINT64_MAX;
} else {
props = (AVCPBProperties *)sd->data;
if (!props->buffer_size) {
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
}
}
}
Expand All @@ -939,7 +939,7 @@ static BYTE ffmpeg_video_add_stream_format_mpeg2(void) {
AVCPBProperties *props = NULL;

props = (AVCPBProperties *)av_stream_new_side_data(video->avs, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props));
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
props->max_bitrate = 0;
props->min_bitrate = 0;
props->avg_bitrate = 0;
Expand All @@ -964,17 +964,16 @@ static BYTE ffmpeg_video_add_stream_format_mpeg2(void) {
if (!sd) {
sd = av_packet_side_data_new(&video->avs->codecpar->coded_side_data,
&video->avs->codecpar->nb_coded_side_data, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props), 0);

props = (AVCPBProperties *)sd->data;
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
props->max_bitrate = 0;
props->min_bitrate = 0;
props->avg_bitrate = 0;
props->vbv_delay = UINT64_MAX;
} else {
props = (AVCPBProperties *)sd->data;
if (!props->buffer_size) {
props->buffer_size = 224 * 1024;
props->buffer_size = 1835 * 1024;
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/core/uncompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static uTCHAR *(*uncompress_item_file_name)(_uncompress_archive *archive, uint32
// zip
static BYTE mz_zip_examine_archive(_uncompress_archive *archive);
static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t selected, BYTE type);
static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
static char *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
#endif

_uncompress_storage uncstorage;
Expand Down Expand Up @@ -360,7 +360,7 @@ static BYTE mz_zip_examine_archive(_uncompress_archive *archive) {
}
static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t selected, BYTE type) {
mz_zip_archive mzarchive;
uTCHAR file[LENGTH_FILE_NAME_LONG];
char file[LENGTH_FILE_NAME_LONG], basename[255];
_uncompress_archive_item *aitem = NULL;

aitem = uncompress_archive_find_item(archive, selected, type);
Expand All @@ -377,7 +377,8 @@ static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t s

mz_zip_reader_get_filename(&mzarchive, aitem->index, file, sizeof(file));

snprintf(file, sizeof(file), "%s/%s", gui_temp_folder(), basename(file));
gui_utf_basename(&file[0], basename, sizeof(basename));
snprintf(file, sizeof(file), "%s/%s", gui_temp_folder(), basename);

if (!mz_zip_reader_extract_to_file(&mzarchive, aitem->index, file, 0)) {
log_error(uL("uncompress;unzip file failed!"));
Expand Down Expand Up @@ -409,8 +410,8 @@ static BYTE mz_zip_extract_from_archive(_uncompress_archive *archive, uint32_t s

return (UNCOMPRESS_EXIT_OK);
}
static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type) {
static uTCHAR file[LENGTH_FILE_NAME_LONG];
static char *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type) {
static char file[LENGTH_FILE_NAME_LONG];
mz_zip_archive mzarchive;
_uncompress_archive_item *aitem = NULL;

Expand Down
8 changes: 7 additions & 1 deletion src/gui/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,12 @@ void mainWindow::open_dkeyb(BYTE mode) {
dlgkeyb->switch_mode(mode);
dlgkeyb->show();
}
void mainWindow::unsupported_hardware(void) {
QMessageBox::warning(this,
tr("Warning"),
tr("This rom requires unsupported hardware to function correctly."),
QMessageBox::Ok);
}

void mainWindow::connect_menu_signals(void) {
// File
Expand Down Expand Up @@ -1669,7 +1675,7 @@ void mainWindow::s_export_fds_image(void) {
if (format < 3) {
rc = fds_from_image_to_file(uQStringCD(fileinfo.absoluteFilePath()),
format == 2 ? QD_FORMAT : FDS_FORMAT,
format == 0 ? FDS_FORMAT_FDS : FDS_FORMAT_RAW);
format == 0 ? FDS_TYPE_FDS : FDS_TYPE_RAW);
} else {
rc = fds_image_to_file(uQStringCD(fileinfo.absoluteFilePath()));
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/mainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class mainWindow : public QMainWindow, public Ui::mainWindow {
void shout_into_mic(BYTE mode);
void hold_fast_forward(BYTE mode);
void open_dkeyb(BYTE mode);
void unsupported_hardware(void);

private:
void connect_menu_signals(void);
Expand Down
4 changes: 4 additions & 0 deletions src/gui/objSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static const struct _kv_specials {
{ 0, Qt::AltModifier, Qt::Key_Alt, "Alt", 273 },
{ 0, Qt::NoModifier, Qt::Key_AltGr, "AltGr", 274 },
{ 0, Qt::MetaModifier, Qt::Key_Meta, "Meta", 275 },
{ 0, Qt::MetaModifier, Qt::Key_Super_L, "Meta", 275 },
{ 0, Qt::MetaModifier, Qt::Key_Super_R, "Meta", 275 },
{ 0, Qt::ShiftModifier, Qt::Key_Shift, "LShift", 276 },
{ 0, Qt::ShiftModifier, Qt::Key_Shift, "RShift", 277 },
{ 0, Qt::ControlModifier, Qt::Key_Control, "LCtrl", 278 },
Expand All @@ -91,6 +93,8 @@ static const struct _kv_specials {
{ 0, Qt::NoModifier, Qt::Key_Alt, "Alt", 273 },
{ 0, Qt::NoModifier, Qt::Key_AltGr, "AltGr", 274 },
{ 0, Qt::NoModifier, Qt::Key_Meta, "Meta", 275 },
{ 0, Qt::NoModifier, Qt::Key_Super_L, "Meta", 275 },
{ 0, Qt::NoModifier, Qt::Key_Super_R, "Meta", 275 },
{ XK_Shift_L, {}, Qt::Key_Shift, "LShift", 276 },
{ XK_Shift_R, {}, Qt::Key_Shift, "RShift", 277 },
{ XK_Control_L, {}, Qt::Key_Control, "LCtrl", 278 },
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ void gui_detach_barcode_change_rom(void) {
qt.dbarcode->change_rom();
}

void gui_unsupported_hardware(void) {
qt.mwin->unsupported_hardware();
}

#if defined (WITH_OPENGL)
void gui_wdgopengl_make_current(void) {
if (gui.start) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ EXTERNC void gui_vs_system_insert_coin(void);

EXTERNC void gui_detach_barcode_change_rom(void);

EXTERNC void gui_unsupported_hardware(void);

EXTERNC void gui_nes_keyboard(void);
EXTERNC void gui_nes_keyboard_paste_event(void);
EXTERNC void gui_nes_keyboard_frame_finished(void);
Expand Down

0 comments on commit 6dde407

Please sign in to comment.