Subversion Repositories Shiroi

Rev

Rev 11 | Rev 13 | 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: main.c 11 2024-08-29 02:49:47Z nishi $ */
1
/* $Id: main.c 12 2024-08-29 04:19:08Z nishi $ */
2
 
2
 
3
#include <stdio.h>
3
#include <stdio.h>
4
#include <stdbool.h>
4
#include <stdbool.h>
5
#include <sys/stat.h>
5
#include <sys/stat.h>
6
#include <stdlib.h>
6
#include <stdlib.h>
Line 8... Line 8...
8
 
8
 
9
#include <raylib.h>
9
#include <raylib.h>
10
 
10
 
11
#include "shiroi.h"
11
#include "shiroi.h"
12
 
12
 
-
 
13
#define ON_COLOR ((Color){0xc0, 0, 0, 0xff})
-
 
14
#define OFF_COLOR ((Color){0x20, 0x20, 0x20, 0xff})
-
 
15
 
13
shiroi_t shiroi;
16
shiroi_t shiroi;
14
 
17
 
15
void thread_start(void);
18
void thread_start(void);
16
void thread_end(void);
19
void thread_end(void);
17
 
20
 
-
 
21
bool get_bit(int n, int f) { return (n & (1 << f)) ? true : false; }
-
 
22
 
18
int main(int argc, char** argv) {
23
int main(int argc, char** argv) {
19
	FILE* fconf = fopen("shiroi.ini", "r");
24
	FILE* fconf = fopen("shiroi.ini", "r");
20
	if(fconf == NULL) {
25
	if(fconf == NULL) {
21
		printf("Creating config.\n");
26
		printf("Creating config.\n");
22
		fconf = fopen("shiroi.ini", "w");
27
		fconf = fopen("shiroi.ini", "w");
Line 88... Line 93...
88
								dev = SHIROI_MATH_MARK_I;
93
								dev = SHIROI_MATH_MARK_I;
89
								n = "Math Mark I";
94
								n = "Math Mark I";
90
							} else if(strcmp(line + j + 1, "text_mark_1") == 0) {
95
							} else if(strcmp(line + j + 1, "text_mark_1") == 0) {
91
								dev = SHIROI_TEXT_MARK_I;
96
								dev = SHIROI_TEXT_MARK_I;
92
								n = "Text Mark I";
97
								n = "Text Mark I";
-
 
98
							} else if(strcmp(line + j + 1, "debug") == 0) {
-
 
99
								dev = SHIROI_DEBUG;
-
 
100
								n = "Debug";
93
							}
101
							}
94
							if(dev == -1) {
102
							if(dev == -1) {
95
								fprintf(stderr, "No such device called `%s' ; ignoring\n", line + j + 1);
103
								fprintf(stderr, "No such device called `%s' ; ignoring\n", line + j + 1);
96
							} else {
104
							} else {
97
								shiroi_install(&shiroi, slot, dev);
105
								shiroi_install(&shiroi, slot, dev);
Line 118... Line 126...
118
	shiroi_card_t* videocard = shiroi_get_video_card(&shiroi);
126
	shiroi_card_t* videocard = shiroi_get_video_card(&shiroi);
119
	shiroi_video_t* video = NULL;
127
	shiroi_video_t* video = NULL;
120
	if(videocard != NULL) {
128
	if(videocard != NULL) {
121
		video = videocard->videoptr;
129
		video = videocard->videoptr;
122
	}
130
	}
-
 
131
 
123
	shiroi_card_t* textcard = shiroi_get_text_card(&shiroi);
132
	shiroi_card_t* textcard = shiroi_get_text_card(&shiroi);
124
	shiroi_text_t* text = NULL;
133
	shiroi_text_t* text = NULL;
125
	if(textcard != NULL) {
134
	if(textcard != NULL) {
126
		text = textcard->textptr;
135
		text = textcard->textptr;
127
	}
136
	}
128
 
137
 
-
 
138
	shiroi_card_t* debugcard = shiroi_get_debug_card(&shiroi);
-
 
139
	shiroi_debug_t* debug = NULL;
-
 
140
	if(debugcard != NULL) {
-
 
141
		debug = debugcard->debugptr;
-
 
142
	}
-
 
143
 
129
	SetTraceLogLevel(LOG_NONE);
144
	SetTraceLogLevel(LOG_NONE);
130
	if(video != NULL) {
145
	if(video != NULL) {
131
		InitWindow(video->width * scx + (text == NULL ? 0 : 100), video->height * scy, "Shiroi Emulator");
146
		InitWindow(video->width * scx + (text == NULL ? 0 : 200), video->height * scy, "Shiroi Emulator");
132
	} else {
147
	} else {
133
		InitWindow(640 + (text == NULL ? 0 : 100), 480, "Shiroi Emulator");
148
		InitWindow(640 + (text == NULL ? 0 : 200), 480, "Shiroi Emulator");
134
	}
149
	}
135
	InitAudioDevice();
150
	InitAudioDevice();
136
	SetAudioStreamBufferSizeDefault(512);
151
	SetAudioStreamBufferSizeDefault(512);
137
	AudioStream as = LoadAudioStream(48000, 16, 1);
152
	AudioStream as = LoadAudioStream(48000, 16, 1);
138
	SetAudioStreamCallback(as, shiroi.play_audio);
153
	SetAudioStreamCallback(as, shiroi.play_audio);
Line 149... Line 164...
149
			}
164
			}
150
		}
165
		}
