2 NEC PC-100 Emulator 'ePC-100'
4 Author : Takeda.Toshiya
15 void CRTC::initialize()
18 memset(vram, 0, sizeof(vram));
22 maskl = maskh = busl = bush = 0;
29 for(int i = 1; i < 16; i++) {
37 register_vline_event(this);
40 void CRTC::event_vline(int v, int clock)
43 d_pic->write_signal(SIG_I8259_IR4, 1, 1);
47 void CRTC::write_io8(uint32_t addr, uint32_t data)
60 vs = (vs & 0xff00) | data;
63 vs = (vs & 0xff) | (data << 8);
81 palette[(addr >> 1) & 0x0f] = (palette[(addr >> 1) & 0x0f] & 0xff00) | data;
82 update_palette((addr >> 1) & 0x0f);
100 palette[(addr >> 1) & 0x0f] = (palette[(addr >> 1) & 0x0f] & 0xff) | (data << 8);
101 update_palette((addr >> 1) & 0x0f);
104 cmd = (cmd & 0xff00) | data;
107 cmd = (cmd & 0xff) | (data << 8);
112 uint32_t CRTC::read_io8(uint32_t addr)
116 switch(addr & 0x3ff) {
122 return regs[sel & 7];
143 return palette[(addr >> 1) & 0x0f] & 0xff;
160 return palette[(addr >> 1) & 0x0f] >> 8;
169 void CRTC::write_memory_mapped_io8(uint32_t addr, uint32_t data)
176 uint32_t bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
180 uint32_t h = (bus >> 8) & 0xff;
181 for(int pl = 0; pl < 4; pl++) {
182 if(write_plane & (1 << pl)) {
183 int ofsh = (addr & 0x1ffff) | (0x20000 * pl);
184 vram[ofsh] = (vram[ofsh] & maskh) | (h & ~maskh);
188 uint32_t l = bus & 0xff;
189 for(int pl = 0; pl < 4; pl++) {
190 if(write_plane & (1 << pl)) {
191 int ofsl = (addr & 0x1ffff) | (0x20000 * pl);
192 vram[ofsl] = (vram[ofsl] & maskl) | (l & ~maskl);
198 uint32_t CRTC::read_memory_mapped_io8(uint32_t addr)
200 return vram[(addr & 0x1ffff) | (0x20000 * read_plane)];
203 void CRTC::write_memory_mapped_io16(uint32_t addr, uint32_t data)
205 busl = (addr & 1) ? (data >> 8) : (data & 0xff);
206 bush = (addr & 1) ? (data & 0xff) : (data >> 8);
207 uint32_t bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
209 uint32_t l = bus & 0xff;
210 uint32_t h = (bus >> 8) & 0xff;
212 for(int pl = 0; pl < 4; pl++) {
213 if(write_plane & (1 << pl)) {
214 int ofsl = ((addr & 1 ? (addr + 1) : addr) & 0x1ffff) | (0x20000 * pl);
215 int ofsh = ((addr & 1 ? addr : (addr + 1)) & 0x1ffff) | (0x20000 * pl);
216 vram[ofsl] = (vram[ofsl] & maskl) | (l & ~maskl);
217 vram[ofsh] = (vram[ofsh] & maskh) | (h & ~maskh);
222 uint32_t CRTC::read_memory_mapped_io16(uint32_t addr)
224 uint32_t val = read_memory_mapped_io8(addr);
225 val |= read_memory_mapped_io8(addr + 1) << 8;
229 void CRTC::write_signal(int id, uint32_t data, uint32_t mask)
231 if(id == SIG_CRTC_BITMASK_LOW) {
234 } else if(id == SIG_CRTC_BITMASK_HIGH) {
237 } else if(id == SIG_CRTC_VRAM_PLANE) {
239 write_plane = data & 0x0f;
240 read_plane = (data >> 4) & 3;
244 void CRTC::draw_screen()
247 int hd = (regs[2] >> 1) & 0x3f;
248 int vd = (regs[6] >> 1) & 0x3f;
249 int hs = (int)(int8_t)((regs[0] & 0x40) ? (regs[0] | 0x80) : (regs[0] & 0x3f));
250 // int hs = (int)(int8_t)regs[0];
251 int vs_tmp = (int)(int16_t)((vs & 0x400) ? (vs | 0xf800) : (vs & 0x3ff));
252 int sa = (hs + hd + 1) * 2 + (vs_tmp + vd) * 0x80;
253 // int sa = (hs + hd + 1) * 2 + ((vs & 0x3ff) + vd) * 0x80;
257 scrntype_t col = RGB_COLOR(255, 255, 255);
258 for(int y = 0; y < 512; y++) {
259 int ptr = sa & 0x1ffff;
261 scrntype_t *dest = emu->get_screen_buffer(y);
263 for(int x = 0; x < 720; x += 8) {
264 uint8_t pat = vram[ptr];
265 ptr = (ptr + 1) & 0x1ffff;
267 dest[x + 0] = pat & 0x01 ? col : 0;
268 dest[x + 1] = pat & 0x02 ? col : 0;
269 dest[x + 2] = pat & 0x04 ? col : 0;
270 dest[x + 3] = pat & 0x08 ? col : 0;
271 dest[x + 4] = pat & 0x10 ? col : 0;
272 dest[x + 5] = pat & 0x20 ? col : 0;
273 dest[x + 6] = pat & 0x40 ? col : 0;
274 dest[x + 7] = pat & 0x80 ? col : 0;
279 for(int y = 0; y < 512; y++) {
280 int ptr = sa & 0x1ffff;
282 scrntype_t *dest = emu->get_screen_buffer(y);
284 for(int x = 0; x < 720; x += 8) {
285 uint8_t p0 = vram[0x00000 | ptr];
286 uint8_t p1 = vram[0x20000 | ptr];
287 uint8_t p2 = vram[0x40000 | ptr];
288 uint8_t p3 = vram[0x60000 | ptr];
289 ptr = (ptr + 1) & 0x1ffff;
291 dest[x + 0] = palette_pc[((p0 & 0x01) << 0) | ((p1 & 0x01) << 1) | ((p2 & 0x01) << 2) | ((p3 & 0x01) << 3)];
292 dest[x + 1] = palette_pc[((p0 & 0x02) >> 1) | ((p1 & 0x02) << 0) | ((p2 & 0x02) << 1) | ((p3 & 0x02) << 2)];
293 dest[x + 2] = palette_pc[((p0 & 0x04) >> 2) | ((p1 & 0x04) >> 1) | ((p2 & 0x04) << 0) | ((p3 & 0x04) << 1)];
294 dest[x + 3] = palette_pc[((p0 & 0x08) >> 3) | ((p1 & 0x08) >> 2) | ((p2 & 0x08) >> 1) | ((p3 & 0x08) << 0)];
295 dest[x + 4] = palette_pc[((p0 & 0x10) >> 4) | ((p1 & 0x10) >> 3) | ((p2 & 0x10) >> 2) | ((p3 & 0x10) >> 1)];
296 dest[x + 5] = palette_pc[((p0 & 0x20) >> 5) | ((p1 & 0x20) >> 4) | ((p2 & 0x20) >> 3) | ((p3 & 0x20) >> 2)];
297 dest[x + 6] = palette_pc[((p0 & 0x40) >> 6) | ((p1 & 0x40) >> 5) | ((p2 & 0x40) >> 4) | ((p3 & 0x40) >> 3)];
298 dest[x + 7] = palette_pc[((p0 & 0x80) >> 7) | ((p1 & 0x80) >> 6) | ((p2 & 0x80) >> 5) | ((p3 & 0x80) >> 4)];
302 emu->screen_skip_line(false);
305 void CRTC::update_palette(int num)
307 int r = (palette[num] >> 0) & 7;
308 int g = (palette[num] >> 3) & 7;
309 int b = (palette[num] >> 6) & 7;
310 palette_pc[num] = RGB_COLOR(r << 5, g << 5, b << 5);
313 #define STATE_VERSION 1
315 bool CRTC::process_state(FILEIO* state_fio, bool loading)
317 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
320 if(!state_fio->StateCheckInt32(this_device_id)) {
323 //state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
324 for(int i = 0; i < (sizeof(palette_pc) / sizeof(scrntype_t)); i++) {
327 r = state_fio->FgetUint8();
328 g = state_fio->FgetUint8();
329 b = state_fio->FgetUint8();
330 palette_pc[i] = RGB_COLOR(r, g, b);
333 r = R_OF_COLOR(palette_pc[i]);
334 g = G_OF_COLOR(palette_pc[i]);
335 b = B_OF_COLOR(palette_pc[i]);
336 state_fio->FputUint8(r);
337 state_fio->FputUint8(g);
338 state_fio->FputUint8(b);
341 //state_fio->StateBuffer(palette, sizeof(palette), 1);
342 for(int i = 0; i < (sizeof(palette) / sizeof(uint16_t)); i++) {
343 state_fio->StateUint16(palette[i]);
345 state_fio->StateUint8(sel);
346 state_fio->StateBuffer(regs, sizeof(regs), 1);
347 state_fio->StateUint16(vs);
348 state_fio->StateUint16(cmd);
349 state_fio->StateBuffer(vram, sizeof(vram), 1);
350 state_fio->StateUint32(shift);
351 state_fio->StateUint32(maskl);
352 state_fio->StateUint32(maskh);
353 state_fio->StateUint32(busl);
354 state_fio->StateUint32(bush);
355 state_fio->StateUint32(write_plane);
356 state_fio->StateUint32(read_plane);