Pokitext: text editor on pokitto

Hmm I can’t create new files?

I do fileOpen with FILE_MODE_OVERWRITE, but inside that function the mode is ignored and it just calls open which just looks for an existing file.

Also if I write to an existing file, it ends up corrupted. But I may be doing something wrong.


Oh it’s PetitFS which can’t do these things, right? I am supposed to use the other one. Sorry.

Weird, if I want to list directory files, I do

SDFileSystem sd(P0_9,P0_8,P0_6,P0_7,"sd");
DirHandle *dir = sd.opendir("/");

In emulator this works, but on Pokitto I get 0 as a return value (I also tried “/sd”, that doesn’t work on either).

Last I checked, writing with PFFS was broken.

Hmm, that should work on hardware. Have you tried formatting the card?
Note that SDFS’s seekdir is completely broken.

1 Like

Hmm I may try to format it, but listing worked with PFFS and the emulator works with the image created directly from the card.

      DirHandle *dir = sdFs->opendir("/");                                        
      if (dir == 0)                                                               
        // Pokitto ends up here                 
        this->popUpWindow("No SD!");                                              
        return 0;                                                                 
      char *fileName;                                                             
      while (true)                                                                
        fileName = dir->readdir()->d_name;                                        
        if (i >= TextEditor::MAX_FILE_NAMES - 1 || fileName == 0 || fileName == NULL || fileName[0] == 0)


Or wait, now it seems to break the emulator as well. May I have corrupted the card with PFFS wrtiting?

It’s likely. Corrupting the card is pretty easy.

An explanation based on a vague memory of why stuff breaks:

When reading and writing data from/to the SD card, it’s done in transfers of 512 bytes. SDFS calls this the “window”. If you seek to the 10th byte of a file and write 1 byte, SDFS will change that byte in the window, then copy the entire 512 bytes to the disk. PFFS, iirc, doesn’t have a window. It will zero bytes 0-9, write the 10th byte and, if you close the file, zero bytes 11 to 511 to complete the transfer.

1 Like

Doesn’t seem to work even after formatting :confused: Emulator shows the files but Pokitto still doesn’t.

I guess I could use PFFS for listing the files and SDFS for opening and saving, but after a quick try now it does this: listing directory files works (PFFS), then I save a file (SDFS), and now I can no longer list directory files (PFFS, even if I call pokInitSD before every attempt to list the files. Code here).


And also now I found that I can’t even open a file on Pokitto with SDFS (PFFS was able to open it. Emulator opens it even with SDFS). I dunno, I must be doing something horribly wrong.

You can’t use both libs at the same time, SD cards have state and the libs will interfere with each other.
I’ll give the code a look when I get home, I don’t have my Pokitto with me.

Edit: Have you tried my loader? Does it work with your card? Just trying to isolate the cause.

Can you upload your makefile and my_settings.h?

1 Like

Well I thought so, but this example is using them both?


Will do.


Works. So it’s probably just me screwing up :smile:

Thanks for the assistance!

Maybe, maybe not. That filesystem lib there has been tweaked/bugfixed a bit.
Now we know it’s not an issue with your card, I’ll try to see if I can reproduce the issue here.

This works:

    DirHandle *dir = sdFs->opendir("/");

    while (i < TextEditor::MAX_FILE_NAMES)
      dirent *ent = dir->readdir();
      if (ent == 0)
      fileName = ent->d_name;



Calling closedir is important, otherwise you’re leaking a lot of memory.

1 Like

Awesome :slight_smile: no need to rush though, I’m leaving it for tomorrow anyway.

PokittoLib seems to need a refactor here, I’m struggling with the lack of documentation and a simple, unified API.

1 Like

Alright, gimme a sec to try.

1 Like

I totally agree.

Nope sorry, still doesn’t work for me :neutral_face: I’ve even reformatted the card again. I’ll have to get a sleep for this. But you’ve fixed me one bug at least, that’s good.

It’s not easy I know. You first want to make automated tests to make sure you don’t break things in the process. This needs some planning.

How are you testing it?

I formatted the card to FAT32, put two small txt files on it, then put the card to Pokitto, turn it on, open the menu in the editor (just navigate with arrow keys), select “open” and there it freezes (ATM there’s no error checking so NULL dereference happens… on emulator files are correctly listed).

Hmm… that’s exactly what I did, but the file list worked and I was able to open a file, go back to the list, open another, and so on.
Try my build? firmware.bin (97.4 KB)
(No hurry, go to sleep already :stuck_out_tongue: )

Am on mobile now, but I’ll try it before sleep. This definitely seems weird, I bet it’s some awkward mistake on my side :smile:


Your bin freezes as well. I don’t get it, your loader worked, so the card has to be working. And PFFS was able to list the files as well. Yes, my SD card is actually in the Pokitto right now. Very very strange. I’ll look at it tomorrow!


Unless your SD card isn’t plugged in properly (actually happened to me once, had me scratching my head wondering why file access suddenly stopped working), it doesn’t sound like it’s just a mistake. :thinking:

Try this:
Install Loader v0.0.3 then test this bin: firmware.bin (67.4 KB)

1 Like