ff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1794 Content-Disposition: inline; filename="method.h" Last-Modified: Sat, 03 May 2025 15:35:16 GMT Expires: Sat, 03 May 2025 15:40:16 GMT ETag: "8efdd33a0b23f0e1f88e7156a450aaf73e20d656" /* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ #ifndef METHOD_H #define METHOD_H #include #include "data.h" #include "config.h" #include "result.h" /** * The base class for state that methods keep. * All derived method state classes must have a member of this type. */ typedef struct { data_t const* data; } method_state_t; /** * A method that compresses the data using config. */ typedef struct { char const* name; /**< The identifier for this method in the results. */ /** * Creates a state that must contain a member variable of method_state_t, * and returns a pointer to that member variable. * * This method can be used to do expensive work that only depends on the * data, like loading the data file into a buffer. */ method_state_t* (*create)(data_t const* data); /** * Compresses the data in the state using the given config. * * @param state A pointer to the state returned by create(). * * @returns The total compressed size on success, or an error code. */ result_t (*compress)(method_state_t* state, config_t const* config); /** * Frees the state. */ void (*destroy)(method_state_t* state); } method_t; /** * Set the zstd cli path. Must be called before any methods are used. */ void method_set_zstdcli(char const* zstdcli); /** * A NULL-terminated list of methods. */ extern method_t const* const* methods; #endif ted'>netlist-generated MAME - Multiple Arcade Machine Emulator
summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/rk_cas.cpp
blob: a31c47592dbdc5f6417b48274917ed2b2b782914 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/*

    Tape support for RK format

*/
#include "rk_cas.h"

#include <cassert>


#define RK_WAV_FREQUENCY    44000
#define WAVE_HIGH       32767
#define WAVE_LOW        -32768

#define RK_HEADER_LEN   256

#define RK_SIZE_20 20
#define RK_SIZE_22 22
#define RK_SIZE_60 60

static int      data_size; // FIXME: global variable prevents multiple instances

static int16_t *rk_emit_level(int16_t *p, int count, int level)
{

	for (int i=0; i<count; i++)
	{
		*(p++) = level;
	}
	return p;
}

static int16_t* rk_output_bit(int16_t *p, uint8_t b,int bitsize)
{
	if (b)
	{
		p = rk_emit_level (p, bitsize, WAVE_HIGH);
		p = rk_emit_level (p, bitsize, WAVE_LOW);
	}
	else
	{
		p = rk_emit_level (p, bitsize, WAVE_LOW);
		p = rk_emit_level (p, bitsize, WAVE_HIGH);

	}
	return p;
}

static int16_t* rk_output_byte(int16_t *p, uint8_t byte,int bitsize)
{
	int i;
	for (i=7; i>=0; i--)
		p = rk_output_bit(p,(byte>>i) & 0x01, bitsize);

	return p;
}


static int rk20_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
	data_size = caslen;
	return  (RK_HEADER_LEN  * 8 * 2 +  8*2 + caslen * 8 * 2) * RK_SIZE_20;
}

static int rk22_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
	data_size = caslen;
	return  (RK_HEADER_LEN  * 8 * 2 +  8*2 + caslen * 8 * 2) * RK_SIZE_22;
}

static int rk60_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
	data_size = caslen;
	return  (RK_HEADER_LEN  * 8 * 2 +  8*2 + caslen * 8 * 2) * RK_SIZE_60;
}

static int gam_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
	data_size = caslen;
	return  (RK_HEADER_LEN  * 8 * 2 +  caslen * 8 * 2) * RK_SIZE_20;
}

static int rk20_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
	int i;
	int16_t * p = buffer;

	for (i=0; i<RK_HEADER_LEN; i++) {
		p = rk_output_byte (p, 0x00, RK_SIZE_20 );
	}

	p = rk_output_byte (p, 0xE6, RK_SIZE_20);

	for (i=0; i<data_size; i++)
		p = rk_output_byte (p, bytes[i], RK_SIZE_20);

	return p - buffer;
}

static int rk22_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
	int i;
	int16_t * p = buffer;

	for (i=0; i<RK_HEADER_LEN; i++) {
		p = rk_output_byte (p, 0x00, RK_SIZE_22 );
	}

	p = rk_output_byte (p, 0xE6, RK_SIZE_22);

	for (i=0; i<data_size; i++)
		p = rk_output_byte (p, bytes[i], RK_SIZE_22);

	return p - buffer;
}

static int rk60_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
	int i;
	int16_t * p = buffer;

	for (i=0; i<RK_HEADER_LEN; i++) {
		p = rk_output_byte (p, 0x00, RK_SIZE_60 );
	}

	p = rk_output_byte (p, 0xE6, RK_SIZE_60);

	for (i=0; i<data_size; i++)
		p = rk_output_byte (p, bytes[i], RK_SIZE_60);

	return p - buffer;
}

static int gam_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
	int i;
	int16_t * p = buffer;

	for (i=0; i<RK_HEADER_LEN; i++) {
		p = rk_output_byte (p, 0x00, RK_SIZE_20 );
	}

	for (i=0; i<data_size; i++)
		p = rk_output_byte (p, bytes[i], RK_SIZE_20);

	return p - buffer;
}

