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
//
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
    }
84
    renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
138 theseven 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);
108
    displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
2 theseven 109
}
15 theseven 110
 
111
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
112
{
113
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
114
    lcdconsole_update();
115
}
116
 
117
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
118
{
119
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
120
    lcdconsole_update();
121
}
122
 
25 theseven 123
void lcdconsole_write(const char* string, size_t length, int fgcolor, int bgcolor)
124
{
125
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
126
    lcdconsole_update();
127
}
128
 
15 theseven 129
void lcdconsole_callback()
130
{
131
    if (lcdconsole_needs_update)
132
    {
133
        displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
134
        lcdconsole_needs_update = false;
135
    }
136
}
122 theseven 137
 
138
int lcdconsole_get_current_x()
139
{
140
    return (current_col + 1) * FONT_WIDTH + OFFSETX;
141
}
142
 
143
int lcdconsole_get_current_y()
144
{
145
    return current_row * FONT_HEIGHT + OFFSETY;
146
}
147
 
148
int lcdconsole_get_lineend_x()
149
{
150
    return LCDCONSOLE_COLS * FONT_WIDTH + OFFSETX - 1;
151
}
152
 
153
int lcdconsole_get_lineend_y()
154
{
155
    return (current_row + 1) * FONT_HEIGHT + OFFSETY - 1;
156
}
124 theseven 157
 
158
void lcdconsole_progressbar(struct progressbar_state* progressbar, int min, int max)
159
{
160
    progressbar_init(progressbar, lcdconsole_get_current_x(), lcdconsole_get_lineend_x(),
161
                     lcdconsole_get_current_y(), lcdconsole_get_lineend_y(),
162
                     lcd_translate_color(0, 0, 0, 0), lcd_translate_color(0, 0xcf, 0xcf, 0xcf),
163
                     lcd_translate_color(0, 0, 0, 0xef), min, max);
164
}