summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/vcs80.h
blob: 904e58299974c29d9aca1955c0e24c5660b9bfa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic, Robbbert
#pragma once

#ifndef MAME_INCLUDES_VCS80_H
#define MAME_INCLUDES_VCS80_H


#include "cpu/z80/z80.h"
#include "machine/z80daisy.h"
#include "machine/z80pio.h"
#include "machine/ram.h"
#include "machine/bankdev.h"
#include "machine/timer.h"

#define SCREEN_TAG      "screen"
#define Z80_TAG         "z80"
#define Z80PIO_TAG      "z80pio"

class vcs80_state : public driver_device
{
public:
	vcs80_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_maincpu(*this, Z80_TAG)
		, m_pio(*this, Z80PIO_TAG)
		, m_y0(*this, "Y0")
		, m_y1(*this, "Y1")
		, m_y2(*this, "Y2")
		, m_bdmem(*this, "bdmem")
		, m_digits(*this, "digit%u", 0U)
	{ }

	required_device<cpu_device> m_maincpu;
	required_device<z80pio_device> m_pio;
	required_ioport m_y0;
	required_ioport m_y1;
	required_ioport m_y2;
	required_device<address_map_bank_device> m_bdmem;
	output_finder<9> m_digits;

	virtual void machine_start() override;

	DECLARE_READ8_MEMBER( pio_r );
	DECLARE_WRITE8_MEMBER( pio_w );
	DECLARE_READ8_MEMBER( pio_pa_r );
	DECLARE_WRITE8_MEMBER( pio_pb_w );

	DECLARE_READ8_MEMBER( mem_r )
	{
		m_pio->port_b_write((!BIT(offset, 0)) << 7);
		return m_bdmem->read8(space, offset);
	}

	DECLARE_WRITE8_MEMBER( mem_w )
	{
		m_pio->port_b_write((!BIT(offset, 0)) << 7);
		m_bdmem->write8(space, offset, data);
	}

	DECLARE_READ8_MEMBER( io_r )
	{
		m_pio->port_b_write((!BIT(offset, 0)) << 7);
		if ((offset >= 4) && (offset <= 7))
		{
			return pio_r(space, offset-4);
		}
		return 0xff;
	}

	DECLARE_WRITE8_MEMBER( io_w )
	{
		m_pio->port_b_write((!BIT(offset, 0)) << 7);
		if ((offset >= 4) && (offset <= 7))
		{
			pio_w(space, offset-4, data);
		}
	}

	/* keyboard state */
	int m_keylatch;
	int m_keyclk;
	void init_vcs80();
	TIMER_DEVICE_CALLBACK_MEMBER(vcs80_keyboard_tick);
	void vcs80(machine_config &config);
	void vcs80_bd_mem(address_map &map);
	void vcs80_io(address_map &map);
	void vcs80_mem(address_map &map);
};

#endif