A89: What is wrong with this program
[Prev][Next][Index][Thread]
A89: What is wrong with this program
it doesn't swap pages right and when you exit, it errors out, what is wrong?
#define SAVE_SCREEN
#include <nostub.h>
#include <all.h>
int _ti89;
static int map1[32][40]=
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
ICON chari=
{
{
0x3C0,
0x420,
0xA50,
0x420,
0x240,
0x180,
0x180,
0x3FFC,
0x43C2,
0x43C2,
0x3C0,
0x420,
0x810,
0x1008,
0x1008,
0x1008
}
};
ICON grou[2]=
{
{
0x8888,
0x1111,
0x2222,
0x4444,
0x8888,
0x1111,
0x2222,
0x4444,
0x8888,
0x1111,
0x2222,
0x4444,
0x8888,
0x1111,
0x2222,
0x4444
},
{
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000,
0x0000
}
};
ICON* picon=NULL;
int X = 32;
int Y = 32;
int i = 0;
int key = 0;
int XX = 0;
int YY = 0;
int pageud = 0;
int pagelr = 1;
LCD_BUFFER bg={0};
void drawbg()
{
ICON* gicon;
for(XX=0+(pageud*6);XX<10+(pageud*6);XX+=1)
{
for(YY=0+(pagelr*10);YY<6+(pagelr*10);YY+=1)
{
gicon = &grou[map1[YY][XX]-1]; // -1 because arrays in C are zero based
DrawIcon(XX*16,YY*16,gicon,A_NORMAL);
}
}
LCD_save(bg);
return;
}
void _main(void)
{
ClrScr();
drawbg();
picon = 0;
picon = &chari;
DrawIcon(X,Y,picon,A_NORMAL);
while(key!=264)
{
if(kbhit())
{
key=tolower(ngetchx());
if(key==337)
{
LCD_restore(bg);
Y-=16;
DrawIcon(X,Y,picon,A_NORMAL);
}
if(key==340)
{
LCD_restore(bg);
Y+=16;
DrawIcon(X,Y,picon,A_NORMAL);
}
if(key==338)
{
LCD_restore(bg);
X-=16;
DrawIcon(X,Y,picon,A_NORMAL);
}
if(key==344)
{
LCD_restore(bg);
X+=16;
DrawIcon(X,Y,picon,A_NORMAL);
}
//Stops working
if(X>=160)
{
pagelr+=1;
drawbg();
X=0;
DrawIcon(0,Y,picon,A_NORMAL);
}
if(X<=0)
{
pagelr-=1;
drawbg();
X=160;
DrawIcon(160,Y,picon,A_NORMAL);
}
if(Y>=96)
{
pageud+=1;
drawbg();
Y=0;
DrawIcon(X,0,picon,A_NORMAL);
}
if(Y<=0)
{
pageud-=1;
drawbg();
Y=96;
DrawIcon(X,96,picon,A_NORMAL);
}
}
}
return 0;
}