pic16: small update, correct savestates (nw)

This commit is contained in:
hap 2017-02-11 04:12:22 +01:00
parent b4acf336b6
commit 56a8b5a73b
3 changed files with 46 additions and 66 deletions

View File

@ -177,8 +177,8 @@ void pic16c5x_device::update_internalram_ptr()
#define PIC16C5x_RAM_RDMEM(A) ((uint8_t)m_data->read_byte(A))
#define PIC16C5x_RAM_WRMEM(A,V) (m_data->write_byte(A,V))
#define M_RDRAM(A) (((A) < 8) ? m_internalram[A] : PIC16C5x_RAM_RDMEM(A))
#define M_WRTRAM(A,V) do { if ((A) < 8) m_internalram[A] = (V); else PIC16C5x_RAM_WRMEM(A,V); } while (0)
#define M_RDRAM(A) (((A) < 9) ? m_internalram[A] : PIC16C5x_RAM_RDMEM(A))
#define M_WRTRAM(A,V) do { if ((A) < 9) m_internalram[A] = (V); else PIC16C5x_RAM_WRMEM(A,V); } while (0)
#define M_RDOP(A) PIC16C5x_RDOP(A)
#define ADDR_MASK 0x7ff
@ -191,6 +191,7 @@ void pic16c5x_device::update_internalram_ptr()
#define PORTA m_internalram[5]
#define PORTB m_internalram[6]
#define PORTC m_internalram[7]
#define PORTD m_internalram[8]
#define INDF M_RDRAM(FSR)
#define ADDR (m_opcode.b.l & 0x1f)
@ -335,21 +336,21 @@ uint8_t pic16c5x_device::GET_REGFILE(offs_t addr) /* Read from internal memory *
switch(addr)
{
case 00: /* Not an actual register, so return 0 */
case 0: /* Not an actual register, so return 0 */
data = 0;
break;
case 04: data = (FSR | (uint8_t)(~m_picRAMmask));
case 4: data = (FSR | (uint8_t)(~m_picRAMmask));
break;
case 05: data = m_read_a(PIC16C5x_PORTA, 0xff);
case 5: data = m_read_a(PIC16C5x_PORTA, 0xff);
data &= m_TRISA;
data |= ((uint8_t)(~m_TRISA) & PORTA);
data &= 0x0f; /* 4-bit port (only lower 4 bits used) */
break;
case 06: data = m_read_b(PIC16C5x_PORTB, 0xff);
case 6: data = m_read_b(PIC16C5x_PORTB, 0xff);
data &= m_TRISB;
data |= ((uint8_t)(~m_TRISB) & PORTB);
break;
case 07: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
case 7: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
data = m_read_c(PIC16C5x_PORTC, 0xff);
data &= m_TRISC;
data |= ((uint8_t)(~m_TRISC) & PORTC);
@ -378,27 +379,27 @@ void pic16c5x_device::STORE_REGFILE(offs_t addr, uint8_t data) /* Write to in
switch(addr)
{
case 00: /* Not an actual register, nothing to save */
case 0: /* Not an actual register, nothing to save */
break;
case 01: m_delay_timer = 2; /* Timer starts after next two instructions */
case 1: m_delay_timer = 2; /* Timer starts after next two instructions */
if (PSA == 0) m_prescaler = 0; /* Must clear the Prescaler */
TMR0 = data;
break;
case 02: PCL = data;
case 2: PCL = data;
m_PC = ((STATUS & PA_REG) << 4) | data;
break;
case 03: STATUS = (STATUS & (TO_FLAG | PD_FLAG)) | (data & (uint8_t)(~(TO_FLAG | PD_FLAG)));
case 3: STATUS = (STATUS & (TO_FLAG | PD_FLAG)) | (data & (uint8_t)(~(TO_FLAG | PD_FLAG)));
break;
case 04: FSR = (data | (uint8_t)(~m_picRAMmask));
case 4: FSR = (data | (uint8_t)(~m_picRAMmask));
break;
case 05: data &= 0x0f; /* 4-bit port (only lower 4 bits used) */
case 5: data &= 0x0f; /* 4-bit port (only lower 4 bits used) */
m_write_a(PIC16C5x_PORTA, data & (uint8_t)(~m_TRISA), 0xff);
PORTA = data;
break;
case 06: m_write_b(PIC16C5x_PORTB, data & (uint8_t)(~m_TRISB), 0xff);
case 6: m_write_b(PIC16C5x_PORTB, data & (uint8_t)(~m_TRISB), 0xff);
PORTB = data;
break;
case 07: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
case 7: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
m_write_c(PIC16C5x_PORTC, data & (uint8_t)(~m_TRISC), 0xff);
PORTC = data;
}
@ -489,7 +490,7 @@ void pic16c5x_device::btfss()
{
if ((GET_REGFILE(ADDR) & bit_set[POS]) == bit_set[POS])
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -499,7 +500,7 @@ void pic16c5x_device::btfsc()
{
if ((GET_REGFILE(ADDR) & bit_set[POS]) == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -553,7 +554,7 @@ void pic16c5x_device::decfsz()
STORE_RESULT(ADDR, m_ALU);
if (m_ALU == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -579,7 +580,7 @@ void pic16c5x_device::incfsz()
STORE_RESULT(ADDR, m_ALU);
if (m_ALU == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -684,11 +685,11 @@ void pic16c5x_device::tris()
{
switch(m_opcode.b.l & 0x7)
{
case 05: if (m_TRISA == m_W) break;
case 5: if (m_TRISA == m_W) break;
else { m_TRISA = m_W | 0xf0; m_write_a(PIC16C5x_PORTA, PORTA & (uint8_t)(~m_TRISA) & 0x0f, 0xff); break; }
case 06: if (m_TRISB == m_W) break;
case 6: if (m_TRISB == m_W) break;
else { m_TRISB = m_W; m_write_b(PIC16C5x_PORTB, PORTB & (uint8_t)(~m_TRISB), 0xff); break; }
case 07: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
case 7: if ((m_picmodel == 0x16C55) || (m_picmodel == 0x16C57)) {
if (m_TRISC == m_W) break;
else { m_TRISC = m_W; m_write_c(PIC16C5x_PORTC, PORTC & (uint8_t)(~m_TRISC), 0xff); break; }
}
@ -722,8 +723,8 @@ void pic16c5x_device::xorwf()
const pic16c5x_device::pic16c5x_opcode pic16c5x_device::s_opcode_main[256]=
{
/*00*/ {1, &pic16c5x_device::nop },{0, &pic16c5x_device::illegal },{1, &pic16c5x_device::movwf },{1, &pic16c5x_device::movwf },
{1, &pic16c5x_device::clrw },{0, &pic16c5x_device::illegal },{1, &pic16c5x_device::clrf },{1, &pic16c5x_device::clrf },
/*00*/ {1, &pic16c5x_device::nop },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::movwf },{1, &pic16c5x_device::movwf },
{1, &pic16c5x_device::clrw },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::clrf },{1, &pic16c5x_device::clrf },
/*08*/ {1, &pic16c5x_device::subwf },{1, &pic16c5x_device::subwf },{1, &pic16c5x_device::subwf },{1, &pic16c5x_device::subwf },
{1, &pic16c5x_device::decf },{1, &pic16c5x_device::decf },{1, &pic16c5x_device::decf },{1, &pic16c5x_device::decf },
/*10*/ {1, &pic16c5x_device::iorwf },{1, &pic16c5x_device::iorwf },{1, &pic16c5x_device::iorwf },{1, &pic16c5x_device::iorwf },
@ -791,10 +792,10 @@ const pic16c5x_device::pic16c5x_opcode pic16c5x_device::s_opcode_main[256]=
const pic16c5x_device::pic16c5x_opcode pic16c5x_device::s_opcode_00x[16]=
{
/*00*/ {1, &pic16c5x_device::nop },{0, &pic16c5x_device::illegal },{1, &pic16c5x_device::option },{1, &pic16c5x_device::sleepic },
/*00*/ {1, &pic16c5x_device::nop },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::option },{1, &pic16c5x_device::sleepic },
{1, &pic16c5x_device::clrwdt },{1, &pic16c5x_device::tris },{1, &pic16c5x_device::tris },{1, &pic16c5x_device::tris },
/*08*/ {0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal },
{0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal },{0, &pic16c5x_device::illegal }
/*08*/ {1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal },
{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal },{1, &pic16c5x_device::illegal }
};
@ -832,13 +833,6 @@ void pic16c5x_device::device_start()
save_item(NAME(m_W));
save_item(NAME(m_ALU));
save_item(NAME(m_OPTION));
save_item(NAME(TMR0));
save_item(NAME(PCL));
save_item(NAME(STATUS));
save_item(NAME(FSR));
save_item(NAME(PORTA));
save_item(NAME(PORTB));
save_item(NAME(PORTC));
save_item(NAME(m_TRISA));
save_item(NAME(m_TRISB));
save_item(NAME(m_TRISC));
@ -847,8 +841,7 @@ void pic16c5x_device::device_start()
save_item(NAME(m_picRAMmask));
save_item(NAME(m_WDT));
save_item(NAME(m_prescaler));
save_item(NAME(m_STACK[0]));
save_item(NAME(m_STACK[1]));
save_item(NAME(m_STACK));
save_item(NAME(m_PC));
save_item(NAME(m_PREVPC));
save_item(NAME(m_CONFIG));
@ -925,7 +918,7 @@ void pic16c5x_device::state_export(const device_state_entry &entry)
m_debugger_temp = TMR0;
break;
case PIC16C5x_PRTA:
m_debugger_temp = PORTA & 0x0f;
m_debugger_temp = PORTA;
break;
case PIC16C5x_PRTB:
m_debugger_temp = PORTB;
@ -978,7 +971,6 @@ void pic16c5x_device::pic16c5x_reset_regs()
m_OPTION = (T0CS_FLAG | T0SE_FLAG | PSA_FLAG | PS_REG);
PCL = 0xff;
FSR |= (uint8_t)(~m_picRAMmask);
PORTA &= 0x0f;
m_prescaler = 0;
m_delay_timer = 0;
m_old_T0 = 0;

View File

@ -22,10 +22,11 @@ enum
{
PIC16C5x_PORTA = 0,
PIC16C5x_PORTB,
PIC16C5x_PORTC
PIC16C5x_PORTC,
PIC16C5x_PORTD
};
// port a, 4 bits, 2-way
// port a, 4 or 8 bits, 2-way
#define MCFG_PIC16C5x_READ_A_CB(_devcb) \
devcb = &pic16c5x_device::set_read_a_callback(*device, DEVCB_##_devcb);
#define MCFG_PIC16C5x_WRITE_A_CB(_devcb) \

View File

@ -529,7 +529,7 @@ void pic16c62x_device::btfss()
{
if ((GET_REGFILE(ADDR) & bit_set[POS]) == bit_set[POS])
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -539,7 +539,7 @@ void pic16c62x_device::btfsc()
{
if ((GET_REGFILE(ADDR) & bit_set[POS]) == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -593,7 +593,7 @@ void pic16c62x_device::decfsz()
STORE_RESULT(ADDR, m_ALU);
if (m_ALU == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -619,7 +619,7 @@ void pic16c62x_device::incfsz()
STORE_RESULT(ADDR, m_ALU);
if (m_ALU == 0)
{
m_PC++ ;
m_PC++;
PCL = m_PC & 0xff;
m_inst_cycles += 1; /* Add NOP cycles */
}
@ -744,8 +744,8 @@ void pic16c62x_device::tris()
{
switch(m_opcode.b.l & 0x7)
{
case 05: STORE_REGFILE(0x85, m_W); break;
case 06: STORE_REGFILE(0x86, m_W); break;
case 5: STORE_REGFILE(0x85, m_W); break;
case 6: STORE_REGFILE(0x86, m_W); break;
default: illegal(); break;
}
}
@ -817,11 +817,11 @@ const pic16c62x_device::pic16c62x_instruction pic16c62x_device::s_instructiontab
void pic16c62x_device::build_opcode_table(void)
{
int instr,mask,bits;
int a;
int instr,mask,bits;
int a;
// defaults
for ( a = 0; a < 16384; a++)
for ( a = 0; a < 0x4000; a++)
{
m_opcode_table[a].cycles = 0;
m_opcode_table[a].function = &pic16c62x_device::illegal;
@ -849,7 +849,7 @@ int a;
break;
}
}
for ( a = 0; a < 16384; a++)
for ( a = 0; a < 0x4000; a++)
{
if (((a & mask) == bits) && (m_opcode_table[a].cycles == 0))
{
@ -882,12 +882,6 @@ void pic16c62x_device::device_start()
save_item(NAME(m_ALU));
save_item(NAME(m_OPTION));
save_item(NAME(m_PCLATH));
save_item(NAME(TMR0));
save_item(NAME(PCL));
save_item(NAME(STATUS));
save_item(NAME(FSR));
save_item(NAME(PORTA));
save_item(NAME(PORTB));
save_item(NAME(m_TRISA));
save_item(NAME(m_TRISB));
save_item(NAME(m_old_T0));
@ -895,14 +889,7 @@ void pic16c62x_device::device_start()
save_item(NAME(m_picRAMmask));
save_item(NAME(m_WDT));
save_item(NAME(m_prescaler));
save_item(NAME(m_STACK[0]));
save_item(NAME(m_STACK[1]));
save_item(NAME(m_STACK[2]));
save_item(NAME(m_STACK[3]));
save_item(NAME(m_STACK[4]));
save_item(NAME(m_STACK[5]));
save_item(NAME(m_STACK[6]));
save_item(NAME(m_STACK[7]));
save_item(NAME(m_STACK));
save_item(NAME(m_PC));
save_item(NAME(m_PREVPC));
save_item(NAME(m_CONFIG));
@ -1143,8 +1130,8 @@ void pic16c62x_device::execute_run()
m_PC++;
PCL++;
m_inst_cycles = m_opcode_table[m_opcode.w.l & 16383].cycles;
(this->*m_opcode_table[m_opcode.w.l & 16383].function)();
m_inst_cycles = m_opcode_table[m_opcode.w.l & 0x3fff].cycles;
(this->*m_opcode_table[m_opcode.w.l & 0x3fff].function)();
if (T0CS) { /* Count mode */
T0_in = S_T0_IN;