2 Skelton for retropc emulator
4 Author : Kyuma Ohta <whatisthis.sowhat _at_ gmail.com>
8 History: 2016.12.28 Initial.
11 #ifndef _TOWNS_VRAM_H_
12 #define _TOWNS_VRAM_H_
15 #include "../../common.h"
16 #include "towns_common.h"
23 #define TOWNS_VRAM_ADDR_MASK 0x7ffff
24 // VRAM DIRECT ACCESS: For Sprite. You should access with 16bit
25 // You can write raw data, drawing with colorkey is automatically.
26 #define SIG_TOWNS_TRANSFER_SPRITE_DATA 0x100000
27 #define SIG_TOWNS_SET_SPRITE_BANK 0x140000
28 #define SIG_TOWNS_CLEAR_SPRITE_BUFFER 0x140001
29 // Do render with any mode. You should set vline to arg.
30 #define SIG_TOWNS_RENDER_RASTER 0x01
31 #define SIG_TOWNS_RENDER_FULL 0x02
32 #define SIG_TOWNS_VRAM_VSTART 0x03
33 #define SIG_TOWNS_VRAM_VBLANK 0x04
34 #define SIG_TOWNS_VRAM_VSYNC 0x05
35 #define SIG_TOWNS_VRAM_HSYNC 0x06
36 #define SIG_TOWNS_VRAM_SET_VLINE 0x07
37 #define SIG_TOWNS_RENDER_FLAG 0x08
38 #define SIG_TOWNS_VRAM_FRAMEBUFFER_READY 0x10
39 #define SIG_TOWNS_VRAM_SWAP_FRAMEBUFFER 0x11
42 class TOWNS_VRAM : public DEVICE
49 // If you use other framework, place mutex lock.
50 QMutex vram_lock[2][2]; // [bank][layer];
55 bool dirty_flag[0x80000 >> 3]; // Per 8bytes : 16pixels(16colors) / 8pixels(256) / 4pixels(32768)
57 // FMR50 Compatible registers. They are mostly dummy.
58 // Digital paletts. I/O FD98H - FD9FH.
59 bool layer_display_flags[2]; // I/O FDA0H (WO) : bit3-2 (Layer1) or bit1-0 (Layer0).Not 0 is true.
62 bool sprite_busy; // I/O 044CH (RO) : bit1. Must update from write_signal().
63 bool sprite_disp_page; // I/O 044CH (RO) : bit0. Must update from write_signal().
64 // Accessing VRAM. Will be separated.
65 // Memory description:
66 // All of accessing must be little endian.
67 // 000C:00000 - 000C:07fff : Plane accessing window(->FM-R50 features?). Access to Layer #0 (8000:00000).
68 // 000C:08000 - 000C:0ffff : I/O CVRAM
69 // 000D:00000 - 000E:0ffff : Reserved (Window for KANJI, DIC etc).
70 // 8000:00000 - 8000:3ffff : Plane accessing Layer #0.
71 // 8000:40000 - 8000:7ffff : Plane accessing Layer #1.
72 // 8010:00000 - 8010:7ffff : Plane accessing with one layer.
73 // 8100:00000 - 8100:1ffff : Sprite (and text vram).
74 // I/O 0458H (RW) : VRAM ACCESS CONTROLLER reg address.
75 // I/O 045AH (RW) : VRAM ACCESS CONTROLLER reg data (LOW).
76 // I/O 045BH (RW) : VRAM ACCESS CONTROLLER reg data (HIGH).
77 uint8_t vram_access_reg_addr;
78 pair32_t packed_pixel_mask_reg; // '1' = Write. I/O 0458H - 045BH.
79 uint8_t vram[0x80000]; // Related by machine.
82 // Flags related by host renderer. Not saved.
83 bool has_hardware_rendering;
84 bool has_hardware_blending;
90 TOWNS_VRAM(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
92 memset(vram, 0x00, sizeof(vram));
95 cpu_id = 0x01; // for 05EEh
97 set_device_name(_T("FM-Towns VRAM"));
101 virtual void initialize();
102 virtual void reset();
104 virtual uint32_t __FASTCALL read_memory_mapped_io8(uint32_t addr);
105 virtual uint32_t __FASTCALL read_memory_mapped_io16(uint32_t addr);
106 virtual uint32_t __FASTCALL read_memory_mapped_io32(uint32_t addr);
107 virtual void __FASTCALL write_memory_mapped_io8(uint32_t addr, uint32_t data);
108 virtual void __FASTCALL write_memory_mapped_io16(uint32_t addr, uint32_t data);
109 virtual void __FASTCALL write_memory_mapped_io32(uint32_t addr, uint32_t data);
111 virtual void __FASTCALL write_io8(uint32_t address, uint32_t data);
112 virtual void __FASTCALL write_io16(uint32_t address, uint32_t data);
114 virtual uint32_t __FASTCALL read_io8(uint32_t address);
115 virtual uint32_t __FASTCALL read_io16(uint32_t address);
117 void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask); // Do render
118 virtual bool process_state(FILEIO* state_fio, bool loading);
121 virtual uint8_t* __FASTCALL get_vram_address(uint32_t offset)
123 if(offset >= 0x80000) return NULL; // ToDo
124 return &(vram[offset]);
126 virtual bool __FASTCALL set_buffer_to_vram(uint32_t offset, uint8_t *buf, int words)
129 // if(words > 16) return false;
130 if(words <= 0) return false;
131 uint8_t* p = &(vram[offset]);
132 if((offset + (words << 1)) <= 0x80000) {
133 memcpy(p, buf, words << 1);
135 int nb = 0x80000 - offset;
137 int nnb = (words << 1) - nb;
139 memcpy(vram, &(buf[nb]), nnb);
144 virtual bool __FASTCALL get_vram_to_buffer(uint32_t offset, uint8_t *buf, int words)
147 // if(words > 16) return false;
148 if(words <= 0) return false;
149 uint8_t* p = &(vram[offset]);
150 if((offset + (words << 1)) <= 0x80000) {
151 memcpy(buf, p, words << 1);
153 uint32_t nb = 0x80000 - offset;
155 int nnb = (words << 1) - nb;
157 memcpy(&(buf[nb]), vram, nnb);
162 virtual void __FASTCALL make_dirty_vram(uint32_t addr, int bytes);
163 virtual uint32_t __FASTCALL get_vram_size()
165 return 0x80000; // ToDo
167 virtual void __FASTCALL lock_framebuffer(int layer, int bank)
170 vram_lock[bank][layer].lock();
173 virtual void __FASTCALL unlock_framebuffer(int layer, int bank)
176 vram_lock[bank][layer].unlock();
179 void set_context_sprite(DEVICE *dev)
183 void set_context_crtc(DEVICE *dev)
187 void set_cpu_id(uint16_t val)
191 void set_machine_id(uint16_t val)
193 machine_id = val & 0xfff8;