home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
new
/
gfx
/
show
/
edushow
/
edushow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-29
|
16KB
|
624 lines
/*********************************************************************
* EDUSHOW Copyright 1990 Laurence Vanhelsuwé
* -------
* Specialised interactive slideshow program for educational purposes
* or giving presentations to groups of people.
*
* Written by L.Vanhelsuwé © 1990
*
* - started/finished on 12-Mar-1990
* - quick check before releasing to Fish PD 22-May-1994
*********************************************************************/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <clib/exec_protos.h> // ANSI function prototypes
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#define FIRST_ARG argv[1]
#define LF (0x0a)
#define MAX_COLOR 16 /** IN HIRES SCREEN **/
#define COLOR 15 /** MASK FOR HARDWARE COLOR PRIMARY **/
#define CHUNK_ID long
#define CHUNK_LEN long
#define COLORS 16
#define NEXT_COLOR ' '
#define PREV_COLOR '\b'
#define NEXT_PICTURE 'n'
#define PREV_PICTURE 'p'
#define QUIT 'q'
#define IN 1 /** COLOR FADE DIRECTIONS **/
#define OUT 0
#define MAX_ALLOCS 40 // maximum objects allocated
/************************************************************************/
char ver[] = "$VER: EDUSHOW v0.9 (12-MAR-90) by Laurence Vanhelsuwé";
char screentitle[] =
"WICPUG 68000 Assembly Language Course -Educational Slideshow 0.9 (C) LVA 1990";
int count_lines(char *text); /** AND ZERO TERMINATE LINES !! **/
int cache_all_pictures(char * list_of_pictures, int number_of_pics);
/****** non "int" functions ******/
char * load_file(char *name); /** CACHES ANY FILE IN MEMORY **/
char * next_string(char*n); /** NEXT START OF LINE **/
char * expand_line(char*a,char*b); /** UN-COMPRESS RUN-LENGTH LINE **/
char * find_chunk(char*s,char*n); /** FIND START OF ANY iff CHUNK **/
char get_input(void); /** USER INPUT ROUTINE **/
short scale_color(short,short); /** FADE COLOR n BY FACTOR x **/
void fade_color(int p, int d); /** FADES PEN n IN or OUT **/
void fade_screen(int dir);
void decode_color_maps(struct mem_iff_pic *mip_array,int n); /** UNPACKS iff CMAP INTO INTERNAL FORM **/
void decompress_pic(void); /** PUT COMPRESSED PICTURE ON SCREEN **/
void open_screen(void); /** OPEN AN Intuition SCREEN **/
void lights_out(void); /** ALL PENS ARE SET TO BLACK **/
void close_everything(void); /** DEALLOCATE,FREE,CLOSE ALL **/
void next_color(void); /** FADE IN NEXT COLOR IN SLIDE **/
void prev_color(void); /** FADE OUT CURRENT COLOR IN SLIDE **/
void next_picture(void); /** FADE OUT THIS SLIDE, SHOW NEXT **/
void prev_picture(void); /** FADE OUT THIS SLIDE, SHOW PREV **/
struct Screen * OpenScreen();
struct Window * OpenWindow();
/****** global variables ******/
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Screen *screen;
struct Window *window;
struct ViewPort *vport;
int current_pic,current_color,lessons;
int alloc_num=0;
/****** global structures *****/
struct iff_header { /** THIS DEFINES THE iff HEADER **/
CHUNK_ID form_id;
CHUNK_LEN form_len;
CHUNK_ID form_type;
CHUNK_ID bmhdr_id;
CHUNK_LEN bmhdr_len;
short width;
short height;
long unknown;
BYTE planes;
BYTE pad0;
BYTE compression;
BYTE pad1;
long pad2,pad3;
CHUNK_ID cmap_id;
CHUNK_LEN cmap_len;
char cmap[16*3];
CHUNK_ID body_id;
CHUNK_LEN body_len;
char body;
};
struct mem_iff_pic {
struct iff_header *file_buffer; /** PTR TO COMPRESSED IFF PIC **/
char *body_ptr; /** PTR TO BODY CHUNK IFF **/
short cmap [COLORS][3]; /** EXPANDED COLOR PALETTE */
};
struct mem_iff_pic *lesson_pics;
struct mem_block { /** define a struct for every object **/
char *ptr; /** that we've allocated **/
int size;
} allocations[MAX_ALLOCS];
/*************************************************************************/
/*************************** START OF MAIN *******************************/
/*************************************************************************/
main(argc,argv) /** TAKES A SCRIPT FILE AS ARGUMENT **/
int argc;
char *argv[];
{
char *script_buffer;
char user_input;
int script_size;
int success;
script_size = 0;
// printf("Filename = %s # of args = %d\n",FIRST_ARG,argc);
if (argc != 2) exit (100);
printf("EDUcational slideSHOW V0.9 (C) 1990 L. Vanhelsuwé\n");
printf("-------------------------- -------------------------\n");
printf("\n");
printf("Use the following keys to control the presentation:\n");
printf("\n");
printf("SPACE...... fade in next image element\n");
printf("BACKSPACE.. fade out current image element\n");
printf("'N'........ fade in next slide\n");
printf("'P'........ fade in previous slide\n\n");
printf("'Q'........ to quit\n\n");
printf("HIT <ENTER> to start presentation."); getch();
printf("\n");
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
IntuitionBase = (struct IntuitionBase*) OpenLibrary("intuition.library",0);
script_buffer = load_file(FIRST_ARG); /** LOAD SCRIPT **/
if (script_buffer == NULL) exit(100);
lessons = count_lines(script_buffer); /** HOWMANY PICS **/
printf("Number of Slides in this presentation = %d \n",lessons);
lesson_pics = (struct mem_iff_pic*)
AllocMem(lessons*sizeof (struct mem_iff_pic),0);
/** LOAD ALL PICS **/
success = cache_all_pictures(script_buffer,lessons);
if (success == FALSE)
{
printf("Cache technique failed this time....\n");
exit(100);
}
decode_color_maps(lesson_pics,lessons);
open_screen(); /** OPEN SLIDESHOW SCREEN **/
current_pic = -1; /** START SHOW OFF .... **/
next_picture();
while ( (user_input = get_input()) != QUIT)
{
switch (user_input)
{
case 13:
case NEXT_COLOR: next_color(); break;
case PREV_COLOR: prev_color(); break;
case NEXT_PICTURE: next_picture(); break;
case PREV_PICTURE: prev_picture(); break;
default:
printf("Don't know event %d !\n",(int) user_input);
}
}
close_everything(); /** RELEASE SCREEN,CACHE ETC..**/
CloseLibrary((struct Library*)GfxBase);
CloseLibrary((struct Library*)IntuitionBase);
printf ("\n\nHave a nice day..\n");
}
/***********************************************************************/
// Turn screen dark, decompress next slide, fade it in.
/***********************************************************************/
void next_picture()
{
if (current_pic != (lessons -1) )
{
lights_out();
current_pic++;
decompress_pic();
current_color = 1; fade_color(current_color,IN);
}
}
/***********************************************************************/
// Fade next "subject" in (mapped to a unique pen color)
// Goto next slide if no more subjects.
/***********************************************************************/
void next_color()
{
current_color++;
if (current_color < MAX_COLOR)
{
fade_color(current_color,IN);
}
else
{
next_picture();
}
}
/***********************************************************************/
// Do opposite of next_color()
/***********************************************************************/
void prev_color()
{
if (current_color != 1)
{
fade_color( current_color, OUT );
current_color--;
}
else
{
prev_picture();
}
}
/***********************************************************************/
// Backtrack by going back to previous slide
/***********************************************************************/
void prev_picture()
{
if (current_pic != 0)
{
lights_out();
current_pic--;
decompress_pic();
fade_screen(IN);
current_color = 1;
}
}
/***********************************************************************/
char get_input() /** WAIT FOR ANY ASCII KEY PRESS **/
{
int type = -1;
char key;
struct IntuiMessage * msg;
while (type != VANILLAKEY)
{
Wait(1 << window->UserPort->mp_SigBit);
while (msg = (struct IntuiMessage *) GetMsg(window->UserPort))
{
type = msg->Class;
key = (char) msg->Code;
ReplyMsg((struct Message*)msg);
}
}
return key;
}
/***********************************************************************/
// Cache a picture file in its entirety.
/*************