OSDN Git Service

[VM] Update DLLs.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 11 Apr 2019 12:41:05 +0000 (21:41 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 11 Apr 2019 12:41:05 +0000 (21:41 +0900)
[COMMON] Add RINGBUFFER:: class, extend of FIFO::.
[FIFO] Add [fill|empty] warning feature.This may be useful for some devices. i.e. 16550 UART, variants of i8251.

12 files changed:
source/build-cmake/cmake/config_emupc9801.cmake
source/build-cmake/cmake/config_mz5500.cmake
source/build-cmake/cmake/config_qc10.cmake
source/build-cmake/mz3500/CMakeLists.txt
source/build-cmake/n5200/CMakeLists.txt
source/src/CMakeLists.txt
source/src/fifo.cpp
source/src/fifo.h
source/src/qt/emuutils/CMakeLists.txt
source/src/ringbuffer.cpp [new file with mode: 0644]
source/src/ringbuffer.h [new file with mode: 0644]
source/src/vm/common_vm/CMakeLists.txt

index 73b8e0b..39b4419 100644 (file)
@@ -6,7 +6,6 @@ set(WITH_MOUSE ON)
 
 set(VMFILES
                   i8237.cpp
-                  upd7220.cpp
 
                   event.cpp
                   io.cpp
@@ -22,7 +21,7 @@ set(VMFILES_LIB
                   pc80s31k.cpp
                   tms3631.cpp
                   upd1990a.cpp
-                  upd7220_base.cpp
+                  upd7220.cpp
                   upd765a.cpp
                   ym2203.cpp
                   prnfile.cpp
index bc7e740..d676c3e 100644 (file)
@@ -11,8 +11,6 @@ set(VMFILES
                   i8237.cpp
                   mz1p17.cpp
                   
-                  upd7220.cpp
-                  
                   event.cpp
                   io.cpp
 )
@@ -28,8 +26,8 @@ set(VMFILES_LIB
                   noise.cpp
                   prnfile.cpp
                   rp5c01.cpp
-                  upd7220_base.cpp
                   upd765a.cpp
+                  upd7220.cpp
                   z80ctc.cpp
                   z80sio.cpp
 )
index fa7b050..612790a 100644 (file)
@@ -6,7 +6,6 @@ set(WITH_MOUSE OFF)
 set(FLAG_USE_Z80 ON)
 set(VMFILES
                   i8237.cpp
-                  upd7220.cpp
                   io.cpp
                   event.cpp
 )
@@ -16,9 +15,9 @@ set(VMFILES_LIB
                   i8253.cpp
                   i8255.cpp
                   i8259.cpp
-                  upd7220_base.cpp
                   hd146818p.cpp
                   pcm1bit.cpp
+                  upd7220.cpp
                   upd765a.cpp
                   z80sio.cpp
 
index 26a447d..2e96771 100644 (file)
@@ -19,10 +19,6 @@ set(WITH_JOYSTICK OFF)
 set(WITH_MOUSE ON)
 
 set(VMFILES
-#         z80.cpp
-          
-          upd7220.cpp
-   
           mz1p17.cpp
           event.cpp
           io.cpp
@@ -38,7 +34,7 @@ set(VMFILES_LIB
           pcm1bit.cpp
           upd1990a.cpp
           upd765a.cpp
-          upd7220_base.cpp
+          upd7220.cpp
           
           prnfile.cpp
           
index 96b75f0..865380e 100644 (file)
@@ -24,7 +24,6 @@ set(WITH_MOUSE ON)
 set(VMFILES_BASE
 #                  i386.cpp
                   i8237.cpp
-                  upd7220.cpp
                   
                   io.cpp
                   event.cpp
@@ -38,7 +37,7 @@ set(VMFILES_LIB
                   i8259.cpp
                   noise.cpp
                   upd1990a.cpp
-                  upd7220_base.cpp
+                  upd7220.cpp
                   upd765a.cpp
                   disk.cpp
 )
index d490826..b18c09d 100644 (file)
@@ -17,5 +17,6 @@ else()
        debugger.cpp
        fileio.cpp
        fifo.cpp
+       ringbuffer.cpp
        )
 endif()
index d0c7aad..802e96e 100644 (file)
 #include "fifo.h"
 #include "fileio.h"
 
-FIFO::FIFO(int s)
+FIFO::FIFO(int s, int empty_warn, int fill_warn)
 {
        size = s;
-       buf = (int*)malloc(size * sizeof(int));
+       //buf = (int*)malloc(size * sizeof(int));
+       buf = new int[size];
+       
        cnt = rpt = wpt = 0;
+       empty_warn_val = empty_warn;
+       if(fill_warn <= 0) {
+               fill_warn_val = INT_MAX;
+       } else {
+               fill_warn_val = fill_warn;
+       }
 }
 
 void FIFO::release()
 {
-       free(buf);
+       //free(buf);
+       delete[] buf;
 }
 
 void FIFO::clear()
 {
        cnt = rpt = wpt = 0;
+       fill_warn_flag = false;
+       if(empty_warn_val > 0) empty_warn_flag = false;
 }
 
-void FIFO::write(int val)
+void FIFO::write(int val, bool *p_fill_warn)
 {
        if(cnt < size) {
                buf[wpt++] = val;
@@ -37,10 +48,18 @@ void FIFO::write(int val)
                        wpt = 0;
                }
                cnt++;
+               if(fill_warn_val < cnt) {
+                       fill_warn_flag = true;
+               } else {
+                       fill_warn_flag = false;
+               }
+               if(p_fill_warn != nullptr) {
+                       *p_fill_warn = fill_warn_flag;
+               }
        }
 }
 
-int FIFO::read()
+int FIFO::read(bool *p_empty_warn)
 {
        int val = 0;
        if(cnt) {
@@ -49,23 +68,42 @@ int FIFO::read()
                        rpt = 0;
                }
                cnt--;
+               if(empty_warn_val > cnt) {
+                       empty_warn_flag = true;
+               } else {
+                       empty_warn_flag = false;
+               }
+               if(p_empty_warn != nullptr) {
+                       *p_empty_warn = empty_warn_flag;
+               }
        }
        return val;
 }
 
-int FIFO::read_not_remove(int pt)
+int FIFO::read_not_remove(int pt, bool *p_empty_warn)
 {
        if(pt >= 0 && pt < cnt) {
                pt += rpt;
                if(pt >= size) {
                        pt -= size;
                }
+               if(empty_warn_val > cnt) {
+                       empty_warn_flag = true;
+               } else {
+                       empty_warn_flag = false;
+               }
+               if(p_empty_warn != nullptr) {
+                       *p_empty_warn = empty_warn_flag;
+               }
                return buf[pt];
        }
+       if(p_empty_warn != nullptr) {
+               *p_empty_warn = false;
+       }
        return 0;
 }
 
-void FIFO::write_not_push(int pt, int d)
+void FIFO::write_not_push(int pt, int d, bool *p_fill_warn)
 {
        if(pt >= 0 && pt < cnt) {
                pt += wpt;
@@ -73,6 +111,18 @@ void FIFO::write_not_push(int pt, int d)
                        pt -= size;
                }
                buf[pt] = d;
+               if(fill_warn_val < cnt) {
+                       fill_warn_flag = true;
+               } else {
+                       fill_warn_flag = false;
+               }
+               if(p_fill_warn != nullptr) {
+                       *p_fill_warn = fill_warn_flag;
+               }
+               return;
+       }
+       if(p_fill_warn != nullptr) {
+               *p_fill_warn = false;
        }
 }
 
index e810ef9..fad118b 100644 (file)
 
 #include "common.h"
 
-class csp_state_data_saver;
 class DLL_PREFIX FIFO
 {
-private:
+protected:
        int size;
        int* buf;
        int cnt, rpt, wpt;
-
+       int empty_warn_val, fill_warn_val;
+       bool empty_warn_flag, fill_warn_flag;
 public:
-       FIFO(int s);
-       void release();
-       void clear();
-       void write(int val);
-       int read();
-       int read_not_remove(int pt);
-       void write_not_push(int pt, int d);
-       int count();
-       bool full();
-       bool empty();
-       bool process_state(void *f, bool loading);
+       FIFO(int s, int empty_warn = -1, int fill_warn = -1);
+       virtual void release();
+       virtual void clear();
+       virtual void write(int val, bool *p_fill_warn = nullptr);
+       virtual int read(bool *p_empty_warn = nullptr);
+       virtual int read_not_remove(int pt, bool *p_empty_warn = nullptr);
+       virtual void write_not_push(int pt, int d, bool *p_fill_warn = nullptr);
+       virtual int count();
+       virtual bool full();
+       virtual bool empty();
+       virtual bool is_fill_warn() { return fill_warn_flag; }
+       virtual bool is_fill_warn_or_empty_warn() { return ((fill_warn_flag) || (empty_warn_flag)); }
+       virtual bool is_empty_warn() { return empty_warn_flag; }
+       virtual void modify_fill_warn_val(int n) { fill_warn_val = n; }
+       virtual void modify_empty_warn_val(int n) { empty_warn_val = n; }
+       virtual void clear_fill_warn() { fill_warn_flag = false; }
+       virtual void clear_empty_warn() { empty_warn_flag = false; }
+       virtual bool process_state(void *f, bool loading);
 };
 
 #endif
index b511442..7c2dac0 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 2.15.4)
+SET(THIS_LIB_VERSION 2.16.0)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
@@ -10,6 +10,7 @@ set(s_qt_emuutils_srcs
          ../../common.cpp
          ../../fifo.cpp
          ../../fileio.cpp
+         ../../ringbuffer.cpp
          ../gui/csp_logger.cpp
          )
 
diff --git a/source/src/ringbuffer.cpp b/source/src/ringbuffer.cpp
new file mode 100644 (file)
index 0000000..eeb85bd
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+       Skelton for retropc emulator
+
+       Author : Kyuma.Ohta <whatisthis.sowhat _at_ gmail.com>
+       Date   : 2019.04.11-
+
+       [ ring buffer ]
+*/
+
+
+#include "ringbuffer.h"
+
+RINGBUFFER::RINGBUFFER(int s, int empty_warn, int fill_warn) : FIFO(s, empty_warn, fill_warn)
+{
+       
+}
+
+void RINGBUFFER::write(int val, bool *p_fill_warn)
+{
+       buf[wpt++] = val;
+       if(wpt >= size) {
+               wpt = 0;
+       }
+       cnt++;
+       if(cnt >= size) cnt = size;
+       if(fill_warn_val < cnt) {
+               fill_warn_flag = true;
+       } else {
+               fill_warn_flag = false;
+       }
+       if(p_fill_warn != nullptr) {
+               *p_fill_warn = fill_warn_flag;
+       }
+}
+
+int RINGBUFFER::read(bool *p_empty_warn)
+{
+       int val = 0;
+       if(cnt > 0) {
+               val = buf[rpt++];
+               if(rpt >= size) {
+                       rpt = 0;
+               }
+               cnt--;
+               if(cnt < 0) cnt = 0;
+               if(empty_warn_val > cnt) {
+                       empty_warn_flag = true;
+               } else {
+                       empty_warn_flag = false;
+               }
+               if(p_empty_warn != nullptr) {
+                       *p_empty_warn = empty_warn_flag;
+               }
+       }
+       return val;
+}
+
+int RINGBUFFER::read_not_remove(int pt, bool *p_empty_warn)
+{
+       if(pt >= 0 && pt < size) {
+               pt += rpt;
+               if(pt >= size) {
+                       pt -= size;
+               }
+               if(empty_warn_val > cnt) {
+                       empty_warn_flag = true;
+               } else {
+                       empty_warn_flag = false;
+               }
+               if(p_empty_warn != nullptr) {
+                       *p_empty_warn = empty_warn_flag;
+               }
+               return buf[pt];
+       }
+       if(p_empty_warn != nullptr) {
+               *p_empty_warn = false;
+       }
+       return 0;
+}
+
+void RINGBUFFER::write_not_push(int pt, int d, bool *p_fill_warn)
+{
+       if(pt >= 0 && pt < size) {
+               pt += wpt;
+               if(pt >= size) {
+                       pt -= size;
+               }
+               buf[pt] = d;
+               if(fill_warn_val < cnt) {
+                       fill_warn_flag = true;
+               } else {
+                       fill_warn_flag = false;
+               }
+               if(p_fill_warn != nullptr) {
+                       *p_fill_warn = fill_warn_flag;
+               }
+               return;
+       }
+       if(p_fill_warn != nullptr) {
+               *p_fill_warn = false;
+       }
+}
+
diff --git a/source/src/ringbuffer.h b/source/src/ringbuffer.h
new file mode 100644 (file)
index 0000000..3754b03
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+       Skelton for retropc emulator
+
+       Author : Kyuma.Ohta <whatisthis.sowhat _at_ gmail.com>
+       Date   : 2019.04.11-
+
+       [ ring buffer ]
+*/
+
+#pragma once
+
+#include "fifo.h"
+
+class DLL_PREFIX RINGBUFFER : public FIFO
+{
+public:
+       RINGBUFFER(int s, int empty_warn = -1, int fill_warn = -1);
+       virtual void write(int val, bool *p_fill_warn = nullptr);
+       virtual int read(bool *p_empty_warn = nullptr);
+       virtual int read_not_remove(int pt, bool *p_empty_warn = nullptr);
+       virtual void write_not_push(int pt, int d, bool *p_fill_warn = nullptr);
+};
index d2145a7..ad97dce 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 2.10.2)
+SET(THIS_LIB_VERSION 2.11.0)
 
 #include(cotire)
 set(s_vm_common_vm_srcs
@@ -78,7 +78,7 @@ set(s_vm_common_vm_srcs
        ../upd1990a.cpp
        ../upd4991a.cpp
        ../upd71071.cpp
-       ../upd7220_base.cpp
+       ../upd7220.cpp
        ../upd765a.cpp
        ../upd7752.cpp
        ../upd7801.cpp