Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mahlemiut committed Mar 25, 2015
2 parents 5592347 + 0147bb4 commit 7ff73c1
Show file tree
Hide file tree
Showing 245 changed files with 3,212 additions and 1,682 deletions.
154 changes: 154 additions & 0 deletions docs/luaengine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Scripting MAME via LUA

## Introduction

It is now possible to externally drive MAME via LUA scripts.
This feature initially appeared in version 0.148, when a minimal `luaengine`
was implemented. Nowadays, the LUA interface is rich enough
to let you inspect and manipulate devices state, access CPU
registers, read and write memory, and draw a custom HUD on screen.

Internally, MAME makes extensive use of `luabridge` to implement
this feature: the idea is to transparently expose as many of
the useful internals as possible.

Finally, a warning: LUA API is not yet declared stable and may
suddenly change without prior notice.
However, we expose methods to let you know at runtime which API
version you are running against, and you can introspect most of the
objects at runtime.

## Features

The API is not yet complete, but this is a partial list of capabilities
currently available to LUA scripts:

* machine metadata (app version, current rom, rom details)
* machine control (starting, pausing, resetting, stopping)
* machine hooks (on frame painting and on user events)
* devices introspection (device tree listing, memory and register enumeration)
* screens introspection (screens listing, screen details, frames counting)
* screen HUD drawing (text, lines, boxes on multiple screens)
* memory read/write (8/16/32/64 bits, signed and unsigned)
* registers and states control (states enumeration, get and set)

## Usage

MAME supports external scripting via LUA (>= 5.3) scripts, either
written on the interactive console or loaded as a file.
To reach the console, just run MAME with `-console`; you will be
greeted by a naked `>` prompt where you can input your script.

To load a whole script at once, store it in a plaintext file and
pass it via the `-autoboot_script`. Please note that script
loading may be delayed (few seconds by default), but you can
override the default with the `-autoboot_delay` argument.

To control the execution of your code, you can use a loop-based or
an event-based approach. The former is not encouraged as it is
resource-intensive and makes control flow unnecessarily complex.
Instead, we suggest to register custom hooks to be invoked on specific
events (eg. at each frame rendering).

## Walktrough

Let's first run MAME in a terminal to reach the LUA console:
```
$ mame -console YOUR_ROM
M.A.M.E. v0.158 (Feb 5 2015) - Multiple Arcade Machine Emulator
Copyright Nicola Salmoria and the MAME team
Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
>
```

At this point, your game is probably running in demo mode, let's pause it:
```
> emu.pause()
>
```
Even without textual feedback on the console, you'll notice the game is now paused.
In general, commands are quiet and only print back error messages.

You can check at runtime which version of MAME you are running, with:
```
> print(emu.app_name() .. " " .. emu.app_version())
mame 0.158
```

We now start exploring screen related methods. First, let's enumerate available screens:
```
> for i,v in pairs(manager:machine().screens) do print(i) end
:screen
```

`manager:machine()` is the root object of your currently running machine:
we will be using this often. `screens` is a table with all available screens;
most machines only have one main screen.
In our case, the main and only screen is tagged as `:screen`, and we can further
inspect it:
```
> -- let's define a shorthand for the main screen
> s = manager:machine().screens[":screen"]
> print(s:width() .. "x" .. s:height())
320x224
```

We have several methods to draw on the screen a HUD composed of lines, boxes and text:
```
> -- we define a HUD-drawing function, and then call it
> function draw_hud()
>> s:draw_text(40, 40, "foo"); -- (x0, y0, msg)
>> s:draw_box(20, 20, 80, 80, 0, 0xff00ffff); -- (x0, y0, x1, y1, fill-color, line-color)
>> s:draw_line(20, 20, 80, 80, 0xff00ffff); -- (x0, y0, x1, y1, line-color)
>> end
> draw_hud();
```

