#define EVENT_AFTER_BLANK 0
#endif
+namespace X1 {
+
#ifdef _X1TURBOZ
#define AEN ((zmode1 & 0x80) != 0)
#define C64 ((zmode1 & 0x10) != 0)
void DISPLAY::update_crtc()
{
#ifdef _X1TURBO_FEATURE
- if (column40) {
+ if(column40) {
d_crtc->set_char_clock((mode1 & 1) ? VDP_CLOCK * 1.5 / 32.0 : VDP_CLOCK / 32.0);
} else {
d_crtc->set_char_clock((mode1 & 1) ? VDP_CLOCK * 1.5 / 16.0 : VDP_CLOCK / 16.0);
}
#else
- if (column40) {
+ if(column40) {
d_crtc->set_char_clock(VDP_CLOCK / 32.0);
} else {
d_crtc->set_char_clock(VDP_CLOCK / 16.0);
return (c1 << 8) | c2;
}
-#define STATE_VERSION 4
+#define STATE_VERSION 5
-void DISPLAY::save_state(FILEIO* state_fio)
+bool DISPLAY::process_state(FILEIO* state_fio, bool loading)
{
- state_fio->FputUint32(STATE_VERSION);
- state_fio->FputInt32(this_device_id);
-
- state_fio->Fwrite(vram_t, sizeof(vram_t), 1);
- state_fio->Fwrite(vram_a, sizeof(vram_a), 1);
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+ return false;
+ }
+ if(!state_fio->StateCheckInt32(this_device_id)) {
+ return false;
+ }
+ state_fio->StateArray(vram_t, sizeof(vram_t), 1);
+ state_fio->StateArray(vram_a, sizeof(vram_a), 1);
#ifdef _X1TURBO_FEATURE
- state_fio->Fwrite(vram_k, sizeof(vram_k), 1);
+ state_fio->StateArray(vram_k, sizeof(vram_k), 1);
#endif
- state_fio->Fwrite(pcg_b, sizeof(pcg_b), 1);
- state_fio->Fwrite(pcg_r, sizeof(pcg_r), 1);
- state_fio->Fwrite(pcg_g, sizeof(pcg_g), 1);
+ state_fio->StateArray(&pcg_b[0][0], sizeof(pcg_b), 1);
+ state_fio->StateArray(&pcg_r[0][0], sizeof(pcg_r), 1);
+ state_fio->StateArray(&pcg_g[0][0], sizeof(pcg_g), 1);
#ifdef _X1TURBO_FEATURE
- state_fio->Fwrite(gaiji_b, sizeof(gaiji_b), 1);
- state_fio->Fwrite(gaiji_r, sizeof(gaiji_r), 1);
- state_fio->Fwrite(gaiji_g, sizeof(gaiji_g), 1);
-#endif
- state_fio->FputUint8(cur_code);
- state_fio->FputUint8(cur_line);
- state_fio->FputInt32(kaddr);
- state_fio->FputInt32(kofs);
- state_fio->FputInt32(kflag);
- state_fio->FputInt32((int)(kanji_ptr - &kanji[0]));
- state_fio->Fwrite(pal, sizeof(pal), 1);
- state_fio->FputUint8(priority);
- state_fio->Fwrite(pri, sizeof(pri), 1);
- state_fio->FputBool(column40);
+ state_fio->StateArray(&gaiji_b[0][0], sizeof(gaiji_b), 1);
+ state_fio->StateArray(&gaiji_r[0][0], sizeof(gaiji_r), 1);
+ state_fio->StateArray(&gaiji_g[0][0], sizeof(gaiji_g), 1);
+#endif
+ state_fio->StateValue(cur_code);
+ state_fio->StateValue(cur_line);
+ state_fio->StateValue(kaddr);
+ state_fio->StateValue(kofs);
+ state_fio->StateValue(kflag);
+ if(loading) {
+ intptr_t p = (intptr_t)(&kanji[0]);
+ kanji_ptr = (uint8_t*)(p + state_fio->FgetInt32_LE());
+ } else {
+ intptr_t p = (intptr_t)(&kanji[0]);
+ intptr_t q = (intptr_t)kanji_ptr;
+ state_fio->FputInt32_LE((int)(q - p));
+ }
+ state_fio->StateArray(pal, sizeof(pal), 1);
+ state_fio->StateValue(priority);
+ state_fio->StateArray(&pri[0][0], sizeof(pri), 1);
+ state_fio->StateValue(column40);
#ifdef _X1TURBO_FEATURE
- state_fio->FputUint8(mode1);
- state_fio->FputUint8(mode2);
- state_fio->FputBool(hireso);
+ state_fio->StateValue(mode1);
+ state_fio->StateValue(mode2);
+ state_fio->StateValue(hireso);
#endif
#ifdef _X1TURBOZ
- state_fio->FputUint8(zmode1);
- state_fio->FputUint8(zpriority);
- state_fio->FputUint8(zadjust);
- state_fio->FputUint8(zmosaic);
- state_fio->FputUint8(zchromakey);
- state_fio->FputUint8(zscroll);
- state_fio->FputUint8(zmode2);
- state_fio->Fwrite(ztpal, sizeof(ztpal), 1);
- state_fio->Fwrite(zpal, sizeof(zpal), 1);
- state_fio->FputInt32(zpal_num);
- state_fio->Fwrite(zpalette_pc, sizeof(zpalette_pc), 1);
-#endif
- state_fio->FputBool(prev_vert_double);
- state_fio->FputInt32(raster);
- state_fio->FputInt32(cblink);
- state_fio->FputInt32(ch_height);
- state_fio->FputInt32(hz_total);
- state_fio->FputInt32(hz_disp);
- state_fio->FputInt32(vt_disp);
- state_fio->FputInt32(st_addr);
- state_fio->FputUint32(vblank_clock);
- state_fio->FputBool(cur_blank);
-}
-
-bool DISPLAY::load_state(FILEIO* state_fio)
-{
- if(state_fio->FgetUint32() != STATE_VERSION) {
- return false;
- }
- if(state_fio->FgetInt32() != this_device_id) {
- return false;
+ state_fio->StateValue(zmode1);
+ state_fio->StateValue(zpriority);
+ state_fio->StateValue(zadjust);
+ state_fio->StateValue(zmosaic);
+ state_fio->StateValue(zchromakey);
+ state_fio->StateValue(zscroll);
+ state_fio->StateValue(zmode2);
+ state_fio->StateArray(ztpal, sizeof(ztpal), 1);
+ for(int i = 0; i < array_length(zpal); i++){
+ state_fio->StateValue(zpal[i].r);
+ state_fio->StateValue(zpal[i].g);
+ state_fio->StateValue(zpal[i].b);
}
- state_fio->Fread(vram_t, sizeof(vram_t), 1);
- state_fio->Fread(vram_a, sizeof(vram_a), 1);
-#ifdef _X1TURBO_FEATURE
- state_fio->Fread(vram_k, sizeof(vram_k), 1);
-#endif
- state_fio->Fread(pcg_b, sizeof(pcg_b), 1);
- state_fio->Fread(pcg_r, sizeof(pcg_r), 1);
- state_fio->Fread(pcg_g, sizeof(pcg_g), 1);
-#ifdef _X1TURBO_FEATURE
- state_fio->Fread(gaiji_b, sizeof(gaiji_b), 1);
- state_fio->Fread(gaiji_r, sizeof(gaiji_r), 1);
- state_fio->Fread(gaiji_g, sizeof(gaiji_g), 1);
-#endif
- cur_code = state_fio->FgetUint8();
- cur_line = state_fio->FgetUint8();
- kaddr = state_fio->FgetInt32();
- kofs = state_fio->FgetInt32();
- kflag = state_fio->FgetInt32();
- kanji_ptr = &kanji[0] + state_fio->FgetInt32();
- state_fio->Fread(pal, sizeof(pal), 1);
- priority = state_fio->FgetUint8();
- state_fio->Fread(pri, sizeof(pri), 1);
- column40 = state_fio->FgetBool();
+ state_fio->StateValue(zpal_num);
+ state_fio->StateArrayScrnType_t(zpalette_pc, sizeof(zpalette_pc), 1);
+#endif
+ state_fio->StateValue(prev_vert_double);
+ state_fio->StateValue(raster);
+ state_fio->StateValue(cblink);
+ state_fio->StateValue(ch_height);
+ state_fio->StateValue(hz_total);
+ state_fio->StateValue(hz_disp);
+ state_fio->StateValue(vt_disp);
+ state_fio->StateValue(st_addr);
+ state_fio->StateValue(vblank_clock);
+ state_fio->StateValue(cur_blank);
+
+ // post process
+ if(loading) {
+ for(int i = 0; i < 8; i++) {
+ palette_pc[i ] = RGB_COLOR((i & 2) ? 255 : 0, (i & 4) ? 255 : 0, (i & 1) ? 255 : 0); // text
+ palette_pc[i + 8] = RGB_COLOR((i & 2) ? 255 : 0, (i & 4) ? 255 : 0, (i & 1) ? 255 : 0); // cg
+ }
+ // Copy images to draw buffers.
+ my_memcpy(dr_text, text, sizeof(dr_text));
+ my_memcpy(dr_cg, cg, sizeof(dr_cg));
#ifdef _X1TURBO_FEATURE
- mode1 = state_fio->FgetUint8();
- mode2 = state_fio->FgetUint8();
- hireso = state_fio->FgetBool();
+ for(int v = 0; v < 400; v++) {
+ memcpy(&pri_line[v][0][0], &pri[0][0], sizeof(pri));
+ }
+#else
+ for(int v = 0; v < 200; v++) {
+ memcpy(&pri_line[v][0][0], &pri[0][0], sizeof(pri));
+ }
#endif
+ my_memcpy(dr_pri_line, pri_line, sizeof(dr_pri_line));
+ my_memcpy(dr_palette_pc, palette_pc, sizeof(dr_palette_pc));
+ dr_priority = priority;
#ifdef _X1TURBOZ
- zmode1 = state_fio->FgetUint8();
- zpriority = state_fio->FgetUint8();
- zadjust = state_fio->FgetUint8();
- zmosaic = state_fio->FgetUint8();
- zchromakey = state_fio->FgetUint8();
- zscroll = state_fio->FgetUint8();
- zmode2 = state_fio->FgetUint8();
- state_fio->Fread(ztpal, sizeof(ztpal), 1);
- state_fio->Fread(zpal, sizeof(zpal), 1);
- zpal_num = state_fio->FgetInt32();
- state_fio->Fread(zpalette_pc, sizeof(zpalette_pc), 1);
-#endif
- prev_vert_double = state_fio->FgetBool();
- raster = state_fio->FgetInt32();
- cblink = state_fio->FgetInt32();
- ch_height = state_fio->FgetInt32();
- hz_total = state_fio->FgetInt32();
- hz_disp = state_fio->FgetInt32();
- vt_disp = state_fio->FgetInt32();
- st_addr = state_fio->FgetInt32();
- vblank_clock = state_fio->FgetUint32();
- cur_blank = state_fio->FgetBool();
-
- // post process
- // Copy images to draw buffers.
- my_memcpy(dr_text, text, sizeof(dr_text));
- my_memcpy(dr_cg, cg, sizeof(dr_cg));
- my_memcpy(dr_pri_line, pri_line, sizeof(dr_pri_line));
- my_memcpy(dr_palette_pc, palette_pc, sizeof(dr_palette_pc));
- dr_priority = priority;
-#ifdef _X1TURBOZ
- dr_zpriority = zpriority;
- my_memcpy(dr_zcg, zcg, sizeof(dr_zcg));
- my_memcpy(dr_aen_line, aen_line, sizeof(dr_aen_line));
- my_memcpy(dr_zpalette_pc, zpalette_pc, sizeof(zpalette_pc));
- zpalette_pc[8 + 0] = zpalette_pc[16 + 0x000];
- zpalette_pc[8 + 1] = zpalette_pc[16 + 0x00f];
- zpalette_pc[8 + 2] = zpalette_pc[16 + 0x0f0];
- zpalette_pc[8 + 3] = zpalette_pc[16 + 0x0ff];
- zpalette_pc[8 + 4] = zpalette_pc[16 + 0xf00];
- zpalette_pc[8 + 5] = zpalette_pc[16 + 0xf0f];
- zpalette_pc[8 + 6] = zpalette_pc[16 + 0xff0];
- zpalette_pc[8 + 7] = zpalette_pc[16 + 0xfff];
+ dr_zpriority = zpriority;
+ my_memcpy(dr_zcg, zcg, sizeof(dr_zcg));
+ my_memcpy(dr_aen_line, aen_line, sizeof(dr_aen_line));
+ my_memcpy(dr_zpalette_pc, zpalette_pc, sizeof(zpalette_pc));
+ zpalette_pc[8 + 0] = zpalette_pc[16 + 0x000];
+ zpalette_pc[8 + 1] = zpalette_pc[16 + 0x00f];
+ zpalette_pc[8 + 2] = zpalette_pc[16 + 0x0f0];
+ zpalette_pc[8 + 3] = zpalette_pc[16 + 0x0ff];
+ zpalette_pc[8 + 4] = zpalette_pc[16 + 0xf00];
+ zpalette_pc[8 + 5] = zpalette_pc[16 + 0xf0f];
+ zpalette_pc[8 + 6] = zpalette_pc[16 + 0xff0];
+ zpalette_pc[8 + 7] = zpalette_pc[16 + 0xfff];
#endif
-
- update_crtc(); // force update timing
-
- return true;
+ update_crtc(); // force update timing
+ }
+ return true;
}
+}