1 // license:BSD-3-Clause 2 // copyright-holders:Aaron Giles,Nathan Woods,Angelo Salese, Robbbert 3 /************************************************************************* 4 5 Atari Jaguar hardware 6 7 *************************************************************************/ 8 9 #include "cpu/jaguar/jaguar.h" 10 #include "machine/nvram.h" 11 #include "sound/dac.h" 12 #include "machine/eepromser.h" 13 #include "machine/vt83c461.h" 14 #include "imagedev/snapquik.h" 15 #include "video/jag_blitter.h" 16 #include "cdrom.h" 17 #include "imagedev/chd_cd.h" 18 #include "screen.h" 19 #include "emupal.h" 20 21 #ifndef ENABLE_SPEEDUP_HACKS 22 #define ENABLE_SPEEDUP_HACKS 1 23 #endif 24 25 /* CoJag and Jaguar have completely different XTALs, pixel clock in Jaguar is the same as the GPU one */ 26 #define COJAG_PIXEL_CLOCK XTAL(14'318'181) 27 #define JAGUAR_CLOCK XTAL(26'590'906) // NTSC 28 // XTAL(26'593'900) PAL, TODO 29 30 class jaguar_state : public driver_device 31 { 32 public: jaguar_state(const machine_config & mconfig,device_type type,const char * tag)33 jaguar_state(const machine_config &mconfig, device_type type, const char *tag) 34 : driver_device(mconfig, type, tag) 35 , m_maincpu(*this, "maincpu") 36 , m_gpu(*this, "gpu") 37 , m_blitter(*this, "blitter") 38 , m_dsp(*this, "dsp") 39 , m_ldac(*this, "ldac") 40 , m_rdac(*this, "rdac") 41 , m_nvram(*this, "nvram") 42 , m_rom_base(*this, "mainrom") 43 , m_cart_base(*this, "cart") 44 , m_dsp_ram(*this, "dspram") 45 , m_wave_rom(*this, "waverom") 46 , m_shared_ram(*this, "sharedram") 47 , m_gpu_ram(*this, "gpuram") 48 , m_gpu_clut(*this, "gpuclut") 49 , m_romboard_region(*this, "romboard") 50 , m_mainram(*this, "mainram") 51 , m_mainram2(*this, "mainram2") 52 , m_maingfxbank(*this, "maingfxbank") 53 , m_gpugfxbank(*this, "gpugfxbank") 54 , m_mainsndbank(*this, "mainsndbank") 55 , m_dspsndbank(*this, "dspsndbank") 56 , m_config_io(*this, "CONFIG") 57 , m_joy(*this, "JOY%u", 0U) 58 , m_buttons(*this, "BUTTONS%u", 0U) 59 , m_system(*this, "SYSTEM") 60 , m_is_r3000(false) 61 , m_is_cojag(false) 62 , m_hacks_enabled(false) 63 , m_using_cart(false) 64 , m_joystick_data(0) 65 , m_misc_control_data(0) 66 , m_eeprom_enable(true) 67 , m_gpu_jump_address(nullptr) 68 , m_gpu_command_pending(false) 69 , m_gpu_spin_pc(0) 70 , m_main_speedup(nullptr) 71 , m_main_speedup_hits(0) 72 , m_main_speedup_last_cycles(0) 73 , m_main_speedup_max_cycles(0) 74 , m_main_gpu_wait(nullptr) 75 , m_eeprom_bit_count(0) 76 , m_protection_check(0) 77 , m_eeprom(*this, "eeprom") 78 , m_ide(*this, "ide") 79 , m_screen(*this, "screen") 80 , m_palette(*this, "palette") 81 { 82 } 83 84 void cojag68k(machine_config &config); 85 void cojagr3k(machine_config &config); 86 void cojagr3k_rom(machine_config &config); 87 void jaguar(machine_config &config); 88 89 void init_jaguar(); 90 void init_area51mx(); 91 void init_maxforce(); 92 void init_freezeat(); 93 void init_fishfren(); 94 void init_a51mxr3k(); 95 void init_area51(); 96 void init_freezeat4(); 97 void init_freezeat5(); 98 void init_freezeat6(); 99 void init_vcircle(); 100 void init_freezeat3(); 101 void init_freezeat2(); 102 void init_area51a(); 103 104 protected: 105 void console_base_map(address_map &map); 106 void console_base_gpu_map(address_map &map); 107 108 // device overrides 109 virtual void machine_start() override; 110 virtual void machine_reset() override; 111 virtual void sound_start() override; 112 virtual void video_start() override; 113 virtual void device_postload(); 114 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 115 116 void video_config(machine_config &config, const XTAL clock); 117 118 // devices 119 required_device<cpu_device> m_maincpu; 120 required_device<jaguargpu_cpu_device> m_gpu; 121 required_device<jag_blitter_device> m_blitter; 122 required_device<jaguardsp_cpu_device> m_dsp; 123 required_device<dac_word_interface> m_ldac; 124 required_device<dac_word_interface> m_rdac; 125 126 // memory 127 optional_shared_ptr<uint32_t> m_nvram; // not used on console 128 optional_region_ptr<uint16_t> m_rom_base; 129 optional_region_ptr<uint32_t> m_cart_base; // not used in cojag 130 required_shared_ptr<uint32_t> m_dsp_ram; 131 required_region_ptr<uint16_t> m_wave_rom; 132 required_shared_ptr<uint32_t> m_shared_ram; 133 required_shared_ptr<uint32_t> m_gpu_ram; 134 required_shared_ptr<uint32_t> m_gpu_clut; 135 optional_memory_region m_romboard_region; 136 optional_shared_ptr<uint32_t> m_mainram; 137 optional_shared_ptr<uint32_t> m_mainram2; 138 139 optional_memory_bank m_maingfxbank; 140 optional_memory_bank m_gpugfxbank; 141 optional_memory_bank m_mainsndbank; 142 optional_memory_bank m_dspsndbank; 143 optional_ioport m_config_io; 144 optional_ioport_array<8> m_joy; 145 optional_ioport_array<8> m_buttons; 146 optional_ioport m_system; 147 148 // configuration 149 bool m_is_r3000; 150 bool m_is_cojag; 151 bool m_hacks_enabled; 152 int m_pixel_clock; 153 bool m_using_cart; 154 155 uint32_t m_joystick_data; 156 157 private: 158 uint32_t m_misc_control_data; 159 bool m_eeprom_enable; 160 uint32_t *m_gpu_jump_address; 161 bool m_gpu_command_pending; 162 uint32_t m_gpu_spin_pc; 163 uint32_t *m_main_speedup; 164 int m_main_speedup_hits; 165 uint64_t m_main_speedup_last_cycles; 166 uint64_t m_main_speedup_max_cycles; 167 uint32_t *m_main_gpu_wait; 168 169 // driver data 170 uint8_t m_eeprom_bit_count; 171 uint8_t m_protection_check; /* 0 = check hasn't started yet; 1= check in progress; 2 = check is finished. */ 172 173 // audio data 174 uint16_t m_dsp_regs[0x40/2]; 175 uint16_t m_serial_frequency; 176 uint8_t m_gpu_irq_state; 177 emu_timer *m_serial_timer; 178 179 // blitter variables 180 uint32_t m_blitter_regs[40]; 181 uint16_t m_gpu_regs[0x100/2]; 182 emu_timer *m_object_timer; 183 uint8_t m_cpu_irq_state; 184 bitmap_rgb32 m_screen_bitmap; 185 uint8_t m_blitter_status; 186 pen_t m_pen_table[65536]; 187 uint8_t m_blend_y[65536]; 188 uint8_t m_blend_cc[65536]; 189 190 static void (jaguar_state::*const bitmap4[8])(uint16_t *, int32_t, int32_t, uint32_t *, int32_t, uint16_t *); 191 static void (jaguar_state::*const bitmap8[8])(uint16_t *, int32_t, int32_t, uint32_t *, int32_t, uint16_t *); 192 static void (jaguar_state::*const bitmap16[8])(uint16_t *, int32_t, int32_t, uint32_t *, int32_t); 193 static void (jaguar_state::*const bitmap32[8])(uint16_t *, int32_t, int32_t, uint32_t *, int32_t); 194 195 void eeprom_w(uint32_t data); 196 uint32_t eeprom_clk(); 197 uint32_t eeprom_cs(); 198 uint32_t misc_control_r(); 199 void misc_control_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 200 uint32_t gpuctrl_r(offs_t offset, uint32_t mem_mask = ~0); 201 void gpuctrl_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 202 uint32_t dspctrl_r(offs_t offset, uint32_t mem_mask = ~0); 203 void dspctrl_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 204 uint32_t joystick_r(); 205 void joystick_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 206 void latch_w(uint32_t data); 207 uint32_t eeprom_data_r(offs_t offset); 208 void eeprom_enable_w(uint32_t data); 209 void eeprom_data_w(offs_t offset, uint32_t data); 210 void gpu_jump_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 211 uint32_t gpu_jump_r(); 212 uint32_t cojagr3k_main_speedup_r(); 213 uint32_t main_gpu_wait_r(); 214 void area51_main_speedup_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 215 void area51mx_main_speedup_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 216 uint16_t gpuctrl_r16(offs_t offset, uint16_t mem_mask = ~0); 217 void gpuctrl_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 218 uint16_t blitter_r16(offs_t offset, uint16_t mem_mask = ~0); 219 void blitter_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 220 uint16_t serial_r16(offs_t offset); 221 void serial_w16(offs_t offset, uint16_t data); 222 uint16_t dspctrl_r16(offs_t offset, uint16_t mem_mask = ~0); 223 void dspctrl_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 224 uint16_t eeprom_cs16(offs_t offset); 225 uint16_t eeprom_clk16(offs_t offset); 226 void eeprom_w16(offs_t offset, uint16_t data); 227 uint16_t joystick_r16(offs_t offset); 228 void joystick_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 229 uint32_t shared_ram_r(offs_t offset); 230 void shared_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 231 uint32_t rom_base_r(offs_t offset); 232 uint32_t wave_rom_r(offs_t offset); 233 uint32_t dsp_ram_r(offs_t offset); 234 void dsp_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 235 uint32_t gpu_clut_r(offs_t offset); 236 void gpu_clut_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 237 uint32_t gpu_ram_r(offs_t offset); 238 void gpu_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 239 uint16_t shared_ram_r16(offs_t offset); 240 void shared_ram_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 241 uint16_t cart_base_r16(offs_t offset); 242 uint16_t dsp_ram_r16(offs_t offset); 243 void dsp_ram_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 244 uint16_t gpu_clut_r16(offs_t offset); 245 void gpu_clut_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 246 uint16_t gpu_ram_r16(offs_t offset); 247 void gpu_ram_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 248 249 // from audio/jaguar.cpp 250 uint16_t jerry_regs_r(offs_t offset); 251 void jerry_regs_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 252 uint32_t serial_r(offs_t offset); 253 void serial_w(offs_t offset, uint32_t data); 254 void serial_update(); 255 256 // from video/jaguar.cpp 257 uint32_t blitter_r(offs_t offset, uint32_t mem_mask = ~0); 258 void blitter_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 259 uint16_t tom_regs_r(offs_t offset); 260 void tom_regs_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 261 uint32_t cojag_gun_input_r(offs_t offset); 262 uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 263 void jagpal_ycc(palette_device &palette) const; 264 265 DECLARE_WRITE_LINE_MEMBER( gpu_cpu_int ); 266 DECLARE_WRITE_LINE_MEMBER( dsp_cpu_int ); 267 DECLARE_WRITE_LINE_MEMBER( external_int ); 268 269 image_init_result quickload_cb(device_image_interface &image, const char *file_type, int quickload_size); 270 DECLARE_DEVICE_IMAGE_LOAD_MEMBER( cart_load ); 271 void cpu_space_map(address_map &map); 272 void dsp_map(address_map &map); 273 void dsp_rom_map(address_map &map); 274 void gpu_map(address_map &map); 275 void gpu_rom_map(address_map &map); 276 void jag_gpu_dsp_map(address_map &map); 277 void jaguar_map(address_map &map); 278 void m68020_map(address_map &map); 279 void r3000_map(address_map &map); 280 void r3000_rom_map(address_map &map); 281 282 // timer IDs 283 enum 284 { 285 TID_SCANLINE, 286 TID_BLITTER_DONE, 287 TID_PIT, 288 TID_SERIAL, 289 TID_GPU_SYNC 290 }; 291 gpu_suspend()292 void gpu_suspend() { m_gpu->suspend(SUSPEND_REASON_SPIN, 1); } gpu_resume()293 void gpu_resume() { m_gpu->resume(SUSPEND_REASON_SPIN); } dsp_suspend()294 void dsp_suspend() { m_dsp->suspend(SUSPEND_REASON_SPIN, 1); } dsp_resume()295 void dsp_resume() { m_dsp->resume(SUSPEND_REASON_SPIN); } 296 297 void fix_endian( void *base, uint32_t size ); 298 void cojag_common_init(uint16_t gpu_jump_offs, uint16_t spin_pc); 299 void init_freeze_common(offs_t main_speedup_addr); 300 301 // from audio/jaguar.cpp 302 void update_gpu_irq(); 303 void dsp_flags_w(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 304 305 // from video/jaguar.cpp 306 void get_crosshair_xy(int player, int &x, int &y); 307 int effective_hvalue(int value); 308 bool adjust_object_timer(int vc); 309 inline void trigger_host_cpu_irq(int level); 310 inline void verify_host_cpu_irq(); memory_base(uint32_t offset)311 uint8_t *memory_base(uint32_t offset) { return reinterpret_cast<uint8_t *>(m_gpu->space(AS_PROGRAM).get_read_ptr(offset)); } 312 void blitter_run(); 313 void scanline_update(int param); 314 void set_palette(uint16_t vmode); 315 316 /* from jagobj.cpp */ 317 void jagobj_init(); 318 uint32_t *process_bitmap(uint16_t *scanline, uint32_t *objdata, int vc, bool logit); 319 uint32_t *process_scaled_bitmap(uint16_t *scanline, uint32_t *objdata, int vc, bool logit); 320 uint32_t *process_branch(uint32_t *objdata, int vc, bool logit); 321 void process_object_list(int vc, uint16_t *_scanline); 322 void bitmap_4_draw(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint8_t flags, int32_t dxpos, uint16_t *clutbase); 323 void bitmap_4_0(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 324 void bitmap_4_1(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 325 void bitmap_4_2(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 326 void bitmap_4_3(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 327 void bitmap_4_4(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 328 void bitmap_4_5(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 329 void bitmap_4_6(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 330 void bitmap_4_7(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 331 void bitmap_8_draw(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint8_t flags, int32_t dxpos, uint16_t *clutbase); 332 void bitmap_8_0(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 333 void bitmap_8_1(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 334 void bitmap_8_2(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 335 void bitmap_8_3(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 336 void bitmap_8_4(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 337 void bitmap_8_5(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 338 void bitmap_8_6(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 339 void bitmap_8_7(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint16_t *clutbase); 340 void bitmap_16_draw(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint8_t flags, int32_t dxpos); 341 void bitmap_16_0(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 342 void bitmap_16_1(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 343 void bitmap_16_2(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 344 void bitmap_16_3(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 345 void bitmap_16_4(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 346 void bitmap_16_5(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 347 void bitmap_16_6(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 348 void bitmap_16_7(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 349 void bitmap_32_draw(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos, uint8_t flags, int32_t dxpos); 350 void bitmap_32_0(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 351 void bitmap_32_1(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 352 void bitmap_32_2(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 353 void bitmap_32_3(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 354 void bitmap_32_4(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 355 void bitmap_32_5(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 356 void bitmap_32_6(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 357 void bitmap_32_7(uint16_t *scanline, int32_t firstpix, int32_t iwidth, uint32_t *src, int32_t xpos); 358 359 /* from jagblit.cpp */ 360 void generic_blitter(uint32_t command, uint32_t a1flags, uint32_t a2flags); 361 void blitter_09800001_010020_010020(uint32_t command, uint32_t a1flags, uint32_t a2flags); 362 void blitter_09800009_000020_000020(uint32_t command, uint32_t a1flags, uint32_t a2flags); 363 void blitter_01800009_000028_000028(uint32_t command, uint32_t a1flags, uint32_t a2flags); 364 void blitter_01800001_000018_000018(uint32_t command, uint32_t a1flags, uint32_t a2flags); 365 void blitter_01c00001_000018_000018(uint32_t command, uint32_t a1flags, uint32_t a2flags); 366 void blitter_00010000_xxxxxx_xxxxxx(uint32_t command, uint32_t a1flags, uint32_t a2flags); 367 void blitter_01800001_xxxxxx_xxxxxx(uint32_t command, uint32_t a1flags, uint32_t a2flags); 368 void blitter_x1800x01_xxxxxx_xxxxxx(uint32_t command, uint32_t a1flags, uint32_t a2flags); 369 370 optional_device<eeprom_serial_93cxx_device> m_eeprom; 371 optional_device<vt83c461_device> m_ide; 372 required_device<screen_device> m_screen; 373 required_device<palette_device> m_palette; 374 }; 375 376 class jaguarcd_state : public jaguar_state 377 { 378 public: jaguarcd_state(const machine_config & mconfig,device_type type,const char * tag)379 jaguarcd_state(const machine_config &mconfig, device_type type, const char *tag) 380 : jaguar_state(mconfig, type, tag) 381 , m_cdrom(*this, "cdrom") 382 , m_cd_bios(*this, "cdbios") 383 { 384 } 385 386 void jaguarcd(machine_config &config); 387 388 void init_jaguarcd(); 389 390 protected: 391 virtual void machine_reset() override; 392 393 private: 394 uint16_t butch_regs_r16(offs_t offset); 395 void butch_regs_w16(offs_t offset, uint16_t data, uint16_t mem_mask = ~0); 396 uint32_t butch_regs_r(offs_t offset); 397 void butch_regs_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); 398 399 uint32_t cd_bios_r(offs_t offset); 400 401 void jaguarcd_map(address_map &map); 402 void jagcd_gpu_dsp_map(address_map &map); 403 404 // devices 405 required_device<cdrom_image_device> m_cdrom; 406 required_region_ptr<uint16_t> m_cd_bios; 407 408 uint32_t m_butch_regs[0x40/4]; 409 uint32_t m_butch_cmd_response[0x102]; 410 uint8_t m_butch_cmd_index; 411 uint8_t m_butch_cmd_size; 412 413 cdrom_file *m_cd_file; 414 //const cdrom_toc* m_toc; 415 }; 416