summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-11-13 06:00:33 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2011-11-13 06:00:33 (GMT)
commit85199fd9322a0b2fc561f557dde7530812fccb20 (patch)
treeb369d178b30f6aca87762fc6dc0300b97a2f072e
parent139a9963c7397573499646763ede6c241ba4aafb (diff)
downloadabc8000-old-85199fd9322a0b2fc561f557dde7530812fccb20.zip
abc8000-old-85199fd9322a0b2fc561f557dde7530812fccb20.tar.gz
abc8000-old-85199fd9322a0b2fc561f557dde7530812fccb20.tar.bz2
abc8000-old-85199fd9322a0b2fc561f557dde7530812fccb20.tar.xz
sysrom: add screen text output routine, including hardware scroll
Add a routine to output text to the screen, including hardware scroll support.
-rw-r--r--data/sysrom/contty.c119
-rw-r--r--data/sysrom/exec.c8
-rw-r--r--data/sysrom/sysrom.h4
-rw-r--r--data/sysrom/sysrom.ld3
-rw-r--r--data/sysrom/sysstart.c11
5 files changed, 137 insertions, 8 deletions
diff --git a/data/sysrom/contty.c b/data/sysrom/contty.c
new file mode 100644
index 0000000..a88a3e2
--- /dev/null
+++ b/data/sysrom/contty.c
@@ -0,0 +1,119 @@
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+#include <ioreg.h>
+#include <sys/cpu.h>
+#include "sysrom.h"
+
+extern const unsigned char __sysfont[256][16];
+extern uint8_t __framebuf[];
+
+static struct con_state {
+ uint8_t *baseptr;
+ uint8_t *rowptr;
+ uint8_t *wrapptr;
+ uint16_t toprow;
+ uint16_t x, y;
+ uint8_t fg, bg;
+} cs;
+
+static inline void wait_for_vblank(void)
+{
+ while (readw(IO_VIDEO_YCTR) < 480)
+ ;
+}
+
+static void scroll(void)
+{
+ uint16_t rown;
+ uint32_t r0start;
+
+ cs.toprow += 16;
+ cs.baseptr += 640*16;
+ if (cs.baseptr >= cs.wrapptr) {
+ cs.baseptr -= 2*640*480;
+ cs.toprow -= 2*480;
+ }
+
+ if (cs.toprow <= 480) {
+ rown = -1;
+ } else {
+ rown = 480*2 - cs.toprow;
+ }
+
+ r0start = (size_t)cs.baseptr << 3;
+
+ memset(cs.rowptr, cs.bg, 640*16);
+
+ /* This really should be done by the vertical interrupt handler */
+ wait_for_vblank();
+
+ writel(r0start, IO_VIDEO_ROW0START);
+ writew(rown, IO_VIDEO_ROWN);
+}
+
+ssize_t syscon_write(int fd, const void *buf, size_t count)
+{
+ uint8_t c, px;
+ const uint8_t *pxp;
+ const uint8_t *p = buf;
+ uint8_t *q, *q0;
+ uint16_t i, j;
+ uint8_t fg = cs.fg;
+ uint8_t bg = cs.bg;
+ ssize_t n = 0;
+
+ (void)fd;
+
+ q0 = cs.rowptr + (cs.x << 3);
+
+ while (count--) {
+ c = *p++;
+
+ q = q0;
+ pxp = __sysfont[c];
+ for (j = 0; j < 16; j++) {
+ px = *pxp++;
+ for (i = 0; i < 8; i++) {
+ uint8_t v = (px & 0x80) ? fg : bg;
+ *q++ = v;
+ px <<= 1;
+ }
+ q += 640-8;
+ }
+
+ q0 += 8;
+ cs.x++;
+ if (cs.x >= 80) {
+ cs.x = 0;
+ cs.y++;
+ cs.rowptr += 640*16;
+ if (cs.rowptr >= cs.wrapptr)
+ cs.rowptr -= 2*640*480;
+ if (cs.y >= 30)
+ scroll();
+
+ q0 = cs.rowptr;
+ }
+ n++;
+ }
+
+ cs.fg -= 011;
+
+ return n;
+}
+
+void syscon_init(void)
+{
+ cs.baseptr = cs.rowptr = __framebuf;
+ cs.wrapptr = __framebuf + 2*640*480;
+ cs.toprow = 0;
+ cs.x = cs.y = 0;
+ cs.fg = 077;
+ cs.bg = 000;
+
+ wait_for_vblank();
+ writel((size_t)cs.baseptr << 3, IO_VIDEO_ROW0START);
+ writew(-1, IO_VIDEO_ROWN);
+ writel((size_t)__framebuf << 3, IO_VIDEO_ROWNSTART);
+}
diff --git a/data/sysrom/exec.c b/data/sysrom/exec.c
index b0419db..5d6e9d8 100644
--- a/data/sysrom/exec.c
+++ b/data/sysrom/exec.c
@@ -113,17 +113,17 @@ err:
* Try to load abc8000.sys, and run it if it exists
*/
static FATFS sd_fs;
-
-#define BOOT_ADDR 0x10000
+extern char __end_of_clear[]; /* Beginning of "free memory" */
void disk_boot(void)
{
static const char boot_filename[] = "abc8000.sys";
+ char * const load_addr = __end_of_clear;
printf("Mounting SD card...\n");
f_mount(0, &sd_fs);
- printf("Running boot file...\n");
- if (exec_file(boot_filename, (void *)BOOT_ADDR))
+ printf("Running boot file @ %p...\n", load_addr);
+ if (exec_file(boot_filename, load_addr))
printf("Boot file execution failed!\n");
}
diff --git a/data/sysrom/sysrom.h b/data/sysrom/sysrom.h
index 6d4ce5e..7c44d66 100644
--- a/data/sysrom/sysrom.h
+++ b/data/sysrom/sysrom.h
@@ -2,6 +2,7 @@
#define SYSROM_H
#include <klibc/compiler.h>
+#include <stddef.h>
#include <stdint.h>
#define ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
@@ -25,6 +26,9 @@ int sdcard_write_sectors(const void *buf, uint32_t lba, int count);
int exec_file(const char *filename, void *addr);
void disk_boot(void);
+ssize_t syscon_write(int fd, const void *buf, size_t count);
+void syscon_init(void);
+
void keyboard_init(void);
#endif /* SYSROM_H */
diff --git a/data/sysrom/sysrom.ld b/data/sysrom/sysrom.ld
index 8c78baf..cba6f74 100644
--- a/data/sysrom/sysrom.ld
+++ b/data/sysrom/sysrom.ld
@@ -62,8 +62,7 @@ SECTIONS
. = __end_of_copy + _ROM_BASE;
/*
- * First we have the data that will be copied to RAM,
- * starting with the exception vector
+ * Text that will be run directly out of ROM
*/
__text_lma = .;
.text : AT(__text_lma) {
diff --git a/data/sysrom/sysstart.c b/data/sysrom/sysstart.c
index 9ba9c58..7fccddf 100644
--- a/data/sysrom/sysstart.c
+++ b/data/sysrom/sysstart.c
@@ -190,7 +190,7 @@ static void irq_init(void)
cpu_set_spl(0);
}
-uint8_t __framebuf[2*480*640];
+uint8_t __framebuf[2*480*640] __attribute__((aligned(32)));
static void picture(void)
{
@@ -250,6 +250,8 @@ static void picture(void)
void sys_start(void)
{
+ int i;
+
printf("Hello C code!\n");
printf("Hello C code again, 2^8 = %d\n", 256);
@@ -257,7 +259,12 @@ void sys_start(void)
picture();
- disk_boot();
+ //disk_boot();
+
+ syscon_init();
+
+ for (i = 0; i < 1000; i++)
+ syscon_write(1, "Hello, World! ", 14);
monitor();
die();