diff options
Diffstat (limited to 'video.c')
| -rw-r--r-- | video.c | 78 |
1 files changed, 78 insertions, 0 deletions
@@ -0,0 +1,78 @@ +/* LCD controller driver for 680 project. + * + * Copyright 2010, Astrid Smith + * GPL + */ + +#include <graph.h> +#include <nostub.h> + +#define VIDEO_ROWMODE 0x01 +#define VIDEO_COLMODE 0x00 +char video_row; + +#define VIDEO_AUTOINC 0x02 +#define VIDEO_AUTODEC 0x00 +char video_increment; + +#define VIDEO_ENABLED 0x00 +#define VIDEO_DISABLED 0x20 +char video_enabled; + +#define VIDEO_6BIT 0x00 +#define VIDEO_8BIT 0x40 +char video_6bit; + +char video_busy; // Always 0 + +char video_cur_row; +char video_cur_col; + +void video_write(char); +char video_read(void); +void *video_compute_address(void); +int video_compute_shift(void); + +void video_write(char data) +{ + int shift = video_compute_shift(); + short int data_mask = ~(0xff00 >> shift); + short int data_dat = data >> (shift-8); + void *addr = video_compute_address(); + *((short int *)addr) &= data_mask; + *((short int *)addr) |= data_dat; + return; +} + +char video_read(void) +{ + int shift = video_compute_shift(); + void *addr = video_compute_address(); + short int data = *((short int *)addr); + data <<= (shift-8); + data &= 0xff; + return; +} + +void *video_compute_address() +{ + void *addr; + int off; + + addr = LCD_MEM; + addr += (video_cur_row) * (240 / 8); + + if (video_6bit == VIDEO_6BIT) + off = video_cur_col * 6 / 8; + else + off = video_cur_col; + return addr + off; +} + +int video_compute_shift() +{ + if (video_6bit == VIDEO_8BIT) + return 0; + + return (video_cur_col * 6) % 8; +} |
