Różnice w programowaniu

Różnice w programowaniu między różnymi systemami jak Amiga Os 3.x, Morphos, Amiga Os 4.x. AROSa pomijam dla AROSa 68k z patchami, robi się soft jak  dla Amiga oS 3.x, dla x86 nie warto – lepiej używać winuae. Oczywiście porządnie napisany soft z Amiga Os 3.x chodzi bez problemu na Amiga Os 4.x, Morphos, Aros 68k.

Jeśli jednak chcemy aby chodziło szybciej to trzeba skompilować pod ppc.

Najlepiej będzie to pokazać na przykładzie.

Poniżej przykładowa własna klasa MUI – przykład z MUI, z obsługą Picasso96.

Najważniejsze zmiany w przypadku Amiga Os4 – inaczej nazywają się pliki include, trzeba otwierać i zamykać tzw interfejsy, oraz nie działa popularna biblioteka SDI.

Zasadniczo to wszystko są bardzo małe zmiany, o wiele mniejsze niż zmiana kompilatora pod amiga os 3.x

//———————————————————-

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

#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/utility.h>
#ifdef __amigaos4__
#include <proto/Picasso96API.h>
#endif

#include <libraries/mui.h>
#include <libraries/Picasso96.h>
#include <utility/utility.h>

#ifdef __amigaos4__
#include <inline4/exec.h>
#include <inline4/graphics.h>
#include <inline4/intuition.h>
#include <inline4/Picasso96API.h>
#include <inline4/muimaster.h>
#include <inline4/utility.h>
#else
#include <clib/intuition_protos.h>
#include <clib/muimaster_protos.h>
#include <clib/Picasso96_protos.h>
#include <inline/Picasso96.h>
#include <inline/muimaster_inline.h>
#endif

#ifdef __amigaos4__
struct IntuitionIFace *IIntuition = NULL;
struct GraphicsIFace *IGraphics = NULL;
struct MUIMasterIFace *IMUIMaster = NULL;
struct UtilityIFace *IUtility = NULL;
struct P96IFace *IP96 = NULL;
#endif

#ifdef __amigaos4__
struct Library *GfxBase;
struct Library *MUIMasterBase ;
struct Library *IntuitionBase;
struct Library *P96Base;
struct Library *UtilityBase;
#else

struct GfxBase *GfxBase;
struct Library *MUIMasterBase ;
struct IntuitionBase* IntuitionBase;
struct Library *P96Base;
#ifndef __AROS__
struct UtilityBase *UtilityBase;
#endif
#endif

#ifdef __amigaos4__
#define DoSuperMethodA IDoSuperMethodA
#define DoMethodA IDoMethodA
#define DoMethod IDoMethod
#endif

static VOID fail(APTR app,char *str)
{
if (app)
MUI_DisposeObject(app);

if (str)
{
puts(str);
exit(20);
}
exit(0);
}

struct MyData
{
struct MUI_PenSpec penspec;
LONG pen;
BOOL penchange;
LONG x;
LONG y;
char* data;
};

void wczytaj_rysunek( struct MyData *data);

#define MYATTR_PEN 0x8022UL

ULONG mNew(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data;
struct TagItem *tags,*tag;

if (!(obj = (Object *)DoSuperMethodA(cl,obj,msg)))
return(0);

data = INST_DATA(cl,obj);

for (tags=((struct opSet *)msg)->ops_AttrList ; tag=NextTagItem(&tags);)
{
switch (tag->ti_Tag)
{
case MYATTR_PEN:
if (tag->ti_Data)
data->penspec = *((struct MUI_PenSpec *)tag->ti_Data);
break;
}
}

wczytaj_rysunek(data);

return (ULONG)obj;
}

ULONG mDispose(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data = INST_DATA(cl,obj);

if(data->data)
{
free(data->data);
data->data=NULL;
}
/* OM_NEW didnt allocates something, just do nothing here… */
return DoSuperMethodA(cl,obj,msg);
}

ULONG mSet(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data = INST_DATA(cl,obj);
struct TagItem *tags,*tag;

for (tags=((struct opSet *)msg)->ops_AttrList ; tag=NextTagItem(&tags);)
{
switch (tag->ti_Tag)
{
case MYATTR_PEN:
if (tag->ti_Data)
{
data->penspec = *((struct MUI_PenSpec *)tag->ti_Data);
data->penchange = TRUE;
MUI_Redraw(obj,MADF_DRAWOBJECT); /* redraw ourselves completely */
}
break;
}
}

return DoSuperMethodA(cl,obj,msg);
}

static ULONG mGet(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data = INST_DATA(cl,obj);

ULONG *store = ((struct opGet *)msg)->opg_Storage;

switch (((struct opGet *)msg)->opg_AttrID)
{
case MYATTR_PEN: *store = (ULONG)&data->penspec; return(TRUE);
}

return DoSuperMethodA(cl,obj,msg);
}

ULONG mSetup(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data = INST_DATA(cl,obj);

if (!DoSuperMethodA(cl,obj,msg))
return(FALSE);

data->pen = MUI_ObtainPen(muiRenderInfo(obj),&data->penspec,0);

return(TRUE);
}

