Hey all!

I'm trying to make a new program, which first installs a GetKeyHook. If you press Y=, the equation editor, I wanna run prgmU, but this doesn't seems to work. When I run this code for the first time, all is ok. But when I press a key which is NOT Y=, it freezes. Why? Any ideas?


Code:
.nolist
#include "ti83plus.inc"
.list

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

start:
   ld hl, $9DA9
   ld de, $8000
   ld bc, $0019
   ldir
   ld hl, $8000
   ld a, 1
   bcall(_SetGetKeyHook)
   ret
   
   .db $83
   bit 2, (iy+1)
   ret z
   cp kYequ
   jr nz, disableHook
   ld hl, varname
   bcall(_Mov9toOP1)
   bcall(_ChkFindSym)
   jr c, disableHook
   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
   ret
   
varname:
   .db ProgObj, "U", 0, 0


EDIT: I figured out that I need to ldir more bytes, so I changed ld bc, $0019 to ld bc, 100. That doesn't freeze, but prgmU don't run when I press Y=
A few issues that I notice:
1) $8000 is only safe for hooks for a very short time, until the calculator Archives or Unarchives things or runs an App.
2) Why hard-code your addresses like that instead of using labels?
3) varname needs to be relative to $8000 instead of $9D95. You can use .rorg $8000 / .org $8000 before your hook code or use varname - hookstart + $8000.
That is for later care. My first primary goal is to get it working. Problem: the 2 programs seperately works, but not together. I mean,

Code:
.nolist
#include "ti83plus.inc"
.list

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

start:
   ld hl, UserMem+20
   ld de, bootbtf
   ld bc, 100
   ldir
   ld hl, bootbtf
   ld a, 1
   bcall(_SetGetKeyHook)
   ret
   
   .db $83
   bit 2,(iy+1)
   ret z
   cp kYequ
   jr nz,disableHook
   bcall(_DispTail)
      ld a, 0
      ret
   
disableHook:
   cp kGraph
   ret nz
   bcall(_ClrRawKeyHook)
   ld a,$00
   ret
   
varname:
   .db ProgObj, "U", 0, 0

works, and

Code:
.nolist
#include "ti83plus.inc"
.list

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

start:
   ld hl, varname
      bcall(_Mov9toOP1)
      bcall(_ChkFindSym)
      ret c
      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)

varname:
   .db ProgObj, "U", 0, 0

too, but not both (code in my first post). Why not?
You'll avoid a lot more mistakes using labels. If it's only a few bytes (like the jr) that's more manageable, but you'll be adding and removing code all the time here, so why not just add a label? It'll save you a lot of headaches when you're debugging and realize you just added an extra byte here or there.

Also, are you running the program through a shell such as zStart or DoorsCS? That might cause conflicts. This code works for me (with zStart/Doors turned off):

Code:
.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:
Wow, that seems indeed to work. Thanks! Smile
Now a second question: if something set or whatever, when you're editing a BASIC program on-calc? That is, I would like to change the code above, such that it only works when you edit a program, and after running prgmU, that it returns to the editor? Is that possible?

EDIT: it looks like you already did that, but it doesn't seem to work. When I'm at the homescreen, prgmU runs normally, and at the editor, prgmU runs, but doesn't work correctly
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement