add support for varying stylus pressure. not tested very well. default hotkey shift +/-

This commit is contained in:
zeromus 2010-12-10 05:17:34 +00:00
parent f0d3bd7f40
commit 0f94429bab
7 changed files with 115 additions and 10 deletions

View File

@ -3176,7 +3176,6 @@ u8 FASTCALL _MMU_ARM9_read08(u32 adr)
if (adr >> 24 == 4)
{ //Address is an IO register
if(MMU_new.is_dma(adr)) return MMU_new.read_dma(ARMCPU_ARM9,8,adr);
switch(adr)
@ -3552,6 +3551,42 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val)
MMU.MMU_MEM[ARMCPU_ARM7][adr>>20][adr&MMU.MMU_MASK[ARMCPU_ARM7][adr>>20]]=val;
}
static void CalculateTouchPressure(int pressurePercent, u16 &z1, u16& z2)
{
bool touch = nds.isTouch!=0;
if(!touch)
{
z1 = z2 = 0;
return;
}
int y = nds.touchY/16;
int x = nds.touchX/16;
float u = (x/256.0f);
float v = (y/192.0f);
//these coefficients
float fPressurePercent = pressurePercent/100.0f;
//z1 goes up as pressure goes up
{
float b0 = (96-80)*fPressurePercent + 80;
float b1 = (970-864)*fPressurePercent + 864;
float b2 = (192-136)*fPressurePercent + 136;
float b3 = (1560-1100)*fPressurePercent + 1100;
z1 = (u16)(int)(b0 + (b1-b0)*u + (b2-b0)*v + (b3-b2-b1+b0)*u*v);
}
//z2 goes down as pressure goes up
{
float b0=(1976-2300)*fPressurePercent + 2300;
float b1=(2360-2600)*fPressurePercent + 2600;
float b2=(3840-3900)*fPressurePercent + 3900;
float b3=(3912-3950)*fPressurePercent + 3950;
z2 = (u16)(int)(b0 + (b1-b0)*u + (b2-b0)*v + (b3-b2-b1+b0)*u*v);
}
}
//================================================= MMU ARM7 write 16
void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val)
{
@ -3776,12 +3811,47 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val)
break;
case TSC_MEASURE_Z1: //Z1
//used for pressure calculation - must be nonzero or else some softwares will think the stylus is up.
if(nds.isTouch) val = 2048;
else val = 0;
//something is wrong in here and some of these LSB dont make it back to libnds... whatever.
{
u16 scratch;
CalculateTouchPressure(CommonSettings.StylusPressure,val,scratch);
}
if(spicnt & 0x800)
{
if(partie)
{
val = ((val<<3)&0x7FF);
partie = 0;
break;
}
val = (val>>5);
partie = 1;
break;
}
val = ((val<<3)&0x7FF);
partie = 1;
break;
case TSC_MEASURE_Z2: //Z2
//used for pressure calculation. we dont support pressure calculation so just return something.
val = 2048;
//used for pressure calculation - must be nonzero or else some softwares will think the stylus is up.
//something is wrong in here and some of these LSB dont make it back to libnds... whatever.
{
u16 scratch;
CalculateTouchPressure(CommonSettings.StylusPressure,scratch,val);
}
if(spicnt & 0x800)
{
if(partie)
{
val = ((val<<3)&0x7FF);
partie = 0;
break;
}
val = (val>>5);
partie = 1;
break;
}
val = ((val<<3)&0x7FF);
partie = 1;
break;
case TSC_MEASURE_X:
if(spicnt & 0x800)

View File

