1 // license:BSD-3-Clause 2 // copyright-holders:Angelo Salese,Carl 3 #ifndef MAME_INCLUDES_PC9801_H 4 #define MAME_INCLUDES_PC9801_H 5 6 #pragma once 7 8 #include "cpu/i386/i386.h" 9 #include "cpu/i86/i286.h" 10 #include "cpu/i86/i86.h" 11 #include "cpu/nec/nec.h" 12 13 #include "imagedev/floppy.h" 14 #include "machine/am9517a.h" 15 #include "machine/bankdev.h" 16 #include "machine/buffer.h" 17 #include "machine/i8251.h" 18 #include "machine/i8255.h" 19 #include "machine/output_latch.h" 20 #include "machine/pic8259.h" 21 #include "machine/pit8253.h" 22 #include "machine/ram.h" 23 #include "machine/timer.h" 24 #include "machine/upd1990a.h" 25 #include "machine/pc9801_memsw.h" 26 #include "machine/upd765.h" 27 28 #include "bus/scsi/pc9801_sasi.h" 29 #include "bus/scsi/scsi.h" 30 #include "bus/scsi/scsihd.h" 31 32 #include "sound/2608intf.h" 33 #include "sound/beep.h" 34 #include "sound/spkrdev.h" 35 36 #include "video/upd7220.h" 37 38 #include "bus/cbus/pc9801_26.h" 39 #include "bus/cbus/pc9801_86.h" 40 #include "bus/cbus/pc9801_118.h" 41 #include "bus/cbus/pc9801_amd98.h" 42 #include "bus/cbus/mpu_pc98.h" 43 #include "bus/cbus/pc9801_cbus.h" 44 #include "machine/pc9801_kbd.h" 45 #include "machine/pc9801_cd.h" 46 47 #include "bus/ata/atadev.h" 48 #include "bus/ata/ataintf.h" 49 50 #include "debugger.h" 51 #include "emupal.h" 52 #include "screen.h" 53 #include "softlist.h" 54 #include "speaker.h" 55 56 #include "formats/pc98_dsk.h" 57 #include "formats/pc98fdi_dsk.h" 58 #include "formats/fdd_dsk.h" 59 #include "formats/dcp_dsk.h" 60 #include "formats/dip_dsk.h" 61 #include "formats/nfd_dsk.h" 62 63 64 #define UPD1990A_TAG "upd1990a" 65 #define UPD8251_TAG "upd8251" 66 #define SASIBUS_TAG "sasi" 67 68 #define ATTRSEL_REG 0 69 #define WIDTH40_REG 2 70 #define FONTSEL_REG 3 71 #define INTERLACE_REG 4 72 #define MEMSW_REG 6 73 #define DISPLAY_REG 7 74 75 #define ANALOG_16_MODE 0 76 #define ANALOG_256_MODE (0x20 >> 1) 77 #define GDC_IS_5MHz (0x84 >> 1) 78 79 class pc9801_state : public driver_device 80 { 81 public: pc9801_state(const machine_config & mconfig,device_type type,const char * tag)82 pc9801_state(const machine_config &mconfig, device_type type, const char *tag) : 83 driver_device(mconfig, type, tag), 84 m_maincpu(*this, "maincpu"), 85 m_dmac(*this, "i8237"), 86 m_pit8253(*this, "pit8253"), 87 m_pic1(*this, "pic8259_master"), 88 m_pic2(*this, "pic8259_slave"), 89 m_ppi_sys(*this, "ppi8255_sys"), 90 m_ppi_prn(*this, "ppi8255_prn"), 91 m_fdc_2hd(*this, "upd765_2hd"), 92 m_fdc_2dd(*this, "upd765_2dd"), 93 m_rtc(*this, UPD1990A_TAG), 94 m_memsw(*this, "memsw"), 95 m_keyb(*this, "keyb"), 96 m_sio(*this, UPD8251_TAG), 97 m_hgdc1(*this, "upd7220_chr"), 98 m_hgdc2(*this, "upd7220_btm"), 99 m_sasibus(*this, SASIBUS_TAG), 100 m_sasi_data_out(*this, "sasi_data_out"), 101 m_sasi_data_in(*this, "sasi_data_in"), 102 m_sasi_ctrl_in(*this, "sasi_ctrl_in"), 103 m_ide(*this, "ide%u", 1U), 104 m_video_ram_1(*this, "video_ram_1"), 105 m_video_ram_2(*this, "video_ram_2"), 106 m_ext_gvram(*this, "ext_gvram"), 107 m_beeper(*this, "beeper"), 108 m_ram(*this, RAM_TAG), 109 m_ipl(*this, "ipl_bank"), 110 m_gfxdecode(*this, "gfxdecode"), 111 m_palette(*this, "palette"), 112 m_screen(*this, "screen") 113 { 114 } 115 116 void pc9821v20(machine_config &config); 117 void pc9801ux(machine_config &config); 118 void pc9801vm(machine_config &config); 119 void pc9801(machine_config &config); 120 void pc9801bx2(machine_config &config); 121 void pc9801rs(machine_config &config); 122 void pc9821(machine_config &config); 123 void pc9821as(machine_config &config); 124 void pc9821ap2(machine_config &config); 125 DECLARE_CUSTOM_INPUT_MEMBER(system_type_r); 126 void init_pc9801_kanji(); 127 void init_pc9801vm_kanji(); 128 129 protected: 130 virtual void video_start() override; 131 132 private: 133 static void cdrom_headphones(device_t *device); 134 135 required_device<cpu_device> m_maincpu; 136 required_device<am9517a_device> m_dmac; 137 required_device<pit8253_device> m_pit8253; 138 required_device<pic8259_device> m_pic1; 139 required_device<pic8259_device> m_pic2; 140 required_device<i8255_device> m_ppi_sys; 141 required_device<i8255_device> m_ppi_prn; 142 required_device<upd765a_device> m_fdc_2hd; 143 optional_device<upd765a_device> m_fdc_2dd; 144 required_device<upd1990a_device> m_rtc; 145 required_device<pc9801_memsw_device> m_memsw; 146 required_device<pc9801_kbd_device> m_keyb; 147 required_device<i8251_device> m_sio; 148 required_device<upd7220_device> m_hgdc1; 149 required_device<upd7220_device> m_hgdc2; 150 optional_device<scsi_port_device> m_sasibus; 151 optional_device<output_latch_device> m_sasi_data_out; 152 optional_device<input_buffer_device> m_sasi_data_in; 153 optional_device<input_buffer_device> m_sasi_ctrl_in; 154 optional_device_array<ata_interface_device, 2> m_ide; 155 required_shared_ptr<uint16_t> m_video_ram_1; 156 required_shared_ptr<uint16_t> m_video_ram_2; 157 optional_shared_ptr<uint32_t> m_ext_gvram; 158 required_device<beep_device> m_beeper; 159 optional_device<ram_device> m_ram; 160 optional_device<address_map_bank_device> m_ipl; 161 required_device<gfxdecode_device> m_gfxdecode; 162 required_device<palette_device> m_palette; 163 required_device<screen_device> m_screen; 164 165 void rtc_w(uint8_t data); 166 void dmapg4_w(offs_t offset, uint8_t data); 167 void dmapg8_w(offs_t offset, uint8_t data); 168 void nmi_ctrl_w(offs_t offset, uint8_t data); 169 void vrtc_clear_w(uint8_t data); 170 void pc9801_video_ff_w(uint8_t data); 171 uint8_t txt_scrl_r(offs_t offset); 172 void txt_scrl_w(offs_t offset, uint8_t data); 173 uint8_t grcg_r(offs_t offset); 174 void grcg_w(offs_t offset, uint8_t data); 175 void egc_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 176 uint8_t pc9801_a0_r(offs_t offset); 177 void pc9801_a0_w(offs_t offset, uint8_t data); 178 uint8_t fdc_2hd_ctrl_r(); 179 void fdc_2hd_ctrl_w(uint8_t data); 180 uint8_t fdc_2dd_ctrl_r(); 181 void fdc_2dd_ctrl_w(uint8_t data); 182 uint16_t tvram_r(offs_t offset, uint16_t mem_mask = ~0); 183 void tvram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 184 uint8_t gvram_r(offs_t offset); 185 void gvram_w(offs_t offset, uint8_t data); 186 void pc9801rs_mouse_freq_w(offs_t offset, uint8_t data); 187 uint16_t grcg_gvram_r(offs_t offset, uint16_t mem_mask = ~0); 188 void grcg_gvram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 189 uint16_t grcg_gvram0_r(offs_t offset, uint16_t mem_mask = ~0); 190 void grcg_gvram0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 191 192 uint16_t pc9821_grcg_gvram_r(offs_t offset, uint16_t mem_mask = ~0); 193 void pc9821_grcg_gvram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 194 uint16_t pc9821_grcg_gvram0_r(offs_t offset, uint16_t mem_mask = ~0); 195 void pc9821_grcg_gvram0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 196 197 uint16_t upd7220_grcg_r(offs_t offset, uint16_t mem_mask = ~0); 198 void upd7220_grcg_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 199 200 uint8_t ide_ctrl_r(); 201 void ide_ctrl_w(uint8_t data); 202 uint16_t ide_cs0_r(offs_t offset, uint16_t mem_mask = ~0); 203 void ide_cs0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 204 uint16_t ide_cs1_r(offs_t offset, uint16_t mem_mask = ~0); 205 void ide_cs1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 206 207 void sasi_data_w(uint8_t data); 208 uint8_t sasi_data_r(); 209 DECLARE_WRITE_LINE_MEMBER(write_sasi_io); 210 DECLARE_WRITE_LINE_MEMBER(write_sasi_req); 211 uint8_t sasi_status_r(); 212 void sasi_ctrl_w(uint8_t data); 213 214 uint8_t pc9801rs_knjram_r(offs_t offset); 215 void pc9801rs_knjram_w(offs_t offset, uint8_t data); 216 void pc9801rs_bank_w(offs_t offset, uint8_t data); 217 uint8_t f0_r(offs_t offset); 218 219 uint8_t a20_ctrl_r(offs_t offset); 220 void a20_ctrl_w(offs_t offset, uint8_t data); 221 uint8_t fdc_mode_ctrl_r(); 222 void fdc_mode_ctrl_w(uint8_t data); 223 // uint8_t pc9801rs_2dd_r(); 224 // void pc9801rs_2dd_w(uint8_t data); 225 void pc9801rs_video_ff_w(offs_t offset, uint8_t data); 226 void pc9801rs_a0_w(offs_t offset, uint8_t data); 227 void pc9821_video_ff_w(offs_t offset, uint8_t data); 228 uint8_t pc9821_a0_r(offs_t offset); 229 void pc9821_a0_w(offs_t offset, uint8_t data); 230 uint8_t access_ctrl_r(offs_t offset); 231 void access_ctrl_w(offs_t offset, uint8_t data); 232 uint8_t midi_r(); 233 // uint8_t winram_r(); 234 // void winram_w(uint8_t data); 235 uint8_t pic_r(offs_t offset); 236 void pic_w(offs_t offset, uint8_t data); 237 238 uint8_t sdip_0_r(offs_t offset); 239 uint8_t sdip_1_r(offs_t offset); 240 uint8_t sdip_2_r(offs_t offset); 241 uint8_t sdip_3_r(offs_t offset); 242 uint8_t sdip_4_r(offs_t offset); 243 uint8_t sdip_5_r(offs_t offset); 244 uint8_t sdip_6_r(offs_t offset); 245 uint8_t sdip_7_r(offs_t offset); 246 uint8_t sdip_8_r(offs_t offset); 247 uint8_t sdip_9_r(offs_t offset); 248 uint8_t sdip_a_r(offs_t offset); 249 uint8_t sdip_b_r(offs_t offset); 250 251 void sdip_0_w(offs_t offset, uint8_t data) ; 252 void sdip_1_w(offs_t offset, uint8_t data) ; 253 void sdip_2_w(offs_t offset, uint8_t data) ; 254 void sdip_3_w(offs_t offset, uint8_t data) ; 255 void sdip_4_w(offs_t offset, uint8_t data) ; 256 void sdip_5_w(offs_t offset, uint8_t data) ; 257 void sdip_6_w(offs_t offset, uint8_t data) ; 258 void sdip_7_w(offs_t offset, uint8_t data) ; 259 void sdip_8_w(offs_t offset, uint8_t data) ; 260 void sdip_9_w(offs_t offset, uint8_t data) ; 261 void sdip_a_w(offs_t offset, uint8_t data) ; 262 void sdip_b_w(offs_t offset, uint8_t data) ; 263 264 uint8_t as_unkdev_data_r(offs_t offset); 265 void as_unkdev_data_w(offs_t offset, uint8_t data); 266 void as_unkdev_addr_w(offs_t offset, uint8_t data); 267 268 uint8_t window_bank_r(offs_t offset); 269 void window_bank_w(offs_t offset, uint8_t data); 270 uint16_t timestamp_r(offs_t offset); 271 uint8_t ext2_video_ff_r(); 272 void ext2_video_ff_w(uint8_t data); 273 274 DECLARE_FLOPPY_FORMATS( floppy_formats ); 275 UPD7220_DISPLAY_PIXELS_MEMBER( hgdc_display_pixels ); 276 UPD7220_DRAW_TEXT_LINE_MEMBER( hgdc_draw_text ); 277 278 DECLARE_MACHINE_START(pc9801_common); 279 DECLARE_MACHINE_START(pc9801f); 280 DECLARE_MACHINE_START(pc9801rs); 281 DECLARE_MACHINE_START(pc9801bx2); 282 DECLARE_MACHINE_START(pc9821); 283 DECLARE_MACHINE_START(pc9821ap2); 284 DECLARE_MACHINE_RESET(pc9801_common); 285 DECLARE_MACHINE_RESET(pc9801f); 286 DECLARE_MACHINE_RESET(pc9801rs); 287 DECLARE_MACHINE_RESET(pc9821); 288 289 void pc9801_palette(palette_device &palette) const; 290 DECLARE_WRITE_LINE_MEMBER(vrtc_irq); 291 uint8_t get_slave_ack(offs_t offset); 292 DECLARE_WRITE_LINE_MEMBER(dma_hrq_changed); 293 DECLARE_WRITE_LINE_MEMBER(tc_w); 294 uint8_t dma_read_byte(offs_t offset); 295 void dma_write_byte(offs_t offset, uint8_t data); 296 DECLARE_WRITE_LINE_MEMBER(dack0_w); 297 DECLARE_WRITE_LINE_MEMBER(dack1_w); 298 DECLARE_WRITE_LINE_MEMBER(dack2_w); 299 DECLARE_WRITE_LINE_MEMBER(dack3_w); 300 void ppi_sys_portc_w(uint8_t data); 301 302 DECLARE_WRITE_LINE_MEMBER(fdc_2dd_irq); 303 DECLARE_WRITE_LINE_MEMBER(pc9801rs_fdc_irq); 304 DECLARE_WRITE_LINE_MEMBER(pc9801rs_fdc_drq); 305 306 uint8_t ppi_mouse_porta_r(); 307 void ppi_mouse_porta_w(uint8_t data); 308 void ppi_mouse_portb_w(uint8_t data); 309 void ppi_mouse_portc_w(uint8_t data); 310 TIMER_DEVICE_CALLBACK_MEMBER( mouse_irq_cb ); 311 uint8_t unk_r(); 312 313 314 uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 315 uint32_t a20_286(bool state); 316 317 void pc9801_keyboard(machine_config &config); 318 void pc9801_mouse(machine_config &config); 319 void pc9801_cbus(machine_config &config); 320 void pc9801_sasi(machine_config &config); 321 void pc9801_ide(machine_config &config); 322 void pc9801_common(machine_config &config); 323 void ipl_bank(address_map &map); 324 void pc9801_common_io(address_map &map); 325 void pc9801_io(address_map &map); 326 void pc9801_map(address_map &map); 327 void pc9801rs_io(address_map &map); 328 void pc9801rs_map(address_map &map); 329 void pc9801ux_io(address_map &map); 330 void pc9801ux_map(address_map &map); 331 void pc9821_io(address_map &map); 332 void pc9821_map(address_map &map); 333 void pc9821as_io(address_map &map); 334 void upd7220_1_map(address_map &map); 335 void upd7220_2_map(address_map &map); 336 void upd7220_grcg_2_map(address_map &map); 337 338 enum 339 { 340 TIMER_VBIRQ 341 }; 342 343 inline void set_dma_channel(int channel, int state); 344 uint8_t *m_char_rom; 345 uint8_t *m_kanji_rom; 346 347 uint8_t m_dma_offset[4]; 348 uint8_t m_dma_autoinc[4]; 349 int m_dack; 350 351 uint8_t m_video_ff[8],m_gfx_ff; 352 uint8_t m_txt_scroll_reg[8]; 353 uint8_t m_pal_clut[4]; 354 355 std::unique_ptr<uint16_t[]> m_tvram; 356 357 uint16_t m_font_addr; 358 uint8_t m_font_line; 359 uint16_t m_font_lr; 360 361 uint8_t m_fdc_2dd_ctrl,m_fdc_2hd_ctrl; 362 uint8_t m_nmi_ff; 363 364 uint8_t m_vram_bank; 365 uint8_t m_vram_disp; 366 367 uint8_t m_sasi_data; 368 int m_sasi_data_enable; 369 uint8_t m_sasi_ctrl; 370 371 struct{ 372 uint8_t control; 373 uint8_t lx; 374 uint8_t ly; 375 uint8_t freq_reg; 376 uint8_t freq_index; 377 }m_mouse; 378 379 uint8_t m_ide_sel; 380 381 /* PC9801RS specific, move to specific state */ 382 uint8_t m_gate_a20; //A20 line 383 uint8_t m_access_ctrl; // DMA related 384 uint8_t m_fdc_ctrl; 385 uint8_t m_ex_video_ff[128]; 386 struct { 387 uint8_t pal_entry; 388 uint8_t r[16],g[16],b[16]; 389 }m_analog16; 390 struct { 391 uint8_t pal_entry; 392 uint8_t r[0x100],g[0x100],b[0x100]; 393 uint16_t bank[2]; 394 }m_analog256; 395 struct { 396 uint8_t mode; 397 uint8_t tile[4], tile_index; 398 }m_grcg; 399 400 void egc_blit_w(uint32_t offset, uint16_t data, uint16_t mem_mask); 401 uint16_t egc_blit_r(uint32_t offset, uint16_t mem_mask); 402 403 404 /* PC9821 specific */ 405 uint8_t m_sdip[24], m_sdip_bank; 406 uint8_t m_unkdev0468[0x100], m_unkdev0468_addr; 407 uint8_t m_pc9821_window_bank; 408 uint8_t m_ext2_ff; 409 uint8_t m_sys_type; 410 411 struct { 412 uint16_t regs[8]; 413 uint16_t pat[4]; 414 uint16_t src[4]; 415 int16_t count; 416 uint16_t leftover[4]; 417 bool first; 418 bool init; 419 } m_egc; 420 421 uint16_t m_pc9821_256vram_bank; 422 423 uint8_t m_sdip_read(uint16_t port, uint8_t sdip_offset); 424 void m_sdip_write(uint16_t port, uint8_t sdip_offset,uint8_t data); 425 uint16_t egc_do_partial_op(int plane, uint16_t src, uint16_t pat, uint16_t dst) const; 426 uint16_t egc_shift(int plane, uint16_t val); 427 }; 428 429 #endif // MAME_INCLUDES_PC9801_H 430