trunk/src/emu/luaengine.c
| r242558 | r242559 | |
| 8 | 8 | |
| 9 | 9 | ***************************************************************************/ |
| 10 | 10 | |
| 11 | #include <limits> |
| 11 | 12 | #include "lua/lua.hpp" |
| 12 | 13 | #include "lua/lib/lualibs.h" |
| 13 | 14 | #include "lua/bridge/LuaBridge.h" |
| r242558 | r242559 | |
| 335 | 336 | return 0; |
| 336 | 337 | } |
| 337 | 338 | |
| 339 | //------------------------------------------------- |
| 340 | // machine_get_devices - return table of available devices userdata |
| 341 | // -> manager:machine().devices[":maincpu"] |
| 342 | //------------------------------------------------- |
| 338 | 343 | |
| 344 | luabridge::LuaRef lua_engine::l_machine_get_devices(const running_machine *r) |
| 345 | { |
| 346 | running_machine *m = const_cast<running_machine *>(r); |
| 347 | lua_State *L = luaThis->m_lua_state; |
| 348 | luabridge::LuaRef devs_table = luabridge::LuaRef::newTable(L); |
| 349 | |
| 350 | device_t *root = &(m->root_device()); |
| 351 | devs_table = devtree_dfs(root, devs_table); |
| 352 | |
| 353 | return devs_table; |
| 354 | } |
| 355 | |
| 356 | // private helper for get_devices - DFS visit all devices in a running machine |
| 357 | luabridge::LuaRef lua_engine::devtree_dfs(device_t *root, luabridge::LuaRef devs_table) |
| 358 | { |
| 359 | if (root) { |
| 360 | for (device_t *dev = root->first_subdevice(); dev != NULL; dev = dev->next()) { |
| 361 | if (dev && dev->configured() && dev->started()) { |
| 362 | devs_table[dev->tag()] = dev; |
| 363 | devtree_dfs(dev, devs_table); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | return devs_table; |
| 368 | } |
| 369 | |
| 370 | //------------------------------------------------- |
| 371 | // device_get_memspaces - return table of available address spaces userdata |
| 372 | // -> manager:machine().devices[":maincpu"].spaces["program"] |
| 373 | //------------------------------------------------- |
| 374 | |
| 375 | luabridge::LuaRef lua_engine::l_dev_get_memspaces(const device_t *d) |
| 376 | { |
| 377 | device_t *dev = const_cast<device_t *>(d); |
| 378 | lua_State *L = luaThis->m_lua_state; |
| 379 | luabridge::LuaRef sp_table = luabridge::LuaRef::newTable(L); |
| 380 | |
| 381 | for (address_spacenum sp = AS_0; sp < ADDRESS_SPACES; sp++) { |
| 382 | if (dev->memory().has_space(sp)) { |
| 383 | sp_table[dev->memory().space(sp).name()] = &(dev->memory().space(sp)); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | return sp_table; |
| 388 | } |
| 389 | |
| 390 | //------------------------------------------------- |
| 391 | // mem_read - templated memory readers for <sign>,<size> |
| 392 | // -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000) |
| 393 | //------------------------------------------------- |
| 394 | |
| 395 | template <typename T> |
| 396 | int lua_engine::lua_addr_space::l_mem_read(lua_State *L) |
| 397 | { |
| 398 | address_space &sp = luabridge::Stack<address_space &>::get(L, 1); |
| 399 | luaL_argcheck(L, lua_isnumber(L, 2), 2, "address (integer) expected"); |
| 400 | offs_t address = lua_tounsigned(L, 2); |
| 401 | T mem_content = 0; |
| 402 | switch(sizeof(mem_content) * 8) { |
| 403 | case 8: |
| 404 | mem_content = sp.read_byte(address); |
| 405 | break; |
| 406 | case 16: |
| 407 | if ((address & 1) == 0) { |
| 408 | mem_content = sp.read_word(address); |
| 409 | } else { |
| 410 | mem_content = sp.read_word_unaligned(address); |
| 411 | } |
| 412 | break; |
| 413 | case 32: |
| 414 | if ((address & 3) == 0) { |
| 415 | mem_content = sp.read_dword(address); |
| 416 | } else { |
| 417 | mem_content = sp.read_dword_unaligned(address); |
| 418 | } |
| 419 | break; |
| 420 | case 64: |
| 421 | if ((address & 7) == 0) { |
| 422 | mem_content = sp.read_qword(address); |
| 423 | } else { |
| 424 | mem_content = sp.read_qword_unaligned(address); |
| 425 | } |
| 426 | break; |
| 427 | default: |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | if (std::numeric_limits<T>::is_signed) { |
| 432 | lua_pushinteger(L, mem_content); |
| 433 | } else { |
| 434 | lua_pushunsigned(L, mem_content); |
| 435 | } |
| 436 | |
| 437 | return 1; |
| 438 | |
| 439 | } |
| 440 | |
| 339 | 441 | void *lua_engine::checkparam(lua_State *L, int idx, const char *tname) |
| 340 | 442 | { |
| 341 | 443 | const char *name; |
| r242558 | r242559 | |
| 564 | 666 | .addFunction ("hard_reset", &running_machine::schedule_hard_reset) |
| 565 | 667 | .addFunction ("soft_reset", &running_machine::schedule_soft_reset) |
| 566 | 668 | .addFunction ("system", &running_machine::system) |
| 669 | .addProperty <luabridge::LuaRef, void> ("devices", &lua_engine::l_machine_get_devices) |
| 567 | 670 | .endClass () |
| 568 | 671 | .beginClass <game_driver> ("game_driver") |
| 569 | 672 | .addData ("name", &game_driver::name) |
| r242558 | r242559 | |
| 571 | 674 | .addData ("year", &game_driver::year) |
| 572 | 675 | .addData ("manufacturer", &game_driver::manufacturer) |
| 573 | 676 | .endClass () |
| 677 | .beginClass <device_t> ("device") |
| 678 | .addFunction("name", &device_t::tag) |
| 679 | .addProperty <luabridge::LuaRef, void> ("spaces", &lua_engine::l_dev_get_memspaces) |
| 680 | .endClass() |
| 681 | .beginClass <lua_addr_space> ("lua_addr_space") |
| 682 | .addCFunction ("read_i8", &lua_addr_space::l_mem_read<INT8>) |
| 683 | .addCFunction ("read_u8", &lua_addr_space::l_mem_read<UINT8>) |
| 684 | .addCFunction ("read_i16", &lua_addr_space::l_mem_read<INT16>) |
| 685 | .addCFunction ("read_u16", &lua_addr_space::l_mem_read<UINT16>) |
| 686 | .addCFunction ("read_i32", &lua_addr_space::l_mem_read<INT32>) |
| 687 | .addCFunction ("read_u32", &lua_addr_space::l_mem_read<UINT32>) |
| 688 | .addCFunction ("read_i64", &lua_addr_space::l_mem_read<INT64>) |
| 689 | .addCFunction ("read_u64", &lua_addr_space::l_mem_read<UINT64>) |
| 690 | .endClass() |
| 691 | .deriveClass <address_space, lua_addr_space> ("addr_space") |
| 692 | .addFunction("name", &address_space::name) |
| 693 | .endClass() |
| 574 | 694 | .endNamespace (); |
| 575 | 695 | |
| 576 | 696 | luabridge::push (m_lua_state, machine_manager::instance()); |
trunk/src/mame/drivers/cps1.c
| r242558 | r242559 | |
| 11518 | 11518 | m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xff0000, 0xffffff, read16_delegate(FUNC(cps_state::ganbare_ram_r),this), write16_delegate(FUNC(cps_state::ganbare_ram_w),this)); |
| 11519 | 11519 | } |
| 11520 | 11520 | |
| 11521 | | READ16_MEMBER(cps_state::dinohunt_sound_r) |
| 11522 | | { |
| 11523 | | /*TODO: understand what's really going on here. According to MT05805; |
| 11524 | | "I think that the values written are only qsound leftovers (after a lot of 0xFF values, |
| 11525 | | there is the same qsound starting sequence, eg: 0x88, 0xFF, 0x0B, 0x00, 0x00, 0x00, ...)."*/ |
| 11526 | | return 0xff; |
| 11527 | | } |
| 11528 | | |
| 11529 | 11521 | DRIVER_INIT_MEMBER(cps_state,dinohunt) |
| 11530 | 11522 | { |
| 11531 | 11523 | // is this shared with the new sound hw? |
| 11532 | | m_maincpu->space(AS_PROGRAM).install_read_handler(0xf18000, 0xf19fff, read16_delegate(FUNC(cps_state::dinohunt_sound_r), this)); |
| 11533 | | m_maincpu->space(AS_PROGRAM).install_read_port(0xfc0000, 0xfc0001, "IN2"); ; |
| 11534 | | // the ym2151 doesn't seem to be used. Is it actually on the PCB? |
| 11535 | | |
| 11524 | UINT8* ram = (UINT8*)m_maincpu->space(AS_PROGRAM).install_ram(0xf18000, 0xf19fff); |
| 11525 | memset(ram,0xff,0x2000); |
| 11526 | m_maincpu->space(AS_PROGRAM).install_read_handler(0xfc0000, 0xfc0001, read16_delegate(FUNC(cps_state::cps1_in2_r), this)); |
| 11536 | 11527 | DRIVER_INIT_CALL(cps1); |
| 11537 | 11528 | } |
| 11538 | 11529 | |