Subversion Repositories freemyipod

Rev

Rev 704 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
2 theseven 7
//
427 farthen 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
//
427 farthen 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
427 farthen 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"
124 theseven 29
#include "progressbar.h"
2 theseven 30
 
31
 
32
#define OFFSETX LCDCONSOLE_OFFSETX
33
#define OFFSETY LCDCONSOLE_OFFSETY
34
#define PIXELBYTES (LCD_BYTESPERPIXEL)
35
#define LINEBYTES (LCD_WIDTH * PIXELBYTES)
36
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
37
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
38
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
39
 
40
 
41
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
15 theseven 42
static unsigned int current_row IBSS_ATTR;
43
static unsigned int current_col IBSS_ATTR;
44
static bool lcdconsole_needs_update IBSS_ATTR;
2 theseven 45
 
46
 
47
void lcdconsole_init()
48
{
257 theseven 49
    memset(framebuf, LCDCONSOLE_BGCOLOR, sizeof(framebuf));
15 theseven 50
    current_row = 0;
51
    current_col = -1;
52
    lcdconsole_needs_update = false;
2 theseven 53
}
54
 
15 theseven 55
void lcdconsole_putc_noblit(char string, int fgcolor, int bgcolor)
2 theseven 56
{
15 theseven 57
    if (string == '\r') return;
58
    current_col++;
59
    if (string == '\n')
60
    {
61
        current_col = -1;
62
        current_row++;
63
        return;
64
    }
65
    if (string == '\t')
66
    {
67
        current_col |= 3;
68
        return;
69
    }
70
    if (current_col >= LCDCONSOLE_COLS)
71
    {
72
        current_col = 0;
73
        current_row++;
74
    }
75
    if (current_row >= LCDCONSOLE_ROWS)
76
    {
77
        int offset = current_row - LCDCONSOLE_ROWS + 1;
78
        memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
261 theseven 79
               ROWBYTES * (LCDCONSOLE_ROWS - offset));
15 theseven 80
        memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
261 theseven 81
               LCDCONSOLE_BGCOLOR, ROWBYTES * offset);
15 theseven 82
        current_row = LCDCONSOLE_ROWS - 1;
83
    }
497 theseven 84
    renderchar_native(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
85
                      fgcolor, bgcolor, string, LCD_WIDTH);
2 theseven 86
}
87
 
15 theseven 88
void lcdconsole_puts_noblit(const char* string, int fgcolor, int bgcolor)
2 theseven 89
{
15 theseven 90
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
2 theseven 91
}
92
 
25 theseven 93
void lcdconsole_write_noblit(const char* string, size_t length, int fgcolor, int bgcolor)
94
{
95
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
96
}
97
 
2 theseven 98
void lcdconsole_update()
99
{
15 theseven 100
    uint32_t mode = enter_critical_section();
101
    if (displaylcd_busy())
102
    {
103
        lcdconsole_needs_update = true;
104
        leave_critical_section(mode);
105
        return;
106
    }
107
    leave_critical_section(mode);
492 theseven 108
    displaylcd_native(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf);
2 theseven 109
}
15 theseven 110
 
704 theseven 111
void lcdconsole_supdate()
112
{
113
    displaylcd_safe_native(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf);
114
}
115
 
15 theseven 116
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
117
{
118
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
119
    lcdconsole_update();
120
}
121
 
122
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
123
{
124
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
125
    lcdconsole_update();
126
}
127
 
25 theseven 128
void lcdconsole_write(const char* string, size_t length, int fgcolor, int bgcolor)
129
{
130
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
131
    lcdconsole_update();
132
}
133
 
15 theseven 134
void lcdconsole_callback()
135
{
136
    if (lcdconsole_needs_update)
137
    {
704 theseven 138
        displaylcd_safe_native(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf);
15 theseven 139
        lcdconsole_needs_update = false;
140
    }
141
}
122 theseven 142
 
143
int lcdconsole_get_current_x()
144
{
145
    return (current_col + 1) * FONT_WIDTH + OFFSETX;
146
}
147
 
148
int lcdconsole_get_current_y()
149
{
150
    return current_row * FONT_HEIGHT + OFFSETY;
151
}
152
 
153
int lcdconsole_get_lineend_x()
154
{
155
    return LCDCONSOLE_COLS * FONT_WIDTH + OFFSETX - 1;
156
}
157
 
158
int lcdconsole_get_lineend_y()
159
{
160
    return (current_row + 1) * FONT_HEIGHT + OFFSETY - 1;
161
}
124 theseven 162
 
163
void lcdconsole_progressbar(struct progressbar_state* progressbar, int min, int max)
164
{
165
    progressbar_init(progressbar, lcdconsole_get_current_x(), lcdconsole_get_lineend_x(),
166
                     lcdconsole_get_current_y(), lcdconsole_get_lineend_y(),
167
                     lcd_translate_color(0, 0, 0, 0), lcd_translate_color(0, 0xcf, 0xcf, 0xcf),
168
                     lcd_translate_color(0, 0, 0, 0xef), min, max);
169
}