Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "lcdconsole.h"
26
#include "util.h"
27
 
28
 
29
#define OFFSETX LCDCONSOLE_OFFSETX
30
#define OFFSETY LCDCONSOLE_OFFSETY
31
#define PIXELBYTES (LCD_BYTESPERPIXEL)
32
#define LINEBYTES (LCD_WIDTH * PIXELBYTES)
33
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
34
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
35
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
36
 
37
 
38
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
39
static unsigned int current_row;
40
static unsigned int current_col;
41
 
42
 
43
void lcdconsole_init()
44
{
45
  memset(framebuf, -1, sizeof(framebuf));
46
  current_row = 0;
47
  current_col = -1;
48
}
49
 
50
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
51
{
52
  if (string == '\r') return;
53
  current_col++;
54
  if (string == '\n')
55
  {
56
    current_col = -1;
57
    current_row++;
58
    return;
59
  }
60
  if (string == '\t')
61
  {
62
    current_col |= 3;
63
    return;
64
  }
65
  if (current_col >= LCDCONSOLE_COLS)
66
  {
67
    current_col = 0;
68
    current_row++;
69
  }
70
  if (current_row >= LCDCONSOLE_ROWS)
71
  {
72
    int offset = current_row - LCDCONSOLE_ROWS + 1;
73
    memcpy(framebuf, &framebuf[ROWBYTES * offset], ROWBYTES * offset);
74
    memset(&framebuf[sizeof(framebuf) - ROWBYTES * offset],
75
           -1, ROWBYTES * offset);
76
  }
77
  renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row
78
                     + COLBYTES * current_col],
7 theseven 79
             fgcolor, bgcolor, string, LINEBYTES);
2 theseven 80
}
81
 
82
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
83
{
84
  while (*string) lcdconsole_putc(*string++, fgcolor, bgcolor);
85
}
86
 
87
void lcdconsole_update()
88
{
89
  displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
90
}