More cleanup via initializer lists
[lsnes.git] / src / emulation / test / test.cpp
blob5c39b2d5877697ed491a4523906733e50093d525
1 /***************************************************************************
2 * Copyright (C) 2012-2013 by Ilari Liusvaara *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License version 2 as *
6 * published by the Free Software Foundation. *
7 * *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11 * GNU General Public License version 2 for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License *
14 * version 2 along with this program; if not, write to the *
15 * Free Software Foundation, Inc., *
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17 ***************************************************************************/
18 #include "lsnes.hpp"
19 #include <sstream>
20 #include <iostream>
21 #include <map>
22 #include <string>
23 #include <vector>
24 #include "core/audioapi.hpp"
25 #include "core/misc.hpp"
26 #include "core/command.hpp"
27 #include "core/controllerframe.hpp"
28 #include "core/dispatch.hpp"
29 #include "core/framebuffer.hpp"
30 #include "core/window.hpp"
31 #include "interface/callbacks.hpp"
32 #include "interface/cover.hpp"
33 #include "interface/romtype.hpp"
34 #include "library/pixfmt-rgb32.hpp"
35 #include "library/string.hpp"
36 #include "library/controller-data.hpp"
37 #include "library/serialization.hpp"
38 #include "library/minmax.hpp"
39 #include "library/framebuffer.hpp"
41 namespace
43 uint32_t cover_fbmem[480 * 432];
44 bool pflag = false;
46 //Framebuffer.
47 struct framebuffer_info cover_fbinfo = {
48 &_pixel_format_rgb32, //Format.
49 (char*)cover_fbmem, //Memory.
50 480, 432, 1920, //Physical size.
51 480, 432, 1920, //Logical size.
52 0, 0 //Offset.
55 struct interface_device_reg test_registers[] = {
56 {NULL, NULL, NULL}
59 #include "ports.inc"
61 port_index_triple t(unsigned p, unsigned c, unsigned i, bool nl)
63 port_index_triple x;
64 x.valid = true;
65 x.port = p;
66 x.controller = c;
67 x.control = i;
68 return x;
71 controller_set test_controllerconfig(std::map<std::string, std::string>& settings)
73 std::map<std::string, std::string> _settings = settings;
74 controller_set r;
75 r.ports.push_back(&psystem);
76 r.ports.push_back(&ptype1);
77 r.ports.push_back(&ptype2);
78 for(unsigned i = 0; i < 5; i++)
79 r.portindex.indices.push_back(t(0, 0, i, false));
80 for(unsigned i = 0; i < 21; i++)
81 r.portindex.indices.push_back(t(1, 0, i, true));
82 for(unsigned i = 0; i < 21; i++)
83 r.portindex.indices.push_back(t(2, 0, i, true));
84 r.portindex.logical_map.push_back(std::make_pair(1, 0));
85 r.portindex.logical_map.push_back(std::make_pair(2, 0));
86 r.portindex.pcid_map.push_back(std::make_pair(1, 0));
87 r.portindex.pcid_map.push_back(std::make_pair(2, 0));
88 return r;
91 void redraw_cover_fbinfo()
93 for(size_t i = 0; i < sizeof(cover_fbmem) / sizeof(cover_fbmem[0]); i++)
94 cover_fbmem[i] = 0x00000000;
95 cover_render_string(cover_fbmem, 0, 0, "TEST MODE", 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
98 void redraw_screen()
100 for(size_t i = 0; i < sizeof(cover_fbmem) / sizeof(cover_fbmem[0]); i++)
101 cover_fbmem[i] = 0x00000000;
103 std::ostringstream str;
104 unsigned k = 0;
105 for(unsigned i = 0; i < 6; i++)
106 str << ecore_callbacks->get_input(1, 0, i) << " ";
107 for(unsigned i = 0; i < 15; i++)
108 if(ecore_callbacks->get_input(1, 0, i + 6)) k |= (1 << i);
109 str << std::hex << std::setw(4) << std::setfill('0') << k;
110 cover_render_string(cover_fbmem, 0, 0, str.str(), 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
113 std::ostringstream str;
114 unsigned k = 0;
115 for(unsigned i = 0; i < 6; i++)
116 str << ecore_callbacks->get_input(2, 0, i) << " ";
117 for(unsigned i = 0; i < 15; i++)
118 if(ecore_callbacks->get_input(2, 0, i + 6)) k |= (1 << i);
119 str << std::hex << std::setw(4) << std::setfill('0') << k;
120 cover_render_string(cover_fbmem, 0, 16, str.str(), 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
124 struct _test_core : public core_core, public core_type, public core_region, public core_sysregion
126 _test_core() : core_core({{_port_types}}), core_type({{
127 .iname = "test",
128 .hname = "test",
129 .id = 0,
130 .sysname = "Test",
131 .extensions = "test",
132 .bios = NULL,
133 .regions = {this},
134 .images = {{"rom", "Cartridge ROM", 1, 0, 0}},
135 .settings = {},
136 .core = this,
137 }}), core_region({{"world", "World", 0, 0, false, {1, 60}, {0}}}),
138 core_sysregion("test", *this, *this) {}
139 std::string c_core_identifier() { return "TEST"; }
140 bool c_set_region(core_region& region) { return (&region == this); }
141 std::pair<uint32_t, uint32_t> c_video_rate() { return std::make_pair(60, 1); }
142 std::pair<uint32_t, uint32_t> c_audio_rate() { return std::make_pair(48000, 1); }
143 std::map<std::string, std::vector<char>> c_save_sram() throw(std::bad_alloc) {
144 std::map<std::string, std::vector<char>> s;
145 return s;
147 void c_load_sram(std::map<std::string, std::vector<char>>& sram) throw(std::bad_alloc) {}
148 void c_serialize(std::vector<char>& out) { out.clear(); }
149 void c_unserialize(const char* in, size_t insize) {}
150 core_region& c_get_region() { return *this; }
151 void c_power() {}
152 void c_unload_cartridge() {}
153 std::pair<uint32_t, uint32_t> c_get_scale_factors(uint32_t width, uint32_t height) {
154 return std::make_pair(max(512 / width, (uint32_t)1), max(448 / height, (uint32_t)1));
156 void c_install_handler() { hide(); }
157 void c_uninstall_handler() {}
158 void c_emulate() {
159 pflag = false;
160 redraw_screen();
161 framebuffer_info inf;
162 inf.type = &_pixel_format_rgb32;
163 inf.mem = const_cast<char*>(reinterpret_cast<const char*>(cover_fbmem));
164 inf.physwidth = 480;
165 inf.physheight = 432;
166 inf.physstride = 1920;
167 inf.width = 480;
168 inf.height = 432;
169 inf.stride = 1920;
170 inf.offset_x = 0;
171 inf.offset_y = 0;
172 framebuffer_raw ls(inf);
173 ecore_callbacks->output_frame(ls, 60,1);
175 void c_runtosave() {}
176 bool c_get_pflag() { return pflag; }
177 void c_set_pflag(bool _pflag) { pflag = _pflag; }
178 framebuffer_raw& c_draw_cover() {
179 static framebuffer_raw x(cover_fbinfo);
180 redraw_cover_fbinfo();
181 return x;
183 std::string c_get_core_shortname() { return "test"; }
184 void c_pre_emulate_frame(controller_frame& cf) {}
185 void c_execute_action(unsigned id, const std::vector<interface_action_paramval>& p)
187 if(id == 0)
188 messages << "ID #0, choice: " << p[0].i << std::endl;
190 const interface_device_reg* c_get_registers() { return test_registers; }
191 int t_load_rom(core_romimage* images, std::map<std::string, std::string>& settings,
192 uint64_t rtc_sec, uint64_t rtc_subsec)
194 return 0;
196 controller_set t_controllerconfig(std::map<std::string, std::string>& settings)
198 return test_controllerconfig(settings);
200 std::pair<uint64_t, uint64_t> t_get_bus_map() { return std::make_pair(0, 0); }
201 std::list<core_vma_info> t_vma_list() { return std::list<core_vma_info>(); }
202 std::set<std::string> t_srams() { return std::set<std::string>(); }
203 unsigned c_action_flags(unsigned id) { return 1; }
204 int c_reset_action(bool hard) { return -1; }
205 } test_core;
206 interface_action act_test1(test_core, 0, "xyzzy", "xyzzy",
207 {{"Magic", "enum:[\"foo\",\"bar\",\"baz\",[\"qux\",\"zot\"]]"}});