This will draw some useless art on the screen. However, when unpausing the game, your HUD
needs to be refreshed otherwise it will just disappear. In order to do this, you have to register
your hook to be called on every frame repaint:
```
> emu.sethook(draw_hud, "frame")
```

Similarly to screens, you can inspect all the devices attached to a
machine:
```
> for k,v in pairs(manager:machine().devices) do print(k) end
:audiocpu
:maincpu
:saveram
:screen
:palette
[...]
```

On some of them, you can also inspect and manipulate memory and state:
```
> cpu = manager:machine().devices[":maincpu"]
> -- enumerate, read and write state registers
> for k,v in pairs(cpu.state) do print(k) end
D5
SP
A4
A3
D0
PC
[...]
> print(cpu.state["D0"].value)
303
> cpu.state["D0"].value = 255
> print(cpu.state["D0"].value)
255
```

```
> -- inspect memory
> for k,v in pairs(cpu.spaces) do print(k) end
program
> mem = cpu.spaces["program"]
> print(mem:read_i8(0xC000))
41
```

11 changes: 11 additions & 0 deletions hash/gba.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12294,6 +12294,17 @@ Note: In the AGB-E05-XX and AGB-E06-XX pcbs, the chip name is hidden under the b
</part>
</software>

<software name="dune">
<description>Frank Herbert's Dune - Ornithopter Assault (Prototype)</description>
<year>200?</year>
<publisher>Cryo</publisher>
<part name="cart" interface="gba_cart">
<dataarea name="rom" size="4194304">
<rom name="dune-ornithopter-assault-gba-cancelled.bin" size="4194304" crc="298d627b" sha1="1d317fb050f6d5b850f4b88b72f3420cb175edf3" offset="000000" />
</dataarea>
</part>
</software>

<software name="eyebehol">
<description>Dungeons &amp; Dragons - Eye of the Beholder (Euro)</description>
<year>2002</year>
Expand Down
4 changes: 2 additions & 2 deletions hash/nes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57391,7 +57391,7 @@ preliminary proto for the PAL version, still running on NTSC systems) or the gfx
<publisher>Union Bond</publisher>
<info name="serial" value="G-0005"/>
<part name="cart" interface="nes_cart">
<feature name="slot" value="nanjing" /> <!-- header actually says 164... -->
<feature name="slot" value="nanjing" /> <!-- header actually says 164... -->
<feature name="pcb" value="UNL-NANJING" />
<dataarea name="prg" size="524288">
<rom name="ying tao xiao wan zi (g-005) (ch).prg" size="524288" crc="8209ba79" sha1="fa56608d8dcf5a144dd1fc81282cd86fd51060fe" offset="00000" status="baddump" />
Expand Down Expand Up @@ -75420,7 +75420,7 @@ be better to redump them properly. -->
<year>19??</year>
<publisher>&lt;unknown&gt;</publisher>
<part name="cart" interface="nes_cart">
<feature name="slot" value="fk23ca" /> <!-- UNIF header pointed to FK23C, but the menu does not appear with that mapper... investigate! -->
<feature name="slot" value="fk23ca" /> <!-- UNIF header pointed to FK23C, but the menu does not appear with that mapper... investigate! -->
<feature name="pcb" value="BMC-FK23C" />
<dataarea name="prg" size="8388608">
<rom name="120-in-1 (unl)[u].prg" size="8388608" crc="678de5aa" sha1="01da22ddf1897b47d6b03ecb4ff0c093f9b39dfc" offset="00000" status="baddump" />
Expand Down
2 changes: 1 addition & 1 deletion hash/pasogo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
歴代棋聖戦名曲集 (Rekidai Kisei Sen Meikyokushuu)
棋界覇王伝・古典編 (Kikai Haoh Den - Koten-hen)
棋界覇王伝・現代編 (Kikai Haoh Den - Gendai-hen)
The undumped cart numbers are KS-1005, KS-1006, KS-1007 and KS-1008
For the remaining undumped games, the game to cart number match is unknown.
-->
Expand Down
2 changes: 1 addition & 1 deletion hash/pc8801_flop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9666,7 +9666,7 @@ ExtractDisk [08]"下巻 ユーザー " -> "aaa_08.d88"
<info name="alt_title" value="ドアドア mk2"/>
<part name="flop1" interface="floppy_5_25">
<dataarea name="flop" size="348624">
<rom name="door door mkii.d88" size="348624" crc="50c65512" sha1="247a29b6f40fe90851c569f50660b877cca8258f" offset="0" />
<rom name="door door mkii (alt).d88" size="348624" crc="50c65512" sha1="247a29b6f40fe90851c569f50660b877cca8258f" offset="0" />
</dataarea>
</part>
</software>
Expand Down
12 changes: 12 additions & 0 deletions hash/pet_rom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
</part>
</software>

