OpenCores
URL https://opencores.org/ocsvn/scarm/scarm/trunk

Subversion Repositories scarm

[/] [scarm/] [trunk/] [src/] [SoC/] [LCDCtrl/] [scLCDCtrl.cpp] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zhong
// scLCDCtrl.cpp: implementation of the scLCDCtrl class.
2
//
3
//////////////////////////////////////////////////////////////////////
4
 
5
#include "scLCDCtrl.h"
6
 
7
//////////////////////////////////////////////////////////////////////
8
// Construction/Destruction
9
//////////////////////////////////////////////////////////////////////
10
 
11
sscLCDCtrl::scLCDCtrl()
12
{
13
  //printf(MODULE_NAME": In Constructor\n");
14
  if((fScreen = fopen(LCDCTRL_SCREENFILE,"w")) == NULL)
15
  {
16
    fprintf(stderr,MODULE_NAME": Error opening %d\n",LCDCTRL_SCREENFILE);
17
    exit(1);
18
  }
19
  Reset();
20
}
21
///////////////////////////////////////////////////////////////////////////////
22
// ~CLCDCtrl - 
23
//
24
scLCDCtrl::~scLCDCtrl()
25
{
26
  //printf(MODULE_NAME": In Destructor\n");
27
  fclose(fScreen);
28
}
29
 
30
 
31
///////////////////////////////////////////////////////////////////////////////
32
// Reset -
33
//
34
void scLCDCtrl::Reset()
35
{
36
  int r, g, b, colorinc;
37
  double dcolorinc;
38
 
39
  memset(m_regs, 0, sizeof(uint32_t) * LCDCTRL_NUMREGS);
40
  m_regs[R_LCDVER] = 0x00001000; // v0.1
41
 
42
  r = g = b = 0;
43
  dcolorinc = (double)0xff/LCDCTRL_NUMPALS;
44
  colorinc = (int) dcolorinc+1;
45
  for(int i = 0; i < LCDCTRL_NUMPALS; i++)
46
  {
47
    r = g = b = i*colorinc;
48
    m_pals[i] = ( (r << 16) | (g << 8) | b );
49
  }
50
}
51
 
52
 
53
///////////////////////////////////////////////////////////////////////////////
54
// UpdateScreen - 
55
//
56
void scLCDCtrl::UpdateScreen()
57
{
58
  //printf(MODULE_NAME": Updating Screen\n");
59
  fseek(fScreen,0,SEEK_SET);
60
  for(int i = 0; i < LCDCTRL_NUMPALS; i++)
61
    fprintf(fScreen, "Pal[%x] = %x\n", i, m_pals[i]);
62
  fflush(fScreen);
63
}
64
 
65
///////////////////////////////////////////////////////////////////////////////
66
// Cycle - 
67
//
68
void scLCDCtrl::Cycle(LCDCTRLBUS* bus)
69
{
70
  static int CycleCount = 0;
71
 
72
 
73
  if( (CycleCount++ % LCDCTRL_UPDATEINTERVAL) == 0)
74
          UpdateScreen();
75
  // See what the pesky real world wants
76
  if (bus->w != 0)
77
  {
78
    uint32_t addr = bus->addr;
79
 
80
    // R_LCDVER        0x0
81
    if (addr == 0x00000004) // R_LCDRESOLUTION 0x1
82
      m_regs[R_LCDRESOLUTION] = bus->data;
83
    else if (addr == 0x00000008) // R_LCDCOLORDEPTH 0x2
84
      m_regs[R_LCDCOLORDEPTH] = bus->data;
85
    else if (addr == 0x0000000C) // R_LCDSTARTADDR  0x3
86
      m_regs[R_LCDSTARTADDR] = bus->data;
87
    // R_LCDRESERVED1  0x4
88
    // R_LCDPALINDEX   0x5
89
    // R_LCDPALDATA    0x6
90
    // R_LCDSTATUS     0x7
91
  }
92
 
93
 
94
  // Did the nosy busy body want any info?
95
  if (bus->r != 0)
96
  {
97
    uint32_t addr = bus->addr;
98
 
99
    if (addr == 0x00000000)
100
            bus->data = m_regs[R_LCDVER];
101
    else if (addr == 0x00000004)
102
            bus->data = m_regs[R_LCDRESOLUTION];
103
    else if (addr == 0x00000008)
104
            bus->data = m_regs[R_LCDCOLORDEPTH];
105
    else if (addr == 0x0000000C)
106
            bus->data = m_regs[R_LCDSTARTADDR];
107
    else
108
            bus->data = 0;
109
  }
110
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.