Wow, bravo

C'est génial, j'ai adapté ton premier code au shell :
zSHELL.zip 

Mais je ne sais pas pourquoi j'ai des erreurs "undefined" de temps à autres (comme si
_chkfindsym ne trouvait pas le programme)...

hook.inc
zshell_hook:
.db $83 ; used by os for hook safety check (add a,e can be used too)
or a
jr z,zshell_hook_start ; we just want to handle prgm, not TI-Basic functions
zshell_hook_return_z:
xor a
ret
zshell_hook_start:
ld hl,(basic_start) ; what's on homescreen
ld a,(hl)
cp tprog
jr nz,zshell_hook_return_z ; if it don't start with "prgm", we don't care
rst rmov9toop1 ; we put "prgmANYTHING" into op1
ld hl,op1
ld (hl),progobj ; then replace "prgm" token with the program type (progobj)
bcall(_chkfindsym) ; so we can find its datas
ex de,hl ; cause of _getbytepaged parameters
ld a,e_undefined
bjumpc(_jerror) ; if not found, throw an "undefined error"
call get_byte ; else start to read it
ld e,a
call get_byte ; first two bytes are length of the program
jr c,zshell_hook_return_nz ; if empty, don't parse
ld d,a
dec de
dec de ; we don't count the first two bytes (t2bytetok/texttok+tasmcmp/tasm84ccmp) into the program length
ld (program_length_count),de
call get_byte ; skip t2bytetok/texttok
call get_byte
cp tasmcmp
jr z,zshell_hook_execute_prgm
;cp tzshellprgm
;ld hl,zshell_txt
;jr z,zshell_hook_execute_prgm
jr zshell_hook_return_z ; TI-Basic program
zshell_hook_execute_prgm:
; todo : skip zshell things
ld a,b
or a
call nz,zshell_hook_unarchive
; todo : relocate non archived prgm before launch
simpleWay:
; create space at progstart to load the program
push hl ; hl = first byte of prog data
push de ; de = prog length-2
ex de,hl ;hl = prog size
ld de,progstart ; $9d95
bcall(_insertmem) ; insert hl bytes to progstart
pop bc ; bc = size of program
pop hl ; hl = first byte of program data
push bc ; save size of program
add hl,bc ; we've inserted bc bytes ;)
ldir ; de = progstart
call progstart ; run the program
; now delete that memory
pop de ; de = number of bytes to delete
ld hl,progstart ; hl = where to delete them from
bcall(_delmem)
ret
zshell_hook_unarchive:
push hl
ld hl,(program_length_count)
push bc
bcall(_enoughmem)
pop bc
pop hl
ld a,e_memory
bjumpc(_jerror)
ld a,b
ld de,progstart
ld bc,(program_length_count)
bcall(_flashtoram)
ret
zshell_hook_return_nz:
or $80 ; reset zero flag, the parser can't continue to parse the variable
ret
Enfaite j'ai utilisé
call get_byte pour calculer la taille du programme et son type pour ne pas avoir plus tard à d'abord désarchiver le programme avant de le tester (savoir s'il est vide et si c'est bien un programme ASM, enfin quoique si on veut permettre l'exécution de programmes TI-Basic archivés...?)
Je vais adapter le "hard way" (ah et je n'ai pas testé le désarchivage, mais ça m'étonnerai que ça marche)
edit : autrement je n'avais pas fait gaffe, mais un shell TI 85 porte déjà ce nom
ZShell (enfin c'est pas exactement identique, mais ça peut être trompeur, non ?). J'aime bien ce nom mais s'il faut on peut le changer.
edit 2 : voilà :
hook.inc
zshell_hook:
.db $83 ; used by os for hook safety check (add a,e can be used too)
or a
jr z,zshell_hook_start ; we just want to handle prgm, not TI-Basic functions
zshell_hook_return_z:
xor a
ret
zshell_hook_start:
ld hl,(basic_start) ; what's on homescreen
ld a,(hl)
cp tprog
jr nz,zshell_hook_return_z ; if it don't start with "prgm", we don't care
rst rmov9toop1 ; we put "prgmANYTHING" into op1
ld hl,op1
ld (hl),progobj ; then replace "prgm" token with the program type (progobj)
bcall(_chkfindsym) ; so we can find its datas
ex de,hl ; cause of _getbytepaged parameters
ld a,e_undefined
bjumpc(_jerror) ; if not found, throw an "undefined error"
call get_byte ; else start to read it
ld e,a
call get_byte ; first two bytes are length of the program
jr c,zshell_hook_return_nz ; if empty, don't parse
ld d,a
dec de
dec de ; we don't count the first two bytes (t2bytetok/texttok+tasmcmp/tasm84ccmp) into the program length
ld (program_length_count),de
call get_byte ; skip t2bytetok/texttok
call get_byte
cp tasmprgm
jr z,zshell_hook_execute_unsquished_asm_prgm
cp tasmcmp
jr z,zshell_hook_execute_compiled_asm_prgm
;cp tzshellprgm
;ld hl,zshell_txt
;jr z,zshell_hook_execute_zshell_prgm
jr zshell_hook_return_z ; TI-Basic program
zshell_hook_execute_unsquished_asm_prgm:
;call zshell_hook_program_start_begin
bcall(_executeprgm) ; can only run unarchived prgm
jr zshell_hook_return_nz
zshell_hook_execute_compiled_asm_prgm:
call zshell_hook_program_start_begin
zshell_hook_load:
push hl ; how many bytes left to copy
ld hl,(progaddress) ; copy the program to the gbuf
push bc ; hl = program data start
ld de,gbuf ; bc = # bytes to copy
ldir ; copy bc bytes
pop de ; # bytes copied
ld (progaddress),hl ; save new program data pointer
; delete bc bytes from the program
or a ; hl = start of prog data+768
sbc hl,de
push de ; de = # of bytes copied
bcall(_delmem) ; hl = where to delete from, de = # bytes
pop hl ; hl = # bytes deleted
; insert HL bytes to $9d95
ld de,(progstartlocation) ; progstart ($9d95)
push hl ; hl = # bytes deleted
bcall(_insertmem) ; insert hl bytes to $9d95
pop bc ; bc = bytes deleted
ld hl,(progstartlocation) ; ex de,hl ???
add hl,bc
ld (progstartlocation),hl
; copy gbuf to $9d95
ld hl,gbuf ; de = location where memory was inserted ($9d95+XXXX)
ldir ; copy # of bytes deleted from gbuf to progstart
pop hl ; how many bytes are left to copy
ld a,l
or h
jr nz,zshell_hook_load_loop
call progstart ; run the program
; now rewrite the data back into the program
; ...not done yet...
zshell_hook_return_nz:
or $80 ; reset zero flag, the parser can't continue to parse the variable
ret
zshell_hook_program_start_begin:
ld a,b
or a
call nz,zshell_hook_unarchive
; hl = first byte of program data
; de = program length-2
ld bc,progstart
ld (progstartlocation),bc
ld (progaddress),hl
ex de,hl ; hl = length
zshell_hook_load_loop:
ld bc,768 ; check if there are <768 bytes left to copy (gbuf length)
or a
sbc hl,bc ; subtract 768 from the program size
ret nc ; if no carry, there are still more than 768 bytes to copy
add hl,bc
ld b,h
ld c,l
ld hl,$0000
ret
zshell_hook_unarchive:
push hl
ld hl,(program_length_count)
push bc
bcall(_enoughmem)
pop bc
pop hl
ld a,e_memory
bjumpc(_jerror)
ld a,b
ld de,progstart
ld bc,(program_length_count)
bcall(_flashtoram)
ret
Enfaite les erreurs "undefined" étaient simplement dues au fait que le hook se terminait avec le zero flag mis
