OSX: Basic keyboard input

This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2015-08-08 07:14:06 +02:00 committed by TwistedUmbrella
parent 5d46b77387
commit 45f0a47eec
6 changed files with 78 additions and 16 deletions

View File

@ -448,17 +448,7 @@ return;
if ('D' == key) { kcode[port] &= ~DPad_Left; }
if ('C' == key) { kcode[port] &= ~DPad_Right; }
#else
if ('b' == key) { kcode[port] &= ~Btn_C; }
if ('v' == key) { kcode[port] &= ~Btn_A; }
if ('c' == key) { kcode[port] &= ~Btn_B; }
if ('x' == key) { kcode[port] &= ~Btn_Y; }
if ('z' == key) { kcode[port] &= ~Btn_X; }
if ('i' == key) { kcode[port] &= ~DPad_Up; }
if ('k' == key) { kcode[port] &= ~DPad_Down; }
if ('j' == key) { kcode[port] &= ~DPad_Left; }
if ('l' == key) { kcode[port] &= ~DPad_Right; }
#endif
if (0x0A== key) { kcode[port] &= ~Btn_Start; }
 
#ifdef TARGET_PANDORA
if ('q' == key){ die("death by escape key"); }
#endif

View File

@ -186,7 +186,7 @@
84B7BF7B1B72720200F9733F /* gltex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BE9F1B72720200F9733F /* gltex.cpp */; };
84B7BF7E1B72720200F9733F /* TexCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BEA51B72720200F9733F /* TexCache.cpp */; };
84B7BF7F1B72720200F9733F /* stdclass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BEA71B72720200F9733F /* stdclass.cpp */; };
84B7BF831B727AD700F9733F /* osx-main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BF821B727AD700F9733F /* osx-main.cpp */; };
84B7BF831B727AD700F9733F /* osx-main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BF821B727AD700F9733F /* osx-main.mm */; };
84B7BF861B72871600F9733F /* EmuGLView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BF851B72871600F9733F /* EmuGLView.swift */; };
/* End PBXBuildFile section */
@ -519,7 +519,7 @@
84B7BEA71B72720200F9733F /* stdclass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = stdclass.cpp; path = ../../../core/stdclass.cpp; sourceTree = "<group>"; };
84B7BEA81B72720200F9733F /* stdclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stdclass.h; path = ../../../core/stdclass.h; sourceTree = "<group>"; };
84B7BEA91B72720200F9733F /* types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = types.h; path = ../../../core/types.h; sourceTree = "<group>"; };
84B7BF821B727AD700F9733F /* osx-main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "osx-main.cpp"; sourceTree = "<group>"; };
84B7BF821B727AD700F9733F /* osx-main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "osx-main.mm"; sourceTree = "<group>"; };
84B7BF841B72821900F9733F /* emulator-osx-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "emulator-osx-Bridging-Header.h"; sourceTree = "<group>"; };
84B7BF851B72871600F9733F /* EmuGLView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmuGLView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -568,7 +568,7 @@
84A388BA1B1CDD3E000166C0 /* Images.xcassets */,
84A388BC1B1CDD3E000166C0 /* MainMenu.xib */,
84A388B61B1CDD3E000166C0 /* Supporting Files */,
84B7BF821B727AD700F9733F /* osx-main.cpp */,
84B7BF821B727AD700F9733F /* osx-main.mm */,
84B7BF841B72821900F9733F /* emulator-osx-Bridging-Header.h */,
84B7BF851B72871600F9733F /* EmuGLView.swift */,
);
@ -1440,7 +1440,7 @@
84B7BEB61B72720200F9733F /* sha256.cpp in Sources */,
84B7BF5A1B72720200F9733F /* cdi.cpp in Sources */,
84B7BEF91B72720200F9733F /* zip_get_archive_comment.c in Sources */,
84B7BF831B727AD700F9733F /* osx-main.cpp in Sources */,
84B7BF831B727AD700F9733F /* osx-main.mm in Sources */,
84B7BEE51B72720200F9733F /* zip_dirent.c in Sources */,
84B7BF761B72720200F9733F /* reios.cpp in Sources */,
84B7BEBF1B72720200F9733F /* pngmem.c in Sources */,

View File

@ -24,5 +24,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

View File

@ -10,6 +10,10 @@ import Cocoa
class EmuGLView: NSOpenGLView {
override var acceptsFirstResponder: Bool {
return true;
}
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
@ -59,4 +63,12 @@ class EmuGLView: NSOpenGLView {
self.needsDisplay = true;
}
override func keyDown(e: NSEvent) {
emu_key_input(e.characters!, 1);
}
override func keyUp(e: NSEvent) {
emu_key_input(e.characters!, 0);
}
}

View File

@ -12,4 +12,5 @@
void emu_main();
bool emu_single_frame(int w, int h);
void emu_gles_init();
void emu_key_input(const char* key, int state);
#endif

View File

@ -5,6 +5,7 @@
// Created by admin on 8/5/15.
// Copyright (c) 2015 reicast. All rights reserved.
//
#import <Carbon/Carbon.h>
#include "types.h"
#include <sys/stat.h>
@ -25,7 +26,7 @@ int msgboxf(const wchar* text,unsigned int type,...)
}
u16 kcode[4];
u16 kcode[4] = { 0xFFFF };
u32 vks[4];
s8 joyx[4],joyy[4];
u8 rt[4],lt[4];
@ -117,3 +118,60 @@ extern "C" bool emu_single_frame(int w, int h) {
extern "C" void emu_gles_init() {
gles_init();
}
enum DCPad {
Btn_C = 1,
Btn_B = 1<<1,
Btn_A = 1<<2,
Btn_Start = 1<<3,
DPad_Up = 1<<4,
DPad_Down = 1<<5,
DPad_Left = 1<<6,
DPad_Right = 1<<7,
Btn_Z = 1<<8,
Btn_Y = 1<<9,
Btn_X = 1<<10,
Btn_D = 1<<11,
DPad2_Up = 1<<12,
DPad2_Down = 1<<13,
DPad2_Left = 1<<14,
DPad2_Right = 1<<15,
Axis_LT= 0x10000,
Axis_RT= 0x10001,
Axis_X= 0x20000,
Axis_Y= 0x20001,
};
void handle_key(int dckey, int state) {
if (state)
kcode[0] &= ~dckey;
else
kcode[0] |= dckey;
}
void handle_trig(u8* dckey, int state) {
if (state)
dckey[0] = 255;
else
dckey[0] = 0;
}
extern "C" void emu_key_input(char* keyt, int state) {
int key = keyt[0];
switch(key) {
case 'z': handle_key(Btn_X, state); break;
case 'x': handle_key(Btn_Y, state); break;
case 'c': handle_key(Btn_B, state); break;
case 'v': handle_key(Btn_A, state); break;
case 'a': handle_trig(lt, state); break;
case 's': handle_trig(rt, state); break;
case 'j': handle_key(DPad_Left, state); break;
case 'k': handle_key(DPad_Down, state); break;
case 'l': handle_key(DPad_Right, state); break;
case 'i': handle_key(DPad_Up, state); break;
case 0xa: handle_key(Btn_Start, state); break;
}
}