1 // license:BSD-3-Clause
2 // copyright-holders:F. Ulivi
3 // *******************************
4 // Driver for HP 9845B/C/T systems
5 // *******************************
6 #ifndef MAME_INCLUDES_HP9845_H
7 #define MAME_INCLUDES_HP9845_H
8 
9 #pragma once
10 
11 #include "cpu/hphybrid/hphybrid.h"
12 #include "machine/hp_taco.h"
13 #include "sound/beep.h"
14 #include "bus/hp9845_io/hp9845_io.h"
15 #include "emupal.h"
16 #include "screen.h"
17 #include "machine/ram.h"
18 #include "machine/timer.h"
19 #include "machine/hp98x5_io_sys.h"
20 
21 class hp9845_base_state : public driver_device
22 {
23 public:
24 	hp9845_base_state(const machine_config &mconfig, device_type type, const char *tag);
25 
26 	DECLARE_INPUT_CHANGED_MEMBER(togglekey_changed);
27 
28 protected:
29 	virtual void machine_start() override;
30 	virtual void device_reset() override;
31 	virtual void machine_reset() override;
32 
33 	TIMER_DEVICE_CALLBACK_MEMBER(gv_timer);
34 
35 	virtual uint16_t graphic_r(offs_t offset) = 0;
36 	virtual void graphic_w(offs_t offset, uint16_t data) = 0;
37 	attotime time_to_gv_mem_availability() const;
38 
39 	TIMER_DEVICE_CALLBACK_MEMBER(kb_scan);
40 	uint16_t kb_scancode_r();
41 	uint16_t kb_status_r();
42 	void kb_irq_clear_w(uint16_t data);
43 	TIMER_DEVICE_CALLBACK_MEMBER(beeper_off);
44 
45 	DECLARE_WRITE_LINE_MEMBER(prt_irl_w);
46 
47 	void hp9845_base(machine_config &config);
48 	void global_mem_map(address_map &map);
49 	void ppu_io_map(address_map &map);
50 
51 	required_device<hp_5061_3001_cpu_device> m_lpu;
52 	required_device<hp_5061_3001_cpu_device> m_ppu;
53 	required_device<hp98x5_io_sys_device> m_io_sys;
54 	required_device<screen_device> m_screen;
55 	required_device<palette_device> m_palette;
56 	required_device<timer_device> m_gv_timer;
57 	required_ioport_array<4> m_io_key;
58 	required_ioport m_io_shiftlock;
59 	required_device<hp_taco_device> m_t14;
60 	required_device<hp_taco_device> m_t15;
61 	required_device<beep_device> m_beeper;
62 	required_device<timer_device> m_beep_timer;
63 	required_device_array<hp9845_io_slot_device, 4> m_io_slot;
64 	required_device<ram_device> m_ram;
65 	output_finder<8> m_softkeys;
66 	output_finder<> m_shift_lock_led;
67 	output_finder<> m_prt_all_led;
68 	output_finder<> m_auto_st_led;
69 
70 	void setup_ram_block(unsigned block , unsigned offset);
71 
72 	virtual void advance_gv_fsm(bool ds , bool trigger) = 0;
73 	void kb_scan_ioport(ioport_value pressed , ioport_port &port , unsigned idx_base , int& max_seq_len , unsigned& max_seq_idx);
74 	void update_kb_prt_irq();
75 
76 	// Slot handling
77 	void set_irq_slot(unsigned slot , int state);
78 	void set_sts_slot(unsigned slot , int state);
79 	void set_flg_slot(unsigned slot , int state);
80 	void set_irq_nextsc_slot(unsigned slot , int state);
81 	void set_sts_nextsc_slot(unsigned slot , int state);
82 	void set_flg_nextsc_slot(unsigned slot , int state);
83 	void set_dmar_slot(unsigned slot , int state);
84 
85 	// Character generator
86 	required_region_ptr<uint8_t> m_chargen;
87 
88 	// Text mode video I/F
89 	typedef struct {
90 		uint8_t chars[ 80 ];
91 		uint8_t attrs[ 80 ];
92 		bool full;
93 	} video_buffer_t;
94 
95 	bitmap_rgb32 m_bitmap;
96 	offs_t m_video_mar;
97 	uint16_t m_video_word;
98 	bool m_video_load_mar;
99 	bool m_video_first_mar;
100 	bool m_video_byte_idx;
101 	bool m_video_buff_idx;
102 	bool m_video_blanked;
103 	video_buffer_t m_video_buff[ 2 ];
104 
105 	// Graphic video
106 	typedef enum {
107 		GV_STAT_RESET,
108 		GV_STAT_WAIT_DS_0 = GV_STAT_RESET,
109 		GV_STAT_WAIT_TRIG_0,
110 		GV_STAT_WAIT_MEM_0,
111 		GV_STAT_WAIT_DS_1,
112 		GV_STAT_WAIT_DS_2,
113 		GV_STAT_WAIT_TRIG_1,
114 		GV_STAT_WAIT_MEM_1,
115 		GV_STAT_WAIT_MEM_2
116 	} gv_fsm_state_t;
117 
118 	bool m_graphic_sel;
119 	gv_fsm_state_t m_gv_fsm_state;
120 	bool m_gv_int_en;
121 	bool m_gv_dma_en;
122 	uint8_t m_gv_cmd; // U65 (GC)
123 	uint16_t m_gv_data_w;     // U29, U45, U28 & U44 (GC)
124 	uint16_t m_gv_data_r;     // U59 & U60 (GC)
125 	uint16_t m_gv_io_counter; // U1, U2, U14 & U15 (GC)
126 	uint16_t m_gv_cursor_x;   // U31 & U23 (GS)
127 	uint16_t m_gv_cursor_y;   // U15 & U8 (GS)
128 	bool m_gv_cursor_gc;    // U8 (GS)
129 	bool m_gv_cursor_fs;    // U8 (GS)
130 
131 	// State of keyboard
132 	ioport_value m_kb_state[ 4 ];
133 	uint8_t m_kb_scancode;
134 	uint16_t m_kb_status;
135 
136 	// Printer
137 	bool m_prt_irl;
138 
139 	// SC of slots
140 	int m_slot_sc[ 4 ];
141 };
142 
143 #endif // MAME_INCLUDES_HP9845_H
144