Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: E37 on January 19, 2016, 04:31:32 pm

Title: Key hooks
Post by: E37 on January 19, 2016, 04:31:32 pm
Ok... I am probably getting in way over my head but, can anyone explain key hooks in z80 asm?
I have mimas installed and some basic knowledge of assembler.
I mostly code in Axe but have always thought hooks were REALLY cool.
Can anyone tell me how to use them? (they will probably be included as hex code in my Axe projects)
Even an example with some comments telling me what to change would be awesome!
(I don't care if it is in mimas or true asm)

Thanks for any help! (even if it is just to tell me that this is way beyond my limited ability)
Title: Re: Key hooks
Post by: Sorunome on January 19, 2016, 04:35:50 pm
If you are just looking for some documention, wikiti has some here: http://wikiti.brandonw.net/index.php?title=Category:83Plus:Hooks
Title: Re: Key hooks
Post by: E37 on January 19, 2016, 04:42:04 pm
That seems helpful!  ;D
Are there any example programs?
Title: Re: Key hooks
Post by: chickendude on January 30, 2016, 10:07:16 pm
You could check out programs with key hooks in them, such as zStart. Actually, i just found this: Key hooks tutorial in Axe (https://www.omnimaga.org/axe-language/%28tutorial%29-key-hooks-in-axe/). I dunno how accurate it is.

Here's some code that runs prgmU instead of loading the graph equation screen when you press Y=:
Code: [Select]
.nolist
#include "ti83plus.inc"
.list

.org UserMem-2
.db $BB,$6D

hook_addr = appBackupScreen

start:
ld hl, hook_start
ld de, hook_addr
push de
ld bc, hook_end-hook_start
ldir
pop hl
ld a, 1
bcall(_SetGetKeyHook)
ret
   
hook_start:
.db $83
bit editOpen, (iy+editFlags)
ret z
cp kYequ ;if y= wasn't pressed, check if we should uninstall hook
jr nz, disableHook
ld hl, hook_addr + varname - hook_start
bcall(_Mov9toOP1)
bcall(_ChkFindSym)
jr c, disableHook ;if prgm doesn't exist
ld hl,$0055
ld (saveSScreen),hl
ld (OP1+1),hl
ld hl,saveSScreen+4
ex de,hl
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld (saveSScreen+2),bc
ldir
ld a,5
ld (OP1),a
bcall(_ChkFindSym)
jr c,$+5
bcall(_DelVarArc)
ld a,5
ld hl,saveSScreen
bcall(_ExecuteNewPrgm)
ld a, 0
ret

disableHook:
cp kGraph
ret nz
bcall(_ClrRawKeyHook)
; ld a, 0 ;pressing Graph continues to the graph screen
ret
   
varname:
.db ProgObj, "U", 0, 0
hook_end: