Previous 15994 Revisions Next

r1880 Monday 10th March, 2008 at 01:34:26 UTC by Robbbert
[Z80BIN] Fixed some bugs.
[src/mess/devices]z80bin.c z80bin.h

src/mess/devices/z80bin.c
r1879r1880
55   A binary quickload format used by the Microbee, the Exidy Sorcerer
66   VZ200/300 and the Super 80
77
8   NOTE: INIT_FAIL == 1, INIT_PASS == 0, EOF == 0xffffffff
9
10   The return_code consists of start_addr | end_addr | exec_addr | status.
11   Status: 0 = good data, 1 = corrupted quickload file.
12
813*********************************************************************/
914
1015#include "driver.h"
16#include "ui.h"
1117#include "z80bin.h"
1218#include "snapquik.h"
1319
14
15static QUICKLOAD_LOAD( z80bin )
20UINT64 z80bin_load_file( mess_image *image, const char *file_type )
1621{
1722   int ch;
1823   UINT16 args[3];
19   UINT16 start_addr, end_addr, exec_addr, i;
24   UINT16 i=0, j, size;
25   UINT64 start_addr, exec_addr, end_addr;   /* need to be this size for return at end */
2026   UINT8 data;
27   char * pgmname;
28   pgmname = (char *) malloc(256);
2129
2230   image_fseek(image, 7, SEEK_SET);
2331
2432   while((ch = image_fgetc(image)) != 0x1A)
2533   {
2634      if (ch == EOF)
35      {
36         ui_popup_time(10,"QUICKLOAD: Unexpected EOF while getting file name");   /* 10 seconds */
37         free(pgmname);
2738         return INIT_FAIL;
39      }
40
41      if (ch)
42      {
43         pgmname[i] = ch;   /* build program name */
44         i++;
45      }
2846   }
2947
48   pgmname[i]=0;   /* terminate string with a null */
49
3050   if (image_fread(image, args, sizeof(args)) != sizeof(args))
51   {
52      ui_popup_time(10,"QUICKLOAD: %s\nUnexpected EOF while getting file size",pgmname);
53      free(pgmname);
3154      return INIT_FAIL;
55   }
3256
3357   exec_addr   = LITTLE_ENDIANIZE_INT16(args[0]);
3458   start_addr   = LITTLE_ENDIANIZE_INT16(args[1]);
3559   end_addr   = LITTLE_ENDIANIZE_INT16(args[2]);
3660
37   for (i = start_addr; i <= end_addr; i++)
61   size = (end_addr - start_addr + 1) & 0xffff;
62
63   popmessage("%s\nsize=%04X : start=%04X : end=%04X : exec=%04X",pgmname,size,(int)start_addr,(int)end_addr,(int)exec_addr);
64
65   for (i = 0; i < size; i++)
3866   {
67      j = (start_addr + i) & 0xffff;
3968      if (image_fread(image, &data, 1) != 1)
69      {
70         ui_popup_time(10,"QUICKLOAD: %s\nUnexpected EOF while writing byte to %04X",pgmname,j);
71         free(pgmname);
4072         return INIT_FAIL;
41      program_write_byte(i, data);
73      }
74      program_write_byte(j, data);
4275   }
43   cpunum_set_reg(0, REG_PC, exec_addr);
76
77   free(pgmname);
78
79   return (start_addr << 48) | (end_addr << 32) | (exec_addr << 16);
80}
81
82static QUICKLOAD_LOAD( z80bin )
83{
84   UINT16 exec_addr;
85   UINT64 return_info = z80bin_load_file( image, file_type );   /* load file */
86   if (return_info == INIT_FAIL) return INIT_FAIL;         /* failure */
87   exec_addr = (return_info & 0xffff0000) >> 16;         /* get program run address */
88   if (exec_addr == 0xffff) return INIT_PASS;         /* non-executable data file */
89   cpunum_set_reg(0, REG_PC, exec_addr);            /* start program */
4490   return INIT_PASS;
4591}
4692
r1879r1880
58104      /* --- the following bits of info are returned as pointers to data or functions --- */
59105      case MESS_DEVINFO_PTR_QUICKLOAD_LOAD:            info->f = (genf *) quickload_load_z80bin; break;
60106
61      default:                              quickload_device_getinfo(devclass, state, info); break;
107      default:                     quickload_device_getinfo(devclass, state, info); break;
62108   }
63109}
64110
src/mess/devices/z80bin.h
r1879r1880
1616
1717void z80bin_quickload_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info);
1818
19UINT64 z80bin_load_file( mess_image *image, const char *file_type );
1920
21
2022#endif /* Z80BIN_H */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team