src/mess/video/iq151_grafik.c
| r0 | r13174 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | IQ151 grafik emulation |
| 4 | |
| 5 | ***************************************************************************/ |
| 6 | |
| 7 | #include "emu.h" |
| 8 | #include "iq151_grafik.h" |
| 9 | |
| 10 | #define LOG 0 |
| 11 | |
| 12 | /*************************************************************************** |
| 13 | IMPLEMENTATION |
| 14 | ***************************************************************************/ |
| 15 | |
| 16 | static I8255_INTERFACE( grafik_ppi8255_intf ) |
| 17 | { |
| 18 | DEVCB_NULL, |
| 19 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, x_write), |
| 20 | DEVCB_NULL, |
| 21 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, y_write), |
| 22 | DEVCB_NULL, |
| 23 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, iq151_grafik_device, control_w), |
| 24 | }; |
| 25 | |
| 26 | static MACHINE_CONFIG_FRAGMENT( iq151_grafik ) |
| 27 | MCFG_I8255_ADD("ppi8255", grafik_ppi8255_intf) |
| 28 | MACHINE_CONFIG_END |
| 29 | |
| 30 | |
| 31 | //************************************************************************** |
| 32 | // GLOBAL VARIABLES |
| 33 | //************************************************************************** |
| 34 | |
| 35 | const device_type IQ151_GRAFIK = &device_creator<iq151_grafik_device>; |
| 36 | |
| 37 | //************************************************************************** |
| 38 | // LIVE DEVICE |
| 39 | //************************************************************************** |
| 40 | |
| 41 | //------------------------------------------------- |
| 42 | // iq151_grafik_device - constructor |
| 43 | //------------------------------------------------- |
| 44 | |
| 45 | iq151_grafik_device::iq151_grafik_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 46 | : device_t(mconfig, IQ151_GRAFIK, "IQ151 grafik", tag, owner, clock), |
| 47 | device_iq151cart_interface( mconfig, *this ), |
| 48 | m_ppi8255(*this, "ppi8255") |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | //------------------------------------------------- |
| 53 | // device_start - device-specific startup |
| 54 | //------------------------------------------------- |
| 55 | |
| 56 | void iq151_grafik_device::device_start() |
| 57 | { |
| 58 | // allocate the videoram |
| 59 | m_videoram = (UINT8*)auto_alloc_array_clear(machine(), UINT8, 0x4000); |
| 60 | } |
| 61 | |
| 62 | //------------------------------------------------- |
| 63 | // device_reset - device-specific reset |
| 64 | //------------------------------------------------- |
| 65 | |
| 66 | void iq151_grafik_device::device_reset() |
| 67 | { |
| 68 | screen_device *screen = machine().primary_screen; |
| 69 | |
| 70 | // if required adjust screen size |
| 71 | if (screen->visible_area().max_x < 64*8-1) |
| 72 | screen->set_visible_area(0, 64*8-1, 0, 32*8-1); |
| 73 | |
| 74 | memset(m_videoram, 0x00, 0x4000); |
| 75 | } |
| 76 | |
| 77 | //------------------------------------------------- |
| 78 | // device_mconfig_additions |
| 79 | //------------------------------------------------- |
| 80 | |
| 81 | machine_config_constructor iq151_grafik_device::device_mconfig_additions() const |
| 82 | { |
| 83 | return MACHINE_CONFIG_NAME( iq151_grafik ); |
| 84 | } |
| 85 | |
| 86 | //------------------------------------------------- |
| 87 | // I8255 port a |
| 88 | //------------------------------------------------- |
| 89 | |
| 90 | WRITE8_MEMBER(iq151_grafik_device::x_write) |
| 91 | { |
| 92 | if (LOG) logerror("Grafik: set posx 0x%02x\n", data); |
| 93 | |
| 94 | m_posx = data & 0x3f; |
| 95 | } |
| 96 | |
| 97 | //------------------------------------------------- |
| 98 | // I8255 port b |
| 99 | //------------------------------------------------- |
| 100 | |
| 101 | WRITE8_MEMBER(iq151_grafik_device::y_write) |
| 102 | { |
| 103 | if (LOG) logerror("Grafik: set posy 0x%02x\n", data); |
| 104 | |
| 105 | m_posy = data; |
| 106 | } |
| 107 | |
| 108 | //------------------------------------------------- |
| 109 | // I8255 port c |
| 110 | //------------------------------------------------- |
| 111 | |
| 112 | WRITE8_MEMBER(iq151_grafik_device::control_w) |
| 113 | { |
| 114 | if (LOG) logerror("Grafik: control write 0x%02x\n", data); |
| 115 | |
| 116 | m_all = BIT(data, 0); |
| 117 | m_pen = BIT(data, 1); |
| 118 | m_fast = BIT(data, 2); |
| 119 | m_ev = BIT(data, 3); |
| 120 | m_ex = (data>>4) & 0x03; |
| 121 | m_sel = BIT(data, 7); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | //------------------------------------------------- |
| 126 | // IO read |
| 127 | //------------------------------------------------- |
| 128 | |
| 129 | void iq151_grafik_device::io_read(offs_t offset, UINT8 &data) |
| 130 | { |
| 131 | if (offset >= 0xd0 && offset < 0xd4) |
| 132 | { |
| 133 | address_space* space = machine().device("maincpu")->memory().space(AS_IO); |
| 134 | data = m_ppi8255->read(*space, offset & 3); |
| 135 | } |
| 136 | else if (offset == 0xd4) |
| 137 | { |
| 138 | if (LOG) logerror("Grafik: vram read 0x%04x\n", m_posx + 0x40 * m_posy); |
| 139 | |
| 140 | if (m_sel) |
| 141 | data = m_videoram[m_posx + 0x40 * m_posy]; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | //------------------------------------------------- |
| 146 | // IO write |
| 147 | //------------------------------------------------- |
| 148 | |
| 149 | void iq151_grafik_device::io_write(offs_t offset, UINT8 data) |
| 150 | { |
| 151 | if (offset >= 0xd0 && offset < 0xd4) |
| 152 | { |
| 153 | address_space* space = machine().device("maincpu")->memory().space(AS_IO); |
| 154 | m_ppi8255->write(*space, offset & 3, data); |
| 155 | } |
| 156 | else if (offset == 0xd4) |
| 157 | { |
| 158 | if (m_sel) |
| 159 | { |
| 160 | if (LOG) logerror("Grafik: vram write 0x%04x 0x%02x\n", m_posx + 0x40 * m_posy, data); |
| 161 | |
| 162 | if (m_all) |
| 163 | { |
| 164 | m_videoram[m_posx + 0x40 * m_posy] = data; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | if (m_pen) |
| 169 | m_videoram[m_posx + 0x40 * m_posy] &= ~(1 << (data >> 5)); |
| 170 | else |
| 171 | m_videoram[m_posx + 0x40 * m_posy] |= (1 << (data >> 5)); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | //------------------------------------------------- |
| 179 | // video update |
| 180 | //------------------------------------------------- |
| 181 | |
| 182 | void iq151_grafik_device::video_update(bitmap_t &bitmap, const rectangle &cliprect) |
| 183 | { |
| 184 | if (m_ev) |
| 185 | { |
| 186 | for (int y = 0; y < 32*8; y++) |
| 187 | { |
| 188 | for (int x = 0; x < 64; x++) |
| 189 | { |
| 190 | for (int ra = 0; ra < 8; ra++) |
| 191 | { |
| 192 | *BITMAP_ADDR16(&bitmap, y, x*8 + ra) |= BIT(m_videoram[(32*8 -1 - y)*64 + x], ra); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
src/mess/video/iq151_grafik.h
| r0 | r13174 | |
| 1 | #pragma once |
| 2 | |
| 3 | #ifndef __IQ151_GRAFIK_H__ |
| 4 | #define __IQ151_GRAFIK_H__ |
| 5 | |
| 6 | #include "emu.h" |
| 7 | #include "machine/iq151cart.h" |
| 8 | #include "machine/i8255.h" |
| 9 | |
| 10 | //************************************************************************** |
| 11 | // TYPE DEFINITIONS |
| 12 | //************************************************************************** |
| 13 | |
| 14 | // ======================> iq151_grafik_device |
| 15 | |
| 16 | class iq151_grafik_device : |
| 17 | public device_t, |
| 18 | public device_iq151cart_interface |
| 19 | { |
| 20 | public: |
| 21 | // construction/destruction |
| 22 | iq151_grafik_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 23 | |
| 24 | // optional information overrides |
| 25 | virtual machine_config_constructor device_mconfig_additions() const; |
| 26 | |
| 27 | // ppi8255 callback |
| 28 | DECLARE_WRITE8_MEMBER(x_write); |
| 29 | DECLARE_WRITE8_MEMBER(y_write); |
| 30 | DECLARE_WRITE8_MEMBER(control_w); |
| 31 | |
| 32 | protected: |
| 33 | // device-level overrides |
| 34 | virtual void device_start(); |
| 35 | virtual void device_reset(); |
| 36 | virtual void device_config_complete() { m_shortname = "iq151_grafik"; } |
| 37 | |
| 38 | // iq151cart_interface overrides |
| 39 | virtual void io_read(offs_t offset, UINT8 &data); |
| 40 | virtual void io_write(offs_t offset, UINT8 data); |
| 41 | virtual void video_update(bitmap_t &bitmap, const rectangle &cliprect); |
| 42 | |
| 43 | private: |
| 44 | |
| 45 | required_device<i8255_device> m_ppi8255; |
| 46 | |
| 47 | UINT8 * m_videoram; |
| 48 | UINT8 m_posx; // horizontal position |
| 49 | UINT8 m_posy; // vertical position |
| 50 | UINT8 m_all; // 0: bit mode 1: byte mode |
| 51 | UINT8 m_pen; |
| 52 | UINT8 m_fast; |
| 53 | UINT8 m_ev; // enable video out |
| 54 | UINT8 m_ex; |
| 55 | UINT8 m_sel; // enable vram access |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | // device type definition |
| 60 | extern const device_type IQ151_GRAFIK; |
| 61 | |
| 62 | #endif /* __IQ151_GRAFIK_H__ */ |