Skip to content

Commit 1f85d70

Browse files
committed
sega/sega_beena.cpp, sega_beena_cart.xml: Add software items and peripheral card reader support
1 parent 4af2e3e commit 1f85d70

File tree

10 files changed

+1462
-274
lines changed

10 files changed

+1462
-274
lines changed

hash/sega_beena_cart.xml

Lines changed: 820 additions & 21 deletions
Large diffs are not rendered by default.

hash/tvochken.xml

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

src/mame/layout/beena.lay

Lines changed: 130 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
license:CC0-1.0
44
-->
55
<mamelayout version="2">
6+
<element name="card" />
7+
68
<element name="pencursor">
79
<image state="1">
810
<data><![CDATA[
@@ -51,77 +53,140 @@ license:CC0-1.0
5153
</element>
5254
</view>
5355

56+
<view name="Storyware and Card View">
57+
<screen index="0">
58+
<bounds x="0" y="0" width="4" height="3" />
59+
</screen>
60+
61+
<element id="leftpage" ref="leftpage">
62+
<bounds x="0" y="3.1" width="2" height="2.8" />
63+
</element>
64+
<element id="rightpage" ref="rightpage">
65+
<bounds x="2" y="3.1" width="2" height="2.8" />
66+
</element>
67+
68+
<element id="pencursor" ref="pencursor">
69+
<!-- will be positioned by script -->
70+
<bounds x="0" y="3.1" width="0.2" height="0.2" />
71+
<color alpha="0.7" />
72+
</element>
73+
74+
<element ref="card">
75+
<bounds x="0" y="6" width="4" height="2.65" />
76+
</element>
77+
</view>
78+
5479
<script><![CDATA[
55-
file:set_resolve_tags_callback(
56-
function ()
57-
-- get memory regions for page scans
58-
local pages = { }
59-
for i = 1, 12 do
60-
local page = file.device:memregion(string.format('cartslot:page%u', i))
61-
if page ~= nil then
62-
pages[i] = page
63-
else
64-
break
65-
end
66-
end
80+
local function init_storyware(view)
81+
-- get memory regions for page scans
82+
local pages = { }
83+
for i = 1, 12 do
84+
local page = file.device:memregion(string.format('cartslot:page%u', i))
85+
if page ~= nil then
86+
pages[i] = page
87+
else
88+
break
89+
end
90+
end
91+
92+
-- left/right page items are needed on-the-fly
93+
local leftpage = file.views[view].items['leftpage']
94+
local rightpage = file.views[view].items['rightpage']
95+
96+
-- recompute target pen cursor size and area when necessary
97+
local curxoffs, curyoffs, curxscale, curyscale, curwidth, curheight
98+
file.views[view]:set_recomputed_callback(
99+
function ()
100+
local lbounds = leftpage.bounds
101+
local rbounds = rightpage.bounds
102+
curwidth = lbounds.width / 10
103+
curheight = lbounds.height / 14
104+
curxoffs = lbounds.x0 - (curwidth * 0.5)
105+
curyoffs = lbounds.y0 - (curheight * 0.5)
106+
curxscale = (rbounds.x1 - lbounds.x0) / 255
107+
curyscale = lbounds.height / 255
108+
end)
109+
110+
-- make page display respond to page selection input
111+
local pagectrl = file.device:ioport('PAGE')
112+
local function get_page() return pagectrl:read() end
113+
leftpage:set_element_state_callback(get_page)
114+
rightpage:set_element_state_callback(get_page)
67115
68-
-- left/right page items are needed on-the-fly
69-
local leftpage = file.views['Default View'].items['leftpage']
70-
local rightpage = file.views['Default View'].items['rightpage']
71-
72-
-- recompute target pen cursor size and area when necessary
73-
local curxoffs, curyoffs, curxscale, curyscale, curwidth, curheight
74-
file.views['Default View']:set_recomputed_callback(
75-
function ()
76-
local lbounds = leftpage.bounds
77-
local rbounds = rightpage.bounds
78-
curwidth = lbounds.width / 10
79-
curheight = lbounds.height / 14
80-
curxoffs = lbounds.x0 - (curwidth * 0.5)
81-
curyoffs = lbounds.y0 - (curheight * 0.5)
82-
curxscale = (rbounds.x1 - lbounds.x0) / 255
83-
curyscale = lbounds.height / 255
84-
end)
85-
86-
-- make page display respond to page selection input
87-
local pagectrl = file.device:ioport('PAGE')
88-
local function get_page() return pagectrl:read() end
89-
leftpage:set_element_state_callback(get_page)
90-
rightpage:set_element_state_callback(get_page)
91-
92-
-- render even pages on the left, odd pages on the right
93-
local function draw_page(n, dest)
94-
local page = pages[n]
95-
if page ~= nil then
116+
-- render even pages on the left, odd pages on the right
117+
local function draw_page(n, dest)
118+
local page = pages[n]
119+
if page ~= nil then
120+
-- TODO: reduce temporary memory usage when I/O classes are exposed to Lua
121+
local data = page:read(0, page.size)
122+
local image = emu.bitmap_argb32.load(data)
123+
image:resample(dest)
124+
end
125+
end
126+
file.elements['leftpage']:set_draw_callback(
127+
function (state, bitmap)
128+
draw_page(state * 2, bitmap)
129+
end)
130+
file.elements['rightpage']:set_draw_callback(
131+
function (state, bitmap)
132+
draw_page((state * 2) + 1, bitmap)
133+
end)
134+
135+
-- animate the position of the pen cursor
136+
local penctrl = file.device:ioport('PEN_LEFT')
137+
local penx = file.device:ioport('PENX')
138+
local peny = file.device:ioport('PENY')
139+
file.views[view].items['pencursor']:set_element_state_callback(
140+
function ()
141+
return (penctrl:read() & 2) >> 1
142+
end)
143+
file.views[view].items['pencursor']:set_bounds_callback(
144+
function ()
145+
local x = curxoffs + (penx:read() * curxscale)
146+
local y = curyoffs + (peny:read() * curyscale)
147+
return emu.render_bounds(x, y, x + curwidth, y + curheight)
148+
end)
149+
end
150+
151+
local sub -- keep this here to avoid it being garbage collected prematurely
152+
153+
local function init_card()
154+
-- get card slot device and card display element
155+
local card_device = emu.image_enumerator(file.device)['card']
156+
local card_element = file.elements['card']
157+
158+
-- invalidate the card display on media change
159+
local card_data = card_device.device:memregion('card')
160+
sub = card_device:add_media_change_notifier(
161+
function (event)
162+
card_data = card_device.device:memregion('card')
163+
card_element:invalidate()
164+
end)
165+
166+
-- draw the card image
167+
card_element:set_draw_callback(
168+
function (state, bitmap)
169+
if card_data ~= nil then
96170
-- TODO: reduce temporary memory usage when I/O classes are exposed to Lua
97-
local data = page:read(0, page.size)
171+
local data = card_data:read(0, card_data.size)
98172
local image = emu.bitmap_argb32.load(data)
99-
image:resample(dest)
173+
image:resample(bitmap)
100174
end
175+
end)
176+
end
177+
178+
file:set_resolve_tags_callback(
179+
function ()
180+
local barcode_device = emu.device_enumerator(file.device, 3)[':card:rd']
181+
if barcode_device == nil then
182+
barcode_device = emu.device_enumerator(file.device, 3)[':card:rd2061']
183+
end
184+
if barcode_device == nil then
185+
init_storyware('Default View')
186+
else
187+
init_storyware('Storyware and Card View')
188+
init_card()
101189
end
102-
file.elements['leftpage']:set_draw_callback(
103-
function (state, bitmap)
104-
draw_page(state * 2, bitmap)
105-
end)
106-
file.elements['rightpage']:set_draw_callback(
107-
function (state, bitmap)
108-
draw_page((state * 2) + 1, bitmap)
109-
end)
110-
111-
-- animate the position of the pen cursor
112-
local penctrl = file.device:ioport('PEN_LEFT')
113-
local penx = file.device:ioport('PENX')
114-
local peny = file.device:ioport('PENY')
115-
file.views['Default View'].items['pencursor']:set_element_state_callback(
116-
function ()
117-
return (penctrl:read() & 2) >> 1
118-
end)
119-
file.views['Default View'].items['pencursor']:set_bounds_callback(
120-
function ()
121-
local x = curxoffs + (penx:read() * curxscale)
122-
local y = curyoffs + (peny:read() * curyscale)
123-
return emu.render_bounds(x, y, x + curwidth, y + curheight)
124-
end)
125190
end)
126191
]]></script>
127192
</mamelayout>

src/mame/sega/tvochken_card.cpp renamed to src/mame/sega/9h0-0008_card.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// copyright-holders:Vas Crabb
33
/******************************************************************************
44
5-
tvochken_card.cpp
5+
9h0-0008_card.cpp
66
7-
Sega TV Ocha-ken barcode card loader
7+
Sega Toys 9H0-0008 barcode card loader
88
99
TODO:
1010
* Decode barcode from the scan so it doesn't need to be in a software
@@ -13,7 +13,8 @@
1313
*******************************************************************************/
1414

1515
#include "emu.h"
16-
#include "tvochken_card.h"
16+
17+
#include "9h0-0008_card.h"
1718

1819
#include "rendutil.h"
1920
#include "softlist_dev.h"
@@ -24,27 +25,33 @@
2425
#include <sstream>
2526

2627

27-
DEFINE_DEVICE_TYPE(TVOCHKEN_CARD, tvochken_card_device, "tvochken_card", "Sega TV Ocha-Ken barcode card")
28+
DEFINE_DEVICE_TYPE(SEGA_9H0_0008_CARD, sega_9h0_0008_card_device, "sega_9h0_0008_card", "Sega Toys 9H0-0008 barcode card")
2829

2930

30-
tvochken_card_device::tvochken_card_device(
31+
sega_9h0_0008_card_device::sega_9h0_0008_card_device(
3132
machine_config const &mconfig,
3233
char const *tag,
3334
device_t *owner,
3435
u32 clock)
35-
: device_t(mconfig, TVOCHKEN_CARD, tag, owner, clock)
36+
: sega_9h0_0008_card_device(mconfig, SEGA_9H0_0008_CARD, tag, owner, clock)
37+
{
38+
}
39+
40+
41+
sega_9h0_0008_card_device::sega_9h0_0008_card_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
42+
: sega_9h0_0008_iox_slot_device(mconfig, type, tag, owner, clock)
3643
, device_image_interface(mconfig, *this)
3744
, m_barcode(0)
3845
{
3946
}
4047

4148

42-
tvochken_card_device::~tvochken_card_device()
49+
sega_9h0_0008_card_device::~sega_9h0_0008_card_device()
4350
{
4451
}
4552

4653

47-
std::pair<std::error_condition, std::string> tvochken_card_device::call_load()
54+
std::pair<std::error_condition, std::string> sega_9h0_0008_card_device::call_load()
4855
{
4956
memory_region *cardrgn;
5057
if (loaded_through_softlist())
@@ -106,7 +113,7 @@ std::pair<std::error_condition, std::string> tvochken_card_device::call_load()
106113
// TODO: support reading barcode from image
107114
m_barcode = 0;
108115
osd_printf_warning(
109-
"%s: TV Ocha-Ken barcodes are only supported for software list items.\n",
116+
"%s: Sega Toys 9H0-0008 barcodes are only supported for software list items.\n",
110117
tag());
111118
}
112119

@@ -137,7 +144,7 @@ std::pair<std::error_condition, std::string> tvochken_card_device::call_load()
137144
}
138145

139146

140-
void tvochken_card_device::call_unload()
147+
void sega_9h0_0008_card_device::call_unload()
141148
{
142149
memory_region *const cardrgn = memregion("card");
143150
if (cardrgn)
@@ -147,11 +154,12 @@ void tvochken_card_device::call_unload()
147154
}
148155

149156

150-
void tvochken_card_device::device_start()
157+
void sega_9h0_0008_card_device::device_start()
151158
{
152159
}
153160

154-
software_list_loader const &tvochken_card_device::get_software_list_loader() const
161+
162+
software_list_loader const &sega_9h0_0008_card_device::get_software_list_loader() const
155163
{
156164
return rom_software_list_loader::instance();
157165
}

src/mame/sega/tvochken_card.h renamed to src/mame/sega/9h0-0008_card.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,37 @@
22
// copyright-holders:Vas Crabb
33
/******************************************************************************
44
5-
tvochken_card.h
5+
9h0-0008_card.h
66
7-
Sega TV Ocha-ken barcode card loader
7+
Sega Toys 9H0-0008 barcode card loader
88
99
*******************************************************************************/
10-
#ifndef MAME_SEGA_TVOCHKEN_CARD_H
11-
#define MAME_SEGA_TVOCHKEN_CARD_H
10+
#ifndef MAME_SEGA_9H0_0008_CARD_H
11+
#define MAME_SEGA_9H0_0008_CARD_H
1212

1313
#pragma once
1414

1515
#include <string>
1616
#include <system_error>
1717
#include <utility>
1818

19+
#include "9h0-0008_iox.h"
1920

20-
class tvochken_card_device : public device_t, public device_image_interface
21+
class sega_9h0_0008_card_device : public sega_9h0_0008_iox_slot_device, public device_image_interface
2122
{
2223
public:
23-
tvochken_card_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock = 0);
24-
virtual ~tvochken_card_device();
24+
// construction/destruction
25+
template <typename T>
26+
sega_9h0_0008_card_device(machine_config const &mconfig, char const *tag, device_t *owner, T &&opts, char const *dflt, bool const fixed)
27+
: sega_9h0_0008_card_device(mconfig, tag, owner, 0)
28+
{
29+
option_reset();
30+
opts(*this);
31+
set_default_option(dflt);
32+
set_fixed(fixed);
33+
}
34+
sega_9h0_0008_card_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock = 0);
35+
virtual ~sega_9h0_0008_card_device();
2536

2637
// device_image_interface implementation
2738
virtual std::pair<std::error_condition, std::string> call_load() override ATTR_COLD;
@@ -30,14 +41,16 @@ class tvochken_card_device : public device_t, public device_image_interface
3041
virtual bool is_writeable() const noexcept override { return false; }
3142
virtual bool is_creatable() const noexcept override { return false; }
3243
virtual bool is_reset_on_load() const noexcept override { return false; }
33-
virtual char const *image_interface() const noexcept override { return "tvochken_card"; }
44+
virtual char const *image_interface() const noexcept override { return "sega_9h0_0008_card"; }
3445
virtual char const *file_extensions() const noexcept override { return "png,jpg,bmp"; } // loose media not supported yet
3546
virtual char const *image_type_name() const noexcept override { return "card"; }
3647
virtual char const *image_brief_type_name() const noexcept override { return "crd"; }
3748

38-
u16 barcode() const noexcept { return m_barcode; }
49+
virtual u16 data() const noexcept override { return m_barcode; }
3950

4051
protected:
52+
sega_9h0_0008_card_device(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, u32 clock);
53+
4154
// device_t implementation
4255
virtual void device_start() override ATTR_COLD;
4356

@@ -49,6 +62,6 @@ class tvochken_card_device : public device_t, public device_image_interface
4962
};
5063

5164

52-
DECLARE_DEVICE_TYPE(TVOCHKEN_CARD, tvochken_card_device)
65+
DECLARE_DEVICE_TYPE(SEGA_9H0_0008_CARD, sega_9h0_0008_card_device)
5366

54-
#endif // MAME_SEGA_TVOCHKEN_CARD_H
67+
#endif // MAME_SEGA_9H0_0008_CARD_H

0 commit comments

Comments
 (0)