Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: TiAddict on May 17, 2011, 07:23:39 pm

Title: about hooks..
Post by: TiAddict on May 17, 2011, 07:23:39 pm
Umm how does hooks work?:P i want to make a token like "csc("
please, detailed explanation :)
Title: Re: about hooks..
Post by: Hot_Dog on May 17, 2011, 08:28:15 pm
Well, what you're talking about is a "token" hook.  (There are many different kinds of hooks.)  You would have to pick a token to CHANGE to csc(.  Unfortunately you cannot create your own token.

So I can only give you a semi-detailed explination, since I do not know what token you would want to change to csc(.  You take the value of the token you want to change, multiply it by 2, and put the value in DE.  HL should point to the location in RAM that the zero-terminated (I think)  name of your token is located at.

http://wikiti.brandonw.net/index.php?title=83Plus:Hooks:9BC8
Title: Re: about hooks..
Post by: TiAddict on May 17, 2011, 08:42:12 pm
oh thanks :) and i want to change "sinh("(C8h) to "csc(" can you show me how should i do this?

 btw is it possible to hide the tokens?
Title: Re: about hooks..
Post by: Hot_Dog on May 17, 2011, 08:53:57 pm
Please refrain from double posting.  I combined your two posts into one.
Title: Re: about hooks..
Post by: TiAddict on May 17, 2011, 09:00:48 pm
alright thanks
Title: Re: about hooks..
Post by: thepenguin77 on May 17, 2011, 09:29:07 pm
Here you go. This is a sample implementation of what you want to do.
Code: [Select]
ld hl, tokenHook
ld de, smallEditRam ;nothing touches this, ever
ld bc, tokenHookEnd-tokenHook
ldir ;copy it to a place where it won't get destroyed

ld a, 1 ;1 means ram
ld hl, smallEditRam
bcall(_enableTokenHook)
ret




tokenHook:
.db $83 ;necessary for hooks, indicates that it hasn't been overwritten
push hl
ld hl, $C8*2
or a
sbc hl, de
add hl, de ;essentially, cp DE
pop hl
ret nz
ld hl, cscText-tokenHook+smallEditRam-1 ;give it a ptr 1 behind where it should be
ret ;I do not know why

cscText:
.db 4, "csc(" ;length, then string

tokenHookEnd:

