Subversion Repositories Shiroi

Rev

Rev 3 | Rev 10 | 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 7 2024-08-28 14:02:52Z 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
 
83
void shiroi_init(shiroi_t* shiroi) {
84
	shiroi->z80_pins = z80_init(&shiroi->z80);
85
	shiroi->stop = false;
86
	shiroi->play_audio = shiroi_play_audio;
87
 
88
	int i;
89
 
90
	for(i = 0; i < 480; i++) {
91
		audio[i] = 0;
92
	}
93
}
94
 
95
void shiroi_loop(shiroi_t* shiroi) {
96
	int x = 0;
97
	int y = 0;
98
	while(!shiroi->stop) {
99
		shiroi->z80_pins = z80_tick(&shiroi->z80, shiroi->z80_pins);
100
		if(shiroi->z80_pins & Z80_MREQ) {
101
			uint16_t addr = Z80_GET_ADDR(shiroi->z80_pins);
102
			if(shiroi->z80_pins & Z80_RD) {
103
				uint8_t data = shiroi->ram[addr];
104
				Z80_SET_DATA(shiroi->z80_pins, data);
105
			} else if(shiroi->z80_pins & Z80_WR) {
3 nishi 106
				if(addr >= 0x8000) {
107
					uint8_t data = Z80_GET_DATA(shiroi->z80_pins);
108
					shiroi->ram[addr] = data;
109
				}
1 nishi 110
			}
111
		} else if(shiroi->z80_pins & Z80_IORQ) {
112
			uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
113
			uint16_t addr = io & 0xff;
114
			uint16_t data = (io >> 8) & 0xff;
115
 
116
			if(shiroi->z80_pins & Z80_M1) {
117
			} else {
118
				shiroi_video_mk_i(shiroi);
7 nishi 119
				shiroi_video_mk_ii(shiroi);
1 nishi 120
				shiroi_sound_mk_i(shiroi);
121
				shiroi_math_mk_i(shiroi);
3 nishi 122
				shiroi_text_mk_i(shiroi);
1 nishi 123
			}
124
		}
125
 
126
		shiroi_video_mk_i_tick(shiroi);
7 nishi 127
		shiroi_video_mk_ii_tick(shiroi);
1 nishi 128
		shiroi_sound_mk_i_tick(shiroi);
129
		shiroi_math_mk_i_tick(shiroi);
3 nishi 130
		shiroi_text_mk_i_tick(shiroi);
1 nishi 131
	}
132
}