Previous 15994 Revisions Next

r2443 Wednesday 23rd April, 2008 at 10:28:11 UTC by Nathan Woods
Z80bin cleanups
[docs]messnew.txt
[src/mess/devices]z80bin.c z80bin.h
[src/mess/drivers]exidy.c mbee.c super80.c vtech1.c

src/mess/devices/z80bin.c
r2442r2443
2222***************************************************************************/
2323
2424/*-------------------------------------------------
25    z80bin_load_file - this is a public function
26   that really should be static
25    z80bin_load_file - load a z80bin file into
26   memory
2727-------------------------------------------------*/
2828
29int z80bin_load_file(const device_config *image, const char *file_type, UINT16 *exec_addr, UINT16 *start_addr, UINT16 *end_addr )
29static int z80bin_load_file(const device_config *image, const char *file_type, UINT16 *exec_addr, UINT16 *start_addr, UINT16 *end_addr )
3030{
3131   int ch;
3232   UINT16 args[3];
r2442r2443
9898
9999static QUICKLOAD_LOAD( z80bin )
100100{
101   const z80bin_config *config;
101102   UINT16 exec_addr, start_addr, end_addr;
103   int autorun;
102104
103   if (z80bin_load_file( image, file_type, &exec_addr, &start_addr, &end_addr ) == INIT_FAIL)
105   /* load the binary into memory */
106   if (z80bin_load_file(image, file_type, &exec_addr, &start_addr, &end_addr) == INIT_FAIL)
104107      return INIT_FAIL;
105108
106   if (exec_addr != 0xffff)   /* non-executable data file */
107      cpunum_set_reg(0, REG_PC, exec_addr);   /* start program */
109   /* is this file executable? */
110   if (exec_addr != 0xffff)
111   {
112      config = (const z80bin_config *) image->inline_config;
108113
114      /* check to see if autorun is on (I hate how this works) */
115      autorun = input_port_read_safe(image->machine, "CONFIG", 0xFF) & 1;
116
117      /* start program */
118      if (config->execute != NULL)
119      {
120         (*config->execute)(start_addr, end_addr, exec_addr, autorun);
121      }
122      else
123      {
124         if (autorun)
125            cpunum_set_reg(0, REG_PC, exec_addr);   
126      }
127   }
128
109129   return INIT_PASS;
110130}
111131
r2442r2443
120140   /* quickload */
121141   switch(state)
122142   {
143      /* --- the following bits of info are returned as 64-bit signed integers --- */
144      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = sizeof(z80bin_config); break;
145
123146      /* --- the following bits of info are returned as NULL-terminated strings --- */
124147      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__; break;
125148      case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:         info->s = "bin"; break;
src/mess/devices/z80bin.h
r2442r2443
1111#define __Z80BIN_H__
1212
1313#include "image.h"
14#include "snapquik.h"
1415
1516
1617/***************************************************************************
r2442r2443
1920
2021#define Z80BIN   DEVICE_GET_INFO_NAME(z80bin)
2122
23#define Z80BIN_EXECUTE_NAME(name)   z80bin_execute_##name
24#define Z80BIN_EXECUTE(name)      void Z80BIN_EXECUTE_NAME(name)(UINT16 start_address, UINT16 end_address, UINT16 execute_address, int autorun)
2225
26#define z80bin_execute_default      NULL
2327
28
29
2430/***************************************************************************
2531    TYPE DEFINITIONS
2632***************************************************************************/
2733
34typedef void (*z80bin_execute_func)(UINT16 start_address, UINT16 end_address, UINT16 execute_address, int autorun);
35
36typedef struct _z80bin_config z80bin_config;
37struct _z80bin_config
38{
39   snapquick_config base;
40   z80bin_execute_func execute;
41};
42
43
44
45/***************************************************************************
46    Z80BIN QUICKLOAD DEVICE CONFIGURATION MACROS
47***************************************************************************/
48
49#define MDRV_Z80BIN_QUICKLOAD_ADD(_execute, _delay) \
50   MDRV_DEVICE_ADD(TAG_QUICKLOAD, Z80BIN) \
51   MDRV_DEVICE_CONFIG_DATA64(snapquick_config, delay_seconds, (seconds_t) (_delay)) \
52   MDRV_DEVICE_CONFIG_DATA64(snapquick_config, delay_attoseconds, (attoseconds_t) (((_delay) - (int)(_delay)) * ATTOSECONDS_PER_SECOND)) \
53   MDRV_DEVICE_CONFIG_DATAPTR(z80bin_config, execute, Z80BIN_EXECUTE_NAME(_execute))
54
55
56
57/***************************************************************************
58    TYPE DEFINITIONS
59***************************************************************************/
60
2861/* device getinfo function */
2962DEVICE_GET_INFO(z80bin);
3063
31/* please stop using this method - z80bin needs to be encapsulated into a proper device */
32int z80bin_load_file(const device_config *image, const char *file_type, UINT16 *exec_addr, UINT16 *start_addr, UINT16 *end_addr );
3364
3465
3566#endif /* __Z80BIN_H__ */
src/mess/drivers/mbee.c
r2442r2443
5858#include "devices/z80bin.h"
5959
6060static SNAPSHOT_LOAD( mbee );
61static QUICKLOAD_LOAD( mbee );
61static Z80BIN_EXECUTE( mbee );
6262
6363static size_t mbee_size;
6464
r2442r2443
313313
314314   /* devices */
315315   MDRV_SNAPSHOT_ADD(mbee, "mwb", 0.5)
316   MDRV_QUICKLOAD_ADD(mbee, "bin", 0)
316   MDRV_Z80BIN_QUICKLOAD_ADD(mbee, 0)
317317MACHINE_DRIVER_END
318318
319319
r2442r2443
350350
351351   /* devices */
352352   MDRV_SNAPSHOT_ADD(mbee, "mwb", 0.5)
353   MDRV_QUICKLOAD_ADD(mbee, "bin", 0)
353   MDRV_Z80BIN_QUICKLOAD_ADD(mbee, 0)
354354MACHINE_DRIVER_END
355355
356356
r2442r2443
447447
448448***************************************************************************/
449449
450static QUICKLOAD_LOAD( mbee )
450static Z80BIN_EXECUTE( mbee )
451451{
452   UINT8 sw = input_port_read(image->machine, "CONFIG") & 1;         /* reading the dipswitch: 1 = autorun */
453   UINT16 exec_addr, start_addr, end_addr;
452   program_write_word_16le(0xa6, execute_address);         /* fix the EXEC command */
454453
455   if (z80bin_load_file(image, file_type, &exec_addr, &start_addr, &end_addr ) == INIT_FAIL)
456      return INIT_FAIL;
457
458   if (exec_addr == 0xffff) return INIT_PASS;         /* data file */
459
460   program_write_word_16le(0xa6,exec_addr);         /* fix the EXEC command */
461
462   if (sw)
454   if (autorun)
463455   {
464      program_write_word_16le(0xa2,exec_addr);      /* fix warm-start vector to get around some copy-protections */
465      cpunum_set_reg(0, REG_PC, exec_addr);
456      program_write_word_16le(0xa2, execute_address);      /* fix warm-start vector to get around some copy-protections */
457      cpunum_set_reg(0, REG_PC, execute_address);
466458   }
467459   else
468      program_write_word_16le(0xa2,0x8517);
469
470   return INIT_PASS;
460   {
461      program_write_word_16le(0xa2, 0x8517);
462   }
471463}
472464
473465static SNAPSHOT_LOAD( mbee )
src/mess/drivers/super80.c
r2442r2443
1010#include "sound/speaker.h"
1111#include "deprecat.h"      /* "Machine" needed for z80pio interrupt */
1212
13static QUICKLOAD_LOAD( super80 );
14
1513static UINT8 super80_mhz=2;   /* state of bit 2 of port F0 */
1614static UINT16 vidpg=0xfe00;   /* Home position of video page being displayed */
1715static UINT8 int_sw;      /* internal 1 mhz flipflop */
r2442r2443
818816   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
819817
820818   /* quickload */
821   MDRV_QUICKLOAD_ADD(super80, "bin", 0)
819   MDRV_Z80BIN_QUICKLOAD_ADD(default, 0)
822820MACHINE_DRIVER_END
823821
824822static MACHINE_DRIVER_START( super80d )
r2442r2443
867865   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
868866
869867   /* quickload */
870   MDRV_QUICKLOAD_ADD(super80, "bin", 0)
868   MDRV_Z80BIN_QUICKLOAD_ADD(default, 0)
871869MACHINE_DRIVER_END
872870
873871static void driver_init_common( void )
r2442r2443
957955
958956/**************************** DEVICES *****************************************************************/
959957
960static QUICKLOAD_LOAD( super80 )
961{
962   UINT8 sw = input_port_read(image->machine, "CONFIG") & 1;            /* reading the dipswitch: 1 = autorun */
963   UINT16 exec_addr, start_addr, end_addr;
964
965   if (z80bin_load_file(image, file_type, &exec_addr, &start_addr, &end_addr ) == INIT_FAIL)
966      return INIT_FAIL;
967
968   if ((exec_addr != 0xffff) && (sw))
969      cpunum_set_reg(0, REG_PC, exec_addr);
970
971   return INIT_PASS;
972}
973
974958static DEVICE_IMAGE_LOAD( super80_cart )
975959{
976960/*   int size = mame_fsize(fp);
src/mess/drivers/exidy.c
r2442r2443
9696#include "sound/speaker.h"
9797
9898
99static QUICKLOAD_LOAD( exidy );
99static Z80BIN_EXECUTE( exidy );
100100
101101static DEVICE_IMAGE_LOAD( exidy_floppy )
102102{
r2442r2443
755755   MDRV_DEVICE_ADD("printer", PRINTER)
756756
757757   /* quickload */
758   MDRV_QUICKLOAD_ADD(exidy, "bin", 0)
758   MDRV_Z80BIN_QUICKLOAD_ADD(exidy, 0)
759759MACHINE_DRIVER_END
760760
761761static MACHINE_DRIVER_START( exidyd )
r2442r2443
804804   ROM_LOAD_OPTIONAL("bruce.dat",   0x0000, 0x0020, CRC(fae922cb) SHA1(470a86844cfeab0d9282242e03ff1d8a1b2238d1)) /* video prom */
805805ROM_END
806806
807static QUICKLOAD_LOAD( exidy )
807static Z80BIN_EXECUTE( exidy )
808808{
809   UINT8 sw = input_port_read(image->machine, "CONFIG") & 1;         /* reading the dipswitch: 1 = autorun */
810   UINT16 exec_addr, start_addr, end_addr;
809   if ((execute_address >= 0xc000) && (execute_address <= 0xdfff) && (program_read_byte(0xdffa) != 0xc3))
810      return;               /* can't run a program if the cartridge isn't in */
811811
812   if (z80bin_load_file(image, file_type, &exec_addr, &start_addr, &end_addr ) == INIT_FAIL)
813      return INIT_FAIL;
814
815   if (exec_addr == 0xffff) return INIT_PASS;         /* data file */
816
817   if ((exec_addr >= 0xc000) && (exec_addr <= 0xdfff) && (program_read_byte(0xdffa) != 0xc3))
818      return INIT_PASS;               /* can't run a program if the cartridge isn't in */
819
820812   /* Since Exidy Basic is by Microsoft, it needs some preprocessing before it can be run.
821813   1. A start address of 01D5 indicates a basic program which needs its pointers fixed up.
822814   2. If autorunning, jump to C689 (command processor), else jump to C3DD (READY prompt).
r2442r2443
825817      C858 = an autorun basic program will have this exec address on the tape
826818      C3DD = part of basic that displays READY and lets user enter input */
827819
828   if ((start_addr == 0x1d5) || (exec_addr == 0xc858))
820   if ((start_address == 0x1d5) || (execute_address == 0xc858))
829821   {
830822      UINT8 i, data[]={
831823         0xcd, 0x26, 0xc4,   // CALL C426   ;set up other pointers
r2442r2443
833825         0x36, 0,      // LD (HL),00   ;make sure dummy end-of-line is there
834826         0xc3, 0x89, 0xc6,};   // JP C689   ;run program
835827
836      for (i = 0; i < 11; i++) program_write_byte(0xf01f + i, data[i]);
837      if (!sw) program_write_word_16le(0xf028,0xc3dd);
838      program_write_byte(0x1b7, end_addr&0xff);      /* Tell BASIC where program ends */
839      program_write_byte(0x1b8, end_addr>>8);
840      if ((exec_addr != 0xc858) && (sw)) program_write_word_16le(0xf028,exec_addr);
828      for (i = 0; i < ARRAY_LENGTH(data); i++)
829         program_write_byte(0xf01f + i, data[i]);
830
831      if (!autorun)
832         program_write_word_16le(0xf028,0xc3dd);
833
834      /* tell BASIC where program ends */
835      program_write_byte(0x1b7, (end_address >> 0) & 0xff);
836      program_write_byte(0x1b8, (end_address >> 8) & 0xff);
837
838      if ((execute_address != 0xc858) && autorun)
839         program_write_word_16le(0xf028, execute_address);
840
841841      cpunum_set_reg(0, REG_PC, 0xf01f);
842842   }
843843   else
844   if (sw) cpunum_set_reg(0, REG_PC, exec_addr);
845
846   return INIT_PASS;
844   {
845      if (autorun)
846         cpunum_set_reg(0, REG_PC, execute_address);
847   }
847848}
848849
849850static void exidy_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
src/mess/drivers/vtech1.c
r2442r2443
115115#include "formats/vt_cas.h"
116116
117117
118static QUICKLOAD_LOAD(vtech1);
118static Z80BIN_EXECUTE(vtech1);
119119
120120/******************************************************************************
121121 Address Maps
r2442r2443
332332
333333   /* snapshot/quickload */
334334   MDRV_SNAPSHOT_ADD(vtech1, "vz", 0.5)
335   MDRV_QUICKLOAD_ADD(vtech1, "bin", 0)
335   MDRV_Z80BIN_QUICKLOAD_ADD(vtech1, 0)
336336MACHINE_DRIVER_END
337337
338338static MACHINE_DRIVER_START(laser200)
r2442r2443
412412 System Config
413413******************************************************************************/
414414
415static QUICKLOAD_LOAD( vtech1 )
415static Z80BIN_EXECUTE( vtech1 )
416416{
417   UINT8 sw = input_port_read(image->machine, "CONFIG") & 1;         /* reading the dipswitch: 1 = autorun */
418   UINT16 exec_addr, start_addr, end_addr;
419
420   if (z80bin_load_file(image, file_type, &exec_addr, &start_addr, &end_addr ) == INIT_FAIL)
421      return INIT_FAIL;
422
423417   /* A Microsoft Basic program needs some manipulation before it can be run.
424418   1. A start address of 7ae9 indicates a basic program which needs its pointers fixed up.
425419   2. If autorun is turned off, the pointers still need fixing, but then display READY.
r2442r2443
428422      7ae9 = start (load) address of a conventional basic program
429423      791e = custom routine to fix basic pointers */
430424
431   program_write_word_16le(0x791c,end_addr+1);
432   program_write_word_16le(0x781e,exec_addr);
425   program_write_word_16le(0x791c, end_address + 1);
426   program_write_word_16le(0x781e, execute_address);
433427
434   if (start_addr == 0x7ae9)
428   if (start_address == 0x7ae9)
435429   {
436      UINT8 i, data[17]={
430      UINT8 i, data[]={
437431         0xe5,         // PUSH HL   ;save pcode pointer
438432         0x2a, 0x1c, 0x79,   // LD HL,(791C)   ;get saved end_addr+1
439433         0x22, 0xf9, 0x78,   // LD (78F9),HL   ;move it to correct place
r2442r2443
442436         0xcb, 0x9e,      // RES 3,(HL)   ;turn off verify (just in case)
443437         0xc3, 0xcf, 0x36,};   // JP 36CF   ;enter bios at autorun point
444438
445      for (i = 0; i < 17; i++) program_write_byte(0x791e + i, data[i]);
446      if (!sw) program_write_byte(0x7929, 0xb6);   /* turn off autorun */
439      for (i = 0; i < ARRAY_LENGTH(data); i++)
440         program_write_byte(0x791e + i, data[i]);
441
442      if (!autorun)
443         program_write_byte(0x7929, 0xb6);   /* turn off autorun */
444
447445      cpunum_set_reg(0, REG_PC, 0x791e);
448446   }
449447   else
450   if ((exec_addr != 0xffff) && (sw)) cpunum_set_reg(0, REG_PC, exec_addr);
451
452   return INIT_PASS;
448   {
449      if (autorun)
450         cpunum_set_reg(0, REG_PC, execute_address);
451   }
453452}
454453
455454static void vtech1_cassette_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info)
docs/messnew.txt
r2442r2443
8787- Major changes to transition MESS's device system onto MAME's device system.
8888  [Nate Woods]
8989 
90- Converted printers to the new device system.  [Nate Woods]
90- Converted printers, snapshots and quickloads to the new device system.
91  [Nate Woods]
9192
9293- Fixed memory bug in the hash file parsing code that could cause problems in
9394  debug builds.  [Nate Woods]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team