Skip to content
jcronaPublic

About

A hardware agnostic first-gen Tamagotchi emulation library

Resources

Stars

288 stars

Watchers

8 watching

Forks

Latest commit

 

History

90 Commits

Folders and files

Repository files navigation

TamaLIB - A hardware agnostic first-gen Tamagotchi emulation library

Synopsis

TamaLib is a hardware agnostic first-gen Tamagotchi (E0C6S46/8 based) emulation library built from scratch. It is self-contained and aims at running on any platform powerful enough, from microcontrollers (MCUs) to desktop computers, thus spreading virtual life across the digital world.

So far, it has been successfully implemented on different platforms:

  • Desktop computers (check out TamaTool for more information)
  • STM32F072 MCU based board (check out MCUGotchi for more information).
  • OpenTama which is an STM32L072 MCU based board (check out OpenTama and MCUGotchi for more information).
  • Arduino UNO (check out ArduinoGotchi for more information).
  • A web app powered by Python/JS (check out Pygotchi for more information).
  • Palm OS (check out TamagotchiPalmOS for more information).
  • M5Stack Cardputer (check out Tamaputer for more information).

Importing TamaLIB

TamaLIB cannot be used as is. In order to create life on a specific target, you need to import all TamaLIB related .c and .h files in your project (for instance in a lib subfolder), to create a hal_types.h file using the template provided and to implement the hal_t structure, that will act as an abstraction layer between TamaLIB and your OS or SDK (detailed information can be found in hal.h). This abstraction layer basically connects TamaLIB to your target's buttons, clock, audio and screen, while also defining the C types that TamaLIB should use to represent 4-bit, 5-bit, 8-bit, 12-bit, 13-bit and 32-bit variables. Once done, you will be able to call the TamaLIB API from your project.

Build options

The following options can be set to 0 or 1 by your build system (for instance with -DOPTION=1) to adjust the trade-off between memory footprint and speed to your target (default values are defined in cpu.h):

  • LOW_FOOTPRINT (enabled by default): Reduces the footprint of the emulated memory buffer in RAM from 4096 4-bit variables (most likely 4096 bytes) to about 550 bytes, by packing two 4-bit values per byte and not buffering invalid memory areas, while slightly increasing the number of operations needed to read/write from/to it. Disable it if RAM is not a concern on your target.
  • OP_LOOKUP_TABLE (disabled by default): Decodes the OP codes using a constant lookup table of 4096 bytes instead of iterating over the list of supported OP codes at every step, which makes the emulation roughly twice as fast. Since the table is constant, it will most likely be stored in flash on MCUs, thus not increasing the RAM footprint. Enable it if your target has 4 KB of flash/ROM to spare, or if you need to speed up the emulation.

Using the TamaLIB API

Basically:

/* ... */

/* Register the HAL */
tamalib_register_hal(&my_hal);

/* ... */

/* Initialize TamaLIB */
tamalib_init(my_program, my_breakpoints, 1000000); // my_breakpoints can be NULL, 1000000 means that timestamps will be expressed in us

/* ... */

/* Enter TamaLIB's loop */
tamalib_mainloop();

/* ... */

/* Release TamaLIB */
tamalib_release();

/* ... */

Your main project should then forward any button input to TamaLIB using the tamalib_set_button() function.

As an alternative to tamalib_mainloop(), you can call tamalib_step() directly if your execution flow requires something more complex than a simple mainloop. In that case, TamaLIB will neither call the HAL handler() function, nor the HAL update_screen() function by itslef.

License

TamaLIB is distributed under the GPLv2 license. See the LICENSE file for more information.

Hardware information

The Tamagotchi P1 and P2 are based on an E0C6S46 Epson MCU, and runs at 32,768 kHz, while the Tamagotchi Angel, Umino (Ocean), Morino (Forest), Mothra, Tamaotch and Genjintch are based on an E0C6S48 Epson MCU running at 32,768 kHz and 1 MHz. Their LCDs are all 32x16 B/W pixels, with 8 icons. To my knowledge, the P1 ROM available online has been extracted from a high-res picture of a die. The ROM mask was clear enough to be optically read. The pictures can be seen there (thx asterick for the link!).
I would love to see the same work done on a P2 and add support for it in TamaLIB/TamaTool! Someone did the same job for the P2 and other first-gen devices!

__
Copyright (C) 2025 Jean-Christophe Rona

About

A hardware agnostic first-gen Tamagotchi emulation library

Resources

Stars

288 stars

Watchers

8 watching

Forks

Releases

Packages

Contributors

Languages