1 // license:BSD-3-Clause
2 // copyright-holders:Raphael Nabet
3 /* register names for apexc_get_reg & apexc_set_reg */
4 #ifndef MAME_CPU_APEXC_APEXC_H
5 #define MAME_CPU_APEXC_APEXC_H
6 
7 #pragma once
8 
9 enum
10 {
11 	APEXC_CR =1,    /* control register */
12 	APEXC_A,        /* accumulator */
13 	APEXC_R,        /* register */
14 	APEXC_ML,       /* memory location */
15 	APEXC_WS,       /* working store */
16 	APEXC_STATE,    /* whether CPU is running */
17 };
18 
19 class apexc_cpu_device : public cpu_device
20 {
21 public:
22 	// construction/destruction
23 	apexc_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
24 
25 	// configuration
tape_read()26 	auto tape_read() { return m_tape_read_cb.bind(); }
tape_punch()27 	auto tape_punch() { return m_tape_punch_cb.bind(); }
28 
29 protected:
30 	// device-level overrides
31 	virtual void device_start() override;
32 	virtual void device_reset() override;
33 
34 	// device_execute_interface overrides
execute_min_cycles()35 	virtual uint32_t execute_min_cycles() const noexcept override { return 2; }
execute_max_cycles()36 	virtual uint32_t execute_max_cycles() const noexcept override { return 75; }
execute_input_lines()37 	virtual uint32_t execute_input_lines() const noexcept override { return 0; }
38 	virtual void execute_run() override;
39 
40 	// device_memory_interface overrides
41 	virtual space_config_vector memory_space_config() const override;
42 
43 	// device_state_interface overrides
44 	virtual void state_import(const device_state_entry &entry) override;
45 
46 	// device_disasm_interface overrides
47 	virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;
48 
apexc_readmem(uint32_t address)49 	inline uint32_t apexc_readmem(uint32_t address) { return m_program->read_dword((address)<<2); }
apexc_writemem(uint32_t address,uint32_t data)50 	inline void apexc_writemem(uint32_t address, uint32_t data) { m_program->write_dword((address)<<2, (data)); }
apexc_writemem_masked(uint32_t address,uint32_t data,uint32_t mask)51 	inline void apexc_writemem_masked(uint32_t address, uint32_t data, uint32_t mask) { apexc_writemem((address), (apexc_readmem(address) & ~(mask)) | ((data) & (mask))); }
52 
53 	uint32_t effective_address(uint32_t address);
54 	uint32_t word_read(uint32_t address, uint32_t special);
55 	void word_write(uint32_t address, uint32_t data, uint32_t mask);
56 	uint8_t papertape_read();
57 	void papertape_punch(uint8_t data);
58 
59 	uint32_t load_ml(uint32_t address, uint32_t vector);
60 	void execute();
61 
62 	address_space_config m_program_config;
63 
64 	devcb_read8 m_tape_read_cb;
65 	devcb_write8 m_tape_punch_cb;
66 
67 	uint32_t m_a;   /* accumulator */
68 	uint32_t m_r;   /* register */
69 	uint32_t m_cr;  /* control register (i.e. instruction register) */
70 	int m_ml;     /* memory location (current track in working store, and requested word position within track) (10 bits) */
71 	int m_working_store;  /* current working store (group of 16 tracks) (1-15) */
72 	int m_current_word;   /* current word position within track (0-31) */
73 
74 	int m_running;    /* 1 flag: */
75 						/* running: flag implied by the existence of the stop instruction */
76 	uint32_t m_pc;  /* address of next instruction for the disassembler */
77 
78 	address_space *m_program;
79 	int m_icount;
80 
81 	// For state
82 	uint32_t m_ml_full;
83 	uint32_t m_genpc;
84 };
85 
86 
87 DECLARE_DEVICE_TYPE(APEXC, apexc_cpu_device)
88 
89 #endif // MAME_CPU_APEXC_APEXC_H
90