Alright, i took some time to recode the whole thing, in a more universal way.
It's compatible with all TI-8X+ models (monochrome screen, at least).
It's larger than quigibo's orginal code (which has probably been updated since), but it doesn't cause any stack leak.
You'll have to manually unarchive the program first if it's not already in RAM.
Code: ;prgmedita - app variant
;DESCRIPTION
;Exits the application, opens the program editor for the specified program, and
; sets the cursor to the specified location.
;This code is to be simply executed, not called.
;Inspired by quigibo's code.
;IN
;target program type : unprotected
;target program location : RAM
;bc = target line offset (see NOTES)
;de = target cursor offset (see NOTES)
;hl = target program name address (0-terminated if not 8 bytes long)
;iy = flags
;NOTES
;bc = line first address - program first address (right after size word)
;de = cursor address - line first address
;It's not allowed to point to the second byte of a word token.
;It's allowed to point to the address right after the last token of the program.
;If the program is empty, both offsets must be equal to zero.
prgmedita
ld (appbackupscreen),bc
ld (appbackupscreen+2),de
ld (appbackupscreen+4),hl
ld de,appbackupscreen+6
ld hl,flags+hookflags2
ld a,(hl)
ld (de),a
or %00000001
ld (hl),a
ld bc,3
inc de
ld hl,getkeyhookptr
ldir
ld hl,prgmedita_hook
ld (getkeyhookptr),hl
in a,($06)
ld (getkeyhookptr+2),a
bcall(_jforcecmdnochar)
prgmedita_hook
.db $83
di
in a,($02)
rla
jr nc,prgmedita_initialise
ld a,$01
out ($20),a
prgmedita_initialise
bcall(_cursoroff)
di
ld a,cxprgmedit
ld bc,8
ld de,progtoedit
ld hl,(appbackupscreen+4)
ldir
ld c,4
ld de,flags+hookflags2
ld hl,appbackupscreen+6
ldi
ld de,getkeyhookptr
ldir
bcall(_newcontext0)
di
ld bc,(appbackupscreen)
ld a,b
or c
jr z,prgmedita_line_start
ld de,(edittop)
ld hl,(edittail)
ldir
ld (editcursor),de
ld (edittail),hl
prgmedita_line_start
ld de,(editcursor)
ld ix,(appbackupscreen+2)
ld iy,0
in a,($02)
and %00100000
ld a,10
jr z,prgmedita_ready
inc a
prgmedita_ready
ex af,af'
jp prgmedita_check_counter_a
prgmedita_next_token
ld a,(de)
ex af,af'
ld c,a
ex af,af'
inc de
ld hl,prgmedita_word_tokens
dec ix
inc iy
cpir
jr nz,prgmedita_check_counter_a
inc de
dec ix
prgmedita_check_counter_a
ld a,ixh
or ixl
jp nz,prgmedita_next_token
push iy
ld iy,flags
bcall(_dispeow)
di
jp prgmedita_check_counter_b
prgmedita_advance_cursor
dec bc
push bc
bcall(_cursorright)
di
prgmedita_check_counter_b
pop bc
ld a,b
or c
jp nz,prgmedita_advance_cursor
ld (kbdscancode),a
ret
prgmedita_word_tokens
.db tvarmat,tvarlst,tvarequ,tvarpict,tvargdb,tvarout,tvarsys,tgformat,tvarstrng
.db t2bytetok,tunused01
Code: ;prgmeditb - prgm variant
;DESCRIPTION
;Exits the program, opens the program editor for the specified program, and sets
; the cursor to the specified location.
;This code is to be simply executed, not called.
;This code is expected to be executed from a program that was properly loaded
; from the homescreen (shells unsupported).
;Inspired by quigibo's code.
;IN
;interrupts : disabled
;target program type : unprotected
;target program location : RAM
;bc = target line offset (see NOTES)
;de = target cursor offset (see NOTES)
;hl = target program name address (0-terminated if not 8 bytes long)
;iy = flags
;NOTES
;bc = line first address - program first address (right after size word)
;de = cursor address - line first address
;It's not allowed to point to the second byte of a word token.
;It's allowed to point to the address right after the last token of the program.
;If the program is empty, both offsets must be equal to zero.
prgmeditb
res oninterrupt,(iy+onflags)
ld (appbackupscreen),bc
ld (appbackupscreen+2),de
ld bc,8
ld de,appbackupscreen+4
ldir
ld hl,flags+hookflags2
ld a,(hl)
ld (de),a
or %00000001
ld (hl),a
ld c,3
inc de
ld hl,getkeyhookptr
ldir
ld (getkeyhookptr),de
dec hl
ld (hl),$01
ld c,prgmeditb_hook_end-prgmeditb_hook_start
ld hl,prgmeditb_hook_start
ldir
in a,($02)
and %00100000
ret nz
ld a,10
ld (prgmeditb_variable-prgmeditb_hook_start+appbackupscreen+16),a
ret
prgmeditb_hook_start
.db $83
di
in a,($02)
rla
jr nc,prgmeditb_initialise
ld a,$01
out ($20),a
prgmeditb_initialise
bcall(_cursoroff)
di
ld a,cxprgmedit
ld bc,8
ld de,progtoedit
ld hl,appbackupscreen+4
ldir
ld c,4
ld de,flags+hookflags2
ldi
ld de,getkeyhookptr
ldir
bcall(_newcontext0)
di
ld bc,(appbackupscreen)
ld a,b
or c
jr z,prgmeditb_line_start
ld de,(edittop)
ld hl,(edittail)
ldir
ld (editcursor),de
ld (edittail),hl
prgmeditb_line_start
ld de,(editcursor)
ld ix,(appbackupscreen+2)
ld iy,0
jp prgmeditb_check_counter_a-prgmeditb_hook_start+appbackupscreen+16
prgmeditb_next_token
ld a,(de)
.db $0E ; ld c,* first half
prgmeditb_variable
.db 11 ; ld c,* second half
inc de
ld hl,prgmeditb_word_tokens-prgmeditb_hook_start+appbackupscreen+16
dec ix
inc iy
cpir
jr nz,prgmeditb_check_counter_a
inc de
dec ix
prgmeditb_check_counter_a
ld a,ixh
or ixl
jp nz,prgmeditb_next_token-prgmeditb_hook_start+appbackupscreen+16
push iy
ld iy,flags
bcall(_dispeow)
di
jp prgmeditb_check_counter_b-prgmeditb_hook_start+appbackupscreen+16
prgmeditb_advance_cursor
dec bc
push bc
bcall(_cursorright)
di
prgmeditb_check_counter_b
pop bc
ld a,b
or c
jp nz,prgmeditb_advance_cursor-prgmeditb_hook_start+appbackupscreen+16
ld (kbdscancode),a
ret
prgmeditb_word_tokens
.db tvarmat,tvarlst,tvarequ,tvarpict,tvargdb,tvarout,tvarsys,tgformat,tvarstrng
.db t2bytetok,tunused01
prgmeditb_hook_end