OSDN Git Service

[VM][X1] Copy VRAMs to shadow data at starting a frame.Reduce flickering a lot.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 28 May 2018 13:28:46 +0000 (22:28 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 28 May 2018 13:28:46 +0000 (22:28 +0900)
source/src/qt/machines/x1/menuclasses.h
source/src/vm/x1/display.cpp
source/src/vm/x1/display.h

index 730d0e1..0973797 100644 (file)
@@ -16,13 +16,7 @@ public:
        Object_Menu_Control_X1(QObject *parent, USING_FLAGS *p);
        ~Object_Menu_Control_X1();
 signals:
-#if !defined(_X1)
-       void sig_display_mode(int);
-#endif
 public slots:
-#if !defined(_X1)
-       void do_set_display_mode(void);
-#endif
 };
 
 class Action_Control_X1 : public Action_Control
@@ -41,11 +35,6 @@ class CSP_Logger;
 class META_MainWindow : public Ui_MainWindow {
        Q_OBJECT
 protected:
-#if !defined(_X1)  
-       QActionGroup   *actionGroup_DisplayMode;
-       class Action_Control_X1 *action_Emu_DisplayMode[2]; // 0=Hi / 1 = Lo
-       QMenu *menu_Emu_DisplayMode;
-#endif
        void setupUI_Emu(void);
        void retranslateUi(void);
 public:
index 969725a..c0c6576 100644 (file)
@@ -123,6 +123,27 @@ void DISPLAY::initialize()
        // register event
        register_frame_event(this);
        register_vline_event(this);
+
+       // 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];
+#endif 
 }
 
 void DISPLAY::reset()
@@ -149,6 +170,27 @@ void DISPLAY::reset()
        
        kaddr = kofs = kflag = 0;
        kanji_ptr = &kanji[0];
+
+       // 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];
+#endif 
 }
 
 void DISPLAY::write_io8(uint32_t addr, uint32_t data)
@@ -541,12 +583,42 @@ void DISPLAY::event_frame()
        int vt_total = ((regs[4] & 0x7f) + 1) * ch_height + (regs[5] & 0x1f);
        hireso = (vt_total > 400);
 #endif
-       
+       int vlen;
+#ifdef _X1TURBO_FEATURE
+       vlen = (hireso) ? 400 : 200;
+#else
+       vlen = 200;
+#endif
+       if(vlen > 0) {
+               // Copy images to draw buffers.
+               my_memcpy(dr_text, text, sizeof(uint8_t) * vlen * (640 + 8));
+               my_memcpy(dr_cg, cg, sizeof(uint8_t) * vlen * 640);
+               my_memcpy(dr_pri_line, pri_line, sizeof(uint8_t) * vlen * 8 * 8);
+       }
+       my_memcpy(dr_palette_pc, palette_pc, sizeof(dr_palette_pc));
+       dr_priority = priority;
        // initialize draw screen
        memset(text, 0, sizeof(text));
        memset(cg, 0, sizeof(cg));
        memset(pri_line, 0, sizeof(pri_line));
 #ifdef _X1TURBOZ
+       if(vlen > 0) {
+       // Copy images to draw buffers.
+               my_memcpy(&(dr_zcg[0][0][0]), &(zcg[0][0][0]), sizeof(uint8_t) * vlen * 640);
+               //my_memcpy(dr_aen_line, aen_line, sizeof(bool) * vlen);
+       }
+       my_memcpy(dr_aen_line, aen_line, sizeof(aen_line));
+       dr_zpriority = zpriority;
+       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];
+       
        memset(zcg, 0, sizeof(zcg));
        memset(aen_line, 0, sizeof(aen_line));
 #endif
