Author |
Message |
|
Jeffrey
Member
Joined: 12 Jun 2003 Posts: 212
|
Posted: 09 Nov 2003 10:12:42 pm Post subject: |
|
|
I was working on my password protection program, AEGIS 1, and was 99% done. You could edit your password, change options, it was ready for distribution. Then I noticed there was some kind of memory leak: every time I ran the program I started running out of free RAM. I narrowed it down to one out of 1350 lines of code. The keyhook was terminating with a bjump(_jforcecmdnochar), a no-no in an ASM RAM program. But when I replaced it with a ret, the keyhook didnt work. I tried the keyhook script from Cirrus next, it only works for blocking the keys, and that isnt what I want to do.
I am trying to run a block of code when the program key is hit. I was just trying to get this code to work below. Now, if I replace the ret with a bjump(_jforcecmdnochar), it works fine, but that results in a memory leakage.
How do I do this in a normal NOSTUB ASM RAM program?
Code: ld hl,keyhook
ld bc,hook_end-keyhook
ld de,appbackupscreen
ldir ;Copy the code to a safe RAM location
ld hl,appbackupscreen;
in a,(6);Get the mem page
bcall($4F66);Install the key hook
bjump(_jforcecmdnochar)
keyhook: ;The actual routine
add a,e
ld (asave),a
cp kprgm;prgm-key?
jp z,prgmblock;Then disable it...
ret
prgmblock:
ld hl,567
bcall(_disphl)
bcall(_getkey)
jp keyend
keyend:
ld a,(asave)
ret
asave:
.db $21
hook_end:
I think the hook_end might be out of place, but I have tried it virtually everywhere, made no difference.
Also, does anyone know how to do the 2 key combo keyhooks, like On + Apps will run some code. Any help would be greatly appreciated, and you will be added to the credits of my first UTI program (wow, what an honor...not)!
Last edited by Guest on 09 Nov 2003 10:14:00 pm; edited 1 time in total |
|
Back to top |
|
|
NETWizz Byte by bit
Bandwidth Hog
Joined: 20 May 2003 Posts: 2369
|
Posted: 09 Nov 2003 10:29:22 pm Post subject: |
|
|
I wil post a program I made that uses ON+key
As for your program, you need to decide if it is an app or an asm program. If it is an asm program, you do not use bjump(_Jforce... to exit. You use ret
If it is an app, do not copy the hook to the appbackupscreen, simply set the flash page and do the hook.
For an app:
ld hl,keyhook
in a,(6);Get the mem page
bcall($4F66);Install the key hook
bjump(_jforcecmdnochar)
You see, I removed the copying to appbackupscreen (safe mem area) because nothing is safer than a flash page, and it makes your coding easier.
Be sure (asave) corasponds to a safe memory area that is in ram not the flash archive.
I think that will at least make your keyhook work. |
|
Back to top |
|
|
Jeffrey
Member
Joined: 12 Jun 2003 Posts: 212
|
Posted: 09 Nov 2003 10:35:32 pm Post subject: |
|
|
I meant this to be an ASM prog, not an APP, so I shouldnt have had the BJUMP in there. Remarkably it only works with the BJUMP, not the ret. The ASAVE is there to save the keypress, so it can complete it once the code is through executing.
So now:
Code: ld hl,keyhook
ld bc,hook_end-keyhook
ld de,appbackupscreen
ldir ;Copy the code to a safe RAM location
ld hl,appbackupscreen;
in a,(6);Get the mem page
bcall($4F66);Install the key hook
ret
keyhook:;The actual routine
add a,e
ld (asave),a
cp kprgm;prgm-key?
jp z,prgmblock;Then disable it...
ret
prgmblock:
ld hl,567
bcall(_disphl)
bcall(_getkey)
jp keyend
keyend:
ld a,(asave)
ret
asave:
.db $21
hook_end:
But that doesnt work, where the first code I posted did. This, though, creates the memory leak I was talking about.
In other words, with the RET, the program does not execute the code (displaying HL) when the program key is pressed. With the bjump, it does.
Last edited by Guest on 09 Nov 2003 10:37:22 pm; edited 1 time in total |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 09 Nov 2003 10:40:27 pm Post subject: |
|
|
Jeffrey wrote: I was working on my password protection program, AEGIS 1, and was 99% done. You could edit your password, change options, it was ready for distribution. Then I noticed there was some kind of memory leak: every time I ran the program I started running out of free RAM. I narrowed it down to one out of 1350 lines of code. The keyhook was terminating with a bjump(_jforcecmdnochar), a no-no in an ASM RAM program. But when I replaced it with a ret, the keyhook didnt work. I tried the keyhook script from Cirrus next, it only works for blocking the keys, and that isnt what I want to do.
I am trying to run a block of code when the program key is hit. I was just trying to get this code to work below. Now, if I replace the ret with a bjump(_jforcecmdnochar), it works fine, but that results in a memory leakage.
How do I do this in a normal NOSTUB ASM RAM program?
Code: ld hl,keyhook
ld bc,hook_end-keyhook
ld de,appbackupscreen
ldir ;Copy the code to a safe RAM location
ld hl,appbackupscreen;
in a,(6);Get the mem page
bcall($4F66);Install the key hook
bjump(_jforcecmdnochar)
keyhook: ;The actual routine
add a,e
ld (asave),a
cp kprgm;prgm-key?
jp z,prgmblock;Then disable it...
ret
prgmblock:
ld hl,567
bcall(_disphl)
bcall(_getkey)
jp keyend
keyend:
ld a,(asave)
ret
asave:
.db $21
hook_end:
I think the hook_end might be out of place, but I have tried it virtually everywhere, made no difference.
Also, does anyone know how to do the 2 key combo keyhooks, like On + Apps will run some code. Any help would be greatly appreciated, and you will be added to the credits of my first UTI program (wow, what an honor...not)!
There are a few problems with your code First of all if this is a no-shell asm program do not use a bcall(_jforcecmdnochar) at all!
2nd if you are trying to block a keypress you must make a equal 0 to represent it as there being no keypress.
Therefore you do not need to save the keypress.
Here's my modded version.
Code: ld hl,keyhook
ld bc,hook_end-keyhook
ld de,appbackupscreen
ldir ;Copy the code to a safe RAM location
ld hl,appbackupscreen;
in a,(6);Get the mem page
bcall($4F66);Install the key hook
ret
keyhook: ;The actual routine
add a,e
cp kprgm ;prgm-key?
jp z,prgmblock ;We want to control this key so jump to prgmblock
;Note here we do not 0 a so the keypress will be delt with normally by the TI-OS
ret
prgmblock:
ld hl,567
bcall(_disphl) ;Display hl as you wanted to, I don't know why
xor a ;a=0 to represent no keypress
ret
;This way it displays 00567 and blocks the keypress.
hook_end:
|
|
Back to top |
|
|
Jeffrey
Member
Joined: 12 Jun 2003 Posts: 212
|
Posted: 09 Nov 2003 10:51:04 pm Post subject: |
|
|
I copied your source exactly, an for some reason it doesnt work.
I only needed to display HL as a demonstration, to see if I could execute code after a keypress.
And since this will be a password program, after the key is pressed it will ask for a password, then open the menu, thus I dont need the XOR. Like if I hit the program menu it will ask the user for his password, will compare it with a password stored in an appvar, then enter the programs menu if the password is correct. Thus I could either load Kprgm into A before I ret, or just store a to Asave if I am dealing with more than 1 menu before the end. |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 09 Nov 2003 11:05:22 pm Post subject: |
|
|
*bangs head against desk*
I missed something, in an ram based key hook, (No-shell) in order to jump to the appropriate label or call it you must use a different syntax.
jp z,appbackupscreen+(prgmblock-keyhook)
same if you wanted to call a label
call appbackupscreen+(label-keyhook)
The reason being. When the compiler assembles the program it's assuming the code is going to be executed from userMem.
In this case it will not, so we need to create an offset to jump to the appropriate label.
appbackupscreen is the buffer the code resides in
label-keyhook finds the total bytes from the beggining of the keyhook code to the label we are trying to find is.
so we add the two together
appbackupscreen+(label-keyhook)
Last edited by Guest on 09 Nov 2003 11:06:57 pm; edited 1 time in total |
|
Back to top |
|
|
Jeffrey
Member
Joined: 12 Jun 2003 Posts: 212
|
Posted: 10 Nov 2003 11:06:51 am Post subject: |
|
|
Thank you!!! I was very dismayed when the program I was working on all weekend had one fatal error. This should fix it, but I am away from a TASM, so I will try it later. |
|
Back to top |
|
|
NETWizz Byte by bit
Bandwidth Hog
Joined: 20 May 2003 Posts: 2369
|
Posted: 10 Nov 2003 03:12:48 pm Post subject: |
|
|
If you wish to return a different key, do this:
cp kprgm
jp z,changekey
ret
changekey:
ld a,kmode
or a
After setting up that hook, pressing the program key will open the mode menu. As you can see, you can have fun with this. |
|
Back to top |
|
|
Darth Android DragonOS Dev Team
Bandwidth Hog
Joined: 31 May 2003 Posts: 2104
|
Posted: 16 Dec 2003 11:20:26 pm Post subject: |
|
|
i think the .org command in task defines where in memory the thing is executed from. can you change it mid program?
also... is the key hook only run when someone presses a key?
Last edited by Guest on 16 Dec 2003 11:21:12 pm; edited 1 time in total |
|
Back to top |
|
|
|