dev_malta_lcd.cc Source File

Back to the index.

dev_malta_lcd.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2009 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  * COMMENT: Malta (evbmips) LCD display
29  *
30  * TODO: Write output to somewhere else, not just as a debug message.
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 #include "thirdparty/maltareg.h"
45 
46 
47 #define DEV_MALTA_LCD_LENGTH 0x80
48 #define MALTA_LCD_TICK_SHIFT 16
49 #define LCD_LEN 8
50 
52  uint64_t base_addr;
53 
55  unsigned char display[LCD_LEN];
56 };
57 
58 
59 DEVICE_TICK(malta_lcd)
60 {
61  struct malta_lcd_data *d = (struct malta_lcd_data *) 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 
71  debug("[ malta_lcd: \"");
72  for (i=0; i<LCD_LEN; i++)
73  if (d->display[i] >= ' ')
74  debug("%c", d->display[i]);
75  else
76  debug("?");
77  debug("\" ]\n");
78 
79  d->display_modified = 0;
80 }
81 
82 
83 DEVICE_ACCESS(malta_lcd)
84 {
85  struct malta_lcd_data *d = (struct malta_lcd_data *) extra;
86  uint64_t idata = 0, odata = 0;
87  int pos;
88 
89  if (writeflag == MEM_WRITE)
90  idata = memory_readmax64(cpu, data, len);
91 
92  relative_addr += d->base_addr;
93 
94  switch (relative_addr) {
95 
104  pos = (relative_addr - MALTA_ASCII_BASE) / 8;
105  if (writeflag == MEM_WRITE) {
106  d->display[pos] = idata;
107  d->display_modified = 1;
108  } else {
109  odata = d->display[pos];
110  }
111  break;
112 
113  default:
114  if (writeflag == MEM_WRITE) {
115  fatal("[ malta_lcd: unimplemented write to "
116  "offset 0x%x: data=0x%02x ]\n", (int)
117  relative_addr, (int)idata);
118  } else {
119  fatal("[ malta_lcd: unimplemented read from "
120  "offset 0x%x ]\n", (int)relative_addr);
121  }
122  }
123 
124  if (writeflag == MEM_READ)
125  memory_writemax64(cpu, data, len, odata);
126 
127  return 1;
128 }
129 
130 
131 DEVINIT(malta_lcd)
132 {
133  struct malta_lcd_data *d;
134 
135  CHECK_ALLOCATION(d = (struct malta_lcd_data *) malloc(sizeof(struct malta_lcd_data)));
136  memset(d, 0, sizeof(struct malta_lcd_data));
137 
138  d->base_addr = devinit->addr;
139 
142  dev_malta_lcd_access, (void *)d, DM_DEFAULT, NULL);
143 
144  machine_add_tickfunction(devinit->machine, dev_malta_lcd_tick,
146 
147  return 1;
148 }
149 
LCD_LEN
#define LCD_LEN
Definition: dev_malta_lcd.cc:49
data
u_short data
Definition: siireg.h:79
malta_lcd_data::display_modified
int display_modified
Definition: dev_malta_lcd.cc:54
malta_lcd_data
Definition: dev_malta_lcd.cc:51
debug
#define debug
Definition: dev_adb.cc:57
DEV_MALTA_LCD_LENGTH
#define DEV_MALTA_LCD_LENGTH
Definition: dev_malta_lcd.cc:47
devinit::addr
uint64_t addr
Definition: device.h:46
memory_device_register
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
MEM_READ
#define MEM_READ
Definition: memory.h:116
DM_DEFAULT
#define DM_DEFAULT
Definition: memory.h:130
devinit::machine
struct machine * machine
Definition: device.h:41
MALTA_ASCIIPOS4
#define MALTA_ASCIIPOS4
Definition: maltareg.h:158
device.h
MEM_WRITE
#define MEM_WRITE
Definition: memory.h:117
maltareg.h
MALTA_ASCIIPOS6
#define MALTA_ASCIIPOS6
Definition: maltareg.h:160
machine_add_tickfunction
void machine_add_tickfunction(struct machine *machine, void(*func)(struct cpu *, void *), void *extra, int clockshift)
Definition: machine.cc:280
malta_lcd_data::display
unsigned char display[LCD_LEN]
Definition: dev_malta_lcd.cc:55
fatal
void fatal(const char *fmt,...)
Definition: main.cc:152
MALTA_ASCIIPOS2
#define MALTA_ASCIIPOS2
Definition: maltareg.h:156
MALTA_ASCIIPOS7
#define MALTA_ASCIIPOS7
Definition: maltareg.h:161
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
MALTA_ASCIIPOS5
#define MALTA_ASCIIPOS5
Definition: maltareg.h:159
machine.h
MALTA_LCD_TICK_SHIFT
#define MALTA_LCD_TICK_SHIFT
Definition: dev_malta_lcd.cc:48
DEVINIT
DEVINIT(malta_lcd)
Definition: dev_malta_lcd.cc:131
devinit::name
char * name
Definition: device.h:43
emul.h
devinit
Definition: device.h:40
cpu.h
MALTA_ASCII_BASE
#define MALTA_ASCII_BASE
Definition: maltareg.h:153
machine::memory
struct memory * memory
Definition: machine.h:126
DEVICE_TICK
DEVICE_TICK(malta_lcd)
Definition: dev_malta_lcd.cc:59
DEVICE_ACCESS
DEVICE_ACCESS(malta_lcd)
Definition: dev_malta_lcd.cc:83
MALTA_ASCIIPOS0
#define MALTA_ASCIIPOS0
Definition: maltareg.h:154
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
malta_lcd_data::base_addr
uint64_t base_addr
Definition: dev_malta_lcd.cc:52
cpu
Definition: cpu.h:326
MALTA_ASCIIPOS3
#define MALTA_ASCIIPOS3
Definition: maltareg.h:157
memory.h
MALTA_ASCIIPOS1
#define MALTA_ASCIIPOS1
Definition: maltareg.h:155
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18