1 // license:GPL-2.0+ 2 // copyright-holders:Peter Trauner 3 /***************************************************************************** 4 * 5 * includes/lynx.h 6 * 7 ****************************************************************************/ 8 #ifndef MAME_INCLUDES_LYNX_H 9 #define MAME_INCLUDES_LYNX_H 10 11 #pragma once 12 13 #include "emupal.h" 14 #include "screen.h" 15 #include "audio/lynx.h" 16 #include "imagedev/snapquik.h" 17 #include "machine/bankdev.h" 18 #include "bus/generic/slot.h" 19 #include "bus/generic/carts.h" 20 21 #define LYNX_CART 0 22 #define LYNX_QUICKLOAD 1 23 24 25 #define NR_LYNX_TIMERS 8 26 27 class lynx_state : public driver_device 28 { 29 public: lynx_state(const machine_config & mconfig,device_type type,const char * tag)30 lynx_state(const machine_config &mconfig, device_type type, const char *tag) : 31 driver_device(mconfig, type, tag), 32 m_mem_0000(*this, "mem_0000"), 33 m_mem_fc00(*this, "mem_fc00"), 34 m_mem_fd00(*this, "mem_fd00"), 35 m_mem_fe00(*this, "mem_fe00"), 36 m_mem_fffa(*this, "mem_fffa"), 37 m_maincpu(*this, "maincpu"), 38 m_sound(*this, "custom"), 39 m_cart(*this, "cartslot"), 40 m_palette(*this, "palette"), 41 m_screen(*this, "screen"), 42 m_bank_fc00(*this, "bank_fc00"), 43 m_bank_fd00(*this, "bank_fd00"), 44 m_bank_fe00(*this, "bank_fe00"), 45 m_bank_fffa(*this, "bank_fffa") 46 { } 47 48 void lynx(machine_config &config); 49 50 private: 51 struct BLITTER 52 { 53 // global 54 uint16_t screen; 55 uint16_t colbuf; 56 uint16_t colpos; // byte where value of collision is written 57 int16_t xoff, yoff; 58 // in command 59 int mode; 60 uint8_t spr_coll; 61 uint8_t spritenr; 62 int16_t x_pos,y_pos; 63 uint16_t width, height; // uint16 important for blue lightning 64 int16_t tilt_accumulator; 65 uint16_t height_accumulator, width_accumulator; 66 uint16_t width_offset, height_offset; 67 int16_t stretch, tilt; 68 uint8_t color[16]; // or stored 69 uint16_t bitmap; 70 int use_rle; 71 int line_color; 72 73 uint8_t spr_ctl0; 74 uint8_t spr_ctl1; 75 uint16_t scb; 76 uint16_t scb_next; 77 uint8_t sprite_collide; 78 79 int everon; 80 uint8_t fred; 81 int memory_accesses; 82 attotime time; 83 84 int no_collide; 85 int vstretch; 86 int lefthanded; 87 int busy; 88 }; 89 90 struct UART 91 { 92 uint8_t serctl; 93 uint8_t data_received, data_to_send, buffer; 94 int received; 95 int sending; 96 int buffer_loaded; 97 }; 98 99 struct SUZY 100 { 101 uint8_t data[0x100]; 102 uint8_t high; 103 int low; 104 int signed_math; 105 int accumulate; 106 int accumulate_overflow; 107 }; 108 109 struct MIKEY 110 { 111 uint8_t data[0x100]; 112 uint16_t disp_addr; 113 uint8_t vb_rest; 114 }; 115 116 struct LYNX_TIMER 117 { 118 uint8_t bakup; 119 uint8_t cntrl1; 120 uint8_t cntrl2; 121 uint8_t counter; 122 emu_timer *timer; 123 int timer_active; 124 }; 125 126 enum 127 { 128 TIMER_BLITTER, 129 TIMER_SHOT, 130 TIMER_UART_LOOPBACK, 131 TIMER_UART 132 }; 133 134 virtual void machine_start() override; 135 virtual void machine_reset() override; 136 virtual void video_start() override; 137 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 138 139 required_shared_ptr<uint8_t> m_mem_0000; 140 required_shared_ptr<uint8_t> m_mem_fc00; 141 required_shared_ptr<uint8_t> m_mem_fd00; 142 required_shared_ptr<uint8_t> m_mem_fe00; 143 required_shared_ptr<uint8_t> m_mem_fffa; 144 required_device<cpu_device> m_maincpu; 145 required_device<lynx_sound_device> m_sound; 146 required_device<generic_slot_device> m_cart; 147 required_device<palette_device> m_palette; 148 required_device<screen_device> m_screen; 149 required_device<address_map_bank_device> m_bank_fc00; 150 required_device<address_map_bank_device> m_bank_fd00; 151 required_memory_bank m_bank_fe00; 152 required_memory_bank m_bank_fffa; 153 uint16_t m_granularity; 154 int m_sign_AB; 155 int m_sign_CD; 156 int m_rotate; 157 uint8_t m_memory_config; 158 159 BLITTER m_blitter; 160 SUZY m_suzy; 161 MIKEY m_mikey; 162 UART m_uart; 163 LYNX_TIMER m_timer[NR_LYNX_TIMERS]; 164 165 bitmap_rgb32 m_bitmap; 166 bitmap_rgb32 m_bitmap_temp; 167 168 void lynx_mem(address_map &map); 169 void lynx_fc00_mem(address_map &map); 170 void lynx_fd00_mem(address_map &map); 171 172 uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 173 174 uint8_t suzy_read(offs_t offset); 175 void suzy_write(offs_t offset, uint8_t data); 176 void lynx_uart_w(offs_t offset, uint8_t data); 177 uint8_t lynx_uart_r(offs_t offset); 178 uint8_t mikey_read(offs_t offset); 179 void mikey_write(offs_t offset, uint8_t data); 180 uint8_t lynx_memory_config_r(); 181 void lynx_memory_config_w(uint8_t data); 182 void lynx_divide(); 183 void lynx_multiply(); 184 uint8_t lynx_timer_read(int which, int offset); 185 void lynx_timer_write(int which, int offset, uint8_t data); 186 void sound_cb(); 187 TIMER_CALLBACK_MEMBER(lynx_blitter_timer); 188 TIMER_CALLBACK_MEMBER(lynx_timer_shot); 189 TIMER_CALLBACK_MEMBER(lynx_uart_loopback_timer); 190 TIMER_CALLBACK_MEMBER(lynx_uart_timer); 191 void lynx_postload(); 192 DECLARE_DEVICE_IMAGE_LOAD_MEMBER(cart_load); 193 uint8_t lynx_read_ram(uint16_t address); 194 void lynx_write_ram(uint16_t address, uint8_t data); 195 inline void lynx_plot_pixel(const int mode, const int16_t x, const int y, const int color); 196 void lynx_blit_do_work(const int y, const int xdir, const int bits_per_pixel, const int mask ); 197 void lynx_blit_rle_do_work( const int16_t y, const int xdir, const int bits_per_pixel, const int mask ); 198 void lynx_blit_lines(); 199 void lynx_blitter(); 200 void lynx_draw_line(); 201 void lynx_timer_init(int which); 202 void lynx_timer_signal_irq(int which); 203 void lynx_timer_count_down(int which); 204 uint32_t lynx_time_factor(int val); 205 void lynx_uart_reset(); 206 image_verify_result lynx_verify_cart(char *header, int kind); 207 DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb); 208 }; 209 210 211 /*---------- suzy registers ------------- */ 212 #define TMPADRL 0x00 // Temporary address (not sure what this is used for) 213 #define TMPADRH 0x01 214 #define TILTACUML 0x02 // Tilt accumulator (signed fixed-point, eight bits to the left of decimal) 215 #define TILTACUMH 0x03 216 #define HOFFL 0x04 // X offset to edge of visible window 217 #define HOFFH 0x05 218 #define VOFFL 0x06 // Y offset to edge of visible window 219 #define VOFFH 0x07 220 #define VIDBASL 0x08 // Video buffer address 221 #define VIDBASH 0x09 222 #define COLLBASL 0x0A // Collision buffer address 223 #define COLLBASH 0x0B 224 #define VIDADRL 0x0C // Current Video Build Address 225 #define VIDADRH 0x0D 226 #define COLLADRL 0x0E // Current Collision Build Address 227 #define COLLADRH 0x0F 228 #define SCBNEXTL 0x10 // Address of next SCB 229 #define SCBNEXTH 0x11 230 #define SPRDLINEL 0x12 // Sprite data start address 231 #define SPRDLINEH 0x13 232 #define HPOSSTRTL 0x14 // Starting Hpos 233 #define HPOSSTRTH 0x15 234 #define VPOSSTRTL 0x16 // Starting Vpos 235 #define VPOSSTRTH 0x17 236 #define SPRHSIZL 0x18 // H Size 237 #define SPRHSIZH 0x19 238 #define SPRVSIZL 0x1A // V Size 239 #define SPRVSIZH 0x1B 240 #define STRETCHL 0x1C // H/V Size Adder (signed fixed-point) 241 #define STRETCHH 0x1D 242 #define TILTL 0x1E // H Position Adder (signed fixed-point) 243 #define TILTH 0x1F 244 #define SPRDOFFL 0x20 // Offset to Next Sprite Data Line 245 #define SPRDOFFH 0x21 246 #define SPRVPOSL 0x22 // Current Vpos 247 #define SPRVPOSH 0x23 248 #define COLLOFFL 0x24 // Offset to Collision Depository 249 #define COLLOFFH 0x25 250 #define VSIZACUML 0x26 // Vertical Size Accumulator 251 #define VSIZACUMH 0x27 252 #define HSIZOFFL 0x28 // Horizontal Size Offset 253 #define HSIZOFFH 0x29 254 #define VSIZOFFL 0x2A // Vertical Size Offset 255 #define VSIZOFFH 0x2B 256 #define SCBADRL 0x2C // Address of Current SCB 257 #define SCBADRH 0x2D 258 #define PROCADRL 0x2E // Current Spr Data Proc Address 259 260 #define MATH_D 0x52 261 #define MATH_C 0x53 262 #define MATH_B 0x54 263 #define MATH_A 0x55 264 #define MATH_P 0x56 265 #define MATH_N 0x57 266 #define MATH_H 0x60 267 #define MATH_G 0x61 268 #define MATH_F 0x62 269 #define MATH_E 0x63 270 271 #define MATH_M 0x6c 272 #define MATH_L 0x6d 273 #define MATH_K 0x6e 274 #define MATH_J 0x6f 275 276 #define SPRCTL0 0x80 // Sprite Control Bits 0 (W)(U) 277 #define SPRCTL1 0x81 // Sprite Control Bits 1 (W)(U) 278 #define SPRCOLL 0x82 // Sprite Collision Number (W) 279 #define SPRINIT 0x83 // Sprite Initialization Bits (W)(U) 280 281 #define SUZYHREV 0x88 // Suzy Hardware Revision (R) = '01' 282 283 #define SUZYBUSEN 0x90 // Suzy Bus Enable (W) 284 #define SPRGO 0x91 // Sprite Process Start Bit (W) 285 #define SPRSYS 0x92 // System Control Bits (R/W) 286 287 #define JOYSTICK 0xB0 // Read Joystick and Switches(R) 288 #define SWITCHES 0xB1 // Read Other Switches (R) 289 #define RCART 0xB2 // Read / Write Cartridge Bank 0 (R/W) 290 #define RCART_BANK1 0xB3 // Read / Write Cartridge Bank 1 (R/W) (Unused in existing cartridges?) 291 292 //0xC0 LEDs (W) 293 //0xC2 Parallel Port Status(R/W) 294 //0xC3 Parallel Port Data (R/W) 295 //0xC4 Howie (R/W) 296 297 // SCB offsets 298 299 //8-bit 300 #define SCB_SPRCTL0 0x00 // 8 bit 301 #define SCB_SPRCTL1 0x01 // 8 bit 302 #define SCB_SPRCOLL 0x02 // 4 bit 303 304 //16-bit 305 #define SCB_SCBNEXT 0x03 // L,H Address of Next SCB 306 #define SCB_SPRDLINE 0x05 // L,H Start of Sprite Data Line Address 307 #define SCB_HPOSSTRT 0x07 // L,H Starting Hpos 308 #define SCB_VPOSSTRT 0x09 // L,H Starting Vpos 309 #define SCB_SPRHSIZ 0x0B // L,H H Size 310 #define SCB_SPRVSIZ 0x0D // L,H V Size 311 #define SCB_STRETCH 0x0F // L H H/V Size Adder 312 #define SCB_TILT 0x11 // L,H H Position Adder 313 314 #endif // MAME_INCLUDES_LYNX_H 315