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"
14 theseven 26
#include "drawing.h"
2 theseven 27
#include "util.h"
28
 
29
 
30
#define OFFSETX LCDCONSOLE_OFFSETX
31
#define OFFSETY LCDCONSOLE_OFFSETY
32
#define PIXELBYTES (LCD_BYTESPERPIXEL)
33
#define LINEBYTES (LCD_WIDTH * PIXELBYTES)
34
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
35
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
36
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
37
 
38
 
39
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
40
static unsigned int current_row;
41
static unsigned int current_col;
42
 
43
 
44
void lcdconsole_init()
45
{
46
  memset(framebuf, -1, sizeof(framebuf));
47
  current_row = 0;
48
  current_col = -1;
49
}
50
 
51
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
52
{
53
  if (string == '\r') return;
54
  current_col++;
55
  if (string == '\n')
56
  {
57
    current_col = -1;
58
    current_row++;
59
    return;
60
  }
61
  if (string == '\t')
62
  {
63
    current_col |= 3;
64
    return;
65
  }
66
  if (current_col >= LCDCONSOLE_COLS)
67
  {
68
    current_col = 0;
69
    current_row++;
70
  }
71
  if (current_row >= LCDCONSOLE_ROWS)
72
  {
73
    int offset = current_row - LCDCONSOLE_ROWS + 1;
14 theseven 74
    memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
75
           ROWBYTES * (LCDCONSOLE_ROWS - offset));
76
    memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
2 theseven 77
           -1, ROWBYTES * offset);
14 theseven 78
    current_row = LCDCONSOLE_ROWS - 1;
2 theseven 79
  }
14 theseven 80
  renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
7 theseven 81
             fgcolor, bgcolor, string, LINEBYTES);
2 theseven 82
}
83
 
84
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
85
{
86
  while (*string) lcdconsole_putc(*string++, fgcolor, bgcolor);
87
}
88
 
89
void lcdconsole_update()
90
{
91
  displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
92
}