reformatted

This commit is contained in:
Markus Fröschle
2014-05-11 20:38:33 +00:00
parent ccec42e55c
commit 65a7986e34
2 changed files with 231 additions and 207 deletions

View File

@@ -1,2 +1,2 @@
~/Dokumente/Development/workspace/BaS_gcc/include
include
/usr/m68k-elf/include

View File

@@ -40,7 +40,8 @@ static unsigned char tx_queue[QUEUE_LEN];
static unsigned char wptr = 0, rptr = 0;
// structure to keep track of ikbd state
static struct {
static struct
{
unsigned char cmd;
unsigned char state;
unsigned char expect;
@@ -55,44 +56,52 @@ static struct {
// #define IKBD_DEBUG
void ikbd_init() {
void ikbd_init()
{
// reset ikbd state
memset(&ikbd, 0, sizeof(ikbd));
ikbd.state = IKBD_DEFAULT;
}
static void enqueue(unsigned char b) {
if(((wptr + 1)&(QUEUE_LEN-1)) == rptr) {
static void enqueue(unsigned char b)
{
if (((wptr + 1)&(QUEUE_LEN-1)) == rptr)
{
xprintf("IKBD: !!!!!!! tx queue overflow !!!!!!!!!\n");
return;
}
tx_queue[wptr] = b;
wptr = (wptr+1)&(QUEUE_LEN-1);
wptr = (wptr + 1) & (QUEUE_LEN - 1);
}
// convert internal joystick format into atari ikbd format
static unsigned char joystick_map2ikbd(unsigned in) {
static unsigned char joystick_map2ikbd(unsigned in)
{
unsigned char out = 0;
if(in & JOY_UP) out |= 0x01;
if(in & JOY_DOWN) out |= 0x02;
if(in & JOY_LEFT) out |= 0x04;
if(in & JOY_RIGHT) out |= 0x08;
if(in & JOY_BTN1) out |= 0x80;
if (in & JOY_UP) out |= 0x01;
if (in & JOY_DOWN) out |= 0x02;
if (in & JOY_LEFT) out |= 0x04;
if (in & JOY_RIGHT) out |= 0x08;
if (in & JOY_BTN1) out |= 0x80;
return out;
}
// process inout from atari core into ikbd
void ikbd_handle_input(unsigned char cmd) {
void ikbd_handle_input(unsigned char cmd)
{
// expecting a second byte for command
if(ikbd.expect) {
if (ikbd.expect)
{
ikbd.expect--;
// last byte of command received
if(!ikbd.expect) {
switch(ikbd.cmd) {
if (!ikbd.expect)
{
switch(ikbd.cmd)
{
case 0x07: // set mouse button action
xprintf("IKBD: mouse button action = %x\n", cmd);
@@ -117,7 +126,8 @@ void ikbd_handle_input(unsigned char cmd) {
ikbd.cmd = cmd;
switch(cmd) {
switch(cmd)
{
case 0x07:
xprintf("IKBD: Set mouse button action");
ikbd.expect = 1;
@@ -205,7 +215,8 @@ void ikbd_handle_input(unsigned char cmd) {
void ikbd_poll(void) {
static int mtimer = 0;
if(CheckTimer(mtimer)) {
if (CheckTimer(mtimer))
{
mtimer = GetTimer(10);
// check for incoming ikbd data
@@ -227,28 +238,33 @@ void ikbd_poll(void) {
SPI(tx_queue[rptr]);
DisableIO();
rptr = (rptr+1)&(QUEUE_LEN-1);
rptr = (rptr + 1) & (QUEUE_LEN - 1);
}
void ikbd_joystick(unsigned char joystick, unsigned char map) {
void ikbd_joystick(unsigned char joystick, unsigned char map)
{
// todo: suppress events for joystick 0 as long as mouse
// is enabled?
if(ikbd.state & IKBD_STATE_JOYSTICK_EVENT_REPORTING) {
if (ikbd.state & IKBD_STATE_JOYSTICK_EVENT_REPORTING)
{
#ifdef IKBD_DEBUG
xprintf("IKBD: joy %d %x\n", joystick, map);
#endif
// only report joystick data for joystick 0 if the mouse is disabled
if((ikbd.state & IKBD_STATE_MOUSE_DISABLED) || (joystick == 1)) {
if ((ikbd.state & IKBD_STATE_MOUSE_DISABLED) || (joystick == 1))
{
enqueue(0xfe + joystick);
enqueue(joystick_map2ikbd(map));
}
if(!(ikbd.state & IKBD_STATE_MOUSE_DISABLED)) {
if (!(ikbd.state & IKBD_STATE_MOUSE_DISABLED))
{
// the fire button also generates a mouse event if
// mouse reporting is enabled
if((map & JOY_BTN1) != (ikbd.joystick[joystick] & JOY_BTN1)) {
if ((map & JOY_BTN1) != (ikbd.joystick[joystick] & JOY_BTN1))
{
// generate mouse event (ikbd_joystick_buttons is evaluated inside
// user_io_mouse)
ikbd.joystick[joystick] = map;
@@ -265,15 +281,17 @@ void ikbd_joystick(unsigned char joystick, unsigned char map) {
ikbd.joystick[joystick] = map;
}
void ikbd_keyboard(unsigned char code) {
void ikbd_keyboard(unsigned char code)
{
#ifdef IKBD_DEBUG
xprintf("IKBD: send keycode %x%s\n", code&0x7f, (code&0x80)?" BREAK":"");
#endif
enqueue(code);
}
void ikbd_mouse(uint8_t b, int8_t x, int8_t y) {
if(ikbd.state & IKBD_STATE_MOUSE_DISABLED)
void ikbd_mouse(uint8_t b, int8_t x, int8_t y)
{
if (ikbd.state & IKBD_STATE_MOUSE_DISABLED)
return;
// joystick and mouse buttons are wired together in
@@ -283,9 +301,11 @@ void ikbd_mouse(uint8_t b, int8_t x, int8_t y) {
static unsigned char b_old = 0;
// monitor state of two mouse buttons
if(b != b_old) {
if (b != b_old)
{
// check if mouse buttons are supposed to be treated like keys
if(ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY) {
if (ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
{
// Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
// handle left mouse button
@@ -297,15 +317,19 @@ void ikbd_mouse(uint8_t b, int8_t x, int8_t y) {
}
#if 0
if(ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY) {
if(ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY)
{
b = 0;
// if mouse position is 0/0 quit here
if(!x && !y) return;
}
#endif
if(ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE) {
} else {
if (ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE)
{
}
else
{
// atari has mouse button bits swapped
enqueue(0xf8|((b&1)?2:0)|((b&2)?1:0));
enqueue(x);