summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/galaxy.cpp
blob: 3b03991d3bbf82e1ab7061fbe00e954711ef61b7 (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
136
// license:BSD-3-Clause
// copyright-holders:Krzysztof Strzecha, Miodrag Milanovic
/***************************************************************************

  galaxy.c

  Functions to emulate the video hardware of the Galaksija.

  20/05/2008 - Real video implementation by Miodrag Milanovic
  01/03/2008 - Update by Miodrag Milanovic to make Galaksija video work with new SVN code
***************************************************************************/

#include "emu.h"
#include "includes/galaxy.h"

#include "cpu/z80/z80.h"
#include "screen.h"


TIMER_CALLBACK_MEMBER(galaxy_state::gal_video)
{
	address_space &space = m_maincpu->space(AS_PROGRAM);
	int y, x;
	if (m_interrupts_enabled == true)
	{
		uint8_t *gfx = m_region_gfx1->base();
		uint8_t dat = (m_latch_value & 0x3c) >> 2;
		if ((m_gal_cnt >= 48 * 2) && (m_gal_cnt < 48 * 210))  // display on screen just m_first 208 lines
		{
			uint8_t mode = (m_latch_value >> 1) & 1; // bit 2 latch represents mode
			uint16_t addr = (m_maincpu->state_int(Z80_I) << 8) | m_maincpu->state_int(Z80_R) | ((m_latch_value & 0x80) ^ 0x80);
			if (mode == 0)
			{
				// Text mode
				if (m_first == 0 && (m_maincpu->state_int(Z80_R) & 0x1f) == 0)
				{
					// Due to a fact that on real processor latch value is set at
					// the end of last cycle we need to skip dusplay of double
					// m_first char in each row
					m_code = 0x00;
					m_first = 1;
				}
				else
				{
					m_code = space.read_byte(addr) & 0xbf;
					m_code += (m_code & 0x80) >> 1;
					m_code = gfx[(m_code & 0x7f) +(dat << 7 )] ^ 0xff;
					m_first = 0;
				}
				y = m_gal_cnt / 48 - 2;
				x = (m_gal_cnt % 48) * 8;

				m_bitmap.pix16(y, x ) = (m_code >> 0) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 1) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 2) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 3) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 4) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 5) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 6) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 7) & 1;
			}
			else
			{ // Graphics mode
				if (m_first < 4 && (m_maincpu->state_int(Z80_R) & 0x1f) == 0)
				{
					// Due to a fact that on real processor latch value is set at
					// the end of last cycle we need to skip dusplay of 4 times
					// m_first char in each row
					m_code = 0x00;
					m_first++;
				}
				else
				{
					m_code = space.read_byte(addr) ^ 0xff;
					m_first = 0;
				}
				y = m_gal_cnt / 48 - 2;
				x = (m_gal_cnt % 48) * 8;

				/* hack - until calc of R is fixed in Z80 */
				if (x == 11 * 8 && y == 0)
				{
					m_start_addr = addr;
				}
				if ((x / 8 >= 11) && (x / 8 < 44))
				{
					m_code = space.read_byte(m_start_addr + y * 32 + (m_gal_cnt % 48) - 11) ^ 0xff;
				}
				else
				{
					m_code = 0x00;
				}
				/* end of hack */

				m_bitmap.pix16(y, x ) = (m_code >> 0) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 1) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 2) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 3) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 4) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 5) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 6) & 1; x++;
				m_bitmap.pix16(y, x ) = (m_code >> 7) & 1;
			}
		}
		m_gal_cnt++;
	}
}

void galaxy_state::galaxy_set_timer()
{
	m_gal_cnt = 0;
	m_gal_video_timer->adjust(attotime::zero, 0, attotime::from_hz(6144000 / 8));
}

void galaxy_state::video_start()
{
	m_gal_cnt = 0;

	m_gal_video_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(galaxy_state::gal_video),this));
	m_gal_video_timer->adjust(attotime::zero, 0, attotime::never);

	m_screen->register_screen_bitmap(m_bitmap);
}

uint32_t galaxy_state::screen_update_galaxy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	m_gal_video_timer->adjust(attotime::zero, 0, attotime::never);
	if (m_interrupts_enabled == false)
	{
		const rectangle black_area(0, 384 - 1, 0, 208 - 1);
		m_bitmap.fill(0, black_area);
	}
	m_interrupts_enabled = false;
	copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
	return 0;
}