ULONG mCleanup(struct IClass *cl,Object *obj,Msg msg)
{
struct MyData *data = INST_DATA(cl,obj);

MUI_ReleasePen(muiRenderInfo(obj),data->pen);

return DoSuperMethodA(cl,obj,msg);
}

ULONG mAskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
{

DoSuperMethodA(cl,obj,(Msg)msg);

msg->MinMaxInfo->MinWidth  += 400;
msg->MinMaxInfo->DefWidth  += 400;
msg->MinMaxInfo->MaxWidth  += 500;

msg->MinMaxInfo->MinHeight += 400;
msg->MinMaxInfo->DefHeight += 400;
msg->MinMaxInfo->MaxHeight += 600;

return 0;
}

char test_mDraw[2000*2000*4];

ULONG mDraw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
{
int i;
struct MyData *data = INST_DATA(cl,obj);
char *srcRect=NULL;
int srcX=0;
int srcY=0;
int srcMod=0;
struct RenderInfo ri;

DoSuperMethodA(cl,obj,(Msg)msg);

if (!(msg->flags & MADF_DRAWOBJECT))
return(0);

if (data->penchange)
{
data->penchange = FALSE;
MUI_ReleasePen(muiRenderInfo(obj),data->pen);
data->pen = MUI_ObtainPen(muiRenderInfo(obj),&data->penspec,0);
}

SetAPen(_rp(obj),MUIPEN(data->pen));

/*memset(test_mDraw,0,1000*1000*4);*/
memcpy(test_mDraw,data->data,2000*1333*4);
ri.Memory=test_mDraw;
ri.BytesPerRow=(data->x)*4;
ri.pad=0;
ri.RGBFormat=RGBFB_B8G8R8A8;
{fprintf(stdout,”%s %d\n”,__FILE__,__LINE__);}
p96WritePixelArray
(
&ri,
0,
0,
_rp(obj),
_mleft(obj),
_mtop(obj),
data->x,
data->y
);
{fprintf(stdout,”%s %d\n”,__FILE__,__LINE__);}
return 0;
}

#ifdef __amigaos4__
LONG MyDispatcher(struct IClass * cl, Object *obj, Msg msg)
#else
DISPATCHER(MyDispatcher)
#endif
{
switch (msg->MethodID)
{
case OM_NEW        : return(mNew      (cl,obj,(APTR)msg));
case OM_DISPOSE    : return(mDispose  (cl,obj,(APTR)msg));
case OM_SET        : return(mSet      (cl,obj,(APTR)msg));
case OM_GET        : return(mGet      (cl,obj,(APTR)msg));
case MUIM_AskMinMax: return(mAskMinMax(cl,obj,(APTR)msg));
case MUIM_Setup    : return(mSetup    (cl,obj,(APTR)msg));
case MUIM_Cleanup  : return(mCleanup  (cl,obj,(APTR)msg));
case MUIM_Draw     : return(mDraw     (cl,obj,(APTR)msg));
}
return DoSuperMethodA(cl,obj,msg);
}

int int_main(int argc,char *argv[])
{
Object *app,*window,*MyObj,*pen;
struct MUI_CustomClass *mcc;
struct MUI_PenSpec *startpen;

#ifdef __amigaos4__
if (!(mcc = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct MyData),MyDispatcher)))
fail(NULL,”Could not create custom class.”);
#else
if (!(mcc = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct MyData),ENTRY(MyDispatcher))))
fail(NULL,”Could not create custom class.”);
#endif

app = ApplicationObject,
MUIA_Application_Title      , “Class2”,
MUIA_Application_Version    , “$VER: Class2 19.5 (12.02.97)”,
MUIA_Application_Copyright  , “©1993, Stefan Stuntz”,
MUIA_Application_Author     , “Stefan Stuntz”,
MUIA_Application_Description, “Demonstrate the use of custom classes.”,
MUIA_Application_Base       , “CLASS2”,

SubWindow, window = WindowObject,
MUIA_Window_Title, “Another Custom Class”,
MUIA_Window_ID   , 0x50525A4B,
WindowContents, VGroup,

Child, TextObject,
TextFrame,
MUIA_Background, MUII_TextBack,
MUIA_Text_Contents, “test2”,
End,

Child, MyObj = NewObject(mcc->mcc_Class,NULL,
TextFrame,
MUIA_Background, MUII_BACKGROUND,
TAG_DONE),

Child, HGroup, MUIA_Weight, 10,
Child, FreeLabel(“Custom Class Color:”),
Child, pen = PoppenObject,
MUIA_CycleChain, 1,
MUIA_Window_Title, “Custom Class Color”,
End,
End,

End,

End,
End;

if (!app)
fail(app,”Failed to create Application.”);

DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);

DoMethod(pen,MUIM_Notify,MUIA_Pendisplay_Spec,MUIV_EveryTime,MyObj,3,MUIM_Set,MYATTR_PEN,MUIV_TriggerValue);

