Subversion Repositories Shiroi

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi_sound_mk_i.c 1 2024-08-28 08:10:28Z 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
 
25
void shiroi_sound_mk_i(shiroi_t* shiroi) {
26
	int i;
27
 
28
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
29
	uint16_t addr = io & 0xff;
30
	uint16_t data = (io >> 8) & 0xff;
31
 
32
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
33
		if(shiroi->cards[i].type == SHIROI_SOUND_MARK_I) {
34
			if(shiroi->z80_pins & Z80_RD) {
35
				/* I/O Read */
36
				if(addr == 5) {
37
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
38
				}
39
			} else if(shiroi->z80_pins & Z80_WR) {
40
				/* I/O Write */
41
				if(addr == 3) {
42
					uint64_t pins;
43
					pins = AY38910_BDIR | AY38910_BC1;
44
					AY38910_SET_DATA(pins, data);
45
					ay38910_iorq(&shiroi->cards[i].sound.psg, pins);
46
				} else if(addr == 4) {
47
					uint64_t pins;
48
					pins = AY38910_BDIR;
49
					AY38910_SET_DATA(pins, data);
50
					ay38910_iorq(&shiroi->cards[i].sound.psg, pins);
51
				}
52
			}
53
		}
54
	}
55
}
56
 
57
void shiroi_sound_mk_i_tick(shiroi_t* shiroi) {
58
	int i;
59
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
60
		if(shiroi->cards[i].type == SHIROI_SOUND_MARK_I) {
61
			if(ay38910_tick(&shiroi->cards[i].sound.psg)) {
62
				audio[incre++] = shiroi->cards[i].sound.psg.sample;
63
				if(incre == 480) incre = 0;
64
			}
65
		}
66
	}
67
}