<software name="mcterm095" cloneof="mcterm">
<description>McTerm 0.95</description>
<year>1980</year>
<publisher>Madison Computer</publisher>

<part name="rom" interface="pet_9000_rom">
<dataarea name="rom" size="0x800">
<rom name="mcterm095-9000.bin" size="0x800" crc="4ef176ea" sha1="b7e66e229a077067b7b88bb2f740ed8be4ca5658" offset="0" />
</dataarea>
</part>
</software>

<software name="mcterm120" cloneof="mcterm">
<description>McTerm 1.20</description>
<year>1981</year>
Expand Down
3 changes: 3 additions & 0 deletions src/build/flags_clang.mak
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ CCOMFLAGS += \
-Wno-cast-align \
-Wno-tautological-compare

# caused by dynamic_array being generally awful
CCOMFLAGS += -Wno-dynamic-class-memaccess

# caused by obj/sdl64d/emu/cpu/tms57002/tms57002.inc
CCOMFLAGS += -Wno-self-assign-field

Expand Down
5 changes: 2 additions & 3 deletions src/emu/bus/a2bus/ezcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MACHINE_CONFIG_END
#define MSX2_VISIBLE_YBORDER_PIXELS 14 * 2

MACHINE_CONFIG_FRAGMENT( ezcgi9938 )
MCFG_V9938_ADD(TMS_TAG, SCREEN_TAG, 0x30000) // 192K of VRAM
MCFG_V9938_ADD(TMS_TAG, SCREEN_TAG, 0x30000) // 192K of VRAM
MCFG_V99X8_INTERRUPT_CALLBACK(WRITELINE(a2bus_ezcgi_9938_device, tms_irq_w))

MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
Expand All @@ -57,7 +57,7 @@ MACHINE_CONFIG_FRAGMENT( ezcgi9938 )
MACHINE_CONFIG_END

MACHINE_CONFIG_FRAGMENT( ezcgi9958 )
MCFG_V9958_ADD(TMS_TAG, SCREEN_TAG, 0x30000) // 192K of VRAM
MCFG_V9958_ADD(TMS_TAG, SCREEN_TAG, 0x30000) // 192K of VRAM
MCFG_V99X8_INTERRUPT_CALLBACK(WRITELINE(a2bus_ezcgi_9958_device, tms_irq_w))

MCFG_SCREEN_ADD(SCREEN_TAG, RASTER)
Expand Down Expand Up @@ -311,4 +311,3 @@ WRITE_LINE_MEMBER( a2bus_ezcgi_9958_device::tms_irq_w )
lower_slot_irq();
}
}

4 changes: 2 additions & 2 deletions src/emu/bus/scsi/omti5100.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const rom_entry *omti5100_device::device_rom_region() const

omti5100_device::omti5100_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: scsihd_device(mconfig, OMTI5100, "OMTI 5100", tag, owner, clock, "omti5100", __FILE__),
m_image0(*this, "image0"),
m_image1(*this, "image1")
m_image0(*this, "image0"),
m_image1(*this, "image1")
{
}

Expand Down
Loading

0 comments on commit 7ff73c1

Please sign in to comment.