DoMethod(pen,MUIM_Pendisplay_SetMUIPen,MPEN_HALFSHINE);

get(pen,MUIA_Pendisplay_Spec,&startpen);

SetAttrs(MyObj,MYATTR_PEN,startpen,TAG_DONE);

SetAttrs(window,MUIA_Window_Open,TRUE,TAG_DONE);

{
ULONG sigs = 0;

while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
{
if (sigs)
{
sigs = Wait(sigs );
}
}
}

SetAttrs(window,MUIA_Window_Open,FALSE,TAG_DONE);

MUI_DisposeObject(app);

MUI_DeleteCustomClass(mcc);

fail(NULL,NULL);
}

long OpenLibs (void)
{
if (!(GfxBase = OpenLibrary (“graphics.library”, 39))) return FALSE;
if (!(IntuitionBase = OpenLibrary (“intuition.library”, 39))) return FALSE;
if (!(UtilityBase = OpenLibrary (“utility.library”, 39))) return FALSE;
if (!(MUIMasterBase = OpenLibrary (“muimaster.library”, 19))) return FALSE;
#ifdef __amigaos4__
if (!(P96Base = OpenLibrary (P96NAME,0))) return FALSE;
#else
if (!(P96Base = OldOpenLibrary (P96NAME))) return FALSE;
#endif

#ifdef __amigaos4__
IIntuition = (struct IntuitionIFace*)GetInterface(IntuitionBase, “main”, 1, NULL);
if(!IIntuition)
{
fprintf(stderr,”%s\n”,”no IIntuition”);
return FALSE;
}

IGraphics = (struct GraphicsIFace*)GetInterface(GfxBase, “main”, 1, NULL);
if(!IGraphics)
{
fprintf(stderr,”%s\n”,”no IGraphics”);
return FALSE;
}

IMUIMaster = (struct MUIMasterIFace*)GetInterface(MUIMasterBase, “main”, 1, NULL);
if(!IMUIMaster)
{
fprintf(stderr,”%s\n”,”no IMUIMaster”);
return FALSE;
}

IUtility = (struct UtilityIFace*)GetInterface(UtilityBase, “main”, 1, NULL);
if(!IUtility)
{
fprintf(stderr,”%s\n”,”no IUtility”);
return FALSE;
}

IP96 = (struct P96IFace*)GetInterface(P96Base, “main”, 1, NULL);
if(!IP96)
{
fprintf(stderr,”%s\n”,”no IP96″);
return FALSE;
}
#endif
return TRUE;
}

/* zamykanie bibliotek hurtem */

void CloseLibs (void)
{
#ifdef __amigaos4__
if(IGraphics)DropInterface((struct Interface*)IGraphics);
if(IIntuition)DropInterface((struct Interface*)IIntuition);
if(IMUIMaster)DropInterface((struct Interface*)IMUIMaster);
if(IUtility)DropInterface((struct Interface*)IUtility);
if(IP96)DropInterface((struct Interface*)IP96);
#endif

if (MUIMasterBase) CloseLibrary (MUIMasterBase);
if (UtilityBase) CloseLibrary (UtilityBase);
if (IntuitionBase) CloseLibrary (IntuitionBase);
if (GfxBase) CloseLibrary (GfxBase);
if (P96Base) CloseLibrary (P96Base);
return;
}

int main (int argc,char *argv[])
{
int res=0;
if (OpenLibs ())
res=int_main(argc,argv);
CloseLibs ();
return 0;
}

void wczytaj_rysunek( struct MyData *data)
{
int i,j,lpix;

FILE *p=NULL;
unsigned char nag[54];
char *buf0=NULL;
char *buf1=NULL;
if(!data)
return;
if(data->data)
return;
p=fopen(“test.bmp”,”rb”);
if(!p)
{
data->x=0;
data->y=0;
data->data=0;
return;
}
fread(nag,51,1,p);
data->x=nag[18]+256*nag[19];
data->y=nag[22]+256*nag[23];
lpix=data->x*data->y;
buf0=malloc(lpix*3);
buf1=malloc(lpix*4);
if(!buf0||!buf1)
{
if(!buf0)free(buf0);
if(!buf1)free(buf1);
data->x=0;
data->y=0;
data->data=0;
return;
}
fread(buf0,lpix*3,1,p);
fclose(p);
for(i=0;i<lpix;i++)
{
buf1[i*4+0]=buf0[i*3+0];
buf1[i*4+1]=buf0[i*3+1];
buf1[i*4+2]=buf0[i*3+2];
buf1[i*4+3]=0;
}
free(buf0);
data->data=buf1;
fprintf(stdout,”jest test.bmp x=%d y=%d lpix=%d data=%x\n”,data->x,data->y,lpix,data->data);
}

#ifndef __amigaos4__

Object *MUI_MakeObject(LONG type, …)
{
return(MUI_MakeObjectA(type, (ULONG *)(((ULONG)&type)+4)));
}

Object *MUI_NewObject          (char *classname,Tag tag1,…)
{
return(MUI_NewObjectA(classname, (struct TagItem *) &tag1));
}

#endif

//———————————————————-

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s