Subversion Repositories Shiroi

Rev

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