Alright.
When you go to install your hook, check to see if the bit is already set. If not, yay, no worries. If so, then...
Copy the 4-byte block for that hook (address, page, and page backup) into your appvar. Then install your own, which does this:
Save all registers. Look up your appvar and find the 4 bytes you saved. Use GetBytePaged or similar to get the first byte of the other hook, and make sure that it's 83h.
If it is 83h, then copy the 4 bytes to the 4-byte block, restore the registers, and call that hook. You can do this by using OffPageJump or similar. Then, once you've gotten control again, restore your own 4-byte block, and return if the hook you just called told you to. If not, do your own loader thing.
If it wasn't 83h, then just don't run it and do your own loader thing. You might also want to set some sort of flag in the appvar to not bother with chaining.
That was probably confusing, so here's the short version: when your hook gets called, restore the old hook and try calling it, then restore yourself and do your own thing.
I think I'm too lazy to write any code, but maybe you get the idea.
EDIT: Okay, I wrote it:
Code:
installMyHook:
bit 5,(iy+34h)
jr z,installRawKeyHook
ld hl,sDCSAppVar
rst 20h
B_CALL ChkFindSym
inc de
inc de
ld hl,9B84h
ld bc,4
ldir
installRawKeyHook:
ld hl,myRawKeyHook
in a,(6)
B_CALL EnRawKeyHook
ret
sDCSAppVar:
DB AppVarObj,"DCS",0
myRawKeyHook:
add a,e
push af
push de
push bc
push hl
ld hl,sDCSAppVar
rst 20h
B_CALL ChkFindSym
inc de
inc de
ex de,hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
ld h,d
ld l,e
inc de
ld (appBackUpScreen),de
ld (appBackUpScreen+1),a
B_CALL GetBytePaged
ld a,b
cp 83h
jr nz,myRawKeyHookContinue
pop hl
pop bc
pop de
pop af
ld ix,returnPoint
push ix
ld ix,appBackUpScreen
push ix
B_JUMP OffPageJump
returnPoint:
ret z ;other hook said to ignore keypress
jr $F
myRawKeyHookContinue:
pop hl
pop bc
pop de
pop af
$$:
cp kPrgm
ret nz
in a,(4)
bit 3,a
ld a,kPrgm
ret nz
ld hl,sDCS
ld de,progToEdit
ld bc,8
ldir
B_CALL ExecuteApp
sDCS:
DB "DoorsCS6"
I didn't run this and it probably doesn't work perfectly, but hopefully it gets the point across.