@@ -557,6 +629,46 @@ void DISPLAY::event_frame()
 void DISPLAY::event_vline(int v, int clock)
 {
        cur_vline = v;
+
+#if 0
+       // Copy images to draw buffers.
+       int vlimit;
+#ifdef _X1TURBO_FEATURE
+       vlimit = (hireso) ? 400 : 200;
+#else
+       vlimit = 200;
+#endif
+       if((v > vlimit) || (v < 0)) return;
+       
+       if(v == vlimit) {
+               my_memcpy(dr_palette_pc, palette_pc, sizeof(palette_pc));
+#ifdef _X1TURBOZ
+               my_memcpy(dr_zpalette_pc, zpalette_pc, sizeof(zpalette_pc));
+#endif
+               // Copy images to draw buffers.
+               //my_memcpy(&(dr_text[v][0]), &(text[v][0]), sizeof(uint8_t) * (640 + 8));
+               //my_memcpy(&(dr_cg[v][0]), &(cg[v][0]), sizeof(uint8_t) * 640);
+               //my_memcpy(&(dr_pri_line[v][0][0]), &(pri_line[v][0][0]), sizeof(uint8_t) * 8 * 8);
+#ifdef _X1TURBOZ
+               //my_memcpy(&(dr_zcg[0][v][0]), &(zcg[0][v][0]), sizeof(uint8_t) * 640);
+               //my_memcpy(&(dr_zcg[1][v][0]), &(zcg[1][v][0]), sizeof(uint8_t) * 640);
+               //dr_aen_line[v] = aen_line[v];
+#endif
+       } else if(v == 0) {
+               return;
+       }
+       // Copy images to draw buffers.
+       my_memcpy(&(dr_text[v - 1][0]), &(text[v - 1][0]), sizeof(uint8_t) * (640 + 8));
+       my_memcpy(&(dr_cg[v - 1][0]), &(cg[v -1 ][0]), sizeof(uint8_t) * 640);
+       my_memcpy(&(dr_pri_line[v - 1][0][0]), &(pri_line[v - 1][0][0]), sizeof(uint8_t) * 8 * 8);
+       dr_priority = priority;
+#ifdef _X1TURBOZ
+       my_memcpy(&(dr_zcg[0][v - 1 ][0]), &(zcg[0][v - 1][0]), sizeof(uint8_t) * 640);
+       my_memcpy(&(dr_zcg[1][v - 1][0]), &(zcg[1][v - 1][0]), sizeof(uint8_t) * 640);
+       dr_zpriority = zpriority;
+       dr_aen_line[v - 1] = aen_line[v - 1];
+#endif
+#endif
 }
 
 #ifdef _X1TURBO_FEATURE
@@ -732,14 +844,14 @@ void DISPLAY::draw_screen()
 {
        // copy to real screen
 #ifdef _X1TURBOZ
-       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_zpalette_pc[8 + 0] = dr_zpalette_pc[16 + 0x000];
+       dr_zpalette_pc[8 + 1] = dr_zpalette_pc[16 + 0x00f];
+       dr_zpalette_pc[8 + 2] = dr_zpalette_pc[16 + 0x0f0];
+       dr_zpalette_pc[8 + 3] = dr_zpalette_pc[16 + 0x0ff];
+       dr_zpalette_pc[8 + 4] = dr_zpalette_pc[16 + 0xf00];
+       dr_zpalette_pc[8 + 5] = dr_zpalette_pc[16 + 0xf0f];
+       dr_zpalette_pc[8 + 6] = dr_zpalette_pc[16 + 0xff0];
+       dr_zpalette_pc[8 + 7] = dr_zpalette_pc[16 + 0xfff];
 #endif
 #ifdef _X1TURBO_FEATURE
        if(hireso) {
@@ -749,10 +861,10 @@ void DISPLAY::draw_screen()
                        // 40 columns
                        for(int y = 0; y < 400; y++) {
                                scrntype_t* dest = emu->get_screen_buffer(y);
-                               uint8_t* src_text = text[y];
+                               uint8_t* src_text = dr_text[y];
 #ifdef _X1TURBOZ
-                               if(aen_line[y]) {
-                                       uint16_t* src_cg0 = zcg[0][y];
+                               if(dr_aen_line[y]) {
+                                       uint16_t* src_cg0 = dr_zcg[0][y];
                                        
                                        for(int x = 0, x2 = 0; x < 320; x++, x2 += 2) {
                                                uint16_t cg00 = src_cg0[x] | (src_cg0[x] >> 2);
@@ -761,13 +873,13 @@ void DISPLAY::draw_screen()
                                        }
                                } else {
 #endif
-                                       uint8_t* src_cg = cg[y];
+                                       uint8_t* src_cg = dr_cg[y];
                                        
                                        for(int x = 0, x2 = 0; x < 320; x++, x2 += 2) {
 #ifdef _X1TURBOZ
-                                               dest[x2] = dest[x2 + 1] = zpalette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest[x2] = dest[x2 + 1] = dr_zpalette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #else
-                                               dest[x2] = dest[x2 + 1] =  palette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest[x2] = dest[x2 + 1] =  dr_palette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #endif
                                        }
 #ifdef _X1TURBOZ
@@ -778,10 +890,10 @@ void DISPLAY::draw_screen()
                        // 80 columns
                        for(int y = 0; y < 400; y++) {
                                scrntype_t* dest = emu->get_screen_buffer(y);
-                               uint8_t* src_text = text[y];
+                               uint8_t* src_text = dr_text[y];
 #ifdef _X1TURBOZ
-                               if(aen_line[y]) {
-                                       uint16_t* src_cg0 = zcg[0][y];
+                               if(dr_aen_line[y]) {
+                                       uint16_t* src_cg0 = dr_zcg[0][y];
                                        
                                        for(int x = 0; x < 640; x++) {
                                                uint16_t cg00 = src_cg0[x] | (src_cg0[x] >> 2);
@@ -790,13 +902,13 @@ void DISPLAY::draw_screen()
                                        }
                                } else {
 #endif
-                                       uint8_t* src_cg = cg[y];
+                                       uint8_t* src_cg = dr_cg[y];
                                        
                                        for(int x = 0; x < 640; x++) {
 #ifdef _X1TURBOZ
-                                               dest[x] = zpalette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest[x] = dr_zpalette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #else
-                                               dest[x] =  palette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest[x] =  dr_palette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #endif
                                        }
 #ifdef _X1TURBOZ
@@ -816,11 +928,11 @@ void DISPLAY::draw_screen()
                        for(int y = 0; y < 200; y++) {
                                scrntype_t* dest0 = emu->get_screen_buffer(y * 2 + 0);
                                scrntype_t* dest1 = emu->get_screen_buffer(y * 2 + 1);
-                               uint8_t* src_text = text[y];
+                               uint8_t* src_text = dr_text[y];
 #ifdef _X1TURBOZ
-                               if(aen_line[y]) {
-                                       uint16_t* src_cg0 = zcg[0][y];
-                                       uint16_t* src_cg1 = zcg[1][y];
+                               if(dr_aen_line[y]) {
+                                       uint16_t* src_cg0 = dr_zcg[0][y];
+                                       uint16_t* src_cg1 = dr_zcg[1][y];
                                        
                                        if(C64) {
                                                for(int x = 0, x2 = 0; x < 320; x++, x2 += 2) {
@@ -839,13 +951,13 @@ void DISPLAY::draw_screen()
                                } else {
 #endif
                                        scrntype_t* dest = emu->get_screen_buffer(y);
-                                       uint8_t* src_cg = cg[y];
+                                       uint8_t* src_cg = dr_cg[y];
                                
                                        for(int x = 0, x2 = 0; x < 320; x++, x2 += 2) {
 #ifdef _X1TURBOZ
-                                               dest0[x2] = dest0[x2 + 1] = zpalette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest0[x2] = dest0[x2 + 1] = dr_zpalette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #else
-                                               dest0[x2] = dest0[x2 + 1] =  palette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest0[x2] = dest0[x2 + 1] =  dr_palette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #endif
                                        }
 #ifdef _X1TURBOZ
@@ -862,10 +974,10 @@ void DISPLAY::draw_screen()
                        for(int y = 0; y < 200; y++) {
                                scrntype_t* dest0 = emu->get_screen_buffer(y * 2 + 0);
                                scrntype_t* dest1 = emu->get_screen_buffer(y * 2 + 1);
-                               uint8_t* src_text = text[y];
+                               uint8_t* src_text = dr_text[y];
 #ifdef _X1TURBOZ
                                if(aen_line[y]) {
-                                       uint16_t* src_cg0 = zcg[0][y];
+                                       uint16_t* src_cg0 = dr_zcg[0][y];
                                        
                                        for(int x = 0; x < 640; x++) {
                                                uint16_t cg00 = src_cg0[x] | (src_cg0[x] >> 2);
@@ -874,13 +986,13 @@ void DISPLAY::draw_screen()
                                        }
                                } else {
 #endif
-                                       uint8_t* src_cg = cg[y];
+                                       uint8_t* src_cg = dr_cg[y];
                                        
                                        for(int x = 0; x < 640; x++) {
 #ifdef _X1TURBOZ
-                                               dest0[x] = zpalette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest0[x] = dr_zpalette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #else
-                                               dest0[x] =  palette_pc[pri_line[y][src_cg[x]][src_text[x]]];
+                                               dest0[x] =  dr_palette_pc[dr_pri_line[y][src_cg[x]][src_text[x]]];
 #endif
                                        }
 #ifdef _X1TURBOZ
@@ -1182,15 +1294,15 @@ scrntype_t DISPLAY::get_zpriority(uint8_t text, uint16_t cg0, uint16_t cg1)
 {
        if((mode2 & 8) && (text == (mode2 & 7))) {
                int digital = ((cg0 >> 9) & 4) | ((cg0 >> 6) & 2) | ((cg0 >> 3) & 1);
-               if(!(priority & (1 << digital))) {
+               if(!(dr_priority & (1 << digital))) {
                        return 0;
                }
        }
-       uint16_t fore = ((zpriority & 0x18) != 0x18) ? cg0 : cg1;
-       uint16_t back = ((zpriority & 0x18) != 0x18) ? cg1 : cg0;
+       uint16_t fore = ((dr_zpriority & 0x18) != 0x18) ? cg0 : cg1;
+       uint16_t back = ((dr_zpriority & 0x18) != 0x18) ? cg1 : cg0;
        uint16_t disp;
        
-       switch(zpriority & 0x13) {
+       switch(dr_zpriority & 0x13) {
        case 0x00:
        case 0x02:
                disp = text ? text : (fore + 16);
@@ -1218,7 +1330,7 @@ scrntype_t DISPLAY::get_zpriority(uint8_t text, uint16_t cg0, uint16_t cg1)
 //     if((mode2 & 0x20) && disp == (0x00f + 16)) {
 //             return 0;
 //     }
-       return zpalette_pc[disp];
+       return dr_zpalette_pc[disp];
 }
 #endif
 
@@ -1520,6 +1632,27 @@ bool DISPLAY::load_state(FILEIO* state_fio)
        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];
+#endif 
+
        update_crtc(); // force update timing
        
        return true;
index 61f20f1..c11d97b 100644 (file)
@@ -56,6 +56,7 @@ private:
        
        uint8_t pal[3];
        uint8_t priority, pri[8][8];    // pri[cg][txt]
+       uint8_t dr_priority;
        
        bool column40;
 #ifdef _X1TURBO_FEATURE
@@ -71,6 +72,8 @@ private:
        uint8_t zscroll;
        uint8_t zmode2;
        uint8_t ztpal[8];
+       uint8_t dr_zpriority;
+
        struct {
                uint8_t b, r, g;
        } zpal[4096];
@@ -81,17 +84,31 @@ private:
        uint8_t text[400][640];
        uint8_t cg[400][640];
        uint8_t pri_line[400][8][8];
+
+       
+       uint8_t dr_text[400][640];
+       uint8_t dr_cg[400][640];
+       uint8_t dr_pri_line[400][8][8];
 #else
        uint8_t text[200][640+8];
        uint8_t cg[200][640];
        uint8_t pri_line[200][8][8];
+
+       uint8_t dr_text[200][640+8];
+       uint8_t dr_cg[200][640];
+       uint8_t dr_pri_line[200][8][8];
 #endif
 #ifdef _X1TURBOZ
        uint16_t zcg[2][400][640];
        bool aen_line[400];
        scrntype_t zpalette_pc[8+8+4096];       // 0-7:text, 8-15:cg, 16-:4096cg
+
+       uint16_t dr_zcg[2][400][640];
+       bool dr_aen_line[400];
+       scrntype_t dr_zpalette_pc[8+8+4096];    // 0-7:text, 8-15:cg, 16-:4096cg
 #endif
        scrntype_t palette_pc[8+8];             // 0-7:text, 8-15:cg
+       scrntype_t dr_palette_pc[8+8];          // 0-7:text, 8-15:cg
        bool prev_vert_double;
        int raster, cblink;