From ea07eb1f5ff969e5c4dcc292a843e3b49120c672 Mon Sep 17 00:00:00 2001 From: system11b Date: Sat, 5 Dec 2015 19:16:50 +0000 Subject: [PATCH 01/28] These games are all mono --- src/mame/drivers/psikyo.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/mame/drivers/psikyo.cpp b/src/mame/drivers/psikyo.cpp index 906bd5fd00a..6f9ea7a0934 100644 --- a/src/mame/drivers/psikyo.cpp +++ b/src/mame/drivers/psikyo.cpp @@ -1055,14 +1055,11 @@ static MACHINE_CONFIG_START( sngkace, psikyo_state ) MCFG_VIDEO_START_OVERRIDE(psikyo_state,sngkace) /* sound hardware */ - MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") + MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD("ymsnd", YM2610, XTAL_32MHz/4) /* verified on pcb */ MCFG_YM2610_IRQ_HANDLER(INPUTLINE("audiocpu", 0)) - MCFG_SOUND_ROUTE(0, "lspeaker", 1.2) - MCFG_SOUND_ROUTE(0, "rspeaker", 1.2) - MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) - MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END @@ -1101,14 +1098,11 @@ static MACHINE_CONFIG_START( gunbird, psikyo_state ) MCFG_VIDEO_START_OVERRIDE(psikyo_state,psikyo) /* sound hardware */ - MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") + MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD("ymsnd", YM2610, 8000000) MCFG_YM2610_IRQ_HANDLER(INPUTLINE("audiocpu", 0)) - MCFG_SOUND_ROUTE(0, "lspeaker", 1.2) - MCFG_SOUND_ROUTE(0, "rspeaker", 1.2) - MCFG_SOUND_ROUTE(1, "lspeaker", 1.0) - MCFG_SOUND_ROUTE(2, "rspeaker", 1.0) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END static MACHINE_CONFIG_START( s1945bl, psikyo_state ) /* Bootleg hardware based on the unprotected Japanese Strikers 1945 set */ @@ -1181,12 +1175,11 @@ static MACHINE_CONFIG_START( s1945, psikyo_state ) MCFG_VIDEO_START_OVERRIDE(psikyo_state,psikyo) /* sound hardware */ - MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") + MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD("ymf", YMF278B, YMF278B_STD_CLOCK) MCFG_YMF278B_IRQ_HANDLER(INPUTLINE("audiocpu", 0)) - MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) - MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) MACHINE_CONFIG_END From d1abdea08c5ca8cabcca155ae1177b08e808f9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sat, 28 Nov 2015 07:30:41 -0200 Subject: [PATCH 02/28] quick draft/boilerplate code for the Patinho Feio CPU emulation module --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 73 +++++++++++++++++++ src/devices/cpu/patinhofeio/patinho_feio.h | 61 ++++++++++++++++ .../cpu/patinhofeio/patinho_feio_dasm.cpp | 36 +++++++++ 3 files changed, 170 insertions(+) create mode 100644 src/devices/cpu/patinhofeio/patinho_feio.cpp create mode 100644 src/devices/cpu/patinhofeio/patinho_feio.h create mode 100644 src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp new file mode 100644 index 00000000000..30ad62c925d --- /dev/null +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -0,0 +1,73 @@ +// license:GPL2+ +// copyright-holders:Felipe Sanches +/* + Patinho Feio +*/ + +#include "emu.h" +#include "debugger.h" +#include "patinho_feio.h" + +#define CI m_ci //The program counter is called "contador de instrucoes" in portuguese +#define ACC m_acc + +#define ADDRESS_MASK_4K 0xFFF +#define INCREMENT_CI_4K (CI = (CI+1) & ADDRESS_MASK_4K) + +const device_type PATINHO_FEIO = &device_creator; + +patinho_feio_device::patinho_feio_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__) +{ +} + +void patinho_feio_device::device_start() +{ + m_ci = 0; + m_acc = 0; + + m_program = &space(AS_PROGRAM); + + save_item(NAME(m_ci)); + save_item(NAME(m_acc)); + + // Register state for debugger + state_add( PATINHO_FEIO_PC, "CI", m_pc ).mask(0xFFF); + state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); +} + + +void patinho_feio_device::device_reset() +{ +} +/* execute instructions on this CPU until icount expires */ +void patinho_feio_device::execute_run() +{ + do + { + debugger_instruction_hook(this, CI); + + if ((! m_run)){ + m_icount = 0; /* if processor is stopped, just burn cycles */ + } else { + execute_instruction(); + m_icount --; + } + } + while (m_icount > 0); +} + + +/* execute one instruction */ +void patinho_feio_device::execute_instruction() +{ +// char opcode = patinho_feio_read(CI); + INCREMENT_CI_4K; +} + +offs_t patinho_feio_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) +{ + extern CPU_DISASSEMBLE( patinho_feio ); + return CPU_DISASSEMBLE_NAME(patinho_feio)(this, buffer, pc, oprom, opram, options); +} + diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h new file mode 100644 index 00000000000..545fe70ed12 --- /dev/null +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -0,0 +1,61 @@ +// license:GPL2+ +// copyright-holders:Felipe Sanches +#pragma once + +#ifndef __PATINHOFEIO_H__ +#define __PATINHOFEIO_H__ + +/* register IDs */ +enum +{ + PATINHOFEIO_CI=1, PATINHOFEIO_ACC +}; + +class patinho_feio_device : public cpu_device +{ +public: + // construction/destruction + patinho_feio_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); + +protected: + virtual void execute_run(); + virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options); + + address_space_config m_program_config; + + /* processor registers */ + int m_acc; /* accumulator (8 bits) */ + int m_ci; /* program counter (12 bits) (CI stands for "Contador de Instrucao")*/ + + /* processor state flip-flops */ + unsigned int m_run; /* processor is running */ + + int m_address_mask; /* address mask */ + int m_ir_mask; /* IR mask */ + int m_icount; + + address_space *m_program; + + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + // device_execute_interface overrides + virtual UINT32 execute_min_cycles() const { return 1; } + virtual UINT32 execute_max_cycles() const { return 3; } + + // device_memory_interface overrides + virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; } + + // device_disasm_interface overrides + virtual UINT32 disasm_min_opcode_bytes() const { return 4; } + virtual UINT32 disasm_max_opcode_bytes() const { return 4; } + +private: + void execute_instruction(); +}; + + +extern const device_type PATINHO_FEIO; + +#endif /* __PATINHOFEIO_H__ */ diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp new file mode 100644 index 00000000000..b4e21ac3a0b --- /dev/null +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -0,0 +1,36 @@ +// license:GPL2+ +// copyright-holders:Felipe Sanches +#include "emu.h" +#include "cpu/patinhofeio/patinho_feio.h" + +CPU_DISASSEMBLE( patinho_feio ) +{ +// int md; +// int x; +// md = oprom[1] << 8 | oprom[0]; +// x = md & 0xFFF; + + //single-opcode instructions + switch (oprom[0]) + { + case 0x80: + sprintf (buffer, "LIMPO"); + break; + case 0x85: + sprintf (buffer, "INC"); + break; + case 0x96: + sprintf (buffer, "SV 1"); + break; + case 0x99: + sprintf (buffer, "TRE"); + break; + case 0x9D: + sprintf (buffer, "PARE"); + break; + default: + sprintf (buffer, "illegal"); + break; + } + return 1; +} From 0618c642ba8a33411539449060c9cb604508fe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sat, 28 Nov 2015 09:59:12 -0200 Subject: [PATCH 03/28] adding a basic machine driver for the Patinho Feio and setting up build system for the driver and the CPU module --- scripts/src/cpu.lua | 16 +++++ scripts/target/mame/mess.lua | 7 +++ src/devices/cpu/patinhofeio/patinho_feio.cpp | 39 +++++++----- src/devices/cpu/patinhofeio/patinho_feio.h | 20 +++--- .../cpu/patinhofeio/patinho_feio_dasm.cpp | 2 +- src/mame/drivers/patinho_feio.cpp | 63 +++++++++++++++++++ src/mame/mess.lst | 3 + 7 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 src/mame/drivers/patinho_feio.cpp diff --git a/scripts/src/cpu.lua b/scripts/src/cpu.lua index dc2eb538b00..985d47c0611 100644 --- a/scripts/src/cpu.lua +++ b/scripts/src/cpu.lua @@ -1435,6 +1435,22 @@ if (CPUS["PDP1"]~=null or _OPTIONS["with-tools"]) then table.insert(disasm_files , MAME_DIR .. "src/devices/cpu/pdp1/tx0dasm.cpp") end +-------------------------------------------------- +-- PATINHO FEIO - Escola Politecnica - USP (Brazil) +--@src/devices/cpu/patinhofeio/patinho_feio.h,CPUS["PATINHOFEIO"] = true +-------------------------------------------------- + +if (CPUS["PATINHOFEIO"]~=null) then + files { + MAME_DIR .. "src/devices/cpu/patinhofeio/patinho_feio.cpp", + MAME_DIR .. "src/devices/cpu/patinhofeio/patinho_feio.h", + } +end + +if (CPUS["PATINHOFEIO"]~=null or _OPTIONS["with-tools"]) then + table.insert(disasm_files , MAME_DIR .. "src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp") +end + -------------------------------------------------- -- Motorola PowerPC series --@src/devices/cpu/powerpc/ppc.h,CPUS["POWERPC"] = true diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index e5436770e03..5b16be78d7e 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -91,6 +91,7 @@ CPUS["APEXC"] = true CPUS["CP1610"] = true CPUS["F8"] = true CPUS["LH5801"] = true +CPUS["PATINHOFEIO"] = true CPUS["PDP1"] = true CPUS["SATURN"] = true CPUS["SC61860"] = true @@ -852,6 +853,7 @@ function linkProjects_mame_mess(_target, _subtarget) "ultratec", "unisonic", "unisys", + "usp", "veb", "vidbrain", "videoton", @@ -2845,6 +2847,11 @@ files { MAME_DIR .. "src/mame/drivers/univac.cpp", } +createMESSProjects(_target, _subtarget, "usp") +files { + MAME_DIR .. "src/mame/drivers/patinho_feio.cpp", +} + createMESSProjects(_target, _subtarget, "veb") files { MAME_DIR .. "src/mame/drivers/chessmst.cpp", diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 30ad62c925d..06dfae0ba5a 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -1,27 +1,34 @@ -// license:GPL2+ +// license:GPL-2.0+ // copyright-holders:Felipe Sanches /* - Patinho Feio + CPU emulation for Patinho Feio, the first computer designed and manufactured in Brazil */ #include "emu.h" #include "debugger.h" #include "patinho_feio.h" -#define CI m_ci //The program counter is called "contador de instrucoes" in portuguese +#define CI m_ci //The program counter is called "contador de instrucoes" in portuguese #define ACC m_acc #define ADDRESS_MASK_4K 0xFFF #define INCREMENT_CI_4K (CI = (CI+1) & ADDRESS_MASK_4K) -const device_type PATINHO_FEIO = &device_creator; +const device_type PATINHO_FEIO = &device_creator; -patinho_feio_device::patinho_feio_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__) +//Internal 4kbytes of RAM +static ADDRESS_MAP_START(prog_8bit, AS_PROGRAM, 8, patinho_feio_cpu_device) + AM_RANGE(0x0000, 0x0fff) AM_RAM +ADDRESS_MAP_END + +patinho_feio_cpu_device::patinho_feio_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__), + m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(prog_8bit)), + m_icount(0) { } -void patinho_feio_device::device_start() +void patinho_feio_cpu_device::device_start() { m_ci = 0; m_acc = 0; @@ -32,24 +39,28 @@ void patinho_feio_device::device_start() save_item(NAME(m_acc)); // Register state for debugger - state_add( PATINHO_FEIO_PC, "CI", m_pc ).mask(0xFFF); + state_add( PATINHO_FEIO_CI, "CI", m_ci ).mask(0xFFF); state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); + + m_icountptr = &m_icount; + m_run = true; } -void patinho_feio_device::device_reset() +void patinho_feio_cpu_device::device_reset() { } + /* execute instructions on this CPU until icount expires */ -void patinho_feio_device::execute_run() +void patinho_feio_cpu_device::execute_run() { do { - debugger_instruction_hook(this, CI); - if ((! m_run)){ m_icount = 0; /* if processor is stopped, just burn cycles */ } else { + debugger_instruction_hook(this, CI); + execute_instruction(); m_icount --; } @@ -59,13 +70,13 @@ void patinho_feio_device::execute_run() /* execute one instruction */ -void patinho_feio_device::execute_instruction() +void patinho_feio_cpu_device::execute_instruction() { // char opcode = patinho_feio_read(CI); INCREMENT_CI_4K; } -offs_t patinho_feio_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) +offs_t patinho_feio_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) { extern CPU_DISASSEMBLE( patinho_feio ); return CPU_DISASSEMBLE_NAME(patinho_feio)(this, buffer, pc, oprom, opram, options); diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 545fe70ed12..c9b21829277 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -1,4 +1,4 @@ -// license:GPL2+ +// license:GPL-2.0+ // copyright-holders:Felipe Sanches #pragma once @@ -8,14 +8,14 @@ /* register IDs */ enum { - PATINHOFEIO_CI=1, PATINHOFEIO_ACC + PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC }; -class patinho_feio_device : public cpu_device +class patinho_feio_cpu_device : public cpu_device { public: // construction/destruction - patinho_feio_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); + patinho_feio_cpu_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); protected: virtual void execute_run(); @@ -25,13 +25,13 @@ protected: /* processor registers */ int m_acc; /* accumulator (8 bits) */ - int m_ci; /* program counter (12 bits) (CI stands for "Contador de Instrucao")*/ + int m_ci; /* program counter (12 bits) + (CI stands for "Contador de Instrucao") */ /* processor state flip-flops */ - unsigned int m_run; /* processor is running */ + bool m_run; /* processor is running */ int m_address_mask; /* address mask */ - int m_ir_mask; /* IR mask */ int m_icount; address_space *m_program; @@ -42,14 +42,14 @@ protected: // device_execute_interface overrides virtual UINT32 execute_min_cycles() const { return 1; } - virtual UINT32 execute_max_cycles() const { return 3; } + virtual UINT32 execute_max_cycles() const { return 2; } // device_memory_interface overrides virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; } // device_disasm_interface overrides - virtual UINT32 disasm_min_opcode_bytes() const { return 4; } - virtual UINT32 disasm_max_opcode_bytes() const { return 4; } + virtual UINT32 disasm_min_opcode_bytes() const { return 1; } + virtual UINT32 disasm_max_opcode_bytes() const { return 2; } private: void execute_instruction(); diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index b4e21ac3a0b..cefb213014b 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -1,4 +1,4 @@ -// license:GPL2+ +// license:GPL-2.0+ // copyright-holders:Felipe Sanches #include "emu.h" #include "cpu/patinhofeio/patinho_feio.h" diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp new file mode 100644 index 00000000000..07c2c70221a --- /dev/null +++ b/src/mame/drivers/patinho_feio.cpp @@ -0,0 +1,63 @@ +// license:GPL-2.0+ +// copyright-holders:Felipe Sanches +/* + Patinho Feio +*/ + +#include "emu.h" +#include "cpu/patinhofeio/patinho_feio.h" + +class patinho_feio_state : public driver_device +{ +public: + patinho_feio_state(const machine_config &mconfig, device_type type, const char *tag) + : driver_device(mconfig, type, tag) + //,m_maincpu(*this, "maincpu") + { } + + DECLARE_DRIVER_INIT(patinho_feio); +// virtual void machine_start(); +// virtual void machine_reset(); +// required_device m_maincpu; +}; + +/* + driver init function +*/ +DRIVER_INIT_MEMBER(patinho_feio_state, patinho_feio) +{ +} + +static INPUT_PORTS_START( patinho_feio ) +// PORT_START("PANEL") /* various operator control panel switches */ +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) +INPUT_PORTS_END + +//Internal 4kbytes of RAM +static ADDRESS_MAP_START(patinho_program_map, AS_PROGRAM, 8, patinho_feio_state) + AM_RANGE(0x0000, 0x0fff) AM_ROM +ADDRESS_MAP_END + +static MACHINE_CONFIG_START( patinho_feio, patinho_feio_state ) + /* basic machine hardware */ + /* CPU @ approx. 500 kHz (memory cycle time is 2usec) */ + MCFG_CPU_ADD("maincpu", PATINHO_FEIO, 500000) + MCFG_CPU_PROGRAM_MAP(patinho_program_map) +MACHINE_CONFIG_END + +ROM_START(patinho) + /*CPU memory space*/ + ROM_REGION(0x01000,"maincpu", ROMREGION_ERASEFF) + /* Load this into th internal RAM... */ + ROM_LOAD("apendice_g__hexam.bin", 0x000, 0x0d5, CRC(c6addc59) SHA1(126bc97247eac45c58708eaac216c2438e9e4af9) ) +ROM_END + +/* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ +COMP( 1972, patinho, 0, 0, patinho_feio, patinho_feio, patinho_feio_state, patinho_feio, "Escola Politecnica - Universidade de Sao Paulo", "Patinho Feio" , MACHINE_NO_SOUND_HW | MACHINE_NOT_WORKING) diff --git a/src/mame/mess.lst b/src/mame/mess.lst index 188bbdda09d..90d9ecedd9e 100644 --- a/src/mame/mess.lst +++ b/src/mame/mess.lst @@ -1774,6 +1774,9 @@ tmc600s2 //osc1000b nano +// Escola Politecnica da USP (Brazil) +patinho // 1972 Patinho Feio + // MIT tx0_64kw // April 1956 MIT TX-0 (64kw RAM) tx0_8kw // 1962 MIT TX-0 (8kw RAM) From 51b8dfa01b68f190ef5f4f270a29e1334ffe834d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sat, 28 Nov 2015 17:33:43 -0200 Subject: [PATCH 04/28] Implemented most of the instruction set for Patinho Feio --- .../cpu/patinhofeio/patinho_feio_dasm.cpp | 164 +++++++++++++++--- 1 file changed, 139 insertions(+), 25 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index cefb213014b..0f97a3a3935 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -5,32 +5,146 @@ CPU_DISASSEMBLE( patinho_feio ) { -// int md; -// int x; -// md = oprom[1] << 8 | oprom[0]; -// x = md & 0xFFF; - - //single-opcode instructions - switch (oprom[0]) + int addr, value, n, f; + + switch (oprom[0] & 0xF0) { - case 0x80: - sprintf (buffer, "LIMPO"); - break; - case 0x85: - sprintf (buffer, "INC"); - break; - case 0x96: - sprintf (buffer, "SV 1"); - break; - case 0x99: - sprintf (buffer, "TRE"); - break; - case 0x9D: - sprintf (buffer, "PARE"); - break; - default: - sprintf (buffer, "illegal"); - break; + case 0x00: + //PLA = "Pula": Unconditionally JUMP to effective address + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "PLA /%03X", addr); + return 2; + case 0x10: + //PLAX = "Pulo indexado": Unconditionally JUMP to indexed address + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "PLAX (IDX) + /%03X", addr); + return 2; + case 0x20: + //ARM = "Armazena": Stores the contents of the + // accumulator in the given 12bit address + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "ARM /%03X", addr); + return 2; + case 0x30: + //ARMX = "Armazenamento indexado": Stores the contents of the accumulator in the + // given 12bit address (indexed by IDX) + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "ARMX (IDX) + /%03X", addr); + return 2; + case 0x40: + //CAR = "Carrega": Loads the contents of the given 12bit address + // into the accumulator + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "CAR /%03X", addr); + return 2; + case 0x50: + //CARX = "Carga indexada": Loads the contents of the given 12bit address + // (indexed by IDX) into the accumulator + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "CARX (IDX) + /%03X", addr); + return 2; + case 0x60: + //SOM = "Soma": Adds the contents of the given 12bit address + // into the accumulator + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "SOM /%03X", addr); + return 2; + case 0x70: + //SOMX = "Soma indexada": Adds the contents of the given 12bit address + // (indexed by IDX) into the accumulator + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "SOMX (IDX) + /%03X", addr); + return 2; + case 0x80: + case 0x90: + switch (oprom[0]) + { + case 0x80: sprintf (buffer, "LIMPO"); return 1; + case 0x81: sprintf (buffer, "UM"); return 1; + case 0x82: sprintf (buffer, "CMP1"); return 1; + case 0x83: sprintf (buffer, "CMP2"); return 1; + case 0x84: sprintf (buffer, "LIN"); return 1; + case 0x85: sprintf (buffer, "INC"); return 1; + case 0x86: sprintf (buffer, "UNEG"); return 1; + case 0x87: sprintf (buffer, "LIMP1"); return 1; + case 0x90: sprintf (buffer, "ST 0"); return 1; + case 0x91: sprintf (buffer, "STM 0"); return 1; + case 0x92: sprintf (buffer, "ST 1"); return 1; + case 0x93: sprintf (buffer, "STM 1"); return 1; + case 0x94: sprintf (buffer, "SV 0"); return 1; + case 0x95: sprintf (buffer, "SVM 0"); return 1; + case 0x96: sprintf (buffer, "SV 1"); return 1; + case 0x97: sprintf (buffer, "SVM 1"); return 1; + case 0x98: sprintf (buffer, "PUL"); return 1; + case 0x99: sprintf (buffer, "TRE"); return 1; + case 0x9A: sprintf (buffer, "INIB"); return 1; + case 0x9B: sprintf (buffer, "PERM"); return 1; + case 0x9C: sprintf (buffer, "ESP"); return 1; + case 0x9D: sprintf (buffer, "PARE"); return 1; + case 0x9E: sprintf (buffer, "TRI"); return 1; + case 0x9F: sprintf (buffer, "IND"); return 1; + } + break; + case 0xA0: + //PLAN = "Pula se ACC for negativo": Jumps to the 12bit address + // if the accumulator is negative + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "PLAN /%03X", addr); + return 2; + case 0xB0: + //PLAZ = "Pula se ACC for zero": Jumps to the 12bit address + // if the accumulator is zero + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "PLAZ /%03X", addr); + return 2; + case 0xC0: + n = (oprom[0] & 0x0F); + f = (oprom[1] & 0x0F); + n+= (n < 10) ? '0' : 'A'-10; + f+= (f < 10) ? '0' : 'A'-10; + switch(oprom[1] & 0xF0) + { + case 0x10: sprintf (buffer, "FNC /%c%c", n, f); return 2; + case 0x20: sprintf (buffer, "SAL /%c%c", n, f); return 2; + case 0x40: sprintf (buffer, "ENTR /%c0", n); return 2; + case 0x80: sprintf (buffer, "SAI /%c0", n); return 2; + } + break; + case 0xD0: + value = oprom[1]; + switch (oprom[0] & 0x0F) + { + case 0x01: + switch (oprom[1] & 0xF0) + { + case 0x00: sprintf (buffer, "DD /%02X", value); return 2; //DD = "Deslocamento para a direita": Shift right + case 0x10: sprintf (buffer, "DDV /%02X", value); return 2; //DDV = "Deslocamento para a direita c/ V": Shift right with carry + case 0x20: sprintf (buffer, "GD /%02X", value); return 2; //GD = "Giro para a direita": Rotate right + case 0x30: sprintf (buffer, "GDV /%02X", value); return 2; //GDV = "Giro para a direita c/ V": Rotate right with carry + case 0x40: sprintf (buffer, "DE /%02X", value); return 2; //DE = "Deslocamento para a esquerda": Shift right + case 0x50: sprintf (buffer, "DEV /%02X", value); return 2; //DEV = "Deslocamento para a esquerda c/ V": Shift right with carry + case 0x60: sprintf (buffer, "GE /%02X", value); return 2; //GE = "Giro para a esquerda": Rotate right + case 0x70: sprintf (buffer, "GEV /%02X", value); return 2; //GEV = "Giro para a esquerda c/ V": Rotate right with carry + case 0x80: sprintf (buffer, "DDS /%02X", value); return 2; //DDS = "Deslocamento para a direita com duplicacao de sinal": Shift right with sign duplication + } + break; + case 0x02: sprintf (buffer, "XOR /%02X", value); return 2; //Logical XOR + case 0x04: sprintf (buffer, "NAND /%02X", value); return 2; //Logical NAND + case 0x08: sprintf (buffer, "SOMI /%02X", value); return 2; //SOMI = "Soma imediata": Add immediate value into accumulator + case 0x0A: sprintf (buffer, "CARI /%02X", value); return 2; //CARI = "Carrega imediato": Loads an immediate value into the accumulator + } + break; + case 0xE0: + //SUS = "Subtrai um ou salta" + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "SUS /%03X", addr); + return 2; + case 0xF0: + //PUG = "Pula e guarda" + addr = (oprom[0] & 0x0F) << 8 | oprom[1]; + sprintf (buffer, "PUG /%03X", addr); + return 2; } + sprintf (buffer, "illegal instruction"); return 1; } From 9037168f335426ef2c67203171dcdf12c93f5551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 18:58:04 -0200 Subject: [PATCH 05/28] Started implementing the actual emulation of the Patinho Feio instruction set. (previous commits provided only disasm routines) --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 89 ++++++++++++++++---- src/devices/cpu/patinhofeio/patinho_feio.h | 4 +- src/mame/drivers/patinho_feio.cpp | 49 +++++------ 3 files changed, 101 insertions(+), 41 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 06dfae0ba5a..966800403ce 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -8,17 +8,24 @@ #include "debugger.h" #include "patinho_feio.h" -#define CI m_ci //The program counter is called "contador de instrucoes" in portuguese +#define PC m_pc //The program counter is called "contador de instrucoes" in portuguese #define ACC m_acc +#define READ_BYTE_PATINHO(A) ((signed)m_program->read_byte(A)) +#define WRITE_BYTE_PATINHO(A,V) (m_program->write_byte(A,V)) + +#define READ_INDEX_REG() READ_BYTE_PATINHO(0x000) +#define WRITE_INDEX_REG(V) WRITE_BYTE_PATINHO(0x000, V) + #define ADDRESS_MASK_4K 0xFFF -#define INCREMENT_CI_4K (CI = (CI+1) & ADDRESS_MASK_4K) +#define INCREMENT_PC_4K (PC = (PC+1) & ADDRESS_MASK_4K) const device_type PATINHO_FEIO = &device_creator; + //Internal 4kbytes of RAM static ADDRESS_MAP_START(prog_8bit, AS_PROGRAM, 8, patinho_feio_cpu_device) - AM_RANGE(0x0000, 0x0fff) AM_RAM + AM_RANGE(0x0000, 0x0fff) AM_RAM AM_SHARE("internalram") ADDRESS_MAP_END patinho_feio_cpu_device::patinho_feio_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) @@ -30,25 +37,25 @@ patinho_feio_cpu_device::patinho_feio_cpu_device(const machine_config &mconfig, void patinho_feio_cpu_device::device_start() { - m_ci = 0; - m_acc = 0; - m_program = &space(AS_PROGRAM); - save_item(NAME(m_ci)); + save_item(NAME(m_pc)); save_item(NAME(m_acc)); // Register state for debugger - state_add( PATINHO_FEIO_CI, "CI", m_ci ).mask(0xFFF); - state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); - + state_add( PATINHO_FEIO_CI, "CI", m_pc ).mask(0xFFF); + state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); + state_add(STATE_GENPC, "GENPC", m_pc).formatstr("0%06O").noshow(); + m_icountptr = &m_icount; - m_run = true; } void patinho_feio_cpu_device::device_reset() { + m_pc = 0xE00; + m_acc = 0; + m_run = true; } /* execute instructions on this CPU until icount expires */ @@ -59,8 +66,6 @@ void patinho_feio_cpu_device::execute_run() if ((! m_run)){ m_icount = 0; /* if processor is stopped, just burn cycles */ } else { - debugger_instruction_hook(this, CI); - execute_instruction(); m_icount --; } @@ -68,12 +73,64 @@ void patinho_feio_cpu_device::execute_run() while (m_icount > 0); } - /* execute one instruction */ void patinho_feio_cpu_device::execute_instruction() { -// char opcode = patinho_feio_read(CI); - INCREMENT_CI_4K; + debugger_instruction_hook(this, PC); + offs_t addr; + unsigned char tmp; + unsigned char opcode = READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + + switch (opcode){ + case 0xDA: + //CARI="Carrega Imediato": + // Load an immediate into the accumulator + ACC = READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + return; + case 0x9A: + //INIB="Inibe" + // disables interrupts + m_interrupts_enabled = false; + return; + case 0x9B: + //PERM="Permite" + // enables interrupts + m_interrupts_enabled = true; + return; + case 0x9C: + //ESP="Espera": + // Holds execution and waits for an interrupt to occur. + m_run = false; + m_wait_for_interrupt = true; + return; + case 0x9D: + //PARE="Pare": + // Holds execution. This can only be recovered by + // manually triggering execution again by + // pressing the "Partida" (start) button in the panel + m_run = false; + m_wait_for_interrupt = false; + return; + case 0x9E: + //TRI="Troca com Indexador": + // Exchange the value of the accumulator with the index register + tmp = ACC; + ACC = READ_INDEX_REG(); + WRITE_INDEX_REG(tmp); + return; + } + + switch (opcode & 0xF0){ + case 0x00: + //PLA = "Pula": Jump to address + addr = READ_BYTE_PATINHO(PC) & 0xFFF; + INCREMENT_PC_4K; + PC = addr; + return; + } + printf("unimplemented opcode: 0x%02X\n", opcode); } offs_t patinho_feio_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index c9b21829277..c4b08878aa4 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -25,11 +25,13 @@ protected: /* processor registers */ int m_acc; /* accumulator (8 bits) */ - int m_ci; /* program counter (12 bits) + int m_pc; /* program counter (12 bits) (CI stands for "Contador de Instrucao") */ /* processor state flip-flops */ bool m_run; /* processor is running */ + bool m_wait_for_interrupt; + bool m_interrupts_enabled; int m_address_mask; /* address mask */ int m_icount; diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp index 07c2c70221a..9e597b9bccb 100644 --- a/src/mame/drivers/patinho_feio.cpp +++ b/src/mame/drivers/patinho_feio.cpp @@ -16,7 +16,7 @@ public: { } DECLARE_DRIVER_INIT(patinho_feio); -// virtual void machine_start(); + virtual void machine_start(); // virtual void machine_reset(); // required_device m_maincpu; }; @@ -28,35 +28,36 @@ DRIVER_INIT_MEMBER(patinho_feio_state, patinho_feio) { } +void patinho_feio_state::machine_start(){ + //copy the "absolute program example" from appendix G directly into RAM + // This is a hack for setting up the computer + // while we don't support loading programs from punched tape rolls... + UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); + UINT8 *program = memregion("example_program")->base(); + memcpy(&RAM[0xE00], program, 0x0D5); +} + static INPUT_PORTS_START( patinho_feio ) -// PORT_START("PANEL") /* various operator control panel switches */ -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) -// PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_START("PANEL") /* various operator control panel switches */ + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) INPUT_PORTS_END -//Internal 4kbytes of RAM -static ADDRESS_MAP_START(patinho_program_map, AS_PROGRAM, 8, patinho_feio_state) - AM_RANGE(0x0000, 0x0fff) AM_ROM -ADDRESS_MAP_END - static MACHINE_CONFIG_START( patinho_feio, patinho_feio_state ) - /* basic machine hardware */ - /* CPU @ approx. 500 kHz (memory cycle time is 2usec) */ - MCFG_CPU_ADD("maincpu", PATINHO_FEIO, 500000) - MCFG_CPU_PROGRAM_MAP(patinho_program_map) + /* basic machine hardware */ + /* CPU @ approx. 500 kHz (memory cycle time is 2usec) */ + MCFG_CPU_ADD("maincpu", PATINHO_FEIO, 500000) MACHINE_CONFIG_END -ROM_START(patinho) - /*CPU memory space*/ - ROM_REGION(0x01000,"maincpu", ROMREGION_ERASEFF) - /* Load this into th internal RAM... */ - ROM_LOAD("apendice_g__hexam.bin", 0x000, 0x0d5, CRC(c6addc59) SHA1(126bc97247eac45c58708eaac216c2438e9e4af9) ) +ROM_START( patinho ) + ROM_REGION( 0x0d5, "example_program", 0 ) + ROM_LOAD( "apendice_g__hexam.bin", 0x000, 0x0d5, CRC(c6addc59) SHA1(126bc97247eac45c58708eaac216c2438e9e4af9) ) ROM_END /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ From 59e2a7bb4f8013121f8ad3897ca4bb019fc496ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 19:16:16 -0200 Subject: [PATCH 06/28] [patinho] fixing PLA instruction and implementing PUG instruction. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 966800403ce..cc408b54190 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -125,10 +125,20 @@ void patinho_feio_cpu_device::execute_instruction() switch (opcode & 0xF0){ case 0x00: //PLA = "Pula": Jump to address - addr = READ_BYTE_PATINHO(PC) & 0xFFF; + addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; PC = addr; return; + case 0xF0: + //PUG = "Pula e guarda": Jump and store. + // It stores the return address to addr and addr+1 + // And then jumps to addr+2 + addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + WRITE_BYTE_PATINHO(addr, 0x12);//(PC >> 8) & 0x0F); + WRITE_BYTE_PATINHO(addr+1, 0x34);//PC & 0xFF); + PC = addr+2; + return; } printf("unimplemented opcode: 0x%02X\n", opcode); } From 44242c0a93298b3ccfab1fa3ffd8c62de38ecad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 19:58:46 -0200 Subject: [PATCH 07/28] [patinho] Fixed PUG instruction implementation; Added IDX register to the debugger UI; Implemented boilerplate for the 0xCB I/O instructions. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 34 ++++++++++++++++---- src/devices/cpu/patinhofeio/patinho_feio.h | 3 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index cc408b54190..b9569734155 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -15,7 +15,7 @@ #define WRITE_BYTE_PATINHO(A,V) (m_program->write_byte(A,V)) #define READ_INDEX_REG() READ_BYTE_PATINHO(0x000) -#define WRITE_INDEX_REG(V) WRITE_BYTE_PATINHO(0x000, V) +#define WRITE_INDEX_REG(V) { WRITE_BYTE_PATINHO(0x000, V); m_idx = V; } #define ADDRESS_MASK_4K 0xFFF #define INCREMENT_PC_4K (PC = (PC+1) & ADDRESS_MASK_4K) @@ -45,6 +45,7 @@ void patinho_feio_cpu_device::device_start() // Register state for debugger state_add( PATINHO_FEIO_CI, "CI", m_pc ).mask(0xFFF); state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); + state_add( PATINHO_FEIO_IDX, "IDX", m_idx ).mask(0xFF); state_add(STATE_GENPC, "GENPC", m_pc).formatstr("0%06O").noshow(); m_icountptr = &m_icount; @@ -55,6 +56,7 @@ void patinho_feio_cpu_device::device_reset() { m_pc = 0xE00; m_acc = 0; + m_idx = READ_INDEX_REG(); m_run = true; } @@ -78,7 +80,7 @@ void patinho_feio_cpu_device::execute_instruction() { debugger_instruction_hook(this, PC); offs_t addr; - unsigned char tmp; + unsigned char value; unsigned char opcode = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; @@ -116,9 +118,29 @@ void patinho_feio_cpu_device::execute_instruction() case 0x9E: //TRI="Troca com Indexador": // Exchange the value of the accumulator with the index register - tmp = ACC; + value = ACC; ACC = READ_INDEX_REG(); - WRITE_INDEX_REG(tmp); + WRITE_INDEX_REG(value); + return; + case 0xCB: + //Executes I/O functions + //TODO: Implement-me! + value = READ_BYTE_PATINHO(PC); + switch(value & 0xF0){ + case 0x10: + printf("Unimplemented FNC /%X%X instruction\n", opcode & 0x0F, value & 0x0F); + break; + case 0x20: + printf("Unimplemented SAL /%X%X instruction\n", opcode & 0x0F, value & 0x0F); + break; + case 0x40: + printf("Unimplemented ENTR /%X0 instruction\n", opcode & 0x0F); + break; + case 0x80: + printf("Unimplemented SAI /%X0 instruction\n", opcode & 0x0F); + break; + } + INCREMENT_PC_4K; return; } @@ -135,8 +157,8 @@ void patinho_feio_cpu_device::execute_instruction() // And then jumps to addr+2 addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; - WRITE_BYTE_PATINHO(addr, 0x12);//(PC >> 8) & 0x0F); - WRITE_BYTE_PATINHO(addr+1, 0x34);//PC & 0xFF); + WRITE_BYTE_PATINHO(addr, (PC >> 8) & 0x0F); + WRITE_BYTE_PATINHO(addr+1, PC & 0xFF); PC = addr+2; return; } diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index c4b08878aa4..4538ebcea0d 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -8,7 +8,7 @@ /* register IDs */ enum { - PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC + PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX }; class patinho_feio_cpu_device : public cpu_device @@ -27,6 +27,7 @@ protected: int m_acc; /* accumulator (8 bits) */ int m_pc; /* program counter (12 bits) (CI stands for "Contador de Instrucao") */ + int m_idx; /* processor state flip-flops */ bool m_run; /* processor is running */ From 1dff81f125526e29f547d1c759d14ff8c09bd02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 21:21:57 -0200 Subject: [PATCH 08/28] [patinho] Implemented the SAL ("Salta": Skip) instruction. It still depends on handling of I/O devices that are not emulated yet. All devices are currently considered "READY", "OK" and not requesting an interrupt. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 43 +++++++++++++++++--- src/devices/cpu/patinhofeio/patinho_feio.h | 9 ++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index b9569734155..01c671b212d 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -51,13 +51,19 @@ void patinho_feio_cpu_device::device_start() m_icountptr = &m_icount; } - void patinho_feio_cpu_device::device_reset() { m_pc = 0xE00; m_acc = 0; m_idx = READ_INDEX_REG(); m_run = true; + + for (int c=0; c<16; c++) { + m_device_is_ok[c] = true; + m_io_status[c] = DEVICE_READY; + m_IRQ_request[c] = false; + } + } /* execute instructions on this CPU until icount expires */ @@ -80,7 +86,8 @@ void patinho_feio_cpu_device::execute_instruction() { debugger_instruction_hook(this, PC); offs_t addr; - unsigned char value; + bool skip; + unsigned char value, channel, function; unsigned char opcode = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; @@ -126,18 +133,42 @@ void patinho_feio_cpu_device::execute_instruction() //Executes I/O functions //TODO: Implement-me! value = READ_BYTE_PATINHO(PC); + channel = opcode & 0x0F; + function = value & 0x0F; switch(value & 0xF0){ case 0x10: - printf("Unimplemented FNC /%X%X instruction\n", opcode & 0x0F, value & 0x0F); + printf("Unimplemented FNC /%X%X instruction\n", channel, function); break; case 0x20: - printf("Unimplemented SAL /%X%X instruction\n", opcode & 0x0F, value & 0x0F); + //SAL="Salta" + // Skips a couple bytes if a condition is met + skip = false; + switch(function) + { + case 1: + if (m_io_status[channel] == DEVICE_READY) + skip = true; + break; + case 2: + if (m_device_is_ok[channel]) + skip = true; + break; + case 4: + if (m_IRQ_request[channel] == true) + skip = true; + break; + } + + if (skip){ + INCREMENT_PC_4K; + INCREMENT_PC_4K; + } break; case 0x40: - printf("Unimplemented ENTR /%X0 instruction\n", opcode & 0x0F); + printf("Unimplemented ENTR /%X0 instruction\n", channel); break; case 0x80: - printf("Unimplemented SAI /%X0 instruction\n", opcode & 0x0F); + printf("Unimplemented SAI /%X0 instruction\n", channel); break; } INCREMENT_PC_4K; diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 4538ebcea0d..d1e8fe9b9d9 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -11,6 +11,11 @@ enum PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX }; +enum { + DEVICE_BUSY=0, + DEVICE_READY=1 +}; + class patinho_feio_cpu_device : public cpu_device { public: @@ -34,6 +39,10 @@ protected: bool m_wait_for_interrupt; bool m_interrupts_enabled; + int m_io_status[16]; + bool m_device_is_ok[16]; + bool m_IRQ_request[16]; + int m_address_mask; /* address mask */ int m_icount; From b6e4298ee6cbcd95747e44096666e41b83565ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 21:52:33 -0200 Subject: [PATCH 09/28] [patinho] Implemented instructions LIMPO, UM, CMP1 and CMP2 and initial support for carry and overflow flags --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 33 ++++++++++++++++++++ src/devices/cpu/patinhofeio/patinho_feio.h | 4 +++ 2 files changed, 37 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 01c671b212d..f0c8ee8e1ba 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -10,6 +10,10 @@ #define PC m_pc //The program counter is called "contador de instrucoes" in portuguese #define ACC m_acc +#define FLAGS m_flags + +#define V 0x01 // V = "Vai um" (Carry) +#define T 0x02 // T = "Transbordo" (Overflow) #define READ_BYTE_PATINHO(A) ((signed)m_program->read_byte(A)) #define WRITE_BYTE_PATINHO(A,V) (m_program->write_byte(A,V)) @@ -47,6 +51,7 @@ void patinho_feio_cpu_device::device_start() state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); state_add( PATINHO_FEIO_IDX, "IDX", m_idx ).mask(0xFF); state_add(STATE_GENPC, "GENPC", m_pc).formatstr("0%06O").noshow(); + state_add(STATE_GENFLAGS, "GENFLAGS", m_flags).noshow().formatstr("%8s"); m_icountptr = &m_icount; } @@ -56,6 +61,7 @@ void patinho_feio_cpu_device::device_reset() m_pc = 0xE00; m_acc = 0; m_idx = READ_INDEX_REG(); + m_flags = 0; m_run = true; for (int c=0; c<16; c++) { @@ -98,6 +104,33 @@ void patinho_feio_cpu_device::execute_instruction() ACC = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; return; + case 0x80: + //LIMPO: + // Clear accumulator and flags + ACC = 0; + FLAGS = 0; + return; + case 0x81: + //UM="One": + // Load 1 into accumulator + // and clear the flags + ACC = 1; + FLAGS = 0; + return; + case 0x82: + //CMP1: + // Compute One's complement of the accumulator + // and clear the flags + ACC = ~ACC; + FLAGS = 0; + return; + case 0x83: + //CMP2: + // Compute Two's complement of the accumulator + // and updates flags according to the result of the operation + ACC = ~ACC + 1; + FLAGS = 0; //TODO: fix-me (I'm not sure yet how to compute the flags here) + return; case 0x9A: //INIB="Inibe" // disables interrupts diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index d1e8fe9b9d9..e7c05f583d7 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -39,6 +39,10 @@ protected: bool m_wait_for_interrupt; bool m_interrupts_enabled; + bool m_flags; + // V = "Vai um" (Carry flag) + // T = "Transbordo" (Overflow flag) + int m_io_status[16]; bool m_device_is_ok[16]; bool m_IRQ_request[16]; From b1960f236073ec1c3269bb8a8382dfea90743bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 29 Nov 2015 21:59:13 -0200 Subject: [PATCH 10/28] [patinho] Implement instructions LIM, INC, UNEG and LIMP1 --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index f0c8ee8e1ba..4f2baa16382 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -131,6 +131,29 @@ void patinho_feio_cpu_device::execute_instruction() ACC = ~ACC + 1; FLAGS = 0; //TODO: fix-me (I'm not sure yet how to compute the flags here) return; + case 0x84: + //LIM="Limpa": + // Clear flags + FLAGS = 0; + return; + case 0x85: + //INC: + // Increment accumulator + ACC++; + FLAGS = 0; //TODO: fix-me (I'm not sure yet how to compute the flags here) + return; + case 0x86: + //UNEG="Um Negativo": + // Load -1 into accumulator and clear flags + ACC = -1; + FLAGS = 0; + return; + case 0x87: + //LIMP1: + // Clear accumulator and sets V=1 + ACC = 0; + FLAGS = V; + return; case 0x9A: //INIB="Inibe" // disables interrupts From 5c4e4a375d2c792c9b489866f7df94e47ca1405b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 12:33:27 -0200 Subject: [PATCH 11/28] [patinho] implementation of the shift/rotate instructions (DE, GE, DEV, GEV, DD, GD, DDV, GDV and DDS) --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 96 ++++++++++++++++++- src/devices/cpu/patinhofeio/patinho_feio.h | 6 +- .../cpu/patinhofeio/patinho_feio_dasm.cpp | 20 ++-- 3 files changed, 108 insertions(+), 14 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 4f2baa16382..04ab1a86cf8 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -93,6 +93,7 @@ void patinho_feio_cpu_device::execute_instruction() debugger_instruction_hook(this, PC); offs_t addr; bool skip; + unsigned int tmp; unsigned char value, channel, function; unsigned char opcode = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; @@ -150,7 +151,7 @@ void patinho_feio_cpu_device::execute_instruction() return; case 0x87: //LIMP1: - // Clear accumulator and sets V=1 + // Clear accumulator, reset T and set V ACC = 0; FLAGS = V; return; @@ -189,6 +190,7 @@ void patinho_feio_cpu_device::execute_instruction() //Executes I/O functions //TODO: Implement-me! value = READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; channel = opcode & 0x0F; function = value & 0x0F; switch(value & 0xF0){ @@ -227,7 +229,99 @@ void patinho_feio_cpu_device::execute_instruction() printf("Unimplemented SAI /%X0 instruction\n", channel); break; } + return; + case 0xD1: + //Bit-Shift/Bit-Rotate instructions + value = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; + for (int i=0; i<4; i++){ + if (value & (1<>= 1; + break; + case 0x20: + //GD="Giro para a Direita" + // Rotate right + FLAGS &= ~V; + if (ACC & 1) + FLAGS |= V; + + ACC = ((ACC & 1) << 7) | (ACC >> 1); + break; + case 0x10: //DDV="Deslocamento para a Direita com Vai-um" + // Shift right with Carry + case 0x30: //GDV="Giro para a Direita com Vai-um" + // Rotate right with Carry + + //both instructions are equivalent + if (FLAGS & V) + tmp = 0x100 | ACC; + else + tmp = ACC; + + FLAGS &= ~V; + if (ACC & 1) + FLAGS |= V; + + ACC = tmp >> 1; + break; + case 0x40: //DE="Deslocamento para a Esquerda" + // Shift left + FLAGS &= ~V; + if (ACC & (1<<7)) + FLAGS |= V; + + ACC <<= 1; + break; + case 0x60: //GE="Giro para a Esquerda" + // Rotate left + FLAGS &= ~V; + if (ACC & (1<<7)) + FLAGS |= V; + + ACC = (ACC << 1) | ((ACC >> 7) & 1); + break; + case 0x50: //DEV="Deslocamento para a Esquerda com Vai-um" + // Shift left with Carry + case 0x70: //GEV="Giro para a Esquerda com Vai-um" + // Rotate left with Carry + + //both instructions are equivalent + if (FLAGS & V) + tmp = (ACC << 1) | 1; + else + tmp = (ACC << 1); + + FLAGS &= ~V; + if (tmp & (1<<8)) + FLAGS |= V; + + ACC = tmp & 0xFF; + break; + case 0x80: //DDS="Deslocamento para a Direita com duplicacao de Sinal" + // Rotate right with signal duplication + FLAGS &= ~V; + if (ACC & 1) + FLAGS |= V; + + ACC = (ACC & (1 << 7)) | ACC >> 1; + break; + default: + printf("Illegal instruction: %02X %02X\n", opcode, value); + return; + } + } + } return; } diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index e7c05f583d7..5ee0474c693 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -29,10 +29,10 @@ protected: address_space_config m_program_config; /* processor registers */ - int m_acc; /* accumulator (8 bits) */ - int m_pc; /* program counter (12 bits) + unsigned char m_acc; /* accumulator (8 bits) */ + unsigned int m_pc; /* program counter (12 bits) (CI stands for "Contador de Instrucao") */ - int m_idx; + unsigned char m_idx; /* processor state flip-flops */ bool m_run; /* processor is running */ diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index 0f97a3a3935..e589fc36742 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -111,21 +111,21 @@ CPU_DISASSEMBLE( patinho_feio ) } break; case 0xD0: - value = oprom[1]; + value = oprom[1] & 0x0F; switch (oprom[0] & 0x0F) { case 0x01: switch (oprom[1] & 0xF0) { - case 0x00: sprintf (buffer, "DD /%02X", value); return 2; //DD = "Deslocamento para a direita": Shift right - case 0x10: sprintf (buffer, "DDV /%02X", value); return 2; //DDV = "Deslocamento para a direita c/ V": Shift right with carry - case 0x20: sprintf (buffer, "GD /%02X", value); return 2; //GD = "Giro para a direita": Rotate right - case 0x30: sprintf (buffer, "GDV /%02X", value); return 2; //GDV = "Giro para a direita c/ V": Rotate right with carry - case 0x40: sprintf (buffer, "DE /%02X", value); return 2; //DE = "Deslocamento para a esquerda": Shift right - case 0x50: sprintf (buffer, "DEV /%02X", value); return 2; //DEV = "Deslocamento para a esquerda c/ V": Shift right with carry - case 0x60: sprintf (buffer, "GE /%02X", value); return 2; //GE = "Giro para a esquerda": Rotate right - case 0x70: sprintf (buffer, "GEV /%02X", value); return 2; //GEV = "Giro para a esquerda c/ V": Rotate right with carry - case 0x80: sprintf (buffer, "DDS /%02X", value); return 2; //DDS = "Deslocamento para a direita com duplicacao de sinal": Shift right with sign duplication + case 0x00: sprintf (buffer, "DD /%01X", value); return 2; //DD = "Deslocamento para a direita": Shift right + case 0x10: sprintf (buffer, "DDV /%01X", value); return 2; //DDV = "Deslocamento para a direita c/ V": Shift right with carry + case 0x20: sprintf (buffer, "GD /%01X", value); return 2; //GD = "Giro para a direita": Rotate right + case 0x30: sprintf (buffer, "GDV /%01X", value); return 2; //GDV = "Giro para a direita c/ V": Rotate right with carry + case 0x40: sprintf (buffer, "DE /%01X", value); return 2; //DE = "Deslocamento para a esquerda": Shift right + case 0x50: sprintf (buffer, "DEV /%01X", value); return 2; //DEV = "Deslocamento para a esquerda c/ V": Shift right with carry + case 0x60: sprintf (buffer, "GE /%01X", value); return 2; //GE = "Giro para a esquerda": Rotate right + case 0x70: sprintf (buffer, "GEV /%01X", value); return 2; //GEV = "Giro para a esquerda c/ V": Rotate right with carry + case 0x80: sprintf (buffer, "DDS /%01X", value); return 2; //DDS = "Deslocamento para a direita com duplicacao de sinal": Shift right with sign duplication } break; case 0x02: sprintf (buffer, "XOR /%02X", value); return 2; //Logical XOR From a35a7a34a662cf74f10740aeaed46650c5b782fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 12:46:48 -0200 Subject: [PATCH 12/28] [patinho] Implement ARM and ARMX instructions --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 04ab1a86cf8..218b75ecb63 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -332,6 +332,19 @@ void patinho_feio_cpu_device::execute_instruction() INCREMENT_PC_4K; PC = addr; return; + case 0x20: + //ARM = "Armazena": Store the value of the accumulator into a given memory position + addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + WRITE_BYTE_PATINHO(addr, ACC); + return; + case 0x30: + //ARMX = "Armazena indexado": Store the value of the accumulator into a given indexed memory position + addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + m_idx = READ_INDEX_REG(); + WRITE_BYTE_PATINHO(m_idx + addr, ACC); + return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 From 864f32d7742efc2ffc80f511bfa744549708dfa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 14:59:20 -0200 Subject: [PATCH 13/28] [patinho] Add support for indirect memory addressing and implement the IND instruction. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 40 +++++++++++++++++--- src/devices/cpu/patinhofeio/patinho_feio.h | 5 ++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 218b75ecb63..20d115fff3c 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -15,15 +15,28 @@ #define V 0x01 // V = "Vai um" (Carry) #define T 0x02 // T = "Transbordo" (Overflow) -#define READ_BYTE_PATINHO(A) ((signed)m_program->read_byte(A)) +#define READ_BYTE_PATINHO(A) (m_program->read_byte(A)) #define WRITE_BYTE_PATINHO(A,V) (m_program->write_byte(A,V)) +#define READ_WORD_PATINHO(A) (READ_BYTE_PATINHO(A+1)*256 + READ_BYTE_PATINHO(A)) + #define READ_INDEX_REG() READ_BYTE_PATINHO(0x000) #define WRITE_INDEX_REG(V) { WRITE_BYTE_PATINHO(0x000, V); m_idx = V; } #define ADDRESS_MASK_4K 0xFFF #define INCREMENT_PC_4K (PC = (PC+1) & ADDRESS_MASK_4K) +unsigned int patinho_feio_cpu_device::compute_effective_address(unsigned int addr){ + unsigned int retval = addr; + if (m_indirect_addressing){ + retval = READ_WORD_PATINHO(addr); + if (retval & 0x1000) + return compute_effective_address(retval & 0xFFF); + } + + return retval; +} + const device_type PATINHO_FEIO = &device_creator; @@ -70,6 +83,8 @@ void patinho_feio_cpu_device::device_reset() m_IRQ_request[c] = false; } + m_scheduled_IND_bit_reset = false; + m_indirect_addressing = false; } /* execute instructions on this CPU until icount expires */ @@ -98,6 +113,12 @@ void patinho_feio_cpu_device::execute_instruction() unsigned char opcode = READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; + if (m_scheduled_IND_bit_reset) + m_indirect_addressing = false; + + if (m_indirect_addressing) + m_scheduled_IND_bit_reset = true; + switch (opcode){ case 0xDA: //CARI="Carrega Imediato": @@ -186,6 +207,12 @@ void patinho_feio_cpu_device::execute_instruction() ACC = READ_INDEX_REG(); WRITE_INDEX_REG(value); return; + case 0x9F: + //IND="Enderecamento indireto": + // Sets memory addressing for the next instruction to be indirect. + m_indirect_addressing = true; + m_scheduled_IND_bit_reset = false; //the next instruction execution will schedule it. + return; case 0xCB: //Executes I/O functions //TODO: Implement-me! @@ -328,28 +355,29 @@ void patinho_feio_cpu_device::execute_instruction() switch (opcode & 0xF0){ case 0x00: //PLA = "Pula": Jump to address - addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); INCREMENT_PC_4K; PC = addr; return; case 0x20: //ARM = "Armazena": Store the value of the accumulator into a given memory position - addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); INCREMENT_PC_4K; WRITE_BYTE_PATINHO(addr, ACC); return; case 0x30: //ARMX = "Armazena indexado": Store the value of the accumulator into a given indexed memory position - addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; m_idx = READ_INDEX_REG(); - WRITE_BYTE_PATINHO(m_idx + addr, ACC); + addr = compute_effective_address(m_idx + value); + WRITE_BYTE_PATINHO(addr, ACC); return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 // And then jumps to addr+2 - addr = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); INCREMENT_PC_4K; WRITE_BYTE_PATINHO(addr, (PC >> 8) & 0x0F); WRITE_BYTE_PATINHO(addr+1, PC & 0xFF); diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 5ee0474c693..92a10f9b18e 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -38,6 +38,8 @@ protected: bool m_run; /* processor is running */ bool m_wait_for_interrupt; bool m_interrupts_enabled; + bool m_scheduled_IND_bit_reset; + bool m_indirect_addressing; bool m_flags; // V = "Vai um" (Carry flag) @@ -68,7 +70,8 @@ protected: virtual UINT32 disasm_max_opcode_bytes() const { return 2; } private: - void execute_instruction(); + void execute_instruction(); + unsigned int compute_effective_address(unsigned int addr); }; From f387764de1d90907918ef0e7389621b5ae93c47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 15:03:56 -0200 Subject: [PATCH 14/28] [patinho] indentation / comments cleanup --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 30 +++++++++---------- src/devices/cpu/patinhofeio/patinho_feio.h | 19 +++++++----- .../cpu/patinhofeio/patinho_feio_dasm.cpp | 10 +++---- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 20d115fff3c..860f01d2187 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -46,7 +46,7 @@ static ADDRESS_MAP_START(prog_8bit, AS_PROGRAM, 8, patinho_feio_cpu_device) ADDRESS_MAP_END patinho_feio_cpu_device::patinho_feio_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__), + : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__), m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(prog_8bit)), m_icount(0) { @@ -56,11 +56,11 @@ void patinho_feio_cpu_device::device_start() { m_program = &space(AS_PROGRAM); - save_item(NAME(m_pc)); - save_item(NAME(m_acc)); + save_item(NAME(m_pc)); + save_item(NAME(m_acc)); - // Register state for debugger - state_add( PATINHO_FEIO_CI, "CI", m_pc ).mask(0xFFF); + // Register state for debugger + state_add( PATINHO_FEIO_CI, "CI", m_pc ).mask(0xFFF); state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); state_add( PATINHO_FEIO_IDX, "IDX", m_idx ).mask(0xFF); state_add(STATE_GENPC, "GENPC", m_pc).formatstr("0%06O").noshow(); @@ -90,16 +90,16 @@ void patinho_feio_cpu_device::device_reset() /* execute instructions on this CPU until icount expires */ void patinho_feio_cpu_device::execute_run() { - do - { - if ((! m_run)){ - m_icount = 0; /* if processor is stopped, just burn cycles */ + do + { + if ((! m_run)){ + m_icount = 0; /* if processor is stopped, just burn cycles */ } else { execute_instruction(); - m_icount --; - } - } - while (m_icount > 0); + m_icount --; + } + } + while (m_icount > 0); } /* execute one instruction */ @@ -389,7 +389,7 @@ void patinho_feio_cpu_device::execute_instruction() offs_t patinho_feio_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) { - extern CPU_DISASSEMBLE( patinho_feio ); - return CPU_DISASSEMBLE_NAME(patinho_feio)(this, buffer, pc, oprom, opram, options); + extern CPU_DISASSEMBLE( patinho_feio ); + return CPU_DISASSEMBLE_NAME(patinho_feio)(this, buffer, pc, oprom, opram, options); } diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 92a10f9b18e..4f1fa60fc80 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -8,7 +8,7 @@ /* register IDs */ enum { - PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX + PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX }; enum { @@ -19,23 +19,26 @@ enum { class patinho_feio_cpu_device : public cpu_device { public: - // construction/destruction - patinho_feio_cpu_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); + // construction/destruction + patinho_feio_cpu_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); protected: - virtual void execute_run(); - virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options); + virtual void execute_run(); + virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options); address_space_config m_program_config; /* processor registers */ unsigned char m_acc; /* accumulator (8 bits) */ unsigned int m_pc; /* program counter (12 bits) - (CI stands for "Contador de Instrucao") */ + * Actual register name is CI, which + * stands for "Contador de Instrucao" + * or "instructions counter". + */ unsigned char m_idx; /* processor state flip-flops */ - bool m_run; /* processor is running */ + bool m_run; /* processor is running */ bool m_wait_for_interrupt; bool m_interrupts_enabled; bool m_scheduled_IND_bit_reset; @@ -49,7 +52,7 @@ protected: bool m_device_is_ok[16]; bool m_IRQ_request[16]; - int m_address_mask; /* address mask */ + int m_address_mask; /* address mask */ int m_icount; address_space *m_program; diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index e589fc36742..cb5aa8e0c2a 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -5,10 +5,10 @@ CPU_DISASSEMBLE( patinho_feio ) { - int addr, value, n, f; + int addr, value, n, f; - switch (oprom[0] & 0xF0) - { + switch (oprom[0] & 0xF0) + { case 0x00: //PLA = "Pula": Unconditionally JUMP to effective address addr = (oprom[0] & 0x0F) << 8 | oprom[1]; @@ -144,7 +144,7 @@ CPU_DISASSEMBLE( patinho_feio ) addr = (oprom[0] & 0x0F) << 8 | oprom[1]; sprintf (buffer, "PUG /%03X", addr); return 2; - } + } sprintf (buffer, "illegal instruction"); - return 1; + return 1; } From 3e7b0c6fa96d0b7e7b175674ec6018c3955457aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 15:08:24 -0200 Subject: [PATCH 15/28] [patinho] Implement PLAX instruction (jump to indexed address) --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 860f01d2187..ba7f5fd4222 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -359,6 +359,13 @@ void patinho_feio_cpu_device::execute_instruction() INCREMENT_PC_4K; PC = addr; return; + case 0x10: + //PLAX = "Pula indexado": Jump to indexed address + value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + m_idx = READ_INDEX_REG(); + PC = compute_effective_address(m_idx + value); + return; case 0x20: //ARM = "Armazena": Store the value of the accumulator into a given memory position addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); From 6d06383a6a9ac85977ee68661ea2eb8bc8b35710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 15:17:50 -0200 Subject: [PATCH 16/28] [patinho] Implement CAR and CARX instructions --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index ba7f5fd4222..386a05bd0d5 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -380,6 +380,20 @@ void patinho_feio_cpu_device::execute_instruction() addr = compute_effective_address(m_idx + value); WRITE_BYTE_PATINHO(addr, ACC); return; + case 0x40: + //CAR = "Carrega": Load a value from a given memory position into the accumulator + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + ACC = READ_BYTE_PATINHO(addr); + return; + case 0x50: + //CARX = "Carga indexada": Load a value from a given indexed memory position into the accumulator + value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + m_idx = READ_INDEX_REG(); + addr = compute_effective_address(m_idx + value); + ACC = READ_BYTE_PATINHO(addr); + return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 From 357127bcb1502a41a9c794d2a0732467a6e36811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 15:21:37 -0200 Subject: [PATCH 17/28] [patinho] Implement SOM and SOMX instructions (TODO: update T and V flags) --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 386a05bd0d5..b2d928253ab 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -394,6 +394,22 @@ void patinho_feio_cpu_device::execute_instruction() addr = compute_effective_address(m_idx + value); ACC = READ_BYTE_PATINHO(addr); return; + case 0x60: + //SOM = "Soma": Add a value from a given memory position into the accumulator + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + ACC += READ_BYTE_PATINHO(addr); + //TODO: update V and T flags + return; + case 0x70: + //SOMX = "Soma indexada": Add a value from a given indexed memory position into the accumulator + value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + m_idx = READ_INDEX_REG(); + addr = compute_effective_address(m_idx + value); + ACC += READ_BYTE_PATINHO(addr); + //TODO: update V and T flags + return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 From 9729ebc804add1e34ab3cd6b2838f99b578e28b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 16:02:46 -0200 Subject: [PATCH 18/28] [patinho] Implement PLAN and PLAZ instructions and fix a bug in all of the instructions dealing with indexed memory access --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 30 ++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index b2d928253ab..d5ec7701648 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -361,10 +361,10 @@ void patinho_feio_cpu_device::execute_instruction() return; case 0x10: //PLAX = "Pula indexado": Jump to indexed address - value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + tmp = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; m_idx = READ_INDEX_REG(); - PC = compute_effective_address(m_idx + value); + PC = compute_effective_address(m_idx + tmp); return; case 0x20: //ARM = "Armazena": Store the value of the accumulator into a given memory position @@ -374,10 +374,10 @@ void patinho_feio_cpu_device::execute_instruction() return; case 0x30: //ARMX = "Armazena indexado": Store the value of the accumulator into a given indexed memory position - value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + tmp = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; m_idx = READ_INDEX_REG(); - addr = compute_effective_address(m_idx + value); + addr = compute_effective_address(m_idx + tmp); WRITE_BYTE_PATINHO(addr, ACC); return; case 0x40: @@ -388,10 +388,10 @@ void patinho_feio_cpu_device::execute_instruction() return; case 0x50: //CARX = "Carga indexada": Load a value from a given indexed memory position into the accumulator - value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + tmp = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; m_idx = READ_INDEX_REG(); - addr = compute_effective_address(m_idx + value); + addr = compute_effective_address(m_idx + tmp); ACC = READ_BYTE_PATINHO(addr); return; case 0x60: @@ -403,13 +403,27 @@ void patinho_feio_cpu_device::execute_instruction() return; case 0x70: //SOMX = "Soma indexada": Add a value from a given indexed memory position into the accumulator - value = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); + tmp = (opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC); INCREMENT_PC_4K; m_idx = READ_INDEX_REG(); - addr = compute_effective_address(m_idx + value); + addr = compute_effective_address(m_idx + tmp); ACC += READ_BYTE_PATINHO(addr); //TODO: update V and T flags return; + case 0xA0: + //PLAN = "Pula se ACC negativo": Jump to a given address if ACC is negative + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + if ((signed char) ACC < 0) + PC = addr; + return; + case 0xB0: + //PLAZ = "Pula se ACC for zero": Jump to a given address if ACC is zero + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + if (ACC == 0) + PC = addr; + return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 From cc0ff74b627605620c8caa7f39cd43459d70add3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 16:46:44 -0200 Subject: [PATCH 19/28] [patinho] Implement SUS instruction --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index d5ec7701648..eac67e79c9b 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -424,6 +424,19 @@ void patinho_feio_cpu_device::execute_instruction() if (ACC == 0) PC = addr; return; + case 0xE0: + //SUS = "Subtrai um ou Salta": Subtract one from the data in the given address + // or, if the data is zero, then simply skip a couple bytes. + addr = compute_effective_address((opcode & 0x0F) << 8 | READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + value = READ_BYTE_PATINHO(addr); + if (value > 0){ + WRITE_BYTE_PATINHO(addr, value-1); + } else { + INCREMENT_PC_4K; + INCREMENT_PC_4K; + } + return; case 0xF0: //PUG = "Pula e guarda": Jump and store. // It stores the return address to addr and addr+1 From 9b032d452ceec558abab938935309b98c65a7060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 16:49:22 -0200 Subject: [PATCH 20/28] [patinho] Update IDX on the debugger UI for every new instruction executed by the CPU. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index eac67e79c9b..595a62db6b6 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -95,6 +95,7 @@ void patinho_feio_cpu_device::execute_run() if ((! m_run)){ m_icount = 0; /* if processor is stopped, just burn cycles */ } else { + m_idx = READ_INDEX_REG(); execute_instruction(); m_icount --; } From 1e9ed2e3c527e579259fec87384bc89a9a16872e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Mon, 30 Nov 2015 16:59:01 -0200 Subject: [PATCH 21/28] [patinho] Implement XOR, NAND and SOMI instructions and fix their disasm textual representation --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 19 +++++++++++++++++++ .../cpu/patinhofeio/patinho_feio_dasm.cpp | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 595a62db6b6..f8a1e3c54c5 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -121,6 +121,25 @@ void patinho_feio_cpu_device::execute_instruction() m_scheduled_IND_bit_reset = true; switch (opcode){ + case 0xD2: + //XOR: Computes the bitwise XOR of an immediate into the accumulator + ACC ^= READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + //TODO: update T and V flags + return; + case 0xD4: + //NAND: Computes the bitwise XOR of an immediate into the accumulator + ACC = ~(ACC & READ_BYTE_PATINHO(PC)); + INCREMENT_PC_4K; + //TODO: update T and V flags + return; + case 0xD8: + //SOMI="Soma Imediato": + // Add an immediate into the accumulator + ACC += READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + //TODO: update T and V flags + return; case 0xDA: //CARI="Carrega Imediato": // Load an immediate into the accumulator diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index cb5aa8e0c2a..15414347179 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -128,10 +128,10 @@ CPU_DISASSEMBLE( patinho_feio ) case 0x80: sprintf (buffer, "DDS /%01X", value); return 2; //DDS = "Deslocamento para a direita com duplicacao de sinal": Shift right with sign duplication } break; - case 0x02: sprintf (buffer, "XOR /%02X", value); return 2; //Logical XOR - case 0x04: sprintf (buffer, "NAND /%02X", value); return 2; //Logical NAND - case 0x08: sprintf (buffer, "SOMI /%02X", value); return 2; //SOMI = "Soma imediata": Add immediate value into accumulator - case 0x0A: sprintf (buffer, "CARI /%02X", value); return 2; //CARI = "Carrega imediato": Loads an immediate value into the accumulator + case 0x02: sprintf (buffer, "XOR /%02X", oprom[1]); return 2; //Logical XOR + case 0x04: sprintf (buffer, "NAND /%02X", oprom[1]); return 2; //Logical NAND + case 0x08: sprintf (buffer, "SOMI /%02X", oprom[1]); return 2; //SOMI = "Soma imediata": Add immediate value into accumulator + case 0x0A: sprintf (buffer, "CARI /%02X", oprom[1]); return 2; //CARI = "Carrega imediato": Loads an immediate value into the accumulator } break; case 0xE0: From a2ac9e36c30ce73910bca34c43c5c4522393e696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Tue, 1 Dec 2015 10:29:10 -0200 Subject: [PATCH 22/28] refactored the handling of peripherals by creating a class to represent each peripheral with its state flags. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 13 +++---------- src/devices/cpu/patinhofeio/patinho_feio.h | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index f8a1e3c54c5..f8829a36ed9 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -76,13 +76,6 @@ void patinho_feio_cpu_device::device_reset() m_idx = READ_INDEX_REG(); m_flags = 0; m_run = true; - - for (int c=0; c<16; c++) { - m_device_is_ok[c] = true; - m_io_status[c] = DEVICE_READY; - m_IRQ_request[c] = false; - } - m_scheduled_IND_bit_reset = false; m_indirect_addressing = false; } @@ -251,15 +244,15 @@ void patinho_feio_cpu_device::execute_instruction() switch(function) { case 1: - if (m_io_status[channel] == DEVICE_READY) + if (m_peripherals[channel].io_status == DEVICE_READY) skip = true; break; case 2: - if (m_device_is_ok[channel]) + if (m_peripherals[channel].device_is_ok) skip = true; break; case 4: - if (m_IRQ_request[channel] == true) + if (m_peripherals[channel].IRQ_request == true) skip = true; break; } diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 4f1fa60fc80..6a869f5b9f6 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -16,6 +16,20 @@ enum { DEVICE_READY=1 }; +class patinho_feio_peripheral +{ +public: + patinho_feio_peripheral() + : io_status(DEVICE_READY) + , device_is_ok(true) + , IRQ_request(false) + { }; + + int io_status; + bool device_is_ok; + bool IRQ_request; +}; + class patinho_feio_cpu_device : public cpu_device { public: @@ -48,9 +62,7 @@ protected: // V = "Vai um" (Carry flag) // T = "Transbordo" (Overflow flag) - int m_io_status[16]; - bool m_device_is_ok[16]; - bool m_IRQ_request[16]; + patinho_feio_peripheral m_peripherals[16]; int m_address_mask; /* address mask */ int m_icount; From 32db54e38f75fc6e1f5cea1a482ce86a465dc4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Tue, 1 Dec 2015 12:33:34 -0200 Subject: [PATCH 23/28] [patinho] Preloaded another example program and fixed the opcode parsing of the SAI instruction that it uses. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 90 ++++++++++---------- src/mame/drivers/patinho_feio.cpp | 22 ++++- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index f8829a36ed9..341fe43552d 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -71,7 +71,7 @@ void patinho_feio_cpu_device::device_start() void patinho_feio_cpu_device::device_reset() { - m_pc = 0xE00; + m_pc = 0x006; m_acc = 0; m_idx = READ_INDEX_REG(); m_flags = 0; @@ -226,50 +226,6 @@ void patinho_feio_cpu_device::execute_instruction() m_indirect_addressing = true; m_scheduled_IND_bit_reset = false; //the next instruction execution will schedule it. return; - case 0xCB: - //Executes I/O functions - //TODO: Implement-me! - value = READ_BYTE_PATINHO(PC); - INCREMENT_PC_4K; - channel = opcode & 0x0F; - function = value & 0x0F; - switch(value & 0xF0){ - case 0x10: - printf("Unimplemented FNC /%X%X instruction\n", channel, function); - break; - case 0x20: - //SAL="Salta" - // Skips a couple bytes if a condition is met - skip = false; - switch(function) - { - case 1: - if (m_peripherals[channel].io_status == DEVICE_READY) - skip = true; - break; - case 2: - if (m_peripherals[channel].device_is_ok) - skip = true; - break; - case 4: - if (m_peripherals[channel].IRQ_request == true) - skip = true; - break; - } - - if (skip){ - INCREMENT_PC_4K; - INCREMENT_PC_4K; - } - break; - case 0x40: - printf("Unimplemented ENTR /%X0 instruction\n", channel); - break; - case 0x80: - printf("Unimplemented SAI /%X0 instruction\n", channel); - break; - } - return; case 0xD1: //Bit-Shift/Bit-Rotate instructions value = READ_BYTE_PATINHO(PC); @@ -437,6 +393,50 @@ void patinho_feio_cpu_device::execute_instruction() if (ACC == 0) PC = addr; return; + case 0xC0: + //Executes I/O functions + //TODO: Implement-me! + value = READ_BYTE_PATINHO(PC); + INCREMENT_PC_4K; + channel = opcode & 0x0F; + function = value & 0x0F; + switch(value & 0xF0){ + case 0x10: + printf("Unimplemented FNC /%X%X instruction\n", channel, function); + break; + case 0x20: + //SAL="Salta" + // Skips a couple bytes if a condition is met + skip = false; + switch(function) + { + case 1: + if (m_peripherals[channel].io_status == DEVICE_READY) + skip = true; + break; + case 2: + if (m_peripherals[channel].device_is_ok) + skip = true; + break; + case 4: + if (m_peripherals[channel].IRQ_request == true) + skip = true; + break; + } + + if (skip){ + INCREMENT_PC_4K; + INCREMENT_PC_4K; + } + break; + case 0x40: + printf("Unimplemented ENTR /%X0 instruction\n", channel); + break; + case 0x80: + printf("Unimplemented SAI /%X0 instruction\n", channel); + break; + } + return; case 0xE0: //SUS = "Subtrai um ou Salta": Subtract one from the data in the given address // or, if the data is zero, then simply skip a couple bytes. diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp index 9e597b9bccb..8a2b4d0ec6d 100644 --- a/src/mame/drivers/patinho_feio.cpp +++ b/src/mame/drivers/patinho_feio.cpp @@ -29,11 +29,22 @@ DRIVER_INIT_MEMBER(patinho_feio_state, patinho_feio) } void patinho_feio_state::machine_start(){ - //copy the "absolute program example" from appendix G directly into RAM + // Copy some programs directly into RAM. // This is a hack for setting up the computer - // while we don't support loading programs from punched tape rolls... + // while we don't support loading programs + // from punched tape rolls... UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); - UINT8 *program = memregion("example_program")->base(); + UINT8 *program; + + //"absolute program example" from page 16.7 + // Prints "PATINHO FEIO" on the DECWRITER: + program = memregion("exemplo_16.7")->base(); + memcpy(&RAM[0x003], program, 0x028); + + //"absolute program example" from appendix G: + // Allows users to load programs from the + // console into the computer memory. + program = memregion("hexam")->base(); memcpy(&RAM[0xE00], program, 0x0D5); } @@ -56,8 +67,11 @@ static MACHINE_CONFIG_START( patinho_feio, patinho_feio_state ) MACHINE_CONFIG_END ROM_START( patinho ) - ROM_REGION( 0x0d5, "example_program", 0 ) + ROM_REGION( 0x0d5, "hexam", 0 ) ROM_LOAD( "apendice_g__hexam.bin", 0x000, 0x0d5, CRC(c6addc59) SHA1(126bc97247eac45c58708eaac216c2438e9e4af9) ) + + ROM_REGION( 0x0d5, "exemplo_16.7", 0 ) + ROM_LOAD( "exemplo_16.7.bin", 0x000, 0x028, CRC(0a87ac8d) SHA1(7c35ac3eed9ed239f2ef56c26e6f0c59f635e1ac) ) ROM_END /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ From d7d12bb39e799589310d6d4201afa3a70ca61dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Tue, 1 Dec 2015 13:13:32 -0200 Subject: [PATCH 24/28] [patinho] Implemented methods for loading punched tape images as well as raw data into RAM. --- src/mame/drivers/patinho_feio.cpp | 37 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp index 8a2b4d0ec6d..10b574676ac 100644 --- a/src/mame/drivers/patinho_feio.cpp +++ b/src/mame/drivers/patinho_feio.cpp @@ -16,6 +16,8 @@ public: { } DECLARE_DRIVER_INIT(patinho_feio); + void load_tape(const char* name); + void load_raw_data(const char* name, unsigned int start_address, unsigned int data_length); virtual void machine_start(); // virtual void machine_reset(); // required_device m_maincpu; @@ -28,24 +30,47 @@ DRIVER_INIT_MEMBER(patinho_feio_state, patinho_feio) { } +void patinho_feio_state::load_tape(const char* name){ + UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); + UINT8 *data = memregion(name)->base(); + unsigned int data_length = data[0]; + unsigned int start_address = data[1]*256 + data[2]; + INT8 expected_checksum = data[data_length + 3]; + INT8 checksum = 0; + + for (int i = 0; i < data_length + 3; i++){ + checksum -= (INT8) data[i]; + } + + if (checksum != expected_checksum){ + printf("[WARNING] Tape \"%s\": checksum = 0x%02X (expected 0x%02X)\n", + name, (unsigned char) checksum, (unsigned char) expected_checksum); + } + + memcpy(&RAM[start_address], &data[3], data_length); +} + +void patinho_feio_state::load_raw_data(const char* name, unsigned int start_address, unsigned int data_length){ + UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); + UINT8 *data = memregion(name)->base(); + + memcpy(&RAM[start_address], data, data_length); +} + void patinho_feio_state::machine_start(){ // Copy some programs directly into RAM. // This is a hack for setting up the computer // while we don't support loading programs // from punched tape rolls... - UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); - UINT8 *program; //"absolute program example" from page 16.7 // Prints "PATINHO FEIO" on the DECWRITER: - program = memregion("exemplo_16.7")->base(); - memcpy(&RAM[0x003], program, 0x028); + load_tape("exemplo_16.7"); //"absolute program example" from appendix G: // Allows users to load programs from the // console into the computer memory. - program = memregion("hexam")->base(); - memcpy(&RAM[0xE00], program, 0x0D5); + load_raw_data("hexam", 0xE00, 0x0D5); } static INPUT_PORTS_START( patinho_feio ) From a1312b7ca52a21048567fed8e18986f35f9d394d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Tue, 1 Dec 2015 13:22:52 -0200 Subject: [PATCH 25/28] [patinho] fixed metadata string (added accented character and tilde) --- src/mame/drivers/patinho_feio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp index 10b574676ac..07bd111c9e8 100644 --- a/src/mame/drivers/patinho_feio.cpp +++ b/src/mame/drivers/patinho_feio.cpp @@ -100,4 +100,4 @@ ROM_START( patinho ) ROM_END /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ -COMP( 1972, patinho, 0, 0, patinho_feio, patinho_feio, patinho_feio_state, patinho_feio, "Escola Politecnica - Universidade de Sao Paulo", "Patinho Feio" , MACHINE_NO_SOUND_HW | MACHINE_NOT_WORKING) +COMP( 1972, patinho, 0, 0, patinho_feio, patinho_feio, patinho_feio_state, patinho_feio, "Escola Politécnica - Universidade de São Paulo", "Patinho Feio" , MACHINE_NO_SOUND_HW | MACHINE_NOT_WORKING) From 6c5bf9b91ad583363feadc98d984d6cc9981d1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Wed, 2 Dec 2015 00:01:31 -0200 Subject: [PATCH 26/28] [patinho] Implement instructions related to reading the 12bit switches from the front panel. --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 66 +++++++++++++++++- src/devices/cpu/patinhofeio/patinho_feio.h | 14 +++- .../cpu/patinhofeio/patinho_feio_dasm.cpp | 67 ++++++++++--------- src/mame/drivers/patinho_feio.cpp | 31 ++++++--- 4 files changed, 137 insertions(+), 41 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 341fe43552d..6fb22420078 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -10,6 +10,7 @@ #define PC m_pc //The program counter is called "contador de instrucoes" in portuguese #define ACC m_acc +#define RC read_panel_keys_register() #define FLAGS m_flags #define V 0x01 // V = "Vai um" (Carry) @@ -48,24 +49,44 @@ ADDRESS_MAP_END patinho_feio_cpu_device::patinho_feio_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : cpu_device(mconfig, PATINHO_FEIO, "PATINHO FEIO", tag, owner, clock, "patinho_feio_cpu", __FILE__), m_program_config("program", ENDIANNESS_LITTLE, 8, 12, 0, ADDRESS_MAP_NAME(prog_8bit)), - m_icount(0) + m_icount(0), + m_rc_read_cb(*this) { } +UINT16 patinho_feio_cpu_device::read_panel_keys_register(){ + if (!m_rc_read_cb.isnull()) + m_rc = m_rc_read_cb(0); + else + m_rc = 0; + + return m_rc; +} + void patinho_feio_cpu_device::device_start() { m_program = &space(AS_PROGRAM); save_item(NAME(m_pc)); save_item(NAME(m_acc)); + save_item(NAME(m_rc)); + save_item(NAME(m_idx)); + save_item(NAME(m_flags)); // Register state for debugger state_add( PATINHO_FEIO_CI, "CI", m_pc ).mask(0xFFF); + state_add( PATINHO_FEIO_RC, "RC", m_rc ).mask(0xFFF); state_add( PATINHO_FEIO_ACC, "ACC", m_acc ).mask(0xFF); state_add( PATINHO_FEIO_IDX, "IDX", m_idx ).mask(0xFF); state_add(STATE_GENPC, "GENPC", m_pc).formatstr("0%06O").noshow(); state_add(STATE_GENFLAGS, "GENFLAGS", m_flags).noshow().formatstr("%8s"); + if (m_rc_read_cb.isnull()){ + fatalerror("Panel keys register not found!"); + } else { + m_rc_read_cb.resolve(); + } + m_icountptr = &m_icount; } @@ -73,6 +94,7 @@ void patinho_feio_cpu_device::device_reset() { m_pc = 0x006; m_acc = 0; + m_rc = 0; m_idx = READ_INDEX_REG(); m_flags = 0; m_run = true; @@ -89,6 +111,8 @@ void patinho_feio_cpu_device::execute_run() m_icount = 0; /* if processor is stopped, just burn cycles */ } else { m_idx = READ_INDEX_REG(); + read_panel_keys_register(); + execute_instruction(); m_icount --; } @@ -189,6 +213,46 @@ void patinho_feio_cpu_device::execute_instruction() ACC = 0; FLAGS = V; return; + case 0x88: + //PNL 0: + ACC = (RC & 0xFF); + FLAGS = 0; + return; + case 0x89: + //PNL 1: + ACC = (RC & 0xFF) + 1; + //TODO: FLAGS = ?; + return; + case 0x8A: + //PNL 2: + ACC = (RC & 0xFF) - ACC - 1; + //TODO: FLAGS = ?; + return; + case 0x8B: + //PNL 3: + ACC = (RC & 0xFF) - ACC; + //TODO: FLAGS = ?; + return; + case 0x8C: + //PNL 4: + ACC = (RC & 0xFF) + ACC; + //TODO: FLAGS = ?; + return; + case 0x8D: + //PNL 5: + ACC = (RC & 0xFF) + ACC + 1; + //TODO: FLAGS = ?; + return; + case 0x8E: + //PNL 6: + ACC = (RC & 0xFF) - 1; + //TODO: FLAGS = ?; + return; + case 0x8F: + //PNL 7: + ACC = (RC & 0xFF); + FLAGS = V; + return; case 0x9A: //INIB="Inibe" // disables interrupts diff --git a/src/devices/cpu/patinhofeio/patinho_feio.h b/src/devices/cpu/patinhofeio/patinho_feio.h index 6a869f5b9f6..b03ce36eccb 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.h +++ b/src/devices/cpu/patinhofeio/patinho_feio.h @@ -5,10 +5,13 @@ #ifndef __PATINHOFEIO_H__ #define __PATINHOFEIO_H__ +#define MCFG_PATINHO_RC_READ_CB(_devcb) \ + devcb = &patinho_feio_cpu_device::set_rc_read_callback(*device, DEVCB_##_devcb); + /* register IDs */ enum { - PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX + PATINHO_FEIO_CI=1, PATINHO_FEIO_ACC, PATINHO_FEIO_IDX, PATINHO_FEIO_RC }; enum { @@ -36,7 +39,10 @@ public: // construction/destruction patinho_feio_cpu_device(const machine_config &mconfig, const char *_tag, device_t *_owner, UINT32 _clock); + template static devcb_base &set_rc_read_callback(device_t &device, _Object object) { return downcast(device).m_rc_read_cb.set_callback(object); } + protected: + virtual void execute_run(); virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options); @@ -49,6 +55,10 @@ protected: * stands for "Contador de Instrucao" * or "instructions counter". */ + unsigned int m_rc; /* RC = "Registrador de Chaves" (Keys Register) + * It represents the 12 bits of input data + * from toggle switches in the computer panel + */ unsigned char m_idx; /* processor state flip-flops */ @@ -87,6 +97,8 @@ protected: private: void execute_instruction(); unsigned int compute_effective_address(unsigned int addr); + UINT16 read_panel_keys_register(); + devcb_read16 m_rc_read_cb; }; diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index 15414347179..f6fca99eb58 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -55,36 +55,6 @@ CPU_DISASSEMBLE( patinho_feio ) addr = (oprom[0] & 0x0F) << 8 | oprom[1]; sprintf (buffer, "SOMX (IDX) + /%03X", addr); return 2; - case 0x80: - case 0x90: - switch (oprom[0]) - { - case 0x80: sprintf (buffer, "LIMPO"); return 1; - case 0x81: sprintf (buffer, "UM"); return 1; - case 0x82: sprintf (buffer, "CMP1"); return 1; - case 0x83: sprintf (buffer, "CMP2"); return 1; - case 0x84: sprintf (buffer, "LIN"); return 1; - case 0x85: sprintf (buffer, "INC"); return 1; - case 0x86: sprintf (buffer, "UNEG"); return 1; - case 0x87: sprintf (buffer, "LIMP1"); return 1; - case 0x90: sprintf (buffer, "ST 0"); return 1; - case 0x91: sprintf (buffer, "STM 0"); return 1; - case 0x92: sprintf (buffer, "ST 1"); return 1; - case 0x93: sprintf (buffer, "STM 1"); return 1; - case 0x94: sprintf (buffer, "SV 0"); return 1; - case 0x95: sprintf (buffer, "SVM 0"); return 1; - case 0x96: sprintf (buffer, "SV 1"); return 1; - case 0x97: sprintf (buffer, "SVM 1"); return 1; - case 0x98: sprintf (buffer, "PUL"); return 1; - case 0x99: sprintf (buffer, "TRE"); return 1; - case 0x9A: sprintf (buffer, "INIB"); return 1; - case 0x9B: sprintf (buffer, "PERM"); return 1; - case 0x9C: sprintf (buffer, "ESP"); return 1; - case 0x9D: sprintf (buffer, "PARE"); return 1; - case 0x9E: sprintf (buffer, "TRI"); return 1; - case 0x9F: sprintf (buffer, "IND"); return 1; - } - break; case 0xA0: //PLAN = "Pula se ACC for negativo": Jumps to the 12bit address // if the accumulator is negative @@ -145,6 +115,43 @@ CPU_DISASSEMBLE( patinho_feio ) sprintf (buffer, "PUG /%03X", addr); return 2; } + + switch (oprom[0]) + { + case 0x80: sprintf (buffer, "LIMPO"); return 1; + case 0x81: sprintf (buffer, "UM"); return 1; + case 0x82: sprintf (buffer, "CMP1"); return 1; + case 0x83: sprintf (buffer, "CMP2"); return 1; + case 0x84: sprintf (buffer, "LIN"); return 1; + case 0x85: sprintf (buffer, "INC"); return 1; + case 0x86: sprintf (buffer, "UNEG"); return 1; + case 0x87: sprintf (buffer, "LIMP1"); return 1; + case 0x88: sprintf (buffer, "PNL 0"); return 1; + case 0x89: sprintf (buffer, "PNL 1"); return 1; + case 0x8A: sprintf (buffer, "PNL 2"); return 1; + case 0x8B: sprintf (buffer, "PNL 3"); return 1; + case 0x8C: sprintf (buffer, "PNL 4"); return 1; + case 0x8D: sprintf (buffer, "PNL 5"); return 1; + case 0x8E: sprintf (buffer, "PNL 6"); return 1; + case 0x8F: sprintf (buffer, "PNL 7"); return 1; + case 0x90: sprintf (buffer, "ST 0"); return 1; + case 0x91: sprintf (buffer, "STM 0"); return 1; + case 0x92: sprintf (buffer, "ST 1"); return 1; + case 0x93: sprintf (buffer, "STM 1"); return 1; + case 0x94: sprintf (buffer, "SV 0"); return 1; + case 0x95: sprintf (buffer, "SVM 0"); return 1; + case 0x96: sprintf (buffer, "SV 1"); return 1; + case 0x97: sprintf (buffer, "SVM 1"); return 1; + case 0x98: sprintf (buffer, "PUL"); return 1; + case 0x99: sprintf (buffer, "TRE"); return 1; + case 0x9A: sprintf (buffer, "INIB"); return 1; + case 0x9B: sprintf (buffer, "PERM"); return 1; + case 0x9C: sprintf (buffer, "ESP"); return 1; + case 0x9D: sprintf (buffer, "PARE"); return 1; + case 0x9E: sprintf (buffer, "TRI"); return 1; + case 0x9F: sprintf (buffer, "IND"); return 1; + } + sprintf (buffer, "illegal instruction"); return 1; } diff --git a/src/mame/drivers/patinho_feio.cpp b/src/mame/drivers/patinho_feio.cpp index 07bd111c9e8..73643d49797 100644 --- a/src/mame/drivers/patinho_feio.cpp +++ b/src/mame/drivers/patinho_feio.cpp @@ -16,6 +16,7 @@ public: { } DECLARE_DRIVER_INIT(patinho_feio); + DECLARE_READ16_MEMBER(rc_r); void load_tape(const char* name); void load_raw_data(const char* name, unsigned int start_address, unsigned int data_length); virtual void machine_start(); @@ -30,6 +31,11 @@ DRIVER_INIT_MEMBER(patinho_feio_state, patinho_feio) { } +READ16_MEMBER(patinho_feio_state::rc_r) +{ + return ioport("RC_HIGH")->read() << 8 | ioport("RC_LOW")->read(); +} + void patinho_feio_state::load_tape(const char* name){ UINT8 *RAM = (UINT8 *) memshare("maincpu:internalram")->ptr(); UINT8 *data = memregion(name)->base(); @@ -74,21 +80,28 @@ void patinho_feio_state::machine_start(){ } static INPUT_PORTS_START( patinho_feio ) - // PORT_START("PANEL") /* various operator control panel switches */ - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) - // PORT_BIT(?, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("control panel key") PORT_CODE(KEYCODE_?) + PORT_START("RC_LOW") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 0") PORT_CODE(KEYCODE_EQUALS) PORT_TOGGLE + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 1") PORT_CODE(KEYCODE_MINUS) PORT_TOGGLE + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 2") PORT_CODE(KEYCODE_0) PORT_TOGGLE + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 3") PORT_CODE(KEYCODE_9) PORT_TOGGLE + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 4") PORT_CODE(KEYCODE_8) PORT_TOGGLE + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 5") PORT_CODE(KEYCODE_7) PORT_TOGGLE + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 6") PORT_CODE(KEYCODE_6) PORT_TOGGLE + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 7") PORT_CODE(KEYCODE_5) PORT_TOGGLE + + PORT_START("RC_HIGH") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 8") PORT_CODE(KEYCODE_4) PORT_TOGGLE + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 7") PORT_CODE(KEYCODE_3) PORT_TOGGLE + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 10") PORT_CODE(KEYCODE_2) PORT_TOGGLE + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("RC bit 11") PORT_CODE(KEYCODE_1) PORT_TOGGLE INPUT_PORTS_END static MACHINE_CONFIG_START( patinho_feio, patinho_feio_state ) /* basic machine hardware */ /* CPU @ approx. 500 kHz (memory cycle time is 2usec) */ MCFG_CPU_ADD("maincpu", PATINHO_FEIO, 500000) + MCFG_PATINHO_RC_READ_CB(READ16(patinho_feio_state, rc_r)) MACHINE_CONFIG_END ROM_START( patinho ) From c0a2483edb192d3b3eca92919effac3b2a8232f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 6 Dec 2015 01:31:59 -0200 Subject: [PATCH 27/28] [patinho] improve log message for the unimplmemented SAI instruction (display the ACC value) --- src/devices/cpu/patinhofeio/patinho_feio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio.cpp b/src/devices/cpu/patinhofeio/patinho_feio.cpp index 6fb22420078..9377ad259f8 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio.cpp @@ -497,7 +497,7 @@ void patinho_feio_cpu_device::execute_instruction() printf("Unimplemented ENTR /%X0 instruction\n", channel); break; case 0x80: - printf("Unimplemented SAI /%X0 instruction\n", channel); + printf("Unimplemented SAI /%X0 instruction (ACC = 0x%02X '%c')\n", channel, ACC, ACC); break; } return; From ae26812a4917ddc43f3952f07181fa7cebe92ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Sun, 6 Dec 2015 01:32:55 -0200 Subject: [PATCH 28/28] [patinho] print IDX instead of /000 in the CAR and ARM instructions disasm --- src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp index f6fca99eb58..ac78ef4be73 100644 --- a/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp +++ b/src/devices/cpu/patinhofeio/patinho_feio_dasm.cpp @@ -23,7 +23,11 @@ CPU_DISASSEMBLE( patinho_feio ) //ARM = "Armazena": Stores the contents of the // accumulator in the given 12bit address addr = (oprom[0] & 0x0F) << 8 | oprom[1]; - sprintf (buffer, "ARM /%03X", addr); + if (addr==0){ + sprintf (buffer, "ARM (IDX)"); + }else{ + sprintf (buffer, "ARM /%03X", addr); + } return 2; case 0x30: //ARMX = "Armazenamento indexado": Stores the contents of the accumulator in the @@ -35,7 +39,11 @@ CPU_DISASSEMBLE( patinho_feio ) //CAR = "Carrega": Loads the contents of the given 12bit address // into the accumulator addr = (oprom[0] & 0x0F) << 8 | oprom[1]; - sprintf (buffer, "CAR /%03X", addr); + if (addr==0){ + sprintf (buffer, "CAR (IDX)"); + }else{ + sprintf (buffer, "CAR /%03X", addr); + } return 2; case 0x50: //CARX = "Carga indexada": Loads the contents of the given 12bit address