Skip to content

Commit

Permalink
-merit/mtouchxl.cpp: Added touch-enabled layout.
Browse files Browse the repository at this point in the history
-ui/tapectrl.cpp: Ensure device monitored for media change is up-to-date.

-osd/windows: Changed a pointer to a const reference in an API.
  • Loading branch information
cuavas committed May 8, 2024
1 parent 5b2280f commit e22aae6
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/source/techspecs/layout_script.rst
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ providing what’s needed:
* ``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,
and ``table`` and ``string`` objects for manipulating strings, tables and
other containers.
and ``math``, ``table`` and ``string`` objects for manipulating numbers,r
strings, tables and other containers.
* Standard Lua ``print`` function for text output to the console.


Expand Down
1 change: 1 addition & 0 deletions plugins/layout/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function layout.startplugin()
print_info = emu.print_info,
print_debug = emu.print_debug },
file = file,
math = math,
print = print,
pairs = pairs,
ipairs = ipairs,
Expand Down
14 changes: 8 additions & 6 deletions src/frontend/mame/ui/tapectrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ menu_tape_control::menu_tape_control(mame_ui_manager &mui, render_container &con

if (device)
{
m_notifier = device->add_media_change_notifier(
[this] (device_image_interface::media_change_event ev)
{
// repopulate the menu if an image is mounted or unmounted
reset(reset_options::REMEMBER_POSITION);
});
}
}

Expand All @@ -94,9 +88,17 @@ menu_tape_control::~menu_tape_control()

void menu_tape_control::populate()
{
m_notifier.reset();
m_slider_item_index = -1;
if (current_device())
{
// repopulate the menu if an image is mounted or unmounted
m_notifier = current_device()->add_media_change_notifier(
[this] (device_image_interface::media_change_event ev)
{
reset(reset_options::REMEMBER_POSITION);
});

// name of tape
item_append(current_display_name(), current_device()->exists() ? current_device()->filename() : "No Tape Image loaded", current_display_flags(), TAPECMD_SELECT);

Expand Down
95 changes: 95 additions & 0 deletions src/mame/layout/mtouchxl.lay
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0"?>
<!--
license:CC0-1.0
-->
<mamelayout version="2">
<view name="Touch-Enabled" showpointers="yes">
<screen id="screen" index="0">
<bounds left="0" top="0" right="4" bottom="3" />
</screen>
</view>

<script><![CDATA[
file:set_resolve_tags_callback(
function ()
-- get the touchscreen I/O port fields
local tsdev = file.device:subdevice('microtouch')
local btn_field = tsdev:ioport('TOUCH'):field(0x01)
local x_field = tsdev:ioport('TOUCH_X'):field(0x3fff)
local y_field = tsdev:ioport('TOUCH_Y'):field(0x3fff)
-- for mapping coordinates
local view = file.views['Touch-Enabled']
local scr_item = view.items['screen']
local floor = math.floor
local l, r, t, b
local x_scale, y_scale
-- pointer state
local ptr_id = nil
local inside = false
local function release_touch()
btn_field:clear_value()
x_field:clear_value()
y_field:clear_value()
end
local function recomputed()
local bounds = scr_item.bounds
l = bounds.x0
r = bounds.x1
t = bounds.y0
b = bounds.y1
x_scale = 0x3fff / bounds.width
y_scale = 0x3fff / bounds.height
end
local function check_pointer(x, y)
if (x >= l) and (x < r) and (y >= t) and (y < b) then
inside = true
btn_field:set_value(1)
x_field:set_value(floor((x - l) * x_scale))
y_field:set_value(floor((y - t) * y_scale))
elseif inside then
inside = false
release_touch()
end
end
local function forget_pointer()
if inside then
release_touch()
end
ptr_id = nil
inside = false
end
local function pointer_updated(type, id, dev, x, y, btn, dn, up, cnt)
if ptr_id == id then
if (btn & 0x01) == 0 then
forget_pointer()
else
check_pointer(x, y)
end
elseif (not ptr_id) and ((dn & 0x01) ~= 0) then
ptr_id = id
check_pointer(x, y)
end
end
local function pointer_lost(type, id, dev, x, y, up, cnt)
if ptr_id == id then
forget_pointer()
end
end
-- attach callbacks to view
view:set_recomputed_callback(recomputed)
view:set_pointer_updated_callback(pointer_updated)
view:set_pointer_left_callback(pointer_lost)
view:set_pointer_aborted_callback(pointer_lost)
view:set_forget_pointers_callback(forget_pointer)
end)
]]></script>
</mamelayout>
22 changes: 15 additions & 7 deletions src/mame/merit/mtouchxl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@
//#define REAL_PCI_CHIPSET

#include "emu.h"

#include "bus/ata/atapicdr.h"
#include "bus/ata/hdd.h"
#include "bus/isa/isa_cards.h"
#include "cpu/i386/i386.h"
#include "machine/at.h"
#include "machine/ram.h"
#include "machine/8042kbdc.h"
#include "machine/nvram.h"
#include "machine/ins8250.h"
#include "machine/microtch.h"
#include "machine/at.h"
#include "machine/bankdev.h"
#include "machine/intelfsh.h"
#include "machine/ds128x.h"
#include "machine/ds1205.h"
#include "machine/ds128x.h"
#include "machine/ins8250.h"
#include "machine/intelfsh.h"
#include "machine/microtch.h"
#include "machine/nvram.h"
#include "machine/ram.h"
#ifdef REAL_PCI_CHIPSET
#include "machine/sis85c496.h"
#endif
#include "sound/ad1848.h"

#include "speaker.h"

#include "mtouchxl.lh"


namespace {

Expand Down Expand Up @@ -287,6 +291,8 @@ void mtxl_state::at486(machine_config &config)
// FIXME: This MCFG fragment does not compile. -R
//MCFG_SIS85C496_ADD(":pci:05.0", ":maincpu", 32*1024*1024)
#endif

config.set_default_layout(layout_mtouchxl);
}

void mtxl_state::at486hd(machine_config &config)
Expand Down Expand Up @@ -346,6 +352,8 @@ void mtxl_state::at486hd(machine_config &config)
// FIXME: This MCFG fragment does not compile. -R
//MCFG_SIS85C496_ADD(":pci:05.0", ":maincpu", 32*1024*1024)
#endif

config.set_default_layout(layout_mtouchxl);
}

#ifdef REAL_PCI_CHIPSET
Expand Down
2 changes: 1 addition & 1 deletion src/osd/modules/debugger/debugwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void debugger_windows::wait_for_debugger(device_t &device, bool firststop)

// process everything else
default:
winwindow_dispatch_message(*m_machine, &message);
winwindow_dispatch_message(*m_machine, message);
break;
}

