src/emu/cpu/sm8500/sm8500.c
| r8776 | r8777 | |
| 7 | 7 | this cpu, and made educated guesses on the number of cycles for each instruction. |
| 8 | 8 | |
| 9 | 9 | Code by Wilbert Pol |
| 10 | |
| 11 | |
| 12 | There is some internal ram for the main cpu registers. They are offset by an index value. |
| 13 | The address is (PS0 & 0xF8) + register number. It is not known what happens when PS0 >= F8. |
| 14 | The assumption is that F8 to 107 is used, but it might wrap around instead. |
| 15 | The registers also mirror out to main RAM, appearing at 0000 to 000F regardless of where |
| 16 | they are internally. |
| 17 | |
| 10 | 18 | */ |
| 11 | 19 | |
| 12 | 20 | #include "emu.h" |
| r8776 | r8777 | |
| 45 | 53 | legacy_cpu_device *device; |
| 46 | 54 | const address_space *program; |
| 47 | 55 | UINT16 oldpc; |
| 56 | UINT8 register_ram[0x108]; |
| 48 | 57 | }; |
| 49 | 58 | |
| 50 | 59 | INLINE sm8500_state *get_safe_token(running_device *device) |
| r8776 | r8777 | |
| 65 | 74 | if (cpustate->SYS&0x40) cpustate->SP |= data; |
| 66 | 75 | } |
| 67 | 76 | |
| 68 | | static UINT8 sm85cpu_mem_readbyte( sm8500_state *cpustate, UINT32 offset ) { |
| 69 | | if (offset < 0x10) offset+= cpustate->PS0 & 0xf8; |
| 70 | | return memory_read_byte( cpustate->program, offset ); |
| 77 | static UINT8 sm85cpu_mem_readbyte( sm8500_state *cpustate, UINT32 offset ) |
| 78 | { |
| 79 | offset &= 0xffff; |
| 80 | return (offset < 0x10) ? cpustate->register_ram[offset + (cpustate->PS0 & 0xF8)] |
| 81 | : memory_read_byte( cpustate->program, offset ); |
| 71 | 82 | } |
| 72 | 83 | |
| 73 | | static void sm85cpu_mem_writebyte( sm8500_state *cpustate, UINT32 offset, UINT8 data ) { |
| 74 | | if (offset < 0x10) offset+= cpustate->PS0 & 0xf8; |
| 84 | static void sm85cpu_mem_writebyte( sm8500_state *cpustate, UINT32 offset, UINT8 data ) |
| 85 | { |
| 86 | UINT8 i; |
| 87 | offset &= 0xffff; |
| 88 | if (offset < 0x10) |
| 89 | cpustate->register_ram[offset + (cpustate->PS0 & 0xF8)] = data; |
| 90 | |
| 75 | 91 | memory_write_byte( cpustate->program, offset, data ); |
| 92 | |
| 76 | 93 | switch (offset) |
| 77 | 94 | { |
| 78 | 95 | case 0x10: cpustate->IE0 = data; break; |
| r8776 | r8777 | |
| 83 | 100 | case 0x1a: cpustate->CKC = data; break; |
| 84 | 101 | case 0x1c: |
| 85 | 102 | case 0x1d: sm8500_get_sp(cpustate); break; |
| 86 | | case 0x1e: cpustate->PS0 = data; break; |
| 103 | case 0x1e: cpustate->PS0 = data; |
| 104 | for (i = 0; i < 16; i++) // refresh register contents in debugger |
| 105 | memory_write_byte(cpustate->program, i, sm85cpu_mem_readbyte(cpustate, i)); break; |
| 87 | 106 | case 0x1f: cpustate->PS1 = data; break; |
| 88 | 107 | } |
| 89 | 108 | } |
| r8776 | r8777 | |
| 91 | 110 | |
| 92 | 111 | INLINE UINT16 sm85cpu_mem_readword( sm8500_state *cpustate, UINT32 address ) |
| 93 | 112 | { |
| 94 | | UINT16 value = (UINT16) sm85cpu_mem_readbyte( cpustate, address ) << 8; |
| 95 | | value |= sm85cpu_mem_readbyte( cpustate, ( address + 1 ) & 0xffff ); |
| 96 | | return value; |
| 113 | return (sm85cpu_mem_readbyte( cpustate, address ) << 8) | (sm85cpu_mem_readbyte( cpustate, address+1 )); |
| 97 | 114 | } |
| 98 | 115 | |
| 99 | 116 | INLINE void sm85cpu_mem_writeword( sm8500_state *cpustate, UINT32 address, UINT16 value ) |
| 100 | 117 | { |
| 101 | 118 | sm85cpu_mem_writebyte( cpustate, address, value >> 8 ); |
| 102 | | sm85cpu_mem_writebyte( cpustate, ( address + 1 ) & 0xffff, value & 0xff ); |
| 119 | sm85cpu_mem_writebyte( cpustate, ++address, value ); |
| 103 | 120 | } |
| 104 | 121 | |
| 105 | 122 | static CPU_INIT( sm8500 ) |
| r8776 | r8777 | |
| 272 | 289 | } |
| 273 | 290 | if (cpustate->SYS&0x40) memory_write_byte(cpustate->program,0x1c,cpustate->SP>>8); |
| 274 | 291 | memory_write_byte(cpustate->program,0x1d,cpustate->SP&0xFF); |
| 275 | | memory_write_byte(cpustate->program,0x1e,cpustate->PS0); |
| 292 | sm85cpu_mem_writebyte(cpustate,0x1e,cpustate->PS0); // need to update debugger |
| 276 | 293 | memory_write_byte(cpustate->program,0x1f,cpustate->PS1); |
| 277 | 294 | } else { |
| 278 | 295 | mycycles = 4; |
src/mess/machine/gamecom.c
| r8776 | r8777 | |
| 66 | 66 | static GAMECOM_TIMER gamecom_timer[2]; |
| 67 | 67 | static gamecom_sound_t gamecom_sound; |
| 68 | 68 | |
| 69 | | //static const int gamecom_timer_limit[8] = { 2/2, 1024/2, 2048/2, 4096/2, 8192/2, 16384/2, 32768/2, 65536/2 }; |
| 70 | 69 | static const int gamecom_timer_limit[8] = { 2, 1024, 2048, 4096, 8192, 16384, 32768, 65536 }; |
| 71 | 70 | |
| 72 | | |
| 73 | 71 | static void gamecom_dma_init(running_machine *machine); |
| 74 | 72 | |
| 75 | 73 | static TIMER_CALLBACK(gamecom_clock_timer_callback) |
| r8776 | r8777 | |
| 499 | 497 | case 0x04: |
| 500 | 498 | /* Extend RAM->VRAM */ |
| 501 | 499 | gamecom_dma.source_width = 64; |
| 502 | | gamecom_dma.source_bank = (UINT8*)memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 500 | gamecom_dma.source_bank = &gamecom_vram[0x4000]; |
| 503 | 501 | gamecom_dma.dest_bank = &gamecom_vram[(RAM[SM8521_DMVP] & 0x02) ? 0x2000 : 0x0000]; |
| 504 | 502 | break; |
| 505 | 503 | case 0x06: |
| 506 | 504 | /* VRAM->Extend RAM */ |
| 507 | 505 | gamecom_dma.source_bank = &gamecom_vram[(RAM[SM8521_DMVP] & 0x01) ? 0x2000 : 0x0000]; |
| 508 | 506 | gamecom_dma.dest_width = 64; |
| 509 | | gamecom_dma.dest_bank = (UINT8*)memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 507 | gamecom_dma.dest_bank = &gamecom_vram[0x4000]; |
| 510 | 508 | break; |
| 511 | 509 | } |
| 512 | 510 | gamecom_dma.source_current = gamecom_dma.source_width * gamecom_dma.source_y; |