summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tmc600.cpp
blob: bfa59a47995a1c1e228d12254212cf7ffe19a816 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// license:BSD-3-Clause
// copyright-holders:Curt Coder
#include "emu.h"
#include "includes/tmc600.h"

WRITE8_MEMBER( tmc600_state::vismac_register_w )
{
	m_vismac_reg_latch = data >> 4;
}

WRITE8_MEMBER( tmc600_state::vismac_data_w )
{
	uint16_t ma = m_maincpu->get_memory_address();

	switch (m_vismac_reg_latch & 0x07)
	{
	case 2: m_vismac_color_latch = data & 0x0f; break;
	case 3: m_vis->out3_w(space, ma, data); break;
	case 4: m_vis->out4_w(space, ma, data); break;
	case 5: m_vis->out5_w(space, ma, data); break;
	case 6: m_vis->out6_w(space, ma, data); break;
	case 7: m_vis->out7_w(space, ma, data); break;
	}
}

uint8_t tmc600_state::get_color(uint16_t pma)
{
	uint16_t pageaddr = pma & TMC600_PAGE_RAM_MASK;
	uint8_t color = m_color_ram[pageaddr];

	if (BIT(color, 3) && m_blink)
	{
		color ^= 0x07;
	}

	return color;
}

WRITE8_MEMBER( tmc600_state::page_ram_w )
{
	m_page_ram[offset] = data;
	m_color_ram[offset] = m_vismac_color_latch;
}

void tmc600_state::cdp1869_page_ram(address_map &map)
{
	map(0x000, 0x3ff).mirror(0x400).ram().share("page_ram").w(FUNC(tmc600_state::page_ram_w));
}

CDP1869_CHAR_RAM_READ_MEMBER( tmc600_state::tmc600_char_ram_r )
{
	uint16_t pageaddr = pma & TMC600_PAGE_RAM_MASK;
	uint8_t color = get_color(pageaddr);
	uint16_t charaddr = ((cma & 0x08) << 8) | (pmd << 3) | (cma & 0x07);
	uint8_t cdb = m_char_rom[charaddr] & 0x3f;

	int ccb0 = BIT(color, 2);
	int ccb1 = BIT(color, 1);

	return (ccb1 << 7) | (ccb0 << 6) | cdb;
}

CDP1869_PCB_READ_MEMBER( tmc600_state::tmc600_pcb_r )
{
	uint16_t pageaddr = pma & TMC600_PAGE_RAM_MASK;
	uint8_t color = get_color(pageaddr);

	return BIT(color, 0);
}

WRITE_LINE_MEMBER( tmc600_state::prd_w )
{
	if (!state) {
		m_frame++;

		switch (m_frame) {
		case 8:
			m_maincpu->int_w(CLEAR_LINE);
			break;

		case 16:
			m_maincpu->int_w(m_rtc_int);
			m_blink = !m_blink;
			m_frame = 0;
			break;
		}
	}
}

void tmc600_state::video_start()
{
	// allocate memory
	m_color_ram.allocate(TMC600_PAGE_RAM_SIZE);

	// state saving
	save_item(NAME(m_vismac_reg_latch));
	save_item(NAME(m_vismac_color_latch));
	save_item(NAME(m_frame));
	save_item(NAME(m_blink));
}

static const gfx_layout tmc600_charlayout =
{
	6, 9,                   // 6 x 9 characters
	256,                    // 256 characters
	1,                      // 1 bits per pixel
	{ 0 },                  // no bitplanes
	// x offsets
	{ 2, 3, 4, 5, 6, 7 },
	// y offsets
	{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 2048*8 },
	8*8                     // every char takes 8 x 8 bytes
};

static GFXDECODE_START( gfx_tmc600 )
	GFXDECODE_ENTRY( "chargen", 0x0000, tmc600_charlayout, 0, 36 )
GFXDECODE_END

MACHINE_CONFIG_START(tmc600_state::tmc600_video)
	// video hardware
	MCFG_CDP1869_SCREEN_PAL_ADD(CDP1869_TAG, SCREEN_TAG, cdp1869_device::DOT_CLK_PAL)

	MCFG_DEVICE_ADD("gfxdecode", GFXDECODE, CDP1869_TAG":palette", gfx_tmc600)

	// sound hardware
	SPEAKER(config, "mono").front_center();
	MCFG_CDP1869_ADD(CDP1869_TAG, cdp1869_device::DOT_CLK_PAL, cdp1869_page_ram)
	MCFG_CDP1869_COLOR_CLOCK(cdp1869_device::COLOR_CLK_PAL)
	MCFG_CDP1869_CHAR_PCB_READ_OWNER(tmc600_state, tmc600_pcb_r)
	MCFG_CDP1869_CHAR_RAM_READ_OWNER(tmc600_state, tmc600_char_ram_r)
	MCFG_CDP1869_PAL_NTSC_CALLBACK(CONSTANT(1))
	MCFG_CDP1869_PRD_CALLBACK(WRITELINE(*this, tmc600_state, prd_w))
	MCFG_VIDEO_SET_SCREEN(SCREEN_TAG)
	MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
MACHINE_CONFIG_END