OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc100 / crtc.cpp
index 94eef0d..6aca8eb 100644 (file)
@@ -42,7 +42,7 @@ void CRTC::event_vline(int v, int clock)
        }
 }
 
-void CRTC::write_io8(uint32 addr, uint32 data)
+void CRTC::write_io8(uint32_t addr, uint32_t data)
 {
        switch(addr & 0xff) {
        case 0x30:
@@ -107,9 +107,9 @@ void CRTC::write_io8(uint32 addr, uint32 data)
        }
 }
 
-uint32 CRTC::read_io8(uint32 addr)
+uint32_t CRTC::read_io8(uint32_t addr)
 {
-       uint32 val = 0xff;
+       uint32_t val = 0xff;
        
        switch(addr & 0x3ff) {
        case 0x30:
@@ -164,18 +164,18 @@ uint32 CRTC::read_io8(uint32 addr)
        return 0xff;
 }
 
-void CRTC::write_memory_mapped_io8(uint32 addr, uint32 data)
+void CRTC::write_memory_mapped_io8(uint32_t addr, uint32_t data)
 {
        if(addr & 1) {
                bush = data;
        } else {
                busl = data;
        }
-       uint32 bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
+       uint32_t bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
        bus >>= shift;
        
        if(addr & 1) {
-               uint32 h = (bus >> 8) & 0xff;
+               uint32_t h = (bus >> 8) & 0xff;
                for(int pl = 0; pl < 4; pl++) {
                        if(write_plane & (1 << pl)) {
                                int ofsh = (addr & 0x1ffff) | (0x20000 * pl);
@@ -183,7 +183,7 @@ void CRTC::write_memory_mapped_io8(uint32 addr, uint32 data)
                        }
                }
        } else {
-               uint32 l = bus & 0xff;
+               uint32_t l = bus & 0xff;
                for(int pl = 0; pl < 4; pl++) {
                        if(write_plane & (1 << pl)) {
                                int ofsl = (addr & 0x1ffff) | (0x20000 * pl);
@@ -193,19 +193,19 @@ void CRTC::write_memory_mapped_io8(uint32 addr, uint32 data)
        }
 }
 
-uint32 CRTC::read_memory_mapped_io8(uint32 addr)
+uint32_t CRTC::read_memory_mapped_io8(uint32_t addr)
 {
        return vram[(addr & 0x1ffff) | (0x20000 * read_plane)];
 }
 
-void CRTC::write_memory_mapped_io16(uint32 addr, uint32 data)
+void CRTC::write_memory_mapped_io16(uint32_t addr, uint32_t data)
 {
        busl = (addr & 1) ? (data >> 8) : (data & 0xff);
        bush = (addr & 1) ? (data & 0xff) : (data >> 8);
-       uint32 bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
+       uint32_t bus = busl | (bush << 8) | (busl << 16) | (bush << 24);
        bus >>= shift;
-       uint32 l = bus & 0xff;
-       uint32 h = (bus >> 8) & 0xff;
+       uint32_t l = bus & 0xff;
+       uint32_t h = (bus >> 8) & 0xff;
        
        for(int pl = 0; pl < 4; pl++) {
                if(write_plane & (1 << pl)) {
@@ -217,14 +217,14 @@ void CRTC::write_memory_mapped_io16(uint32 addr, uint32 data)
        }
 }
 
-uint32 CRTC::read_memory_mapped_io16(uint32 addr)
+uint32_t CRTC::read_memory_mapped_io16(uint32_t addr)
 {
-       uint32 val = read_memory_mapped_io8(addr);
+       uint32_t val = read_memory_mapped_io8(addr);
        val |= read_memory_mapped_io8(addr + 1) << 8;
        return val;
 }
 
-void CRTC::write_signal(int id, uint32 data, uint32 mask)
+void CRTC::write_signal(int id, uint32_t data, uint32_t mask)
 {
        if(id == SIG_CRTC_BITMASK_LOW) {
                // $18: 8255 PA
@@ -244,22 +244,22 @@ void CRTC::draw_screen()
        // display region
        int hd = (regs[2] >> 1) & 0x3f;
        int vd = (regs[6] >> 1) & 0x3f;
-       int hs = (int)(int8)((regs[0] & 0x40) ? (regs[0] | 0x80) : (regs[0] & 0x3f));
-//     int hs = (int)(int8)regs[0];
-       int vs_tmp = (int)(int16)((vs & 0x400) ? (vs | 0xf800) : (vs & 0x3ff));
+       int hs = (int)(int8_t)((regs[0] & 0x40) ? (regs[0] | 0x80) : (regs[0] & 0x3f));
+//     int hs = (int)(int8_t)regs[0];
+       int vs_tmp = (int)(int16_t)((vs & 0x400) ? (vs | 0xf800) : (vs & 0x3ff));
        int sa = (hs + hd + 1) * 2 + (vs_tmp + vd) * 0x80;
 //     int sa = (hs + hd + 1) * 2 + ((vs & 0x3ff) + vd) * 0x80;
        
        if(cmd != 0xffff) {
                // mono
-               scrntype col = RGB_COLOR(255, 255, 255);
+               scrntype_t col = RGB_COLOR(255, 255, 255);
                for(int y = 0; y < 512; y++) {
                        int ptr = sa & 0x1ffff;
                        sa += 0x80;
-                       scrntype *dest = emu->screen_buffer(y);
+                       scrntype_t *dest = emu->get_screen_buffer(y);
                        
                        for(int x = 0; x < 720; x += 8) {
-                               uint8 pat = vram[ptr];
+                               uint8_t pat = vram[ptr];
                                ptr = (ptr + 1) & 0x1ffff;
                                
                                dest[x + 0] = pat & 0x01 ? col : 0;
@@ -277,13 +277,13 @@ void CRTC::draw_screen()
                for(int y = 0; y < 512; y++) {
                        int ptr = sa & 0x1ffff;
                        sa += 0x80;
-                       scrntype *dest = emu->screen_buffer(y);
+                       scrntype_t *dest = emu->get_screen_buffer(y);
                        
                        for(int x = 0; x < 720; x += 8) {
-                               uint8 p0 = vram[0x00000 | ptr];
-                               uint8 p1 = vram[0x20000 | ptr];
-                               uint8 p2 = vram[0x40000 | ptr];
-                               uint8 p3 = vram[0x60000 | ptr];
+                               uint8_t p0 = vram[0x00000 | ptr];
+                               uint8_t p1 = vram[0x20000 | ptr];
+                               uint8_t p2 = vram[0x40000 | ptr];
+                               uint8_t p3 = vram[0x60000 | ptr];
                                ptr = (ptr + 1) & 0x1ffff;
                                
                                dest[x + 0] = palette_pc[((p0 & 0x01) << 0) | ((p1 & 0x01) << 1) | ((p2 & 0x01) << 2) | ((p3 & 0x01) << 3)];
@@ -310,49 +310,107 @@ void CRTC::update_palette(int num)
 
 #define STATE_VERSION  1
 
+#include "../../statesub.h"
+
+void CRTC::decl_state()
+{
+       enter_decl_state(STATE_VERSION);
+
+       DECL_STATE_ENTRY_SCRNTYPE_T_1D_ARRAY(palette_pc, 16);
+       DECL_STATE_ENTRY_1D_ARRAY(palette, 16);
+       DECL_STATE_ENTRY_UINT8(sel);
+       DECL_STATE_ENTRY_1D_ARRAY(regs, sizeof(regs));
+       DECL_STATE_ENTRY_UINT16(vs);
+       DECL_STATE_ENTRY_UINT16(cmd);
+       DECL_STATE_ENTRY_1D_ARRAY(vram, sizeof(vram));
+       DECL_STATE_ENTRY_UINT32(shift);
+       DECL_STATE_ENTRY_UINT32(maskl);
+       DECL_STATE_ENTRY_UINT32(maskh);
+       DECL_STATE_ENTRY_UINT32(busl);
+       DECL_STATE_ENTRY_UINT32(bush);
+       DECL_STATE_ENTRY_UINT32(write_plane);
+       DECL_STATE_ENTRY_UINT32(read_plane);
+       
+       leave_decl_state();
+}
+       
 void CRTC::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+//     state_fio->FputUint32(STATE_VERSION);
+//     state_fio->FputInt32(this_device_id);
        
-       state_fio->Fwrite(palette_pc, sizeof(palette_pc), 1);
-       state_fio->Fwrite(palette, sizeof(palette), 1);
-       state_fio->FputUint8(sel);
-       state_fio->Fwrite(regs, sizeof(regs), 1);
-       state_fio->FputUint16(vs);
-       state_fio->FputUint16(cmd);
-       state_fio->Fwrite(vram, sizeof(vram), 1);
-       state_fio->FputUint32(shift);
-       state_fio->FputUint32(maskl);
-       state_fio->FputUint32(maskh);
-       state_fio->FputUint32(busl);
-       state_fio->FputUint32(bush);
-       state_fio->FputUint32(write_plane);
-       state_fio->FputUint32(read_plane);
+//     state_fio->Fwrite(palette_pc, sizeof(palette_pc), 1);
+//     state_fio->Fwrite(palette, sizeof(palette), 1);
+//     state_fio->FputUint8(sel);
+//     state_fio->Fwrite(regs, sizeof(regs), 1);
+//     state_fio->FputUint16(vs);
+//     state_fio->FputUint16(cmd);
+//     state_fio->Fwrite(vram, sizeof(vram), 1);
+//     state_fio->FputUint32(shift);
+//     state_fio->FputUint32(maskl);
+//     state_fio->FputUint32(maskh);
+//     state_fio->FputUint32(busl);
+//     state_fio->FputUint32(bush);
+//     state_fio->FputUint32(write_plane);
+//     state_fio->FputUint32(read_plane);
 }
 
 bool CRTC::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
        }
-       if(state_fio->FgetInt32() != this_device_id) {
+       if(!mb) {
                return false;
        }
-       state_fio->Fread(palette_pc, sizeof(palette_pc), 1);
-       state_fio->Fread(palette, sizeof(palette), 1);
-       sel = state_fio->FgetUint8();
-       state_fio->Fread(regs, sizeof(regs), 1);
-       vs = state_fio->FgetUint16();
-       cmd = state_fio->FgetUint16();
-       state_fio->Fread(vram, sizeof(vram), 1);
-       shift = state_fio->FgetUint32();
-       maskl = state_fio->FgetUint32();
-       maskh = state_fio->FgetUint32();
-       busl = state_fio->FgetUint32();
-       bush = state_fio->FgetUint32();
-       write_plane = state_fio->FgetUint32();
-       read_plane = state_fio->FgetUint32();
+//     if(state_fio->FgetUint32() != STATE_VERSION) {
+//             return false;
+//     }
+//     if(state_fio->FgetInt32() != this_device_id) {
+//             return false;
+//     }
+//     state_fio->Fread(palette_pc, sizeof(palette_pc), 1);
+//     state_fio->Fread(palette, sizeof(palette), 1);
+//     sel = state_fio->FgetUint8();
+//     state_fio->Fread(regs, sizeof(regs), 1);
+//     vs = state_fio->FgetUint16();
+//     cmd = state_fio->FgetUint16();
+//     state_fio->Fread(vram, sizeof(vram), 1);
+//     shift = state_fio->FgetUint32();
+//     maskl = state_fio->FgetUint32();
+//     maskh = state_fio->FgetUint32();
+//     busl = state_fio->FgetUint32();
+//     bush = state_fio->FgetUint32();
+//     write_plane = state_fio->FgetUint32();
+//     read_plane = state_fio->FgetUint32();
        return true;
 }
 
+bool CRTC::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(palette_pc, sizeof(palette_pc), 1);
+       state_fio->StateBuffer(palette, sizeof(palette), 1);
+       state_fio->StateUint8(sel);
+       state_fio->StateBuffer(regs, sizeof(regs), 1);
+       state_fio->StateUint16(vs);
+       state_fio->StateUint16(cmd);
+       state_fio->StateBuffer(vram, sizeof(vram), 1);
+       state_fio->StateUint32(shift);
+       state_fio->StateUint32(maskl);
+       state_fio->StateUint32(maskh);
+       state_fio->StateUint32(busl);
+       state_fio->StateUint32(bush);
+       state_fio->StateUint32(write_plane);
+       state_fio->StateUint32(read_plane);
+       return true;
+}