mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-04-24 19:50:31 +00:00
Start to refactor code attempting to avoid incompatibility with minimig
This commit is contained in:
4
Makefile
4
Makefile
@@ -8,7 +8,7 @@ DUMP = $(BASE)-objdump
|
||||
TODAY = `date +"%m/%d/%y"`
|
||||
|
||||
PRJ = firmware
|
||||
SRC = Cstartup_SAM7.c fat.c fdd.c firmware.c fpga.c hardware.c spi.c hdd.c main.c menu.c mmc.c osd.c syscalls.c user_io.c boot.c rafile.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c mist_cfg.c archie.c
|
||||
SRC = Cstartup_SAM7.c fat.c fdd.c firmware.c fpga.c hardware.c spi.c hdd.c main.c menu.c mmc.c osd.c state.c syscalls.c user_io.c boot.c rafile.c idxfile.c config.c tos.c ikbd.c xmodem.c ini_parser.c mist_cfg.c archie.c
|
||||
SRC += usb/max3421e.c usb/usb.c usb/hub.c usb/hid.c usb/hidparser.c usb/timer.c usb/asix.c usb/pl2303.c usb/usbrtc.c usb/joymapping.c
|
||||
# SRC += usb/storage.c
|
||||
SRC += cdc_enumerate.c cdc_control.c
|
||||
@@ -47,7 +47,7 @@ reset:
|
||||
$(MKUPG): $(MKUPG).c
|
||||
gcc -o $@ $<
|
||||
|
||||
flash: $(PRJ).bin
|
||||
flash: $(PRJ).hex $(PRJ).upg $(PRJ).bin
|
||||
openocd -f interface/$(INTERFACE).cfg -f target/at91sam7sx.cfg --command "adapter_khz $(ADAPTER_KHZ); init; reset init; flash protect 0 0 7 off; sleep 1; arm7_9 fast_memory_access enable; flash write_bank 0 $(PRJ).bin 0x0; resume; shutdown"
|
||||
|
||||
flash_sam: $(PRJ).hex
|
||||
|
||||
18
menu.c
18
menu.c
@@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "mmc.h"
|
||||
#include "fat.h"
|
||||
#include "osd.h"
|
||||
#include "state.h"
|
||||
#include "fpga.h"
|
||||
#include "fdd.h"
|
||||
#include "hdd.h"
|
||||
@@ -430,6 +431,14 @@ void get_joystick_id ( char *usb_id, unsigned char joy_num, short raw_id ) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned int keys_ps2[6] = { 0,0,0,0,0,0 };
|
||||
void StateKeyboardPressedPS2(unsigned int *keycodes) {
|
||||
unsigned i=0;
|
||||
for(i=0; i<6; i++) {
|
||||
keycodes[i]=keys_ps2[i];
|
||||
}
|
||||
}
|
||||
|
||||
void HandleUI(void)
|
||||
{
|
||||
@@ -444,7 +453,6 @@ void HandleUI(void)
|
||||
static const char *helptext;
|
||||
static char helpstate=0;
|
||||
unsigned char keys[6] = {0,0,0,0,0,0};
|
||||
unsigned int keys_ps2[6] = {0,0,0,0,0,0};
|
||||
|
||||
/* check joystick status */
|
||||
char joy_string[32];
|
||||
@@ -1047,14 +1055,14 @@ void HandleUI(void)
|
||||
OsdSetTitle("Keyboard", 0);
|
||||
menustate = MENU_8BIT_KEYTEST2;
|
||||
parentstate=MENU_8BIT_KEYTEST1;
|
||||
OsdKeyboardPressed(keys);
|
||||
StateKeyboardPressed(keys);
|
||||
OsdWrite(0, "", 0, 0);
|
||||
OsdWrite(1, " USB scancodes", 0, 0);
|
||||
siprintf(s, " %2x %2x %2x %2x %2x %2x", keys[0], keys[1], keys[2], keys[3], keys[4], keys[5]);
|
||||
OsdWrite(2, s, 0,0);
|
||||
OsdWrite(3, "", 0, 0);
|
||||
OsdWrite(4, " PS/2 scancodes", 0, 0);
|
||||
OsdKeyboardPressedPS2(keys_ps2);
|
||||
//OsdKeyboardPressedPS2(keys_ps2);
|
||||
siprintf(s, " %3x%3x%3x%3x%3x%3x", keys_ps2[0], keys_ps2[1], keys_ps2[2], keys_ps2[3], keys_ps2[4], keys_ps2[5]);
|
||||
OsdWrite(5, s, 0, 0);
|
||||
OsdWrite(6, " ", 0, 0);
|
||||
@@ -1062,10 +1070,10 @@ void HandleUI(void)
|
||||
break;
|
||||
|
||||
case MENU_8BIT_KEYTEST2:
|
||||
OsdKeyboardPressed(keys);
|
||||
StateKeyboardPressed(keys);
|
||||
siprintf(s, " %2x %2x %2x %2x %2x %2x", keys[0], keys[1], keys[2], keys[3], keys[4], keys[5]);
|
||||
OsdWrite(2, s, 0,0);
|
||||
OsdKeyboardPressedPS2(keys_ps2);
|
||||
//StateKeyboardPressedPS2(keys_ps2);
|
||||
siprintf(s, " %3x%3x%3x%3x%3x%3x", keys_ps2[0], keys_ps2[1], keys_ps2[2], keys_ps2[3], keys_ps2[4], keys_ps2[5]);
|
||||
OsdWrite(5, s, 0, 0);
|
||||
// allow allow exit when hitting space and ESC
|
||||
|
||||
6
osd.h
6
osd.h
@@ -168,12 +168,6 @@ void OsdUsbIdSetB(unsigned int vid, unsigned int pid);
|
||||
unsigned int OsdUsbVidGetB();
|
||||
unsigned int OsdUsbPidGetB();
|
||||
|
||||
// keyboard status
|
||||
void OsdKeyboardSet( unsigned char modifier, char* pressed, int* pressed_ps2); //get usb and ps2 codes
|
||||
unsigned char OsdKeyboardModifiers();
|
||||
void OsdKeyboardPressed(char *pressed);
|
||||
void OsdKeyboardPressedPS2(unsigned int *keycodes);
|
||||
|
||||
// get/set core currently loaded
|
||||
void OsdCoreNameSet(const char* str);
|
||||
char* OsdCoreName();
|
||||
|
||||
232
state.c
Normal file
232
state.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
Copyright 2005, 2006, 2007 Dennis van Weeren
|
||||
Copyright 2008, 2009 Jakub Bednarski
|
||||
|
||||
This file is part of Minimig
|
||||
|
||||
Minimig is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Minimig is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
This code keeps status of MiST state
|
||||
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "stdio.h"
|
||||
|
||||
#include "state.h"
|
||||
//#include "charrom.h"
|
||||
|
||||
|
||||
/* latest joystick state */
|
||||
|
||||
void joy_reset ( mist_joystick_t joy ) {
|
||||
joy.vid = 0;
|
||||
joy.pid = 0;
|
||||
joy.num_buttons=1; // DB9 has 1 button
|
||||
joy.state=0;
|
||||
joy.state_extra=0;
|
||||
joy.usb_state=0;
|
||||
joy.usb_state_extra=0;
|
||||
joy.turbo=50;
|
||||
joy.turbo_counter=0;
|
||||
joy.turbo_mask=0x30; // A and B buttons
|
||||
joy.turbo_state=0xFF; // flip state (0 or 1)
|
||||
}
|
||||
|
||||
static mist_joystick_t mist_joy[3] = { // 3rd one is dummy, used to store defaults
|
||||
{
|
||||
.vid = 0,
|
||||
.pid = 0,
|
||||
.num_buttons=1, // DB9 has 1 button
|
||||
.state=0,
|
||||
.state_extra=0,
|
||||
.usb_state=0,
|
||||
.usb_state_extra=0,
|
||||
.turbo=50,
|
||||
.turbo_counter=0,
|
||||
.turbo_mask=0x30, // A and B buttons
|
||||
.turbo_state=0xFF // flip state (0 or 1)
|
||||
},
|
||||
{
|
||||
.vid = 0,
|
||||
.pid = 0,
|
||||
.num_buttons=1, // DB9 has 1 button
|
||||
.state=0,
|
||||
.state_extra=0,
|
||||
.usb_state=0,
|
||||
.usb_state_extra=0,
|
||||
.turbo=0,
|
||||
.turbo_counter=0,
|
||||
.turbo_mask=0x30, // A and B buttons
|
||||
.turbo_state=0xFF // flip state (0 or 1)
|
||||
},
|
||||
{
|
||||
.vid = 0,
|
||||
.pid = 0,
|
||||
.num_buttons=1, // DB9 has 1 button
|
||||
.state=0,
|
||||
.state_extra=0,
|
||||
.usb_state=0,
|
||||
.usb_state_extra=0,
|
||||
.turbo=0,
|
||||
.turbo_counter=0,
|
||||
.turbo_mask=0x30, // A and B buttons
|
||||
.turbo_state=0xFF // flip state (0 or 1)
|
||||
}
|
||||
};
|
||||
|
||||
void StateNumJoysticksSet(unsigned char num) {
|
||||
mist_joystick_t joy;
|
||||
//joysticks = num;
|
||||
if(1) { //joysticks<3) {
|
||||
//clear USB joysticks
|
||||
if(1) //joysticks<2)
|
||||
joy = mist_joy[0];
|
||||
else
|
||||
joy = mist_joy[1];
|
||||
joy.vid=0;
|
||||
joy.vid=0;
|
||||
joy.num_buttons=1;
|
||||
joy.state=0;
|
||||
joy.state_extra=0;
|
||||
joy.usb_state=0;
|
||||
joy.usb_state_extra=0;
|
||||
}
|
||||
}
|
||||
|
||||
// state of MIST virtual joystick
|
||||
|
||||
mist_joystick_t StateJoyGet(uint8_t joy_num) {
|
||||
if(joy_num>1) return mist_joy[2];
|
||||
return mist_joy[joy_num];
|
||||
}
|
||||
|
||||
void StateJoySet(unsigned char c, uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].state = c;
|
||||
if(c==0) StateTurboReset(joy_num); //clear turbo if no button pressed
|
||||
}
|
||||
void StateJoySetExtra(unsigned char c, uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].state_extra = c;
|
||||
}
|
||||
|
||||
// raw state of USB controller
|
||||
|
||||
void StateUsbJoySet(uint8_t usbjoy, uint8_t usbextra, uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].usb_state = usbjoy;
|
||||
mist_joy[joy_num].usb_state_extra = usbextra;
|
||||
}
|
||||
|
||||
/* connected HID information */
|
||||
void StateUsbIdSet(unsigned int vid, unsigned int pid, unsigned int btn_count, uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].vid = vid;
|
||||
mist_joy[joy_num].pid = pid;
|
||||
mist_joy[joy_num].num_buttons = btn_count;
|
||||
}
|
||||
|
||||
/* handle button's turbo timers */
|
||||
void StateTurboUpdate(uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].turbo_counter += 1;
|
||||
if(mist_joy[joy_num].turbo_counter > mist_joy[joy_num].turbo) {
|
||||
mist_joy[joy_num].turbo_counter = 0;
|
||||
mist_joy[joy_num].turbo_state ^= mist_joy[joy_num].turbo_mask;
|
||||
}
|
||||
}
|
||||
/* reset all turbo timers and state */
|
||||
void StateTurboReset(uint8_t joy_num) {
|
||||
if(joy_num>1) return;
|
||||
mist_joy[joy_num].turbo_counter = 0;
|
||||
mist_joy[joy_num].turbo_state = 0xFF;
|
||||
}
|
||||
/* set a specific turbo mask and timeout */
|
||||
void StateTurboSet ( uint16_t turbo, uint16_t mask, uint8_t joy_num ) {
|
||||
if(joy_num>1) return;
|
||||
StateTurboReset(joy_num);
|
||||
mist_joy[joy_num].turbo = turbo;
|
||||
mist_joy[joy_num].turbo_mask = mask;
|
||||
}
|
||||
/* return Joy state including turbo settings */
|
||||
uint8_t StateJoyState ( uint8_t joy_num ) {
|
||||
if(joy_num>1) return 0;
|
||||
uint8_t result = mist_joy[joy_num].state;
|
||||
result &= mist_joy[joy_num].turbo_state;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* keyboard data */
|
||||
static uint8_t key_modifier = 0;
|
||||
static unsigned char key_pressed[6] = { 0,0,0,0,0,0 };
|
||||
|
||||
void StateKeyboardSet( unsigned char modifier, char* keycodes, int* keycodes_ps2) {
|
||||
unsigned i=0;
|
||||
key_modifier = modifier;
|
||||
for(i=0; i<6; i++) {
|
||||
if((keycodes[i]&0xFF) != 0xFF ) {
|
||||
key_pressed[i]=keycodes[i];
|
||||
if((keycodes_ps2[i]&0xFF) != 0xFF ) {
|
||||
//iprintf("PS2 keycode: %x\n", keycodes_ps2[i]);
|
||||
// translate EXT into 0E
|
||||
if(0x1000 & keycodes_ps2[i]) {
|
||||
//key_ps2[i] = keycodes_ps2[i]&0xFF | 0xE000;
|
||||
} else {
|
||||
//key_ps2[i] = keycodes_ps2[i]&0xFF;
|
||||
}
|
||||
} else {
|
||||
//key_ps2[i]=0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
key_pressed[i]=0;
|
||||
//key_ps2[i]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
void StateKeyboardModifiers(uint8_t m) {
|
||||
m = key_modifier;
|
||||
return;
|
||||
}
|
||||
void StateKeyboardPressed(char *keycodes) {
|
||||
unsigned i=0;
|
||||
for(i=0; i<6; i++)
|
||||
keycodes[i]=key_pressed[i];
|
||||
}
|
||||
|
||||
|
||||
/* core currently loaded */
|
||||
static char lastcorename[261+10] = "CORE";
|
||||
void StateCoreNameSet(const char* str) {
|
||||
siprintf(lastcorename, "%s", str);
|
||||
}
|
||||
char* StateCoreName() {
|
||||
return lastcorename;
|
||||
}
|
||||
|
||||
// clear all states
|
||||
void StateReset() {
|
||||
strcpy(lastcorename, "CORE");
|
||||
//State_key = 0;
|
||||
//joysticks=0;
|
||||
key_modifier = 0;
|
||||
for(int i=0; i<6; i++) {
|
||||
key_pressed[i]=0;
|
||||
//key_ps2[i]=0;
|
||||
}
|
||||
joy_reset(mist_joy[0]);
|
||||
joy_reset(mist_joy[1]);
|
||||
joy_reset(mist_joy[2]);
|
||||
}
|
||||
61
state.h
Normal file
61
state.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef STATE_H_INCLUDED
|
||||
#define STATE_H_INCLUDED
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
void StateReset();
|
||||
|
||||
//// type definitions ////
|
||||
typedef struct {
|
||||
uint16_t vid; // USB vendor ID
|
||||
uint16_t pid; // USB product ID
|
||||
uint8_t num_buttons; // number of physical buttons reported by HID parsing
|
||||
uint8_t state; // virtual joystick: current state of 4 direction + 4 first buttons
|
||||
uint8_t state_extra; // current state of 8 more buttons
|
||||
uint8_t usb_state; // raw USB state of direction and buttons
|
||||
uint8_t usb_state_extra; // raw USB state of 8 more buttons
|
||||
uint16_t turbo; // 0 if disabled, otherwise max number to flip state
|
||||
uint16_t turbo_counter; // increased when using turbo, flips state when passing turbo
|
||||
uint8_t turbo_mask; // buttons subject to turbo
|
||||
uint8_t turbo_state; // current mask to apply
|
||||
|
||||
} mist_joystick_t;
|
||||
|
||||
|
||||
|
||||
/*****
|
||||
* Various functions to retrieve hardware state from the State
|
||||
*/
|
||||
|
||||
mist_joystick_t StateJoyGet(uint8_t joy_num); // all data
|
||||
uint8_t StateJoyState ( uint8_t joy_num ); // directions and 4 buttons, reflecting turbo settings
|
||||
|
||||
// State of first (virtual) internal joystisk i.e. after mapping
|
||||
void StateJoySet(unsigned char, uint8_t joy_num);
|
||||
void StateJoySetExtra(unsigned char, uint8_t joy_num);
|
||||
|
||||
// USB raw data for joystick 1
|
||||
void StateUsbJoySet(uint8_t usbjoy, uint8_t usbextra, uint8_t joy_num);
|
||||
void StateUsbIdSet(unsigned int vid, unsigned int pid, unsigned int num_buttons, uint8_t joy_num);
|
||||
|
||||
// Keep track of connected sticks
|
||||
unsigned char StateNumJoysticks();
|
||||
void StateNumJoysticksSet(unsigned char num);
|
||||
|
||||
// turbo function
|
||||
void StateTurboUpdate(uint8_t joy_num);
|
||||
void StateTurboReset(uint8_t joy_num);
|
||||
void StateTurboSet ( uint16_t turbo, uint16_t mask, uint8_t joy_num );
|
||||
|
||||
// keyboard status
|
||||
void StateKeyboardSet( unsigned char modifier, char* pressed, int* pressed_ps2); //get usb and ps2 codes
|
||||
void StateKeyboardModifiers(uint8_t m);
|
||||
void StateKeyboardPressed(char *pressed);
|
||||
void StateKeyboardPressedPS2(unsigned int *keycodes);
|
||||
|
||||
// get/set core currently loaded
|
||||
void StateCoreNameSet(const char* str);
|
||||
char* StateCoreName();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "hardware.h"
|
||||
#include "osd.h"
|
||||
#include "state.h"
|
||||
#include "user_io.h"
|
||||
#include "archie.h"
|
||||
#include "cdc_control.h"
|
||||
@@ -309,10 +310,7 @@ void user_io_digital_joystick(unsigned char joystick, unsigned char map) {
|
||||
// becomes joystick 1 and only the second one becomes joystick 0
|
||||
// (mouse port)
|
||||
|
||||
if (joystick==1)
|
||||
OsdJoySet(map);
|
||||
else if (joystick==0) // WARNING: 0 is the second joystick, either USB or DB9
|
||||
OsdJoySet2(map);
|
||||
StateJoySet(map, joystick);// WARNING: 0 is the second joystick, either USB or DB9
|
||||
|
||||
// iprintf("joy to osd\n");
|
||||
|
||||
@@ -1650,7 +1648,7 @@ void user_io_kbd(unsigned char m, unsigned char *k, uint8_t priority) {
|
||||
keycodes[i] = pressed[i]; // send raw USB code, not amiga - keycode(pressed[i]);
|
||||
keycodes_ps2[i] = keycode(pressed[i]);
|
||||
}
|
||||
OsdKeyboardSet(m, keycodes, keycodes_ps2);
|
||||
StateKeyboardSet(m, keycodes, keycodes_ps2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user