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)
33
#define LINEBYTES (LCD_WIDTH * PIXELBYTES)
34
#define COLBYTES (FONT_WIDTH * PIXELBYTES)
35
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
36
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
37
 
38
 
39
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
15 theseven 40
static unsigned int current_row IBSS_ATTR;
41
static unsigned int current_col IBSS_ATTR;
42
static bool lcdconsole_needs_update IBSS_ATTR;
2 theseven 43
 
44
 
45
void lcdconsole_init()
46
{
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],
138 theseven 83
               fgcolor, bgcolor, string, LCD_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);
106
    displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
2 theseven 107
}
15 theseven 108
 
109
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
110
{
111
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
112
    lcdconsole_update();
113
}
114
 
115
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
116
{
117
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
118
    lcdconsole_update();
119
}
120
 
25 theseven 121
void lcdconsole_write(const char* string, size_t length, int fgcolor, int bgcolor)
122
{
123
    while (length--) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
124
    lcdconsole_update();
125
}
126
 
15 theseven 127
void lcdconsole_callback()
128
{
129
    if (lcdconsole_needs_update)
130
    {
131
        displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
132
        lcdconsole_needs_update = false;
133
    }
134
}
122 theseven 135
 
136
int lcdconsole_get_current_x()
137
{
138
    return (current_col + 1) * FONT_WIDTH + OFFSETX;
139
}
140
 
141
int lcdconsole_get_current_y()
142
{
143
    return current_row * FONT_HEIGHT + OFFSETY;
144
}
145
 
146
int lcdconsole_get_lineend_x()
147
{
148
    return LCDCONSOLE_COLS * FONT_WIDTH + OFFSETX - 1;
149
}
150
 
151
int lcdconsole_get_lineend_y()
152
{
153
    return (current_row + 1) * FONT_HEIGHT + OFFSETY - 1;
154
}