;HookMan hooks ;Everything in this file is extremely time-sensitive; some of these hooks are called VERY frequently ; and it needs to traverse through them as fast as possible. ;Some of these also influence the speed of BASIC programs, so they need to do very little; load each hook, call it, and move on. ;This file could probably use some serious work. ;TODO: write the code for all these hooks (!) include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN GetHookInfo,translatePage EXTERN appEnd LoadConfigFromStorageArea: ;A contains the hook block to process, or zero for everything ;Scan the application data for each hook block and process it (if we found it): ld hl,(appEnd) ld b,a loadConfigLoop: push bc ld a,(hl) ld d,h ld e,l inc hl ld c,(hl) inc hl ld b,(hl) inc hl add hl,bc pop bc inc a jr z,loadConfigDone dec a jr z,loadConfigLoop cp b jr z,foundConfigEntry ld a,b or a jr nz,loadConfigLoop foundConfigEntry: push bc push hl ld a,(de) ;A is the hook ID we really found (in case we're searching for anything) push af ld (iMathPtr5),de inc de ;now at size 1 inc de ;now at size 2 inc de ;now at number of hooks ld a,(de) dec a pop bc push bc ld a,b jr nz,enableOurHook ;We just have one hook in this block, so enable it instead of ours (less overhead) ;Install hook (ID B, address AHL) inc de ld a,(de) ld l,a inc de ld a,(de) ld h,a inc de ld a,(de) push af push hl ld a,b call GetHookInfo xor 0FFh or (hl) pop hl pop af pop bc ;AHL contains the hook page:address ;DE points to the RAM block for this hook ex de,hl ld (hl),e inc hl ld (hl),d inc hl ld (hl),a jr restartConfigLoop enableOurHook: call GetHookInfo ;Now just install it xor 0FFh or (hl) ex de,hl ld (hl),c inc hl ld (hl),b inc hl in a,(6) ld (hl),a ;And refresh the block pointer ld hl,linkActivityHookBlockPtr-2 pop bc $$: inc hl inc hl djnz $B ld de,(iMathPtr5) ld (hl),e inc hl ld (hl),d restartConfigLoop: pop hl pop bc jr loadConfigLoop loadConfigDone: ;Cache the address of the OS' internal _OffPageJump routine to RAM ld a,7Bh call translatePage ld hl,_OffPageJump ld de,OP1 ld bc,2 B_CALL FlashToRam ld de,(OP1) ld hl,offPageJumpPtr ld (hl),e inc hl ld (hl),d ret ;The hooks: ; App Change Hook ; Catalog 1 Hook ; Catalog 2 Hook ; Cursor Hook ; Font Hook ; GetKey Hook ; Graph Hook ; Graphics Hook ; Help Hook ; Homescreen Hook ; Library Hook ; Link Activity Hook ; Localize Hook ; Menu Hook ; Parser Hook ; RawKey Hook ; Regraph Hook ; Silent Link Hook ; Token Hook ; Trace Hook ; USB Activity Hook ; Window Hook ; Y Equ Hook ; cxRedisp Hook ExecuteTempHook: ld ix,myHookExecTemp push ix ; B_JUMP OffPageJump ld ix,(offPageJumpPtr) jp (ix) ret ;might not be necessary, too lazy to check SaveRegisters: pop ix push bc push af push de push hl jp (ix) RestoreRegisters: pop ix pop hl pop de pop bc ld a,b pop bc jp (ix) linkActivityHook: add a,e call SaveRegisters ld hl,(linkActivityHookBlockPtr) inc hl inc hl ld a,(hl) ld (hookExecTemp+2),a inc hl ld (hookExecTemp),hl $$: ld hl,(hookExecTemp) ld de,linkActivityHookPtr ldi ldi ldi ldi ld (hookExecTemp),hl ld hl,(linkActivityHookPtr) ld a,(linkActivityHookPtr+2) ld (myHookExecTemp+2),a B_CALL GetBytePaged ld a,b cp 83h jr nz,skipLinkActivityHook inc hl ld (myHookExecTemp),hl call RestoreRegisters call ExecuteTempHook call SaveRegisters ;Cancel the hook or whatever here by jumping to linkActivityHookDone skipLinkActivityHook: ld hl,hookExecTemp+2 dec (hl) jr nz,$B linkActivityHookDone: ld hl,linkActivityHook ld (linkActivityHookPtr),hl in a,(6) ld (linkActivityHookPtr+2),a jr RestoreRegisters ;If the above works, then the others will follow the same pattern cursorHook: add a,e ret libraryHook: add a,e ret rawKeyHook: add a,e or a ret getKeyHook: add a,e cp 1Ah jr z,$F or a ld a,b ret $$: or a ret homescreenHook: add a,e ret windowHook: add a,e ret graphHook: add a,e ret yEqualsHook: add a,e ret fontHook: add a,e ret regraphHook: add a,e ret graphicsHook: add a,e ret traceHook: add a,e ret parserHook: add a,e ret appChangeHook: add a,e ret catalog1Hook: add a,e ret catalog2Hook: add a,e ret helpHook: add a,e ret cxRedispHook: add a,e ret menuHook: add a,e ret tokenHook: add a,e ret localizeHook: add a,e ret silentLinkHook: add a,e ret USBActivityHook: add a,e ret