mirror of
https://github.com/holub/mame
synced 2025-06-04 11:56:28 +03:00
Refactoring and cleanup of tapectrl.? and bbcontrl.?, created base class
This commit is contained in:
parent
77044d754f
commit
cd9479b751
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2506,6 +2506,7 @@ src/emu/ui.c svneol=native#text/plain
|
||||
src/emu/ui.h svneol=native#text/plain
|
||||
src/emu/ui/bbcontrl.c svneol=native#text/plain
|
||||
src/emu/ui/bbcontrl.h svneol=native#text/plain
|
||||
src/emu/ui/devctrl.h svneol=native#text/plain
|
||||
src/emu/ui/filemngr.c svneol=native#text/plain
|
||||
src/emu/ui/filemngr.h svneol=native#text/plain
|
||||
src/emu/ui/filesel.c svneol=native#text/plain
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "emu.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/bbcontrl.h"
|
||||
#include "imagedev/bitbngr.h"
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
@ -33,7 +32,8 @@
|
||||
// ctor
|
||||
//-------------------------------------------------
|
||||
|
||||
ui_menu_mess_bitbanger_control::ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container) : ui_menu(machine, container)
|
||||
ui_menu_mess_bitbanger_control::ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container, bitbanger_device *device)
|
||||
: ui_menu_device_control<bitbanger_device>(machine, container, device)
|
||||
{
|
||||
}
|
||||
|
||||
@ -47,67 +47,54 @@ ui_menu_mess_bitbanger_control::~ui_menu_mess_bitbanger_control()
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// bitbanger_count - returns the number of bitbanger
|
||||
// devices in the machine
|
||||
//-------------------------------------------------
|
||||
|
||||
int ui_menu_mess_bitbanger_control::bitbanger_count()
|
||||
{
|
||||
bitbanger_device_iterator iter(machine().root_device());
|
||||
return iter.count();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// populate - populates the main bitbanger control menu
|
||||
//-------------------------------------------------
|
||||
|
||||
void ui_menu_mess_bitbanger_control::populate()
|
||||
{
|
||||
int count = bitbanger_count();
|
||||
UINT32 flags = 0, mode_flags = 0, baud_flags = 0, tune_flags = 0;
|
||||
|
||||
if( count > 0 )
|
||||
if( count() > 0 )
|
||||
{
|
||||
if( index == (count-1) )
|
||||
int index = current_index();
|
||||
|
||||
if( index == (count()-1) )
|
||||
flags |= MENU_FLAG_LEFT_ARROW;
|
||||
else
|
||||
flags |= MENU_FLAG_RIGHT_ARROW;
|
||||
}
|
||||
|
||||
if ((device != NULL) && (device->exists()))
|
||||
if ((current_device() != NULL) && (current_device()->exists()))
|
||||
{
|
||||
bitbanger_device *bitbanger = downcast<bitbanger_device *>(&device->device());
|
||||
|
||||
if (bitbanger->inc_mode(TRUE))
|
||||
if (current_device()->inc_mode(TRUE))
|
||||
mode_flags |= MENU_FLAG_RIGHT_ARROW;
|
||||
|
||||
if (bitbanger->dec_mode(TRUE))
|
||||
if (current_device()->dec_mode(TRUE))
|
||||
mode_flags |= MENU_FLAG_LEFT_ARROW;
|
||||
|
||||
if (bitbanger->inc_baud(TRUE))
|
||||
if (current_device()->inc_baud(TRUE))
|
||||
baud_flags |= MENU_FLAG_RIGHT_ARROW;
|
||||
|
||||
if (bitbanger->dec_baud(TRUE))
|
||||
if (current_device()->dec_baud(TRUE))
|
||||
baud_flags |= MENU_FLAG_LEFT_ARROW;
|
||||
|
||||
if (bitbanger->inc_tune(TRUE))
|
||||
if (current_device()->inc_tune(TRUE))
|
||||
tune_flags |= MENU_FLAG_RIGHT_ARROW;
|
||||
|
||||
if (bitbanger->dec_tune(TRUE))
|
||||
if (current_device()->dec_tune(TRUE))
|
||||
tune_flags |= MENU_FLAG_LEFT_ARROW;
|
||||
|
||||
// name of bitbanger file
|
||||
item_append(device->device().name(), device->filename(), flags, BITBANGERCMD_SELECT);
|
||||
item_append("Device Mode:", bitbanger->mode_string(), mode_flags, BITBANGERCMD_MODE);
|
||||
item_append("Baud:", bitbanger->baud_string(), baud_flags, BITBANGERCMD_BAUD);
|
||||
item_append("Baud Tune:", bitbanger->tune_string(), tune_flags, BITBANGERCMD_TUNE);
|
||||
item_append(current_device()->device().name(), current_device()->filename(), flags, BITBANGERCMD_SELECT);
|
||||
item_append("Device Mode:", current_device()->mode_string(), mode_flags, BITBANGERCMD_MODE);
|
||||
item_append("Baud:", current_device()->baud_string(), baud_flags, BITBANGERCMD_BAUD);
|
||||
item_append("Baud Tune:", current_device()->tune_string(), tune_flags, BITBANGERCMD_TUNE);
|
||||
item_append("Protocol:", "8-1-N", 0, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no tape loaded
|
||||
// no bitbanger loaded
|
||||
item_append("No Bitbanger Image loaded", NULL, flags, NULL);
|
||||
}
|
||||
}
|
||||
@ -119,17 +106,6 @@ void ui_menu_mess_bitbanger_control::populate()
|
||||
|
||||
void ui_menu_mess_bitbanger_control::handle()
|
||||
{
|
||||
// do we have to load the device?
|
||||
if (device == NULL)
|
||||
{
|
||||
bitbanger_device_iterator iter(machine().root_device());
|
||||
device = iter.byindex(index);
|
||||
reset((ui_menu_reset_options)0);
|
||||
}
|
||||
|
||||
// get the bitbanger
|
||||
bitbanger_device *bitbanger = downcast<bitbanger_device *>(device);
|
||||
|
||||
// rebuild the menu
|
||||
reset(UI_MENU_RESET_REMEMBER_POSITION);
|
||||
populate();
|
||||
@ -142,52 +118,25 @@ void ui_menu_mess_bitbanger_control::handle()
|
||||
{
|
||||
case IPT_UI_LEFT:
|
||||
if (event->itemref==BITBANGERCMD_SELECT)
|
||||
{
|
||||
// left arrow - rotate left through cassette devices
|
||||
if (index > 0)
|
||||
index--;
|
||||
else
|
||||
index = bitbanger_count() - 1;
|
||||
device = NULL;
|
||||
}
|
||||
previous();
|
||||
else if (event->itemref==BITBANGERCMD_MODE)
|
||||
{
|
||||
bitbanger->dec_mode(FALSE);
|
||||
}
|
||||
current_device()->dec_mode(false);
|
||||
else if (event->itemref==BITBANGERCMD_BAUD)
|
||||
{
|
||||
bitbanger->dec_baud(FALSE);
|
||||
}
|
||||
current_device()->dec_baud(false);
|
||||
else if (event->itemref==BITBANGERCMD_TUNE)
|
||||
{
|
||||
bitbanger->dec_tune(FALSE);
|
||||
}
|
||||
current_device()->dec_tune(false);
|
||||
break;
|
||||
|
||||
case IPT_UI_RIGHT:
|
||||
if (event->itemref==BITBANGERCMD_SELECT)
|
||||
{
|
||||
// right arrow - rotate right through cassette devices
|
||||
if (index < bitbanger_count() - 1)
|
||||
index++;
|
||||
else
|
||||
index = 0;
|
||||
device = NULL;
|
||||
}
|
||||
next();
|
||||
else if (event->itemref==BITBANGERCMD_MODE)
|
||||
{
|
||||
bitbanger->inc_mode(FALSE);
|
||||
}
|
||||
current_device()->inc_mode(false);
|
||||
else if (event->itemref==BITBANGERCMD_BAUD)
|
||||
{
|
||||
bitbanger->inc_baud(FALSE);
|
||||
}
|
||||
current_device()->inc_baud(false);
|
||||
else if (event->itemref==BITBANGERCMD_TUNE)
|
||||
{
|
||||
bitbanger->inc_tune(FALSE);
|
||||
}
|
||||
current_device()->inc_tune(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,17 +14,15 @@
|
||||
#ifndef __UI_BBCONTRL_H__
|
||||
#define __UI_BBCONTRL_H__
|
||||
|
||||
class ui_menu_mess_bitbanger_control : public ui_menu {
|
||||
#include "imagedev/bitbngr.h"
|
||||
#include "ui/devctrl.h"
|
||||
|
||||
class ui_menu_mess_bitbanger_control : public ui_menu_device_control<bitbanger_device> {
|
||||
public:
|
||||
ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container);
|
||||
ui_menu_mess_bitbanger_control(running_machine &machine, render_container *container, bitbanger_device *bitbanger);
|
||||
virtual ~ui_menu_mess_bitbanger_control();
|
||||
virtual void populate();
|
||||
virtual void handle();
|
||||
|
||||
private:
|
||||
int index;
|
||||
device_image_interface *device;
|
||||
int bitbanger_count();
|
||||
};
|
||||
|
||||
#endif // __UI_BBCONTRL_H__
|
||||
|
107
src/emu/ui/devctrl.h
Normal file
107
src/emu/ui/devctrl.h
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
|
||||
ui/devctrl.h
|
||||
|
||||
Device specific control (base class for tapectrl and bbcontrl)
|
||||
|
||||
Copyright Nicola Salmoria and the MAME Team.
|
||||
Visit http://mamedev.org for licensing and usage restrictions.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __UI_DEVCTRL_H__
|
||||
#define __UI_DEVCTRL_H__
|
||||
|
||||
template<class _DeviceType>
|
||||
class ui_menu_device_control : public ui_menu
|
||||
{
|
||||
public:
|
||||
ui_menu_device_control(running_machine &machine, render_container *container, _DeviceType *device);
|
||||
|
||||
protected:
|
||||
_DeviceType *current_device() { return m_device; }
|
||||
int count() { return m_count; }
|
||||
|
||||
int current_index();
|
||||
void previous();
|
||||
void next();
|
||||
|
||||
private:
|
||||
// device iterator
|
||||
typedef device_type_iterator<&device_creator<_DeviceType>, _DeviceType> device_iterator;
|
||||
|
||||
_DeviceType * m_device;
|
||||
int m_count;
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// ctor
|
||||
//-------------------------------------------------
|
||||
|
||||
template<class _DeviceType>
|
||||
ui_menu_device_control<_DeviceType>::ui_menu_device_control(running_machine &machine, render_container *container, _DeviceType *device)
|
||||
: ui_menu(machine, container)
|
||||
{
|
||||
device_iterator iter(machine.root_device());
|
||||
m_device = device ? device : iter.first();
|
||||
m_count = iter.count();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// current_index
|
||||
//-------------------------------------------------
|
||||
|
||||
template<class _DeviceType>
|
||||
int ui_menu_device_control<_DeviceType>::current_index()
|
||||
{
|
||||
device_iterator iter(machine().root_device());
|
||||
return iter.indexof(*m_device);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// previous
|
||||
//-------------------------------------------------
|
||||
|
||||
template<class _DeviceType>
|
||||
void ui_menu_device_control<_DeviceType>::previous()
|
||||
{
|
||||
// left arrow - rotate left through cassette devices
|
||||
if (m_device != NULL)
|
||||
{
|
||||
device_iterator iter(machine().root_device());
|
||||
int index = iter.indexof(*m_device);
|
||||
if (index > 0)
|
||||
index--;
|
||||
else
|
||||
index = m_count - 1;
|
||||
m_device = iter.byindex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// next
|
||||
//-------------------------------------------------
|
||||
|
||||
template<class _DeviceType>
|
||||
void ui_menu_device_control<_DeviceType>::next()
|
||||
{
|
||||
// right arrow - rotate right through cassette devices
|
||||
if (m_device != NULL)
|
||||
{
|
||||
device_iterator iter(machine().root_device());
|
||||
int index = iter.indexof(*m_device);
|
||||
if (index < m_count - 1)
|
||||
index++;
|
||||
else
|
||||
index = 0;
|
||||
m_device = iter.byindex(index);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __UI_DEVCTRL_H__ */
|
@ -187,11 +187,11 @@ void ui_menu_main::handle()
|
||||
break;
|
||||
|
||||
case MESS_MENU_TAPE_CONTROL:
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_tape_control(machine(), container)));
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_tape_control(machine(), container, NULL)));
|
||||
break;
|
||||
|
||||
case MESS_MENU_BITBANGER_CONTROL:
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_bitbanger_control(machine(), container)));
|
||||
ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_mess_bitbanger_control(machine(), container, NULL)));
|
||||
break;
|
||||
|
||||
case SLOT_DEVICES:
|
||||
|
@ -36,8 +36,8 @@
|
||||
// ctor
|
||||
//-------------------------------------------------
|
||||
|
||||
ui_menu_mess_tape_control::ui_menu_mess_tape_control(running_machine &machine, render_container *container)
|
||||
: ui_menu(machine, container)
|
||||
ui_menu_mess_tape_control::ui_menu_mess_tape_control(running_machine &machine, render_container *container, cassette_image_device *device)
|
||||
: ui_menu_device_control<cassette_image_device>(machine, container, device)
|
||||
{
|
||||
}
|
||||
|
||||
@ -51,18 +51,6 @@ ui_menu_mess_tape_control::~ui_menu_mess_tape_control()
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// cassette_count - returns the number of cassette
|
||||
// devices in the machine
|
||||
//-------------------------------------------------
|
||||
|
||||
int ui_menu_mess_tape_control::cassette_count()
|
||||
{
|
||||
cassette_device_iterator iter(machine().root_device());
|
||||
return iter.count();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// populate - populates the main tape control menu
|
||||
//-------------------------------------------------
|
||||
@ -71,25 +59,25 @@ void ui_menu_mess_tape_control::populate()
|
||||
{
|
||||
astring timepos;
|
||||
cassette_state state;
|
||||
int count = cassette_count();
|
||||
UINT32 flags = 0;
|
||||
|
||||
if( count > 0 )
|
||||
if (count() > 0)
|
||||
{
|
||||
if( index == (count-1) )
|
||||
int index = current_index();
|
||||
|
||||
if( index == (count()-1) )
|
||||
flags |= MENU_FLAG_LEFT_ARROW;
|
||||
else
|
||||
flags |= MENU_FLAG_RIGHT_ARROW;
|
||||
}
|
||||
|
||||
if ((device != NULL) && (device->exists()))
|
||||
if ((current_device() != NULL) && (current_device()->exists()))
|
||||
{
|
||||
double t0, t1;
|
||||
UINT32 tapeflags = 0;
|
||||
cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&device->device());
|
||||
|
||||
t0 = cassette->get_position();
|
||||
t1 = cassette->get_length();
|
||||
t0 = current_device()->get_position();
|
||||
t1 = current_device()->get_length();
|
||||
|
||||
if (t1 > 0)
|
||||
{
|
||||
@ -100,11 +88,11 @@ void ui_menu_mess_tape_control::populate()
|
||||
}
|
||||
|
||||
// name of tape
|
||||
item_append(device->device().name(), device->filename(), flags, TAPECMD_SELECT);
|
||||
item_append(current_device()->device().name(), current_device()->filename(), flags, TAPECMD_SELECT);
|
||||
|
||||
// state
|
||||
get_time_string(timepos, cassette, NULL, NULL);
|
||||
state = cassette->get_state();
|
||||
get_time_string(timepos, current_device(), NULL, NULL);
|
||||
state = current_device()->get_state();
|
||||
item_append(
|
||||
(state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
|
||||
? "stopped"
|
||||
@ -145,20 +133,10 @@ void ui_menu_mess_tape_control::populate()
|
||||
|
||||
void ui_menu_mess_tape_control::handle()
|
||||
{
|
||||
// do we have to load the device?
|
||||
if (device == NULL)
|
||||
{
|
||||
cassette_device_iterator iter(machine().root_device());
|
||||
device = iter.byindex(index);
|
||||
reset((ui_menu_reset_options)0);
|
||||
}
|
||||
|
||||
// rebuild the menu - we have to do this so that the counter updates
|
||||
reset(UI_MENU_RESET_REMEMBER_POSITION);
|
||||
populate();
|
||||
|
||||
cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&device->device());
|
||||
|
||||
// process the menu
|
||||
const ui_menu_event *event = process(UI_MENU_PROCESS_LR_REPEAT);
|
||||
if (event != NULL)
|
||||
@ -167,46 +145,32 @@ void ui_menu_mess_tape_control::handle()
|
||||
{
|
||||
case IPT_UI_LEFT:
|
||||
if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette->seek(-1, SEEK_CUR);
|
||||
current_device()->seek(-1, SEEK_CUR);
|
||||
else if (event->itemref==TAPECMD_SELECT)
|
||||
{
|
||||
// left arrow - rotate left through cassette devices
|
||||
if (index > 0)
|
||||
index--;
|
||||
else
|
||||
index = cassette_count() - 1;
|
||||
device = NULL;
|
||||
}
|
||||
previous();
|
||||
break;
|
||||
|
||||
case IPT_UI_RIGHT:
|
||||
if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette->seek(+1, SEEK_CUR);
|
||||
current_device()->seek(+1, SEEK_CUR);
|
||||
else if (event->itemref==TAPECMD_SELECT)
|
||||
{
|
||||
// right arrow - rotate right through cassette devices
|
||||
if (index < cassette_count() - 1)
|
||||
index++;
|
||||
else
|
||||
index = 0;
|
||||
device = NULL;
|
||||
}
|
||||
next();
|
||||
break;
|
||||
|
||||
case IPT_UI_SELECT:
|
||||
{
|
||||
if (event->itemref==TAPECMD_STOP)
|
||||
cassette->change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
current_device()->change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
else if (event->itemref==TAPECMD_PLAY)
|
||||
cassette->change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
current_device()->change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
else if (event->itemref==TAPECMD_RECORD)
|
||||
cassette->change_state(CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
current_device()->change_state(CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
else if (event->itemref==TAPECMD_REWIND)
|
||||
cassette->seek(-30, SEEK_CUR);
|
||||
current_device()->seek(-30, SEEK_CUR);
|
||||
else if (event->itemref==TAPECMD_FAST_FORWARD)
|
||||
cassette->seek(30, SEEK_CUR);
|
||||
current_device()->seek(30, SEEK_CUR);
|
||||
else if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette->seek(0, SEEK_SET);
|
||||
current_device()->seek(0, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -15,19 +15,16 @@
|
||||
#define __UI_TAPECTRL_H__
|
||||
|
||||
#include "imagedev/cassette.h"
|
||||
#include "ui/devctrl.h"
|
||||
|
||||
class ui_menu_mess_tape_control : public ui_menu {
|
||||
class ui_menu_mess_tape_control : public ui_menu_device_control<cassette_image_device> {
|
||||
public:
|
||||
ui_menu_mess_tape_control(running_machine &machine, render_container *container);
|
||||
ui_menu_mess_tape_control(running_machine &machine, render_container *container, cassette_image_device *device);
|
||||
virtual ~ui_menu_mess_tape_control();
|
||||
virtual void populate();
|
||||
virtual void handle();
|
||||
|
||||
private:
|
||||
int index;
|
||||
device_image_interface *device;
|
||||
int cassette_count();
|
||||
|
||||
static void get_time_string(astring &dest, cassette_image_device *cassette, int *curpos, int *endpos);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user