(name is subject to change - let me know if you have any suggestions)
I'm working on a patch for the CE Python app that allows you to call LibLoad library functions, among other things.

Currently, it's able to load LibLoad libraries and call functions from them, but I'm still working on creating reasonably Pythonic wrappers for the existing libraries.

Normally I'd share a animated screenshot here, but CEmu doesn't yet emulate the Python hardware well enough to get to the point where it could actually run my code. So instead, just have a code snippet (that works on hardware!) and like imagine what it looks like:

Code:
import graphxpy
with graphxpy.GfxContext() as gfx:
  gfx.set_draw(1)
  for i in range(128):
    gfx.fill_screen(i)
    gfx.set_color(255 - i)
    gfx.fill_rectangle(25,i,50,12)
    gfx.set_text_xy(26,i+1)
    gfx.print_string("hello python")
    gfx.blit(1)

There's also this potato-quality YouTube video of an older build, I guess:


Those are basically the only functions implemented so far, but it's not particularly hard to add new ones. For functions that only take numeric arguments (no pointers) I just have to specify the argument names and the relative address of the function. I may do something fancier with classes for things like sprites.

Unfortunately performance isn't that great at the moment - the Python-side code takes a few milliseconds per function call, and all functions are blocking. I'll try to rewrite the Python code to minimize the number of memory allocations, since I didn't really care about that in my original implementation. I might also have the command for calling a function tell the ez80 whether and what to return, allowing for a non-blocking function.

Internally, the communication between the coprocessor and the ez80 uses CSI sequences, like the ti_graphics commands do. There are commands for checking the version, loading a LibLoad library, calling a function, reading data, writing data, setting memory to a single byte, allocating memory, freeing memory, and freeing all memory.
Variable-length data is transmitted with a 6-bit encoding, as values greater than 127 bork the coprocessor, and newlines get automatically converted to CRLF. It transmits data in 24-bit blocks, even if the data is not a multiple of 3, since I'm somewhat lazy it reduces code size.

I have a few other features I may add in the future, since I can change whatever I want in the app:
    Function for disabling keypad input to the terminal emulator - would be helpful when using libraries that access the keypad
    Update to the latest circuitpython version - the main issue here is that TI distributed some modules in bytecode form which are incompatible with newer micropython versions, so I would have to either decompile or recreate these modules if I wanted this program to be backward-compatible
    Add an ExecLib thing for running or editing a program from TI-BASIC or a compatible program (e.g. Cesium)

In order to distribute this without violating TI's EULA, I wrote a Javascript-based app patcher that uses the relocation table to patch an app locally without having to disassemble the entire thing or to distribute slightly-modified portions of TI code. Since apps need to be signed by TI, it instead creates a program that installs an app similarly to Cesium. You'll obviously need an exploit like arTIfiCE to use this.

Unfortunately it's still not ready for even a beta release at this point, as the installer tends to overwrite the OS if you haven't garbage collected recently or have too much data in archive. If you're interested in contributing or giving feedback, shoot me a DM and I can get you access to the repository.
That's a neat trick.

commandblockguy wrote:
[A]ll functions are blocking.

Yeah, I was thinking about hooking up a Pi Pico and figured you'd have to have an asynchronous command/data FIFO in each direction to keep performance reasonable. I'm not sure how big the UART FIFO is, though, so you might be forced to resort to polling periodically while executing commands. Come to think of it, it's got to be a one-byte FIFO because that's the slowest-possible implementation, so it has to be the one TI chose.
You could call it something like "LibPyCE" or "Pylib."
As in, libpng style
I've worked on this a bit more, and fixed some of the major issues with it. It no longer borks the OS when installing (instead prompting you to garbage collect if there's no space, rather than bulldozing over everything), and doesn't leak RAM every time you load a library. I've also removed the cursor and the run indicator while graphx is doing its thing.

More visibly, I've also implemented a module for doing a non-blocking read of the keyboard. Here's a demo:

And the corresponding code:

Code:
import graphxpy, ez80, keypadpy

with graphxpy.GfxContext() as gfx:
  gfx.set_draw(1)
  x = 50
  y = 50
  while True:
    keys = keypadpy.get_keys()
    if keys.is_down(keypadpy.KEY_CLEAR):
      break
    if keys.is_down(keypadpy.KEY_LEFT):
      x -= 5
    if keys.is_down(keypadpy.KEY_RIGHT):
      x += 5
    if keys.is_down(keypadpy.KEY_UP):
      y -= 5
    if keys.is_down(keypadpy.KEY_DOWN):
      y += 5
    gfx.fill_screen(255)
    gfx.set_color(248)
    gfx.fill_rectangle(x,y,50,12)
    gfx.set_text_xy(x,y)
    gfx.print_string("hello python")
    gfx.blit(1)


I might write a full snake game as a test program at some point.

I'll probably work on the wrapper for the rest of the graphx functions next, and then try to implement some variable IO functions. It would also be neat to be able to run TI-BASIC from Python, but I'm not how feasible that is, since IIRC BASIC clobbers a lot of the memory that the app uses.
Nice work, this is coming along very nicely.

I would be very interested to see how sprites and tilemaps and stuff could be possible.
Great progress Smile
Hey do you think you could release this? I would love to play around with it on my calculator.
SharkTaleLover wrote:
Hey do you think you could release this? I would love to play around with it on my calculator.

Sorry to necro post but could you put what you have so far on github for everyone to mess with, and possibly find bugs? Razz
eh, sure, why not: https://github.com/commandblockguy/tipython-plus

note that it's still very broken, and you'll need a copy of whatever version of the Python app was most recent at the time that I created this to even be able to use it.
Thanks this is cool, hopefully some other people will pick up the project.
Im sorry for necroposting, but im unable to get the site in the github to work, and i want to use this for a small test project.

it throws this error:

Uncaught (in promise) ReferenceError: pythonPatch is not defined
getPatchedInstaller file:///C:/Users/User/Downloads/tipython-plus-main/site/patch.js:463
handleFile file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:2
handleChange file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:17
EventListener.handleEvent* file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:24

I tried looking into it, but my very limited knowledge of JS is just not enough
Jelte2357 wrote:
Im sorry for necroposting, but im unable to get the site in the github to work, and i want to use this for a small test project.

it throws this error:

Uncaught (in promise) ReferenceError: pythonPatch is not defined
getPatchedInstaller file:///C:/Users/User/Downloads/tipython-plus-main/site/patch.js:463
handleFile file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:2
handleChange file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:17
EventListener.handleEvent* file:///C:/Users/User/Downloads/tipython-plus-main/site/site.js:24

I tried looking into it, but my very limited knowledge of JS is just not enough


You should be aware that the code is completely broken and that I mostly just put it on GitHub for reference purposes. I'm certainly no longer developing it.

This error is probably caused by python.js not existing. Make sure you run make before opening anything in a web browser.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement