diff options
author | Aki <please@ignore.pl> | 2021-10-24 00:55:16 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-10-24 00:55:16 +0200 |
commit | b28a51120c8fca3105387f2931023a025dea3753 (patch) | |
tree | b6b713b0ce88fd28b2e7fafe749be367c4017d0b /src/memory.cpp | |
parent | 3a183df872409594e74d3c55e3c1eedf9ee8abec (diff) | |
download | hwd-python-b28a51120c8fca3105387f2931023a025dea3753.zip hwd-python-b28a51120c8fca3105387f2931023a025dea3753.tar.gz hwd-python-b28a51120c8fca3105387f2931023a025dea3753.tar.bz2 |
Added memory module
Diffstat (limited to 'src/memory.cpp')
-rw-r--r-- | src/memory.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/memory.cpp b/src/memory.cpp new file mode 100644 index 0000000..415695d --- /dev/null +++ b/src/memory.cpp @@ -0,0 +1,41 @@ +#define PY_SSIZE_T_CLEAN +#include <Python.h> + +#include <cstddef> +#include <vector> + +#include <hwd.h> + + +static PyObject * memory_write(PyObject * self, PyObject * args) +{ + Py_ssize_t offset; + Py_buffer data; + if (!PyArg_ParseTuple(args, "y*n", &data, &offset)) + return NULL; + hwd::memory::write( + std::vector<char> {static_cast<char *>(data.buf), static_cast<char *>(data.buf) + data.len}, + static_cast<std::size_t>(offset)); + Py_RETURN_NONE; +} + + +static PyMethodDef memory_methods[] = { + {"write", memory_write, METH_VARARGS, "mem_write(data, offset)\n--\n\nWrites *data* to memory at *offset*."}, + {NULL, NULL, 0, NULL} +}; + + +static struct PyModuleDef memory_module = { + PyModuleDef_HEAD_INIT, + "memory", + NULL, + -1, + memory_methods +}; + + +PyMODINIT_FUNC PyInit_memory(void) +{ + return PyModule_Create(&memory_module); +} |