Since dumping the ROM of my TamaTown Tama-Go, I’ve been going through it looking for information on how Tamagotchis work. I’ve managed to answer some questions on how Tamagotchis behave.
Reversing the Tamagotchi ROM was fairly challenging, partly because I’m not that familiar with 6502 , and partly because I don’t have a lot of information on the GP processor. I was able to determine some ports and the locations of interrupt vectors from an application note, but otherwise I had to guess. Paging also made analysis more difficult, as IDA often misinterpreted branch locations because the page had changed.
I eventually wrote a simulator for the Tamagotchi based on py65. It isn’t the sort of simulator you can play Tamagotchi on, but it allowed me to step through instructions, view the LCD and generally understand the control flow of the Tamagotchi.
Once a Tamagotchi has started up, it constantly loops through a single loop triggered by a timer interrupt.
The loop is always in one of 0×41 states, such as hatching, eating a meal, etc. The states are listed in a table with the corresponding page number for the table. Jumping into the page in the table at 0×4000 with the state in the accumulator causes the program to index into the page’s state table, and jump into the code for that state. States can have substates and substates can have subsubstates and so on. Pointer tables for each of these are contained within the page, separate from the main pointer table. Each state is responsible for handling non-interrupt controlled inputs, such as button presses, and transitioning to the next state as needed. Interrupts can also sometimes cause state changes.
I’ve gone through about ten of the states, and answered some questions about Tamagotchi behaviour as follows.
What makes a Tamagotchi a boy or a girl?
This is determined randomly based on the entropy source C4, which is set based on the number of times interrupt tm0 has fired since the Tamagotchi was started. So the exact instant you hit the B button and start entering your data or reset the Tamagotchi is what seals its fate.
What determines where a Tamagotchi lives?
This is determined based on a value in the EEPROM, which is read and incremented before the EEPROM is verified. So barring very serious corruption, the Tamagotchi should move sequentially through each background as it is reset.
What determines what toddler a Tamagotchi baby becomes?
For the first generation, it’s random based on entropy source C4. It is equally likely a girl will be Belltchi and Hositchi, and equally likely a boy will be Mattaritchi or Ahirkutchi.
For the next generation, it is more probable that a baby will grow into a character that you did not have last time. If the previous toddler was Belltchi or Ahirkutchi, there is a 2/3 chance it will be Mattaritchi or Hositchi (depending on gender), and a 1/3 chance it will be Belltchi or Ahirkutchi, and vice versa.
For the next generation (and all odd numbered generations), it is random again.
This of course only applies to ‘normal’ toddlers. If a toddler’s parent was an Olditchi, it will become Grippatchi or Oyajitchi based on gender.
What determines what teenager a toddler becomes?
The Tamagotchi maintains two ‘care factors’, factor A and B based in how well you care for it. The ideal score is zero, and you get dinged for various lapses in care. It’s not clear to me everything that contributes to this score at this point, but it appears that all the Tamagotchi’s stats play a part, and whether a figure is attached seems to have an impact, although it’s not clear what that is. There’s also a random element to the care factors, sometimes it’s randomly determined whether factor A or B gets impacted.
Which character your toddler turns into depends on these care factors, but some toddlers are higher maintenance than others. For all toddlers, if both care factors are less than or equal to two, they will turn into Shelltchi or Kilatchi. For Belltchi or Ahirkutchi, if the care factors are both less than or equal to four (but not both two or less), they will turn into Mikazukitchi or Kurokotchi, but for Mattaritchi or Hositchi, both need to be three or less! Otherwise, the toddler will turn into Chuchutchi or Monpatchi.
What determines what adult a teenager will become?
This is determined based on the same care factors that determine what teenager a toddler becomes, but there is one extra factor: training. Different teens react differently to training as well.
A poorly-cared for teen will turn into Gozarutchi, Necktie-chi, Kinoitchi or Pipotchi (which specific one is determined randomly). For all teens, if the care factor is more than four, it will turn into one of these characters. However, for training, it depend on the teen. For Chuchutchi or Monpatchi, if their training is less than eight, they will turn into one of these characters. For Mikazukitchi or Kurokotchi, this value is six, and for Shelltchi or Kilatchi this value is four. So if you care for your toddler poorly, you need to make up for this in discipline in the teen years or else you will get a ‘bad’ character.
I won’t go into all the combinations here (they confirm the growth chart here), but what the Tamagotchi turns into continues to depend on what toddler it was. For example, to become the ‘best’ set of adults, the ‘best’ toddlers only need care factors of less than or equal to two, and training of more than eight, while the worst cared-for toddlers need care factors of less than or equal to one, and training of fourteen or higher.
Is it possible to get any of the ‘secret characters’ in the ROM?
I haven’t found any, and I’ve been through the whole evolve function. I suspect these got removed at some point late in development (maybe they weren’t working), because there’s a lot of situations in the evolve function where a condition branches to the same function regardless of what it evaluates to, which seems like a ‘quick fix’ to remove characters.
Can you toilet train your Tamagotchi?
It will never start going to the toilet by itself, but every time you drag it to the toilet in time, it improves its training score by three points. Once a Tamagotchi’s training score is over ten, it will start to go less, which is almost like toilet training it …. . Yes! Every time you drag your Tamagotchi to the toilet, it’s training increases by three, and once it’s training is greater than 10, it will start to go by itself!*
That’s it! Please post your “questions of Tamagotchi life” in the comments, and I will try to answer them as I understand the ROM better!
*Thanks to Ra for pointing this out to me