Skip to content

Commit

Permalink
Merge pull request #1 from proskd/fix-3do
Browse files Browse the repository at this point in the history
Fix 3DO Emulation (Metal only)
  • Loading branch information
JoeMatt authored Aug 14, 2024
2 parents 7376c32 + 02d0bd5 commit 413d29c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
51 changes: 49 additions & 2 deletions FreeDOGameCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ - (GLenum)internalPixelFormat {
}

- (GLenum)pixelType {
return GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
// return GL_UNSIGNED_INT_8_8_8_8_REV;
return GL_UNSIGNED_BYTE;
}

- (const void *)videoBuffer {
Expand Down Expand Up @@ -541,6 +540,52 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
}

#pragma mark - Input

- (void)updateControllers
{
if ([self.controller1 extendedGamepad])
{
GCExtendedGamepad *gamepad = [self.controller1 extendedGamepad];
GCControllerDirectionPad *dpad = [gamepad dpad];

(dpad.up.isPressed || gamepad.leftThumbstick.up.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONUP : internal_input_state[0].buttons&=~INPUTBUTTONUP;
(dpad.down.isPressed || gamepad.leftThumbstick.down.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONDOWN : internal_input_state[0].buttons&=~INPUTBUTTONDOWN;
(dpad.left.isPressed || gamepad.leftThumbstick.left.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONLEFT : internal_input_state[0].buttons&=~INPUTBUTTONLEFT;
(dpad.right.isPressed || gamepad.leftThumbstick.right.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONRIGHT : internal_input_state[0].buttons&=~INPUTBUTTONRIGHT;

(gamepad.buttonA.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONA : internal_input_state[0].buttons&=~INPUTBUTTONA;
(gamepad.buttonB.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONB : internal_input_state[0].buttons&=~INPUTBUTTONB;
(gamepad.buttonY.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONC : internal_input_state[0].buttons&=~INPUTBUTTONC;

(gamepad.leftShoulder.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONL : internal_input_state[0].buttons&=~INPUTBUTTONL;
(gamepad.rightShoulder.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONR : internal_input_state[0].buttons&=~INPUTBUTTONR;

(gamepad.leftTrigger.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONX : internal_input_state[0].buttons&=~INPUTBUTTONX;
(gamepad.rightTrigger.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONP : internal_input_state[0].buttons&=~INPUTBUTTONP;

}
else if ([self.controller1 gamepad])
{
GCGamepad *gamepad = [self.controller1 gamepad];
GCControllerDirectionPad *dpad = [gamepad dpad];

(dpad.up.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONUP : internal_input_state[0].buttons&=~INPUTBUTTONP;
(dpad.down.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONDOWN : internal_input_state[0].buttons&=~INPUTBUTTONDOWN;
(dpad.left.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONLEFT : internal_input_state[0].buttons&=~INPUTBUTTONLEFT;
(dpad.right.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONRIGHT : internal_input_state[0].buttons&=~INPUTBUTTONRIGHT;

(gamepad.buttonA.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONA : internal_input_state[0].buttons&=~INPUTBUTTONA;
(gamepad.buttonB.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONB : internal_input_state[0].buttons&=~INPUTBUTTONB;
(gamepad.buttonY.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONC : internal_input_state[0].buttons&=~INPUTBUTTONC;

(gamepad.leftShoulder.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONL : internal_input_state[0].buttons&=~INPUTBUTTONL;
(gamepad.rightShoulder.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONR : internal_input_state[0].buttons&=~INPUTBUTTONR;

(gamepad.buttonX.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONX : internal_input_state[0].buttons&=~INPUTBUTTONX;
//nothing to assign to P for legacy gamepad support
// (gamepad.buttonX.isPressed) ? internal_input_state[0].buttons|=INPUTBUTTONP : internal_input_state[0].buttons&=~INPUTBUTTONP;
}
}
- (void)didPush3DOButton:(PV3DOButton)button forPlayer:(NSInteger)player {
player--;

Expand Down Expand Up @@ -718,6 +763,8 @@ - (void)loadBIOSes {
biosRom1Copy = (unsigned char *)malloc(len);
memcpy(biosRom1Copy, [data bytes], len);

//there's supposed to be a 3rd BIOS here, so add that later

// "ROM 2 Japanese Character ROM" / Set it if we find it. It's not requiered for soem JAP games. We still have to init the memory tho
NSString *rom2Path = [[self BIOSPath] stringByAppendingPathComponent:@"rom2.rom"];
data = [NSData dataWithContentsOfFile:rom2Path];
Expand Down
35 changes: 29 additions & 6 deletions libfreedo/arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,37 @@ unsigned char * _arm_Init()

void _arm_Destroy()
{
io_interface(EXT_WRITE_NVRAM,pNVRam);//_3do_SaveNVRAM(pNVRam);
io_interface(EXT_WRITE_NVRAM,pNVRam);//_3do_SaveNVRAM(pNVRam);

if (profiling != NULL) {
delete []profiling;
delete []profiling2;
delete []profiling3;
delete []pNVRam;
delete []pRom;
delete []pRam;
profiling = NULL;
}

if (profiling2 != NULL) {
delete []profiling2;
profiling2 = NULL;
}

if (profiling3 != NULL) {
delete []profiling3;
profiling3 = NULL;
}

if (pNVRam != NULL) {
delete []pNVRam;
pNVRam = NULL;
}

if (pRom != NULL) {
delete []pRom;
pRom = NULL;
}

if (pRam != NULL) {
delete []pRam;
pRam = NULL;
}
}

void _arm_Reset()
Expand Down

0 comments on commit 413d29c

Please sign in to comment.