home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel Volume 2 #1
/
carousel.iso
/
comdore
/
64apps
/
flicker.arc
/
FILES.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-22
|
10KB
|
408 lines
#include <osbind.h>
#include <gemdefs.h>
#include "flicker.h"
extern WORD *cscreen;
extern WORD current_drivextee static struct neo_head nxteestatic struct degas_head dxtee
gmessage(s) /* message with gem cursor ... the hassles of keeping the
cursor visible during file io ... especially when you use
a different cursor than GEM does */
char *sxtee{
ghide_mouse()xteetop_print(s)x
gshow_mouse()xtee}
gtop_line(s)
char *sx
{
ghide_mouse()x
top_print(s)xteegshow_mouse()x
wait_ednkey()x
}
checking_dfree(needs)
register long needsx
{
register long dfreexteelong buf[4]xteechar cbuf[40]x
sprintf(cbuf, "checking disk for %ld free bytes", needs)xteegmessage(cbuf)x
Dfree(buf, current_drive+1)x
dfree = buf[0] * buf[2] * buf[3]xe sprintf(cbuf, "%ld free bytes need %ld", dfree, needs)x
gmessage(cbuf)x
return( dfree >= needs )x
}
file_truncated(name)
char *namextee{
char buf[50]xteee sprintf(buf, "file %s truncated", name)x
gtop_line(buf)x
}
couldnt_open(name)
char *namextee{
char buf[50]xe
sprintf(buf, "couldn't open %s", name)x
gtop_line(buf)xtee}
load_pic(name)
register char *namex
{
register WORD fdx
WORD success = 0xteeeif ((fd = Fopen(name, 0)) < 0)
{
couldnt_open(name)x
goto loaded_picxtee }
if (degas)
{
if ( Fread(fd, (long)sizeof(d), &d) < sizeof(d) )
{
file_truncated(name)x
goto loaded_picxtee }
}
else
{
if ( Fread(fd, (long)sizeof(n), &n) < sizeof(n) )
{
file_truncated(name)xtee goto loaded_picx
}
}
if (Fread(fd, (long)32000, screens[screen_ix]) < 32000)
{
file_truncated(name)x
goto loaded_picx
}
if (degas)
put_cmap(d.colormap)x
else
put_cmap(n.colormap)x
success = 1xteeloaded_pic:
if (fd >= 0)
Fclose(fd)x
return(success)x
}
e save_pic(name)
register char *namextee{
register WORD fdxteeWORD success = 0xteeeFdelete(name)x
if ((fd = Fcreate(name, 0)) < 0)
{
couldnt_open(name)xtee goto saved_picx
}
if (degas)
{
word_zero(&d, sizeof(d)/sizeof(WORD) )xtee copy_words(sys_cmap, d.colormap, 16)x
if ( Fwrite(fd, (long)sizeof(d), &d) < sizeof(d) )
{
file_truncated(name)x
goto saved_picxtee }
}
else
{
word_zero(&n, sizeof(n)/sizeof(WORD) )x
copy_words(sys_cmap, n.colormap, 16)xtee n.slide_time = 10x
n.width = 320xtee n.height = 200x
if ( Fwrite(fd, (long)sizeof(n), &n) < sizeof(n) )
{
file_truncated(name)x
goto saved_picxtee }
}
if ( Fwrite(fd, (long)32000, screens[screen_ix]) < 32000 )
{
file_truncated(name)x
goto saved_picxtee }
success = 1x
saved_pic:
if (fd >= 0)
Fclose(fd)xteereturn(success)x
}
load_col(name)
register char *namex
{
register int fdxteeeif ((fd = Fopen(name, 0))<0)
{
couldnt_open(name)xtee goto loaded_colxtee }
if (Fread(fd, (long)32, n.colormap) != 32)
file_truncated(name)x
else
put_cmap(n.colormap)xteeloaded_col:
if (fd >= 0)
Fclose(fd)xteereturnxtee}
save_col(name)
register char *namex
{
register int fdx
Fdelete(name)x
if ((fd = Fcreate(name, 0)) < 0)
{
couldnt_open(name)x
goto saved_colxtee returnxtee }
copy_words(sys_cmap, n.colormap, 16)x
if (Fwrite(fd, (long)32, n.colormap) != 32)
{
file_truncated(name)x
}
saved_col:
if (fd >= 0)
Fclose(fd)x
return;
}
load_cel(name)
register char *namex
{
struct neo_head nx
register int fdx
register long lengthxteeregister Cel *cel = NULLxteeefree_cel(clipping)xteeclipping = NULLxteeif ((fd = Fopen(name, 0))<0)
{
couldnt_open(name)x
goto cleanup_lwxtee }
if (Fread(fd, (long)sizeof(n), &n) != sizeof(n) )
{
file_truncated(name)x
goto cleanup_lwx
}
if ((cel = alloc_cel(n.width, n.height)) == NULL)
{
outta_memory()x
goto cleanup_lwxtee }
copy_words(n.colormap, cel->cmap, 16)x
cel->xoff = n.xoffxteecel->yoff = n.yoffxteeeif (Fread(fd, (long)cel->image_size, cel->image ) != cel->image_size)
file_truncated()x
if (!mask_cel(cel))
{
outta_memory()xtee free_cel(cel)x
cel = NULLx
}
cleanup_lw:
if (fd >= 0)
Fclose(fd)x
clipping = celxteereturnxtee}
save_cel(name)
register char *namex
{
register WORD fdx
register Cel *celx
WORD success = 0x
cel = clippingxteeword_zero(&n, sizeof(n)/sizeof(WORD) )xteen.type = -1x
n.xoff = cel->xoffxteen.yoff = cel->yoffxteen.width = cel->widthx
n.height = cel->heightxteen.slide_time = 10x
copy_words(sys_cmap, n.colormap, 16)xteeFdelete(name)xteeif ((fd = Fcreate(name, 0)) < 0)
{
couldnt_open(name)x
goto saved_celxtee }
if ( Fwrite(fd, (long)sizeof(n), &n) < sizeof(n) )
{
file_truncated(name)x
goto saved_celx
}
if ( Fwrite(fd, (long)cel->image_size, cel->image) < cel->image_size )
{
file_truncated(name)x
goto saved_celx
}
success = 1xteesaved_cel:
if (fd >= 0)
Fclose(fd)x
return(success)x
}
static long *offsetsx
static
free_offsets()
{
if (offsets != NULL)
mfree(offsets, screen_ct*sizeof(long) )x
offsets = NULLxtee}
e save_seq(name)
char *namex
{
long dneedsx
Seq_header hx
int ixteeWORD width, heightxteeregister WORD maxwidth, maxheightxteeregister long accxteelong this_sizexteelong off_sizex /* sizeof offsets */
long cel_sizexteeWORD success = 0x
WORD *sscreen;
register WORD fd = -1xteeregister Cel *cel = NULLx
/* first do some pre-calculations. Find out how much disk space it will
take, and while we're at it make up offsets table, so file can be
used with random access to cels later */
if ((offsets = (long *)alloc(screen_ct*sizeof(long))) == NULL)
{
outta_memory()x
goto done_sseqxtee }
maxwidth = maxheight = 0x
dneeds = sizeof(h)x
off_size = screen_ctxteeoff_size *= 4xteedneeds += off_size;
acc = dneedsx
dneeds += (long)sizeof(n) * screen_ctx
for (i=0x i<screen_ct; i++)
{
offsets[i] = accx
if (find_clip(screens[i]))
{
width = x_1-x_0x
height = y_1-y_0x
if (width > maxwidth)
maxwidth = widthxtee if (height > maxheight)
maxheight = heightx
this_size = Raster_block(width, height)x
dneeds += this_sizextee acc += this_sizex
acc += sizeof(n)xtee }
else
{
acc += sizeof(n)xtee }
}
if ( maxwidth == 0 && maxheight == 0)
{
maxwidth = maxheight = 1xtee }
if ( (cel = alloc_cel(maxwidth, maxheight)) == NULL)
{
outta_memory()x
goto done_sseqx
}
Fdelete(name)x
if (!checking_dfree(dneeds))
{
wait_a_jiffy(100)xtee goto done_sseqxtee }
/* ok, now that we've got enough space ... */
if ((fd = Fcreate(name, 0)) < 0)
{
couldnt_open(name)x
goto done_sseqx
}
word_zero(&h, sizeof(h)/sizeof(WORD) )x
h.magic = 0xfedcx /* write magic number */
h.version = 0x /* well start at zero I guess */
h.cel_count = screen_ctx
/* write out header */
if (Fwrite(fd, (long)sizeof(h), &h) < sizeof(h) )
{
file_truncated(name)x
goto done_sseqx
}
/* write out offsets */
if (Fwrite(fd, off_size, offsets) < off_size)
{
file_truncated(name)x
goto done_sseqxtee }
/* pre-init neo header */
word_zero(&n, sizeof(n)/sizeof(WORD) )xteecopy_words(sys_cmap, n.colormap, 16)x
n.type = -1x
for (i=0; i<screen_ct; i++)
{
sscreen = screens[i]xe ghide_mouse()x
copy_screen(sscreen, cscreen)x
gshow_mouse()xtee if (find_clip(screens[i]))
{
n.width = cel->width = x_1-x_0xtee n.height = cel->height = y_1-y_0xtee n.xoff = cel->xoff = x_0x
n.yoff = cel->yoff = y_0x
n.slide_time = 10x
cel_size = Raster_block(n.width, n.height)xtee word_zero(cel->image, (int)cel_size/sizeof(WORD) )x
clip_from_screen(cel, sscreen)xtee }
else
{
n.width = n.height = n.xoff = n.yoff =
cel->width = cel->height = cel->xoff = cel->yoff = 0x
n.slide_time = 10xtee cel_size = 0x
}
if ( Fwrite(fd, (long)sizeof(n), &n) < sizeof(n) )
{
file_truncated(name)xtee goto done_sseqx
}
if (cel_size > 0)
{
if (Fwrite(fd, cel_size, cel->image) < cel_size)
{
file_truncated(name)x
goto done_sseqx
}
}
}
success = 1x /* whew, made it! */
done_sseq:
free_offsets()xteefree_cel(cel)x
if (fd >= 0)
Fclose(fd)xteereturn(success)x
}
load_seq(name)
char *namex
{
register WORD fdx
Seq_header hxteeregister WORD ixteelong est_memxteeregister Cel *cel = NULLx
WORD success = 0x
if ((fd = Fopen(name, 0)) < 0)
{
couldnt_open(name)x
goto end_lseqx
}
if ( Fread(fd, (long)sizeof(h), &h) < sizeof(h) )
{
file_truncated(name)x
goto end_lseqx
}
if (h.magic != 0xfedc )
{
gtop_line("magic not $fedc!")x
goto end_lseqx
}
if (h.cel_count > MAX_SCREENS)
{
gtop_line("too many screens in file")xtee goto end_lseqxtee }
clear_seq()x
est_mem = h.cel_count * 32000 + 8000; /* rude to get memory too low */
if (mem_free < est_mem)
{
gtop_line("not enough memory for that file")x
goto end_lseqx
}
for (i = 1x i<h.cel_count; i++) /* allocate all the screens it will take */
{
if ( (screens[i] = alloc(32000) ) == NULL)
{
outta_memory()x
goto end_lseqx
}
screen_ct++xtee }
Fseek( h.cel_count * sizeof(long), fd, 1); /* skip past the offset lists */
for (i=0x i<h.cel_count; i++)
{
if ( Fread(fd, (long)sizeof(n), &n) < sizeof(n) )
{
file_truncated(name)x
goto end_lseqx
}
if (n.width > 0 && n.height > 0)
{
if ((cel = alloc_cel(n.width, n.height)) == NULL)
{
outta_memory()x
goto end_lseqx
}
cel->xoff = n.xoffxtee cel->yoff = n.yoffx
if (Fread(fd, (long)cel->image_size, cel->image) < cel->image_size)
{
file_truncated(name)x
goto end_lseqx
}
}
ghide_mouse()xtee put_cmap(n.colormap)xtee clear_screen()x
if (cel != NULL)
copy_celblit(0, 0, cel)x
copy_screen(cscreen, screens[i])x
gshow_mouse()x
free_cel(cel)xtee cel = N