diff options
Diffstat (limited to 'src/devices/cpu/pic16c5x')
-rw-r--r-- | src/devices/cpu/pic16c5x/16c5xdsm.cpp | 147 | ||||
-rw-r--r-- | src/devices/cpu/pic16c5x/16c5xdsm.h | 58 | ||||
-rw-r--r-- | src/devices/cpu/pic16c5x/dis16c5x.cpp | 136 | ||||
-rw-r--r-- | src/devices/cpu/pic16c5x/pic16c5x.cpp | 10 | ||||
-rw-r--r-- | src/devices/cpu/pic16c5x/pic16c5x.h | 6 |
5 files changed, 122 insertions, 235 deletions
diff --git a/src/devices/cpu/pic16c5x/16c5xdsm.cpp b/src/devices/cpu/pic16c5x/16c5xdsm.cpp index 03cd0539c8c..4768cbb12e8 100644 --- a/src/devices/cpu/pic16c5x/16c5xdsm.cpp +++ b/src/devices/cpu/pic16c5x/16c5xdsm.cpp @@ -24,86 +24,60 @@ \**************************************************************************/ #include "emu.h" +#include "16c5xdsm.h" #include <ctype.h> -static const uint8_t *rombase; -static const uint8_t *rambase; -static offs_t pcbase; -#define READOP16(A) (rombase[(A) - pcbase] | (rombase[(A) + 1 - pcbase] << 8)) -#define READARG16(A) (rambase[(A) - pcbase] | (rambase[(A) + 1 - pcbase] << 8)) - - - -typedef unsigned char byte; -typedef unsigned short int word; - -#define FMT(a,b) a, b -#define PTRS_PER_FORMAT 2 - -static const char *const regfile[32] = { "Reg$00 (IND)", "Reg$01 (TMR)", "Reg$02 (PCL)", "Reg$03 (ST)", "Reg$04 (FSR)", "Reg$05 (PTA)", "Reg$06 (PTB)", "Reg$07 (PTC)", +const char *const pic16c5x_disassembler::regfile[32] = { "Reg$00 (IND)", "Reg$01 (TMR)", "Reg$02 (PCL)", "Reg$03 (ST)", "Reg$04 (FSR)", "Reg$05 (PTA)", "Reg$06 (PTB)", "Reg$07 (PTC)", "Reg$08", "Reg$09", "Reg$0A", "Reg$0B", "Reg$0C", "Reg$0D", "Reg$0E", "Reg$0F", "Reg$10", "Reg$11", "Reg$12", "Reg$13", "Reg$14", "Reg$15", "Reg$16", "Reg$17", "Reg$18", "Reg$19", "Reg$1A", "Reg$1B", "Reg$1C", "Reg$1D", "Reg$1E", "Reg$1F" }; -static const char *const dest[2] = { "W", "Reg" }; - -static const char *const PIC16C5xFormats[] = { - FMT("000000000000", "nop"), - FMT("000000000010", "option"), - FMT("000000000011", "sleep"), - FMT("000000000100", "clrwdt"), - FMT("000000000101", "tris Port A"), - FMT("000000000110", "tris Port B"), - FMT("000000000111", "tris Port C"), - FMT("0000001fffff", "movwf %F"), - FMT("000001000000", "clrw"), - FMT("0000011fffff", "clrf %F"), - FMT("000010dfffff", "subwf %F,%D"), - FMT("000011dfffff", "decf %F,%D"), - FMT("000100dfffff", "iorwf %F,%D"), - FMT("000101dfffff", "andwf %F,%D"), - FMT("000110dfffff", "xorwf %F,%D"), - FMT("000111dfffff", "addwf %F,%D"), - FMT("001000dfffff", "movf %F,%D"), - FMT("001001dfffff", "comf %F,%D"), - FMT("001010dfffff", "incf %F,%D"), - FMT("001011dfffff", "decfsz %F,%D"), - FMT("001100dfffff", "rrf %F,%D"), - FMT("001101dfffff", "rlf %F,%D"), - FMT("001110dfffff", "swapf %F,%D"), - FMT("001111dfffff", "incfsz %F,%D"), - FMT("0100bbbfffff", "bcf %F,%B"), - FMT("0101bbbfffff", "bsf %F,%B"), - FMT("0110bbbfffff", "btfsc %F,%B"), - FMT("0111bbbfffff", "btfss %F,%B"), - FMT("1000kkkkkkkk", "retlw %K"), - FMT("1001aaaaaaaa", "call %A"), - FMT("101aaaaaaaaa", "goto %A"), - FMT("1100kkkkkkkk", "movlw %K"), - FMT("1101kkkkkkkk", "iorlw %K"), - FMT("1110kkkkkkkk", "andlw %K"), - FMT("1111kkkkkkkk", "xorlw %K"), +const char *const pic16c5x_disassembler::dest[2] = { "W", "Reg" }; + +const char *const pic16c5x_disassembler::PIC16C5xFormats[] = { + "000000000000", "nop", + "000000000010", "option", + "000000000011", "sleep", + "000000000100", "clrwdt", + "000000000101", "tris Port A", + "000000000110", "tris Port B", + "000000000111", "tris Port C", + "0000001fffff", "movwf %F", + "000001000000", "clrw", + "0000011fffff", "clrf %F", + "000010dfffff", "subwf %F,%D", + "000011dfffff", "decf %F,%D", + "000100dfffff", "iorwf %F,%D", + "000101dfffff", "andwf %F,%D", + "000110dfffff", "xorwf %F,%D", + "000111dfffff", "addwf %F,%D", + "001000dfffff", "movf %F,%D", + "001001dfffff", "comf %F,%D", + "001010dfffff", "incf %F,%D", + "001011dfffff", "decfsz %F,%D", + "001100dfffff", "rrf %F,%D", + "001101dfffff", "rlf %F,%D", + "001110dfffff", "swapf %F,%D", + "001111dfffff", "incfsz %F,%D", + "0100bbbfffff", "bcf %F,%B", + "0101bbbfffff", "bsf %F,%B", + "0110bbbfffff", "btfsc %F,%B", + "0111bbbfffff", "btfss %F,%B", + "1000kkkkkkkk", "retlw %K", + "1001aaaaaaaa", "call %A", + "101aaaaaaaaa", "goto %A", + "1100kkkkkkkk", "movlw %K", + "1101kkkkkkkk", "iorlw %K", + "1110kkkkkkkk", "andlw %K", + "1111kkkkkkkk", "xorlw %K", nullptr }; -#define MAX_OPS ((ARRAY_LENGTH(PIC16C5xFormats) - 1) / PTRS_PER_FORMAT) - -struct PIC16C5xOpcode { - word mask; /* instruction mask */ - word bits; /* constant bits */ - word extcode; /* value that gets extension code */ - const char *parse; /* how to parse bits */ - const char *fmt; /* instruction format */ -}; - -static PIC16C5xOpcode Op[MAX_OPS+1]; -static int OpInizialized = 0; - -static void InitDasm16C5x(void) +pic16c5x_disassembler::pic16c5x_disassembler() { const char *p; const char *const *ops; - word mask, bits; + u16 mask, bits; int bit; int i; @@ -136,20 +110,14 @@ static void InitDasm16C5x(void) ops[0],ops[1],bit); } while (isspace((uint8_t)*p)) p++; - if (*p) Op[i].extcode = *p; - Op[i].bits = bits; - Op[i].mask = mask; - Op[i].fmt = ops[1]; - Op[i].parse = ops[0]; + Op.emplace_back(mask, bits, *p, ops[0], ops[1]); - ops += PTRS_PER_FORMAT; + ops += 2; i++; } - - OpInizialized = 1; } -CPU_DISASSEMBLE(pic16c5x) +offs_t pic16c5x_disassembler::disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer ¶ms) { int a, b, d, f, k; /* these can all be filled in by parsing an instruction */ int i; @@ -161,15 +129,9 @@ CPU_DISASSEMBLE(pic16c5x) const char *cp; /* character pointer in OpFormats */ uint32_t flags = 0; - rombase = oprom; - rambase = opram; - pcbase = 2*pc; - - if (!OpInizialized) InitDasm16C5x(); - op = -1; /* no matching opcode */ - code = READOP16(2*pc); - for ( i = 0; i < MAX_OPS; i++) + code = opcodes.r16(pc); + for ( i = 0; i < int(Op.size()); i++) { if ((code & Op[i].mask) == Op[i].bits) { @@ -184,14 +146,14 @@ CPU_DISASSEMBLE(pic16c5x) if (op == -1) { util::stream_format(stream, "???? dw %04Xh",code); - return cnt; + return cnt | SUPPORTED; } //buffertmp = buffer; if (Op[op].extcode) /* Actually, theres no double length opcodes */ { bit = 27; code <<= 16; - code |= READARG16(2*(pc+cnt)); + code |= params.r16(pc+cnt); cnt++; } else @@ -223,9 +185,9 @@ CPU_DISASSEMBLE(pic16c5x) /* now traverse format string */ cp = Op[op].fmt; if (!strncmp(cp, "call", 4)) - flags = DASMFLAG_STEP_OVER; + flags = STEP_OVER; else if (!strncmp(cp, "ret", 3)) - flags = DASMFLAG_STEP_OUT; + flags = STEP_OUT; while (*cp) { @@ -248,5 +210,10 @@ CPU_DISASSEMBLE(pic16c5x) stream << *cp++; } } - return cnt | flags | DASMFLAG_SUPPORTED; + return cnt | flags | SUPPORTED; +} + +uint32_t pic16c5x_disassembler::opcode_alignment() const +{ + return 1; } diff --git a/src/devices/cpu/pic16c5x/16c5xdsm.h b/src/devices/cpu/pic16c5x/16c5xdsm.h new file mode 100644 index 00000000000..de3c8b4425f --- /dev/null +++ b/src/devices/cpu/pic16c5x/16c5xdsm.h @@ -0,0 +1,58 @@ +// license:BSD-3-Clause +// copyright-holders:Tony La Porta + /**************************************************************************\ + * Microchip PIC16C5x Emulator * + * * + * Copyright Tony La Porta * + * Originally written for the MAME project. * + * * + * * + * Addressing architecture is based on the Harvard addressing scheme. * + * * + * Many thanks to those involved in the i8039 Disassembler * + * as this was based on it. * + * * + * * + * * + * A Address to jump to. * + * B Bit address within an 8-bit file register. * + * D Destination select (0 = store result in W (accumulator)) * + * (1 = store result in file register) * + * F Register file address (00-1F). * + * K Literal field, constant data. * + * * + \**************************************************************************/ + +#ifndef MAME_CPU_PIC16C5X_16C5XDSM_H +#define MAME_CPU_PIC16C5X_16C5XDSM_H + +#pragma once + +class pic16c5x_disassembler : public util::disasm_interface +{ +public: + pic16c5x_disassembler(); + virtual ~pic16c5x_disassembler() = default; + + virtual u32 opcode_alignment() const override; + virtual offs_t disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer ¶ms) override; + +private: + struct PIC16C5xOpcode { + u16 mask; /* instruction mask */ + u16 bits; /* constant bits */ + u16 extcode; /* value that gets extension code */ + const char *parse; /* how to parse bits */ + const char *fmt; /* instruction format */ + + PIC16C5xOpcode(u16 m, u16 b, u16 e, const char *p, const char *f) : mask(m), bits(b), extcode(e), parse(p), fmt(f) {} + }; + + static const char *const regfile[32]; + static const char *const dest[2]; + static const char *const PIC16C5xFormats[]; + + std::vector<PIC16C5xOpcode> Op; +}; + +#endif diff --git a/src/devices/cpu/pic16c5x/dis16c5x.cpp b/src/devices/cpu/pic16c5x/dis16c5x.cpp deleted file mode 100644 index 08c7f2657df..00000000000 --- a/src/devices/cpu/pic16c5x/dis16c5x.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Tony La Porta - /**************************************************************************\ - * Microchip PIC16C5x Emulator * - * * - * Copyright Tony La Porta * - * Originally written for the MAME project. * - * * - * * - * Notes : Data is expected to be read from source file as LSB first. * - * * - \**************************************************************************/ - -#include <stdio.h> -#include <string.h> - -#include "16c5xdsm.c" - - -unsigned char *Buffer; - - -int main(int argc,char *argv[]) -{ - int length=0, length_to_dump=0, offset=0, disasm_words=0; - int filelength=0, bytes_read; - int Counter=0; - - FILE *F; - char *String_Output; - - if(argc<2) - { - printf("\n"); - printf("PIC16C5x Disassembler 1.0 by Tony La Porta (C)2003+\n\n"); - printf("Usage: dis16c5x <input-file> [ <start-addr> [ <num-of-addr> ] ]\n"); - printf(" <input-file> source file data must be MSB first\n"); - printf(" <start-addr> starting address to disassemble from (decimal)\n"); - printf(" <num-of-addr> number of addresses to disassemble (decimal)\n"); - printf(" Precede values with 0x if HEX values preffered\n"); - exit(1); - } - - if(!(F=fopen(argv[1],"rb"))) - { - printf("\n%s: Can't open file %s\n",argv[0],argv[1]); - exit(2); - } - argv++; argc--; - if (argv[1]) - { - offset = strtol(argv[1],nullptr,0); - argv++; argc--; - } - if (argv[1]) - { - length = strtol(argv[1],nullptr,0); - argv++; argc--; - } - - fseek(F,0, SEEK_END); - filelength = ftell(F); - - length *= 2; - - if ((length > (filelength - (offset*2))) || (length == 0)) length = filelength - (offset*2); - printf("Length=%04Xh(words) Offset=$%04Xh filelength=%04Xh(words) %04Xh(bytes)\n",length/2,offset,filelength/2,filelength); - length_to_dump = length; - printf("Starting from %d, dumping %d opcodes (word size)\n",offset,length/2); - Buffer = calloc((filelength+1),sizeof(char)); - if (Buffer==nullptr) - { - printf("Out of Memory !!!"); - fclose(F); - exit(3); - } - String_Output = calloc(80,sizeof(char)); - if (String_Output==nullptr) - { - printf("Out of Memory !!!"); - free(Buffer); - fclose(F); - exit(4); - } - - if (fseek(F,0,SEEK_SET) != 0) - { - printf("Error seeking to beginning of file\n"); - free(String_Output); - free(Buffer); - fclose(F); - exit(5); - } - - Counter = offset; - bytes_read = fread(Buffer,sizeof(char),filelength,F); - if (bytes_read >= length) - { - for (; length > 0; length -= (disasm_words*2)) - { - int ii; - disasm_words = Dasm16C5x(String_Output,Counter); - printf("$%03X: ",Counter); - for (ii = 0; ii < disasm_words; ii++) - { - if (((Counter*2) + ii) > filelength) /* Past end of length to dump ? */ - { - sprintf(String_Output,"???? dw %02.2X%02.2Xh (Past end of disassembly !)",Buffer[((Counter-1)*2)+1],Buffer[((Counter-1)*2)]); - } - else - { - printf("%02.2x%02.2x ",Buffer[(Counter*2)+1],Buffer[(Counter*2)]); - } - Counter++ ; - } - for (; ii < 4; ii++) - { - printf(" "); - } - printf("\t%s\n",String_Output); - } - } - else - { - printf("ERROR length to dump was %d ", length_to_dump/2); - printf(", but bytes read from file were %d\n", bytes_read/2); - free(String_Output); - free(Buffer); - fclose(F); - exit(7); - } - free(String_Output); - free(Buffer); - fclose(F); - return(0); -} diff --git a/src/devices/cpu/pic16c5x/pic16c5x.cpp b/src/devices/cpu/pic16c5x/pic16c5x.cpp index 52a9beeac77..d92ae93d3c1 100644 --- a/src/devices/cpu/pic16c5x/pic16c5x.cpp +++ b/src/devices/cpu/pic16c5x/pic16c5x.cpp @@ -73,6 +73,7 @@ #include "emu.h" #include "pic16c5x.h" +#include "16c5xdsm.h" #include "debugger.h" @@ -183,10 +184,9 @@ device_memory_interface::space_config_vector pic16c5x_device::memory_space_confi }; } -offs_t pic16c5x_device::disasm_disassemble(std::ostream &stream, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options) +util::disasm_interface *pic16c5x_device::create_disassembler() { - extern CPU_DISASSEMBLE( pic16c5x ); - return CPU_DISASSEMBLE_NAME(pic16c5x)(this, stream, pc, oprom, opram, options); + return new pic16c5x_disassembler; } @@ -197,7 +197,7 @@ void pic16c5x_device::update_internalram_ptr() -#define PIC16C5x_RDOP(A) (m_direct->read_word((A)<<1)) +#define PIC16C5x_RDOP(A) (m_direct->read_word(A)) #define PIC16C5x_RAM_RDMEM(A) ((uint8_t)m_data->read_byte(A)) #define PIC16C5x_RAM_WRMEM(A,V) (m_data->write_byte(A,V)) @@ -883,7 +883,7 @@ enum void pic16c5x_device::device_start() { m_program = &space(AS_PROGRAM); - m_direct = &m_program->direct(); + m_direct = m_program->direct<-1>(); m_data = &space(AS_DATA); m_read_a.resolve_safe(0); diff --git a/src/devices/cpu/pic16c5x/pic16c5x.h b/src/devices/cpu/pic16c5x/pic16c5x.h index 593397e4847..e51ef9a1c89 100644 --- a/src/devices/cpu/pic16c5x/pic16c5x.h +++ b/src/devices/cpu/pic16c5x/pic16c5x.h @@ -133,9 +133,7 @@ protected: virtual void state_string_export(const device_state_entry &entry, std::string &str) const override; // device_disasm_interface overrides - virtual uint32_t disasm_min_opcode_bytes() const override { return 2; } - virtual uint32_t disasm_max_opcode_bytes() const override { return 2; } - virtual offs_t disasm_disassemble(std::ostream &stream, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options) override; + virtual util::disasm_interface *create_disassembler() override; private: address_space_config m_program_config; @@ -169,7 +167,7 @@ private: int m_inst_cycles; address_space *m_program; - direct_read_data *m_direct; + direct_read_data<-1> *m_direct; address_space *m_data; // i/o handlers |