1 |
/* |
2 |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: dev_malta_lcd.c,v 1.9 2007/02/03 20:14:23 debug Exp $ |
29 |
* |
30 |
* Malta (evbmips) LCD thingy. Mostly a dummy device. |
31 |
*/ |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <stdlib.h> |
35 |
#include <string.h> |
36 |
|
37 |
#include "cpu.h" |
38 |
#include "device.h" |
39 |
#include "emul.h" |
40 |
#include "machine.h" |
41 |
#include "memory.h" |
42 |
#include "misc.h" |
43 |
|
44 |
|
45 |
#define DEV_MALTA_LCD_LENGTH 0x80 |
46 |
#define MALTA_LCD_TICK_SHIFT 15 |
47 |
#define LCD_LEN 8 |
48 |
|
49 |
struct malta_lcd_data { |
50 |
int display_modified; |
51 |
unsigned char display[LCD_LEN]; |
52 |
}; |
53 |
|
54 |
|
55 |
|
56 |
/* |
57 |
* dev_malta_lcd_tick(): |
58 |
*/ |
59 |
void dev_malta_lcd_tick(struct cpu *cpu, void *extra) |
60 |
{ |
61 |
struct malta_lcd_data *d = extra; |
62 |
int i; |
63 |
|
64 |
if (d->display_modified == 0) |
65 |
return; |
66 |
if (d->display_modified == 1) { |
67 |
d->display_modified = 2; |
68 |
return; |
69 |
} |
70 |
debug("[ malta_lcd: "); |
71 |
for (i=0; i<LCD_LEN; i++) |
72 |
if (d->display[i] >= ' ') |
73 |
debug("%c", d->display[i]); |
74 |
debug(" ]\n"); |
75 |
d->display_modified = 0; |
76 |
} |
77 |
|
78 |
|
79 |
/* |
80 |
* dev_malta_lcd_access(): |
81 |
*/ |
82 |
DEVICE_ACCESS(malta_lcd) |
83 |
{ |
84 |
struct malta_lcd_data *d = (struct malta_lcd_data *) extra; |
85 |
uint64_t idata = 0, odata = 0; |
86 |
int i; |
87 |
|
88 |
if (writeflag == MEM_WRITE) |
89 |
idata = memory_readmax64(cpu, data, len); |
90 |
|
91 |
switch (relative_addr) { |
92 |
case 0x18: |
93 |
case 0x20: |
94 |
case 0x28: |
95 |
case 0x30: |
96 |
case 0x38: |
97 |
case 0x40: |
98 |
case 0x48: |
99 |
case 0x50: |
100 |
i = (relative_addr - 0x18) / 8; |
101 |
if (writeflag == MEM_WRITE) { |
102 |
d->display[i] = idata; |
103 |
d->display_modified = 1; |
104 |
} else |
105 |
odata = d->display[i]; |
106 |
break; |
107 |
default:if (writeflag == MEM_WRITE) { |
108 |
fatal("[ malta_lcd: unimplemented write to " |
109 |
"offset 0x%x: data=0x%02x ]\n", (int) |
110 |
relative_addr, (int)idata); |
111 |
} else { |
112 |
fatal("[ malta_lcd: unimplemented read from " |
113 |
"offset 0x%x ]\n", (int)relative_addr); |
114 |
} |
115 |
} |
116 |
|
117 |
if (writeflag == MEM_READ) |
118 |
memory_writemax64(cpu, data, len, odata); |
119 |
|
120 |
return 1; |
121 |
} |
122 |
|
123 |
|
124 |
DEVINIT(malta_lcd) |
125 |
{ |
126 |
struct malta_lcd_data *d = malloc(sizeof(struct malta_lcd_data)); |
127 |
|
128 |
if (d == NULL) { |
129 |
fprintf(stderr, "out of memory\n"); |
130 |
exit(1); |
131 |
} |
132 |
memset(d, 0, sizeof(struct malta_lcd_data)); |
133 |
|
134 |
memory_device_register(devinit->machine->memory, devinit->name, |
135 |
devinit->addr, DEV_MALTA_LCD_LENGTH, |
136 |
dev_malta_lcd_access, (void *)d, DM_DEFAULT, NULL); |
137 |
|
138 |
machine_add_tickfunction(devinit->machine, dev_malta_lcd_tick, |
139 |
d, MALTA_LCD_TICK_SHIFT, 0.0); |
140 |
|
141 |
return 1; |
142 |
} |
143 |
|