If you are writing an App, then obviously you do not need to relocate this to smallEditRam. If you get some compiler errors, (you will), check this (http://brandonw.net/calcstuff/ti83plus.txt) to get the equates you need. (Ctrl + F to find what you need)

Also, don't forget that just because you changed the words, it doesn't mean that you actually changed the function. For that, you are going to have to go into the scary world of  parser hooks (http://wikiti.brandonw.net/index.php?title=83Plus:Hooks:9BAC).

Lastly, I just remembered that I actually wrote a guide (http://wikiti.brandonw.net/index.php?title=83Plus:OS:Hooks) on this.
Title: Re: about hooks..
Post by: TiAddict on May 17, 2011, 10:24:18 pm
Ah thank you :) and is it okay if i use .db     "csc(",0  instead of  .db     4, "csc("?
because the "sinh(" changes to "sc(..........", not "csc("
Title: Re: about hooks..
Post by: thepenguin77 on May 17, 2011, 10:35:41 pm
Ummm... Maybe. I thought I tried that and it didn't work. But if it works for you, then good. There must be a flag or something we don't know about.
Title: Re: about hooks..
Post by: TiAddict on May 17, 2011, 10:43:49 pm
Oh well then:P and I spasm assembler gives me error on enableTokenHook. i dont think the ti83inc has it. what should i do?
Title: Re: about hooks..
Post by: thepenguin77 on May 17, 2011, 10:48:20 pm
Add
Code: [Select]
_enableTokenHook equ 4F99h
to your ti83plus.inc. And preferably, add it in where it fits alphabetically, just for organizing.

Sometimes brandonW doesn't always name the bcall's what you would expect. So to find that I had to ctrl + F: "tokenHook" to find the address for it in that big .inc file (http://brandonw.net/calcstuff/ti83plus.txt) I linked to up top.
Title: Re: about hooks..
Post by: TiAddict on May 17, 2011, 10:56:00 pm
oh now it works :) i found out why the token was looking weird.. it doesnt work with null terminated string :P aha too bad that Mimas only support null terminated string...:(
Title: Re: about hooks..
Post by: Matrefeytontias on January 12, 2012, 12:31:25 am
Up !

I found this and now I use it, so thank you thepenguin77 :thumbsup:

TiAddict : to use hooks with Mimas, you must use the length and the hex codes of the ascii catacteres instead of the length and the string.

Code: [Select]
cscText:
.db 4,$63,$73,$63,$28
; instead of
.db 4,"csc("

And I've a question : with your code thepenguin77, how do you define several hooks in one file ?
Title: Re: about hooks..
Post by: TIfanx1999 on January 12, 2012, 10:40:22 am
@Matrefeytontias: I'm glad you found this useful. The last post date was however 8 months ago, and TiAddict hasn't logged in to Omnimaga in 5 months. It's possible he may not see your post. :P
Title: Re: about hooks..
Post by: Xeda112358 on January 12, 2012, 11:58:47 am
Wow, I am glad you posted here because I find this useful, too ! I do have experience with hokks, so what do you mean by several hooks? Do you mean like changing several names and commands or do you mean like a font hook, parser hook, and token hook in one app?
Title: Re: about hooks..
Post by: Matrefeytontias on January 12, 2012, 12:42:37 pm
No, change several names, sorry ^^
Title: Re: about hooks..
Post by: Xeda112358 on January 12, 2012, 02:34:29 pm
No, change several names, sorry ^^
Ah, well you have a few options, there. The section that checks which token you have is this:
Code: [Select]
push hl
ld hl, $C8*2
or a
sbc hl, de
add hl, de ;essentially, cp DE
pop hl
This returns Z if you have the right token, NZ if you don't. If you are changing a lot of token names, you would be better off using a look-up table. In your case, though, I think you are only changing a few tokens, so you can try to test like this:
Code: [Select]
ld hl, tokenHook
ld de, smallEditRam ;nothing touches this, ever
ld bc, tokenHookEnd-tokenHook
ldir ;copy it to a place where it won't get destroyed

ld a, 1 ;1 means ram
ld hl, smallEditRam
bcall(_enableTokenHook)
ret

tokenHook:
.db $83 ;necessary for hooks, indicates that it hasn't been overwritten
push hl
;Test the first token
;DE contains the token
ld hl, $C8*2 ;sinh(
or a
sbc hl, de
add hl, de ;essentially, cp DE
        jr z, cscToken
;Test the next token
ld hl, $CA*2 ;cosh(
or a
sbc hl, de
add hl, de ;essentially, cp DE
pop hl
ret nz
secToken:
ld hl, secText-tokenHook+smallEditRam-1
        ret
cscToken:
pop hl
ld hl, cscText-tokenHook+smallEditRam-1
ret
cscText:
.db 4, "csc(" ;length, then string
SecToken:
.db 4, "sec("

tokenHookEnd:
Title: Re: about hooks..
Post by: Matrefeytontias on January 12, 2012, 02:56:26 pm
Actually, I want to rename much tokens ... :P all the tokens of the [prgm] menu
Title: Re: about hooks..
Post by: C0deH4cker on January 12, 2012, 03:47:29 pm
Up !

I found this and now I use it, so thank you thepenguin77 :thumbsup:

TiAddict : to use hooks with Mimas, you must use the length and the hex codes of the ascii catacteres instead of the length and the string.

Code: [Select]
cscText:
.db 4,$63,$73,$63,$28
; instead of
.db 4,"csc("

And I've a question : with your code thepenguin77, how do you define several hooks in one file ?

Couldnt you do this?

Code: [Select]
.db 4,'c','s','c','('

IIRC, mimas converts characters in single quotes to their ascii values, so this would work: ld a,'q'
Title: Re: about hooks..
Post by: Matrefeytontias on January 12, 2012, 03:52:59 pm
You already said it :P and it works :thumbsup:
Title: Re: about hooks..
Post by: Xeda112358 on January 12, 2012, 04:35:02 pm
Okay, so here is some code I just threw together for Grammer that changes some tokens around:
Code: [Select]

tokenHook:
     .db $83
     push hl
     ld hl,TokenTable
     ld b,0
TokenSearchLoop:
       ld a,e
       cp (hl)
       inc hl
       jr z,ChkByte2
NotTokenMatch:
       inc hl
       ld c,(hl)
       inc c
       add hl,bc
       ld a,(hl)
       or a
       jr nz,TokenSearchLoop
     pop hl
     ret
ChkByte2:
     ld a,d
     cp (hl)
     jr nz,NotTokenMatch
     ex (sp),hl
     pop hl
     ld de,8478h
     push de
     inc hl
     ld c,(hl)
     inc c \ inc c
     dec hl
     ldir
     pop hl
     ret
NoChange:
TokenTable:
 .db $06,0,8,"lFactor",5
 .db $0C,0,7,"WriteM",$C1
 .db $10,0,6,"ReadW("
 .db $20,0,6,"ReadB("
 .db $28,0,7,"Insert("
 .db $36,0,7,"ClrPart"
 .db $38,0,7,"RunPart"
 .db $3A,0,8,"AddPart("
 .db $3C,0,9,"PartType("
 .db $44,0,5,"Misc("
 .db $58,0,1,5Fh
 .db $BE,0,5,"call "
 .db $38,1,5,"Rect("
 .db $3C,1,5,"Tile("
 .db $3E,1,7,"Sprite("
 .db $40,1,8,"TileMap("
 .db $48,1,9,"Contrast("
 .db $4E,1,9,"ShiftBuf("
 .db $62,1,7,"WriteB("
 .db $70,1,4,"Inv("
 .db $72,1,7,"WriteW("
 .db $A6,1,4,"For "
 .db $B4,1,7,"GetInc("
 .db $BC,1,7,"SetBuf "
 .db $C0,1,8,"SetFont "
 .db $CE,1,8,"MakeVar("
 .db $D0,1,8,"FindVar("
 .db 0
The syntax for the token names is the value of DE (little endian), followed by the name size and then the name. So the last token on that list is E8 (the Get( token). DE will be 1D0h, so I do .db $D0,1
EDIT: Add this to the start of the hook (after .db 83h) so that 2-byte tokens don't interfere:
Code: [Select]
     ld a,b
     or a
     ret nz
Title: Re: about hooks..
Post by: Matrefeytontias on January 12, 2012, 04:41:25 pm
isn't it for apps ?
Title: Re: about hooks..
Post by: Xeda112358 on January 12, 2012, 04:44:54 pm
Oh, yes, that will only work in an APP. For a program, just copy the hook and table to RAM. You will need to play with pointers, though, too.
Title: Re: about hooks..
Post by: C0deH4cker on January 12, 2012, 06:07:01 pm
You already said it :P and it works :thumbsup:
Woops, didnt realize that i already posted it. Thought that it didnt submit correctly. I deleted the first message.
Title: Re: about hooks..
Post by: Matrefeytontias on January 13, 2012, 01:38:15 am
I'm really a beginner in ASM, but I think that put this code after :
Code: [Select]
ld hl,tokenHook
ld de,smallEditRam
ld bc,tokenEnd-tokenHook
ldir
ld a,1
ld hl,smallEditRam
bcall _enableTokenHook
ret
Will work, right ?

EDIT : no, it doesn't work ... what should I do ?
Title: Re: about hooks..
Post by: jacobly on January 13, 2012, 04:50:48 am
Here is a simple single token replacement hook that appears to work, to get you started. (Mimas syntax)
Code: [Select]
ORG  userMem-2
 DB   $BB,$6D
Start:
 LD   HL,TokenHook
 LD   DE,smallEditRAM
 LD   BC,TokenHookEnd-TokenHook
 LDIR
 LD   A,1
 LD   HL,smallEditRAM
 BCALL $4F99
 RET
;
TokenHook:
 RORG smallEditRAM
 DB   $83
 PUSH HL
 LD   HL,$0180
 OR   A
 SBC  HL,DE
 POP  HL
 RET  NZ
 LD   HL,Lambda
 RET
Lambda:
 DB   1,2,$C2,'('
 RORG LPC
TokenHookEnd:
Title: Re: about hooks..
Post by: Matrefeytontias on January 13, 2012, 07:02:11 am
No, I can do this, but I don't know how to rename much tokens.
Title: Re: about hooks..
Post by: Xeda112358 on January 13, 2012, 07:07:24 am
In my code, try changing this:
Code: [Select]
     ld hl,TokenTable
to this if you are copying to smallEditRam:
Code: [Select]
     ld hl,smallEditRAM+TokenTable-tokenHook
Title: Re: about hooks..
Post by: Matrefeytontias on January 13, 2012, 07:11:50 am
Doesn't work :(
But I don't know how to copy the token table to smallEditRam, my code seems not work
Title: Re: about hooks..
Post by: Xeda112358 on January 13, 2012, 07:17:40 am
When you are copying the token hook to smallEditRam, include the table as part of the hook :) So pretty much keep tokenHookEnd at the end of the table.
Title: Re: about hooks..
Post by: jacobly on January 13, 2012, 09:06:37 am
Code: [Select]
ORG  userMem-2
 DB   $BB,$6D
Start:
 IM   1
 BCALL DelRes
 LD   HL,TokenHook
 LD   DE,statVars
 LD   BC,TokenHookEnd-TokenHook
 LDIR
 LD   A,1
 LD   HL,statVars
 BCALL $4F99
 RET
;
TokenHook:
 RORG statVars
 DB   $83
 LD   A,B
 OR   A
 RET  NZ
 PUSH HL
 LD   HL,TokenTable
;LD   B,0
TokenSearchLoop:
 LD   A,E
 CP   (HL)
 INC  HL
 JR   Z,ChkByte2
NotTokenMatch:
 INC  HL
 LD   C,(HL)
 INC  C
 ADD  HL,BC
 LD   A,(HL)
 INC  A
 JR   NZ,TokenSearchLoop
 POP  HL
 RET
ChkByte2:
 LD   A,D
 CP   (HL)
 JR   NZ,NotTokenMatch
 POP  BC
 RET
TokenTable:
 DW   $06
 DB   8
 DB   "lFactor"
 DB   5
 DW   $0C
 DB   7
 DB   "WriteM"
 DB   $C1
 DW   $10
 DB   6
 DB   "ReadW("
 DW   $20
 DB   6
 DB   "ReadB("
 DW   $28
 DB   7
 DB   "Insert("
 DW   $36
 DB   7
 DB   "ClrPart"
 DW   $38
 DB   7
 DB   "RunPart"
 DW   $3A
 DB   8
 DB   "AddPart("
 DW   $3C
 DB   9
 DB   "PartType("
 DW   $44
 DB   5
 DB   "Misc("
 DW   $58
 DB   1
 DB   $5F
 DW   $BE
 DB   5
 DB   "call "
 DW   $0138
 DB   5
 DB   "Rect("
 DW   $013C
 DB   5
 DB   "Tile("
 DW   $013E
 DB   7
 DB   "Sprite("
 DW   $0140
 DB   8
 DB   "TileMap("
 DW   $0148
 DB   9
 DB   "Contrast("
 DW   $014E
 DB   9
 DB   "ShiftBuf("
 DW   $0162
 DB   7
 DB   "WriteB("
 DW   $0170
 DB   4
 DB   "Inv("
 DW   $0172
 DB   7
 DB   "WriteW("
 DW   $01A6
 DB   4
 DB   "For "
 DW   $01B4
 DB   7
 DB   "GetInc("
 DW   $01BC
 DB   7
 DB   "SetBuf "
 DW   $01C0
 DB   8
 DB   "SetFont "
 DW   $01CE
 DB   8
 DB   "MakeVar("
 DW   $01D0
 DB   8
 DB   "FindVar("
 DB   $FF
 RORG LPC
TokenHookEnd:
Title: Re: about hooks..
Post by: Matrefeytontias on January 14, 2012, 04:07:56 am
That's ok jacobly, your code works but I believe that there is a problem with the ending .db : the And and the ] tokens get mad.
Title: Re: about hooks..
Post by: Xeda112358 on January 14, 2012, 10:16:58 am
OKay, to change the ] as well as the and token, you should use this code:
Code: [Select]
.dw 14 \ .db 2,"]]"
 .dw 80h \ .db 7," AND?! "
The last db statement is the "end" of the table, so your table needs to end with it.
Title: Re: about hooks..
Post by: Matrefeytontias on January 14, 2012, 10:20:51 am
No no, it's ok, I just forgot the ending db $FF