/*-----------------------------------------------------------------------------
//     $Date: 2004/11/19 20:19:52 $
//     $RCSfile: plat_flash_menu.c,v $
//-----------------------------------------------------------------------------
//
//     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
//     SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
//     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
//     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
//     OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
//     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
//     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
//     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
//     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
//     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
//     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
//     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//     FOR A PARTICULAR PURPOSE.
//     
//     (c) Copyright 2004 Xilinx, Inc.
//     All rights reserved.
//
//---------------------------------------------------------------------------*/
#include "xio.h"
#include "xbasic_types.h"
#include "xstatus.h"
#include "xtft.h"
#include "xtft_l.h"
#include "xparameters.h"
#include "bootload_graphics.h"
#include "xromlcd.h"

#define UART_BASEADDR   XPAR_OPB_UART16550_0_BASEADDR
#define UART_CLOCK      XPAR_XUARTNS550_CLOCK_HZ
#define UART_BAUDRATE   9600

#define TFT_DEVICE_ID   XPAR_PLB_TFT_CNTLR_REF_0_DEVICE_ID

#define STATUS_CHECK(Status) { if (Status != XST_SUCCESS) { return Status; } }

#include <stdio.h>
#include "xuartns550_l.h"

int main()
  {
  XTft Tft;
  XStatus Status;
  Xuint32 CurrentSel = 1, LastSel = 1;
  Xuint32 SelColor;
  Xuint32 y_pos, i;
  char *text[] = {"This bitstream was loaded in from the Xilinx Platform Flash. The Platform Flash",
                  "on this boards holds 4 bitstream \"revisions\" selected via the \"CFG ADDR\" DIP",
                  "switches. To run any of these demos, set the position \"2\" and \"3\" DIP switches",
                  "to choose the demo you want to run:",
                  "",
                  "DIP SW 2 | DIP SW 3 | ADDRESS | DEMO on Platform Flash",
                  "---------+----------+---------+-----------------------------------",
                  "  OFF    |   OFF    |    0    | This How-To Demo",
                  "  OFF    |   ON     |    1    | Simple Game",
                  "  ON     |   OFF    |    2    | My Own Platform Flash Image",
                  "  ON     |   ON     |    3    | XROM (Board Test and Demo Program)",
                  "",
                  "After changing the Configuration Address DIP switches, Press the \"Prog\" button",
                  "to reconfigure the board and load the new demo."};

  XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE);
  XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS);

  /* Initialize TFT */
  Status = XTft_Initialize(&Tft, TFT_DEVICE_ID);
  STATUS_CHECK(Status);
  
  /* Initialize TFT and display */
  XTft_SetColor(&Tft, 0x00ffffff, 0x00404040);
  XTft_ClearScreen(&Tft);
  XTft_SetPos(&Tft, 5, 0);
  XTft_WriteColorString(&Tft, "*** ML401 Platform Flash Demo List ***", 0x0000FF80, 0x00404040);
  xil_printf ("*** ML401 Platform Flash Demo List ***\r\n\r\n");

  for (i = 0; i < 14; i++)
    {
    XTft_SetPos(&Tft, 5, (i*15)+30);
    XTft_WriteColorString(&Tft,text[i],0x00FFFFFF, 0x00404040);
    xil_printf (text[i]);
    xil_printf ("\r\n");
    }

  /* print directions to LCD screen */
  XromLCDOn();
  XromLCDInit();
  while (1) {
    XromLCDPrintString ("Platform Flash  "  , "List of Demos...");
    usleep (3000000);
    XromLCDPrintString ("CFG ADDR = \"000\"", "This Program    ");
    usleep (2000000);
    XromLCDPrintString ("CFG ADDR = \"001\"", "ML401 Simon Game");
    usleep (2000000);
    XromLCDPrintString ("CFG ADDR = \"010\"", "My Own Design   ");
    usleep (2000000);
    XromLCDPrintString ("CFG ADDR = \"011\"", "Test/Diagnostics");
    usleep (2000000);
  }
  return 0;
  }
