summaryrefslogtreecommitdiff
path: root/video.c
blob: 3d9c49859c4717b9dd98dc33dc8106dd65968caa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* LCD controller driver for 680 project.
 *
 * Copyright 2010, Duncan Smith
 * GPL
 */

#include <graph.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;
}