Skip to content
Permalink
Browse files

Fixes support for 4MB Roms (Bad Apple now works). Switched some more …

…variables to c99 datatypes. I've also added Bad Apple to the ROM database as it requires PAL timings
  • Loading branch information...
gameblabla committed Aug 12, 2018
1 parent 7b0fc18 commit 80aefb94565e1cd463991cfae8331b2e8205ab37
Showing with 118 additions and 107 deletions.
  1. +1 −0 docs/contributors.txt
  2. +10 −5 source/loadrom.c
  3. +61 −58 source/sms.h
  4. +16 −16 source/system.c
  5. +30 −28 source/system.h
@@ -84,6 +84,7 @@ Gameblabla, me
Switced most variables to c99 data types. (Fixed rendering issues on 64-bits and somewhat broken PSG sound for Maxim's PSG core)
Improving PocketSprite's EightyOne patches for making sure it works with the newer SMS Plus version. (not as straightfoward as it might seem)
Disabled collision check for 9th sprite. Doing so passes Flubba's test.
Fixed support for 256 pages. This fixes Bad Apple SMS. (also added it to the ROM database list as it requires PAL timings)
Put everything together and making sure it works :' )

Maxim
@@ -22,7 +22,7 @@

#include "shared.h"

#define GAME_DATABASE_CNT 93
#define GAME_DATABASE_CNT 94

typedef struct
{
@@ -123,7 +123,9 @@ rominfo_t game_list[GAME_DATABASE_CNT] =
"Space Harrier [50 Hz]"},
{0x85CFC9C9, 0, DEVICE_PAD2B, MAPPER_SEGA, DISPLAY_PAL, TERRITORY_EXPORT, CONSOLE_SMS2,
"Taito Chase H.Q."},

{0x38434560, 0, DEVICE_PAD2B, MAPPER_SEGA, DISPLAY_PAL, TERRITORY_EXPORT, CONSOLE_SMS2,
"Bad Apple SMS"},

/* games requiring 315-5124 VDP (Mark-III, Sega Master System) */
{0x32759751, 0, DEVICE_PAD2B, MAPPER_SEGA, DISPLAY_NTSC, TERRITORY_DOMESTIC, CONSOLE_SMS,
"Y's (J)"},
@@ -375,14 +377,16 @@ int load_rom (char *filename)
int8_t name[PATH_MAX];
uint32_t size = cart.size;
cart.rom = loadFromZipByName(filename, name, &size);
if(!cart.rom) return 0;
if (!cart.rom)
return 0;
strcpy(option.game_name, name);
}
else
{
FILE *fd = NULL;
fd = fopen(filename, "rb");
if(!fd) return 0;
if (!fd)
return 0;

/* Seek to end of file, and get size */
fseek(fd, 0, SEEK_END);
@@ -391,7 +395,8 @@ int load_rom (char *filename)

if (cart.size < 0x4000) cart.size = 0x4000;
cart.rom = malloc(cart.size);
if(!cart.rom) return 0;
if (!cart.rom)
return 0;
fread(cart.rom, cart.size, 1, fd);

fclose(fd);
@@ -28,52 +28,52 @@
#define CYCLES_PER_LINE 228

enum {
SLOT_BIOS = 0,
SLOT_CARD = 1,
SLOT_CART = 2,
SLOT_EXP = 3
SLOT_BIOS = 0,
SLOT_CARD = 1,
SLOT_CART = 2,
SLOT_EXP = 3
};

enum {
MAPPER_NONE = 0,
MAPPER_SEGA = 1,
MAPPER_CODIES = 2,
MAPPER_KOREA = 3,
MAPPER_KOREA_MSX = 4
MAPPER_NONE = 0,
MAPPER_SEGA = 1,
MAPPER_CODIES = 2,
MAPPER_KOREA = 3,
MAPPER_KOREA_MSX = 4
};

enum {
DISPLAY_NTSC = 0,
DISPLAY_PAL = 1
DISPLAY_NTSC = 0,
DISPLAY_PAL = 1
};

enum {
FPS_NTSC = 60,
FPS_PAL = 50
FPS_NTSC = 60,
FPS_PAL = 50
};

enum {
CLOCK_NTSC = 3579545,
CLOCK_PAL = 3546895,
CLOCK_NTSC_SMS1 = 3579527
CLOCK_NTSC = 3579545,
CLOCK_PAL = 3546895,
CLOCK_NTSC_SMS1 = 3579527
};

enum {
CONSOLE_COLECO = 0x10,
CONSOLE_SG1000 = 0x11,
CONSOLE_SC3000 = 0x12,
CONSOLE_SF7000 = 0x13,
CONSOLE_COLECO = 0x10,
CONSOLE_SG1000 = 0x11,
CONSOLE_SC3000 = 0x12,
CONSOLE_SF7000 = 0x13,

CONSOLE_SMS = 0x20,
CONSOLE_SMS2 = 0x21,
CONSOLE_SMS = 0x20,
CONSOLE_SMS2 = 0x21,

CONSOLE_GG = 0x40,
CONSOLE_GGMS = 0x41,
CONSOLE_GG = 0x40,
CONSOLE_GGMS = 0x41,

CONSOLE_MD = 0x80,
CONSOLE_MDPBC = 0x81,
CONSOLE_GEN = 0x82,
CONSOLE_GENPBC = 0x83
CONSOLE_MD = 0x80,
CONSOLE_MDPBC = 0x81,
CONSOLE_GEN = 0x82,
CONSOLE_GENPBC = 0x83
};

#define HWTYPE_TMS CONSOLE_COLECO
@@ -94,28 +94,29 @@ enum {
/* SMS context */
typedef struct
{
uint8_t wram[0x2000];
uint8_t paused;
uint8_t save;
uint8_t territory;
uint8_t console;
uint8_t display;
uint8_t fm_detect;
uint8_t glasses_3d;
uint8_t hlatch;
uint8_t use_fm;
uint8_t memctrl;
uint8_t ioctrl;
uint8_t irq;
struct {
uint8_t pdr; /* Parallel data register */
uint8_t ddr; /* Data direction register */
uint8_t txdata; /* Transmit data buffer */
uint8_t rxdata; /* Receive data buffer */
uint8_t sctrl; /* Serial mode control and status */
} sio;
uint8_t device[2];
uint8_t gun_offset;
uint8_t wram[0x2000];
uint8_t paused;
uint8_t save;
uint8_t territory;
uint8_t console;
uint8_t display;
uint8_t fm_detect;
uint8_t glasses_3d;
uint8_t hlatch;
uint8_t use_fm;
uint8_t memctrl;
uint8_t ioctrl;
uint8_t irq;
struct
{
uint8_t pdr; /* Parallel data register */
uint8_t ddr; /* Data direction register */
uint8_t txdata; /* Transmit data buffer */
uint8_t rxdata; /* Receive data buffer */
uint8_t sctrl; /* Serial mode control and status */
} sio;
uint8_t device[2];
uint8_t gun_offset;
} sms_t;

/* BIOS ROM */
@@ -129,16 +130,18 @@ typedef struct

typedef struct
{
uint8_t *rom;
uint8_t pages;
uint8_t *fcr;
uint8_t mapper;
uint8_t *rom;
/* We need to use an unsigned short for pages, as Bad Apple SMS requires it !*/
uint16_t pages;
uint8_t *fcr;
uint8_t mapper;
} slot_t;

typedef struct {
uint8_t rom[0x2000]; /* BIOS ROM */
uint8_t pio_mode; /* PIO mode */
uint8_t keypad[2]; /* Keypad inputs */
typedef struct
{
uint8_t rom[0x2000]; /* BIOS ROM */
uint8_t pio_mode; /* PIO mode */
uint8_t keypad[2]; /* Keypad inputs */
} t_coleco;

/* Global data */
@@ -31,7 +31,7 @@ input_t input;
extern uint32_t z80_cycle_count ;

/* Run the virtual console emulation for one frame */
void system_frame(int skip_render)
void system_frame(uint32_t skip_render)
{
uint32_t iline = 0, line_z80 = 0;

@@ -86,9 +86,9 @@ void system_frame(int skip_render)
/* IRQ line is latched between instructions, on instruction last cycle */
/* This means that if Z80 cycle count is exactly a multiple of CYCLES_PER_LINE, */
/* interrupt should be triggered AFTER the next instruction. */
if (!(z80_get_elapsed_cycles()%CYCLES_PER_LINE))
z80_execute(1);
z80_set_irq_line(0, ASSERT_LINE);
if (!(z80_get_elapsed_cycles()%CYCLES_PER_LINE))
z80_execute(1);
z80_set_irq_line(0, ASSERT_LINE);
}
}
}
@@ -129,22 +129,22 @@ void system_init(void)

void system_shutdown(void)
{
sms_shutdown();
pio_shutdown();
vdp_shutdown();
render_shutdown();
sound_shutdown();
error_shutdown();
sms_shutdown();
pio_shutdown();
vdp_shutdown();
render_shutdown();
sound_shutdown();
error_shutdown();
}

void system_reset(void)
{
sms_reset();
pio_reset();
vdp_reset();
render_reset();
sound_reset();
system_manage_sram(cart.sram, SLOT_CART, SRAM_LOAD);
sms_reset();
pio_reset();
vdp_reset();
render_reset();
sound_reset();
system_manage_sram(cart.sram, SLOT_CART, SRAM_LOAD);
}


@@ -46,48 +46,50 @@
#define INPUT_PAUSE 0x00000002 /* Master System only */
#define INPUT_RESET 0x00000004 /* Master System only */

enum {
SRAM_SAVE = 0,
SRAM_LOAD = 1
enum
{
SRAM_SAVE = 0,
SRAM_LOAD = 1
};


/* User input structure */
typedef struct
{
uint8 pad[2];
int analog[2][2];
uint8 system;
uint8_t pad[2];
int32_t analog[2][2];
uint8_t system;
} input_t;

/* Game image structure */
typedef struct
{
uint8 *rom;
uint8 loaded;
uint32 size;
uint8 pages;
uint32 crc;
uint32 sram_crc;
int8 mapper;
uint8 sram[0x8000];
uint8 fcr[4];
uint8_t *rom;
uint8_t loaded;
uint32_t size;
/* We need to use an unsigned short for pages, as Bad Apple SMS requires it !*/
uint16_t pages;
int32_t crc;
uint32_t sram_crc;
int8_t mapper;
uint8_t sram[0x8000];
uint8_t fcr[4];
} cart_t;

/* Bitmap structure */
typedef struct
{
unsigned char *data;
int width;
int height;
int pitch;
int depth;
int granularity;
struct {
int x, y, w, h;
int ox, oy, ow, oh;
int changed;
} viewport;
uint8_t *data;
uint32_t width;
uint32_t height;
uint32_t pitch;
uint32_t depth;
uint32_t granularity;
struct
{
int32_t x, y, w, h;
int32_t ox, oy, ow, oh;
int32_t changed;
} viewport;
} bitmap_t;

/* Global variables */
@@ -96,7 +98,7 @@ extern cart_t cart; /* Game cartridge data */
extern input_t input; /* Controller input */

/* Function prototypes */
extern void system_frame(int skip_render);
extern void system_frame(uint32_t skip_render);
extern void system_init(void);
extern void system_shutdown(void);
extern void system_reset(void);

0 comments on commit 80aefb9

Please sign in to comment.
You can’t perform that action at this time.