changed naming scheme in scrolling demos

This commit is contained in:
Wei-ju Wu 2016-06-20 17:40:44 -07:00
parent 9426af1e0c
commit ab8c02cc7b
9 changed files with 305 additions and 365 deletions

View File

@ -31,13 +31,13 @@ static struct Process *thisprocess;
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
static LONG NullInputHandler(void)
static LONG null_input_handler(void)
{
// kills all input
return 0;
}
void KillSystem(void)
void kill_system(void)
{
thisprocess = (struct Process *)FindTask(0);
@ -48,7 +48,7 @@ void KillSystem(void)
WaitTOF();
WaitTOF();
// install NullInputHandler to kill all input events
// install null_input_handler() to kill all input events
if ((inputmp = CreateMsgPort())) {
if ((inputreq = CreateIORequest(inputmp,sizeof(*inputreq)))) {
if (OpenDevice("input.device",0,(struct IORequest *)inputreq,0) == 0) {
@ -56,7 +56,7 @@ void KillSystem(void)
inputhandler.is_Node.ln_Type = NT_INTERRUPT;
inputhandler.is_Node.ln_Pri = 127;
inputhandler.is_Data = 0;
inputhandler.is_Code = (APTR)NullInputHandler;
inputhandler.is_Code = (APTR) null_input_handler;
inputreq->io_Command = IND_ADDHANDLER;
inputreq->io_Data = &inputhandler;
DoIO((struct IORequest *)inputreq);
@ -82,7 +82,7 @@ void KillSystem(void)
old_intreq = custom->intreqr | 0x8000;
}
void ActivateSystem(void)
void activate_system(void)
{
// reset important custom registers
custom->dmacon = 0x7FFF;
@ -123,7 +123,7 @@ void ActivateSystem(void)
WaitTOF();
}
void WaitVBL(void)
void wait_vbl(void)
{
UBYTE b;
@ -131,7 +131,7 @@ void WaitVBL(void)
while(*(UBYTE *)0xbfe801 == b) ;
}
void WaitVBeam(ULONG line)
void wait_vbeam(ULONG line)
{
ULONG vpos;
@ -142,32 +142,38 @@ void WaitVBeam(ULONG line)
} while ((vpos & 0x1FF00) != line);
}
void HardWaitBlit(void)
void hard_wait_blit(void)
{
if (custom->dmaconr & DMAF_BLTDONE) ;
while (custom->dmaconr & DMAF_BLTDONE) ;
}
void HardWaitLMB(void)
{
while (((*(UBYTE *)0xbfe001) & 64) != 0) ;
while (((*(UBYTE *)0xbfe001) & 64) == 0) ;
}
BOOL joy_left(void) { return (custom->joy1dat & 512) ? TRUE : FALSE; }
BOOL joy_right(void) { return (custom->joy1dat & 2) ? TRUE : FALSE; }
BOOL JoyLeft(void) { return (custom->joy1dat & 512) ? TRUE : FALSE; }
BOOL JoyRight(void) { return (custom->joy1dat & 2) ? TRUE : FALSE; }
BOOL JoyFire(void) { return ((*(UBYTE *)0xbfe001) & 128) ? FALSE : TRUE; }
BOOL LMBDown(void) { return ((*(UBYTE *)0xbfe001) & 64) ? FALSE : TRUE; }
BOOL JoyUp(void)
BOOL joy_up(void)
{
// ^ = xor
WORD w = custom->joy1dat << 1;
return ((w ^ custom->joy1dat) & 512) ? TRUE : FALSE;
}
BOOL JoyDown(void)
BOOL joy_down(void)
{
// ^ = xor
WORD w = custom->joy1dat << 1;
return ((w ^ custom->joy1dat) & 2) ? TRUE : FALSE;
}
BOOL joy_fire(void) { return ((*(UBYTE *)0xbfe001) & 128) ? FALSE : TRUE; }
BOOL lmb_down(void) { return ((*(UBYTE *)0xbfe001) & 64) ? FALSE : TRUE; }
// This is not used, but keeping it as a reference, since waiting for mouse button is
// tricky in C vs assembly
/*
void hard_wait_lmb(void)
{
while (((*(UBYTE *)0xbfe001) & 64) != 0) ;
while (((*(UBYTE *)0xbfe001) & 64) == 0) ;
}
*/

View File

@ -11,17 +11,17 @@
#define BPL0_BPU3_F 0x10
#define BPL0_BPUMASK 0x7000
void KillSystem(void);
void ActivateSystem(void);
void WaitVBL(void);
void WaitVBeam(ULONG line);
void HardWaitBlit(void);
void HardWaitLMB(void);
void kill_system(void);
void activate_system(void);
void wait_vbl(void);
void wait_vbeam(ULONG line);
void hard_wait_blit(void);
BOOL JoyLeft(void);
BOOL JoyRight(void);
BOOL JoyUp(void);
BOOL JoyDown(void);
BOOL JoyFire(void);
BOOL LMBDown(void);
BOOL joy_left(void);
BOOL joy_right(void);
BOOL joy_up(void);
BOOL joy_down(void);
BOOL joy_fire(void);
BOOL lmb_down(void);

View File

@ -41,23 +41,20 @@
#define DIRECTION_RIGHT 0
#define DIRECTION_LEFT 1
struct Screen *scr;
struct RastPort *ScreenRastPort;
struct BitMap *BlocksBitmap, *ScreenBitmap;
UBYTE *frontbuffer, *blocksbuffer;
WORD mapposx,videoposx;
WORD bitmapheight;
BYTE previous_direction;
WORD *savewordpointer;
WORD saveword;
struct LevelMap level_map;
UWORD colors[BLOCKSCOLORS];
struct Screen *scr;
struct RastPort *ScreenRastPort;
struct BitMap *BlocksBitmap, *ScreenBitmap;
struct LevelMap level_map;
struct PrgOptions options;
char s[256];
UBYTE *frontbuffer, *blocksbuffer;
WORD mapposx, videoposx;
WORD bitmapheight;
BYTE previous_direction;
WORD *savewordpointer;
WORD saveword;
UWORD colors[BLOCKSCOLORS];
char s[256];
#if EXTRAWIDTH == 32
@ -86,9 +83,7 @@ struct FetchInfo fetchinfo [] =
{0x18,0xB8,8,48,64} /* BPL32 + BPAGEM */
};
/************* SETUP/CLEANUP ROUTINES ***************/
static void Cleanup (char *msg)
static void cleanup (char *msg)
{
WORD rc;
@ -115,77 +110,68 @@ static void Cleanup (char *msg)
exit(rc);
}
static void OpenDisplay(void)
static void open_display(void)
{
ULONG modeid;
ULONG modeid;
bitmapheight = BITMAPHEIGHT +
(level_map.width / BITMAPBLOCKSPERROW / BLOCKSDEPTH) + 1 +
3;
bitmapheight = BITMAPHEIGHT + (level_map.width / BITMAPBLOCKSPERROW / BLOCKSDEPTH) + 1 + 3;
if (!(ScreenBitmap = AllocBitMap(BITMAPWIDTH,bitmapheight,BLOCKSDEPTH,BMF_STANDARD | BMF_INTERLEAVED | BMF_CLEAR,0)))
{
Cleanup("Can't alloc screen bitmap!");
if (!(ScreenBitmap = AllocBitMap(BITMAPWIDTH, bitmapheight, BLOCKSDEPTH,
BMF_STANDARD | BMF_INTERLEAVED | BMF_CLEAR, 0))) {
cleanup("Can't alloc screen bitmap!");
}
frontbuffer = ScreenBitmap->Planes[0];
frontbuffer += (fetchinfo[options.fetchmode].bitmapoffset / 8);
if (!(TypeOfMem(ScreenBitmap->Planes[0]) & MEMF_CHIP))
{
Cleanup("Screen bitmap is not in CHIP RAM!?? If you have a gfx card try disabling \"planes to fast\" or similiar options in your RTG system!");
if (!(TypeOfMem(ScreenBitmap->Planes[0]) & MEMF_CHIP)) {
cleanup("Screen bitmap is not in CHIP RAM!?? If you have a gfx card try disabling \"planes to fast\" or similiar options in your RTG system!");
}
if (!IS_BITMAP_INTERLEAVED(ScreenBitmap)) {
Cleanup("Screen bitmap is not in interleaved format!??");
cleanup("Screen bitmap is not in interleaved format!??");
}
modeid = get_mode_id(options.how, options.ntsc);
if (!(scr = OpenScreenTags(0,SA_Width,BITMAPWIDTH,
SA_Height,bitmapheight,
SA_Depth,BLOCKSDEPTH,
SA_DisplayID,modeid,
SA_BitMap,ScreenBitmap,
options.how ? SA_Overscan : TAG_IGNORE,OSCAN_TEXT,
options.how ? SA_AutoScroll : TAG_IGNORE,TRUE,
SA_Quiet,TRUE,
TAG_DONE))) {
Cleanup("Can't open screen!");
if (!(scr = OpenScreenTags(0, SA_Width, BITMAPWIDTH,
SA_Height, bitmapheight,
SA_Depth, BLOCKSDEPTH,
SA_DisplayID, modeid,
SA_BitMap, ScreenBitmap,
options.how ? SA_Overscan : TAG_IGNORE, OSCAN_TEXT,
options.how ? SA_AutoScroll : TAG_IGNORE, TRUE,
SA_Quiet, TRUE,
TAG_DONE))) {
cleanup("Can't open screen!");
}
if (scr->RastPort.BitMap->Planes[0] != ScreenBitmap->Planes[0]) {
Cleanup("Screen was not created with the custom bitmap I supplied!??");
cleanup("Screen was not created with the custom bitmap I supplied!??");
}
ScreenRastPort = &scr->RastPort;
LoadRGB4(&scr->ViewPort,colors,BLOCKSCOLORS);
LoadRGB4(&scr->ViewPort, colors, BLOCKSCOLORS);
}
static void InitCopperlist(void)
static void init_copper_list(void)
{
WORD *wp;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
CopFETCHMODE[1] = options.fetchmode;
// bitplane control registers
CopBPLCON0[1] = ((BLOCKSDEPTH * BPL0_BPU0_F) & BPL0_BPUMASK) +
((BLOCKSDEPTH / 8) * BPL0_BPU3_F) +
BPL0_COLOR_F +
(options.speed ? 0 : BPL0_USEBPLCON3_F);
CopBPLCON0[1] = ((BLOCKSDEPTH * BPL0_BPU0_F) & BPL0_BPUMASK) + ((BLOCKSDEPTH / 8) * BPL0_BPU3_F) +
BPL0_COLOR_F + (options.speed ? 0 : BPL0_USEBPLCON3_F);
CopBPLCON1[1] = 0;
CopBPLCON3[1] = BPLCON3_BRDNBLNK;
// bitplane modulos
l = BITMAPBYTESPERROW * BLOCKSDEPTH -
SCREENBYTESPERROW - fetchinfo[options.fetchmode].modulooffset;
l = BITMAPBYTESPERROW * BLOCKSDEPTH - SCREENBYTESPERROW - fetchinfo[options.fetchmode].modulooffset;
CopBPLMODA[1] = l;
CopBPLMODB[1] = l;
@ -202,8 +188,8 @@ static void InitCopperlist(void)
wp = CopPLANE1H;
for (l = 0; l < BLOCKSDEPTH; l++) {
wp[1] = (WORD)(((ULONG)ScreenBitmap->Planes[l]) >> 16);
wp[3] = (WORD)(((ULONG)ScreenBitmap->Planes[l]) & 0xFFFF);
wp[1] = (WORD) (((ULONG)ScreenBitmap->Planes[l]) >> 16);
wp[3] = (WORD) (((ULONG)ScreenBitmap->Planes[l]) & 0xFFFF);
wp += 4;
}
@ -213,12 +199,10 @@ static void InitCopperlist(void)
}
custom->intena = 0x7FFF;
custom->dmacon = DMAF_SETCLR | DMAF_BLITTER | DMAF_COPPER | DMAF_RASTER | DMAF_MASTER;
custom->cop2lc = (ULONG)CopperList;
custom->cop2lc = (ULONG) CopperList;
}
/******************* SCROLLING **********************/
static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
static void draw_block(LONG x, LONG y, LONG mapx, LONG mapy)
{
UBYTE block;
@ -228,13 +212,12 @@ static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
y = y * BITMAPBYTESPERROW;
block = level_map.data[mapy * level_map.width + mapx];
mapx = (block % BLOCKSPERROW) * (BLOCKWIDTH / 8);
mapy = (block / BLOCKSPERROW) * (BLOCKPLANELINES * BLOCKSBYTESPERROW);
if (options.how) OwnBlitter();
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -243,13 +226,13 @@ static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
custom->bltamod = BLOCKSBYTESPERROW - (BLOCKWIDTH / 8);
custom->bltdmod = BITMAPBYTESPERROW - (BLOCKWIDTH / 8);
custom->bltapt = blocksbuffer + mapy + mapx;
custom->bltdpt = frontbuffer + y + x;
custom->bltdpt = frontbuffer + y + x;
custom->bltsize = BLOCKPLANELINES * 64 + (BLOCKWIDTH / 16);
if (options.how) DisownBlitter();
}
static void FillScreen(void)
static void fill_screen(void)
{
WORD a, b, x, y;
@ -257,12 +240,12 @@ static void FillScreen(void)
for (a = 0; a < BITMAPBLOCKSPERROW; a++) {
x = a * BLOCKWIDTH;
y = b * BLOCKPLANELINES;
DrawBlock(x, y, a, b);
draw_block(x, y, a, b);
}
}
}
static void ScrollLeft(void)
static void scroll_left(void)
{
WORD mapx,mapy,x,y;
@ -278,17 +261,17 @@ static void ScrollLeft(void)
y = mapy * BLOCKPLANELINES;
if (previous_direction == DIRECTION_RIGHT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
savewordpointer = (WORD *)(frontbuffer + y * BITMAPBYTESPERROW + (x / 8));
saveword = *savewordpointer;
DrawBlock(x,y,mapx,mapy);
draw_block(x,y,mapx,mapy);
previous_direction = DIRECTION_LEFT;
}
static void ScrollRight(void)
static void scroll_right(void)
{
WORD mapx,mapy,x,y;
@ -301,40 +284,27 @@ static void ScrollRight(void)
y = mapy * BLOCKPLANELINES;
if (previous_direction == DIRECTION_LEFT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
savewordpointer = (WORD *)(frontbuffer + (y + BLOCKPLANELINES - 1) * BITMAPBYTESPERROW + (x / 8));
saveword = *savewordpointer;
DrawBlock(x,y,mapx,mapy);
draw_block(x, y, mapx, mapy);
mapposx++;
videoposx = mapposx;
previous_direction = DIRECTION_RIGHT;
}
static void CheckJoyScroll(void)
static void check_joy_scroll(void)
{
WORD i,count;
if (JoyFire()) count = 8;
else count = 1;
if (JoyLeft()) {
for (i = 0; i < count; i++) {
ScrollLeft();
}
}
if (JoyRight()) {
for (i = 0;i < count;i++) {
ScrollRight();
}
}
WORD count = joy_fire() ? 8 : 1;
if (joy_left()) for (int i = 0; i < count; i++) scroll_left();
if (joy_right()) for (int i = 0; i < count; i++) scroll_right();
}
static void UpdateCopperlist(void)
static void update_copper_list(void)
{
ULONG pl;
WORD xpos, planeaddx, scroll, i;
@ -359,81 +329,79 @@ static void UpdateCopperlist(void)
for (i = 0; i < BLOCKSDEPTH; i++) {
pl = ((ULONG)ScreenBitmap->Planes[i]) + planeaddx;
wp[1] = (WORD)(pl >> 16);
wp[3] = (WORD)(pl & 0xFFFF);
wp[1] = (WORD) (pl >> 16);
wp[3] = (WORD) (pl & 0xFFFF);
wp += 4;
}
}
static void ShowWhatCopperWouldDo(void)
static void show_what_copper_would_do(void)
{
WORD x = (videoposx+16) % BITMAPWIDTH;
SetWriteMask(ScreenRastPort,1);
SetAPen(ScreenRastPort,0);
RectFill(ScreenRastPort,0,bitmapheight - 3,BITMAPWIDTH-1,bitmapheight - 3);
SetWriteMask(ScreenRastPort, 1);
SetAPen(ScreenRastPort, 0);
RectFill(ScreenRastPort, 0, bitmapheight - 3, BITMAPWIDTH - 1, bitmapheight - 3);
SetAPen(ScreenRastPort,1);
if (x <= EXTRAWIDTH) {
RectFill(ScreenRastPort,x,bitmapheight - 3,x+SCREENWIDTH-1,bitmapheight - 3);
RectFill(ScreenRastPort, x, bitmapheight - 3, x + SCREENWIDTH - 1, bitmapheight - 3);
} else {
RectFill(ScreenRastPort,x,bitmapheight - 3,BITMAPWIDTH-1,bitmapheight - 3);
RectFill(ScreenRastPort,0,bitmapheight - 3,x - EXTRAWIDTH,bitmapheight - 3);
RectFill(ScreenRastPort, x, bitmapheight - 3, BITMAPWIDTH - 1, bitmapheight - 3);
RectFill(ScreenRastPort, 0, bitmapheight - 3, x - EXTRAWIDTH, bitmapheight - 3);
}
}
static void MainLoop(void)
static void main_loop(void)
{
if (!options.how) {
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
// activate copperlist
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(199);
WaitVBeam(200);
wait_vbeam(199);
wait_vbeam(200);
} else {
Delay(1);
}
if (options.speed) *(WORD *)0xdff180 = 0xFF0;
if (options.speed) *(WORD *) 0xdff180 = 0xFF0;
CheckJoyScroll();
check_joy_scroll();
if (options.speed) *(WORD *)0xdff180 = 0xF00;
if (!options.how) UpdateCopperlist();
else ShowWhatCopperWouldDo();
if (options.speed) *(WORD *) 0xdff180 = 0xF00;
if (!options.how) update_copper_list();
else show_what_copper_would_do();
}
}
/********************* MAIN *************************/
int main(int argc, char **argv)
{
BOOL res = get_arguments(&options, s);
if (!res) Cleanup(s);
if (!res) cleanup(s);
res = read_level_map(LARGE_MAP_PATH, &level_map, s);
if (!res) Cleanup(s);
if (!res) cleanup(s);
BlocksBitmap = read_blocks(DEMO_BLOCKS_PATH, colors, s, BLOCKSWIDTH, BLOCKSHEIGHT);
if (!BlocksBitmap) Cleanup(s);
if (!BlocksBitmap) cleanup(s);
blocksbuffer = BlocksBitmap->Planes[0];
OpenDisplay();
open_display();
if (!options.how) {
Delay(2*50);
KillSystem();
InitCopperlist();
kill_system();
init_copper_list();
}
FillScreen();
MainLoop();
fill_screen();
main_loop();
if (!options.how) ActivateSystem();
Cleanup(0);
if (!options.how) activate_system();
cleanup(0);
return 0;
}

View File

@ -41,37 +41,31 @@
#define BLOCKSFILESIZE (BLOCKSWIDTH * BLOCKSHEIGHT * BLOCKSPLANES / 8 + PALSIZE)
struct Screen *scr;
struct RastPort *ScreenRastPort;
struct BitMap *BlocksBitmap, *ScreenBitmap;
UBYTE *frontbuffer, *blocksbuffer;
WORD mapposx,videoposx;
struct LevelMap level_map;
UWORD colors[BLOCKSCOLORS];
struct LevelMap level_map;
struct PrgOptions options;
char s[256];
struct BitMap *BlocksBitmap, *ScreenBitmap;
struct RastPort *ScreenRastPort;
struct Screen *scr;
UBYTE *frontbuffer, *blocksbuffer;
WORD mapposx, videoposx;
UWORD colors[BLOCKSCOLORS];
char s[256];
struct FetchInfo fetchinfo [] =
{
{0x30,0xD0,2,0,16}, /* normal */
{0x28,0xC8,4,16,32}, /* BPL32 */
{0x28,0xC8,4,16,32}, /* BPAGEM */
{0x18,0xB8,8,48,64} /* BPL32 + BPAGEM */
{0x30, 0xD0, 2, 0, 16}, /* normal */
{0x28, 0xC8, 4, 16, 32}, /* BPL32 */
{0x28, 0xC8, 4, 16, 32}, /* BPAGEM */
{0x18, 0xB8, 8, 48, 64} /* BPL32 + BPAGEM */
};
/************* SETUP/CLEANUP ROUTINES ***************/
static void Cleanup(char *msg)
static void cleanup(char *msg)
{
WORD rc;
if (msg) {
printf("Error: %s\n",msg);
printf("Error: %s\n", msg);
rc = RETURN_WARN;
} else rc = RETURN_OK;
@ -86,73 +80,69 @@ static void Cleanup(char *msg)
WaitBlit();
FreeBitMap(BlocksBitmap);
}
if (level_map.raw_map) free(level_map.raw_map);
exit(rc);
}
static void OpenDisplay(void)
static void open_display(void)
{
ULONG modeid;
LONG bmflags;
ULONG modeid;
LONG bmflags;
if (!(ScreenBitmap = AllocBitMap(BITMAPWIDTH,BITMAPHEIGHT + 3,BLOCKSDEPTH,
BMF_STANDARD | BMF_INTERLEAVED | BMF_CLEAR,0))) {
Cleanup("Can't alloc screen bitmap!");
if (!(ScreenBitmap = AllocBitMap(BITMAPWIDTH, BITMAPHEIGHT + 3, BLOCKSDEPTH,
BMF_STANDARD | BMF_INTERLEAVED | BMF_CLEAR, 0))) {
cleanup("Can't alloc screen bitmap!");
}
frontbuffer = ScreenBitmap->Planes[0];
frontbuffer += (fetchinfo[options.fetchmode].bitmapoffset / 8);
if (!(TypeOfMem(ScreenBitmap->Planes[0]) & MEMF_CHIP)) {
Cleanup("Screen bitmap is not in CHIP RAM!?? If you have a gfx card try disabling \"planes to fast\" or similiar options in your RTG system!");
cleanup("Screen bitmap is not in CHIP RAM!?? If you have a gfx card try disabling \"planes to fast\" or similiar options in your RTG system!");
}
if (!IS_BITMAP_INTERLEAVED(ScreenBitmap)) {
Cleanup("Screen bitmap is not in interleaved format!??");
cleanup("Screen bitmap is not in interleaved format!??");
}
modeid = get_mode_id(options.how, options.ntsc);
if (!(scr = OpenScreenTags(0,SA_Width,BITMAPWIDTH,
SA_Height,BITMAPHEIGHT + 3,
SA_Depth,BLOCKSDEPTH,
SA_DisplayID,modeid,
SA_BitMap,ScreenBitmap,
options.how ? SA_Overscan : TAG_IGNORE,OSCAN_TEXT,
options.how ? SA_AutoScroll : TAG_IGNORE,TRUE,
SA_Quiet,TRUE,
TAG_DONE))) {
Cleanup("Can't open screen!");
if (!(scr = OpenScreenTags(0, SA_Width, BITMAPWIDTH,
SA_Height, BITMAPHEIGHT + 3,
SA_Depth, BLOCKSDEPTH,
SA_DisplayID, modeid,
SA_BitMap, ScreenBitmap,
options.how ? SA_Overscan : TAG_IGNORE,OSCAN_TEXT,
options.how ? SA_AutoScroll : TAG_IGNORE,TRUE,
SA_Quiet,TRUE,
TAG_DONE))) {
cleanup("Can't open screen!");
}
if (scr->RastPort.BitMap->Planes[0] != ScreenBitmap->Planes[0]) {
Cleanup("Screen was not created with the custom bitmap I supplied!??");
cleanup("Screen was not created with the custom bitmap I supplied!??");
}
ScreenRastPort = &scr->RastPort;
LoadRGB4(&scr->ViewPort,colors,BLOCKSCOLORS);
LoadRGB4(&scr->ViewPort, colors, BLOCKSCOLORS);
}
static void InitCopperlist(void)
static void init_copper_list(void)
{
WORD *wp;
WORD *wp;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
CopFETCHMODE[1] = options.fetchmode;
// bitplane control registers
CopBPLCON0[1] = ((BLOCKSDEPTH * BPL0_BPU0_F) & BPL0_BPUMASK) +
((BLOCKSDEPTH / 8) * BPL0_BPU3_F) +
BPL0_COLOR_F +
(options.speed ? 0 : BPL0_USEBPLCON3_F);
CopBPLCON0[1] = ((BLOCKSDEPTH * BPL0_BPU0_F) & BPL0_BPUMASK) + ((BLOCKSDEPTH / 8) * BPL0_BPU3_F) +
BPL0_COLOR_F + (options.speed ? 0 : BPL0_USEBPLCON3_F);
CopBPLCON1[1] = 0;
CopBPLCON3[1] = BPLCON3_BRDNBLNK;
// bitplane modulos
l = BITMAPBYTESPERROW * BLOCKSDEPTH -
SCREENBYTESPERROW - fetchinfo[options.fetchmode].modulooffset;
l = BITMAPBYTESPERROW * BLOCKSDEPTH - SCREENBYTESPERROW - fetchinfo[options.fetchmode].modulooffset;
CopBPLMODA[1] = l;
CopBPLMODB[1] = l;
@ -166,28 +156,25 @@ static void InitCopperlist(void)
CopDDFSTOP[1] = fetchinfo[options.fetchmode].ddfstop;
// plane pointers
wp = CopPLANE1H;
for (l = 0;l < BLOCKSDEPTH;l++) {
wp[1] = (WORD)(((ULONG)ScreenBitmap->Planes[l]) >> 16);
wp[3] = (WORD)(((ULONG)ScreenBitmap->Planes[l]) & 0xFFFF);
for (l = 0; l < BLOCKSDEPTH; l++) {
wp[1] = (WORD)(((ULONG) ScreenBitmap->Planes[l]) >> 16);
wp[3] = (WORD)(((ULONG) ScreenBitmap->Planes[l]) & 0xFFFF);
wp += 4;
}
if (options.sky) {
// activate copper sky
CopSKY[0] = 0x290f;
}
// activate copper sky
if (options.sky) CopSKY[0] = 0x290f;
custom->intena = 0x7FFF;
custom->dmacon = DMAF_SETCLR | DMAF_BLITTER | DMAF_COPPER | DMAF_RASTER | DMAF_MASTER;
custom->cop2lc = (ULONG)CopperList;
custom->cop2lc = (ULONG) CopperList;
}
/******************* SCROLLING **********************/
static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
static void draw_block(LONG x, LONG y, LONG mapx, LONG mapy)
{
UBYTE block;
@ -203,7 +190,7 @@ static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
if (options.how) OwnBlitter();
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -212,27 +199,27 @@ static void DrawBlock(LONG x, LONG y, LONG mapx, LONG mapy)
custom->bltamod = BLOCKSBYTESPERROW - (BLOCKWIDTH / 8);
custom->bltdmod = BITMAPBYTESPERROW - (BLOCKWIDTH / 8);
custom->bltapt = blocksbuffer + mapy + mapx;
custom->bltdpt = frontbuffer + y + x;
custom->bltdpt = frontbuffer + y + x;
custom->bltsize = BLOCKPLANELINES * 64 + (BLOCKWIDTH / 16);
if (options.how) DisownBlitter();
}
static void FillScreen(void)
static void fill_screen(void)
{
WORD a,b,x,y;
WORD a, b, x, y;
for (b = 0;b < BITMAPBLOCKSPERCOL;b++) {
for (a = 0;a < HALFBITMAPBLOCKSPERROW;a++) {
for (b = 0; b < BITMAPBLOCKSPERCOL; b++) {
for (a = 0; a < HALFBITMAPBLOCKSPERROW; a++) {
x = a * BLOCKWIDTH;
y = b * BLOCKPLANELINES;
DrawBlock(x,y,a,b);
DrawBlock(x + HALFBITMAPWIDTH,y,a,b);
draw_block(x, y, a, b);
draw_block(x + HALFBITMAPWIDTH, y, a, b);
}
}
}
static void ScrollLeft(void)
static void scroll_left(void)
{
WORD mapx,mapy,x,y;
@ -247,13 +234,13 @@ static void ScrollLeft(void)
x = ROUND2BLOCKWIDTH(videoposx);
y = mapy * BLOCKPLANELINES;
DrawBlock(x,y,mapx,mapy);
DrawBlock(x + HALFBITMAPWIDTH,y,mapx,mapy);
draw_block(x, y, mapx, mapy);
draw_block(x + HALFBITMAPWIDTH, y, mapx, mapy);
}
static void ScrollRight(void)
static void scroll_right(void)
{
WORD mapx,mapy,x,y;
WORD mapx, mapy, x, y;
if (mapposx >= (level_map.width * BLOCKWIDTH - SCREENWIDTH - BLOCKWIDTH)) return;
@ -263,32 +250,25 @@ static void ScrollRight(void)
x = ROUND2BLOCKWIDTH(videoposx);
y = mapy * BLOCKPLANELINES;
DrawBlock(x,y,mapx,mapy);
DrawBlock(x + HALFBITMAPWIDTH,y,mapx,mapy);
draw_block(x, y, mapx, mapy);
draw_block(x + HALFBITMAPWIDTH, y, mapx, mapy);
mapposx++;
videoposx = mapposx % HALFBITMAPWIDTH;
}
static void CheckJoyScroll(void)
static void check_joy_scroll(void)
{
WORD i,count;
if (JoyFire()) count = 8; else count = 1;
if (JoyLeft()) {
for (i = 0; i < count; i++) ScrollLeft();
}
if (JoyRight()) {
for (i = 0; i < count; i++) ScrollRight();
}
WORD count = joy_fire() ? count = 8 : 1;
if (joy_left()) for (int i = 0; i < count; i++) scroll_left();
if (joy_right()) for (int i = 0; i < count; i++) scroll_right();
}
static void UpdateCopperlist(void)
static void update_copper_list(void)
{
ULONG pl;
WORD xpos,planeaddx,scroll,i;
WORD *wp;
WORD xpos, planeaddx, scroll, i;
WORD *wp;
i = fetchinfo[options.fetchmode].scrollpixels;
@ -307,73 +287,71 @@ static void UpdateCopperlist(void)
// set plane pointers
wp = CopPLANE1H;
for (i = 0;i < BLOCKSDEPTH;i++) {
pl = ((ULONG)ScreenBitmap->Planes[i]) + planeaddx;
wp[1] = (WORD)(pl >> 16);
wp[3] = (WORD)(pl & 0xFFFF);
for (i = 0; i < BLOCKSDEPTH; i++) {
pl = ((ULONG) ScreenBitmap->Planes[i]) + planeaddx;
wp[1] = (WORD) (pl >> 16);
wp[3] = (WORD) (pl & 0xFFFF);
wp += 4;
}
}
static void ShowWhatCopperWouldDo(void)
static void show_what_copper_would_do(void)
{
SetWriteMask(ScreenRastPort,1);
SetAPen(ScreenRastPort,0);
RectFill(ScreenRastPort,0,BITMAPHEIGHT + 1,BITMAPWIDTH - 1,BITMAPHEIGHT + 1);
SetAPen(ScreenRastPort,1);
RectFill(ScreenRastPort,videoposx + BLOCKWIDTH,BITMAPHEIGHT + 1,
videoposx + BLOCKWIDTH + SCREENWIDTH - 1,BITMAPHEIGHT + 1);
SetAPen(ScreenRastPort, 0);
RectFill(ScreenRastPort, 0, BITMAPHEIGHT + 1, BITMAPWIDTH - 1, BITMAPHEIGHT + 1);
SetAPen(ScreenRastPort, 1);
RectFill(ScreenRastPort, videoposx + BLOCKWIDTH, BITMAPHEIGHT + 1,
videoposx + BLOCKWIDTH + SCREENWIDTH - 1, BITMAPHEIGHT + 1);
}
static void MainLoop(void)
static void main_loop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(199);
WaitVBeam(200);
wait_vbeam(199);
wait_vbeam(200);
} else Delay(1);
if (options.speed) *(WORD *)0xdff180 = 0xFF0;
if (options.speed) *(WORD *) 0xdff180 = 0xFF0;
CheckJoyScroll();
check_joy_scroll();
if (options.speed) *(WORD *)0xdff180 = 0xF00;
if (!options.how) UpdateCopperlist();
else ShowWhatCopperWouldDo();
if (options.speed) *(WORD *) 0xdff180 = 0xF00;
if (!options.how) update_copper_list();
else show_what_copper_would_do();
}
}
/********************* MAIN *************************/
int main(int argc, char **argv)
{
BOOL res = get_arguments(&options, s);
if (!res) Cleanup(s);
if (!res) cleanup(s);
res = read_level_map(LARGE_MAP_PATH, &level_map, s);
if (!res) Cleanup(s);
if (!res) cleanup(s);
BlocksBitmap = read_blocks(DEMO_BLOCKS_PATH, colors, s, BLOCKSWIDTH, BLOCKSHEIGHT);
if (!BlocksBitmap) Cleanup(s);
if (!BlocksBitmap) cleanup(s);
blocksbuffer = BlocksBitmap->Planes[0];
OpenDisplay();
open_display();
if (!options.how) {
Delay(2*50);
KillSystem();
InitCopperlist();
kill_system();
init_copper_list();
}
FillScreen();
MainLoop();
fill_screen();
main_loop();
if (!options.how) ActivateSystem();
Cleanup(0);
if (!options.how) activate_system();
cleanup(0);
return 0;
}

View File

@ -191,7 +191,7 @@ static void InitCopperlist(void)
ULONG plane,plane2;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
@ -274,7 +274,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
if (options.how) OwnBlitter();
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
custom->bltafwm = 0xFFFF;
@ -515,7 +515,7 @@ static void ScrollLeft(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_RIGHT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -564,7 +564,7 @@ static void ScrollRight(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_LEFT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -646,28 +646,28 @@ static void CheckJoyScroll(void)
{
WORD i,count;
if (JoyFire()) count = 4;
if (joy_fire()) count = 4;
else count = 1;
if (JoyUp()) {
if (joy_up()) {
for (i = 0; i < count; i++) {
ScrollUp();
}
}
if (JoyDown()) {
if (joy_down()) {
for (i = 0; i < count; i++) {
ScrollDown();
}
}
if (JoyLeft()) {
if (joy_left()) {
for (i = 0; i < count; i++) {
ScrollLeft();
}
}
if (JoyRight()) {
if (joy_right()) {
for (i = 0; i < count; i++) {
ScrollRight();
}
@ -752,16 +752,16 @@ static void MainLoop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(1);
wait_vbeam(1);
UpdateCopperlist();
WaitVBeam(200);
wait_vbeam(200);
} else {
Delay(1);
}
@ -790,7 +790,7 @@ int main(int argc, char **argv)
if (!options.how) {
Delay(2*50);
KillSystem();
kill_system();
InitCopperlist();
}
@ -798,7 +798,7 @@ int main(int argc, char **argv)
MainLoop();
if (!options.how) {
ActivateSystem();
activate_system();
}
Cleanup(0);
return 0;

View File

@ -197,7 +197,7 @@ static void InitCopperlist(void)
ULONG plane,plane2;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
@ -279,7 +279,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
if (y + BLOCKPLANELINES <= BITMAPPLANELINES) {
// blit does not cross bitmap's bottom boundary
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -294,7 +294,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
} else {
// blit does cross bitmap's bottom boundary
// --> need to split blit = do two blit operations
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -308,7 +308,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
y = BITMAPPLANELINES - y;
custom->bltsize = y * 64 + (BLOCKWIDTH / 16);
HardWaitBlit();
hard_wait_blit();
custom->bltdpt = frontbuffer + x;
custom->bltsize = (BLOCKPLANELINES - y) * 64 + (BLOCKWIDTH / 16);
@ -562,7 +562,7 @@ static void ScrollLeft(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_RIGHT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -608,7 +608,7 @@ static void ScrollRight(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_LEFT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -700,28 +700,28 @@ static void CheckJoyScroll(void)
{
WORD i,count;
if (JoyFire()) count = 4;
if (joy_fire()) count = 4;
else count = 1;
if (JoyUp()) {
if (joy_up()) {
for (i = 0; i < count; i++) {
ScrollUp();
}
}
if (JoyDown()) {
if (joy_down()) {
for (i = 0; i < count; i++) {
ScrollDown();
}
}
if (JoyLeft()) {
if (joy_left()) {
for (i = 0; i < count; i++) {
ScrollLeft();
}
}
if (JoyRight()) {
if (joy_right()) {
for (i = 0; i < count; i++) {
ScrollRight();
}
@ -737,7 +737,7 @@ static void BlitVideoSplitLine(void)
bytes = y * BITMAPBYTESPERROW + (x / 8);
if (bytes >= 2) {
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0;
custom->bltcon1 = 0;
@ -836,16 +836,16 @@ static void MainLoop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(1);
wait_vbeam(1);
UpdateCopperlist();
WaitVBeam(200);
wait_vbeam(200);
} else {
Delay(1);
}
@ -876,14 +876,14 @@ int main(int argc, char **argv)
if (!options.how) {
Delay(2*50);
KillSystem();
kill_system();
InitCopperlist();
}
FillScreen();
MainLoop();
if (!options.how) {
ActivateSystem();
activate_system();
}
Cleanup(0);
return 0;

View File

@ -192,7 +192,7 @@ static void InitCopperlist(void)
ULONG plane,plane2;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
@ -282,7 +282,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
if (y + BLOCKPLANELINES <= BITMAPPLANELINES) {
// blit does not cross bitmap's bottom boundary
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
custom->bltafwm = 0xFFFF;
@ -296,7 +296,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
} else {
// blit does cross bitmap's bottom boundary
// --> need to split blit = do two blit operations
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -310,7 +310,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
y = BITMAPPLANELINES - y;
custom->bltsize = y * 64 + (BLOCKWIDTH / 16);
HardWaitBlit();
hard_wait_blit();
custom->bltdpt = frontbuffer + x;
custom->bltsize = (BLOCKPLANELINES - y) * 64 + (BLOCKWIDTH / 16);
@ -343,7 +343,7 @@ static void BlitExtraLine(WORD dest)
a = frontbuffer;
b = frontbuffer + BITMAPPLANELINES * BITMAPBYTESPERROW;
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0;
custom->bltcon1 = 0;
@ -597,7 +597,7 @@ static void ScrollLeft(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_RIGHT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -650,7 +650,7 @@ static void ScrollRight(void)
x = ROUND2BLOCKWIDTH(videoposx);
if (previous_xdirection == DIRECTION_LEFT) {
HardWaitBlit();
hard_wait_blit();
*savewordpointer = saveword;
}
@ -744,27 +744,27 @@ static void CheckJoyScroll(void)
{
WORD i,count;
if (JoyFire()) count = 4; else count = 1;
if (joy_fire()) count = 4; else count = 1;
if (JoyUp()) {
if (joy_up()) {
for (i = 0; i < count; i++) {
ScrollUp();
}
}
if (JoyDown()) {
if (joy_down()) {
for (i = 0; i < count; i++) {
ScrollDown();
}
}
if (JoyLeft()) {
if (joy_left()) {
for (i = 0; i < count; i++) {
ScrollLeft();
}
}
if (JoyRight()) {
if (joy_right()) {
for (i = 0; i < count; i++) {
ScrollRight();
}
@ -856,17 +856,17 @@ static void MainLoop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(1);
wait_vbeam(1);
UpdateCopperlist();
WaitVBeam(200);
wait_vbeam(200);
} else {
Delay(1);
}
@ -894,13 +894,13 @@ int main(int argc, char *argv)
if (!options.how) {
Delay(2*50);
KillSystem();
kill_system();
InitCopperlist();
}
FillScreen();
MainLoop();
if (!options.how) {
ActivateSystem();
activate_system();
}
Cleanup(0);
return 0;

View File

@ -155,7 +155,7 @@ static void InitCopperlist(void)
WORD *wp;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
@ -221,7 +221,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
if (options.how) OwnBlitter();
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -318,15 +318,15 @@ static void CheckJoyScroll(void)
{
WORD i,count;
if (JoyFire()) count = 8; else count = 1;
if (joy_fire()) count = 8; else count = 1;
if (JoyUp()) {
if (joy_up()) {
for (i = 0; i < count; i++) {
ScrollUp();
}
}
if (JoyDown()) {
if (joy_down()) {
for (i = 0; i < count; i++) {
ScrollDown();
}
@ -357,15 +357,15 @@ static void MainLoop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown()) {
while (!lmb_down()) {
if (!options.how) {
WaitVBeam(199);
WaitVBeam(200);
wait_vbeam(199);
wait_vbeam(200);
} else {
Delay(1);
}
@ -398,14 +398,14 @@ int main(int argc, char **argv)
if (!options.how) {
Delay(2*50);
KillSystem();
kill_system();
InitCopperlist();
}
FillScreen();
MainLoop();
if (!options.how) {
ActivateSystem();
activate_system();
}
Cleanup(0);
return 0;

View File

@ -162,7 +162,7 @@ static void InitCopperlist(void)
ULONG plane,plane2;
LONG l;
WaitVBL();
wait_vbl();
custom->dmacon = 0x7FFF;
custom->beamcon0 = options.ntsc ? 0 : DISPLAYPAL;
@ -250,7 +250,7 @@ static void DrawBlock(LONG x,LONG y,LONG mapx,LONG mapy)
if (options.how) OwnBlitter();
HardWaitBlit();
hard_wait_blit();
custom->bltcon0 = 0x9F0; // use A and D. Op: D = A
custom->bltcon1 = 0;
@ -338,21 +338,9 @@ static void ScrollDown(void)
static void CheckJoyScroll(void)
{
WORD i,count;
if (JoyFire()) count = 8; else count = 1;
if (JoyUp()) {
for (i = 0; i < count; i++) {
ScrollUp();
}
}
if (JoyDown()) {
for (i = 0; i < count; i++) {
ScrollDown();
}
}
WORD count = joy_fire() ? 8 : 1;
if (joy_up()) for (int i = 0; i < count; i++) ScrollUp();
if (joy_down()) for (int i = 0; i < count; i++) ScrollDown();
}
static void UpdateCopperlist(void)
@ -408,17 +396,17 @@ static void MainLoop(void)
{
if (!options.how) {
// activate copperlist
HardWaitBlit();
WaitVBL();
hard_wait_blit();
wait_vbl();
custom->copjmp2 = 0;
}
while (!LMBDown())
while (!lmb_down())
{
if (!options.how) {
WaitVBeam(1);
wait_vbeam(1);
UpdateCopperlist();
WaitVBeam(200);
wait_vbeam(200);
} else {
Delay(1);
}
@ -447,14 +435,14 @@ int main(int argc, char **argv)
if (!options.how) {
Delay(2*50);
KillSystem();
kill_system();
InitCopperlist();
}
FillScreen();
MainLoop();
if (!options.how) {
ActivateSystem();
activate_system();
}
Cleanup(0);
return 0;