Browse Source

oki cleanup and use int16_t for samples

vampirefrog 1 year ago
parent
commit
222961b882
2 changed files with 10 additions and 35 deletions
  1. 9
    29
      okim6258.c
  2. 1
    6
      okim6258.h

+ 9
- 29
okim6258.c View File

@@ -8,8 +8,10 @@
8 8
  *
9 9
  **********************************************************************************************/
10 10
 
11
+#include <stdio.h>
12
+#include <stdlib.h>
11 13
 #include <stddef.h>	// for NULL
12
-#include "mamedef.h"
14
+#include "v68.h"
13 15
 
14 16
 #ifdef _DEBUG
15 17
 #include <stdio.h>
@@ -111,20 +113,18 @@ static int16_t clock_adpcm(struct okim6258 *chip, uint8_t nibble) {
111 113
      okim6258_update -- update the sound chip so that it is in sync with CPU execution
112 114
 
113 115
 ***********************************************************************************************/
114
-void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int samples) {
115
-	stream_sample_t *bufL = outputs[0];
116
-	stream_sample_t *bufR = outputs[1];
117
-
116
+void okim6258_update(struct okim6258 *chip, int16_t **outputs, int samples) {
117
+	int16_t *bufL = outputs[0];
118
+	int16_t *bufR = outputs[1];
118 119
 	if (chip->status & STATUS_PLAYING) {
119 120
 		int nibble_shift = chip->nibble_shift;
120 121
 
121 122
 		while (samples) {
122 123
 			/* Compute the new amplitude and update the current step */
123
-			//int nibble = (chip->data_in >> nibble_shift) & 0xf;
124 124
 			int nibble;
125 125
 			int16_t sample;
126 126
 
127
-			if (! nibble_shift) {
127
+			if (!nibble_shift) {
128 128
 				// 1st nibble - get data
129 129
 				if (! chip->data_empty) {
130 130
 					chip->data_in = chip->data_buf[chip->data_buf_pos >> 4];
@@ -133,7 +133,6 @@ void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int sampl
133 133
 					if ((chip->data_buf_pos >> 4) == (chip->data_buf_pos & 0x0F))
134 134
 						chip->data_empty ++;
135 135
 				} else {
136
-					//chip->data_in = chip->data_in_last;
137 136
 					if (chip->data_empty < 0x80)
138 137
 						chip->data_empty ++;
139 138
 				}
@@ -141,7 +140,6 @@ void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int sampl
141 140
 			nibble = (chip->data_in >> nibble_shift) & 0xf;
142 141
 
143 142
 			/* Output to the buffer */
144
-			//int16_t sample = clock_adpcm(chip, nibble);
145 143
 			if (chip->data_empty < 0x02) {
146 144
 				sample = clock_adpcm(chip, nibble);
147 145
 				chip->last_smpl = sample;
@@ -156,7 +154,7 @@ void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int sampl
156 154
 			}
157 155
 
158 156
 			nibble_shift ^= 4;
159
-
157
+			verbose2("okim6258_update samples=%d sample=%d\n", samples, sample);
160 158
 			*bufL++ = (chip->pan & 0x02) ? 0x00 : sample;
161 159
 			*bufR++ = (chip->pan & 0x01) ? 0x00 : sample;
162 160
 			samples--;
@@ -167,7 +165,6 @@ void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int sampl
167 165
 	} else {
168 166
 		/* Fill with 0 */
169 167
 		while (samples--) {
170
-			//*buffer++ = 0;
171 168
 			*bufL++ = 0;
172 169
 			*bufR++ = 0;
173 170
 		}
@@ -199,7 +196,6 @@ int okim6258_init(struct okim6258 *chip, int clock, int divider, int adpcm_type,
199 196
 	chip->clock_buffer[0x01] = (clock & 0x0000FF00) >>  8;
200 197
 	chip->clock_buffer[0x02] = (clock & 0x00FF0000) >> 16;
201 198
 	chip->clock_buffer[0x03] = (clock & 0xFF000000) >> 24;
202
-	chip->SmpRateFunc = NULL;
203 199
 
204 200
 	/* D/A precision is 10-bits but 12-bit data can be output serially to an external DAC */
205 201
 	chip->output_bits = output_12bits ? 12 : 10;
@@ -233,8 +229,6 @@ void okim6258_reset(struct okim6258 *chip) {
233 229
 	chip->clock_buffer[0x02] = (chip->initial_clock & 0x00FF0000) >> 16;
234 230
 	chip->clock_buffer[0x03] = (chip->initial_clock & 0xFF000000) >> 24;
235 231
 	chip->divider = dividers[chip->initial_div];
236
-	if (chip->SmpRateFunc != NULL)
237
-		chip->SmpRateFunc(chip->SmpRateData, get_vclk(chip));
238 232
 
239 233
 	chip->signal = -2;
240 234
 	chip->step = 0;
@@ -255,9 +249,6 @@ void okim6258_reset(struct okim6258 *chip) {
255 249
 ***********************************************************************************************/
256 250
 void okim6258_set_divider(struct okim6258 *chip, int val) {
257 251
 	chip->divider = dividers[val];
258
-
259
-	if (chip->SmpRateFunc != NULL)
260
-		chip->SmpRateFunc(chip->SmpRateData, get_vclk(chip));
261 252
 }
262 253
 
263 254
 
@@ -275,9 +266,6 @@ void okim6258_set_clock(struct okim6258 *chip, int val) {
275 266
 								(chip->clock_buffer[0x02] << 16) |
276 267
 								(chip->clock_buffer[0x03] << 24);
277 268
 	}
278
-
279
-	if (chip->SmpRateFunc != NULL)
280
-		chip->SmpRateFunc(chip->SmpRateData, get_vclk(chip));
281 269
 }
282 270
 
283 271
 
@@ -290,13 +278,13 @@ int okim6258_get_vclk(struct okim6258 *chip) {
290 278
 	return get_vclk(chip);
291 279
 }
292 280
 
293
-
294 281
 /**********************************************************************************************
295 282
 
296 283
      okim6258_data_w -- write to the control port of an OKIM6258-compatible chip
297 284
 
298 285
 ***********************************************************************************************/
299 286
 static void okim6258_data_w(struct okim6258 *chip, uint8_t data) {
287
+	verbose1("okim6258_data_w data=0x%02x\n", data);
300 288
 	if (chip->data_empty >= 0x02)
301 289
 		chip->data_buf_pos = 0x00;
302 290
 	chip->data_in_last = data;
@@ -304,7 +292,6 @@ static void okim6258_data_w(struct okim6258 *chip, uint8_t data) {
304 292
 	chip->data_buf_pos += 0x01;
305 293
 	chip->data_buf_pos &= 0xF7;
306 294
 	if ((chip->data_buf_pos >> 4) == (chip->data_buf_pos & 0x0F)) {
307
-		//fprintf(stderr, "Warning: FIFO full!\n");
308 295
 		chip->data_buf_pos = (chip->data_buf_pos & 0xF0) | ((chip->data_buf_pos-1) & 0x07);
309 296
 	}
310 297
 	chip->data_empty = 0x00;
@@ -342,7 +329,6 @@ static void okim6258_ctrl_w(struct okim6258 *chip, uint8_t data) {
342 329
 	}
343 330
 
344 331
 	if(data & COMMAND_RECORD) {
345
-		// logerror("M6258: Record enabled\n");
346 332
 		chip->status |= STATUS_RECORDING;
347 333
 	} else {
348 334
 		chip->status &= ~STATUS_RECORDING;
@@ -388,9 +374,3 @@ void okim6258_write(struct okim6258 *chip, uint8_t Port, uint8_t Data) {
388 374
 void okim6258_set_options(struct okim6258 *chip, uint16_t options) {
389 375
 	chip->internal_10_bit = (options >> 0) & 0x01;
390 376
 }
391
-
392
-void okim6258_set_srchg_cb(struct okim6258 *chip, SRATE_CALLBACK CallbackFunc, void* DataPtr) {
393
-	// set Sample Rate Change Callback routine
394
-	chip->SmpRateFunc = CallbackFunc;
395
-	chip->SmpRateData = DataPtr;
396
-}

+ 1
- 6
okim6258.h View File

@@ -1,7 +1,6 @@
1 1
 #pragma once
2 2
 
3 3
 #include <stdint.h>
4
-#include "mamedef.h"
5 4
 
6 5
 struct okim6258 {
7 6
 	uint8_t status;
@@ -34,9 +33,6 @@ struct okim6258 {
34 33
 	uint8_t clock_buffer[0x04];
35 34
 	uint32_t initial_clock;
36 35
 	uint8_t initial_div;
37
-
38
-	SRATE_CALLBACK SmpRateFunc;
39
-	void* SmpRateData;
40 36
 };
41 37
 
42 38
 #define FOSC_DIV_BY_1024    0
@@ -58,9 +54,8 @@ void okim6258_set_divider(struct okim6258 *chip, int val);
58 54
 void okim6258_set_clock(struct okim6258 *chip, int val);
59 55
 int okim6258_get_vclk(struct okim6258 *chip);
60 56
 
61
-void okim6258_update(struct okim6258 *chip, stream_sample_t **outputs, int samples);
57
+void okim6258_update(struct okim6258 *chip, int16_t **outputs, int samples);
62 58
 
63 59
 void okim6258_write(struct okim6258 *chip, uint8_t Port, uint8_t Data);
64 60
 
65 61
 void okim6258_set_options(struct okim6258 *chip, uint16_t options);
66
-void okim6258_set_srchg_cb(struct okim6258 *chip, SRATE_CALLBACK CallbackFunc, void* DataPtr);

Loading…
Cancel
Save