Expand Down
18 changes: 9 additions & 9 deletions src/osd/windows/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void windows_osd_interface::process_events(bool ingame, bool nodispatch)

// dispatch if necessary
if (dispatch)
winwindow_dispatch_message(machine(), &message);
winwindow_dispatch_message(machine(), message);
}
}
while (ui_temp_pause > 0);
Expand All @@ -480,12 +480,12 @@ void windows_osd_interface::process_events(bool ingame, bool nodispatch)
// (main thread)
//============================================================

void winwindow_dispatch_message(running_machine &machine, MSG *message)
void winwindow_dispatch_message(running_machine &machine, MSG const &message)
{
assert(GetCurrentThreadId() == main_threadid);

// dispatch our special communication messages
switch (message->message)
switch (message.message)
{
// special case for quit
case WM_QUIT:
Expand All @@ -494,8 +494,8 @@ void winwindow_dispatch_message(running_machine &machine, MSG *message)

// everything else dispatches normally
default:
TranslateMessage(message);
DispatchMessage(message);
TranslateMessage(&message);
DispatchMessage(&message);
break;
}
}
Expand Down Expand Up @@ -2293,17 +2293,17 @@ std::vector<win_window_info::win_pointer_info>::iterator win_window_info::find_m

bool winwindow_qt_filter(void *message)
{
MSG *msg = (MSG *)message;
MSG *const msg = reinterpret_cast<MSG *>(message);

if(is_mame_window(msg->hwnd) || (!msg->hwnd && (msg->message >= WM_USER)))
if (is_mame_window(msg->hwnd) || (!msg->hwnd && (msg->message >= WM_USER)))
{
LONG_PTR ptr;
if(msg->hwnd) // get the machine associated with this window
if (msg->hwnd) // get the machine associated with this window
ptr = GetWindowLongPtr(msg->hwnd, GWLP_USERDATA);
else // any one will have to do
ptr = (LONG_PTR)osd_common_t::window_list().front().get();

winwindow_dispatch_message(((win_window_info *)ptr)->machine(), msg);
winwindow_dispatch_message(reinterpret_cast<win_window_info *>(ptr)->machine(), *msg);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/osd/windows/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void winwindow_toggle_fsfx(void);
void winwindow_ui_pause(running_machine &machine, int pause);
int winwindow_ui_is_paused(running_machine &machine);

void winwindow_dispatch_message(running_machine &machine, MSG *message);
void winwindow_dispatch_message(running_machine &machine, MSG const &message);



Expand Down

1 comment on commit e22aae6

@cuavas
Copy link
Member Author

@cuavas cuavas commented on e22aae6 May 8, 2024

Choose a reason for hiding this comment

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

This lets you just click/touch the screen in Megatouch XL games, and it will be converted to the units the fake “lightgun” uses automatically, without needing -mouse or -lightgun. I successfully played a game of Photo Hunt purely for QA purposes.

Please sign in to comment.