Statistics
| Branch: | Revision:

root / hw / tcx.c @ 420557e8

History | View | Annotate | Download (4.9 kB)

1
/*
2
 * QEMU Sun4m System Emulator
3
 * 
4
 * Copyright (c) 2003-2004 Fabrice Bellard
5
 * 
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
#include "vl.h"
25

    
26
#define PHYS_JJ_TCX_FB        0x50800000        /* Start address, frame buffer body */
27
#define PHYS_JJ_TCX_0E        0x5E000000        /* Top address, one byte used. */
28

    
29
#define MAXX 1024
30
#define MAXY 768
31
#define XSZ (8*80)
32
#define YSZ (24*11)
33
#define XOFF (MAXX-XSZ)
34
#define YOFF (MAXY-YSZ)
35

    
36
#define DEBUG_VGA_MEM
37

    
38
typedef struct TCXState {
39
    uint8_t *vram_ptr;
40
    unsigned long vram_offset;
41
    unsigned int vram_size;
42
    DisplayState *ds;
43
} TCXState;
44

    
45
static TCXState *ts;
46

    
47
static int tcx_io_memory;
48

    
49
void vga_update_display()
50
{
51
    dpy_update(ts->ds, 0, 0, XSZ, YSZ);
52
}
53

    
54
static uint32_t tcx_mem_readb(void *opaque, target_phys_addr_t addr)
55
{
56
    TCXState *s = opaque;
57
    uint32_t saddr;
58
    unsigned int x, y;
59
    char *sptr;
60

    
61
    saddr = addr - PHYS_JJ_TCX_FB - YOFF*MAXX - XOFF;
62
    y = saddr / MAXX;
63
    x = saddr - y * MAXX;
64
    if (x < MAXX && y < MAXY) {
65
        sptr =         s->ds->data;
66
        if (sptr)
67
            return sptr[y * s->ds->linesize + x*4];
68
    }
69
    return 0;
70
}
71

    
72
static uint32_t tcx_mem_readw(void *opaque, target_phys_addr_t addr)
73
{
74
    uint32_t v;
75
#ifdef TARGET_WORDS_BIGENDIAN
76
    v = tcx_mem_readb(opaque, addr) << 8;
77
    v |= tcx_mem_readb(opaque, addr + 1);
78
#else
79
    v = tcx_mem_readb(opaque, addr);
80
    v |= tcx_mem_readb(opaque, addr + 1) << 8;
81
#endif
82
    return v;
83
}
84

    
85
static uint32_t tcx_mem_readl(void *opaque, target_phys_addr_t addr)
86
{
87
    uint32_t v;
88
#ifdef TARGET_WORDS_BIGENDIAN
89
    v = tcx_mem_readb(opaque, addr) << 24;
90
    v |= tcx_mem_readb(opaque, addr + 1) << 16;
91
    v |= tcx_mem_readb(opaque, addr + 2) << 8;
92
    v |= tcx_mem_readb(opaque, addr + 3);
93
#else
94
    v = tcx_mem_readb(opaque, addr);
95
    v |= tcx_mem_readb(opaque, addr + 1) << 8;
96
    v |= tcx_mem_readb(opaque, addr + 2) << 16;
97
    v |= tcx_mem_readb(opaque, addr + 3) << 24;
98
#endif
99
    return v;
100
}
101

    
102
/* called for accesses between 0xa0000 and 0xc0000 */
103
static void tcx_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
104
{
105
    TCXState *s = opaque;
106
    uint32_t saddr;
107
    unsigned int x, y;
108
    char *sptr;
109

    
110
    saddr = addr - PHYS_JJ_TCX_FB - YOFF*MAXX - XOFF;
111
    y = saddr / MAXX;
112
    x = saddr - y * MAXX;
113
    if (x < MAXX && y < MAXY) {
114
        sptr =         s->ds->data;
115
        if (sptr) {
116
            sptr[y * s->ds->linesize + x*4] = val;
117
            sptr[y * s->ds->linesize + x*4+1] = val;
118
            sptr[y * s->ds->linesize + x*4+2] = val;
119
            cpu_physical_memory_set_dirty(addr);
120
        }
121
    }
122
}
123

    
124
static void tcx_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
125
{
126
#ifdef TARGET_WORDS_BIGENDIAN
127
    tcx_mem_writeb(opaque, addr, (val >> 8) & 0xff);
128
    tcx_mem_writeb(opaque, addr + 1, val & 0xff);
129
#else
130
    tcx_mem_writeb(opaque, addr, val & 0xff);
131
    tcx_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
132
#endif
133
}
134

    
135
static void tcx_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
136
{
137
#ifdef TARGET_WORDS_BIGENDIAN
138
    tcx_mem_writeb(opaque, addr, (val >> 24) & 0xff);
139
    tcx_mem_writeb(opaque, addr + 1, (val >> 16) & 0xff);
140
    tcx_mem_writeb(opaque, addr + 2, (val >> 8) & 0xff);
141
    tcx_mem_writeb(opaque, addr + 3, val & 0xff);
142
#else
143
    tcx_mem_writeb(opaque, addr, val & 0xff);
144
    tcx_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
145
    tcx_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff);
146
    tcx_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff);
147
#endif
148
}
149

    
150
static CPUReadMemoryFunc *tcx_mem_read[3] = {
151
    tcx_mem_readb,
152
    tcx_mem_readw,
153
    tcx_mem_readl,
154
};
155

    
156
static CPUWriteMemoryFunc *tcx_mem_write[3] = {
157
    tcx_mem_writeb,
158
    tcx_mem_writew,
159
    tcx_mem_writel,
160
};
161

    
162
void tcx_init(DisplayState *ds)
163
{
164
    TCXState *s;
165

    
166
    s = qemu_mallocz(sizeof(TCXState));
167
    if (!s)
168
        return;
169
    s->ds = ds;
170
    ts = s;
171
    tcx_io_memory = cpu_register_io_memory(0, tcx_mem_read, tcx_mem_write, s);
172
    cpu_register_physical_memory(PHYS_JJ_TCX_FB, 0x100000, 
173
                                 tcx_io_memory);
174
    dpy_resize(s->ds, XSZ, YSZ);
175
}
176