Skip to content

Commit

Permalink
sega/sega_beena.cpp: Added basic book page display.
Browse files Browse the repository at this point in the history
sega_beena_cart.xml: Put page scans in individual data areas.

frontend/mame/luaengine_mem.cpp: Added a raw read function for memory
regions.

plugins/layout: Added bitmap classes to layout sandbox.
  • Loading branch information
cuavas committed Nov 3, 2023
1 parent ddbdbb3 commit 6e60af3
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 35 deletions.
6 changes: 6 additions & 0 deletions docs/source/luascript/ref-mem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ manager.machine.devices[tag]:memregion(tag)
Methods
~~~~~~~

region:read(offs, len)
Reads up to the specified length in bytes from the specified offset in the
memory region. The bytes read will be returned as a string. If the
specified length extends beyond the end of the memory region, the returned
string will be shorter than requested. Note that the data will be in host
byte order.
region:read_i{8,16,32,64}(offs)
Reads a signed integer value of the size in bits from the specified offset
in the memory region. The offset is specified in bytes. Reading beyond the
Expand Down
22 changes: 22 additions & 0 deletions docs/source/techspecs/layout_script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ providing what’s needed:
creating :ref:`attotime <luascript-ref-attotime>`, :ref:`bounds
<luascript-ref-renderbounds>` and :ref:`colour <luascript-ref-rendercolor>`
objects.
* ``emu.bitmap_ind8``, ``emu.bitmap_ind16``, ``emu.bitmap_ind32``,
``emu.bitmap_ind64``, ``emu.bitmap_yuy16``, ``emu.bitmap_rgb32`` and
``emu.bitmap_argb32`` objects for creating
:ref:`bitmaps <luascript-ref-bitmap>`.
* ``emu.print_verbose``, ``emu.print_error``, ``emu.print_warning``,
``emu.print_info`` and ``emu.print_debug`` functions for diagnostic output.
* Standard Lua ``tonumber``, ``tostring``, ``pairs`` and ``ipairs`` functions,
Expand Down Expand Up @@ -667,3 +671,21 @@ Get item vertical scroll position
item; larger values pan down. Call with ``nil`` as the argument to restore
the default vertical scroll position handler (based on bindings in the
``yscroll`` child element).

.. _layscript-events-element:

Layout element events
~~~~~~~~~~~~~~~~~~~~~

Layout element events apply to an individual visual element definition.

Draw
``element:set_draw_callback(cb)``

Set callback for additional drawing after the element’s components have been
drawn. This gives the script direct control over the final texture when an
element item is drawn.

The callback is passed two arguments: the element state (an integer) and the
32-bit ARGB bitmap at the required size. The callback must not attempt to
resize the bitmap.
460 changes: 439 additions & 21 deletions hash/sega_beena_cart.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions plugins/layout/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ function layout.startplugin()
attotime = emu.attotime,
render_bounds = emu.render_bounds,
render_color = emu.render_color,
bitmap_ind8 = emu.bitmap_ind8,
bitmap_ind16 = emu.bitmap_ind16,
bitmap_ind32 = emu.bitmap_ind32,
bitmap_ind64 = emu.bitmap_ind64,
bitmap_yuy16 = emu.bitmap_yuy16,
bitmap_rgb32 = emu.bitmap_rgb32,
bitmap_argb32 = emu.bitmap_argb32,
print_verbose = emu.print_verbose,
print_error = emu.print_error,
print_warning = emu.print_warning,
Expand Down
23 changes: 12 additions & 11 deletions scripts/src/formats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,18 @@ if opt_tool(FORMATS, "MZ_CAS") then
}
end

--------------------------------------------------
--
--@src/lib/formats/nabupc_dsk.h,FORMATS["NABUPC_DSK"] = true
--------------------------------------------------

if opt_tool(FORMATS, "NABUPC_DSK") then
files {
MAME_DIR.. "src/lib/formats/nabupc_dsk.cpp",
MAME_DIR.. "src/lib/formats/nabupc_dsk.h",
}
end

--------------------------------------------------
--
--@src/lib/formats/nanos_dsk.h,FORMATS["NANOS_DSK"] = true
Expand Down Expand Up @@ -2318,15 +2330,4 @@ if opt_tool(FORMATS, "FS_HP98X5") then
}
end

--------------------------------------------------
--
--@src/lib/formats/nabupc_dsk.h,FORMATS["NABUPC_DSK"] = true
--------------------------------------------------

if opt_tool(FORMATS, "NABUPC_DSK") then
files {
MAME_DIR.. "src/lib/formats/nabupc_dsk.cpp",
MAME_DIR.. "src/lib/formats/nabupc_dsk.h",
}
end
end
17 changes: 17 additions & 0 deletions src/frontend/mame/luaengine_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "emu.h"
#include "luaengine.ipp"

#include <cstring>


