- Screen only shows on button press and flickers
- 15 Feb 2013 10:03:26 pm
- Last edited by ProgrammerNerd on 15 Feb 2013 10:40:25 pm; edited 1 time in total
I recently started coding for the casio prizm for some reason I encounter an odd error even though the code always updates the screen regardless of if a button is pressed for some reason there is only display on button press otherwise the screen is white here is my entire code
Code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <color.h>
#include <keyboard.hpp>
//#include <stdint.h>
#include "ang_tab.h"
#define LCD_WIDTH_PX 384
#define LCD_HEIGHT_PX 216
unsigned short VX=24576;
unsigned short VY=24576;
unsigned short VZ=0;
#define SRX 192 //screen half x
#define SRY 108 //screen half y
inline short abs_short(short val)
{
if (val < 0)
val*=-1;
return val;
}
inline void set_pixel(unsigned short x,unsigned short y)
{
unsigned short* p = (unsigned short*)0xA8000000;
p += (LCD_WIDTH_PX*y + x);
*p=0;
}
void fill_scr_col(unsigned short col)
{
unsigned short* p = (unsigned short*)0xA8000000;
unsigned int x;
for (x=0;x<82944;x++)
*p++=col;
}
void line(short x0,short y0,short x1,short y1)
{
short dx=abs_short(x1-x0);
short dy=abs_short(y1-y0);
char sx,sy;
if (x0 < x1)
sx=1;
else
sx=-1;
if (y0 < y1)
sy=1;
else
sy=-1;
short err=dx-dy;
while (1)
{
set_pixel(x0,y0);
if (x0 == x1 && y0 == y1)
break;
short e2=2*err;
if (e2 > -dy)
{
err-=dy;
x0+=sx;
}
if (e2 < dx)
{
err+=dx;
y0+=sy;
}
}
}
void render_rect(unsigned int x0,unsigned int y0,unsigned int baseSize,unsigned short z,short ang)
{
unsigned int points[8];
unsigned char a;
baseSize<<=14;
x0<<=14;
y0<<=14;
points[0]=x0;
points[1]=y0;
points[2]=x0+baseSize;
points[3]=y0;
points[4]=x0;
points[5]=y0+baseSize;
points[6]=x0+baseSize;
points[7]=y0+baseSize;
//unsigned short sx[2],sy[2];
for (a=0;a<8;a+=2)
{
points[a]=((points[a] - VX) / (z - VZ)) + SRX;
points[a+1]=((points[a+1] - VY) / (z - VZ)) + SRY;
}
line(points[0],points[1],points[2],points[3]);//Top line
line(points[0],points[1],points[4],points[5]);//Left line
line(points[4],points[5],points[6],points[7]);//Bottom line
line(points[2],points[3],points[6],points[7]);//Right line
//x and y are top left cordance in pixels
//baseSize is an integer that specifies how large the rectange is if z=1
//z is fixed point math 2.14
//ang is also fixed point math it is 9.6 plus sign
}
void main(void)
{
int key;
Bdisp_EnableColor(1);
PrintXY(3,1," Cube Field 2!",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
PrintXY(3,4," Press EXE",TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
PrintXY(3,5," To use game!",TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
Bdisp_PutDisp_DD();
while (1)
{
GetKey(&key);
if (key == KEY_CTRL_EXE)
break;
}
//start by clear screen
char buf[10];
buf[0] = ' ';
buf[1] = ' ';
unsigned char editMode;
char add=0;
unsigned short x=16,y=16,z=16384,baseSize=24,ang;
unsigned short *var;
while (key == KEY_CTRL_EXE)
GetKey(&key);
while (1)
{
add=0;
GetKey(&key);
if (key == KEY_CTRL_EXE)
break;
else if (key == KEY_CTRL_UP)
add=1;
else if (key == KEY_CTRL_DOWN)
add=-1;
else if (key == KEY_CTRL_LEFT)
editMode-=1;
else if (key == KEY_CTRL_RIGHT)
editMode+=1;
if (editMode > 7)
editMode=7;
switch (editMode)
{
case 0:
PrintXY(1,1," X",0,TEXT_COLOR_BLUE);
var=&x;
break;
case 1:
PrintXY(1,1," Y",0,TEXT_COLOR_BLUE);
var=&y;
break;
case 2:
PrintXY(1,1," Z",0,TEXT_COLOR_BLUE);
var=&z;
break;
case 3:
PrintXY(1,1," baseSize",0,TEXT_COLOR_BLUE);
var=&baseSize;
break;
case 4:
PrintXY(1,1," ang",0,TEXT_COLOR_BLUE);
var=∠
break;
case 5:
PrintXY(1,1," VX",0,TEXT_COLOR_BLUE);
var=&VX;
break;
case 6:
PrintXY(1,1," VY",0,TEXT_COLOR_BLUE);
var=&VY;
break;
case 7:
PrintXY(1,1," VZ",0,TEXT_COLOR_BLUE);
var=&VZ;
break;
}
*var+=add;
itoa(*var, &buf[2]);
PrintXY(1,2,buf,0,TEXT_COLOR_RED);
render_rect(x,y,baseSize,z,ang);
Bdisp_PutDisp_DD();
Bdisp_Fill_VRAM(0xFFFF,1);
}
return;
}