#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <exec/exec.h>
#include <clib/exec_protos.h>
#include <exec/exec.h>
#include <dos/dos.h>
#include <clib/chunkyppc_protos.h>
#include <cybergraphics/cybergraphics.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/dos_protos.h>

#ifndef __PPC__
#include <pragma/exec_lib.h>
#endif

struct Library *ChunkyPPCBase;

struct tester
{
    int a;
};

extern void *myhook(void *data);

void __saveds mixedmain()
{
    struct Mode_Screen ms;
    struct Mode_Screen *msptr=&ms;
    unsigned char *screen;
    unsigned char *buffer;
    int f;
    struct tester m;
    m.a=5;
    ms.SCREENWIDTH=320;
    ms.SCREENHEIGHT=200;
    ms.MAXWIDTH=640;
    ms.MAXHEIGHT=480;
    ms.MINDEPTH=8;
    ms.MAXDEPTH=8;
    ms.video_screen=0;
    ms.video_window=0;
    buffer=(unsigned char *)malloc(640*480);
    ChunkyPPCBase=OpenLibrary("chunkyppc.library",3);
    msptr=OpenGraphics("HereticII",&ms,0);
    if (!msptr) return;
    ms.SCREENWIDTH=640;
    ms.SCREENHEIGHT=480;
    ms.MINDEPTH=8;
    ms.MAXDEPTH=8;
    Delay(100);
    msptr=OpenGraphics("HereticII",&ms,1);
    if (!msptr) return;
    screen=ms.screenb;
    if (!(ChunkyInit(&ms,PIXFMT_LUT8))) return;
    for (f=0;f<640*480;f++)
    {
     buffer[f]=12;
    }
    ms.algo(&ms,screen,(void *)buffer,PIXFMT_LUT8,(void *)myhook,(void *)(&m));
    fprintf(stderr,"Return value from 68k: %i\n",m.a);
    Delay(100);
    DoubleBuffer(&ms);
    Delay(100);
    CloseGraphics(&ms,1);
    if (buffer) free(buffer);
    CloseLibrary(ChunkyPPCBase);
}

