Subversion Repositories freemyipod

Rev

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"
15 theseven 28
#include "contextswitch.h"
2 theseven 29
 
30
 
31
#define OFFSETX LCDCONSOLE_OFFSETX
32
#define OFFSETY LCDCONSOLE_OFFSETY
33
#define PIXELBYTES (LCD_BYTESPERPIXEL)
34
#define LINEBYTES (LCD_WIDTH * PIXELBYTES)
35
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
36
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
37
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
38
 
39
 
40
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
15 theseven 41
static unsigned int current_row IBSS_ATTR;
42
static unsigned int current_col IBSS_ATTR;
43
static bool lcdconsole_needs_update IBSS_ATTR;
2 theseven 44
 
45
 
46
void lcdconsole_init()
47
{
15 theseven 48
    memset(framebuf, -1, sizeof(framebuf));
49
    current_row = 0;
50
    current_col = -1;
51
    lcdconsole_needs_update = false;
2 theseven 52
}
53
 
15 theseven 54
void lcdconsole_putc_noblit(char string, int fgcolor, int bgcolor)
2 theseven 55
{
15 theseven 56
    if (string == '\r') return;
57
    current_col++;
58
    if (string == '\n')
59
    {
60
        current_col = -1;
61
        current_row++;
62
        return;
63
    }
64
    if (string == '\t')
65
    {
66
        current_col |= 3;
67
        return;
68
    }
69
    if (current_col >= LCDCONSOLE_COLS)
70
    {
71
        current_col = 0;
72
        current_row++;
73
    }
74
    if (current_row >= LCDCONSOLE_ROWS)
75
    {
76
        int offset = current_row - LCDCONSOLE_ROWS + 1;
77
        memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
78
            ROWBYTES * (LCDCONSOLE_ROWS - offset));
79
        memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
80
            -1, ROWBYTES * offset);
81
        current_row = LCDCONSOLE_ROWS - 1;
82
    }
83
    renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
84
        fgcolor, bgcolor, string, LINEBYTES);
2 theseven 85
}
86
 
15 theseven 87
void lcdconsole_puts_noblit(const char* string, int fgcolor, int bgcolor)
2 theseven 88
{
15 theseven 89
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
2 theseven 90
}
91
 
92
void lcdconsole_update()
93
{
15 theseven 94
    uint32_t mode = enter_critical_section();
95
    if (displaylcd_busy())
96
    {
97
        lcdconsole_needs_update = true;
98
        leave_critical_section(mode);
99
        return;
100
    }
101
    leave_critical_section(mode);
102
    displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
2 theseven 103
}
15 theseven 104
 
105
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
106
{
107
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
108
    lcdconsole_update();
109
}
110
 
111
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
112
{
113
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
114
    lcdconsole_update();
115
}
116
 
117
void lcdconsole_callback()
118
{
119
    if (lcdconsole_needs_update)
120
    {
121
        displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
122
        lcdconsole_needs_update = false;
123
    }
124
}