| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "diskimage.h" |
| 6 |
|
| |
| 7 |
|
| #define DIRECTORY_FILENAME_LENGTH 16 |
| 8 |
|
| #define DISKDRIVE_STATUS_LENGTH 80 |
| 9 |
|
| |
| 10 |
|
| MODULE = D64::Disk::Image PACKAGE = D64::Disk::Image |
| 11 |
|
| PROTOTYPES: ENABLE |
| 12 |
|
| |
| 13 |
|
| # my $diskImage = di_load_image($name); |
| 14 |
|
| |
| 15 |
|
| DiskImage* |
| 16 |
|
| di_load_image(name) |
| 17 |
|
| char *name |
| 18 |
|
| CODE: |
| 19 |
1 |
| RETVAL = di_load_image(name); |
| 20 |
|
| OUTPUT: |
| 21 |
|
| RETVAL |
| 22 |
|
| |
| 23 |
|
| # my $diskImage = di_create_image($name, $size); |
| 24 |
|
| |
| 25 |
|
| DiskImage* |
| 26 |
|
| di_create_image(name, size); |
| 27 |
|
| char *name |
| 28 |
|
| int size |
| 29 |
|
| CODE: |
| 30 |
28 |
| RETVAL = di_create_image(name, size); |
| 31 |
|
| OUTPUT: |
| 32 |
|
| RETVAL |
| 33 |
|
| |
| 34 |
|
| # di_free_image($diskImage); |
| 35 |
|
| |
| 36 |
|
| void |
| 37 |
|
| di_free_image(di) |
| 38 |
|
| DiskImage *di |
| 39 |
|
| CODE: |
| 40 |
29 |
| di_free_image(di); |
| 41 |
|
| |
| 42 |
|
| # di_sync($diskImage); |
| 43 |
|
| |
| 44 |
|
| void |
| 45 |
|
| di_sync(di) |
| 46 |
|
| DiskImage *di |
| 47 |
|
| CODE: |
| 48 |
1 |
| di_sync(di); |
| 49 |
|
| |
| 50 |
|
| # my ($numstatus, $status) = di_status($diskImage); |
| 51 |
|
| |
| 52 |
|
| void |
| 53 |
|
| di_status(di) |
| 54 |
|
| DiskImage *di |
| 55 |
|
| PREINIT: |
| 56 |
|
| char *status; |
| 57 |
|
| int numstatus, statuslen; |
| 58 |
|
| PPCODE: |
| 59 |
3 |
| New(1, status, DISKDRIVE_STATUS_LENGTH + 1, char); |
| 60 |
3 |
▶ | if (status) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (status) { |
3 |
0 |
3 |
|
| 61 |
3 |
| memset(status, '\0', DISKDRIVE_STATUS_LENGTH + 1); |
| 62 |
3 |
| numstatus = di_status(di, status); |
| 63 |
3 |
| statuslen = strlen(status); |
| 64 |
3 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
3 |
3 |
|
| 65 |
3 |
| PUSHs(sv_2mortal(newSViv(numstatus))); |
| 66 |
3 |
| PUSHs(sv_2mortal(newSVpv(status, statuslen))); |
| 67 |
|
| } |
| 68 |
3 |
| Safefree(status); |
| 69 |
|
| |
| 70 |
|
| # my $numstatus = di_format($diskImage, $rawname, $rawid); |
| 71 |
|
| |
| 72 |
|
| int |
| 73 |
|
| di_format(di, rawname, rawid) |
| 74 |
|
| DiskImage *di |
| 75 |
|
| unsigned char *rawname |
| 76 |
|
| unsigned char *rawid |
| 77 |
|
| CODE: |
| 78 |
23 |
| RETVAL = di_format(di, rawname, rawid); |
| 79 |
|
| OUTPUT: |
| 80 |
|
| RETVAL |
| 81 |
|
| |
| 82 |
|
| # my $status = di_delete($diskImage, $rawPattern, $fileType); |
| 83 |
|
| |
| 84 |
|
| int |
| 85 |
|
| di_delete(di, rawpattern, type) |
| 86 |
|
| DiskImage *di |
| 87 |
|
| unsigned char *rawpattern |
| 88 |
|
| FileType type |
| 89 |
|
| CODE: |
| 90 |
1 |
| RETVAL = di_delete(di, rawpattern, type); |
| 91 |
|
| OUTPUT: |
| 92 |
|
| RETVAL |
| 93 |
|
| |
| 94 |
|
| # my $status = di_rename($diskImage, $oldRawName, $newRawName, $fileType); |
| 95 |
|
| |
| 96 |
|
| int |
| 97 |
|
| di_rename(di, oldrawname, newrawname, type) |
| 98 |
|
| DiskImage *di |
| 99 |
|
| unsigned char *oldrawname |
| 100 |
|
| unsigned char *newrawname |
| 101 |
|
| FileType type |
| 102 |
|
| CODE: |
| 103 |
2 |
| RETVAL = di_rename(di, oldrawname, newrawname, type); |
| 104 |
|
| OUTPUT: |
| 105 |
|
| RETVAL |
| 106 |
|
| |
| 107 |
|
| # my $sectors = di_sectors_per_track($imageType, $track); |
| 108 |
|
| |
| 109 |
|
| int |
| 110 |
|
| di_sectors_per_track(type, track) |
| 111 |
|
| ImageType type |
| 112 |
|
| int track |
| 113 |
|
| CODE: |
| 114 |
6 |
| RETVAL = di_sectors_per_track(type, track); |
| 115 |
|
| OUTPUT: |
| 116 |
|
| RETVAL |
| 117 |
|
| |
| 118 |
|
| # my $tracks = di_tracks($imageType); |
| 119 |
|
| |
| 120 |
|
| int |
| 121 |
|
| di_tracks(type) |
| 122 |
|
| ImageType type |
| 123 |
|
| CODE: |
| 124 |
3 |
| RETVAL = di_tracks(type); |
| 125 |
|
| OUTPUT: |
| 126 |
|
| RETVAL |
| 127 |
|
| |
| 128 |
|
| # my ($title, $id) = di_title($diskImage); |
| 129 |
|
| |
| 130 |
|
| void |
| 131 |
|
| di_title(di) |
| 132 |
|
| DiskImage *di |
| 133 |
|
| PREINIT: |
| 134 |
|
| unsigned char *title; |
| 135 |
|
| unsigned char *id; |
| 136 |
|
| PPCODE: |
| 137 |
2 |
| title = di_title(di); |
| 138 |
2 |
| id = title + 18; |
| 139 |
2 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
2 |
2 |
|
| 140 |
2 |
| PUSHs(sv_2mortal(newSVpv((const char *)title, 16))); |
| 141 |
2 |
| PUSHs(sv_2mortal(newSVpv((const char *)id, 5))); |
| 142 |
|
| |
| 143 |
|
| # my $track_blocks_free = di_track_blocks_free($diskImage, $track); |
| 144 |
|
| |
| 145 |
|
| int |
| 146 |
|
| di_track_blocks_free(di, track) |
| 147 |
|
| DiskImage *di |
| 148 |
|
| int track |
| 149 |
|
| CODE: |
| 150 |
3 |
| RETVAL = di_track_blocks_free(di, track); |
| 151 |
|
| OUTPUT: |
| 152 |
|
| RETVAL |
| 153 |
|
| |
| 154 |
|
| # my $is_ts_free = di_is_ts_free($diskImage, $track, $sector); |
| 155 |
|
| |
| 156 |
|
| int |
| 157 |
|
| di_is_ts_free(di, track, sector) |
| 158 |
|
| DiskImage *di |
| 159 |
|
| int track |
| 160 |
|
| int sector |
| 161 |
|
| CODE: |
| 162 |
|
| TrackSector ts; |
| 163 |
3 |
| ts.track = (unsigned char)track; |
| 164 |
3 |
| ts.sector = (unsigned char)sector; |
| 165 |
3 |
| RETVAL = di_is_ts_free(di, ts); |
| 166 |
|
| OUTPUT: |
| 167 |
|
| RETVAL |
| 168 |
|
| |
| 169 |
|
| # di_alloc_ts($diskImage, $track, $sector); |
| 170 |
|
| |
| 171 |
|
| void |
| 172 |
|
| di_alloc_ts(di, track, sector) |
| 173 |
|
| DiskImage *di |
| 174 |
|
| int track |
| 175 |
|
| int sector |
| 176 |
|
| CODE: |
| 177 |
|
| TrackSector ts; |
| 178 |
4 |
| ts.track = (unsigned char)track; |
| 179 |
4 |
| ts.sector = (unsigned char)sector; |
| 180 |
4 |
| di_alloc_ts(di, ts); |
| 181 |
|
| |
| 182 |
|
| # di_free_ts($diskImage, $track, $sector); |
| 183 |
|
| |
| 184 |
|
| void |
| 185 |
|
| di_free_ts(di, track, sector) |
| 186 |
|
| DiskImage *di |
| 187 |
|
| int track |
| 188 |
|
| int sector |
| 189 |
|
| CODE: |
| 190 |
|
| TrackSector ts; |
| 191 |
2 |
| ts.track = (unsigned char)track; |
| 192 |
2 |
| ts.sector = (unsigned char)sector; |
| 193 |
2 |
| di_free_ts(di, ts); |
| 194 |
|
| |
| 195 |
|
| # my $rawname = di_rawname_from_name($name); |
| 196 |
|
| |
| 197 |
|
| void |
| 198 |
|
| di_rawname_from_name(name) |
| 199 |
|
| char *name |
| 200 |
|
| PREINIT: |
| 201 |
|
| unsigned char *rawname; |
| 202 |
|
| PPCODE: |
| 203 |
57 |
| New(1, rawname, DIRECTORY_FILENAME_LENGTH + 1, unsigned char); |
| 204 |
57 |
▶ | if (rawname) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rawname) { |
57 |
0 |
57 |
|
| 205 |
57 |
| di_rawname_from_name(rawname, name); |
| 206 |
57 |
| rawname[DIRECTORY_FILENAME_LENGTH] = '\0'; |
| 207 |
57 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
57 |
57 |
|
| 208 |
57 |
| PUSHs(sv_2mortal(newSVpv((const char *)rawname, DIRECTORY_FILENAME_LENGTH))); |
| 209 |
|
| } |
| 210 |
57 |
| Safefree(rawname); |
| 211 |
|
| |
| 212 |
|
| # my $name = di_name_from_rawname($rawname); |
| 213 |
|
| |
| 214 |
|
| void |
| 215 |
|
| di_name_from_rawname(rawname) |
| 216 |
|
| unsigned char *rawname |
| 217 |
|
| PREINIT: |
| 218 |
|
| int namelen; |
| 219 |
|
| char *name; |
| 220 |
|
| PPCODE: |
| 221 |
25 |
| New(1, name, DIRECTORY_FILENAME_LENGTH + 1, char); |
| 222 |
25 |
▶ | if (name) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (name) { |
25 |
0 |
25 |
|
| 223 |
25 |
| namelen = di_name_from_rawname(name, rawname); |
| 224 |
25 |
| name[namelen] = '\0'; |
| 225 |
25 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
25 |
25 |
|
| 226 |
25 |
| PUSHs(sv_2mortal(newSVpv(name, namelen))); |
| 227 |
|
| } |
| 228 |
25 |
| Safefree(name); |
| 229 |
|
| |
| 230 |
|
| # my $blocksfree = _di_blocksfree($diskImage); |
| 231 |
|
| |
| 232 |
|
| int |
| 233 |
|
| _di_blocksfree(di) |
| 234 |
|
| DiskImage *di |
| 235 |
|
| CODE: |
| 236 |
0 |
▶ | RETVAL = di->blocksfree; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = di->blocksfree; |
0 |
0 |
0 |
|
| 237 |
|
| OUTPUT: |
| 238 |
|
| RETVAL |
| 239 |
|
| |
| 240 |
|
| # my $imageType = _di_type($diskImage); |
| 241 |
|
| |
| 242 |
|
| ImageType |
| 243 |
|
| _di_type(di) |
| 244 |
|
| DiskImage *di |
| 245 |
|
| CODE: |
| 246 |
0 |
▶ | RETVAL = di->type; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = di->type; |
0 |
0 |
0 |
|
| 247 |
|
| OUTPUT: |
| 248 |
|
| RETVAL |
| 249 |
|
| |
| 250 |
|
| MODULE = D64::Disk::Image PACKAGE = D64::Disk::Image::File |
| 251 |
|
| PROTOTYPES: ENABLE |
| 252 |
|
| |
| 253 |
|
| # my $imageFile = di_open($diskImage, $rawname, $fileType, $mode); |
| 254 |
|
| |
| 255 |
|
| ImageFile* |
| 256 |
|
| di_open(di, rawname, type, mode) |
| 257 |
|
| DiskImage *di |
| 258 |
|
| unsigned char *rawname |
| 259 |
|
| FileType type |
| 260 |
|
| char *mode |
| 261 |
|
| CODE: |
| 262 |
20 |
| RETVAL = di_open(di, rawname, type, mode); |
| 263 |
20 |
▶ | if (RETVAL == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == NULL) |
3 |
17 |
20 |
|
| 264 |
3 |
| XSRETURN_UNDEF; |
| 265 |
|
| OUTPUT: |
| 266 |
|
| RETVAL |
| 267 |
|
| |
| 268 |
|
| # di_close($imageFile); |
| 269 |
|
| |
| 270 |
|
| void |
| 271 |
|
| di_close(imgfile) |
| 272 |
|
| ImageFile *imgfile |
| 273 |
|
| CODE: |
| 274 |
16 |
| di_close(imgfile); |
| 275 |
|
| |
| 276 |
|
| # my ($counter, $buffer) = di_read($imageFile, $maxlength); |
| 277 |
|
| |
| 278 |
|
| void |
| 279 |
|
| di_read(imgfile, len); |
| 280 |
|
| ImageFile *imgfile |
| 281 |
|
| int len |
| 282 |
|
| PREINIT: |
| 283 |
|
| unsigned char *buffer; |
| 284 |
|
| int counter; |
| 285 |
|
| PPCODE: |
| 286 |
3 |
| New(1, buffer, len + 1, unsigned char); |
| 287 |
3 |
▶ | if (buffer) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffer) { |
3 |
0 |
3 |
|
| 288 |
3 |
| memset(buffer, '\0', len + 1); |
| 289 |
3 |
| counter = di_read(imgfile, buffer, len); |
| 290 |
3 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
3 |
3 |
|
| 291 |
3 |
| PUSHs(sv_2mortal(newSViv(counter))); |
| 292 |
3 |
| PUSHs(sv_2mortal(newSVpv((const char *)buffer, counter))); |
| 293 |
|
| } |
| 294 |
3 |
| Safefree(buffer); |
| 295 |
|
| |
| 296 |
|
| # my $counter = di_write($imageFile, $buffer, $length); |
| 297 |
|
| |
| 298 |
|
| int |
| 299 |
|
| di_write(imgfile, buffer, len); |
| 300 |
|
| ImageFile *imgfile |
| 301 |
|
| unsigned char *buffer |
| 302 |
|
| int len |
| 303 |
|
| CODE: |
| 304 |
12 |
| RETVAL = di_write(imgfile, buffer, len); |
| 305 |
|
| OUTPUT: |
| 306 |
|
| RETVAL |