Setting call vector (hooking) from ROM

Page 1/2
| 2

By Eugeny_Brychkov

Hero (604)

Eugeny_Brychkov's picture

12-12-2010, 16:33

I know there're knowledgeable guys here, please help solving an issue... There're call vectors (hooks) in Fxxx area in RAM, and I want to set it to call my own code in some slot. Vector occupies 5 bytes enough to hold rst30 and ret. But it will call ROM, which in its turn will need to call next subs in the chain. But to call next sub, ROM should have saved previous call pointer somewhere.

The question is - where to save it? Is there any valid / approved way for ROMs to do that?

Saving that data "somewhere in RAM" is a bad workaround as it can be overwritten by user/another system call and machine may crash...

Login or register to post comments

By Leo

Paragon (1236)

Leo's picture

12-12-2010, 17:29

stack ?

By nikodr

Paladin (693)

nikodr's picture

12-12-2010, 17:51

use the stack pointer i think this is the approved method.You can use a command to increase the stack and set it larger than what it is.

By Eugeny_Brychkov

Hero (604)

Eugeny_Brychkov's picture

12-12-2010, 17:59

Oh great idea thank you Leo and Nikodr. How will it look like technically?

By nikodr

Paladin (693)

nikodr's picture

12-12-2010, 18:43

Eugeny do you want to create a rom program that would run from cartridge ? Do you need to have active ram in slot 0 ?Do you use a custom interrupt handler in that routine?

By Eugeny_Brychkov

Hero (604)

Eugeny_Brychkov's picture

12-12-2010, 19:01

I need machine to run some code from ROM through hooking and then go further the subroutine chain. As I understand I only can use c000-ffff RAM segment in order to ensure it works in most configurations.

By Leo

Paragon (1236)

Leo's picture

12-12-2010, 19:48

edit
konamiman uses slot work area , this may help :
http://www.konamiman.com/msx/unapi/unapirom.asm

look for the section :

----- copy paste from konamiman site : example of rom unapi ethernet ----------
INIT:
;--- Initialize EXTBIO hook if necessary

ld a,(HOKVLD)
bit 0,a
jr nz,OK_INIEXTB

ld hl,EXTBIO
ld de,EXTBIO+1
ld bc,5-1
ld (hl),#C9 ;code for RET
ldir

or 1
ld (HOKVLD),a
OK_INIEXTB:

;--- Save previous EXTBIO hook

call GETSLT
call GETWRK
ex de,hl
ld hl,EXTBIO
ld bc,5
ldir

;--- Patch EXTBIO hook

di
ld a,#F7 ;code for "RST #30"
ld (EXTBIO),a
call GETSLT
ld (EXTBIO+1),a
ld hl,DO_EXTBIO
ld (EXTBIO+2),hl
ei

;>>> UNAPI initialization finished, now perform
; other ROM initialization tasks.

By Eugeny_Brychkov

Hero (604)

Eugeny_Brychkov's picture

12-12-2010, 20:04

I need to hook to the entry point permanently, and not temporarily.
When ROM is started, it should "install" its subroutine into the chain and every time in the future this hook/entry point is called, this subroutine should be activated. Location of this subroutine is fixed - in ROM, while it is not clear for me how to implement calling further down the chain - I need machine to "memorize" old hook pointer in order for ROM to call it.

I can not do it in any register, and obviously can not do it in ROM. Thus I need to do is somehwere in RAM. Thus I am looking if there's any place in RAM which can be reliably used for such purposes. Using stack... a good idea, but it is not clear for me how to "install" data into the stack and not to corrupt "ret" and "pop" sequence.

Is it more clear now?

By Leo

Paragon (1236)

Leo's picture

12-12-2010, 20:08

yes yes , sorry i was editing my previous at the same time , yes my question was that i didnt understand but now it is clearer

By Leo

Paragon (1236)

Leo's picture

12-12-2010, 20:09

so the correct answer is more : slot working area .

By Eugeny_Brychkov

Hero (604)

Eugeny_Brychkov's picture

12-12-2010, 20:16

I see

SLTWRK (FD09H, 128)
          contents: allocates specific work area for each slot

but is there specific layout? Is it protected from modifications from other ROMs/applications?

Page 1/2
| 2
My MSX profile