bebbo / amiga-gcc

The GNU C-Compiler with Binutils and other useful tools for cross development for Amiga
GNU General Public License v2.0
322 stars 66 forks source link

NT_INTERRUPT issues #369

Open Bearsoft749 opened 11 months ago

Bearsoft749 commented 11 months ago

This code works in GCC 6.5 but does not work in GCC 13.1. I must use "m68k-amigaos-strip" to get it to be executable in GCC 13.1.

#include <stdio.h>
#include <unistd.h>
#include <proto/exec.h>
#include <exec/execbase.h>
#include <hardware/intbits.h>

struct Interrupt *vbint2;
int counter;
int quit;
int value=0;
int valueEnd=60;

void startInterrupt(void *interruptFuncton)
{
    vbint2=NULL;

    if (vbint2 = (struct Interrupt *)AllocMem(sizeof(struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR))
    {
        vbint2->is_Node.ln_Type = NT_INTERRUPT;

        vbint2->is_Node.ln_Pri = -60;   //-60
        vbint2->is_Node.ln_Name = "VertB";
        vbint2->is_Data = (APTR)&counter;
        vbint2->is_Code = (void (*)())interruptFuncton;

        AddIntServer(INTB_VERTB, vbint2); 
    }
    else 
    {
        printf("Can't allocate memory for interrupt node\n");   
    }
}

void endInterrupt()
{
    quit=1;

     if (vbint2 != NULL)
     {
        RemIntServer(INTB_VERTB, vbint2);
        FreeMem(vbint2, sizeof(struct Interrupt));

//        printf("%ld vertical blanks occurred\nRemoving server\n", counter);
     }
}

int waitInterrupt()
{
    if (quit==2)
    {
        quit=0;
    }

    int tempQuit=quit;
    quit++;

    return tempQuit;
}

int interruptLoop()
{
    while(!waitInterrupt())
    {
        value++;

        if (value>=valueEnd)
        {
            value=valueEnd;
        }
    }
}

int main()
{
    startInterrupt((void*)interruptLoop);

    while(value<valueEnd)
    {
        sleep(3);
    }

    endInterrupt();

    printf("value %d\n", value);

    return 0;
}
Bearsoft749 commented 11 months ago

I forgot... m68k-amigaos-g++ -w -O3 -mno-align-int -funsafe-math-optimizations -ffast-math -mhard-float -fomit-frame-pointer -m68060 -noixemul -o main main.cpp

bebbo commented 1 month ago

please check again

Bearsoft749 commented 6 days ago

It doesn't work... It works in 6.5.

Bearsoft749 commented 5 days ago

GCC6.5 with -S option

main6.5.txt

GCC13.1.1 with -S option

main13.1.1.txt

Bearsoft749 commented 5 days ago

You can use WinMerge to compare...

bebbo commented 5 days ago

What should the program do? And what is the problem?

Doesn't work is not precise enough.

Bearsoft749 commented 4 days ago

It's a vertical blank interrupt. https://en.wikipedia.org/wiki/Vertical_blank_interrupt

http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node0326.html

It doesn't work. AmigaOS crashes if you try to run it.

Same with the function CreateNewProc

http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node028D.html