src/emu/video/msm6255.c
| r0 | r10972 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | OKI MSM6255 Dot Matrix LCD Controller implementation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "msm6255.h" |
| 12 | #include "machine/devhelpr.h" |
| 13 | |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // MACROS / CONSTANTS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | #define LOG 0 |
| 21 | |
| 22 | |
| 23 | // registers |
| 24 | enum |
| 25 | { |
| 26 | REGISTER_MOR = 0, |
| 27 | REGISTER_PR, |
| 28 | REGISTER_HNR, |
| 29 | REGISTER_DVR, |
| 30 | REGISTER_CPR, |
| 31 | REGISTER_SLR, |
| 32 | REGISTER_SUR, |
| 33 | REGISTER_CLR, |
| 34 | REGISTER_CUR |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | #define MOR_GRAPHICS 0x01 |
| 39 | #define MOR_4_BIT_PARALLEL 0x02 |
| 40 | #define MOR_2_BIT_PARALLEL 0x04 |
| 41 | #define MOR_DISPLAY_ON 0x08 |
| 42 | #define MOR_CURSOR_BLINK 0x10 |
| 43 | #define MOR_CURSOR_ON 0x20 |
| 44 | #define MOR_BLINK_TIME_16 0x40 |
| 45 | |
| 46 | |
| 47 | #define PR_HP_4 0x03 |
| 48 | #define PR_HP_5 0x04 |
| 49 | #define PR_HP_6 0x05 |
| 50 | #define PR_HP_7 0x06 |
| 51 | #define PR_HP_8 0x07 |
| 52 | #define PR_HP_MASK 0x07 |
| 53 | #define PR_VP_MASK 0xf0 |
| 54 | |
| 55 | |
| 56 | #define HNR_HN_MASK 0x7f |
| 57 | |
| 58 | |
| 59 | #define DVR_DN_MASK 0x7f |
| 60 | |
| 61 | |
| 62 | #define CPR_CPD_MASK 0x0f |
| 63 | #define CPR_CPU_MASK 0xf0 |
| 64 | |
| 65 | |
| 66 | |
| 67 | //************************************************************************** |
| 68 | // GLOBAL VARIABLES |
| 69 | //************************************************************************** |
| 70 | |
| 71 | // devices |
| 72 | const device_type MSM6255 = msm6255_device_config::static_alloc_device_config; |
| 73 | |
| 74 | |
| 75 | |
| 76 | //************************************************************************** |
| 77 | // DEVICE CONFIGURATION |
| 78 | //************************************************************************** |
| 79 | |
| 80 | GENERIC_DEVICE_CONFIG_SETUP(msm6255, "MSM6255") |
| 81 | |
| 82 | |
| 83 | //------------------------------------------------- |
| 84 | // device_config_complete - perform any |
| 85 | // operations now that the configuration is |
| 86 | // complete |
| 87 | //------------------------------------------------- |
| 88 | |
| 89 | void msm6255_device_config::device_config_complete() |
| 90 | { |
| 91 | // inherit a copy of the static data |
| 92 | const msm6255_interface *intf = reinterpret_cast<const msm6255_interface *>(static_config()); |
| 93 | if (intf != NULL) |
| 94 | { |
| 95 | *static_cast<msm6255_interface *>(this) = *intf; |
| 96 | |
| 97 | m_char_ram_r = intf->m_char_ram_r; |
| 98 | } |
| 99 | // or initialize to defaults if none provided |
| 100 | else |
| 101 | { |
| 102 | fatalerror("Interface not specified!"); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | //************************************************************************** |
| 109 | // INLINE HELPERS |
| 110 | //************************************************************************** |
| 111 | |
| 112 | //------------------------------------------------- |
| 113 | // read_video_data - read video ROM/RAM |
| 114 | //------------------------------------------------- |
| 115 | |
| 116 | inline UINT8 msm6255_device::read_video_data(UINT16 ma, UINT8 ra) |
| 117 | { |
| 118 | return m_config.m_char_ram_r(this, ma, ra); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | |
| 123 | //************************************************************************** |
| 124 | // LIVE DEVICE |
| 125 | //************************************************************************** |
| 126 | |
| 127 | //------------------------------------------------- |
| 128 | // msm6255_device - constructor |
| 129 | //------------------------------------------------- |
| 130 | |
| 131 | msm6255_device::msm6255_device(running_machine &_machine, const msm6255_device_config &config) |
| 132 | : device_t(_machine, config), |
| 133 | m_cursor(0), |
| 134 | m_config(config) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | |
| 139 | //------------------------------------------------- |
| 140 | // device_start - device-specific startup |
| 141 | //------------------------------------------------- |
| 142 | |
| 143 | void msm6255_device::device_start() |
| 144 | { |
| 145 | // find screen |
| 146 | m_screen = machine->device<screen_device>(m_config.m_screen_tag); |
| 147 | |
| 148 | // register for state saving |
| 149 | save_item(NAME(m_ir)); |
| 150 | save_item(NAME(m_mor)); |
| 151 | save_item(NAME(m_pr)); |
| 152 | save_item(NAME(m_hnr)); |
| 153 | save_item(NAME(m_dvr)); |
| 154 | save_item(NAME(m_cpr)); |
| 155 | save_item(NAME(m_slr)); |
| 156 | save_item(NAME(m_sur)); |
| 157 | save_item(NAME(m_clr)); |
| 158 | save_item(NAME(m_cur)); |
| 159 | save_item(NAME(m_cursor)); |
| 160 | save_item(NAME(m_frame)); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | //------------------------------------------------- |
| 165 | // device_reset - device-specific reset |
| 166 | //------------------------------------------------- |
| 167 | |
| 168 | void msm6255_device::device_reset() |
| 169 | { |
| 170 | m_frame = 0; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | //------------------------------------------------- |
| 175 | // read - register read |
| 176 | //------------------------------------------------- |
| 177 | |
| 178 | READ8_MEMBER( msm6255_device::read ) |
| 179 | { |
| 180 | UINT8 data = 0; |
| 181 | |
| 182 | if (offset & 0x01) |
| 183 | { |
| 184 | return m_ir; |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | switch (m_ir) |
| 189 | { |
| 190 | case REGISTER_MOR: |
| 191 | break; // write-only |
| 192 | |
| 193 | case REGISTER_PR: |
| 194 | data = m_pr; |
| 195 | break; |
| 196 | |
| 197 | case REGISTER_HNR: |
| 198 | data = m_hnr; |
| 199 | break; |
| 200 | |
| 201 | case REGISTER_DVR: |
| 202 | break; // write-only |
| 203 | |
| 204 | case REGISTER_CPR: |
| 205 | data = m_cpr; |
| 206 | break; |
| 207 | |
| 208 | case REGISTER_SLR: |
| 209 | data = m_slr; |
| 210 | break; |
| 211 | |
| 212 | case REGISTER_SUR: |
| 213 | data = m_sur; |
| 214 | break; |
| 215 | |
| 216 | case REGISTER_CLR: |
| 217 | data = m_clr; |
| 218 | break; |
| 219 | |
| 220 | case REGISTER_CUR: |
| 221 | data = m_cur; |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return data; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | //------------------------------------------------- |
| 231 | // write - register write |
| 232 | //------------------------------------------------- |
| 233 | |
| 234 | WRITE8_MEMBER( msm6255_device::write ) |
| 235 | { |
| 236 | if (offset & 0x01) |
| 237 | { |
| 238 | m_ir = data & 0x0f; |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | switch (m_ir) |
| 243 | { |
| 244 | case REGISTER_MOR: |
| 245 | m_mor = data & 0x7f; |
| 246 | break; |
| 247 | |
| 248 | case REGISTER_PR: |
| 249 | m_pr = data & 0xf7; |
| 250 | break; |
| 251 | |
| 252 | case REGISTER_HNR: |
| 253 | m_hnr = data & 0x7f; |
| 254 | break; |
| 255 | |
| 256 | case REGISTER_DVR: |
| 257 | m_dvr = data; |
| 258 | break; |
| 259 | |
| 260 | case REGISTER_CPR: |
| 261 | m_cpr = data; |
| 262 | break; |
| 263 | |
| 264 | case REGISTER_SLR: |
| 265 | m_slr = data; |
| 266 | break; |
| 267 | |
| 268 | case REGISTER_SUR: |
| 269 | m_sur = data; |
| 270 | break; |
| 271 | |
| 272 | case REGISTER_CLR: |
| 273 | m_clr = data; |
| 274 | break; |
| 275 | |
| 276 | case REGISTER_CUR: |
| 277 | m_cur = data; |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | //------------------------------------------------- |
| 285 | // update_cursor - |
| 286 | //------------------------------------------------- |
| 287 | |
| 288 | void msm6255_device::update_cursor() |
| 289 | { |
| 290 | if (m_mor & MOR_CURSOR_ON) |
| 291 | { |
| 292 | if (m_mor & MOR_CURSOR_BLINK) |
| 293 | { |
| 294 | if (m_mor & MOR_BLINK_TIME_16) |
| 295 | { |
| 296 | if (m_frame == 16) |
| 297 | { |
| 298 | m_cursor = !m_cursor; |
| 299 | m_frame = 0; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | m_frame++; |
| 304 | } |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | if (m_frame == 32) |
| 309 | { |
| 310 | m_cursor = !m_cursor; |
| 311 | m_frame = 0; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | m_frame++; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | m_cursor = 1; |
| 322 | } |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | m_cursor = 0; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
| 331 | //------------------------------------------------- |
| 332 | // draw_scanline - |
| 333 | //------------------------------------------------- |
| 334 | |
| 335 | void msm6255_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ma, UINT8 ra) |
| 336 | { |
| 337 | UINT8 hp = (m_pr & PR_HP_MASK) + 1; |
| 338 | UINT8 hn = (m_hnr & HNR_HN_MASK) + 1; |
| 339 | UINT8 cpu = m_cpr & CPR_CPU_MASK; |
| 340 | UINT8 cpd = m_cpr & CPR_CPD_MASK; |
| 341 | UINT16 car = (m_cur << 8) | m_clr; |
| 342 | |
| 343 | int sx, x; |
| 344 | |
| 345 | for (sx = 0; sx < hn; sx++) |
| 346 | { |
| 347 | UINT8 data = read_video_data(ma, ra); |
| 348 | |
| 349 | if (m_cursor) |
| 350 | { |
| 351 | if (ma == car) |
| 352 | { |
| 353 | if (ra >= cpu && ra <= cpd) |
| 354 | { |
| 355 | data ^= 0xff; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | for (x = 0; x < hp; x++) |
| 361 | { |
| 362 | *BITMAP_ADDR16(bitmap, y, (sx * hp) + x) = BIT(data, 7); |
| 363 | |
| 364 | data <<= 1; |
| 365 | } |
| 366 | |
| 367 | ma++; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | |
| 372 | //------------------------------------------------- |
| 373 | // update_graphics - |
| 374 | //------------------------------------------------- |
| 375 | |
| 376 | void msm6255_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect) |
| 377 | { |
| 378 | UINT8 hn = (m_hnr & HNR_HN_MASK) + 1; |
| 379 | UINT8 nx = (m_dvr & DVR_DN_MASK) + 1; |
| 380 | UINT16 sar = (m_sur << 8) | m_slr; |
| 381 | |
| 382 | int y; |
| 383 | |
| 384 | m_cursor = 0; |
| 385 | m_frame = 0; |
| 386 | |
| 387 | for (y = 0; y < nx; y++) |
| 388 | { |
| 389 | // draw upper half scanline |
| 390 | UINT16 ma = sar + (y * hn); |
| 391 | draw_scanline(bitmap, cliprect, y, ma, 0); |
| 392 | |
| 393 | // draw lower half scanline |
| 394 | ma = sar + ((y + nx) * hn); |
| 395 | draw_scanline(bitmap, cliprect, y + nx, ma, 0); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | |
| 400 | //------------------------------------------------- |
| 401 | // update_text - |
| 402 | //------------------------------------------------- |
| 403 | |
| 404 | void msm6255_device::update_text(bitmap_t *bitmap, const rectangle *cliprect) |
| 405 | { |
| 406 | UINT8 hn = (m_hnr & HNR_HN_MASK) + 1; |
| 407 | UINT8 vp = (m_pr & PR_VP_MASK) + 1; |
| 408 | UINT8 nx = (m_dvr & DVR_DN_MASK) + 1; |
| 409 | UINT16 sar = (m_sur << 8) | m_slr; |
| 410 | |
| 411 | int sy, y; |
| 412 | |
| 413 | update_cursor(); |
| 414 | |
| 415 | for (sy = 0; sy < nx; sy++) |
| 416 | { |
| 417 | for (y = 0; y < vp; y++) |
| 418 | { |
| 419 | // draw upper half scanline |
| 420 | UINT16 ma = sar + ((sy * vp) + y) * hn; |
| 421 | draw_scanline(bitmap, cliprect, (sy * vp) + y, ma, y); |
| 422 | |
| 423 | // draw lower half scanline |
| 424 | ma = sar + (((sy + nx) * vp) + y) * hn; |
| 425 | draw_scanline(bitmap, cliprect, (sy * vp) + y, ma, y); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | |
| 431 | //------------------------------------------------- |
| 432 | // update_screen - update screen |
| 433 | //------------------------------------------------- |
| 434 | |
| 435 | void msm6255_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 436 | { |
| 437 | if (m_mor & MOR_DISPLAY_ON) |
| 438 | { |
| 439 | if (m_mor & MOR_GRAPHICS) |
| 440 | { |
| 441 | update_graphics(bitmap, cliprect); |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | update_text(bitmap, cliprect); |
| 446 | } |
| 447 | } |
| 448 | else |
| 449 | { |
| 450 | bitmap_fill(bitmap, cliprect, get_black_pen(machine)); |
| 451 | } |
| 452 | } |
src/emu/video/msm6255.h
| r0 | r10972 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | OKI MSM6255 Dot Matrix LCD Controller implementation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #pragma once |
| 11 | |
| 12 | #ifndef __MSM6255__ |
| 13 | #define __MSM6255__ |
| 14 | |
| 15 | #include "emu.h" |
| 16 | |
| 17 | |
| 18 | |
| 19 | ///************************************************************************* |
| 20 | // INTERFACE CONFIGURATION MACROS |
| 21 | ///************************************************************************* |
| 22 | |
| 23 | #define MCFG_MSM6255_ADD(_tag, _clock, _config) \ |
| 24 | MCFG_DEVICE_ADD(_tag, MSM6255, _clock) \ |
| 25 | MCFG_DEVICE_CONFIG(_config) |
| 26 | |
| 27 | |
| 28 | #define MSM6255_INTERFACE(name) \ |
| 29 | const msm6255_interface (name) = |
| 30 | |
| 31 | |
| 32 | #define MSM6255_CHAR_RAM_READ(_name) \ |
| 33 | UINT8 _name(device_t *device, UINT16 ma, UINT8 ra) |
| 34 | |
| 35 | |
| 36 | |
| 37 | ///************************************************************************* |
| 38 | // TYPE DEFINITIONS |
| 39 | ///************************************************************************* |
| 40 | |
| 41 | // ======================> msm6255_char_ram_read_func |
| 42 | |
| 43 | typedef UINT8 (*msm6255_char_ram_read_func)(device_t *device, UINT16 ma, UINT8 ra); |
| 44 | |
| 45 | |
| 46 | // ======================> msm6255_interface |
| 47 | |
| 48 | struct msm6255_interface |
| 49 | { |
| 50 | const char *m_screen_tag; |
| 51 | |
| 52 | int m_character_clock; |
| 53 | |
| 54 | // ROM/RAM data read function |
| 55 | msm6255_char_ram_read_func m_char_ram_r; |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | // ======================> msm6255_device_config |
| 60 | |
| 61 | class msm6255_device_config : public device_config, |
| 62 | public msm6255_interface |
| 63 | { |
| 64 | friend class msm6255_device; |
| 65 | |
| 66 | // construction/destruction |
| 67 | msm6255_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 68 | |
| 69 | public: |
| 70 | // allocators |
| 71 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 72 | virtual device_t *alloc_device(running_machine &machine) const; |
| 73 | |
| 74 | protected: |
| 75 | // device_config overrides |
| 76 | virtual void device_config_complete(); |
| 77 | |
| 78 | msm6255_char_ram_read_func m_char_ram_r; |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | // ======================> msm6255_device |
| 83 | |
| 84 | class msm6255_device : public device_t |
| 85 | { |
| 86 | friend class msm6255_device_config; |
| 87 | |
| 88 | // construction/destruction |
| 89 | msm6255_device(running_machine &_machine, const msm6255_device_config &_config); |
| 90 | |
| 91 | public: |
| 92 | DECLARE_READ8_MEMBER( read ); |
| 93 | DECLARE_WRITE8_MEMBER( write ); |
| 94 | |
| 95 | void update_screen(bitmap_t *bitmap, const rectangle *cliprect); |
| 96 | |
| 97 | protected: |
| 98 | // device-level overrides |
| 99 | virtual void device_start(); |
| 100 | virtual void device_reset(); |
| 101 | |
| 102 | private: |
| 103 | inline UINT8 read_video_data(UINT16 ma, UINT8 ra); |
| 104 | void update_cursor(); |
| 105 | void draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ma, UINT8 ra); |
| 106 | void update_graphics(bitmap_t *bitmap, const rectangle *cliprect); |
| 107 | void update_text(bitmap_t *bitmap, const rectangle *cliprect); |
| 108 | |
| 109 | screen_device *m_screen; |
| 110 | |
| 111 | UINT8 m_ir; // instruction register |
| 112 | UINT8 m_mor; // mode control register |
| 113 | UINT8 m_pr; // character pitch register |
| 114 | UINT8 m_hnr; // horizontal character number register |
| 115 | UINT8 m_dvr; // duty number register |
| 116 | UINT8 m_cpr; // cursor form register |
| 117 | UINT8 m_slr; // start address (lower) register |
| 118 | UINT8 m_sur; // start address (upper) register |
| 119 | UINT8 m_clr; // cursor address (lower) register |
| 120 | UINT8 m_cur; // cursor address (upper) register |
| 121 | |
| 122 | int m_cursor; // is cursor displayed |
| 123 | int m_frame; // frame counter |
| 124 | |
| 125 | const msm6255_device_config &m_config; |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | // device type definition |
| 130 | extern const device_type MSM6255; |
| 131 | |
| 132 | |
| 133 | |
| 134 | #endif |
src/mess/video/msm6255.c
| r10971 | r10972 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | OKI MSM6255 Dot Matrix LCD Controller implementation |
| 4 | | |
| 5 | | Copyright MESS team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | ***************************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "msm6255.h" |
| 12 | | |
| 13 | | /*************************************************************************** |
| 14 | | PARAMETERS |
| 15 | | ***************************************************************************/ |
| 16 | | |
| 17 | | #define MSM6255_MOR_GRAPHICS 0x01 |
| 18 | | #define MSM6255_MOR_4_BIT_PARALLEL 0x02 |
| 19 | | #define MSM6255_MOR_2_BIT_PARALLEL 0x04 |
| 20 | | #define MSM6255_MOR_DISPLAY_ON 0x08 |
| 21 | | #define MSM6255_MOR_CURSOR_BLINK 0x10 |
| 22 | | #define MSM6255_MOR_CURSOR_ON 0x20 |
| 23 | | #define MSM6255_MOR_BLINK_TIME_16 0x40 |
| 24 | | |
| 25 | | #define MSM6255_PR_HP_4 0x03 |
| 26 | | #define MSM6255_PR_HP_5 0x04 |
| 27 | | #define MSM6255_PR_HP_6 0x05 |
| 28 | | #define MSM6255_PR_HP_7 0x06 |
| 29 | | #define MSM6255_PR_HP_8 0x07 |
| 30 | | #define MSM6255_PR_HP_MASK 0x07 |
| 31 | | #define MSM6255_PR_VP_MASK 0xf0 |
| 32 | | |
| 33 | | #define MSM6255_HNR_HN_MASK 0x7f |
| 34 | | |
| 35 | | #define MSM6255_DVR_DN_MASK 0x7f |
| 36 | | |
| 37 | | #define MSM6255_CPR_CPD_MASK 0x0f |
| 38 | | #define MSM6255_CPR_CPU_MASK 0xf0 |
| 39 | | |
| 40 | | enum |
| 41 | | { |
| 42 | | MSM6255_REGISTER_MOR = 0, |
| 43 | | MSM6255_REGISTER_PR, |
| 44 | | MSM6255_REGISTER_HNR, |
| 45 | | MSM6255_REGISTER_DVR, |
| 46 | | MSM6255_REGISTER_CPR, |
| 47 | | MSM6255_REGISTER_SLR, |
| 48 | | MSM6255_REGISTER_SUR, |
| 49 | | MSM6255_REGISTER_CLR, |
| 50 | | MSM6255_REGISTER_CUR |
| 51 | | }; |
| 52 | | |
| 53 | | /*************************************************************************** |
| 54 | | TYPE DEFINITIONS |
| 55 | | ***************************************************************************/ |
| 56 | | |
| 57 | | typedef struct _msm6255_t msm6255_t; |
| 58 | | struct _msm6255_t |
| 59 | | { |
| 60 | | const msm6255_interface *intf; /* interface */ |
| 61 | | |
| 62 | | screen_device *screen; /* screen */ |
| 63 | | |
| 64 | | UINT8 ir; /* instruction register */ |
| 65 | | UINT8 mor; /* mode control register */ |
| 66 | | UINT8 pr; /* character pitch register */ |
| 67 | | UINT8 hnr; /* horizontal character number register */ |
| 68 | | UINT8 dvr; /* duty number register */ |
| 69 | | UINT8 cpr; /* cursor form register */ |
| 70 | | UINT8 slr; /* start address (lower) register */ |
| 71 | | UINT8 sur; /* start address (upper) register */ |
| 72 | | UINT8 clr; /* cursor address (lower) register */ |
| 73 | | UINT8 cur; /* cursor address (upper) register */ |
| 74 | | |
| 75 | | int cursor; /* is cursor displayed */ |
| 76 | | int frame; /* frame counter */ |
| 77 | | }; |
| 78 | | |
| 79 | | /*************************************************************************** |
| 80 | | INLINE FUNCTIONS |
| 81 | | ***************************************************************************/ |
| 82 | | |
| 83 | | INLINE msm6255_t *get_safe_token(device_t *device) |
| 84 | | { |
| 85 | | assert(device != NULL); |
| 86 | | assert(device->type() == MSM6255); |
| 87 | | |
| 88 | | return (msm6255_t *)downcast<legacy_device_base *>(device)->token(); |
| 89 | | } |
| 90 | | |
| 91 | | /*************************************************************************** |
| 92 | | IMPLEMENTATION |
| 93 | | ***************************************************************************/ |
| 94 | | |
| 95 | | /*------------------------------------------------- |
| 96 | | msm6255_register_r - register read |
| 97 | | -------------------------------------------------*/ |
| 98 | | |
| 99 | | READ8_DEVICE_HANDLER( msm6255_register_r ) |
| 100 | | { |
| 101 | | msm6255_t *msm6255 = get_safe_token(device); |
| 102 | | |
| 103 | | if (offset & 0x01) |
| 104 | | { |
| 105 | | return msm6255->ir; |
| 106 | | } |
| 107 | | else |
| 108 | | { |
| 109 | | switch (msm6255->ir) |
| 110 | | { |
| 111 | | case MSM6255_REGISTER_MOR: |
| 112 | | return 0x00; // write-only |
| 113 | | |
| 114 | | case MSM6255_REGISTER_PR: |
| 115 | | return msm6255->pr; |
| 116 | | |
| 117 | | case MSM6255_REGISTER_HNR: |
| 118 | | return msm6255->hnr; |
| 119 | | |
| 120 | | case MSM6255_REGISTER_DVR: |
| 121 | | return 0x00; // write-only |
| 122 | | |
| 123 | | case MSM6255_REGISTER_CPR: |
| 124 | | return msm6255->cpr; |
| 125 | | |
| 126 | | case MSM6255_REGISTER_SLR: |
| 127 | | return msm6255->slr; |
| 128 | | |
| 129 | | case MSM6255_REGISTER_SUR: |
| 130 | | return msm6255->sur; |
| 131 | | |
| 132 | | case MSM6255_REGISTER_CLR: |
| 133 | | return msm6255->clr; |
| 134 | | |
| 135 | | case MSM6255_REGISTER_CUR: |
| 136 | | return msm6255->cur; |
| 137 | | |
| 138 | | default: |
| 139 | | return 0; |
| 140 | | } |
| 141 | | } |
| 142 | | } |
| 143 | | |
| 144 | | /*------------------------------------------------- |
| 145 | | msm6255_register_w - register write |
| 146 | | -------------------------------------------------*/ |
| 147 | | |
| 148 | | WRITE8_DEVICE_HANDLER( msm6255_register_w ) |
| 149 | | { |
| 150 | | msm6255_t *msm6255 = get_safe_token(device); |
| 151 | | |
| 152 | | if (offset & 0x01) |
| 153 | | { |
| 154 | | msm6255->ir = data & 0x0f; |
| 155 | | } |
| 156 | | else |
| 157 | | { |
| 158 | | switch (msm6255->ir) |
| 159 | | { |
| 160 | | case MSM6255_REGISTER_MOR: |
| 161 | | msm6255->mor = data & 0x7f; |
| 162 | | break; |
| 163 | | |
| 164 | | case MSM6255_REGISTER_PR: |
| 165 | | msm6255->pr = data & 0xf7; |
| 166 | | break; |
| 167 | | |
| 168 | | case MSM6255_REGISTER_HNR: |
| 169 | | msm6255->hnr = data & 0x7f; |
| 170 | | break; |
| 171 | | |
| 172 | | case MSM6255_REGISTER_DVR: |
| 173 | | msm6255->dvr = data; |
| 174 | | break; |
| 175 | | |
| 176 | | case MSM6255_REGISTER_CPR: |
| 177 | | msm6255->cpr = data; |
| 178 | | break; |
| 179 | | |
| 180 | | case MSM6255_REGISTER_SLR: |
| 181 | | msm6255->slr = data; |
| 182 | | break; |
| 183 | | |
| 184 | | case MSM6255_REGISTER_SUR: |
| 185 | | msm6255->sur = data; |
| 186 | | break; |
| 187 | | |
| 188 | | case MSM6255_REGISTER_CLR: |
| 189 | | msm6255->clr = data; |
| 190 | | break; |
| 191 | | |
| 192 | | case MSM6255_REGISTER_CUR: |
| 193 | | msm6255->cur = data; |
| 194 | | break; |
| 195 | | } |
| 196 | | } |
| 197 | | } |
| 198 | | |
| 199 | | /*------------------------------------------------- |
| 200 | | update_cursor - update cursor state |
| 201 | | -------------------------------------------------*/ |
| 202 | | |
| 203 | | static void update_cursor(device_t *device) |
| 204 | | { |
| 205 | | msm6255_t *msm6255 = get_safe_token(device); |
| 206 | | |
| 207 | | if (msm6255->mor & MSM6255_MOR_CURSOR_ON) |
| 208 | | { |
| 209 | | if (msm6255->mor & MSM6255_MOR_CURSOR_BLINK) |
| 210 | | { |
| 211 | | if (msm6255->mor & MSM6255_MOR_BLINK_TIME_16) |
| 212 | | { |
| 213 | | if (msm6255->frame == 16) |
| 214 | | { |
| 215 | | msm6255->cursor = !msm6255->cursor; |
| 216 | | msm6255->frame = 0; |
| 217 | | } |
| 218 | | else |
| 219 | | { |
| 220 | | msm6255->frame++; |
| 221 | | } |
| 222 | | } |
| 223 | | else |
| 224 | | { |
| 225 | | if (msm6255->frame == 32) |
| 226 | | { |
| 227 | | msm6255->cursor = !msm6255->cursor; |
| 228 | | msm6255->frame = 0; |
| 229 | | } |
| 230 | | else |
| 231 | | { |
| 232 | | msm6255->frame++; |
| 233 | | } |
| 234 | | } |
| 235 | | } |
| 236 | | else |
| 237 | | { |
| 238 | | msm6255->cursor = 1; |
| 239 | | } |
| 240 | | } |
| 241 | | else |
| 242 | | { |
| 243 | | msm6255->cursor = 0; |
| 244 | | } |
| 245 | | } |
| 246 | | |
| 247 | | /*------------------------------------------------- |
| 248 | | draw_scanline - draw one scanline |
| 249 | | -------------------------------------------------*/ |
| 250 | | |
| 251 | | static void draw_scanline(device_t *device, bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ma, UINT8 ra) |
| 252 | | { |
| 253 | | msm6255_t *msm6255 = get_safe_token(device); |
| 254 | | |
| 255 | | UINT8 hp = (msm6255->pr & MSM6255_PR_HP_MASK) + 1; |
| 256 | | UINT8 hn = (msm6255->hnr & MSM6255_HNR_HN_MASK) + 1; |
| 257 | | UINT8 cpu = msm6255->cpr & MSM6255_CPR_CPU_MASK; |
| 258 | | UINT8 cpd = msm6255->cpr & MSM6255_CPR_CPD_MASK; |
| 259 | | UINT16 car = (msm6255->cur << 8) | msm6255->clr; |
| 260 | | |
| 261 | | int sx, x; |
| 262 | | |
| 263 | | for (sx = 0; sx < hn; sx++) |
| 264 | | { |
| 265 | | UINT8 data = msm6255->intf->char_ram_r(device, ma, ra); |
| 266 | | |
| 267 | | if (msm6255->cursor) |
| 268 | | { |
| 269 | | if (ma == car) |
| 270 | | { |
| 271 | | if (ra >= cpu && ra <= cpd) |
| 272 | | { |
| 273 | | data ^= 0xff; |
| 274 | | } |
| 275 | | } |
| 276 | | } |
| 277 | | |
| 278 | | for (x = 0; x < hp; x++) |
| 279 | | { |
| 280 | | *BITMAP_ADDR16(bitmap, y, (sx * hp) + x) = BIT(data, 7); |
| 281 | | |
| 282 | | data <<= 1; |
| 283 | | } |
| 284 | | |
| 285 | | ma++; |
| 286 | | } |
| 287 | | } |
| 288 | | |
| 289 | | /*------------------------------------------------- |
| 290 | | update_graphics - draw graphics mode screen |
| 291 | | -------------------------------------------------*/ |
| 292 | | |
| 293 | | static void update_graphics(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 294 | | { |
| 295 | | msm6255_t *msm6255 = get_safe_token(device); |
| 296 | | |
| 297 | | UINT8 hn = (msm6255->hnr & MSM6255_HNR_HN_MASK) + 1; |
| 298 | | UINT8 nx = (msm6255->dvr & MSM6255_DVR_DN_MASK) + 1; |
| 299 | | UINT16 sar = (msm6255->sur << 8) | msm6255->slr; |
| 300 | | |
| 301 | | int y; |
| 302 | | |
| 303 | | msm6255->cursor = 0; |
| 304 | | msm6255->frame = 0; |
| 305 | | |
| 306 | | for (y = 0; y < nx; y++) |
| 307 | | { |
| 308 | | /* draw upper half scanline */ |
| 309 | | UINT16 ma = sar + (y * hn); |
| 310 | | draw_scanline(device, bitmap, cliprect, y, ma, 0); |
| 311 | | |
| 312 | | /* draw lower half scanline */ |
| 313 | | ma = sar + ((y + nx) * hn); |
| 314 | | draw_scanline(device, bitmap, cliprect, y + nx, ma, 0); |
| 315 | | } |
| 316 | | } |
| 317 | | |
| 318 | | /*------------------------------------------------- |
| 319 | | update_text - draw text mode screen |
| 320 | | -------------------------------------------------*/ |
| 321 | | |
| 322 | | static void update_text(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 323 | | { |
| 324 | | msm6255_t *msm6255 = get_safe_token(device); |
| 325 | | |
| 326 | | UINT8 hn = (msm6255->hnr & MSM6255_HNR_HN_MASK) + 1; |
| 327 | | UINT8 vp = (msm6255->pr & MSM6255_PR_VP_MASK) + 1; |
| 328 | | UINT8 nx = (msm6255->dvr & MSM6255_DVR_DN_MASK) + 1; |
| 329 | | UINT16 sar = (msm6255->sur << 8) | msm6255->slr; |
| 330 | | |
| 331 | | int sy, y; |
| 332 | | |
| 333 | | update_cursor(device); |
| 334 | | |
| 335 | | for (sy = 0; sy < nx; sy++) |
| 336 | | { |
| 337 | | for (y = 0; y < vp; y++) |
| 338 | | { |
| 339 | | /* draw upper half scanline */ |
| 340 | | UINT16 ma = sar + ((sy * vp) + y) * hn; |
| 341 | | draw_scanline(device, bitmap, cliprect, (sy * vp) + y, ma, y); |
| 342 | | |
| 343 | | /* draw lower half scanline */ |
| 344 | | ma = sar + (((sy + nx) * vp) + y) * hn; |
| 345 | | draw_scanline(device, bitmap, cliprect, (sy * vp) + y, ma, y); |
| 346 | | } |
| 347 | | } |
| 348 | | } |
| 349 | | |
| 350 | | /*------------------------------------------------- |
| 351 | | update_text - draw screen |
| 352 | | -------------------------------------------------*/ |
| 353 | | |
| 354 | | void msm6255_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 355 | | { |
| 356 | | msm6255_t *msm6255 = get_safe_token(device); |
| 357 | | |
| 358 | | if (msm6255->mor & MSM6255_MOR_DISPLAY_ON) |
| 359 | | { |
| 360 | | if (msm6255->mor & MSM6255_MOR_GRAPHICS) |
| 361 | | { |
| 362 | | update_graphics(device, bitmap, cliprect); |
| 363 | | } |
| 364 | | else |
| 365 | | { |
| 366 | | update_text(device, bitmap, cliprect); |
| 367 | | } |
| 368 | | } |
| 369 | | else |
| 370 | | { |
| 371 | | bitmap_fill(bitmap, cliprect, get_black_pen(device->machine)); |
| 372 | | } |
| 373 | | } |
| 374 | | |
| 375 | | /*------------------------------------------------- |
| 376 | | DEVICE_START( msm6255 ) |
| 377 | | -------------------------------------------------*/ |
| 378 | | |
| 379 | | static DEVICE_START( msm6255 ) |
| 380 | | { |
| 381 | | msm6255_t *msm6255 = get_safe_token(device); |
| 382 | | |
| 383 | | /* resolve callbacks */ |
| 384 | | msm6255->intf = (const msm6255_interface*)device->baseconfig().static_config(); |
| 385 | | assert(msm6255->intf->char_ram_r != NULL); |
| 386 | | |
| 387 | | /* get the screen */ |
| 388 | | msm6255->screen = device->machine->device<screen_device>(msm6255->intf->screen_tag); |
| 389 | | assert(msm6255->screen != NULL); |
| 390 | | |
| 391 | | /* register for state saving */ |
| 392 | | device->save_item(NAME(msm6255->ir)); |
| 393 | | device->save_item(NAME(msm6255->mor)); |
| 394 | | device->save_item(NAME(msm6255->pr)); |
| 395 | | device->save_item(NAME(msm6255->hnr)); |
| 396 | | device->save_item(NAME(msm6255->dvr)); |
| 397 | | device->save_item(NAME(msm6255->cpr)); |
| 398 | | device->save_item(NAME(msm6255->slr)); |
| 399 | | device->save_item(NAME(msm6255->sur)); |
| 400 | | device->save_item(NAME(msm6255->clr)); |
| 401 | | device->save_item(NAME(msm6255->cur)); |
| 402 | | device->save_item(NAME(msm6255->cursor)); |
| 403 | | device->save_item(NAME(msm6255->frame)); |
| 404 | | } |
| 405 | | |
| 406 | | /*------------------------------------------------- |
| 407 | | DEVICE_RESET( msm6255 ) |
| 408 | | -------------------------------------------------*/ |
| 409 | | |
| 410 | | static DEVICE_RESET( msm6255 ) |
| 411 | | { |
| 412 | | msm6255_t *msm6255 = get_safe_token(device); |
| 413 | | |
| 414 | | msm6255->frame = 0; |
| 415 | | } |
| 416 | | |
| 417 | | /*------------------------------------------------- |
| 418 | | DEVICE_GET_INFO( msm6255 ) |
| 419 | | -------------------------------------------------*/ |
| 420 | | |
| 421 | | DEVICE_GET_INFO( msm6255 ) |
| 422 | | { |
| 423 | | switch (state) |
| 424 | | { |
| 425 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 426 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(msm6255_t); break; |
| 427 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 428 | | |
| 429 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 430 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(msm6255); break; |
| 431 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 432 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(msm6255); break; |
| 433 | | |
| 434 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 435 | | case DEVINFO_STR_NAME: strcpy(info->s, "OKI MSM6255"); break; |
| 436 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "OKI MSM6255"); break; |
| 437 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 438 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 439 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 440 | | } |
| 441 | | } |
| 442 | | |
| 443 | | DEFINE_LEGACY_DEVICE(MSM6255, msm6255); |