Previous 199869 Revisions Next

r22577 Saturday 27th April, 2013 at 14:35:53 UTC by Robbbert
(MESS) CD2650: added beeper for morse code program
[src/mess/drivers]cd2650.c

trunk/src/mess/drivers/cd2650.c
r22576r22577
2727#include "imagedev/snapquik.h"
2828#include "imagedev/cassette.h"
2929#include "sound/wave.h"
30#include "sound/beep.h"
3031
3132
3233class cd2650_state : public driver_device
r22576r22577
3435public:
3536   cd2650_state(const machine_config &mconfig, device_type type, const char *tag)
3637      : 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   { }
4043
41   DECLARE_READ8_MEMBER(cd2650_keyin_r);
44   DECLARE_READ8_MEMBER(keyin_r);
45   DECLARE_WRITE8_MEMBER(beep_w);
4246   DECLARE_WRITE8_MEMBER(kbd_put);
4347   DECLARE_READ8_MEMBER(cass_r);
4448   DECLARE_WRITE8_MEMBER(cass_w);
r22576r22577
5054   UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
5155   required_device<cpu_device> m_maincpu;
5256   required_shared_ptr<const UINT8> m_p_videoram;
57   required_device<beep_device> m_beep;
5358   required_device<cassette_image_device> m_cass;
5459};
5560
5661
62WRITE8_MEMBER( cd2650_state::beep_w )
63{
64   if (data & 7)
65      m_beep->set_state(BIT(data, 3));
66}
67
5768WRITE8_MEMBER( cd2650_state::cass_w )
5869{
5970   m_cass->output(BIT(data, 0) ? -1.0 : +1.0);
r22576r22577
6475   return (m_cass->input() > 0.03) ? 1 : 0;
6576}
6677
67READ8_MEMBER( cd2650_state::cd2650_keyin_r )
78READ8_MEMBER( cd2650_state::keyin_r )
6879{
6980   UINT8 ret = m_term_data;
7081   m_term_data = 0x80;
r22576r22577
7788   ADDRESS_MAP_UNMAP_HIGH
7889   AM_RANGE( 0x0000, 0x03ff) AM_ROM
7990   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")
8192   AM_RANGE( 0x1800, 0x7fff) AM_RAM // expansion ram needed by quickloads
8293ADDRESS_MAP_END
8394
8495static ADDRESS_MAP_START( cd2650_io, AS_IO, 8, cd2650_state)
8596   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)
8798   AM_RANGE(S2650_SENSE_PORT, S2650_FO_PORT) AM_READWRITE(cass_r, cass_w)
8899ADDRESS_MAP_END
89100
r22576r22577
95106void cd2650_state::machine_reset()
96107{
97108   m_term_data = 0x80;
109   m_beep->set_frequency(950);    /* guess */
110   m_beep->set_state(0);
98111}
99112
100113void cd2650_state::video_start()
r22576r22577
175188   int result = IMAGE_INIT_FAIL;
176189
177190   quick_length = image.length();
178   quick_data = (UINT8*)malloc(quick_length);
179   if (!quick_data)
191   if (quick_length < 0x0444)
180192   {
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");
183195   }
196   else if (quick_length > 0x8000)
197   {
198      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
199      image.message(" File too long");
200   }
184201   else
185202   {
186      read_ = image.fread( quick_data, quick_length);
187      if (read_ != quick_length)
203      quick_data = (UINT8*)malloc(quick_length);
204      if (!quick_data)
188205      {
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");
191208      }
192      else if (quick_data[0] != 0x40)
193      {
194         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
195         image.message(" Invalid header");
196      }
197209      else
198210      {
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)
202213         {
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");
205216         }
206         else if (quick_length < 0x0444)
217         else if (quick_data[0] != 0x40)
207218         {
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");
210221         }
211         else if (quick_length > 0x8000)
212         {
213            image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
214            image.message(" File too long");
215         }
216222         else
217223         {
218            read_ = 0x1000;
219            if (quick_length < 0x1000)
220               read_ = quick_length;
224            exec_addr = quick_data[1] * 256 + quick_data[2];
221225
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;
224236
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++)
231238                  space.write_byte(i, quick_data[i]);
232239
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;
236243
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]);
239247
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]);
242251
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            }
244260         }
245261      }
246262
r22576r22577
273289
274290   /* cassette */
275291   MCFG_CASSETTE_ADD( "cassette", default_cassette_interface )
292
293   /* Sound */
276294   MCFG_SPEAKER_STANDARD_MONO("mono")
277295   MCFG_SOUND_WAVE_ADD(WAVE_TAG, "cassette")
278296   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
297   MCFG_SOUND_ADD("beeper", BEEP, 0)
298   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
279299MACHINE_CONFIG_END
280300
281301/* ROM definition */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team