Subversion Repositories Shiroi

Rev

Rev 11 | Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 1... Line 1...
1
/* $Id: shiroi.c 11 2024-08-29 02:49:47Z nishi $ */
1
/* $Id: shiroi.c 12 2024-08-29 04:19:08Z nishi $ */
2
 
2
 
3
#include "shiroi.h"
3
#include "shiroi.h"
4
 
4
 
5
#include "card/shiroi_video_mk_i.h"
5
#include "card/shiroi_video_mk_i.h"
6
#include "card/shiroi_video_mk_ii.h"
6
#include "card/shiroi_video_mk_ii.h"
7
#include "card/shiroi_sound_mk_i.h"
7
#include "card/shiroi_sound_mk_i.h"
8
#include "card/shiroi_math_mk_i.h"
8
#include "card/shiroi_math_mk_i.h"
9
#include "card/shiroi_text_mk_i.h"
9
#include "card/shiroi_text_mk_i.h"
-
 
10
#include "card/shiroi_debug.h"
10
 
11
 
11
#include <stdio.h>
12
#include <stdio.h>
12
#include <stdlib.h>
13
#include <stdlib.h>
13
#include <math.h>
14
#include <math.h>
-
 
15
#include <time.h>
14
 
16
 
15
float audio[480];
17
float audio[480];
16
int16_t incre = 0;
18
int16_t incre = 0;
17
 
19
 
18
void shiroi_play_audio(void* buffer, unsigned int frames) {
20
void shiroi_play_audio(void* buffer, unsigned int frames) {
Line 57... Line 59...
57
		if(shiroi->cards[i].type == SHIROI_TEXT_MARK_I) return &shiroi->cards[i];
59
		if(shiroi->cards[i].type == SHIROI_TEXT_MARK_I) return &shiroi->cards[i];
58
	}
60
	}
59
	return NULL;
61
	return NULL;
60
}
62
}
61
 
63
 
-
 
64
shiroi_card_t* shiroi_get_debug_card(shiroi_t* shiroi) {
-
 
65
	int i;
-
 
66
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
-
 
67
		if(shiroi->cards[i].type == 0) continue;
-
 
68
		if(shiroi->cards[i].type == SHIROI_DEBUG) return &shiroi->cards[i];
-
 
69
	}
-
 
70
	return NULL;
-
 
71
}
-
 
72
 
62
void shiroi_init_cards(shiroi_t* shiroi) {
73
void shiroi_init_cards(shiroi_t* shiroi) {
63
	int i;
74
	int i;
64
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
75
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
65
		shiroi->cards[i].type = 0;
76
		shiroi->cards[i].type = 0;
66
	}
77
	}
Line 75... Line 86...
75
		shiroi_sound_mk_i_install(shiroi, slot);
86
		shiroi_sound_mk_i_install(shiroi, slot);
76
	} else if(card == SHIROI_MATH_MARK_I) {
87
	} else if(card == SHIROI_MATH_MARK_I) {
77
		shiroi_math_mk_i_install(shiroi, slot);
88
		shiroi_math_mk_i_install(shiroi, slot);
78
	} else if(card == SHIROI_TEXT_MARK_I) {
89
	} else if(card == SHIROI_TEXT_MARK_I) {
79
		shiroi_text_mk_i_install(shiroi, slot);
90
		shiroi_text_mk_i_install(shiroi, slot);
-
 
91
	} else if(card == SHIROI_DEBUG) {
-
 
92
		shiroi_debug_install(shiroi, slot);
80
	}
93
	}
81
}
94
}
82
 
95
 
83
void shiroi_reset_card(shiroi_t* shiroi, int slot) {
96
void shiroi_reset_card(shiroi_t* shiroi, int slot) {
84
	int card = shiroi->cards[slot].type;
97
	int card = shiroi->cards[slot].type;
Line 91... Line 104...
91
		shiroi_sound_mk_i_reset(shiroi, slot);
104
		shiroi_sound_mk_i_reset(shiroi, slot);
92
	} else if(card == SHIROI_MATH_MARK_I) {
105
	} else if(card == SHIROI_MATH_MARK_I) {
93
		shiroi_math_mk_i_reset(shiroi, slot);
106
		shiroi_math_mk_i_reset(shiroi, slot);
94
	} else if(card == SHIROI_TEXT_MARK_I) {
107
	} else if(card == SHIROI_TEXT_MARK_I) {
95
		shiroi_text_mk_i_reset(shiroi, slot);
108
		shiroi_text_mk_i_reset(shiroi, slot);
-
 
109
	} else if(card == SHIROI_DEBUG) {
-
 
110
		shiroi_debug_reset(shiroi, slot);
96
	}
111
	}
