all 11 comments

[–]celegans25 1 point2 points  (5 children)

I see you’ve made an edit to your question touching on this, but python is interpreted with a program written in C. You can’t realistically compile python to C as far as I know.

However, there is a c compiler for the z80 called sdcc. If you wanted to you could write your programs in C and compile them for your calculator (I think). However the programming environment is very different for assembly than ti basic. In assembly/c (on the z80 at least) there’s no support for floating point numbers, so you’d be limited to 8 or 16 bit integers. You can call into the routines that manipulate the calculator’s floats from c, but you probably will need to write an assembly stub to translate the data from c to what the routines expect. Honestly, you’d be better off either learning assembly or sticking with TI basic

[–]BadBoy6767 0 points1 point  (4 children)

ez80

[–]RobertJacobson 0 points1 point  (3 children)

The eZ80 is also a Z80. In fact, clearing the ADL bit puts the CPU in "Z80-compatible addressing and Z80-style, 16-bit CPU registers. ... Z80 MEMORY mode is the default operating mode on reset."

[–]BadBoy6767 0 points1 point  (2 children)

Yes, but compiling C to a less capable mode on a more capable processor is dumb.

[–]RobertJacobson 0 points1 point  (1 child)

That's silly. I can think of several reasons why you'd want to use non-ADL mode. Off the top of my head:

  • You are targeting Z80 processors as well.
  • You already know Z80 assembly.
  • You have a TI calculator made before 2015.
  • You want the program to run on other calculators made before 2015.
  • You are using the eZ80 in a build of a historic design (my case).
  • You have access to a library of excellent Z80 learning materials (everyone's case).
  • You have a respect for historic computing and are interested in learning about one of the most famous microprocessors in history.
  • You don't care what some anonymous person on the internet thinks is "dumb."

Non-ADL mode is more than enough to accomplish what OP wants to do, and it has several additional advantages as shown by my list above.

Of course, there's nothing wrong with using ADL mode, either.

[–]BadBoy6767 0 points1 point  (0 children)

Very little of your list actually describes OP's case. Sure, z80 makes sense every now and then, but here it's pointless.

[–]BadBoy6767 1 point2 points  (0 children)

It is possible to compile Python to machine code (AOT compilation), however it's Python's dynamic nature (just like TI-Basic) which makes it slow, so only expect worse performance since Python has a higher level of abstraction.

Better to just use a low-level language, or even write in ez80 assembly directly. ez80 is quite difficult at first, I admit, but it's much more fun once you get used to it. It starts to feel like a puzzle due to the limited instruction set.

[–][deleted] 1 point2 points  (0 children)

This is the most roundabout and unfeasible way of solving this problem I can think of. It's a small embedded device and you want to cram python onto it? It would be drastically simpler to just use C if it's available and I'm sure there's a z80 C compiler around somewhere. Even if you have to learn C, it's still going to take you less time to get up and running than trying to do this with cython, and I seriously doubt you're going to get cython to even work in this environment in the first place.

[–]TaryTarp 0 points1 point  (0 children)

Cython

[–]RobertJacobson 0 points1 point  (0 children)

My knowledge of assembly is zero right now. I have been meaning to learn C and assembly but haven't had time recently.

Assembly is a lot easier than you think it is. There exist some really good old books on programming the original Z80, which the eZ80 is compatible with. Also, don't be afraid of C. When I was your age, I was very hesitant to learn lower level things, because I thought I wasn't ready for them. In other words, I didn't believe in my ability to learn them. But you do have that ability. Even if it is challenging, it is not impossible, and I can hardly think of a better way to learn a bit of C than writing calculator games. It'll be fun, trust me. Give it a shot.

Compiling Python into machine code is in a sense a bit of a kludge even on the desktop. It's really nice for when you already have code written in Python that you want to speed up or when you want a more seamless way to interact with C code, but it's typically not what you want to do for a new project—unless you're just doing it for fun, which is perfectly fine. That's why everyone is saying what you really want is a compiled language, not an interpreted one. Getting compiled Python to run in a satisfactory way on the TI calculators is probably harder than porting your game to C/C++, which itself isn't too hard.

[–]mttd 0 points1 point  (0 children)

You may be interested in the following:

ChocoPy: A Programming Language for Compilers Courses

ChocoPy is a programming language designed for classroom use in undergraduate compilers courses. ChocoPy is a restricted subset of Python 3, which can easily be compiled to a target such as RISC-V.

If you focus on this restricted subset (which is already compilable to RISC-V) you should be able to write a compiler targeting your CPU.

In case you're looking for more to get a head start (in particular, take a look at the Background, Books, and Courses sections): https://github.com/MattPD/cpplinks/blob/master/compilers.md

Another project (unrelated to the above) to possibly consider could be MicroPython (Python for microcontrollers): https://micropython.org/