;Routines for InstHook (integrated hook install) interface include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN IsEnoughUserMemory,UnlockFlash,DefragmentAppStorage,GetFreeStorageArea InstallHook: ;Inputs: HL: zero-terminated name (8 bytes max) of this hook, or 0000h for no name ; DE: address of hook data ; BC: size of the hook data ; A: flags byte (zero for defaults): ; Bit 0: set to NOT defragment to try and recover space for this hook. ; Bit 1: set to display "Defragmenting..." and progress at bottom of screen if defragmenting if necessary ; Bit 2: set to preserve hooks that are currently "invalid" if defragmenting if necessary ; The reason why you'd want to do this is if you've temporarily disabled hooks that could be installed here ; (you would be killing them by erasing them in the defragment, even though they're only temporarily invalid). ;Outputs: Returns carry flag set if space could not be found for hook data ; HL: address of the hook data ; A: page of the hook data ;Destroys all registers, asm_Flag3, appBackUpScreen, and some archive-related system RAM (see UnlockFlash) res silentInstall,(iy+hookManFlags) bit 1,a jr z,$F set silentInstall,(iy+hookManFlags) $$: res preserveHooks,(iy+hookManFlags) bit 2,a jr z,$F set preserveHooks,(iy+hookManFlags) $$: push hl push de push bc push af call UnlockFlash pop af pop bc push bc push af ld h,b ld l,c call IsEnoughUserMemory pop bc ld a,b bit 0,a jr z,$F ;try defragmenting first jr c,P3ret ;we aren't allowed to attempt defragmenting and we don't have the space, so get out $$: call c,DefragmentAppStorage pop hl push hl call IsEnoughUserMemory jr c,P3ret ;we tried defragmenting and we still don't have it, so get out ;STKT: size of the hook data ;STK1: address of hook data ;STK2: hook name pop bc pop de pop hl push de push bc push hl call GetFreeStorageArea pop de ex de,hl ;DE is the place to write to ;HL is the hook name (or 0000h) push de push hl B_CALL ZeroOP1 pop hl ld a,h or l jr z,$F rst 20h $$: pop de ;Hook name is in OP1 ;DE is the place to write to pop bc push bc ;BC is the size of the hook data ld hl,8 add hl,bc push de ex de,hl ld hl,OP2 ld (hl),hookDataID inc hl ld (hl),e inc hl ld (hl),d ld hl,OP2 pop de push de in a,(6) ld bc,3 B_CALL WriteFlash pop de inc de inc de inc de ld hl,OP1 ld bc,8 in a,(6) push de B_CALL WriteFlash pop hl ld hl,8 add hl,bc ex de,hl pop bc pop hl in a,(6) B_CALL WriteFlash or a ret P3ret: pop bc pop bc pop bc ret