151
	}
166
	}
152
 
167
 
153
	RenderTexture r;
168
	RenderTexture r;
-
 
169
	if(video != NULL) {
154
	if(video != NULL) r = LoadRenderTexture(video->width, video->height);
170
		r = LoadRenderTexture(video->width, video->height);
-
 
171
		BeginTextureMode(r);
-
 
172
		ClearBackground(BLACK);
-
 
173
		EndTextureMode();
-
 
174
	}
155
	PlayAudioStream(as);
175
	PlayAudioStream(as);
156
	thread_start();
176
	thread_start();
157
	while(!WindowShouldClose()) {
177
	while(!WindowShouldClose()) {
158
		BeginDrawing();
178
		BeginDrawing();
159
 
179
 
Line 282... Line 302...
282
				}
302
				}
283
			}
303
			}
284
 
304
 
285
			EndTextureMode();
305
			EndTextureMode();
286
 
306
 
287
			DrawTexturePro(r.texture, (Rectangle){0, 0, video->width, -video->height}, (Rectangle){text == NULL ? 0 : 100, 0, GetScreenWidth() - (text == NULL ? 0 : 100), GetScreenHeight()}, (Vector2){0, 0}, 0, WHITE);
307
			DrawTexturePro(r.texture, (Rectangle){0, 0, video->width, -video->height}, (Rectangle){text == NULL ? 0 : 200, 0, GetScreenWidth() - (text == NULL ? 0 : 200), GetScreenHeight()}, (Vector2){0, 0}, 0, WHITE);
288
		} else {
308
		} else {
289
			DrawText("No Video", 0, 20, 20, WHITE);
309
			DrawText("No Video", 0, 20, 20, WHITE);
290
		}
310
		}
291
 
311
 
292
		DrawText("Caps Lock", 5, 5, 10, WHITE);
312
		DrawText("Caps Lock", 5, 5, 10, WHITE);
293
 
313
 
294
		DrawCircle(100 - 10, 10, 5, text->caps ? RED : BLACK);
314
		DrawCircle(200 - 10, 10, 5, text->caps ? ON_COLOR : OFF_COLOR);
-
 
315
 
-
 
316
		if(debug != NULL) {
-
 
317
			DrawText("Debug", 5, 5 + 10 + 5, 10, WHITE);
-
 
318
			for(i = 0; i < 4; i++) {
-
 
319
				int shx = i * (5 + 20 + 5 + 5 + 10);
-
 
320
				DrawRectangle(shx + 10, 5 + 5 + 10 + 5 + 10 + 5, 20, 5, get_bit(debug->latch[i], 0) ? ON_COLOR : OFF_COLOR);
-
 
321
				DrawRectangle(shx + 5, 5 + 5 + 10 + 5 + 10 + 10, 5, 20, get_bit(debug->latch[i], 1) ? ON_COLOR : OFF_COLOR);
-
 
322
				DrawRectangle(shx + 5 + 20 + 5, 5 + 5 + 10 + 5 + 10 + 10, 5, 20, get_bit(debug->latch[i], 2) ? ON_COLOR : OFF_COLOR);
-
 
323
				DrawRectangle(shx + 10, 5 + 5 + 10 + 5 + 10 + 5 + 20 + 5, 20, 5, get_bit(debug->latch[i], 3) ? ON_COLOR : OFF_COLOR);
-
 
324
				DrawRectangle(shx + 5, 5 + 5 + 10 + 5 + 10 + 10 + 5 + 20, 5, 20, get_bit(debug->latch[i], 4) ? ON_COLOR : OFF_COLOR);
-
 
325
				DrawRectangle(shx + 5 + 20 + 5, 5 + 5 + 10 + 5 + 10 + 10 + 5 + 20, 5, 20, get_bit(debug->latch[i], 5) ? ON_COLOR : OFF_COLOR);
-
 
326
				DrawRectangle(shx + 10, 5 + 5 + 10 + 5 + 10 + 5 + 20 + 5 + 20 + 5, 20, 5, get_bit(debug->latch[i], 6) ? ON_COLOR : OFF_COLOR);
-
 
327
				DrawRectangle(shx + 5 + 5 + 20 + 5 + 5, 5 + 5 + 10 + 5 + 10 + 5 + 20 + 5 + 20 + 5, 5, 5, get_bit(debug->latch[i], 7) ? ON_COLOR : OFF_COLOR);
-
 
328
			}
-
 
329
		}
295
 
330
 
296
		EndDrawing();
331
		EndDrawing();
297
	}
332
	}
298
	CloseWindow();
333
	CloseWindow();
299
	UnloadAudioStream(as);
334
	UnloadAudioStream(as);