Vitalii
1
Hi,
I’ve been attempting to write a fun little Teletype mod.
Conways Game Of Life for Event Triggering
The progress so far is that I have all the fundamental functionality working and running on the hardware.
But as I feared when starting with this, save load to memory is quite difficult to grasp for someone inexperienced.
From my understanding:
-The functions inside “scene_serialization.c”
Are responsible for writing and reading scene data from the scene slots
-There are defined states to process the different parts that make up scenes in order.
-There is frequent use of function “itoa()” it is difficult to understand what it does
-There are ‘\n’ and ‘\t’ used to separate data?
-I am unsure if there are other .c files involved in the whole process
If anyone can point me towards previous discussions of serialization or has any general information to help with understanding the process, i would be very very grateful
1 Like
Hey Vitalii,
Just to start off, I’ve never written any C code for the Teletype but I am an software engineer who writes a bit of C from time to time. So I’m sure others here can correct me where I’m wrong, or give better advice.
Yes, looks like the scene_serialization.c is responsible for taking the user typed script and saving it.
The itoa() function is responsible for taking an int type and turning it into a string type. Basically it takes the computers representation of some number like 42 (which in memory might be something like 0b00101010) and turns it into the text “42”. I can get more technical about that if you really care, but you probably don’t need that for what you’re doing.
The \n and \t are adding new-line and tab characters. I don’t know why they’re doing this. Maybe they’re trying to convert their in-memory representation of the user’s script back into what was typed? I don’t know, I’m just guessing.
While looking for other code involved I noticed that the serialize_scene() function in scene_serialization.c is only called from some test and usb_disk_mode.c. So that serializer may just be for writing to a USB drive and not to the internal memory.
That’s all I know about this. Hope it gets you a little further on your journey. Good luck.
Dewb
3
Answered on Discord since we were already having a conversation there, but here’s a summary for posterity:
- The serialization code is for saving and loading to text formats like files on a USB stick. If you want your new additions to be saved to scene data stored in non-volatile flash memory, the code you want to look at is in
flash.c. You’ll need to handle your new data in flash_read and flash_write. Currently, only scripts, patterns, grid data, and the scene description text are saved to flash when you use SCENE WRITE mode.
- The VCV Rack version of Teletype works the same way as hardware with respect to flash persistence and SCENE READ/WRITE modes. The difference is that module RAM is also saved in the Rack patch, so you don’t have to write your active scene to scene memory, but you still can.
- “Serialization” is an industry term and maybe this Wikipedia page is helpful: Serialization - Wikipedia
- The code in scene_serialization.c was previously all in usb_disk_mode.c. I was the last person to touch most of this code, but it was mostly reorganizing the work others had already done; you can read some background on that change here: Proposal: separate scene serialization logic from USB disk logic, add scene serialization tests by Dewb · Pull Request #287 · monome/teletype · GitHub
1 Like