Skip to content

Commit ef69445

Browse files
committed
bandai/wswan.cpp, bandai/wswansound.cpp: Use logmacro.h for logging, Implement Hypervoice, Sound output select (external (Stereo) is default), Implement output reading, Difference per output select, Fix namings
1 parent d4eafea commit ef69445

File tree

3 files changed

+422
-139
lines changed

3 files changed

+422
-139
lines changed

src/mame/bandai/wswan.cpp

+61-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@
4444

4545
#include <algorithm>
4646

47+
#define LOG_UNKNOWN (1 << 1)
48+
#define LOG_EEPROM (1 << 2)
49+
#define LOG_DMA (1 << 3)
50+
51+
#define LOG_ALL (LOG_UNKNOWN | LOG_EEPROM | LOG_DMA)
52+
53+
#define VERBOSE (0)
54+
55+
#include "logmacro.h"
56+
57+
#define LOGUNKNOWN(...) LOGMASKED(LOG_UNKNOWN, __VA_ARGS__)
58+
#define LOGEEPROM(...) LOGMASKED(LOG_EEPROM, __VA_ARGS__)
59+
#define LOGDMA(...) LOGMASKED(LOG_DMA, __VA_ARGS__)
4760

4861
namespace {
4962

@@ -60,12 +73,15 @@ class wswan_state : public driver_device
6073
m_cursx(*this, "CURSX"),
6174
m_cursy(*this, "CURSY"),
6275
m_buttons(*this, "BUTTONS"),
76+
m_sound_output(*this, "SOUND_OUTPUT"),
6377
m_icons(*this, "icon%u", 0U)
6478
{ }
6579

6680
void wswan(machine_config &config);
6781
void pockchv2(machine_config &config);
6882

83+
DECLARE_INPUT_CHANGED_MEMBER(sound_output_changed);
84+
6985
protected:
7086
virtual void machine_start() override ATTR_COLD;
7187
virtual void machine_reset() override ATTR_COLD;
@@ -109,6 +125,7 @@ class wswan_state : public driver_device
109125
required_ioport m_cursx;
110126
required_ioport m_cursy;
111127
required_ioport m_buttons;
128+
required_ioport m_sound_output;
112129
output_finder<6> m_icons;
113130

114131
u16 m_ws_portram[128] = { };
@@ -153,7 +170,8 @@ class wscolor_state : public wswan_state
153170
public:
154171
wscolor_state(const machine_config &mconfig, device_type type, const char *tag) :
155172
wswan_state(mconfig, type, tag),
156-
m_dma_view(*this, "dma_view")
173+
m_dma_view(*this, "dma_view"),
174+
m_hypervoice_view(*this, "hypervoice_view")
157175
{ }
158176

159177
void wscolor(machine_config &config);
@@ -168,6 +186,7 @@ class wscolor_state : public wswan_state
168186
static constexpr u8 SOUND_DMA_DIV[4] = { 6, 4, 2, 1 };
169187

170188
memory_view m_dma_view;
189+
memory_view m_hypervoice_view;
171190

172191
struct sound_dma_t
173192
{
@@ -187,7 +206,7 @@ class wscolor_state : public wswan_state
187206

188207
u16 dma_r(offs_t offset, u16 mem_mask);
189208
void dma_w(offs_t offset, u16 data, u16 mem_mask);
190-
void dma_view_w(int state);
209+
void color_mode_view_w(int state);
191210

192211
TIMER_CALLBACK_MEMBER(sound_dma_cb);
193212

@@ -222,6 +241,8 @@ void wscolor_state::io_map(address_map &map)
222241
map(0x00, 0xff).rw(FUNC(wscolor_state::port_r), FUNC(wscolor_state::port_w)); // I/O ports
223242
map(0x40, 0x53).view(m_dma_view);
224243
m_dma_view[0](0x40, 0x53).rw(FUNC(wscolor_state::dma_r), FUNC(wscolor_state::dma_w));
244+
map(0x64, 0x6b).view(m_hypervoice_view);
245+
m_hypervoice_view[0](0x64, 0x6b).rw(m_sound, FUNC(wswan_sound_device::hypervoice_r), FUNC(wswan_sound_device::hypervoice_w));
225246
}
226247

227248

@@ -248,6 +269,11 @@ static INPUT_PORTS_START(wswan)
248269
PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Y3 - Down") PORT_CODE(KEYCODE_S)
249270
PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Y2 - Right") PORT_CODE(KEYCODE_D)
250271
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Y1 - Up") PORT_CODE(KEYCODE_W)
272+
273+
PORT_START("SOUND_OUTPUT")
274+
PORT_CONFNAME( 0x01, 0x01, "Sound output select" ) PORT_CHANGED_MEMBER(DEVICE_SELF, FUNC(wswan_state::sound_output_changed), 0)
275+
PORT_CONFSETTING( 0x00, "Internal speaker (Mono)" )
276+
PORT_CONFSETTING( 0x01, "External headphone (Stereo)" )
251277
INPUT_PORTS_END
252278

253279

@@ -327,7 +353,7 @@ void wscolor_state::wscolor(machine_config &config)
327353
m_vdp->set_screen("screen");
328354
m_vdp->set_irq_callback(FUNC(wscolor_state::set_irq_line));
329355
m_vdp->icons_cb().set(FUNC(wscolor_state::set_icons));
330-
m_vdp->color_mode_cb().set(FUNC(wscolor_state::dma_view_w));
356+
m_vdp->color_mode_cb().set(FUNC(wscolor_state::color_mode_view_w));
331357

332358
// software lists
333359
config.device_remove("wsc_list");
@@ -337,6 +363,10 @@ void wscolor_state::wscolor(machine_config &config)
337363
m_cart->set_must_be_loaded(true);
338364
}
339365

