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
#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);
15 theseven 47
    memset(framebuf, -1, sizeof(framebuf));
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
 
25 theseven 91
void lcdconsole_write_noblit(const char* string, size_t length, int fgcolor, int bgcolor)
92
{
93
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
94
}
95
 
2 theseven 96
void lcdconsole_update()
97
{
15 theseven 98
    uint32_t mode = enter_critical_section();
99
    if (displaylcd_busy())
100
    {
101
        lcdconsole_needs_update = true;
102
        leave_critical_section(mode);
103
        return;
104
    }
105
    leave_critical_section(mode);
293 theseven 106
    displaylcd((LCD_WIDTH - FRAMEBUF_WIDTH) / 2,
107
               (LCD_WIDTH - FRAMEBUF_WIDTH) / 2 + FRAMEBUF_WIDTH - 1,
108
               (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2,
109
               (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2 + FRAMEBUF_HEIGHT - 1,
110
               framebuf, 0);
2 theseven 111
}
15 theseven 112
 
113
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
114
{
115
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
116
    lcdconsole_update();
117
}
118
 
119
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
120
{
121
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
122
    lcdconsole_update();
123
}
124
 
25 theseven 125
void lcdconsole_write(const char* string, size_t length, int fgcolor, int bgcolor)
126
{
127
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
128
    lcdconsole_update();
129
}
130
 
15 theseven 131
void lcdconsole_callback()
132
{
133
    if (lcdconsole_needs_update)
134
    {
293 theseven 135
        displaylcd((LCD_WIDTH - FRAMEBUF_WIDTH) / 2,
136
                   (LCD_WIDTH - FRAMEBUF_WIDTH) / 2 + FRAMEBUF_WIDTH - 1,
137
                   (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2,
138
                   (LCD_HEIGHT - FRAMEBUF_HEIGHT) / 2 + FRAMEBUF_HEIGHT - 1,
139
                   framebuf, 0);
15 theseven 140
        lcdconsole_needs_update = false;
141
    }
142
}
122 theseven 143
 
144
int lcdconsole_get_current_x()
145
{
146
    return (current_col + 1) * FONT_WIDTH + OFFSETX;
147
}
148
 
149
int lcdconsole_get_current_y()
150
{
151
    return current_row * FONT_HEIGHT + OFFSETY;
152
}
153
 
154
int lcdconsole_get_lineend_x()
155
{
156
    return LCDCONSOLE_COLS * FONT_WIDTH + OFFSETX - 1;
157
}
158
 
159
int lcdconsole_get_lineend_y()
160
{
161
    return (current_row + 1) * FONT_HEIGHT + OFFSETY - 1;
162
}