From 1859e012d294b3f93c0f466e3aa09825443c59c3 Mon Sep 17 00:00:00 2001 From: Curt Coder Date: Wed, 2 Apr 2008 14:43:06 +0000 Subject: [PATCH] - converted CDP1869 to the new device system - refactored to represent how the hardware actually works - added PMA latching on OUT5 - separated Cidelsa video to its own file --- .gitattributes | 2 + src/emu/video/cdp1869.c | 1018 ++++++++++++++++++++++------------- src/emu/video/cdp1869.h | 112 ++-- src/mame/drivers/cidelsa.c | 437 ++++++--------- src/mame/includes/cidelsa.h | 38 ++ src/mame/mame.mak | 2 +- src/mame/video/cidelsa.c | 298 ++++++++++ 7 files changed, 1230 insertions(+), 677 deletions(-) create mode 100644 src/mame/includes/cidelsa.h create mode 100644 src/mame/video/cidelsa.c diff --git a/.gitattributes b/.gitattributes index 2542d05c414..a40205cf5e4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2146,6 +2146,7 @@ src/mame/includes/ccastles.h svneol=native#text/plain src/mame/includes/cchasm.h svneol=native#text/plain src/mame/includes/cclimber.h svneol=native#text/plain src/mame/includes/centiped.h svneol=native#text/plain +src/mame/includes/cidelsa.h svneol=native#text/plain src/mame/includes/cinemat.h svneol=native#text/plain src/mame/includes/circus.h svneol=native#text/plain src/mame/includes/cloak.h svneol=native#text/plain @@ -2689,6 +2690,7 @@ src/mame/video/champbas.c svneol=native#text/plain src/mame/video/changela.c svneol=native#text/plain src/mame/video/cheekyms.c svneol=native#text/plain src/mame/video/chqflag.c svneol=native#text/plain +src/mame/video/cidelsa.c svneol=native#text/plain src/mame/video/cinemat.c svneol=native#text/plain src/mame/video/circus.c svneol=native#text/plain src/mame/video/circusc.c svneol=native#text/plain diff --git a/src/emu/video/cdp1869.c b/src/emu/video/cdp1869.c index 1002fcdde4a..82563f3ab20 100644 --- a/src/emu/video/cdp1869.c +++ b/src/emu/video/cdp1869.c @@ -1,5 +1,6 @@ #include "driver.h" -#include "deprecat.h" +#include "sndintrf.h" +#include "streams.h" #include "cpu/cdp1802/cdp1802.h" #include "video/cdp1869.h" #include "sound/cdp1869.h" @@ -8,34 +9,357 @@ TODO: - - convert CDP1869 into a device with video/sound - - add predisplay/display timers + - connect to sound system when possible + - white noise + - scanline based update + - fix flashing spaceship in destryer/altair + - fix flashing player in draco */ -typedef struct -{ - int ntsc_pal; - int dispoff; - int fresvert, freshorz; - int dblpage, line16, line9, cmem, cfc; - UINT8 col, bkg; - UINT16 pma, hma; - UINT8 cram[CDP1869_CHARRAM_SIZE]; - UINT8 pram[CDP1869_PAGERAM_SIZE]; - int cramsize, pramsize; - UINT8 (*color_callback)(UINT8 cramdata, UINT16 cramaddr, UINT16 pramaddr); -} CDP1869_VIDEO_CONFIG; +#define CDP1869_WEIGHT_RED 30 /* % of max luminance */ +#define CDP1869_WEIGHT_GREEN 59 +#define CDP1869_WEIGHT_BLUE 11 -static CDP1869_VIDEO_CONFIG cdp1869; +#define CDP1869_COLUMNS_HALF 20 +#define CDP1869_COLUMNS_FULL 40 +#define CDP1869_ROWS_HALF 12 +#define CDP1869_ROWS_FULL_PAL 25 +#define CDP1869_ROWS_FULL_NTSC 24 + +enum +{ + CDB0 = 0, + CDB1, + CDB2, + CDB3, + CDB4, + CDB5, + CCB0, + CCB1 +}; + +typedef struct _cdp1869_t cdp1869_t; +struct _cdp1869_t +{ + const cdp1869_interface *intf; /* interface */ + const device_config *screen; /* screen */ + sound_stream *stream; /* sound output */ + + /* video state */ + int dispoff; /* display off */ + int fresvert; /* full resolution vertical */ + int freshorz; /* full resolution horizontal */ + int cmem; /* character memory access mode */ + int dblpage; /* double page mode */ + int line16; /* 16-line hi-res mode */ + int line9; /* 9 line mode */ + int cfc; /* color format control */ + UINT8 col; /* character color control */ + UINT8 bkg; /* background color */ + UINT16 pma; /* page memory address */ + UINT16 hma; /* home memory address */ + + /* video timer */ + emu_timer *prd_changed_timer; /* predisplay changed timer */ + + /* sound state */ + INT16 signal; /* current signal */ + int incr; /* initial wave state */ + int toneoff; /* tone off */ + int wnoff; /* white noise off */ + UINT8 tonediv; /* tone divisor */ + UINT8 tonefreq; /* tone range select */ + UINT8 toneamp; /* tone output amplitude */ + UINT8 wnfreq; /* white noise range select */ + UINT8 wnamp; /* white noise output amplitude */ +}; + +INLINE cdp1869_t *get_safe_token(const device_config *device) +{ + assert(device != NULL); + assert(device->token != NULL); + + return (cdp1869_t *)device->token; +} + +/* Predisplay Timer */ + +static void update_prd_changed_timer(cdp1869_t *cdp1869) +{ + if (cdp1869->prd_changed_timer != NULL) + { + attotime duration; + int start, end, level; + int scanline = video_screen_get_vpos(cdp1869->screen); + int next_scanline; + + if (cdp1869->intf->pal_ntsc == CDP1869_NTSC) + { + start = CDP1869_SCANLINE_PREDISPLAY_START_NTSC; + end = CDP1869_SCANLINE_PREDISPLAY_END_NTSC; + } + else + { + start = CDP1869_SCANLINE_PREDISPLAY_START_PAL; + end = CDP1869_SCANLINE_PREDISPLAY_END_PAL; + } + + if (scanline < start) + { + next_scanline = start; + level = 0; + } + else if (scanline < end) + { + next_scanline = end; + level = 1; + } + else + { + next_scanline = start; + level = 0; + } + + if (cdp1869->dispoff) + { + level = 1; + } + + duration = video_screen_get_time_until_pos(cdp1869->screen, next_scanline, 0); + timer_adjust_oneshot(cdp1869->prd_changed_timer, duration, level); + } +} + +static TIMER_CALLBACK( prd_changed_tick ) +{ + const device_config *device = ptr; + cdp1869_t *cdp1869 = get_safe_token(device); + + /* call the callback function -- we know it exists */ + cdp1869->intf->on_prd_changed(device, param); + + update_prd_changed_timer(cdp1869); +} + +/* State Save Postload */ + +static void cdp1869_state_save_postload(void *param) +{ + update_prd_changed_timer(param); +} + +/* CDP1802 X Register */ static UINT16 cdp1802_get_r_x(void) { return activecpu_get_reg(CDP1802_R0 + activecpu_get_reg(CDP1802_X)); } -WRITE8_HANDLER ( cdp1869_out3_w ) +/* Palette Initialization */ + +static rgb_t cdp1869_get_rgb(int i, int c, int l) { + int luma = 0, r, g, b; + + luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; + luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; + luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; + + luma = (luma * 0xff) / 100; + + r = (c & 4) ? luma : 0; + g = (c & 1) ? luma : 0; + b = (c & 2) ? luma : 0; + + return MAKE_RGB(r, g, b); +} + +/* Screen Update */ + +static int cdp1869_get_lines(const device_config *device) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + if (cdp1869->line16 && !cdp1869->dblpage) + { + return 16; + } + else if (!cdp1869->line9) + { + return 9; + } + else + { + return 8; + } +} + +static UINT16 cdp1869_get_pmemsize(const device_config *device, int cols, int rows) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + int pmemsize = cols * rows; + + if (cdp1869->dblpage) pmemsize *= 2; + if (cdp1869->line16) pmemsize *= 2; + + return pmemsize; +} + +static UINT16 cdp1869_get_pma(const device_config *device) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + if (cdp1869->dblpage) + { + return cdp1869->pma; + } + else + { + return cdp1869->pma & 0x3ff; + } +} + +static int cdp1869_get_pen(const device_config *device, int ccb0, int ccb1, int pcb) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + int r = 0, g = 0, b = 0, color; + + switch (cdp1869->col) + { + case 0: + r = ccb0; + b = ccb1; + g = pcb; + break; + + case 1: + r = ccb0; + b = pcb; + g = ccb1; + break; + + case 2: + case 3: + r = pcb; + b = ccb0; + g = ccb1; + break; + } + + color = (r << 2) + (b << 1) + g; + + if (cdp1869->cfc) + { + return color + ((cdp1869->bkg + 1) * 8); + } + else + { + return color; + } +} + +static void cdp1869_draw_line(const device_config *device, bitmap_t *bitmap, int x, int y, int data, int color) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + int i; + + data <<= 2; + + for (i = 0; i < CDP1869_CHAR_WIDTH; i++) + { + if (data & 0x80) + { + *BITMAP_ADDR16(bitmap, y, x) = color; + + if (!cdp1869->fresvert) + { + *BITMAP_ADDR16(bitmap, y + 1, x) = color; + } + + if (!cdp1869->freshorz) + { + *BITMAP_ADDR16(bitmap, y, x + 1) = color; + + if (!cdp1869->fresvert) + { + *BITMAP_ADDR16(bitmap, y + 1, x + 1) = color; + } + } + } + + if (!cdp1869->freshorz) + { + x++; + } + + x++; + + data <<= 1; + } +} + +static void cdp1869_draw_char(const device_config *device, bitmap_t *bitmap, int x, int y, UINT16 pma, const rectangle *screenrect) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + UINT8 cma = 0; + + for (cma = 0; cma < cdp1869_get_lines(device); cma++) + { + UINT8 data = cdp1869->intf->char_ram_r(device, pma, cma); + + int ccb0 = BIT(data, CCB0); + int ccb1 = BIT(data, CCB1); + int pcb = cdp1869->intf->pcb_r(device, pma, cma); + + int color = cdp1869_get_pen(device, ccb0, ccb1, pcb); + + cdp1869_draw_line(device, bitmap, screenrect->min_x + x, screenrect->min_y + y, data, color); + + y++; + + if (!cdp1869->fresvert) + { + y++; + } + } +} + +/* Palette Initialization */ + +PALETTE_INIT( cdp1869 ) +{ + int i, c, l; + + // color-on-color display (CFC=0) + + for (i = 0; i < 8; i++) + { + palette_set_color(machine, i, cdp1869_get_rgb(i, i, 15)); + } + + // tone-on-tone display (CFC=1) + + for (c = 0; c < 8; c++) + { + for (l = 0; l < 8; l++) + { + palette_set_color(machine, i, cdp1869_get_rgb(i, c, l)); + i++; + } + } +} + +/* Register Access */ + +WRITE8_DEVICE_HANDLER( cdp1869_out3_w ) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + /* bit description @@ -49,15 +373,17 @@ WRITE8_HANDLER ( cdp1869_out3_w ) 7 fres horz */ - cdp1869.bkg = (data & 0x07); - cdp1869.cfc = (data & 0x08) >> 3; - cdp1869.dispoff = (data & 0x10) >> 4; - cdp1869.col = (data & 0x60) >> 5; - cdp1869.freshorz = (data & 0x80) >> 7; + cdp1869->bkg = data & 0x07; + cdp1869->cfc = BIT(data, 3); + cdp1869->dispoff = BIT(data, 4); + cdp1869->col = (data & 0x60) >> 5; + cdp1869->freshorz = BIT(data, 7); } -WRITE8_HANDLER ( cdp1869_out4_w ) +WRITE8_DEVICE_HANDLER( cdp1869_out4_w ) { + cdp1869_t *cdp1869 = get_safe_token(device); + UINT16 word = cdp1802_get_r_x(); /* @@ -81,14 +407,22 @@ WRITE8_HANDLER ( cdp1869_out4_w ) 15 always 0 */ - cdp1869_set_toneamp(0, word & 0x0f); - cdp1869_set_tonefreq(0, (word & 0x70) >> 4); - cdp1869_set_toneoff(0, (word & 0x80) >> 7); - cdp1869_set_tonediv(0, (word & 0x7f00) >> 8); + cdp1869->toneamp = word & 0x0f; + cdp1869->tonefreq = (word & 0x70) >> 4; + cdp1869->toneoff = BIT(word, 7); + cdp1869->tonediv = (word & 0x7f00) >> 8; + + // fork out to CDP1869 sound core + cdp1869_set_toneamp(0, cdp1869->toneamp); + cdp1869_set_tonefreq(0, cdp1869->tonefreq); + cdp1869_set_toneoff(0, cdp1869->toneoff); + cdp1869_set_tonediv(0, cdp1869->tonediv); } -WRITE8_HANDLER ( cdp1869_out5_w ) +WRITE8_DEVICE_HANDLER( cdp1869_out5_w ) { + cdp1869_t *cdp1869 = get_safe_token(device); + UINT16 word = cdp1802_get_r_x(); /* @@ -112,19 +446,40 @@ WRITE8_HANDLER ( cdp1869_out5_w ) 15 wn off */ - cdp1869.cmem = (word & 0x01); - cdp1869.line9 = (word & 0x08) >> 3; - cdp1869.line16 = (word & 0x20) >> 5; - cdp1869.dblpage = (word & 0x40) >> 6; - cdp1869.fresvert = (word & 0x80) >> 7; + cdp1869->cmem = BIT(word, 0); + cdp1869->line9 = BIT(word, 3); - cdp1869_set_wnamp(0, (word & 0x0f00) >> 8); - cdp1869_set_wnfreq(0, (word & 0x7000) >> 12); - cdp1869_set_wnoff(0, (word & 0x8000) >> 15); + if (cdp1869->intf->pal_ntsc == CDP1869_NTSC) + { + cdp1869->line16 = BIT(word, 5); + } + + cdp1869->dblpage = BIT(word, 6); + cdp1869->fresvert = BIT(word, 7); + + cdp1869->wnamp = (word & 0x0f00) >> 8; + cdp1869->wnfreq = (word & 0x7000) >> 12; + cdp1869->wnoff = BIT(word, 15); + + // fork out to CDP1869 sound core + cdp1869_set_wnamp(0, cdp1869->wnamp); + cdp1869_set_wnfreq(0, cdp1869->wnfreq); + cdp1869_set_wnoff(0, cdp1869->wnoff); + + if (cdp1869->cmem) + { + cdp1869->pma = word; + } + else + { + cdp1869->pma = 0; + } } -WRITE8_HANDLER ( cdp1869_out6_w ) +WRITE8_DEVICE_HANDLER( cdp1869_out6_w ) { + cdp1869_t *cdp1869 = get_safe_token(device); + UINT16 word = cdp1802_get_r_x(); /* @@ -148,11 +503,13 @@ WRITE8_HANDLER ( cdp1869_out6_w ) 15 x */ - cdp1869.pma = word & 0x7ff; + cdp1869->pma = word & 0x7ff; } -WRITE8_HANDLER ( cdp1869_out7_w ) +WRITE8_DEVICE_HANDLER( cdp1869_out7_w ) { + cdp1869_t *cdp1869 = get_safe_token(device); + UINT16 word = cdp1802_get_r_x(); /* @@ -176,143 +533,64 @@ WRITE8_HANDLER ( cdp1869_out7_w ) 15 x */ - cdp1869.hma = word & 0x7fc; + cdp1869->hma = word & 0x7fc; } -static void cdp1869_set_color(int i, int c, int l) +/* Page RAM Access */ + +READ8_DEVICE_HANDLER( cdp1869_pageram_r ) { - int luma = 0, r, g, b; + cdp1869_t *cdp1869 = get_safe_token(device); - luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; - luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; - luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; + UINT16 pma; - luma = (luma * 0xff) / 100; - - r = (c & 4) ? luma : 0; - g = (c & 1) ? luma : 0; - b = (c & 2) ? luma : 0; - - palette_set_color( Machine, i, MAKE_RGB(r, g, b) ); -} - -PALETTE_INIT( cdp1869 ) -{ - int i, c, l; - - // color-on-color display (CFC=0) - - for (i = 0; i < 8; i++) + if (cdp1869->cmem) { - cdp1869_set_color(i, i, 15); + pma = cdp1869_get_pma(device); + } + else + { + pma = offset; } - // tone-on-tone display (CFC=1) + return cdp1869->intf->page_ram_r(device, pma); +} - for (c = 0; c < 8; c++) +WRITE8_DEVICE_HANDLER( cdp1869_pageram_w ) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + UINT16 pma; + + if (cdp1869->cmem) { - for (l = 0; l < 8; l++) + pma = cdp1869_get_pma(device); + } + else + { + pma = offset; + } + + cdp1869->intf->page_ram_w(device, pma, data); +} + +/* Character RAM Access */ + +READ8_DEVICE_HANDLER( cdp1869_charram_r ) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + if (cdp1869->cmem) + { + UINT16 pma = cdp1869_get_pma(device); + UINT8 cma = offset & 0x0f; + + if (cdp1869_get_lines(device) == 8) { - cdp1869_set_color(i, c, l); - i++; + cma &= 0x07; } - } -} -static int cdp1869_get_lines(void) -{ - if (cdp1869.line16 && !cdp1869.dblpage) - { - return 16; - } - else if (!cdp1869.line9) - { - return 9; - } - else - { - return 8; - } -} - -static UINT16 cdp1869_get_pmemsize(int cols, int rows) -{ - int pmemsize = cols * rows; - - if (cdp1869.dblpage) pmemsize *= 2; - if (cdp1869.line16) pmemsize *= 2; - - return pmemsize; -} - -static UINT16 cdp1869_get_pma(void) -{ - if (cdp1869.dblpage) - { - return cdp1869.pma; - } - else - { - return cdp1869.pma & 0x3ff; - } -} - -UINT16 cdp1869_get_cma(UINT16 offset) -{ - int column = cdp1869.pram[cdp1869_get_pma()]; - int row = offset & 0x07; - - int addr = (column << 3) + row; - - if ((offset & 0x08) && (cdp1869_get_lines() > 8)) - { - addr += (CDP1869_CHARRAM_SIZE / 2); - } - - return addr; -} - -static UINT8 cdp1869_read_pageram(UINT16 addr) -{ - if (addr >= cdp1869.pramsize) - { - return 0xff; - } - else - { - return cdp1869.pram[addr]; - } -} - -#ifdef UNUSED_FUNCTION -UINT8 cdp1869_read_charram(UINT16 addr) -{ - if (addr >= cdp1869.cramsize) - { - return 0xff; - } - else - { - return cdp1869.cram[addr]; - } -} -#endif - -WRITE8_HANDLER ( cdp1869_charram_w ) -{ - if (cdp1869.cmem) - { - UINT16 addr = cdp1869_get_cma(offset); - cdp1869.cram[addr] = data; - } -} - -READ8_HANDLER ( cdp1869_charram_r ) -{ - if (cdp1869.cmem) - { - UINT16 addr = cdp1869_get_cma(offset); - return cdp1869.cram[addr]; + return cdp1869->intf->char_ram_r(device, pma, cma); } else { @@ -320,230 +598,85 @@ READ8_HANDLER ( cdp1869_charram_r ) } } -WRITE8_HANDLER ( cdp1869_pageram_w ) +WRITE8_DEVICE_HANDLER( cdp1869_charram_w ) { - UINT16 addr; + cdp1869_t *cdp1869 = get_safe_token(device); - if (cdp1869.cmem) + if (cdp1869->cmem) { - addr = cdp1869_get_pma(); - } - else - { - addr = offset; - } + UINT16 pma = cdp1869_get_pma(device); + UINT8 cma = offset & 0x0f; - cdp1869.pram[addr] = data; + if (cdp1869_get_lines(device) == 8) + { + cma &= 0x07; + } + + cdp1869->intf->char_ram_w(device, pma, cma, data); + } } -READ8_HANDLER ( cdp1869_pageram_r ) +/* Screen Update */ + +void cdp1869_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect) { - UINT16 addr; + cdp1869_t *cdp1869 = get_safe_token(device); - if (cdp1869.cmem) + rectangle screen_rect, outer; + + switch (cdp1869->intf->pal_ntsc) { - addr = cdp1869_get_pma(); - } - else - { - addr = offset; - } - - return cdp1869.pram[addr]; -} - -static int cdp1869_get_color(int ccb0, int ccb1, int pcb) -{ - int r = 0, g = 0, b = 0, color; - - switch (cdp1869.col) - { - case 0: - r = ccb0; - g = pcb; - b = ccb1; + case CDP1869_NTSC: + outer.min_x = CDP1869_HBLANK_END; + outer.max_x = CDP1869_HBLANK_START - 1; + outer.min_y = CDP1869_SCANLINE_VBLANK_END_NTSC; + outer.max_y = CDP1869_SCANLINE_VBLANK_START_NTSC - 1; + screen_rect.min_x = CDP1869_SCREEN_START_NTSC; + screen_rect.max_x = CDP1869_SCREEN_END - 1; + screen_rect.min_y = CDP1869_SCANLINE_DISPLAY_START_NTSC; + screen_rect.max_y = CDP1869_SCANLINE_DISPLAY_END_NTSC - 1; break; - case 1: - r = ccb0; - g = ccb1; - b = pcb; - break; - - case 2: - case 3: - r = pcb; - g = ccb1; - b = ccb0; + default: + case CDP1869_PAL: + outer.min_x = CDP1869_HBLANK_END; + outer.max_x = CDP1869_HBLANK_START - 1; + outer.min_y = CDP1869_SCANLINE_VBLANK_END_PAL; + outer.max_y = CDP1869_SCANLINE_VBLANK_START_PAL - 1; + screen_rect.min_x = CDP1869_SCREEN_START_PAL; + screen_rect.max_x = CDP1869_SCREEN_END - 1; + screen_rect.min_y = CDP1869_SCANLINE_DISPLAY_START_PAL; + screen_rect.max_y = CDP1869_SCANLINE_DISPLAY_END_PAL - 1; break; } - color = (r << 2) + (b << 1) + g; + sect_rect(&outer, cliprect); + fillbitmap(bitmap, device->machine->pens[cdp1869->bkg], &outer); - if (cdp1869.cfc) - { - return color + ((cdp1869.bkg + 1) * 8); - } - else - { - return color; - } -} - -static void cdp1869_draw_line(running_machine *machine, bitmap_t *bitmap, int x, int y, int data, int color) -{ - int i; - - data <<= 2; - - for (i = 0; i < CDP1869_CHAR_WIDTH; i++) - { - if (data & 0x80) - { - *BITMAP_ADDR16(bitmap, y, x) = machine->pens[color]; - - if (!cdp1869.fresvert) - { - *BITMAP_ADDR16(bitmap, y + 1, x) = machine->pens[color]; - } - - if (!cdp1869.freshorz) - { - *BITMAP_ADDR16(bitmap, y, x + 1) = machine->pens[color]; - - if (!cdp1869.fresvert) - { - *BITMAP_ADDR16(bitmap, y + 1, x + 1) = machine->pens[color]; - } - } - } - - if (!cdp1869.freshorz) - { - x++; - } - - x++; - - data <<= 1; - } -} - -static void cdp1869_draw_char(running_machine *machine, bitmap_t *bitmap, int x, int y, UINT16 pramaddr, const rectangle *screenrect) -{ - int i; - UINT8 code = cdp1869_read_pageram(pramaddr); - UINT16 addr = code * 8; - UINT16 addr2 = addr + (CDP1869_CHARRAM_SIZE / 2); - - for (i = 0; i < cdp1869_get_lines(); i++) - { - UINT8 data = cdp1869.cram[addr]; - - UINT8 colorbits = cdp1869.color_callback(data, addr, pramaddr); - - int pcb = colorbits & 0x01; - int ccb1 = (colorbits & 0x02) >> 1; - int ccb0 = (colorbits & 0x04) >> 2; - - int color = cdp1869_get_color(ccb0, ccb1, pcb); - - cdp1869_draw_line(machine, bitmap, screenrect->min_x + x, screenrect->min_y + y, data, color); - - addr++; - y++; - - if (!cdp1869.fresvert) - { - y++; - } - - if (i == 7) - { - addr = addr2; - } - } -} - -VIDEO_START( cdp1869 ) -{ - state_save_register_item("cdp1869", 0, cdp1869.ntsc_pal); - state_save_register_item("cdp1869", 0, cdp1869.dispoff); - state_save_register_item("cdp1869", 0, cdp1869.fresvert); - state_save_register_item("cdp1869", 0, cdp1869.freshorz); - state_save_register_item("cdp1869", 0, cdp1869.dblpage); - state_save_register_item("cdp1869", 0, cdp1869.line16); - state_save_register_item("cdp1869", 0, cdp1869.line9); - state_save_register_item("cdp1869", 0, cdp1869.cmem); - state_save_register_item("cdp1869", 0, cdp1869.cfc); - state_save_register_item("cdp1869", 0, cdp1869.col); - state_save_register_item("cdp1869", 0, cdp1869.bkg); - state_save_register_item("cdp1869", 0, cdp1869.pma); - state_save_register_item("cdp1869", 0, cdp1869.hma); - state_save_register_item_array("cdp1869", 0, cdp1869.cram); - state_save_register_item_array("cdp1869", 0, cdp1869.pram); - state_save_register_item("cdp1869", 0, cdp1869.cramsize); - state_save_register_item("cdp1869", 0, cdp1869.pramsize); -} - -VIDEO_UPDATE( cdp1869 ) -{ - fillbitmap(bitmap, get_black_pen(screen->machine), cliprect); - - if (!cdp1869.dispoff) + if (!cdp1869->dispoff) { int sx, sy, rows, cols, width, height; UINT16 addr, pmemsize; - rectangle screen_rect, outer; - - switch (cdp1869.ntsc_pal) - { - case CDP1869_NTSC: - outer.min_x = CDP1869_HBLANK_END; - outer.max_x = CDP1869_HBLANK_START - 1; - outer.min_y = CDP1869_SCANLINE_VBLANK_END_NTSC; - outer.max_y = CDP1869_SCANLINE_VBLANK_START_NTSC - 1; - screen_rect.min_x = CDP1869_SCREEN_START_NTSC; - screen_rect.max_x = CDP1869_SCREEN_END - 1; - screen_rect.min_y = CDP1869_SCANLINE_DISPLAY_START_NTSC; - screen_rect.max_y = CDP1869_SCANLINE_DISPLAY_END_NTSC - 1; - break; - - default: - case CDP1869_PAL: - outer.min_x = CDP1869_HBLANK_END; - outer.max_x = CDP1869_HBLANK_START - 1; - outer.min_y = CDP1869_SCANLINE_VBLANK_END_PAL; - outer.max_y = CDP1869_SCANLINE_VBLANK_START_PAL - 1; - screen_rect.min_x = CDP1869_SCREEN_START_PAL; - screen_rect.max_x = CDP1869_SCREEN_END - 1; - screen_rect.min_y = CDP1869_SCANLINE_DISPLAY_START_PAL; - screen_rect.max_y = CDP1869_SCANLINE_DISPLAY_END_PAL - 1; - break; - } - - sect_rect(&outer, cliprect); - fillbitmap(bitmap, screen->machine->pens[cdp1869.bkg], &outer); width = CDP1869_CHAR_WIDTH; - height = cdp1869_get_lines(); + height = cdp1869_get_lines(device); - if (!cdp1869.freshorz) + if (!cdp1869->freshorz) { width *= 2; } - if (!cdp1869.fresvert) + if (!cdp1869->fresvert) { height *= 2; } - cols = cdp1869.freshorz ? CDP1869_COLUMNS_FULL : CDP1869_COLUMNS_HALF; + cols = cdp1869->freshorz ? CDP1869_COLUMNS_FULL : CDP1869_COLUMNS_HALF; rows = (screen_rect.max_y - screen_rect.min_y + 1) / height; - pmemsize = cdp1869_get_pmemsize(cols, rows); + pmemsize = cdp1869_get_pmemsize(device, cols, rows); - addr = cdp1869.hma; + addr = cdp1869->hma; for (sy = 0; sy < rows; sy++) { @@ -552,7 +685,7 @@ VIDEO_UPDATE( cdp1869 ) int x = sx * width; int y = sy * height; - cdp1869_draw_char(screen->machine, bitmap, x, y, addr, &screen_rect); + cdp1869_draw_char(device, bitmap, x, y, addr, &screen_rect); addr++; @@ -560,20 +693,171 @@ VIDEO_UPDATE( cdp1869 ) } } } - - return 0; } -void cdp1869_configure(const CDP1869_interface *intf) +/* Sound Update */ + +#ifdef UNUSED_FUNCTION +static void cdp1869_sum_square_wave(stream_sample_t *buffer, double frequency, double amplitude) { - if (intf->charrom_region != REGION_INVALID) + // do a fast fourier transform on all the waves in the white noise range +} + +static void cdp1869_sound_update(const device_config *device, stream_sample_t **inputs, stream_sample_t **_buffer, int length) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + + INT16 signal = cdp1869->signal; + stream_sample_t *buffer = _buffer[0]; + + memset(buffer, 0, length * sizeof(*buffer)); + + if (!cdp1869->toneoff && cdp1869->toneamp) { - UINT8 *memory = memory_region(intf->charrom_region); - memcpy(cdp1869.cram, memory, intf->charram_size); + double frequency = (cdp1869->intf->pixel_clock / 2) / (512 >> cdp1869->tonefreq) / (cdp1869->tonediv + 1); + + int rate = device->machine->sample_rate / 2; + + /* get progress through wave */ + int incr = cdp1869->incr; + + if (signal < 0) + { + signal = -(cdp1869->toneamp * (0x07fff / 15)); + } + else + { + signal = cdp1869->toneamp * (0x07fff / 15); + } + + while( length-- > 0 ) + { + *buffer++ = signal; + incr -= frequency; + while( incr < 0 ) + { + incr += rate; + signal = -signal; + } + } + + /* store progress through wave */ + cdp1869->incr = incr; + cdp1869->signal = signal; } - cdp1869.ntsc_pal = intf->video_format; - cdp1869.cramsize = intf->charram_size; - cdp1869.pramsize = intf->pageram_size; - cdp1869.color_callback = intf->get_color_bits; + if (!cdp1869->wnoff) + { + int wndiv; + double amplitude = cdp1869->wnamp * ((0.78*5) / 15); + + for (wndiv = 0; wndiv < 128; wndiv++) + { + double frequency = (cdp1869->intf->pixel_clock / 2) / (4096 >> cdp1869->wnfreq) / (wndiv + 1); + + cdp1869_sum_square_wave(buffer, frequency, amplitude); + } + } +} +#endif + +/* Device Interface */ + +static DEVICE_START( cdp1869 ) +{ + cdp1869_t *cdp1869 = get_safe_token(device); + char unique_tag[30]; + + // validate arguments + + assert(device != NULL); + assert(device->tag != NULL); + assert(strlen(device->tag) < 20); + assert(device->static_config != NULL); + + cdp1869->intf = device->static_config; + + assert(cdp1869->intf->page_ram_r != NULL); + assert(cdp1869->intf->page_ram_w != NULL); + assert(cdp1869->intf->pcb_r != NULL); + assert(cdp1869->intf->char_ram_r != NULL); + assert(cdp1869->intf->char_ram_w != NULL); + + // set initial values + + cdp1869->toneoff = 1; + cdp1869->wnoff = 1; + + // get the screen device + + cdp1869->screen = device_list_find_by_tag(device->machine->config->devicelist, VIDEO_SCREEN, cdp1869->intf->screen_tag); + assert(cdp1869->screen != NULL); + + // allocate timers + + if (cdp1869->intf->on_prd_changed != NULL) + { + cdp1869->prd_changed_timer = timer_alloc(prd_changed_tick, (void *)device); + update_prd_changed_timer(cdp1869); + } + + // register for state saving + + state_save_combine_module_and_tag(unique_tag, "CDP1869", device->tag); + state_save_register_func_postload_ptr(cdp1869_state_save_postload, cdp1869); + + state_save_register_item(unique_tag, 0, cdp1869->dispoff); + state_save_register_item(unique_tag, 0, cdp1869->fresvert); + state_save_register_item(unique_tag, 0, cdp1869->freshorz); + state_save_register_item(unique_tag, 0, cdp1869->cmem); + state_save_register_item(unique_tag, 0, cdp1869->dblpage); + state_save_register_item(unique_tag, 0, cdp1869->line16); + state_save_register_item(unique_tag, 0, cdp1869->line9); + state_save_register_item(unique_tag, 0, cdp1869->cfc); + state_save_register_item(unique_tag, 0, cdp1869->col); + state_save_register_item(unique_tag, 0, cdp1869->bkg); + state_save_register_item(unique_tag, 0, cdp1869->pma); + state_save_register_item(unique_tag, 0, cdp1869->hma); + + state_save_register_item(unique_tag, 0, cdp1869->signal); + state_save_register_item(unique_tag, 0, cdp1869->incr); + state_save_register_item(unique_tag, 0, cdp1869->toneoff); + state_save_register_item(unique_tag, 0, cdp1869->wnoff); + state_save_register_item(unique_tag, 0, cdp1869->tonediv); + state_save_register_item(unique_tag, 0, cdp1869->tonefreq); + state_save_register_item(unique_tag, 0, cdp1869->toneamp); + state_save_register_item(unique_tag, 0, cdp1869->wnfreq); + state_save_register_item(unique_tag, 0, cdp1869->wnamp); +} + +static DEVICE_SET_INFO( cdp1869 ) +{ + switch (state) + { + /* no parameters to set */ + } +} + +DEVICE_GET_INFO( cdp1869_video ) +{ + switch (state) + { + /* --- the following bits of info are returned as 64-bit signed integers --- */ + case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1869_t); break; + case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; + case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; + + /* --- the following bits of info are returned as pointers to data or functions --- */ + case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(cdp1869); break; + case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1869); break; + case DEVINFO_FCT_STOP: /* Nothing */ break; + case DEVINFO_FCT_RESET: /* Nothing */ break; + + /* --- the following bits of info are returned as NULL-terminated strings --- */ + case DEVINFO_STR_NAME: info->s = "RCA CDP1869"; break; + case DEVINFO_STR_FAMILY: info->s = "RCA CDP1869"; break; + case DEVINFO_STR_VERSION: info->s = "1.0"; break; + case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; + case DEVINFO_STR_CREDITS: info->s = "Copyright Nicola Salmoria and the MAME Team"; break; + } } diff --git a/src/emu/video/cdp1869.h b/src/emu/video/cdp1869.h index 3320f020633..e5bb914abe2 100644 --- a/src/emu/video/cdp1869.h +++ b/src/emu/video/cdp1869.h @@ -34,13 +34,6 @@ #ifndef __CDP1869_VIDEO__ #define __CDP1869_VIDEO__ -typedef enum _cdp1869_video_format cdp1869_video_format; - -enum _cdp1869_video_format { - CDP1869_NTSC, - CDP1869_PAL -}; - #define CDP1869_DOT_CLK_PAL 5626000.0 #define CDP1869_DOT_CLK_NTSC 5670000.0 #define CDP1869_COLOR_CLK_PAL 8867236.0 @@ -54,8 +47,8 @@ enum _cdp1869_video_format { #define CDP1869_HSYNC_START (56 * CDP1869_CHAR_WIDTH) #define CDP1869_HSYNC_END (60 * CDP1869_CHAR_WIDTH) #define CDP1869_HBLANK_START (54 * CDP1869_CHAR_WIDTH) -#define CDP1869_HBLANK_END (5 * CDP1869_CHAR_WIDTH) -#define CDP1869_SCREEN_START_PAL (9 * CDP1869_CHAR_WIDTH) +#define CDP1869_HBLANK_END ( 5 * CDP1869_CHAR_WIDTH) +#define CDP1869_SCREEN_START_PAL ( 9 * CDP1869_CHAR_WIDTH) #define CDP1869_SCREEN_START_NTSC (10 * CDP1869_CHAR_WIDTH) #define CDP1869_SCREEN_START (10 * CDP1869_CHAR_WIDTH) #define CDP1869_SCREEN_END (50 * CDP1869_CHAR_WIDTH) @@ -83,48 +76,85 @@ enum _cdp1869_video_format { #define CDP1869_SCANLINE_PREDISPLAY_END_NTSC 228 #define CDP1869_VISIBLE_SCANLINES_NTSC (CDP1869_SCANLINE_DISPLAY_END_NTSC - CDP1869_SCANLINE_DISPLAY_START_NTSC) -#define CDP1869_FPS_PAL CDP1869_DOT_CLK_PAL / CDP1869_SCREEN_WIDTH / CDP1869_TOTAL_SCANLINES_PAL -#define CDP1869_FPS_NTSC CDP1869_DOT_CLK_NTSC / CDP1869_SCREEN_WIDTH / CDP1869_TOTAL_SCANLINES_NTSC +#define CDP1869_PALETTE_LENGTH 8+64 -#define CDP1869_WEIGHT_RED 30 // % of max luminance -#define CDP1869_WEIGHT_GREEN 59 -#define CDP1869_WEIGHT_BLUE 11 +#define CDP1869_VIDEO DEVICE_GET_INFO_NAME(cdp1869_video) -#define CDP1869_CHARRAM_SIZE 0x1000 -#define CDP1869_PAGERAM_SIZE 0x800 +typedef UINT8 (*cdp1869_char_ram_read_func)(const device_config *device, UINT16 pma, UINT8 cma); +#define CDP1869_CHAR_RAM_READ(name) UINT8 name(const device_config *device, UINT16 pma, UINT8 cma) -#define CDP1869_COLUMNS_HALF 20 -#define CDP1869_COLUMNS_FULL 40 -#define CDP1869_ROWS_HALF 12 -#define CDP1869_ROWS_FULL_PAL 25 -#define CDP1869_ROWS_FULL_NTSC 24 +typedef void (*cdp1869_char_ram_write_func)(const device_config *device, UINT16 pma, UINT8 cma, UINT8 data); +#define CDP1869_CHAR_RAM_WRITE(name) void name(const device_config *device, UINT16 pma, UINT8 cma, UINT8 data) -typedef struct CDP1869_interface +typedef UINT8 (*cdp1869_page_ram_read_func)(const device_config *device, UINT16 pma); +#define CDP1869_PAGE_RAM_READ(name) UINT8 name(const device_config *device, UINT16 pma) + +typedef void (*cdp1869_page_ram_write_func)(const device_config *device, UINT16 pma, UINT8 data); +#define CDP1869_PAGE_RAM_WRITE(name) void name(const device_config *device, UINT16 pma, UINT8 data) + +typedef int (*cdp1869_pcb_read_func)(const device_config *device, UINT16 pma, UINT8 cma); +#define CDP1869_PCB_READ(name) int name(const device_config *device, UINT16 pma, UINT8 cma) + +typedef void (*cdp1869_on_prd_changed_func) (const device_config *device, int prd); +#define CDP1869_ON_PRD_CHANGED(name) void name(const device_config *device, int prd) + +typedef enum _cdp1869_format cdp1869_format; +enum _cdp1869_format { + CDP1869_NTSC = 0, + CDP1869_PAL +}; + +/* interface */ +typedef struct _cdp1869_interface cdp1869_interface; +struct _cdp1869_interface { - cdp1869_video_format video_format; // display format (NTSC/PAL) - int charrom_region; // memory region to load CHARRAM from - UINT16 charram_size; // CHARRAM size - UINT16 pageram_size; // PAGERAM size - UINT8 (*get_color_bits)(UINT8 cramdata, UINT16 cramaddr, UINT16 pramaddr); // 0x01 = PCB, 0x02 = CCB0, 0x04 = CCB1 -} CDP1869_interface; + const char *screen_tag; /* screen we are acting on */ + int pixel_clock; /* the dot clock of the chip */ + int color_clock; /* the chroma clock of the chip */ -WRITE8_HANDLER ( cdp1869_out3_w ); -WRITE8_HANDLER ( cdp1869_out4_w ); -WRITE8_HANDLER ( cdp1869_out5_w ); -WRITE8_HANDLER ( cdp1869_out6_w ); -WRITE8_HANDLER ( cdp1869_out7_w ); + cdp1869_format pal_ntsc; /* screen format */ + /* page memory read function */ + cdp1869_page_ram_read_func page_ram_r; + + /* page memory write function */ + cdp1869_page_ram_write_func page_ram_w; + + /* page memory color bit read function */ + cdp1869_pcb_read_func pcb_r; + + /* character memory read function */ + cdp1869_char_ram_read_func char_ram_r; + + /* character memory write function */ + cdp1869_char_ram_write_func char_ram_w; + + /* if specified, this gets called for every change of the predisplay pin (CDP1870/76 pin 1) */ + cdp1869_on_prd_changed_func on_prd_changed; +}; + +/* device interface */ +DEVICE_GET_INFO( cdp1869_video ); + +/* palette initialization */ PALETTE_INIT( cdp1869 ); -VIDEO_START( cdp1869 ); -VIDEO_UPDATE( cdp1869 ); -READ8_HANDLER ( cdp1869_charram_r ); -READ8_HANDLER ( cdp1869_pageram_r ); -WRITE8_HANDLER ( cdp1869_charram_w ); -WRITE8_HANDLER ( cdp1869_pageram_w ); +/* io port access */ +WRITE8_DEVICE_HANDLER( cdp1869_out3_w ); +WRITE8_DEVICE_HANDLER( cdp1869_out4_w ); +WRITE8_DEVICE_HANDLER( cdp1869_out5_w ); +WRITE8_DEVICE_HANDLER( cdp1869_out6_w ); +WRITE8_DEVICE_HANDLER( cdp1869_out7_w ); -void cdp1869_configure(const CDP1869_interface *intf); +/* character memory access */ +READ8_DEVICE_HANDLER ( cdp1869_charram_r ); +WRITE8_DEVICE_HANDLER ( cdp1869_charram_w ); -UINT16 cdp1869_get_cma(UINT16 offset); +/* page memory access */ +READ8_DEVICE_HANDLER ( cdp1869_pageram_r ); +WRITE8_DEVICE_HANDLER ( cdp1869_pageram_w ); + +/* updates the screen */ +void cdp1869_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect); #endif diff --git a/src/mame/drivers/cidelsa.c b/src/mame/drivers/cidelsa.c index dc81fb64588..be055a3c384 100644 --- a/src/mame/drivers/cidelsa.c +++ b/src/mame/drivers/cidelsa.c @@ -1,9 +1,11 @@ #include "driver.h" +#include "deprecat.h" #include "cpu/cdp1802/cdp1802.h" #include "cpu/cop400/cop400.h" #include "video/cdp1869.h" #include "sound/cdp1869.h" #include "sound/ay8910.h" +#include "cidelsa.h" /* @@ -14,118 +16,137 @@ */ -#define DESTRYER_CHR1 3579000.0 // unverified -#define DESTRYER_CHR2 XTAL_5_7143MHz -#define ALTAIR_CHR1 3579000.0 // unverified -#define ALTAIR_CHR2 CDP1869_DOT_CLK_PAL // unverified -#define DRACO_CHR1 XTAL_4_43361MHz -#define DRACO_CHR2 CDP1869_DOT_CLK_PAL // unverified -#define DRACO_SND_CHR1 XTAL_2_01216MHz +#define CDP1869_TAG "cdp1869" /* CDP1802 Interface */ -static int cdp1869_prd; -static int cdp1869_pcb; -static UINT8 *pcb_ram; // 2048x1 bit PCB ram - -static int cdp1802_mode = CDP1802_MODE_RESET; - static UINT8 cidelsa_mode_r(void) { - return cdp1802_mode; + cidelsa_state *state = Machine->driver_data; + + return state->cdp1802_mode; } static UINT8 cidelsa_ef_r(void) { + /* + EF1 CDP1869 _PRD + EF2 Test + EF3 Coin 2 + EF4 Coin 1 + */ + return readinputportbytag("EF"); } +static void cidelsa_q_w(int q) +{ + cidelsa_state *state = Machine->driver_data; + + state->cdp1802_q = q; +} + static const CDP1802_CONFIG cidelsa_cdp1802_config = { - cidelsa_mode_r, // MODE input - cidelsa_ef_r, // EF input - NULL, // SC output - NULL, // Q output - NULL, // DMA read - NULL // DMA write + cidelsa_mode_r, // MODE + cidelsa_ef_r, // EF + NULL, // SC + cidelsa_q_w, // Q + NULL, // DMA read + NULL // DMA write }; -/* Draco Sound Interface */ +/* Sound Interface */ -static int draco_sound; -static int draco_ay_latch; - -static WRITE8_HANDLER ( draco_sound_bankswitch_w ) -{ - memory_set_bank(1, BIT(data, 3)); -} - -static WRITE8_HANDLER ( draco_sound_g_w ) +static WRITE8_HANDLER( draco_sound_bankswitch_w ) { /* - G1 G0 description + pin description - 0 0 IAB inactive - 0 1 DWS write to PSG - 1 0 DTB read from PSG - 1 1 INTAK latch address + D0 not connected + D1 not connected + D2 not connected + D3 2716 A10 + + */ + + int bank = BIT(data, 3); + + memory_set_bank(1, bank); +} + +static WRITE8_HANDLER( draco_sound_g_w ) +{ + cidelsa_state *state = machine->driver_data; + + /* + + G1 G0 description + + 0 0 IAB inactive + 0 1 DWS write to PSG + 1 0 DTB read from PSG + 1 1 INTAK latch address */ switch (data) { case 0x01: - AY8910_write_port_0_w(machine, 0, draco_ay_latch); + AY8910_write_port_0_w(machine, 0, state->draco_ay_latch); break; case 0x02: - draco_ay_latch = AY8910_read_port_0_r(machine, 0); + state->draco_ay_latch = AY8910_read_port_0_r(machine, 0); break; case 0x03: - AY8910_control_port_0_w(machine, 0, draco_ay_latch); + AY8910_control_port_0_w(machine, 0, state->draco_ay_latch); break; } } -static READ8_HANDLER ( draco_sound_in_r ) +static READ8_HANDLER( draco_sound_in_r ) { - return ~draco_sound & 0x07; // inverted + cidelsa_state *state = machine->driver_data; + + return ~(state->draco_sound) & 0x07; } -static READ8_HANDLER ( draco_sound_ay8910_r ) +static READ8_HANDLER( draco_sound_ay8910_r ) { - return draco_ay_latch; + cidelsa_state *state = machine->driver_data; + + return state->draco_ay_latch; } -static WRITE8_HANDLER ( draco_sound_ay8910_w ) +static WRITE8_HANDLER( draco_sound_ay8910_w ) { - draco_ay_latch = data; + cidelsa_state *state = machine->driver_data; + + state->draco_ay_latch = data; } -static WRITE8_HANDLER ( draco_ay8910_port_a_w ) +static WRITE8_HANDLER( draco_ay8910_port_a_w ) { /* - bit description - 0 N/C - 1 N/C - 2 N/C - 3 N/C - 4 N/C - 5 N/C - 6 N/C - 7 N/C - + 0 not connected + 1 not connected + 2 not connected + 3 not connected + 4 not connected + 5 not connected + 6 not connected + 7 not connected */ } -static WRITE8_HANDLER ( draco_ay8910_port_b_w ) +static WRITE8_HANDLER( draco_ay8910_port_b_w ) { /* - bit description 0 RELE0 @@ -133,27 +154,25 @@ static WRITE8_HANDLER ( draco_ay8910_port_b_w ) 2 sound output -> * -> 22K capacitor -> GND 3 sound output -> * -> 220K capacitor -> GND 4 5V -> 1K resistor -> * -> 10uF capacitor -> GND (volume pot voltage adjustment) - 5 N/C - 6 N/C - 7 N/C - + 5 not connected + 6 not connected + 7 not connected */ } static const struct AY8910interface ay8910_interface = { - 0, // port A read - 0, // port B read - draco_ay8910_port_a_w, // port A write - draco_ay8910_port_b_w // port B write + 0, + 0, + draco_ay8910_port_a_w, + draco_ay8910_port_b_w }; /* Read/Write Handlers */ -static WRITE8_HANDLER ( destryer_out1_w ) +static WRITE8_HANDLER( destryer_out1_w ) { /* - bit description 0 @@ -164,14 +183,12 @@ static WRITE8_HANDLER ( destryer_out1_w ) 5 6 7 - */ } -static WRITE8_HANDLER ( altair_out1_w ) +static WRITE8_HANDLER( altair_out1_w ) { /* - bit description 0 S1 (CARTUCHO) @@ -182,50 +199,31 @@ static WRITE8_HANDLER ( altair_out1_w ) 5 LGF 6 CONT. M2 7 CONT. M1 - */ - set_led_status(0, BIT(data, 3)); // 1P - set_led_status(1, BIT(data, 4)); // 2P - set_led_status(2, BIT(data, 5)); // FIRE + set_led_status(0, data & 0x08); // 1P + set_led_status(1, data & 0x10); // 2P + set_led_status(2, data & 0x20); // FIRE } -static WRITE8_HANDLER ( draco_out1_w ) +static WRITE8_HANDLER( draco_out1_w ) { - /* + cidelsa_state *state = machine->driver_data; + /* bit description 0 3K9 -> Green signal 1 820R -> Blue signal 2 510R -> Red signal - 3 1K -> N/C - 4 N/C + 3 1K -> not connected + 4 not connected 5 SONIDO A -> COP402 IN0 6 SONIDO B -> COP402 IN1 7 SONIDO C -> COP402 IN2 - */ - draco_sound = (data >> 5) & 0x07; -} - -static WRITE8_HANDLER ( cidelsa_charram_w ) -{ - int addr = cdp1869_get_cma(offset); - - pcb_ram[addr] = activecpu_get_reg(CDP1802_Q); - - cdp1869_charram_w(machine, offset, data); -} - -static READ8_HANDLER ( cidelsa_charram_r ) -{ - int addr = cdp1869_get_cma(offset); - - cdp1869_pcb = pcb_ram[addr]; - - return cdp1869_charram_r(machine, offset); + state->draco_sound = (data & 0xe0) >> 5; } /* Memory Maps */ @@ -235,25 +233,25 @@ static READ8_HANDLER ( cidelsa_charram_r ) static ADDRESS_MAP_START( destryer_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x1fff) AM_ROM AM_RANGE(0x2000, 0x20ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) - AM_RANGE(0xf400, 0xf7ff) AM_READWRITE(cidelsa_charram_r, cidelsa_charram_w) - AM_RANGE(0xf800, 0xffff) AM_READWRITE(cdp1869_pageram_r, cdp1869_pageram_w) + AM_RANGE(0xf400, 0xf7ff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_charram_r, cdp1869_charram_w) + AM_RANGE(0xf800, 0xffff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_pageram_r, cdp1869_pageram_w) ADDRESS_MAP_END static ADDRESS_MAP_START( destryea_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x1fff) AM_ROM AM_RANGE(0x3000, 0x30ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) - AM_RANGE(0xf400, 0xf7ff) AM_READWRITE(cidelsa_charram_r, cidelsa_charram_w) - AM_RANGE(0xf800, 0xffff) AM_READWRITE(cdp1869_pageram_r, cdp1869_pageram_w) + AM_RANGE(0xf400, 0xf7ff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_charram_r, cdp1869_charram_w) + AM_RANGE(0xf800, 0xffff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_pageram_r, cdp1869_pageram_w) ADDRESS_MAP_END static ADDRESS_MAP_START( destryer_io_map, ADDRESS_SPACE_IO, 8 ) AM_RANGE(0x01, 0x01) AM_READ_PORT("IN0") AM_WRITE(destryer_out1_w) AM_RANGE(0x02, 0x02) AM_READ_PORT("IN1") - AM_RANGE(0x03, 0x03) AM_WRITE(cdp1869_out3_w) - AM_RANGE(0x04, 0x04) AM_WRITE(cdp1869_out4_w) - AM_RANGE(0x05, 0x05) AM_WRITE(cdp1869_out5_w) - AM_RANGE(0x06, 0x06) AM_WRITE(cdp1869_out6_w) - AM_RANGE(0x07, 0x07) AM_WRITE(cdp1869_out7_w) + AM_RANGE(0x03, 0x03) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out3_w) + AM_RANGE(0x04, 0x04) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out4_w) + AM_RANGE(0x05, 0x05) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out5_w) + AM_RANGE(0x06, 0x06) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out6_w) + AM_RANGE(0x07, 0x07) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out7_w) ADDRESS_MAP_END // Altair @@ -261,18 +259,18 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( altair_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x2fff) AM_ROM AM_RANGE(0x3000, 0x30ff) AM_RAM - AM_RANGE(0xf400, 0xf7ff) AM_READWRITE(cidelsa_charram_r, cidelsa_charram_w) - AM_RANGE(0xf800, 0xffff) AM_READWRITE(cdp1869_pageram_r, cdp1869_pageram_w) + AM_RANGE(0xf400, 0xf7ff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_charram_r, cdp1869_charram_w) + AM_RANGE(0xf800, 0xffff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_pageram_r, cdp1869_pageram_w) ADDRESS_MAP_END static ADDRESS_MAP_START( altair_io_map, ADDRESS_SPACE_IO, 8 ) AM_RANGE(0x01, 0x01) AM_READ_PORT("IN0") AM_WRITE(altair_out1_w) AM_RANGE(0x02, 0x02) AM_READ_PORT("IN1") - AM_RANGE(0x03, 0x03) AM_WRITE(cdp1869_out3_w) - AM_RANGE(0x04, 0x04) AM_READ_PORT("IN2") AM_WRITE(cdp1869_out4_w) - AM_RANGE(0x05, 0x05) AM_WRITE(cdp1869_out5_w) - AM_RANGE(0x06, 0x06) AM_WRITE(cdp1869_out6_w) - AM_RANGE(0x07, 0x07) AM_WRITE(cdp1869_out7_w) + AM_RANGE(0x03, 0x03) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out3_w) + AM_RANGE(0x04, 0x04) AM_READ_PORT("IN2") AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out4_w) + AM_RANGE(0x05, 0x05) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out5_w) + AM_RANGE(0x06, 0x06) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out6_w) + AM_RANGE(0x07, 0x07) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out7_w) ADDRESS_MAP_END // Draco @@ -280,18 +278,18 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( draco_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x3fff) AM_ROM AM_RANGE(0x8000, 0x83ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) - AM_RANGE(0xf400, 0xf7ff) AM_READWRITE(cidelsa_charram_r, cidelsa_charram_w) - AM_RANGE(0xf800, 0xffff) AM_READWRITE(cdp1869_pageram_r, cdp1869_pageram_w) + AM_RANGE(0xf400, 0xf7ff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_charram_r, cdp1869_charram_w) + AM_RANGE(0xf800, 0xffff) AM_DEVREADWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_pageram_r, cdp1869_pageram_w) ADDRESS_MAP_END static ADDRESS_MAP_START( draco_io_map, ADDRESS_SPACE_IO, 8 ) AM_RANGE(0x01, 0x01) AM_READ_PORT("IN0") AM_WRITE(draco_out1_w) AM_RANGE(0x02, 0x02) AM_READ_PORT("IN1") - AM_RANGE(0x03, 0x03) AM_WRITE(cdp1869_out3_w) - AM_RANGE(0x04, 0x04) AM_READ_PORT("IN2") AM_WRITE(cdp1869_out4_w) - AM_RANGE(0x05, 0x05) AM_WRITE(cdp1869_out5_w) - AM_RANGE(0x06, 0x06) AM_WRITE(cdp1869_out6_w) - AM_RANGE(0x07, 0x07) AM_WRITE(cdp1869_out7_w) + AM_RANGE(0x03, 0x03) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out3_w) + AM_RANGE(0x04, 0x04) AM_READ_PORT("IN2") AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out4_w) + AM_RANGE(0x05, 0x05) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out5_w) + AM_RANGE(0x06, 0x06) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out6_w) + AM_RANGE(0x07, 0x07) AM_DEVWRITE(CDP1869_VIDEO, CDP1869_TAG, cdp1869_out7_w) ADDRESS_MAP_END static ADDRESS_MAP_START( draco_sound_map, ADDRESS_SPACE_PROGRAM, 8 ) @@ -311,12 +309,16 @@ ADDRESS_MAP_END static CUSTOM_INPUT( cdp1869_pcb_r ) { - return cdp1869_pcb; + cidelsa_state *state = machine->driver_data; + + return state->cdp1869_pcb; } static CUSTOM_INPUT( cdp1869_predisplay_r ) { - return cdp1869_prd; + cidelsa_state *state = machine->driver_data; + + return state->cdp1869_prd; } static INPUT_PORTS_START( destryer ) @@ -461,118 +463,49 @@ static INPUT_PORTS_START( draco ) PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 ) // M1 INPUT_PORTS_END -/* Video Timer Callbacks */ - -static TIMER_CALLBACK( altair_prd_start ) -{ - cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE); - cdp1869_prd = 1; // inverted -} - -static TIMER_CALLBACK( altair_prd_end ) -{ - cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, CLEAR_LINE); - cdp1869_prd = 0; // inverted -} - -static TIMER_CALLBACK( draco_prd_start ) -{ - cdp1869_prd = 0; -} - -static TIMER_CALLBACK( draco_prd_end ) -{ - cdp1869_prd = 1; -} - /* Machine Start */ static TIMER_CALLBACK( set_cpu_mode ) { - cdp1802_mode = CDP1802_MODE_RUN; + cidelsa_state *state = machine->driver_data; + + state->cdp1802_mode = CDP1802_MODE_RUN; } -static UINT8 cidelsa_get_color_bits(UINT8 cramdata, UINT16 cramaddr, UINT16 pramaddr) +static MACHINE_START( cidelsa ) { - int ccb0 = BIT(cramdata, 6); - int ccb1 = BIT(cramdata, 7); - int pcb = BIT(pcb_ram[cramaddr & 0x7ff], 0); + cidelsa_state *state = machine->driver_data; - return (ccb0 << 2) + (ccb1 << 1) + pcb; -} - -static const CDP1869_interface destryer_CDP1869_interface = -{ - CDP1869_PAL, // display format - REGION_INVALID, // character RAM region - 0x800, // character RAM size - 0x400, // page RAM size - cidelsa_get_color_bits // color callback function -}; - -static const CDP1869_interface draco_CDP1869_interface = -{ - CDP1869_PAL, // display format - REGION_INVALID, // character RAM region - 0x800, // character RAM size - 0x800, // page RAM size - cidelsa_get_color_bits // color callback function -}; - -static MACHINE_START( destryer ) -{ - // allocate PCB RAM - - pcb_ram = auto_malloc(0x800); - - // configure CDP1869 - - cdp1869_configure(&destryer_CDP1869_interface); - - // allocate one-shot CPU mode set timer + // reset the CPU + state->cdp1802_mode = CDP1802_MODE_RESET; timer_set(ATTOTIME_IN_MSEC(200), NULL, 0, set_cpu_mode); - // save state support + // register save states - state_save_register_global(cdp1802_mode); - state_save_register_global_pointer(pcb_ram, 0x800); - state_save_register_global(cdp1869_prd); - state_save_register_global(cdp1869_pcb); + state_save_register_global(state->cdp1802_mode); } static MACHINE_START( draco ) { - // configure COP402 ROM banking + cidelsa_state *state = machine->driver_data; - UINT8 *ROM = memory_region(REGION_CPU2); - memory_configure_bank(1, 0, 2, &ROM[0x000], 0x400); + MACHINE_START_CALL( cidelsa ); - // allocate PCB RAM + // COP402 memory banking - pcb_ram = auto_malloc(0x800); + memory_configure_bank(1, 0, 2, memory_region(REGION_CPU2), 0x400); + memory_set_bank(1, 0); - // configure CDP1869 + // register save states - cdp1869_configure(&draco_CDP1869_interface); - - // allocate one-shot CPU mode set timer - - timer_set(ATTOTIME_IN_MSEC(200), NULL, 0, set_cpu_mode); - - // save state support - - state_save_register_global(cdp1802_mode); - state_save_register_global_pointer(pcb_ram, 0x800); - state_save_register_global(cdp1869_prd); - state_save_register_global(cdp1869_pcb); - state_save_register_global(draco_sound); - state_save_register_global(draco_ay_latch); + state_save_register_global(state->draco_sound); + state_save_register_global(state->draco_ay_latch); } /* Machine Reset */ -static MACHINE_RESET( destryer ) +static MACHINE_RESET( cidelsa ) { cpunum_set_input_line(machine, 0, INPUT_LINE_RESET, PULSE_LINE); } @@ -580,6 +513,8 @@ static MACHINE_RESET( destryer ) /* Machine Drivers */ static MACHINE_DRIVER_START( destryer ) + MDRV_DRIVER_DATA(cidelsa_state) + // basic system hardware MDRV_CPU_ADD(CDP1802, DESTRYER_CHR1) @@ -587,23 +522,13 @@ static MACHINE_DRIVER_START( destryer ) MDRV_CPU_IO_MAP(destryer_io_map, 0) MDRV_CPU_CONFIG(cidelsa_cdp1802_config) MDRV_NVRAM_HANDLER(generic_0fill) - MDRV_MACHINE_START(destryer) - MDRV_MACHINE_RESET(destryer) + + MDRV_MACHINE_START(cidelsa) + MDRV_MACHINE_RESET(cidelsa) // video hardware - MDRV_PALETTE_LENGTH(8+64) - MDRV_PALETTE_INIT(cdp1869) - MDRV_VIDEO_START(cdp1869) - MDRV_VIDEO_UPDATE(cdp1869) - - MDRV_SCREEN_ADD("main", RASTER) - MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) - MDRV_SCREEN_RAW_PARAMS(DESTRYER_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) - MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.4, 0.044) - - MDRV_TIMER_ADD_SCANLINE("prd_start", altair_prd_start, "main", CDP1869_SCANLINE_PREDISPLAY_START_PAL, CDP1869_TOTAL_SCANLINES_PAL) - MDRV_TIMER_ADD_SCANLINE("prd_end", altair_prd_end, "main", CDP1869_SCANLINE_PREDISPLAY_END_PAL, CDP1869_TOTAL_SCANLINES_PAL) + MDRV_IMPORT_FROM(destryer_video) // sound hardware @@ -614,6 +539,8 @@ static MACHINE_DRIVER_START( destryer ) MACHINE_DRIVER_END static MACHINE_DRIVER_START( destryea ) + MDRV_DRIVER_DATA(cidelsa_state) + // basic system hardware MDRV_CPU_ADD(CDP1802, DESTRYER_CHR1) @@ -621,23 +548,13 @@ static MACHINE_DRIVER_START( destryea ) MDRV_CPU_IO_MAP(destryer_io_map, 0) MDRV_CPU_CONFIG(cidelsa_cdp1802_config) MDRV_NVRAM_HANDLER(generic_0fill) - MDRV_MACHINE_START(destryer) - MDRV_MACHINE_RESET(destryer) + + MDRV_MACHINE_START(cidelsa) + MDRV_MACHINE_RESET(cidelsa) // video hardware - MDRV_PALETTE_LENGTH(8+64) - MDRV_PALETTE_INIT(cdp1869) - MDRV_VIDEO_START(cdp1869) - MDRV_VIDEO_UPDATE(cdp1869) - - MDRV_SCREEN_ADD("main", RASTER) - MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) - MDRV_SCREEN_RAW_PARAMS(DESTRYER_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) - MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.4, 0.044) - - MDRV_TIMER_ADD_SCANLINE("prd_start", altair_prd_start, "main", CDP1869_SCANLINE_PREDISPLAY_START_PAL, CDP1869_TOTAL_SCANLINES_PAL) - MDRV_TIMER_ADD_SCANLINE("prd_end", altair_prd_end, "main", CDP1869_SCANLINE_PREDISPLAY_END_PAL, CDP1869_TOTAL_SCANLINES_PAL) + MDRV_IMPORT_FROM(destryer_video) // sound hardware @@ -648,29 +565,21 @@ static MACHINE_DRIVER_START( destryea ) MACHINE_DRIVER_END static MACHINE_DRIVER_START( altair ) + MDRV_DRIVER_DATA(cidelsa_state) + // basic system hardware MDRV_CPU_ADD(CDP1802, ALTAIR_CHR1) MDRV_CPU_PROGRAM_MAP(altair_map, 0) MDRV_CPU_IO_MAP(altair_io_map, 0) MDRV_CPU_CONFIG(cidelsa_cdp1802_config) - MDRV_MACHINE_START(destryer) - MDRV_MACHINE_RESET(destryer) + + MDRV_MACHINE_START(cidelsa) + MDRV_MACHINE_RESET(cidelsa) // video hardware - MDRV_PALETTE_LENGTH(8+64) - MDRV_PALETTE_INIT(cdp1869) - MDRV_VIDEO_START(cdp1869) - MDRV_VIDEO_UPDATE(cdp1869) - - MDRV_SCREEN_ADD("main", RASTER) - MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) - MDRV_SCREEN_RAW_PARAMS(ALTAIR_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) - MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.4, 0.044) - - MDRV_TIMER_ADD_SCANLINE("prd_start", altair_prd_start, "main", CDP1869_SCANLINE_PREDISPLAY_START_PAL, CDP1869_TOTAL_SCANLINES_PAL) - MDRV_TIMER_ADD_SCANLINE("prd_end", altair_prd_end, "main", CDP1869_SCANLINE_PREDISPLAY_END_PAL, CDP1869_TOTAL_SCANLINES_PAL) + MDRV_IMPORT_FROM(altair_video) // sound hardware @@ -681,6 +590,8 @@ static MACHINE_DRIVER_START( altair ) MACHINE_DRIVER_END static MACHINE_DRIVER_START( draco ) + MDRV_DRIVER_DATA(cidelsa_state) + // basic system hardware MDRV_CPU_ADD(CDP1802, DRACO_CHR1) @@ -688,8 +599,9 @@ static MACHINE_DRIVER_START( draco ) MDRV_CPU_IO_MAP(draco_io_map, 0) MDRV_CPU_CONFIG(cidelsa_cdp1802_config) MDRV_NVRAM_HANDLER(generic_0fill) + MDRV_MACHINE_START(draco) - MDRV_MACHINE_RESET(destryer) + MDRV_MACHINE_RESET(cidelsa) MDRV_CPU_ADD(COP420, DRACO_SND_CHR1) // COP402N MDRV_CPU_PROGRAM_MAP(draco_sound_map, 0) @@ -697,18 +609,7 @@ static MACHINE_DRIVER_START( draco ) // video hardware - MDRV_PALETTE_LENGTH(8+64) - MDRV_PALETTE_INIT(cdp1869) - MDRV_VIDEO_START(cdp1869) - MDRV_VIDEO_UPDATE(cdp1869) - - MDRV_SCREEN_ADD("main", RASTER) - MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) - MDRV_SCREEN_RAW_PARAMS(DRACO_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) - MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.360, 0.024) - - MDRV_TIMER_ADD_SCANLINE("prd_start", draco_prd_start, "main", CDP1869_SCANLINE_PREDISPLAY_START_PAL, CDP1869_TOTAL_SCANLINES_PAL) - MDRV_TIMER_ADD_SCANLINE("prd_end", draco_prd_end, "main", CDP1869_SCANLINE_PREDISPLAY_END_PAL, CDP1869_TOTAL_SCANLINES_PAL) + MDRV_IMPORT_FROM(draco_video) // sound hardware @@ -768,7 +669,7 @@ ROM_END /* Game Drivers */ -GAME( 1980, destryer, 0, destryer, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 1)", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) -GAME( 1980, destryea, destryer, destryea, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 2)", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) -GAME( 1981, altair, 0, altair, altair, 0, ROT90, "Cidelsa", "Altair", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) +GAME( 1980, destryer, 0, destryer, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 1)", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) +GAME( 1980, destryea, destryer, destryea, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 2)", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) +GAME( 1981, altair, 0, altair, altair, 0, ROT90, "Cidelsa", "Altair", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) GAME( 1981, draco, 0, draco, draco, 0, ROT90, "Cidelsa", "Draco", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE ) diff --git a/src/mame/includes/cidelsa.h b/src/mame/includes/cidelsa.h new file mode 100644 index 00000000000..ccac5b50219 --- /dev/null +++ b/src/mame/includes/cidelsa.h @@ -0,0 +1,38 @@ +#ifndef __CIDELSA__ +#define __CIDELSA__ + +#include "video/cdp1869.h" + +#define DESTRYER_CHR1 3579000.0 // unverified +#define DESTRYER_CHR2 XTAL_5_7143MHz +#define ALTAIR_CHR1 3579000.0 // unverified +#define ALTAIR_CHR2 CDP1869_DOT_CLK_PAL // unverified +#define DRACO_CHR1 XTAL_4_43361MHz +#define DRACO_CHR2 CDP1869_DOT_CLK_PAL // unverified +#define DRACO_SND_CHR1 XTAL_2_01216MHz + +typedef struct _cidelsa_state cidelsa_state; + +struct _cidelsa_state +{ + int cdp1802_mode; + int cdp1802_q; + + int cdp1869_prd; + int cdp1869_pcb; + + int draco_sound; + int draco_ay_latch; + + UINT8 *pageram; + UINT8 *pcbram; + UINT8 *charram; +}; + +/*----------- defined in video/cidelsa.c -----------*/ + +MACHINE_DRIVER_EXTERN( destryer_video ); +MACHINE_DRIVER_EXTERN( altair_video ); +MACHINE_DRIVER_EXTERN( draco_video ); + +#endif diff --git a/src/mame/mame.mak b/src/mame/mame.mak index 465cdf4dff8..44b73742d1e 100644 --- a/src/mame/mame.mak +++ b/src/mame/mame.mak @@ -1515,7 +1515,7 @@ $(MAMEOBJ)/misc.a: \ $(DRIVERS)/carrera.o \ $(DRIVERS)/cave.o $(VIDEO)/cave.o \ $(DRIVERS)/cherrym.o \ - $(DRIVERS)/cidelsa.o \ + $(DRIVERS)/cidelsa.o $(VIDEO)/cidelsa.o \ $(DRIVERS)/coinmstr.o \ $(DRIVERS)/comebaby.o \ $(DRIVERS)/coolpool.o \ diff --git a/src/mame/video/cidelsa.c b/src/mame/video/cidelsa.c new file mode 100644 index 00000000000..c4b9b0d38db --- /dev/null +++ b/src/mame/video/cidelsa.c @@ -0,0 +1,298 @@ +#include "driver.h" +#include "video/cdp1869.h" +#include "cidelsa.h" + +#define CIDELSA_PAGERAM_SIZE 0x400 +#define DRACO_PAGERAM_SIZE 0x800 +#define CIDELSA_CHARRAM_SIZE 0x800 + +#define CIDELSA_PAGERAM_MASK 0x3ff +#define DRACO_PAGERAM_MASK 0x7ff +#define CIDELSA_CHARRAM_MASK 0x7ff + +#define SCREEN_TAG "main" +#define CDP1869_TAG "cdp1869" + +/* Page RAM Access */ + +static CDP1869_PAGE_RAM_READ(cidelsa_pageram_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT16 addr = pma & CIDELSA_PAGERAM_MASK; + + if (BIT(pma, 10)) + { + return 0xff; + } + + return state->pageram[addr]; +} + +static CDP1869_PAGE_RAM_WRITE(cidelsa_pageram_w) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT16 addr = pma & CIDELSA_PAGERAM_MASK; + + if (BIT(pma, 10)) + { + return; + } + + state->pageram[addr] = data; +} + +static CDP1869_PAGE_RAM_READ(draco_pageram_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT16 addr = pma & DRACO_PAGERAM_MASK; + + return state->pageram[addr]; +} + +static CDP1869_PAGE_RAM_WRITE(draco_pageram_w) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT16 addr = pma & DRACO_PAGERAM_MASK; + + state->pageram[addr] = data; +} + +/* Character RAM Access */ + +static CDP1869_CHAR_RAM_READ(cidelsa_charram_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = BIT(pma, 10) ? 0xff : state->pageram[pma & CIDELSA_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + UINT8 data = state->charram[addr]; + state->cdp1869_pcb = state->pcbram[addr]; + + return data; +} + +static CDP1869_CHAR_RAM_WRITE(cidelsa_charram_w) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = BIT(pma, 10) ? 0xff : state->pageram[pma & CIDELSA_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + state->charram[addr] = data; + state->pcbram[addr] = state->cdp1802_q; +} + +static CDP1869_CHAR_RAM_READ(draco_charram_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = state->pageram[pma & DRACO_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + UINT8 data = state->charram[addr]; + state->cdp1869_pcb = state->pcbram[addr]; + + return data; +} + +static CDP1869_CHAR_RAM_WRITE(draco_charram_w) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = state->pageram[pma & DRACO_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + state->charram[addr] = data; + state->pcbram[addr] = state->cdp1802_q; +} + +/* Page Color Bit Access */ + +static CDP1869_PCB_READ(cidelsa_pcb_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = state->pageram[pma & CIDELSA_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + return state->pcbram[addr]; +} + +static CDP1869_PCB_READ(draco_pcb_r) +{ + cidelsa_state *state = device->machine->driver_data; + + UINT8 column = state->pageram[pma & DRACO_PAGERAM_MASK]; + UINT16 addr = ((column << 3) | (cma & 0x07)) & CIDELSA_CHARRAM_MASK; + + return state->pcbram[addr]; +} + +/* Predisplay Changed Handler */ + +static CDP1869_ON_PRD_CHANGED(cidelsa_prd_changed) +{ + cidelsa_state *state = device->machine->driver_data; + + // PRD is inverted + + cpunum_set_input_line(device->machine, 0, INPUT_LINE_IRQ0, !prd); + state->cdp1869_prd = !prd; +} + +static CDP1869_ON_PRD_CHANGED(draco_prd_changed) +{ + cidelsa_state *state = device->machine->driver_data; + + state->cdp1869_prd = prd; +} + +/* CDP1869 Interface */ + +static const cdp1869_interface destryer_cdp1869_intf = +{ + SCREEN_TAG, + DESTRYER_CHR2, + 0, + CDP1869_PAL, + cidelsa_pageram_r, + cidelsa_pageram_w, + cidelsa_pcb_r, + cidelsa_charram_r, + cidelsa_charram_w, + cidelsa_prd_changed, +}; + +static const cdp1869_interface altair_cdp1869_intf = +{ + SCREEN_TAG, + ALTAIR_CHR2, + 0, + CDP1869_PAL, + cidelsa_pageram_r, + cidelsa_pageram_w, + cidelsa_pcb_r, + cidelsa_charram_r, + cidelsa_charram_w, + cidelsa_prd_changed, +}; + +static const cdp1869_interface draco_cdp1869_intf = +{ + SCREEN_TAG, + DRACO_CHR2, + 0, + CDP1869_PAL, + draco_pageram_r, + draco_pageram_w, + draco_pcb_r, + draco_charram_r, + draco_charram_w, + draco_prd_changed, +}; + +/* Video Start */ + +static VIDEO_START(cidelsa) +{ + cidelsa_state *state = machine->driver_data; + + // allocate memory + + state->pageram = auto_malloc(CIDELSA_PAGERAM_SIZE); + state->pcbram = auto_malloc(CIDELSA_CHARRAM_SIZE); + state->charram = auto_malloc(CIDELSA_CHARRAM_SIZE); + + // register for save state + + state_save_register_global(state->cdp1869_prd); + state_save_register_global(state->cdp1869_pcb); + state_save_register_global_pointer(state->pageram, CIDELSA_PAGERAM_SIZE); + state_save_register_global_pointer(state->pcbram, CIDELSA_CHARRAM_SIZE); + state_save_register_global_pointer(state->charram, CIDELSA_CHARRAM_SIZE); +} + +static VIDEO_START(draco) +{ + cidelsa_state *state = machine->driver_data; + + // allocate memory + + state->pageram = auto_malloc(DRACO_PAGERAM_SIZE); + state->pcbram = auto_malloc(CIDELSA_CHARRAM_SIZE); + state->charram = auto_malloc(CIDELSA_CHARRAM_SIZE); + + // register for save state + + state_save_register_global(state->cdp1869_prd); + state_save_register_global(state->cdp1869_pcb); + state_save_register_global_pointer(state->pageram, DRACO_PAGERAM_SIZE); + state_save_register_global_pointer(state->pcbram, CIDELSA_CHARRAM_SIZE); + state_save_register_global_pointer(state->charram, CIDELSA_CHARRAM_SIZE); +} + +/* Video Update */ + +static VIDEO_UPDATE( cidelsa ) +{ + const device_config *cdp1869 = device_list_find_by_tag(screen->machine->config->devicelist, CDP1869_VIDEO, CDP1869_TAG); + + cdp1869_update(cdp1869, bitmap, cliprect); + + return 0; +} + +/* Machine Drivers */ + +MACHINE_DRIVER_START( destryer_video ) + MDRV_PALETTE_LENGTH(CDP1869_PALETTE_LENGTH) + MDRV_PALETTE_INIT(cdp1869) + + MDRV_VIDEO_START(cidelsa) + MDRV_VIDEO_UPDATE(cidelsa) + + MDRV_SCREEN_ADD(SCREEN_TAG, RASTER) + MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) + MDRV_SCREEN_RAW_PARAMS(DESTRYER_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) + MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.4, 0.044) + + MDRV_DEVICE_ADD(CDP1869_TAG, CDP1869_VIDEO) + MDRV_DEVICE_CONFIG(destryer_cdp1869_intf) +MACHINE_DRIVER_END + +MACHINE_DRIVER_START( altair_video ) + MDRV_PALETTE_LENGTH(CDP1869_PALETTE_LENGTH) + MDRV_PALETTE_INIT(cdp1869) + + MDRV_VIDEO_START(cidelsa) + MDRV_VIDEO_UPDATE(cidelsa) + + MDRV_SCREEN_ADD(SCREEN_TAG, RASTER) + MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) + MDRV_SCREEN_RAW_PARAMS(ALTAIR_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) + MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.4, 0.044) + + MDRV_DEVICE_ADD(CDP1869_TAG, CDP1869_VIDEO) + MDRV_DEVICE_CONFIG(altair_cdp1869_intf) +MACHINE_DRIVER_END + +MACHINE_DRIVER_START( draco_video ) + MDRV_PALETTE_LENGTH(CDP1869_PALETTE_LENGTH) + MDRV_PALETTE_INIT(cdp1869) + + MDRV_VIDEO_START(draco) + MDRV_VIDEO_UPDATE(cidelsa) + + MDRV_SCREEN_ADD(SCREEN_TAG, RASTER) + MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) + MDRV_SCREEN_RAW_PARAMS(DRACO_CHR2, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) + MDRV_SCREEN_DEFAULT_POSITION(1.226, 0.012, 1.360, 0.024) + + MDRV_DEVICE_ADD(CDP1869_TAG, CDP1869_VIDEO) + MDRV_DEVICE_CONFIG(draco_cdp1869_intf) +MACHINE_DRIVER_END