1 /***************************************************************************
2 * Copyright (C) 2012-2013 by Ilari Liusvaara *
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. *
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. *
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 ***************************************************************************/
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/instance.hpp"
31 #include "core/messages.hpp"
32 #include "interface/callbacks.hpp"
33 #include "interface/cover.hpp"
34 #include "interface/romtype.hpp"
35 #include "library/framebuffer-pixfmt-rgb32.hpp"
36 #include "library/string.hpp"
37 #include "library/portctrl-data.hpp"
38 #include "library/serialization.hpp"
39 #include "library/minmax.hpp"
40 #include "library/framebuffer.hpp"
41 #include "library/hex.hpp"
45 uint32_t cover_fbmem
[480 * 432];
49 struct framebuffer::info cover_fbinfo
= {
50 &framebuffer::pixfmt_rgb32
, //Format.
51 (char*)cover_fbmem
, //Memory.
52 480, 432, 1920, //Physical size.
53 480, 432, 1920, //Logical size.
57 struct interface_device_reg test_registers
[] = {
63 controller_set
test_controllerconfig(std::map
<std::string
, std::string
>& settings
)
65 std::map
<std::string
, std::string
> _settings
= settings
;
67 r
.ports
.push_back(&psystem
);
68 r
.ports
.push_back(&ptype1
);
69 r
.ports
.push_back(&ptype2
);
70 r
.logical_map
.push_back(std::make_pair(1, 0));
71 r
.logical_map
.push_back(std::make_pair(2, 0));
75 void redraw_cover_fbinfo()
77 for(size_t i
= 0; i
< sizeof(cover_fbmem
) / sizeof(cover_fbmem
[0]); i
++)
78 cover_fbmem
[i
] = 0x00000000;
79 cover_render_string(cover_fbmem
, 0, 0, "TEST MODE", 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
84 for(size_t i
= 0; i
< sizeof(cover_fbmem
) / sizeof(cover_fbmem
[0]); i
++)
85 cover_fbmem
[i
] = 0x00000000;
87 std::ostringstream str
;
89 for(unsigned i
= 0; i
< 6; i
++)
90 str
<< ecore_callbacks
->get_input(1, 0, i
) << " ";
91 for(unsigned i
= 0; i
< 15; i
++)
92 if(ecore_callbacks
->get_input(1, 0, i
+ 6)) k
|= (1 << i
);
94 cover_render_string(cover_fbmem
, 0, 0, str
.str(), 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
97 std::ostringstream str
;
99 for(unsigned i
= 0; i
< 6; i
++)
100 str
<< ecore_callbacks
->get_input(2, 0, i
) << " ";
101 for(unsigned i
= 0; i
< 15; i
++)
102 if(ecore_callbacks
->get_input(2, 0, i
+ 6)) k
|= (1 << i
);
104 cover_render_string(cover_fbmem
, 0, 16, str
.str(), 0xFFFFFF, 0x00000, 480, 432, 1920, 4);
108 struct _test_core
: public core_core
, public core_type
, public core_region
, public core_sysregion
111 : core_core({&psystem
, &ptype1
, &ptype2
}, {
112 {0, "xyzzy", "xyzzy", {
113 {"Magic", "enum:[\"foo\",\"bar\",\"baz\",[\"qux\",\"zot\"]]"}
123 .images
= {{"rom", "Cartridge ROM", 1, 0, 0, "test"}},
127 core_region({{"world", "World", 0, 0, false, {1, 60}, {0}}}),
128 core_sysregion("test", *this, *this) { hide(); }
130 std::string
c_core_identifier() const { return "TEST"; }
131 bool c_set_region(core_region
& region
) { return (®ion
== this); }
132 std::pair
<uint32_t, uint32_t> c_video_rate() { return std::make_pair(60, 1); }
133 double c_get_PAR() { return 1.0; }
134 std::pair
<uint32_t, uint32_t> c_audio_rate() { return std::make_pair(48000, 1); }
135 std::map
<std::string
, std::vector
<char>> c_save_sram() throw(std::bad_alloc
) {
136 std::map
<std::string
, std::vector
<char>> s
;
139 void c_load_sram(std::map
<std::string
, std::vector
<char>>& sram
) throw(std::bad_alloc
) {}
140 void c_serialize(std::vector
<char>& out
) { out
.clear(); }
141 void c_unserialize(const char* in
, size_t insize
) {}
142 core_region
& c_get_region() { return *this; }
144 void c_unload_cartridge() {}
145 std::pair
<uint32_t, uint32_t> c_get_scale_factors(uint32_t width
, uint32_t height
) {
146 return std::make_pair(max(512 / width
, (uint32_t)1), max(448 / height
, (uint32_t)1));
148 void c_install_handler() {}
149 void c_uninstall_handler() {}
151 int16_t audio
[800] = {0};
154 framebuffer::info inf
;
155 inf
.type
= &framebuffer::pixfmt_rgb32
;
156 inf
.mem
= reinterpret_cast<char*>(cover_fbmem
);
158 inf
.physheight
= 432;
159 inf
.physstride
= 1920;
165 framebuffer::raw
ls(inf
);
166 ecore_callbacks
->output_frame(ls
, 60,1);
167 CORE().audio
->submit_buffer(audio
, 800, false, 48000);
169 void c_runtosave() {}
170 bool c_get_pflag() { return pflag
; }
171 void c_set_pflag(bool _pflag
) { pflag
= _pflag
; }
172 framebuffer::raw
& c_draw_cover() {
173 static framebuffer::raw
x(cover_fbinfo
);
174 redraw_cover_fbinfo();
177 std::string
c_get_core_shortname() const { return "test"; }
178 void c_pre_emulate_frame(portctrl::frame
& cf
) {}
179 void c_execute_action(unsigned id
, const std::vector
<interface_action_paramval
>& p
)
182 messages
<< "ID #0, choice: " << p
[0].i
<< std::endl
;
184 const interface_device_reg
* c_get_registers() { return test_registers
; }
185 int t_load_rom(core_romimage
* images
, std::map
<std::string
, std::string
>& settings
,
186 uint64_t rtc_sec
, uint64_t rtc_subsec
)
190 controller_set
t_controllerconfig(std::map
<std::string
, std::string
>& settings
)
192 return test_controllerconfig(settings
);
194 std::pair
<uint64_t, uint64_t> c_get_bus_map() { return std::make_pair(0, 0); }
195 std::list
<core_vma_info
> c_vma_list() { return std::list
<core_vma_info
>(); }
196 std::set
<std::string
> c_srams() { return std::set
<std::string
>(); }
197 unsigned c_action_flags(unsigned id
) { return 1; }
198 int c_reset_action(bool hard
) { return -1; }
199 void c_set_debug_flags(uint64_t addr
, unsigned int sflags
, unsigned int cflags
) {}
200 void c_set_cheat(uint64_t addr
, uint64_t value
, bool set
) {}
201 void c_debug_reset() {}
202 std::vector
<std::string
> c_get_trace_cpus()
204 return std::vector
<std::string
>();
206 void c_reset_to_load()