366+
INPUT_CHANGED_MEMBER(wswan_state::sound_output_changed)
367+
{
368+
m_sound->set_headphone_connected(BIT(m_sound_output->read(), 0));
369+
}
340370

341371
void wswan_state::handle_irqs()
342372
{
@@ -402,13 +432,19 @@ TIMER_CALLBACK_MEMBER(wscolor_state::sound_dma_cb)
402432
if (BIT(m_sound_dma.control, 2))
403433
{
404434
// Sound DMA hold
405-
port_w(0x88 / 2, 0 << 8, 0xff00);
435+
if (BIT(m_sound_dma.control, 4))
436+
m_sound->hypervoice_dma_w(0);
437+
else
438+
port_w(0x88 / 2, 0 << 8, 0xff00);
406439
}
407440
else
408441
{
409442
address_space &space = m_maincpu->space(AS_PROGRAM);
410443
/* TODO: Output sound DMA byte */
411-
port_w(0x88 / 2, space.read_byte(m_sound_dma.source) << 8, 0xff00);
444+
if (BIT(m_sound_dma.control, 4))
445+
m_sound->hypervoice_dma_w(space.read_byte(m_sound_dma.source));
446+
else
447+
port_w(0x88 / 2, space.read_byte(m_sound_dma.source) << 8, 0xff00);
412448
m_sound_dma.size--;
413449
m_sound_dma.source = (m_sound_dma.source + (BIT(m_sound_dma.control, 6) ? -1 : 1)) & 0x0fffff;
414450
if (m_sound_dma.size == 0)
@@ -511,6 +547,7 @@ void wscolor_state::machine_start()
511547

512548
void wswan_state::machine_reset()
513549
{
550+
m_sound->set_headphone_connected(BIT(m_sound_output->read(), 0));
514551
m_bios_disabled = false;
515552

516553
m_rotate = 0;
@@ -536,6 +573,7 @@ void wscolor_state::machine_reset()
536573
wswan_state::machine_reset();
537574

538575
m_dma_view.disable();
576+
m_hypervoice_view.disable();
539577

540578
/* Initialize sound DMA */
541579
m_sound_dma.timer->adjust(attotime::never);
@@ -545,12 +583,18 @@ void wscolor_state::machine_reset()
545583
}
546584

547585

548-
void wscolor_state::dma_view_w(int state)
586+
void wscolor_state::color_mode_view_w(int state)
549587
{
550588
if (state)
589+
{
551590
m_dma_view.select(0);
591+
m_hypervoice_view.select(0);
592+
}
552593
else
594+
{
553595
m_dma_view.disable();
596+
m_hypervoice_view.disable();
597+
}
554598
}
555599

556600

@@ -653,6 +697,10 @@ u16 wswan_state::port_r(offs_t offset, u16 mem_mask)
653697
case 0xcc / 2:
654698
case 0xce / 2:
655699
return m_cart->read_io(offset, mem_mask);
700+
default:
701+
if (!machine().side_effects_disabled())
702+
LOGUNKNOWN("%s: Read from unsupported port: %02x & %04x", machine().describe_context(), offset << 1, mem_mask);
703+
break;
656704
}
657705

658706
return value;
@@ -844,7 +892,7 @@ void wswan_state::port_w(offs_t offset, u16 data, u16 mem_mask)
844892
}
845893
else
846894
{
847-
logerror("Unsupported internal EEPROM command: %X\n", data);
895+
LOGEEPROM("%s: Unsupported internal EEPROM command: %02X\n", machine().describe_context(), data & 0xff);
848896
}
849897
}
850898
break;
@@ -859,7 +907,7 @@ void wswan_state::port_w(offs_t offset, u16 data, u16 mem_mask)
859907
m_cart->write_io(offset, data, mem_mask);
860908
break;
861909
default:
862-
logerror("Write to unsupported port: %x - %x\n", offset, data);
910+
LOGUNKNOWN("%s: Write to unsupported port: %02x - %04x & %04x\n", machine().describe_context(), offset << 1, data, mem_mask);
863911
break;
864912
}
865913

@@ -900,6 +948,10 @@ u16 wscolor_state::dma_r(offs_t offset, u16 mem_mask)
900948
case 0x52 / 2:
901949
// Sound DMA control
902950
return m_sound_dma.control;
951+
default:
952+
if (!machine().side_effects_disabled())
953+
LOGDMA("%s: Read from unknown DMA port: %02x & %04x", machine().describe_context(), offset << 1, mem_mask);
954+
break;
903955
}
904956
return value;
905957
}
@@ -1021,7 +1073,7 @@ void wscolor_state::dma_w(offs_t offset, u16 data, u16 mem_mask)
10211073
}
10221074
break;
10231075
default:
1024-
logerror("Write to unsupported port: %x - %x\n", offset, data);
1076+
LOGDMA("%s: Write to unknown DMA port: %x - %x\n", machine().describe_context(), offset, data);
10251077
break;
10261078
}
10271079
// Update the port value

0 commit comments

Comments
 (0)