trunk/src/mess/machine/mos8722.c
| r18534 | r18535 | |
| 55 | 55 | #define CR_ROM_LO BIT(m_reg[CR], 1) |
| 56 | 56 | #define CR_ROM_MID ((m_reg[CR] >> 2) & 0x03) |
| 57 | 57 | #define CR_ROM_HI ((m_reg[CR] >> 4) & 0x03) |
| 58 | | #define CR_RAM ((m_reg[CR] >> 6) & 0x03) |
| 58 | #define CR_A16 BIT(m_reg[CR], 6) |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | // mode configuration register |
| r18534 | r18535 | |
| 161 | 161 | |
| 162 | 162 | void mos8722_device::device_reset() |
| 163 | 163 | { |
| 164 | | for (int i = 0; i < 12; i++) |
| 164 | for (int i = 0; i < 16; i++) |
| 165 | 165 | { |
| 166 | 166 | m_reg[i] = 0; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | | m_p0l_written = false; |
| 170 | | m_p1l_written = false; |
| 169 | m_reg[P1L] = 0x01; |
| 171 | 170 | |
| 171 | m_p0h_latch = 0; |
| 172 | m_p1h_latch = 0; |
| 173 | |
| 172 | 174 | m_out_z80en_func(MCR_8500); |
| 173 | 175 | m_out_fsdir_func(MCR_FSDIR); |
| 174 | 176 | } |
| r18534 | r18535 | |
| 180 | 182 | |
| 181 | 183 | UINT8 mos8722_device::read(offs_t offset, UINT8 data) |
| 182 | 184 | { |
| 183 | | if (!MCR_C64) |
| 185 | if (MCR_C64) return data; |
| 186 | |
| 187 | if (!CR_IO && offset >= 0xd500 && offset < 0xd50c) |
| 184 | 188 | { |
| 185 | | if (!CR_IO && offset >= 0xd500 && offset < 0xd50c) |
| 189 | switch (offset & 0x0f) |
| 186 | 190 | { |
| 187 | | switch (offset & 0x0f) |
| 188 | | { |
| 189 | | case MCR: |
| 190 | | data = m_reg[MCR] & 0x49; |
| 191 | case CR: |
| 192 | data = m_reg[CR] | 0x80; |
| 193 | break; |
| 191 | 194 | |
| 192 | | data |= m_in_game_func() << 4; |
| 193 | | data |= m_in_exrom_func() << 5; |
| 194 | | data |= m_in_sense40_func() << 7; |
| 195 | | break; |
| 195 | case MCR: |
| 196 | data = m_reg[MCR] | 0x06; |
| 196 | 197 | |
| 197 | | case VR: |
| 198 | | data = 0x20; |
| 199 | | break; |
| 198 | data &= ((m_in_game_func() << 4) | ~0x10); |
| 199 | data &= ((m_in_exrom_func() << 5) | ~0x20); |
| 200 | data &= ((m_in_sense40_func() << 7) | ~0x80); |
| 201 | break; |
| 200 | 202 | |
| 201 | | default: |
| 202 | | data = m_reg[offset & 0x0f]; |
| 203 | | break; |
| 204 | | } |
| 203 | case VR: |
| 204 | data = 0x20; |
| 205 | break; |
| 206 | |
| 207 | default: |
| 208 | data = m_reg[offset & 0x0f]; |
| 209 | break; |
| 205 | 210 | } |
| 206 | | else if (offset == 0xff00) |
| 211 | } |
| 212 | else if (offset >= 0xff00 && offset < 0xff05) |
| 213 | { |
| 214 | switch (offset & 0x0f) |
| 207 | 215 | { |
| 208 | | return m_reg[CR]; |
| 216 | case CR: |
| 217 | data = m_reg[CR] | 0x80; |
| 218 | break; |
| 219 | |
| 220 | default: |
| 221 | data = m_reg[offset & 0x0f]; |
| 222 | break; |
| 209 | 223 | } |
| 210 | 224 | } |
| 211 | 225 | |
| r18534 | r18535 | |
| 219 | 233 | |
| 220 | 234 | WRITE8_MEMBER( mos8722_device::write ) |
| 221 | 235 | { |
| 222 | | if (!MCR_C64) |
| 236 | if (MCR_C64) return; |
| 237 | |
| 238 | if (!CR_IO && offset >= 0xd500 && offset < 0xd50c) |
| 223 | 239 | { |
| 224 | | if (!CR_IO && offset >= 0xd500 && offset < 0xd50c) |
| 240 | if (LOG) logerror("MOS8722 '%s' Write %01x : %02x\n", tag(), offset & 0x0f, data); |
| 241 | |
| 242 | switch (offset & 0x0f) |
| 225 | 243 | { |
| 226 | | if (LOG) logerror("MOS8722 '%s' Write %01x : %02x\n", tag(), offset & 0x0f, data); |
| 244 | case CR: |
| 245 | m_reg[CR] = data & 0x7f; |
| 246 | break; |
| 227 | 247 | |
| 228 | | m_reg[offset & 0x0f] = data; |
| 248 | case PCRA: |
| 249 | case PCRB: |
| 250 | case PCRC: |
| 251 | case PCRD: |
| 252 | m_reg[offset & 0x0f] = data & 0x7f; |
| 253 | break; |
| 229 | 254 | |
| 230 | | switch (offset & 0x0f) |
| 231 | | { |
| 232 | | case MCR: |
| 233 | | m_out_z80en_func(MCR_8500); |
| 234 | | m_out_fsdir_func(MCR_FSDIR); |
| 235 | | break; |
| 255 | case MCR: |
| 256 | { |
| 257 | int _8500 = MCR_8500; |
| 258 | int fsdir = MCR_FSDIR; |
| 236 | 259 | |
| 237 | | case P0L: |
| 238 | | m_p0l_written = true; |
| 239 | | break; |
| 260 | m_reg[MCR] = data; |
| 261 | |
| 262 | if (_8500 != MCR_8500) m_out_z80en_func(MCR_8500); |
| 263 | if (fsdir != MCR_FSDIR) m_out_fsdir_func(MCR_FSDIR); |
| 264 | break; |
| 265 | } |
| 240 | 266 | |
| 241 | | case P0H: |
| 242 | | m_p0l_written = false; |
| 243 | | break; |
| 267 | case RCR: |
| 268 | m_reg[RCR] = data & 0x4f; |
| 269 | break; |
| 244 | 270 | |
| 245 | | case P1L: |
| 246 | | m_p1l_written = true; |
| 247 | | break; |
| 271 | case P0L: |
| 272 | m_reg[P0L] = data; |
| 273 | m_reg[P0H] = m_p0h_latch; |
| 274 | break; |
| 248 | 275 | |
| 249 | | case P1H: |
| 250 | | m_p1l_written = false; |
| 251 | | break; |
| 252 | | } |
| 276 | case P0H: |
| 277 | m_p0h_latch = data & 0x01; |
| 278 | break; |
| 279 | |
| 280 | case P1L: |
| 281 | m_reg[P1L] = data; |
| 282 | m_reg[P1H] = m_p1h_latch; |
| 283 | break; |
| 284 | |
| 285 | case P1H: |
| 286 | m_p1h_latch = data & 0x01; |
| 287 | break; |
| 288 | |
| 289 | default: |
| 290 | m_reg[offset & 0x0f] = data; |
| 253 | 291 | } |
| 254 | | else if (offset >= 0xff00 && offset < 0xff05) |
| 292 | } |
| 293 | else if (offset >= 0xff00 && offset < 0xff05) |
| 294 | { |
| 295 | if (LOG) logerror("MOS8722 '%s' Write %01x : %02x\n", tag(), offset & 0x0f, data); |
| 296 | |
| 297 | switch (offset & 0x0f) |
| 255 | 298 | { |
| 256 | | if (LOG) logerror("MOS8722 '%s' Write %01x : %02x\n", tag(), offset & 0x0f, data); |
| 299 | case CR: |
| 300 | m_reg[CR] = data & 0x7f; |
| 301 | break; |
| 257 | 302 | |
| 258 | | switch (offset & 0x0f) |
| 259 | | { |
| 260 | | case CR: |
| 261 | | m_reg[CR] = data; |
| 262 | | break; |
| 263 | | |
| 264 | | default: |
| 265 | | m_reg[CR] = m_reg[offset & 0x0f]; |
| 266 | | break; |
| 267 | | } |
| 303 | default: |
| 304 | m_reg[CR] = m_reg[offset & 0x0f]; |
| 305 | break; |
| 268 | 306 | } |
| 269 | 307 | } |
| 270 | 308 | } |
| r18534 | r18535 | |
| 286 | 324 | |
| 287 | 325 | offs_t mos8722_device::ta_r(offs_t offset, int aec, int *ms0, int *ms1, int *ms2, int *ms3, int *cas0, int *cas1) |
| 288 | 326 | { |
| 289 | | offs_t ta = offset & 0xff00; |
| 327 | offs_t ta; |
| 290 | 328 | |
| 291 | | if (!aec) |
| 292 | | { |
| 293 | | ta = 0xf000 | (offset & 0xf00); |
| 294 | | } |
| 329 | *ms0 = 1; |
| 330 | *ms1 = 1; |
| 331 | *ms2 = CR_IO; |
| 332 | *ms3 = !MCR_C64; |
| 295 | 333 | |
| 296 | | if (!MCR_C64) |
| 334 | if (aec) |
| 297 | 335 | { |
| 298 | | *ms0 = 1; |
| 299 | | *ms1 = 1; |
| 300 | | *ms2 = CR_IO; |
| 336 | // CPU access |
| 337 | ta = offset & 0xff00; |
| 301 | 338 | |
| 302 | | if (offset < 0x1000 && !MCR_8500) |
| 303 | | { |
| 304 | | ta = 0xd000 | (offset & 0xf00); |
| 339 | *cas0 = CR_A16; |
| 340 | *cas1 = !*cas0; |
| 305 | 341 | |
| 306 | | *ms0 = 0; |
| 307 | | *ms1 = 0; |
| 308 | | } |
| 309 | | else if (offset >= 0x4000 && offset < 0x8000) |
| 342 | if (!MCR_C64) |
| 310 | 343 | { |
| 311 | | *ms0 = CR_ROM_LO; |
| 312 | | *ms1 = CR_ROM_LO; |
| 313 | | } |
| 314 | | else if (offset >= 0x8000 && offset < 0xc000) |
| 315 | | { |
| 316 | | *ms0 = BIT(CR_ROM_MID, 0); |
| 317 | | *ms1 = BIT(CR_ROM_MID, 1); |
| 318 | | } |
| 319 | | else if (offset >= 0xc000) |
| 320 | | { |
| 321 | | *ms0 = BIT(CR_ROM_HI, 0); |
| 322 | | *ms1 = BIT(CR_ROM_HI, 1); |
| 323 | | } |
| 344 | if (offset >= 0xff00 && offset < 0xff05) |
| 345 | { |
| 346 | // MMU registers |
| 347 | *cas0 = 1; |
| 348 | *cas1 = 1; |
| 349 | } |
| 350 | else if (!MCR_8500 && !CR_A16 && offset < 0x1000) |
| 351 | { |
| 352 | // Z80 ROM |
| 353 | ta = 0xd000 | (offset & 0xf00); |
| 324 | 354 | |
| 325 | | if (*ms0 == 1 && *ms1 == 1) |
| 326 | | { |
| 327 | | if (aec) |
| 355 | *ms0 = 0; |
| 356 | *ms1 = 0; |
| 357 | } |
| 358 | else |
| 328 | 359 | { |
| 329 | | *cas0 = BIT(CR_RAM, 0); |
| 330 | | *cas1 = BIT(CR_RAM, 1); |
| 331 | | |
| 332 | 360 | if (offset < 0x0100) |
| 333 | 361 | { |
| 334 | | if (m_p0l_written && m_reg[P0L]) |
| 335 | | { |
| 336 | | ta = m_reg[P0L] << 8; |
| 362 | // page 0 pointer |
| 363 | ta = m_reg[P0L] << 8; |
| 337 | 364 | |
| 338 | | *cas0 = P0H_A16 ? 1 : 0; |
| 339 | | *cas1 = P0H_A16 ? 0 : 1; |
| 340 | | } |
| 365 | *cas0 = P0H_A16; |
| 366 | *cas1 = !*cas0; |
| 341 | 367 | } |
| 342 | 368 | else if (offset < 0x0200) |
| 343 | 369 | { |
| 344 | | if (m_p1l_written && m_reg[P1L]) |
| 370 | // page 1 pointer |
| 371 | ta = m_reg[P1L] << 8; |
| 372 | |
| 373 | *cas0 = P1H_A16; |
| 374 | *cas1 = !*cas0; |
| 375 | } |
| 376 | else if (offset >= 0x4000 && offset < 0x8000) |
| 377 | { |
| 378 | // low ROM |
| 379 | *ms0 = CR_ROM_LO; |
| 380 | *ms1 = CR_ROM_LO; |
| 381 | } |
| 382 | else if (offset >= 0x8000 && offset < 0xc000) |
| 383 | { |
| 384 | // middle ROM |
| 385 | *ms0 = BIT(CR_ROM_MID, 0); |
| 386 | *ms1 = BIT(CR_ROM_MID, 1); |
| 387 | } |
| 388 | else if (offset >= 0xc000) |
| 389 | { |
| 390 | // high ROM |
| 391 | *ms0 = BIT(CR_ROM_HI, 0); |
| 392 | *ms1 = BIT(CR_ROM_HI, 1); |
| 393 | } |
| 394 | |
| 395 | if (*ms0 && *ms1) |
| 396 | { |
| 397 | if ((offset >> 8) == m_reg[P0L]) |
| 345 | 398 | { |
| 346 | | ta = m_reg[P1L] << 8; |
| 347 | | |
| 348 | | *cas0 = P1H_A16 ? 1 : 0; |
| 349 | | *cas1 = P1H_A16 ? 0 : 1; |
| 399 | ta = 0x0000; |
| 350 | 400 | } |
| 401 | else if ((offset >> 8) == m_reg[P1L]) |
| 402 | { |
| 403 | ta = 0x0100; |
| 404 | } |
| 351 | 405 | } |
| 352 | 406 | |
| 353 | 407 | if ((RCR_BOTTOM && offset < RCR_BOTTOM_ADDRESS[RCR_SHARE]) || |
| 354 | 408 | (RCR_TOP && offset >= RCR_TOP_ADDRESS[RCR_SHARE])) |
| 355 | 409 | { |
| 410 | // RAM sharing |
| 356 | 411 | *cas0 = 0; |
| 357 | | *cas1 = 1; |
| 412 | *cas1 = !*cas0; |
| 358 | 413 | } |
| 359 | 414 | } |
| 360 | | else |
| 361 | | { |
| 362 | | *cas0 = RCR_VA16 ? 1 : 0; |
| 363 | | *cas1 = RCR_VA16 ? 0 : 1; |
| 364 | | } |
| 365 | 415 | } |
| 366 | | else |
| 367 | | { |
| 368 | | *cas0 = 1; |
| 369 | | *cas1 = 1; |
| 370 | | } |
| 371 | 416 | } |
| 372 | 417 | else |
| 373 | 418 | { |
| 374 | | *ms0 = 1; |
| 375 | | *ms1 = 1; |
| 376 | | *ms2 = 1; |
| 419 | // VIC access |
| 420 | ta = 0xf000 | (offset & 0xf00); |
| 377 | 421 | |
| 378 | | *cas0 = 0; |
| 379 | | *cas1 = 1; |
| 422 | *cas0 = RCR_VA16; |
| 423 | *cas1 = !*cas0; |
| 380 | 424 | } |
| 381 | 425 | |
| 382 | | *ms3 = !MCR_C64; |
| 383 | | |
| 384 | 426 | return ta; |
| 385 | 427 | } |