summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/hp48.h
blob: a7fa42ff064b2c58fdd369019a9fa88066e86d41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// license:BSD-3-Clause
// copyright-holders:Antoine Mine
/**********************************************************************

  Copyright (C) Antoine Mine' 2008

   Hewlett Packard HP48 S/SX & G/GX and HP49 G

**********************************************************************/
#ifndef MAME_INCLUDES_HP84_H
#define MAME_INCLUDES_HP84_H

#pragma once

#include "machine/hp48_port.h"

#include "sound/dac.h"
#include "screen.h"

/* model */
typedef enum {
	HP48_S,
	HP48_SX,
	HP48_G,
	HP48_GX,
	HP48_GP,
	HP49_G
} hp48_models;

/* memory module configuration */
typedef struct
{
	/* static part */
	uint32_t off_mask;             /* offset bit-mask, indicates the real size */
	read8_delegate read;
	const char *read_name;
	write8_delegate write;
	void* data;                  /* non-NULL for banks */
	int isnop;

	/* configurable part */
	uint8_t  state;                /* one of HP48_MODULE_ */
	uint32_t base;                 /* base address */
	uint32_t mask;                 /* often improperly called size, it is an address select mask */

} hp48_module;


/* screen image averaging */
#define HP48_NB_SCREENS 3

class hp48_state : public driver_device
{
public:
	hp48_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_maincpu(*this, "maincpu")
		, m_dac(*this, "dac")
		, m_palette(*this, "palette")
		, m_screen(*this, "screen")
		, m_port(*this, "port%u", 1U) {}

	virtual void machine_reset() override;
	void base_machine_start(hp48_models model);

	void init_hp48();
	DECLARE_PALETTE_INIT(hp48);
	void machine_start_hp49g()  ATTR_COLD;
	void machine_start_hp48gx() ATTR_COLD;
	void machine_start_hp48g()  ATTR_COLD;
	void machine_start_hp48gp() ATTR_COLD;
	void machine_start_hp48sx() ATTR_COLD;
	void machine_start_hp48s()  ATTR_COLD;
	uint32_t screen_update_hp48(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	DECLARE_WRITE8_MEMBER(io_w);
	DECLARE_READ8_MEMBER(io_r);
	DECLARE_READ8_MEMBER(bank_r);
	DECLARE_WRITE8_MEMBER(hp49_bank_w);
	TIMER_CALLBACK_MEMBER(rs232_byte_recv_cb);
	TIMER_CALLBACK_MEMBER(rs232_byte_sent_cb);
	TIMER_CALLBACK_MEMBER(kbd_cb);
	TIMER_CALLBACK_MEMBER(timer1_cb);
	TIMER_CALLBACK_MEMBER(timer2_cb);
	void update_annunciators();
	void apply_modules();
	void pulse_irq(int irq_line);
	void rs232_start_recv_byte(uint8_t data);
	void rs232_send_byte();
	int get_in();
	void update_kdn();
	void reset_modules();
	void decode_nibble(uint8_t* dst, uint8_t* src, int size);
	void encode_nibble(uint8_t* dst, uint8_t* src, int size);

	/* memory controller */
	DECLARE_WRITE_LINE_MEMBER(mem_reset);
	DECLARE_WRITE32_MEMBER(mem_config);
	DECLARE_WRITE32_MEMBER(mem_unconfig);
	DECLARE_READ32_MEMBER(mem_id);

	/* CRC computation */
	DECLARE_WRITE32_MEMBER(mem_crc);

	/* IN/OUT registers */
	DECLARE_READ32_MEMBER(reg_in);
	DECLARE_WRITE32_MEMBER(reg_out);

	/* keyboard interrupt system */
	DECLARE_WRITE_LINE_MEMBER(rsi);
	void hp48_common(machine_config &config);
	void hp48s(machine_config &config);
	void hp48gp(machine_config &config);
	void hp48sx(machine_config &config);
	void hp48g(machine_config &config);
	void hp48gx(machine_config &config);
	void hp49g(machine_config &config);
	void hp48(address_map &map);

	required_device<cpu_device> m_maincpu;
	required_device<dac_bit_interface> m_dac;
	required_device<palette_device> m_palette;
	required_device<screen_device> m_screen;

	uint8_t *m_videoram;
	uint8_t m_io[64];
	hp48_models m_model;

	/* OUT register from SATURN (actually 12-bit) */
	uint16_t m_out;

	/* keyboard interrupt */
	uint8_t m_kdn;

	/* from highest to lowest priority: HDW, NCE2, CE1, CE2, NCE3, NCE1 */
	hp48_module m_modules[6];

	/* RAM/ROM extensions, GX/SX only
	   port1: SX/GX: 32/128 KB
	   port2: SX:32/128KB, GX:128/512/4096 KB
	*/
	optional_device_array<hp48_port_image_device, 2> m_port;

	uint32_t m_bank_switch;
	uint32_t m_io_addr;
	uint16_t m_crc;
	uint8_t m_timer1;
	uint32_t m_timer2;
	uint8_t m_screens[HP48_NB_SCREENS][64][144];
	int m_cur_screen;
	uint8_t* m_rom;
	emu_timer *m_1st_timer;
	emu_timer *m_2nd_timer;
	emu_timer *m_kbd_timer;
};


/***************************************************************************
    MACROS
***************************************************************************/

/* read from I/O memory */
#define HP48_IO_4(x)   (m_io[(x)])
#define HP48_IO_8(x)   (m_io[(x)] | (m_io[(x)+1] << 4))
#define HP48_IO_12(x)  (m_io[(x)] | (m_io[(x)+1] << 4) | (m_io[(x)+2] << 8))
#define HP48_IO_20(x)  (m_io[(x)] | (m_io[(x)+1] << 4) | (m_io[(x)+2] << 8) | \
						(m_io[(x)+3] << 12) | (m_io[(x)+4] << 16))


/*----------- defined in machine/hp48.c -----------*/

/***************************************************************************
    GLOBAL VARIABLES & CONSTANTS
***************************************************************************/

/* I/O memory */



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

/* list of memory modules from highest to lowest priority */
#define HP48_HDW  0
#define HP48_NCE2 1
#define HP48_CE1  2
#define HP48_CE2  3
#define HP48_NCE3 4
#define HP48_NCE1 5

#endif // MAME_INCLUDES_HP84_H