mirror of https://github.com/weiju/amiga-stuff
outfactored read_blocks() into common.c
This commit is contained in:
parent
79d09d1184
commit
6a63542f10
|
@ -104,3 +104,43 @@ BOOL read_level_map(struct LevelMap *level_map, char *s)
|
|||
level_map->height = raw_map->mapheight;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
struct BitMap *read_blocks(UWORD *colors, char *s)
|
||||
{
|
||||
LONG l;
|
||||
struct BitMap *bitmap;
|
||||
BPTR fhandle;
|
||||
|
||||
if (!(bitmap = AllocBitMap(BLOCKSWIDTH,
|
||||
BLOCKSHEIGHT,
|
||||
BLOCKSDEPTH,
|
||||
BMF_STANDARD | BMF_INTERLEAVED,
|
||||
0))) {
|
||||
strcpy(s, "Can't alloc blocks bitmap!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(fhandle = Open(BLOCKSNAME,MODE_OLDFILE))) {
|
||||
Fault(IoErr(), 0, s, 255);
|
||||
FreeBitMap(bitmap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (Read(fhandle, colors, PALSIZE) != PALSIZE) {
|
||||
Fault(IoErr(), 0, s, 255);
|
||||
FreeBitMap(bitmap);
|
||||
Close(fhandle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l = BLOCKSWIDTH * BLOCKSHEIGHT * BLOCKSDEPTH / 8;
|
||||
|
||||
if (Read(fhandle, bitmap->Planes[0], l) != l) {
|
||||
Fault(IoErr(), 0, s, 255);
|
||||
FreeBitMap(bitmap);
|
||||
Close(fhandle);
|
||||
return NULL;
|
||||
}
|
||||
Close(fhandle);
|
||||
return bitmap;
|
||||
}
|
||||
|
|
|
@ -39,5 +39,6 @@ struct LevelMap {
|
|||
extern ULONG get_mode_id(BOOL option_how, BOOL option_ntsc);
|
||||
extern BOOL get_arguments(struct PrgOptions *options, char *s);
|
||||
extern BOOL read_level_map(struct LevelMap *level_map, char *s);
|
||||
extern struct BitMap *read_blocks(UWORD *colors, char *s);
|
||||
|
||||
#endif /* __COMMON_H__ */
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
struct Screen *scr;
|
||||
struct RastPort *ScreenRastPort;
|
||||
struct BitMap *BlocksBitmap,*ScreenBitmap;
|
||||
UBYTE *frontbuffer,*blocksbuffer;
|
||||
struct BitMap *BlocksBitmap, *ScreenBitmap;
|
||||
UBYTE *frontbuffer, *blocksbuffer;
|
||||
|
||||
WORD mapposx,videoposx;
|
||||
WORD bitmapheight;
|
||||
|
@ -50,7 +50,6 @@ struct LevelMap level_map;
|
|||
UWORD colors[BLOCKSCOLORS];
|
||||
|
||||
struct PrgOptions options;
|
||||
BPTR MyHandle;
|
||||
char s[256];
|
||||
|
||||
#if EXTRAWIDTH == 32
|
||||
|
@ -106,44 +105,9 @@ static void Cleanup (char *msg)
|
|||
}
|
||||
|
||||
if (level_map.raw_map) FreeVec(level_map.raw_map);
|
||||
|
||||
if (MyHandle) Close(MyHandle);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static void OpenBlocks(void)
|
||||
{
|
||||
LONG l;
|
||||
|
||||
if (!(BlocksBitmap = AllocBitMap(BLOCKSWIDTH,
|
||||
BLOCKSHEIGHT,
|
||||
BLOCKSDEPTH,
|
||||
BMF_STANDARD | BMF_INTERLEAVED,
|
||||
0))) {
|
||||
Cleanup("Can't alloc blocks bitmap!");
|
||||
}
|
||||
|
||||
if (!(MyHandle = Open(BLOCKSNAME,MODE_OLDFILE))) {
|
||||
Fault(IoErr(),0,s,255);
|
||||
Cleanup(s);
|
||||
}
|
||||
|
||||
if (Read(MyHandle,colors,PALSIZE) != PALSIZE) {
|
||||
Fault(IoErr(),0,s,255);
|
||||
Cleanup(s);
|
||||
}
|
||||
|
||||
l = BLOCKSWIDTH * BLOCKSHEIGHT * BLOCKSDEPTH / 8;
|
||||
|
||||
if (Read(MyHandle, BlocksBitmap->Planes[0], l) != l) {
|
||||
Fault(IoErr(), 0, s, 255);
|
||||
Cleanup(s);
|
||||
}
|
||||
Close(MyHandle);
|
||||
MyHandle = 0;
|
||||
blocksbuffer = BlocksBitmap->Planes[0];
|
||||
}
|
||||
|
||||
static void OpenDisplay(void)
|
||||
{
|
||||
ULONG modeid;
|
||||
|
@ -448,7 +412,10 @@ int main(int argc, char **argv)
|
|||
res = read_level_map(&level_map, s);
|
||||
if (!res) Cleanup(s);
|
||||
|
||||
OpenBlocks();
|
||||
BlocksBitmap = read_blocks(colors, s);
|
||||
if (!BlocksBitmap) Cleanup(s);
|
||||
blocksbuffer = BlocksBitmap->Planes[0];
|
||||
|
||||
OpenDisplay();
|
||||
|
||||
if (!options.how) {
|
||||
|
|
|
@ -37,7 +37,7 @@ struct Screen *scr;
|
|||
struct RastPort *ScreenRastPort;
|
||||
struct BitMap *BlocksBitmap, *ScreenBitmap;
|
||||
|
||||
UBYTE *frontbuffer,*blocksbuffer;
|
||||
UBYTE *frontbuffer, *blocksbuffer;
|
||||
|
||||
WORD mapposx,videoposx;
|
||||
|
||||
|
@ -46,7 +46,6 @@ struct LevelMap level_map;
|
|||
UWORD colors[BLOCKSCOLORS];
|
||||
|
||||
struct PrgOptions options;
|
||||
BPTR MyHandle;
|
||||
char s[256];
|
||||
|
||||
struct FetchInfo fetchinfo [] =
|
||||
|
@ -81,43 +80,9 @@ static void Cleanup(char *msg)
|
|||
}
|
||||
|
||||
if (level_map.raw_map) free(level_map.raw_map);
|
||||
if (MyHandle) Close(MyHandle);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static void OpenBlocks(void)
|
||||
{
|
||||
LONG l;
|
||||
|
||||
if (!(BlocksBitmap = AllocBitMap(BLOCKSWIDTH,
|
||||
BLOCKSHEIGHT,
|
||||
BLOCKSDEPTH,
|
||||
BMF_STANDARD | BMF_INTERLEAVED,
|
||||
0))) {
|
||||
Cleanup("Can't alloc blocks bitmap!");
|
||||
}
|
||||
|
||||
if (!(MyHandle = Open(BLOCKSNAME,MODE_OLDFILE))) {
|
||||
Fault(IoErr(),0,s,255);
|
||||
Cleanup(s);
|
||||
}
|
||||
|
||||
if (Read(MyHandle,colors,PALSIZE) != PALSIZE) {
|
||||
Fault(IoErr(),0,s,255);
|
||||
Cleanup(s);
|
||||
}
|
||||
|
||||
l = BLOCKSWIDTH * BLOCKSHEIGHT * BLOCKSDEPTH / 8;
|
||||
|
||||
if (Read(MyHandle,BlocksBitmap->Planes[0],l) != l) {
|
||||
Fault(IoErr(),0,s,255);
|
||||
Cleanup(s);
|
||||
}
|
||||
Close(MyHandle);
|
||||
MyHandle = 0;
|
||||
blocksbuffer = BlocksBitmap->Planes[0];
|
||||
}
|
||||
|
||||
static void OpenDisplay(void)
|
||||
{
|
||||
ULONG modeid;
|
||||
|
@ -386,7 +351,10 @@ int main(int argc, char **argv)
|
|||
res = read_level_map(&level_map, s);
|
||||
if (!res) Cleanup(s);
|
||||
|
||||
OpenBlocks();
|
||||
BlocksBitmap = read_blocks(colors, s);
|
||||
if (!BlocksBitmap) Cleanup(s);
|
||||
blocksbuffer = BlocksBitmap->Planes[0];
|
||||
|
||||
OpenDisplay();
|
||||
|
||||
if (!options.how) {
|
||||
|
|
Loading…
Reference in New Issue