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:

#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=&ang;
         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;

}
Here's my attempt to make your post a bit more readable with some grammar:

Quote:
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 if a button is pressed. For some reason the display shows on button press otherwise the screen is white; here is my entire code.


I'll have to look at your code a bit more, but are you accidentally clearing the screen after each button press?
comicIDIOT wrote:
Here's my attempt to make your post a bit more readable with some grammar:

I'll have to look at your code a bit more, but are you accidentally clearing the screen after each button press?

Sorry about my grammar it is bad but anyways here is all code related to buttons and there is no screen clear.

Code:

     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;
I'm pretty sure the getKey call does a copy-to-LCD, so you're basically doing:
Code:
      Bdisp_PutDisp_DD();
      Bdisp_Fill_VRAM(0xFFFF,1);
      Bdisp_PutDisp_DD();
Also, you should Introduce Yourself when you get a chance.
It's okay; now I'm no expert at programming at all but at the bottom you have this:


Code:
*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);


After you PrintXY you Fill the VRAM with 0xFFFF (which, is white if I recall correctly). What happens if you remove bdisp_Fill_VRAM?
GetKey must have caused a redraw I fixed my code now and it works well.
GetKey calls BDisp_PutDisp_DD() by itself, you don't need to call it before GetKey() (even because if you do, you're wasting processing time by drawing the screen twice).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement