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
//
677 theseven 6
//    This file is part of emCORE.
2 theseven 7
//
677 theseven 8
//    emCORE is free software: you can redistribute it and/or
2 theseven 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
//
677 theseven 13
//    emCORE is distributed in the hope that it will be useful,
2 theseven 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
677 theseven 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
2 theseven 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
#define OFFSETX LCDCONSOLE_OFFSETX
31
#define OFFSETY LCDCONSOLE_OFFSETY
32
#define PIXELBYTES (LCD_BYTESPERPIXEL)
293 theseven 33
#define LINEBYTES (FRAMEBUF_WIDTH * PIXELBYTES)
2 theseven 34
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
35
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
36
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
37
 
38
 
293 theseven 39
static unsigned char framebuf[LCD_FRAMEBUFSIZE] IBSS_ATTR;
40
static unsigned int current_row;
41
static unsigned int current_col;
42
static bool lcdconsole_needs_update;
2 theseven 43
 
44
void lcdconsole_init()
45
{
293 theseven 46
    displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, (void*)0xffffffff, 0);
421 theseven 47
    memset(framebuf, LCDCONSOLE_BGCOLOR, sizeof(framebuf));
15 theseven 48
    current_row = 0;
49
    current_col = -1;
50
    lcdconsole_needs_update = false;
2 theseven 51
}
52
 
15 theseven 53
void lcdconsole_putc_noblit(char string, int fgcolor, int bgcolor)
2 theseven 54
{
15 theseven 55
    if (string == '\r') return;
56
    current_col++;
57
    if (string == '\n')
58
    {
59
        current_col = -1;
60
        current_row++;
61
        return;
62
    }
63
    if (string == '\t')
64
    {
65
        current_col |= 3;
66
        return;
67
    }
68
    if (current_col >= LCDCONSOLE_COLS)
69
    {
70
        current_col = 0;
71
        current_row++;
72
    }
73
    if (current_row >= LCDCONSOLE_ROWS)
74
    {
75
        int offset = current_row - LCDCONSOLE_ROWS + 1;
76
        memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
77
            ROWBYTES * (LCDCONSOLE_ROWS - offset));
78
        memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
79
            -1, ROWBYTES * offset);
80
        current_row = LCDCONSOLE_ROWS - 1;
81
    }
82
    renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
293 theseven 83
               fgcolor, bgcolor, string, FRAMEBUF_WIDTH);
2 theseven 84
}
85
 
15 theseven 86
void lcdconsole_puts_noblit(const char* string, int fgcolor, int bgcolor)
2 theseven 87
{
15 theseven 88
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
2 theseven 89
}
90
 
91
void lcdconsole_update()
92
{
15 theseven 93
    uint32_t mode = enter_critical_section();
94
    if (displaylcd_busy())
95
    {
96
        lcdconsole_needs_update = true;
97
        leave_critical_section(mode);
98
        return;
99
    }
100
    leave_critical_section(mode);
293 theseven 101
    displaylcd((LCD_WIDTH - FRAMEBUF_WIDTH) / 2,
102
               (LCD_WIDTH - FRAMEBUF_WIDTH) / 2 + FRAMEBUF_WIDTH - 1,
103
               (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2,
104
               (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2 + FRAMEBUF_HEIGHT - 1,
105
               framebuf, 0);
2 theseven 106
}
15 theseven 107
 
108
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
109
{
110
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
111
    lcdconsole_update();
112
}
113
 
114
void lcdconsole_callback()
115
{
116
    if (lcdconsole_needs_update)
117
    {
293 theseven 118
        displaylcd((LCD_WIDTH - FRAMEBUF_WIDTH) / 2,
119
                   (LCD_WIDTH - FRAMEBUF_WIDTH) / 2 + FRAMEBUF_WIDTH - 1,
120
                   (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2,
121
                   (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2 + FRAMEBUF_HEIGHT - 1,
122
                   framebuf, 0);
15 theseven 123
        lcdconsole_needs_update = false;
124
    }
125
}