Page 1 of 1

uninstall or disable a service routine in im2

Posted: Wed Mar 18, 2020 12:35 am
by fraespre
Hi,

If I have installed a service routine for the im2 with the typical code (https://github.com/z88dk/z88dk/wiki/interrupts) as this:

Code: Select all

   di
   im2_Init(0xd300);                // place z80 in im2 mode with interrupt vector table located at 0xd300
   memset(0xd300, 0xd4, 257);       // initialize 257-byte im2 vector table with all 0xd4 bytes
   bpoke(0xd4d4, 195);              // POKE jump instruction at address 0xd4d4 (interrupt service routine entry)
   wpoke(0xd4d5, isr);              // POKE isr address following the jump instruction
   ei
How can I uninstall this routine or disable the isr to recover the default behaviour ?

May be doing something like this:

Code: Select all

   di
   wpoke(0xd4d5, im2_EmptyISR);
   ei
Thanks in advanced

Posted: Wed Mar 18, 2020 7:53 pm
by dom
That's one way to do it, or if you just want to go back to the regular ROM interrupt handler then you can call intrinsic_im_1() from <intrinsic.h>

There's an alternate way to do interrupts in classic on the ZX which uses some unfortunately named functions, but does allow you to register multiple handlers and allow them to be removed.

Code: Select all

    // Setup the im2 table at 0xd300, the jump is at 0xd3d4, this switches to im2
    zx_im2_init(0xd300, 0xd4);

    // Register an interrupt handler
    im1_install_isr(handler);

    // Deregister an interrupt handler
    im1_uninstall_isr(handler);
I'd like to find some time to clean up the APIs around interrupts, it's a bit of amalgam of several different models and the naming doesn't quite work correctly cross-machine, but we are where we are at the moment.

Posted: Thu Mar 19, 2020 11:15 am
by fraespre
Thanks a lot dom,

I'm using the new lib version (not classic). But don't worry :-D
I have tested that you said, to enable the m1 interrupts and works perfectly: clean, easy and elegant !!!


I take advantage of the thread to ask for another curiosity:
Where would be the better place to locate the vector table ? if we want save memory or leave memory well organized.
Because sometimes I see: "im2_Init(0xd000)", "im2_Init(0xd300)", etc

Are there any directive, blueprint or something to take in count ?

Posted: Thu Mar 19, 2020 4:47 pm
by dom
Back when I was writing games, I tended to put the table at 0xfe00 pointing to 0xfdfd which kept it nicely in a single chunk at the end of memory. It's rubbish if you're doing 128k paging, but for 48k it worked out well enough.

I don't think appmake has a fence for +zx so you just need to keep an eye on the size yourself.

Posted: Sun Mar 22, 2020 3:10 pm
by jordi
hi,

I'm trying to use the new WYZ support on new lib without too much success... just took oldlib example from:
https://github.com/z88dk/z88dk/tree/mas ... /sound/wyz

But importing it into the newlib doesn't work. `zx_im2_init` are not present

Code: Select all

// zcc +zx -v -startup=31 -DWFRAMES=3 -clib=sdcc_iy main.c sham.mus.asm effects.asm -create-app
#include <sound/aywyz.h>
#include <im2.h>
#include <stdlib.h>
#include <string.h>
#include <z80.h>
#include <intrinsic.h>
#include <arch/zx.h>
#include <arch/zx/sp1.h>
#include <sound/aywyz.h>
#include <input.h>



extern wyz_song mysong;
extern wyz_effects myeffects;

IM2_DEFINE_ISR(playmusic)
{

   ay_wyz_play();

}


void setup_int() {
   im2_init((void *)0xd000); // CRT_ORG = 25124
   memset((void *)0xd000, 0xd1, 257);

   z80_bpoke(0xd1d1, 0xc3);
   z80_wpoke(0xd1d2, (unsigned int)playmusic);
}


void main()
{
   //printf("%cWYZ Tracker example\n",12);

   // Load the tracker file
   ay_wyz_init(&mysong);
   // Setup the effects
   ay_wyz_effect_init(&myeffects);
   // Play song 1 within the  file
   //ay_wyz_start(0);

   // Setup interrupt
   setup_int();

   // Just loop
   while  ( 1 ) {
      if(in_key_pressed(IN_KEY_SCANCODE_1)) {
        zx_border(INK_BLUE);
          ay_wyz_start_effect(3, 0);
      } else {
        zx_border(INK_BLACK);
      }
   }
}
I first tried to bring it on my ms pacman 'tutorial', but no success, so then I started migrating WYZ example to newlib...

Posted: Sun Mar 22, 2020 3:12 pm
by jordi
Wop, I just had forgotten the enable interrupt :D