1 // license:BSD-3-Clause 2 // copyright-holders:Wilbert Pol, Nigel Barnes 3 /***************************************************************************** 4 * 5 * includes/electron.h 6 * 7 * Acorn Electron 8 * 9 * Driver by Wilbert Pol 10 * 11 ****************************************************************************/ 12 #ifndef MAME_INCLUDES_ELECTRON_H 13 #define MAME_INCLUDES_ELECTRON_H 14 15 #pragma once 16 17 #include "machine/ram.h" 18 #include "machine/6522via.h" 19 #include "machine/input_merger.h" 20 #include "imagedev/cassette.h" 21 #include "sound/beep.h" 22 #include "emupal.h" 23 24 #include "bus/electron/exp.h" 25 #include "bus/bbc/userport/userport.h" 26 #include "bus/generic/slot.h" 27 #include "bus/generic/carts.h" 28 29 /* Interrupts */ 30 #define INT_HIGH_TONE 0x40 31 #define INT_TRANSMIT_EMPTY 0x20 32 #define INT_RECEIVE_FULL 0x10 33 #define INT_RTC 0x08 34 #define INT_DISPLAY_END 0x04 35 #define INT_SET 0x100 36 #define INT_CLEAR 0x200 37 38 class electron_state : public driver_device 39 { 40 public: electron_state(const machine_config & mconfig,device_type type,const char * tag)41 electron_state(const machine_config &mconfig, device_type type, const char *tag) 42 : driver_device(mconfig, type, tag) 43 , m_maincpu(*this, "maincpu") 44 , m_irqs(*this, "irqs") 45 , m_screen(*this, "screen") 46 , m_cassette(*this, "cassette") 47 , m_beeper(*this, "beeper") 48 , m_region_mos(*this, "mos") 49 , m_keybd(*this, "LINE.%u", 0) 50 , m_exp(*this, "exp") 51 , m_ram(*this, RAM_TAG) 52 , m_mrb(*this, "MRB") 53 , m_capslock_led(*this, "capslock_led") 54 { } 55 56 void electron(machine_config &config); 57 void btm2105(machine_config &config); 58 59 void electron64(machine_config &config); 60 61 static void plus3_default(device_t* device); 62 63 DECLARE_INPUT_CHANGED_MEMBER( trigger_reset ); 64 65 protected: 66 enum 67 { 68 TIMER_TAPE_HANDLER, 69 TIMER_SETUP_BEEP, 70 TIMER_SCANLINE_INTERRUPT 71 }; 72 73 emu_timer *m_tape_timer; 74 int m_map4[256]; 75 int m_map16[256]; 76 emu_timer *m_scanline_timer; 77 uint8_t electron64_fetch_r(offs_t offset); 78 uint8_t electron_mem_r(offs_t offset); 79 void electron_mem_w(offs_t offset, uint8_t data); 80 virtual uint8_t electron_paged_r(offs_t offset); 81 virtual void electron_paged_w(offs_t offset, uint8_t data); 82 uint8_t electron_mos_r(offs_t offset); 83 void electron_mos_w(offs_t offset, uint8_t data); 84 virtual uint8_t electron_fred_r(offs_t offset); 85 virtual void electron_fred_w(offs_t offset, uint8_t data); 86 uint8_t electron_jim_r(offs_t offset); 87 void electron_jim_w(offs_t offset, uint8_t data); 88 uint8_t electron_sheila_r(offs_t offset); 89 void electron_sheila_w(offs_t offset, uint8_t data); 90 91 void electron_colours(palette_device &palette) const; 92 uint32_t screen_update_electron(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 93 TIMER_CALLBACK_MEMBER(electron_tape_timer_handler); 94 TIMER_CALLBACK_MEMBER(setup_beep); 95 TIMER_CALLBACK_MEMBER(electron_scanline_interrupt); 96 97 inline uint8_t read_vram( uint16_t addr ); 98 inline void electron_plot_pixel(bitmap_ind16 &bitmap, int x, int y, uint32_t color); 99 void electron_interrupt_handler(int mode, int interrupt); 100 101 void electron_mem(address_map &map); 102 103 void electron64_opcodes(address_map &map); 104 105 virtual void machine_start() override; 106 virtual void machine_reset() override; 107 virtual void video_start() override; 108 109 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 110 111 required_device<cpu_device> m_maincpu; 112 required_device<input_merger_device> m_irqs; 113 required_device<screen_device> m_screen; 114 required_device<cassette_image_device> m_cassette; 115 required_device<beep_device> m_beeper; 116 required_memory_region m_region_mos; 117 required_ioport_array<14> m_keybd; 118 required_device<electron_expansion_slot_device> m_exp; 119 required_device<ram_device> m_ram; 120 optional_ioport m_mrb; 121 output_finder<> m_capslock_led; 122 123 void waitforramsync(); 124 void electron_tape_start(); 125 void electron_tape_stop(); 126 127 /* ULA context */ 128 struct ULA 129 { 130 uint8_t interrupt_status; 131 uint8_t interrupt_control; 132 uint8_t rompage; 133 uint16_t screen_start; 134 uint16_t screen_base; 135 uint16_t screen_size; 136 uint16_t screen_addr; 137 int screen_dispend; 138 int current_pal[16]; 139 int communication_mode; 140 int screen_mode; 141 int cassette_motor_mode; 142 int capslock_mode; 143 /* tape reading related */ 144 uint32_t tape_value; 145 int tape_steps; 146 int bit_count; 147 int high_tone_set; 148 int start_bit; 149 int stop_bit; 150 int tape_running; 151 uint8_t tape_byte; 152 }; 153 154 ULA m_ula; 155 bool m_mrb_mapped; 156 bool m_vdu_drivers; 157 }; 158 159 160 class electronsp_state : public electron_state 161 { 162 public: electronsp_state(const machine_config & mconfig,device_type type,const char * tag)163 electronsp_state(const machine_config &mconfig, device_type type, const char *tag) 164 : electron_state(mconfig, type, tag) 165 , m_region_sp64(*this, "sp64") 166 , m_via(*this, "via6522") 167 , m_userport(*this, "userport") 168 , m_romi(*this, "romi%u", 1) 169 , m_rompages(*this, "ROMPAGES") 170 { } 171 172 void electronsp(machine_config &config); 173 174 protected: 175 virtual uint8_t electron_paged_r(offs_t offset) override; 176 virtual void electron_paged_w(offs_t offset, uint8_t data) override; 177 virtual uint8_t electron_fred_r(offs_t offset) override; 178 virtual void electron_fred_w(offs_t offset, uint8_t data) override; 179 180 virtual void machine_start() override; 181 182 private: 183 required_memory_region m_region_sp64; 184 required_device<via6522_device> m_via; 185 required_device<bbc_userport_slot_device> m_userport; 186 required_device_array<generic_slot_device, 2> m_romi; 187 required_ioport m_rompages; 188 189 uint8_t m_sp64_bank; 190 std::unique_ptr<uint8_t[]> m_sp64_ram; 191 192 image_init_result load_rom(device_image_interface &image, generic_slot_device *slot); DECLARE_DEVICE_IMAGE_LOAD_MEMBER(rom1_load)193 DECLARE_DEVICE_IMAGE_LOAD_MEMBER(rom1_load) { return load_rom(image, m_romi[0]); } DECLARE_DEVICE_IMAGE_LOAD_MEMBER(rom2_load)194 DECLARE_DEVICE_IMAGE_LOAD_MEMBER(rom2_load) { return load_rom(image, m_romi[1]); } 195 }; 196 197 198 #endif // MAME_INCLUDES_ELECTRON_H 199