home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
utilities
/
utilsf
/
gol
/
!Gol
/
c
/
Gol
< prev
next >
Wrap
Text File
|
1993-12-19
|
39KB
|
1,108 lines
/*
* Copyright © 1993 Michael R Brown
* Release version: 0.01 (Oct 24 1993)
* Permission is granted to use and alter this software for private use.
* Permission is also granted to copy this software in its un-altered form.
*/
/* Wimp interface to !GOL */
#include "wimp.h" /* access to WIMP SWIs */
#include "wimpt.h" /* wimp task facilities */
#include "win.h" /* registering window handlers */
#include "event.h" /* poll loops, etc */
#include "baricon.h" /* putting icon on icon bar */
#include "sprite.h" /* sprite operations */
#include "werr.h" /* error reporting */
#include "res.h" /* access to resources */
#include "resspr.h" /* sprite resources */
#include "flex.h" /* dynamic mem alloc from WIMP */
#include "template.h" /* reading in template file */
#include "bbc.h" /* olde-style graphics routines */
#include "colourtran.h" /* interface to colour translation module */
#include "os.h" /* low-level RISCOS access */
#include "dbox.h" /* dialogue box handling */
#include "saveas.h" /* data export from dbox by icon dragging */
#include "visdelay.h" /* show the hourglass for delay */
#include "xferrecv.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "life.h"
#include "fcntl.h"
#define REG register
struct lVARS_str
{int width;
int height;
int flags;
int init;
int mask;
int bits;
int Rules[10];
} lVARS={256, 256, 3, 53, LIFE_STANDARD, 8, lCLEAR, lCLEAR,
lLEAVE, lSET, lCLEAR, lCLEAR, lCLEAR, lCLEAR, lCLEAR, lCLEAR};
#define GOL_FAST_LIFE 0x1
#define GOL_LIFE_WRAP 0x2
#define GOL_PAUSED 0x4
#define GOL_FAST_SPRITE 0x8
typedef struct
{menu wmenu;
int whand;
int wh; /* width in bytes | height<<16 */
int flags;
char table[0x40000];
struct lVARS_str lVARS_bak;
char save_filename[128];
/* */
int scanline, scanlines;
int spr_mag, spr_div;
sprite_factors factors;
sprite_pixtrans pixtrans[256];
int *spr_ptr[2];
sprite_id id[2];
sprite_area area;
} GOL_struct;
typedef enum {AREA_HEADER, SPRITE_HEADER
,SPRITE_DATA, SKIP_BYTES} IO_State_str;
static int GOL_count=16;
static char GOL_titles[16][32];
static GOL_struct *GOL_vector[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static os_regset GOL_registers;
static char CLEAR_TEXT[]="Clear";
static char LEAVE_TEXT[]="Leave";
static char SET_TEXT[]="Set";
static char LIFE_WINDOW_NAME[]="LifeField";
static char SETUP_WINDOW_NAME[]="Setup";
static char INFO_WINDOW_NAME[]="Info";
static char SPRITE1_NAME[]="s1";
static char SPRITE2_NAME[]="s2";
static char APP_NAME[]="Gol";
static char SPRITE_NAME[]="!Gol";
static char WINDOW_TITLE[]="Life";
static char COPYWRITE[]="This software is copywrite Michael R Brown (Oct 24 1993)";
static char MAGNIFIER_WINDOW_NAME[]="Magnifier";
static char SAVE_FILENAME[]="LifeField";
static char VALID_STRING[]="31091973";
#define Sprite_FileType 0x0ff9
#define Sprite_Mode 18
#define xshift(x) ((x)<<1)
#define yshift(y) ((y)<<1)
#define shiftx(x) ((x)>>1)
#define shifty(y) ((y)>>1)
#define REDRAW_WIMP 0
#define REDRAW_ALL 1
#define REDRAW_AREA 2
#define REDRAW_LATER 3
#define Sprite_FileSize(w,h) (((w)*(h))+sizeof(sprite_area) \
+sizeof(sprite_header)-sizeof(int))
#define Sprite_Size ((lVARS.height*(lVARS.width>>2))+sizeof(sprite_area) \
+(sizeof(sprite_header)<<1))
#define Alloc_Size (Sprite_Size+sizeof(GOL_struct))
#define Task_Threshold (32*8192)
#define Icon_Rules 4
#define Icon_Pixels 25
#define Icon_Fast_Life 36
#define Icon_Life_Wrap 37
#define Icon_Width_Down 39
#define Icon_Width_Up 40
#define Icon_Width 38
#define Icon_Height_Down 42
#define Icon_Height_Up 43
#define Icon_Height 41
#define Icon_Go 47
#define Icon_Paused 50
#define Icon_Clear_All 51
#define Icon_Set_All 52
#define Icon_Random 53
#define Icon_Mag_Down 0
#define Icon_Mag_Up 1
#define Icon_Mag 2
#define Icon_Div 3
#define Icon_Div_Up 6
#define Icon_Div_Down 7
void GOL_info(void);
void GOL_open_setup(wimp_i i);
void GOL_close(wimp_w whand, int slot);
void GOL_redraw(int slot, int all);
static int GOL_redraw_ignor=0;
void GOL_err(const char *format,...)
{va_list args;
static char line[256];
va_start(args,format);
vsprintf(line,format,args);
werr(FALSE, line);
va_end(args);
}
int WIMP_MAG;
int WIMP_XMAG;
int WIMP_YMAG;
int WIMP_BPP;
void GOL_SpeedCheck(slot)
int slot;
{GOL_struct *handle=GOL_vector[slot];
int mag=handle->spr_mag;
int div=handle->spr_div;
if (WIMP_MAG && !(mag%div) && xshift(mag/div)==WIMP_MAG)
handle->flags|= GOL_FAST_SPRITE;
else handle->flags&=~GOL_FAST_SPRITE;
}
void GOL_ModeChange()
{int slot;
GOL_struct *handle;
GOL_registers.r[0]=-1;
GOL_registers.r[1]=4;
WIMP_XMAG=1<<(os_swi(0x35, &GOL_registers), GOL_registers.r[2]);
GOL_registers.r[1]=5;
WIMP_YMAG=1<<(os_swi(0x35, &GOL_registers), GOL_registers.r[2]);
GOL_registers.r[1]=9;
WIMP_BPP =1<<(os_swi(0x35, &GOL_registers), GOL_registers.r[2]);
if (WIMP_BPP==1 && WIMP_XMAG==WIMP_YMAG)
WIMP_MAG=WIMP_XMAG;
else WIMP_MAG=0;
for (slot=0; slot<16; slot++) if (GOL_vector[slot])
{handle=GOL_vector[slot];
wimp_readpixtrans(&(handle->area), &(handle->id[0]),
&(handle->factors), handle->pixtrans);
GOL_SpeedCheck(slot);
}
}
static wimp_redrawstr GOL_redraw_box;
void GOL_redraw(slot, mode)
int slot;
int mode;
{wimp_redrawstr r;
sprite_factors factors;
GOL_struct *handle=GOL_vector[slot];
int mag=handle->spr_mag;
int div=handle->spr_div;
int width=(handle->wh&0xffff)<<3;
int height=(handle->wh>>16);
r.w=handle->whand;
switch (mode)
{case REDRAW_WIMP:
wimpt_noerr(wimp_redraw_wind(&r, &slot));
break;
case REDRAW_ALL:
r.box.x0=r.box.y1=0;
r.box.x1= xshift( width)*mag/div ;
r.box.y0=-(yshift(height)*mag/div);
wimp_update_wind(&r, &slot);
break;
case REDRAW_AREA:
r.box.x0=xshift(shiftx(GOL_redraw_box.box.x0*div/mag)*mag/div);
r.box.x1=xshift(shiftx(GOL_redraw_box.box.x1*div/mag)*mag/div);
r.box.y0=-yshift(shifty((-GOL_redraw_box.box.y0)*div/mag)*mag/div);
r.box.y1=-yshift(shifty((-GOL_redraw_box.box.y1)*div/mag)*mag/div);
wimpt_noerr(wimp_update_wind(&r, &slot));
break;
case REDRAW_LATER:
r.box.x0=r.box.y1=0;
r.box.x1= xshift( width)*mag/div ;
r.box.y0=-(yshift(height)*mag/div);
wimp_force_redraw(&r);
return;
}
if (slot)
{factors.xmag=handle->factors.xmag*mag;
factors.ymag=handle->factors.ymag*mag;
factors.xdiv=handle->factors.xdiv*div;
factors.ydiv=handle->factors.ydiv*div;