namespace {

Expand Down Expand Up @@ -734,6 +736,21 @@ void lua_engine::initialize_memory(sol::table &emu)


auto region_type = sol().registry().new_usertype<memory_region>("region", sol::no_constructor);
region_type.set_function(
"read",
[] (memory_region &region, sol::this_state s, offs_t offset, offs_t length)
{
// TODO: should this do something special if the offset isn't a multiple of the byte width?
buffer_helper buf(s);
const offs_t limit = std::min<offs_t>(region.bytes(), offset + length);
const offs_t copyable = (limit > offset) ? (limit - offset) : 0;
auto space = buf.prepare(copyable);
if (copyable)
std::memcpy(space.get(), &region.as_u8(offset), copyable);
space.add(copyable);
buf.push();
return sol::make_reference(s, sol::stack_reference(s, -1));
});
region_type.set_function("read_i8", &region_read<s8>);
region_type.set_function("read_u8", &region_read<u8>);
region_type.set_function("read_i16", &region_read<s16>);
Expand Down
64 changes: 61 additions & 3 deletions src/mame/layout/beena.lay
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,68 @@
license:CC0-1.0
-->
<mamelayout version="2">
<view name="Single Screen">
<bounds x="0" y="0" width="704" height="480" />
<element name="leftpage">
<!-- force maximum state -->
<rect state="0"><color alpha="0" /></rect>
<rect state="6"><color alpha="0" /></rect>
</element>
<element name="rightpage">
<!-- force maximum state -->
<rect state="0"><color alpha="0" /></rect>
<rect state="6"><color alpha="0" /></rect>
</element>

<view name="Default View">
<screen index="0">
<bounds left="0" top="0" right="704" bottom="480" />
<bounds x="0" y="0" width="4" height="3" />
</screen>

<element id="leftpage" ref="leftpage">
<bounds x="0" y="3.1" width="2" height="2.8" />
</element>
<element id="rightpage" ref="rightpage">
<bounds x="2" y="3.1" width="2" height="2.8" />
</element>
</view>

<script><![CDATA[
file:set_resolve_tags_callback(
function ()
-- get memory regions for page scans
local pages = { }
for i = 1, 12 do
local page = file.device:memregion(string.format('cartslot:page%u', i))
if page ~= nil then
pages[i] = page
else
break
end
end
-- make page display respond to page selection input
local pagectrl = file.device:ioport('PAGE')
local function get_page() return pagectrl:read() end
file.views['Default View'].items['leftpage']:set_element_state_callback(get_page)
file.views['Default View'].items['rightpage']:set_element_state_callback(get_page)
-- render even pages on the left, odd pages on the right
local function draw_page(n, dest)
local page = pages[n]
if page ~= nil then
-- TODO: reduce temporary memory usage when I/O classes are exposed to Lua
local data = page:read(0, page.size)
local image = emu.bitmap_argb32.load(data)
image:resample(dest)
end
end
file.elements['leftpage']:set_draw_callback(
function (state, bitmap)
draw_page(state * 2, bitmap)
end)
file.elements['rightpage']:set_draw_callback(
function (state, bitmap)
draw_page((state * 2) + 1, bitmap)
end)
end)
]]></script>
</mamelayout>

3 comments on commit 6e60af3

@cuavas
Copy link
Member Author

@cuavas cuavas commented on 6e60af3 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t done yet – I just wanted to get something visible in before I go away for the weekend. I’ll sort out some more stuff later. In particular:

  • I haven’t done the pen position display when the book has focus.
  • Memory shares and address spaces could probably do with block read from Lua as well.

The current book scans aren’t great. The pages aren’t aligned consistently, they have varying amounts of surrounding whitespace, and some of them have the outer tabs cut off. Ideally we’d need to:

  • Re-scan the pages that were cut off.
  • Align and crop the images.
  • Make the empty area around the pages transparent (they aren’t rectangular – they have rounded corners and tabs).
  • Stack the images so the tabs of the pages underneath the topmost page are visible. (This could conceivably be done on-the-fly by the layout script, I guess.)

Tag @qufb as it’s relevant.

@qufb
Copy link
Contributor

@qufb qufb commented on 6e60af3 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cuavas Nice, some other things to consider:

  • This requires starting with -plugin layout or having it enabled in mame.ini, would it make sense to mention that in the driver, or show a warning if it's disabled?
  • For games with less than 6 pages (logical pages, not book pages), we should show the last available book page when advancing beyond the last logical page (for example, if a game has 4 logical pages, loading page 5 or 6 is equivalent to loading page 4, so we should show the last book page, instead of not rendering any book pages).
  • For TV Ocha-ken, will a dedicated layout file and softlist be needed to load artwork? In that case, should the ROM_LOAD in the driver be removed, so that the rom is loaded via softlist as well?

@qufb
Copy link
Contributor

@qufb qufb commented on 6e60af3 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the settings backdrop ends up being very straightforward, pages will get rendered on top:

@@ -14,11 +14,17 @@ license:CC0-1.0
                <rect state="6"><color alpha="0" /></rect>
        </element>
 
+       <element name="settings">
+               <image file="settings.png" />
+       </element>
        <view name="Default View">
                <screen index="0">
                        <bounds x="0" y="0" width="4" height="3" />
                </screen>
 
+               <element ref="settings">
+                       <bounds x="0" y="3.1" width="2" height="2.8" />
+               </element>
                <element id="leftpage" ref="leftpage">
                        <bounds x="0" y="3.1" width="2" height="2.8" />
                </element>

Please sign in to comment.