x49gp/s3c2410_lcd.c

417 lines
9.6 KiB
C
Raw Normal View History

/* $Id: s3c2410_lcd.c,v 1.4 2008/12/11 12:18:17 ecd Exp $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <gtk/gtk.h>
#include <x49gp.h>
#include <x49gp_ui.h>
#include <s3c2410.h>
typedef struct {
uint32_t lcdcon1;
uint32_t lcdcon2;
uint32_t lcdcon3;
uint32_t lcdcon4;
uint32_t lcdcon5;
uint32_t lcdsaddr1;
uint32_t lcdsaddr2;
uint32_t lcdsaddr3;
uint32_t redlut;
uint32_t greenlut;
uint32_t bluelut;
uint32_t dithmode;
uint32_t tpal;
uint32_t lcdintpnd;
uint32_t lcdsrcpnd;
uint32_t lcdintmsk;
uint32_t lpcsel;
uint32_t __unknown_68;
unsigned int nr_regs;
s3c2410_offset_t *regs;
x49gp_t *x49gp;
} s3c2410_lcd_t;
static int
s3c2410_lcd_data_init(s3c2410_lcd_t *lcd)
{
s3c2410_offset_t regs[] = {
S3C2410_OFFSET(LCD, LCDCON1, 0x00000000, lcd->lcdcon1),
S3C2410_OFFSET(LCD, LCDCON2, 0x00000000, lcd->lcdcon2),
S3C2410_OFFSET(LCD, LCDCON3, 0x00000000, lcd->lcdcon3),
S3C2410_OFFSET(LCD, LCDCON4, 0x00000000, lcd->lcdcon4),
S3C2410_OFFSET(LCD, LCDCON5, 0x00000000, lcd->lcdcon5),
S3C2410_OFFSET(LCD, LCDSADDR1, 0x00000000, lcd->lcdsaddr1),
S3C2410_OFFSET(LCD, LCDSADDR2, 0x00000000, lcd->lcdsaddr2),
S3C2410_OFFSET(LCD, LCDSADDR3, 0x00000000, lcd->lcdsaddr3),
S3C2410_OFFSET(LCD, REDLUT, 0x00000000, lcd->redlut),
S3C2410_OFFSET(LCD, GREENLUT, 0x00000000, lcd->greenlut),
S3C2410_OFFSET(LCD, BLUELUT, 0x00000000, lcd->bluelut),
S3C2410_OFFSET(LCD, DITHMODE, 0x00000000, lcd->dithmode),
S3C2410_OFFSET(LCD, TPAL, 0x00000000, lcd->tpal),
S3C2410_OFFSET(LCD, LCDINTPND, 0x00000000, lcd->lcdintpnd),
S3C2410_OFFSET(LCD, LCDSRCPND, 0x00000000, lcd->lcdsrcpnd),
S3C2410_OFFSET(LCD, LCDINTMSK, 0x00000003, lcd->lcdintmsk),
S3C2410_OFFSET(LCD, LPCSEL, 0x00000004, lcd->lpcsel),
S3C2410_OFFSET(LCD, UNKNOWN_68, 0x00000000, lcd->__unknown_68)
};
memset(lcd, 0, sizeof(s3c2410_lcd_t));
lcd->regs = malloc(sizeof(regs));
if (NULL == lcd->regs) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
return -ENOMEM;
}
memcpy(lcd->regs, regs, sizeof(regs));
lcd->nr_regs = sizeof(regs) / sizeof(regs[0]);
return 0;
}
void
x49gp_schedule_lcd_update(x49gp_t *x49gp)
{
if (! x49gp_timer_pending(x49gp->lcd_timer)) {
x49gp_mod_timer(x49gp->lcd_timer,
x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL);
}
}
2017-10-26 12:12:16 +02:00
static int
x49gp_get_pixel_color(s3c2410_lcd_t *lcd, int x, int y)
{
uint32_t bank, addr, data, offset, pixel_offset;
int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5;
bank = (lcd->lcdsaddr1 << 1) & 0x7fc00000;
addr = bank | ((lcd->lcdsaddr1 << 1) & 0x003ffffe);
pixel_offset = (160 * y + x) * bits_per_pixel;
offset = (pixel_offset >> 3) & 0xfffffffc;
data = ldl_phys(addr + offset);
data >>= pixel_offset & 31;
data &= (1 << bits_per_pixel) - 1;
switch (bits_per_pixel) {
case 1:
return 15 * data;
case 2:
On behalf of: 3298 - Applied 23 patches by 3298: Misc changes, mostly fixes: - fix ./newconfig systems other than OSX (broke in c8b823f) - fix palette usage in 2-bit color mode (was broken ever since grayscale was implemented in 18e1003 and its improperly attributed copy f7913eb) - fix continuing from breakpoints in the debugger (never worked, was exposed when the debugger was enabled in 9c1f2ed) - restore the printf statements commented out in 9c1f2ed and hide them with #ifdefs instead - close the server socket after accepting a debugger connection to allow another simultaneous debug session to be started using the same TCP port - use the symbolic constant DEFAULT_GDBSTUB_PORT (already defined in gdb_stub.h as 1234) when starting the gdb server in main.c in place of the raw number 1234 - change Makefile to read the name of the firmware file from the file update.scp instead of hardcoding it; this allows users to switch to another firmware by simply pasting it along with its accompanying update.scp into the x49gp directory - Enhance port G (keyboard) handling to remember the value of output bits across periods with these bits configured as input This fixes interaction with HPGCC3 keyboard routines, and it also fixes keys with eint==7 (assuming the stock firmware is in use) needing a double-tap to work unless pressed very shortly after another keypress (the latter broke in b5f93ed) - Get rid of the deprecated function warning by switching from gdk_pixbuf_new_from_inline to gdk_pixbuf_new_from_data (based on code by chwdt) - Delete remaining now-redundant CVS files - Don't release all buttons anymore if there are still physical keys and/or the left mouse button are holding some down On the other hand, forcibly release all buttons when losing focus to avoid getting stuck in a state with buttons down when they are not held down by anything; this would happen due to missed events while not in focus - Add a context menu to the screen, containing only "Reset" and "Quit" items for now - Ensure that the files backing flash, sram, and s3c2410-sram exist and have the correct size when opening them Note that if the flash file does not exist, this will not fill it with the code that's supposed to be in there, obviously causing the calculator to crash. That's an improvement for later. - Allow the config system to fill not only numbers, but also strings (including filenames) with default values basename is excluded, but it's planned to be dropped entirely. - Add an "install" target to the Makefile - Implement a more generic command-line parser for substantially improved flexibility - Also adds a proper help option, though the manual referenced in the corresponding output (a manpage, hopefully) does not exist yet. - Drop the "basename" config property in favor of interpreting relative paths in the config as relative to the config file's location - Retire the "image" config property in favor of simply loading the image from next to the binary or from the install directory - Split the UI name property into name (affecting only the window title) and type (affecting the UI image and in the future also the default bootcode) properties - Change the default calculator type to the 50g everywhere, which probably matches today's user expectations better than the 49g+. - Create a flash file from the calculator model's appropriate boot file if it does not exist, relying on the bootcode to detect the absence of a firmware The bootcode will complain about the missing firmware and enter update mode, so the user needs to supply their favorite firmware version and point the bootcode's updater to it. The easiest way is probably pointing the emulated SD card at a directory containing the firmware and its accompanying update.scp file, and then starting the SD-based update. - Add SD mount / unmount options to the right-click / menu-key popup menu - Remove most of the old script-based config-generating system since the binary now has these capabilities as well - Add an applications menu item for installing - Keep some debug output on stderr and a huge vvfat.log file from showing up when not debugging x49gp itself - Allow (re-)connecting a debugger to a running session This is done through the right-click / menu-key popup menu. To avoid confusion due to the accidental clicks leading to an unresponsive interface (caused by waiting for the debugger to connect), this option is hidden unless option -d or its new companion -D (same as -d, but does not start the debug interface right away) is present. - Improved support for hardware keyboards - Update README.md, add manpage, rename other README files to TODO to reflect their contents
2018-05-07 23:32:14 +02:00
return 15 & (lcd->bluelut >> (4 * data));
2017-10-26 12:12:16 +02:00
default:
return data;
}
}
void
x49gp_lcd_update(x49gp_t *x49gp)
{
x49gp_ui_t *ui = x49gp->ui;
s3c2410_lcd_t *lcd = x49gp->s3c2410_lcd;
GdkRectangle rect;
2018-08-28 18:32:03 +02:00
GdkGC *gc;
2017-10-26 12:12:16 +02:00
int color, x, y;
if (!(lcd->lcdcon1 & 1)) {
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0],
ui->bg_pixmap,
ui->lcd_x_offset, ui->lcd_y_offset,
0, 0, ui->lcd_width, ui->lcd_height);
goto done;
}
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0],
ui->bg_pixmap,
ui->lcd_x_offset, ui->lcd_y_offset,
0, 0, ui->lcd_width, ui->lcd_height);
2017-10-26 12:12:16 +02:00
color = x49gp_get_pixel_color(lcd, 131, 0);
gdk_gc_set_rgb_fg_color(ui->ann_io_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_io_gc, TRUE, 236, 0, 15, 12);
color = x49gp_get_pixel_color(lcd, 131, 1);
gdk_gc_set_rgb_fg_color(ui->ann_left_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_left_gc, TRUE, 11, 0, 15, 12);
color = x49gp_get_pixel_color(lcd, 131, 2);
gdk_gc_set_rgb_fg_color(ui->ann_right_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_right_gc, TRUE, 56, 0, 15, 12);
color = x49gp_get_pixel_color(lcd, 131, 3);
gdk_gc_set_rgb_fg_color(ui->ann_alpha_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_alpha_gc, TRUE, 101, 0, 15, 12);
color = x49gp_get_pixel_color(lcd, 131, 4);
gdk_gc_set_rgb_fg_color(ui->ann_battery_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_battery_gc, TRUE, 146, 0, 15, 12);
color = x49gp_get_pixel_color(lcd, 131, 5);
gdk_gc_set_rgb_fg_color(ui->ann_busy_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_busy_gc, TRUE, 191, 0, 15, 12);
2018-08-28 18:32:03 +02:00
gc = gdk_gc_new(ui->lcd_canvas->window);
2017-10-26 12:12:16 +02:00
for (y = 0; y < (ui->lcd_height - ui->lcd_top_margin) / 2; y++) {
for (x = 0; x < ui->lcd_width / 2; x++) {
color = x49gp_get_pixel_color(lcd, x, y);
2018-08-28 18:32:03 +02:00
gdk_gc_set_rgb_fg_color(gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color]));
gdk_draw_rectangle(ui->lcd_pixmap, gc, TRUE,
2 * x, 2 * y + ui->lcd_top_margin, 2, 2);
}
}
2018-08-28 18:32:03 +02:00
g_object_unref(gc);
done:
rect.x = 0;
rect.y = 0;
rect.width = ui->lcd_width;
rect.height = ui->lcd_height;
gdk_window_invalidate_rect(ui->lcd_canvas->window, &rect, FALSE);
}
static uint32_t
s3c2410_lcd_read(void *opaque, target_phys_addr_t offset)
{
s3c2410_lcd_t *lcd = opaque;
s3c2410_offset_t *reg;
uint32_t linecnt;
if (! S3C2410_OFFSET_OK(lcd, offset)) {
return ~(0);
}
reg = S3C2410_OFFSET_ENTRY(lcd, offset);
switch (offset) {
case S3C2410_LCD_LCDCON1:
linecnt = (lcd->lcdcon1 >> 18) & 0x3ff;
if (linecnt > 0) {
linecnt--;
} else {
linecnt = (lcd->lcdcon2 >> 14) & 0x3ff;
}
lcd->lcdcon1 &= ~(0x3ff << 18);
lcd->lcdcon1 |= (linecnt << 18);
}
#ifdef DEBUG_S3C2410_LCD
printf("read %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-lcd", S3C2410_LCD_BASE,
reg->name, (unsigned long) offset, *(reg->datap));
#endif
return *(reg->datap);
}
static void
s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{
s3c2410_lcd_t *lcd = opaque;
x49gp_t *x49gp = lcd->x49gp;
s3c2410_offset_t *reg;
if (! S3C2410_OFFSET_OK(lcd, offset)) {
return;
}
reg = S3C2410_OFFSET_ENTRY(lcd, offset);
#ifdef DEBUG_S3C2410_LCD
printf("write %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-lcd", S3C2410_LCD_BASE,
reg->name, (unsigned long) offset, data);
#endif
switch (offset) {
case S3C2410_LCD_LCDCON1:
if ((lcd->lcdcon1 ^ data) & 1) {
x49gp_schedule_lcd_update(x49gp);
}
lcd->lcdcon1 = (lcd->lcdcon1 & (0x3ff << 18)) |
(data & ~(0x3ff << 18));
break;
default:
*(reg->datap) = data;
break;
}
}
static int
s3c2410_lcd_load(x49gp_module_t *module, GKeyFile *key)
{
s3c2410_lcd_t *lcd = module->user_data;
s3c2410_offset_t *reg;
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
for (i = 0; i < lcd->nr_regs; i++) {
reg = &lcd->regs[i];
if (NULL == reg->name)
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
return error;
}
static int
s3c2410_lcd_save(x49gp_module_t *module, GKeyFile *key)
{
s3c2410_lcd_t *lcd = module->user_data;
s3c2410_offset_t *reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
for (i = 0; i < lcd->nr_regs; i++) {
reg = &lcd->regs[i];
if (NULL == reg->name)
continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap));
}
return 0;
}
static int
s3c2410_lcd_reset(x49gp_module_t *module, x49gp_reset_t reset)
{
s3c2410_lcd_t *lcd = module->user_data;
s3c2410_offset_t *reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
for (i = 0; i < lcd->nr_regs; i++) {
reg = &lcd->regs[i];
if (NULL == reg->name)
continue;
*(reg->datap) = reg->reset;
}
return 0;
}
static CPUReadMemoryFunc *s3c2410_lcd_readfn[] =
{
s3c2410_lcd_read,
s3c2410_lcd_read,
s3c2410_lcd_read
};
static CPUWriteMemoryFunc *s3c2410_lcd_writefn[] =
{
s3c2410_lcd_write,
s3c2410_lcd_write,
s3c2410_lcd_write
};
static int
s3c2410_lcd_init(x49gp_module_t *module)
{
s3c2410_lcd_t *lcd;
int iotype;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
lcd = malloc(sizeof(s3c2410_lcd_t));
if (NULL == lcd) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
return -ENOMEM;
}
if (s3c2410_lcd_data_init(lcd)) {
free(lcd);
return -ENOMEM;
}
module->user_data = lcd;
module->x49gp->s3c2410_lcd = lcd;
lcd->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_lcd_readfn,
s3c2410_lcd_writefn, lcd);
On behalf of: 3298 - Applied 23 patches by 3298: Misc changes, mostly fixes: - fix ./newconfig systems other than OSX (broke in c8b823f) - fix palette usage in 2-bit color mode (was broken ever since grayscale was implemented in 18e1003 and its improperly attributed copy f7913eb) - fix continuing from breakpoints in the debugger (never worked, was exposed when the debugger was enabled in 9c1f2ed) - restore the printf statements commented out in 9c1f2ed and hide them with #ifdefs instead - close the server socket after accepting a debugger connection to allow another simultaneous debug session to be started using the same TCP port - use the symbolic constant DEFAULT_GDBSTUB_PORT (already defined in gdb_stub.h as 1234) when starting the gdb server in main.c in place of the raw number 1234 - change Makefile to read the name of the firmware file from the file update.scp instead of hardcoding it; this allows users to switch to another firmware by simply pasting it along with its accompanying update.scp into the x49gp directory - Enhance port G (keyboard) handling to remember the value of output bits across periods with these bits configured as input This fixes interaction with HPGCC3 keyboard routines, and it also fixes keys with eint==7 (assuming the stock firmware is in use) needing a double-tap to work unless pressed very shortly after another keypress (the latter broke in b5f93ed) - Get rid of the deprecated function warning by switching from gdk_pixbuf_new_from_inline to gdk_pixbuf_new_from_data (based on code by chwdt) - Delete remaining now-redundant CVS files - Don't release all buttons anymore if there are still physical keys and/or the left mouse button are holding some down On the other hand, forcibly release all buttons when losing focus to avoid getting stuck in a state with buttons down when they are not held down by anything; this would happen due to missed events while not in focus - Add a context menu to the screen, containing only "Reset" and "Quit" items for now - Ensure that the files backing flash, sram, and s3c2410-sram exist and have the correct size when opening them Note that if the flash file does not exist, this will not fill it with the code that's supposed to be in there, obviously causing the calculator to crash. That's an improvement for later. - Allow the config system to fill not only numbers, but also strings (including filenames) with default values basename is excluded, but it's planned to be dropped entirely. - Add an "install" target to the Makefile - Implement a more generic command-line parser for substantially improved flexibility - Also adds a proper help option, though the manual referenced in the corresponding output (a manpage, hopefully) does not exist yet. - Drop the "basename" config property in favor of interpreting relative paths in the config as relative to the config file's location - Retire the "image" config property in favor of simply loading the image from next to the binary or from the install directory - Split the UI name property into name (affecting only the window title) and type (affecting the UI image and in the future also the default bootcode) properties - Change the default calculator type to the 50g everywhere, which probably matches today's user expectations better than the 49g+. - Create a flash file from the calculator model's appropriate boot file if it does not exist, relying on the bootcode to detect the absence of a firmware The bootcode will complain about the missing firmware and enter update mode, so the user needs to supply their favorite firmware version and point the bootcode's updater to it. The easiest way is probably pointing the emulated SD card at a directory containing the firmware and its accompanying update.scp file, and then starting the SD-based update. - Add SD mount / unmount options to the right-click / menu-key popup menu - Remove most of the old script-based config-generating system since the binary now has these capabilities as well - Add an applications menu item for installing - Keep some debug output on stderr and a huge vvfat.log file from showing up when not debugging x49gp itself - Allow (re-)connecting a debugger to a running session This is done through the right-click / menu-key popup menu. To avoid confusion due to the accidental clicks leading to an unresponsive interface (caused by waiting for the debugger to connect), this option is hidden unless option -d or its new companion -D (same as -d, but does not start the debug interface right away) is present. - Improved support for hardware keyboards - Update README.md, add manpage, rename other README files to TODO to reflect their contents
2018-05-07 23:32:14 +02:00
#ifdef DEBUG_S3C2410_LCD
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
#endif
cpu_register_physical_memory(S3C2410_LCD_BASE, S3C2410_MAP_SIZE, iotype);
return 0;
}
static int
s3c2410_lcd_exit(x49gp_module_t *module)
{
s3c2410_lcd_t *lcd;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
if (module->user_data) {
lcd = module->user_data;
if (lcd->regs)
free(lcd->regs);
free(lcd);
}
x49gp_module_unregister(module);
free(module);
return 0;
}
int
x49gp_s3c2410_lcd_init(x49gp_t *x49gp)
{
x49gp_module_t *module;
if (x49gp_module_init(x49gp, "s3c2410-lcd",
s3c2410_lcd_init,
s3c2410_lcd_exit,
s3c2410_lcd_reset,
s3c2410_lcd_load,
s3c2410_lcd_save,
NULL, &module)) {
return -1;
}
return x49gp_module_register(module);
}