Skip to content

Commit e89a687

Browse files
committed
Merge branch 'master' of https://github.com/grumpycoders/pcsx-redux into ftdi
2 parents 70ad10b + 69cbb97 commit e89a687

File tree

16 files changed

+290
-18
lines changed

16 files changed

+290
-18
lines changed

src/core/cdriso.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
#include <stdio.h>
2424

25-
#include "core/file.h"
2625
#include "core/plugins.h"
2726
#include "core/psxemulator.h"
27+
#include "support/file.h"
2828

2929
namespace PCSX {
3030

src/core/psxmem.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
#include "core/psxmem.h"
2525
#include "core/debug.h"
26-
#include "core/file.h"
2726
#include "core/psxhw.h"
2827
#include "core/r3000a.h"
28+
#include "support/file.h"
2929

3030
int PCSX::Memory::psxMemInit() {
3131
int i;

src/core/sstate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
#pragma once
2121

22-
#include "core/protobuf.h"
2322
#include "main/settings.h"
2423
#include "spu/types.h"
24+
#include "support/protobuf.h"
2525

2626
namespace PCSX {
2727

src/core/system.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <iomanip>
2323
#include <sstream>
2424

25-
#include "core/file.h"
2625
#include "core/system.h"
26+
#include "support/file.h"
2727

2828
PCSX::System* PCSX::g_system = NULL;
2929

src/main/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "flags.h"
3333
#include "gui/gui.h"
3434
#include "spu/interface.h"
35+
#include "support/slice.h"
3536

3637
static PCSX::GUI *s_gui;
3738

@@ -168,6 +169,7 @@ using json = nlohmann::json;
168169

169170
int main(int argc, char **argv) {
170171
const flags::args args(argc, argv);
172+
PCSX::Slice slice;
171173

172174
if (args.get<bool>("dumpproto")) {
173175
PCSX::SaveStates::ProtoFile::dumpSchema(std::cout);

src/spu/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#pragma once
2121

22-
#include "core/protobuf.h"
22+
#include "support/protobuf.h"
2323

2424
namespace PCSX {
2525

src/core/file.cc renamed to src/support/file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <algorithm>
2121

22-
#include "core/file.h"
22+
#include "support/file.h"
2323

2424
const uint8_t PCSX::File::m_internalBuffer = 0;
2525
void PCSX::File::close() {
File renamed without changes.
File renamed without changes.

src/support/slice.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/***************************************************************************
2+
* Copyright (C) 2020 PCSX-Redux authors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18+
***************************************************************************/
19+
20+
#pragma once
21+
22+
#include <assert.h>
23+
#include <stdint.h>
24+
25+
namespace PCSX {
26+
27+
class Slice {
28+
public:
29+
Slice() : m_isInlined(false), m_isOwned(false), m_size(0) {
30+
m_data.ptr = nullptr;
31+
}
32+
~Slice() { maybeFree(); }
33+
void copy(const void * data, uint32_t size) {
34+
assert(size < (1 << 30));
35+
maybeFree();
36+
m_size = size;
37+
m_isOwned = true;
38+
if (size > sizeof(m_data.inlined)) {
39+
m_isInlined = false;
40+
m_data.ptr = (uint8_t *) malloc(size);
41+
memcpy(m_data.ptr, data, size);
42+
} else {
43+
m_isInlined = true;
44+
memcpy(m_data.inlined, data, size);
45+
}
46+
}
47+
void acquire(void * data, uint32_t size) {
48+
assert(size < (1 << 30));
49+
maybeFree();
50+
m_size = size;
51+
m_isOwned = true;
52+
m_isInlined = false;
53+
m_data.ptr = data;
54+
}
55+
void borrow(const void * data, uint32_t size) {
56+
assert(size < (1 << 30));
57+
maybeFree();
58+
m_size = size;
59+
m_isOwned = false;
60+
m_isInlined = false;
61+
m_data.ptr = const_cast<void*>(data);
62+
}
63+
const void * data() { return m_isInlined ? m_data.inlined : m_data.ptr; }
64+
const uint32_t size() { return m_size; }
65+
private:
66+
void maybeFree() { if (m_isOwned && !m_isInlined) free(m_data.ptr); }
67+
union {
68+
uint8_t inlined[24];
69+
void * ptr;
70+
} m_data;
71+
bool m_isInlined : 1;
72+
bool m_isOwned : 1;
73+
uint32_t m_size : 30;
74+
};
75+
76+
} // namespace PCSX

0 commit comments

Comments
 (0)