mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-05-23 06:34:18 -04:00
Implement & link famicom.cpp
This commit is contained in:
+103
-26
@@ -9,6 +9,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FAMICOM_SAVE_HEADER_SIZE 0x40
|
||||
#define FAMICOM_INTERNAL_ROM_NUM 19
|
||||
|
||||
#define NESTAG_CMD_SIZE 3
|
||||
@@ -44,8 +45,8 @@ extern "C" {
|
||||
|
||||
typedef void* (*MALLOC_ALIGN_FUNC)(size_t size, u32 align);
|
||||
typedef void (*MALLOC_FREE_FUNC)(void* ptr);
|
||||
typedef size_t (*MALLOC_GETMEMBLOCKSIZE_FUNC)(void* ptr);
|
||||
typedef size_t (*MALLOC_GETTOTALFREESIZE_FUNC)();
|
||||
typedef int (*MALLOC_GETMEMBLOCKSIZE_FUNC)(void* ptr);
|
||||
typedef int (*MALLOC_GETTOTALFREESIZE_FUNC)();
|
||||
|
||||
typedef struct malloc_s {
|
||||
MALLOC_ALIGN_FUNC malloc_align;
|
||||
@@ -54,11 +55,59 @@ typedef struct malloc_s {
|
||||
MALLOC_GETTOTALFREESIZE_FUNC gettotalfreesize;
|
||||
} Famicom_MallocInfo;
|
||||
|
||||
typedef struct save_data_header_s {
|
||||
u8 _temp[0x19C0];
|
||||
enum filer_demo_mode {
|
||||
FILER_DEMO_MODE_NORMAL,
|
||||
FILER_DEMO_MODE_AUTO,
|
||||
|
||||
FILER_DEMO_MODE_NUM
|
||||
};
|
||||
|
||||
#define FAMICOM_SAVE_DATA_NAME_LEN 8
|
||||
|
||||
typedef struct FamicomSaveDataHeader {
|
||||
u8 name[FAMICOM_SAVE_DATA_NAME_LEN];
|
||||
u8 _08;
|
||||
u8 _09;
|
||||
u8 headerSize;
|
||||
u8 checksum;
|
||||
u16 size;
|
||||
u8 no_save;
|
||||
u8 _temp[FAMICOM_SAVE_HEADER_SIZE - 0x000F];
|
||||
} FamicomSaveDataHeader;
|
||||
|
||||
typedef struct memcard_game_header_s {
|
||||
enum {
|
||||
MEMCARD_COMMENT_TYPE_NONE,
|
||||
MEMCARD_COMMENT_TYPE_DEFAULT,
|
||||
MEMCARD_COMMENT_TYPE_COPY_ROM, // converts rom's comment but converts "] ROM" to "] SAVE"
|
||||
MEMCARD_COMMENT_TYPE_COPY_EMBEDDED // uses the embedded and unique 'save' comment
|
||||
};
|
||||
|
||||
enum {
|
||||
MEMCARD_BANNER_TYPE_NONE,
|
||||
MEMCARD_BANNER_TYPE_DEFAULT,
|
||||
MEMCARD_BANNER_TYPE_COPY_ROM, // copies the NES rom save's banner
|
||||
MEMCARD_BANNER_TYPE_COPY_EMBEDDED // uses the embedded and unique 'save' banner
|
||||
};
|
||||
|
||||
enum {
|
||||
MEMCARD_ICON_TYPE_NONE,
|
||||
MEMCARD_ICON_TYPE_DEFAULT,
|
||||
MEMCARD_ICON_TYPE_COPY_ROM, // copies the NES rom save's icon
|
||||
MEMCARD_ICON_TYPE_COPY_EMBEDDED // uses the embedded and unique 'save' icon
|
||||
};
|
||||
|
||||
enum {
|
||||
FAMICOM_RESULT_OK,
|
||||
FAMICOM_RESULT_NOSPACE,
|
||||
FAMICOM_RESULT_NOENTRY,
|
||||
FAMICOM_RESULT_BROKEN,
|
||||
FAMICOM_RESULT_WRONGDEVICE,
|
||||
FAMICOM_RESULT_WRONGENCODING,
|
||||
FAMICOM_RESULT_NOCARD,
|
||||
FAMICOM_RESULT_NOFILE
|
||||
};
|
||||
|
||||
typedef struct MemcardGameHeader_t {
|
||||
u8 _00;
|
||||
u8 _01;
|
||||
u8 mori_name[16];
|
||||
@@ -66,14 +115,24 @@ typedef struct memcard_game_header_s {
|
||||
u16 nestags_size;
|
||||
u16 icon_format;
|
||||
u16 icon_flags;
|
||||
u16 banner_size;
|
||||
u8 flags0;
|
||||
u8 flags1;
|
||||
u16 comment_img_size; /* Size of comment + banner + icon */
|
||||
struct {
|
||||
u8 has_comment_img:1;
|
||||
u8 comment_type:2;
|
||||
u8 banner_type:2;
|
||||
u8 icon_type:2;
|
||||
u8 no_copy_flag:1;
|
||||
} flags0;
|
||||
struct {
|
||||
u8 no_move_flag:1;
|
||||
u8 banner_fmt:2;
|
||||
u8 reserved:5;
|
||||
} flags1;
|
||||
u16 pad;
|
||||
} MemcardGameHeader_t;
|
||||
|
||||
/* sizeof (FamicomCommon) == 0xB8 */
|
||||
typedef struct famicom_common_s {
|
||||
typedef struct FamicomCommon {
|
||||
/* 0x00 */ ksNesCommonWorkObj* wp;
|
||||
/* 0x04 */ ksNesStateObj* sp;
|
||||
/* 0x08 */ u8* nesromp;
|
||||
@@ -85,27 +144,28 @@ typedef struct famicom_common_s {
|
||||
/* 0x20 */ u8* highscore_flagsp;
|
||||
/* 0x24 */ u8* nesinfo_tagsp;
|
||||
/* 0x28 */ int _28;
|
||||
/* 0x2C */ u8 player_no;
|
||||
/* 0x2D */ u8 _2d;
|
||||
/* 0x2E */ u8 _2e;
|
||||
/* 0x2C */ u8 nesrom_memcard; // TRUE: rom is loaded from memcard, FALSE: rom is loaded internally
|
||||
/* 0x2D */ u8 rom_no;
|
||||
/* 0x2E */ s8 save_pl_no;
|
||||
/* 0x2F */ u8 mura_save_name[33];
|
||||
/* 0x50 */ u8 famicom_save_name[33];
|
||||
/* 0x74 */ FamicomSaveDataHeader* save_data_header;
|
||||
/* 0x78 */ int _78;
|
||||
/* 0x7C */ size_t save_data_header_size;
|
||||
/* 0x80 */ size_t _80;
|
||||
/* 0x78 */ u8* internal_save_datap;
|
||||
/* 0x7C */ size_t save_data_total_size;
|
||||
/* 0x80 */ size_t save_data_single_size;
|
||||
/* 0x84 */ int _84;
|
||||
/* 0x88 */ u8* _88;
|
||||
/* 0x8C */ u16 _8C;
|
||||
/* 0x88 */ u8* save_data_name;
|
||||
/* 0x8C */ u8 _8C;
|
||||
/* 0x8D */ u8 low_res_mode;
|
||||
/* 0x8E */ MemcardGameHeader_t memcard_game_header;
|
||||
/* 0xB0 */ u8* memcard_save_comment;
|
||||
/* 0xB4 */ int _b4;
|
||||
/* 0xB4 */ size_t unused_save_data_start_ofs;
|
||||
} FamicomCommon;
|
||||
|
||||
|
||||
extern void* my_malloc_current;
|
||||
extern Famicom_MallocInfo* my_malloc_current;
|
||||
extern u8 save_game_image;
|
||||
extern char** nesrom_filename_ptrs;
|
||||
extern u8** nesrom_filename_ptrs;
|
||||
|
||||
extern u32 nesinfo_tags_size;
|
||||
extern u8* nesinfo_tags_start;
|
||||
@@ -115,16 +175,33 @@ extern u32 nesinfo_data_size;
|
||||
extern u8* nesinfo_data_start;
|
||||
extern u8* nesinfo_data_end;
|
||||
|
||||
extern u8 InputValid[];
|
||||
extern u32 InputData[];
|
||||
extern u32 InputButton[];
|
||||
extern u32 InputTrigger[];
|
||||
extern u32 InputRepeat[];
|
||||
extern u32 InputRepeatCount[];
|
||||
|
||||
extern u8 tcs_bad;
|
||||
extern u8 ics_bad;
|
||||
|
||||
extern FamicomCommon famicomCommon;
|
||||
|
||||
typedef u8 (*FAMICOM_GETSAVECHAN_PROC)(int* player_no, int* slot_card_result);
|
||||
extern void famicom_setCallback_getSaveChan(FAMICOM_GETSAVECHAN_PROC getSaveChan_proc);
|
||||
extern int famicom_mount_archive();
|
||||
typedef s32 (*FAMICOM_GETSAVECHAN_PROC)(int* player_no, s32* slot_card_result);
|
||||
|
||||
extern int famicom_getErrorChan();
|
||||
extern void famicom_setCallback_getSaveChan(FAMICOM_GETSAVECHAN_PROC proc);
|
||||
extern int famicom_mount_archive_end_check();
|
||||
extern int famicom_rom_load_check();
|
||||
extern int famicom_1frame();
|
||||
extern int famicom_init(int, void*, u8);
|
||||
extern void famicom_mount_archive();
|
||||
extern int famicom_init(int rom_idx, Famicom_MallocInfo* malloc_info, int player_no);
|
||||
extern int famicom_cleanup();
|
||||
extern void famicom_1frame();
|
||||
extern int famicom_rom_load_check();
|
||||
extern int famicom_internal_data_load();
|
||||
extern int famicom_internal_data_save();
|
||||
extern int famicom_external_data_save();
|
||||
extern int famicom_external_data_save_check();
|
||||
extern int famicom_get_disksystem_titles(int* n_games, char* title_name_bufp, int namebuf_size);
|
||||
|
||||
extern void nesinfo_tags_set(int rom_no);
|
||||
extern void nesinfo_tag_process1(u8* save_data, int mode, u32* max_ofs_p);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef FAMICOMINTERNAL_H
|
||||
#define FAMICOMINTERNAL_H
|
||||
|
||||
#include "types.h"
|
||||
#include "Famicom/famicom.h"
|
||||
#include "Famicom/ks_nes.h"
|
||||
|
||||
#define MURA_GAME_NAME_SIZE 16
|
||||
|
||||
static void* my_malloc(size_t size, u32 align) { return (*my_malloc_current->malloc_align)(size, align); }
|
||||
static void my_free(void* ptr) { (*my_malloc_current->free)(ptr); }
|
||||
static int my_getmemblocksize(void* ptr) { return (*my_malloc_current->getmemblocksize)(ptr); }
|
||||
static int my_gettotalfreesize() { return (*my_malloc_current->gettotalfreesize)(); }
|
||||
|
||||
#endif
|
||||
@@ -7,28 +7,71 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define KS_NES_WIDTH 256
|
||||
#define KS_NES_HEIGHT 228
|
||||
|
||||
#define CHR_TO_I8_BUF_SIZE 0x100000
|
||||
#define KS_NES_NESFILE_HEADER_SIZE 0x10
|
||||
#define KS_NES_PRGROM_SIZE 0x8000 // not certain, generally 32kb (0x8000)
|
||||
#define KS_NES_CHRROM_SIZE 0x4000 // not certain, usually only 8kb (0x2000)
|
||||
#define KS_NES_PRGROM_SIZE 0x80000 // 512kb for MMC3
|
||||
#define KS_NES_CHRROM_SIZE 0x40000 // 256kb for MMC3
|
||||
|
||||
#define KS_NES_CHRRAM_SIZE 0x2000 // 8kb
|
||||
#define KS_NES_BBRAM_SIZE 0x8000 // 32kb, battery backed-up ram
|
||||
#define KS_NES_NOISE_DATA_SIZE 0x7F000
|
||||
#define KS_NES_DRAW_RESULT_SIZE 0x1C800
|
||||
#define KS_NES_DRAW_RESULT_BUF_SIZE 0x1C800
|
||||
|
||||
#define KS_NES_SAVE_DATA_HEADER_SIZE
|
||||
#define KS_NES_WRAM_SIZE 0x800 // 2kb
|
||||
|
||||
#define KS_NES_EMU_STACK_SIZE 0x1000 // 4kb for thread stack
|
||||
|
||||
#define KS_NES_BYTES_PER_KB (1024)
|
||||
#define KS_NES_TO_KB(b) ((f32)b / (1.0f / (f32)KS_NES_BYTES_PER_KB))
|
||||
#define KS_NES_TO_KB(b) ((f32)b * (1.0f / (f32)KS_NES_BYTES_PER_KB))
|
||||
|
||||
typedef struct ks_nes_common_work_obj_s {
|
||||
u8 _temp[0x8F78];
|
||||
typedef struct ksNesCommonWorkPriv {
|
||||
/* 0x0000 */ u8 wram[KS_NES_WRAM_SIZE];
|
||||
/* 0x0800 */ u8 _0800[0x0B40 - 0x0800];
|
||||
/* 0x0B40 */ u8 _0B40[1]; // TODO: figure out what this is and its size
|
||||
/* 0x0B41 */ u8 _0B41[0x2A40 - 0x0B41];
|
||||
/* 0x2A40 */ u8 _2A40[0x800];
|
||||
/* 0x3240 */ u8 _3240[0x8F18 - 0x3240];
|
||||
} ksNesCommonWorkPriv;
|
||||
|
||||
typedef struct ksNesCommonWorkObj {
|
||||
/* 0x0000 */ u8* nesromp;
|
||||
/* 0x0004 */ u8* noise_bufp;
|
||||
/* 0x0008 */ size_t chr_to_i8_buf_size;
|
||||
/* 0x000C */ u8* chr_to_u8_bufp;
|
||||
/* 0x0010 */ u8* result_bufp;
|
||||
/* 0x0014 */ int _0014;
|
||||
/* 0x0018 */ int _0018;
|
||||
/* 0x001C */ u8 frames;
|
||||
/* 0x001D */ u8 _001D;
|
||||
/* 0x001E */ u8 _001E;
|
||||
/* 0x001F */ u8 _001F;
|
||||
/* 0x0020 */ u32 pads[4];
|
||||
/* 0x0030 */ u32 _0030;
|
||||
/* 0x0034 */ u32 _0034;
|
||||
/* 0x0038 */ u32 _0038;
|
||||
/* 0x003C */ u8 _003C[0x0048 - 0x003C];
|
||||
/* 0x0048 */ size_t prg_size;
|
||||
/* 0x004C */ u8 _004C[0x0060 - 0x004C];
|
||||
/* 0x0060 */ ksNesCommonWorkPriv work_priv;
|
||||
} ksNesCommonWorkObj;
|
||||
|
||||
typedef struct ks_nes_state_obj_s {
|
||||
/* 0x0000 */ u8 wram[2048];
|
||||
/* 0x0800 */ u8 _temp[0x1A78 - 0x800];
|
||||
typedef struct ksNesStateObj {
|
||||
/* 0x0000 */ u8 wram[KS_NES_WRAM_SIZE];
|
||||
/* 0x0800 */ u8 _0800[0x16B4 - 0x0800];
|
||||
/* 0x16B4 */ u32 _16B4;
|
||||
/* 0x16BC */ u8 _16B8[0x176D - 0x16B8];
|
||||
/* 0x176D */ u8 disk_motor;
|
||||
/* 0x176E */ u8 _176E[0x17FC - 0x176E];
|
||||
/* 0x17FC */ u8 _17FC[8];
|
||||
/* 0x1804 */ u8 _1804[0x1844 - 0x1804];
|
||||
/* 0x1844 */ u16 PC;
|
||||
/* 0x1846 */ u8 _1846[0x1860 - 0x1846];
|
||||
/* 0x1860 */ size_t prg_size;
|
||||
/* 0x1864 */ size_t chr_size;
|
||||
/* 0x1868 */ u8 _1868[0x1A78 - 0x1868];
|
||||
} ksNesStateObj;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -4,14 +4,8 @@
|
||||
#include "types.h"
|
||||
#include "Famicom/ks_nes_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
extern int ksNesReset(ksNesCommonWorkObj* wp, ksNesStateObj* sp, u32 flags, u8* chrramp, u8* bbramp);
|
||||
extern void ksNesEmuFrame(ksNesCommonWorkObj* wp, ksNesStateObj* sp, u32 flags);
|
||||
extern void ksNesPushResetButton(ksNesStateObj* sp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,14 +4,8 @@
|
||||
#include "types.h"
|
||||
#include "Famicom/ks_nes_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
extern void ksNesDrawInit(ksNesCommonWorkObj* wp);
|
||||
extern void ksNesDraw(ksNesCommonWorkObj* wp, ksNesStateObj* sp);
|
||||
extern void ksNesDrawEnd();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user