Mouse 2 JoyStick

This commit is contained in:
tudnai 2020-05-20 22:22:44 -07:00
parent 1b4985d3c8
commit 26341faff2
4 changed files with 66 additions and 45 deletions

View File

@ -494,6 +494,9 @@
<PersistentString
value = "clkfrm">
</PersistentString>
<PersistentString
value = "mouseLocation">
</PersistentString>
<PersistentString
value = "txtArr">
</PersistentString>

View File

@ -364,42 +364,51 @@ class ViewController: NSViewController {
kbdUp()
}
// override func flagsChanged(with event: NSEvent) {
// switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
// case [.shift]:
// print("shift key is pressed")
// case [.control]:
// print("control key is pressed")
// case [.option] :
// print("option key is pressed")
// case [.command]:
// print("Command key is pressed")
// case [.control, .shift]:
// print("control-shift keys are pressed")
// case [.option, .shift]:
// print("option-shift keys are pressed")
// case [.command, .shift]:
// print("command-shift keys are pressed")
// case [.control, .option]:
// print("control-option keys are pressed")
// case [.control, .command]:
// print("control-command keys are pressed")
// case [.option, .command]:
// print("option-command keys are pressed")
// case [.shift, .control, .option]:
// print("shift-control-option keys are pressed")
// case [.shift, .control, .command]:
// print("shift-control-command keys are pressed")
// case [.control, .option, .command]:
// print("control-option-command keys are pressed")
// case [.shift, .command, .option]:
// print("shift-command-option keys are pressed")
// case [.shift, .control, .option, .command]:
// print("shift-control-option-command keys are pressed")
// default:
// print("no modifier keys are pressed")
// }
// }
override func flagsChanged(with event: NSEvent) {
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
case [.shift]:
print("shift key is pressed")
case [.control]:
print("control key is pressed")
case [.option] :
setIO(0xC061, 1 << 7);
print("option key is pressed")
case [.command]:
print("Command key is pressed")
setIO(0xC062, 1 << 7);
case [.control, .shift]:
print("control-shift keys are pressed")
case [.option, .shift]:
print("option-shift keys are pressed")
case [.command, .shift]:
print("command-shift keys are pressed")
case [.control, .option]:
print("control-option keys are pressed")
case [.control, .command]:
print("control-command keys are pressed")
case [.option, .command]:
print("option-command keys are pressed")
case [.shift, .control, .option]:
print("shift-control-option keys are pressed")
case [.shift, .control, .command]:
print("shift-control-command keys are pressed")
case [.control, .option, .command]:
print("control-option-command keys are pressed")
case [.shift, .command, .option]:
print("shift-command-option keys are pressed")
case [.shift, .control, .option, .command]:
print("shift-control-option-command keys are pressed")
case [.function]:
print("function key is pressed")
case [.capsLock]:
print("capsLock key is pressed")
default:
setIO(0xC061, 0);
setIO(0xC062, 0);
print("no modifier keys are pressed")
}
}
@ -414,9 +423,13 @@ class ViewController: NSViewController {
var halted = true;
var mouseLocation = NSPoint.zero
func Update() {
// clk_6502_per_frm_max = 0
clkCounter += Double(clkfrm)
// we start a new frame from here, so CPU is running even while rendering
clkfrm = 0
@ -569,8 +582,14 @@ class ViewController: NSViewController {
// stream speaker from a separate thread from the simulation
// TODO: Do we need to do this from here?
// spkr_update()
// Mouse 2 JoyStick (Game Controller / Paddle)
self.mouseLocation = self.view.window!.mouseLocationOutsideOfEventStream
pdl_valarr[0] = Double(self.mouseLocation.x / (self.displayField.frame.width) )
pdl_valarr[1] = 1 - Double(self.mouseLocation.y / (self.displayField.frame.height) )
}
#if SPEEDTEST
#else
if ( !halted ) {

View File

@ -148,6 +148,8 @@ extern uint8_t * const RAM;
extern uint8_t * const MEM; // Pointer to the Shadow Memory Map so we can use this from Swift//extern uint8_t * AUX_VID_RAM;
extern uint32_t * videoMemPtr;
extern double * pdl_valarr;
//extern void hires_Update(void);
extern double mips;
@ -161,7 +163,7 @@ extern void tst6502(void);
extern void m6502_ColdReset( const char * bundlePath, const char * romFilePath );
extern void m6502_Run(void);
extern void kbdInput ( uint8_t code );
extern void kbdUp ();
extern void kbdUp (void);
extern void setIO ( uint16_t ioaddr, uint8_t val );
extern void interrupt_IRQ(void);

View File

@ -11,14 +11,16 @@
#include "6502.h"
#define PDL_MAX_TIME 3300.0
// TODO: We may need a joystick calibration
#define PDL_MAX_TIME 3072.0 // 3300.0
#define PDL_TIME_DECAY ( 255.0 / PDL_MAX_TIME )
uint64_t pdl_reset_time = 0;
uint64_t pdl_current_time = 0;
uint64_t pdl_elapsed_time = 0;
float pdl_value[4] = { 0.5, 0.0, 1.0, 0.1 };
double pdl_value[4] = { 0.5, 0.5, 0.5, 0.5 };
double * pdl_valarr = pdl_value;
INLINE uint8_t pdl_reset() {
pdl_reset_time = m6502.clktime + clkfrm;
@ -29,13 +31,8 @@ INLINE uint8_t pdl_reset() {
INLINE uint8_t pdl_read( uint8_t pdl ) {
pdl_current_time = m6502.clktime + clkfrm;
pdl_elapsed_time = pdl_current_time - pdl_reset_time;
double normalized_time = pdl_elapsed_time / PDL_MAX_TIME; // 0: started, >= 1 ended
// printf("PDL%d: %d\n", pdl, (uint8_t) ( pdl_value[pdl] * 512 * ( 1 - (pdl_elapsed_time / PDL_MAX_TIME) )) );
// return (uint8_t) ( pdl_value[pdl] * 512 * ( 1 - (pdl_elapsed_time / PDL_MAX_TIME) ) );
return normalized_time >= pdl_value[pdl] ? 0 : 0x80;
return normalized_time >= pdl_value[pdl] ? 0 : 1 << 7;
}
#endif /* paddle_h */