Homebrew Discussion Does anyone have a working method of text input?

jfmherokiller

Well-Known Member
OP
Newcomer
Joined
Jan 6, 2017
Messages
51
Trophies
0
Age
28
XP
236
Country
United States
I would like to attempt to port something like Zork to the switch but I'm unable to devise my own method of allowing the player to input text.

Something like the input method used in godmode9 as linked below would work just fine.
https://github.com/d0k3/GodMode9/blob/master/arm9/source/common/ui.c#L636

I also found this
https://github.com/zrafa/onscreenkeyboard

I'm asking if this exists because as far as my reading of the libnx source code allowed me to observe. It does not have the ability to launch library applets yet.
So what I would like to know is if someone has already created a good method.

I attempted to copy the behavior of godmode9 myself and my attempt which is still in the early stages can be seen in the gist below.
https://gist.github.com/jfmherokiller/288b95479593ea0e25f3c866b537d718
https://gist.github.com/jfmherokiller/288b95479593ea0e25f3c866b537d718
 

jfmherokiller

Well-Known Member
OP
Newcomer
Joined
Jan 6, 2017
Messages
51
Trophies
0
Age
28
XP
236
Country
United States
You could check this out: https://github.com/misson20000/swkbd-demo

Switchbrew also has information on it: http://switchbrew.org/index.php?title=Software_Keyboard

You might/will need to adjust the homebrew loader's (https://github.com/switchbrew/nx-hbloader) wonky memory stuff, though.
Thank you for that I was attempting to launch it via code copied from the file https://github.com/switchbrew/libnx/blob/master/nx/source/services/applet.c

Which wasnt exactly working, only issue with what you linked is its using the libtransistor library while I primarily use libnx. But ill see if i can convert it.
 
Last edited by jfmherokiller,

jfmherokiller

Well-Known Member
OP
Newcomer
Joined
Jan 6, 2017
Messages
51
Trophies
0
Age
28
XP
236
Country
United States
In terms of converting thier code into something i can use I seem to have hit a snag. I seem to be unable to replicate thier IStorageAccessor Write function using libnx.
Their implementation correctly calls the function in yuzu. While, my implementation seems to just crash yuzu with no output on why it crashed (In the log It does not even show the api being called).
I know its something with my implementation because my GetSize implementation works correctly and shows up in the yuzu log.
If I had to guess I'd say something is going on with the buffer it needs.

heres how its being called in context
Code:
u32 common_args_header[] = {0x1, 0x20}; // {version?, size?}
rc = StorageWrite(StorageAccessHandle, 0, (uint8_t *) common_args_header, sizeof(common_args_header));

My Implementation
Code:
Result StorageWrite(Handle srv, u64 offset, const uint8_t *data, size_t size) {
    IpcCommand c;
    ipcInitialize(&c);

    struct {
        u64 magic;
        u64 cmd_id;
        u64 offset;
    } *raw;

    raw = ipcPrepareHeader(&c, sizeof(*raw));

    raw->magic = SFCI_MAGIC;
    raw->cmd_id = 10;
    raw->offset = offset;
    ipcAddSendBuffer(&c, (void *) data, size, 0x21);

    Result rc = ipcDispatch(srv);

    if (R_SUCCEEDED(rc)) {
        IpcParsedCommand r;
        ipcParse(&r);

        struct {
            u64 magic;
            u64 result;
        } *resp = r.Raw;

        rc = resp->result;
    }

    return rc;
}
their implementation
Code:
void IStorageAccessor::Write(size_t offset, const uint8_t *data, size_t size) {
   ResultCode::AssertOk(
      object.SendSyncRequest<10>(
         ipc::InRaw<uint64_t>(offset),
         ipc::Buffer<uint8_t, 0x21>((uint8_t*) data, size)));
}
Below is how the buffer is implemented in libnx and libtransistor
Code:
~~~~~~LIBNX~~~~~~
* @brief Adds a buffer to an IPC command structure.
* @param cmd IPC command structure.
* @param buffer Address of the buffer.
* @param size Size of the buffer.
* @param type Buffer type.
*/
static inline void ipcAddSendBuffer(IpcCommand* cmd, const void* buffer, size_t size, BufferType type) {
   size_t off = cmd->NumSend;
   cmd->Buffers[off] = buffer;
   cmd->BufferSizes[off] = size;
   cmd->BufferTypes[off] = type;
   cmd->NumSend++;
}
~~~~~~LIBTRANSISTOR~~~~~
template<typename T, uint32_t type, size_t expected_size> 
struct FormatMutator<ipc::Buffer<T, type, expected_size>> {
   static AccessorHelper<ipc::Buffer<T, type, expected_size>> MutateFormat(TransactionFormat &fmt) {
     ipc_buffer_t *buffer = new ipc_buffer_t();
     buffer->type = type;
     buffer->size = expected_size;
    fmt.buffers.push_back(buffer);
    return AccessorHelper<ipc::Buffer<T, type, expected_size>>(buffer);
   }
};
 
Last edited by jfmherokiller,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    BigOnYa @ BigOnYa: @NinStar I like it gentle, then rough, then gentle again. Then I nap.