Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 17788c3ddd | |||
| 15af996d79 | |||
| 2c0279c0ac | |||
| 6863200707 | |||
| 35889724f4 | |||
| 41577e1fa5 | |||
| 02499a735b | |||
| 2875815a60 | |||
| f1828430d3 | |||
| 682625653b |
Binary file not shown.
+149
-48
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2015, OpenEmu Team
|
||||
Copyright (c) 2018, OpenEmu Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
@@ -36,9 +36,19 @@
|
||||
#include "shared.h"
|
||||
#include "scrc32.h"
|
||||
|
||||
#define OptionDefault(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @YES, }
|
||||
#define Option(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, }
|
||||
#define OptionIndented(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeIndentationLevelKey : @(1), }
|
||||
#define OptionToggleable(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeAllowsToggleKey : @YES, }
|
||||
#define OptionToggleableNoSave(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeAllowsToggleKey : @YES, OEGameCoreDisplayModeDisallowPrefSaveKey : @YES, }
|
||||
#define Label(_NAME_) @{ OEGameCoreDisplayModeLabelKey : _NAME_, }
|
||||
#define SeparatorItem() @{ OEGameCoreDisplayModeSeparatorItemKey : @"",}
|
||||
|
||||
static const double pal_fps = 53203424.0 / (3420.0 * 313.0);
|
||||
static const double ntsc_fps = 53693175.0 / (3420.0 * 262.0);
|
||||
|
||||
t_config config;
|
||||
|
||||
char GG_ROM[256];
|
||||
char AR_ROM[256];
|
||||
char SK_ROM[256];
|
||||
@@ -99,9 +109,10 @@ typedef NS_ENUM(NSInteger, MultiTapType)
|
||||
|
||||
@interface GenPlusGameCore () <OEGenesisSystemResponderClient, OESegaCDSystemResponderClient>
|
||||
{
|
||||
uint8_t *videoBuffer;
|
||||
int16_t *soundBuffer;
|
||||
NSMutableDictionary *cheatList;
|
||||
uint8_t *_videoBuffer;
|
||||
int16_t *_soundBuffer;
|
||||
NSMutableDictionary<NSString *, NSNumber *> *_cheatList;
|
||||
NSMutableArray <NSMutableDictionary <NSString *, id> *> *_availableDisplayModes;
|
||||
NSURL *_romFile;
|
||||
MultiTapType _multiTapType;
|
||||
}
|
||||
@@ -119,9 +130,9 @@ static __weak GenPlusGameCore *_current;
|
||||
{
|
||||
if((self = [super init]))
|
||||
{
|
||||
videoBuffer = (uint8_t*)malloc(720 * 576 * 4);
|
||||
soundBuffer = (int16_t *)malloc(2048 * 2 * 2);
|
||||
cheatList = [NSMutableDictionary dictionary];
|
||||
_videoBuffer = (uint8_t *)malloc(720 * 576 * sizeof(uint32_t));
|
||||
_soundBuffer = (int16_t *)malloc(2048 * 2 * sizeof(int16_t));
|
||||
_cheatList = [NSMutableDictionary dictionary];
|
||||
}
|
||||
|
||||
_current = self;
|
||||
@@ -131,8 +142,8 @@ static __weak GenPlusGameCore *_current;
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
free(videoBuffer);
|
||||
free(soundBuffer);
|
||||
free(_videoBuffer);
|
||||
free(_soundBuffer);
|
||||
}
|
||||
|
||||
# pragma mark - Execution
|
||||
@@ -142,13 +153,13 @@ static __weak GenPlusGameCore *_current;
|
||||
_romFile = [NSURL fileURLWithPath:path];
|
||||
|
||||
// Set CD BIOS and BRAM/RAM Cart paths
|
||||
snprintf(CD_BIOS_EU, sizeof(CD_BIOS_EU), "%s%sbios_CD_E.bin", [[self biosDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BIOS_US, sizeof(CD_BIOS_US), "%s%sbios_CD_U.bin", [[self biosDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BIOS_JP, sizeof(CD_BIOS_JP), "%s%sbios_CD_J.bin", [[self biosDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%sscd_E.brm", [[self batterySavesDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%sscd_U.brm", [[self batterySavesDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BRAM_JP, sizeof(CD_BRAM_JP), "%s%sscd_J.brm", [[self batterySavesDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CART_BRAM, sizeof(CART_BRAM), "%s%scart.brm", [[self batterySavesDirectoryPath] fileSystemRepresentation], "/");
|
||||
snprintf(CD_BIOS_EU, sizeof(CD_BIOS_EU), "%s%sbios_CD_E.bin", self.biosDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CD_BIOS_US, sizeof(CD_BIOS_US), "%s%sbios_CD_U.bin", self.biosDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CD_BIOS_JP, sizeof(CD_BIOS_JP), "%s%sbios_CD_J.bin", self.biosDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CD_BRAM_EU, sizeof(CD_BRAM_EU), "%s%sscd_E.brm", self.batterySavesDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CD_BRAM_US, sizeof(CD_BRAM_US), "%s%sscd_U.brm", self.batterySavesDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CD_BRAM_JP, sizeof(CD_BRAM_JP), "%s%sscd_J.brm", self.batterySavesDirectoryPath.fileSystemRepresentation, "/");
|
||||
snprintf(CART_BRAM, sizeof(CART_BRAM), "%s%scart.brm", self.batterySavesDirectoryPath.fileSystemRepresentation, "/");
|
||||
|
||||
[self configureOptions];
|
||||
|
||||
@@ -167,7 +178,7 @@ static __weak GenPlusGameCore *_current;
|
||||
{
|
||||
config.region_detect = 3;
|
||||
region_code = REGION_JAPAN_NTSC;
|
||||
NSLog(@"Genesis Plus GX: Forcing region to Japan for multi-region cart");
|
||||
NSLog(@"[Genesis Plus GX] Forcing region to Japan for multi-region cart");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,17 +192,17 @@ static __weak GenPlusGameCore *_current;
|
||||
bram_load();
|
||||
|
||||
// Set battery saves dir and load sram
|
||||
NSString *extensionlessFilename = [[_romFile lastPathComponent] stringByDeletingPathExtension];
|
||||
NSURL *batterySavesDirectory = [NSURL fileURLWithPath:[self batterySavesDirectoryPath]];
|
||||
[[NSFileManager defaultManager] createDirectoryAtURL:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
NSString *extensionlessFilename = _romFile.lastPathComponent.stringByDeletingPathExtension;
|
||||
NSURL *batterySavesDirectory = [NSURL fileURLWithPath:self.batterySavesDirectoryPath];
|
||||
[NSFileManager.defaultManager createDirectoryAtURL:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
NSURL *saveFile = [batterySavesDirectory URLByAppendingPathComponent:[extensionlessFilename stringByAppendingPathExtension:@"sav"]];
|
||||
|
||||
if ([saveFile checkResourceIsReachableAndReturnError:nil])
|
||||
{
|
||||
NSData *saveData = [NSData dataWithContentsOfURL:saveFile];
|
||||
memcpy(sram.sram, [saveData bytes], 0x10000);
|
||||
memcpy(sram.sram, saveData.bytes, 0x10000);
|
||||
sram.crc = crc32(0, sram.sram, 0x10000);
|
||||
NSLog(@"GenesisPlusGX: Loaded sram");
|
||||
NSLog(@"[Genesis Plus GX] Loaded sram");
|
||||
}
|
||||
|
||||
if([self.systemIdentifier isEqualToString:@"openemu.system.sg"] || [self.systemIdentifier isEqualToString:@"openemu.system.scd"])
|
||||
@@ -213,8 +224,8 @@ static __weak GenPlusGameCore *_current;
|
||||
else
|
||||
system_frame_sms(0);
|
||||
|
||||
int samples = audio_update(soundBuffer);
|
||||
[[self ringBufferAtIndex:0] write:soundBuffer maxLength:samples << 2];
|
||||
int samples = audio_update(_soundBuffer);
|
||||
[[self ringBufferAtIndex:0] write:_soundBuffer maxLength:samples << 2];
|
||||
}
|
||||
|
||||
- (void)resetEmulation
|
||||
@@ -241,8 +252,8 @@ static __weak GenPlusGameCore *_current;
|
||||
if ((filesize != 0) || (crc32(0, &sram.sram[0], 0x10000) != sram.crc))
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSString *extensionlessFilename = [[_romFile lastPathComponent] stringByDeletingPathExtension];
|
||||
NSURL *batterySavesDirectory = [NSURL fileURLWithPath:[self batterySavesDirectoryPath]];
|
||||
NSString *extensionlessFilename = _romFile.lastPathComponent.stringByDeletingPathExtension;
|
||||
NSURL *batterySavesDirectory = [NSURL fileURLWithPath:self.batterySavesDirectoryPath];
|
||||
NSURL *saveFile = [batterySavesDirectory URLByAppendingPathComponent:[extensionlessFilename stringByAppendingPathExtension:@"sav"]];
|
||||
|
||||
// copy SRAM data
|
||||
@@ -253,9 +264,9 @@ static __weak GenPlusGameCore *_current;
|
||||
sram.crc = crc32(0, sram.sram, 0x10000);
|
||||
|
||||
if (error)
|
||||
NSLog(@"GenesisPlusGX: Error writing sram file: %@", error);
|
||||
NSLog(@"[Genesis Plus GX] Error writing sram file: %@", error);
|
||||
else
|
||||
NSLog(@"GenesisPlusGX: Saved sram file: %@", saveFile);
|
||||
NSLog(@"[Genesis Plus GX] Saved sram file: %@", saveFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +288,7 @@ static __weak GenPlusGameCore *_current;
|
||||
- (const void *)getVideoBufferWithHint:(void *)hint
|
||||
{
|
||||
if (!hint) {
|
||||
hint = videoBuffer;
|
||||
hint = _videoBuffer;
|
||||
}
|
||||
|
||||
return bitmap.data = (uint8_t*)hint;
|
||||
@@ -306,7 +317,7 @@ static __weak GenPlusGameCore *_current;
|
||||
{
|
||||
return OEIntSizeMake(160, 144);
|
||||
}
|
||||
else if([self.systemIdentifier isEqualToString:@"openemu.system.sms"] || [self.systemIdentifier isEqualToString:@"openemu.system.sg100"])
|
||||
else if([self.systemIdentifier isEqualToString:@"openemu.system.sms"] || [self.systemIdentifier isEqualToString:@"openemu.system.sg1000"])
|
||||
{
|
||||
return OEIntSizeMake(256 * (8.0/7.0), 192);
|
||||
}
|
||||
@@ -347,7 +358,7 @@ static __weak GenPlusGameCore *_current;
|
||||
int serial_size = STATE_SIZE;
|
||||
NSMutableData *stateData = [NSMutableData dataWithLength:serial_size];
|
||||
|
||||
if(!state_save([stateData mutableBytes]))
|
||||
if(!state_save(stateData.mutableBytes))
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
|
||||
NSLocalizedDescriptionKey : @"Save state data could not be written",
|
||||
@@ -375,17 +386,17 @@ static __weak GenPlusGameCore *_current;
|
||||
}
|
||||
|
||||
int serial_size = STATE_SIZE;
|
||||
if(serial_size != [data length])
|
||||
if(serial_size != data.length)
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreStateHasWrongSizeError userInfo:@{
|
||||
NSLocalizedDescriptionKey : @"Save state has wrong file size.",
|
||||
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, serial_size, [data length]],
|
||||
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, serial_size, data.length],
|
||||
}];
|
||||
block(NO, error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!state_load((uint8_t *)[data bytes]))
|
||||
if(!state_load((uint8_t *)data.bytes))
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
|
||||
NSLocalizedDescriptionKey : @"The save state data could not be read",
|
||||
@@ -418,15 +429,15 @@ static __weak GenPlusGameCore *_current;
|
||||
|
||||
- (BOOL)deserializeState:(NSData *)state withError:(NSError **)outError
|
||||
{
|
||||
const void *bytes = [state bytes];
|
||||
size_t length = [state length];
|
||||
const void *bytes = state.bytes;
|
||||
size_t length = state.length;
|
||||
size_t serialSize = STATE_SIZE;
|
||||
|
||||
if(serialSize != length) {
|
||||
if (outError) {
|
||||
*outError = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreStateHasWrongSizeError userInfo:@{
|
||||
NSLocalizedDescriptionKey : @"Save state has wrong file size.",
|
||||
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the save state does not have the right size, %lu expected, got: %ld.", serialSize, [state length]],
|
||||
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the save state does not have the right size, %lu expected, got: %ld.", serialSize, state.length],
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -653,18 +664,18 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
code = [code stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
|
||||
if (enabled)
|
||||
cheatList[code] = @YES;
|
||||
_cheatList[code] = @YES;
|
||||
else
|
||||
[cheatList removeObjectForKey:code];
|
||||
[_cheatList removeObjectForKey:code];
|
||||
|
||||
[self resetCheats];
|
||||
|
||||
NSArray *multipleCodes = [NSArray array];
|
||||
NSArray<NSString *> *multipleCodes = [NSArray array];
|
||||
|
||||
// Apply enabled cheats found in dictionary
|
||||
for (id key in cheatList)
|
||||
for (NSString *key in _cheatList)
|
||||
{
|
||||
if ([cheatList[key] isEqual:@YES])
|
||||
if ([_cheatList[key] boolValue])
|
||||
{
|
||||
// Handle multi-line cheats
|
||||
multipleCodes = [key componentsSeparatedByString:@"+"];
|
||||
@@ -676,6 +687,84 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
}
|
||||
}
|
||||
|
||||
# pragma mark - Display Mode
|
||||
|
||||
- (NSArray <NSDictionary <NSString *, id> *> *)displayModes
|
||||
{
|
||||
if (![self.systemIdentifier isEqualToString:@"openemu.system.gg"])
|
||||
return nil;
|
||||
|
||||
if (_availableDisplayModes.count == 0)
|
||||
{
|
||||
_availableDisplayModes = [NSMutableArray array];
|
||||
|
||||
NSArray <NSDictionary <NSString *, id> *> *availableModesWithDefault =
|
||||
@[
|
||||
Label(@"Screen"),
|
||||
OptionToggleable(@"LCD Ghosting", @"ggLCDFilter"),
|
||||
];
|
||||
|
||||
// Deep mutable copy
|
||||
_availableDisplayModes = (NSMutableArray *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFArrayRef)availableModesWithDefault, kCFPropertyListMutableContainers));
|
||||
}
|
||||
|
||||
return [_availableDisplayModes copy];
|
||||
}
|
||||
|
||||
- (void)changeDisplayWithMode:(NSString *)displayMode
|
||||
{
|
||||
if (_availableDisplayModes.count == 0)
|
||||
[self displayModes];
|
||||
|
||||
// First check if 'displayMode' is valid
|
||||
BOOL isDisplayModeToggleable = NO;
|
||||
BOOL isValidDisplayMode = NO;
|
||||
BOOL displayModeState = NO;
|
||||
NSString *displayModePrefKey;
|
||||
|
||||
for (NSDictionary *modeDict in _availableDisplayModes) {
|
||||
if ([modeDict[OEGameCoreDisplayModeNameKey] isEqualToString:displayMode]) {
|
||||
displayModeState = [modeDict[OEGameCoreDisplayModeStateKey] boolValue];
|
||||
displayModePrefKey = modeDict[OEGameCoreDisplayModePrefKeyNameKey];
|
||||
isDisplayModeToggleable = [modeDict[OEGameCoreDisplayModeAllowsToggleKey] boolValue];
|
||||
isValidDisplayMode = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Disallow a 'displayMode' not found in _availableDisplayModes
|
||||
if (!isValidDisplayMode)
|
||||
return;
|
||||
|
||||
// Handle option state changes
|
||||
for (NSMutableDictionary *optionDict in _availableDisplayModes) {
|
||||
NSString *modeName = optionDict[OEGameCoreDisplayModeNameKey];
|
||||
NSString *prefKey = optionDict[OEGameCoreDisplayModePrefKeyNameKey];
|
||||
|
||||
if (!modeName)
|
||||
continue;
|
||||
// Mutually exclusive option state change
|
||||
else if ([modeName isEqualToString:displayMode] && !isDisplayModeToggleable)
|
||||
optionDict[OEGameCoreDisplayModeStateKey] = @YES;
|
||||
// Reset mutually exclusive options that are the same prefs group as 'displayMode'
|
||||
else if (!isDisplayModeToggleable && [prefKey isEqualToString:displayModePrefKey])
|
||||
optionDict[OEGameCoreDisplayModeStateKey] = @NO;
|
||||
// Toggleable option state change
|
||||
else if ([modeName isEqualToString:displayMode] && isDisplayModeToggleable)
|
||||
optionDict[OEGameCoreDisplayModeStateKey] = @(!displayModeState);
|
||||
}
|
||||
|
||||
// Game Gear: LCD ghosting / motion blur
|
||||
// Required for proper display of some effects in a few games (James Pond 3, Power Drift, Super Monaco GP II)
|
||||
if ([displayMode isEqualToString:@"LCD Ghosting"])
|
||||
{
|
||||
if (!displayModeState)
|
||||
config.lcd = (uint8)(0.80 * 256);
|
||||
else
|
||||
config.lcd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# pragma mark - Misc Helper Methods
|
||||
|
||||
- (void)applyCheat:(NSString *)code
|
||||
@@ -684,7 +773,7 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
clear_cheats();
|
||||
|
||||
/* interpret code and give it an index */
|
||||
decode_cheat((char *)[code UTF8String], maxcheats);
|
||||
decode_cheat((char *)code.UTF8String, maxcheats);
|
||||
|
||||
/* increment cheat count */
|
||||
maxcheats++;
|
||||
@@ -737,7 +826,19 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
config.overscan = 0; /* 3 == FULL */
|
||||
config.gg_extra = 0; /* 1 = show extended Game Gear screen (256x192) */
|
||||
config.ntsc = 0;
|
||||
config.lcd = 0;
|
||||
|
||||
// Only temporary, so core doesn't crash on an older OpenEmu version
|
||||
if ([self respondsToSelector:@selector(displayModeInfo)]) {
|
||||
BOOL isLCDFilterEnabled = [self.displayModeInfo[@"ggLCDFilter"] boolValue];
|
||||
if (isLCDFilterEnabled)
|
||||
[self changeDisplayWithMode:@"LCD Ghosting"];
|
||||
else
|
||||
config.lcd = 0;
|
||||
|
||||
}
|
||||
else
|
||||
config.lcd = 0;
|
||||
|
||||
config.render = 0;
|
||||
|
||||
/* initialize bitmap */
|
||||
@@ -745,7 +846,7 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
bitmap.width = 720;
|
||||
bitmap.height = 576;
|
||||
bitmap.pitch = bitmap.width * sizeof(uint32_t);
|
||||
bitmap.data = (uint8_t *)videoBuffer;
|
||||
bitmap.data = (uint8_t *)_videoBuffer;
|
||||
}
|
||||
|
||||
- (void)configureInput
|
||||
@@ -753,7 +854,7 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
_multiTapType = MultiTapTypeNone;
|
||||
|
||||
// Overrides: Six button controller-supported games missing '6' byte in cart header, so they cannot be auto-detected
|
||||
NSArray *pad6Buttons = @[
|
||||
NSArray<NSString *> *pad6Buttons = @[
|
||||
@"b04c06df1009c60182df902a4ec7c959", // Batman Forever (World)
|
||||
@"7b144947f6e8842dd4419d5166cddff6", // Boogerman - A Pick and Flick Adventure (Europe)
|
||||
@"265a10bf2ea2d1ee30e6cde631d54474", // Boogerman - A Pick and Flick Adventure (USA)
|
||||
@@ -790,7 +891,7 @@ const int MasterSystemMap[] = {INPUT_UP, INPUT_DOWN, INPUT_LEFT, INPUT_RIGHT, IN
|
||||
// Different port configurations and multitap devices are used depending on the game
|
||||
// NOTE: J-Cart games are automatically handled.
|
||||
// TODO: Identify supported Sega CD games by rominfo.domestic/rominfo.international?
|
||||
NSDictionary *multiTapGames =
|
||||
NSDictionary<NSString *, NSNumber *> *multiTapGames =
|
||||
@{
|
||||
//@"3cc6df243e714097f1599cf618f94d0b" : @(TeamPlayerPort1), // Aq Renkan Awa (Taiwan) (Unl)
|
||||
@"2b27a61cdae4492044bd273c5807de75" : @(TeamPlayerPort1), // Barkley Shut Up and Jam! (USA, Europe)
|
||||
@@ -1563,7 +1664,7 @@ void RAMCheatUpdate(void)
|
||||
/* apply RAM patch */
|
||||
//if (cheatlist[index].data & 0xFF00)
|
||||
//if (cheatlist[index].data & 0x00FF) // For LSB?
|
||||
BOOL isSega8bit = [[_current systemIdentifier] isEqualToString:@"openemu.system.gg"] || [[_current systemIdentifier] isEqualToString:@"openemu.system.sms"] || [[_current systemIdentifier] isEqualToString:@"openemu.system.sg1000"];
|
||||
BOOL isSega8bit = [_current.systemIdentifier isEqualToString:@"openemu.system.gg"] || [_current.systemIdentifier isEqualToString:@"openemu.system.sms"] || [_current.systemIdentifier isEqualToString:@"openemu.system.sg1000"];
|
||||
// TODO: Figure out why this is. Some PAR cheats for Genesis don't work otherwise.
|
||||
if (isSega8bit ? cheatlist[index].data & 0xFF00 : cheatlist[index].data & 0x00FF)
|
||||
{
|
||||
|
||||
@@ -126,10 +126,10 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
089C167EFE841241C02AAC07 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
|
||||
82287C08101E9C2C0072172D /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
|
||||
82287C33101E9DB40072172D /* GenPlusGameCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenPlusGameCore.h; sourceTree = "<group>"; };
|
||||
82287C34101E9DB40072172D /* GenPlusGameCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GenPlusGameCore.m; sourceTree = "<group>"; };
|
||||
@@ -258,7 +258,7 @@
|
||||
94ED8A8714CF933700FF8901 /* z80.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = z80.h; sourceTree = "<group>"; };
|
||||
C6B948191365164700A425F0 /* OEGenesisSystemResponderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OEGenesisSystemResponderClient.h; path = ../OpenEmu/Genesis/OEGenesisSystemResponderClient.h; sourceTree = "<group>"; };
|
||||
C6D120F1171130E700E868A8 /* OpenEmuBase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OpenEmuBase.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
||||
D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -575,7 +575,7 @@
|
||||
};
|
||||
buildConfigurationList = 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "GenesisPlus" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 1;
|
||||
knownRegions = (
|
||||
en,
|
||||
@@ -714,7 +714,7 @@
|
||||
089C167DFE841241C02AAC07 /* InfoPlist.strings */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
089C167EFE841241C02AAC07 /* English */,
|
||||
089C167EFE841241C02AAC07 /* en */,
|
||||
);
|
||||
name = InfoPlist.strings;
|
||||
sourceTree = "<group>";
|
||||
|
||||
+3
-1
@@ -19,7 +19,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.7.4.9</string>
|
||||
<string>1.7.4.12</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>OEGameCoreController</string>
|
||||
<key>OEGameCoreClass</key>
|
||||
@@ -34,6 +34,8 @@
|
||||
<integer>0</integer>
|
||||
<key>OEGameCoreSupportsCheatCode</key>
|
||||
<true/>
|
||||
<key>OEGameCoreSupportsDisplayModeChange</key>
|
||||
<true/>
|
||||
<key>OEGameCoreSupportsRewinding</key>
|
||||
<true/>
|
||||
</dict>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/* Localized versions of Info.plist keys */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Mega Drive cartridge hardware support
|
||||
*
|
||||
* Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Many cartridge protections were initially documented by Haze
|
||||
* (http://haze.mameworld.info/)
|
||||
@@ -74,7 +74,11 @@ static void mapper_seganet_w(uint32 address, uint32 data);
|
||||
static void mapper_32k_w(uint32 data);
|
||||
static void mapper_64k_w(uint32 data);
|
||||
static void mapper_64k_multi_w(uint32 address);
|
||||
static uint32 mapper_radica_r(uint32 address);
|
||||
static uint32 mapper_128k_multi_r(uint32 address);
|
||||
static void mapper_256k_multi_w(uint32 address, uint32 data);
|
||||
static void mapper_wd1601_w(uint32 address, uint32 data);
|
||||
static uint32 mapper_64k_radica_r(uint32 address);
|
||||
static uint32 mapper_128k_radica_r(uint32 address);
|
||||
static void default_time_w(uint32 address, uint32 data);
|
||||
static void default_regs_w(uint32 address, uint32 data);
|
||||
static uint32 default_regs_r(uint32 address);
|
||||
@@ -102,13 +106,26 @@ static const md_entry_t rom_database[] =
|
||||
/* Tom Clown */
|
||||
{0x0000,0xc0cd,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},1,0,NULL,NULL,NULL,mapper_realtec_w}},
|
||||
|
||||
/* 1800-in-1 */
|
||||
{0x3296,0x2370,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,1,mapper_128k_multi_r,m68k_unused_8_w,NULL,NULL}},
|
||||
|
||||
/* Golden Mega 250-in-1 */
|
||||
{0xe43c,0x886f,0x08,0x08,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,1,NULL,m68k_unused_8_w,NULL,mapper_256k_multi_w}},
|
||||
|
||||
/* RADICA (Volume 1) (bad dump ?) */
|
||||
{0x0000,0x2326,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,1,mapper_radica_r,NULL,NULL,NULL}},
|
||||
{0x0000,0x2326,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,1,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Volume 1) */
|
||||
{0x24f4,0xfc84,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_radica_r,NULL,NULL,NULL}},
|
||||
{0x24f4,0xfc84,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Volume 2) */
|
||||
{0x104f,0x32e9,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_radica_r,NULL,NULL,NULL}},
|
||||
{0xd951,0x78d0,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Volume 3 - Super Sonic Gold edition) */
|
||||
{0x0000,0x1f25,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Street Fighter II CE edition) */
|
||||
{0x1add,0xa838,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Street Fighter II CE edition) (PAL) */
|
||||
{0x104f,0x32e9,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_64k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
/* RADICA (Sensible Soccer Plus edition) (PAL) */
|
||||
{0x0000,0x1f7f,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_128k_radica_r,m68k_unused_8_w,NULL,NULL}},
|
||||
|
||||
|
||||
/* Tenchi wo Kurau III: Sangokushi Gaiden - Chinese Fighter */
|
||||
@@ -376,17 +393,48 @@ void md_cart_init(void)
|
||||
sram_init();
|
||||
eeprom_i2c_init();
|
||||
|
||||
/* external SRAM */
|
||||
/* memory-mapped SRAM */
|
||||
if (sram.on && !sram.custom)
|
||||
{
|
||||
/* initialize default memory mapping for SRAM */
|
||||
m68k.memory_map[sram.start >> 16].base = sram.sram;
|
||||
m68k.memory_map[sram.start >> 16].read8 = sram_read_byte;
|
||||
m68k.memory_map[sram.start >> 16].read16 = sram_read_word;
|
||||
m68k.memory_map[sram.start >> 16].write8 = sram_write_byte;
|
||||
m68k.memory_map[sram.start >> 16].write16 = sram_write_word;
|
||||
zbank_memory_map[sram.start >> 16].read = sram_read_byte;
|
||||
zbank_memory_map[sram.start >> 16].write = sram_write_byte;
|
||||
/* SRAM is mapped by default unless it overlaps with ROM area (Phantasy Star 4, Beyond Oasis/Legend of Thor, World Series Baseball 9x, Duke Nukem 3D,...) */
|
||||
if (sram.start >= cart.romsize)
|
||||
{
|
||||
m68k.memory_map[sram.start >> 16].base = sram.sram;
|
||||
m68k.memory_map[sram.start >> 16].read8 = sram_read_byte;
|
||||
m68k.memory_map[sram.start >> 16].read16 = sram_read_word;
|
||||
m68k.memory_map[sram.start >> 16].write8 = sram_write_byte;
|
||||
m68k.memory_map[sram.start >> 16].write16 = sram_write_word;
|
||||
zbank_memory_map[sram.start >> 16].read = sram_read_byte;
|
||||
zbank_memory_map[sram.start >> 16].write = sram_write_byte;
|
||||
}
|
||||
|
||||
/* support for Triple Play 96 & Triple Play - Gold Edition mapping */
|
||||
else if ((strstr(rominfo.product,"T-172026") != NULL) || (strstr(rominfo.product,"T-172116") != NULL))
|
||||
{
|
||||
/* $000000-$1fffff: cartridge ROM (lower 2MB) */
|
||||
/* $200000-$2fffff: SRAM (32KB mirrored) */
|
||||
/* NB: existing 4MB ROM dumps include SRAM data at ROM offsets 0x200000-0x2fffff */
|
||||
for (i=0x20; i<0x30; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = sram.sram;
|
||||
m68k.memory_map[i].read8 = sram_read_byte;
|
||||
m68k.memory_map[i].read16 = sram_read_word;
|
||||
m68k.memory_map[i].write8 = sram_write_byte;
|
||||
m68k.memory_map[i].write16 = sram_write_word;
|
||||
zbank_memory_map[i].read = sram_read_byte;
|
||||
zbank_memory_map[i].write = sram_write_byte;
|
||||
}
|
||||
|
||||
/* $300000-$3fffff: cartridge ROM (upper 1MB) */
|
||||
/* NB: only real (3MB) Mask ROM dumps need ROM offsets 0x200000-0x2fffff to be remapped to this area */
|
||||
if (READ_BYTE(cart.rom, 0x200000) != 0xFF)
|
||||
{
|
||||
for (i=0x30; i<0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = cart.rom + ((i - 0x10) << 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
@@ -401,7 +449,7 @@ void md_cart_init(void)
|
||||
/**********************************************
|
||||
LOCK-ON
|
||||
***********************************************/
|
||||
|
||||
|
||||
/* clear existing patches */
|
||||
ggenie_shutdown();
|
||||
areplay_shutdown();
|
||||
@@ -434,7 +482,7 @@ void md_cart_init(void)
|
||||
{
|
||||
/* try to load Sonic 2 & Knuckles UPMEM ROM (256 KB) */
|
||||
if (load_archive(SK_UPMEM, cart.rom + 0x900000, 0x40000, NULL) == 0x40000)
|
||||
{
|
||||
{
|
||||
/* $000000-$1FFFFF is mapped to S&K ROM */
|
||||
for (i=0x00; i<0x20; i++)
|
||||
{
|
||||
@@ -449,7 +497,7 @@ void md_cart_init(void)
|
||||
cart.rom[i + 0x600000] = cart.rom[i + 0x600000 + 1];
|
||||
cart.rom[i + 0x600000 + 1] = temp;
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<0x40000; i+=2)
|
||||
{
|
||||
/* Byteswap ROM */
|
||||
@@ -637,6 +685,20 @@ void md_cart_init(void)
|
||||
m68k.memory_map[0x00].write16 = mapper_flashkit_w;
|
||||
zbank_memory_map[0x00].write = mapper_flashkit_w;
|
||||
}
|
||||
else if ((cart.romsize = 0x400000) &&
|
||||
(READ_BYTE(cart.rom, 0x200150) == 'C') &&
|
||||
(READ_BYTE(cart.rom, 0x200151) == 'A') &&
|
||||
(READ_BYTE(cart.rom, 0x200152) == 'N') &&
|
||||
(READ_BYTE(cart.rom, 0x200153) == 'O') &&
|
||||
(READ_BYTE(cart.rom, 0x200154) == 'N'))
|
||||
{
|
||||
/* Canon - Legend of the new Gods (4MB dump) */
|
||||
cart.hw.time_w = mapper_wd1601_w;
|
||||
cart.hw.bankshift = 1;
|
||||
sram.on = 1;
|
||||
sram.start = 0x200000;
|
||||
sram.end = 0x201fff;
|
||||
}
|
||||
else if ((*(uint16 *)(cart.rom + 0x08) == 0x6000) && (*(uint16 *)(cart.rom + 0x0a) == 0x01f6) && (rominfo.realchecksum == 0xf894))
|
||||
{
|
||||
/* Super Mario World 64 (unlicensed) mapper */
|
||||
@@ -760,9 +822,14 @@ int md_cart_context_save(uint8 *state)
|
||||
/* SRAM */
|
||||
state[bufferptr++] = 0xff;
|
||||
}
|
||||
else if (base == boot_rom)
|
||||
{
|
||||
/* Boot ROM */
|
||||
state[bufferptr++] = 0xfe;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ROM */
|
||||
/* Cartridge ROM */
|
||||
state[bufferptr++] = ((base - cart.rom) >> 16) & 0xff;
|
||||
}
|
||||
}
|
||||
@@ -819,7 +886,7 @@ int md_cart_context_load(uint8 *state)
|
||||
}
|
||||
|
||||
/* ROM */
|
||||
m68k.memory_map[i].base = cart.rom + (offset << 16);
|
||||
m68k.memory_map[i].base = (offset == 0xfe) ? boot_rom : (cart.rom + (offset << 16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -908,7 +975,7 @@ static void mapper_512k_w(uint32 address, uint32 data)
|
||||
uint32 i;
|
||||
|
||||
/* 512K ROM paging */
|
||||
uint8 *src = cart.rom + (data << 19);
|
||||
uint8 *src = cart.rom + ((data << 19) & cart.mask);
|
||||
|
||||
/* cartridge area ($000000-$3FFFFF) is divided into 8 x 512K banks */
|
||||
address = (address << 2) & 0x38;
|
||||
@@ -1621,27 +1688,208 @@ static void mapper_64k_multi_w(uint32 address)
|
||||
/* 64 x 64k banks */
|
||||
for (i=0; i<64; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[((address++) & 0x3f) << 16];
|
||||
m68k.memory_map[i].base = &cart.rom[((address + i) & 0x3f) << 16];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Custom ROM Bankswitch used in pirate "1800-in-1" cartridge
|
||||
*/
|
||||
static uint32 mapper_128k_multi_r(uint32 address)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* 16 x 128k banks (2MB ROM) */
|
||||
/* Bank index (B3 B2 B1 B0) is encoded in address lower byte = {0 X B0 B1 X B2 B3 0} */
|
||||
/* Note: {0 B0 X B1 X B2 B3 0} also works, see below for the 9 unique values being used for all menu entries
|
||||
read16 00A13000 (0002FBEE) => 0x000000-0x03ffff (2x128KB)
|
||||
read16 00A13018 (00FF2056) => 0x040000-0x07ffff (2x128KB)
|
||||
read16 00A13004 (00FF2120) => 0x080000-0x0bffff (2x128KB)
|
||||
read16 00A1301C (00FF20A6) => 0x0c0000-0x0fffff (2x128KB)
|
||||
read16 00A1300A (00FF20BA) => 0x100000-0x13ffff (2x128KB)
|
||||
read16 00A1301A (00FF20CE) => 0x140000-0x17ffff (2x128KB)
|
||||
read16 00A1300E (00FF20F4) => 0x180000-0x1bffff (2x128KB)
|
||||
read16 00A1301E (00FF2136) => 0x1c0000-0x1dffff (1x128KB)
|
||||
read16 00A1307E (00FF2142) => 0x1e0000-0x1fffff (1x128KB)
|
||||
*/
|
||||
int bank = ((address & 0x02) << 2) | (address & 0x04) | ((address & 0x10) >> 3) | ((address & 0x20) >> 5);
|
||||
|
||||
/* remap cartridge area (64 x 64k banks) */
|
||||
address = bank << 1;
|
||||
for (i=0x00; i<0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[((address + i) & 0x3f) << 16];
|
||||
}
|
||||
|
||||
/* returned value changes the menu title and number of entries in the 'game' list (the number of distinct games does not change though) */
|
||||
/* 0x00 => 9-in-1 */
|
||||
/* 0x01 => 190-in-1 */
|
||||
/* 0x02 => 888-in-1 */
|
||||
/* 0x03 => 1800-in-1 */
|
||||
/* real cartridge board has switches to select between the four different menus but here we force the largest menu selection (each other menus being a subset of the next larger menu) */
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
/*
|
||||
Custom ROM Bankswitch used in pirate "Golden Mega 250-in-1" cartridge
|
||||
*/
|
||||
static void mapper_256k_multi_w(uint32 address, uint32 data)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* 8 x 256k banks (2MB ROM) */
|
||||
/* Bank index (B2 B1 B0) is encoded in data lower byte = {B1 B0 X X 0 0 0 B2} */
|
||||
/* Note: {X B0 B1 B2 0 0 0 X}, {B1 B0 X B2 0 0 0 X} or {X B0 B1 X 0 0 0 B2} also work, see below for the 4 unique values being used for all menu entries
|
||||
write16 00089000 = 0000 (00FF0006) => 0x000000-0x03ffff (1x256KB)
|
||||
write16 00089000 = 0040 (00FF0006) => 0x040000-0x07ffff (1x256KB)
|
||||
write16 00089000 = 00A0 (00FF0006) => 0x080000-0x0fffff (2x256KB)
|
||||
write16 00089000 = 0011 (00FF0006) => 0x100000-0x1fffff (4x256KB)
|
||||
*/
|
||||
int bank = ((data & 0x01) << 2) | ((data & 0xc0) >> 6);
|
||||
|
||||
/* remap cartridge area (64 x 64k banks) */
|
||||
address = bank << 2;
|
||||
for (i=0x00; i<0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[((address + i) & 0x3f) << 16];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Custom ROM Bankswitch used in "Canon - Legend of the New Gods"
|
||||
(uses WD1601 QFPL V1.01 board also used in chinese X-in-1 pirates sold by mindkids)
|
||||
*/
|
||||
static void mapper_wd1601_w(uint32 address, uint32 data)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* !TIME write16 0xA13002 = 0x3002 (00FFFE0C) */
|
||||
/* The board probably allows up to 256MB Flash ROM remapping but this game only has 4MB ROM chip */
|
||||
if ((address & 0xfe) == 0x02)
|
||||
{
|
||||
/* upper 2MB ROM mapped to $000000-$1fffff */
|
||||
for (i=0; i<0x20; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[(0x20 + i) << 16];
|
||||
}
|
||||
|
||||
/* backup RAM (8KB) mapped to $2000000-$3fffff */
|
||||
for (i=0x20; i<0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = sram.sram;
|
||||
m68k.memory_map[i].read8 = sram_read_byte;
|
||||
m68k.memory_map[i].read16 = sram_read_word;
|
||||
m68k.memory_map[i].write8 = sram_write_byte;
|
||||
m68k.memory_map[i].write16 = sram_write_word;
|
||||
zbank_memory_map[i].read = sram_read_byte;
|
||||
zbank_memory_map[i].write = sram_write_byte;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Custom ROM Bankswitch used in RADICA cartridges
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Two different boards seem to exist (one with support for 64KB banks mapping and another one supporting 128KB banks + battery-RAM).
|
||||
Radica Volume 1 requires 64KB banks mapping as the menu is located at a 64KB boundary.
|
||||
Sensible Soccer Plus edition requires 128KB banks mapping with only VA6-VA2 being used to select bank index (VA1 is ignored).
|
||||
Sensible Soccer Plus edition also requires 8KB backup RAM to be mapped in higher 2MB range.
|
||||
Other games support both 64KB or 128KB mapping so it's not clear what exact board they are using but none require SRAM so we use 64KB mapper by default.
|
||||
Note that Radica Volume 3 uses similar ROM mapping as Sensible Soccer Plus edition so it might be using same 128KB board, without any SRAM chip connected.
|
||||
*/
|
||||
static uint32 mapper_radica_r(uint32 address)
|
||||
static uint32 mapper_64k_radica_r(uint32 address)
|
||||
{
|
||||
int i = 0;
|
||||
address = (address >> 1);
|
||||
|
||||
|
||||
/* 64 x 64k banks */
|
||||
for (i = 0; i < 64; i++)
|
||||
/*
|
||||
Volume 1
|
||||
--------
|
||||
000000h-0fffffh: Kid Chameleon : !TIME read16 0xA13000 (00FF103A)
|
||||
100000h-1fffffh: Dr Robotnik's Mean Bean Machine : !TIME read16 0xA13020 (00FF101E)
|
||||
200000h-27ffffh: Sonic The Hedgehog : !TIME read16 0xA13040 (00FF101E)
|
||||
280000h-2fffffh: Golden Axe : !TIME read16 0xA13050 (00FF101E)
|
||||
300000h-37ffffh: Altered Beast : !TIME read16 0xA13060 (00FF101E)
|
||||
380000h-39ffffh: Flicky : !TIME read16 0xA13070 (00FF101E)
|
||||
3a0000h-3effffh: N/A : N/A
|
||||
3f0000h-3fffffh: Radica Menu (64 KB) : !TIME read16 0xA1307E (00FF1006)
|
||||
|
||||
Volume 2
|
||||
--------
|
||||
000000h-0fffffh: Sonic The Hedgehog 2 : !TIME read16 0xA13000 (00FF103A)
|
||||
100000h-1fffffh: The Ooze : !TIME read16 0xA13020 (00FF101E)
|
||||
200000h-2fffffh: Ecco The Dolphin : !TIME read16 0xA13040 (00FF101E)
|
||||
300000h-37ffffh: Gain Ground : !TIME read16 0xA13060 (00FF101E)
|
||||
380000h-3bffffh: Alex Kidd in Enchanted Castle : !TIME read16 0xA13070 (00FF101E)
|
||||
3c0000h-3dffffh: Columns : !TIME read16 0xA13078 (00FF101E)
|
||||
3e0000h-3fffffh: Radica Menu (128 KB) : !TIME read16 0xA1307C (00FF1006)
|
||||
|
||||
Volume 3 - Super Sonic Gold edition
|
||||
-----------------------------------
|
||||
000000h-01ffffh: Radica Menu (128 KB) : N/A
|
||||
020000h-07ffffh: N/A : N/A
|
||||
080000h-0fffffh: Sonic The Hedgehog : !TIME read16 0xA13010 (00FF1012)
|
||||
100000h-1fffffh: Sonic The Hedgehog 2 : !TIME read16 0xA13020 (00FF1012)
|
||||
200000h-2fffffh: Sonic Spinball : !TIME read16 0xA13040 (00FF1012)
|
||||
300000h-3fffffh: Dr Robotnik's Mean Bean Machine : !TIME read16 0xA13060 (00FF1012)
|
||||
|
||||
Street Fighter 2 CE edition
|
||||
---------------------------
|
||||
000000h-2fffffh: Street Fighter 2 CE : !TIME read16 0xA13000 (00FF103A)
|
||||
300000h-3bffffh: Ghouls'n Ghosts : !TIME read16 0xA13060 (00FF101E)
|
||||
3c0000h-3dffffh: Radica Menu (128 KB) : !TIME read16 0xA13078 (00FF1006)
|
||||
3e0000h-3fffffh: N/A : N/A
|
||||
*/
|
||||
int index = (address >> 1) & 0x3F;
|
||||
|
||||
/* $000000-$3fffff area is mapped to selected banks (OR gates between VA21-VA16 and selected index) */
|
||||
for (i = 0x00; i < 0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[((address++)& 0x3f)<< 16];
|
||||
m68k.memory_map[i].base = &cart.rom[(index | i) << 16];
|
||||
}
|
||||
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
static uint32 mapper_128k_radica_r(uint32 address)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* 32 x 128k banks */
|
||||
/*
|
||||
Sensible Soccer Plus edition
|
||||
----------------------------
|
||||
000000h-01ffffh: Radica Menu (128 KB) : N/A
|
||||
020000h-07ffffh: N/A : N/A
|
||||
080000h-0fffffh: Sensible Soccer : !TIME read16 0xA13010 (00FF1012)
|
||||
100000h-1fffffh: Mega-Lo-Mania : !TIME read16 0xA13022 (00FF1012)
|
||||
200000h-37ffffh: Cannon Fodder : !TIME read16 0xA13042 (00FF1012)
|
||||
380000h-3fffffh: N/A : N/A
|
||||
|
||||
Note: address bit 1 is ignored for bank selection but might be used to enable/disable SRAM mapping ?
|
||||
*/
|
||||
int index = (address >> 1) & 0x3E;
|
||||
|
||||
/* $000000-$1fffff area is mapped to selected banks (OR gates between VA20-VA17 and selected index) */
|
||||
for (i = 0x00; i < 0x20; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = &cart.rom[(index | i) << 16];
|
||||
}
|
||||
|
||||
/* $200000-$3fffff area is mapped to 8KB SRAM (mirrored) */
|
||||
for (i = 0x20; i < 0x40; i++)
|
||||
{
|
||||
m68k.memory_map[i].base = sram.sram;
|
||||
m68k.memory_map[i].read8 = sram_read_byte;
|
||||
m68k.memory_map[i].read16 = sram_read_word;
|
||||
m68k.memory_map[i].write8 = sram_write_byte;
|
||||
m68k.memory_map[i].write16 = sram_write_word;
|
||||
zbank_memory_map[i].read = sram_read_byte;
|
||||
zbank_memory_map[i].write = sram_write_byte;
|
||||
}
|
||||
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
default !TIME signal handler
|
||||
@@ -1650,7 +1898,7 @@ static uint32 mapper_radica_r(uint32 address)
|
||||
static void default_time_w(uint32 address, uint32 data)
|
||||
{
|
||||
/* enable multi-game cartridge mapper by default */
|
||||
if (address < 0xa13040)
|
||||
if (address < 0xa13060)
|
||||
{
|
||||
mapper_64k_multi_w(address);
|
||||
return;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Mega Drive cartridge hardware support
|
||||
*
|
||||
* Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Most cartridge protections were initially documented by Haze
|
||||
* (http://haze.mameworld.info/)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* SG-1000, Master System & Game Gear cartridge hardware support
|
||||
*
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -243,6 +243,7 @@ static const rominfo_t game_list[] =
|
||||
/* games requiring 3-D Glasses & Sega Light Phaser */
|
||||
{0xFBE5CFBB, 1, 0, SYSTEM_LIGHTPHASER, MAPPER_SEGA, SYSTEM_SMS, REGION_USA}, /* Missile Defense 3D */
|
||||
{0xE79BB689, 1, 0, SYSTEM_LIGHTPHASER, MAPPER_SEGA, SYSTEM_SMS, REGION_USA}, /* Missile Defense 3D [BIOS] */
|
||||
{0x43DEF05D, 1, 0, SYSTEM_LIGHTPHASER, MAPPER_SEGA, SYSTEM_SMS, REGION_USA}, /* Missile Defense 3D [Proto] */
|
||||
|
||||
/* games requiring Sega Light Phaser */
|
||||
{0x861B6E79, 0, 0, SYSTEM_LIGHTPHASER, MAPPER_SEGA, SYSTEM_SMS, REGION_USA}, /* Assault City [Light Phaser] */
|
||||
@@ -609,9 +610,6 @@ void sms_cart_reset(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* reset Memory Control register (RAM & I/O are enabled, either BIOS or Cartridge ROM are enabled) */
|
||||
io_reg[0x0E] = bios_rom.pages ? 0xE0 : 0xA8;
|
||||
|
||||
/* reset Z80 memory map */
|
||||
mapper_reset();
|
||||
|
||||
@@ -742,14 +740,96 @@ int sms_cart_region_detect(void)
|
||||
int sms_cart_context_save(uint8 *state)
|
||||
{
|
||||
int bufferptr = 0;
|
||||
save_param(slot.fcr, 4);
|
||||
|
||||
/* check if cartridge ROM is disabled */
|
||||
if (io_reg[0x0E] & 0x40)
|
||||
{
|
||||
/* save Boot ROM mapper settings */
|
||||
save_param(bios_rom.fcr, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* save cartridge mapper settings */
|
||||
save_param(cart_rom.fcr, 4);
|
||||
}
|
||||
|
||||
/* support for SG-1000 games with extra RAM */
|
||||
if ((cart_rom.mapper == MAPPER_RAM_8K) || (cart_rom.mapper == MAPPER_RAM_8K_EXT1))
|
||||
{
|
||||
/* 8KB extra RAM */
|
||||
save_param(work_ram + 0x2000, 0x2000);
|
||||
}
|
||||
else if (cart_rom.mapper == MAPPER_RAM_2K)
|
||||
{
|
||||
/* 2KB extra RAM */
|
||||
save_param(work_ram + 0x2000, 0x800);
|
||||
}
|
||||
|
||||
return bufferptr;
|
||||
}
|
||||
|
||||
int sms_cart_context_load(uint8 *state)
|
||||
{
|
||||
int bufferptr = 0;
|
||||
load_param(slot.fcr, 4);
|
||||
|
||||
/* check if cartridge ROM is disabled */
|
||||
if (io_reg[0x0E] & 0x40)
|
||||
{
|
||||
/* load Boot ROM mapper settings */
|
||||
load_param(bios_rom.fcr, 4);
|
||||
|
||||
/* set default cartridge ROM paging */
|
||||
switch (cart_rom.mapper)
|
||||
{
|
||||
case MAPPER_SEGA:
|
||||
case MAPPER_SEGA_X:
|
||||
cart_rom.fcr[0] = 0;
|
||||
cart_rom.fcr[1] = 0;
|
||||
cart_rom.fcr[2] = 1;
|
||||
cart_rom.fcr[3] = 2;
|
||||
break;
|
||||
|
||||
case MAPPER_KOREA_8K:
|
||||
case MAPPER_MSX:
|
||||
case MAPPER_MSX_NEMESIS:
|
||||
cart_rom.fcr[0] = 0;
|
||||
cart_rom.fcr[1] = 0;
|
||||
cart_rom.fcr[2] = 0;
|
||||
cart_rom.fcr[3] = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
cart_rom.fcr[0] = 0;
|
||||
cart_rom.fcr[1] = 0;
|
||||
cart_rom.fcr[2] = 1;
|
||||
cart_rom.fcr[3] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* load cartridge mapper settings */
|
||||
load_param(cart_rom.fcr, 4);
|
||||
|
||||
/* set default BIOS ROM paging (SEGA mapper by default) */
|
||||
bios_rom.fcr[0] = 0;
|
||||
bios_rom.fcr[1] = 0;
|
||||
bios_rom.fcr[2] = 1;
|
||||
bios_rom.fcr[3] = 2;
|
||||
}
|
||||
|
||||
/* support for SG-1000 games with extra RAM */
|
||||
if ((cart_rom.mapper == MAPPER_RAM_8K) || (cart_rom.mapper == MAPPER_RAM_8K_EXT1))
|
||||
{
|
||||
/* 8KB extra RAM */
|
||||
load_param(work_ram + 0x2000, 0x2000);
|
||||
}
|
||||
else if (cart_rom.mapper == MAPPER_RAM_2K)
|
||||
{
|
||||
/* 2KB extra RAM */
|
||||
load_param(work_ram + 0x2000, 0x800);
|
||||
}
|
||||
|
||||
return bufferptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* SG-1000, Master System & Game Gear cartridge hardware support
|
||||
*
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Backup RAM support
|
||||
*
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -147,6 +147,13 @@ void sram_init()
|
||||
sram.start = 0x400001;
|
||||
sram.end = 0x40ffff;
|
||||
}
|
||||
else if ((rominfo.checksum == 0x0000) && (rominfo.realchecksum == 0x1f7f) && (READ_BYTE(cart.rom + 0x80000,0x1b0) == 0x52) && (READ_BYTE(cart.rom + 0x80000,0x1b1) == 0x41))
|
||||
{
|
||||
/* Radica - Sensible Soccer Plus edition (use bankswitching) */
|
||||
sram.on = 1;
|
||||
sram.start = 0x200001;
|
||||
sram.end = 0x203fff;
|
||||
}
|
||||
else if ((strstr(rominfo.ROMType,"SF") != NULL) && (strstr(rominfo.product,"001") != NULL))
|
||||
{
|
||||
/* SF-001 */
|
||||
@@ -214,8 +221,7 @@ unsigned int sram_read_byte(unsigned int address)
|
||||
|
||||
unsigned int sram_read_word(unsigned int address)
|
||||
{
|
||||
address &= 0xfffe;
|
||||
return (sram.sram[address + 1] | (sram.sram[address] << 8));
|
||||
return READ_WORD(sram.sram, address & 0xfffe);
|
||||
}
|
||||
|
||||
void sram_write_byte(unsigned int address, unsigned int data)
|
||||
@@ -225,7 +231,5 @@ void sram_write_byte(unsigned int address, unsigned int data)
|
||||
|
||||
void sram_write_word(unsigned int address, unsigned int data)
|
||||
{
|
||||
address &= 0xfffe;
|
||||
sram.sram[address] = data >> 8;
|
||||
sram.sram[address + 1] = data & 0xff;
|
||||
WRITE_WORD(sram.sram, address & 0xfffe, data);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Backup RAM support
|
||||
*
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -555,11 +555,8 @@ static u32 pm_io(int reg, int write, u32 d)
|
||||
elprintf(EL_SVP, "ssp ROM r [%06x] %04x", CADDR,
|
||||
((unsigned short *)cart.rom)[addr|((mode&0xf)<<16)]);
|
||||
#endif
|
||||
/*if ((signed int)ssp->pmac_read[reg] >> 16 == -1) ssp->pmac_read[reg]++;
|
||||
ssp->pmac_read[reg] += 1<<16;*/
|
||||
if ((signed int)(ssp->pmac[0][reg] & 0xffff) == -1) ssp->pmac[0][reg] += 1<<16;
|
||||
ssp->pmac[0][reg] ++;
|
||||
|
||||
|
||||
d = ((unsigned short *)cart.rom)[addr|((mode&0xf)<<16)];
|
||||
}
|
||||
else if ((mode & 0x47ff) == 0x0018) /* DRAM */
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
/* CD compatible ROM/RAM cartridge */
|
||||
typedef struct
|
||||
{
|
||||
uint8 area[0x840080]; /* cartridge ROM/RAM area (max. 8MB ROM + 64KB backup memory + Pro Action Replay 128KB ROM / 64KB RAM + cartridge infos) */
|
||||
uint8 reserved[0x80]; /* reserved for ROM cartridge infos (see md_cart.h) */
|
||||
uint8 area[0x840000]; /* cartridge ROM/RAM area (max. 8MB ROM + 64KB backup memory + Pro Action Replay 128KB ROM / 64KB RAM) */
|
||||
uint8 boot; /* cartridge boot mode (0x00: boot from CD with ROM/RAM cartridge enabled, 0x40: boot from ROM cartridge with CD enabled) */
|
||||
uint8 id; /* RAM cartridge ID (related to RAM size, 0 if disabled) */
|
||||
uint8 prot; /* RAM cartridge write protection */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus
|
||||
* CD data controller (LC89510 compatible)
|
||||
* CD data controller (LC8951x compatible)
|
||||
*
|
||||
* Copyright (C) 2012-2015 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -51,7 +51,6 @@
|
||||
|
||||
/* CTRL0 register bitmasks */
|
||||
#define BIT_DECEN 0x80
|
||||
#define BIT_E01RQ 0x20
|
||||
#define BIT_AUTORQ 0x10
|
||||
#define BIT_WRRQ 0x04
|
||||
|
||||
@@ -60,7 +59,7 @@
|
||||
#define BIT_FORMRQ 0x04
|
||||
#define BIT_SHDREN 0x01
|
||||
|
||||
/* CTRL2 register bitmask */
|
||||
/* STAT3 register bitmask */
|
||||
#define BIT_VALST 0x80
|
||||
|
||||
/* TODO: figure exact DMA transfer rate */
|
||||
@@ -248,7 +247,7 @@ void cdc_decoder_update(uint32 header)
|
||||
/* data decoding enabled ? */
|
||||
if (cdc.ctrl[0] & BIT_DECEN)
|
||||
{
|
||||
/* update HEAD registers */
|
||||
/* update HEADx registers with current block header */
|
||||
*(uint32 *)(cdc.head[0]) = header;
|
||||
|
||||
/* set !VALST */
|
||||
@@ -285,18 +284,50 @@ void cdc_decoder_update(uint32 header)
|
||||
/* CDC buffer address */
|
||||
offset = cdc.pt.w & 0x3fff;
|
||||
|
||||
/* write CDD block header (4 bytes) */
|
||||
/* write current block header to RAM buffer (4 bytes) */
|
||||
*(uint32 *)(cdc.ram + offset) = header;
|
||||
offset += 4;
|
||||
|
||||
/* write CDD block data (2048 bytes) */
|
||||
cdd_read_data(cdc.ram + 4 + offset);
|
||||
/* check decoded block mode */
|
||||
if (cdc.head[0][3] == 0x01)
|
||||
{
|
||||
/* write Mode 1 user data to RAM buffer (2048 bytes) */
|
||||
cdd_read_data(cdc.ram + offset, NULL);
|
||||
offset += 2048;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* check if CD-ROM Mode 2 decoding is enabled */
|
||||
if (cdc.ctrl[1] & BIT_MODRQ)
|
||||
{
|
||||
/* update HEADx registers with current block sub-header & write Mode 2 user data to RAM buffer (max 2328 bytes) */
|
||||
cdd_read_data(cdc.ram + offset + 8, cdc.head[1]);
|
||||
|
||||
/* write current block sub-header to RAM buffer (4 bytes x 2) */
|
||||
*(uint32 *)(cdc.ram + offset) = *(uint32 *)(cdc.head[1]);
|
||||
*(uint32 *)(cdc.ram + offset + 4) = *(uint32 *)(cdc.head[1]);
|
||||
offset += 2336;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update HEADx registers with current block sub-header & write Mode 2 user data to RAM buffer (max 2328 bytes) */
|
||||
/* NB: when Mode 2 decoding is disabled, sub-header is apparently not written to RAM buffer (required by Wonder Library) */
|
||||
cdd_read_data(cdc.ram + offset, cdc.head[1]);
|
||||
offset += 2328;
|
||||
}
|
||||
|
||||
/* set STAT2 register FORM bit according to sub-header FORM bit when CTRL0 register AUTORQ bit is set */
|
||||
if (cdc.ctrl[0] & BIT_AUTORQ)
|
||||
{
|
||||
cdc.stat[2] = (cdc.ctrl[1] & BIT_MODRQ) | ((cdc.head[1][2] & 0x20) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* take care of buffer overrun */
|
||||
offset = offset + 2048 + 4 - 0x4000;
|
||||
if (offset > 0)
|
||||
if (offset > 0x4000)
|
||||
{
|
||||
/* data should be written at the start of buffer */
|
||||
memcpy(cdc.ram, cdc.ram + 0x4000, offset);
|
||||
memcpy(cdc.ram, cdc.ram + 0x4000, offset - 0x4000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,15 +515,15 @@ void cdc_reg_w(unsigned char data)
|
||||
/* set CRCOK bit only if decoding is enabled */
|
||||
cdc.stat[0] = data & BIT_DECEN;
|
||||
|
||||
/* update decoding mode */
|
||||
/* update STAT2 register */
|
||||
if (data & BIT_AUTORQ)
|
||||
{
|
||||
/* set MODE bit according to CTRL1 register & clear FORM bit */
|
||||
cdc.stat[2] = cdc.ctrl[1] & BIT_MODRQ;
|
||||
/* set MODE bit according to CTRL1 register MODRQ bit & set FORM bit according to sub-header FORM bit*/
|
||||
cdc.stat[2] = (cdc.ctrl[1] & BIT_MODRQ) | ((cdc.head[1][2] & 0x20) >> 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set MODE & FORM bits according to CTRL1 register */
|
||||
/* set MODE & FORM bits according to CTRL1 register MODRQ & FORMRQ bits */
|
||||
cdc.stat[2] = cdc.ctrl[1] & (BIT_MODRQ | BIT_FORMRQ);
|
||||
}
|
||||
|
||||
@@ -503,15 +534,15 @@ void cdc_reg_w(unsigned char data)
|
||||
|
||||
case 0x0b: /* CTRL1 */
|
||||
{
|
||||
/* update decoding mode */
|
||||
/* update STAT2 register */
|
||||
if (cdc.ctrl[0] & BIT_AUTORQ)
|
||||
{
|
||||
/* set MODE bit according to CTRL1 register & clear FORM bit */
|
||||
cdc.stat[2] = data & BIT_MODRQ;
|
||||
/* set MODE bit according to CTRL1 register MODRQ bit & set FORM bit according to sub-header FORM bit*/
|
||||
cdc.stat[2] = (data & BIT_MODRQ) | ((cdc.head[1][2] & 0x20) >> 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set MODE & FORM bits according to CTRL1 register */
|
||||
/* set MODE & FORM bits according to CTRL1 register MODRQ & FORMRQ bits */
|
||||
cdc.stat[2] = data & (BIT_MODRQ | BIT_FORMRQ);
|
||||
}
|
||||
|
||||
@@ -612,7 +643,7 @@ unsigned char cdc_reg_r(void)
|
||||
|
||||
/* clear pending decoder interrupt */
|
||||
cdc.ifstat |= BIT_DECI;
|
||||
|
||||
|
||||
#if 0
|
||||
/* no pending data transfer end interrupt */
|
||||
if ((cdc.ifstat | BIT_DTEI) || !(cdc.ifctrl & BIT_DTEIEN))
|
||||
@@ -639,13 +670,8 @@ unsigned short cdc_host_r(void)
|
||||
/* check if data is available */
|
||||
if (scd.regs[0x04>>1].byte.h & 0x40)
|
||||
{
|
||||
/* read data word from CDC RAM buffer */
|
||||
uint16 data = *(uint16 *)(cdc.ram + (cdc.dac.w & 0x3ffe));
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* source data is stored in big endian format */
|
||||
data = ((data >> 8) | (data << 8)) & 0xffff;
|
||||
#endif
|
||||
/* read 16-bit word from CDC RAM buffer (big-endian format) */
|
||||
uint16 data = READ_WORD(cdc.ram, cdc.dac.w & 0x3ffe);
|
||||
|
||||
#ifdef LOG_CDC
|
||||
error("CDC host read 0x%04x -> 0x%04x (dbc=0x%x) (%X)\n", cdc.dac.w, data, cdc.dbc.w, s68k.pc);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus
|
||||
* CD data controller (LC89510 compatible)
|
||||
* CD data controller (LC8951x compatible)
|
||||
*
|
||||
* Copyright (C) 2012-2015 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
+222
-196
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* CD drive processor & CD-DA fader
|
||||
*
|
||||
* Copyright (C) 2012-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -47,7 +47,9 @@
|
||||
#define CD_SCAN_SPEED 30
|
||||
|
||||
/* CD tracks type (CD-DA by default) */
|
||||
#define TYPE_CDROM 0x01
|
||||
#define TYPE_AUDIO 0x00
|
||||
#define TYPE_MODE1 0x01
|
||||
#define TYPE_MODE2 0x02
|
||||
|
||||
/* BCD conversion lookup tables */
|
||||
static const uint8 lut_BCD_8[100] =
|
||||
@@ -122,14 +124,8 @@ static const uint32 toc_ffightj[29] =
|
||||
14553, 9834, 10542, 1699, 1792, 1781, 3783, 3052
|
||||
};
|
||||
|
||||
/* supported WAVE file header (16-bit stereo samples @44.1kHz) */
|
||||
static const unsigned char waveHeader[28] =
|
||||
{
|
||||
0x57,0x41,0x56,0x45,0x66,0x6d,0x74,0x20,0x10,0x00,0x00,0x00,0x01,0x00,
|
||||
0x02,0x00,0x44,0xac,0x00,0x00,0x10,0xb1,0x02,0x00,0x04,0x00,0x10,0x00
|
||||
};
|
||||
|
||||
/* supported WAVE file extensions */
|
||||
/* supported audio file extensions */
|
||||
static const char extensions[SUPPORTED_EXT][16] =
|
||||
{
|
||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||
@@ -198,23 +194,20 @@ void cdd_init(int samplerate)
|
||||
|
||||
void cdd_reset(void)
|
||||
{
|
||||
/* reset cycle counter */
|
||||
cdd.cycles = 0;
|
||||
|
||||
/* reset drive access latency */
|
||||
cdd.latency = 0;
|
||||
|
||||
|
||||
/* reset track index */
|
||||
cdd.index = 0;
|
||||
|
||||
|
||||
/* reset logical block address */
|
||||
cdd.lba = 0;
|
||||
|
||||
/* reset status */
|
||||
cdd.status = cdd.loaded ? CD_STOP : NO_DISC;
|
||||
cdd.status = cdd.loaded ? CD_TOC : NO_DISC;
|
||||
|
||||
/* reset CD-DA fader (full volume) */
|
||||
cdd.volume = 0x400;
|
||||
cdd.fader[0] = cdd.fader[1] = 0x400;
|
||||
|
||||
/* clear CD-DA output */
|
||||
cdd.audio[0] = cdd.audio[1] = 0;
|
||||
@@ -229,7 +222,7 @@ int cdd_context_save(uint8 *state)
|
||||
save_param(&cdd.index, sizeof(cdd.index));
|
||||
save_param(&cdd.lba, sizeof(cdd.lba));
|
||||
save_param(&cdd.scanOffset, sizeof(cdd.scanOffset));
|
||||
save_param(&cdd.volume, sizeof(cdd.volume));
|
||||
save_param(&cdd.fader, sizeof(cdd.fader));
|
||||
save_param(&cdd.status, sizeof(cdd.status));
|
||||
|
||||
return bufferptr;
|
||||
@@ -255,7 +248,7 @@ int cdd_context_load(uint8 *state)
|
||||
load_param(&cdd.index, sizeof(cdd.index));
|
||||
load_param(&cdd.lba, sizeof(cdd.lba));
|
||||
load_param(&cdd.scanOffset, sizeof(cdd.scanOffset));
|
||||
load_param(&cdd.volume, sizeof(cdd.volume));
|
||||
load_param(&cdd.fader, sizeof(cdd.fader));
|
||||
load_param(&cdd.status, sizeof(cdd.status));
|
||||
|
||||
/* adjust current LBA within track limit */
|
||||
@@ -403,19 +396,31 @@ int cdd_load(char *filename, char *header)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* COOKED format (2048 bytes data blocks) */
|
||||
if (!strcmp(type, "MODE1"))
|
||||
cdd.sectorSize = 2048;
|
||||
|
||||
/* RAW format (2352 bytes data blocks) */
|
||||
else if (!strcmp(type, "MODE1_RAW"))
|
||||
if (!strcmp(type, "MODE1_RAW"))
|
||||
{
|
||||
/* Mode 1 RAW format (2352 bytes data blocks) */
|
||||
cdd.sectorSize = 2352;
|
||||
|
||||
/* unsupported track format */
|
||||
cdd.toc.tracks[0].type = TYPE_MODE1;
|
||||
}
|
||||
else if (!strcmp(type, "MODE1"))
|
||||
{
|
||||
/* Mode 1 COOKED format (2048 bytes data blocks) */
|
||||
cdd.sectorSize = 2048;
|
||||
cdd.toc.tracks[0].type = TYPE_MODE1;
|
||||
}
|
||||
else if (!strcmp(type, "MODE2_RAW"))
|
||||
{
|
||||
/* Mode 2 RAW format (2352 bytes data blocks) */
|
||||
cdd.sectorSize = 2352;
|
||||
cdd.toc.tracks[0].type = TYPE_MODE2;
|
||||
}
|
||||
else if (strcmp(type, "AUDIO"))
|
||||
{
|
||||
/* unsupported track format */
|
||||
break;
|
||||
|
||||
/* Data track start LBA (2s pause assumed by default) */
|
||||
}
|
||||
|
||||
/* First track start LBA (2s pause assumed by default) */
|
||||
cdd.toc.tracks[0].start = 0;
|
||||
}
|
||||
|
||||
@@ -451,9 +456,6 @@ int cdd_load(char *filename, char *header)
|
||||
|
||||
/* copy CD image header + security code (skip RAW sector 16-byte header) */
|
||||
memcpy(header, cdd.chd.hunk + (cdd.toc.tracks[0].offset % cdd.chd.hunkbytes) + ((cdd.sectorSize == 2048) ? 0 : 16), 0x210);
|
||||
|
||||
/* there is a valid DATA track */
|
||||
cdd.toc.tracks[0].type = TYPE_CDROM;
|
||||
}
|
||||
|
||||
/* valid CD image ? */
|
||||
@@ -482,40 +484,43 @@ int cdd_load(char *filename, char *header)
|
||||
{
|
||||
int len;
|
||||
|
||||
static const uint8 sync[12] = {0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00};
|
||||
|
||||
/* read first 16 bytes */
|
||||
cdStreamRead(header, 0x10, 1, fd);
|
||||
|
||||
/* look for valid CD image identifier */
|
||||
/* auto-detect valid Sega CD image */
|
||||
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
||||
{
|
||||
/* COOKED format (2048 bytes data blocks) */
|
||||
cdd.sectorSize = 2048;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* read next 16 bytes */
|
||||
cdStreamRead(header, 0x10, 1, fd);
|
||||
|
||||
/* look for valid CD image identifier */
|
||||
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
||||
{
|
||||
/* RAW format (2352 bytes data blocks) */
|
||||
cdd.sectorSize = 2352;
|
||||
}
|
||||
}
|
||||
|
||||
/* valid CD image file ? */
|
||||
if (cdd.sectorSize)
|
||||
{
|
||||
/* read CD image header + security code */
|
||||
/* COOKED CD-ROM image (2048 bytes data blocks) */
|
||||
cdd.sectorSize = 2048;
|
||||
|
||||
/* CD-ROM Mode 1 by default */
|
||||
cdd.toc.tracks[0].type = TYPE_MODE1;
|
||||
}
|
||||
|
||||
/* auto-detect CD-ROM synchro pattern */
|
||||
else if (!memcmp(sync, header, 12))
|
||||
{
|
||||
/* RAW CD-ROM image (2352 bytes data blocks) */
|
||||
cdd.sectorSize = 2352;
|
||||
|
||||
/* auto-detect CD-ROM mode from block header (byte 15) */
|
||||
cdd.toc.tracks[0].type = header[15];
|
||||
|
||||
/* read next 16 bytes (start of user data) */
|
||||
cdStreamRead(header, 0x10, 1, fd);
|
||||
}
|
||||
|
||||
/* supported CD-ROM image file ? */
|
||||
if ((cdd.toc.tracks[0].type == TYPE_MODE1) || (cdd.toc.tracks[0].type == TYPE_MODE2))
|
||||
{
|
||||
/* read Sega CD image header + security code */
|
||||
cdStreamRead(header + 0x10, 0x200, 1, fd);
|
||||
|
||||
/* initialize first track file descriptor */
|
||||
cdd.toc.tracks[0].fd = fd;
|
||||
|
||||
/* this is a valid DATA track */
|
||||
cdd.toc.tracks[0].type = TYPE_CDROM;
|
||||
|
||||
/* DATA track end LBA (based on DATA file length) */
|
||||
cdStreamSeek(fd, 0, SEEK_END);
|
||||
cdd.toc.tracks[0].end = cdStreamTell(fd) / cdd.sectorSize;
|
||||
@@ -536,7 +541,7 @@ int cdd_load(char *filename, char *header)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* this is not a CD image file */
|
||||
/* this is not a supported CD-ROM image file */
|
||||
isCDfile = 0;
|
||||
|
||||
/* close file */
|
||||
@@ -621,26 +626,26 @@ int cdd_load(char *filename, char *header)
|
||||
if (!strstr(lptr,"BINARY") && !strstr(lptr,"MOTOROLA"))
|
||||
{
|
||||
/* read file header */
|
||||
unsigned char head[28];
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, 8, SEEK_SET);
|
||||
cdStreamRead(head, 28, 1, cdd.toc.tracks[cdd.toc.last].fd);
|
||||
unsigned char head[12];
|
||||
cdStreamRead(head, 12, 1, cdd.toc.tracks[cdd.toc.last].fd);
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
||||
|
||||
/* autodetect WAVE file header (44.1KHz 16-bit stereo format only) */
|
||||
if (!memcmp(head, waveHeader, 28))
|
||||
|
||||
/* autodetect WAVE file */
|
||||
if (!memcmp(head, "RIFF", 4) && !memcmp(head + 8, "WAVE", 4))
|
||||
{
|
||||
/* look for 'data' chunk id */
|
||||
int dataOffset = 0;
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, 36, SEEK_SET);
|
||||
while (cdStreamRead(head, 4, 1, cdd.toc.tracks[cdd.toc.last].fd))
|
||||
/* look for 'data' chunk */
|
||||
int chunkSize, dataOffset = 0;
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, 12, SEEK_SET);
|
||||
while (cdStreamRead(head, 8, 1, cdd.toc.tracks[cdd.toc.last].fd))
|
||||
{
|
||||
if (!memcmp(head, "data", 4))
|
||||
{
|
||||
dataOffset = cdStreamTell(cdd.toc.tracks[cdd.toc.last].fd) + 4;
|
||||
dataOffset = cdStreamTell(cdd.toc.tracks[cdd.toc.last].fd);
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
||||
break;
|
||||
}
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, -2, SEEK_CUR);
|
||||
chunkSize = head[4] + (head[5] << 8) + (head[6] << 16) + (head[7] << 24);
|
||||
cdStreamSeek(cdd.toc.tracks[cdd.toc.last].fd, chunkSize, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* check if 'data' chunk has not been found */
|
||||
@@ -682,42 +687,35 @@ int cdd_load(char *filename, char *header)
|
||||
/* decode TRACK commands */
|
||||
else if ((sscanf(lptr, "TRACK %02d %*s", &bb)) || (sscanf(lptr, "TRACK %d %*s", &bb)))
|
||||
{
|
||||
/* check track number */
|
||||
if (bb != (cdd.toc.last + 1))
|
||||
{
|
||||
/* close any opened file */
|
||||
if (cdd.toc.tracks[cdd.toc.last].fd)
|
||||
{
|
||||
cdStreamClose(cdd.toc.tracks[cdd.toc.last].fd);
|
||||
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
||||
}
|
||||
|
||||
/* missing tracks */
|
||||
break;
|
||||
}
|
||||
|
||||
/* autodetect DATA track (first track only) */
|
||||
/* autodetect DATA track type (first track only) */
|
||||
if (!cdd.toc.last)
|
||||
{
|
||||
/* CD-ROM Mode 1 support only */
|
||||
if (strstr(lptr,"MODE1/2048"))
|
||||
{
|
||||
/* COOKED format (2048 bytes / block) */
|
||||
/* Mode 1 COOKED format (2048 bytes / block) */
|
||||
cdd.sectorSize = 2048;
|
||||
cdd.toc.tracks[0].type = TYPE_MODE1;
|
||||
}
|
||||
else if (strstr(lptr,"MODE1/2352"))
|
||||
{
|
||||
/* RAW format (2352 bytes / block) */
|
||||
/* Mode 1 RAW format (2352 bytes / block) */
|
||||
cdd.sectorSize = 2352;
|
||||
|
||||
/* skip 16-byte header */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, 0x10, SEEK_SET);
|
||||
cdd.toc.tracks[0].type = TYPE_MODE1;
|
||||
}
|
||||
else if (strstr(lptr,"MODE2/2352"))
|
||||
{
|
||||
/* Mode 2 RAW format (2352 bytes / block) */
|
||||
cdd.sectorSize = 2352;
|
||||
cdd.toc.tracks[0].type = TYPE_MODE2;
|
||||
}
|
||||
|
||||
if (cdd.sectorSize)
|
||||
{
|
||||
/* this is a valid DATA track */
|
||||
cdd.toc.tracks[0].type = TYPE_CDROM;
|
||||
if (cdd.sectorSize == 2352)
|
||||
{
|
||||
/* skip 16-byte header */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, 0x10, SEEK_SET);
|
||||
}
|
||||
|
||||
/* read CD image header + security code */
|
||||
cdStreamRead(header, 0x210, 1, cdd.toc.tracks[0].fd);
|
||||
@@ -760,16 +758,16 @@ int cdd_load(char *filename, char *header)
|
||||
cdd.toc.tracks[cdd.toc.last].offset += pregap * 2352;
|
||||
|
||||
/* check if a single file is used for consecutive tracks */
|
||||
if (!cdd.toc.tracks[cdd.toc.last].fd)
|
||||
if (!cdd.toc.tracks[cdd.toc.last].fd && cdd.toc.last)
|
||||
{
|
||||
/* use common file descriptor */
|
||||
cdd.toc.tracks[cdd.toc.last].fd = cdd.toc.tracks[0].fd;
|
||||
cdd.toc.tracks[cdd.toc.last].fd = cdd.toc.tracks[cdd.toc.last - 1].fd;
|
||||
|
||||
/* current track start time (based on current file absolute time + PREGAP length) */
|
||||
cdd.toc.tracks[cdd.toc.last].start = bb + ss*75 + mm*60*75 + pregap;
|
||||
|
||||
/* check if previous track end time needs to be set */
|
||||
if (cdd.toc.last && !cdd.toc.tracks[cdd.toc.last - 1].end)
|
||||
if (!cdd.toc.tracks[cdd.toc.last - 1].end)
|
||||
{
|
||||
/* set previous track end time (based on current track start time, ignoring any "PREGAP"-type pause if no INDEX00) */
|
||||
cdd.toc.tracks[cdd.toc.last - 1].end = cdd.toc.tracks[cdd.toc.last].start;
|
||||
@@ -866,7 +864,7 @@ int cdd_load(char *filename, char *header)
|
||||
/* close CUE file */
|
||||
cdStreamClose(fd);
|
||||
}
|
||||
else
|
||||
else if (cdd.toc.last)
|
||||
{
|
||||
int i, offset = 1;
|
||||
|
||||
@@ -893,26 +891,27 @@ int cdd_load(char *filename, char *header)
|
||||
/* repeat until no more valid track files can be found */
|
||||
while (fd)
|
||||
{
|
||||
/* read file HEADER */
|
||||
unsigned char head[28];
|
||||
cdStreamSeek(fd, 8, SEEK_SET);
|
||||
cdStreamRead(head, 28, 1, fd);
|
||||
/* read file header */
|
||||
unsigned char head[12];
|
||||
cdStreamRead(head, 12, 1, fd);
|
||||
cdStreamSeek(fd, 0, SEEK_SET);
|
||||
|
||||
/* check if this is a valid WAVE file (44.1KHz 16-bit stereo format only) */
|
||||
if (!memcmp(head, waveHeader, 28))
|
||||
|
||||
/* autodetect WAVE file */
|
||||
if (!memcmp(head, "RIFF", 4) && !memcmp(head + 8, "WAVE", 4))
|
||||
{
|
||||
/* look for 'data' chunk id */
|
||||
int dataOffset = 0;
|
||||
cdStreamSeek(fd, 36, SEEK_SET);
|
||||
while (cdStreamRead(head, 4, 1, fd))
|
||||
/* look for 'data' chunk */
|
||||
int chunkSize, dataOffset = 0;
|
||||
cdStreamSeek(fd, 12, SEEK_SET);
|
||||
while (cdStreamRead(head, 8, 1, fd))
|
||||
{
|
||||
if (!memcmp(head, "data", 4))
|
||||
{
|
||||
dataOffset = cdStreamTell(fd) + 4;
|
||||
dataOffset = cdStreamTell(fd);
|
||||
cdStreamSeek(fd, 0, SEEK_SET);
|
||||
break;
|
||||
}
|
||||
cdStreamSeek(fd, -2, SEEK_CUR);
|
||||
chunkSize = head[4] + (head[5] << 8) + (head[6] << 16) + (head[7] << 24);
|
||||
cdStreamSeek(fd, chunkSize, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* check if 'data' chunk has not been found */
|
||||
@@ -1036,19 +1035,9 @@ int cdd_load(char *filename, char *header)
|
||||
sprintf(ptr, extensions[i], cdd.toc.last + offset);
|
||||
fd = cdStreamOpen(fname);
|
||||
}
|
||||
}
|
||||
|
||||
/* CD tracks found ? */
|
||||
if (cdd.toc.last)
|
||||
{
|
||||
/* Lead-out */
|
||||
cdd.toc.tracks[cdd.toc.last].start = cdd.toc.end;
|
||||
|
||||
/* CD mounted */
|
||||
cdd.loaded = 1;
|
||||
|
||||
/* Valid DATA track found ? */
|
||||
if (cdd.toc.tracks[0].type)
|
||||
/* Valid CD-ROM Mode 1 track found ? */
|
||||
if (cdd.toc.tracks[0].type == TYPE_MODE1)
|
||||
{
|
||||
/* simulate audio tracks if none found */
|
||||
if (cdd.toc.last == 1)
|
||||
@@ -1132,6 +1121,11 @@ int cdd_load(char *filename, char *header)
|
||||
}
|
||||
while (cdd.toc.last < 29);
|
||||
}
|
||||
else if (strstr(header + 0x180,"T-06201-01") != NULL)
|
||||
{
|
||||
/* Sewer Shark (USA) (REV1) */
|
||||
/* no audio track */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* default TOC (99 tracks & 2s per audio tracks) */
|
||||
@@ -1147,8 +1141,19 @@ int cdd_load(char *filename, char *header)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* CD tracks found ? */
|
||||
if (cdd.toc.last)
|
||||
{
|
||||
/* Lead-out */
|
||||
cdd.toc.tracks[cdd.toc.last].start = cdd.toc.end;
|
||||
|
||||
/* CD mounted */
|
||||
cdd.loaded = 1;
|
||||
|
||||
/* Automatically try to open associated subcode data file */
|
||||
strncpy(&fname[strlen(fname) - 4], ".sub", 4);
|
||||
memcpy(&fname[strlen(fname) - 4], ".sub", 4);
|
||||
cdd.toc.sub = cdStreamOpen(fname);
|
||||
|
||||
/* return 1 if loaded file is CD image file */
|
||||
@@ -1218,7 +1223,7 @@ void cdd_unload(void)
|
||||
cdd.sectorSize = 0;
|
||||
}
|
||||
|
||||
void cdd_read_data(uint8 *dst)
|
||||
void cdd_read_data(uint8 *dst, uint8 *subheader)
|
||||
{
|
||||
/* only allow reading (first) CD-ROM track sectors */
|
||||
if (cdd.toc.tracks[cdd.index].type && (cdd.lba >= 0))
|
||||
@@ -1239,36 +1244,60 @@ void cdd_read_data(uint8 *dst)
|
||||
cdd.chd.hunknum = hunknum;
|
||||
}
|
||||
|
||||
/* copy Mode 1 sector data (2048 bytes only) */
|
||||
/* check sector size */
|
||||
if (cdd.sectorSize == 2048)
|
||||
{
|
||||
/* Mode 1 COOKED data (ISO) */
|
||||
/* read Mode 1 user data (2048 bytes) */
|
||||
memcpy(dst, cdd.chd.hunk + (offset % cdd.chd.hunkbytes), 2048);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mode 1 RAW data (skip 16-byte header) */
|
||||
memcpy(dst, cdd.chd.hunk + (offset % cdd.chd.hunkbytes) + 16, 2048);
|
||||
/* check if sub-header is required (Mode 2 sector only) */
|
||||
if (!subheader)
|
||||
{
|
||||
/* read Mode 1 user data (2048 bytes), skipping block sync pattern (12 bytes) + block header (4 bytes)*/
|
||||
memcpy(dst, cdd.chd.hunk + (offset % cdd.chd.hunkbytes) + 12 + 4, 2048);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* read Mode 2 sub-header (first 4 bytes), skipping block sync pattern (12 bytes) + block header (4 bytes)*/
|
||||
memcpy(subheader, cdd.chd.hunk + (offset % cdd.chd.hunkbytes) + 12 + 4, 4);
|
||||
|
||||
/* read Mode 2 user data (max 2328 bytes), skipping Mode 2 sub-header (8 bytes) */
|
||||
memcpy(dst, cdd.chd.hunk + (offset % cdd.chd.hunkbytes) + 12 + 4 + 8, 2328);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* seek current track sector */
|
||||
/* check sector size */
|
||||
if (cdd.sectorSize == 2048)
|
||||
{
|
||||
/* Mode 1 COOKED data (ISO) */
|
||||
/* read Mode 1 user data (2048 bytes) */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, cdd.lba * 2048, SEEK_SET);
|
||||
cdStreamRead(dst, 2048, 1, cdd.toc.tracks[0].fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mode 1 RAW data (skip 16-byte header) */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, cdd.lba * 2352 + 16, SEEK_SET);
|
||||
}
|
||||
/* check if sub-header is required (Mode 2 sector only) */
|
||||
if (!subheader)
|
||||
{
|
||||
/* skip block sync pattern (12 bytes) + block header (4 bytes) then read Mode 1 user data (2048 bytes) */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, (cdd.lba * 2352) + 12 + 4, SEEK_SET);
|
||||
cdStreamRead(dst, 2048, 1, cdd.toc.tracks[0].fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* skip block sync pattern (12 bytes) + block header (4 bytes) + Mode 2 sub-header (first 4 bytes) then read Mode 2 sub-header (last 4 bytes) */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, (cdd.lba * 2352) + 12 + 4 + 4, SEEK_SET);
|
||||
cdStreamRead(subheader, 4, 1, cdd.toc.tracks[0].fd);
|
||||
|
||||
/* read Mode 1 sector data (2048 bytes only) */
|
||||
cdStreamRead(dst, 2048, 1, cdd.toc.tracks[0].fd);
|
||||
/* read Mode 2 user data (max 2328 bytes) */
|
||||
cdStreamRead(dst, 2328, 1, cdd.toc.tracks[0].fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1287,10 +1316,10 @@ void cdd_read_audio(unsigned int samples)
|
||||
int i, mul, l, r;
|
||||
|
||||
/* current CD-DA fader volume */
|
||||
int curVol = cdd.volume;
|
||||
int curVol = cdd.fader[0];
|
||||
|
||||
/* CD-DA fader volume setup (0-1024) */
|
||||
int endVol = scd.regs[0x34>>1].w >> 4;
|
||||
int endVol = cdd.fader[1];
|
||||
|
||||
/* read samples from current block */
|
||||
#if defined(USE_LIBCHDR)
|
||||
@@ -1476,7 +1505,7 @@ void cdd_read_audio(unsigned int samples)
|
||||
}
|
||||
|
||||
/* save current CD-DA fader volume */
|
||||
cdd.volume = curVol;
|
||||
cdd.fader[0] = curVol;
|
||||
|
||||
/* save last audio output for next frame */
|
||||
cdd.audio[0] = prev_l;
|
||||
@@ -1548,30 +1577,16 @@ void cdd_update(void)
|
||||
error("LBA = %d (track %d)(latency=%d)\n", cdd.lba, cdd.index, cdd.latency);
|
||||
#endif
|
||||
|
||||
/* seeking disc */
|
||||
if (cdd.status == CD_SEEK)
|
||||
/* drive latency */
|
||||
if (cdd.latency > 0)
|
||||
{
|
||||
/* drive latency */
|
||||
if (cdd.latency > 0)
|
||||
{
|
||||
cdd.latency--;
|
||||
return;
|
||||
}
|
||||
|
||||
/* drive is ready */
|
||||
cdd.status = CD_PAUSE;
|
||||
cdd.latency--;
|
||||
return;
|
||||
}
|
||||
|
||||
/* reading disc */
|
||||
else if (cdd.status == CD_PLAY)
|
||||
if (cdd.status == CD_PLAY)
|
||||
{
|
||||
/* drive latency */
|
||||
if (cdd.latency > 0)
|
||||
{
|
||||
cdd.latency--;
|
||||
return;
|
||||
}
|
||||
|
||||
/* end of disc detection */
|
||||
if (cdd.index >= cdd.toc.last)
|
||||
{
|
||||
@@ -1588,13 +1603,13 @@ void cdd_update(void)
|
||||
/* track type */
|
||||
if (cdd.toc.tracks[cdd.index].type)
|
||||
{
|
||||
/* CD-ROM (Mode 1) sector header */
|
||||
/* CD-ROM sector header */
|
||||
uint8 header[4];
|
||||
uint32 msf = cdd.lba + 150;
|
||||
header[0] = lut_BCD_8[(msf / 75) / 60];
|
||||
header[1] = lut_BCD_8[(msf / 75) % 60];
|
||||
header[2] = lut_BCD_8[(msf % 75)];
|
||||
header[3] = 0x01;
|
||||
header[3] = cdd.toc.tracks[cdd.index].type;
|
||||
|
||||
/* decode CD-ROM track sector */
|
||||
cdc_decoder_update(*(uint32 *)(header));
|
||||
@@ -1728,7 +1743,7 @@ void cdd_update(void)
|
||||
}
|
||||
|
||||
/* AUDIO track playing ? */
|
||||
scd.regs[0x36>>1].byte.h = cdd.toc.tracks[cdd.index].type;
|
||||
scd.regs[0x36>>1].byte.h = cdd.toc.tracks[cdd.index].type ? 0x01 : 0x00;
|
||||
|
||||
/* seek to current subcode position */
|
||||
if (cdd.toc.sub)
|
||||
@@ -1778,18 +1793,20 @@ void cdd_process(void)
|
||||
/* Process CDD command */
|
||||
switch (scd.regs[0x42>>1].byte.h & 0x0f)
|
||||
{
|
||||
case 0x00: /* Drive Status */
|
||||
case 0x00: /* Get Drive Status */
|
||||
{
|
||||
/* RS1-RS8 normally unchanged */
|
||||
scd.regs[0x38>>1].byte.h = cdd.status;
|
||||
|
||||
/* unless RS1 indicated invalid track infos */
|
||||
if (scd.regs[0x38>>1].byte.l == 0x0f)
|
||||
/* RS0-RS8 are normally unchanged unless reported drive status needs to be updated (i.e previous drive command has been processed) */
|
||||
/* Note: this function is called one 75hz frame ahead of CDD update so latency counter is always one step ahead of upcoming status */
|
||||
/* Radical Rex and Annet Futatabi both need at least respectively 2 and 3 interrupts with 'playing' status returned before sectors start getting incremented */
|
||||
if (cdd.latency <= 3)
|
||||
{
|
||||
/* and drive is now ready */
|
||||
if (!cdd.latency)
|
||||
/* update reported drive status */
|
||||
scd.regs[0x38>>1].byte.h = cdd.status;
|
||||
|
||||
/* check if RS1 indicated invalid track infos (during seeking) */
|
||||
if (scd.regs[0x38>>1].byte.l == 0x0f)
|
||||
{
|
||||
/* then return valid track infos, e.g current track number in RS2-RS3 (fixes Lunar - The Silver Star) */
|
||||
/* seeking has ended so we return valid track infos, e.g current track number in RS2-RS3 (fixes Lunar - The Silver Star) */
|
||||
scd.regs[0x38>>1].byte.l = 0x02;
|
||||
scd.regs[0x3a>>1].w = (cdd.index < cdd.toc.last) ? lut_BCD_16[cdd.index + 1] : 0x0A0A;
|
||||
}
|
||||
@@ -1800,21 +1817,21 @@ void cdd_process(void)
|
||||
case 0x01: /* Stop Drive */
|
||||
{
|
||||
/* update status */
|
||||
cdd.status = cdd.loaded ? CD_STOP : NO_DISC;
|
||||
cdd.status = cdd.loaded ? CD_TOC : NO_DISC;
|
||||
|
||||
/* no audio track playing */
|
||||
scd.regs[0x36>>1].byte.h = 0x01;
|
||||
|
||||
/* RS1-RS8 ignored, expects 0x0 (drive busy ?) in RS0 once */
|
||||
scd.regs[0x38>>1].w = CD_BUSY << 8;
|
||||
/* RS1-RS8 ignored, expects 0x0 (CD_STOP) in RS0 once */
|
||||
scd.regs[0x38>>1].w = CD_STOP << 8;
|
||||
scd.regs[0x3a>>1].w = 0x0000;
|
||||
scd.regs[0x3c>>1].w = 0x0000;
|
||||
scd.regs[0x3e>>1].w = 0x0000;
|
||||
scd.regs[0x40>>1].w = ~CD_BUSY & 0x0f;
|
||||
scd.regs[0x40>>1].w = ~CD_STOP & 0x0f;
|
||||
return;
|
||||
}
|
||||
|
||||
case 0x02: /* Read TOC */
|
||||
case 0x02: /* Report TOC infos */
|
||||
{
|
||||
/* Infos automatically retrieved by CDD processor from Q-Channel */
|
||||
/* commands 0x00-0x02 (current block) and 0x03-0x05 (Lead-In) */
|
||||
@@ -1827,7 +1844,7 @@ void cdd_process(void)
|
||||
scd.regs[0x3a>>1].w = lut_BCD_16[(lba/75)/60];
|
||||
scd.regs[0x3c>>1].w = lut_BCD_16[(lba/75)%60];
|
||||
scd.regs[0x3e>>1].w = lut_BCD_16[(lba%75)];
|
||||
scd.regs[0x40>>1].byte.h = cdd.toc.tracks[cdd.index].type << 2; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */
|
||||
scd.regs[0x40>>1].byte.h = cdd.toc.tracks[cdd.index].type ? 0x04 : 0x00; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1838,7 +1855,7 @@ void cdd_process(void)
|
||||
scd.regs[0x3a>>1].w = lut_BCD_16[(lba/75)/60];
|
||||
scd.regs[0x3c>>1].w = lut_BCD_16[(lba/75)%60];
|
||||
scd.regs[0x3e>>1].w = lut_BCD_16[(lba%75)];
|
||||
scd.regs[0x40>>1].byte.h = cdd.toc.tracks[cdd.index].type << 2; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */
|
||||
scd.regs[0x40>>1].byte.h = cdd.toc.tracks[cdd.index].type ? 0x04 : 0x00; /* Current block flags in RS8 (bit0 = mute status, bit1: pre-emphasis status, bit2: track type) */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1881,15 +1898,25 @@ void cdd_process(void)
|
||||
scd.regs[0x3a>>1].w = lut_BCD_16[(lba/75)/60];
|
||||
scd.regs[0x3c>>1].w = lut_BCD_16[(lba/75)%60];
|
||||
scd.regs[0x3e>>1].w = lut_BCD_16[(lba%75)];
|
||||
scd.regs[0x3e>>1].byte.h |= (cdd.toc.tracks[track-1].type << 3); /* RS6 bit 3 is set for CD-ROM track */
|
||||
scd.regs[0x3e>>1].byte.h |= cdd.toc.tracks[track-1].type ? 0x08 : 0x00; /* RS6 bit 3 is set for CD-ROM track */
|
||||
scd.regs[0x40>>1].byte.h = track % 10; /* Track Number (low digit) */
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x06: /* Latest Error Information */
|
||||
{
|
||||
scd.regs[0x38>>1].w = (cdd.status << 8) | 0x06;
|
||||
scd.regs[0x3a>>1].w = 0x0000; /* no error */
|
||||
scd.regs[0x3c>>1].w = 0x0000;
|
||||
scd.regs[0x3e>>1].w = 0x0000;
|
||||
scd.regs[0x40>>1].byte.h = 0x00;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
#ifdef LOG_ERROR
|
||||
error("Unknown CDD Command %02X (%X)\n", scd.regs[0x44>>1].byte.l, s68k.pc);
|
||||
error("Invalid CDD request code %02X (%X)\n", scd.regs[0x44>>1].byte.l, s68k.pc);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@@ -1911,10 +1938,9 @@ void cdd_process(void)
|
||||
if (!cdd.latency)
|
||||
{
|
||||
/* Fixes a few games hanging because they expect data to be read with some delay */
|
||||
/* Radical Rex needs at least one interrupt delay */
|
||||
/* Wolf Team games (Anet Futatabi, Cobra Command, Earnest Evans, Road Avenger & Time Gal) need at least 10 interrupts delay */
|
||||
/* Space Adventure Cobra (2nd morgue scene) needs at least 13 interrupts delay (incl. seek time, so 10 is OK) */
|
||||
cdd.latency = 10;
|
||||
/* Wolf Team games (Annet Futatabi, Aisle Lord, Cobra Command, Earnest Evans, Road Avenger & Time Gal) need at least 11 interrupts delay */
|
||||
/* Space Adventure Cobra (2nd morgue scene) needs at least 13 interrupts delay (incl. seek time, so 11 is OK) */
|
||||
cdd.latency = 11;
|
||||
}
|
||||
|
||||
/* CD drive seek time */
|
||||
@@ -1971,14 +1997,14 @@ void cdd_process(void)
|
||||
if (cdd.chd.file)
|
||||
{
|
||||
/* CHD file offset */
|
||||
cdd.chd.hunkofs = cdd.toc.tracks[cdd.index].offset + (lba * CD_FRAME_SIZE);
|
||||
cdd.chd.hunkofs = cdd.toc.tracks[index].offset + (lba * CD_FRAME_SIZE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (cdd.toc.tracks[index].type)
|
||||
{
|
||||
/* DATA track */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||
cdStreamSeek(cdd.toc.tracks[index].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||
}
|
||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||
else if (cdd.toc.tracks[index].vf.seekable)
|
||||
@@ -2002,15 +2028,16 @@ void cdd_process(void)
|
||||
/* no audio track playing (yet) */
|
||||
scd.regs[0x36>>1].byte.h = 0x01;
|
||||
|
||||
/* update status */
|
||||
/* update status (reported to host once seeking has ended) */
|
||||
cdd.status = CD_PLAY;
|
||||
|
||||
/* RS0 should indicates seeking until drive is ready (fixes audio delay in Bari Arm) */
|
||||
/* RS1=0xf to invalidate track infos in RS2-RS8 until drive is ready (fixes Snatcher Act 2 start cutscene) */
|
||||
scd.regs[0x38>>1].w = (CD_PLAY << 8) | 0x0f;
|
||||
scd.regs[0x38>>1].w = (CD_SEEK << 8) | 0x0f;
|
||||
scd.regs[0x3a>>1].w = 0x0000;
|
||||
scd.regs[0x3c>>1].w = 0x0000;
|
||||
scd.regs[0x3e>>1].w = 0x0000;
|
||||
scd.regs[0x40>>1].w = ~(CD_PLAY + 0xf) & 0x0f;
|
||||
scd.regs[0x40>>1].w = ~(CD_SEEK + 0xf) & 0x0f;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2077,14 +2104,14 @@ void cdd_process(void)
|
||||
if (cdd.chd.file)
|
||||
{
|
||||
/* CHD file offset */
|
||||
cdd.chd.hunkofs = cdd.toc.tracks[cdd.index].offset + (lba * CD_FRAME_SIZE);
|
||||
cdd.chd.hunkofs = cdd.toc.tracks[index].offset + (lba * CD_FRAME_SIZE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (cdd.toc.tracks[index].type)
|
||||
{
|
||||
/* DATA track */
|
||||
cdStreamSeek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||
cdStreamSeek(cdd.toc.tracks[index].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||
}
|
||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||
else if (cdd.toc.tracks[index].vf.seekable)
|
||||
@@ -2108,8 +2135,8 @@ void cdd_process(void)
|
||||
/* no audio track playing */
|
||||
scd.regs[0x36>>1].byte.h = 0x01;
|
||||
|
||||
/* update status */
|
||||
cdd.status = CD_SEEK;
|
||||
/* update status (reported to host once seeking has ended) */
|
||||
cdd.status = CD_PAUSE;
|
||||
|
||||
/* RS1=0xf to invalidate track infos in RS2-RS8 while seeking (fixes Final Fight CD intro when seek time is emulated) */
|
||||
scd.regs[0x38>>1].w = (CD_SEEK << 8) | 0x0f;
|
||||
@@ -2157,7 +2184,6 @@ void cdd_process(void)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 0x0a: /* N-Track Jump Control ? (usually sent before CD_SEEK or CD_PLAY commands) */
|
||||
{
|
||||
/* TC3 corresponds to seek direction (00=forward, FF=reverse) */
|
||||
@@ -2179,14 +2205,14 @@ void cdd_process(void)
|
||||
scd.regs[0x36>>1].byte.h = 0x01;
|
||||
|
||||
/* update status */
|
||||
cdd.status = cdd.loaded ? CD_STOP : NO_DISC;
|
||||
cdd.status = cdd.loaded ? CD_TOC : NO_DISC;
|
||||
|
||||
/* RS1-RS8 ignored, expects 0x0 (drive busy ?) in RS0 once */
|
||||
scd.regs[0x38>>1].w = CD_BUSY << 8;
|
||||
/* RS1-RS8 ignored, expects CD_STOP in RS0 once */
|
||||
scd.regs[0x38>>1].w = CD_STOP << 8;
|
||||
scd.regs[0x3a>>1].w = 0x0000;
|
||||
scd.regs[0x3c>>1].w = 0x0000;
|
||||
scd.regs[0x3e>>1].w = 0x0000;
|
||||
scd.regs[0x40>>1].w = ~CD_BUSY & 0x0f;
|
||||
scd.regs[0x40>>1].w = ~CD_STOP & 0x0f;
|
||||
|
||||
#ifdef CD_TRAY_CALLBACK
|
||||
CD_TRAY_CALLBACK
|
||||
@@ -2214,8 +2240,8 @@ void cdd_process(void)
|
||||
}
|
||||
|
||||
default: /* Unknown command */
|
||||
#ifdef LOG_CDD
|
||||
error("Unknown CDD Command !!!\n");
|
||||
#ifdef LOG_ERROR
|
||||
error("Unsupported CDD command %02X (%X)\n", scd.regs[0x42>>1].byte.h & 0x0f, s68k.pc);
|
||||
#endif
|
||||
scd.regs[0x38>>1].byte.h = cdd.status;
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* CD drive processor & CD-DA fader
|
||||
*
|
||||
* Copyright (C) 2012-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -54,15 +54,26 @@
|
||||
#define cdd scd.cdd_hw
|
||||
|
||||
/* CDD status */
|
||||
#define CD_BUSY 0x00
|
||||
#define CD_PLAY 0x01
|
||||
#define CD_SEEK 0x02
|
||||
#define CD_SCAN 0x03
|
||||
#define CD_PAUSE 0x04
|
||||
#define CD_OPEN 0x05
|
||||
#define CD_STOP 0x09
|
||||
#define NO_DISC 0x0B
|
||||
#define CD_END 0x0C
|
||||
#define CD_STOP 0x00
|
||||
#define CD_PLAY 0x01
|
||||
#define CD_SEEK 0x02
|
||||
#define CD_SCAN 0x03
|
||||
#define CD_PAUSE 0x04
|
||||
#define CD_OPEN 0x05
|
||||
#define NO_VALID_CHK 0x06 /* unused */
|
||||
#define NO_VALID_CMD 0x07 /* unused */
|
||||
#define CD_ERROR 0x08 /* unused */
|
||||
#define CD_TOC 0x09
|
||||
#define CD_TRACK_MOVE 0x0A /* unused */
|
||||
#define NO_DISC 0x0B
|
||||
#define CD_END 0x0C
|
||||
#define CD_TRAY 0x0E /* unused */
|
||||
#define CD_TEST 0x0F /* unusec */
|
||||
|
||||
/* CD-DA digital filter types */
|
||||
#define CD_TYPE_DEFAULT 0x00
|
||||
#define CD_TYPE_WONDERMEGA 0x01
|
||||
#define CD_TYPE_WONDERMEGA_M2 0x02
|
||||
|
||||
/* CD track */
|
||||
typedef struct
|
||||
@@ -103,11 +114,12 @@ typedef struct
|
||||
{
|
||||
uint32 cycles;
|
||||
uint32 latency;
|
||||
int type;
|
||||
int loaded;
|
||||
int index;
|
||||
int lba;
|
||||
int scanOffset;
|
||||
int volume;
|
||||
uint16 fader[2];
|
||||
uint8 status;
|
||||
uint16 sectorSize;
|
||||
toc_t toc;
|
||||
@@ -124,7 +136,7 @@ extern int cdd_context_save(uint8 *state);
|
||||
extern int cdd_context_load(uint8 *state);
|
||||
extern int cdd_load(char *filename, char *header);
|
||||
extern void cdd_unload(void);
|
||||
extern void cdd_read_data(uint8 *dst);
|
||||
extern void cdd_read_data(uint8 *dst, uint8 *subheader);
|
||||
extern void cdd_read_audio(unsigned int samples);
|
||||
extern void cdd_update(void);
|
||||
extern void cdd_process(void);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* CD graphics processor
|
||||
*
|
||||
* Copyright (C) 2012 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -47,10 +47,10 @@ void word_ram_0_dma_w(unsigned int words)
|
||||
|
||||
/* CDC buffer source address */
|
||||
uint16 src_index = cdc.dac.w & 0x3ffe;
|
||||
|
||||
|
||||
/* WORD-RAM destination address*/
|
||||
uint32 dst_index = (scd.regs[0x0a>>1].w << 3) & 0x1fffe;
|
||||
|
||||
|
||||
/* update DMA destination address */
|
||||
scd.regs[0x0a>>1].w += (words >> 2);
|
||||
|
||||
@@ -60,13 +60,8 @@ void word_ram_0_dma_w(unsigned int words)
|
||||
/* DMA transfer */
|
||||
while (words--)
|
||||
{
|
||||
/* read 16-bit word from CDC buffer */
|
||||
data = *(uint16 *)(cdc.ram + src_index);
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* source data is stored in big endian format */
|
||||
data = ((data >> 8) | (data << 8)) & 0xffff;
|
||||
#endif
|
||||
/* read 16-bit word from CDC RAM buffer (big-endian format) */
|
||||
data = READ_WORD(cdc.ram, src_index);
|
||||
|
||||
/* write 16-bit word to WORD-RAM */
|
||||
*(uint16 *)(scd.word_ram[0] + dst_index) = data ;
|
||||
@@ -85,10 +80,10 @@ void word_ram_1_dma_w(unsigned int words)
|
||||
|
||||
/* CDC buffer source address */
|
||||
uint16 src_index = cdc.dac.w & 0x3ffe;
|
||||
|
||||
|
||||
/* WORD-RAM destination address*/
|
||||
uint32 dst_index = ((scd.regs[0x0a>>1].w << 3) & 0x1fffe);
|
||||
|
||||
|
||||
/* update DMA destination address */
|
||||
scd.regs[0x0a>>1].w += (words >> 2);
|
||||
|
||||
@@ -98,13 +93,8 @@ void word_ram_1_dma_w(unsigned int words)
|
||||
/* DMA transfer */
|
||||
while (words--)
|
||||
{
|
||||
/* read 16-bit word from CDC buffer */
|
||||
data = *(uint16 *)(cdc.ram + src_index);
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* source data is stored in big endian format */
|
||||
data = ((data >> 8) | (data << 8)) & 0xffff;
|
||||
#endif
|
||||
/* read 16-bit word from CDC RAM buffer (big-endian format) */
|
||||
data = READ_WORD(cdc.ram, src_index);
|
||||
|
||||
/* write 16-bit word to WORD-RAM */
|
||||
*(uint16 *)(scd.word_ram[1] + dst_index) = data ;
|
||||
@@ -123,10 +113,10 @@ void word_ram_2M_dma_w(unsigned int words)
|
||||
|
||||
/* CDC buffer source address */
|
||||
uint16 src_index = cdc.dac.w & 0x3ffe;
|
||||
|
||||
|
||||
/* WORD-RAM destination address*/
|
||||
uint32 dst_index = (scd.regs[0x0a>>1].w << 3) & 0x3fffe;
|
||||
|
||||
|
||||
/* update DMA destination address */
|
||||
scd.regs[0x0a>>1].w += (words >> 2);
|
||||
|
||||
@@ -136,13 +126,8 @@ void word_ram_2M_dma_w(unsigned int words)
|
||||
/* DMA transfer */
|
||||
while (words--)
|
||||
{
|
||||
/* read 16-bit word from CDC buffer */
|
||||
data = *(uint16 *)(cdc.ram + src_index);
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* source data is stored in big endian format */
|
||||
data = ((data >> 8) | (data << 8)) & 0xffff;
|
||||
#endif
|
||||
/* read 16-bit word from CDC RAM buffer (big-endian format) */
|
||||
data = READ_WORD(cdc.ram, src_index);
|
||||
|
||||
/* write 16-bit word to WORD-RAM */
|
||||
*(uint16 *)(scd.word_ram_2M + dst_index) = data ;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* CD graphics processor
|
||||
*
|
||||
* Copyright (C) 2012 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
+135
-89
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Mega CD / Sega CD hardware
|
||||
*
|
||||
* Copyright (C) 2012-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -101,13 +101,8 @@ void prg_ram_dma_w(unsigned int words)
|
||||
/* DMA transfer */
|
||||
while (words--)
|
||||
{
|
||||
/* read 16-bit word from CDC buffer */
|
||||
data = *(uint16 *)(cdc.ram + src_index);
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* source data is stored in big endian format */
|
||||
data = ((data >> 8) | (data << 8)) & 0xffff;
|
||||
#endif
|
||||
/* read 16-bit word from CDC RAM buffer (big-endian format) */
|
||||
data = READ_WORD(cdc.ram, src_index);
|
||||
|
||||
/* write 16-bit word to PRG-RAM */
|
||||
*(uint16 *)(scd.prg_ram + dst_index) = data ;
|
||||
@@ -255,7 +250,7 @@ static void word_ram_z80_write_byte(unsigned int address, unsigned int data)
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_BYTE(m68k.memory_map[offset].base, address & 0xffff, data);
|
||||
*(uint16 *)(m68k.memory_map[offset].base + (address & 0xfffe)) = data | (data << 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +288,7 @@ static void word_ram_m68k_write_byte(unsigned int address, unsigned int data)
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_BYTE(m68k.memory_map[offset].base, address & 0xffff, data);
|
||||
*(uint16 *)(m68k.memory_map[offset].base + (address & 0xfffe)) = data | (data << 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +340,7 @@ static void word_ram_s68k_write_byte(unsigned int address, unsigned int data)
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITE_BYTE(s68k.memory_map[offset].base, address & 0xffff, data);
|
||||
*(uint16 *)(s68k.memory_map[offset].base + (address & 0xfffe)) = data | (data << 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,10 +440,16 @@ static void s68k_poll_sync(unsigned int reg_mask)
|
||||
/* relative MAIN-CPU cycle counter */
|
||||
unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE;
|
||||
|
||||
/* sync MAIN-CPU with SUB-CPU */
|
||||
if (!m68k.stopped)
|
||||
{
|
||||
/* save current MAIN-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = m68k.cycle_end;
|
||||
|
||||
/* sync MAIN-CPU with SUB-CPU */
|
||||
m68k_run(cycles);
|
||||
|
||||
/* restore MAIN-CPU end cycle count */
|
||||
m68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
/* MAIN-CPU idle on register polling ? */
|
||||
@@ -669,8 +670,14 @@ static unsigned int scd_read_word(unsigned int address)
|
||||
/* relative MAIN-CPU cycle counter */
|
||||
unsigned int cycles = (s68k.cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE;
|
||||
|
||||
/* save current MAIN-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = m68k.cycle_end;
|
||||
|
||||
/* sync MAIN-CPU with SUB-CPU (Mighty Morphin Power Rangers) */
|
||||
m68k_run(cycles);
|
||||
|
||||
/* restore MAIN-CPU end cycle count */
|
||||
m68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
s68k_poll_detect(3 << (address & 0x1e));
|
||||
@@ -781,7 +788,7 @@ static void scd_write_byte(unsigned int address, unsigned int data)
|
||||
|
||||
case 0x01: /* RESET status */
|
||||
{
|
||||
/* RESET bit cleared ? */
|
||||
/* RESET bit cleared ? */
|
||||
if (!(data & 0x01))
|
||||
{
|
||||
/* reset CD hardware */
|
||||
@@ -985,28 +992,6 @@ static void scd_write_byte(unsigned int address, unsigned int data)
|
||||
return;
|
||||
}
|
||||
|
||||
case 0x37: /* CDD control (controlled by BIOS, byte access only ?) */
|
||||
{
|
||||
/* CDD communication started ? */
|
||||
if ((data & 0x04) && !(scd.regs[0x37>>1].byte.l & 0x04))
|
||||
{
|
||||
/* reset CDD cycle counter */
|
||||
cdd.cycles = (scd.cycles - s68k.cycles) * 3;
|
||||
|
||||
/* set pending interrupt level 4 */
|
||||
scd.pending |= (1 << 4);
|
||||
|
||||
/* update IRQ level if interrupt is enabled */
|
||||
if (scd.regs[0x32>>1].byte.l & 0x10)
|
||||
{
|
||||
s68k_update_irq((scd.pending & scd.regs[0x32>>1].byte.l) >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
scd.regs[0x37>>1].byte.l = data;
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
/* SUB-CPU communication words */
|
||||
@@ -1059,7 +1044,7 @@ static void scd_write_word(unsigned int address, unsigned int data)
|
||||
/* only update LED status (register $00 is reserved for MAIN-CPU, use $06 instead) */
|
||||
scd.regs[0x06>>1].byte.h = data >> 8;
|
||||
|
||||
/* RESET bit cleared ? */
|
||||
/* RESET bit cleared ? */
|
||||
if (!(data & 0x01))
|
||||
{
|
||||
/* reset CD hardware */
|
||||
@@ -1281,6 +1266,46 @@ static void scd_write_word(unsigned int address, unsigned int data)
|
||||
return;
|
||||
}
|
||||
|
||||
case 0x34: /* CD Fader */
|
||||
{
|
||||
/* Wondermega hardware (CXD2554M digital filter) */
|
||||
if (cdd.type == CD_TYPE_WONDERMEGA)
|
||||
{
|
||||
/* only MSB is latched by CXD2554M chip, LSB is ignored (8-bit digital filter) */
|
||||
/* attenuator data is 7-bit only (bits 0-7) */
|
||||
data = (data >> 8) & 0x7f;
|
||||
|
||||
/* scale CXD2554M volume (0-127) to full (LC7883KM compatible) volume range (0-1024) */
|
||||
cdd.fader[1] = (1024 * data) / 127 ;
|
||||
}
|
||||
|
||||
/* Wondermega M2 / X'Eye hardware (SM5841A digital filter) */
|
||||
else if (cdd.type == CD_TYPE_WONDERMEGA_M2)
|
||||
{
|
||||
/* only MSB is latched by SM5841A chip, LSB is ignored (8-bit digital filter) */
|
||||
data = data >> 8;
|
||||
|
||||
/* attenuator data is set only when command bit (bit 0) is cleared (other commands are ignored) */
|
||||
if (data & 0x01) return;
|
||||
|
||||
/* attenuator data is 7-bit only (bits 8-1) and reverted (bit 1 = msb) */
|
||||
/* bit reversing formula taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits */
|
||||
data = (((((data * 0x0802) & 0x22110) | ((data * 0x8020) & 0x88440)) * 0x10101) >> 16) & 0x7f;
|
||||
|
||||
/* convert & scale SM5841A attenuation (127-0) to full (LC7883KM compatible) volume range (0-1024) */
|
||||
cdd.fader[1] = (1024 * (127 - data)) / 127 ;
|
||||
}
|
||||
|
||||
/* default CD hardware (LC7883KM digital filter) */
|
||||
else
|
||||
{
|
||||
/* get LC7883KM volume data (12-bit) */
|
||||
cdd.fader[1] = data >> 4 ;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
case 0x4a: /* CDD command 9 (controlled by BIOS, word access only ?) */
|
||||
{
|
||||
scd.regs[0x4a>>1].w = 0;
|
||||
@@ -1574,6 +1599,9 @@ void scd_reset(int hard)
|
||||
s68k.cycles = 0;
|
||||
s68k_pulse_reset();
|
||||
s68k_pulse_halt();
|
||||
|
||||
/* Reset frame cycle counter */
|
||||
scd.cycles = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1597,10 +1625,7 @@ void scd_reset(int hard)
|
||||
|
||||
/* Reset Timer & Stopwatch counters */
|
||||
scd.timer = 0;
|
||||
scd.stopwatch = 0;
|
||||
|
||||
/* Reset frame cycle counter */
|
||||
scd.cycles = 0;
|
||||
scd.stopwatch = s68k.cycles;
|
||||
|
||||
/* Clear pending interrupts */
|
||||
scd.pending = 0;
|
||||
@@ -1609,6 +1634,9 @@ void scd_reset(int hard)
|
||||
memset(&m68k.poll, 0, sizeof(m68k.poll));
|
||||
memset(&s68k.poll, 0, sizeof(s68k.poll));
|
||||
|
||||
/* reset CDD cycle counter */
|
||||
cdd.cycles = (scd.cycles - s68k.cycles) * 3;
|
||||
|
||||
/* Reset CD hardware */
|
||||
cdd_reset();
|
||||
cdc_reset();
|
||||
@@ -1618,6 +1646,10 @@ void scd_reset(int hard)
|
||||
|
||||
void scd_update(unsigned int cycles)
|
||||
{
|
||||
int m68k_end_cycles;
|
||||
int s68k_run_cycles;
|
||||
int s68k_end_cycles = scd.cycles + SCYCLES_PER_LINE;
|
||||
|
||||
/* update CDC DMA transfer */
|
||||
if (cdc.dma_w)
|
||||
{
|
||||
@@ -1627,63 +1659,77 @@ void scd_update(unsigned int cycles)
|
||||
/* run both CPU in sync until end of line */
|
||||
do
|
||||
{
|
||||
m68k_run(cycles);
|
||||
s68k_run(scd.cycles + SCYCLES_PER_LINE);
|
||||
}
|
||||
while ((m68k.cycles < cycles) || (s68k.cycles < (scd.cycles + SCYCLES_PER_LINE)));
|
||||
/* CD hardware remaining cycles until end of line */
|
||||
s68k_run_cycles = s68k_end_cycles - scd.cycles;
|
||||
|
||||
/* increment CD hardware cycle counter */
|
||||
scd.cycles += SCYCLES_PER_LINE;
|
||||
|
||||
/* CDD processing at 75Hz (one clock = 12500000/75 = 500000/3 CPU clocks) */
|
||||
cdd.cycles += (SCYCLES_PER_LINE * 3);
|
||||
if (cdd.cycles >= (500000 * 4))
|
||||
{
|
||||
/* reload CDD cycle counter */
|
||||
cdd.cycles -= (500000 * 4);
|
||||
|
||||
/* update CDD sector */
|
||||
cdd_update();
|
||||
|
||||
/* check if a new CDD command has been processed */
|
||||
if (!(scd.regs[0x4a>>1].byte.l & 0xf0))
|
||||
/* check Timer interrupt occurence */
|
||||
if ((scd.timer > 0) && (scd.timer < s68k_run_cycles))
|
||||
{
|
||||
/* reset CDD command wait flag */
|
||||
scd.regs[0x4a>>1].byte.l = 0xf0;
|
||||
/* adjust Sub-CPU and Main-CPU end cycle counters up to Timer interrupt occurence */
|
||||
s68k_run_cycles = scd.timer;
|
||||
m68k_end_cycles = mcycles_vdp + ((s68k_run_cycles * MCYCLES_PER_LINE) / SCYCLES_PER_LINE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* default Main-CPU end cycle counter (end of line) */
|
||||
m68k_end_cycles = cycles;
|
||||
}
|
||||
|
||||
/* pending level 4 interrupt */
|
||||
scd.pending |= (1 << 4);
|
||||
/* run both CPU in sync until required cycle counters */
|
||||
m68k_run(m68k_end_cycles);
|
||||
s68k_run(scd.cycles + s68k_run_cycles);
|
||||
|
||||
/* level 4 interrupt enabled */
|
||||
if (scd.regs[0x32>>1].byte.l & 0x10)
|
||||
/* increment CD hardware cycle counter */
|
||||
scd.cycles += s68k_run_cycles;
|
||||
|
||||
/* CDD processing at 75Hz (one clock = 12500000/75 = 500000/3 CPU clocks) */
|
||||
cdd.cycles += (s68k_run_cycles * 3);
|
||||
if (cdd.cycles >= (500000 * 4))
|
||||
{
|
||||
/* reload CDD cycle counter */
|
||||
cdd.cycles -= (500000 * 4);
|
||||
|
||||
/* update CDD sector */
|
||||
cdd_update();
|
||||
|
||||
/* check if CDD communication is enabled */
|
||||
if (scd.regs[0x37>>1].byte.l & 0x04)
|
||||
{
|
||||
/* update IRQ level */
|
||||
s68k_update_irq((scd.pending & scd.regs[0x32>>1].byte.l) >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Timer */
|
||||
if (scd.timer)
|
||||
{
|
||||
/* decrement timer */
|
||||
scd.timer -= SCYCLES_PER_LINE;
|
||||
if (scd.timer <= 0)
|
||||
{
|
||||
/* reload timer (one timer clock = 384 CPU cycles) */
|
||||
scd.timer += (scd.regs[0x30>>1].byte.l * TIMERS_SCYCLES_RATIO);
|
||||
|
||||
/* level 3 interrupt enabled ? */
|
||||
if (scd.regs[0x32>>1].byte.l & 0x08)
|
||||
{
|
||||
/* trigger level 3 interrupt */
|
||||
scd.pending |= (1 << 3);
|
||||
|
||||
/* update IRQ level */
|
||||
s68k_update_irq((scd.pending & scd.regs[0x32>>1].byte.l) >> 1);
|
||||
/* pending level 4 interrupt */
|
||||
scd.pending |= (1 << 4);
|
||||
|
||||
/* level 4 interrupt enabled */
|
||||
if (scd.regs[0x32>>1].byte.l & 0x10)
|
||||
{
|
||||
/* update IRQ level */
|
||||
s68k_update_irq((scd.pending & scd.regs[0x32>>1].byte.l) >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Timer */
|
||||
if (scd.timer)
|
||||
{
|
||||
/* decrement timer */
|
||||
scd.timer -= s68k_run_cycles;
|
||||
if (scd.timer <= 0)
|
||||
{
|
||||
/* reload timer (one timer clock = 384 CPU cycles) */
|
||||
scd.timer += (scd.regs[0x30>>1].byte.l * TIMERS_SCYCLES_RATIO);
|
||||
|
||||
/* level 3 interrupt enabled ? */
|
||||
if (scd.regs[0x32>>1].byte.l & 0x08)
|
||||
{
|
||||
/* trigger level 3 interrupt */
|
||||
scd.pending |= (1 << 3);
|
||||
|
||||
/* update IRQ level */
|
||||
s68k_update_irq((scd.pending & scd.regs[0x32>>1].byte.l) >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while ((m68k.cycles < cycles) || (s68k.cycles < s68k_end_cycles));
|
||||
|
||||
/* GFX processing */
|
||||
if (scd.regs[0x58>>1].byte.h & 0x80)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Mega CD / Sega CD hardware
|
||||
*
|
||||
* Copyright (C) 2012-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus GX
|
||||
* CPU hooking support
|
||||
*
|
||||
* HOOK_CPU should be defined in a makefile or MSVC project to enable this functionality
|
||||
*
|
||||
* Copyright feos (2019)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions may not be sold, nor may they be used in a commercial
|
||||
* product or activity.
|
||||
*
|
||||
* - Redistributions that are modified from the original source must include the
|
||||
* complete source code, including the source code for all components used by a
|
||||
* binary built from the modified sources. However, as a special exception, the
|
||||
* source code distributed need not include anything that is normally distributed
|
||||
* (in either source or binary form) with the major components (compiler, kernel,
|
||||
* and so on) of the operating system on which the executable runs, unless that
|
||||
* component itself accompanies the executable.
|
||||
*
|
||||
* - Redistributions must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cpuhook.h"
|
||||
|
||||
void(*cpu_hook)(hook_type_t type, int width, unsigned int address, unsigned int value) = NULL;
|
||||
|
||||
void set_cpu_hook(void(*hook)(hook_type_t type, int width, unsigned int address, unsigned int value))
|
||||
{
|
||||
cpu_hook = hook;
|
||||
}
|
||||
|
||||
#endif /* HOOK_CPU */
|
||||
@@ -0,0 +1,91 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus GX
|
||||
* CPU hooking support
|
||||
*
|
||||
* HOOK_CPU should be defined in a makefile or MSVC project to enable this functionality
|
||||
*
|
||||
* Copyright DrMefistO (2018-2019)
|
||||
*
|
||||
* Copyright feos (2019)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions may not be sold, nor may they be used in a commercial
|
||||
* product or activity.
|
||||
*
|
||||
* - Redistributions that are modified from the original source must include the
|
||||
* complete source code, including the source code for all components used by a
|
||||
* binary built from the modified sources. However, as a special exception, the
|
||||
* source code distributed need not include anything that is normally distributed
|
||||
* (in either source or binary form) with the major components (compiler, kernel,
|
||||
* and so on) of the operating system on which the executable runs, unless that
|
||||
* component itself accompanies the executable.
|
||||
*
|
||||
* - Redistributions must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef _CPUHOOK_H_
|
||||
#define _CPUHOOK_H_
|
||||
|
||||
|
||||
typedef enum {
|
||||
HOOK_ANY = (0 << 0),
|
||||
|
||||
// M68K
|
||||
HOOK_M68K_E = (1 << 0),
|
||||
HOOK_M68K_R = (1 << 1),
|
||||
HOOK_M68K_W = (1 << 2),
|
||||
HOOK_M68K_RW = HOOK_M68K_R | HOOK_M68K_W,
|
||||
|
||||
// VDP
|
||||
HOOK_VRAM_R = (1 << 3),
|
||||
HOOK_VRAM_W = (1 << 4),
|
||||
HOOK_VRAM_RW = HOOK_VRAM_R | HOOK_VRAM_W,
|
||||
|
||||
HOOK_CRAM_R = (1 << 5),
|
||||
HOOK_CRAM_W = (1 << 6),
|
||||
HOOK_CRAM_RW = HOOK_CRAM_R | HOOK_CRAM_W,
|
||||
|
||||
HOOK_VSRAM_R = (1 << 7),
|
||||
HOOK_VSRAM_W = (1 << 8),
|
||||
HOOK_VSRAM_RW = HOOK_VSRAM_R | HOOK_VSRAM_W,
|
||||
|
||||
// Z80
|
||||
HOOK_Z80_E = (1 << 9),
|
||||
HOOK_Z80_R = (1 << 10),
|
||||
HOOK_Z80_W = (1 << 11),
|
||||
HOOK_Z80_RW = HOOK_Z80_R | HOOK_Z80_W,
|
||||
|
||||
// REGS
|
||||
HOOK_VDP_REG = (1 << 12),
|
||||
HOOK_M68K_REG = (1 << 13),
|
||||
} hook_type_t;
|
||||
|
||||
|
||||
/* CPU hook is called on read, write, and execute.
|
||||
*/
|
||||
void (*cpu_hook)(hook_type_t type, int width, unsigned int address, unsigned int value);
|
||||
|
||||
/* Use set_cpu_hook() to assign a callback that can process the data provided
|
||||
* by cpu_hook().
|
||||
*/
|
||||
void set_cpu_hook(void(*hook)(hook_type_t type, int width, unsigned int address, unsigned int value));
|
||||
|
||||
|
||||
#endif /* _CPUHOOK_H_ */
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for SG-1000, Mark-III, Master System, Game Gear, Mega Drive & Mega CD hardware
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -279,10 +279,18 @@ void gen_reset(int hard_reset)
|
||||
/* reset CD hardware */
|
||||
scd_reset(1);
|
||||
}
|
||||
|
||||
/* reset MD cartridge hardware (only when booting from cartridge) */
|
||||
if (scd.cartridge.boot)
|
||||
{
|
||||
md_cart_reset(hard_reset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* reset MD cartridge hardware */
|
||||
md_cart_reset(hard_reset);
|
||||
}
|
||||
|
||||
/* reset MD cartridge hardware */
|
||||
md_cart_reset(hard_reset);
|
||||
|
||||
/* Z80 bus is released & Z80 is reseted */
|
||||
m68k.memory_map[0xa0].read8 = m68k_read_bus_8;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for SG-1000, Mark-III, Master System, Game Gear, Mega Drive & Mega CD hardware
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 2-Buttons, 3-Buttons & 6-Buttons controller support
|
||||
* with support for J-Cart, 4-Way Play & Master Tap adapters
|
||||
*
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -125,8 +125,7 @@ INLINE unsigned char gamepad_read(int port)
|
||||
/* From gen_hw.txt (*):
|
||||
|
||||
A 6-button gamepad allows the extra buttons to be read based on how
|
||||
many times TH is switched from (and not 0 to 1). Observe the
|
||||
following sequence:
|
||||
many times TH is switched from 0 to 1. Observe the following sequence:
|
||||
|
||||
TH = 1 : ?1CBRLDU 3-button pad return value
|
||||
TH = 0 : ?0SA00DU 3-button pad return value
|
||||
@@ -141,7 +140,7 @@ INLINE unsigned char gamepad_read(int port)
|
||||
|
||||
(*) additional High-to-Low transition is necessary to access extra buttons according to official MK-1653-50 specification
|
||||
*/
|
||||
case 6: /*** Third Low ***/
|
||||
case 4: /*** Third Low ***/
|
||||
{
|
||||
/* TH = 0 : ?0SA0000 D3-D0 forced to '0' */
|
||||
data &= ~(((pad >> 2) & 0x30) | 0x0F);
|
||||
@@ -155,7 +154,7 @@ INLINE unsigned char gamepad_read(int port)
|
||||
break;
|
||||
}
|
||||
|
||||
case 8: /*** Fourth Low ***/
|
||||
case 6: /*** Fourth Low ***/
|
||||
{
|
||||
/* TH = 0 : ?0SA1111 D3-D0 forced to '1' */
|
||||
data &= ~((pad >> 2) & 0x30);
|
||||
@@ -193,10 +192,10 @@ INLINE void gamepad_write(int port, unsigned char data, unsigned char mask)
|
||||
gamepad[port].Latency = 0;
|
||||
|
||||
/* 6-Buttons controller specific */
|
||||
if ((input.dev[port] == DEVICE_PAD6B) && (gamepad[port].Counter < 10))
|
||||
if ((input.dev[port] == DEVICE_PAD6B) && (gamepad[port].Counter < 8))
|
||||
{
|
||||
/* TH 1->0 transition */
|
||||
if (!data && gamepad[port].State)
|
||||
/* TH 0->1 transition */
|
||||
if (data && !gamepad[port].State)
|
||||
{
|
||||
gamepad[port].Counter += 2;
|
||||
gamepad[port].Timeout = 0;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 2-Buttons, 3-Buttons & 6-Buttons controller support
|
||||
* with support for J-Cart, 4-Way Play & Master Tap adapters
|
||||
*
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for Master System (315-5216, 315-5237 & 315-5297), Game Gear & Mega Drive I/O chips
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -321,13 +321,27 @@ void io_reset(void)
|
||||
io_reg[0x0D] |= IO_CONT1_HI;
|
||||
}
|
||||
|
||||
/* Control registers */
|
||||
io_reg[0x0E] = 0x00;
|
||||
io_reg[0x0F] = 0xFF;
|
||||
|
||||
/* on SG-1000 & Mark-III, TH is not connected (always return 1) */
|
||||
if (system_hw < SYSTEM_SMS)
|
||||
/* Memory Control register (Master System and Game Gear hardware only) */
|
||||
if ((system_hw & SYSTEM_SMS) || (system_hw & SYSTEM_GG))
|
||||
{
|
||||
/* RAM, I/O and either BIOS or Cartridge ROM are enabled */
|
||||
io_reg[0x0E] = (z80_readmap[0] == cart.rom + 0x400000) ? 0xE0 : 0xA8;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* default value (no Memory Control register) */
|
||||
io_reg[0x0E] = 0x00;
|
||||
}
|
||||
|
||||
/* I/O control register (Master System, Mega Drive and Game Gear hardware only) */
|
||||
if (system_hw >= SYSTEM_SMS)
|
||||
{
|
||||
/* on power-on, TR and TH are configured as inputs */
|
||||
io_reg[0x0F] = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* on SG-1000 & Mark-III, TR is always an input and TH is not connected (always return 1) */
|
||||
io_reg[0x0F] = 0xF5;
|
||||
}
|
||||
}
|
||||
@@ -350,6 +364,16 @@ void io_68k_write(unsigned int offset, unsigned int data)
|
||||
case 0x02: /* Port B Data */
|
||||
case 0x03: /* Port C Data */
|
||||
{
|
||||
/*
|
||||
D7 : Unused. This bit will return any value written to it
|
||||
D6 : TH pin output level (1=high, 0=low)
|
||||
D5 : TR pin output level (1=high, 0=low)
|
||||
D4 : TL pin output level (1=high, 0=low)
|
||||
D3 : D3 pin output level (1=high, 0=low)
|
||||
D2 : D2 pin output level (1=high, 0=low)
|
||||
D1 : D1 pin output level (1=high, 0=low)
|
||||
D0 : D0 pin output level (1=high, 0=low)
|
||||
*/
|
||||
io_reg[offset] = data;
|
||||
port[offset-1].data_w(data, io_reg[offset + 3]);
|
||||
return;
|
||||
@@ -359,6 +383,16 @@ void io_68k_write(unsigned int offset, unsigned int data)
|
||||
case 0x05: /* Port B Ctrl */
|
||||
case 0x06: /* Port C Ctrl */
|
||||
{
|
||||
/*
|
||||
D7 : /HL output control (1=TH input level, 0=forced high)
|
||||
D6 : TH pin is 1=output, 0=input
|
||||
D5 : TR pin is 1=output, 0=input
|
||||
D4 : TL pin is 1=output, 0=input
|
||||
D3 : D3 pin is 1=output, 0=input
|
||||
D2 : D2 pin is 1=output, 0=input
|
||||
D1 : D1 pin is 1=output, 0=input
|
||||
D0 : D0 pin is 1=output, 0=input
|
||||
*/
|
||||
if (data != io_reg[offset])
|
||||
{
|
||||
io_reg[offset] = data;
|
||||
@@ -379,6 +413,15 @@ void io_68k_write(unsigned int offset, unsigned int data)
|
||||
case 0x0C: /* Port B S-Ctrl */
|
||||
case 0x0F: /* Port C S-Ctrl */
|
||||
{
|
||||
/*
|
||||
D7-D6 : Serial baud rate (00= 4800 bps, 01= 2400 bps, 10= 1200 bps, 11= 300 bps)
|
||||
D5 : TR pin functions as 1= serial input pin, 0= normal
|
||||
D4 : TL pin functions as 1= serial output pin, 0= normal
|
||||
D3 : 1= Make I/O chip strobe /HL low when a byte has been received, 0= Do nothing
|
||||
D2 : read-only (on read, 1= Error receiving current byte, 0= No error)
|
||||
D1 : read-only (on read, 1= Rxd buffer is ready to read, 0= Rxd buffer isn't ready)
|
||||
D0 : read-only (on read, 1= Txd buffer is full, 0= Can write to Txd buffer)
|
||||
*/
|
||||
io_reg[offset] = data & 0xF8;
|
||||
return;
|
||||
}
|
||||
@@ -398,6 +441,16 @@ unsigned int io_68k_read(unsigned int offset)
|
||||
case 0x02: /* Port B Data */
|
||||
case 0x03: /* Port C Data */
|
||||
{
|
||||
/*
|
||||
D7 : Unused. This bit will return any value written to it
|
||||
D6 : TH pin input level (1=high, 0=low)
|
||||
D5 : TR pin input level (1=high, 0=low)
|
||||
D4 : TL pin input level (1=high, 0=low)
|
||||
D3 : D3 pin input level (1=high, 0=low)
|
||||
D2 : D2 pin input level (1=high, 0=low)
|
||||
D1 : D1 pin input level (1=high, 0=low)
|
||||
D0 : D0 pin input level (1=high, 0=low)
|
||||
*/
|
||||
unsigned int mask = 0x80 | io_reg[offset + 3];
|
||||
unsigned int data = port[offset-1].data_r();
|
||||
return (io_reg[offset] & mask) | (data & ~mask);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for Master System (315-5216, 315-5237 & 315-5297), Game Gear & Mega Drive I/O chips
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* ROM Loading Support
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -417,6 +417,23 @@ int load_bios(int system)
|
||||
/* CD BOOTROM loaded ? */
|
||||
if (size > 0)
|
||||
{
|
||||
/* auto-detect CD hardware model */
|
||||
if (!memcmp (&scd.bootrom[0x120], "WONDER-MEGA BOOT", 16))
|
||||
{
|
||||
/* Wondermega CD hardware */
|
||||
cdd.type = CD_TYPE_WONDERMEGA;
|
||||
}
|
||||
else if (!memcmp (&scd.bootrom[0x120], "WONDERMEGA2 BOOT", 16))
|
||||
{
|
||||
/* Wondermega M2 / X'Eye CD hardware */
|
||||
cdd.type = CD_TYPE_WONDERMEGA_M2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* default CD hardware */
|
||||
cdd.type = CD_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
#ifdef LSB_FIRST
|
||||
/* Byteswap ROM to optimize 16-bit access */
|
||||
int i;
|
||||
@@ -630,7 +647,9 @@ int load_rom(char *filename)
|
||||
|
||||
/* auto-detect byte-swapped dumps */
|
||||
if (!memcmp((char *)(cart.rom + 0x100),"ESAGM GE ARDVI E", 16) ||
|
||||
!memcmp((char *)(cart.rom + 0x100),"ESAGG NESESI", 12))
|
||||
!memcmp((char *)(cart.rom + 0x100),"ESAGG NESESI", 12) ||
|
||||
!memcmp((char *)(cart.rom + 0x80000 + 0x100),"ESAGM GE ARDVI E", 16) ||
|
||||
!memcmp((char *)(cart.rom + 0x80000 + 0x100),"ESAGG NESESI", 12))
|
||||
{
|
||||
for(i = 0; i < size; i += 2)
|
||||
{
|
||||
@@ -1059,7 +1078,8 @@ void get_region(char *romheader)
|
||||
(strstr(rominfo.product,"T-69046-50") != NULL) || /* Back to the Future III (Europe) */
|
||||
(strstr(rominfo.product,"T-120106-00") != NULL) || /* Brian Lara Cricket (Europe) */
|
||||
(strstr(rominfo.product,"T-97126 -50") != NULL) || /* Williams Arcade's Greatest Hits (Europe) */
|
||||
(strstr(rominfo.product,"T-70096 -00") != NULL)) /* Muhammad Ali Heavyweight Boxing (Europe) */
|
||||
(strstr(rominfo.product,"T-70096 -00") != NULL) || /* Muhammad Ali Heavyweight Boxing (Europe) */
|
||||
((rominfo.checksum == 0x0000) && (rominfo.realchecksum == 0x1f7f))) /* Radica - Sensible Soccer Plus edition */
|
||||
{
|
||||
/* need PAL settings */
|
||||
region_code = REGION_EUROPE;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* ROM Loading Support
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "macros.h"
|
||||
#ifdef HOOK_CPU
|
||||
#include "cpuhook.h"
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ==================== ARCHITECTURE-DEPENDANT DEFINES ==================== */
|
||||
|
||||
@@ -188,7 +188,8 @@ void m68k_set_fc_callback(void (*callback)(unsigned int new_fc))
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
#ifdef LOGERROR
|
||||
|
||||
extern void error(char *format, ...);
|
||||
extern uint16 v_counter;
|
||||
#endif
|
||||
@@ -202,8 +203,8 @@ void m68k_update_irq(unsigned int mask)
|
||||
/* Update IRQ level */
|
||||
CPU_INT_LEVEL |= (mask << 8);
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#ifdef LOGERROR
|
||||
error("[%d(%d)][%d(%d)] m68k IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -212,8 +213,8 @@ void m68k_set_irq(unsigned int int_level)
|
||||
/* Set IRQ level */
|
||||
CPU_INT_LEVEL = int_level << 8;
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#ifdef LOGERROR
|
||||
error("[%d(%d)][%d(%d)] m68k IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -245,8 +246,8 @@ void m68k_set_irq_delay(unsigned int int_level)
|
||||
CPU_INT_LEVEL = int_level << 8;
|
||||
}
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#ifdef LOGERROR
|
||||
error("[%d(%d)][%d(%d)] m68k IRQ Level = %d(0x%02x) (%x)\n", v_counter, m68k.cycles/3420, m68k.cycles, m68k.cycles%3420,CPU_INT_LEVEL>>8,FLAG_INT_MASK,m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
|
||||
/* Check interrupt mask to process IRQ */
|
||||
@@ -277,7 +278,7 @@ void m68k_run(unsigned int cycles)
|
||||
/* Return point for when we have an address error (TODO: use goto) */
|
||||
m68ki_set_address_error_trap() /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
#ifdef LOGVDP
|
||||
#ifdef LOGERROR
|
||||
error("[%d][%d] m68k run to %d cycles (%x), irq mask = %x (%x)\n", v_counter, m68k.cycles, cycles, m68k.pc,FLAG_INT_MASK, CPU_INT_LEVEL);
|
||||
#endif
|
||||
|
||||
@@ -289,6 +290,12 @@ void m68k_run(unsigned int cycles)
|
||||
/* Set the address space for reads */
|
||||
m68ki_use_data_space() /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
/* Trigger execution hook */
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_E, 0, REG_PC, 0);
|
||||
#endif
|
||||
|
||||
/* Decode next instruction */
|
||||
REG_IR = m68ki_read_imm_16();
|
||||
|
||||
|
||||
@@ -849,36 +849,60 @@ INLINE uint m68ki_read_imm_32(void)
|
||||
*/
|
||||
INLINE uint m68ki_read_8(uint address)
|
||||
{
|
||||
cpu_memory_map *temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];;
|
||||
cpu_memory_map *temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
uint val;
|
||||
|
||||
m68ki_set_fc(FLAG_S | m68ki_get_address_space()) /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
if (temp->read8) return (*temp->read8)(ADDRESS_68K(address));
|
||||
else return READ_BYTE(temp->base, (address) & 0xffff);
|
||||
if (temp->read8) val = (*temp->read8)(ADDRESS_68K(address));
|
||||
else val = READ_BYTE(temp->base, (address) & 0xffff);
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_R, 1, address, val);
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
INLINE uint m68ki_read_16(uint address)
|
||||
{
|
||||
cpu_memory_map *temp;
|
||||
uint val;
|
||||
|
||||
m68ki_set_fc(FLAG_S | m68ki_get_address_space()) /* auto-disable (see m68kcpu.h) */
|
||||
m68ki_check_address_error(address, MODE_READ, FLAG_S | m68ki_get_address_space()) /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
if (temp->read16) return (*temp->read16)(ADDRESS_68K(address));
|
||||
else return *(uint16 *)(temp->base + ((address) & 0xffff));
|
||||
if (temp->read16) val = (*temp->read16)(ADDRESS_68K(address));
|
||||
else val = *(uint16 *)(temp->base + ((address) & 0xffff));
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_R, 2, address, val);
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
INLINE uint m68ki_read_32(uint address)
|
||||
{
|
||||
cpu_memory_map *temp;
|
||||
uint val;
|
||||
|
||||
m68ki_set_fc(FLAG_S | m68ki_get_address_space()) /* auto-disable (see m68kcpu.h) */
|
||||
m68ki_check_address_error(address, MODE_READ, FLAG_S | m68ki_get_address_space()) /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
if (temp->read16) return ((*temp->read16)(ADDRESS_68K(address)) << 16) | ((*temp->read16)(ADDRESS_68K(address + 2)));
|
||||
else return m68k_read_immediate_32(address);
|
||||
if (temp->read16) val = ((*temp->read16)(ADDRESS_68K(address)) << 16) | ((*temp->read16)(ADDRESS_68K(address + 2)));
|
||||
else val = m68k_read_immediate_32(address);
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_R, 4, address, val);
|
||||
#endif
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
INLINE void m68ki_write_8(uint address, uint value)
|
||||
@@ -887,6 +911,11 @@ INLINE void m68ki_write_8(uint address, uint value)
|
||||
|
||||
m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_DATA) /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_W, 1, address, value);
|
||||
#endif
|
||||
|
||||
temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
if (temp->write8) (*temp->write8)(ADDRESS_68K(address),value);
|
||||
else WRITE_BYTE(temp->base, (address) & 0xffff, value);
|
||||
@@ -899,6 +928,11 @@ INLINE void m68ki_write_16(uint address, uint value)
|
||||
m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_DATA) /* auto-disable (see m68kcpu.h) */
|
||||
m68ki_check_address_error(address, MODE_WRITE, FLAG_S | FUNCTION_CODE_USER_DATA); /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_W, 2, address, value);
|
||||
#endif
|
||||
|
||||
temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
if (temp->write16) (*temp->write16)(ADDRESS_68K(address),value);
|
||||
else *(uint16 *)(temp->base + ((address) & 0xffff)) = value;
|
||||
@@ -911,6 +945,11 @@ INLINE void m68ki_write_32(uint address, uint value)
|
||||
m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_DATA) /* auto-disable (see m68kcpu.h) */
|
||||
m68ki_check_address_error(address, MODE_WRITE, FLAG_S | FUNCTION_CODE_USER_DATA) /* auto-disable (see m68kcpu.h) */
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_M68K_W, 4, address, value);
|
||||
#endif
|
||||
|
||||
temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];
|
||||
if (temp->write16) (*temp->write16)(ADDRESS_68K(address),value>>16);
|
||||
else *(uint16 *)(temp->base + ((address) & 0xffff)) = value >> 16;
|
||||
|
||||
@@ -19,7 +19,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -51,7 +51,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -83,7 +83,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -115,7 +115,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -147,7 +147,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -179,7 +179,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -211,7 +211,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
@@ -243,7 +243,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 6*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7,
|
||||
10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 10*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 8*7, 0*7, 0*7, 0*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 12*7, 16*7, 12*7, 14*7, 10*7, 0*7, 0*7, 0*7,
|
||||
8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 8*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7, 24*7,
|
||||
12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7, 12*7,
|
||||
14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 14*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7, 16*7,
|
||||
|
||||
@@ -8117,7 +8117,7 @@ static void m68k_op_divu_16_d(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8148,7 +8148,7 @@ static void m68k_op_divu_16_ai(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8179,7 +8179,7 @@ static void m68k_op_divu_16_pi(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 *10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8210,7 +8210,7 @@ static void m68k_op_divu_16_pd(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8241,7 +8241,7 @@ static void m68k_op_divu_16_di(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8272,7 +8272,7 @@ static void m68k_op_divu_16_ix(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8303,7 +8303,7 @@ static void m68k_op_divu_16_aw(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8334,7 +8334,7 @@ static void m68k_op_divu_16_al(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8365,7 +8365,7 @@ static void m68k_op_divu_16_pcdi(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8396,7 +8396,7 @@ static void m68k_op_divu_16_pcix(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -8427,7 +8427,7 @@ static void m68k_op_divu_16_i(void)
|
||||
*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
|
||||
return;
|
||||
}
|
||||
USE_CYCLES(7 * 10);
|
||||
USE_CYCLES(MUL * 10);
|
||||
FLAG_V = VFLAG_SET;
|
||||
FLAG_N = NFLAG_SET; /* undocumented behavior (fixes Blood Shot on Genesis) */
|
||||
FLAG_C = CFLAG_CLEAR;
|
||||
@@ -20967,7 +20967,10 @@ static void m68k_op_stop(void)
|
||||
uint new_sr = OPER_I_16();
|
||||
CPU_STOPPED |= STOP_LEVEL_STOP;
|
||||
m68ki_set_sr(new_sr);
|
||||
SET_CYCLES(m68ki_cpu.cycle_end - 4*MUL);
|
||||
if (CPU_STOPPED)
|
||||
{
|
||||
SET_CYCLES(m68ki_cpu.cycle_end - 4*MUL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
m68ki_exception_privilege_violation();
|
||||
@@ -24235,7 +24238,7 @@ static const opcode_handler_struct m68k_opcode_handler_table[] =
|
||||
{m68k_op_btst_8_r_al , 0xf1ff, 0x0139, 16},
|
||||
{m68k_op_btst_8_r_pcdi , 0xf1ff, 0x013a, 12},
|
||||
{m68k_op_btst_8_r_pcix , 0xf1ff, 0x013b, 14},
|
||||
{m68k_op_btst_8_r_i , 0xf1ff, 0x013c, 8},
|
||||
{m68k_op_btst_8_r_i , 0xf1ff, 0x013c, 10},
|
||||
{m68k_op_bchg_8_r_pi7 , 0xf1ff, 0x015f, 12},
|
||||
{m68k_op_bchg_8_r_pd7 , 0xf1ff, 0x0167, 14},
|
||||
{m68k_op_bchg_8_r_aw , 0xf1ff, 0x0178, 16},
|
||||
|
||||
@@ -213,7 +213,7 @@ void s68k_update_irq(unsigned int mask)
|
||||
CPU_INT_LEVEL = mask << 8;
|
||||
|
||||
#ifdef LOG_SCD
|
||||
error("[%d][%d] IRQ Level = %d(0x%02x) (%x)\n", v_counter, s68k.cycles, CPU_INT_LEVEL>>8,FLAG_INT_MASK,s68k.pc);
|
||||
error("[%d][%d] s68k IRQ Level = %d(0x%02x) (%x)\n", v_counter, s68k.cycles, CPU_INT_LEVEL>>8,FLAG_INT_MASK,s68k.pc);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -51,7 +51,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -83,7 +83,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -115,7 +115,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -147,7 +147,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -179,7 +179,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -211,7 +211,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 10*4, 0*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
@@ -243,7 +243,7 @@ static const unsigned char m68ki_cycles[0x10000] =
|
||||
6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 6*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4,
|
||||
10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 10*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 0*4, 0*4, 0*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 12*4, 16*4, 12*4, 14*4, 8*4, 10*4, 0*4, 0*4,
|
||||
8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 8*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4, 24*4,
|
||||
12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4, 12*4,
|
||||
14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 14*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4, 16*4,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Main 68k bus handlers
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -268,10 +268,16 @@ static void m68k_poll_sync(unsigned int reg_mask)
|
||||
/* relative SUB-CPU cycle counter */
|
||||
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
|
||||
|
||||
/* sync SUB-CPU with MAIN-CPU */
|
||||
if (!s68k.stopped)
|
||||
{
|
||||
/* save current SUB-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = s68k.cycle_end;
|
||||
|
||||
/* sync SUB-CPU with MAIN-CPU */
|
||||
s68k_run(cycles);
|
||||
|
||||
/* restore SUB-CPU end cycle count */
|
||||
s68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
/* SUB-CPU idle on register polling ? */
|
||||
@@ -354,8 +360,14 @@ unsigned int ctrl_io_read_byte(unsigned int address)
|
||||
/* relative SUB-CPU cycle counter */
|
||||
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
|
||||
|
||||
/* save current SUB-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = s68k.cycle_end;
|
||||
|
||||
/* sync SUB-CPU with MAIN-CPU (Dracula Unleashed w/ Sega CD Model 2 Boot ROM) */
|
||||
s68k_run(cycles);
|
||||
|
||||
/* restore SUB-CPU end cycle count */
|
||||
s68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
m68k_poll_detect(1<<0x0f);
|
||||
@@ -527,8 +539,14 @@ unsigned int ctrl_io_read_word(unsigned int address)
|
||||
/* relative SUB-CPU cycle counter */
|
||||
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
|
||||
|
||||
/* save current SUB-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = s68k.cycle_end;
|
||||
|
||||
/* sync SUB-CPU with MAIN-CPU (Soul Star) */
|
||||
s68k_run(cycles);
|
||||
|
||||
/* restore SUB-CPU end cycle count */
|
||||
s68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
m68k_poll_detect(3 << (index - 0x10));
|
||||
@@ -646,8 +664,14 @@ void ctrl_io_write_byte(unsigned int address, unsigned int data)
|
||||
/* relative SUB-CPU cycle counter */
|
||||
unsigned int cycles = (m68k.cycles * SCYCLES_PER_LINE) / MCYCLES_PER_LINE;
|
||||
|
||||
/* save current SUB-CPU end cycle count (recursive execution is possible) */
|
||||
int end_cycle = s68k.cycle_end;
|
||||
|
||||
/* sync SUB-CPU with MAIN-CPU (Earnest Evans, Fhey Area) */
|
||||
s68k_run(cycles);
|
||||
|
||||
/* restore SUB-CPU end cycle count */
|
||||
s68k.cycle_end = end_cycle;
|
||||
}
|
||||
|
||||
/* set IFL2 flag */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Main 68k bus handlers
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Z80 bank access to 68k bus
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -39,6 +39,9 @@
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
|
||||
t_zbank_memory_map zbank_memory_map[256];
|
||||
|
||||
/*
|
||||
Handlers for access to unused addresses and those which make the
|
||||
machine lock up.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Z80 bank access to 68k bus
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -49,10 +49,12 @@ extern void zbank_write_ctrl_io(unsigned int address, unsigned int data);
|
||||
extern unsigned int zbank_read_vdp(unsigned int address);
|
||||
extern void zbank_write_vdp(unsigned int address, unsigned int data);
|
||||
|
||||
struct _zbank_memory_map
|
||||
typedef struct
|
||||
{
|
||||
unsigned int (*read)(unsigned int address);
|
||||
void (*write)(unsigned int address, unsigned int data);
|
||||
} zbank_memory_map[256];
|
||||
} t_zbank_memory_map;
|
||||
|
||||
extern t_zbank_memory_map zbank_memory_map[256];
|
||||
|
||||
#endif /* _MEMBNK_H_ */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for SG-1000, Mark-III, Master System, Game Gear & Mega Drive ports access
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -111,6 +111,8 @@ unsigned char z80_memory_r(unsigned int address)
|
||||
{
|
||||
if ((address >> 8) == 0x7F)
|
||||
{
|
||||
/* average Z80 wait-states when accessing 68k area */
|
||||
Z80.cycles += 3 * 15;
|
||||
return (*zbank_memory_map[0xc0].read)(address);
|
||||
}
|
||||
return z80_unused_r(address);
|
||||
@@ -118,6 +120,9 @@ unsigned char z80_memory_r(unsigned int address)
|
||||
|
||||
default: /* $8000-$FFFF: 68k bank (32K) */
|
||||
{
|
||||
/* average Z80 wait-states when accessing 68k area */
|
||||
Z80.cycles += 3 * 15;
|
||||
|
||||
address = zbank | (address & 0x7FFF);
|
||||
if (zbank_memory_map[address >> 16].read)
|
||||
{
|
||||
@@ -158,6 +163,8 @@ void z80_memory_w(unsigned int address, unsigned char data)
|
||||
|
||||
case 0x7F: /* $7F00-$7FFF: VDP */
|
||||
{
|
||||
/* average Z80 wait-states when accessing 68k area */
|
||||
Z80.cycles += 3 * 15;
|
||||
(*zbank_memory_map[0xc0].write)(address, data);
|
||||
return;
|
||||
}
|
||||
@@ -172,6 +179,9 @@ void z80_memory_w(unsigned int address, unsigned char data)
|
||||
|
||||
default: /* $8000-$FFFF: 68k bank (32K) */
|
||||
{
|
||||
/* average Z80 wait-states when accessing 68k area */
|
||||
Z80.cycles += 3 * 15;
|
||||
|
||||
address = zbank | (address & 0x7FFF);
|
||||
if (zbank_memory_map[address >> 16].write)
|
||||
{
|
||||
@@ -300,7 +310,7 @@ unsigned char z80_md_port_r(unsigned int port)
|
||||
/* read FM chip if enabled */
|
||||
if ((port >= 0xF0) && (config.ym2413 & 1))
|
||||
{
|
||||
return YM2413Read();
|
||||
return fm_read(Z80.cycles, port);
|
||||
}
|
||||
|
||||
return z80_unused_port_r(port);
|
||||
@@ -578,7 +588,7 @@ unsigned char z80_ms_port_r(unsigned int port)
|
||||
/* read FM board if enabled */
|
||||
if (!(port & 4) && (config.ym2413 & 1))
|
||||
{
|
||||
data = YM2413Read();
|
||||
data = fm_read(Z80.cycles, port);
|
||||
}
|
||||
|
||||
/* read I/O ports if enabled */
|
||||
@@ -678,7 +688,7 @@ unsigned char z80_m3_port_r(unsigned int port)
|
||||
if (!(port & 4) && (config.ym2413 & 1))
|
||||
{
|
||||
/* I/O ports are automatically disabled by hardware */
|
||||
return YM2413Read();
|
||||
return fm_read(Z80.cycles, port);
|
||||
}
|
||||
|
||||
/* read I/O ports */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Support for SG-1000, Mark-III, Master System, Game Gear & Mega Drive ports access
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#ifdef HAVE_YM3438_CORE
|
||||
#include "ym3438.h"
|
||||
#endif
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
#include "opll.h"
|
||||
#endif
|
||||
#include "sram.h"
|
||||
#include "ggenie.h"
|
||||
#include "areplay.h"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Nuke.YKT
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions may not be sold, nor may they be used in a commercial
|
||||
* product or activity.
|
||||
*
|
||||
* - Redistributions that are modified from the original source must include the
|
||||
* complete source code, including the source code for all components used by a
|
||||
* binary built from the modified sources. However, as a special exception, the
|
||||
* source code distributed need not include anything that is normally distributed
|
||||
* (in either source or binary form) with the major components (compiler, kernel,
|
||||
* and so on) of the operating system on which the executable runs, unless that
|
||||
* component itself accompanies the executable.
|
||||
*
|
||||
* - Redistributions must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* Yamaha YM2413 emulator
|
||||
* Thanks:
|
||||
* siliconpr0n.org(digshadow, John McMaster):
|
||||
* VRC VII decap and die shot.
|
||||
*
|
||||
* version: 1.0
|
||||
*/
|
||||
|
||||
#ifndef OPLL_H
|
||||
#define OPLL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
opll_type_ym2413 = 0x00, /* Yamaha YM2413 */
|
||||
opll_type_ds1001, /* Konami VRC VII */
|
||||
opll_type_ym2413b /* Yamaha YM2413B */
|
||||
};
|
||||
|
||||
enum {
|
||||
opll_patch_1 = 0x00,
|
||||
opll_patch_2,
|
||||
opll_patch_3,
|
||||
opll_patch_4,
|
||||
opll_patch_5,
|
||||
opll_patch_6,
|
||||
opll_patch_7,
|
||||
opll_patch_8,
|
||||
opll_patch_9,
|
||||
opll_patch_10,
|
||||
opll_patch_11,
|
||||
opll_patch_12,
|
||||
opll_patch_13,
|
||||
opll_patch_14,
|
||||
opll_patch_15,
|
||||
opll_patch_drum_0,
|
||||
opll_patch_drum_1,
|
||||
opll_patch_drum_2,
|
||||
opll_patch_drum_3,
|
||||
opll_patch_drum_4,
|
||||
opll_patch_drum_5,
|
||||
opll_patch_max
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t tl;
|
||||
uint8_t dc;
|
||||
uint8_t dm;
|
||||
uint8_t fb;
|
||||
uint8_t am[2];
|
||||
uint8_t vib[2];
|
||||
uint8_t et[2];
|
||||
uint8_t ksr[2];
|
||||
uint8_t multi[2];
|
||||
uint8_t ksl[2];
|
||||
uint8_t ar[2];
|
||||
uint8_t dr[2];
|
||||
uint8_t sl[2];
|
||||
uint8_t rr[2];
|
||||
} opll_patch_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t chip_type;
|
||||
uint32_t cycles;
|
||||
uint32_t slot;
|
||||
const opll_patch_t *patchrom;
|
||||
/* IO */
|
||||
uint8_t write_data;
|
||||
uint8_t write_a;
|
||||
uint8_t write_d;
|
||||
uint8_t write_a_en;
|
||||
uint8_t write_d_en;
|
||||
uint8_t write_fm_address;
|
||||
uint8_t write_fm_data;
|
||||
uint8_t write_mode_address;
|
||||
uint8_t address;
|
||||
uint8_t data;
|
||||
/* Envelope generator */
|
||||
uint8_t eg_counter_state;
|
||||
uint8_t eg_counter_state_prev;
|
||||
uint32_t eg_timer;
|
||||
uint8_t eg_timer_low_lock;
|
||||
uint8_t eg_timer_carry;
|
||||
uint8_t eg_timer_shift;
|
||||
uint8_t eg_timer_shift_lock;
|
||||
uint8_t eg_timer_shift_stop;
|
||||
uint8_t eg_state[18];
|
||||
uint8_t eg_level[18];
|
||||
uint8_t eg_kon;
|
||||
uint32_t eg_dokon;
|
||||
uint8_t eg_off;
|
||||
uint8_t eg_rate;
|
||||
uint8_t eg_maxrate;
|
||||
uint8_t eg_zerorate;
|
||||
uint8_t eg_inc_lo;
|
||||
uint8_t eg_inc_hi;
|
||||
uint8_t eg_rate_hi;
|
||||
uint16_t eg_sl;
|
||||
uint16_t eg_ksltl;
|
||||
uint8_t eg_out;
|
||||
uint8_t eg_silent;
|
||||
/* Phase generator */
|
||||
uint16_t pg_fnum;
|
||||
uint8_t pg_block;
|
||||
uint16_t pg_out;
|
||||
uint32_t pg_inc;
|
||||
uint32_t pg_phase[18];
|
||||
uint32_t pg_phase_next;
|
||||
/* Operator */
|
||||
int16_t op_fb1[9];
|
||||
int16_t op_fb2[9];
|
||||
int16_t op_fbsum;
|
||||
int16_t op_mod;
|
||||
uint8_t op_neg;
|
||||
uint16_t op_logsin;
|
||||
uint16_t op_exp_m;
|
||||
uint16_t op_exp_s;
|
||||
/* Channel */
|
||||
int16_t ch_out;
|
||||
int16_t ch_out_hh;
|
||||
int16_t ch_out_tm;
|
||||
int16_t ch_out_bd;
|
||||
int16_t ch_out_sd;
|
||||
int16_t ch_out_tc;
|
||||
/* LFO */
|
||||
uint16_t lfo_counter;
|
||||
uint8_t lfo_vib_counter;
|
||||
uint16_t lfo_am_counter;
|
||||
uint8_t lfo_am_step;
|
||||
uint8_t lfo_am_dir;
|
||||
uint8_t lfo_am_car;
|
||||
uint8_t lfo_am_out;
|
||||
/* Register set */
|
||||
uint16_t fnum[9];
|
||||
uint8_t block[9];
|
||||
uint8_t kon[9];
|
||||
uint8_t son[9];
|
||||
uint8_t vol[9];
|
||||
uint8_t inst[9];
|
||||
uint8_t rhythm;
|
||||
uint8_t testmode;
|
||||
opll_patch_t patch;
|
||||
uint8_t c_instr;
|
||||
uint8_t c_op;
|
||||
uint8_t c_tl;
|
||||
uint8_t c_dc;
|
||||
uint8_t c_dm;
|
||||
uint8_t c_fb;
|
||||
uint8_t c_am;
|
||||
uint8_t c_vib;
|
||||
uint8_t c_et;
|
||||
uint8_t c_ksr;
|
||||
uint8_t c_ksr_freq;
|
||||
uint8_t c_ksl_freq;
|
||||
uint8_t c_ksl_block;
|
||||
uint8_t c_multi;
|
||||
uint8_t c_ksl;
|
||||
uint8_t c_adrr[3];
|
||||
uint8_t c_sl;
|
||||
uint16_t c_fnum;
|
||||
uint16_t c_block;
|
||||
/* Rhythm mode */
|
||||
int8_t rm_enable;
|
||||
uint32_t rm_noise;
|
||||
uint32_t rm_select;
|
||||
uint8_t rm_hh_bit2;
|
||||
uint8_t rm_hh_bit3;
|
||||
uint8_t rm_hh_bit7;
|
||||
uint8_t rm_hh_bit8;
|
||||
uint8_t rm_tc_bit3;
|
||||
uint8_t rm_tc_bit5;
|
||||
|
||||
int16_t output_m;
|
||||
int16_t output_r;
|
||||
|
||||
} opll_t;
|
||||
|
||||
void OPLL_Reset(opll_t *chip, uint32_t chip_type);
|
||||
void OPLL_Clock(opll_t *chip, int32_t *buffer);
|
||||
void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data);
|
||||
#endif
|
||||
+128
-13
@@ -3,7 +3,7 @@
|
||||
* Sound Hardware
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -44,7 +44,7 @@
|
||||
#define YM2612_CLOCK_RATIO (7*6)
|
||||
|
||||
/* FM output buffer (large enough to hold a whole frame at original chips rate) */
|
||||
#ifdef HAVE_YM3438_CORE
|
||||
#if defined(HAVE_YM3438_CORE) || defined(HAVE_OPLL_CORE)
|
||||
static int fm_buffer[1080 * 2 * 24];
|
||||
#else
|
||||
static int fm_buffer[1080 * 2];
|
||||
@@ -72,6 +72,14 @@ static int ym3438_sample[2];
|
||||
static int ym3438_cycles;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
static opll_t opll;
|
||||
static int opll_accm[18][2];
|
||||
static int opll_sample;
|
||||
static int opll_cycles;
|
||||
static int opll_status;
|
||||
#endif
|
||||
|
||||
/* Run FM chip until required M-cycles */
|
||||
INLINE void fm_update(int cycles)
|
||||
{
|
||||
@@ -126,7 +134,7 @@ static unsigned int YM2612_Read(unsigned int cycles, unsigned int a)
|
||||
if ((a == 0) || (config.ym2612 > YM2612_DISCRETE))
|
||||
{
|
||||
/* synchronize FM chip with CPU */
|
||||
fm_update(cycles - fm_cycles_ratio + 1);
|
||||
fm_update(cycles);
|
||||
|
||||
/* read FM status */
|
||||
if (cycles >= fm_cycles_busy)
|
||||
@@ -167,6 +175,11 @@ static void YM2413_Write(unsigned int cycles, unsigned int a, unsigned int v)
|
||||
YM2413Write(a, v);
|
||||
}
|
||||
|
||||
static unsigned int YM2413_Read(unsigned int cycles, unsigned int a)
|
||||
{
|
||||
return YM2413Read();
|
||||
}
|
||||
|
||||
#ifdef HAVE_YM3438_CORE
|
||||
static void YM3438_Update(int *buffer, int length)
|
||||
{
|
||||
@@ -211,13 +224,66 @@ static void YM3438_Write(unsigned int cycles, unsigned int a, unsigned int v)
|
||||
static unsigned int YM3438_Read(unsigned int cycles, unsigned int a)
|
||||
{
|
||||
/* synchronize FM chip with CPU */
|
||||
fm_update(cycles - fm_cycles_ratio + 1);
|
||||
fm_update(cycles);
|
||||
|
||||
/* read FM status */
|
||||
return OPN2_Read(&ym3438, a);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
static void OPLL2413_Update(int* buffer, int length)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
OPLL_Clock(&opll, opll_accm[opll_cycles]);
|
||||
opll_cycles = (opll_cycles + 1) % 18;
|
||||
if (opll_cycles == 0)
|
||||
{
|
||||
opll_sample = 0;
|
||||
for (j = 0; j < 18; j++)
|
||||
{
|
||||
opll_sample += opll_accm[j][0] + opll_accm[j][1];
|
||||
}
|
||||
}
|
||||
*buffer++ = opll_sample * 16 * opll_status;
|
||||
*buffer++ = opll_sample * 16 * opll_status;
|
||||
}
|
||||
}
|
||||
|
||||
static void OPLL2413_Reset(unsigned int cycles)
|
||||
{
|
||||
/* synchronize FM chip with CPU */
|
||||
fm_update(cycles);
|
||||
|
||||
/* reset FM chip */
|
||||
OPLL_Reset(&opll, opll_type_ym2413);
|
||||
}
|
||||
|
||||
static void OPLL2413_Write(unsigned int cycles, unsigned int a, unsigned int v)
|
||||
{
|
||||
if (!(a&2))
|
||||
{
|
||||
/* synchronize FM chip with CPU */
|
||||
fm_update(cycles);
|
||||
|
||||
/* write FM register */
|
||||
OPLL_Write(&opll, a, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
opll_status = v&1;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int OPLL2413_Read(unsigned int cycles, unsigned int a)
|
||||
{
|
||||
return 0xf8 | opll_status;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void sound_init( void )
|
||||
{
|
||||
/* Initialize FM chip */
|
||||
@@ -257,14 +323,34 @@ void sound_init( void )
|
||||
else
|
||||
{
|
||||
/* YM2413 */
|
||||
YM2413Init();
|
||||
YM_Update = (config.ym2413 & 1) ? YM2413Update : NULL;
|
||||
fm_reset = YM2413_Reset;
|
||||
fm_write = YM2413_Write;
|
||||
fm_read = NULL;
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
if (config.opll)
|
||||
{
|
||||
/* Nuked OPLL */
|
||||
memset(&opll, 0, sizeof(opll));
|
||||
memset(&opll_accm, 0, sizeof(opll_accm));
|
||||
opll_sample = 0;
|
||||
opll_status = 0;
|
||||
YM_Update = (config.ym2413 & 1) ? OPLL2413_Update : NULL;
|
||||
fm_reset = OPLL2413_Reset;
|
||||
fm_write = OPLL2413_Write;
|
||||
fm_read = OPLL2413_Read;
|
||||
|
||||
/* chip is running at ZCLK / 72 = MCLK / 15 / 72 */
|
||||
fm_cycles_ratio = 72 * 15;
|
||||
/* chip is running at internal clock */
|
||||
fm_cycles_ratio = 4 * 15;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
YM2413Init();
|
||||
YM_Update = (config.ym2413 & 1) ? YM2413Update : NULL;
|
||||
fm_reset = YM2413_Reset;
|
||||
fm_write = YM2413_Write;
|
||||
fm_read = YM2413_Read;
|
||||
|
||||
/* chip is running at ZCLK / 72 = MCLK / 15 / 72 */
|
||||
fm_cycles_ratio = 72 * 15;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize PSG chip */
|
||||
@@ -401,7 +487,21 @@ int sound_context_save(uint8 *state)
|
||||
}
|
||||
else
|
||||
{
|
||||
save_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
save_param(&config.opll, sizeof(config.opll));
|
||||
if (config.opll)
|
||||
{
|
||||
save_param(&opll, sizeof(opll));
|
||||
save_param(&opll_accm, sizeof(opll_accm));
|
||||
save_param(&opll_sample, sizeof(opll_sample));
|
||||
save_param(&opll_cycles, sizeof(opll_cycles));
|
||||
save_param(&opll_status, sizeof(opll_status));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
save_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
||||
}
|
||||
}
|
||||
|
||||
bufferptr += psg_context_save(&state[bufferptr]);
|
||||
@@ -437,7 +537,22 @@ int sound_context_load(uint8 *state)
|
||||
}
|
||||
else
|
||||
{
|
||||
load_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
||||
#ifdef HAVE_OPLL_CORE
|
||||
uint8 config_opll;
|
||||
load_param(&config_opll, sizeof(config_opll));
|
||||
if (config_opll)
|
||||
{
|
||||
load_param(&opll, sizeof(opll));
|
||||
load_param(&opll_accm, sizeof(opll_accm));
|
||||
load_param(&opll_sample, sizeof(opll_sample));
|
||||
load_param(&opll_cycles, sizeof(opll_cycles));
|
||||
load_param(&opll_status, sizeof(opll_status));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
load_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
||||
}
|
||||
}
|
||||
|
||||
bufferptr += psg_context_load(&state[bufferptr]);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Sound Hardware
|
||||
*
|
||||
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
||||
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Savestate support
|
||||
*
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
@@ -197,7 +197,7 @@ int state_save(unsigned char *state)
|
||||
|
||||
/* version string */
|
||||
char version[16];
|
||||
strncpy(version,STATE_VERSION,16);
|
||||
memcpy(version,STATE_VERSION,16);
|
||||
save_param(version, 16);
|
||||
|
||||
/* GENESIS */
|
||||
@@ -260,8 +260,8 @@ int state_save(unsigned char *state)
|
||||
if (system_hw == SYSTEM_MCD)
|
||||
{
|
||||
/* CD hardware ID flag */
|
||||
char id[5];
|
||||
strncpy(id,"SCD!",4);
|
||||
char id[4];
|
||||
memcpy(id,"SCD!",4);
|
||||
save_param(id, 4);
|
||||
|
||||
/* CD hardware */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Genesis Plus
|
||||
* Savestate support
|
||||
*
|
||||
* Copyright (C) 2007-2016 Eke-Eke (Genesis Plus GX)
|
||||
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
|
||||
*
|
||||
* Redistribution and use of this code or any derivative works are permitted
|
||||
* provided that the following conditions are met:
|
||||
|
||||
@@ -2167,6 +2167,11 @@ static void vdp_bus_w(unsigned int data)
|
||||
MARK_BG_DIRTY (index);
|
||||
}
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_VRAM_W, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] VRAM 0x%x write -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2210,6 +2215,12 @@ static void vdp_bus_w(unsigned int data)
|
||||
remap_line(v_counter);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_CRAM_W, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] CRAM 0x%x write -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2230,6 +2241,12 @@ static void vdp_bus_w(unsigned int data)
|
||||
render_line(v_counter);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_VSRAM_W, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] VSRAM 0x%x write -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2434,6 +2451,11 @@ static unsigned int vdp_68k_data_r_m5(void)
|
||||
/* read two bytes from VRAM */
|
||||
data = *(uint16 *)&vram[addr & 0xFFFE];
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_VRAM_R, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] VRAM 0x%x read -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2458,6 +2480,11 @@ static unsigned int vdp_68k_data_r_m5(void)
|
||||
/* Unused bits are set using data from next available FIFO entry */
|
||||
data |= (fifo[fifo_idx] & ~0x7FF);
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_VSRAM_R, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] VSRAM 0x%x read -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2475,6 +2502,11 @@ static unsigned int vdp_68k_data_r_m5(void)
|
||||
/* Unused bits are set using data from next available FIFO entry */
|
||||
data |= (fifo[fifo_idx] & ~0xEEE);
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_CRAM_R, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] CRAM 0x%x read -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
@@ -2489,6 +2521,11 @@ static unsigned int vdp_68k_data_r_m5(void)
|
||||
/* Unused bits are set using data from next available FIFO entry */
|
||||
data |= (fifo[fifo_idx] & ~0xFF);
|
||||
|
||||
#ifdef HOOK_CPU
|
||||
if (cpu_hook)
|
||||
cpu_hook(HOOK_VRAM_R, 2, addr, data);
|
||||
#endif
|
||||
|
||||
#ifdef LOGVDP
|
||||
error("[%d(%d)][%d(%d)] 8-bit VRAM 0x%x read -> 0x%x (%x)\n", v_counter, (v_counter + (m68k.cycles - mcycles_vdp)/MCYCLES_PER_LINE)%lines_per_frame, m68k.cycles, m68k.cycles%MCYCLES_PER_LINE, addr, data, m68k_get_reg(M68K_REG_PC));
|
||||
#endif
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
* - Implemented cycle-accurate INI/IND (needed by SMS emulation)
|
||||
* - Fixed Z80 reset
|
||||
* - Made SZHVC_add & SZHVC_sub tables statically allocated
|
||||
* - Fixed compiler warning when BIG_SWITCH is defined
|
||||
* Changes in 3.9:
|
||||
* - Fixed cycle counts for LD IYL/IXL/IYH/IXH,n [Marshmellow]
|
||||
* - Fixed X/Y flags in CCF/SCF/BIT, ZEXALL is happy now [hap]
|
||||
@@ -428,7 +429,9 @@ typedef void (*funcptr)(void);
|
||||
INLINE void prefix##_f0(void); INLINE void prefix##_f1(void); INLINE void prefix##_f2(void); INLINE void prefix##_f3(void); \
|
||||
INLINE void prefix##_f4(void); INLINE void prefix##_f5(void); INLINE void prefix##_f6(void); INLINE void prefix##_f7(void); \
|
||||
INLINE void prefix##_f8(void); INLINE void prefix##_f9(void); INLINE void prefix##_fa(void); INLINE void prefix##_fb(void); \
|
||||
INLINE void prefix##_fc(void); INLINE void prefix##_fd(void); INLINE void prefix##_fe(void); INLINE void prefix##_ff(void); \
|
||||
INLINE void prefix##_fc(void); INLINE void prefix##_fd(void); INLINE void prefix##_fe(void); INLINE void prefix##_ff(void);
|
||||
|
||||
#define FUNCTABLE(tablename,prefix) \
|
||||
static const funcptr tablename[0x100] = { \
|
||||
prefix##_00,prefix##_01,prefix##_02,prefix##_03,prefix##_04,prefix##_05,prefix##_06,prefix##_07, \
|
||||
prefix##_08,prefix##_09,prefix##_0a,prefix##_0b,prefix##_0c,prefix##_0d,prefix##_0e,prefix##_0f, \
|
||||
@@ -464,12 +467,21 @@ static const funcptr tablename[0x100] = { \
|
||||
prefix##_f8,prefix##_f9,prefix##_fa,prefix##_fb,prefix##_fc,prefix##_fd,prefix##_fe,prefix##_ff \
|
||||
}
|
||||
|
||||
PROTOTYPES(Z80op,op);
|
||||
PROTOTYPES(Z80cb,cb);
|
||||
PROTOTYPES(Z80dd,dd);
|
||||
PROTOTYPES(Z80ed,ed);
|
||||
PROTOTYPES(Z80fd,fd);
|
||||
PROTOTYPES(Z80xycb,xycb);
|
||||
PROTOTYPES(Z80op,op)
|
||||
PROTOTYPES(Z80cb,cb)
|
||||
PROTOTYPES(Z80dd,dd)
|
||||
PROTOTYPES(Z80ed,ed)
|
||||
PROTOTYPES(Z80fd,fd)
|
||||
PROTOTYPES(Z80xycb,xycb)
|
||||
|
||||
#ifndef BIG_SWITCH
|
||||
FUNCTABLE(Z80op,op);
|
||||
#endif
|
||||
FUNCTABLE(Z80cb,cb);
|
||||
FUNCTABLE(Z80dd,dd);
|
||||
FUNCTABLE(Z80ed,ed);
|
||||
FUNCTABLE(Z80fd,fd);
|
||||
FUNCTABLE(Z80xycb,xycb);
|
||||
|
||||
/****************************************************************************/
|
||||
/* Burn an odd amount of cycles, that is instructions taking something */
|
||||
|
||||
@@ -28,7 +28,7 @@ typedef struct
|
||||
uint8 padtype;
|
||||
} t_input_config;
|
||||
|
||||
struct
|
||||
typedef struct
|
||||
{
|
||||
char version[16];
|
||||
uint8 hq_fm;
|
||||
@@ -62,7 +62,7 @@ struct
|
||||
uint8 lcd;
|
||||
uint8 render;
|
||||
t_input_config input[MAX_INPUTS];
|
||||
} config;
|
||||
} t_config;
|
||||
|
||||
extern char GG_ROM[256];
|
||||
extern char AR_ROM[256];
|
||||
@@ -76,6 +76,8 @@ extern char MS_BIOS_US[256];
|
||||
extern char MS_BIOS_EU[256];
|
||||
extern char MS_BIOS_JP[256];
|
||||
|
||||
extern t_config config;
|
||||
|
||||
void osd_input_update(void);
|
||||
int load_archive(char *filename, unsigned char *buffer, int maxsize, char *extension);
|
||||
extern void ROMCheatUpdate(void);
|
||||
|
||||
Reference in New Issue
Block a user