From 0f94429bab7fe3a2ed115ab0877bf33d64207fd5 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 10 Dec 2010 05:17:34 +0000 Subject: [PATCH] add support for varying stylus pressure. not tested very well. default hotkey shift +/- --- desmume/src/MMU.cpp | 80 +++++++++++++++++++++++++++++-- desmume/src/NDSSystem.h | 3 ++ desmume/src/bios.cpp | 12 +++-- desmume/src/windows/hotkey.cpp | 26 ++++++++++ desmume/src/windows/hotkey.h | 2 +- desmume/src/windows/resource.h | 2 + desmume/src/windows/resources.rc | Bin 955858 -> 956410 bytes 7 files changed, 115 insertions(+), 10 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 565edc1ff..0586dc873 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -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) diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 1078848ac..673acca52 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -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; diff --git a/desmume/src/bios.cpp b/desmume/src/bios.cpp index 3042bf253..9da575806 100644 --- a/desmume/src/bios.cpp +++ b/desmume/src/bios.cpp @@ -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() diff --git a/desmume/src/windows/hotkey.cpp b/desmume/src/windows/hotkey.cpp index 1d9655679..19cefcaab 100644 --- a/desmume/src/windows/hotkey.cpp +++ b/desmume/src/windows/hotkey.cpp @@ -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; diff --git a/desmume/src/windows/hotkey.h b/desmume/src/windows/hotkey.h index d041c52ab..64e32f2ce 100644 --- a/desmume/src/windows/hotkey.h +++ b/desmume/src/windows/hotkey.h @@ -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; diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index dae9e2b2b..e0a22e5cc 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -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 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index ff5ad27e9f62b601f53b8ba0ce6e135ffe095b77..39e3ae520ca8b4ddf91b4d34ce4fb00568e8addf 100644 GIT binary patch delta 329 zcmcb#+UnPOtA-ZFEle-&F>+2nc%Mmfde9nHsp<39atnzEFcdMQG86-0DVU|iz{|kJ z09D2`flq4sf{Uyy)89R3;^RkC+y3w#6A&{4F$)m00x=s9vu}TRk3*Q1s#XDwWO~Rr rJz)}`T>G1+96-#u{moOZMW<+G%XFYE7482vaRV{W_J5mruRH<(LfUok delta 118 zcmeyh-s;k7tA-ZFEle-&O}}uL!)g16NqjRHr!HV*X|H?81jNih3}UkaF&hxGZ?AjE xp~nnYyp3`Cx-Hxl)8}ktm23a>oCAnCw|{!h#d8WtNjp#p5c6zbw}sc|F#wLlI;;Qy