@ -486,6 +486,7 @@ extern struct TCommonSettings {
, manualBackupType(0)
, spu_captureMuted(false)
, spu_advanced(false)
, StylusPressure(50)
{
strcpy(ARM9BIOS, "biosnds9.bin");
strcpy(ARM7BIOS, "biosnds7.bin");
@ -529,6 +530,8 @@ extern struct TCommonSettings {
bool single_core() { return num_cores==1; }
bool rigorous_timing;
int StylusPressure;
bool dispLayers[2][5];
FAST_ALIGN bool advanced_timing;

View File

@ -192,6 +192,8 @@ TEMPLATE static u32 bios_nop()
TEMPLATE static u32 WaitByLoop()
{
u32 elapsed;
//printf("%lld waitbyloop\n",nds_timer);
//INFO("ARM%c: SWI 0x03 (WaitByLoop)\n", PROCNUM?'7':'9');
if (PROCNUM == ARMCPU_ARM9)
@ -199,12 +201,14 @@ TEMPLATE static u32 WaitByLoop()
armcp15_t *cp = (armcp15_t*)(cpu->coproc[15]);
if (cp->ctrl & ((1<<16)|(1<<18))) // DTCM or ITCM is on (cache)
return cpu->R[0] * 2;
elapsed = cpu->R[0] * 2;
else
return cpu->R[0] * 8;
elapsed = cpu->R[0] * 8;
}
return cpu->R[0] * 4;
else
elapsed = cpu->R[0] * 4;
cpu->R[0] = 0;
return elapsed;
}
TEMPLATE static u32 wait4IRQ()

View File

@ -422,6 +422,18 @@ void HK_ToggleRasterizer(int, bool justPressed) {
Change3DCoreWithFallbackAndSave(cur3DCore);
}
void HK_IncreasePressure(int, bool justPressed) {
CommonSettings.StylusPressure += 10;
if(CommonSettings.StylusPressure<0) CommonSettings.StylusPressure = 0;
osd->addLine("Stylus Pressure to %d%%",CommonSettings.StylusPressure);
}
void HK_DecreasePressure(int, bool justPressed) {
CommonSettings.StylusPressure -= 10;
if(CommonSettings.StylusPressure<0) CommonSettings.StylusPressure = 0;
osd->addLine("Stylus Pressure to %d%%",CommonSettings.StylusPressure);
}
//======================================================================================
//=====================================DEFINITIONS======================================
//======================================================================================
@ -504,6 +516,20 @@ void InitCustomKeys (SCustomKeys *keys)
keys->DecreaseSpeed.name = STRW(ID_LABEL_HK8);
keys->DecreaseSpeed.page = HOTKEY_PAGE_MAIN;
keys->DecreaseSpeed.key = VK_OEM_MINUS;
keys->IncreasePressure.handleKeyDown = HK_IncreasePressure;
keys->IncreasePressure.code = "IncreasePressure";
keys->IncreasePressure.name = STRW(ID_LABEL_HK55);
keys->IncreasePressure.page = HOTKEY_PAGE_MAIN;
keys->IncreasePressure.key = VK_OEM_PLUS;
keys->DecreasePressure.modifiers = CUSTKEY_SHIFT_MASK;
keys->DecreasePressure.handleKeyDown = HK_DecreasePressure;
keys->DecreasePressure.code = "DecreasePressure";
keys->DecreasePressure.name = STRW(ID_LABEL_HK56);
keys->DecreasePressure.page = HOTKEY_PAGE_MAIN;
keys->DecreasePressure.key = VK_OEM_MINUS;
keys->DecreasePressure.modifiers = CUSTKEY_SHIFT_MASK;
keys->Microphone.handleKeyDown = HK_MicrophoneKeyDown;
keys->Microphone.handleKeyUp = HK_MicrophoneKeyUp;

View File

@ -68,7 +68,7 @@ struct SCustomKeys
SCustomKey Slot[10];
SCustomKey QuickSave, QuickLoad, NextSaveSlot, PreviousSaveSlot;
SCustomKey OpenROM, ReloadROM, Reset, Pause, FrameAdvance, FastForward, FastForwardToggle, IncreaseSpeed, DecreaseSpeed, Microphone;
SCustomKey OpenROM, ReloadROM, Reset, Pause, FrameAdvance, FastForward, FastForwardToggle, IncreaseSpeed, DecreaseSpeed, Microphone, IncreasePressure, DecreasePressure;
SCustomKey PlayMovie, RecordMovie, StopMovie, ToggleReadOnly;

View File

@ -774,6 +774,8 @@
#define ID_LABEL_HK53 4517
#define ID_LABEL_HK13b 4518
#define ID_LABEL_HK54 4519
#define ID_LABEL_HK55 4520
#define ID_LABEL_HK56 4521
#define IDD_MICROPHONE 5000
#define IDM_MICROPHONESETTINGS 5001
#define IDC_MICSAMPLEBROWSE 5003

Binary file not shown.