annotate libblastem.c @ 1892:1afd6e85ec26

Properly mask addresses to 24-bit in disassembler
author Michael Pavone <pavone@retrodev.com>
date Thu, 05 Dec 2019 09:32:52 -0800
parents 377f110e4cea
children 81b059e3ded6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1687
diff changeset
1 #include <stdlib.h>
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1687
diff changeset
2 #include <string.h>
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "libretro.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "system.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "util.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "vdp.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "render.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "io.h"
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 static retro_environment_t retro_environment;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 RETRO_API void retro_set_environment(retro_environment_t re)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 retro_environment = re;
1864
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
14 # define input_descriptor_macro(pad_num) \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
15 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
16 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
17 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
18 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
19 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "A" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
20 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "B" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
21 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Y" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
22 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "X" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
23 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Z" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
24 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "C" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
25 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Mode" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
26 { pad_num, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, \
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
27
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
28 static const struct retro_input_descriptor desc[] = {
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
29 input_descriptor_macro(0)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
30 input_descriptor_macro(1)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
31 input_descriptor_macro(2)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
32 input_descriptor_macro(3)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
33 input_descriptor_macro(4)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
34 input_descriptor_macro(5)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
35 input_descriptor_macro(6)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
36 input_descriptor_macro(7)
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
37 { 0 },
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
38 };
96323d73b8ab add input descriptors
hizzlekizzle <hizzlekizzle@users.noreply.github.com>
parents: 1822
diff changeset
39
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
40 re(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, (void *)desc);
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 static retro_video_refresh_t retro_video_refresh;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 RETRO_API void retro_set_video_refresh(retro_video_refresh_t rvf)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 retro_video_refresh = rvf;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 static retro_audio_sample_t retro_audio_sample;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 RETRO_API void retro_set_audio_sample(retro_audio_sample_t ras)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 retro_audio_sample = ras;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 RETRO_API void retro_set_audio_sample_batch(retro_audio_sample_batch_t rasb)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 static retro_input_poll_t retro_input_poll;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 RETRO_API void retro_set_input_poll(retro_input_poll_t rip)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 retro_input_poll = rip;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 static retro_input_state_t retro_input_state;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 RETRO_API void retro_set_input_state(retro_input_state_t ris)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 retro_input_state = ris;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 int headless = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 int exit_after = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 int z80_enabled = 1;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 char *save_filename;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 tern_node *config;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 uint8_t use_native_states = 1;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 system_header *current_system;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 system_media media;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 RETRO_API void retro_init(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 RETRO_API void retro_deinit(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 {
1691
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
86 if (current_system) {
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
87 retro_unload_game();
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
88 }
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 RETRO_API unsigned retro_api_version(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 return RETRO_API_VERSION;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 RETRO_API void retro_get_system_info(struct retro_system_info *info)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 info->library_name = "BlastEm";
1819
4fb9af0c65b6 Update verison number in liblastem.c
Mike Pavone <pavone@retrodev.com>
parents: 1818
diff changeset
99 info->library_version = "0.6.3-pre"; //TODO: share this with blastem.c
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 info->valid_extensions = "md|gen|sms|bin|rom";
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 info->need_fullpath = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 info->block_extract = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 static vid_std video_standard;
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
106 static uint32_t last_width, last_height;
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
107 static uint32_t overscan_top, overscan_bot, overscan_left, overscan_right;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
108 static void update_overscan(void)
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
109 {
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
110 uint8_t overscan;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
111 retro_environment(RETRO_ENVIRONMENT_GET_OVERSCAN, &overscan);
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
112 if (overscan) {
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
113 overscan_top = overscan_bot = overscan_left = overscan_right = 0;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
114 } else {
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
115 if (video_standard == VID_NTSC) {
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
116 overscan_top = 11;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
117 overscan_bot = 8;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
118 overscan_left = 13;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
119 overscan_right = 14;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
120 } else {
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
121 overscan_top = 30;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
122 overscan_bot = 24;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
123 overscan_left = 13;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
124 overscan_right = 14;
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
125 }
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
126 }
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
127 }
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
128
1889
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
129 static int32_t sample_rate;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 RETRO_API void retro_get_system_av_info(struct retro_system_av_info *info)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 {
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
132 update_overscan();
1694
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
133 last_width = LINEBUF_SIZE;
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
134 info->geometry.base_width = info->geometry.max_width = LINEBUF_SIZE - (overscan_left + overscan_right);
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
135 info->geometry.base_height = (video_standard == VID_NTSC ? 243 : 294) - (overscan_top + overscan_bot);
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
136 last_height = info->geometry.base_height;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
137 info->geometry.max_height = info->geometry.base_height * 2;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 info->geometry.aspect_ratio = 0;
1889
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
139 double master_clock = video_standard == VID_NTSC ? 53693175 : 53203395;
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
140 double lines = video_standard == VID_NTSC ? 262 : 313;
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
141 info->timing.fps = master_clock / (3420.0 * lines);
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
142 info->timing.sample_rate = master_clock / (7 * 6 * 24); //sample rate of YM2612
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
143 sample_rate = info->timing.sample_rate;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 /* Resets the current game. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 RETRO_API void retro_reset(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 current_system->soft_reset(current_system);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 /* Runs the game for one video frame.
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 * During retro_run(), input_poll callback must be called at least once.
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 *
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 * If a frame is not rendered for reasons where a game "dropped" a frame,
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 * this still counts as a frame, and retro_run() should explicitly dupe
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 * a frame if GET_CAN_DUPE returns true.
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 * In this case, the video callback can take a NULL argument for data.
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 static uint8_t started;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 RETRO_API void retro_run(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 if (started) {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 current_system->resume_context(current_system);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 } else {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 current_system->start_context(current_system, NULL);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 started = 1;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 /* Returns the amount of data the implementation requires to serialize
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 * internal state (save states).
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 * Between calls to retro_load_game() and retro_unload_game(), the
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 * returned size is never allowed to be larger than a previous returned
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 * value, to ensure that the frontend can allocate a save state buffer once.
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 */
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
181 static size_t serialize_size_cache;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 RETRO_API size_t retro_serialize_size(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 {
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
184 if (!serialize_size_cache) {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
185 uint8_t *tmp = current_system->serialize(current_system, &serialize_size_cache);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
186 free(tmp);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
187 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
188 return serialize_size_cache;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 /* Serializes internal state. If failed, or size is lower than
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 * retro_serialize_size(), it should return false, true otherwise. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 RETRO_API bool retro_serialize(void *data, size_t size)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 {
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
195 size_t actual_size;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
196 uint8_t *tmp = current_system->serialize(current_system, &actual_size);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
197 if (actual_size > size) {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
198 free(tmp);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
199 return 0;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
200 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
201 memcpy(data, tmp, actual_size);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
202 free(tmp);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
203 return 1;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 RETRO_API bool retro_unserialize(const void *data, size_t size)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 {
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
208 current_system->deserialize(current_system, (uint8_t *)data, size);
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 return 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 RETRO_API void retro_cheat_reset(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 /* Loads a game. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 RETRO_API bool retro_load_game(const struct retro_game_info *game)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 {
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1689
diff changeset
223 serialize_size_cache = 0;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 if (game->path) {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 media.dir = path_dirname(game->path);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 media.name = basename_no_extension(game->path);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 media.extension = path_extension(game->path);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 media.buffer = malloc(nearest_pow2(game->size));
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 memcpy(media.buffer, game->data, game->size);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 media.size = game->size;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 current_system = alloc_config_system(detect_system_type(&media), &media, 0, 0);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 unsigned format = RETRO_PIXEL_FORMAT_XRGB8888;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 retro_environment(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &format);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 return current_system != NULL;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 /* Loads a "special" kind of game. Should not be used,
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 * except in extreme cases. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 RETRO_API bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 return retro_load_game(info);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 /* Unloads a currently loaded game. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 RETRO_API void retro_unload_game(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 free(media.dir);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 free(media.name);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 free(media.extension);
1691
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
252 media.dir = media.name = media.extension = NULL;
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
253 //buffer is freed by the context
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
254 media.buffer = NULL;
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
255 current_system->free_context(current_system);
e96d0d3bec7f Don't leak a system context when a game is unloaded
Mike Pavone <pavone@retrodev.com>
parents: 1690
diff changeset
256 current_system = NULL;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 /* Gets region of game. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 RETRO_API unsigned retro_get_region(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 return video_standard == VID_NTSC ? RETRO_REGION_NTSC : RETRO_REGION_PAL;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
264
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 /* Gets region of memory. */
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 RETRO_API void *retro_get_memory_data(unsigned id)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 return NULL;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 RETRO_API size_t retro_get_memory_size(unsigned id)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 return 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
275
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 //blastem render backend API implementation
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 return r << 16 | g << 8 | b;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
282 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
283 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
284 //not supported in lib build
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 return 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 void render_destroy_window(uint8_t which)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 //not supported in lib build
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 static uint32_t fb[LINEBUF_SIZE * 294 * 2];
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
294 static uint8_t last_fb;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
295 uint32_t *render_get_framebuffer(uint8_t which, int *pitch)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
296 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
297 *pitch = LINEBUF_SIZE * sizeof(uint32_t);
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
298 if (which != last_fb) {
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
299 *pitch = *pitch * 2;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
300 }
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
301
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
302 if (which) {
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
303 return fb + LINEBUF_SIZE;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
304 } else {
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
305 return fb;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
306 }
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
307 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
308
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
309 void render_framebuffer_updated(uint8_t which, int width)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
310 {
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
311 unsigned height = (video_standard == VID_NTSC ? 243 : 294) - (overscan_top + overscan_bot);
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
312 width -= (overscan_left + overscan_right);
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
313 unsigned base_height = height;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
314 if (which != last_fb) {
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
315 height *= 2;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
316 last_fb = which;
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
317 }
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
318 if (width != last_width || height != last_height) {
1694
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
319 struct retro_game_geometry geometry = {
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
320 .base_width = width,
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
321 .base_height = height,
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
322 .aspect_ratio = (float)LINEBUF_SIZE / base_height
1694
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
323 };
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
324 retro_environment(RETRO_ENVIRONMENT_SET_GEOMETRY, &geometry);
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
325 last_width = width;
1695
3c34122754ac Properly support interlace in libretro build
Michael Pavone <pavone@retrodev.com>
parents: 1694
diff changeset
326 last_height = height;
1694
9e4dd1595f37 Fix aspect ratio for H32 games
Michael Pavone <pavone@retrodev.com>
parents: 1691
diff changeset
327 }
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
328 retro_video_refresh(fb + overscan_left + LINEBUF_SIZE * overscan_top, width, height, LINEBUF_SIZE * sizeof(uint32_t));
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
329 current_system->request_exit(current_system);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
330 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
331
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
332 uint8_t render_get_active_framebuffer(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
333 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
334 return 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
335 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
336
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
337 void render_set_video_standard(vid_std std)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
338 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
339 video_standard = std;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
340 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
341
1822
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1819
diff changeset
342 int render_fullscreen(void)
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1819
diff changeset
343 {
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1819
diff changeset
344 return 1;
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1819
diff changeset
345 }
8500bd987dda Make libretro target successfully build for Windows and possibly Mac
Mike Pavone <pavone@retrodev.com>
parents: 1819
diff changeset
346
1881
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
347 uint32_t render_overscan_top()
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
348 {
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
349 return overscan_top;
1881
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
350 }
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
351
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
352 uint32_t render_overscan_bot()
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
353 {
1882
62e8a8833e39 Implement overscan crop in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1881
diff changeset
354 return overscan_bot;
1881
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
355 }
55198fc9cc1f Don't render lines that are cropped by overscan. Allows submitting frame earlier when bottom overscan is non-zero which can reduce latency in some cases
Mike Pavone <pavone@retrodev.com>
parents: 1868
diff changeset
356
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
357 void process_events()
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
358 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
359 static int16_t prev_state[2][RETRO_DEVICE_ID_JOYPAD_L2];
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
360 static const uint8_t map[] = {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
361 BUTTON_A, BUTTON_X, BUTTON_MODE, BUTTON_START, DPAD_UP, DPAD_DOWN,
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
362 DPAD_LEFT, DPAD_RIGHT, BUTTON_B, BUTTON_Y, BUTTON_Z, BUTTON_C
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
363 };
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
364 //TODO: handle other input device types
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
365 //TODO: handle more than 2 ports when appropriate
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
366 retro_input_poll();
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
367 for (int port = 0; port < 2; port++)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
368 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
369 for (int id = RETRO_DEVICE_ID_JOYPAD_B; id < RETRO_DEVICE_ID_JOYPAD_L2; id++)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
370 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371 int16_t new_state = retro_input_state(port, RETRO_DEVICE_JOYPAD, 0, id);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 if (new_state != prev_state[port][id]) {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
373 if (new_state) {
1689
7f42a93f18a4 Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
374 current_system->gamepad_down(current_system, port + 1, map[id]);
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
375 } else {
1689
7f42a93f18a4 Have a suitable default IO port configuration when nonIO is present from the config file. Fixed off by one in processing gamepad button events in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
376 current_system->gamepad_up(current_system, port + 1, map[id]);
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
377 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
378 prev_state[port][id] = new_state;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
379 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
380 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
381 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
382 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
383
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
384 void render_errorbox(char *title, char *message)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
385 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
386 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
387 void render_warnbox(char *title, char *message)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
388 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
389 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
390 void render_infobox(char *title, char *message)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393
1868
bfacedbae5f0 Fix libretro and stateview targets
Michael Pavone <pavone@retrodev.com>
parents: 1864
diff changeset
394 typedef struct {
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 int32_t freq;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
396 int32_t left_accum;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
397 int32_t right_accum;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398 int32_t num_samples;
1868
bfacedbae5f0 Fix libretro and stateview targets
Michael Pavone <pavone@retrodev.com>
parents: 1864
diff changeset
399 } audio_source;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
400
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
401 static audio_source *audio_sources[8];
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
402 static uint8_t num_audio_sources;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
403 audio_source *render_audio_source(uint64_t master_clock, uint64_t sample_divider, uint8_t channels)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
404 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
405 audio_sources[num_audio_sources] = calloc(1, sizeof(audio_source));
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1687
diff changeset
406 audio_sources[num_audio_sources]->freq = master_clock / sample_divider;
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
407 return audio_sources[num_audio_sources++];
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
408 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
409
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
410 void render_audio_adjust_clock(audio_source *src, uint64_t master_clock, uint64_t sample_divider)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
411 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
412 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
413
1817
03895a4585c3 Fix build breakage for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1695
diff changeset
414 void render_audio_source_gaindb(audio_source *src, float gain)
03895a4585c3 Fix build breakage for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1695
diff changeset
415 {
03895a4585c3 Fix build breakage for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1695
diff changeset
416 //TODO: Implement this once I hook up a core option for individual FM/PSG gain
03895a4585c3 Fix build breakage for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1695
diff changeset
417 }
03895a4585c3 Fix build breakage for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1695
diff changeset
418
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
419 static void check_put_sample(void)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
420 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
421 for (int i = 0; i < num_audio_sources; i++)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
422 {
1889
377f110e4cea Report more accurate frame and sample rates to frontend in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1882
diff changeset
423 int32_t min_samples = audio_sources[i]->freq / sample_rate;
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1687
diff changeset
424 if (audio_sources[i]->num_samples < min_samples) {
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
425 return;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
426 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
427 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
428 int16_t left = 0, right = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
429 for (int i = 0; i < num_audio_sources; i++)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
430 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
431 left += audio_sources[i]->left_accum / audio_sources[i]->num_samples;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
432 right += audio_sources[i]->right_accum / audio_sources[i]->num_samples;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
433 audio_sources[i]->left_accum = audio_sources[i]->right_accum = audio_sources[i]->num_samples = 0;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
434 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
435 retro_audio_sample(left, right);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
436 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
437
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
438 void render_put_mono_sample(audio_source *src, int16_t value)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
439 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
440 src->left_accum += value;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
441 src->right_accum += value;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
442 src->num_samples++;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
443 check_put_sample();
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
444 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
445 void render_put_stereo_sample(audio_source *src, int16_t left, int16_t right)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
446 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
447 src->left_accum += left;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
448 src->right_accum += right;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
449 src->num_samples++;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
450 check_put_sample();
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
451 }
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1687
diff changeset
452
1687
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
453 void render_free_source(audio_source *src)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
454 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
455 int index;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456 for (index = 0; index < num_audio_sources; index++)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
457 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
458 if (audio_sources[index] == src) {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
459 break;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
460 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
461 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
462 num_audio_sources--;
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
463 audio_sources[index] = audio_sources[num_audio_sources];
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
464 free(src);
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
465 }
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
466
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
467 void bindings_set_mouse_mode(uint8_t mode)
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
468 {
6c54bb5fe3b3 Hacky WIP libertro implementation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
469 }
1818
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
470
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
471 extern const char rom_db_data[];
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
472 char *read_bundled_file(char *name, uint32_t *sizeret)
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
473 {
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
474 if (!strcmp(name, "rom.db")) {
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
475 *sizeret = strlen(rom_db_data);
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
476 char *ret = malloc(*sizeret+1);
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
477 memcpy(ret, rom_db_data, *sizeret + 1);
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
478 return ret;
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
479 }
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
480 return NULL;
243f3a7247f9 Include ROM DB in library binary for libretro target
Mike Pavone <pavone@retrodev.com>
parents: 1817
diff changeset
481 }