src/emu/sound/cdp1864.c
| r11283 | r11284 | |
| 22 | 22 | |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | |
| 25 | 26 | #include "emu.h" |
| 26 | 27 | #include "cdp1864.h" |
| 27 | 28 | |
| 28 | | /*************************************************************************** |
| 29 | | PARAMETERS |
| 30 | | ***************************************************************************/ |
| 31 | 29 | |
| 30 | |
| 31 | //************************************************************************** |
| 32 | // MACROS / CONSTANTS |
| 33 | //************************************************************************** |
| 34 | |
| 32 | 35 | #define CDP1864_DEFAULT_LATCH 0x35 |
| 33 | 36 | |
| 34 | 37 | #define CDP1864_CYCLES_DMA_START 2*8 |
| r11283 | r11284 | |
| 37 | 40 | |
| 38 | 41 | static const int CDP1864_BACKGROUND_COLOR_SEQUENCE[] = { 2, 0, 1, 4 }; |
| 39 | 42 | |
| 40 | | /*************************************************************************** |
| 41 | | TYPE DEFINITIONS |
| 42 | | ***************************************************************************/ |
| 43 | 43 | |
| 44 | | typedef struct _cdp1864_t cdp1864_t; |
| 45 | | struct _cdp1864_t |
| 46 | | { |
| 47 | | devcb_resolved_read_line in_rdata_func; |
| 48 | | devcb_resolved_read_line in_bdata_func; |
| 49 | | devcb_resolved_read_line in_gdata_func; |
| 50 | | devcb_resolved_write_line out_int_func; |
| 51 | | devcb_resolved_write_line out_dmao_func; |
| 52 | | devcb_resolved_write_line out_efx_func; |
| 53 | 44 | |
| 54 | | screen_device *screen; /* screen */ |
| 55 | | bitmap_t *bitmap; /* bitmap */ |
| 56 | | sound_stream *stream; /* sound output */ |
| 45 | //************************************************************************** |
| 46 | // GLOBAL VARIABLES |
| 47 | //************************************************************************** |
| 57 | 48 | |
| 58 | | /* video state */ |
| 59 | | int disp; /* display on */ |
| 60 | | int dmaout; /* DMA request active */ |
| 61 | | int bgcolor; /* background color */ |
| 62 | | int con; /* color on */ |
| 49 | // devices |
| 50 | const device_type CDP1864 = cdp1864_device_config::static_alloc_device_config; |
| 63 | 51 | |
| 64 | | /* sound state */ |
| 65 | | int aoe; /* audio on */ |
| 66 | | int latch; /* sound latch */ |
| 67 | | INT16 signal; /* current signal */ |
| 68 | | int incr; /* initial wave state */ |
| 69 | 52 | |
| 70 | | /* timers */ |
| 71 | | emu_timer *int_timer; /* interrupt timer */ |
| 72 | | emu_timer *efx_timer; /* EFx timer */ |
| 73 | | emu_timer *dma_timer; /* DMA timer */ |
| 74 | 53 | |
| 75 | | device_t *cpu; |
| 76 | | }; |
| 54 | //************************************************************************** |
| 55 | // DEVICE CONFIGURATION |
| 56 | //************************************************************************** |
| 77 | 57 | |
| 78 | | /*************************************************************************** |
| 79 | | INLINE FUNCTIONS |
| 80 | | ***************************************************************************/ |
| 81 | 58 | |
| 82 | | INLINE cdp1864_t *get_safe_token(device_t *device) |
| 59 | //------------------------------------------------- |
| 60 | // cdp1864_device_config - constructor |
| 61 | //------------------------------------------------- |
| 62 | |
| 63 | cdp1864_device_config::cdp1864_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 64 | : device_config(mconfig, static_alloc_device_config, "CDP1864", tag, owner, clock), |
| 65 | device_config_sound_interface(mconfig, *this) |
| 83 | 66 | { |
| 84 | | assert(device != NULL); |
| 85 | | return (cdp1864_t *)downcast<legacy_device_base *>(device)->token(); |
| 86 | 67 | } |
| 87 | 68 | |
| 88 | | /*************************************************************************** |
| 89 | | IMPLEMENTATION |
| 90 | | ***************************************************************************/ |
| 91 | 69 | |
| 92 | | /*------------------------------------------------- |
| 93 | | TIMER_CALLBACK( cdp1864_int_tick ) |
| 94 | | -------------------------------------------------*/ |
| 70 | //------------------------------------------------- |
| 71 | // static_alloc_device_config - allocate a new |
| 72 | // configuration object |
| 73 | //------------------------------------------------- |
| 95 | 74 | |
| 96 | | static TIMER_CALLBACK( cdp1864_int_tick ) |
| 75 | device_config *cdp1864_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 97 | 76 | { |
| 98 | | device_t *device = (device_t *) ptr; |
| 99 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 77 | return global_alloc(cdp1864_device_config(mconfig, tag, owner, clock)); |
| 78 | } |
| 100 | 79 | |
| 101 | | int scanline = cdp1864->screen->vpos(); |
| 102 | 80 | |
| 103 | | if (scanline == CDP1864_SCANLINE_INT_START) |
| 104 | | { |
| 105 | | if (cdp1864->disp) |
| 106 | | { |
| 107 | | devcb_call_write_line(&cdp1864->out_int_func, ASSERT_LINE); |
| 108 | | } |
| 81 | //------------------------------------------------- |
| 82 | // alloc_device - allocate a new device object |
| 83 | //------------------------------------------------- |
| 109 | 84 | |
| 110 | | cdp1864->int_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_INT_END)); |
| 111 | | } |
| 112 | | else |
| 113 | | { |
| 114 | | if (cdp1864->disp) |
| 115 | | { |
| 116 | | devcb_call_write_line(&cdp1864->out_int_func, CLEAR_LINE); |
| 117 | | } |
| 118 | | |
| 119 | | cdp1864->int_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_INT_START)); |
| 120 | | } |
| 85 | device_t *cdp1864_device_config::alloc_device(running_machine &machine) const |
| 86 | { |
| 87 | return auto_alloc(machine, cdp1864_device(machine, *this)); |
| 121 | 88 | } |
| 122 | 89 | |
| 123 | | /*------------------------------------------------- |
| 124 | | TIMER_CALLBACK( cdp1864_efx_tick ) |
| 125 | | -------------------------------------------------*/ |
| 126 | 90 | |
| 127 | | static TIMER_CALLBACK( cdp1864_efx_tick ) |
| 91 | //------------------------------------------------- |
| 92 | // device_config_complete - perform any |
| 93 | // operations now that the configuration is |
| 94 | // complete |
| 95 | //------------------------------------------------- |
| 96 | |
| 97 | void cdp1864_device_config::device_config_complete() |
| 128 | 98 | { |
| 129 | | device_t *device = (device_t *) ptr; |
| 130 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 99 | // inherit a copy of the static data |
| 100 | const cdp1864_interface *intf = reinterpret_cast<const cdp1864_interface *>(static_config()); |
| 101 | if (intf != NULL) |
| 102 | *static_cast<cdp1864_interface *>(this) = *intf; |
| 131 | 103 | |
| 132 | | int scanline = cdp1864->screen->vpos(); |
| 133 | | |
| 134 | | switch (scanline) |
| 104 | // or initialize to defaults if none provided |
| 105 | else |
| 135 | 106 | { |
| 136 | | case CDP1864_SCANLINE_EFX_TOP_START: |
| 137 | | devcb_call_write_line(&cdp1864->out_efx_func, ASSERT_LINE); |
| 138 | | cdp1864->efx_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_END)); |
| 139 | | break; |
| 140 | | |
| 141 | | case CDP1864_SCANLINE_EFX_TOP_END: |
| 142 | | devcb_call_write_line(&cdp1864->out_efx_func, CLEAR_LINE); |
| 143 | | cdp1864->efx_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_EFX_BOTTOM_START)); |
| 144 | | break; |
| 145 | | |
| 146 | | case CDP1864_SCANLINE_EFX_BOTTOM_START: |
| 147 | | devcb_call_write_line(&cdp1864->out_efx_func, ASSERT_LINE); |
| 148 | | cdp1864->efx_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_EFX_BOTTOM_END)); |
| 149 | | break; |
| 150 | | |
| 151 | | case CDP1864_SCANLINE_EFX_BOTTOM_END: |
| 152 | | devcb_call_write_line(&cdp1864->out_efx_func, CLEAR_LINE); |
| 153 | | cdp1864->efx_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_START)); |
| 154 | | break; |
| 107 | memset(&m_in_inlace_func, 0, sizeof(m_in_inlace_func)); |
| 108 | memset(&m_in_rdata_func, 0, sizeof(m_in_rdata_func)); |
| 109 | memset(&m_in_bdata_func, 0, sizeof(m_in_bdata_func)); |
| 110 | memset(&m_in_gdata_func, 0, sizeof(m_in_gdata_func)); |
| 111 | memset(&m_out_int_func, 0, sizeof(m_out_int_func)); |
| 112 | memset(&m_out_dmao_func, 0, sizeof(m_out_dmao_func)); |
| 113 | memset(&m_out_efx_func, 0, sizeof(m_out_efx_func)); |
| 114 | memset(&m_out_hsync_func, 0, sizeof(m_out_hsync_func)); |
| 155 | 115 | } |
| 156 | 116 | } |
| 157 | 117 | |
| 158 | | /*------------------------------------------------- |
| 159 | | TIMER_CALLBACK( cdp1864_dma_tick ) |
| 160 | | -------------------------------------------------*/ |
| 161 | 118 | |
| 162 | | static TIMER_CALLBACK( cdp1864_dma_tick ) |
| 163 | | { |
| 164 | | device_t *device = (device_t *) ptr; |
| 165 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 166 | 119 | |
| 167 | | int scanline = cdp1864->screen->vpos(); |
| 120 | //************************************************************************** |
| 121 | // INLINE HELPERS |
| 122 | //************************************************************************** |
| 168 | 123 | |
| 169 | | if (cdp1864->dmaout) |
| 170 | | { |
| 171 | | if (cdp1864->disp) |
| 172 | | { |
| 173 | | if (scanline >= CDP1864_SCANLINE_DISPLAY_START && scanline < CDP1864_SCANLINE_DISPLAY_END) |
| 174 | | { |
| 175 | | devcb_call_write_line(&cdp1864->out_dmao_func, CLEAR_LINE); |
| 176 | | } |
| 177 | | } |
| 124 | //------------------------------------------------- |
| 125 | // initialize_palette - |
| 126 | //------------------------------------------------- |
| 178 | 127 | |
| 179 | | cdp1864->dma_timer->adjust(machine.firstcpu->cycles_to_attotime(CDP1864_CYCLES_DMA_WAIT)); |
| 180 | | |
| 181 | | cdp1864->dmaout = 0; |
| 182 | | } |
| 183 | | else |
| 184 | | { |
| 185 | | if (cdp1864->disp) |
| 186 | | { |
| 187 | | if (scanline >= CDP1864_SCANLINE_DISPLAY_START && scanline < CDP1864_SCANLINE_DISPLAY_END) |
| 188 | | { |
| 189 | | devcb_call_write_line(&cdp1864->out_dmao_func, ASSERT_LINE); |
| 190 | | } |
| 191 | | } |
| 192 | | |
| 193 | | cdp1864->dma_timer->adjust(machine.firstcpu->cycles_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); |
| 194 | | |
| 195 | | cdp1864->dmaout = 1; |
| 196 | | } |
| 197 | | } |
| 198 | | |
| 199 | | /*------------------------------------------------- |
| 200 | | cdp1864_init_palette - initialize palette |
| 201 | | -------------------------------------------------*/ |
| 202 | | |
| 203 | | static void cdp1864_init_palette(device_t *device, const cdp1864_interface *intf) |
| 128 | inline void cdp1864_device::initialize_palette() |
| 204 | 129 | { |
| 205 | | int i; |
| 130 | double res_total = m_config.m_res_r + m_config.m_res_g + m_config.m_res_b + m_config.m_res_bkg; |
| 206 | 131 | |
| 207 | | double res_total = intf->res_r + intf->res_g + intf->res_b + intf->res_bkg; |
| 132 | int weight_r = (m_config.m_res_r / res_total) * 100; |
| 133 | int weight_g = (m_config.m_res_g / res_total) * 100; |
| 134 | int weight_b = (m_config.m_res_b / res_total) * 100; |
| 135 | int weight_bkg = (m_config.m_res_bkg / res_total) * 100; |
| 208 | 136 | |
| 209 | | int weight_r = (intf->res_r / res_total) * 100; |
| 210 | | int weight_g = (intf->res_g / res_total) * 100; |
| 211 | | int weight_b = (intf->res_b / res_total) * 100; |
| 212 | | int weight_bkg = (intf->res_bkg / res_total) * 100; |
| 213 | | |
| 214 | | for (i = 0; i < 16; i++) |
| 137 | for (int i = 0; i < 16; i++) |
| 215 | 138 | { |
| 216 | | int r, g, b, luma = 0; |
| 139 | int luma = 0; |
| 217 | 140 | |
| 218 | 141 | luma += (i & 4) ? weight_r : 0; |
| 219 | 142 | luma += (i & 1) ? weight_g : 0; |
| r11283 | r11284 | |
| 222 | 145 | |
| 223 | 146 | luma = (luma * 0xff) / 100; |
| 224 | 147 | |
| 225 | | r = (i & 4) ? luma : 0; |
| 226 | | g = (i & 1) ? luma : 0; |
| 227 | | b = (i & 2) ? luma : 0; |
| 148 | int r = (i & 4) ? luma : 0; |
| 149 | int g = (i & 1) ? luma : 0; |
| 150 | int b = (i & 2) ? luma : 0; |
| 228 | 151 | |
| 229 | | palette_set_color_rgb( device->machine(), i, r, g, b ); |
| 152 | palette_set_color_rgb(machine(), i, r, g, b); |
| 230 | 153 | } |
| 231 | 154 | } |
| 232 | 155 | |
| 233 | | /*------------------------------------------------- |
| 234 | | cdp1864_aoe_w - audio output enable |
| 235 | | -------------------------------------------------*/ |
| 236 | 156 | |
| 237 | | WRITE_LINE_DEVICE_HANDLER( cdp1864_aoe_w ) |
| 238 | | { |
| 239 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 240 | 157 | |
| 241 | | if (!state) |
| 242 | | { |
| 243 | | cdp1864->latch = CDP1864_DEFAULT_LATCH; |
| 244 | | } |
| 158 | //************************************************************************** |
| 159 | // LIVE DEVICE |
| 160 | //************************************************************************** |
| 245 | 161 | |
| 246 | | cdp1864->aoe = state; |
| 162 | //------------------------------------------------- |
| 163 | // cdp1864_device - constructor |
| 164 | //------------------------------------------------- |
| 165 | |
| 166 | cdp1864_device::cdp1864_device(running_machine &_machine, const cdp1864_device_config &config) |
| 167 | : device_t(_machine, config), |
| 168 | device_sound_interface(_machine, config, *this), |
| 169 | m_disp(0), |
| 170 | m_dmaout(0), |
| 171 | m_bgcolor(0), |
| 172 | m_con(0), |
| 173 | m_aoe(0), |
| 174 | m_latch(CDP1864_DEFAULT_LATCH), |
| 175 | m_config(config) |
| 176 | { |
| 247 | 177 | } |
| 248 | 178 | |
| 249 | | /*------------------------------------------------- |
| 250 | | cdp1864_dispon_r - turn display on |
| 251 | | -------------------------------------------------*/ |
| 252 | 179 | |
| 253 | | READ8_DEVICE_HANDLER( cdp1864_dispon_r ) |
| 180 | //------------------------------------------------- |
| 181 | // device_start - device-specific startup |
| 182 | //------------------------------------------------- |
| 183 | |
| 184 | void cdp1864_device::device_start() |
| 254 | 185 | { |
| 255 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 186 | // resolve callbacks |
| 187 | devcb_resolve_read_line(&m_in_inlace_func, &m_config.m_in_inlace_func, this); |
| 188 | devcb_resolve_read_line(&m_in_rdata_func, &m_config.m_in_rdata_func, this); |
| 189 | devcb_resolve_read_line(&m_in_bdata_func, &m_config.m_in_bdata_func, this); |
| 190 | devcb_resolve_read_line(&m_in_gdata_func, &m_config.m_in_gdata_func, this); |
| 191 | devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this); |
| 192 | devcb_resolve_write_line(&m_out_dmao_func, &m_config.m_out_dmao_func, this); |
| 193 | devcb_resolve_write_line(&m_out_efx_func, &m_config.m_out_efx_func, this); |
| 194 | devcb_resolve_write_line(&m_out_hsync_func, &m_config.m_out_hsync_func, this); |
| 256 | 195 | |
| 257 | | cdp1864->disp = 1; |
| 196 | // initialize palette |
| 197 | initialize_palette(); |
| 258 | 198 | |
| 259 | | return 0xff; |
| 260 | | } |
| 199 | // create sound stream |
| 200 | m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); |
| 261 | 201 | |
| 262 | | /*------------------------------------------------- |
| 263 | | cdp1864_dispoff_r - turn display off |
| 264 | | -------------------------------------------------*/ |
| 202 | // allocate timers |
| 203 | m_int_timer = timer_alloc(TIMER_INT); |
| 204 | m_efx_timer = timer_alloc(TIMER_EFX); |
| 205 | m_dma_timer = timer_alloc(TIMER_DMA); |
| 206 | m_hsync_timer = timer_alloc(TIMER_HSYNC); |
| 265 | 207 | |
| 266 | | READ8_DEVICE_HANDLER( cdp1864_dispoff_r ) |
| 267 | | { |
| 268 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 208 | // find devices |
| 209 | m_cpu = machine().device<cpu_device>(m_config.m_cpu_tag); |
| 210 | m_screen = machine().device<screen_device>(m_config.m_screen_tag); |
| 211 | m_bitmap = auto_bitmap_alloc(machine(), m_screen->width(), m_screen->height(), m_screen->format()); |
| 269 | 212 | |
| 270 | | cdp1864->disp = 0; |
| 213 | // register for state saving |
| 214 | save_item(NAME(m_disp)); |
| 215 | save_item(NAME(m_dmaout)); |
| 216 | save_item(NAME(m_bgcolor)); |
| 217 | save_item(NAME(m_con)); |
| 218 | save_item(NAME(m_aoe)); |
| 219 | save_item(NAME(m_latch)); |
| 220 | save_item(NAME(m_signal)); |
| 221 | save_item(NAME(m_incr)); |
| 222 | } |
| 271 | 223 | |
| 272 | | devcb_call_write_line(&cdp1864->out_int_func, CLEAR_LINE); |
| 273 | | devcb_call_write_line(&cdp1864->out_dmao_func, CLEAR_LINE); |
| 274 | 224 | |
| 275 | | return 0xff; |
| 276 | | } |
| 225 | //------------------------------------------------- |
| 226 | // device_reset - device-specific reset |
| 227 | //------------------------------------------------- |
| 277 | 228 | |
| 278 | | /*------------------------------------------------- |
| 279 | | cdp1864_step_bgcolor_w - step background color |
| 280 | | -------------------------------------------------*/ |
| 281 | | |
| 282 | | WRITE8_DEVICE_HANDLER( cdp1864_step_bgcolor_w ) |
| 229 | void cdp1864_device::device_reset() |
| 283 | 230 | { |
| 284 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 231 | m_int_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_INT_START, 0)); |
| 232 | m_efx_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_START, 0)); |
| 233 | m_dma_timer->adjust(m_cpu->cycles_to_attotime(CDP1864_CYCLES_DMA_START)); |
| 285 | 234 | |
| 286 | | cdp1864->disp = 1; |
| 235 | m_disp = 0; |
| 236 | m_dmaout = 0; |
| 287 | 237 | |
| 288 | | if (++cdp1864->bgcolor > 3) cdp1864->bgcolor = 0; |
| 238 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 239 | devcb_call_write_line(&m_out_dmao_func, CLEAR_LINE); |
| 240 | devcb_call_write_line(&m_out_efx_func, CLEAR_LINE); |
| 289 | 241 | } |
| 290 | 242 | |
| 291 | | /*------------------------------------------------- |
| 292 | | cdp1864_con_w - color on write |
| 293 | | -------------------------------------------------*/ |
| 294 | 243 | |
| 295 | | WRITE_LINE_DEVICE_HANDLER( cdp1864_con_w ) |
| 244 | //------------------------------------------------- |
| 245 | // device_timer - handle timer events |
| 246 | //------------------------------------------------- |
| 247 | |
| 248 | void cdp1864_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 296 | 249 | { |
| 297 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 250 | int scanline = m_screen->vpos(); |
| 298 | 251 | |
| 299 | | if (!state) |
| 252 | switch (id) |
| 300 | 253 | { |
| 301 | | cdp1864->con = 0; |
| 302 | | } |
| 303 | | } |
| 254 | case TIMER_INT: |
| 255 | if (scanline == CDP1864_SCANLINE_INT_START) |
| 256 | { |
| 257 | if (m_disp) |
| 258 | { |
| 259 | devcb_call_write_line(&m_out_int_func, ASSERT_LINE); |
| 260 | } |
| 304 | 261 | |
| 305 | | /*------------------------------------------------- |
| 306 | | cdp1864_tone_latch_w - load tone latch |
| 307 | | -------------------------------------------------*/ |
| 262 | m_int_timer->adjust(m_screen->time_until_pos( CDP1864_SCANLINE_INT_END, 0)); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | if (m_disp) |
| 267 | { |
| 268 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 269 | } |
| 308 | 270 | |
| 309 | | WRITE8_DEVICE_HANDLER( cdp1864_tone_latch_w ) |
| 310 | | { |
| 311 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 271 | m_int_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_INT_START, 0)); |
| 272 | } |
| 273 | break; |
| 312 | 274 | |
| 313 | | cdp1864->latch = data; |
| 314 | | } |
| 275 | case TIMER_EFX: |
| 276 | switch (scanline) |
| 277 | { |
| 278 | case CDP1864_SCANLINE_EFX_TOP_START: |
| 279 | devcb_call_write_line(&m_out_efx_func, ASSERT_LINE); |
| 280 | m_efx_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_END, 0)); |
| 281 | break; |
| 315 | 282 | |
| 316 | | /*------------------------------------------------- |
| 317 | | cdp1864_dma_w - write DMA byte |
| 318 | | -------------------------------------------------*/ |
| 283 | case CDP1864_SCANLINE_EFX_TOP_END: |
| 284 | devcb_call_write_line(&m_out_efx_func, CLEAR_LINE); |
| 285 | m_efx_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_EFX_BOTTOM_START, 0)); |
| 286 | break; |
| 319 | 287 | |
| 320 | | WRITE8_DEVICE_HANDLER( cdp1864_dma_w ) |
| 321 | | { |
| 322 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 288 | case CDP1864_SCANLINE_EFX_BOTTOM_START: |
| 289 | devcb_call_write_line(&m_out_efx_func, ASSERT_LINE); |
| 290 | m_efx_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_EFX_BOTTOM_END, 0)); |
| 291 | break; |
| 323 | 292 | |
| 324 | | int rdata = 1, bdata = 1, gdata = 1; |
| 325 | | int sx = cdp1864->screen->hpos() + 4; |
| 326 | | int y = cdp1864->screen->vpos(); |
| 327 | | int x; |
| 293 | case CDP1864_SCANLINE_EFX_BOTTOM_END: |
| 294 | devcb_call_write_line(&m_out_efx_func, CLEAR_LINE); |
| 295 | m_efx_timer->adjust(m_screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_START, 0)); |
| 296 | break; |
| 297 | } |
| 298 | break; |
| 328 | 299 | |
| 329 | | if (!cdp1864->con) |
| 330 | | { |
| 331 | | rdata = devcb_call_read_line(&cdp1864->in_rdata_func); |
| 332 | | bdata = devcb_call_read_line(&cdp1864->in_bdata_func); |
| 333 | | gdata = devcb_call_read_line(&cdp1864->in_gdata_func); |
| 334 | | } |
| 300 | case TIMER_DMA: |
| 301 | if (m_dmaout) |
| 302 | { |
| 303 | if (m_disp) |
| 304 | { |
| 305 | if (scanline >= CDP1864_SCANLINE_DISPLAY_START && scanline < CDP1864_SCANLINE_DISPLAY_END) |
| 306 | { |
| 307 | devcb_call_write_line(&m_out_dmao_func, CLEAR_LINE); |
| 308 | } |
| 309 | } |
| 335 | 310 | |
| 336 | | for (x = 0; x < 8; x++) |
| 337 | | { |
| 338 | | int color = CDP1864_BACKGROUND_COLOR_SEQUENCE[cdp1864->bgcolor] + 8; |
| 311 | m_dma_timer->adjust(m_cpu->cycles_to_attotime(CDP1864_CYCLES_DMA_WAIT)); |
| 339 | 312 | |
| 340 | | if (BIT(data, 7)) |
| 313 | m_dmaout = 0; |
| 314 | } |
| 315 | else |
| 341 | 316 | { |
| 342 | | color = (gdata << 2) | (bdata << 1) | rdata; |
| 343 | | } |
| 317 | if (m_disp) |
| 318 | { |
| 319 | if (scanline >= CDP1864_SCANLINE_DISPLAY_START && scanline < CDP1864_SCANLINE_DISPLAY_END) |
| 320 | { |
| 321 | devcb_call_write_line(&m_out_dmao_func, ASSERT_LINE); |
| 322 | } |
| 323 | } |
| 344 | 324 | |
| 345 | | *BITMAP_ADDR16(cdp1864->bitmap, y, sx + x) = color; |
| 325 | m_dma_timer->adjust(m_cpu->cycles_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); |
| 346 | 326 | |
| 347 | | data <<= 1; |
| 327 | m_dmaout = 1; |
| 328 | } |
| 329 | break; |
| 348 | 330 | } |
| 349 | 331 | } |
| 350 | 332 | |
| 351 | | /*------------------------------------------------- |
| 352 | | STREAM_UPDATE( cdp1864_stream_update ) |
| 353 | | -------------------------------------------------*/ |
| 354 | 333 | |
| 355 | | static STREAM_UPDATE( cdp1864_stream_update ) |
| 334 | //------------------------------------------------- |
| 335 | // sound_stream_update - handle update requests for |
| 336 | // our sound stream |
| 337 | //------------------------------------------------- |
| 338 | |
| 339 | void cdp1864_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 356 | 340 | { |
| 357 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 341 | // reset the output stream |
| 342 | memset(outputs[0], 0, samples * sizeof(*outputs[0])); |
| 358 | 343 | |
| 359 | | INT16 signal = cdp1864->signal; |
| 344 | INT16 signal = m_signal; |
| 360 | 345 | stream_sample_t *buffer = outputs[0]; |
| 361 | 346 | |
| 362 | 347 | memset( buffer, 0, samples * sizeof(*buffer) ); |
| 363 | 348 | |
| 364 | | if (cdp1864->aoe) |
| 349 | if (m_aoe) |
| 365 | 350 | { |
| 366 | | double frequency = cdp1864->cpu->unscaled_clock() / 8 / 4 / (cdp1864->latch + 1) / 2; |
| 367 | | int rate = device->machine().sample_rate() / 2; |
| 351 | double frequency = m_cpu->unscaled_clock() / 8 / 4 / (m_latch + 1) / 2; |
| 352 | int rate = machine().sample_rate() / 2; |
| 368 | 353 | |
| 369 | 354 | /* get progress through wave */ |
| 370 | | int incr = cdp1864->incr; |
| 355 | int incr = m_incr; |
| 371 | 356 | |
| 372 | 357 | if (signal < 0) |
| 373 | 358 | { |
| r11283 | r11284 | |
| 390 | 375 | } |
| 391 | 376 | |
| 392 | 377 | /* store progress through wave */ |
| 393 | | cdp1864->incr = incr; |
| 394 | | cdp1864->signal = signal; |
| 378 | m_incr = incr; |
| 379 | m_signal = signal; |
| 395 | 380 | } |
| 396 | 381 | } |
| 397 | 382 | |
| 398 | | /*------------------------------------------------- |
| 399 | | cdp1864_update - update screen |
| 400 | | -------------------------------------------------*/ |
| 401 | 383 | |
| 402 | | void cdp1864_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 384 | //------------------------------------------------- |
| 385 | // dispon_r - |
| 386 | //------------------------------------------------- |
| 387 | |
| 388 | READ8_MEMBER( cdp1864_device::dispon_r ) |
| 403 | 389 | { |
| 404 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 390 | m_disp = 1; |
| 405 | 391 | |
| 406 | | if (cdp1864->disp) |
| 407 | | { |
| 408 | | copybitmap(bitmap, cdp1864->bitmap, 0, 0, 0, 0, cliprect); |
| 409 | | bitmap_fill(cdp1864->bitmap, cliprect, CDP1864_BACKGROUND_COLOR_SEQUENCE[cdp1864->bgcolor] + 8); |
| 410 | | } |
| 411 | | else |
| 412 | | { |
| 413 | | bitmap_fill(bitmap, cliprect, get_black_pen(device->machine())); |
| 414 | | } |
| 392 | return 0xff; |
| 415 | 393 | } |
| 416 | 394 | |
| 417 | | /*------------------------------------------------- |
| 418 | | DEVICE_START( cdp1864 ) |
| 419 | | -------------------------------------------------*/ |
| 420 | 395 | |
| 421 | | static DEVICE_START( cdp1864 ) |
| 396 | //------------------------------------------------- |
| 397 | // dispoff_r - |
| 398 | //------------------------------------------------- |
| 399 | |
| 400 | READ8_MEMBER( cdp1864_device::dispoff_r ) |
| 422 | 401 | { |
| 423 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 424 | | const cdp1864_interface *intf = (const cdp1864_interface *) device->baseconfig().static_config(); |
| 402 | m_disp = 0; |
| 425 | 403 | |
| 426 | | /* resolve callbacks */ |
| 427 | | devcb_resolve_read_line(&cdp1864->in_rdata_func, &intf->in_rdata_func, device); |
| 428 | | devcb_resolve_read_line(&cdp1864->in_bdata_func, &intf->in_bdata_func, device); |
| 429 | | devcb_resolve_read_line(&cdp1864->in_gdata_func, &intf->in_gdata_func, device); |
| 430 | | devcb_resolve_write_line(&cdp1864->out_int_func, &intf->out_int_func, device); |
| 431 | | devcb_resolve_write_line(&cdp1864->out_dmao_func, &intf->out_dmao_func, device); |
| 432 | | devcb_resolve_write_line(&cdp1864->out_efx_func, &intf->out_efx_func, device); |
| 404 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 405 | devcb_call_write_line(&m_out_dmao_func, CLEAR_LINE); |
| 433 | 406 | |
| 434 | | /* get the cpu */ |
| 435 | | cdp1864->cpu = device->machine().device(intf->cpu_tag); |
| 407 | return 0xff; |
| 408 | } |
| 436 | 409 | |
| 437 | | /* get the screen device */ |
| 438 | | cdp1864->screen = downcast<screen_device *>(device->machine().device(intf->screen_tag)); |
| 439 | | assert(cdp1864->screen != NULL); |
| 440 | 410 | |
| 441 | | /* allocate the temporary bitmap */ |
| 442 | | cdp1864->bitmap = auto_bitmap_alloc(device->machine(), cdp1864->screen->width(), cdp1864->screen->height(), cdp1864->screen->format()); |
| 443 | | bitmap_fill(cdp1864->bitmap, 0, CDP1864_BACKGROUND_COLOR_SEQUENCE[cdp1864->bgcolor] + 8); |
| 411 | //------------------------------------------------- |
| 412 | // step_bgcolor_w - |
| 413 | //------------------------------------------------- |
| 444 | 414 | |
| 445 | | /* initialize the palette */ |
| 446 | | cdp1864_init_palette(device, intf); |
| 415 | WRITE8_MEMBER( cdp1864_device::step_bgcolor_w ) |
| 416 | { |
| 417 | m_disp = 1; |
| 447 | 418 | |
| 448 | | /* create sound stream */ |
| 449 | | cdp1864->stream = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), cdp1864, cdp1864_stream_update); |
| 419 | m_bgcolor++; |
| 450 | 420 | |
| 451 | | /* create the timers */ |
| 452 | | cdp1864->int_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1864_int_tick), (void *)device); |
| 453 | | cdp1864->efx_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1864_efx_tick), (void *)device); |
| 454 | | cdp1864->dma_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1864_dma_tick), (void *)device); |
| 421 | if (m_bgcolor > 3) |
| 422 | { |
| 423 | m_bgcolor = 0; |
| 424 | } |
| 425 | } |
| 455 | 426 | |
| 456 | | /* register for state saving */ |
| 457 | | device->save_item(NAME(cdp1864->disp)); |
| 458 | | device->save_item(NAME(cdp1864->dmaout)); |
| 459 | | device->save_item(NAME(cdp1864->bgcolor)); |
| 460 | | device->save_item(NAME(cdp1864->con)); |
| 461 | 427 | |
| 462 | | device->save_item(NAME(cdp1864->aoe)); |
| 463 | | device->save_item(NAME(cdp1864->latch)); |
| 464 | | device->save_item(NAME(cdp1864->signal)); |
| 465 | | device->save_item(NAME(cdp1864->incr)); |
| 428 | //------------------------------------------------- |
| 429 | // tone_latch_w - |
| 430 | //------------------------------------------------- |
| 466 | 431 | |
| 467 | | device->save_item(NAME(*cdp1864->bitmap)); |
| 432 | WRITE8_MEMBER( cdp1864_device::tone_latch_w ) |
| 433 | { |
| 434 | m_latch = data; |
| 468 | 435 | } |
| 469 | 436 | |
| 470 | | /*------------------------------------------------- |
| 471 | | DEVICE_RESET( cdp1864 ) |
| 472 | | -------------------------------------------------*/ |
| 473 | 437 | |
| 474 | | static DEVICE_RESET( cdp1864 ) |
| 438 | //------------------------------------------------- |
| 439 | // dma_w - |
| 440 | //------------------------------------------------- |
| 441 | |
| 442 | WRITE8_MEMBER( cdp1864_device::dma_w ) |
| 475 | 443 | { |
| 476 | | cdp1864_t *cdp1864 = get_safe_token(device); |
| 444 | int rdata = 1, bdata = 1, gdata = 1; |
| 445 | int sx = m_screen->hpos() + 4; |
| 446 | int y = m_screen->vpos(); |
| 477 | 447 | |
| 478 | | cdp1864->int_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_INT_START)); |
| 479 | | cdp1864->efx_timer->adjust(cdp1864->screen->time_until_pos(CDP1864_SCANLINE_EFX_TOP_START)); |
| 480 | | cdp1864->dma_timer->adjust(device->machine().firstcpu->cycles_to_attotime(CDP1864_CYCLES_DMA_START)); |
| 448 | if (!m_con) |
| 449 | { |
| 450 | rdata = devcb_call_read_line(&m_in_rdata_func); |
| 451 | bdata = devcb_call_read_line(&m_in_bdata_func); |
| 452 | gdata = devcb_call_read_line(&m_in_gdata_func); |
| 453 | } |
| 481 | 454 | |
| 482 | | cdp1864->disp = 0; |
| 483 | | cdp1864->dmaout = 0; |
| 484 | | cdp1864->bgcolor = 0; |
| 485 | | cdp1864->con = 1; |
| 455 | for (int x = 0; x < 8; x++) |
| 456 | { |
| 457 | int color = CDP1864_BACKGROUND_COLOR_SEQUENCE[m_bgcolor] + 8; |
| 486 | 458 | |
| 487 | | devcb_call_write_line(&cdp1864->out_int_func, CLEAR_LINE); |
| 488 | | devcb_call_write_line(&cdp1864->out_dmao_func, CLEAR_LINE); |
| 489 | | devcb_call_write_line(&cdp1864->out_efx_func, CLEAR_LINE); |
| 459 | if (BIT(data, 7)) |
| 460 | { |
| 461 | color = (gdata << 2) | (bdata << 1) | rdata; |
| 462 | } |
| 490 | 463 | |
| 491 | | cdp1864_aoe_w(device, 0); |
| 464 | *BITMAP_ADDR16(m_bitmap, y, sx + x) = color; |
| 465 | |
| 466 | data <<= 1; |
| 467 | } |
| 492 | 468 | } |
| 493 | 469 | |
| 494 | | /*------------------------------------------------- |
| 495 | | DEVICE_GET_INFO( cdp1864 ) |
| 496 | | -------------------------------------------------*/ |
| 497 | 470 | |
| 498 | | DEVICE_GET_INFO( cdp1864 ) |
| 471 | //------------------------------------------------- |
| 472 | // con_w - color on write |
| 473 | //------------------------------------------------- |
| 474 | |
| 475 | WRITE_LINE_MEMBER( cdp1864_device::con_w ) |
| 499 | 476 | { |
| 500 | | switch (state) |
| 477 | if (!state) |
| 501 | 478 | { |
| 502 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 503 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1864_t); break; |
| 504 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 479 | m_con = 0; |
| 480 | } |
| 481 | } |
| 505 | 482 | |
| 506 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 507 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1864); break; |
| 508 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 509 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cdp1864); break; |
| 510 | 483 | |
| 511 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 512 | | case DEVINFO_STR_NAME: strcpy(info->s, "RCA CDP1864"); break; |
| 513 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "RCA CDP1800"); break; |
| 514 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 515 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 516 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 484 | //------------------------------------------------- |
| 485 | // aoe_w - audio output enable write |
| 486 | //------------------------------------------------- |
| 487 | |
| 488 | WRITE_LINE_MEMBER( cdp1864_device::aoe_w ) |
| 489 | { |
| 490 | if (!state) |
| 491 | { |
| 492 | m_latch = CDP1864_DEFAULT_LATCH; |
| 517 | 493 | } |
| 494 | |
| 495 | m_aoe = state; |
| 518 | 496 | } |
| 519 | 497 | |
| 520 | 498 | |
| 521 | | DEFINE_LEGACY_SOUND_DEVICE(CDP1864, cdp1864); |
| 499 | //------------------------------------------------- |
| 500 | // evs_w - external vertical sync write |
| 501 | //------------------------------------------------- |
| 502 | |
| 503 | WRITE_LINE_MEMBER( cdp1864_device::evs_w ) |
| 504 | { |
| 505 | } |
| 506 | |
| 507 | |
| 508 | //------------------------------------------------- |
| 509 | // update_screen - |
| 510 | //------------------------------------------------- |
| 511 | |
| 512 | void cdp1864_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 513 | { |
| 514 | if (m_disp) |
| 515 | { |
| 516 | copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect); |
| 517 | bitmap_fill(m_bitmap, cliprect, CDP1864_BACKGROUND_COLOR_SEQUENCE[m_bgcolor] + 8); |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | bitmap_fill(bitmap, cliprect, get_black_pen(machine())); |
| 522 | } |
| 523 | } |
src/emu/sound/cdp1864.h
| r11283 | r11284 | |
| 6 | 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | |
| 8 | 8 | ********************************************************************** |
| 9 | | ________________ |
| 10 | | INLACE 1 ---| \/ |--- 40 Vdd |
| 11 | | CLK IN_ 2 ---| |--- 39 AUD |
| 12 | | CLR OUT_ 3 ---| |--- 38 CLR IN_ |
| 13 | | AOE 4 ---| |--- 37 DMA0_ |
| 14 | | SC1 5 ---| |--- 36 INT_ |
| 15 | | SC0 6 ---| |--- 35 TPA |
| 16 | | MRD_ 7 ---| |--- 34 TPB |
| 17 | | BUS 7 8 ---| |--- 33 EVS |
| 18 | | BUS 6 9 ---| |--- 32 V SYNC |
| 19 | | BUS 5 10 ---| CDP1864C |--- 31 H SYNC |
| 20 | | BUS 4 11 ---| top view |--- 30 C SYNC_ |
| 21 | | BUS 3 12 ---| |--- 29 RED |
| 22 | | BUS 2 13 ---| |--- 28 BLUE |
| 23 | | BUS 1 14 ---| |--- 27 GREEN |
| 24 | | BUS 0 15 ---| |--- 26 BCK GND_ |
| 25 | | CON_ 16 ---| |--- 25 BURST |
| 26 | | N2 17 ---| |--- 24 ALT |
| 27 | | EF_ 18 ---| |--- 23 R DATA |
| 28 | | N0 19 ---| |--- 22 G DATA |
| 29 | | Vss 20 ---|________________|--- 21 B DATA |
| 9 | _____ _____ |
| 10 | INLACE 1 |* \_/ | 40 Vdd |
| 11 | CLK IN_ 2 | | 39 AUD |
| 12 | CLR OUT_ 3 | | 38 CLR IN_ |
| 13 | AOE 4 | | 37 DMA0_ |
| 14 | SC1 5 | | 36 INT_ |
| 15 | SC0 6 | | 35 TPA |
| 16 | MRD_ 7 | | 34 TPB |
| 17 | BUS 7 8 | | 33 EVS |
| 18 | BUS 6 9 | | 32 V SYNC |
| 19 | BUS 5 10 | CDP1864 | 31 H SYNC |
| 20 | BUS 4 11 | | 30 C SYNC_ |
| 21 | BUS 3 12 | | 29 RED |
| 22 | BUS 2 13 | | 28 BLUE |
| 23 | BUS 1 14 | | 27 GREEN |
| 24 | BUS 0 15 | | 26 BCK GND_ |
| 25 | CON_ 16 | | 25 BURST |
| 26 | N2 17 | | 24 ALT |
| 27 | EF_ 18 | | 23 R DATA |
| 28 | N0 19 | | 22 G DATA |
| 29 | Vss 20 |_____________| 21 B DATA |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | http://homepage.mac.com/ruske/cosmacelf/cdp1864.pdf |
| 33 | 33 | |
| 34 | 34 | **********************************************************************/ |
| 35 | 35 | |
| 36 | #pragma once |
| 37 | |
| 36 | 38 | #ifndef __CDP1864__ |
| 37 | 39 | #define __CDP1864__ |
| 38 | 40 | |
| 39 | | #include "devlegcy.h" |
| 41 | #include "emu.h" |
| 40 | 42 | |
| 41 | 43 | |
| 42 | | /*************************************************************************** |
| 43 | | PARAMETERS |
| 44 | | ***************************************************************************/ |
| 45 | 44 | |
| 45 | //************************************************************************** |
| 46 | // MACROS / CONSTANTS |
| 47 | //************************************************************************** |
| 48 | |
| 46 | 49 | #define CDP1864_CLOCK XTAL_1_75MHz |
| 47 | 50 | |
| 48 | 51 | #define CDP1864_VISIBLE_COLUMNS 64 |
| r11283 | r11284 | |
| 71 | 74 | #define CDP1864_SCANLINE_EFX_BOTTOM_START CDP1864_SCANLINE_DISPLAY_END - 4 |
| 72 | 75 | #define CDP1864_SCANLINE_EFX_BOTTOM_END CDP1864_SCANLINE_DISPLAY_END |
| 73 | 76 | |
| 74 | | /*************************************************************************** |
| 75 | | MACROS / CONSTANTS |
| 76 | | ***************************************************************************/ |
| 77 | 77 | |
| 78 | | DECLARE_LEGACY_SOUND_DEVICE(CDP1864, cdp1864); |
| 79 | 78 | |
| 79 | //************************************************************************** |
| 80 | // INTERFACE CONFIGURATION MACROS |
| 81 | //************************************************************************** |
| 82 | |
| 80 | 83 | #define MCFG_CDP1864_ADD(_tag, _clock, _config) \ |
| 81 | 84 | MCFG_SOUND_ADD(_tag, CDP1864, _clock) \ |
| 82 | 85 | MCFG_DEVICE_CONFIG(_config) |
| 83 | 86 | |
| 87 | |
| 84 | 88 | #define MCFG_CDP1864_SCREEN_ADD(_tag, _clock) \ |
| 85 | 89 | MCFG_SCREEN_ADD(_tag, RASTER) \ |
| 86 | 90 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) \ |
| 87 | 91 | MCFG_SCREEN_RAW_PARAMS(_clock, CDP1864_SCREEN_WIDTH, CDP1864_HBLANK_END, CDP1864_HBLANK_START, CDP1864_TOTAL_SCANLINES, CDP1864_SCANLINE_VBLANK_END, CDP1864_SCANLINE_VBLANK_START) |
| 88 | 92 | |
| 93 | |
| 89 | 94 | #define CDP1864_INTERFACE(name) \ |
| 90 | 95 | const cdp1864_interface (name) = |
| 91 | 96 | |
| 92 | | /*************************************************************************** |
| 93 | | TYPE DEFINITIONS |
| 94 | | ***************************************************************************/ |
| 95 | 97 | |
| 96 | | enum _cdp1864_format { |
| 97 | | CDP1864_NON_INTERLACED = 0, |
| 98 | | CDP1864_INTERLACED |
| 99 | | }; |
| 100 | | typedef enum _cdp1864_format cdp1864_format; |
| 98 | #define CDP1864_NON_INTERLACED \ |
| 99 | DEVCB_LINE_VCC |
| 101 | 100 | |
| 102 | | typedef struct _cdp1864_interface cdp1864_interface; |
| 103 | | struct _cdp1864_interface |
| 101 | |
| 102 | #define CDP1864_INTERLACED \ |
| 103 | DEVCB_LINE_GND |
| 104 | |
| 105 | |
| 106 | |
| 107 | //************************************************************************** |
| 108 | // TYPE DEFINITIONS |
| 109 | //************************************************************************** |
| 110 | |
| 111 | // ======================> cdp1864_interface |
| 112 | |
| 113 | struct cdp1864_interface |
| 104 | 114 | { |
| 105 | | const char *cpu_tag; /* cpu we are working with */ |
| 106 | | const char *screen_tag; /* screen we are acting on */ |
| 115 | const char *m_cpu_tag; |
| 116 | const char *m_screen_tag; |
| 107 | 117 | |
| 108 | | cdp1864_format interlace; /* interlace */ |
| 118 | devcb_read_line m_in_inlace_func; |
| 109 | 119 | |
| 110 | | devcb_read_line in_rdata_func; |
| 111 | | devcb_read_line in_bdata_func; |
| 112 | | devcb_read_line in_gdata_func; |
| 120 | devcb_read_line m_in_rdata_func; |
| 121 | devcb_read_line m_in_bdata_func; |
| 122 | devcb_read_line m_in_gdata_func; |
| 113 | 123 | |
| 114 | | /* this gets called for every change of the INT pin (pin 36) */ |
| 115 | | devcb_write_line out_int_func; |
| 124 | devcb_write_line m_out_int_func; |
| 125 | devcb_write_line m_out_dmao_func; |
| 126 | devcb_write_line m_out_efx_func; |
| 127 | devcb_write_line m_out_hsync_func; |
| 116 | 128 | |
| 117 | | /* this gets called for every change of the DMAO pin (pin 37) */ |
| 118 | | devcb_write_line out_dmao_func; |
| 129 | double m_res_r; // red output resistor value |
| 130 | double m_res_g; // green output resistor value |
| 131 | double m_res_b; // blue output resistor value |
| 132 | double m_res_bkg; // background output resistor value |
| 133 | }; |
| 119 | 134 | |
| 120 | | /* this gets called for every change of the EFX pin (pin 18) */ |
| 121 | | devcb_write_line out_efx_func; |
| 122 | 135 | |
| 123 | | double res_r; /* red output resistor value */ |
| 124 | | double res_g; /* green output resistor value */ |
| 125 | | double res_b; /* blue output resistor value */ |
| 126 | | double res_bkg; /* background output resistor value */ |
| 136 | |
| 137 | // ======================> cdp1864_device_config |
| 138 | |
| 139 | class cdp1864_device_config : public device_config, |
| 140 | public device_config_sound_interface, |
| 141 | public cdp1864_interface |
| 142 | { |
| 143 | friend class cdp1864_device; |
| 144 | |
| 145 | // construction/destruction |
| 146 | cdp1864_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 147 | |
| 148 | public: |
| 149 | // allocators |
| 150 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 151 | virtual device_t *alloc_device(running_machine &machine) const; |
| 152 | |
| 153 | protected: |
| 154 | // device_config overrides |
| 155 | virtual void device_config_complete(); |
| 127 | 156 | }; |
| 128 | 157 | |
| 129 | | /*************************************************************************** |
| 130 | | PROTOTYPES |
| 131 | | ***************************************************************************/ |
| 132 | 158 | |
| 133 | | /* display on (0x69) */ |
| 134 | | READ8_DEVICE_HANDLER( cdp1864_dispon_r ) ATTR_NONNULL(1); |
| 135 | 159 | |
| 136 | | /* display off (0x6c) */ |
| 137 | | READ8_DEVICE_HANDLER( cdp1864_dispoff_r ) ATTR_NONNULL(1); |
| 160 | // ======================> cdp1864_device |
| 138 | 161 | |
| 139 | | /* step background color (0x61) */ |
| 140 | | WRITE8_DEVICE_HANDLER( cdp1864_step_bgcolor_w ) ATTR_NONNULL(1); |
| 162 | class cdp1864_device : public device_t, |
| 163 | public device_sound_interface |
| 164 | { |
| 165 | friend class cdp1864_device_config; |
| 141 | 166 | |
| 142 | | /* color on */ |
| 143 | | WRITE_LINE_DEVICE_HANDLER( cdp1864_con_w ) ATTR_NONNULL(1); |
| 167 | // construction/destruction |
| 168 | cdp1864_device(running_machine &_machine, const cdp1864_device_config &_config); |
| 144 | 169 | |
| 145 | | /* load tone latch (0x64) */ |
| 146 | | WRITE8_DEVICE_HANDLER( cdp1864_tone_latch_w ) ATTR_NONNULL(1); |
| 170 | public: |
| 171 | DECLARE_READ8_MEMBER( dispon_r ); |
| 172 | DECLARE_READ8_MEMBER( dispoff_r ); |
| 147 | 173 | |
| 148 | | /* audio output enable */ |
| 149 | | WRITE_LINE_DEVICE_HANDLER( cdp1864_aoe_w ) ATTR_NONNULL(1); |
| 174 | DECLARE_WRITE8_MEMBER( step_bgcolor_w ); |
| 175 | DECLARE_WRITE8_MEMBER( tone_latch_w ); |
| 150 | 176 | |
| 151 | | /* DMA write */ |
| 152 | | WRITE8_DEVICE_HANDLER( cdp1864_dma_w ) ATTR_NONNULL(1); |
| 177 | DECLARE_WRITE8_MEMBER( dma_w ); |
| 153 | 178 | |
| 154 | | /* screen update */ |
| 155 | | void cdp1864_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) ATTR_NONNULL(1) ATTR_NONNULL(2) ATTR_NONNULL(3); |
| 179 | DECLARE_WRITE_LINE_MEMBER( con_w ); |
| 180 | DECLARE_WRITE_LINE_MEMBER( aoe_w ); |
| 181 | DECLARE_WRITE_LINE_MEMBER( evs_w ); |
| 156 | 182 | |
| 183 | void update_screen(bitmap_t *bitmap, const rectangle *cliprect); |
| 184 | |
| 185 | protected: |
| 186 | // device-level overrides |
| 187 | virtual void device_start(); |
| 188 | virtual void device_reset(); |
| 189 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 190 | |
| 191 | // internal callbacks |
| 192 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 193 | |
| 194 | private: |
| 195 | inline void initialize_palette(); |
| 196 | |
| 197 | static const device_timer_id TIMER_INT = 0; |
| 198 | static const device_timer_id TIMER_EFX = 1; |
| 199 | static const device_timer_id TIMER_DMA = 2; |
| 200 | static const device_timer_id TIMER_HSYNC = 3; |
| 201 | |
| 202 | devcb_resolved_read_line m_in_inlace_func; |
| 203 | devcb_resolved_read_line m_in_rdata_func; |
| 204 | devcb_resolved_read_line m_in_bdata_func; |
| 205 | devcb_resolved_read_line m_in_gdata_func; |
| 206 | devcb_resolved_write_line m_out_int_func; |
| 207 | devcb_resolved_write_line m_out_dmao_func; |
| 208 | devcb_resolved_write_line m_out_efx_func; |
| 209 | devcb_resolved_write_line m_out_hsync_func; |
| 210 | |
| 211 | cpu_device *m_cpu; |
| 212 | screen_device *m_screen; // screen |
| 213 | bitmap_t *m_bitmap; // bitmap |
| 214 | sound_stream *m_stream; // sound output |
| 215 | |
| 216 | // video state |
| 217 | int m_disp; // display on |
| 218 | int m_dmaout; // DMA request active |
| 219 | int m_bgcolor; // background color |
| 220 | int m_con; // color on |
| 221 | |
| 222 | // sound state |
| 223 | int m_aoe; // audio on |
| 224 | int m_latch; // sound latch |
| 225 | INT16 m_signal; // current signal |
| 226 | int m_incr; // initial wave state |
| 227 | |
| 228 | // timers |
| 229 | emu_timer *m_int_timer; |
| 230 | emu_timer *m_efx_timer; |
| 231 | emu_timer *m_dma_timer; |
| 232 | emu_timer *m_hsync_timer; |
| 233 | |
| 234 | const cdp1864_device_config &m_config; |
| 235 | }; |
| 236 | |
| 237 | |
| 238 | // device type definition |
| 239 | extern const device_type CDP1864; |
| 240 | |
| 241 | |
| 242 | |
| 157 | 243 | #endif |