Converting and decompiling
tipy-asm convert-project turns a C or ICE project into a TIpy-asm project:
tipy-asm convert-project path/to/project -o converted
tipy-asm build converted
The project type is detected from its source files, and --type cedev or
--type ice overrides that. The command then compiles its own output for CE and
tells you whether that worked.
What it writes
src/*.py: one module for each source file. Constants fromfoo.hgo at the top offoo.py, and#include "foo.h"becomesfrom foo import *.pyproject.toml: named from the makefile’sNAMEwhen there is one, with images, fonts, and.binfiles declared as assets.assets/: copies of those files.CONVERSION_NOTES.md: everything that needs your attention.
What converts
Functions, globals, if, while, do, for, break, continue,
return, ternaries, casts, #define constants, and global arrays all convert.
Common gfx_, os_, and kb_ calls map to library methods.
The current gfx_SetColor() color is kept in a variable and passed to each drawing
call.
What does not
Pointers, structs, switch, goto, and calls with no TIpy equivalent are not
guessed at. Each becomes a visible comment and a line in the notes, so you can search
for what is left:
# TODO(convert): not converted (switch): switch (mode) {
pass
Calls with no effect here, such as kb_Scan(), are removed and noted. Function-like
macros are not expanded, and are listed in the notes.
Check the results
Colors: CEdev palette indices are not RGB565 colors, so a converted
gfx_SetColor(5)draws a different color. Named colors such asgfx_redmap correctly.Loops: a
forloop that cannot becomerange()becomes awhileloop. The notes flag any such loop that containscontinue, which would skip its step.Integers: assembly integers are 24-bit on CE, so
longvalues may not fit.Double buffering: assembly targets draw directly to the screen, so
gfx_SwapDraw()is removed and a program may flicker.
Axe programs
tipy-asm convert-project also converts Axe Parser source, from the tokenized .8xp you edit on the calculator or from a text file
with a .axe suffix. The result is a project for the classic target.
tipy-asm convert-project GAME.8xp -o game
The converter keeps Axe’s own rules where Python’s differ:
Math runs left to right. Axe has no operator precedence, so
1+2*3is 9. Every operation is parenthesized in Axe’s order, so the result is the same.Variables:
A-Zandθbecomea-zandtheta.r1-r6carry the arguments ofsub().Routines:
Lbl Xup to itsReturnbecomeslbl_x(), andsub(X,1,2)setsr1andr2and calls it.Numbers:
ᴇ1Fis hex,π101is binary, and'A'is a character code.
If, !If, Else, While, Repeat, For(, getKey, getKey(n),
rand, Disp, Text(, Pause, ClrDraw, Pxl-On(, Pxl-Off(,
Line(, Rect(, and Circle( convert. Goto, pointers and {} memory,
sprites, and the rest of Axe’s library become TODO(convert) comments and lines in
CONVERSION_NOTES.md.
Decompiling a program
tipy-asm decompile turns a calculator file back into source you can read:
tipy-asm decompile GAME.8xp
TI-BASIC or Axe source comes out as text, token by token, in
GAME.txt.An assembly program comes out twice:
as a disassembly in
GAME.asm: Z80 for the TI-83 Plus and 84 Plus, or eZ80 in ADL mode for the CE, withL_labels at jump and call targets and named OS routines, such asti.PutSandbcall(_PutS);as Python in
GAME.py, which the next section describes.
Anything else, such as an AppVar, comes out as a hex dump.
-o - prints the result instead of writing a file. A disassembler cannot tell code
from data, so a program’s tables and strings come out as instructions too; the bytes
on each line show what is really there.
Assembly as Python
Machine code has no variables, types, or loops, only registers, memory, and jumps, so the Python keeps that shape while reading as code:
Only code. The lifter follows the program from its start through jumps and calls, so data is not mistaken for instructions. The file says how many bytes were left out.
Functions. Each call target is a function. One with no jumps inside is straight Python; one with jumps runs through a
gotodispatcher, since Python has no goto.Registers and memory.
a,bc,de,hl,ix,iy, andspare variables, and the 8-bit halves are read and written inside their pairs. Memory ismem8[...]andmemw[...], with 16-bit words on classic calculators and 24-bit words on the CE.Conditions. A compare followed by a jump becomes
if a == 5:orif hl == 0:. Flags are kept inzf,cf,sf, andpvfonly when something in between would change what they test.OS calls. These are named:
ti.PutS()on the CE andbcall("PutS")on classic calculators. OS RAM addresses keep their include-file names.Anything else. An instruction the lifter does not model stays as
asm("...").
The file is plain Python, with small stand-ins for memory and the OS at the end. It shows what the program does; it is not a TIpy program, because TIpy’s Python has no registers or raw memory.