Subversion Repositories freemyipod

Rev

Rev 14 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 15
Line 23... Line 23...
23
 
23
 
24
#include "global.h"
24
#include "global.h"
25
#include "lcdconsole.h"
25
#include "lcdconsole.h"
26
#include "drawing.h"
26
#include "drawing.h"
27
#include "util.h"
27
#include "util.h"
-
 
28
#include "contextswitch.h"
28
 
29
 
29
 
30
 
30
#define OFFSETX LCDCONSOLE_OFFSETX
31
#define OFFSETX LCDCONSOLE_OFFSETX
31
#define OFFSETY LCDCONSOLE_OFFSETY
32
#define OFFSETY LCDCONSOLE_OFFSETY
32
#define PIXELBYTES (LCD_BYTESPERPIXEL)
33
#define PIXELBYTES (LCD_BYTESPERPIXEL)
Line 35... Line 36...
35
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
36
#define ROWBYTES (FONT_HEIGHT * LINEBYTES)
36
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
37
#define OFFSETBYTES (LINEBYTES * OFFSETY + PIXELBYTES * OFFSETX)
37
 
38
 
38
 
39
 
39
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
40
static unsigned char framebuf[LCD_FRAMEBUFSIZE];
40
static unsigned int current_row;
41
static unsigned int current_row IBSS_ATTR;
41
static unsigned int current_col;
42
static unsigned int current_col IBSS_ATTR;
-
 
43
static bool lcdconsole_needs_update IBSS_ATTR;
42
 
44
 
43
 
45
 
44
void lcdconsole_init()
46
void lcdconsole_init()
45
{
47
{
46
  memset(framebuf, -1, sizeof(framebuf));
48
    memset(framebuf, -1, sizeof(framebuf));
47
  current_row = 0;
49
    current_row = 0;
48
  current_col = -1;
50
    current_col = -1;
-
 
51
    lcdconsole_needs_update = false;
49
}
52
}
50
 
53
 
51
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
54
void lcdconsole_putc_noblit(char string, int fgcolor, int bgcolor)
52
{
55
{
53
  if (string == '\r') return;
56
    if (string == '\r') return;
54
  current_col++;
57
    current_col++;
55
  if (string == '\n')
58
    if (string == '\n')
56
  {
59
    {
57
    current_col = -1;
60
        current_col = -1;
58
    current_row++;
61
        current_row++;
59
    return;
62
        return;
60
  }
63
    }
61
  if (string == '\t')
64
    if (string == '\t')
62
  {
65
    {
63
    current_col |= 3;
66
        current_col |= 3;
64
    return;
67
        return;
65
  }
68
    }
66
  if (current_col >= LCDCONSOLE_COLS)
69
    if (current_col >= LCDCONSOLE_COLS)
67
  {
70
    {
68
    current_col = 0;
71
        current_col = 0;
69
    current_row++;
72
        current_row++;
70
  }
73
    }
71
  if (current_row >= LCDCONSOLE_ROWS)
74
    if (current_row >= LCDCONSOLE_ROWS)
72
  {
75
    {
73
    int offset = current_row - LCDCONSOLE_ROWS + 1;
76
        int offset = current_row - LCDCONSOLE_ROWS + 1;
74
    memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
77
        memcpy(&framebuf[LINEBYTES * OFFSETY], &framebuf[LINEBYTES * OFFSETY + ROWBYTES * offset],
75
           ROWBYTES * (LCDCONSOLE_ROWS - offset));
78
            ROWBYTES * (LCDCONSOLE_ROWS - offset));
76
    memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
79
        memset(&framebuf[LINEBYTES * OFFSETY + ROWBYTES * (LCDCONSOLE_ROWS - offset)],
77
           -1, ROWBYTES * offset);
80
            -1, ROWBYTES * offset);
78
    current_row = LCDCONSOLE_ROWS - 1;
81
        current_row = LCDCONSOLE_ROWS - 1;
79
  }
82
    }
80
  renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
83
    renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
81
             fgcolor, bgcolor, string, LINEBYTES);
84
        fgcolor, bgcolor, string, LINEBYTES);
82
}
85
}
83
 
86
 
84
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
87
void lcdconsole_puts_noblit(const char* string, int fgcolor, int bgcolor)
85
{
88
{
86
  while (*string) lcdconsole_putc(*string++, fgcolor, bgcolor);
89
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
87
}
90
}
88
 
91
 
89
void lcdconsole_update()
92
void lcdconsole_update()
90
{
93
{
-
 
94
    uint32_t mode = enter_critical_section();
-
 
95
    if (displaylcd_busy())
-
 
96
    {
-
 
97
        lcdconsole_needs_update = true;
-
 
98
        leave_critical_section(mode);
-
 
99
        return;
-
 
100
    }
-
 
101
    leave_critical_section(mode);
91
  displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
102
    displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
-
 
103
}
-
 
104
 
-
 
105
void lcdconsole_putc(char string, int fgcolor, int bgcolor)
-
 
106
{
-
 
107
    lcdconsole_putc_noblit(string, fgcolor, bgcolor);
-
 
108
    lcdconsole_update();
-
 
109
}
-
 
110
    
-
 
111
void lcdconsole_puts(const char* string, int fgcolor, int bgcolor)
-
 
112
{
-
 
113
    while (*string) lcdconsole_putc_noblit(*string++, fgcolor, bgcolor);
-
 
114
    lcdconsole_update();
-
 
115
}
-
 
116
 
-
 
117
void lcdconsole_callback()
-
 
118
{
-
 
119
    if (lcdconsole_needs_update)
-
 
120
    {
-
 
121
        displaylcd(0, LCD_WIDTH - 1, 0, LCD_HEIGHT - 1, framebuf, 0);
-
 
122
        lcdconsole_needs_update = false;
-
 
123
    }
92
}
124
}