~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/lib/util/harddisk.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Emmanuel Kasper, Jordi Mallach
  • Date: 2012-06-05 20:02:23 UTC
  • mfrom: (0.3.1) (0.1.4)
  • Revision ID: package-import@ubuntu.com-20120605200223-gnlpogjrg6oqe9md
Tags: 0.146-1
[ Emmanuel Kasper ]
* New upstream release
* Drop patch to fix man pages section and patches to link with flac 
  and jpeg system lib: all this has been pushed upstream by Cesare Falco
* Add DM-Upload-Allowed: yes field.

[ Jordi Mallach ]
* Create a "gnu" TARGETOS stanza that defines NO_AFFINITY_NP.
* Stop setting TARGETOS to "unix" in d/rules. It should be autodetected,
  and set to the appropriate value.
* mame_manpage_section.patch: Change mame's manpage section to 6 (games),
  in the TH declaration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    TYPE DEFINITIONS
47
47
***************************************************************************/
48
48
 
49
 
struct _hard_disk_file
 
49
struct hard_disk_file
50
50
{
51
51
        chd_file *                      chd;                            /* CHD file */
52
52
        hard_disk_info          info;                           /* hard disk info */
53
 
        UINT32                          hunksectors;            /* sectors per hunk */
54
 
        UINT32                          cachehunk;                      /* which hunk is cached */
55
 
        UINT8 *                         cache;                          /* cache of the current hunk */
56
53
};
57
54
 
58
55
 
70
67
{
71
68
        int cylinders, heads, sectors, sectorbytes;
72
69
        hard_disk_file *file;
73
 
        char metadata[256];
 
70
        astring metadata;
74
71
        chd_error err;
75
72
 
76
73
        /* punt if no CHD */
78
75
                return NULL;
79
76
 
80
77
        /* read the hard disk metadata */
81
 
        err = chd_get_metadata(chd, HARD_DISK_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL);
 
78
        err = chd->read_metadata(HARD_DISK_METADATA_TAG, 0, metadata);
82
79
        if (err != CHDERR_NONE)
83
80
                return NULL;
84
81
 
97
94
        file->info.heads = heads;
98
95
        file->info.sectors = sectors;
99
96
        file->info.sectorbytes = sectorbytes;
100
 
        file->hunksectors = chd_get_header(chd)->hunkbytes / file->info.sectorbytes;
101
 
        file->cachehunk = -1;
102
 
 
103
 
        /* allocate a cache */
104
 
        file->cache = (UINT8 *)malloc(chd_get_header(chd)->hunkbytes);
105
 
        if (file->cache == NULL)
106
 
        {
107
 
                free(file);
108
 
                return NULL;
109
 
        }
110
 
 
111
97
        return file;
112
98
}
113
99
 
118
104
 
119
105
void hard_disk_close(hard_disk_file *file)
120
106
{
121
 
        /* free the cache */
122
 
        if (file->cache != NULL)
123
 
                free(file->cache);
124
107
        free(file);
125
108
}
126
109
 
154
137
 
155
138
UINT32 hard_disk_read(hard_disk_file *file, UINT32 lbasector, void *buffer)
156
139
{
157
 
        UINT32 hunknum = lbasector / file->hunksectors;
158
 
        UINT32 sectoroffs = lbasector % file->hunksectors;
159
 
 
160
 
        /* if we haven't cached this hunk, read it now */
161
 
        if (file->cachehunk != hunknum)
162
 
        {
163
 
                chd_error err = chd_read(file->chd, hunknum, file->cache);
164
 
                if (err != CHDERR_NONE)
165
 
                        return 0;
166
 
                file->cachehunk = hunknum;
167
 
        }
168
 
 
169
 
        /* copy out the requested sector */
170
 
        memcpy(buffer, &file->cache[sectoroffs * file->info.sectorbytes], file->info.sectorbytes);
171
 
        return 1;
 
140
        chd_error err = file->chd->read_units(lbasector, buffer);
 
141
        return (err == CHDERR_NONE);
172
142
}
173
143
 
174
144
 
179
149
 
180
150
UINT32 hard_disk_write(hard_disk_file *file, UINT32 lbasector, const void *buffer)
181
151
{
182
 
        UINT32 hunknum = lbasector / file->hunksectors;
183
 
        UINT32 sectoroffs = lbasector % file->hunksectors;
184
 
        chd_error err;
185
 
 
186
 
        /* if we haven't cached this hunk, read it now */
187
 
        if (file->cachehunk != hunknum)
188
 
        {
189
 
                err = chd_read(file->chd, hunknum, file->cache);
190
 
                if (err != CHDERR_NONE)
191
 
                        return 0;
192
 
                file->cachehunk = hunknum;
193
 
        }
194
 
 
195
 
        /* copy in the requested data */
196
 
        memcpy(&file->cache[sectoroffs * file->info.sectorbytes], buffer, file->info.sectorbytes);
197
 
 
198
 
        /* write it back out */
199
 
        err = chd_write(file->chd, hunknum, file->cache);
200
 
        return (err == CHDERR_NONE) ? 1 : 0;
 
152
        chd_error err = file->chd->write_units(lbasector, buffer);
 
153
        return (err == CHDERR_NONE);
201
154
}