trunk/src/mess/drivers/cd2650.c
| r22576 | r22577 | |
| 27 | 27 | #include "imagedev/snapquik.h" |
| 28 | 28 | #include "imagedev/cassette.h" |
| 29 | 29 | #include "sound/wave.h" |
| 30 | #include "sound/beep.h" |
| 30 | 31 | |
| 31 | 32 | |
| 32 | 33 | class cd2650_state : public driver_device |
| r22576 | r22577 | |
| 34 | 35 | public: |
| 35 | 36 | cd2650_state(const machine_config &mconfig, device_type type, const char *tag) |
| 36 | 37 | : driver_device(mconfig, type, tag), |
| 37 | | m_maincpu(*this, "maincpu"), |
| 38 | | m_p_videoram(*this, "p_videoram"), |
| 39 | | m_cass(*this, "cassette") { } |
| 38 | m_maincpu(*this, "maincpu"), |
| 39 | m_p_videoram(*this, "videoram"), |
| 40 | m_beep(*this, "beeper"), |
| 41 | m_cass(*this, "cassette") |
| 42 | { } |
| 40 | 43 | |
| 41 | | DECLARE_READ8_MEMBER(cd2650_keyin_r); |
| 44 | DECLARE_READ8_MEMBER(keyin_r); |
| 45 | DECLARE_WRITE8_MEMBER(beep_w); |
| 42 | 46 | DECLARE_WRITE8_MEMBER(kbd_put); |
| 43 | 47 | DECLARE_READ8_MEMBER(cass_r); |
| 44 | 48 | DECLARE_WRITE8_MEMBER(cass_w); |
| r22576 | r22577 | |
| 50 | 54 | UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 51 | 55 | required_device<cpu_device> m_maincpu; |
| 52 | 56 | required_shared_ptr<const UINT8> m_p_videoram; |
| 57 | required_device<beep_device> m_beep; |
| 53 | 58 | required_device<cassette_image_device> m_cass; |
| 54 | 59 | }; |
| 55 | 60 | |
| 56 | 61 | |
| 62 | WRITE8_MEMBER( cd2650_state::beep_w ) |
| 63 | { |
| 64 | if (data & 7) |
| 65 | m_beep->set_state(BIT(data, 3)); |
| 66 | } |
| 67 | |
| 57 | 68 | WRITE8_MEMBER( cd2650_state::cass_w ) |
| 58 | 69 | { |
| 59 | 70 | m_cass->output(BIT(data, 0) ? -1.0 : +1.0); |
| r22576 | r22577 | |
| 64 | 75 | return (m_cass->input() > 0.03) ? 1 : 0; |
| 65 | 76 | } |
| 66 | 77 | |
| 67 | | READ8_MEMBER( cd2650_state::cd2650_keyin_r ) |
| 78 | READ8_MEMBER( cd2650_state::keyin_r ) |
| 68 | 79 | { |
| 69 | 80 | UINT8 ret = m_term_data; |
| 70 | 81 | m_term_data = 0x80; |
| r22576 | r22577 | |
| 77 | 88 | ADDRESS_MAP_UNMAP_HIGH |
| 78 | 89 | AM_RANGE( 0x0000, 0x03ff) AM_ROM |
| 79 | 90 | AM_RANGE( 0x0400, 0x0fff) AM_RAM |
| 80 | | AM_RANGE( 0x1000, 0x17ff) AM_RAM AM_SHARE("p_videoram") |
| 91 | AM_RANGE( 0x1000, 0x17ff) AM_RAM AM_SHARE("videoram") |
| 81 | 92 | AM_RANGE( 0x1800, 0x7fff) AM_RAM // expansion ram needed by quickloads |
| 82 | 93 | ADDRESS_MAP_END |
| 83 | 94 | |
| 84 | 95 | static ADDRESS_MAP_START( cd2650_io, AS_IO, 8, cd2650_state) |
| 85 | 96 | ADDRESS_MAP_UNMAP_HIGH |
| 86 | | AM_RANGE(S2650_DATA_PORT,S2650_DATA_PORT) AM_READ(cd2650_keyin_r) |
| 97 | AM_RANGE(S2650_DATA_PORT,S2650_DATA_PORT) AM_READWRITE(keyin_r, beep_w) |
| 87 | 98 | AM_RANGE(S2650_SENSE_PORT, S2650_FO_PORT) AM_READWRITE(cass_r, cass_w) |
| 88 | 99 | ADDRESS_MAP_END |
| 89 | 100 | |
| r22576 | r22577 | |
| 95 | 106 | void cd2650_state::machine_reset() |
| 96 | 107 | { |
| 97 | 108 | m_term_data = 0x80; |
| 109 | m_beep->set_frequency(950); /* guess */ |
| 110 | m_beep->set_state(0); |
| 98 | 111 | } |
| 99 | 112 | |
| 100 | 113 | void cd2650_state::video_start() |
| r22576 | r22577 | |
| 175 | 188 | int result = IMAGE_INIT_FAIL; |
| 176 | 189 | |
| 177 | 190 | quick_length = image.length(); |
| 178 | | quick_data = (UINT8*)malloc(quick_length); |
| 179 | | if (!quick_data) |
| 191 | if (quick_length < 0x0444) |
| 180 | 192 | { |
| 181 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); |
| 182 | | image.message(" Cannot open file"); |
| 193 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); |
| 194 | image.message(" File too short"); |
| 183 | 195 | } |
| 196 | else if (quick_length > 0x8000) |
| 197 | { |
| 198 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); |
| 199 | image.message(" File too long"); |
| 200 | } |
| 184 | 201 | else |
| 185 | 202 | { |
| 186 | | read_ = image.fread( quick_data, quick_length); |
| 187 | | if (read_ != quick_length) |
| 203 | quick_data = (UINT8*)malloc(quick_length); |
| 204 | if (!quick_data) |
| 188 | 205 | { |
| 189 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); |
| 190 | | image.message(" Cannot read the file"); |
| 206 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file"); |
| 207 | image.message(" Cannot open file"); |
| 191 | 208 | } |
| 192 | | else if (quick_data[0] != 0x40) |
| 193 | | { |
| 194 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); |
| 195 | | image.message(" Invalid header"); |
| 196 | | } |
| 197 | 209 | else |
| 198 | 210 | { |
| 199 | | exec_addr = quick_data[1] * 256 + quick_data[2]; |
| 200 | | |
| 201 | | if (exec_addr >= quick_length) |
| 211 | read_ = image.fread( quick_data, quick_length); |
| 212 | if (read_ != quick_length) |
| 202 | 213 | { |
| 203 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); |
| 204 | | image.message(" Exec address beyond end of file"); |
| 214 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file"); |
| 215 | image.message(" Cannot read the file"); |
| 205 | 216 | } |
| 206 | | else if (quick_length < 0x0444) |
| 217 | else if (quick_data[0] != 0x40) |
| 207 | 218 | { |
| 208 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short"); |
| 209 | | image.message(" File too short"); |
| 219 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header"); |
| 220 | image.message(" Invalid header"); |
| 210 | 221 | } |
| 211 | | else if (quick_length > 0x8000) |
| 212 | | { |
| 213 | | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long"); |
| 214 | | image.message(" File too long"); |
| 215 | | } |
| 216 | 222 | else |
| 217 | 223 | { |
| 218 | | read_ = 0x1000; |
| 219 | | if (quick_length < 0x1000) |
| 220 | | read_ = quick_length; |
| 224 | exec_addr = quick_data[1] * 256 + quick_data[2]; |
| 221 | 225 | |
| 222 | | for (i = quick_addr; i < read_; i++) |
| 223 | | space.write_byte(i, quick_data[i]); |
| 226 | if (exec_addr >= quick_length) |
| 227 | { |
| 228 | image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file"); |
| 229 | image.message(" Exec address beyond end of file"); |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | read_ = 0x1000; |
| 234 | if (quick_length < 0x1000) |
| 235 | read_ = quick_length; |
| 224 | 236 | |
| 225 | | read_ = 0x1780; |
| 226 | | if (quick_length < 0x1780) |
| 227 | | read_ = quick_length; |
| 228 | | |
| 229 | | if (quick_length > 0x157f) |
| 230 | | for (i = 0x1580; i < read_; i++) |
| 237 | for (i = quick_addr; i < read_; i++) |
| 231 | 238 | space.write_byte(i, quick_data[i]); |
| 232 | 239 | |
| 233 | | if (quick_length > 0x17ff) |
| 234 | | for (i = 0x1800; i < quick_length; i++) |
| 235 | | space.write_byte(i, quick_data[i]); |
| 240 | read_ = 0x1780; |
| 241 | if (quick_length < 0x1780) |
| 242 | read_ = quick_length; |
| 236 | 243 | |
| 237 | | /* display a message about the loaded quickload */ |
| 238 | | image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); |
| 244 | if (quick_length > 0x157f) |
| 245 | for (i = 0x1580; i < read_; i++) |
| 246 | space.write_byte(i, quick_data[i]); |
| 239 | 247 | |
| 240 | | // Start the quickload |
| 241 | | m_maincpu->set_pc(exec_addr); |
| 248 | if (quick_length > 0x17ff) |
| 249 | for (i = 0x1800; i < quick_length; i++) |
| 250 | space.write_byte(i, quick_data[i]); |
| 242 | 251 | |
| 243 | | result = IMAGE_INIT_PASS; |
| 252 | /* display a message about the loaded quickload */ |
| 253 | image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr); |
| 254 | |
| 255 | // Start the quickload |
| 256 | m_maincpu->set_pc(exec_addr); |
| 257 | |
| 258 | result = IMAGE_INIT_PASS; |
| 259 | } |
| 244 | 260 | } |
| 245 | 261 | } |
| 246 | 262 | |
| r22576 | r22577 | |
| 273 | 289 | |
| 274 | 290 | /* cassette */ |
| 275 | 291 | MCFG_CASSETTE_ADD( "cassette", default_cassette_interface ) |
| 292 | |
| 293 | /* Sound */ |
| 276 | 294 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 277 | 295 | MCFG_SOUND_WAVE_ADD(WAVE_TAG, "cassette") |
| 278 | 296 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) |
| 297 | MCFG_SOUND_ADD("beeper", BEEP, 0) |
| 298 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 279 | 299 | MACHINE_CONFIG_END |
| 280 | 300 | |
| 281 | 301 | /* ROM definition */ |