Skip to content

Commit

Permalink
Update code for new libnx and nfpemu ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
CompSciOrBust committed Dec 12, 2019
1 parent d15a250 commit 559e71b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ INCLUDES := include
#ROMFS := romfs
APP_TITLE := Amiigo
APP_AUTHOR := CompSciOrBust
APP_VERSION := 1.5.1
APP_VERSION := 1.5.2

#---------------------------------------------------------------------------------
# options for code generation
Expand Down
41 changes: 30 additions & 11 deletions include/nfpemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

bool emuiiboIsPresent();
bool nfpemuIsAccessible();

Result nfpemuInitialize();
void nfpemuExit();
Expand All @@ -14,25 +14,44 @@ typedef enum {
EmuEmulationStatus_OnForever = 0,
EmuEmulationStatus_OnOnce = 1,
EmuEmulationStatus_Off = 2,
} EmuEmulationStatus;
} NfpEmuEmulationStatus;

typedef struct {
u8 Major;
u8 Minor;
u8 Micro;
} EmuVersion;

Result nfpemuGetCurrentAmiibo(char *out, bool *out_ok);
u8 major;
u8 minor;
u8 micro;
u8 dev_build;
} NfpEmuVersion;

enum {
Module_NfpEmu = 352
};

enum {
NfpEmuError_NoAmiiboLoaded = 1,
NfpEmuError_UnableToMove = 2,
NfpEmuError_StatusOff = 3
};

Result nfpemuGetCurrentAmiibo(char *out);
Result nfpemuSetCustomAmiibo(const char *path);
Result nfpemuHasCustomAmiibo(bool *out_has);
Result nfpemuResetCustomAmiibo();
Result nfpemuSetEmulationOnForever();
Result nfpemuSetEmulationOnOnce();
Result nfpemuSetEmulationOff();
Result nfpemuMoveToNextAmiibo(bool *out_ok);
Result nfpemuGetStatus(EmuEmulationStatus *out);
Result nfpemuMoveToNextAmiibo();
Result nfpemuGetStatus(NfpEmuEmulationStatus *out);
Result nfpemuRefresh();
Result nfpemuGetVersion(EmuVersion *out_ver);
Result nfpemuGetVersion(NfpEmuVersion *out_ver);

NX_CONSTEXPR bool nfpemuIsDevBuild(const NfpEmuVersion *ver) {
return !!ver->dev_build;
}

NX_CONSTEXPR bool nfpemuMatches(const NfpEmuVersion *ver, u8 major, u8 minor, u8 micro) {
return (ver->major == major) && (ver->minor == minor) && (ver->micro == micro);
}

