| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |  * QEMU TCX Frame buffer | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |  * Copyright (c) 2003-2005 Fabrice Bellard | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-25 10:04:17 +02:00
										 |  |  | #include "qemu-common.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-28 12:06:30 +01:00
										 |  |  | #include "ui/console.h"
 | 
					
						
							|  |  |  | #include "ui/pixel_ops.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  | #include "hw/loader.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/sysbus.h"
 | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  | #define TCX_ROM_FILE "QEMU,tcx.bin"
 | 
					
						
							|  |  |  | #define FCODE_MAX_ROM_SIZE 0x10000
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | #define MAXX 1024
 | 
					
						
							|  |  |  | #define MAXY 768
 | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  | #define TCX_DAC_NREGS 16
 | 
					
						
							| 
									
										
										
										
											2007-05-06 17:39:55 +00:00
										 |  |  | #define TCX_THC_NREGS_8  0x081c
 | 
					
						
							|  |  |  | #define TCX_THC_NREGS_24 0x1000
 | 
					
						
							|  |  |  | #define TCX_TEC_NREGS    0x1000
 | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 01:13:54 +02:00
										 |  |  | #define TYPE_TCX "SUNW,tcx"
 | 
					
						
							|  |  |  | #define TCX(obj) OBJECT_CHECK(TCXState, (obj), TYPE_TCX)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | typedef struct TCXState { | 
					
						
							| 
									
										
										
										
											2013-07-25 01:13:54 +02:00
										 |  |  |     SysBusDevice parent_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     QemuConsole *con; | 
					
						
							| 
									
										
										
										
											2004-10-04 21:23:09 +00:00
										 |  |  |     uint8_t *vram; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     uint32_t *vram24, *cplane; | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  |     hwaddr prom_addr; | 
					
						
							|  |  |  |     MemoryRegion rom; | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     MemoryRegion vram_mem; | 
					
						
							|  |  |  |     MemoryRegion vram_8bit; | 
					
						
							|  |  |  |     MemoryRegion vram_24bit; | 
					
						
							|  |  |  |     MemoryRegion vram_cplane; | 
					
						
							|  |  |  |     MemoryRegion dac; | 
					
						
							|  |  |  |     MemoryRegion tec; | 
					
						
							|  |  |  |     MemoryRegion thc24; | 
					
						
							|  |  |  |     MemoryRegion thc8; | 
					
						
							|  |  |  |     ram_addr_t vram24_offset, cplane_offset; | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  |     uint32_t vram_size; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |     uint32_t palette[256]; | 
					
						
							| 
									
										
										
										
											2011-08-07 19:13:24 +00:00
										 |  |  |     uint8_t r[256], g[256], b[256]; | 
					
						
							|  |  |  |     uint16_t width, height, depth; | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     uint8_t dac_index, dac_state; | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } TCXState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  | static void tcx_set_dirty(TCXState *s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-16 16:04:59 +00:00
										 |  |  |     memory_region_set_dirty(&s->vram_mem, 0, MAXX * MAXY); | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void tcx24_set_dirty(TCXState *s) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-16 16:04:59 +00:00
										 |  |  |     memory_region_set_dirty(&s->vram_mem, s->vram24_offset, MAXX * MAXY * 4); | 
					
						
							|  |  |  |     memory_region_set_dirty(&s->vram_mem, s->cplane_offset, MAXX * MAXY * 4); | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-04-09 01:06:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  | static void update_palette_entries(TCXState *s, int start, int end) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     DisplaySurface *surface = qemu_console_surface(s->con); | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (i = start; i < end; i++) { | 
					
						
							|  |  |  |         switch (surface_bits_per_pixel(surface)) { | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |         default: | 
					
						
							|  |  |  |         case 8: | 
					
						
							|  |  |  |             s->palette[i] = rgb_to_pixel8(s->r[i], s->g[i], s->b[i]); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 15: | 
					
						
							| 
									
										
										
										
											2009-01-15 22:07:16 +00:00
										 |  |  |             s->palette[i] = rgb_to_pixel15(s->r[i], s->g[i], s->b[i]); | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case 16: | 
					
						
							| 
									
										
										
										
											2009-01-15 22:07:16 +00:00
										 |  |  |             s->palette[i] = rgb_to_pixel16(s->r[i], s->g[i], s->b[i]); | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case 32: | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |             if (is_surface_bgr(surface)) { | 
					
						
							| 
									
										
										
										
											2009-03-13 15:02:13 +00:00
										 |  |  |                 s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]); | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-03-13 15:02:13 +00:00
										 |  |  |                 s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]); | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  |     if (s->depth == 24) { | 
					
						
							|  |  |  |         tcx24_set_dirty(s); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         tcx_set_dirty(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  | static void tcx_draw_line32(TCXState *s1, uint8_t *d, | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                             const uint8_t *s, int width) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     int x; | 
					
						
							|  |  |  |     uint8_t val; | 
					
						
							| 
									
										
										
										
											2006-12-21 17:24:45 +00:00
										 |  |  |     uint32_t *p = (uint32_t *)d; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for(x = 0; x < width; x++) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         val = *s++; | 
					
						
							| 
									
										
										
										
											2006-12-21 17:24:45 +00:00
										 |  |  |         *p++ = s1->palette[val]; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  | static void tcx_draw_line16(TCXState *s1, uint8_t *d, | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                             const uint8_t *s, int width) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int x; | 
					
						
							|  |  |  |     uint8_t val; | 
					
						
							| 
									
										
										
										
											2006-12-21 17:24:45 +00:00
										 |  |  |     uint16_t *p = (uint16_t *)d; | 
					
						
							| 
									
										
										
										
											2004-10-04 21:23:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     for(x = 0; x < width; x++) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         val = *s++; | 
					
						
							| 
									
										
										
										
											2006-12-21 17:24:45 +00:00
										 |  |  |         *p++ = s1->palette[val]; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  | static void tcx_draw_line8(TCXState *s1, uint8_t *d, | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |                            const uint8_t *s, int width) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     int x; | 
					
						
							|  |  |  |     uint8_t val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for(x = 0; x < width; x++) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         val = *s++; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |         *d++ = s1->palette[val]; | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-24 11:26:38 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |   XXX Could be much more optimal: | 
					
						
							|  |  |  |   * detect if line/page/whole screen is in 24 bit mode | 
					
						
							|  |  |  |   * if destination is also BGR, use memcpy | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d, | 
					
						
							|  |  |  |                                      const uint8_t *s, int width, | 
					
						
							|  |  |  |                                      const uint32_t *cplane, | 
					
						
							|  |  |  |                                      const uint32_t *s24) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     DisplaySurface *surface = qemu_console_surface(s1->con); | 
					
						
							| 
									
										
										
										
											2009-03-13 15:02:13 +00:00
										 |  |  |     int x, bgr, r, g, b; | 
					
						
							| 
									
										
										
										
											2008-07-24 11:26:38 +00:00
										 |  |  |     uint8_t val, *p8; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     uint32_t *p = (uint32_t *)d; | 
					
						
							|  |  |  |     uint32_t dval; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     bgr = is_surface_bgr(surface); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     for(x = 0; x < width; x++, s++, s24++) { | 
					
						
							| 
									
										
										
										
											2008-07-24 11:26:38 +00:00
										 |  |  |         if ((be32_to_cpu(*cplane++) & 0xff000000) == 0x03000000) { | 
					
						
							|  |  |  |             // 24-bit direct, BGR order
 | 
					
						
							|  |  |  |             p8 = (uint8_t *)s24; | 
					
						
							|  |  |  |             p8++; | 
					
						
							|  |  |  |             b = *p8++; | 
					
						
							|  |  |  |             g = *p8++; | 
					
						
							| 
									
										
										
										
											2010-01-13 18:58:51 +00:00
										 |  |  |             r = *p8; | 
					
						
							| 
									
										
										
										
											2009-03-13 15:02:13 +00:00
										 |  |  |             if (bgr) | 
					
						
							|  |  |  |                 dval = rgb_to_pixel32bgr(r, g, b); | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 dval = rgb_to_pixel32(r, g, b); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             val = *s; | 
					
						
							|  |  |  |             dval = s1->palette[val]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         *p++ = dval; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  | static inline int check_dirty(TCXState *s, ram_addr_t page, ram_addr_t page24, | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |                               ram_addr_t cpage) | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-22 16:38:21 +00:00
										 |  |  |     ret = memory_region_get_dirty(&s->vram_mem, page, TARGET_PAGE_SIZE, | 
					
						
							|  |  |  |                                   DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  |     ret |= memory_region_get_dirty(&s->vram_mem, page24, TARGET_PAGE_SIZE * 4, | 
					
						
							|  |  |  |                                    DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  |     ret |= memory_region_get_dirty(&s->vram_mem, cpage, TARGET_PAGE_SIZE * 4, | 
					
						
							|  |  |  |                                    DIRTY_MEMORY_VGA); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  | static inline void reset_dirty(TCXState *ts, ram_addr_t page_min, | 
					
						
							|  |  |  |                                ram_addr_t page_max, ram_addr_t page24, | 
					
						
							|  |  |  |                               ram_addr_t cpage) | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     memory_region_reset_dirty(&ts->vram_mem, | 
					
						
							| 
									
										
										
										
											2013-06-02 17:23:00 +01:00
										 |  |  |                               page_min, | 
					
						
							|  |  |  |                               (page_max - page_min) + TARGET_PAGE_SIZE, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                               DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  |     memory_region_reset_dirty(&ts->vram_mem, | 
					
						
							|  |  |  |                               page24 + page_min * 4, | 
					
						
							| 
									
										
										
										
											2013-06-02 17:23:00 +01:00
										 |  |  |                               (page_max - page_min) * 4 + TARGET_PAGE_SIZE, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                               DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  |     memory_region_reset_dirty(&ts->vram_mem, | 
					
						
							|  |  |  |                               cpage + page_min * 4, | 
					
						
							| 
									
										
										
										
											2013-06-02 17:23:00 +01:00
										 |  |  |                               (page_max - page_min) * 4 + TARGET_PAGE_SIZE, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                               DIRTY_MEMORY_VGA); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | /* Fixed line length 1024 allows us to do nice tricks not possible on
 | 
					
						
							|  |  |  |    VGA... */ | 
					
						
							| 
									
										
										
										
											2006-04-09 01:06:34 +00:00
										 |  |  | static void tcx_update_display(void *opaque) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     TCXState *ts = opaque; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     DisplaySurface *surface = qemu_console_surface(ts->con); | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |     ram_addr_t page, page_min, page_max; | 
					
						
							| 
									
										
										
										
											2006-08-02 22:19:33 +00:00
										 |  |  |     int y, y_start, dd, ds; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     uint8_t *d, *s; | 
					
						
							| 
									
										
										
										
											2007-06-25 19:56:13 +00:00
										 |  |  |     void (*f)(TCXState *s1, uint8_t *dst, const uint8_t *src, int width); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     if (surface_bits_per_pixel(surface) == 0) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     page = 0; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     y_start = -1; | 
					
						
							| 
									
										
										
										
											2009-04-27 18:10:37 +00:00
										 |  |  |     page_min = -1; | 
					
						
							| 
									
										
										
										
											2006-08-02 22:19:33 +00:00
										 |  |  |     page_max = 0; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     d = surface_data(surface); | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     s = ts->vram; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     dd = surface_stride(surface); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     ds = 1024; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     switch (surface_bits_per_pixel(surface)) { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     case 32: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         f = tcx_draw_line32; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |     case 15: | 
					
						
							|  |  |  |     case 16: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         f = tcx_draw_line16; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     default: | 
					
						
							|  |  |  |     case 8: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         f = tcx_draw_line8; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     case 0: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-09-17 08:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE) { | 
					
						
							| 
									
										
										
										
											2012-01-22 16:38:21 +00:00
										 |  |  |         if (memory_region_get_dirty(&ts->vram_mem, page, TARGET_PAGE_SIZE, | 
					
						
							|  |  |  |                                     DIRTY_MEMORY_VGA)) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             if (y_start < 0) | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |                 y_start = y; | 
					
						
							|  |  |  |             if (page < page_min) | 
					
						
							|  |  |  |                 page_min = page; | 
					
						
							|  |  |  |             if (page > page_max) | 
					
						
							|  |  |  |                 page_max = page; | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             f(ts, d, s, ts->width); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             f(ts, d, s, ts->width); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             f(ts, d, s, ts->width); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             f(ts, d, s, ts->width); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |             if (y_start >= 0) { | 
					
						
							|  |  |  |                 /* flush to display */ | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |                 dpy_gfx_update(ts->con, 0, y_start, | 
					
						
							| 
									
										
										
										
											2012-09-28 15:02:08 +02:00
										 |  |  |                                ts->width, y - y_start); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |                 y_start = -1; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             d += dd * 4; | 
					
						
							|  |  |  |             s += ds * 4; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (y_start >= 0) { | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         /* flush to display */ | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |         dpy_gfx_update(ts->con, 0, y_start, | 
					
						
							| 
									
										
										
										
											2012-09-28 15:02:08 +02:00
										 |  |  |                        ts->width, y - y_start); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* reset modified pages */ | 
					
						
							| 
									
										
										
										
											2009-04-27 18:10:37 +00:00
										 |  |  |     if (page_max >= page_min) { | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |         memory_region_reset_dirty(&ts->vram_mem, | 
					
						
							| 
									
										
										
										
											2013-06-02 17:23:00 +01:00
										 |  |  |                                   page_min, | 
					
						
							|  |  |  |                                   (page_max - page_min) + TARGET_PAGE_SIZE, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                                   DIRTY_MEMORY_VGA); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | static void tcx24_update_display(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     TCXState *ts = opaque; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     DisplaySurface *surface = qemu_console_surface(ts->con); | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |     ram_addr_t page, page_min, page_max, cpage, page24; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     int y, y_start, dd, ds; | 
					
						
							|  |  |  |     uint8_t *d, *s; | 
					
						
							|  |  |  |     uint32_t *cptr, *s24; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     if (surface_bits_per_pixel(surface) != 32) { | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     page = 0; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     page24 = ts->vram24_offset; | 
					
						
							|  |  |  |     cpage = ts->cplane_offset; | 
					
						
							|  |  |  |     y_start = -1; | 
					
						
							| 
									
										
										
										
											2009-04-27 18:10:37 +00:00
										 |  |  |     page_min = -1; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     page_max = 0; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     d = surface_data(surface); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     s = ts->vram; | 
					
						
							|  |  |  |     s24 = ts->vram24; | 
					
						
							|  |  |  |     cptr = ts->cplane; | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     dd = surface_stride(surface); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     ds = 1024; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for(y = 0; y < ts->height; y += 4, page += TARGET_PAGE_SIZE, | 
					
						
							|  |  |  |             page24 += TARGET_PAGE_SIZE, cpage += TARGET_PAGE_SIZE) { | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |         if (check_dirty(ts, page, page24, cpage)) { | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |             if (y_start < 0) | 
					
						
							|  |  |  |                 y_start = y; | 
					
						
							|  |  |  |             if (page < page_min) | 
					
						
							|  |  |  |                 page_min = page; | 
					
						
							|  |  |  |             if (page > page_max) | 
					
						
							|  |  |  |                 page_max = page; | 
					
						
							|  |  |  |             tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             cptr += ds; | 
					
						
							|  |  |  |             s24 += ds; | 
					
						
							|  |  |  |             tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             cptr += ds; | 
					
						
							|  |  |  |             s24 += ds; | 
					
						
							|  |  |  |             tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             cptr += ds; | 
					
						
							|  |  |  |             s24 += ds; | 
					
						
							|  |  |  |             tcx24_draw_line32(ts, d, s, ts->width, cptr, s24); | 
					
						
							|  |  |  |             d += dd; | 
					
						
							|  |  |  |             s += ds; | 
					
						
							|  |  |  |             cptr += ds; | 
					
						
							|  |  |  |             s24 += ds; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             if (y_start >= 0) { | 
					
						
							|  |  |  |                 /* flush to display */ | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |                 dpy_gfx_update(ts->con, 0, y_start, | 
					
						
							| 
									
										
										
										
											2012-09-28 15:02:08 +02:00
										 |  |  |                                ts->width, y - y_start); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |                 y_start = -1; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             d += dd * 4; | 
					
						
							|  |  |  |             s += ds * 4; | 
					
						
							|  |  |  |             cptr += ds * 4; | 
					
						
							|  |  |  |             s24 += ds * 4; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (y_start >= 0) { | 
					
						
							|  |  |  |         /* flush to display */ | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |         dpy_gfx_update(ts->con, 0, y_start, | 
					
						
							| 
									
										
										
										
											2012-09-28 15:02:08 +02:00
										 |  |  |                        ts->width, y - y_start); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     /* reset modified pages */ | 
					
						
							| 
									
										
										
										
											2009-04-27 18:10:37 +00:00
										 |  |  |     if (page_max >= page_min) { | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |         reset_dirty(ts, page_min, page_max, page24, cpage); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-09 01:06:34 +00:00
										 |  |  | static void tcx_invalidate_display(void *opaque) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     TCXState *s = opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  |     tcx_set_dirty(s); | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     qemu_console_resize(s->con, s->width, s->height); | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | static void tcx24_invalidate_display(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     TCXState *s = opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  |     tcx_set_dirty(s); | 
					
						
							|  |  |  |     tcx24_set_dirty(s); | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     qemu_console_resize(s->con, s->width, s->height); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 22:48:21 +02:00
										 |  |  | static int vmstate_tcx_post_load(void *opaque, int version_id) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     TCXState *s = opaque; | 
					
						
							| 
									
										
										
										
											2007-09-17 08:09:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |     update_palette_entries(s, 0, 256); | 
					
						
							| 
									
										
										
										
											2009-07-16 13:45:57 +00:00
										 |  |  |     if (s->depth == 24) { | 
					
						
							|  |  |  |         tcx24_set_dirty(s); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         tcx_set_dirty(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-04-13 19:24:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-28 20:43:01 +00:00
										 |  |  | static const VMStateDescription vmstate_tcx = { | 
					
						
							|  |  |  |     .name ="tcx", | 
					
						
							|  |  |  |     .version_id = 4, | 
					
						
							|  |  |  |     .minimum_version_id = 4, | 
					
						
							|  |  |  |     .minimum_version_id_old = 4, | 
					
						
							| 
									
										
										
										
											2009-09-10 03:04:30 +02:00
										 |  |  |     .post_load = vmstate_tcx_post_load, | 
					
						
							| 
									
										
										
										
											2009-08-28 20:43:01 +00:00
										 |  |  |     .fields      = (VMStateField []) { | 
					
						
							|  |  |  |         VMSTATE_UINT16(height, TCXState), | 
					
						
							|  |  |  |         VMSTATE_UINT16(width, TCXState), | 
					
						
							|  |  |  |         VMSTATE_UINT16(depth, TCXState), | 
					
						
							|  |  |  |         VMSTATE_BUFFER(r, TCXState), | 
					
						
							|  |  |  |         VMSTATE_BUFFER(g, TCXState), | 
					
						
							|  |  |  |         VMSTATE_BUFFER(b, TCXState), | 
					
						
							|  |  |  |         VMSTATE_UINT8(dac_index, TCXState), | 
					
						
							|  |  |  |         VMSTATE_UINT8(dac_state, TCXState), | 
					
						
							|  |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 13:40:27 +03:00
										 |  |  | static void tcx_reset(DeviceState *d) | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-25 01:13:54 +02:00
										 |  |  |     TCXState *s = TCX(d); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Initialize palette */ | 
					
						
							|  |  |  |     memset(s->r, 0, 256); | 
					
						
							|  |  |  |     memset(s->g, 0, 256); | 
					
						
							|  |  |  |     memset(s->b, 0, 256); | 
					
						
							|  |  |  |     s->r[255] = s->g[255] = s->b[255] = 255; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |     update_palette_entries(s, 0, 256); | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  |     memset(s->vram, 0, MAXX*MAXY); | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4), | 
					
						
							|  |  |  |                               DIRTY_MEMORY_VGA); | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     s->dac_index = 0; | 
					
						
							|  |  |  |     s->dac_state = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static uint64_t tcx_dac_readl(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                               unsigned size) | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                            unsigned size) | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     TCXState *s = opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 17:47:02 +00:00
										 |  |  |     switch (addr) { | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     case 0: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         s->dac_index = val >> 24; | 
					
						
							|  |  |  |         s->dac_state = 0; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2008-12-02 17:47:02 +00:00
										 |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         switch (s->dac_state) { | 
					
						
							|  |  |  |         case 0: | 
					
						
							|  |  |  |             s->r[s->dac_index] = val >> 24; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             update_palette_entries(s, s->dac_index, s->dac_index + 1); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             s->dac_state++; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 1: | 
					
						
							|  |  |  |             s->g[s->dac_index] = val >> 24; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             update_palette_entries(s, s->dac_index, s->dac_index + 1); | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |             s->dac_state++; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 2: | 
					
						
							|  |  |  |             s->b[s->dac_index] = val >> 24; | 
					
						
							| 
									
										
										
										
											2006-09-09 11:31:34 +00:00
										 |  |  |             update_palette_entries(s, s->dac_index, s->dac_index + 1); | 
					
						
							| 
									
										
										
										
											2007-04-17 19:42:21 +00:00
										 |  |  |             s->dac_index = (s->dac_index + 1) & 255; // Index autoincrement
 | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         default: | 
					
						
							|  |  |  |             s->dac_state = 0; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2007-10-06 11:28:21 +00:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  | static const MemoryRegionOps tcx_dac_ops = { | 
					
						
							|  |  |  |     .read = tcx_dac_readl, | 
					
						
							|  |  |  |     .write = tcx_dac_writel, | 
					
						
							|  |  |  |     .endianness = DEVICE_NATIVE_ENDIAN, | 
					
						
							|  |  |  |     .valid = { | 
					
						
							|  |  |  |         .min_access_size = 4, | 
					
						
							|  |  |  |         .max_access_size = 4, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2005-03-13 09:43:36 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static uint64_t dummy_readl(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                             unsigned size) | 
					
						
							| 
									
										
										
										
											2007-05-06 17:39:55 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | static void dummy_writel(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                          uint64_t val, unsigned size) | 
					
						
							| 
									
										
										
										
											2007-05-06 17:39:55 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  | static const MemoryRegionOps dummy_ops = { | 
					
						
							|  |  |  |     .read = dummy_readl, | 
					
						
							|  |  |  |     .write = dummy_writel, | 
					
						
							|  |  |  |     .endianness = DEVICE_NATIVE_ENDIAN, | 
					
						
							|  |  |  |     .valid = { | 
					
						
							|  |  |  |         .min_access_size = 4, | 
					
						
							|  |  |  |         .max_access_size = 4, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2007-05-06 17:39:55 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 14:04:18 +01:00
										 |  |  | static const GraphicHwOps tcx_ops = { | 
					
						
							|  |  |  |     .invalidate = tcx_invalidate_display, | 
					
						
							|  |  |  |     .gfx_update = tcx_update_display, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const GraphicHwOps tcx24_ops = { | 
					
						
							|  |  |  |     .invalidate = tcx24_invalidate_display, | 
					
						
							|  |  |  |     .gfx_update = tcx24_update_display, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-14 10:36:05 +02:00
										 |  |  | static int tcx_init1(SysBusDevice *dev) | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-25 01:13:54 +02:00
										 |  |  |     TCXState *s = TCX(dev); | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     ram_addr_t vram_offset = 0; | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  |     int size, ret; | 
					
						
							| 
									
										
										
										
											2009-04-09 22:21:07 +00:00
										 |  |  |     uint8_t *vram_base; | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  |     char *fcode_filename; | 
					
						
							| 
									
										
										
										
											2009-04-09 22:21:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_ram(&s->vram_mem, OBJECT(s), "tcx.vram", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                            s->vram_size * (1 + 4 + 4)); | 
					
						
							| 
									
										
										
										
											2011-12-20 15:59:12 +02:00
										 |  |  |     vmstate_register_ram_global(&s->vram_mem); | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |     vram_base = memory_region_get_ram_ptr(&s->vram_mem); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-02 16:03:50 +00:00
										 |  |  |     /* FCode ROM */ | 
					
						
							|  |  |  |     memory_region_init_ram(&s->rom, NULL, "tcx.prom", FCODE_MAX_ROM_SIZE); | 
					
						
							|  |  |  |     vmstate_register_ram_global(&s->rom); | 
					
						
							|  |  |  |     memory_region_set_readonly(&s->rom, true); | 
					
						
							|  |  |  |     sysbus_init_mmio(dev, &s->rom); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, TCX_ROM_FILE); | 
					
						
							|  |  |  |     if (fcode_filename) { | 
					
						
							|  |  |  |         ret = load_image_targphys(fcode_filename, s->prom_addr, | 
					
						
							|  |  |  |                                   FCODE_MAX_ROM_SIZE); | 
					
						
							|  |  |  |         if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) { | 
					
						
							|  |  |  |             fprintf(stderr, "tcx: could not load prom '%s'\n", TCX_ROM_FILE); | 
					
						
							|  |  |  |             return -1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |     /* 8-bit plane */ | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     s->vram = vram_base; | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  |     size = s->vram_size; | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_alias(&s->vram_8bit, OBJECT(s), "tcx.vram.8bit", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                              &s->vram_mem, vram_offset, size); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |     sysbus_init_mmio(dev, &s->vram_8bit); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     vram_offset += size; | 
					
						
							|  |  |  |     vram_base += size; | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |     /* DAC */ | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_io(&s->dac, OBJECT(s), &tcx_dac_ops, s, | 
					
						
							|  |  |  |                           "tcx.dac", TCX_DAC_NREGS); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |     sysbus_init_mmio(dev, &s->dac); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |     /* TEC (dummy) */ | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_io(&s->tec, OBJECT(s), &dummy_ops, s, | 
					
						
							|  |  |  |                           "tcx.tec", TCX_TEC_NREGS); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |     sysbus_init_mmio(dev, &s->tec); | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |     /* THC: NetBSD writes here even with 8-bit display: dummy */ | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_io(&s->thc24, OBJECT(s), &dummy_ops, s, "tcx.thc24", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                           TCX_THC_NREGS_24); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |     sysbus_init_mmio(dev, &s->thc24); | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (s->depth == 24) { | 
					
						
							|  |  |  |         /* 24-bit plane */ | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  |         size = s->vram_size * 4; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |         s->vram24 = (uint32_t *)vram_base; | 
					
						
							|  |  |  |         s->vram24_offset = vram_offset; | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |         memory_region_init_alias(&s->vram_24bit, OBJECT(s), "tcx.vram.24bit", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                                  &s->vram_mem, vram_offset, size); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |         sysbus_init_mmio(dev, &s->vram_24bit); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |         vram_offset += size; | 
					
						
							|  |  |  |         vram_base += size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |         /* Control plane */ | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  |         size = s->vram_size * 4; | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |         s->cplane = (uint32_t *)vram_base; | 
					
						
							|  |  |  |         s->cplane_offset = vram_offset; | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |         memory_region_init_alias(&s->vram_cplane, OBJECT(s), "tcx.vram.cplane", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                                  &s->vram_mem, vram_offset, size); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |         sysbus_init_mmio(dev, &s->vram_cplane); | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 15:35:21 +01:00
										 |  |  |         s->con = graphic_console_init(DEVICE(dev), 0, &tcx24_ops, s); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  |         /* THC 8 bit (dummy) */ | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |         memory_region_init_io(&s->thc8, OBJECT(s), &dummy_ops, s, "tcx.thc8", | 
					
						
							| 
									
										
										
										
											2011-10-05 18:26:24 +02:00
										 |  |  |                               TCX_THC_NREGS_8); | 
					
						
							| 
									
										
										
										
											2011-11-27 11:38:10 +02:00
										 |  |  |         sysbus_init_mmio(dev, &s->thc8); | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 15:35:21 +01:00
										 |  |  |         s->con = graphic_console_init(DEVICE(dev), 0, &tcx_ops, s); | 
					
						
							| 
									
										
										
										
											2007-04-21 19:45:49 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2004-12-19 23:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     qemu_console_resize(s->con, s->width, s->height); | 
					
						
							| 
									
										
										
										
											2009-08-14 10:36:05 +02:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2004-09-30 22:13:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | static Property tcx_properties[] = { | 
					
						
							| 
									
										
										
										
											2014-02-08 11:01:53 +01:00
										 |  |  |     DEFINE_PROP_UINT32("vram_size", TCXState, vram_size, -1), | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  |     DEFINE_PROP_UINT16("width",    TCXState, width,     -1), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT16("height",   TCXState, height,    -1), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT16("depth",    TCXState, depth,     -1), | 
					
						
							| 
									
										
										
										
											2014-02-08 11:01:53 +01:00
										 |  |  |     DEFINE_PROP_UINT64("prom_addr", TCXState, prom_addr, -1), | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void tcx_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  |     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     k->init = tcx_init1; | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     dc->reset = tcx_reset; | 
					
						
							|  |  |  |     dc->vmsd = &vmstate_tcx; | 
					
						
							|  |  |  |     dc->props = tcx_properties; | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 16:19:07 +01:00
										 |  |  | static const TypeInfo tcx_info = { | 
					
						
							| 
									
										
										
										
											2013-07-25 01:13:54 +02:00
										 |  |  |     .name          = TYPE_TCX, | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     .parent        = TYPE_SYS_BUS_DEVICE, | 
					
						
							|  |  |  |     .instance_size = sizeof(TCXState), | 
					
						
							|  |  |  |     .class_init    = tcx_class_init, | 
					
						
							| 
									
										
										
										
											2009-07-15 13:43:31 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | static void tcx_register_types(void) | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     type_register_static(&tcx_info); | 
					
						
							| 
									
										
										
										
											2009-07-12 19:21:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | type_init(tcx_register_types) |