Now that I've solved ASM and TI-BASIC program running from C (thanks to everyone who gave me advice on that), the next task is to figure out how to open the TI-OS TI-BASIC editor from C. This is the code I have so far (lifted from BOSshell, with a virtual so that it will compile). This code seems to cause TI-OS to throw an undefined error, even though it opens the program editor. I know I've stored to OP1 correctly before running this code, thanks to the CEmu debugger. For reference, here's the code I have so far:

Code:
public _EditPrgm
include 'include/ez80.inc'
include 'include/ti84pceg.inc'

_EditPrgm:
virtual at ti.cursorImage
; required: OP1 = name of program to edit
edit_basic_program_goto:
   ld iy,ti.flags
   ld hl,string_temp
   call   ti.Mov9ToOP1
   call   ti.ChkFindSym
   xor   a,a
   ld   (ti.menuCurrent),a
   call   ti.CursorOff
   call   ti.RunIndicOff
   ld   hl,string_temp
   push   hl
   ld   de,ti.progToEdit
   call   ti.Mov9b
   pop   hl
   dec   hl
   ld   de,ti.basic_prog
   call   ti.Mov9b
   ld   a,ti.cxPrgmEdit
   call   ti.NewContext
   xor   a,a
   ld   (ti.winTop),a
   call   ti.ScrollUp
   call   ti.HomeUp
   ld   a,':'
   call   ti.PutC
   call   ti.DispEOW
   ld   hl,$100
   ld.sis   (ti.curRow and $ffff),hl
   call   ti.BufToTop
   xor   a,a
   ld   (ti.menuCurrent),a
   set   7,(iy + $28)
   jp   ti.Mon
string_temp := ti.cursorImage + $100
   load code: $-edit_basic_program_goto from edit_basic_program_goto
   end virtual
   db code

I'd appreciate any help with this, or to know if the problem trying to be solved is impossible. Worst case scenario would be scrapping this and just having programs open with KEDIT or another editor, maybe even one that I could make myself.
I remember something similar happening like that when I downloaded a small font editor for the TI-84 Plus. A program did not show how much memory it took up, and I would get "ERR:UNDEFINED" if I ran it, archived it, or deleted it.

If it's achieveable in Cesium, then it should be achieveable in C.
Made some more progress with this: I stole the code the ICE used to edit programs, and adapted it to compile with LLVM, as well as fixing up some stuff. It now goes to the editor as it should, but cannot return to the program that called it. I'd like to know whether I could reload the original program in the same way that I did in this project, or if there's something different I have to do (maybe because TI-BASIC programs and the editor are distinct in some fundamental way). Here's the code I have so far, which does work:
Code:
public _EditPrgm
include 'include/ez80.inc'
include 'include/ti84pceg.inc'

;ref __errsp

_EditPrgm:
   extern __exitsp
   ld   iy, ti.flags
   call   ti.DrawStatusBar
   pop   bc
   pop   hl
   pop   de
   ld.sis   (ti.errOffset and 0FFFFh), de
   ;os_progToEdit
   ld   de, 0xD0065B
   ld   bc, 8
   push   hl
   ldir
   pop   hl
; This is necessary because Cesium always assumes that OP1 is pushed before going into the editor
   call   ti.Mov9ToOP1
   call   ti.PushOP1
;make a reloader?

; Cleanup C things
   ld   sp,(__exitsp)
   pop   iy,af,hl
   ld   (hl),a
    call   $04F0
   ;ex   (sp), hl
   ;ld   (hl), a
   ;call   ti.usb_ResetTimer
   ;pop   hl
   ld   de, ti.plotSScreen
   ld   hl, StartProgramEditor
   ld   bc, StopProgramEditor - StartProgramEditor
   ldir
   jp   ti.plotSScreen
StartProgramEditor:
   ;not sure why this wasn't here before
   ld   hl, ti.userMem
   ld   de, (ti.asm_prgm_size)
   call   ti.DelMem
   ld   a, ti.kPrgmEd
   call   ti.NewContext
   ld.sis   bc, (ti.errOffset and 0FFFFh)
   ld   hl, (ti.editTail)
   ld   de, (ti.editCursor)
   ld   a, b
   or   a, c
   jr   z, FindPreviousEnter
   ldir
   ld   (ti.editTail), hl
   ld   (ti.editCursor), de
FindPreviousEnter:
   call   ti.BufLeft
   jr   z, AtTopOfProgram
   ld   a, e
   cp   a, ti.tEnter
   jr   z, AtStartOfLine
   inc   bc
   jr   FindPreviousEnter
AtStartOfLine:
   call   ti.BufRight
AtTopOfProgram:
   push   bc
   call   ti.ClrWindow
   ld   hl, 0000001h
   ld   (ti.curRow), hl
   ld   a, ':'
   call   ti.PutC
   call   ti.DispEOW
   pop   bc
FindCursor:
   ld   a, b
   or   a, c
   jp   z, ti.Mon
   call   ti.CursorRight
   dec   bc
   jr   FindCursor
StopProgramEditor:
  
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