예제 #1
0
파일: gradius.c 프로젝트: bcherry/bcherry
void Draw_Map(int map_array[12][20], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) {
	//int x = map_x_location;
	int x = 0;
	int y = 0;
	

	SetPlane (LIGHT_PLANE);
	ClrScr ();

	SetPlane (DARK_PLANE);
	ClrScr ();
	
	drawRType(pos);
	if (laser) drawLaser(laserPos);
	if (missile) drawMissile(missilePos);
	
	// Well.. the map_x_location will keep track of where we are on the X-plane on the map array
	// This way we mask out the stuff in the array that we use.. So we will only read 30x8 elements of the
	// array (instead of 60x8 which it is at the moment.. ).. This might sound unuseful, and it sort of is
	// with a small array as this one.. but i'm guessing you will create worlds that are much much bigger..
	// so.. to gain more speed.. we mask it out ;)

	/*while (x<20) {// Again, we can't view more than 30 blocks.. so.. don't calculate more than 30 blocks 
		if ((map_array[y][x]==7)) { // If the array at this location is equal to 1, place a ground piece
			Sprite8(x*8, y*8, 8, ground_down, GetPlane (DARK_PLANE), SPRT_XOR);
			Sprite8(x*8, y*8, 8, ground_down, GetPlane (LIGHT_PLANE), SPRT_XOR);
		}
		if ((map_array[y][x]==8)) { // .. and if it's 2, place block1
			Sprite8(x*8, y*8, 8, ground_flat, GetPlane (DARK_PLANE), SPRT_XOR);
			Sprite8(x*8, y*8, 8, ground_flat, GetPlane (LIGHT_PLANE), SPRT_XOR);
		}
		if (map_array[y][x]==9) {
			Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
			Sprite8(x*8, y+8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR);
		}
		y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT
				// I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT
		 	 // is the best way to draw the world..
		if (y>11) { // We've reached the limit.. restore the Y value, and move 1 block row forward..
			y=0;
			x++;
		} 
	}*/
	
	for (x = 0; x <= 19; x++) {
		for (y = 0; y <= 11; y++) {
			if (map_array[y][x] == 7) {
				Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(DARK_PLANE), SPRT_XOR);
				Sprite8(x*8, y*8, 8, ground_down, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
			}	else if (map_array[y][x] == 8) {
				Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(DARK_PLANE), SPRT_XOR);
				Sprite8(x*8, y*8, 8, ground_flat, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
			} else if (map_array[y][x] == 9) {
				Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(DARK_PLANE), SPRT_XOR);
				Sprite8(x*8, y*8, 8, ground_up, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
			}
		}
	}	
}
예제 #2
0
파일: demo4.c 프로젝트: debrouxl/ExtGraph
void _main(void) {
    LCD_BUFFER backbuffer;
    unsigned char buffer[100*5*4];
    unsigned short i,j;

    LCD_save(backbuffer);

    ST_helpMsg("Sprite8Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<20;i++) {
            Sprite8Get_R(j+(i<<3),0,100,backbuffer,((unsigned char*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<20;i++) {
            Sprite8_OR_R(i<<3,0,100,((unsigned char*)buffer)+100*i,LCD_MEM);
        }
    }

    ST_helpMsg("Sprite16Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<10;i++) {
            Sprite16Get_R(j+(i<<4),0,100,backbuffer,((unsigned short*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<10;i++) {
            Sprite16_OR_R(i<<4,0,100,((unsigned short*)buffer)+100*i,LCD_MEM);
        }
    }

    ST_helpMsg("Sprite32Get() Demo - Press Key");
    ngetchx();

    for (j=0;j<64;j++) {
        for (i=0;i<5;i++) {
            Sprite32Get_R(j+(i<<5),0,100,backbuffer,((unsigned long*)buffer)+100*i);
        }
        ClrScr();
        for (i=0;i<5;i++) {
            Sprite32_OR_R(i<<5,0,100,((unsigned long*)buffer)+100*i,LCD_MEM);
        }
    }

    LCD_restore(backbuffer);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
예제 #3
0
int main()
{
    BOOL	bSuccess;
    int     i;
    char	szBuf[30];

    InitConsoleIO();        // must call this at startup

    ClrScr();              // clear the screen

    for ( i=0; i < 20; i += 2 ) {
		// QUESTION H what does the next line do?
        GotoXY(i,i);   
		// make a message and put it out
        sprintf( szBuf, "%d,%d", i, 2*i );
        bSuccess = PutText(szBuf);  // test PutText.
        if (!bSuccess) 
            printf("WriteConsoleOutputCharacter error\n"); 
    }

	// make some cool messages in different colours
    TextColour( BC_RED );
    TextBackground( BC_GREEN );
    Cprintf("Cool %d ", i++);

    TextColour( BC_BLACK );
    TextBackground( BC_LIGHTGRAY );
    Cprintf("colours %d ", i++);

    TextColour( BC_LIGHTMAGENTA );
    TextBackground( BC_BLUE );
    Cprintf(" Eh %d?", i);

    return(1);
}
예제 #4
0
파일: gfx.c 프로젝트: bcherry/bcherry
// drawLevel - draws one of the maze levels
void drawLevel(short int level) {
	short int yLoop,xLoop;
	long int area, mask;

	// clear the screen first
	ClrScr();

	for (yLoop = 0; yLoop < YTILES; yLoop++) {
		area = levels[level][yLoop];
		mask = 0x100000;

		// start the x loop
		for (xLoop = 0; xLoop < XTILES; xLoop++) {
			// shift the mask index
			mask >>= 1;

			// if the level data says to put a block here, then do it
			if (area & mask) {
				drawBlock(xLoop * WIDTH, yLoop * HEIGHT, block, SPRT_OR);
			}
		}
	}

	// share the bottom line of the maze
	clearDisplayLine();
}
예제 #5
0
int CMyView::OnCreate(LPCREATESTRUCT lpcs)
{
   /*
   if (m_font.m_hObject == NULL)
   {
      m_font.CreatePointFont(120, _T("Amstrad CPC"));
      // strange: function always return ok, also if Amstrad font not installed
   }
   */
   m_font.CreatePointFont(100, _T("Courier New"));

   if (CxEditView::OnCreate(lpcs) == -1)
   {
		return -1;
   }

   CMyDocument* pDoc = GetDocument();
   CPCHANDLE handle = pDoc->m_handle = (*PUB_cpc_editview_api.create)(NULL, this);
   if (handle == NULL)
   {
      return -1;
   }
   (*handle->api->set_mode)(handle, 1);
   ClrScr();
   (*handle->api->set_cursor_pos)(handle, 1, 1);
	return 0;
}
예제 #6
0
파일: demo27.c 프로젝트: debrouxl/ExtGraph
/*===========================================================================*/
void _main(void) {
#define bsize (100*20+4) // Size of a bitmap for a 160x100 screen.
    int i;
    LCD_BUFFER lcd;
    static const SCR_RECT theScreen = {{0,0,159,99}};
    unsigned char sscreen[bsize];
    unsigned char sscreen2[bsize];

    LCD_save(lcd);

    BitmapGet(&theScreen,sscreen);
    memset(sscreen2,0,bsize);
    ((BITMAP*)sscreen2)->NumRows=((BITMAP*)sscreen)->NumRows;
    ((BITMAP*)sscreen2)->NumCols=((BITMAP*)sscreen)->NumCols;
    GKeyFlush();
    for (i = 0; (i <= 360) && (!kbhit()); i++)
    {
        RotateSpriteX8_R(((BITMAP*)sscreen)->Data,((BITMAP*)sscreen2)->Data,160,100,80,50,i);
        ClrScr();
        FastCopyScreen160to240_R(100,((BITMAP*)sscreen2)->Data,LCD_MEM);
    }

    LCD_restore(lcd);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
#undef bsize
}
예제 #7
0
파일: blaster.c 프로젝트: bcherry/bcherry
// function that draws the screen
void Draw_Map(int map_x_location, char map_array[12][MAP_SIZE], POSITION pos, POSITION laserPos, int laser, POSITION missilePos, int missile) {
    int x = map_x_location;
    int y = 0;

    // clear both planes
    SetPlane (LIGHT_PLANE);
    ClrScr();
    SetPlane (DARK_PLANE);
    ClrScr();

    // draw ship, and missiles and cannons if they exist
    drawShip(pos, map_x_location);
    if (laser) drawLaser(laserPos, map_x_location);
    if (missile == 1) drawMissile(missilePos, map_x_location);
    if (missile == -1) drawUpMissile(missilePos, map_x_location);

    // Well.. the map_x_location will keep track of where we are on the X-plane on the map array
    // This way we mask out the stuff in the array that we use.. So we will only read 20x12 elements of the
    // array (instead of MAP_SIZEx12 which it is at the moment.. )
    while (x < (map_x_location + 20)) {// Again, we can't view more than 20 blocks.. so.. don't calculate more than 20 blocks
        if ((map_array[y][x] == 1)) { // If the array at this location is equal to 1, place a broken piece
            Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_dark, GetPlane (DARK_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, broken2_light, GetPlane (LIGHT_PLANE), SPRT_XOR);
        }
        if ((map_array[y][x] == 2)) { // If the array at this location is equal to 1, place a broken piece
            Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_dark, GetPlane (DARK_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, broken1_light, GetPlane (LIGHT_PLANE), SPRT_XOR);
        }
        if ((map_array[y][x] == 3)) { // .. and if it's 2, place block1
            Sprite8((x - map_x_location) * 8, y * 8, 8, block1_dark, GetPlane (DARK_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, block1_light, GetPlane (LIGHT_PLANE), SPRT_XOR);
        }
        if ((map_array[y][x] == 4)) { // a 3 means the indestructible block
            Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_light, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(LIGHT_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_mid, GrayGetPlane(DARK_PLANE), SPRT_XOR);
            Sprite8((x - map_x_location) * 8, y * 8, 8, solid1_dark, GrayGetPlane(DARK_PLANE), SPRT_XOR);
        }
        y++; // Now.. we're increasing the Y value.. note that i'm drawing the world from LEFT to RIGHT
        // I've seen people who draw their world TOP to DOWN or otherwise, but i found LEFT to RIGHT
        // is the best way to draw the world..
        if (y > 11) { // We've reached the limit.. restore the Y value, and move 1 block row forward..
            y = 0;
            x++;
        }
    }
}
예제 #8
0
파일: flappy.c 프로젝트: nucular/flappy
// clean up and exit gracefully
void deinit()
{
	if (buffermem)
		free(buffermem);
	// turn this off or we'd crash the calc
	GrayOff();
	// for good measure
	ClrScr();
}
예제 #9
0
파일: HR.C 프로젝트: hex-ci/Hyper-Reader
void HyperReader_init(void)
{CloseCur();
 ClrScr();
 puts("\nWelcome to the HyperReader 2000");
 puts("=========================================");
 read_ini();
 alloc_mem();
 read_HZK();
 graph_init();
 image();
 CloseCur();
 read_file();
 read_LabelFile();
}
예제 #10
0
LRESULT CMyView::OnCharFromCPC(LPARAM p,WPARAM ch) // WM_USER_CHAR
{
   CxEdit& ctrl = GetEditCtrl();

   CString str;
   if (ch) str = (TCHAR)ch; else str = (LPCTSTR)p;

   CPoint position;
   GetPosition(&position.x, &position.y);

	if(0)TRACE(_T("%2d,%2d: %s\n"), position.x, position.y, str);

   const CSize size = GetSize();
   const int pos = ctrl.LineIndex(position.y);

   switch (str[0])
   {
      case 8:
         //SetPosition(position.x-1, position.y);
         break;
      case 12:
         ClrScr();
         break;
      case 10:
         if (position.y == size.cy-1)
         {
            ctrl.DeleteLine(0);
            ctrl.AddString(CString(' ', size.cx) + _T("\r\n"));
         }
         else
         {
            SetPosition(position.x, position.y + 1);
         }
         break;
      case 13:
         SetPosition(0, position.y);
         break;
      default:
         ctrl.SetSel(pos + position.x, pos + position.x + 1, TRUE);
         ctrl.ReplaceSel(str);
         position.x++;
         if (position.x == size.cx)
         {
            position.y = (position.y + 1) % ctrl.GetLineCount(), position.x = 0;
            SetPosition(position.x, position.y);
         }
         break;
   }
   return 0;
}
예제 #11
0
파일: pins.c 프로젝트: bcherry/bcherry
// Main Function
void _main(void)
{
	// declare the sprite positions
	int x1 = 20, y1 = 20, direction1 = RIGHT;
	int x2 = 40, y2 = 40, direction2 = LEFT;
	int x3 = 60, y3 = 60, direction3 = RIGHT;
	int x4 = 80, y4 = 80, direction4 = LEFT;
	int x5 = 50, y5 = 50, direction5 = RIGHT;
	
	// keycode variable
	int key = 0;
	
	// Define the pins
	unsigned char pinsprt[] = {0x18,0x3C,0x18,0x38,0x7C,0x7C,0x7C,0x38};
	unsigned long int balsprt[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
																 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,};

	// clear the screen
	ClrScr();
	
	// Annotate the display
	DrawStr(0, 0, "These Are Bowling Pins!", A_NORMAL);
	
	// draw the sprites
	Sprite8(x1, y1, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x2, y2, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x3, y3, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite8(x4, y4, SPRITE_HEIGHT, pinsprt, LCD_MEM, SPRT_XOR);
	Sprite32(x5, y5, 32, balsprt, LCD_MEM, SPRT_XOR);
	
	// wait for a key before exit
	ngetchx();
}
예제 #12
0
void _main(void)
{
  char str[30];  
  
  ClrScr ();
  FontSetSys (F_8x10);
  
  sprintf(str, "RomDumper v%s", VERSION);
  DrawStr(0, 0, str, A_NORMAL);
  
  sprintf(str, "Type: HW%i", HW_VERSION);
  DrawStr(0, 20, str, A_NORMAL);
  
  sprintf(str, "ROM base: 0x%lx", (uint32_t)ROM_base);
  DrawStr(0, 40, str, A_NORMAL);  
  
  sprintf(str, "by The TiLP Team");
  DrawStr(0, 80, str, A_NORMAL);  
  
  Dump();
  
  return;
}
예제 #13
0
파일: flappy.c 프로젝트: nucular/flappy
// allocate and set up stuff
void init()
{
	// start the random number generator
	randomize();

	// allocate our graphic buffers
	buffermem = malloc(LCD_WIDTH * LCD_HEIGHT * 2);
	// not enough RAM
	if (!buffermem)
		error(LC_MEMORY_ERROR_TEXT);
	lightbuffer = buffermem;
	darkbuffer = buffermem + LCD_WIDTH * LCD_HEIGHT;

	// quit if we can't switch to grayscale
	if (!GrayOn())
		error(LC_GRAYSCALE_ERROR_TEXT);

	// clear the screen
	ClrScr();

	// get the grayscale plane pointers
	lightplane = GrayGetPlane(LIGHT_PLANE);
	darkplane = GrayGetPlane(DARK_PLANE);
}
예제 #14
0
파일: demo33.c 프로젝트: debrouxl/ExtGraph
/*===========================================================================*/
void _main(void) {
    short         i,j;
    unsigned long measure_val;
    char          tmpstr[50] = "Measuring, please wait ...";
    static const short modes[4] = {COLOR_LIGHTGRAY,COLOR_DARKGRAY,COLOR_BLACK,COLOR_WHITE};
    unsigned short clippedcoord[4];
    LCD_BUFFER    screen;

    LCD_save(screen);

    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER,INITIAL_TIMER_VALUE);

    if (!GrayOn()) goto end;

    //---------------------------------------------------------------------
    // built-in OS line drawing routine ...
    //---------------------------------------------------------------------
    GrayClearScreen_R();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        short used_color = modes[j];
        for (i=-40;  i<280;i++) GrayDrawClipLine(120,64,i,-40,used_color);
        for (i=-40;  i<168;i++) GrayDrawClipLine(120,64,280,i,used_color);
        for (i=280;i>=-40; i--) GrayDrawClipLine(120,64,i,168,used_color);
        for (i=168;i>=-40; i--) GrayDrawClipLine(120,64,-40,i,used_color);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED);
    GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6);

    if (ngetchx() == KEY_ESC) goto end;

    
    //---------------------------------------------------------------------
    // new line drawing routine ...
    //---------------------------------------------------------------------
    GrayClearScreen_R();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        short used_color = modes[j];
        for (i=-40;  i<280;i++) GrayClipDrawLine_R(120,64,i,-40,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=-40;  i<280;i++) GrayClipDrawLine_R(120,64,280,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=280;i>=-40; i--) GrayClipDrawLine_R(120,64,i,168,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
        for (i=168;i>=-40; i--) GrayClipDrawLine_R(120,64,-40,i,clippedcoord,used_color,GrayGetPlane(LIGHT_PLANE),GrayGetPlane(DARK_PLANE),GrayFastDrawLine2B_R);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect(0,0,239,7,COLOR_WHITE,RECT_FILLED);
    GrayDrawStrExt(0,0,tmpstr,A_NORMAL | A_CENTERED | A_SHADOWED,F_4x6);

    if (ngetchx() == KEY_ESC) goto end;


    GrayOff();
    ClrScr();
    //---------------------------------------------------------------------
    // built-in OS line drawing routine ...
    //---------------------------------------------------------------------
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        WIN_RECT rect = {120, 64, 0, -40};
        for (i=-40;  i<280;i++) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=-40;  i<168;i++) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=280;i>=-40; i--) {rect.x1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
        for (i=168;i>=-40; i--) {rect.y1 = i; DrawClipLine(&rect,&(SCR_RECT){{0, 0, 239, 127}},A_XOR); }
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"OS routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM);
    GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM);

    if (ngetchx() == KEY_ESC) goto end;

    //---------------------------------------------------------------------
    // new line drawing routine ...
    //---------------------------------------------------------------------
    ClrScr();
    OSTimerRestart(USER_TIMER);
    for (j=0;j<4;j++) {
        for (i=-40;  i<280;i++) ClipDrawLine_R(120,64,i,-40,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=-40;  i<280;i++) ClipDrawLine_R(120,64,280,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=280;i>=-40; i--) ClipDrawLine_R(120,64,i,168,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
        for (i=168;i>=-40; i--) ClipDrawLine_R(120,64,-40,i,clippedcoord,A_XOR,LCD_MEM,FastDrawLine_R);
    }
    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"Own routine took %lu ticks",INITIAL_TIMER_VALUE-measure_val);
    GrayDrawRect2B(0,0,239,7,COLOR_WHITE,RECT_FILLED,LCD_MEM,LCD_MEM);
    GrayDrawStrExt2B(0,0,tmpstr,A_NORMAL | A_CENTERED,F_4x6,LCD_MEM,LCD_MEM);

    ngetchx();

    end:
    OSFreeTimer(USER_TIMER);
    GrayOff();
    LCD_restore(screen);
    GKeyFlush();
    ST_helpMsg(EXTGRAPH_VERSION_PWDSTR);
}
예제 #15
0
int _k_main(struct multiboot_info *bootinfo)
{
	int i;
	uint32_t memSize;
	struct memory_region*  region;
	uint32_t *p,*p2;

	/*Initialize hardware drivers*/
	hw_initialize();

	//! install our exception handlers
	setvect (0,  divide_by_zero_fault);
	setvect (1,  single_step_trap);
	setvect (2,  nmi_trap);
	setvect (3,  breakpoint_trap);
	setvect (4,  overflow_trap);
	setvect (5,  bounds_check_fault);
	setvect (6,  invalid_opcode_fault);
	setvect (7,  no_device_fault);
	setvect (8,  double_fault_abort);
	setvect (10, invalid_tss_fault);
	setvect (11, no_segment_fault);
	setvect (12, stack_fault);
	setvect (13, general_protection_fault);
	setvect (14, page_fault);
	setvect (16, fpu_fault);
	setvect (17, alignment_check_fault);
	setvect (18, machine_check_abort);
	setvect (19, simd_fpu_fault);

	ClrScr (0x13);
	GotoXY (0,0);
	SetColor (0x12);

	Puts ("\n		     zygote OS v0.01\n");
	SetColor (0x17);
/*	Puts ("Enabled A20!\n");
	Puts ("Initialized GDT and IDT!\n");
	Puts ("Installed PIC, PIT, and exception handlers!\n");
	Printf ("Cpu vender: %s \n", get_cpu_vender ());*/

	//! get memory size in KB
	memSize = 1024 + bootinfo->m_memoryLo + bootinfo->m_memoryHi*64;
	
	//! initialize the physical memory manager
	//! we place the memory bit map used by the PMM at the end of the kernel in memory
	pmmngr_init (memSize, 0x100000);

	Printf("pmm initialized with %i KB physical memory; memLo: %i memHi: %i\n",
	memSize,bootinfo->m_memoryLo,bootinfo->m_memoryHi);

	SetColor (0x19);
	Printf ("Physical Memory Map:\n");

	region = (struct memory_region*)0x1000;

	for (i=0; i<15; ++i) {

		//! sanity check; if type is > 4 mark it reserved
		if (region[i].type>4)
			region[i].type=1;

		//! if start address is 0, there is no more entries, break out
		if (i>0 && region[i].startLo==0)
			break;

		//! display entry
		Printf ("region %i: start: 0x%x%x length (bytes): 0x%x%x type: %i (%s)\n", i, 
			region[i].startHi, region[i].startLo,
			region[i].sizeHi,region[i].sizeLo,
			region[i].type, strMemoryTypes[region[i].type-1]);

		//! if region is avilable memory, initialize the region for use
		if (region[i].type==1)
			pmmngr_init_region (region[i].startLo, region[i].sizeLo);
	}

	SetColor (0x17);

	Printf ("\npmm regions initialized: %i allocation blocks; used or reserved blocks: %i\nfree blocks: %i\n",
		pmmngr_get_block_count (),  pmmngr_get_use_block_count (), pmmngr_get_free_block_count () );

	//! allocating and deallocating memory examples...

	SetColor (0x12);

	p = (uint32_t*)pmmngr_alloc_block ();
	Printf ("\np allocated at 0x%x", p);

	p2 = (uint32_t*)pmmngr_alloc_blocks (2);
	Printf ("\nallocated 2 blocks for p2 at 0x%x", p2);

	pmmngr_free_block (p);
	p = (uint32_t*)pmmngr_alloc_block ();
	Printf ("\nUnallocated p to free block 1. p is reallocated to 0x%x", p);

	pmmngr_free_block (p);
	pmmngr_free_blocks (p2, 2);

	//To test divide by zero exception
	//i = 10/0;
	Puts ("\nHitting any key will fire the default handlers \n");
	for(;;) {
	}
	
};
void VioInit( )
{
 APIRET      rc;
 UCHAR     **cpp;
 UINT        vlen;
 UINT        row;
 VIOMODEINFO md;

 memset(&md, 0, sizeof(md) );
 md.cb = sizeof(md);

 if( VioGetMode(&md, 0) )
 {
  printf( "Vio error" );
  exit(0);
 }

 VideoRows = md.row;
 VideoCols = md.col;
 MaxPer    = VideoRows - 2 ;            /* max # of lines of Code            */
 MaxData   = VideoRows * 2 / 3;         /* max # of rows for data window     */
 MinPer    = MaxPer - MaxData;          /* min # of lines of Code            */
 ProRow    = VideoRows - 3;             /* screen row for prompt (0..N)      */
 MenuRow   = VideoRows - 3;             /* screen row for menu bar (0..N)    */
 FnameRow  = VideoRows - 2;             /* screen row for file name (0..N)   */
 HelpRow   = VideoRows - 1;             /* screen row for menu help (0..N)   */
 MsgRow    = VideoRows - 1;             /* screen row for messages (0..N)    */
 LinesPer  = MaxPer - TopLine;          /* current # of lines per screen     */
                                        /* for source                        */
 VideoMap  = vaColor;

 if( md.color == 1 )
  VideoMap = vaMono;


    rc = VioGetBuf((PULONG)&VideoPtr, (PUSHORT)&vlen, 0);
    if( rc != 0 ){
        printf( "VioGetBuf() returned %d\n", rc );
        panic(OOquit);
    }
    if( ! HiddenCursor.attr ){
        rc = VioGetCurType(&NormalCursor,0);
        if( rc != 0 ){
            printf( "VioGetCurType() returned %d\n", rc );
            panic(OOquit);  }

        /*********************************************************************/
        /* If the cursor is in insert mode when we enter here then convert   */
        /* the parms of cursorinfo into a normal mode cursor.                */
        /*********************************************************************/
        if ((NormalCursor.cEnd - NormalCursor.yStart) > 2)
          NormalCursor.yStart = NormalCursor.cEnd -
                           ((NormalCursor.cEnd - NormalCursor.yStart - 1) / 4);
        NormalCursor.yStart -= 1;                                       /*112*/
        memcpy( &InsertCursor, &NormalCursor, sizeof(InsertCursor) );   /*100*/
        InsertCursor.yStart = 0;
        memcpy( &HiddenCursor, &NormalCursor, sizeof(HiddenCursor) );   /*100*/
        HiddenCursor.attr = -1;
    }

    /*************************************************************************/
    /* - Allocate memory for screen bounds                                400*/
    /* - set the bounds to the video cols                                 400*/
    /*************************************************************************/
    BoundPtr = Talloc(VideoRows);                                   /*521 518*/
    if (BoundPtr)                                                       /*518*/
       memset(BoundPtr,VideoCols,VideoRows);                            /*518*/
    else                                                                /*518*/
    {                                                                   /*518*/
        printf( "malloc failed\n");                                     /*518*/
        panic(OOquit);                                                  /*518*/
    }                                                                   /*518*/

    VioStartOffSet = 1;
    TopLine = 1;
    MenuRow  = 0;
    LinesPer = MaxPer - TopLine;
    InitDataWinCsr();
    AccessMouse();

    HideCursor();
    ClrScr( 0, VideoRows-1, vaBptOk );
    cpp = banner;
    for( row = BANNER_ROW; *cpp; cpp++,row++ )
    {
     putrc( row, (VideoCols-strlen(*cpp)) / 2, *cpp );
    }
}
예제 #17
0
파일: demo3.c 프로젝트: debrouxl/ExtGraph
/*===========================================================================*/
static inline short Test32(void) {
    unsigned long  measure_val;
    char           tmpstr[100];
    short          x,y;
    long           count;

    //-------------------------------------------------------------------------
    // original sprite functions
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_AND);
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_OR);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

#if __TIGCCLIB_VERSION__ >= 272
    //-------------------------------------------------------------------------
    // original sprite functions with RPLC (GCC4TI 0.96 Beta 10+)
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_RPLC);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB RPLC: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;
#endif

    //-------------------------------------------------------------------------
    // modified sprite functions using separate and/or
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_AND_R(x,y,8,spritedata32,LCD_MEM);
            Sprite32_OR_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // modified sprite functions using just one call
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_MASK_R(x,y,8,spritedata32,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph MASK: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_BLIT_R(x,y,8,spritedata32,0x00000000,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph BLIT: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_RPLC_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph RPLC: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // original sprite functions
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32(x,y,8,spritedata32,LCD_MEM,SPRT_XOR);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"TIGCCLIB AND+OR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    if (ngetchx() == KEY_ESC) return KEY_ESC;

    //-------------------------------------------------------------------------
    // modified sprite functions using just one call
    //-------------------------------------------------------------------------
    count = 0;
    ClrScr();

    OSTimerRestart(USER_TIMER);
    for (y=0;y<100-16;y++) {
        for (x=0;x<160-32;x++) {
            count++;
            Sprite32_XOR_R(x,y,8,spritedata32,LCD_MEM);
        }
    }

    measure_val = OSTimerCurVal(USER_TIMER);
    sprintf(tmpstr,"ExtGraph XOR: %lu ticks for %ld sprites",INITIAL_TIMER_VALUE-measure_val,count);
    ST_helpMsg(tmpstr);
    return ngetchx();
}
예제 #18
0
파일: nibbles.c 프로젝트: bcherry/bcherry
// doIntro - display the game intro and wait for menu selections
// 	returns FALSE if user selects exit, TRUE otherwise
short int doIntro(short int *gamespeed, short int *gamedifficulty) {
	short int selector = MENUSTART, done = FALSE, key, options = FALSE, selection = 0;
	short int speed = *gamespeed, difficulty = *gamedifficulty;

	// clear the screen
	ClrScr();

	// draw the intro screen
	drawBorder();
	drawLogo();
	drawMenu();
	drawCopyright();
	drawSelector(selector);

	while (!done) {
		// wait for keypress
		while ((key = getKey()) == 0);

		if (key == KUP) {
			// move up the menu
			drawSelector(selector);

			if (selector == MENUSTART) {
				selector = MENUEND;
			} else {
				selector -= MENUSTEP;
			}

			drawSelector(selector);
		} else if (key == KDOWN) {
			// move down the menu
			drawSelector(selector);

			if (selector == MENUEND) {
				selector = MENUSTART;
			} else {
				selector += MENUSTEP;
			}

			drawSelector(selector);
		} else if (key == KLEFT) {
			if (options) {
				// if we are in the options menu
				selection = (selector - MENUSTART) / MENUSTEP;

				// set the speed option
				if (selection == START) {
					// same as speed option -- option 1 == SPEED
					drawSpeedOption(speed);

					if (speed == VERYSLOW) {
						speed = VERYFAST;
					} else {
						speed--;
					}

					drawSpeedOption(speed);

				// set the difficulty option
				} else if (selection == OPTIONS) {
					// same as difficulty option -- option 2 == DIFFICULTY
					drawDifficultyOption(difficulty);

					if (difficulty == EASY) {
						difficulty = HARD;
					} else {
						difficulty--;
					}

					drawDifficultyOption(difficulty);
				}
			}
		} else if (key == KENTER || key == KRIGHT) {
			// select menu option
			selection = (selector - MENUSTART) / MENUSTEP;

			if (options) {
			// if we're in the options menu

				// exit the options menu
				if (selection == QUIT) {
					// close options menu
					options = FALSE;

					// switch the options and main menus
					drawOptionsMenu(speed,difficulty);
					drawMenu();

					// reset the selector
					drawSelector(selector);
					selector = MENUSTART;
					drawSelector(selector);
				} else if (selection == START) {
					// same as speed option -- option 1 == SPEED
					drawSpeedOption(speed);

					if (speed == VERYFAST) {
						speed = VERYSLOW;
					} else {
						speed++;
					}

					drawSpeedOption(speed);
				} else if (selection == OPTIONS) {
					// same as difficulty option -- option 2 == DIFFICULTY
					drawDifficultyOption(difficulty);

					if (difficulty == HARD) {
						difficulty = EASY;
					} else {
						difficulty++;
					}

					drawDifficultyOption(difficulty);
				}
			} else {
				// if we chose to start or exit, end the loop
				if (selection == START || selection == QUIT) {
					done = TRUE;
				} else {
					// enter the options menu
					options = TRUE;

					// switch the main and options menus
					drawMenu();
					drawOptionsMenu(speed,difficulty);

					// reset the selector
					drawSelector(selector);
					selector = MENUSTART;
					drawSelector(selector);
				}
			}
		} else if (key == KESC) {
			// exit the options menu
			if (options) {
				// close options menu
				options = FALSE;

				// switch the options and main menus
				drawOptionsMenu(speed,difficulty);
				drawMenu();

				// reset the selector
				drawSelector(selector);
				selector = MENUSTART;
				drawSelector(selector);
			} else {
				selection = QUIT;
				done = TRUE;
			}
		}

		// wait for keypress to dissipate
		delay(KEYDELAY);
	}

	// set the game options
	*gamespeed = speed;
	*gamedifficulty = difficulty;

	return (selection == START) ? TRUE : FALSE;
}
예제 #19
0
void main(void)
{
  // USER CODE BEGIN (Main,1)
	
	int ledState = 0;	// LED Status
	char s[COLCOUNT + 1]; // 20 Zeichen fuers Display + '\0'
	char canCnt = 0;

  // USER CODE END

  Project_Init();

  // USER CODE BEGIN (Main,2)
	
	ClrScr();
	DoPrintZ(1, "Hallo!");

	while(1)
	{ 	
		
		// main wurde so veraendert, dass es keine Displayausgaben
		// macht ausser denen zum Testen des CAN-Moduls.
		// Alles andere wurde auskommentiert.
				
		if (KeyDown())
		{
			switch(GetKey())
			{

				case '1': 
		
					CAN_vTransmit(1);

					if (++kanal >= ADNUM) // kanal = ++kanal % ADNUM;
						kanal = 0;

					//refreshDisplay(REFRESH_Z1);

					ledState ^= 0x10; 
					break;

				case '2':	
					
					vMakeCanValue(fGibGewicht());

					refreshDisplay(REFRESH_Z2);
									
					ledState ^= 0x20;
					break;

				case '3':

					// Geschw.stufe erhoehen
					if (stufe < 10)
					{
						stufe++;
						compare16 = -500 * stufe;

						//refreshDisplay(REFRESH_Z4);
					}
					
					ledState ^= 0x40;
					break;

				case '4':

					// Geschw.stufe erniedrigen
					if (stufe > 1)
					{
						stufe--;
						compare16 = -500 * stufe;

						//refreshDisplay(REFRESH_Z4);
					}

					ledState ^= 0x80;
					break;
			}

			IO_vWritePort(P1L, ledState);

		}

		if (bCanRok())
		{
			canCnt++;
			sprintf(s, "%2d: %2.4f", canCnt, fGiveCanValue());
			DoPrintZ(1, s);
		}

		/*
		// refresh Flag wird von RTC gesetzt
		if (refresh)
		{
			refreshDisplay(REFRESH_ALL);
			refresh = 0;
		}
		*/
		/*
		// Messung wird durch StartTemp() angestoßen,
		// und angezeigt, sobald's fertig ist.
		if (bTempDa())
		{
			sprintf(s, "Temperatur: %5.2f", fGetTemp());
			DoPrintZ(3, s);
		}
		*/
	}

  // USER CODE END
}
예제 #20
0
파일: gfx.c 프로젝트: bcherry/bcherry
// drawHiScoreBoard - draws the hiscore board, and updates it with the hiscore from the latest game
void drawHiScoreBoard(unsigned long int newscore) {
	SCORE scores[MAX_HISCORES];
	short int loop, pos = -1;
	char name[10], str[50], *error = "File I/O Error";
	HANDLE dlg;

	// restore interrupt handlers
	OSSetSR(0x0000);

	if (!loadHiScores(scores)) {
		// cannot open hiscore file -- display error
		DlgMessage(error,"Unable to Load HiScore Data",BT_OK,BT_NONE);
		return;
	}

	// check if latest score is a highscore
	for (loop = (MAX_HISCORES - 1); loop >= 0; loop--) {
		if (newscore > scores[loop].score) {
			// new HiScore!!
			pos = loop;
		}
	}

	if (pos != -1) {
		// if we found a new hiscore
		if ((dlg = DialogNewSimple(DLGWIDTH,DLGHEIGHT)) == H_NULL) {
			DlgMessage("Memory Allocation Error","Not Enough Free Memory!",BT_OK,BT_NONE);
		} else {
			DialogAddTitle(dlg,"New Hiscore!",BT_OK,BT_NONE);
			DialogAddRequest(dlg,5,25,"Your Name:",0,9,11);

			sprintf(str,"You earned the #%hd hiscore position!",pos+1);
			DialogAddText(dlg,5,15,str);

			do {
				// truncate name variable
				name[0] = 0;
			} while (DialogDo(dlg,CENTER,CENTER,name,NULL) != KEY_ENTER);

			// free the dialog box memory
			HeapFree(dlg);

			// move the hiscore list down
			if (pos < (MAX_HISCORES - 1)) {
				for (loop = (MAX_HISCORES - 1); loop > pos; loop--) {
					scores[loop].score = scores[loop - 1].score;
					scores[loop].name[0] = 0;
					strcpy(scores[loop].name,scores[loop - 1].name);
				}
			}

			// fill in the new hiscore
			scores[pos].score = newscore;
			scores[pos].name[0] = 0;
			strcpy(scores[pos].name,name);

			if (!saveHiScores(scores)) {
				DlgMessage(error,"Unable to save HiScore Board",BT_OK,BT_NONE);
			}
		}
	}

	// display the hiscore board

	// clear the screen
	ClrScr();

	// draw the screen borders
	drawBorder();

	// draw the game logo
	drawLogo();

	FontSetSys(F_8x10);
	DrawStr(25,35,"Hiscore Board",A_NORMAL);
	FontSetSys(F_6x8);

	for (loop = 0; loop < 5; loop++) {
		printf_xy(20,50+loop*10,"#%hd %-9s %lu",loop+1,scores[loop].name,scores[loop].score);
	}

	ngetchx();

	// disable interrupts
	OSSetSR(0x0700);

	// wait for keypresses to dissipate
	delay(KEYDELAY);
}
예제 #21
0
파일: map.c 프로젝트: bcherry/bcherry
// Main Function
void _main(void)
{	
	// declare variables
	char keys[8]; getKeyMasks(keys);
	BITS bit= {0,0,0,0,0,0,0,0};
	char arrow_key=0;
	POSITION thingPOS= {0,0};
	POSITION mapPOS= {0,0};
	// main menu
	title();
	
	// prepare for GRAYSCALE AND ROWREAD
	interrupt1 = GetIntVec(AUTO_INT_1);
	SetIntVec(AUTO_INT_1,DUMMY_HANDLER);
	
	while (1) {
		
		// initialize
		bit.one=0;
		thingPOS= (POSITION){0,0};
		
		// a blank slate
		ClrScr();
		
		//setup game, draw screen, etc
		draw(thing,thingPOS,mapPOS);
		makeMap(mapPOS);
		while (!button(ARROW_ROW,keys[UP]));
		
		while(!button(TI89_ESCROW,TI89_ESCKEY) && !bit.one) {
			// the game loop
			arrow_key=_rowread(ARROW_ROW);
			bit=(BITS){0,0,0,0,0,0,0,0};
			
			//get input
			if (arrow_key) {
				if (arrow_key & keys[UP]) bit.yup=1;
				if (arrow_key & keys[RIGHT]) bit.xright=1;
				if (arrow_key & keys[DOWN]) bit.ydown=1;
				if (arrow_key & keys[LEFT]) bit.xleft=1;
			}
			
			// test gunner is within dimension
			if (dim(thingPOS,bit)) {
				bit.draw=1;
				thingPOS.x+=bit.xright+(-bit.xleft);
				thingPOS.y+=bit.yup+(-bit.ydown);
			}
			
			if (bit.draw) {
			mapPOS.x=thingPOS.x-10;
			mapPOS.y=thingPOS.y-5;
			if (mapPOS.x<0) mapPOS.x=0;
			else if (mapPOS.x>11) mapPOS.x=11;
			if (mapPOS.y<0) mapPOS.y=0;
			else if (mapPOS.y>20) mapPOS.y=20;
			}
			
			// if movement=true, draw new position
			if (bit.draw) {
				ClrScr();
				makeMap(mapPOS);
				draw(thing,thingPOS,mapPOS);
			}
			
			//delay
			delay(6);
		} 
		if (!bit.one) {
			SetIntVec(AUTO_INT_1,interrupt1);
			return;
		}	  														//while !quit and !done
	} 																														//infinite loop
}
uint                                    /*                                521*/
ShowArray( DFILE *dfp, uint row, uint rows, uint skip )                 /*112*/
{                                                                       /**12*/
 TD_ARRAY  *tp;                         /*                                813*/
 uint   item;                           /* array item to display.         112*/
 uint   rr;                             /*                                112*/
 uint   n;                              /* gp integer.                    112*/
 uint   Nitems;                         /* number of array items.         112*/
 uint   atomtype;                       /* type of array items.           112*/
 uint   atomsize;                       /* size of an array item.         112*/
 uint   mid;                            /* module id for the array var.   112*/
 uint   sfx;                            /* stack frame index if auto.     112*/
 uint   baseaddr;                       /* user addr where array starts.  112*/
 uchar  buffer[2*DATALINESPAN];         /* display buffer for array item. 112*/
 uchar *cp;                             /* gp char ptr.                   112*/
 uint   addr;                           /* gp address.                    112*/
                                                                        /*112*/
 mid = dfp->mid;                                                        /*112*/
 sfx = dfp->sfx;                                                        /*112*/
 baseaddr = dfp->baseaddr;                                              /*112*/
                                                                        /*112*/
 /****************************************************************************/
 /* - get a ptr to the defining type record in $$type seg.                112*/
 /* - get the atomic type of the array elements.                          112*/
 /* - get the size of the atomic type.                                    112*/
 /* - get the number of array items.                                      112*/
 /* - handle any errors in the above steps by simply returning false.     112*/
 /*                                                                       112*/
 /****************************************************************************/
 tp = (TD_ARRAY*)QbasetypeRec(mid, dfp->showtype);                   /*813112*/
 if( ( tp == NULL ) || ( tp->RecType != T_ARRAY ) )                  /*813112*/
  return( FALSE );                                                      /*112*/
                                                                        /*112*/
 atomtype = tp->ElemType;                                            /*813112*/
 atomtype = HandleUserDefs(mid,atomtype);                               /*813*/
                                                                        /*512*/
 if( atomtype == 0 )                                                    /*112*/
  return( FALSE );                                                      /*112*/
                                                                        /*112*/
 atomsize = QtypeSize(mid, atomtype);                                   /*112*/
 if( atomsize == 0 )                                                    /*112*/
  return( FALSE );                                                      /*112*/
                                                                        /*112*/
 Nitems = tp->ByteSize/atomsize;                                     /*813112*/
 if( Nitems == 0 )                                                      /*912*/
   Nitems = 1;                                                          /*912*/
 if( Nitems <= skip )                                                   /*112*/
  return( FALSE );                                                      /*112*/
                                                                        /*112*/
 /************************************************************************112*/
 /* simply show character array bytes as a string.                        112*/
 /************************************************************************112*/
 if( atomtype == TYPE_CHAR || atomtype == TYPE_UCHAR )                  /*112*/
 {                                                                      /*112*/
  ShowHexBytes(dfp, row, rows, skip);                                   /*112*/
  return( TRUE );                                                       /*112*/
 }                                                                      /*112*/
                                                                        /*112*/
 /************************************************************************112*/
 /* -we only want to associate the array name with the first element of   112*/
 /*  the array. We set dfp == null after the first element, or before the 112*/
 /*  first element if we have scrolled the array name off the screen.     112*/
 /* -format each element.                                                 112*/
 /* -display in int and hex format.                                       112*/
 /* -truncate long lines.                                                 112*/
 /*                                                                       112*/
 /************************************************************************112*/
 if( skip )                                                             /*112*/
  dfp = NULL;                                                           /*112*/
                                                                        /*112*/
 for( rr=0, item=skip+1; (rr < rows) && (item <= Nitems); ++rr, ++item) /*112*/
 {                                                                      /*112*/
  InitDataBuffer( buffer, DATALINESPAN, dfp );                          /*112*/
  dfp = NULL;                                                           /*112*/
  n = sprintf( buffer + STGCOL+1, "[%02u] ", item-1 );                  /*521*/
                                                                        /*112*/
  *(buffer + STGCOL+1 + n) = ' ';                                       /*112*/
                                                                        /*112*/
  if ( n <= TAB1 )  n = TAB1;                                           /*112*/
  else  n = TAB2;                                                       /*112*/
                                                                        /*112*/
                                                                        /*112*/
  cp   = buffer + STGCOL + 1 + n;                                       /*112*/
  addr = baseaddr+atomsize*(item-1);                                    /*112*/
  FormatDataItem( cp , addr, mid, atomtype, sfx);                       /*112*/
  buffer[ DATALINESPAN-1 ] = 0;                                         /*112*/
  putrc( row + rr, 0, buffer );                                         /*112*/
 }                                                                      /*112*/
 if( rr < rows )                                                        /*112*/
  ClrScr( row + rr, row + rows - 1, vaStgExp );                         /*112*/
 return( TRUE );                                                        /*112*/
}                                       /* end ShowArray().             /*112*/
uint                                    /*                                521*/
ShowStruct(DFILE *dfp,uint row,uint rows,uint skip)
                                        /* -> dfile node containing stucture.*/
                                        /* screen row.                       */
                                        /* rows available for display.       */
                                        /* # of logical data recs to skip.   */
{                                       /*                                   */
 uint   item;                           /*                                   */
 uint   rr;                             /*                                   */
 uint   n;                              /*                                   */
 TD_STRUCT   *tp;                       /*                                813*/
 TD_TYPELIST *typelist;                 /*                                813*/
 Trec  *namelist;                       /*                                   */
 uint   Nitems;                         /*                                   */
 uint   mid;                            /*                                   */
 uint   sfx;                            /*                                   */
 uchar *cp;                             /*                                   */
 uint   baseaddr;                       /*                                112*/
 uchar  buffer[2*DATALINESPAN];         /*                                   */
 uint   memberoffs;                     /* offset of member within structure.*/
 uint   membertype;                     /* type of the structure member.     */
 USHORT MaxLen;                         /* length of max structure name813529*/
                                        /*                                   */
 mid = dfp->mid;                        /*                                   */
 sfx = dfp->sfx;                        /*                                   */
 baseaddr = dfp->baseaddr;              /*                                   */

/*****************************************************************************/
/* The first thing we want to do is get a pointer to the base type record.   */
/* If the showtype is <= 512, indicating a primitive type, then we will      */
/* get a back a NULL.                                                        */
/*****************************************************************************/
 tp = (TD_STRUCT*)QbasetypeRec(mid, dfp->showtype); /*                    813*/
 if(!tp ||                              /* cutting through the typedefs.     */
    tp->RecType != T_STRUCT             /*                                   */
   )                                    /* cutting through the typedefs.     */
  return(FALSE);

/*****************************************************************************/
/* Now, we are going to get the number of structure members and quit if we   */
/* were told to skip more than the number of structure members.              */
/*****************************************************************************/
 Nitems = tp->NumMembers;               /*                                813*/
 if( Nitems <= skip )
  return(FALSE);

/*****************************************************************************/
/* Now, get pointers to the type list and the name list.                     */
/*****************************************************************************/
 typelist = (TD_TYPELIST*)QtypeRec(mid, tp->TypeListIndex);             /*813*/
 namelist = QtypeRec(mid, tp->NameListIndex);                           /*813*/
                                        /*                                   */
 if( skip )                             /*                                   */
     dfp = NULL;                        /*                                   */
                                        /*                                   */
 for( rr=0, item=skip+1;                /*                                813*/
      (rr < rows) &&                    /*                                   */
      (item <= Nitems);                 /*                                   */
      ++rr, ++item                      /*                                   */
    )                                   /*                                   */
 {                                      /*                                   */
  cp = (UCHAR *)QNameList(namelist,NAME,item-1);   /* find a member name. 813*/

  if(!cp)                               /* if there is no name then go home. */
    break;                              /*                                   */
                                        /*                                   */
  InitDataBuffer( buffer,               /* initialize the data buffer, i.e.  */
                  DATALINESPAN,         /* clear it, put expression name in  */
                  dfp                   /* it, put attributes in it, and  .  */
                );                      /* and terminate it with \0.         */
  dfp = NULL;                           /* kill dfp so we won't write the    */
                                        /* expression name again.            */
  MaxLen = *(USHORT*)cp;                /* length of structure name    813529*/
  MaxLen =                              /* limit the length of the name   529*/
  (MaxLen < (TAB2-2)) ? MaxLen : (TAB2-2);  /* till TAB2 position         529*/
  n = sprintf( buffer + STGCOL+1,       /* put the member name in the buffer.*/
              "%.*s: ",                 /*                                521*/
              MaxLen,                   /*                                529*/
              cp+sizeof(USHORT)         /*                                813*/
            );                          /*                                   */
                                        /*                                   */
                                        /* compute the offset of this member */
                                        /* within the data structure.        */
  memberoffs = QNameList(namelist,MEMBEROFFSET,item-1);                 /*813*/

                                        /* find the type of this member.     */
  membertype = typelist->TypeIndex[item-1];                          /*813112*/
                                        /*                                   */
                                        /*                                   */
  *(buffer + STGCOL+1 + n) = ' ';       /* remove null inserted by buffmt    */
                                        /*                                   */
  if ( n <= TAB1 )  n = TAB1;           /* move to a tab position based      */
  else  n = TAB2;                       /* on length of member name          */
                                        /*                                   */
                                        /*                                   */
                                        /* now format this item in the buffer*/
  FormatDataItem( buffer + STGCOL+1 + n,/*  starting position for the data.  */
                  baseaddr + memberoffs,/*  address of the member to format. */
                  mid,                  /*  mid containing the data.         */
                  membertype,           /*  type of the member.              */
                  sfx                   /*  stack frame index if there is one*/
                );                      /*                                   */
                                        /*                                   */
  buffer[ DATALINESPAN-1 ] = 0;         /* terminate the data buffer...again.*/
  putrc( row + rr, 0, buffer );         /* now display the data line.        */
 }                                      /*                                   */
                                        /*                                   */
 if( rr < rows )                        /* now clear the remaining rows.     */
   ClrScr( row + rr,                    /*                                   */
           row + rows - 1,              /*                                   */
           vaStgExp                     /*                                   */
         );                             /*                                   */
 return( TRUE );                        /*                                   */
}                                       /*                                   */
예제 #24
0
파일: t2048.c 프로젝트: 1cook/t2048
// Main Function
void _main( void ){
	//Create or load savefile
	SAVE gameState;
	if(readSave(&gameState))
		makeSave(&gameState);
	writeSave(&gameState); /*just to test whether writing is possible here
	so the player doesn't spend a long time and lose their progress*/
	//Buffer for the text at the bottom of the
	scoreString = (char*)malloc(60*sizeof(char));
	if(scoreString == NULL)
		exit(ER_MEMORY);
	
	//Pause menu
	pauseMenu = PopupNew(strConv[11], 50);
	if(pauseMenu == H_NULL)
		memkill(4, ER_MEMORY);
		PopupAddText(pauseMenu, -1, "New Game", 1);
		PopupAddText(pauseMenu, 0, "Options", 2);
			PopupAddText(pauseMenu,2,"Toggle Animations",5);
			PopupAddText(pauseMenu,2,"Reset Save Data",6);
			PopupAddText(pauseMenu, -1, "Exit", 3);
			PopupAddText(pauseMenu, -1, "About", 4);
	
	//Hiscore Name Entry
	nameBox = DialogNewSimple(140,35);
	if(nameBox == H_NULL)
		memkill(3, ER_MEMORY);
		DialogAddTitle(nameBox,"NEW HISCORE!",BT_OK,BT_NONE);
		DialogAddRequest(nameBox,3,14,"Name:", 0, 10, 14);
	
	//Game Over Entry
	gameOver = PopupNew("GAME OVER!", 40);
	if(gameOver == H_NULL)
		memkill(2, ER_MEMORY);
		PopupAddText(gameOver,-1,"Try Again",1);
		PopupAddText(gameOver,-1,"Exit",2);
	
	
	//About Dialouge
	aboutBox = DialogNewSimple(140,80);
	if(aboutBox == H_NULL)
		memkill(1, ER_MEMORY);	
		DialogAddTitle(aboutBox,"ABOUT",BT_OK,BT_NONE);

			DialogAddText(aboutBox, 3, 13, "2048: A sliding tile puzzle");
			DialogAddText(aboutBox, 3, 21, "Ti68k port by Harrison Cook");
			DialogAddText(aboutBox, 3, 29, "Original game by Gabriele Cirulli");
			DialogAddText(aboutBox, 3, 37, "\"Based on\" 1024 by Veewo Studio");
			DialogAddText(aboutBox, 3, 45, "\"Conceptually Similar to\":");
			DialogAddText(aboutBox, 3, 52, "Threes by Asher Vollmer");
			DialogAddText(aboutBox, 3, 59, "Built using TIGCC");
	
	ClrScr();
	FontSetSys(F_8x10);
	randomize();
	short int key;
	for(;;){
		ClrScr();
		drawGrid(gameState.grid);
		sprintf(scoreString, "Score: %lu Hiscore: %lu by %s", gameState.score, gameState.bscore, gameState.name);
		if(!isGridAvailable(gameState.grid)){
			
			if(gameState.score > gameState.bscore){
					DialogDo(nameBox,CENTER,CENTER,	gameState.name,NULL);
					gameState.bscore = gameState.score;
					FontSetSys(F_8x10);
			}
			gameState.score = 0;
			initGrid(gameState.grid);
			switch(PopupDo(gameOver,CENTER,CENTER,0)){
			case 1:
				continue;
				break;
			default:
				goto endGame;
				
			}
		}
		ST_helpMsg(scoreString);
		nodraw:
		ST_busy(ST_IDLE);
		key = ngetchx();
		ST_busy(ST_BUSY);
		ST_helpMsg(scoreString);
		char move = 4;
		if(key == KEY_UP)
			move = UP;
		else if(key == KEY_RIGHT)
			move = RIGHT;
		else if(key == KEY_DOWN)
			move = DOWN;
		else if(key == KEY_LEFT)
			move = LEFT;
		else if(key == KEY_OFF || key==KEY_ON)
			//Turn the calculator off during a game. Resume it later
			off();
		else if(key == KEY_ESC){ //Brings up the pause menu
			switch (PopupDo(pauseMenu,CENTER,CENTER,0)){
				case 1: //1. New Game
					gameState.score = 0;
					initGrid(gameState.grid);
					break;
				//case 2: //2. Options
					//this is a submenu
				case 3: //3: Exit
					endGame:
					writeSave(&gameState);
					memkill(0,0);
					break;
				case 4: //4: About
					DialogDo(aboutBox,CENTER,CENTER,NULL,NULL);
					//Dialog sets the font weirdly, set it back
					FontSetSys(F_8x10);
					break;
				case 5: //1. Toggle Animations
					gameState.animations = !gameState.animations;
					break;
				case 6: //2. Reset Saved Data
					makeSave(&gameState);
					break;
			}
		}
		else goto nodraw;
		if(move < 4){
			if(isDirectionAvailable(gameState.grid, move)){
				shiftGrid(gameState.grid,move,&gameState.score, gameState.animations);
				pushNewTile(gameState.grid);
			}
			else goto nodraw;
		}
	}
}