CPCWiki forum

General Category => Programming => Topic started by: Xifos on 11:08, 28 March 13

Title: using both interrupts and firmware
Post by: Xifos on 11:08, 28 March 13
Hi,

I am trying to use the 6 fixed interrupts to just change the background color.
I am using sdcc, but i wrote an asm function to do that.
I put a jp myfunction at 038h, di at the beginning, and  at the end of my function, i am jumping at B942h (winape as 6128).
In this function i am trying to change the color folowing a counter.

Here's my algorithm :
di
save registers on stack
test if vbl is set
if vbl counter set it as 0
test counter, set color
inc counter
restore registers
jp B942h
ret

Everything works fine, colors are changed at the right time.
But if i do a firmware call in the main program, for exemple a keyboard vector call (call BB1Eh), it goes wrong, as if the counter was lost.

I know it's not good to use firmware, but in that case i would like to undertsand what's happening.
Are there just 6 interrupts per vbl doing rst 038h, or can there be more ?

I know i'am not good at using interrupts neither at writing in english ! :(
Title: Re: using both interrupts and firmware
Post by: AMSDOS on 11:29, 28 March 13
Think you'll need to Enable Interrupts before using the Firmware.
Title: Re: using both interrupts and firmware
Post by: arnoldemu on 14:40, 28 March 13
don't fight the firmware.

try something like this:



typedef  void (*ticker_fn)(void);

void InstallFastTicker(void *pDataBlock, ticker_fn fn)
{
    __asm
        ld hl,#_pDataBlock ;; block
        ld b,#0x080        ;; class
        ld c,#0x0ff        ;; rom select
        ld de,#_fn        ;; function
        call 0x0bce3    ;;kl_new_fast_ticker
    __endasm
}

void DelFastTicker(void *pDataBlock)
{
    __asm
    {
        ld hl,#_pDataBlock
        call 0x0bce6    ;;kl_del_fast_ticker
    }
}

void MyFastTicker()
{
    // here...

}


// not sure of the size of the block
unsigned char MyFastTickerBlock[32];

void main()
{
    InstallFastTicker(MyFastTickerBlock, MyFastTicker);
}



Code is not tested!!
Title: Re: using both interrupts and firmware
Post by: Xifos on 19:34, 28 March 13
Thanks for the replies.
:)

> AMSDOS
You 're saying , put ei before the part where i jump to B941 ?
no changes
The fact is that everything works fine if i don't use system vectors !

>Arnoldemu
When doing this, does not my routine need to be between 4000h and c000h ?
I'am not good at doing relocatable code ! (i know i know)
:(

But i'll try, probably this week end...
Title: Re: using both interrupts and firmware
Post by: arnoldemu on 20:45, 28 March 13
Yes probably between 4000 and 8000. It may work from Rom but the kernel b l rock must be in ram. Try it.
Title: Re: using both interrupts and firmware
Post by: AMSDOS on 22:36, 28 March 13
Quote from: Xifos on 19:34, 28 March 13
Thanks for the replies.
:)

> AMSDOS
You 're saying , put ei before the part where i jump to B941 ?
no changes
The fact is that everything works fine if i don't use system vectors !


Hmmm, yes, I think this maybe a bit out of my league.  :(  My feeling was you cannot use Firmware routines like &BB1E while Interrupts are disabled.
Title: Re: using both interrupts and firmware
Post by: Xifos on 16:08, 29 March 13
I finally did it, following Arnoldemu's way.
And after seeing this : source/intpos.asm (http://cpctech.cpc-live.com/source/intpos.html)

One thing is that i have to forget trying to detect if i'm in the vbl interrupt or no.
I am just reseting the counter after 5.
The other annoying thing is that the fast ticker routine and it's block have to be between 4000 and 8000.
And i don't understand what exactly means this part :
ld b,#0x080        ;; class
ld c,#0x0ff        ;; rom select

The good things is that that's working, even with firmware routines calls, even without vbl synchro in the main program, but i find that the interrupts locations are not equal.

Thanks for your help !!!  :)
Title: Re: using both interrupts and firmware
Post by: arnoldemu on 20:23, 29 March 13
Quote from: Xifos on 16:08, 29 March 13
I finally did it, following Arnoldemu's way.
And after seeing this : source/intpos.asm (http://cpctech.cpc-live.com/source/intpos.html)

One thing is that i have to forget trying to detect if i'm in the vbl interrupt or no.
I am just reseting the counter after 5.
The other annoying thing is that the fast ticker routine and it's block have to be between 4000 and 8000.
And i don't understand what exactly means this part :
ld b,#0x080        ;; class
ld c,#0x0ff        ;; rom select

The good things is that that's working, even with firmware routines calls, even without vbl synchro in the main program, but i find that the interrupts locations are not equal.

Thanks for your help !!!  :)

The class and Rom select are described in the soft968 manual.
In this programming part of the forum I posted some assembly code which gives exact interrupt position for mode and colour splits. I use a special type of fast ticker firmware interrupt to make this. I had to disassemble the Cpc firmware to discover the way to do this.

When I have time I will post a full c example of the code I gave in my post above.
Title: Re: using both interrupts and firmware
Post by: Xifos on 21:01, 29 March 13
Ah, i understand now.
:)
I could put my fast ticker routine at a far address, but it seems that the fast ticker block must stay between 4000 and c000.
The locations of the code relative to the interrupts are better now.
(i am a good student, isn'it ?)

Powered by SMFPacks Menu Editor Mod