Author Topic: about hooks..  (Read 12882 times)

0 Members and 2 Guests are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: about hooks..
« Reply #15 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:

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #16 on: January 12, 2012, 02:56:26 pm »
Actually, I want to rename much tokens ... :P all the tokens of the [prgm] menu

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: about hooks..
« Reply #17 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'

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #18 on: January 12, 2012, 03:52:59 pm »
You already said it :P and it works :thumbsup:

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: about hooks..
« Reply #19 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

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #20 on: January 12, 2012, 04:41:25 pm »
isn't it for apps ?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: about hooks..
« Reply #21 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.

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: about hooks..
« Reply #22 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.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #23 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 ?
« Last Edit: January 13, 2012, 03:54:28 am by Matrefeytontias »

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: about hooks..
« Reply #24 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:

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #25 on: January 13, 2012, 07:02:11 am »
No, I can do this, but I don't know how to rename much tokens.
« Last Edit: January 13, 2012, 07:07:57 am by Matrefeytontias »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: about hooks..
« Reply #26 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

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: about hooks..
« Reply #27 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

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: about hooks..
« Reply #28 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.

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: about hooks..
« Reply #29 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: