Author Topic: [cpctelera] Interrupts example  (Read 1954 times)

0 Members and 1 Guest are viewing this topic.

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 695
  • Country: fr
  • Liked: 617
  • Likes Given: 1304
[cpctelera] Interrupts example
« on: 20:08, 29 October 15 »
Hello,

in this example the border color are flickering, is there a way to exactly change the color at the right moment ?

I tried to use cpct_waitVSYNC() just before launching the interruption in order to synchronize it with the VSync, but it doesn't work.

Arnaud.


Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 650
  • Country: es
    • Profesor Retroman
  • Liked: 952
  • Likes Given: 836
Re: [cpctelera] Interrupts example
« Reply #1 on: 21:49, 29 October 15 »
Are you referring to CPCtelera's interrupt example? I don't see colors fickering: I see them fixed, with a minimal timing variation on changing one of them due to branch logic used in the interrupt handler.

What does it mean that you "use cpct_waitVSYNC() just before launching the interruption"? Do you mean you wait for VSYNC before setting the interrupt handler?

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 695
  • Country: fr
  • Liked: 617
  • Likes Given: 1304
Re: [cpctelera] Interrupts example
« Reply #2 on: 22:01, 29 October 15 »
Sorry, i really misspoke, i have used your example in my code and the color border are moving as not synchronised. And sometime order color change.

What does it mean that you "use cpct_waitVSYNC() just before launching the interruption"? Do you mean you wait for VSYNC before setting the interrupt handler?

Yes exactly, i try something to force synchronisation.
« Last Edit: 22:20, 29 October 15 by Arnaud »

Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 650
  • Country: es
    • Profesor Retroman
  • Liked: 952
  • Likes Given: 836
Re: [cpctelera] Interrupts example
« Reply #3 on: 22:46, 29 October 15 »
Then that may be due to 2 possible circumstances:
  • Your interrupt handler being too large (or too large sometimes). Larger enough to run up till the next interrupt.
  • Part of your code disables interrupts and you are loosing some of them.
In CPCtelera, drawChar/drawString functions do disable interrupts when drawing.

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 695
  • Country: fr
  • Liked: 617
  • Likes Given: 1304
Re: [cpctelera] Interrupts example
« Reply #4 on: 23:01, 29 October 15 »
  • Your interrupt handler being too large (or too large sometimes). Larger enough to run up till the next interrupt.
I have copy / paste the example code and i increase a timer variable.

  • Part of your code disables interrupts and you are loosing some of them.
I don't use drawChar/drawString, and if the interrupts was disabled i shouldn't see the border color changes ? But they are always visible.


Is my main loop can be the problem ? i do a lot of things.
« Last Edit: 23:05, 29 October 15 by Arnaud »

Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 650
  • Country: es
    • Profesor Retroman
  • Liked: 952
  • Likes Given: 836
Re: [cpctelera] Interrupts example
« Reply #5 on: 23:21, 29 October 15 »
I don't use drawChar/drawString, and if the interrupts was disabled i shouldn't see the border color changes ? But they are always visible.

Not exactly. You may be using functions that disable and reenable interrupts (like cpct_drawString does). Some firmware functions may do this, or some part of your code (may be some of your assembly functions). The problem you are describing clearly points to interrupts being lost, and that only happens if an interrupt comes when they are disabled.

Offline Arnaud

  • Supporter
  • 6128 Plus
  • *
  • Posts: 695
  • Country: fr
  • Liked: 617
  • Likes Given: 1304
Re: [cpctelera] Interrupts example
« Reply #6 on: 22:22, 02 November 15 »
Effectively i found functions in my code, cpct_scanKeyboard for example, that disable and reenable interrupts and make my border color not stable.

But how i can handle this problem ?

I try to put :
Code: [Select]
cpct_waitVSYNC();
cpct_setInterruptHandler(interruptHandler);
after each call of the functions that disable interrupts, but i'm sure it's not the good solution.

I also try to disable interrupts with the function cpct_removeInterruptHandler, but it's not in cpctelera firmware.h (it's internal function ?) and it crashes my program when i call it.

Maybe the current line to be drawn can be known in my interrupt function in order to set the right border color ?

Offline ronaldo

  • Dev
  • 6128 Plus
  • *****
  • Posts: 650
  • Country: es
    • Profesor Retroman
  • Liked: 952
  • Likes Given: 836
Re: [cpctelera] Interrupts example
« Reply #7 on: 23:58, 16 November 15 »
Yes, you are right. If cpct_scanKeyboard is called and an interrupt comes in the middle, that interrupt gets lost.

At the present momment, you've got 2 solutions:
  • Ensure that cpct_scanKeyboard will be called at an interrupt-safe time. Depending on your code, you may be able to call it earlier or latter and ensure this.
  • Call cpct_scanKeyboard at the end of an interrupt. If you do this, be sure that interrupt's code is small enough not to take into the next interrupt or it may explode. This may happen because cpct_scanKeyboard enables interrupts at the end.
I'm adding a new scanKeyboard function to the task list: one specially designed to be used on interrupts, for cases like yours :).

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2281
  • Likes Given: 3478
Re: [cpctelera] Interrupts example
« Reply #8 on: 11:04, 17 November 15 »
Yes, you are right. If cpct_scanKeyboard is called and an interrupt comes in the middle, that interrupt gets lost.
I thought it would be delayed and trigger after the scan is done?
The CPC holds the interrupt until it is acknowledged.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1161
  • Likes Given: 1931
Re: [cpctelera] Interrupts example
« Reply #9 on: 11:50, 17 November 15 »
I thought it would be delayed and trigger after the scan is done?
The CPC holds the interrupt until it is acknowledged.


Unsure if this relates to some BASIC programs I entered recently, which had the sort of Key Scanning Routines which weren't detecting Key press immediately. One of those programs (at least) I think was Looping back on itself until it found one of those keys had been pressed. Though wasn't sure if that's a case of an Interrupt being Lost?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3