Subversion Repositories Shiroi

Rev

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

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi.c 1 2024-08-28 08:10:28Z nishi $ */
2
 
3
#include "shiroi.h"
4
 
5
#include "card/shiroi_video_mk_i.h"
6
#include "card/shiroi_sound_mk_i.h"
7
#include "card/shiroi_math_mk_i.h"
8
 
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <math.h>
12
 
13
float audio[480];
14
int16_t incre = 0;
15
 
16
void shiroi_play_audio(void* buffer, unsigned int frames) {
17
	int16_t* d = (int16_t*)buffer;
18
	int i;
19
	for(i = 0; i < frames; i++) {
20
		d[i] = audio[(i + incre >= 480) ? (i + incre - 480) : (i + incre)] * 32767;
21
	}
22
}
23
 
24
shiroi_card_t* shiroi_get_video_card(shiroi_t* shiroi) {
25
	int i;
26
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
27
		if(shiroi->cards[i].type == 0) continue;
28
		if((shiroi->cards[i].type & 0xf0) == SHIROI_VIDEO) return &shiroi->cards[i];
29
	}
30
	return NULL;
31
}
32
 
33
shiroi_card_t* shiroi_get_sound_card(shiroi_t* shiroi) {
34
	int i;
35
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
36
		if(shiroi->cards[i].type == 0) continue;
37
		if((shiroi->cards[i].type & 0xf0) == SHIROI_SOUND) return &shiroi->cards[i];
38
	}
39
	return NULL;
40
}
41
 
42
shiroi_card_t* shiroi_get_math_card(shiroi_t* shiroi) {
43
	int i;
44
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
45
		if(shiroi->cards[i].type == 0) continue;
46
		if((shiroi->cards[i].type & 0xf0) == SHIROI_MATH) return &shiroi->cards[i];
47
	}
48
	return NULL;
49
}
50
 
51
void shiroi_init_cards(shiroi_t* shiroi) {
52
	int i;
53
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
54
		shiroi->cards[i].type = 0;
55
	}
56
}
57
 
58
void shiroi_install(shiroi_t* shiroi, int slot, int card) {
59
	if(card == SHIROI_VIDEO_MARK_I) {
60
		shiroi_video_mk_i_install(shiroi, slot);
61
	} else if(card == SHIROI_SOUND_MARK_I) {
62
		shiroi_sound_mk_i_install(shiroi, slot);
63
	} else if(card == SHIROI_MATH_MARK_I) {
64
		shiroi_math_mk_i_install(shiroi, slot);
65
	}
66
}
67
 
68
void shiroi_init(shiroi_t* shiroi) {
69
	shiroi->z80_pins = z80_init(&shiroi->z80);
70
	shiroi->stop = false;
71
	shiroi->play_audio = shiroi_play_audio;
72
 
73
	int i;
74
 
75
	for(i = 0; i < 480; i++) {
76
		audio[i] = 0;
77
	}
78
}
79
 
80
void shiroi_loop(shiroi_t* shiroi) {
81
	int x = 0;
82
	int y = 0;
83
	while(!shiroi->stop) {
84
		shiroi->z80_pins = z80_tick(&shiroi->z80, shiroi->z80_pins);
85
		if(shiroi->z80_pins & Z80_MREQ) {
86
			uint16_t addr = Z80_GET_ADDR(shiroi->z80_pins);
87
			if(shiroi->z80_pins & Z80_RD) {
88
				uint8_t data = shiroi->ram[addr];
89
				Z80_SET_DATA(shiroi->z80_pins, data);
90
			} else if(shiroi->z80_pins & Z80_WR) {
91
				uint8_t data = Z80_GET_DATA(shiroi->z80_pins);
92
				shiroi->ram[addr] = data;
93
			}
94
		} else if(shiroi->z80_pins & Z80_IORQ) {
95
			uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
96
			uint16_t addr = io & 0xff;
97
			uint16_t data = (io >> 8) & 0xff;
98
 
99
			if(shiroi->z80_pins & Z80_M1) {
100
			} else {
101
				shiroi_video_mk_i(shiroi);
102
				shiroi_sound_mk_i(shiroi);
103
				shiroi_math_mk_i(shiroi);
104
			}
105
		}
106
 
107
		shiroi_video_mk_i_tick(shiroi);
108
		shiroi_sound_mk_i_tick(shiroi);
109
		shiroi_math_mk_i_tick(shiroi);
110
	}
111
}