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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/***************************************************************************
SAM Coupe
Functions to emulate the video hardware
***************************************************************************/
#include "emu.h"
#include "includes/samcoupe.h"
/***************************************************************************
MACROS
***************************************************************************/
/* border color from border register */
#define BORDER_COLOR(x) ((x & 0x20) >> 2 | (x & 0x07))
/* foreground and background color from attribute byte in mode 1 and 2 */
#define ATTR_BG(x) ((x >> 3) & 0x07)
#define ATTR_FG(x) (((x >> 3) & 0x08) | (x & 0x07))
/***************************************************************************
IMPLEMENTATION
***************************************************************************/
void samcoupe_state::video_start()
{
machine().primary_screen->register_screen_bitmap(m_bitmap);
}
UINT32 samcoupe_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
return 0;
}
static void draw_mode4_line(running_machine &machine, int y, int hpos)
{
samcoupe_state *state = machine.driver_data<samcoupe_state>();
UINT8 *videoram = state->m_videoram;
/* get start address */
UINT8 *vram = videoram + ((y - SAM_BORDER_TOP) * 128) + ((hpos - SAM_BORDER_LEFT) / 4);
for (int i = 0; i < (SAM_BLOCK*2)/4; i++)
{
/* draw 2 pixels (doublewidth) */
state->m_bitmap.pix16(y, hpos + i * 4 + 0) = state->m_clut[(*vram >> 4) & 0x0f];
state->m_bitmap.pix16(y, hpos + i * 4 + 1) = state->m_clut[(*vram >> 4) & 0x0f];
state->m_bitmap.pix16(y, hpos + i * 4 + 2) = state->m_clut[(*vram >> 0) & 0x0f];
state->m_bitmap.pix16(y, hpos + i * 4 + 3) = state->m_clut[(*vram >> 0) & 0x0f];
/* move to next address */
vram++;
/* attribute register contains the third displayed byte */
if (i == 2)
state->m_attribute = *vram;
}
}
static void draw_mode3_line(running_machine &machine, int y, int hpos)
{
samcoupe_state *state = machine.driver_data<samcoupe_state>();
UINT8 *videoram = state->m_videoram;
/* get start address */
UINT8 *vram = videoram + ((y - SAM_BORDER_TOP) * 128) + ((hpos - SAM_BORDER_LEFT) / 4);
for (int i = 0; i < (SAM_BLOCK*2)/4; i++)
{
/* draw 4 pixels */
state->m_bitmap.pix16(y, hpos + i * 4 + 0) = state->m_clut[(*vram >> 6) & 0x03];
state->m_bitmap.pix16(y, hpos + i * 4 + 1) = state->m_clut[(*vram >> 4) & 0x03];
state->m_bitmap.pix16(y, hpos + i * 4 + 2) = state->m_clut[(*vram >> 2) & 0x03];
state->m_bitmap.pix16(y, hpos + i * 4 + 3) = state->m_clut[(*vram >> 0) & 0x03];
/* move to next address */
vram++;
/* attribute register contains the third displayed byte */
if (i == 2)
state->m_attribute = *vram;
}
}
static void draw_mode12_block(samcoupe_state *state, bitmap_ind16 &bitmap, int vpos, int hpos, UINT8 mask)
{
/* extract colors from attribute */
UINT8 ink = state->m_clut[ATTR_FG(state->m_attribute)];
UINT8 pap = state->m_clut[ATTR_BG(state->m_attribute)];
/* draw block of 8 pixels (doubled to 16) */
for (int i = 0; i < SAM_BLOCK; i++)
{
bitmap.pix16(vpos, hpos + i*2 + 0) = BIT(mask, 7 - i) ? ink : pap;
bitmap.pix16(vpos, hpos + i*2 + 1) = BIT(mask, 7 - i) ? ink : pap;
}
}
static void draw_mode2_line(running_machine &machine, int y, int hpos)
{
samcoupe_state *state = machine.driver_data<samcoupe_state>();
UINT8 *videoram = state->m_videoram;
int cell = (y - SAM_BORDER_TOP) * 32 + (hpos - SAM_BORDER_LEFT) / SAM_BLOCK / 2;
UINT8 mask = videoram[cell];
state->m_attribute = videoram[cell + 0x2000];
draw_mode12_block(state, state->m_bitmap, y, hpos, mask);
}
static void draw_mode1_line(running_machine &machine, int y, int hpos)
{
samcoupe_state *state = machine.driver_data<samcoupe_state>();
UINT8 *videoram = state->m_videoram;
UINT8 mask = videoram[((((y - SAM_BORDER_TOP) & 0xc0) << 5) | (((y - SAM_BORDER_TOP) & 0x07) << 8) | (((y - SAM_BORDER_TOP) & 0x38) << 2)) + (hpos - SAM_BORDER_LEFT) / SAM_BLOCK / 2];
state->m_attribute = videoram[32*192 + (((y - SAM_BORDER_TOP) & 0xf8) << 2) + (hpos - SAM_BORDER_LEFT) / SAM_BLOCK / 2];
draw_mode12_block(state, state->m_bitmap, y, hpos, mask);
}
TIMER_CALLBACK( sam_video_update_callback )
{
samcoupe_state *state = machine.driver_data<samcoupe_state>();
int vpos = machine.primary_screen->vpos();
int hpos = machine.primary_screen->hpos();
int next_vpos = vpos;
int next_hpos = hpos + SAM_BLOCK*2;
/* next scanline? */
if (next_hpos >= SAM_BORDER_LEFT + SAM_SCREEN_WIDTH + SAM_BORDER_RIGHT)
{
next_vpos = (vpos + 1) % (SAM_BORDER_TOP + SAM_SCREEN_HEIGHT + SAM_BORDER_BOTTOM);
next_hpos = 0;
}
/* display disabled? (only in mode 3 or 4) */
if (BIT(state->m_vmpr, 6) && BIT(state->m_border, 7))
{
state->m_bitmap.plot_box(hpos, vpos, SAM_BLOCK*2, 1, 0);
}
else
{
/* border area? */
if (vpos < SAM_BORDER_TOP || vpos >= SAM_BORDER_TOP + SAM_SCREEN_HEIGHT || hpos < SAM_BORDER_LEFT || hpos >= SAM_BORDER_LEFT + SAM_SCREEN_WIDTH)
{
state->m_attribute = 0xff;
state->m_bitmap.plot_box(hpos, vpos, SAM_BLOCK*2, 1, state->m_clut[BORDER_COLOR(state->m_border)]);
}
else
{
/* main screen area */
switch ((state->m_vmpr & 0x60) >> 5)
{
case 0: draw_mode1_line(machine, vpos, hpos); break;
case 1: draw_mode2_line(machine, vpos, hpos); break;
case 2: draw_mode3_line(machine, vpos, hpos); break;
case 3: draw_mode4_line(machine, vpos, hpos); break;
}
}
}
/* do we need to trigger the scanline interrupt (interrupt happens at the start of the right border before the specified line)? */
if (state->m_line_int < SAM_SCREEN_HEIGHT && hpos == SAM_BORDER_LEFT + SAM_SCREEN_WIDTH && vpos == (state->m_line_int + SAM_BORDER_TOP - 1))
samcoupe_irq(machine.firstcpu, SAM_LINE_INT);
/* schedule next update */
state->m_video_update_timer->adjust(machine.primary_screen->time_until_pos(next_vpos, next_hpos));
}
|