97
}
112
}
98
 
113
 
99
void shiroi_init(shiroi_t* shiroi) {
114
void shiroi_init(shiroi_t* shiroi) {
100
	shiroi->z80_pins = z80_init(&shiroi->z80);
115
	shiroi->z80_pins = z80_init(&shiroi->z80);
Line 110... Line 125...
110
}
125
}
111
 
126
 
112
void shiroi_loop(shiroi_t* shiroi) {
127
void shiroi_loop(shiroi_t* shiroi) {
113
	int x = 0;
128
	int x = 0;
114
	int y = 0;
129
	int y = 0;
-
 
130
#ifdef ACCURATE_CLOCK
-
 
131
	double hz = 1000000000 / (20 * 1024 * 1024);
-
 
132
	struct timespec deadline;
-
 
133
#endif
115
	while(!shiroi->stop || shiroi->reset) {
134
	while(!shiroi->stop || shiroi->reset) {
116
		if(shiroi->reset) {
135
		if(shiroi->reset) {
117
			z80_reset(&shiroi->z80);
136
			z80_reset(&shiroi->z80);
118
			int i;
137
			int i;
119
			for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
138
			for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
Line 122... Line 141...
122
			shiroi->reset = false;
141
			shiroi->reset = false;
123
			incre = 0;
142
			incre = 0;
124
			for(i = 0; i < 480; i++) audio[i] = 0;
143
			for(i = 0; i < 480; i++) audio[i] = 0;
125
			continue;
144
			continue;
126
		}
145
		}
-
 
146
#ifdef ACCURATE_CLOCK
-
 
147
		clock_gettime(CLOCK_MONOTONIC, &deadline);
-
 
148
		deadline.tv_nsec += hz;
-
 
149
		if(deadline.tv_nsec >= 1000000000) {
-
 
150
			deadline.tv_nsec -= 1000000000;
-
 
151
			deadline.tv_sec++;
-
 
152
		}
-
 
153
#endif
127
		shiroi->z80_pins = z80_tick(&shiroi->z80, shiroi->z80_pins);
154
		shiroi->z80_pins = z80_tick(&shiroi->z80, shiroi->z80_pins);
128
		if(shiroi->z80_pins & Z80_MREQ) {
155
		if(shiroi->z80_pins & Z80_MREQ) {
129
			uint16_t addr = Z80_GET_ADDR(shiroi->z80_pins);
156
			uint16_t addr = Z80_GET_ADDR(shiroi->z80_pins);
130
			if(shiroi->z80_pins & Z80_RD) {
157
			if(shiroi->z80_pins & Z80_RD) {
131
				uint8_t data = shiroi->ram[addr];
158
				uint8_t data = shiroi->ram[addr];
Line 146... Line 173...
146
				shiroi_video_mk_i(shiroi);
173
				shiroi_video_mk_i(shiroi);
147
				shiroi_video_mk_ii(shiroi);
174
				shiroi_video_mk_ii(shiroi);
148
				shiroi_sound_mk_i(shiroi);
175
				shiroi_sound_mk_i(shiroi);
149
				shiroi_math_mk_i(shiroi);
176
				shiroi_math_mk_i(shiroi);
150
				shiroi_text_mk_i(shiroi);
177
				shiroi_text_mk_i(shiroi);
-
 
178
				shiroi_debug(shiroi);
151
			}
179
			}
152
		}
180
		}
153
 
181
 
154
		shiroi_video_mk_i_tick(shiroi);
182
		shiroi_video_mk_i_tick(shiroi);
155
		shiroi_video_mk_ii_tick(shiroi);
183
		shiroi_video_mk_ii_tick(shiroi);
156
		shiroi_sound_mk_i_tick(shiroi);
184
		shiroi_sound_mk_i_tick(shiroi);
157
		shiroi_math_mk_i_tick(shiroi);
185
		shiroi_math_mk_i_tick(shiroi);
158
		shiroi_text_mk_i_tick(shiroi);
186
		shiroi_text_mk_i_tick(shiroi);
-
 
187
		shiroi_debug_tick(shiroi);
-
 
188
#ifdef ACCURATE_CLOCK
-
 
189
		clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, NULL);
-
 
190
#endif
159
	}
191
	}
160
}
192
}