1 /*
2  *  SPDX-License-Identifier: GPL-2.0-or-later
3  *
4  *  Copyright (C) 2020-2021  The DOSBox Staging Team
5  *  Copyright (C) 2017-2020  The DOSBox Team
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License along
18  *  with this program; if not, write to the Free Software Foundation, Inc.,
19  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef DOSBOX_MAME_EMU_H
23 #define DOSBOX_MAME_EMU_H
24 
25 #include "dosbox.h"
26 
27 #include <cmath>
28 #if defined(_MSC_VER) && (_MSC_VER  <= 1500)
29 #include <SDL.h>
30 #else
31 #include <stdint.h>
32 #endif
33 #include <float.h>
34 #include <stdlib.h>
35 #include <memory.h>
36 
37 #if C_DEBUG
38 #include <stdio.h>
39 #include <stdarg.h>
40 #endif
41 
42 typedef Bit16s stream_sample_t;
43 
44 typedef Bit8u u8;
45 typedef Bit32u u32;
46 
47 class device_t;
48 struct machine_config;
49 
50 #define NAME( _ASDF_ ) 0
51 #define BIT( _INPUT_, _BIT_ ) ( ( _INPUT_) >> (_BIT_)) & 1
52 
53 #define ATTR_UNUSED
54 #define DECLARE_READ8_MEMBER(name)      u8     name( int, int)
55 #define DECLARE_WRITE8_MEMBER(name)     void   name( int, int, u8 data)
56 #define READ8_MEMBER(name)              u8     name( int, int)
57 #define WRITE8_MEMBER(name)				void   name([[maybe_unused]] int offset, [[maybe_unused]] int space, [[maybe_unused]] u8 data)
58 
59 #define DECLARE_DEVICE_TYPE(Type, Class) \
60 		extern const device_type Type; \
61 		class Class;
62 
63 #define DEFINE_DEVICE_TYPE(Type, Class, ShortName, FullName)		\
64 	const device_type Type = 0;
65 
66 class device_sound_interface {
67 public:
68 	struct sound_stream {
updatesound_stream69 		void update() {}
70 	};
71 
72 	sound_stream temp;
73 
device_sound_interface(const machine_config &,device_t & _device)74 	device_sound_interface(const machine_config & /* mconfig */, [[maybe_unused]] device_t &_device)
75 	        : temp()
76 	{}
77 
78 	virtual ~device_sound_interface() = default;
79 
stream_alloc(int whatever,int channels,int size)80 	sound_stream *stream_alloc([[maybe_unused]] int whatever, [[maybe_unused]] int channels, [[maybe_unused]] int size)
81 	{
82 		return &temp;
83 	}
84 
85 	virtual void sound_stream_update(sound_stream &stream,
86 	                                 stream_sample_t **inputs,
87 	                                 stream_sample_t **outputs,
88 	                                 int samples) = 0;
89 };
90 
91 struct attotime {
92 	int whatever;
93 
from_hzattotime94 	static attotime from_hz([[maybe_unused]] int hz) {
95 		return attotime();
96 	}
97 };
98 
99 struct machine_config {
100 };
101 
102 typedef int device_type;
103 
104 class device_t {
105 	u32 clockRate;
106 public:
107 	struct machine_t {
describe_contextmachine_t108 		int describe_context() const {
109 			return 0;
110 		}
111 	};
112 
machine()113 	machine_t machine() const {
114 		return machine_t();
115 	}
116 
117 	//int offset, space;
118 
clock()119 	u32 clock() const {
120 		return clockRate;
121 	}
122 
logerror(const char * format,...)123 	void logerror([[maybe_unused]] const char* format, ...) {
124 #if C_DEBUG
125 		char buf[512*2];
126 		va_list msg;
127 		va_start(msg,format);
128 		vsprintf(buf,format,msg);
129 		va_end(msg);
130 		LOG(LOG_MISC,LOG_NORMAL)("%s",buf);
131 #endif
132 	}
133 
tag()134 	static int tag() {
135 		return 0;
136 	}
137 
device_start()138 	virtual void device_start() {
139 	}
140 
141 	void save_item(int, [[maybe_unused]] int blah= 0) {
142 	}
143 
device_t(const machine_config &,device_type type,const char * tag,device_t * owner,u32 _clock)144 	device_t(const machine_config & /* mconfig */, [[maybe_unused]] device_type type, [[maybe_unused]] const char *tag, [[maybe_unused]] device_t *owner, u32 _clock) : clockRate( _clock ) {
145 	}
146 
~device_t()147 	virtual ~device_t() {
148 	}
149 };
150 
151 #define auto_alloc_array_clear(m, t, c) calloc(c, sizeof(t) )
152 #define auto_alloc_clear(m, t) static_cast<t*>( calloc(1, sizeof(t) ) )
153 
154 #endif
155