Subversion Repositories Shiroi

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi_sound_mk_i.c 10 2024-08-29 01:39:27Z nishi $ */
2
#include "shiroi_sound_mk_i.h"
3
 
4
#include "shiroi.h"
5
 
6
extern float audio[];
7
extern int16_t incre;
8
 
9
void shiroi_sound_mk_i_install(shiroi_t* shiroi, int slot) {
10
	shiroi->cards[slot].type = SHIROI_SOUND_MARK_I;
11
	shiroi->cards[slot].soundptr = &shiroi->cards[slot].sound;
12
 
13
	ay38910_desc_t desc;
14
	desc.tick_hz = 3 * 1024 * 1024;
15
	desc.sound_hz = 48000;
16
	desc.magnitude = 0.5;
17
	desc.user_data = NULL;
18
	desc.in_cb = NULL;
19
	desc.out_cb = NULL;
20
	desc.type = AY38910_TYPE_8910;
21
 
22
	ay38910_init(&shiroi->cards[slot].sound.psg, &desc);
23
}
24
 
10 nishi 25
void shiroi_sound_mk_i_reset(shiroi_t* shiroi, int slot) { ay38910_reset(&shiroi->cards[slot].sound.psg); }
26
 
1 nishi 27
void shiroi_sound_mk_i(shiroi_t* shiroi) {
28
	int i;
29
 
30
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
31
	uint16_t addr = io & 0xff;
32
	uint16_t data = (io >> 8) & 0xff;
33
 
34
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
35
		if(shiroi->cards[i].type == SHIROI_SOUND_MARK_I) {
36
			if(shiroi->z80_pins & Z80_RD) {
37
				/* I/O Read */
38
				if(addr == 5) {
39
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
40
				}
41
			} else if(shiroi->z80_pins & Z80_WR) {
42
				/* I/O Write */
43
				if(addr == 3) {
44
					uint64_t pins;
45
					pins = AY38910_BDIR | AY38910_BC1;
46
					AY38910_SET_DATA(pins, data);
47
					ay38910_iorq(&shiroi->cards[i].sound.psg, pins);
48
				} else if(addr == 4) {
49
					uint64_t pins;
50
					pins = AY38910_BDIR;
51
					AY38910_SET_DATA(pins, data);
52
					ay38910_iorq(&shiroi->cards[i].sound.psg, pins);
53
				}
54
			}
55
		}
56
	}
57
}
58
 
59
void shiroi_sound_mk_i_tick(shiroi_t* shiroi) {
60
	int i;
61
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
62
		if(shiroi->cards[i].type == SHIROI_SOUND_MARK_I) {
63
			if(ay38910_tick(&shiroi->cards[i].sound.psg)) {
64
				audio[incre++] = shiroi->cards[i].sound.psg.sample;
65
				if(incre == 480) incre = 0;
66
			}
67
		}
68
	}
69
}