[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.
set(VMFILES
i8237.cpp
- upd7220.cpp
event.cpp
io.cpp
pc80s31k.cpp
tms3631.cpp
upd1990a.cpp
- upd7220_base.cpp
+ upd7220.cpp
upd765a.cpp
ym2203.cpp
prnfile.cpp
i8237.cpp
mz1p17.cpp
- upd7220.cpp
-
event.cpp
io.cpp
)
noise.cpp
prnfile.cpp
rp5c01.cpp
- upd7220_base.cpp
upd765a.cpp
+ upd7220.cpp
z80ctc.cpp
z80sio.cpp
)
set(FLAG_USE_Z80 ON)
set(VMFILES
i8237.cpp
- upd7220.cpp
io.cpp
event.cpp
)
i8253.cpp
i8255.cpp
i8259.cpp
- upd7220_base.cpp
hd146818p.cpp
pcm1bit.cpp
+ upd7220.cpp
upd765a.cpp
z80sio.cpp
set(WITH_MOUSE ON)
set(VMFILES
-# z80.cpp
-
- upd7220.cpp
-
mz1p17.cpp
event.cpp
io.cpp
pcm1bit.cpp
upd1990a.cpp
upd765a.cpp
- upd7220_base.cpp
+ upd7220.cpp
prnfile.cpp
set(VMFILES_BASE
# i386.cpp
i8237.cpp
- upd7220.cpp
io.cpp
event.cpp
i8259.cpp
noise.cpp
upd1990a.cpp
- upd7220_base.cpp
+ upd7220.cpp
upd765a.cpp
disk.cpp
)
debugger.cpp
fileio.cpp
fifo.cpp
+ ringbuffer.cpp
)
endif()
#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;
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) {
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;
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;
}
}
#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
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
../../common.cpp
../../fifo.cpp
../../fileio.cpp
+ ../../ringbuffer.cpp
../gui/csp_logger.cpp
)
--- /dev/null
+/*
+ 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;
+ }
+}
+
--- /dev/null
+/*
+ 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);
+};
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
../upd1990a.cpp
../upd4991a.cpp
../upd71071.cpp
- ../upd7220_base.cpp
+ ../upd7220.cpp
../upd765a.cpp
../upd7752.cpp
../upd7801.cpp