src/emu/sound/cdp1869.c
| r9412 | r9413 | |
| 1 | | #include "emu.h" |
| 2 | | #include "streams.h" |
| 3 | | #include "cpu/cosmac/cosmac.h" |
| 4 | | #include "sound/cdp1869.h" |
| 1 | /********************************************************************** |
| 5 | 2 | |
| 3 | RCA CDP1869/1870/1876 Video Interface System (VIS) emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 6 | 10 | /* |
| 7 | 11 | |
| 8 | 12 | TODO: |
| 9 | 13 | |
| 10 | | - remove CDP1802 dependency |
| 11 | | - sound base frequencies are TPA/TPB |
| 12 | 14 | - white noise |
| 13 | 15 | - scanline based update |
| 14 | 16 | - CMSEL output |
| 15 | 17 | |
| 16 | 18 | */ |
| 17 | 19 | |
| 18 | | /*************************************************************************** |
| 19 | | PARAMETERS |
| 20 | | ***************************************************************************/ |
| 20 | #include "emu.h" |
| 21 | #include "cdp1869.h" |
| 21 | 22 | |
| 22 | | #define CDP1869_WEIGHT_RED 30 /* % of max luminance */ |
| 23 | |
| 24 | |
| 25 | //************************************************************************** |
| 26 | // MACROS / CONSTANTS |
| 27 | //************************************************************************** |
| 28 | |
| 29 | #define LOG 0 |
| 30 | |
| 31 | #define CDP1869_WEIGHT_RED 30 // % of max luminance |
| 23 | 32 | #define CDP1869_WEIGHT_GREEN 59 |
| 24 | 33 | #define CDP1869_WEIGHT_BLUE 11 |
| 25 | 34 | |
| r9412 | r9413 | |
| 29 | 38 | #define CDP1869_ROWS_FULL_PAL 25 |
| 30 | 39 | #define CDP1869_ROWS_FULL_NTSC 24 |
| 31 | 40 | |
| 32 | | /*************************************************************************** |
| 33 | | TYPE DEFINITIONS |
| 34 | | ***************************************************************************/ |
| 35 | | |
| 36 | 41 | enum |
| 37 | 42 | { |
| 38 | 43 | CDB0 = 0, |
| r9412 | r9413 | |
| 45 | 50 | CCB1 |
| 46 | 51 | }; |
| 47 | 52 | |
| 48 | | typedef struct _cdp1869_t cdp1869_t; |
| 49 | | struct _cdp1869_t |
| 53 | |
| 54 | |
| 55 | //************************************************************************** |
| 56 | // GLOBAL VARIABLES |
| 57 | //************************************************************************** |
| 58 | |
| 59 | // devices |
| 60 | const device_type CDP1869 = cdp1869_device_config::static_alloc_device_config; |
| 61 | |
| 62 | |
| 63 | // default address map |
| 64 | static ADDRESS_MAP_START( cdp1869, 0, 8 ) |
| 65 | AM_RANGE(0x000, 0x7ff) AM_RAM |
| 66 | ADDRESS_MAP_END |
| 67 | |
| 68 | |
| 69 | |
| 70 | //************************************************************************** |
| 71 | // DEVICE CONFIGURATION |
| 72 | //************************************************************************** |
| 73 | |
| 74 | //------------------------------------------------- |
| 75 | // cdp1869_device_config - constructor |
| 76 | //------------------------------------------------- |
| 77 | |
| 78 | cdp1869_device_config::cdp1869_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 79 | : device_config(mconfig, static_alloc_device_config, "RCA CDP1869", tag, owner, clock), |
| 80 | device_config_sound_interface(mconfig, *this), |
| 81 | device_config_memory_interface(mconfig, *this), |
| 82 | m_space_config("pageram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(cdp1869)) |
| 50 | 83 | { |
| 51 | | devcb_resolved_read8 in_page_ram_func; |
| 52 | | devcb_resolved_write8 out_page_ram_func; |
| 53 | | devcb_resolved_write_line out_prd_func; |
| 54 | | devcb_resolved_read_line in_pal_ntsc_func; |
| 84 | } |
| 55 | 85 | |
| 56 | | running_device *device; |
| 57 | | const cdp1869_interface *intf; /* interface */ |
| 58 | | screen_device *screen; /* screen */ |
| 59 | | running_device *cpu; /* CPU */ |
| 60 | | sound_stream *stream; /* sound output */ |
| 61 | | int color_clock; |
| 62 | 86 | |
| 63 | | /* video state */ |
| 64 | | int prd; /* predisplay */ |
| 65 | | int dispoff; /* display off */ |
| 66 | | int fresvert; /* full resolution vertical */ |
| 67 | | int freshorz; /* full resolution horizontal */ |
| 68 | | int cmem; /* character memory access mode */ |
| 69 | | int dblpage; /* double page mode */ |
| 70 | | int line16; /* 16-line hi-res mode */ |
| 71 | | int line9; /* 9 line mode */ |
| 72 | | int cfc; /* color format control */ |
| 73 | | UINT8 col; /* character color control */ |
| 74 | | UINT8 bkg; /* background color */ |
| 75 | | UINT16 pma; /* page memory address */ |
| 76 | | UINT16 hma; /* home memory address */ |
| 87 | //------------------------------------------------- |
| 88 | // static_alloc_device_config - allocate a new |
| 89 | // configuration object |
| 90 | //------------------------------------------------- |
| 77 | 91 | |
| 78 | | /* video timer */ |
| 79 | | emu_timer *prd_changed_timer; /* predisplay changed timer */ |
| 92 | device_config *cdp1869_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 93 | { |
| 94 | return global_alloc(cdp1869_device_config(mconfig, tag, owner, clock)); |
| 95 | } |
| 80 | 96 | |
| 81 | | /* sound state */ |
| 82 | | INT16 signal; /* current signal */ |
| 83 | | int incr; /* initial wave state */ |
| 84 | | int toneoff; /* tone off */ |
| 85 | | int wnoff; /* white noise off */ |
| 86 | | UINT8 tonediv; /* tone divisor */ |
| 87 | | UINT8 tonefreq; /* tone range select */ |
| 88 | | UINT8 toneamp; /* tone output amplitude */ |
| 89 | | UINT8 wnfreq; /* white noise range select */ |
| 90 | | UINT8 wnamp; /* white noise output amplitude */ |
| 91 | | }; |
| 92 | 97 | |
| 93 | | /*************************************************************************** |
| 94 | | INLINE FUNCTIONS |
| 95 | | ***************************************************************************/ |
| 98 | //------------------------------------------------- |
| 99 | // alloc_device - allocate a new device object |
| 100 | //------------------------------------------------- |
| 96 | 101 | |
| 97 | | INLINE cdp1869_t *get_safe_token(running_device *device) |
| 102 | device_t *cdp1869_device_config::alloc_device(running_machine &machine) const |
| 98 | 103 | { |
| 99 | | assert(device != NULL); |
| 100 | | return (cdp1869_t *)downcast<legacy_device_base *>(device)->token(); |
| 104 | return auto_alloc(&machine, cdp1869_device(machine, *this)); |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | | /*************************************************************************** |
| 104 | | IMPLEMENTATION |
| 105 | | ***************************************************************************/ |
| 106 | 107 | |
| 107 | | #define CDP1869_IS_NTSC \ |
| 108 | | (!devcb_call_read_line(&cdp1869->in_pal_ntsc_func)) |
| 108 | //------------------------------------------------- |
| 109 | // memory_space_config - return a description of |
| 110 | // any address spaces owned by this device |
| 111 | //------------------------------------------------- |
| 109 | 112 | |
| 110 | | /*------------------------------------------------- |
| 111 | | update_prd_changed_timer - update predisplay |
| 112 | | changed timer |
| 113 | | -------------------------------------------------*/ |
| 113 | const address_space_config *cdp1869_device_config::memory_space_config(int spacenum) const |
| 114 | { |
| 115 | return (spacenum == 0) ? &m_space_config : NULL; |
| 116 | } |
| 114 | 117 | |
| 115 | | static void update_prd_changed_timer(cdp1869_t *cdp1869) |
| 118 | |
| 119 | //------------------------------------------------- |
| 120 | // device_config_complete - perform any |
| 121 | // operations now that the configuration is |
| 122 | // complete |
| 123 | //------------------------------------------------- |
| 124 | |
| 125 | void cdp1869_device_config::device_config_complete() |
| 116 | 126 | { |
| 117 | | if (cdp1869->prd_changed_timer != NULL) |
| 127 | // inherit a copy of the static data |
| 128 | const cdp1869_interface *intf = reinterpret_cast<const cdp1869_interface *>(static_config()); |
| 129 | if (intf != NULL) |
| 130 | *static_cast<cdp1869_interface *>(this) = *intf; |
| 131 | |
| 132 | // or initialize to defaults if none provided |
| 133 | else |
| 118 | 134 | { |
| 119 | | attotime duration; |
| 120 | | int start, end, level; |
| 121 | | int scanline = cdp1869->screen->vpos(); |
| 122 | | int next_scanline; |
| 135 | memset(&in_pal_ntsc_func, 0, sizeof(in_pal_ntsc_func)); |
| 136 | memset(&out_prd_func, 0, sizeof(out_prd_func)); |
| 137 | in_pcb_func = NULL; |
| 138 | in_char_ram_func = NULL; |
| 139 | out_char_ram_func = NULL; |
| 140 | } |
| 141 | } |
| 123 | 142 | |
| 124 | | if (CDP1869_IS_NTSC) |
| 125 | | { |
| 126 | | start = CDP1869_SCANLINE_PREDISPLAY_START_NTSC; |
| 127 | | end = CDP1869_SCANLINE_PREDISPLAY_END_NTSC; |
| 128 | | } |
| 129 | | else |
| 130 | | { |
| 131 | | start = CDP1869_SCANLINE_PREDISPLAY_START_PAL; |
| 132 | | end = CDP1869_SCANLINE_PREDISPLAY_END_PAL; |
| 133 | | } |
| 134 | 143 | |
| 135 | | if (scanline < start) |
| 136 | | { |
| 137 | | next_scanline = start; |
| 138 | | level = ASSERT_LINE; |
| 139 | | } |
| 140 | | else if (scanline < end) |
| 141 | | { |
| 142 | | next_scanline = end; |
| 143 | | level = CLEAR_LINE; |
| 144 | | } |
| 145 | | else |
| 146 | | { |
| 147 | | next_scanline = start; |
| 148 | | level = ASSERT_LINE; |
| 149 | | } |
| 150 | 144 | |
| 151 | | if (cdp1869->dispoff) |
| 152 | | { |
| 153 | | level = CLEAR_LINE; |
| 154 | | } |
| 145 | //************************************************************************** |
| 146 | // INLINE HELPERS |
| 147 | //************************************************************************** |
| 155 | 148 | |
| 156 | | duration = cdp1869->screen->time_until_pos(next_scanline); |
| 157 | | timer_adjust_oneshot(cdp1869->prd_changed_timer, duration, level); |
| 158 | | } |
| 149 | //------------------------------------------------- |
| 150 | // is_ntsc - is device in NTSC mode |
| 151 | //------------------------------------------------- |
| 152 | |
| 153 | inline bool cdp1869_device::is_ntsc() |
| 154 | { |
| 155 | return devcb_call_read_line(&m_in_pal_ntsc_func) ? false : true; |
| 159 | 156 | } |
| 160 | 157 | |
| 161 | | /*------------------------------------------------- |
| 162 | | TIMER_CALLBACK( prd_changed_tick ) |
| 163 | | -------------------------------------------------*/ |
| 164 | 158 | |
| 165 | | static TIMER_CALLBACK( prd_changed_tick ) |
| 159 | //------------------------------------------------- |
| 160 | // read_page_ram_byte - read a page RAM byte at |
| 161 | // the given address |
| 162 | //------------------------------------------------- |
| 163 | |
| 164 | inline UINT8 cdp1869_device::read_page_ram_byte(offs_t pma) |
| 166 | 165 | { |
| 167 | | running_device *device = (running_device *)ptr; |
| 168 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 166 | return space()->read_byte(pma); |
| 167 | } |
| 169 | 168 | |
| 170 | | devcb_call_write_line(&cdp1869->out_prd_func, param); |
| 171 | | cdp1869->prd = param; |
| 172 | 169 | |
| 173 | | update_prd_changed_timer(cdp1869); |
| 170 | //------------------------------------------------- |
| 171 | // write_page_ram_byte - write a page RAM byte at |
| 172 | // the given address |
| 173 | //------------------------------------------------- |
| 174 | |
| 175 | inline void cdp1869_device::write_page_ram_byte(offs_t pma, UINT8 data) |
| 176 | { |
| 177 | space()->write_byte(pma, data); |
| 174 | 178 | } |
| 175 | 179 | |
| 176 | | /*------------------------------------------------- |
| 177 | | STATE_POSTLOAD( cdp1869_state_save_postload ) |
| 178 | | -------------------------------------------------*/ |
| 179 | 180 | |
| 180 | | static STATE_POSTLOAD( cdp1869_state_save_postload ) |
| 181 | //------------------------------------------------- |
| 182 | // read_char_ram_byte - read a char RAM byte at |
| 183 | // the given address |
| 184 | //------------------------------------------------- |
| 185 | |
| 186 | inline UINT8 cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, UINT8 pmd) |
| 181 | 187 | { |
| 182 | | update_prd_changed_timer((cdp1869_t *)param); |
| 188 | UINT8 data = 0; |
| 189 | |
| 190 | if (m_in_char_ram_func != NULL) |
| 191 | { |
| 192 | data = m_in_char_ram_func(this, pma, cma, pmd); |
| 193 | } |
| 194 | |
| 195 | return data; |
| 183 | 196 | } |
| 184 | 197 | |
| 185 | | /*------------------------------------------------- |
| 186 | | cdp1802_get_r_x - get CDP1802 R(X) value |
| 187 | | -------------------------------------------------*/ |
| 188 | 198 | |
| 189 | | static UINT16 cdp1802_get_r_x(cdp1869_t *cdp1869) |
| 199 | //------------------------------------------------- |
| 200 | // write_char_ram_byte - write a char RAM byte at |
| 201 | // the given address |
| 202 | //------------------------------------------------- |
| 203 | |
| 204 | inline void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, UINT8 pmd, UINT8 data) |
| 190 | 205 | { |
| 191 | | return cpu_get_reg(cdp1869->cpu, COSMAC_R0 + cpu_get_reg(cdp1869->cpu, COSMAC_X)); |
| 206 | if (m_out_char_ram_func != NULL) |
| 207 | { |
| 208 | m_out_char_ram_func(this, pma, cma, pmd, data); |
| 209 | } |
| 192 | 210 | } |
| 193 | 211 | |
| 194 | | /*------------------------------------------------- |
| 195 | | get_rgb - get RGB value |
| 196 | | -------------------------------------------------*/ |
| 197 | 212 | |
| 198 | | static rgb_t get_rgb(int i, int c, int l) |
| 213 | //------------------------------------------------- |
| 214 | // read_pcb - read page control bit |
| 215 | //------------------------------------------------- |
| 216 | |
| 217 | inline int cdp1869_device::read_pcb(offs_t pma, offs_t cma, UINT8 pmd) |
| 199 | 218 | { |
| 219 | int pcb = 0; |
| 220 | |
| 221 | if (m_in_pcb_func != NULL) |
| 222 | { |
| 223 | pcb = m_in_pcb_func(this, pma, cma, pmd); |
| 224 | } |
| 225 | |
| 226 | return pcb; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | //------------------------------------------------- |
| 231 | // update_prd_changed_timer - |
| 232 | //------------------------------------------------- |
| 233 | |
| 234 | inline void cdp1869_device::update_prd_changed_timer() |
| 235 | { |
| 236 | int start = CDP1869_SCANLINE_PREDISPLAY_START_PAL; |
| 237 | int end = CDP1869_SCANLINE_PREDISPLAY_END_PAL; |
| 238 | int next_state; |
| 239 | int scanline = m_screen->vpos(); |
| 240 | int next_scanline; |
| 241 | |
| 242 | if (is_ntsc()) |
| 243 | { |
| 244 | start = CDP1869_SCANLINE_PREDISPLAY_START_NTSC; |
| 245 | end = CDP1869_SCANLINE_PREDISPLAY_END_NTSC; |
| 246 | } |
| 247 | |
| 248 | if (scanline < start) |
| 249 | { |
| 250 | next_scanline = start; |
| 251 | next_state = ASSERT_LINE; |
| 252 | } |
| 253 | else if (scanline < end) |
| 254 | { |
| 255 | next_scanline = end; |
| 256 | next_state = CLEAR_LINE; |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | next_scanline = start; |
| 261 | next_state = ASSERT_LINE; |
| 262 | } |
| 263 | |
| 264 | if (m_dispoff) |
| 265 | { |
| 266 | next_state = CLEAR_LINE; |
| 267 | } |
| 268 | |
| 269 | attotime duration = m_screen->time_until_pos(next_scanline); |
| 270 | timer_adjust_oneshot(m_prd_timer, duration, next_state); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | //------------------------------------------------- |
| 275 | // get_rgb - get RGB value |
| 276 | //------------------------------------------------- |
| 277 | |
| 278 | inline rgb_t cdp1869_device::get_rgb(int i, int c, int l) |
| 279 | { |
| 200 | 280 | int luma = 0, r, g, b; |
| 201 | 281 | |
| 202 | 282 | luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; |
| r9412 | r9413 | |
| 212 | 292 | return MAKE_RGB(r, g, b); |
| 213 | 293 | } |
| 214 | 294 | |
| 215 | | /*------------------------------------------------- |
| 216 | | get_lines - get number of character lines |
| 217 | | -------------------------------------------------*/ |
| 218 | 295 | |
| 219 | | static int get_lines(running_device *device) |
| 296 | //------------------------------------------------- |
| 297 | // get_lines - get number of character lines |
| 298 | //------------------------------------------------- |
| 299 | |
| 300 | inline int cdp1869_device::get_lines() |
| 220 | 301 | { |
| 221 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 222 | | |
| 223 | | if (cdp1869->line16 && !cdp1869->dblpage) |
| 302 | if (m_line16 && !m_dblpage) |
| 224 | 303 | { |
| 225 | 304 | return 16; |
| 226 | 305 | } |
| 227 | | else if (!cdp1869->line9) |
| 306 | else if (!m_line9) |
| 228 | 307 | { |
| 229 | 308 | return 9; |
| 230 | 309 | } |
| r9412 | r9413 | |
| 234 | 313 | } |
| 235 | 314 | } |
| 236 | 315 | |
| 237 | | /*------------------------------------------------- |
| 238 | | get_pmemsize - get page memory size |
| 239 | | -------------------------------------------------*/ |
| 240 | 316 | |
| 241 | | static UINT16 get_pmemsize(running_device *device, int cols, int rows) |
| 317 | //------------------------------------------------- |
| 318 | // get_pmemsize - get page memory size |
| 319 | //------------------------------------------------- |
| 320 | |
| 321 | inline UINT16 cdp1869_device::get_pmemsize(int cols, int rows) |
| 242 | 322 | { |
| 243 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 244 | | |
| 245 | 323 | int pmemsize = cols * rows; |
| 246 | 324 | |
| 247 | | if (cdp1869->dblpage) pmemsize *= 2; |
| 248 | | if (cdp1869->line16) pmemsize *= 2; |
| 325 | if (m_dblpage) pmemsize *= 2; |
| 326 | if (m_line16) pmemsize *= 2; |
| 249 | 327 | |
| 250 | 328 | return pmemsize; |
| 251 | 329 | } |
| 252 | 330 | |
| 253 | | /*------------------------------------------------- |
| 254 | | get_pma - get page memory address |
| 255 | | -------------------------------------------------*/ |
| 256 | 331 | |
| 257 | | static UINT16 get_pma(running_device *device) |
| 332 | //------------------------------------------------- |
| 333 | // get_pma - get page memory address |
| 334 | //------------------------------------------------- |
| 335 | |
| 336 | inline UINT16 cdp1869_device::get_pma() |
| 258 | 337 | { |
| 259 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 260 | | |
| 261 | | if (cdp1869->dblpage) |
| 338 | if (m_dblpage) |
| 262 | 339 | { |
| 263 | | return cdp1869->pma; |
| 340 | return m_pma; |
| 264 | 341 | } |
| 265 | 342 | else |
| 266 | 343 | { |
| 267 | | return cdp1869->pma & 0x3ff; |
| 344 | return m_pma & 0x3ff; |
| 268 | 345 | } |
| 269 | 346 | } |
| 270 | 347 | |
| 271 | | /*------------------------------------------------- |
| 272 | | get_pen - get pen for color bits |
| 273 | | -------------------------------------------------*/ |
| 274 | 348 | |
| 275 | | static int get_pen(running_device *device, int ccb0, int ccb1, int pcb) |
| 349 | //------------------------------------------------- |
| 350 | // get_pen - get pen for color bits |
| 351 | //------------------------------------------------- |
| 352 | |
| 353 | inline int cdp1869_device::get_pen(int ccb0, int ccb1, int pcb) |
| 276 | 354 | { |
| 277 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 355 | int r = 0, g = 0, b = 0; |
| 278 | 356 | |
| 279 | | int r = 0, g = 0, b = 0, color; |
| 280 | | |
| 281 | | switch (cdp1869->col) |
| 357 | switch (m_col) |
| 282 | 358 | { |
| 283 | 359 | case 0: |
| 284 | 360 | r = ccb0; |
| r9412 | r9413 | |
| 300 | 376 | break; |
| 301 | 377 | } |
| 302 | 378 | |
| 303 | | color = (r << 2) + (b << 1) + g; |
| 379 | int color = (r << 2) + (b << 1) + g; |
| 304 | 380 | |
| 305 | | if (cdp1869->cfc) |
| 381 | if (m_cfc) |
| 306 | 382 | { |
| 307 | | return color + ((cdp1869->bkg + 1) * 8); |
| 383 | return color + ((m_bkg + 1) * 8); |
| 308 | 384 | } |
| 309 | 385 | else |
| 310 | 386 | { |
| r9412 | r9413 | |
| 312 | 388 | } |
| 313 | 389 | } |
| 314 | 390 | |
| 315 | | /*------------------------------------------------- |
| 316 | | draw_line - draw character line |
| 317 | | -------------------------------------------------*/ |
| 318 | 391 | |
| 319 | | static void draw_line(running_device *device, bitmap_t *bitmap, int x, int y, int data, int color) |
| 392 | |
| 393 | //************************************************************************** |
| 394 | // LIVE DEVICE |
| 395 | //************************************************************************** |
| 396 | |
| 397 | //------------------------------------------------- |
| 398 | // cdp1869_device - constructor |
| 399 | //------------------------------------------------- |
| 400 | |
| 401 | cdp1869_device::cdp1869_device(running_machine &_machine, const cdp1869_device_config &config) |
| 402 | : device_t(_machine, config), |
| 403 | device_sound_interface(_machine, config, *this), |
| 404 | device_memory_interface(_machine, config, *this), |
| 405 | m_stream(NULL), |
| 406 | m_config(config) |
| 320 | 407 | { |
| 321 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 322 | 408 | |
| 409 | } |
| 410 | |
| 411 | |
| 412 | //------------------------------------------------- |
| 413 | // device_start - device-specific startup |
| 414 | //------------------------------------------------- |
| 415 | |
| 416 | void cdp1869_device::device_start() |
| 417 | { |
| 418 | // get the screen device |
| 419 | m_screen = m_machine.device<screen_device>(m_config.screen_tag); |
| 420 | assert(m_screen != NULL); |
| 421 | |
| 422 | // resolve callbacks |
| 423 | devcb_resolve_read_line(&m_in_pal_ntsc_func, &m_config.in_pal_ntsc_func, this); |
| 424 | devcb_resolve_write_line(&m_out_prd_func, &m_config.out_prd_func, this); |
| 425 | m_in_pcb_func = m_config.in_pcb_func; |
| 426 | m_in_char_ram_func = m_config.in_char_ram_func; |
| 427 | m_out_char_ram_func = m_config.out_char_ram_func; |
| 428 | |
| 429 | // allocate timers |
| 430 | m_prd_timer = device_timer_alloc(*this); |
| 431 | update_prd_changed_timer(); |
| 432 | |
| 433 | // initialize palette |
| 434 | initialize_palette(); |
| 435 | |
| 436 | // create sound stream |
| 437 | m_stream = stream_create(this, 0, 1, m_machine.sample_rate, this, static_stream_generate); |
| 438 | |
| 439 | // register for state saving |
| 440 | state_save_register_device_item(this, 0, m_prd); |
| 441 | state_save_register_device_item(this, 0, m_dispoff); |
| 442 | state_save_register_device_item(this, 0, m_fresvert); |
| 443 | state_save_register_device_item(this, 0, m_freshorz); |
| 444 | state_save_register_device_item(this, 0, m_cmem); |
| 445 | state_save_register_device_item(this, 0, m_dblpage); |
| 446 | state_save_register_device_item(this, 0, m_line16); |
| 447 | state_save_register_device_item(this, 0, m_line9); |
| 448 | state_save_register_device_item(this, 0, m_cfc); |
| 449 | state_save_register_device_item(this, 0, m_col); |
| 450 | state_save_register_device_item(this, 0, m_bkg); |
| 451 | state_save_register_device_item(this, 0, m_pma); |
| 452 | state_save_register_device_item(this, 0, m_hma); |
| 453 | state_save_register_device_item(this, 0, m_signal); |
| 454 | state_save_register_device_item(this, 0, m_incr); |
| 455 | state_save_register_device_item(this, 0, m_toneoff); |
| 456 | state_save_register_device_item(this, 0, m_wnoff); |
| 457 | state_save_register_device_item(this, 0, m_tonediv); |
| 458 | state_save_register_device_item(this, 0, m_tonefreq); |
| 459 | state_save_register_device_item(this, 0, m_toneamp); |
| 460 | state_save_register_device_item(this, 0, m_wnfreq); |
| 461 | state_save_register_device_item(this, 0, m_wnamp); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | //------------------------------------------------- |
| 466 | // device_post_load - device-specific post-load |
| 467 | //------------------------------------------------- |
| 468 | |
| 469 | void cdp1869_device::device_post_load() |
| 470 | { |
| 471 | update_prd_changed_timer(); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | //------------------------------------------------- |
| 476 | // device_timer - handler timer events |
| 477 | //------------------------------------------------- |
| 478 | |
| 479 | void cdp1869_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 480 | { |
| 481 | devcb_call_write_line(&m_out_prd_func, param); |
| 482 | m_prd = param; |
| 483 | |
| 484 | update_prd_changed_timer(); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | //------------------------------------------------- |
| 489 | // initialize_palette - initialize palette |
| 490 | //------------------------------------------------- |
| 491 | |
| 492 | void cdp1869_device::initialize_palette() |
| 493 | { |
| 494 | // color-on-color display (CFC=0) |
| 323 | 495 | int i; |
| 324 | 496 | |
| 497 | for (i = 0; i < 8; i++) |
| 498 | { |
| 499 | palette_set_color(machine, i, get_rgb(i, i, 15)); |
| 500 | } |
| 501 | |
| 502 | // tone-on-tone display (CFC=1) |
| 503 | for (int c = 0; c < 8; c++) |
| 504 | { |
| 505 | for (int l = 0; l < 8; l++) |
| 506 | { |
| 507 | palette_set_color(machine, i, get_rgb(i, c, l)); |
| 508 | i++; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 | //------------------------------------------------- |
| 515 | // stream_generate - handle update requests for |
| 516 | // our sound stream |
| 517 | //------------------------------------------------- |
| 518 | |
| 519 | STREAM_UPDATE( cdp1869_device::static_stream_generate ) |
| 520 | { |
| 521 | reinterpret_cast<cdp1869_device *>(param)->stream_generate(inputs, outputs, samples); |
| 522 | } |
| 523 | |
| 524 | void cdp1869_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 525 | { |
| 526 | // reset the output stream |
| 527 | memset(outputs[0], 0, samples * sizeof(*outputs[0])); |
| 528 | |
| 529 | INT16 signal = m_signal; |
| 530 | stream_sample_t *buffer = outputs[0]; |
| 531 | |
| 532 | if (!m_toneoff && m_toneamp) |
| 533 | { |
| 534 | double frequency = (clock() / 2) / (512 >> m_tonefreq) / (m_tonediv + 1); |
| 535 | // double amplitude = m_toneamp * ((0.78*5) / 15); |
| 536 | |
| 537 | int rate = m_machine.sample_rate / 2; |
| 538 | |
| 539 | /* get progress through wave */ |
| 540 | int incr = m_incr; |
| 541 | |
| 542 | if (signal < 0) |
| 543 | { |
| 544 | signal = -(m_toneamp * (0x07fff / 15)); |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | signal = m_toneamp * (0x07fff / 15); |
| 549 | } |
| 550 | |
| 551 | while( samples-- > 0 ) |
| 552 | { |
| 553 | *buffer++ = signal; |
| 554 | incr -= frequency; |
| 555 | while( incr < 0 ) |
| 556 | { |
| 557 | incr += rate; |
| 558 | signal = -signal; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /* store progress through wave */ |
| 563 | m_incr = incr; |
| 564 | m_signal = signal; |
| 565 | } |
| 566 | /* |
| 567 | if (!m_wnoff) |
| 568 | { |
| 569 | double amplitude = m_wnamp * ((0.78*5) / 15); |
| 570 | |
| 571 | for (int wndiv = 0; wndiv < 128; wndiv++) |
| 572 | { |
| 573 | double frequency = (clock() / 2) / (4096 >> m_wnfreq) / (wndiv + 1): |
| 574 | |
| 575 | sum_square_wave(buffer, frequency, amplitude); |
| 576 | } |
| 577 | } |
| 578 | */ |
| 579 | |
| 580 | } |
| 581 | |
| 582 | |
| 583 | //------------------------------------------------- |
| 584 | // draw_line - draw character line |
| 585 | //------------------------------------------------- |
| 586 | |
| 587 | void cdp1869_device::draw_line(bitmap_t *bitmap, const rectangle *rect, int x, int y, UINT8 data, int color) |
| 588 | { |
| 589 | int i; |
| 590 | |
| 325 | 591 | data <<= 2; |
| 326 | 592 | |
| 327 | 593 | for (i = 0; i < CDP1869_CHAR_WIDTH; i++) |
| r9412 | r9413 | |
| 330 | 596 | { |
| 331 | 597 | *BITMAP_ADDR16(bitmap, y, x) = color; |
| 332 | 598 | |
| 333 | | if (!cdp1869->fresvert) |
| 599 | if (!m_fresvert) |
| 334 | 600 | { |
| 335 | 601 | *BITMAP_ADDR16(bitmap, y + 1, x) = color; |
| 336 | 602 | } |
| 337 | 603 | |
| 338 | | if (!cdp1869->freshorz) |
| 604 | if (!m_freshorz) |
| 339 | 605 | { |
| 340 | 606 | *BITMAP_ADDR16(bitmap, y, x + 1) = color; |
| 341 | 607 | |
| 342 | | if (!cdp1869->fresvert) |
| 608 | if (!m_fresvert) |
| 343 | 609 | { |
| 344 | 610 | *BITMAP_ADDR16(bitmap, y + 1, x + 1) = color; |
| 345 | 611 | } |
| 346 | 612 | } |
| 347 | 613 | } |
| 348 | 614 | |
| 349 | | if (!cdp1869->freshorz) |
| 615 | if (!m_freshorz) |
| 350 | 616 | { |
| 351 | 617 | x++; |
| 352 | 618 | } |
| r9412 | r9413 | |
| 357 | 623 | } |
| 358 | 624 | } |
| 359 | 625 | |
| 360 | | /*------------------------------------------------- |
| 361 | | draw_char - draw character |
| 362 | | -------------------------------------------------*/ |
| 363 | 626 | |
| 364 | | static void draw_char(running_device *device, bitmap_t *bitmap, int x, int y, UINT16 pma, const rectangle *screenrect) |
| 627 | //------------------------------------------------- |
| 628 | // draw_char - draw character |
| 629 | //------------------------------------------------- |
| 630 | |
| 631 | void cdp1869_device::draw_char(bitmap_t *bitmap, const rectangle *rect, int x, int y, UINT16 pma) |
| 365 | 632 | { |
| 366 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 633 | UINT8 pmd = read_page_ram_byte(pma); |
| 367 | 634 | |
| 368 | | UINT8 cma = 0; |
| 369 | | |
| 370 | | for (cma = 0; cma < get_lines(device); cma++) |
| 635 | for (UINT8 cma = 0; cma < get_lines(); cma++) |
| 371 | 636 | { |
| 372 | | UINT8 data = cdp1869->intf->char_ram_r(device, pma, cma); |
| 637 | UINT8 data = read_char_ram_byte(pma, cma, pmd); |
| 373 | 638 | |
| 374 | 639 | int ccb0 = BIT(data, CCB0); |
| 375 | 640 | int ccb1 = BIT(data, CCB1); |
| 376 | | int pcb = BIT(cdp1869->intf->pcb_r(device, pma, cma), 0); |
| 641 | int pcb = read_pcb(pma, cma, pmd); |
| 377 | 642 | |
| 378 | | int color = get_pen(device, ccb0, ccb1, pcb); |
| 643 | int color = get_pen(ccb0, ccb1, pcb); |
| 379 | 644 | |
| 380 | | draw_line(device, bitmap, screenrect->min_x + x, screenrect->min_y + y, data, color); |
| 645 | draw_line(bitmap, rect, rect->min_x + x, rect->min_y + y, data, color); |
| 381 | 646 | |
| 382 | 647 | y++; |
| 383 | 648 | |
| 384 | | if (!cdp1869->fresvert) |
| 649 | if (!m_fresvert) |
| 385 | 650 | { |
| 386 | 651 | y++; |
| 387 | 652 | } |
| 388 | 653 | } |
| 389 | 654 | } |
| 390 | 655 | |
| 391 | | /*------------------------------------------------- |
| 392 | | PALETTE_INIT( cdp1869 ) |
| 393 | | -------------------------------------------------*/ |
| 394 | 656 | |
| 395 | | PALETTE_INIT( cdp1869 ) |
| 396 | | { |
| 397 | | int i, c, l; |
| 657 | //------------------------------------------------- |
| 658 | // out3_w - register 3 write |
| 659 | //------------------------------------------------- |
| 398 | 660 | |
| 399 | | /* color-on-color display (CFC=0) */ |
| 400 | | for (i = 0; i < 8; i++) |
| 401 | | { |
| 402 | | palette_set_color(machine, i, get_rgb(i, i, 15)); |
| 403 | | } |
| 404 | | |
| 405 | | /* tone-on-tone display (CFC=1) */ |
| 406 | | for (c = 0; c < 8; c++) |
| 407 | | { |
| 408 | | for (l = 0; l < 8; l++) |
| 409 | | { |
| 410 | | palette_set_color(machine, i, get_rgb(i, c, l)); |
| 411 | | i++; |
| 412 | | } |
| 413 | | } |
| 414 | | } |
| 415 | | |
| 416 | | /*------------------------------------------------- |
| 417 | | cdp1869_out3_w - register 3 write |
| 418 | | -------------------------------------------------*/ |
| 419 | | |
| 420 | | WRITE8_DEVICE_HANDLER( cdp1869_out3_w ) |
| 661 | WRITE8_MEMBER( cdp1869_device::out3_w ) |
| 421 | 662 | { |
| 422 | 663 | /* |
| 423 | 664 | bit description |
| r9412 | r9413 | |
| 432 | 673 | 7 fres horz |
| 433 | 674 | */ |
| 434 | 675 | |
| 435 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 436 | | |
| 437 | | cdp1869->bkg = data & 0x07; |
| 438 | | cdp1869->cfc = BIT(data, 3); |
| 439 | | cdp1869->dispoff = BIT(data, 4); |
| 440 | | cdp1869->col = (data & 0x60) >> 5; |
| 441 | | cdp1869->freshorz = BIT(data, 7); |
| 676 | m_bkg = data & 0x07; |
| 677 | m_cfc = BIT(data, 3); |
| 678 | m_dispoff = BIT(data, 4); |
| 679 | m_col = (data & 0x60) >> 5; |
| 680 | m_freshorz = BIT(data, 7); |
| 442 | 681 | } |
| 443 | 682 | |
| 444 | | /*------------------------------------------------- |
| 445 | | cdp1869_out4_w - register 4 write |
| 446 | | -------------------------------------------------*/ |
| 447 | 683 | |
| 448 | | WRITE8_DEVICE_HANDLER( cdp1869_out4_w ) |
| 684 | //------------------------------------------------- |
| 685 | // out4_w - register 4 write |
| 686 | //------------------------------------------------- |
| 687 | |
| 688 | WRITE8_MEMBER( cdp1869_device::out4_w ) |
| 449 | 689 | { |
| 450 | 690 | /* |
| 451 | 691 | bit description |
| r9412 | r9413 | |
| 468 | 708 | 15 always 0 |
| 469 | 709 | */ |
| 470 | 710 | |
| 471 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 472 | | UINT16 word = cdp1802_get_r_x(cdp1869); |
| 711 | m_toneamp = offset & 0x0f; |
| 712 | m_tonefreq = (offset & 0x70) >> 4; |
| 713 | m_toneoff = BIT(offset, 7); |
| 714 | m_tonediv = (offset & 0x7f00) >> 8; |
| 473 | 715 | |
| 474 | | cdp1869->toneamp = word & 0x0f; |
| 475 | | cdp1869->tonefreq = (word & 0x70) >> 4; |
| 476 | | cdp1869->toneoff = BIT(word, 7); |
| 477 | | cdp1869->tonediv = (word & 0x7f00) >> 8; |
| 716 | stream_update(m_stream); |
| 478 | 717 | } |
| 479 | 718 | |
| 480 | | /*------------------------------------------------- |
| 481 | | cdp1869_out5_w - register 5 write |
| 482 | | -------------------------------------------------*/ |
| 483 | 719 | |
| 484 | | WRITE8_DEVICE_HANDLER( cdp1869_out5_w ) |
| 720 | //------------------------------------------------- |
| 721 | // out5_w - register 5 write |
| 722 | //------------------------------------------------- |
| 723 | |
| 724 | WRITE8_MEMBER( cdp1869_device::out5_w ) |
| 485 | 725 | { |
| 486 | 726 | /* |
| 487 | 727 | bit description |
| r9412 | r9413 | |
| 504 | 744 | 15 wn off |
| 505 | 745 | */ |
| 506 | 746 | |
| 507 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 508 | | UINT16 word = cdp1802_get_r_x(cdp1869); |
| 747 | m_cmem = BIT(offset, 0); |
| 748 | m_line9 = BIT(offset, 3); |
| 749 | m_line16 = BIT(offset, 5); |
| 750 | m_dblpage = BIT(offset, 6); |
| 751 | m_fresvert = BIT(offset, 7); |
| 752 | m_wnamp = (offset & 0x0f00) >> 8; |
| 753 | m_wnfreq = (offset & 0x7000) >> 12; |
| 754 | m_wnoff = BIT(offset, 15); |
| 509 | 755 | |
| 510 | | cdp1869->cmem = BIT(word, 0); |
| 511 | | cdp1869->line9 = BIT(word, 3); |
| 756 | stream_update(m_stream); |
| 512 | 757 | |
| 513 | | if (CDP1869_IS_NTSC) |
| 758 | if (m_cmem) |
| 514 | 759 | { |
| 515 | | cdp1869->line16 = BIT(word, 5); |
| 760 | m_pma = offset; |
| 516 | 761 | } |
| 517 | | |
| 518 | | cdp1869->dblpage = BIT(word, 6); |
| 519 | | cdp1869->fresvert = BIT(word, 7); |
| 520 | | |
| 521 | | cdp1869->wnamp = (word & 0x0f00) >> 8; |
| 522 | | cdp1869->wnfreq = (word & 0x7000) >> 12; |
| 523 | | cdp1869->wnoff = BIT(word, 15); |
| 524 | | |
| 525 | | if (cdp1869->cmem) |
| 526 | | { |
| 527 | | cdp1869->pma = word; |
| 528 | | } |
| 529 | 762 | else |
| 530 | 763 | { |
| 531 | | cdp1869->pma = 0; |
| 764 | m_pma = 0; |
| 532 | 765 | } |
| 533 | 766 | } |
| 534 | 767 | |
| 535 | | /*------------------------------------------------- |
| 536 | | cdp1869_out6_w - register 6 write |
| 537 | | -------------------------------------------------*/ |
| 538 | 768 | |
| 539 | | WRITE8_DEVICE_HANDLER( cdp1869_out6_w ) |
| 769 | //------------------------------------------------- |
| 770 | // out6_w - register 6 write |
| 771 | //------------------------------------------------- |
| 772 | |
| 773 | WRITE8_MEMBER( cdp1869_device::out6_w ) |
| 540 | 774 | { |
| 541 | 775 | /* |
| 542 | 776 | bit description |
| r9412 | r9413 | |
| 559 | 793 | 15 x |
| 560 | 794 | */ |
| 561 | 795 | |
| 562 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 563 | | UINT16 word = cdp1802_get_r_x(cdp1869); |
| 564 | | |
| 565 | | cdp1869->pma = word & 0x7ff; |
| 796 | m_pma = offset & 0x7ff; |
| 566 | 797 | } |
| 567 | 798 | |
| 568 | | /*------------------------------------------------- |
| 569 | | cdp1869_out7_w - register 7 write |
| 570 | | -------------------------------------------------*/ |
| 571 | 799 | |
| 572 | | WRITE8_DEVICE_HANDLER( cdp1869_out7_w ) |
| 800 | //------------------------------------------------- |
| 801 | // out7_w - register 7 write |
| 802 | //------------------------------------------------- |
| 803 | |
| 804 | WRITE8_MEMBER( cdp1869_device::out7_w ) |
| 573 | 805 | { |
| 574 | 806 | /* |
| 575 | 807 | bit description |
| r9412 | r9413 | |
| 592 | 824 | 15 x |
| 593 | 825 | */ |
| 594 | 826 | |
| 595 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 596 | | UINT16 word = cdp1802_get_r_x(cdp1869); |
| 597 | | |
| 598 | | cdp1869->hma = word & 0x7fc; |
| 827 | m_hma = offset & 0x7fc; |
| 599 | 828 | } |
| 600 | 829 | |
| 601 | | /*------------------------------------------------- |
| 602 | | cdp1869_pageram_r - page memory read |
| 603 | | -------------------------------------------------*/ |
| 604 | 830 | |
| 605 | | READ8_DEVICE_HANDLER( cdp1869_pageram_r ) |
| 831 | //------------------------------------------------- |
| 832 | // char_ram_r - character RAM read |
| 833 | //------------------------------------------------- |
| 834 | |
| 835 | READ8_MEMBER( cdp1869_device::char_ram_r ) |
| 606 | 836 | { |
| 607 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 608 | | |
| 837 | UINT8 cma = offset & 0x0f; |
| 609 | 838 | UINT16 pma; |
| 610 | 839 | |
| 611 | | if (cdp1869->cmem) |
| 840 | if (m_cmem) |
| 612 | 841 | { |
| 613 | | pma = get_pma(device); |
| 842 | pma = get_pma(); |
| 614 | 843 | } |
| 615 | 844 | else |
| 616 | 845 | { |
| 617 | 846 | pma = offset; |
| 618 | 847 | } |
| 619 | 848 | |
| 620 | | return devcb_call_read8(&cdp1869->in_page_ram_func, pma); |
| 849 | if (m_dblpage) |
| 850 | { |
| 851 | cma &= 0x07; |
| 852 | } |
| 853 | |
| 854 | UINT8 pmd = read_page_ram_byte(pma); |
| 855 | |
| 856 | return read_char_ram_byte(pma, cma, pmd); |
| 621 | 857 | } |
| 622 | 858 | |
| 623 | | /*------------------------------------------------- |
| 624 | | cdp1869_pageram_w - page memory write |
| 625 | | -------------------------------------------------*/ |
| 626 | 859 | |
| 627 | | WRITE8_DEVICE_HANDLER( cdp1869_pageram_w ) |
| 860 | //------------------------------------------------- |
| 861 | // char_ram_w - character RAM write |
| 862 | //------------------------------------------------- |
| 863 | |
| 864 | WRITE8_MEMBER( cdp1869_device::char_ram_w ) |
| 628 | 865 | { |
| 629 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 630 | | |
| 866 | UINT8 cma = offset & 0x0f; |
| 631 | 867 | UINT16 pma; |
| 632 | 868 | |
| 633 | | if (cdp1869->cmem) |
| 869 | if (m_cmem) |
| 634 | 870 | { |
| 635 | | pma = get_pma(device); |
| 871 | pma = get_pma(); |
| 636 | 872 | } |
| 637 | 873 | else |
| 638 | 874 | { |
| 639 | 875 | pma = offset; |
| 640 | 876 | } |
| 641 | 877 | |
| 642 | | devcb_call_write8(&cdp1869->out_page_ram_func, pma, data); |
| 878 | if (m_dblpage) |
| 879 | { |
| 880 | cma &= 0x07; |
| 881 | } |
| 882 | |
| 883 | UINT8 pmd = read_page_ram_byte(pma); |
| 884 | |
| 885 | write_char_ram_byte(pma, cma, pmd, data); |
| 643 | 886 | } |
| 644 | 887 | |
| 645 | | /*------------------------------------------------- |
| 646 | | cdp1869_charram_r - character memory read |
| 647 | | -------------------------------------------------*/ |
| 648 | 888 | |
| 649 | | READ8_DEVICE_HANDLER( cdp1869_charram_r ) |
| 889 | //------------------------------------------------- |
| 890 | // page_ram_r - page RAM read |
| 891 | //------------------------------------------------- |
| 892 | |
| 893 | READ8_MEMBER( cdp1869_device::page_ram_r ) |
| 650 | 894 | { |
| 651 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 652 | | |
| 653 | | UINT8 cma = offset & 0x0f; |
| 654 | 895 | UINT16 pma; |
| 655 | 896 | |
| 656 | | if (cdp1869->cmem) |
| 897 | if (m_cmem) |
| 657 | 898 | { |
| 658 | | pma = get_pma(device); |
| 899 | pma = get_pma(); |
| 659 | 900 | } |
| 660 | 901 | else |
| 661 | 902 | { |
| 662 | 903 | pma = offset; |
| 663 | 904 | } |
| 664 | 905 | |
| 665 | | if (cdp1869->dblpage) |
| 666 | | { |
| 667 | | cma &= 0x07; |
| 668 | | } |
| 669 | | |
| 670 | | return cdp1869->intf->char_ram_r(device, pma, cma); |
| 906 | return read_page_ram_byte(pma); |
| 671 | 907 | } |
| 672 | 908 | |
| 673 | | /*------------------------------------------------- |
| 674 | | cdp1869_charram_w - character memory write |
| 675 | | -------------------------------------------------*/ |
| 676 | 909 | |
| 677 | | WRITE8_DEVICE_HANDLER( cdp1869_charram_w ) |
| 910 | //------------------------------------------------- |
| 911 | // page_ram_w - page RAM write |
| 912 | //------------------------------------------------- |
| 913 | |
| 914 | WRITE8_MEMBER( cdp1869_device::page_ram_w ) |
| 678 | 915 | { |
| 679 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 680 | | |
| 681 | | UINT8 cma = offset & 0x0f; |
| 682 | 916 | UINT16 pma; |
| 683 | 917 | |
| 684 | | if (cdp1869->cmem) |
| 918 | if (m_cmem) |
| 685 | 919 | { |
| 686 | | pma = get_pma(device); |
| 920 | pma = get_pma(); |
| 687 | 921 | } |
| 688 | 922 | else |
| 689 | 923 | { |
| 690 | 924 | pma = offset; |
| 691 | 925 | } |
| 692 | 926 | |
| 693 | | if (cdp1869->dblpage) |
| 694 | | { |
| 695 | | cma &= 0x07; |
| 696 | | } |
| 697 | | |
| 698 | | if (cdp1869->intf->char_ram_w) |
| 699 | | { |
| 700 | | cdp1869->intf->char_ram_w(device, pma, cma, data); |
| 701 | | } |
| 927 | write_page_ram_byte(pma, data); |
| 702 | 928 | } |
| 703 | 929 | |
| 704 | | /*------------------------------------------------- |
| 705 | | cdp1869_predisplay_r - predisplay read |
| 706 | | -------------------------------------------------*/ |
| 707 | 930 | |
| 708 | | READ_LINE_DEVICE_HANDLER( cdp1869_predisplay_r ) |
| 931 | //------------------------------------------------- |
| 932 | // page_ram_w - predisplay |
| 933 | //------------------------------------------------- |
| 934 | |
| 935 | READ_LINE_MEMBER( cdp1869_device::predisplay_r ) |
| 709 | 936 | { |
| 710 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 711 | | |
| 712 | | return cdp1869->prd; |
| 937 | return m_prd; |
| 713 | 938 | } |
| 714 | 939 | |
| 715 | | /*------------------------------------------------- |
| 716 | | cdp1869_pal_ntsc_r - PAL/NTSC read |
| 717 | | -------------------------------------------------*/ |
| 718 | 940 | |
| 719 | | READ_LINE_DEVICE_HANDLER( cdp1869_pal_ntsc_r ) |
| 941 | //------------------------------------------------- |
| 942 | // pal_ntsc_r - PAL/NTSC |
| 943 | //------------------------------------------------- |
| 944 | |
| 945 | READ_LINE_MEMBER( cdp1869_device::pal_ntsc_r ) |
| 720 | 946 | { |
| 721 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 722 | | |
| 723 | | return devcb_call_read_line(&cdp1869->in_pal_ntsc_func); |
| 947 | return devcb_call_read_line(&m_in_pal_ntsc_func); |
| 724 | 948 | } |
| 725 | 949 | |
| 726 | | /*------------------------------------------------- |
| 727 | | cdp1869_update - screen update |
| 728 | | -------------------------------------------------*/ |
| 729 | 950 | |
| 730 | | void cdp1869_update(running_device *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 951 | //------------------------------------------------- |
| 952 | // update_screen - update screen |
| 953 | //------------------------------------------------- |
| 954 | |
| 955 | void cdp1869_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 731 | 956 | { |
| 732 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 733 | | |
| 734 | 957 | rectangle screen_rect, outer; |
| 735 | 958 | |
| 736 | | if (CDP1869_IS_NTSC) |
| 959 | if (is_ntsc()) |
| 737 | 960 | { |
| 738 | 961 | outer.min_x = CDP1869_HBLANK_END; |
| 739 | 962 | outer.max_x = CDP1869_HBLANK_START - 1; |
| r9412 | r9413 | |
| 757 | 980 | } |
| 758 | 981 | |
| 759 | 982 | sect_rect(&outer, cliprect); |
| 760 | | bitmap_fill(bitmap, &outer, device->machine->pens[cdp1869->bkg]); |
| 983 | bitmap_fill(bitmap, &outer, m_bkg); |
| 761 | 984 | |
| 762 | | if (!cdp1869->dispoff) |
| 985 | if (!m_dispoff) |
| 763 | 986 | { |
| 764 | | int sx, sy, rows, cols, width, height; |
| 765 | | UINT16 addr, pmemsize; |
| 987 | int width = CDP1869_CHAR_WIDTH; |
| 988 | int height = get_lines(); |
| 766 | 989 | |
| 767 | | width = CDP1869_CHAR_WIDTH; |
| 768 | | height = get_lines(device); |
| 769 | | |
| 770 | | if (!cdp1869->freshorz) |
| 990 | if (!m_freshorz) |
| 771 | 991 | { |
| 772 | 992 | width *= 2; |
| 773 | 993 | } |
| 774 | 994 | |
| 775 | | if (!cdp1869->fresvert) |
| 995 | if (!m_fresvert) |
| 776 | 996 | { |
| 777 | 997 | height *= 2; |
| 778 | 998 | } |
| 779 | 999 | |
| 780 | | cols = cdp1869->freshorz ? CDP1869_COLUMNS_FULL : CDP1869_COLUMNS_HALF; |
| 781 | | rows = (screen_rect.max_y - screen_rect.min_y + 1) / height; |
| 1000 | int cols = m_freshorz ? CDP1869_COLUMNS_FULL : CDP1869_COLUMNS_HALF; |
| 1001 | int rows = (screen_rect.max_y - screen_rect.min_y + 1) / height; |
| 782 | 1002 | |
| 783 | | pmemsize = get_pmemsize(device, cols, rows); |
| 1003 | UINT16 pmemsize = get_pmemsize(cols, rows); |
| 1004 | UINT16 addr = m_hma; |
| 784 | 1005 | |
| 785 | | addr = cdp1869->hma; |
| 786 | | |
| 787 | | for (sy = 0; sy < rows; sy++) |
| 1006 | for (int sy = 0; sy < rows; sy++) |
| 788 | 1007 | { |
| 789 | | for (sx = 0; sx < cols; sx++) |
| 1008 | for (int sx = 0; sx < cols; sx++) |
| 790 | 1009 | { |
| 791 | 1010 | int x = sx * width; |
| 792 | 1011 | int y = sy * height; |
| 793 | 1012 | |
| 794 | | draw_char(device, bitmap, x, y, addr, &screen_rect); |
| 795 | | |
| 1013 | draw_char(bitmap, &screen_rect, x, y, addr); |
| 1014 | |
| 796 | 1015 | addr++; |
| 797 | 1016 | |
| 798 | 1017 | if (addr == pmemsize) addr = 0; |
| r9412 | r9413 | |
| 800 | 1019 | } |
| 801 | 1020 | } |
| 802 | 1021 | } |
| 803 | | |
| 804 | | /*------------------------------------------------- |
| 805 | | STREAM_UPDATE( cdp1869_stream_update ) |
| 806 | | -------------------------------------------------*/ |
| 807 | | |
| 808 | | static STREAM_UPDATE( cdp1869_stream_update ) |
| 809 | | { |
| 810 | | cdp1869_t *cdp1869 = (cdp1869_t *)param; |
| 811 | | INT16 signal = cdp1869->signal; |
| 812 | | stream_sample_t *buffer = outputs[0]; |
| 813 | | |
| 814 | | memset( buffer, 0, samples * sizeof(*buffer) ); |
| 815 | | |
| 816 | | if (!cdp1869->toneoff && cdp1869->toneamp) |
| 817 | | { |
| 818 | | double frequency = (cdp1869->device->clock() / 2) / (512 >> cdp1869->tonefreq) / (cdp1869->tonediv + 1); |
| 819 | | // double amplitude = cdp1869->toneamp * ((0.78*5) / 15); |
| 820 | | |
| 821 | | int rate = cdp1869->device->machine->sample_rate / 2; |
| 822 | | |
| 823 | | /* get progress through wave */ |
| 824 | | int incr = cdp1869->incr; |
| 825 | | |
| 826 | | if (signal < 0) |
| 827 | | { |
| 828 | | signal = -(cdp1869->toneamp * (0x07fff / 15)); |
| 829 | | } |
| 830 | | else |
| 831 | | { |
| 832 | | signal = cdp1869->toneamp * (0x07fff / 15); |
| 833 | | } |
| 834 | | |
| 835 | | while( samples-- > 0 ) |
| 836 | | { |
| 837 | | *buffer++ = signal; |
| 838 | | incr -= frequency; |
| 839 | | while( incr < 0 ) |
| 840 | | { |
| 841 | | incr += rate; |
| 842 | | signal = -signal; |
| 843 | | } |
| 844 | | } |
| 845 | | |
| 846 | | /* store progress through wave */ |
| 847 | | cdp1869->incr = incr; |
| 848 | | cdp1869->signal = signal; |
| 849 | | } |
| 850 | | /* |
| 851 | | if (!cdp1869->wnoff) |
| 852 | | { |
| 853 | | double amplitude = cdp1869->wnamp * ((0.78*5) / 15); |
| 854 | | |
| 855 | | for (int wndiv = 0; wndiv < 128; wndiv++) |
| 856 | | { |
| 857 | | double frequency = (cdp1869->clock / 2) / (4096 >> cdp1869->wnfreq) / (wndiv + 1): |
| 858 | | |
| 859 | | sum_square_wave(buffer, frequency, amplitude); |
| 860 | | } |
| 861 | | } |
| 862 | | */ |
| 863 | | } |
| 864 | | |
| 865 | | /*------------------------------------------------- |
| 866 | | DEVICE_START( cdp1869 ) |
| 867 | | -------------------------------------------------*/ |
| 868 | | |
| 869 | | static DEVICE_START( cdp1869 ) |
| 870 | | { |
| 871 | | cdp1869_t *cdp1869 = get_safe_token(device); |
| 872 | | |
| 873 | | /* validate arguments */ |
| 874 | | cdp1869->intf = (const cdp1869_interface *)device->baseconfig().static_config(); |
| 875 | | |
| 876 | | assert(cdp1869->intf->pcb_r != NULL); |
| 877 | | assert(cdp1869->intf->char_ram_r != NULL); |
| 878 | | |
| 879 | | /* resolve callbacks */ |
| 880 | | devcb_resolve_read8(&cdp1869->in_page_ram_func, &cdp1869->intf->in_page_ram_func, device); |
| 881 | | devcb_resolve_write8(&cdp1869->out_page_ram_func, &cdp1869->intf->out_page_ram_func, device); |
| 882 | | devcb_resolve_write_line(&cdp1869->out_prd_func, &cdp1869->intf->out_prd_func, device); |
| 883 | | devcb_resolve_read_line(&cdp1869->in_pal_ntsc_func, &cdp1869->intf->in_pal_ntsc_func, device); |
| 884 | | |
| 885 | | /* set initial values */ |
| 886 | | cdp1869->device = device; |
| 887 | | cdp1869->stream = stream_create(device, 0, 1, device->machine->sample_rate, cdp1869, cdp1869_stream_update); |
| 888 | | cdp1869->incr = 0; |
| 889 | | cdp1869->signal = 0x07fff; |
| 890 | | cdp1869->toneoff = 1; |
| 891 | | cdp1869->wnoff = 1; |
| 892 | | |
| 893 | | /* get the screen device */ |
| 894 | | cdp1869->screen = downcast<screen_device *>(device->machine->device(cdp1869->intf->screen_tag)); |
| 895 | | assert(cdp1869->screen != NULL); |
| 896 | | |
| 897 | | /* get the CPU device */ |
| 898 | | cdp1869->cpu = device->machine->device(cdp1869->intf->cpu_tag); |
| 899 | | assert(cdp1869->cpu != NULL); |
| 900 | | |
| 901 | | /* allocate predisplay timer */ |
| 902 | | cdp1869->prd_changed_timer = timer_alloc(device->machine, prd_changed_tick, (void *)device); |
| 903 | | update_prd_changed_timer(cdp1869); |
| 904 | | |
| 905 | | /* register for state saving */ |
| 906 | | state_save_register_postload(device->machine, cdp1869_state_save_postload, cdp1869); |
| 907 | | |
| 908 | | state_save_register_device_item(device, 0, cdp1869->prd); |
| 909 | | state_save_register_device_item(device, 0, cdp1869->dispoff); |
| 910 | | state_save_register_device_item(device, 0, cdp1869->fresvert); |
| 911 | | state_save_register_device_item(device, 0, cdp1869->freshorz); |
| 912 | | state_save_register_device_item(device, 0, cdp1869->cmem); |
| 913 | | state_save_register_device_item(device, 0, cdp1869->dblpage); |
| 914 | | state_save_register_device_item(device, 0, cdp1869->line16); |
| 915 | | state_save_register_device_item(device, 0, cdp1869->line9); |
| 916 | | state_save_register_device_item(device, 0, cdp1869->cfc); |
| 917 | | state_save_register_device_item(device, 0, cdp1869->col); |
| 918 | | state_save_register_device_item(device, 0, cdp1869->bkg); |
| 919 | | state_save_register_device_item(device, 0, cdp1869->pma); |
| 920 | | state_save_register_device_item(device, 0, cdp1869->hma); |
| 921 | | |
| 922 | | state_save_register_device_item(device, 0, cdp1869->signal); |
| 923 | | state_save_register_device_item(device, 0, cdp1869->incr); |
| 924 | | state_save_register_device_item(device, 0, cdp1869->toneoff); |
| 925 | | state_save_register_device_item(device, 0, cdp1869->wnoff); |
| 926 | | state_save_register_device_item(device, 0, cdp1869->tonediv); |
| 927 | | state_save_register_device_item(device, 0, cdp1869->tonefreq); |
| 928 | | state_save_register_device_item(device, 0, cdp1869->toneamp); |
| 929 | | state_save_register_device_item(device, 0, cdp1869->wnfreq); |
| 930 | | state_save_register_device_item(device, 0, cdp1869->wnamp); |
| 931 | | } |
| 932 | | |
| 933 | | /*------------------------------------------------- |
| 934 | | DEVICE_GET_INFO( cdp1869 ) |
| 935 | | -------------------------------------------------*/ |
| 936 | | |
| 937 | | DEVICE_GET_INFO( cdp1869 ) |
| 938 | | { |
| 939 | | switch (state) |
| 940 | | { |
| 941 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 942 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cdp1869_t); break; |
| 943 | | |
| 944 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 945 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cdp1869); break; |
| 946 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 947 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 948 | | |
| 949 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 950 | | case DEVINFO_STR_NAME: strcpy(info->s, "RCA CDP1869"); break; |
| 951 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "RCA CDP1800"); break; |
| 952 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 953 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 954 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 955 | | } |
| 956 | | } |
| 957 | | |
| 958 | | |
| 959 | | DEFINE_LEGACY_SOUND_DEVICE(CDP1869, cdp1869); |
src/emu/sound/cdp1869.h
| r9412 | r9413 | |
| 1 | | /* |
| 1 | /********************************************************************** |
| 2 | 2 | |
| 3 | | RCA CDP1869/70/76 Video Interface System (VIS) |
| 3 | RCA CDP1869/1870/1876 Video Interface System (VIS) emulation |
| 4 | 4 | |
| 5 | | http://homepage.mac.com/ruske/cosmacelf/cdp1869.pdf |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 6 | 7 | |
| 7 | | ________________ ________________ |
| 8 | | TPA 1 ---| \/ |--- 40 Vdd PREDISPLAY_ 1 ---| \/ |--- 40 Vdd |
| 9 | | TPB 2 ---| |--- 39 PMSEL *DISPLAY_ 2 ---| |--- 39 PAL/NTSC_ |
| 10 | | MRD_ 3 ---| |--- 38 PMWR_ PCB 3 ---| |--- 38 CPUCLK |
| 11 | | MWR_ 4 ---| |--- 37 *CMSEL CCB1 4 ---| |--- 37 XTAL (DOT) |
| 12 | | MA0/8 5 ---| |--- 36 CMWR_ BUS7 5 ---| |--- 36 XTAL (DOT)_ |
| 13 | | MA1/9 6 ---| |--- 35 PMA0 CCB0 6 ---| |--- 35 *ADDRSTB_ |
| 14 | | MA2/10 7 ---| |--- 34 PMA1 BUS6 7 ---| |--- 34 MRD_ |
| 15 | | MA3/11 8 ---| |--- 33 PMA2 CDB5 8 ---| |--- 33 TPB |
| 16 | | MA4/12 9 ---| |--- 32 PMA3 BUS5 9 ---| |--- 32 *CMSEL |
| 17 | | MA5/13 10 ---| CDP1869C |--- 31 PMA4 CDB4 10 ---| CDP1870/76C |--- 31 BURST |
| 18 | | MA6/14 11 ---| top view |--- 30 PMA5 BUS4 11 ---| top view |--- 30 *H SYNC_ |
| 19 | | MA7/15 12 ---| |--- 29 PMA6 CDB3 12 ---| |--- 29 COMPSYNC_ |
| 20 | | N0 13 ---| |--- 28 PMA7 BUS3 13 ---| |--- 28 LUM / (RED)^ |
| 21 | | N1 14 ---| |--- 27 PMA8 CDB2 14 ---| |--- 27 PAL CHROM / (BLUE)^ |
| 22 | | N2 15 ---| |--- 26 PMA9 BUS2 15 ---| |--- 26 NTSC CHROM / (GREEN)^ |
| 23 | | *H SYNC_ 16 ---| |--- 25 CMA3/PMA10 CDB1 16 ---| |--- 25 XTAL_ (CHROM) |
| 24 | | *DISPLAY_ 17 ---| |--- 24 CMA2 BUS1 17 ---| |--- 24 XTAL (CHROM) |
| 25 | | *ADDRSTB_ 18 ---| |--- 23 CMA1 CDB0 18 ---| |--- 23 EMS_ |
| 26 | | SOUND 19 ---| |--- 22 CMA0 BUS0 19 ---| |--- 22 EVS_ |
| 27 | | VSS 20 ---|________________|--- 21 *N=3_ Vss 20 ---|________________|--- 21 *N=3_ |
| 8 | ********************************************************************** |
| 9 | _____ _____ |
| 10 | TPA 1 |* \_/ | 40 Vdd |
| 11 | TPB 2 | | 39 PMSEL |
| 12 | _MRD 3 | | 38 _PMWR |
| 13 | _MWR 4 | | 37 CMSEL |
| 14 | MA0/8 5 | | 36 _CMWR |
| 15 | MA1/9 6 | | 35 PMA0 |
| 16 | MA2/10 7 | | 34 PMA1 |
| 17 | MA3/11 8 | | 33 PMA2 |
| 18 | MA4/12 9 | | 32 PMA3 |
| 19 | MA5/13 10 | | 31 PMA4 |
| 20 | MA6/14 11 | CDP1869 | 30 PMA5 |
| 21 | MA7/15 12 | | 29 PMA6 |
| 22 | N0 13 | | 28 PMA7 |
| 23 | N1 14 | | 27 PMA8 |
| 24 | N2 15 | | 26 PMA9 |
| 25 | _H SYNC 16 | | 25 CMA3/PMA10 |
| 26 | _DISPLAY 17 | | 24 CMA2 |
| 27 | _ADDRSTB 18 | | 23 CMA1 |
| 28 | SOUND 19 | | 22 CMA0 |
| 29 | Vss 20 |_____________| 21 _N=3 |
| 28 | 30 | |
| 31 | _____ _____ |
| 32 | _PREDISPLAY 1 |* \_/ | 40 Vdd |
| 33 | _DISPLAY 2 | | 39 PAL/_NTSC |
| 34 | PCB 3 | | 38 CPUCLK |
| 35 | CCB1 4 | | 37 XTAL (DOT) |
| 36 | BUS7 5 | | 36 _XTAL (DOT) |
| 37 | CCB0 6 | | 35 _ADDRSTB |
| 38 | BUS6 7 | | 34 _MRD |
| 39 | CDB5 8 | | 33 TPB |
| 40 | BUS5 9 | | 32 CMSEL |
| 41 | CDB4 10 | | 31 BURST |
| 42 | BUS4 11 | CDP1870 | 30 _H SYNC |
| 43 | CDB3 12 | | 29 _COMPSYNC |
| 44 | BUS3 13 | | 28 LUM |
| 45 | CDB2 14 | | 27 PAL CHROM |
| 46 | BUS2 15 | | 26 NTSC CHROM |
| 47 | CDB1 16 | | 25 _XTAL (CHROM) |
| 48 | BUS1 17 | | 24 XTAL (CHROM) |
| 49 | CDB0 18 | | 23 _EMS |
| 50 | BUS0 19 | | 22 _EVS |
| 51 | Vss 20 |_____________| 21 _N=3 |
| 29 | 52 | |
| 30 | | * = INTERCHIP CONNECTIONS ^ = FOR THE RGB BOND-OUT OPTION (CDP1876C) _ = ACTIVE LOW |
| 53 | _____ _____ |
| 54 | _PREDISPLAY 1 |* \_/ | 40 Vdd |
| 55 | _DISPLAY 2 | | 39 PAL/_NTSC |
| 56 | PCB 3 | | 38 CPUCLK |
| 57 | CCB1 4 | | 37 XTAL (DOT) |
| 58 | BUS7 5 | | 36 _XTAL (DOT) |
| 59 | CCB0 6 | | 35 _ADDRSTB |
| 60 | BUS6 7 | | 34 _MRD |
| 61 | CDB5 8 | | 33 TPB |
| 62 | BUS5 9 | | 32 CMSEL |
| 63 | CDB4 10 | | 31 BURST |
| 64 | BUS4 11 | CDP1876 | 30 _H SYNC |
| 65 | CDB3 12 | | 29 _COMPSYNC |
| 66 | BUS3 13 | | 28 RED |
| 67 | CDB2 14 | | 27 BLUE |
| 68 | BUS2 15 | | 26 GREEN |
| 69 | CDB1 16 | | 25 _XTAL (CHROM) |
| 70 | BUS1 17 | | 24 XTAL (CHROM) |
| 71 | CDB0 18 | | 23 _EMS |
| 72 | BUS0 19 | | 22 _EVS |
| 73 | Vss 20 |_____________| 21 _N=3 |
| 31 | 74 | |
| 32 | | */ |
| 75 | **********************************************************************/ |
| 33 | 76 | |
| 77 | #pragma once |
| 78 | |
| 34 | 79 | #ifndef __CDP1869__ |
| 35 | 80 | #define __CDP1869__ |
| 36 | 81 | |
| 37 | | #include "devlegcy.h" |
| 82 | #include "emu.h" |
| 38 | 83 | |
| 39 | 84 | |
| 40 | | /*************************************************************************** |
| 41 | | MACROS / CONSTANTS |
| 42 | | ***************************************************************************/ |
| 43 | 85 | |
| 44 | | #define CDP1869_DOT_CLK_PAL 5626000.0 |
| 45 | | #define CDP1869_DOT_CLK_NTSC 5670000.0 |
| 46 | | #define CDP1869_COLOR_CLK_PAL 8867236.0 |
| 47 | | #define CDP1869_COLOR_CLK_NTSC 7159090.0 |
| 86 | //************************************************************************** |
| 87 | // MACROS / CONSTANTS |
| 88 | //************************************************************************** |
| 48 | 89 | |
| 90 | #define CDP1869_DOT_CLK_PAL (float)XTAL_5_626MHz |
| 91 | #define CDP1869_DOT_CLK_NTSC (float)XTAL_5_67MHz |
| 92 | #define CDP1869_COLOR_CLK_PAL (float)XTAL_8_867236MHz |
| 93 | #define CDP1869_COLOR_CLK_NTSC (float)XTAL_7_15909MHz |
| 94 | |
| 49 | 95 | #define CDP1869_CPU_CLK_PAL (CDP1869_DOT_CLK_PAL / 2) |
| 50 | 96 | #define CDP1869_CPU_CLK_NTSC (CDP1869_DOT_CLK_NTSC / 2) |
| 51 | 97 | |
| r9412 | r9413 | |
| 85 | 131 | |
| 86 | 132 | #define CDP1869_PALETTE_LENGTH 8+64 |
| 87 | 133 | |
| 88 | | DECLARE_LEGACY_SOUND_DEVICE(CDP1869, cdp1869); |
| 89 | 134 | |
| 90 | | #define MDRV_CDP1869_ADD(_tag, _pixclock, _config) \ |
| 135 | |
| 136 | //************************************************************************** |
| 137 | // INTERFACE CONFIGURATION MACROS |
| 138 | //************************************************************************** |
| 139 | |
| 140 | #define MDRV_CDP1869_ADD(_tag, _pixclock, _config, _map) \ |
| 91 | 141 | MDRV_DEVICE_ADD(_tag, CDP1869, _pixclock) \ |
| 92 | | MDRV_DEVICE_CONFIG(_config) |
| 142 | MDRV_DEVICE_CONFIG(_config) \ |
| 143 | MDRV_DEVICE_ADDRESS_MAP(0, _map) |
| 93 | 144 | |
| 94 | 145 | #define MDRV_CDP1869_SCREEN_PAL_ADD(_tag, _clock) \ |
| 95 | 146 | MDRV_SCREEN_ADD(_tag, RASTER) \ |
| 96 | 147 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) \ |
| 97 | 148 | MDRV_SCREEN_RAW_PARAMS(_clock, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_PAL, CDP1869_SCANLINE_VBLANK_END_PAL, CDP1869_SCANLINE_VBLANK_START_PAL) \ |
| 98 | | MDRV_PALETTE_LENGTH(8+64) \ |
| 99 | | MDRV_PALETTE_INIT(cdp1869) |
| 149 | MDRV_PALETTE_LENGTH(8+64) |
| 100 | 150 | |
| 101 | 151 | #define MDRV_CDP1869_SCREEN_NTSC_ADD(_tag, _clock) \ |
| 102 | 152 | MDRV_SCREEN_ADD(_tag, RASTER) \ |
| 103 | 153 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) \ |
| 104 | 154 | MDRV_SCREEN_RAW_PARAMS(_clock, CDP1869_SCREEN_WIDTH, CDP1869_HBLANK_END, CDP1869_HBLANK_START, CDP1869_TOTAL_SCANLINES_NTSC, CDP1869_SCANLINE_VBLANK_END_NTSC, CDP1869_SCANLINE_VBLANK_START_NTSC) \ |
| 105 | | MDRV_PALETTE_LENGTH(8+64) \ |
| 106 | | MDRV_PALETTE_INIT(cdp1869) |
| 155 | MDRV_PALETTE_LENGTH(8+64) |
| 107 | 156 | |
| 108 | 157 | #define CDP1869_INTERFACE(_name) \ |
| 109 | 158 | const cdp1869_interface (_name) = |
| 110 | 159 | |
| 111 | | #define CDP1869_CHAR_RAM_READ(name) UINT8 name(running_device *device, UINT16 pma, UINT8 cma) |
| 112 | | #define CDP1869_CHAR_RAM_WRITE(name) void name(running_device *device, UINT16 pma, UINT8 cma, UINT8 data) |
| 113 | | #define CDP1869_PCB_READ(name) int name(running_device *device, UINT16 pma, UINT8 cma) |
| 160 | #define CDP1869_CHAR_RAM_READ(name) UINT8 name(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd) |
| 161 | #define CDP1869_CHAR_RAM_WRITE(name) void name(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd, UINT8 data) |
| 162 | #define CDP1869_PCB_READ(name) int name(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd) |
| 114 | 163 | |
| 115 | 164 | #define CDP1869_PAL \ |
| 116 | 165 | DEVCB_LINE_VCC |
| r9412 | r9413 | |
| 118 | 167 | #define CDP1869_NTSC \ |
| 119 | 168 | DEVCB_LINE_GND |
| 120 | 169 | |
| 121 | | /*************************************************************************** |
| 122 | | TYPE DEFINITIONS |
| 123 | | ***************************************************************************/ |
| 124 | 170 | |
| 125 | | typedef UINT8 (*cdp1869_char_ram_read_func)(running_device *device, UINT16 pma, UINT8 cma); |
| 126 | | typedef void (*cdp1869_char_ram_write_func)(running_device *device, UINT16 pma, UINT8 cma, UINT8 data); |
| 127 | | typedef int (*cdp1869_pcb_read_func)(running_device *device, UINT16 pma, UINT8 cma); |
| 128 | 171 | |
| 129 | | /* interface */ |
| 130 | | typedef struct _cdp1869_interface cdp1869_interface; |
| 131 | | struct _cdp1869_interface |
| 172 | //************************************************************************** |
| 173 | // TYPE DEFINITIONS |
| 174 | //************************************************************************** |
| 175 | |
| 176 | typedef UINT8 (*cdp1869_char_ram_read_func)(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd); |
| 177 | typedef void (*cdp1869_char_ram_write_func)(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd, UINT8 data); |
| 178 | typedef int (*cdp1869_pcb_read_func)(running_device *device, UINT16 pma, UINT8 cma, UINT8 pmd); |
| 179 | |
| 180 | |
| 181 | // ======================> cdp1869_interface |
| 182 | |
| 183 | struct cdp1869_interface |
| 132 | 184 | { |
| 133 | | const char *cpu_tag; /* CPU we work together with */ |
| 134 | | const char *screen_tag; /* screen we are acting on */ |
| 185 | const char *screen_tag; // screen we are acting on |
| 135 | 186 | |
| 136 | | /* pixel clock of the chip is the device clock */ |
| 137 | | int color_clock; /* the chroma clock of the chip */ |
| 187 | // pixel clock of the chip is the device clock |
| 188 | int color_clock; // the chroma clock of the chip |
| 138 | 189 | |
| 139 | | /* screen format */ |
| 190 | // screen format |
| 140 | 191 | devcb_read_line in_pal_ntsc_func; |
| 141 | 192 | |
| 142 | | /* page memory read function */ |
| 143 | | devcb_read8 in_page_ram_func; |
| 193 | // page memory color bit read function |
| 194 | cdp1869_pcb_read_func in_pcb_func; |
| 144 | 195 | |
| 145 | | /* page memory write function */ |
| 146 | | devcb_write8 out_page_ram_func; |
| 196 | // character memory read function |
| 197 | cdp1869_char_ram_read_func in_char_ram_func; |
| 147 | 198 | |
| 148 | | /* page memory color bit read function */ |
| 149 | | cdp1869_pcb_read_func pcb_r; |
| 199 | // character memory write function |
| 200 | cdp1869_char_ram_write_func out_char_ram_func; |
| 150 | 201 | |
| 151 | | /* character memory read function */ |
| 152 | | cdp1869_char_ram_read_func char_ram_r; |
| 202 | // if specified, this gets called for every change of the predisplay pin (CDP1870/76 pin 1) |
| 203 | devcb_write_line out_prd_func; |
| 204 | }; |
| 153 | 205 | |
| 154 | | /* character memory write function */ |
| 155 | | cdp1869_char_ram_write_func char_ram_w; |
| 156 | 206 | |
| 157 | | /* if specified, this gets called for every change of the predisplay pin (CDP1870/76 pin 1) */ |
| 158 | | devcb_write_line out_prd_func; |
| 207 | |
| 208 | // ======================> cdp1869_device_config |
| 209 | |
| 210 | class cdp1869_device_config : public device_config, |
| 211 | public device_config_sound_interface, |
| 212 | public device_config_memory_interface, |
| 213 | public cdp1869_interface |
| 214 | { |
| 215 | friend class cdp1869_device; |
| 216 | |
| 217 | // construction/destruction |
| 218 | cdp1869_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 219 | |
| 220 | public: |
| 221 | // allocators |
| 222 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 223 | virtual device_t *alloc_device(running_machine &machine) const; |
| 224 | |
| 225 | protected: |
| 226 | // device_config overrides |
| 227 | virtual void device_config_complete(); |
| 228 | |
| 229 | // device_config_memory_interface overrides |
| 230 | virtual const address_space_config *memory_space_config(int spacenum = 0) const; |
| 231 | |
| 232 | // address space configurations |
| 233 | const address_space_config m_space_config; |
| 159 | 234 | }; |
| 160 | 235 | |
| 161 | | /*************************************************************************** |
| 162 | | PROTOTYPES |
| 163 | | ***************************************************************************/ |
| 164 | 236 | |
| 165 | | /* palette initialization */ |
| 166 | | PALETTE_INIT( cdp1869 ); |
| 167 | 237 | |
| 168 | | /* register access */ |
| 169 | | WRITE8_DEVICE_HANDLER( cdp1869_out3_w ); |
| 170 | | WRITE8_DEVICE_HANDLER( cdp1869_out4_w ); |
| 171 | | WRITE8_DEVICE_HANDLER( cdp1869_out5_w ); |
| 172 | | WRITE8_DEVICE_HANDLER( cdp1869_out6_w ); |
| 173 | | WRITE8_DEVICE_HANDLER( cdp1869_out7_w ); |
| 238 | // ======================> cdp1869_device |
| 174 | 239 | |
| 175 | | /* character memory access */ |
| 176 | | READ8_DEVICE_HANDLER ( cdp1869_charram_r ); |
| 177 | | WRITE8_DEVICE_HANDLER ( cdp1869_charram_w ); |
| 240 | class cdp1869_device : public device_t, |
| 241 | public device_sound_interface, |
| 242 | public device_memory_interface |
| 243 | { |
| 244 | friend class cdp1869_device_config; |
| 178 | 245 | |
| 179 | | /* page memory access */ |
| 180 | | READ8_DEVICE_HANDLER ( cdp1869_pageram_r ); |
| 181 | | WRITE8_DEVICE_HANDLER ( cdp1869_pageram_w ); |
| 246 | // construction/destruction |
| 247 | cdp1869_device(running_machine &_machine, const cdp1869_device_config &_config); |
| 182 | 248 | |
| 183 | | /* predisplay */ |
| 184 | | READ_LINE_DEVICE_HANDLER( cdp1869_predisplay_r ); |
| 249 | public: |
| 250 | DECLARE_WRITE8_MEMBER( out3_w ); |
| 251 | DECLARE_WRITE8_MEMBER( out4_w ); |
| 252 | DECLARE_WRITE8_MEMBER( out5_w ); |
| 253 | DECLARE_WRITE8_MEMBER( out6_w ); |
| 254 | DECLARE_WRITE8_MEMBER( out7_w ); |
| 185 | 255 | |
| 186 | | /* PAL/NTSC */ |
| 187 | | READ_LINE_DEVICE_HANDLER( cdp1869_pal_ntsc_r ); |
| 256 | DECLARE_READ8_MEMBER( char_ram_r ); |
| 257 | DECLARE_WRITE8_MEMBER( char_ram_w ); |
| 188 | 258 | |
| 189 | | /* screen update */ |
| 190 | | void cdp1869_update(running_device *device, bitmap_t *bitmap, const rectangle *cliprect); |
| 259 | DECLARE_READ8_MEMBER( page_ram_r ); |
| 260 | DECLARE_WRITE8_MEMBER( page_ram_w ); |
| 191 | 261 | |
| 262 | DECLARE_READ_LINE_MEMBER( predisplay_r ); |
| 263 | DECLARE_READ_LINE_MEMBER( pal_ntsc_r ); |
| 264 | |
| 265 | void update_screen(bitmap_t *bitmap, const rectangle *cliprect); |
| 266 | |
| 267 | protected: |
| 268 | // device-level overrides |
| 269 | virtual void device_start(); |
| 270 | virtual void device_post_load(); |
| 271 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 272 | |
| 273 | // internal callbacks |
| 274 | static STREAM_UPDATE( static_stream_generate ); |
| 275 | virtual void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 276 | |
| 277 | inline bool is_ntsc(); |
| 278 | inline UINT8 read_page_ram_byte(offs_t address); |
| 279 | inline void write_page_ram_byte(offs_t address, UINT8 data); |
| 280 | inline UINT8 read_char_ram_byte(offs_t pma, offs_t cma, UINT8 pmd); |
| 281 | inline void write_char_ram_byte(offs_t pma, offs_t cma, UINT8 pmd, UINT8 data); |
| 282 | inline int read_pcb(offs_t pma, offs_t cma, UINT8 pmd); |
| 283 | inline void update_prd_changed_timer(); |
| 284 | inline rgb_t get_rgb(int i, int c, int l); |
| 285 | inline int get_lines(); |
| 286 | inline UINT16 get_pmemsize(int cols, int rows); |
| 287 | inline UINT16 get_pma(); |
| 288 | inline int get_pen(int ccb0, int ccb1, int pcb); |
| 289 | |
| 290 | void initialize_palette(); |
| 291 | void draw_line(bitmap_t *bitmap, const rectangle *rect, int x, int y, UINT8 data, int color); |
| 292 | void draw_char(bitmap_t *bitmap, const rectangle *rect, int x, int y, UINT16 pma); |
| 293 | |
| 294 | private: |
| 295 | devcb_resolved_read_line m_in_pal_ntsc_func; |
| 296 | devcb_resolved_write_line m_out_prd_func; |
| 297 | cdp1869_pcb_read_func m_in_pcb_func; |
| 298 | cdp1869_char_ram_read_func m_in_char_ram_func; |
| 299 | cdp1869_char_ram_write_func m_out_char_ram_func; |
| 300 | |
| 301 | screen_device *m_screen; |
| 302 | address_space *m_page_ram; |
| 303 | emu_timer *m_prd_timer; |
| 304 | sound_stream *m_stream; |
| 305 | |
| 306 | // video state |
| 307 | int m_prd; // predisplay |
| 308 | int m_dispoff; // display off |
| 309 | int m_fresvert; // full resolution vertical |
| 310 | int m_freshorz; // full resolution horizontal |
| 311 | int m_cmem; // character memory access mode |
| 312 | int m_dblpage; // double page mode |
| 313 | int m_line16; // 16-line hi-res mode |
| 314 | int m_line9; // 9 line mode |
| 315 | int m_cfc; // color format control |
| 316 | UINT8 m_col; // character color control |
| 317 | UINT8 m_bkg; // background color |
| 318 | UINT16 m_pma; // page memory address |
| 319 | UINT16 m_hma; // home memory address |
| 320 | |
| 321 | // sound state |
| 322 | INT16 m_signal; // current signal |
| 323 | int m_incr; // initial wave state |
| 324 | int m_toneoff; // tone off |
| 325 | int m_wnoff; // white noise off |
| 326 | UINT8 m_tonediv; // tone divisor |
| 327 | UINT8 m_tonefreq; // tone range select |
| 328 | UINT8 m_toneamp; // tone output amplitude |
| 329 | UINT8 m_wnfreq; // white noise range select |
| 330 | UINT8 m_wnamp; // white noise output amplitude |
| 331 | |
| 332 | const cdp1869_device_config &m_config; |
| 333 | }; |
| 334 | |
| 335 | |
| 336 | // device type definition |
| 337 | extern const device_type CDP1869; |
| 338 | |
| 339 | |
| 340 | |
| 192 | 341 | #endif |
src/mess/drivers/cosmicos.c
| r9412 | r9413 | |
| 34 | 34 | |
| 35 | 35 | #include "emu.h" |
| 36 | 36 | #include "includes/cosmicos.h" |
| 37 | | #include "cpu/cdp1802/cdp1802.h" |
| 37 | #include "cpu/cosmac/cosmac.h" |
| 38 | 38 | #include "devices/cassette.h" |
| 39 | 39 | #include "devices/messram.h" |
| 40 | 40 | #include "devices/snapquik.h" |
| r9412 | r9413 | |
| 44 | 44 | #include "video/dm9368.h" |
| 45 | 45 | #include "cosmicos.lh" |
| 46 | 46 | |
| 47 | enum |
| 48 | { |
| 49 | MODE_RUN, |
| 50 | MODE_LOAD, |
| 51 | MODE_PAUSE, |
| 52 | MODE_RESET |
| 53 | }; |
| 54 | |
| 47 | 55 | /* Read/Write Handlers */ |
| 48 | 56 | |
| 49 | 57 | static READ8_DEVICE_HANDLER( video_off_r ) |
| r9412 | r9413 | |
| 193 | 201 | { |
| 194 | 202 | cosmicos_state *state = field->port->machine->driver_data<cosmicos_state>(); |
| 195 | 203 | |
| 196 | | if (!newval && (state->cdp1802_mode == CDP1802_MODE_LOAD)) |
| 204 | if (!newval && !state->wait && !state->clear) |
| 197 | 205 | { |
| 198 | | cputag_set_input_line(field->port->machine, CDP1802_TAG, CDP1802_INPUT_LINE_DMAIN, ASSERT_LINE); |
| 206 | cputag_set_input_line(field->port->machine, CDP1802_TAG, COSMAC_INPUT_LINE_DMAIN, ASSERT_LINE); |
| 199 | 207 | } |
| 200 | 208 | } |
| 201 | 209 | |
| r9412 | r9413 | |
| 204 | 212 | // if in PAUSE mode, set RUN mode until TPB=active |
| 205 | 213 | } |
| 206 | 214 | |
| 207 | | static void set_cdp1802_mode(running_machine *machine, cdp1802_control_mode mode) |
| 215 | static void set_cdp1802_mode(running_machine *machine, int mode) |
| 208 | 216 | { |
| 209 | 217 | cosmicos_state *state = machine->driver_data<cosmicos_state>(); |
| 210 | 218 | |
| 211 | | state->cdp1802_mode = mode; |
| 212 | | |
| 213 | 219 | output_set_led_value(LED_RUN, 0); |
| 214 | 220 | output_set_led_value(LED_LOAD, 0); |
| 215 | 221 | output_set_led_value(LED_PAUSE, 0); |
| r9412 | r9413 | |
| 217 | 223 | |
| 218 | 224 | switch (mode) |
| 219 | 225 | { |
| 220 | | case CDP1802_MODE_RUN: |
| 226 | case MODE_RUN: |
| 221 | 227 | output_set_led_value(LED_RUN, 1); |
| 228 | |
| 229 | state->wait = 1; |
| 230 | state->clear = 1; |
| 222 | 231 | break; |
| 223 | 232 | |
| 224 | | case CDP1802_MODE_LOAD: |
| 233 | case MODE_LOAD: |
| 225 | 234 | output_set_led_value(LED_LOAD, 1); |
| 235 | |
| 236 | state->wait = 0; |
| 237 | state->clear = 0; |
| 226 | 238 | break; |
| 227 | 239 | |
| 228 | | case CDP1802_MODE_PAUSE: |
| 240 | case MODE_PAUSE: |
| 229 | 241 | output_set_led_value(LED_PAUSE, 1); |
| 242 | |
| 243 | state->wait = 1; |
| 244 | state->clear = 0; |
| 230 | 245 | break; |
| 231 | 246 | |
| 232 | | case CDP1802_MODE_RESET: |
| 233 | | cputag_set_input_line(machine, CDP1802_TAG, CDP1802_INPUT_LINE_INT, CLEAR_LINE); |
| 234 | | cputag_set_input_line(machine, CDP1802_TAG, CDP1802_INPUT_LINE_DMAIN, CLEAR_LINE); |
| 247 | case MODE_RESET: |
| 248 | cputag_set_input_line(machine, CDP1802_TAG, COSMAC_INPUT_LINE_INT, CLEAR_LINE); |
| 249 | cputag_set_input_line(machine, CDP1802_TAG, COSMAC_INPUT_LINE_DMAIN, CLEAR_LINE); |
| 235 | 250 | |
| 251 | state->wait = 1; |
| 252 | state->clear = 0; |
| 236 | 253 | state->boot = 1; |
| 237 | 254 | |
| 238 | 255 | output_set_led_value(LED_RESET, 1); |
| r9412 | r9413 | |
| 240 | 257 | } |
| 241 | 258 | } |
| 242 | 259 | |
| 243 | | static INPUT_CHANGED( run ) { if (!newval) set_cdp1802_mode(field->port->machine, CDP1802_MODE_RUN); } |
| 244 | | static INPUT_CHANGED( load ) { if (!newval) set_cdp1802_mode(field->port->machine, CDP1802_MODE_LOAD); } |
| 245 | | static INPUT_CHANGED( cosmicos_pause ) { if (!newval) set_cdp1802_mode(field->port->machine, CDP1802_MODE_PAUSE); } |
| 246 | | static INPUT_CHANGED( reset ) { if (!newval) set_cdp1802_mode(field->port->machine, CDP1802_MODE_RESET); } |
| 260 | static INPUT_CHANGED( run ) { if (!newval) set_cdp1802_mode(field->port->machine, MODE_RUN); } |
| 261 | static INPUT_CHANGED( load ) { if (!newval) set_cdp1802_mode(field->port->machine, MODE_LOAD); } |
| 262 | static INPUT_CHANGED( cosmicos_pause ) { if (!newval) set_cdp1802_mode(field->port->machine, MODE_PAUSE); } |
| 263 | static INPUT_CHANGED( reset ) { if (!newval) set_cdp1802_mode(field->port->machine, MODE_RESET); } |
| 247 | 264 | |
| 248 | 265 | static void clear_input_data(running_machine *machine) |
| 249 | 266 | { |
| r9412 | r9413 | |
| 351 | 368 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_CODE(KEYCODE_F) PORT_CHAR('F') |
| 352 | 369 | |
| 353 | 370 | PORT_START("SPECIAL") |
| 354 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("RET") PORT_CODE(KEYCODE_F1) |
| 355 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("DEC") PORT_CODE(KEYCODE_F2) |
| 356 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("REQ") PORT_CODE(KEYCODE_F3) |
| 357 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("SEQ") PORT_CODE(KEYCODE_F4) |
| 371 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("RET") PORT_CODE(KEYCODE_F1) |
| 372 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("DEC") PORT_CODE(KEYCODE_F2) |
| 373 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("REQ") PORT_CODE(KEYCODE_F3) |
| 374 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("SEQ") PORT_CODE(KEYCODE_F4) |
| 358 | 375 | INPUT_PORTS_END |
| 359 | 376 | |
| 360 | 377 | /* Video */ |
| r9412 | r9413 | |
| 370 | 387 | |
| 371 | 388 | static TIMER_DEVICE_CALLBACK( int_tick ) |
| 372 | 389 | { |
| 373 | | cputag_set_input_line(timer.machine, CDP1802_TAG, CDP1802_INPUT_LINE_INT, ASSERT_LINE); |
| 390 | cputag_set_input_line(timer.machine, CDP1802_TAG, COSMAC_INPUT_LINE_INT, ASSERT_LINE); |
| 374 | 391 | } |
| 375 | 392 | |
| 376 | 393 | static WRITE_LINE_DEVICE_HANDLER( cosmicos_dmaout_w ) |
| r9412 | r9413 | |
| 395 | 412 | DEVCB_LINE_VCC, |
| 396 | 413 | DEVCB_LINE_VCC, |
| 397 | 414 | DEVCB_LINE_VCC, |
| 398 | | DEVCB_CPU_INPUT_LINE(CDP1802_TAG, CDP1802_INPUT_LINE_INT), |
| 415 | DEVCB_CPU_INPUT_LINE(CDP1802_TAG, COSMAC_INPUT_LINE_INT), |
| 399 | 416 | DEVCB_LINE(cosmicos_dmaout_w), |
| 400 | 417 | DEVCB_LINE(cosmicos_efx_w), |
| 401 | 418 | RES_K(2), // R2 |
| r9412 | r9413 | |
| 415 | 432 | |
| 416 | 433 | /* CDP1802 Configuration */ |
| 417 | 434 | |
| 418 | | static CDP1802_MODE_READ( cosmicos_mode_r ) |
| 435 | static READ_LINE_DEVICE_HANDLER( wait_r ) |
| 419 | 436 | { |
| 420 | 437 | cosmicos_state *state = device->machine->driver_data<cosmicos_state>(); |
| 421 | 438 | |
| 422 | | return state->cdp1802_mode; |
| 439 | return state->wait; |
| 423 | 440 | } |
| 424 | 441 | |
| 425 | | static CDP1802_EF_READ( cosmicos_ef_r ) |
| 442 | static READ_LINE_DEVICE_HANDLER( clear_r ) |
| 426 | 443 | { |
| 427 | | /* |
| 428 | | EF1 |
| 429 | | EF2 cassette input |
| 430 | | EF3 |
| 431 | | EF4 ENTER |
| 432 | | */ |
| 444 | cosmicos_state *state = device->machine->driver_data<cosmicos_state>(); |
| 433 | 445 | |
| 434 | | cosmicos_state *state = device->machine->driver_data<cosmicos_state>(); |
| 446 | return state->clear; |
| 447 | } |
| 448 | |
| 449 | static READ_LINE_DEVICE_HANDLER( ef1_r ) |
| 450 | { |
| 435 | 451 | UINT8 special = input_port_read(device->machine, "SPECIAL"); |
| 436 | | UINT8 flags = 0x0f; |
| 437 | 452 | |
| 438 | | /* cassette input */ |
| 439 | | if (cassette_input(state->cassette) < 0.0) |
| 440 | | { |
| 441 | | output_set_led_value(LED_CASSETTE, 1); |
| 442 | | flags &= ~EF2; |
| 443 | | } |
| 444 | | else |
| 445 | | { |
| 446 | | output_set_led_value(LED_CASSETTE, 0); |
| 447 | | } |
| 453 | return BIT(special, 0); |
| 454 | } |
| 448 | 455 | |
| 449 | | /* ENTER */ |
| 450 | | if (!BIT(input_port_read(device->machine, "BUTTONS"), 0)) flags &= ~EF4; |
| 456 | static READ_LINE_DEVICE_HANDLER( ef2_r ) |
| 457 | { |
| 458 | UINT8 special = input_port_read(device->machine, "SPECIAL"); |
| 459 | int casin = cassette_input(device) < 0.0; |
| 460 | |
| 461 | output_set_led_value(LED_CASSETTE, casin); |
| 451 | 462 | |
| 452 | | /* hexadecimal keypad */ |
| 453 | | if (!BIT(special, 0)) flags &= ~EF1; |
| 454 | | if (!BIT(special, 1)) flags &= ~EF2; |
| 455 | | if (!BIT(special, 2)) flags &= ~EF3; |
| 456 | | if (!BIT(special, 3)) flags &= ~(EF2 | EF3); |
| 463 | return BIT(special, 1) | BIT(special, 3) | casin; |
| 464 | } |
| 457 | 465 | |
| 458 | | return flags; |
| 466 | static READ_LINE_DEVICE_HANDLER( ef3_r ) |
| 467 | { |
| 468 | UINT8 special = input_port_read(device->machine, "SPECIAL"); |
| 469 | |
| 470 | return BIT(special, 2) | BIT(special, 3); |
| 459 | 471 | } |
| 460 | 472 | |
| 461 | | static CDP1802_SC_WRITE( cosmicos_sc_w ) |
| 473 | static READ_LINE_DEVICE_HANDLER( ef4_r ) |
| 462 | 474 | { |
| 475 | return BIT(input_port_read(device->machine, "BUTTONS"), 0); |
| 476 | } |
| 477 | |
| 478 | static COSMAC_SC_WRITE( cosmicos_sc_w ) |
| 479 | { |
| 463 | 480 | cosmicos_state *driver_state = device->machine->driver_data<cosmicos_state>(); |
| 464 | 481 | |
| 482 | int sc1 = BIT(sc, 1); |
| 483 | |
| 465 | 484 | if (driver_state->sc1 && !sc1) |
| 466 | 485 | { |
| 467 | 486 | clear_input_data(device->machine); |
| r9412 | r9413 | |
| 469 | 488 | |
| 470 | 489 | if (sc1) |
| 471 | 490 | { |
| 472 | | cpu_set_input_line(device, CDP1802_INPUT_LINE_INT, CLEAR_LINE); |
| 473 | | cpu_set_input_line(device, CDP1802_INPUT_LINE_DMAIN, CLEAR_LINE); |
| 491 | cpu_set_input_line(device, COSMAC_INPUT_LINE_INT, CLEAR_LINE); |
| 492 | cpu_set_input_line(device, COSMAC_INPUT_LINE_DMAIN, CLEAR_LINE); |
| 474 | 493 | } |
| 475 | 494 | |
| 476 | 495 | driver_state->sc1 = sc1; |
| r9412 | r9413 | |
| 499 | 518 | return state->data; |
| 500 | 519 | } |
| 501 | 520 | |
| 502 | | static CDP1802_INTERFACE( cosmicos_config ) |
| 521 | static COSMAC_INTERFACE( cosmicos_config ) |
| 503 | 522 | { |
| 504 | | cosmicos_mode_r, |
| 505 | | cosmicos_ef_r, |
| 506 | | cosmicos_sc_w, |
| 523 | DEVCB_LINE(wait_r), |
| 524 | DEVCB_LINE(clear_r), |
| 525 | DEVCB_LINE(ef1_r), |
| 526 | DEVCB_DEVICE_LINE(CASSETTE_TAG, ef2_r), |
| 527 | DEVCB_LINE(ef3_r), |
| 528 | DEVCB_LINE(ef4_r), |
| 507 | 529 | DEVCB_LINE(cosmicos_q_w), |
| 508 | 530 | DEVCB_HANDLER(cosmicos_dma_r), |
| 531 | DEVCB_NULL, |
| 532 | cosmicos_sc_w, |
| 533 | DEVCB_NULL, |
| 509 | 534 | DEVCB_NULL |
| 510 | 535 | }; |
| 511 | 536 | |
| 537 | |
| 512 | 538 | /* Machine Initialization */ |
| 513 | 539 | |
| 514 | 540 | static MACHINE_START( cosmicos ) |
| r9412 | r9413 | |
| 540 | 566 | set_ram_mode(machine); |
| 541 | 567 | |
| 542 | 568 | /* register for state saving */ |
| 543 | | state_save_register_global(machine, state->cdp1802_mode); |
| 569 | state_save_register_global(machine, state->wait); |
| 570 | state_save_register_global(machine, state->clear); |
| 544 | 571 | state_save_register_global(machine, state->sc1); |
| 545 | 572 | state_save_register_global(machine, state->data); |
| 546 | 573 | state_save_register_global(machine, state->boot); |
| r9412 | r9413 | |
| 558 | 585 | |
| 559 | 586 | static MACHINE_RESET( cosmicos ) |
| 560 | 587 | { |
| 561 | | set_cdp1802_mode(machine, CDP1802_MODE_RESET); |
| 588 | set_cdp1802_mode(machine, MODE_RESET); |
| 562 | 589 | } |
| 563 | 590 | |
| 564 | 591 | /* Quickload */ |
| r9412 | r9413 | |
| 585 | 612 | }; |
| 586 | 613 | |
| 587 | 614 | static MACHINE_CONFIG_START( cosmicos, cosmicos_state ) |
| 588 | | |
| 589 | 615 | /* basic machine hardware */ |
| 590 | | MDRV_CPU_ADD(CDP1802_TAG, CDP1802, XTAL_1_75MHz) |
| 616 | MDRV_CPU_ADD(CDP1802_TAG, COSMAC, XTAL_1_75MHz) |
| 591 | 617 | MDRV_CPU_PROGRAM_MAP(cosmicos_mem) |
| 592 | 618 | MDRV_CPU_IO_MAP(cosmicos_io) |
| 593 | 619 | MDRV_CPU_CONFIG(cosmicos_config) |