Subversion Repositories Shiroi

Rev

Rev 7 | Rev 11 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi.c 10 2024-08-29 01:39:27Z nishi $ */
2
 
3
#include "shiroi.h"
4
 
5
#include "card/shiroi_video_mk_i.h"
7 nishi 6
#include "card/shiroi_video_mk_ii.h"
1 nishi 7
#include "card/shiroi_sound_mk_i.h"
8
#include "card/shiroi_math_mk_i.h"
3 nishi 9
#include "card/shiroi_text_mk_i.h"
1 nishi 10
 
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <math.h>
14
 
15
float audio[480];
16
int16_t incre = 0;
17
 
18
void shiroi_play_audio(void* buffer, unsigned int frames) {
19
	int16_t* d = (int16_t*)buffer;
20
	int i;
21
	for(i = 0; i < frames; i++) {
22
		d[i] = audio[(i + incre >= 480) ? (i + incre - 480) : (i + incre)] * 32767;
23
	}
24
}
25
 
26
shiroi_card_t* shiroi_get_video_card(shiroi_t* shiroi) {
27
	int i;
28
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
29
		if(shiroi->cards[i].type == 0) continue;
30
		if((shiroi->cards[i].type & 0xf0) == SHIROI_VIDEO) return &shiroi->cards[i];
31
	}
32
	return NULL;
33
}
34
 
35
shiroi_card_t* shiroi_get_sound_card(shiroi_t* shiroi) {
36
	int i;
37
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
38
		if(shiroi->cards[i].type == 0) continue;
39
		if((shiroi->cards[i].type & 0xf0) == SHIROI_SOUND) return &shiroi->cards[i];
40
	}
41
	return NULL;
42
}
43
 
44
shiroi_card_t* shiroi_get_math_card(shiroi_t* shiroi) {
45
	int i;
46
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
47
		if(shiroi->cards[i].type == 0) continue;
3 nishi 48
		if(shiroi->cards[i].type == SHIROI_MATH_MARK_I) return &shiroi->cards[i];
1 nishi 49
	}
50
	return NULL;
51
}
52
 
3 nishi 53
shiroi_card_t* shiroi_get_text_card(shiroi_t* shiroi) {
54
	int i;
55
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
56
		if(shiroi->cards[i].type == 0) continue;
57
		if(shiroi->cards[i].type == SHIROI_TEXT_MARK_I) return &shiroi->cards[i];
58
	}
59
	return NULL;
60
}
61
 
1 nishi 62
void shiroi_init_cards(shiroi_t* shiroi) {
63
	int i;
64
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
65
		shiroi->cards[i].type = 0;
66
	}
67
}
68
 
69
void shiroi_install(shiroi_t* shiroi, int slot, int card) {
70
	if(card == SHIROI_VIDEO_MARK_I) {
71
		shiroi_video_mk_i_install(shiroi, slot);
7 nishi 72
	} else if(card == SHIROI_VIDEO_MARK_II) {
73
		shiroi_video_mk_ii_install(shiroi, slot);
1 nishi 74
	} else if(card == SHIROI_SOUND_MARK_I) {
75
		shiroi_sound_mk_i_install(shiroi, slot);
76
	} else if(card == SHIROI_MATH_MARK_I) {
77
		shiroi_math_mk_i_install(shiroi, slot);
3 nishi 78
	} else if(card == SHIROI_TEXT_MARK_I) {
79
		shiroi_text_mk_i_install(shiroi, slot);
1 nishi 80
	}
81
}
82
 
10 nishi 83
void shiroi_reset_card(shiroi_t* shiroi, int slot) {
84
	int card = shiroi->cards[slot].type;
85
	if(card == 0) {
86
	} else if(card == SHIROI_VIDEO_MARK_I) {
87
		shiroi_video_mk_i_reset(shiroi, slot);
88
	} else if(card == SHIROI_VIDEO_MARK_II) {
89
		shiroi_video_mk_ii_reset(shiroi, slot);
90
	} else if(card == SHIROI_SOUND_MARK_I) {
91
		shiroi_sound_mk_i_reset(shiroi, slot);
92
	} else if(card == SHIROI_MATH_MARK_I) {
93
		shiroi_math_mk_i_reset(shiroi, slot);
94
	} else if(card == SHIROI_TEXT_MARK_I) {
95
		shiroi_text_mk_i_reset(shiroi, slot);
96
	}
97
}
98
 
1 nishi 99
void shiroi_init(shiroi_t* shiroi) {
100
	shiroi->z80_pins = z80_init(&shiroi->z80);
101
	shiroi->stop = false;
10 nishi 102
	shiroi->reset = false;
1 nishi 103
	shiroi->play_audio = shiroi_play_audio;
104
 
105
	int i;
106
 
107
	for(i = 0; i < 480; i++) {
108
		audio[i] = 0;
109
	}
110
}
111
 
112
void shiroi_loop(shiroi_t* shiroi) {
113
	int x = 0;
114
	int y = 0;
115
	while(!shiroi->stop) {
10 nishi 116
		if(shiroi->reset) {
117
			z80_reset(&shiroi->z80);
118
			int i;
119
			for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
120
				shiroi_reset_card(shiroi, i);
121
			}
122
			shiroi->reset = false;
123
		}
1 nishi 124
		shiroi->z80_pins = z80_tick(&shiroi->z80, shiroi->z80_pins);
125
		if(shiroi->z80_pins & Z80_MREQ) {
126
			uint16_t addr = Z80_GET_ADDR(shiroi->z80_pins);
127
			if(shiroi->z80_pins & Z80_RD) {
128
				uint8_t data = shiroi->ram[addr];
129
				Z80_SET_DATA(shiroi->z80_pins, data);
130
			} else if(shiroi->z80_pins & Z80_WR) {
3 nishi 131
				if(addr >= 0x8000) {
132
					uint8_t data = Z80_GET_DATA(shiroi->z80_pins);
133
					shiroi->ram[addr] = data;
134
				}
1 nishi 135
			}
136
		} else if(shiroi->z80_pins & Z80_IORQ) {
137
			uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
138
			uint16_t addr = io & 0xff;
139
			uint16_t data = (io >> 8) & 0xff;
140
 
141
			if(shiroi->z80_pins & Z80_M1) {
142
			} else {
143
				shiroi_video_mk_i(shiroi);
7 nishi 144
				shiroi_video_mk_ii(shiroi);
1 nishi 145
				shiroi_sound_mk_i(shiroi);
146
				shiroi_math_mk_i(shiroi);
3 nishi 147
				shiroi_text_mk_i(shiroi);
1 nishi 148
			}
149
		}
150
 
151
		shiroi_video_mk_i_tick(shiroi);
7 nishi 152
		shiroi_video_mk_ii_tick(shiroi);
1 nishi 153
		shiroi_sound_mk_i_tick(shiroi);
154
		shiroi_math_mk_i_tick(shiroi);
3 nishi 155
		shiroi_text_mk_i_tick(shiroi);
1 nishi 156
	}
157
}