1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder, Robbbert, Wilbert Pol
3 #include "emu.h"
4 #include "includes/osi.h"
5 #include "screen.h"
6 
7 /* Palette Initialization */
8 
osi630_palette(palette_device & palette) const9 void sb2m600_state::osi630_palette(palette_device &palette) const
10 {
11 	/* black and white */
12 	palette.set_pen_color(0, 0x00, 0x00, 0x00); // black
13 	palette.set_pen_color(1, 0xff, 0xff, 0xff); // white
14 
15 	/* color enabled */
16 	palette.set_pen_color(2, 0xff, 0xff, 0x00); // yellow
17 	palette.set_pen_color(3, 0xff, 0x00, 0x00); // red
18 	palette.set_pen_color(4, 0x00, 0xff, 0x00); // green
19 	palette.set_pen_color(5, 0x00, 0x80, 0x00); // olive green
20 	palette.set_pen_color(6, 0x00, 0x00, 0xff); // blue
21 	palette.set_pen_color(7, 0xff, 0x00, 0xff); // purple
22 	palette.set_pen_color(8, 0x00, 0x00, 0x80); // sky blue
23 	palette.set_pen_color(9, 0x00, 0x00, 0x00); // black
24 }
25 
26 /* Video Start */
27 
video_start()28 void sb2m600_state::video_start()
29 {
30 	// randomize video memory contents
31 	for (uint16_t addr = 0; addr < OSI600_VIDEORAM_SIZE; addr++)
32 		m_video_ram[addr] = machine().rand() & 0xff;
33 
34 	// randomize color memory contents
35 	if (m_color_ram)
36 		for (uint16_t addr = 0; addr < OSI630_COLORRAM_SIZE; addr++)
37 			m_color_ram[addr] = machine().rand() & 0x0f;
38 }
39 
40 /* Video Update */
41 
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)42 uint32_t sb2m600_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
43 {
44 	if (m_32)
45 	{
46 		for (int y = 0; y < 256; y++)
47 		{
48 			uint16_t videoram_addr = (y >> 4) * 64;
49 			int const line = (y >> 1) & 0x07;
50 			int x = 0;
51 
52 			for (int sx = 0; sx < 64; sx++)
53 			{
54 				uint8_t videoram_data = m_video_ram[videoram_addr];
55 				uint16_t charrom_addr = ((videoram_data << 3) | line) & 0x7ff;
56 				uint8_t charrom_data = m_p_chargen[charrom_addr];
57 
58 				for (int bit = 0; bit < 8; bit++)
59 				{
60 					bool color = BIT(charrom_data, 7);
61 
62 					if (m_coloren)
63 					{
64 						uint8_t colorram_data = m_color_ram[videoram_addr];
65 						color = (color ^ BIT(colorram_data, 0)) ? (((colorram_data >> 1) & 0x07) + 2) : 0;
66 					}
67 
68 					bitmap.pix(y, x++) = color;
69 
70 					charrom_data <<= 1;
71 				}
72 
73 				videoram_addr++;
74 			}
75 		}
76 	}
77 	else
78 	{
79 		for (int y = 0; y < 256; y++)
80 		{
81 			uint16_t videoram_addr = (y >> 3) * 32;
82 			int const line = y & 0x07;
83 			int x = 0;
84 
85 			for (int sx = 0; sx < 32; sx++)
86 			{
87 				uint8_t videoram_data = m_video_ram[videoram_addr];
88 				uint16_t const charrom_addr = ((videoram_data << 3) | line) & 0x7ff;
89 				uint8_t charrom_data = m_p_chargen[charrom_addr];
90 
91 				for (int bit = 0; bit < 8; bit++)
92 				{
93 					bool color = BIT(charrom_data, 7);
94 
95 					if (m_coloren)
96 					{
97 						uint8_t colorram_data = m_color_ram[videoram_addr];
98 						color = (color ^ BIT(colorram_data, 0)) ? (((colorram_data >> 1) & 0x07) + 2) : 0;
99 					}
100 
101 					bitmap.pix(y, x++) = color;
102 					bitmap.pix(y, x++) = color;
103 
104 					charrom_data <<= 1;
105 				}
106 
107 				videoram_addr++;
108 			}
109 		}
110 	}
111 
112 	return 0;
113 }
114 
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)115 uint32_t uk101_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
116 {
117 	for (int y = 0; y < 256; y++)
118 	{
119 		uint16_t videoram_addr = (y >> 4) * 64;
120 		int const line = (y >> 1) & 0x07;
121 		int x = 0;
122 
123 		for (int sx = 0; sx < 64; sx++)
124 		{
125 			uint8_t videoram_data = m_video_ram[videoram_addr++];
126 			uint16_t const charrom_addr = ((videoram_data << 3) | line) & 0x7ff;
127 			uint8_t charrom_data = m_p_chargen[charrom_addr];
128 
129 			for (int bit = 0; bit < 8; bit++)
130 			{
131 				bitmap.pix(y, x) = BIT(charrom_data, 7);
132 				x++;
133 				charrom_data <<= 1;
134 			}
135 		}
136 	}
137 
138 	return 0;
139 }
140 
141 /* Machine Drivers */
142 
osi600_video(machine_config & config)143 void sb2m600_state::osi600_video(machine_config &config)
144 {
145 	screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER));
146 	screen.set_refresh_hz(X1/256/256); // 60 Hz
147 	screen.set_screen_update(FUNC(sb2m600_state::screen_update));
148 	screen.set_size(64*8, 32*8);
149 	screen.set_visarea(0*8, 64*8-1, 0, 32*8-1);
150 	screen.set_palette("palette");
151 
152 	PALETTE(config, "palette", palette_device::MONOCHROME);
153 }
154 
uk101_video(machine_config & config)155 void uk101_state::uk101_video(machine_config &config)
156 {
157 	screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER));
158 	screen.set_refresh_hz(50);
159 	screen.set_screen_update(FUNC(uk101_state::screen_update));
160 	screen.set_size(64*8, 16*16);
161 	screen.set_visarea(0, 64*8-1, 0, 16*16-1);
162 	screen.set_palette("palette");
163 
164 	PALETTE(config, "palette", palette_device::MONOCHROME);
165 }
166 
osi630_video(machine_config & config)167 void sb2m600_state::osi630_video(machine_config &config)
168 {
169 	screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER));
170 	screen.set_refresh_hz(X1/256/256); // 60 Hz
171 	screen.set_screen_update(FUNC(sb2m600_state::screen_update));
172 	screen.set_size(64*8, 16*16);
173 	screen.set_visarea(0, 64*8-1, 0, 16*16-1);
174 	screen.set_palette("palette");
175 
176 	PALETTE(config, "palette", FUNC(sb2m600_state::osi630_palette), 8+2);
177 }
178