-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.c
111 lines (97 loc) · 4.29 KB
/
basic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// MIT License
//
// Copyright (c) 2024 Elias Engelbert Plank
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <libretro/retro.h>
#include <stdio.h>
int main(int argc, char **argv) {
display_t display;
display_create(&display, "Emulator", 800, 600);
// renderer with apple2 pc21 font
renderer_t renderer;
renderer_create(&renderer, "assets/pc21.ttf");
renderer_clear_color(&(f32vec4_t){ 0.05f, 0.05f, 0.05f, 1.0f });
emulator_t emulator;
emulator_create(&emulator, &renderer);
// set up callbacks
display_callback_argument(&display, &emulator);
display_key_callback(&display, emulator_key_callback);
display_char_callback(&display, emulator_char_callback);
f32vec3_t amber = { 1.0f, 0.6f, 0.0f };
f32vec3_t amber_dimmed = { 0.9f, 0.5f, 0.0f };
u32 fps_display_counter = 0;
while (display_running(&display)) {
renderer_resize(&renderer, display.width, display.height);
if (emulator.enable_crt) {
renderer_begin_capture(&renderer);
}
renderer_clear();
// stage 1
// input processing
if (emulator.text.submit) {
// spin off executing thread
emulator_run(&emulator);
}
// stage 2, render graphics
switch (emulator.state) {
case EMULATOR_STATE_INPUT: {
// history
f32vec2_t position_iterator = { 30.0f, 30.0f };
for (text_entry_t *it = emulator.history->begin; it; it = it->next) {
position_iterator.x = 30.0f;
renderer_begin_batch(&renderer);
renderer_draw_text(&renderer, &position_iterator, &amber_dimmed, 0.5f, "]%.*s", it->length,
it->data);
renderer_end_batch(&renderer);
}
position_iterator.x = 30.0f;
renderer_begin_batch(&renderer);
renderer_draw_text_with_cursor(&renderer, &position_iterator, &amber, 0.5f, emulator.text.cursor,
"%.*s", emulator.text.fill, emulator.text.data);
renderer_end_batch(&renderer);
// should definitely document this more, here we must clear the render group,
// due to the fact that we might draw the emulator text output in the next frame,
// which would result in left over render commands from our input text
renderer_begin_batch(&renderer);
break;
}
case EMULATOR_STATE_EXECUTION: {
// if the emulator is in execution state, we check the render group for commands and flush
// them to the graphics card, do not clear the render groups as the emulator must
// decide that for himself
renderer_end_batch(&renderer);
break;
}
}
if (emulator.enable_crt) {
renderer_end_capture(&renderer);
}
// stage 3
// check for incoming input
display_update_input(&display);
display_update_frame(&display);
}
// don't be a dork, free your resources :)
emulator_destroy(&emulator);
renderer_destroy(&renderer);
display_destroy(&display);
return 0;
}