Skip to content

Commit

Permalink
1. fixes rendering when using Metal as the renderer - does NOT work f…
Browse files Browse the repository at this point in the history
…or OpenGL (black screen)

2.  adds support for game controllers
  • Loading branch information
proskd committed Aug 14, 2024
1 parent c80fcf5 commit 02d0bd5
Showing 1 changed file with 49 additions and 2 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

0 comments on commit 02d0bd5

Please sign in to comment.