A small snake game

Hello!

I am currently developing a small, Snake-style game for the PicoCalc using C# and the .NET nanoFramework. I am utilizing the open-source C# PicoCalcNano drivers available on GitHub. The game’s source code will be made available once it is complete. Other games will follow, with the goal of providing as much sample code as possible.

The drivers can be found here: GitHub - Sydney680928/PicoCalcNanoFramework: Community C# drivers for the Clockwork PicoCalc on .NET nanoFramework: keyboard, display, console, SD card and sound, for Raspberry Pi Pico and Pico 2 W. Not affiliated with Clockwork. · GitHub

Stéphane Sibué

3 Likes

Nice work, Stéphane — a full driver set in C#, with docs and NuGet packages, is a real gift to the PicoCalc crowd.

One thing I can maybe save you some time on, since your SD table says writes are slow and an optimisation is planned. I ran into the same thing with Blair’s picocalc-text-starter. Its driver sent one command per 512-byte block, and each write waited for the card to finish programming before the next — that’s where large files spent their time. Your FAT code writes the same way (WriteSector(sector + i, ...) in a loop).

What fixed it for us was multi-block transfers:

  • Writes: CMD25 (WRITE_MULTIPLE_BLOCK) once, then for each sector the start token 0xFC + 512 bytes + CRC, wait for the data response and not-busy, and finish with the stop token 0xFD and a final busy wait.
  • Reads: CMD18 (READ_MULTIPLE_BLOCK) once, read each data block after its 0xFE token, then CMD12 to stop.
  • FAT side: hand the driver whole runs of consecutive sectors (a cluster at a time is the natural unit) instead of one sector per call.

Measured with an FTP server on those drivers (Pico 2 W, FileZilla over Wi-Fi, one 38 MB file): upload went from 126 s to 46 s, download from 41 s to 35 s, and the file read back identical (SHA-256). The C version is here if a worked example helps: sdcard: multi-block reads and writes (CMD18, CMD25) by ctorkildson-netizen · Pull Request #47 · BlairLeduc/picocalc-text-starter · GitHub (drivers/sdcard.c, sd_write_blocks / sd_read_blocks). Happy to answer questions.

1 Like

Thanks for this information! I’ll take a close look at it all.