summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-06-12 00:51:04 +0200
committerUros Majstorovic <majstor@majstor.org>2020-06-12 00:51:04 +0200
commite5fcdeda041831cb326f1d1963c0651b78041788 (patch)
tree3763f5c596b068ec7b3a71c1db02f6c9936a3bcb /code/fe310/eos/eve
parent6d868629c96f53358f1b7e2f6ac687d7b7195b35 (diff)
implemented font metrics
Diffstat (limited to 'code/fe310/eos/eve')
-rw-r--r--code/fe310/eos/eve/eve.c26
-rw-r--r--code/fe310/eos/eve/eve.h3
-rw-r--r--code/fe310/eos/eve/screen/font.c9
-rw-r--r--code/fe310/eos/eve/screen/font.h3
-rw-r--r--code/fe310/eos/eve/widget/text.c12
5 files changed, 43 insertions, 10 deletions
diff --git a/code/fe310/eos/eve/eve.c b/code/fe310/eos/eve/eve.c
index 0ab5427..1db5744 100644
--- a/code/fe310/eos/eve/eve.c
+++ b/code/fe310/eos/eve/eve.c
@@ -70,6 +70,28 @@ void eve_write32(uint32_t addr, uint32_t data) {
eve_spi_cs_clear();
}
+void eve_readb(uint32_t addr, uint8_t *b, size_t size) {
+ int i;
+
+ eve_spi_cs_set();
+ eve_spi_xchg32(addr << 8, 0);
+ for (i=0; i<size; i++) {
+ b[i] = eve_spi_xchg8(0, 0);
+ }
+ eve_spi_cs_clear();
+}
+
+void eve_writeb(uint32_t addr, uint8_t *b, size_t size) {
+ int i;
+
+ eve_spi_cs_set();
+ eve_spi_xchg24(addr | EVE_MEM_WRITE, 0);
+ for (i=0; i<size; i++) {
+ eve_spi_xchg8(b[i], 0);
+ }
+ eve_spi_cs_clear();
+}
+
static void _dl_inc(uint32_t i) {
_dl_addr += i;
}
@@ -316,9 +338,9 @@ static int _init(void) {
/* do not set PCLK yet - wait for just after the first display list */
/* disable Audio */
- eve_write8(REG_VOL_PB, 0x00); /* turn recorded audio volume down */
+ eve_write16(REG_SOUND, 0x0000); /* set synthesizer to silence */
eve_write8(REG_VOL_SOUND, 0x00); /* turn synthesizer volume off */
- eve_write16(REG_SOUND, 0x6000); /* set synthesizer to mute */
+ eve_write8(REG_VOL_PB, 0x00); /* turn recorded audio volume off */
/* write a basic display-list to get things started */
eve_dl_start(EVE_RAM_DL);
diff --git a/code/fe310/eos/eve/eve.h b/code/fe310/eos/eve/eve.h
index c27d81f..5fd58df 100644
--- a/code/fe310/eos/eve/eve.h
+++ b/code/fe310/eos/eve/eve.h
@@ -31,6 +31,9 @@ void eve_write8(uint32_t addr, uint8_t data);
void eve_write16(uint32_t addr, uint16_t data);
void eve_write32(uint32_t addr, uint32_t data);
+void eve_readb(uint32_t addr, uint8_t *b, size_t size);
+void eve_writeb(uint32_t addr, uint8_t *b, size_t size);
+
void eve_dl_start(uint32_t addr);
void eve_dl_write(uint32_t dl);
void eve_dl_swap(void);
diff --git a/code/fe310/eos/eve/screen/font.c b/code/fe310/eos/eve/screen/font.c
index 26e7cf0..1be462d 100644
--- a/code/fe310/eos/eve/screen/font.c
+++ b/code/fe310/eos/eve/screen/font.c
@@ -4,14 +4,21 @@
#include "font.h"
void eve_font_init(EVEFont *font, uint8_t font_id) {
+ uint32_t p;
+
+ p = eve_read32(EVE_ROM_FONT_ADDR);
+ p += (148 * (font_id - 16));
font->id = font_id;
+ font->w = eve_read32(p + 136);
+ font->h = eve_read32(p + 140);
+ eve_readb(p, font->w_ch, 128);
}
uint16_t eve_font_string_width(EVEFont *font, char *s) {
uint16_t r = 0;
while (*s) {
- r += font->w[*s];
+ r += font->w_ch[*s];
s++;
}
return r;
diff --git a/code/fe310/eos/eve/screen/font.h b/code/fe310/eos/eve/screen/font.h
index 24b745e..a46c942 100644
--- a/code/fe310/eos/eve/screen/font.h
+++ b/code/fe310/eos/eve/screen/font.h
@@ -2,8 +2,9 @@
typedef struct EVEFont {
uint8_t id;
- uint8_t w[128];
+ uint8_t w;
uint8_t h;
+ uint8_t w_ch[128];
} EVEFont;
void eve_font_init(EVEFont *font, uint8_t font_id);
diff --git a/code/fe310/eos/eve/widget/text.c b/code/fe310/eos/eve/widget/text.c
index 834729f..ae83656 100644
--- a/code/fe310/eos/eve/widget/text.c
+++ b/code/fe310/eos/eve/widget/text.c
@@ -284,7 +284,7 @@ void eve_textw_putc(void *_page, int c) {
switch (c) {
case CH_BS:
if (cursor1->ch > 0) {
- cursor1->x -= widget->font->w[*(text - 1)];
+ cursor1->x -= widget->font->w_ch[*(text - 1)];
memmove(text - 1, text, widget->text_len - cursor1->ch + 1);
widget->text_len--;
cursor1->ch--;
@@ -300,7 +300,7 @@ void eve_textw_putc(void *_page, int c) {
break;
default:
if (widget->text_len < (widget->text_size - 1)) {
- cursor1->x += widget->font->w[c];
+ cursor1->x += widget->font->w_ch[c];
memmove(text + 1, text, widget->text_len - cursor1->ch + 1);
*text = c;
widget->text_len++;
@@ -345,7 +345,7 @@ int eve_textw_update(EVETextWidget *widget, EVEPage *page, uint16_t line) {
line_b = LINE_EMPTY;
for (i=LINE_START(widget, line); i<widget->text_size; i++) {
ch = widget->text[i];
- ch_w = widget->font->w[ch];
+ ch_w = widget->font->w_ch[ch];
if (ch <= 0x20) {
if ((ch == '\n') || (ch == '\0')) {
if (widget->line[line] == i) return line;
@@ -406,7 +406,7 @@ void eve_textw_cursor_update(EVETextWidget *widget, EVETextCursor *cursor) {
x = 0;
for (i=LINE_START(widget, cursor->line); i<LINE_END(widget, cursor->line); i++) {
if (cursor->ch == i) break;
- x += widget->font->w[widget->text[i]];
+ x += widget->font->w_ch[widget->text[i]];
}
cursor->x = x;
}
@@ -430,12 +430,12 @@ void eve_textw_cursor_set(EVETextWidget *widget, EVETextCursor *cursor, uint8_t
_x = 0;
_d = x;
for (i=LINE_START(widget, cursor->line); i<LINE_END(widget, cursor->line); i++) {
- _x += widget->font->w[widget->text[i]];
+ _x += widget->font->w_ch[widget->text[i]];
if (_x >= x) {
if (_x - x < _d) {
i++;
} else {
- _x -= widget->font->w[widget->text[i]];
+ _x -= widget->font->w_ch[widget->text[i]];
}
break;
} else {