1 // license:BSD-3-Clause
2 // copyright-holders:Phill Harvey-Smith
3 /*
4     mbc55x.h
5     Includes for the Sanyo MBC-550, MBC-555.
6 
7     Phill Harvey-Smith
8     2011-01-29.
9 */
10 #ifndef MAME_INCLUDES_MBC55X_H
11 #define MAME_INCLUDES_MBC55X_H
12 
13 #pragma once
14 
15 #include "bus/a2gameio/gameio.h"
16 #include "bus/centronics/ctronics.h"
17 #include "cpu/i86/i86.h"
18 #include "imagedev/floppy.h"
19 #include "machine/bankdev.h"
20 #include "machine/i8251.h"
21 #include "machine/i8255.h"
22 #include "machine/pic8259.h"
23 #include "machine/pit8253.h"
24 #include "machine/ram.h"
25 #include "machine/wd_fdc.h"
26 #include "sound/spkrdev.h"
27 #include "video/mc6845.h"
28 
29 #include "debug/debugcon.h"
30 #include "debugger.h"
31 #include "emupal.h"
32 
33 #include "formats/pc_dsk.h"
34 
35 
36 #define MAINCPU_TAG "maincpu"
37 
38 #define SCREEN_TAG      "screen"
39 #define SCREEN_WIDTH_PIXELS     640
40 #define SCREEN_HEIGHT_LINES     250
41 #define SCREEN_NO_COLOURS       8
42 
43 #define VIDEO_MEM_SIZE      (32*1024)
44 #define VID_MC6845_NAME     "mc6845"
45 
46 // Red and blue colour planes sit at a fixed location, green
47 // is in main memory.
48 
49 #define COLOUR_PLANE_SIZE   0x4000
50 
51 #define RED_PLANE_OFFSET    (0*COLOUR_PLANE_SIZE)
52 #define BLUE_PLANE_OFFSET   (1*COLOUR_PLANE_SIZE)
53 
54 #define COLOUR_PLANE_MEMBASE    0xF0000
55 #define RED_PLANE_MEMBASE   (COLOUR_PLANE_MEMBASE+RED_PLANE_OFFSET)
56 #define BLUE_PLANE_MEMBASE  (COLOUR_PLANE_MEMBASE+BLUE_PLANE_OFFSET)
57 
58 #define RED_PLANE_TAG       "red"
59 #define BLUE_PLANE_TAG      "blue"
60 
61 #define PPI8255_TAG     "ppi8255"
62 #define PIC8259_TAG     "pic8259"
63 #define PIT8253_TAG     "pit8253"
64 
65 #define MONO_TAG                "mono"
66 #define I8251A_KB_TAG           "i8251a_kb"
67 #define FDC_TAG                 "wd1793"
68 
69 
70 
71 class mbc55x_state : public driver_device
72 {
73 public:
mbc55x_state(const machine_config & mconfig,device_type type,const char * tag)74 	mbc55x_state(const machine_config &mconfig, device_type type, const char *tag) :
75 		driver_device(mconfig, type, tag),
76 		m_maincpu(*this, MAINCPU_TAG),
77 		m_iodecode(*this, "iodecode"),
78 		m_crtc(*this, VID_MC6845_NAME),
79 		m_kb_uart(*this, I8251A_KB_TAG),
80 		m_pit(*this, PIT8253_TAG),
81 		m_ppi(*this, PPI8255_TAG),
82 		m_pic(*this, PIC8259_TAG),
83 		m_fdc(*this, FDC_TAG),
84 		m_floppy(*this, FDC_TAG ":%u", 0U),
85 		m_gameio(*this, "gameio"),
86 		m_printer(*this, "printer"),
87 		m_speaker(*this, "speaker"),
88 		m_ram(*this, RAM_TAG),
89 		m_palette(*this, "palette")
90 	{
91 	}
92 
93 	void mbc55x(machine_config &config);
94 
95 	required_device<i8086_cpu_device> m_maincpu;
96 	required_device<address_map_bank_device> m_iodecode;
97 
98 protected:
99 	virtual void machine_start() override;
100 	virtual void machine_reset() override;
101 	virtual void video_start() override;
102 	virtual void video_reset() override;
103 
104 private:
105 	DECLARE_FLOPPY_FORMATS(floppy_formats);
106 
107 	uint8_t iodecode_r(offs_t offset);
108 	void iodecode_w(offs_t offset, uint8_t data);
109 
110 	uint8_t vram_page_r();
111 	void vram_page_w(uint8_t data);
112 	uint8_t game_io_r();
113 	uint8_t printer_status_r();
114 	void printer_data_w(uint8_t data);
115 	void disk_select_w(uint8_t data);
116 	DECLARE_WRITE_LINE_MEMBER(printer_busy_w);
117 	DECLARE_WRITE_LINE_MEMBER(printer_paper_end_w);
118 	DECLARE_WRITE_LINE_MEMBER(printer_select_w);
119 
120 	DECLARE_WRITE_LINE_MEMBER(vid_hsync_changed);
121 	DECLARE_WRITE_LINE_MEMBER(vid_vsync_changed);
122 
123 	MC6845_UPDATE_ROW(crtc_update_row);
124 	void mbc55x_palette(palette_device &palette) const;
125 
126 	void mbc55x_io(address_map &map);
127 	void mbc55x_mem(address_map &map);
128 	void mbc55x_iodecode(address_map &map);
129 
130 	void set_ram_size();
131 
132 	required_device<mc6845_device> m_crtc;
133 	required_device<i8251_device> m_kb_uart;
134 	required_device<pit8253_device> m_pit;
135 	required_device<i8255_device> m_ppi;
136 	required_device<pic8259_device> m_pic;
137 	required_device<fd1793_device> m_fdc;
138 	required_device_array<floppy_connector, 4> m_floppy;
139 	required_device<apple2_gameio_device> m_gameio;
140 	required_device<centronics_device> m_printer;
141 	required_device<speaker_sound_device> m_speaker;
142 	required_device<ram_device> m_ram;
143 	required_device<palette_device> m_palette;
144 
145 	uint32_t      m_debug_video;
146 	uint8_t       m_video_mem[VIDEO_MEM_SIZE];
147 	uint8_t       m_vram_page;
148 	uint8_t       m_printer_status;
149 
150 	double        m_x_calibration, m_y_calibration;
151 	bool          m_ls123_strobe;
152 	double        m_ls123_clear_time[4];
153 
154 	void video_debug(int ref, const std::vector<std::string> &params);
155 };
156 
157 /*----------- defined in machine/mbc55x.c -----------*/
158 
159 /* Memory controller */
160 #define RAM_BANK00_TAG  "bank0"
161 #define RAM_BANK01_TAG  "bank1"
162 #define RAM_BANK02_TAG  "bank2"
163 #define RAM_BANK03_TAG  "bank3"
164 #define RAM_BANK04_TAG  "bank4"
165 #define RAM_BANK05_TAG  "bank5"
166 #define RAM_BANK06_TAG  "bank6"
167 #define RAM_BANK07_TAG  "bank7"
168 #define RAM_BANK08_TAG  "bank8"
169 #define RAM_BANK09_TAG  "bank9"
170 #define RAM_BANK0A_TAG  "banka"
171 #define RAM_BANK0B_TAG  "bankb"
172 #define RAM_BANK0C_TAG  "bankc"
173 #define RAM_BANK0D_TAG  "bankd"
174 #define RAM_BANK0E_TAG  "banke"
175 
176 #define RAM_BANK_SIZE   (64*1024)
177 #define RAM_BANK_COUNT  15
178 
179 /* Floppy drive interface */
180 
181 #define FDC_PAUSE               10000
182 
183 
184 /*----------- defined in video/mbc55x.c -----------*/
185 
186 #define LINEAR_ADDR(seg,ofs)    ((seg<<4)+ofs)
187 
188 #define OUTPUT_SEGOFS(mess,seg,ofs)  logerror("%s=%04X:%04X [%08X]\n",mess,seg,ofs,((seg<<4)+ofs))
189 
190 #endif // MAME_INCLUDES_MBC55X_H
191