#ifdef __cplusplus
}
Expand Down
10 changes: 5 additions & 5 deletions source/AmiigoUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void AmiigoUI::GetInput()
else if (Event->jbutton.button == 2)
{
//Get info about the current status
EmuEmulationStatus CurrentStatus;
NfpEmuEmulationStatus CurrentStatus;
nfpemuGetStatus(&CurrentStatus);
//Change Emuiibo status
switch(CurrentStatus)
Expand All @@ -126,7 +126,7 @@ void AmiigoUI::GetInput()
//Y pressed
else if(Event->jbutton.button == 3)
{
nfpemuMoveToNextAmiibo(NULL);
nfpemuMoveToNextAmiibo();
}
//Up pressed
else if(Event->jbutton.button == 13)
Expand Down Expand Up @@ -238,7 +238,7 @@ void AmiigoUI::DrawHeader()
//Get the Amiibo path
char CurrentAmiibo[FS_MAX_PATH] = {0};
string HeaderText = "";
nfpemuGetCurrentAmiibo(CurrentAmiibo, NULL);
nfpemuGetCurrentAmiibo(CurrentAmiibo);
//String is empty so we need to set it to something so SDL doesn't crash
if(CurrentAmiibo[0] == NULL)
{
Expand Down Expand Up @@ -278,14 +278,14 @@ void AmiigoUI::DrawHeader()
//Switch to next Amiibo
if(CheckButtonPressed(&HeaderRect, TouchX, TouchY))
{
nfpemuMoveToNextAmiibo(NULL);
nfpemuMoveToNextAmiibo();
}
}

void AmiigoUI::DrawFooter()
{
//Get info about the current status
EmuEmulationStatus CurrentStatus;
NfpEmuEmulationStatus CurrentStatus;
nfpemuGetStatus(&CurrentStatus);
//Draw the footer
int FooterYOffset = *Height - FooterHeight;
Expand Down
2 changes: 1 addition & 1 deletion source/CreatorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CreatorUI

CreatorUI::CreatorUI()
{
nifmInitialize(); //Init nifm for connection stuff
nifmInitialize(NifmServiceType_User); //Init nifm for connection stuff
HeaderFont = GetSharedFont(48);
ListFont = GetSharedFont(32);
//HeaderFont = TTF_OpenFont("romfs:/font.ttf", 48); //Load the header font
Expand Down
2 changes: 1 addition & 1 deletion source/UpdaterUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UpdaterUI

UpdaterUI::UpdaterUI()
{
nifmInitialize(); //Init nifm for connection stuff
nifmInitialize(NifmServiceType_User); //Init nifm for connection stuff
TextFont = GetSharedFont(48);
}

Expand Down
4 changes: 1 addition & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ int main(int argc, char *argv[])
int Width = 1280;
int Height = 720;
int WindowState = 0;

// mandatory at least on switch, else gfx is not properly closed
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
SDL_Log("SDL_Init: %s\n", SDL_GetError());
Expand Down Expand Up @@ -61,8 +60,8 @@ int main(int argc, char *argv[])
}

TTF_Init(); //Init the font
nfpemuInitialize(); //Init nfp ipc
plInitialize(); //Init needed for shared font
nfpemuInitialize(); //Init nfp ipc

//Give MainUI access to vars
AmiigoUI *MainUI = new AmiigoUI();
Expand All @@ -81,7 +80,6 @@ int main(int argc, char *argv[])
//Not if it exists checking first feels dirty but it doesn't error out. Should we check anyway?
mkdir("sdmc:/emuiibo/", 0);
mkdir("sdmc:/emuiibo/amiibo/", 0);

while (!done)
{
//Clear the frame
Expand Down
34 changes: 11 additions & 23 deletions source/nfpemu.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "nfpemu.h"
#include <string.h>

bool emuiiboIsPresent()
bool nfpemuIsAccessible()
{
SmServiceName nfpemuService = smEncodeName("nfp:emu");
Handle tmph = 0;
Result rc = smRegisterService(&tmph, "nfp:emu", false, 1);
Result rc = smRegisterService(&tmph, nfpemuService, false, 1);
if(R_FAILED(rc)) return true;
smUnregisterService("nfp:emu");
smUnregisterService(nfpemuService);
return false;
}

Expand All @@ -15,8 +16,6 @@ static u64 g_refCnt;

Result nfpemuInitialize()
{
if(!emuiiboIsPresent()) return MAKERESULT(Module_Libnx, LibnxError_NotFound);

atomicIncrement64(&g_refCnt);
if(serviceIsActive(&g_nfpEmuSrv)) return 0;
return smGetService(&g_nfpEmuSrv, "nfp:emu");
Expand All @@ -27,7 +26,7 @@ void nfpemuExit()
if(atomicDecrement64(&g_refCnt) == 0) serviceClose(&g_nfpEmuSrv);
}

Result nfpemuGetCurrentAmiibo(char *out, bool *out_ok)
Result nfpemuGetCurrentAmiibo(char *out)
{
IpcCommand c;
ipcInitialize(&c);
Expand All @@ -51,11 +50,9 @@ Result nfpemuGetCurrentAmiibo(char *out, bool *out_ok)
struct {
u64 magic;
u64 result;
bool ok;
} *resp = r.Raw;

rc = resp->result;
if(R_SUCCEEDED(rc) && out_ok) *out_ok = resp->ok;
}

return rc;
Expand Down Expand Up @@ -247,7 +244,7 @@ Result nfpemuSetEmulationOff()
return rc;
}

Result nfpemuMoveToNextAmiibo(bool *out_ok)
Result nfpemuMoveToNextAmiibo()
{
IpcCommand c;
ipcInitialize(&c);
Expand All @@ -270,17 +267,15 @@ Result nfpemuMoveToNextAmiibo(bool *out_ok)
struct {
u64 magic;
u64 result;
bool ok;
} *resp = r.Raw;

rc = resp->result;
if(R_SUCCEEDED(rc) && out_ok) *out_ok = resp->ok;
}

return rc;
}

Result nfpemuGetStatus(EmuEmulationStatus *out)
Result nfpemuGetStatus(NfpEmuEmulationStatus *out)
{
IpcCommand c;
ipcInitialize(&c);
Expand All @@ -306,7 +301,7 @@ Result nfpemuGetStatus(EmuEmulationStatus *out)
} *resp = r.Raw;

rc = resp->result;
if(R_SUCCEEDED(rc)) *out = (EmuEmulationStatus)resp->status;
if(R_SUCCEEDED(rc) && out) *out = (NfpEmuEmulationStatus)resp->status;
}

return rc;
Expand Down Expand Up @@ -342,7 +337,7 @@ Result nfpemuRefresh()
return rc;
}

Result nfpemuGetVersion(EmuVersion *out_ver)
Result nfpemuGetVersion(NfpEmuVersion *out_ver)
{
IpcCommand c;
ipcInitialize(&c);
Expand All @@ -365,18 +360,11 @@ Result nfpemuGetVersion(EmuVersion *out_ver)
struct {
u64 magic;
u64 result;
u32 major;
u32 minor;
u32 micro;
NfpEmuVersion ver;
} *resp = r.Raw;

rc = resp->result;
if(R_SUCCEEDED(rc))
{
out_ver->Major = resp->major;
out_ver->Minor = resp->minor;
out_ver->Micro = resp->micro;
}
if(R_SUCCEEDED(rc) && out_ver) *out_ver = resp->ver;
}

return rc;
Expand Down

0 comments on commit 559e71b

Please sign in to comment.