static const cassette_image::LegacyWaveFiller rk20_legacy_fill_wave = {
	rk20_cas_fill_wave,         /* fill_wave */
	-1,                 /* chunk_size */
	0,                  /* chunk_samples */
	rk20_cas_to_wav_size,           /* chunk_sample_calc */
	RK_WAV_FREQUENCY,           /* sample_frequency */
	0,                  /* header_samples */
	0                   /* trailer_samples */
};

static cassette_image::error rk20_cassette_identify( cassette_image *cassette, cassette_image::Options *opts ) {
	return cassette->legacy_identify( opts, &rk20_legacy_fill_wave );
}

static cassette_image::error rk20_cassette_load( cassette_image *cassette ) {
	return cassette->legacy_construct( &rk20_legacy_fill_wave );
}

static const cassette_image::LegacyWaveFiller rk22_legacy_fill_wave = {
	rk22_cas_fill_wave,         /* fill_wave */
	-1,                 /* chunk_size */
	0,                  /* chunk_samples */
	rk22_cas_to_wav_size,           /* chunk_sample_calc */
	RK_WAV_FREQUENCY,           /* sample_frequency */
	0,                  /* header_samples */
	0                   /* trailer_samples */
};

static cassette_image::error rk22_cassette_identify( cassette_image *cassette, cassette_image::Options *opts ) {
	return cassette->legacy_identify( opts, &rk22_legacy_fill_wave );
}

static cassette_image::error rk22_cassette_load( cassette_image *cassette ) {
	return cassette->legacy_construct( &rk22_legacy_fill_wave );
}

static const cassette_image::LegacyWaveFiller gam_legacy_fill_wave = {
	gam_cas_fill_wave,          /* fill_wave */
	-1,                 /* chunk_size */
	0,                  /* chunk_samples */
	gam_cas_to_wav_size,            /* chunk_sample_calc */
	RK_WAV_FREQUENCY,           /* sample_frequency */
	0,                  /* header_samples */
	0                   /* trailer_samples */
};

static cassette_image::error gam_cassette_identify( cassette_image *cassette, cassette_image::Options *opts ) {
	return cassette->legacy_identify( opts, &gam_legacy_fill_wave );
}

static cassette_image::error gam_cassette_load( cassette_image *cassette ) {
	return cassette->legacy_construct( &gam_legacy_fill_wave );
}

static const cassette_image::LegacyWaveFiller rk60_legacy_fill_wave = {
	rk60_cas_fill_wave,         /* fill_wave */
	-1,                 /* chunk_size */
	0,                  /* chunk_samples */
	rk60_cas_to_wav_size,           /* chunk_sample_calc */
	RK_WAV_FREQUENCY,           /* sample_frequency */
	0,                  /* header_samples */
	0                   /* trailer_samples */
};

static cassette_image::error rk60_cassette_identify( cassette_image *cassette, cassette_image::Options *opts ) {
	return cassette->legacy_identify( opts, &rk60_legacy_fill_wave );
}

static cassette_image::error rk60_cassette_load( cassette_image *cassette ) {
	return cassette->legacy_construct( &rk60_legacy_fill_wave );
}

static const cassette_image::Format rku_cassette_format = {
	"rku",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format rk8_cassette_format = {
	"rk8",
	rk60_cassette_identify,
	rk60_cassette_load,
	nullptr
};

static const cassette_image::Format rks_cassette_format = {
	"rks",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format rko_cassette_format = {
	"rko",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format rkr_cassette_format = {
	"rk,rkr",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format rka_cassette_format = {
	"rka",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format rkm_cassette_format = {
	"rkm",
	rk22_cassette_identify,
	rk22_cassette_load,
	nullptr
};

static const cassette_image::Format rkp_cassette_format = {
	"rkp",
	rk20_cassette_identify,
	rk20_cassette_load,
	nullptr
};

static const cassette_image::Format gam_cassette_format = {
	"gam,g16,pki",
	gam_cassette_identify,
	gam_cassette_load,
	nullptr
};

CASSETTE_FORMATLIST_START(rku_cassette_formats)
	CASSETTE_FORMAT(rku_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rk8_cassette_formats)
	CASSETTE_FORMAT(rk8_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rks_cassette_formats)
	CASSETTE_FORMAT(rks_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rko_cassette_formats)
	CASSETTE_FORMAT(rko_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rkr_cassette_formats)
	CASSETTE_FORMAT(rkr_cassette_format)
	CASSETTE_FORMAT(gam_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rka_cassette_formats)
	CASSETTE_FORMAT(rka_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rkm_cassette_formats)
	CASSETTE_FORMAT(rkm_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(rkp_cassette_formats)
	CASSETTE_FORMAT(rkp_cassette_format)
CASSETTE_FORMATLIST_END

CASSETTE_FORMATLIST_START(gam_cassette_formats)
	CASSETTE_FORMAT(gam_cassette_format)
CASSETTE_FORMATLIST_END