1 // license:BSD-3-Clause
2 // copyright-holders:Antoine Mine
3 /**********************************************************************
4 
5   Copyright (C) Antoine Mine' 2008
6 
7    Hewlett Packard HP48 S/SX & G/GX and HP49 G
8 
9 **********************************************************************/
10 #ifndef MAME_INCLUDES_HP84_H
11 #define MAME_INCLUDES_HP84_H
12 
13 #pragma once
14 
15 #include "cpu/saturn/saturn.h"
16 #include "machine/hp48_port.h"
17 #include "sound/dac.h"
18 #include "emupal.h"
19 #include "screen.h"
20 
21 /* model */
22 typedef enum {
23 	HP48_S,
24 	HP48_SX,
25 	HP48_G,
26 	HP48_GX,
27 	HP48_GP,
28 	HP49_G
29 } hp48_models;
30 
31 /* screen image averaging */
32 #define HP48_NB_SCREENS 3
33 
34 class hp48_state : public driver_device
35 {
36 public:
hp48_state(const machine_config & mconfig,device_type type,const char * tag)37 	hp48_state(const machine_config &mconfig, device_type type, const char *tag)
38 		: driver_device(mconfig, type, tag)
39 		, m_modules{ { *this }, { *this }, { *this }, { *this }, { *this }, { *this } }
40 		, m_maincpu(*this, "maincpu")
41 		, m_dac(*this, "dac")
42 		, m_palette(*this, "palette")
43 		, m_screen(*this, "screen")
44 		, m_port(*this, "port%u", 1U)
45 		, m_lshift0(*this, "lshift0")
46 		, m_rshift0(*this, "rshift0")
47 		, m_alpha0(*this, "alpha0")
48 		, m_alert0(*this, "alert0")
49 		, m_busy0(*this, "busy0")
50 		, m_transmit0(*this, "transmit0")
51 	{
52 	}
53 
54 	void hp48s(machine_config &config);
55 	void hp48gp(machine_config &config);
56 	void hp48sx(machine_config &config);
57 	void hp48g(machine_config &config);
58 	void hp48gx(machine_config &config);
59 	void hp49g(machine_config &config);
60 
61 	void init_hp48();
62 
63 	void decode_nibble(uint8_t* dst, uint8_t* src, int size);
64 	void encode_nibble(uint8_t* dst, uint8_t* src, int size);
65 
66 	void apply_modules();
67 
68 	/* memory module configuration */
69 	struct hp48_module
70 	{
hp48_modulehp48_module71 		hp48_module(device_t &owner) : read(owner), write(owner) { }
72 
73 		/* static part */
74 		uint32_t off_mask;          // offset bit-mask, indicates the real size
75 		read8sm_delegate read;
76 		const char *read_name;
77 		write8sm_delegate write;
78 		void* data;                 // non-NULL for banks
79 		int isnop;
80 
81 		/* configurable part */
82 		uint8_t  state;             // one of HP48_MODULE_
83 		uint32_t base;              // base address
84 		uint32_t mask;              // often improperly called size, it is an address select mask
85 
86 	};
87 
88 	/* from highest to lowest priority: HDW, NCE2, CE1, CE2, NCE3, NCE1 */
89 	hp48_module m_modules[6];
90 
91 private:
92 	virtual void machine_reset() override;
93 	void base_machine_start(hp48_models model);
94 
95 	void hp48_palette(palette_device &palette) const;
96 	DECLARE_MACHINE_START(hp49g);
97 	DECLARE_MACHINE_START(hp48gx);
98 	DECLARE_MACHINE_START(hp48g);
99 	DECLARE_MACHINE_START(hp48gp);
100 	DECLARE_MACHINE_START(hp48sx);
101 	DECLARE_MACHINE_START(hp48s);
102 	uint32_t screen_update_hp48(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
103 	void io_w(offs_t offset, uint8_t data);
104 	uint8_t io_r(offs_t offset);
105 	uint8_t bank_r(offs_t offset);
106 	void hp49_bank_w(offs_t offset, uint8_t data);
107 	TIMER_CALLBACK_MEMBER(rs232_byte_recv_cb);
108 	TIMER_CALLBACK_MEMBER(rs232_byte_sent_cb);
109 	TIMER_CALLBACK_MEMBER(kbd_cb);
110 	TIMER_CALLBACK_MEMBER(timer1_cb);
111 	TIMER_CALLBACK_MEMBER(timer2_cb);
112 	void update_annunciators();
113 	void pulse_irq(int irq_line);
114 	void rs232_start_recv_byte(uint8_t data);
115 	void rs232_send_byte();
116 	int get_in();
117 	void update_kdn();
118 	void reset_modules();
119 
120 	/* memory controller */
121 	DECLARE_WRITE_LINE_MEMBER(mem_reset);
122 	void mem_config(uint32_t data);
123 	void mem_unconfig(uint32_t data);
124 	uint32_t mem_id();
125 
126 	/* CRC computation */
127 	void mem_crc(offs_t offset, uint32_t data);
128 
129 	/* IN/OUT registers */
130 	uint32_t reg_in();
131 	void reg_out(uint32_t data);
132 
133 	/* keyboard interrupt system */
134 	DECLARE_WRITE_LINE_MEMBER(rsi);
135 	void hp48_common(machine_config &config);
136 	void hp48(address_map &map);
137 
138 	required_device<saturn_device> m_maincpu;
139 	required_device<dac_bit_interface> m_dac;
140 	required_device<palette_device> m_palette;
141 	required_device<screen_device> m_screen;
142 
143 	uint8_t *m_videoram;
144 	uint8_t m_io[64];
145 	hp48_models m_model;
146 
147 	/* OUT register from SATURN (actually 12-bit) */
148 	uint16_t m_out;
149 
150 	/* keyboard interrupt */
151 	uint8_t m_kdn;
152 
153 	/* RAM/ROM extensions, GX/SX only
154 	   port1: SX/GX: 32/128 KB
155 	   port2: SX:32/128KB, GX:128/512/4096 KB
156 	*/
157 	optional_device_array<hp48_port_image_device, 2> m_port;
158 
159 	output_finder<> m_lshift0;
160 	output_finder<> m_rshift0;
161 	output_finder<> m_alpha0;
162 	output_finder<> m_alert0;
163 	output_finder<> m_busy0;
164 	output_finder<> m_transmit0;
165 
166 	uint32_t m_bank_switch;
167 	uint32_t m_io_addr;
168 	uint16_t m_crc;
169 	uint8_t m_timer1;
170 	uint32_t m_timer2;
171 	uint8_t m_screens[HP48_NB_SCREENS][64][144];
172 	int m_cur_screen;
173 	uint8_t* m_rom;
174 	emu_timer *m_1st_timer;
175 	emu_timer *m_2nd_timer;
176 	emu_timer *m_kbd_timer;
177 };
178 
179 
180 /***************************************************************************
181     MACROS
182 ***************************************************************************/
183 
184 /* read from I/O memory */
185 #define HP48_IO_4(x)   (m_io[(x)])
186 #define HP48_IO_8(x)   (m_io[(x)] | (m_io[(x)+1] << 4))
187 #define HP48_IO_12(x)  (m_io[(x)] | (m_io[(x)+1] << 4) | (m_io[(x)+2] << 8))
188 #define HP48_IO_20(x)  (m_io[(x)] | (m_io[(x)+1] << 4) | (m_io[(x)+2] << 8) | \
189 						(m_io[(x)+3] << 12) | (m_io[(x)+4] << 16))
190 
191 
192 /*----------- defined in machine/hp48.c -----------*/
193 
194 /***************************************************************************
195     GLOBAL VARIABLES & CONSTANTS
196 ***************************************************************************/
197 
198 /* I/O memory */
199 
200 
201 
202 /***************************************************************************
203     FUNCTION PROTOTYPES
204 ***************************************************************************/
205 
206 /* list of memory modules from highest to lowest priority */
207 #define HP48_HDW  0
208 #define HP48_NCE2 1
209 #define HP48_CE1  2
210 #define HP48_CE2  3
211 #define HP48_NCE3 4
212 #define HP48_NCE1 5
213 
214 #endif // MAME_INCLUDES_HP84_H
215