summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/textbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/debug/textbuf.cpp')
-rw-r--r--src/emu/debug/textbuf.cpp119
1 files changed, 54 insertions, 65 deletions
diff --git a/src/emu/debug/textbuf.cpp b/src/emu/debug/textbuf.cpp
index 279ce8dead6..48a6f71c5fd 100644
--- a/src/emu/debug/textbuf.cpp
+++ b/src/emu/debug/textbuf.cpp
@@ -8,9 +8,10 @@
***************************************************************************/
-#include "corealloc.h"
#include "textbuf.h"
+#include <new>
+
/***************************************************************************
@@ -27,47 +28,53 @@
struct text_buffer
{
- char * buffer;
- s32 * lineoffs;
- s32 bufsize;
- s32 bufstart;
- s32 bufend;
- s32 linesize;
- s32 linestart;
- s32 lineend;
- u32 linestartseq;
- s32 maxwidth;
-};
-
-
-
-/***************************************************************************
- INLINE FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- buffer_used - return the number of bytes
- currently held in the buffer
--------------------------------------------------*/
-
-static inline s32 buffer_used(text_buffer *text)
-{
- s32 used = text->bufend - text->bufstart;
- if (used < 0)
- used += text->bufsize;
- return used;
-}
-
+ text_buffer(u32 bytes, u32 lines) noexcept
+ : buffer(new (std::nothrow) char [bytes])
+ , lineoffs(new (std::nothrow) s32 [lines])
+ , bufsize(buffer ? bytes : 0)
+ , linesize(lineoffs ? lines : 0)
+ {
+ }
+ ~text_buffer()
+ {
+ if (buffer)
+ delete [] buffer;
+ if (lineoffs)
+ delete [] lineoffs;
+ }
-/*-------------------------------------------------
- buffer_space - return the number of bytes
- available in the buffer
--------------------------------------------------*/
+ char *const buffer;
+ s32 *const lineoffs;
+ s32 const bufsize;
+ s32 bufstart = 0;
+ s32 bufend = 0;
+ s32 const linesize;
+ s32 linestart = 0;
+ s32 lineend = 0;
+ u32 linestartseq = 0;
+ s32 maxwidth = 0;
+
+ /*-------------------------------------------------
+ buffer_used - return the number of bytes
+ currently held in the buffer
+ -------------------------------------------------*/
+
+ s32 buffer_used() const noexcept
+ {
+ s32 const used(bufend - bufstart);
+ return (used < 0) ? (used + bufsize) : used;
+ }
-static inline s32 buffer_space(text_buffer *text)
-{
- return text->bufsize - buffer_used(text);
-}
+ /*-------------------------------------------------
+ buffer_space - return the number of bytes
+ available in the buffer
+ -------------------------------------------------*/
+
+ s32 buffer_space() const noexcept
+ {
+ return bufsize - buffer_used();
+ }
+};
@@ -83,33 +90,19 @@ static inline s32 buffer_space(text_buffer *text)
text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
{
- text_buffer *text;
+ // allocate memory for the text buffer object
+ text_buffer *const text(new (std::nothrow) text_buffer(bytes, lines));
- /* allocate memory for the text buffer object */
- text = global_alloc_nothrow(text_buffer);
if (!text)
return nullptr;
- /* allocate memory for the buffer itself */
- text->buffer = global_alloc_array_nothrow(char, bytes);
- if (!text->buffer)
- {
- global_free(text);
- return nullptr;
- }
-
- /* allocate memory for the lines array */
- text->lineoffs = global_alloc_array_nothrow(s32, lines);
- if (!text->lineoffs)
+ if (!text->buffer || !text->lineoffs)
{
- global_free_array(text->buffer);
- global_free(text);
+ delete text;
return nullptr;
}
- /* initialize the buffer description */
- text->bufsize = bytes;
- text->linesize = lines;
+ // initialize the buffer description
text_buffer_clear(text);
return text;
@@ -123,11 +116,7 @@ text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
void text_buffer_free(text_buffer *text)
{
- if (text->lineoffs)
- global_free_array(text->lineoffs);
- if (text->buffer)
- global_free_array(text->buffer);
- global_free(text);
+ delete text;
}
@@ -186,7 +175,7 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
needed_space = s32(strlen(data)) + MAX_LINE_LENGTH;
/* make space in the buffer if we need to */
- while (buffer_space(text) < needed_space && text->linestart != text->lineend)
+ while (text->buffer_space() < needed_space && text->linestart != text->lineend)
{
text->linestartseq++;
if (++text->linestart >= text->linesize)