src/mess/devices/cassette.c
| r2166 | r2167 | |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | |
| 37 | | static struct mess_cassetteimg *get_cassimg(mess_image *image) |
| 37 | static struct mess_cassetteimg *get_cassimg(const device_config *image) |
| 38 | 38 | { |
| 39 | 39 | return image_lookuptag(image, CASSETTE_TAG); |
| 40 | 40 | } |
| r2166 | r2167 | |
| 53 | 53 | cassette IO |
| 54 | 54 | *********************************************************************/ |
| 55 | 55 | |
| 56 | | static int cassette_is_motor_on(mess_image *cassette) |
| 56 | static int cassette_is_motor_on(const device_config *cassette) |
| 57 | 57 | { |
| 58 | 58 | cassette_state state; |
| 59 | 59 | state = cassette_get_state(cassette); |
| r2166 | r2167 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
| 69 | | static void cassette_update(mess_image *cassette) |
| 69 | static void cassette_update(const device_config *cassette) |
| 70 | 70 | { |
| 71 | 71 | struct mess_cassetteimg *tag; |
| 72 | 72 | double cur_time; |
| r2166 | r2167 | |
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | |
| 98 | | cassette_state cassette_get_state(mess_image *cassette) |
| 98 | cassette_state cassette_get_state(const device_config *cassette) |
| 99 | 99 | { |
| 100 | 100 | return get_cassimg(cassette)->state; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | |
| 105 | | void cassette_change_state(mess_image *cassette, cassette_state state, cassette_state mask) |
| 105 | void cassette_change_state(const device_config *cassette, cassette_state state, cassette_state mask) |
| 106 | 106 | { |
| 107 | 107 | struct mess_cassetteimg *tag; |
| 108 | 108 | cassette_state new_state; |
| r2166 | r2167 | |
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | |
| 124 | | void cassette_set_state(mess_image *cassette, cassette_state state) |
| 124 | void cassette_set_state(const device_config *cassette, cassette_state state) |
| 125 | 125 | { |
| 126 | 126 | cassette_change_state(cassette, state, ~0); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
| 130 | 130 | |
| 131 | | double cassette_input(mess_image *cassette) |
| 131 | double cassette_input(const device_config *cassette) |
| 132 | 132 | { |
| 133 | 133 | INT32 sample; |
| 134 | 134 | double double_value; |
| r2166 | r2167 | |
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | |
| 149 | | void cassette_output(mess_image *cassette, double value) |
| 149 | void cassette_output(const device_config *cassette, double value) |
| 150 | 150 | { |
| 151 | 151 | struct mess_cassetteimg *tag; |
| 152 | 152 | tag = get_cassimg(cassette); |
| r2166 | r2167 | |
| 163 | 163 | |
| 164 | 164 | |
| 165 | 165 | |
| 166 | | cassette_image *cassette_get_image(mess_image *cassette) |
| 166 | cassette_image *cassette_get_image(const device_config *cassette) |
| 167 | 167 | { |
| 168 | 168 | struct mess_cassetteimg *tag; |
| 169 | 169 | tag = get_cassimg(cassette); |
| r2166 | r2167 | |
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | |
| 175 | | double cassette_get_position(mess_image *cassette) |
| 175 | double cassette_get_position(const device_config *cassette) |
| 176 | 176 | { |
| 177 | 177 | double position; |
| 178 | 178 | struct mess_cassetteimg *tag; |
| r2166 | r2167 | |
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | |
| 190 | | double cassette_get_length(mess_image *cassette) |
| 190 | double cassette_get_length(const device_config *cassette) |
| 191 | 191 | { |
| 192 | 192 | struct mess_cassetteimg *tag; |
| 193 | 193 | struct CassetteInfo info; |
| r2166 | r2167 | |
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | |
| 202 | | void cassette_seek(mess_image *cassette, double time, int origin) |
| 202 | void cassette_seek(const device_config *cassette, double time, int origin) |
| 203 | 203 | { |
| 204 | 204 | struct mess_cassetteimg *tag; |
| 205 | 205 | |
| r2166 | r2167 | |
| 328 | 328 | /* |
| 329 | 329 | display a small tape icon, with the current position in the tape image |
| 330 | 330 | */ |
| 331 | | static void device_display_cassette(mess_image *image) |
| 331 | static void device_display_cassette(const device_config *image) |
| 332 | 332 | { |
| 333 | 333 | char buf[65]; |
| 334 | 334 | float x, y; |
src/mess/devices/flopdrv.c
| r2166 | r2167 | |
| 23 | 23 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 24 | 24 | #define FLOPDRVTAG "flopdrv" |
| 25 | 25 | |
| 26 | | static struct floppy_drive *get_drive(mess_image *img) |
| 26 | static struct floppy_drive *get_drive(const device_config *img) |
| 27 | 27 | { |
| 28 | 28 | return image_lookuptag(img, FLOPDRVTAG); |
| 29 | 29 | } |
| r2166 | r2167 | |
| 31 | 31 | static TIMER_CALLBACK(floppy_drive_index_callback); |
| 32 | 32 | |
| 33 | 33 | /* this is called on device init */ |
| 34 | | int floppy_drive_init(mess_image *img, const floppy_interface *iface) |
| 34 | int floppy_drive_init(const device_config *img, const floppy_interface *iface) |
| 35 | 35 | { |
| 36 | 36 | struct floppy_drive *pDrive; |
| 37 | 37 | |
| r2166 | r2167 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | /* index pulses at rpm/60 Hz, and stays high 1/20th of time */ |
| 69 | | static void floppy_drive_index_func(mess_image *img) |
| 69 | static void floppy_drive_index_func(const device_config *img) |
| 70 | 70 | { |
| 71 | 71 | struct floppy_drive *pDrive = get_drive(img); |
| 72 | 72 | |
| r2166 | r2167 | |
| 91 | 91 | |
| 92 | 92 | static TIMER_CALLBACK(floppy_drive_index_callback) |
| 93 | 93 | { |
| 94 | | mess_image *image = (mess_image *) ptr; |
| 94 | const device_config *image = (const device_config *) ptr; |
| 95 | 95 | floppy_drive_index_func(image); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /* set the callback for the index pulse */ |
| 101 | | void floppy_drive_set_index_pulse_callback(mess_image *img, void (*callback)(mess_image *image, int state)) |
| 101 | void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *image, int state)) |
| 102 | 102 | { |
| 103 | 103 | struct floppy_drive *pDrive = get_drive(img); |
| 104 | 104 | pDrive->index_pulse_callback = callback; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
| 108 | | void floppy_drive_set_ready_state_change_callback(mess_image *img, void (*callback)(mess_image *img, int state)) |
| 108 | void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *img, int state)) |
| 109 | 109 | { |
| 110 | 110 | struct floppy_drive *pDrive = get_drive(img); |
| 111 | 111 | pDrive->ready_state_change_callback = callback; |
| r2166 | r2167 | |
| 120 | 120 | 2) drive present/missing |
| 121 | 121 | */ |
| 122 | 122 | |
| 123 | | int floppy_status(mess_image *img, int new_status) |
| 123 | int floppy_status(const device_config *img, int new_status) |
| 124 | 124 | { |
| 125 | 125 | /* return current status only? */ |
| 126 | 126 | if (new_status!=-1) |
| r2166 | r2167 | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /* set interface for image interface */ |
| 141 | | void floppy_drive_set_disk_image_interface(mess_image *img, const floppy_interface *iface) |
| 141 | void floppy_drive_set_disk_image_interface(const device_config *img, const floppy_interface *iface) |
| 142 | 142 | { |
| 143 | 143 | struct floppy_drive *pDrive = get_drive(img); |
| 144 | 144 | if (iface) |
| r2166 | r2167 | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /* set flag state */ |
| 151 | | void floppy_drive_set_flag_state(mess_image *img, int flag, int state) |
| 151 | void floppy_drive_set_flag_state(const device_config *img, int flag, int state) |
| 152 | 152 | { |
| 153 | 153 | struct floppy_drive *drv = get_drive(img); |
| 154 | 154 | int prev_state; |
| r2166 | r2167 | |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | | void floppy_drive_set_motor_state(mess_image *img, int state) |
| 180 | void floppy_drive_set_motor_state(const device_config *img, int state) |
| 181 | 181 | { |
| 182 | 182 | int new_motor_state = 0; |
| 183 | 183 | int previous_state = 0; |
| r2166 | r2167 | |
| 235 | 235 | /* for pc, drive is always ready, for amstrad,pcw,spectrum it is only ready under |
| 236 | 236 | a fixed set of circumstances */ |
| 237 | 237 | /* use this to set ready state of drive */ |
| 238 | | void floppy_drive_set_ready_state(mess_image *img, int state, int flag) |
| 238 | void floppy_drive_set_ready_state(const device_config *img, int state, int flag) |
| 239 | 239 | { |
| 240 | 240 | if (flag) |
| 241 | 241 | { |
| r2166 | r2167 | |
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | /* get flag state */ |
| 273 | | int floppy_drive_get_flag_state(mess_image *img, int flag) |
| 273 | int floppy_drive_get_flag_state(const device_config *img, int flag) |
| 274 | 274 | { |
| 275 | 275 | struct floppy_drive *drv = get_drive(img); |
| 276 | 276 | int drive_flags; |
| r2166 | r2167 | |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
| 313 | | void floppy_drive_set_geometry(mess_image *img, floppy_type type) |
| 313 | void floppy_drive_set_geometry(const device_config *img, floppy_type type) |
| 314 | 314 | { |
| 315 | 315 | int max_track, num_sides; |
| 316 | 316 | |
| r2166 | r2167 | |
| 332 | 332 | floppy_drive_set_geometry_absolute(img, max_track, num_sides); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | | void floppy_drive_set_geometry_absolute(mess_image *img, int tracks, int sides) |
| 335 | void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides) |
| 336 | 336 | { |
| 337 | 337 | struct floppy_drive *pDrive = get_drive(img); |
| 338 | 338 | pDrive->max_track = tracks; |
| 339 | 339 | pDrive->num_sides = sides; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | | void floppy_drive_seek(mess_image *img, signed int signed_tracks) |
| 342 | void floppy_drive_seek(const device_config *img, signed int signed_tracks) |
| 343 | 343 | { |
| 344 | 344 | struct floppy_drive *pDrive; |
| 345 | 345 | |
| r2166 | r2167 | |
| 377 | 377 | |
| 378 | 378 | |
| 379 | 379 | /* this is not accurate. But it will do for now */ |
| 380 | | int floppy_drive_get_next_id(mess_image *img, int side, chrn_id *id) |
| 380 | int floppy_drive_get_next_id(const device_config *img, int side, chrn_id *id) |
| 381 | 381 | { |
| 382 | 382 | struct floppy_drive *pDrive; |
| 383 | 383 | int spt; |
| r2166 | r2167 | |
| 415 | 415 | return (spt == 0) ? 0 : 1; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | | int floppy_drive_get_current_track(mess_image *img) |
| 418 | int floppy_drive_get_current_track(const device_config *img) |
| 419 | 419 | { |
| 420 | 420 | struct floppy_drive *drv = get_drive(img); |
| 421 | 421 | return drv->current_track; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | | void floppy_drive_read_track_data_info_buffer(mess_image *img, int side, void *ptr, int *length ) |
| 424 | void floppy_drive_read_track_data_info_buffer(const device_config *img, int side, void *ptr, int *length ) |
| 425 | 425 | { |
| 426 | 426 | if (image_exists(img)) |
| 427 | 427 | { |
| r2166 | r2167 | |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | | void floppy_drive_write_track_data_info_buffer(mess_image *img, int side, const void *ptr, int *length ) |
| 434 | void floppy_drive_write_track_data_info_buffer(const device_config *img, int side, const void *ptr, int *length ) |
| 435 | 435 | { |
| 436 | 436 | if (image_exists(img)) |
| 437 | 437 | { |
| r2166 | r2167 | |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | | void floppy_drive_format_sector(mess_image *img, int side, int sector_index,int c,int h, int r, int n, int filler) |
| 444 | void floppy_drive_format_sector(const device_config *img, int side, int sector_index,int c,int h, int r, int n, int filler) |
| 445 | 445 | { |
| 446 | 446 | if (image_exists(img)) |
| 447 | 447 | { |
| r2166 | r2167 | |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | | void floppy_drive_read_sector_data(mess_image *img, int side, int index1, void *pBuffer, int length) |
| 454 | void floppy_drive_read_sector_data(const device_config *img, int side, int index1, void *pBuffer, int length) |
| 455 | 455 | { |
| 456 | 456 | if (image_exists(img)) |
| 457 | 457 | { |
| r2166 | r2167 | |
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | | void floppy_drive_write_sector_data(mess_image *img, int side, int index1, const void *pBuffer,int length, int ddam) |
| 464 | void floppy_drive_write_sector_data(const device_config *img, int side, int index1, const void *pBuffer,int length, int ddam) |
| 465 | 465 | { |
| 466 | 466 | if (image_exists(img)) |
| 467 | 467 | { |
| r2166 | r2167 | |
| 508 | 508 | |
| 509 | 509 | |
| 510 | 510 | |
| 511 | | void floppy_drive_set_rpm(mess_image *img, float rpm) |
| 511 | void floppy_drive_set_rpm(const device_config *img, float rpm) |
| 512 | 512 | { |
| 513 | 513 | struct floppy_drive *drv = get_drive(img); |
| 514 | 514 | drv->rpm = rpm; |
src/mess/devices/flopdrv.h
| r2166 | r2167 | |
| 23 | 23 | /* CRC error in data field */ |
| 24 | 24 | #define ID_FLAG_CRC_ERROR_IN_DATA_FIELD 0x0004 |
| 25 | 25 | |
| 26 | | int floppy_status(mess_image *img, int new_status); |
| 26 | int floppy_status(const device_config *img, int new_status); |
| 27 | 27 | |
| 28 | 28 | typedef struct chrn_id |
| 29 | 29 | { |
| r2166 | r2167 | |
| 50 | 50 | typedef struct floppy_interface |
| 51 | 51 | { |
| 52 | 52 | /* seek to physical track */ |
| 53 | | void (*seek_callback)(mess_image *img, int physical_track); |
| 53 | void (*seek_callback)(const device_config *img, int physical_track); |
| 54 | 54 | |
| 55 | 55 | /* the following are not strictly floppy drive operations, but are used by the |
| 56 | 56 | nec765 to get data from the track - really the whole track should be constructed |
| r2166 | r2167 | |
| 59 | 59 | with the data */ |
| 60 | 60 | |
| 61 | 61 | /* get number of sectors per track on side specified */ |
| 62 | | int (*get_sectors_per_track)(mess_image *image, int physical_side); |
| 62 | int (*get_sectors_per_track)(const device_config *image, int physical_side); |
| 63 | 63 | |
| 64 | 64 | /* get id from current track and specified side */ |
| 65 | | void (*get_id_callback)(mess_image *image, chrn_id *, int id_index, int physical_side); |
| 65 | void (*get_id_callback)(const device_config *image, chrn_id *, int id_index, int physical_side); |
| 66 | 66 | |
| 67 | 67 | /* read sector data into buffer, length = number of bytes to read */ |
| 68 | | void (*read_sector_data_into_buffer)(mess_image *image, int side,int data_id,char *, int length); |
| 68 | void (*read_sector_data_into_buffer)(const device_config *image, int side,int data_id,char *, int length); |
| 69 | 69 | |
| 70 | 70 | /* write sector data from buffer, length = number of bytes to read */ |
| 71 | | void (*write_sector_data_from_buffer)(mess_image *image, int side,int data_id, const char *, int length, int ddam); |
| 71 | void (*write_sector_data_from_buffer)(const device_config *image, int side,int data_id, const char *, int length, int ddam); |
| 72 | 72 | |
| 73 | 73 | /* Read track in buffer, length = number of bytes to read */ |
| 74 | | void (*read_track_data_info_buffer)(mess_image *image, int side, void *ptr, int *length ); |
| 74 | void (*read_track_data_info_buffer)(const device_config *image, int side, void *ptr, int *length ); |
| 75 | 75 | |
| 76 | 76 | /* Write track in buffer, length = number of bytes to read */ |
| 77 | | void (*write_track_data_info_buffer)(mess_image *image, int side, const void *ptr, int *length ); |
| 77 | void (*write_track_data_info_buffer)(const device_config *image, int side, const void *ptr, int *length ); |
| 78 | 78 | |
| 79 | 79 | /* format */ |
| 80 | | void (*format_sector)(mess_image *img, int side, int sector_index,int c, int h, int r, int n, int filler); |
| 80 | void (*format_sector)(const device_config *img, int side, int sector_index,int c, int h, int r, int n, int filler); |
| 81 | 81 | } floppy_interface; |
| 82 | 82 | |
| 83 | 83 | struct floppy_drive |
| r2166 | r2167 | |
| 95 | 95 | /* index pulse timer */ |
| 96 | 96 | void *index_timer; |
| 97 | 97 | /* index pulse callback */ |
| 98 | | void (*index_pulse_callback)(mess_image *image, int state); |
| 98 | void (*index_pulse_callback)(const device_config *image, int state); |
| 99 | 99 | /* rotation per minute => gives index pulse frequency */ |
| 100 | 100 | float rpm; |
| 101 | 101 | /* current index pulse value */ |
| 102 | 102 | int index; |
| 103 | 103 | |
| 104 | | void (*ready_state_change_callback)(mess_image *img, int state); |
| 104 | void (*ready_state_change_callback)(const device_config *img, int state); |
| 105 | 105 | |
| 106 | 106 | unsigned char id_buffer[4]; |
| 107 | 107 | |
| r2166 | r2167 | |
| 112 | 112 | }; |
| 113 | 113 | |
| 114 | 114 | /* a callback which will be executed if the ready state of the drive changes e.g. not ready->ready, ready->not ready */ |
| 115 | | void floppy_drive_set_ready_state_change_callback(mess_image *img, void (*callback)(mess_image *img, int state)); |
| 115 | void floppy_drive_set_ready_state_change_callback(const device_config *img, void (*callback)(const device_config *img, int state)); |
| 116 | 116 | |
| 117 | 117 | /* floppy drive types */ |
| 118 | 118 | typedef enum |
| r2166 | r2167 | |
| 121 | 121 | FLOPPY_DRIVE_DS_80 |
| 122 | 122 | } floppy_type; |
| 123 | 123 | |
| 124 | | void floppy_drive_set_index_pulse_callback(mess_image *img, void (*callback)(mess_image *image, int state)); |
| 124 | void floppy_drive_set_index_pulse_callback(const device_config *img, void (*callback)(const device_config *image, int state)); |
| 125 | 125 | |
| 126 | 126 | /* set flag state */ |
| 127 | | int floppy_drive_get_flag_state(mess_image *img, int flag); |
| 127 | int floppy_drive_get_flag_state(const device_config *img, int flag); |
| 128 | 128 | /* get flag state */ |
| 129 | | void floppy_drive_set_flag_state(mess_image *img, int flag, int state); |
| 129 | void floppy_drive_set_flag_state(const device_config *img, int flag, int state); |
| 130 | 130 | /* get current physical track drive is on */ |
| 131 | | int floppy_drive_get_current_track(mess_image *img); |
| 131 | int floppy_drive_get_current_track(const device_config *img); |
| 132 | 132 | |
| 133 | | void floppy_drive_set_geometry(mess_image *img, floppy_type type); |
| 134 | | void floppy_drive_set_geometry_absolute(mess_image *img, int tracks, int sides); |
| 133 | void floppy_drive_set_geometry(const device_config *img, floppy_type type); |
| 134 | void floppy_drive_set_geometry_absolute(const device_config *img, int tracks, int sides); |
| 135 | 135 | |
| 136 | 136 | /* called in device init/exit functions */ |
| 137 | | int floppy_drive_init(mess_image *img, const floppy_interface *iface); |
| 137 | int floppy_drive_init(const device_config *img, const floppy_interface *iface); |
| 138 | 138 | |
| 139 | 139 | /* get next id from track, 1 if got a id, 0 if no id was got */ |
| 140 | | int floppy_drive_get_next_id(mess_image *img, int side, chrn_id *); |
| 140 | int floppy_drive_get_next_id(const device_config *img, int side, chrn_id *); |
| 141 | 141 | /* set ready state of drive. If flag == 1, set ready state only if drive present, |
| 142 | 142 | disk is in drive, and motor is on. Otherwise set ready state to the state passed */ |
| 143 | | void floppy_drive_set_ready_state(mess_image *img, int state, int flag); |
| 143 | void floppy_drive_set_ready_state(const device_config *img, int state, int flag); |
| 144 | 144 | |
| 145 | | void floppy_drive_set_motor_state(mess_image *img, int state); |
| 145 | void floppy_drive_set_motor_state(const device_config *img, int state); |
| 146 | 146 | |
| 147 | 147 | /* deprecated; set interface for disk image functions */ |
| 148 | | void floppy_drive_set_disk_image_interface(mess_image *img, const floppy_interface *iface); |
| 148 | void floppy_drive_set_disk_image_interface(const device_config *img, const floppy_interface *iface); |
| 149 | 149 | |
| 150 | 150 | /* seek up or down */ |
| 151 | | void floppy_drive_seek(mess_image *img, signed int signed_tracks); |
| 151 | void floppy_drive_seek(const device_config *img, signed int signed_tracks); |
| 152 | 152 | |
| 153 | | void floppy_drive_read_track_data_info_buffer(mess_image *img, int side, void *ptr, int *length ); |
| 154 | | void floppy_drive_write_track_data_info_buffer(mess_image *img, int side, const void *ptr, int *length ); |
| 155 | | void floppy_drive_format_sector(mess_image *img, int side, int sector_index, int c, int h, int r, int n, int filler); |
| 156 | | void floppy_drive_read_sector_data(mess_image *img, int side, int index1, void *pBuffer, int length); |
| 157 | | void floppy_drive_write_sector_data(mess_image *img, int side, int index1, const void *pBuffer, int length, int ddam); |
| 153 | void floppy_drive_read_track_data_info_buffer(const device_config *img, int side, void *ptr, int *length ); |
| 154 | void floppy_drive_write_track_data_info_buffer(const device_config *img, int side, const void *ptr, int *length ); |
| 155 | void floppy_drive_format_sector(const device_config *img, int side, int sector_index, int c, int h, int r, int n, int filler); |
| 156 | void floppy_drive_read_sector_data(const device_config *img, int side, int index1, void *pBuffer, int length); |
| 157 | void floppy_drive_write_sector_data(const device_config *img, int side, int index1, const void *pBuffer, int length, int ddam); |
| 158 | 158 | int floppy_drive_get_datarate_in_us(DENSITY density); |
| 159 | 159 | |
| 160 | 160 | /* set motor speed to get correct index pulses |
| r2166 | r2167 | |
| 162 | 162 | Note: this actually only works for soft sectored disks: one index pulse per |
| 163 | 163 | track. |
| 164 | 164 | */ |
| 165 | | void floppy_drive_set_rpm(mess_image *image, float rpm); |
| 165 | void floppy_drive_set_rpm(const device_config *image, float rpm); |
| 166 | 166 | |
| 167 | 167 | |
| 168 | 168 | #endif /* FLOPDRV_H */ |
src/mess/devices/mfmdisk.c
| r2166 | r2167 | |
| 13 | 13 | #include "flopdrv.h" |
| 14 | 14 | |
| 15 | 15 | |
| 16 | | static void mfm_disk_seek_callback(mess_image *image, int); |
| 17 | | static int mfm_disk_get_sectors_per_track(mess_image *image, int); |
| 18 | | static void mfm_disk_get_id_callback(mess_image *image, chrn_id *, int, int); |
| 19 | | static void mfm_disk_read_sector_data_into_buffer(mess_image *image, int side, int index1, char *ptr, int length); |
| 20 | | static void mfm_disk_write_sector_data_from_buffer(mess_image *image, int side, int index1, const char *ptr, int length,int ddam); |
| 16 | static void mfm_disk_seek_callback(const device_config *image, int); |
| 17 | static int mfm_disk_get_sectors_per_track(const device_config *image, int); |
| 18 | static void mfm_disk_get_id_callback(const device_config *image, chrn_id *, int, int); |
| 19 | static void mfm_disk_read_sector_data_into_buffer(const device_config *image, int side, int index1, char *ptr, int length); |
| 20 | static void mfm_disk_write_sector_data_from_buffer(const device_config *image, int side, int index1, const char *ptr, int length,int ddam); |
| 21 | 21 | |
| 22 | 22 | const floppy_interface mfm_disk_floppy_interface = |
| 23 | 23 | { |
| r2166 | r2167 | |
| 102 | 102 | deleted data mark and data in the sector field! |
| 103 | 103 | */ |
| 104 | 104 | |
| 105 | | static struct mfm_disk_info *get_disk(mess_image *image) |
| 105 | static struct mfm_disk_info *get_disk(const device_config *image) |
| 106 | 106 | { |
| 107 | 107 | int disk = image_index_in_device(image); |
| 108 | 108 | return &mfm_disks[disk]; |
| r2166 | r2167 | |
| 110 | 110 | |
| 111 | 111 | /* TODO: Error checking if a id is found at very end of track, or a sector which |
| 112 | 112 | goes over end of track */ |
| 113 | | static void mfm_info_cache_sector_info(mess_image *image,unsigned char *pTrackPtr, unsigned long Length) |
| 113 | static void mfm_info_cache_sector_info(const device_config *image,unsigned char *pTrackPtr, unsigned long Length) |
| 114 | 114 | { |
| 115 | 115 | /* initialise these with single density values if single density */ |
| 116 | 116 | unsigned char IdMark = 0x0fe; |
| r2166 | r2167 | |
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | | static unsigned long mfm_disk_get_track_size(mess_image *image) |
| 193 | static unsigned long mfm_disk_get_track_size(const device_config *image) |
| 194 | 194 | { |
| 195 | 195 | struct mfm_disk_info *pDisk = get_disk(image); |
| 196 | 196 | switch (pDisk->Density) |
| r2166 | r2167 | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
| 209 | | static unsigned char *mfm_disk_get_track_ptr(mess_image *image, int track, int side) |
| 209 | static unsigned char *mfm_disk_get_track_ptr(const device_config *image, int track, int side) |
| 210 | 210 | { |
| 211 | 211 | struct mfm_disk_info *pDisk = get_disk(image); |
| 212 | 212 | |
| r2166 | r2167 | |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /* cache info about track */ |
| 330 | | static void mfm_disk_cache_data(mess_image *image, int track, int side) |
| 330 | static void mfm_disk_cache_data(const device_config *image, int track, int side) |
| 331 | 331 | { |
| 332 | 332 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 333 | 333 | |
| r2166 | r2167 | |
| 345 | 345 | |
| 346 | 346 | |
| 347 | 347 | |
| 348 | | static void mfm_disk_get_id_callback(mess_image *image, chrn_id *id, int id_index, int side) |
| 348 | static void mfm_disk_get_id_callback(const device_config *image, chrn_id *id, int id_index, int side) |
| 349 | 349 | { |
| 350 | 350 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 351 | 351 | |
| r2166 | r2167 | |
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | | static int mfm_disk_get_sectors_per_track(mess_image *image, int side) |
| 372 | static int mfm_disk_get_sectors_per_track(const device_config *image, int side) |
| 373 | 373 | { |
| 374 | 374 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 375 | 375 | |
| r2166 | r2167 | |
| 385 | 385 | return mfm_disk->NumSectors; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | | static void mfm_disk_seek_callback(mess_image *image, int physical_track) |
| 388 | static void mfm_disk_seek_callback(const device_config *image, int physical_track) |
| 389 | 389 | { |
| 390 | 390 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 391 | 391 | mfm_disk->CurrentTrack = physical_track; |
| r2166 | r2167 | |
| 393 | 393 | |
| 394 | 394 | /* reading and writing are not clever, they need to be so that the data is correctly written back |
| 395 | 395 | to the image */ |
| 396 | | static void mfm_disk_write_sector_data_from_buffer(mess_image *image, int side, int index1, const char *ptr, int length, int ddam) |
| 396 | static void mfm_disk_write_sector_data_from_buffer(const device_config *image, int side, int index1, const char *ptr, int length, int ddam) |
| 397 | 397 | { |
| 398 | 398 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 399 | 399 | unsigned char *pSectorPtr; |
| r2166 | r2167 | |
| 405 | 405 | memcpy(pSectorPtr, ptr, length); |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | | static void mfm_disk_read_sector_data_into_buffer(mess_image *image, int side, int index1, char *ptr, int length) |
| 408 | static void mfm_disk_read_sector_data_into_buffer(const device_config *image, int side, int index1, char *ptr, int length) |
| 409 | 409 | { |
| 410 | 410 | struct mfm_disk_info *mfm_disk = get_disk(image); |
| 411 | 411 | unsigned char *pSectorPtr; |
src/mess/devices/mflopimg.c
| r2166 | r2167 | |
| 31 | 31 | { |
| 32 | 32 | floppy_image *floppy; |
| 33 | 33 | int track; |
| 34 | | void (*unload_proc)(mess_image *image); |
| 35 | | int (*tracktranslate_proc)(mess_image *image, floppy_image *floppy, int physical_track); |
| 34 | void (*unload_proc)(const device_config *image); |
| 35 | int (*tracktranslate_proc)(const device_config *image, floppy_image *floppy, int physical_track); |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | |
| r2166 | r2167 | |
| 64 | 64 | IMPLEMENTATION |
| 65 | 65 | ***************************************************************************/ |
| 66 | 66 | |
| 67 | | static mess_flopimg *get_flopimg(mess_image *image) |
| 67 | static mess_flopimg *get_flopimg(const device_config *image) |
| 68 | 68 | { |
| 69 | 69 | return (mess_flopimg *) image_lookuptag(image, FLOPPY_TAG); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
| 73 | 73 | |
| 74 | | floppy_image *flopimg_get_image(mess_image *image) |
| 74 | floppy_image *flopimg_get_image(const device_config *image) |
| 75 | 75 | { |
| 76 | 76 | return get_flopimg(image)->floppy; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | |
| 81 | | static void flopimg_seek_callback(mess_image *image, int physical_track) |
| 81 | static void flopimg_seek_callback(const device_config *image, int physical_track) |
| 82 | 82 | { |
| 83 | 83 | mess_flopimg *flopimg; |
| 84 | 84 | |
| r2166 | r2167 | |
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | |
| 98 | | static int flopimg_get_sectors_per_track(mess_image *image, int side) |
| 98 | static int flopimg_get_sectors_per_track(const device_config *image, int side) |
| 99 | 99 | { |
| 100 | 100 | mess_flopimg *flopimg; |
| 101 | 101 | floperr_t err; |
| r2166 | r2167 | |
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | | static void flopimg_get_id_callback(mess_image *image, chrn_id *id, int id_index, int side) |
| 116 | static void flopimg_get_id_callback(const device_config *image, chrn_id *id, int id_index, int side) |
| 117 | 117 | { |
| 118 | 118 | mess_flopimg *flopimg; |
| 119 | 119 | int cylinder, sector, N; |
| r2166 | r2167 | |
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | |
| 151 | | static void flopimg_read_sector_data_into_buffer(mess_image *image, int side, int index1, char *ptr, int length) |
| 151 | static void flopimg_read_sector_data_into_buffer(const device_config *image, int side, int index1, char *ptr, int length) |
| 152 | 152 | { |
| 153 | 153 | mess_flopimg *flopimg; |
| 154 | 154 | |
| r2166 | r2167 | |
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | |
| 167 | | static void flopimg_write_sector_data_from_buffer(mess_image *image, int side, int index1, const char *ptr, int length,int ddam) |
| 167 | static void flopimg_write_sector_data_from_buffer(const device_config *image, int side, int index1, const char *ptr, int length,int ddam) |
| 168 | 168 | { |
| 169 | 169 | mess_flopimg *flopimg; |
| 170 | 170 | |
| r2166 | r2167 | |
| 180 | 180 | |
| 181 | 181 | |
| 182 | 182 | |
| 183 | | static void flopimg_read_track_data_info_buffer(mess_image *image, int side, void *ptr, int *length) |
| 183 | static void flopimg_read_track_data_info_buffer(const device_config *image, int side, void *ptr, int *length) |
| 184 | 184 | { |
| 185 | 185 | mess_flopimg *flopimg; |
| 186 | 186 | |
| r2166 | r2167 | |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | |
| 196 | | static void flopimg_write_track_data_info_buffer(mess_image *image, int side, const void *ptr, int *length) |
| 196 | static void flopimg_write_track_data_info_buffer(const device_config *image, int side, const void *ptr, int *length) |
| 197 | 197 | { |
| 198 | 198 | mess_flopimg *flopimg; |
| 199 | 199 | |
| r2166 | r2167 | |
| 222 | 222 | |
| 223 | 223 | static int image_fseek_thunk(void *file, INT64 offset, int whence) |
| 224 | 224 | { |
| 225 | | return image_fseek((mess_image *) file, offset, whence); |
| 225 | return image_fseek((const device_config *) file, offset, whence); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | static size_t image_fread_thunk(void *file, void *buffer, size_t length) |
| 229 | 229 | { |
| 230 | | return image_fread((mess_image *) file, buffer, length); |
| 230 | return image_fread((const device_config *) file, buffer, length); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | static size_t image_fwrite_thunk(void *file, const void *buffer, size_t length) |
| 234 | 234 | { |
| 235 | | return image_fwrite((mess_image *) file, buffer, length); |
| 235 | return image_fwrite((const device_config *) file, buffer, length); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | static UINT64 image_fsize_thunk(void *file) |
| 239 | 239 | { |
| 240 | | return image_length((mess_image *) file); |
| 240 | return image_length((const device_config *) file); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /* ----------------------------------------------------------------------- */ |
| r2166 | r2167 | |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | |
| 269 | | static int internal_floppy_device_load(mess_image *image, int create_format, option_resolution *create_args) |
| 269 | static int internal_floppy_device_load(const device_config *image, int create_format, option_resolution *create_args) |
| 270 | 270 | { |
| 271 | 271 | floperr_t err; |
| 272 | 272 | mess_flopimg *flopimg; |
| r2166 | r2167 | |
| 367 | 367 | * |
| 368 | 368 | *************************************/ |
| 369 | 369 | |
| 370 | | void floppy_install_unload_proc(mess_image *image, void (*proc)(mess_image *image)) |
| 370 | void floppy_install_unload_proc(const device_config *image, void (*proc)(const device_config *image)) |
| 371 | 371 | { |
| 372 | 372 | mess_flopimg *flopimg; |
| 373 | 373 | flopimg = image_lookuptag(image, FLOPPY_TAG); |
| r2166 | r2167 | |
| 376 | 376 | |
| 377 | 377 | |
| 378 | 378 | |
| 379 | | void floppy_install_tracktranslate_proc(mess_image *image, int (*proc)(mess_image *image, floppy_image *floppy, int physical_track)) |
| 379 | void floppy_install_tracktranslate_proc(const device_config *image, int (*proc)(const device_config *image, floppy_image *floppy, int physical_track)) |
| 380 | 380 | { |
| 381 | 381 | mess_flopimg *flopimg; |
| 382 | 382 | flopimg = image_lookuptag(image, FLOPPY_TAG); |
src/mess/devices/dsk.c
| r2166 | r2167 | |
| 34 | 34 | |
| 35 | 35 | static void dsk_disk_image_init(dsk_drive *); |
| 36 | 36 | |
| 37 | | static void dsk_seek_callback(mess_image *img, int physical_track); |
| 38 | | static void dsk_get_id_callback(mess_image *img, struct chrn_id *id, int id_index, int side); |
| 39 | | static int dsk_get_sectors_per_track(mess_image *img, int side); |
| 37 | static void dsk_seek_callback(const device_config *img, int physical_track); |
| 38 | static void dsk_get_id_callback(const device_config *img, struct chrn_id *id, int id_index, int side); |
| 39 | static int dsk_get_sectors_per_track(const device_config *img, int side); |
| 40 | 40 | |
| 41 | | static void dsk_write_sector_data_from_buffer(mess_image *img, int sector_index, int side, const char *ptr, int length, int ddam); |
| 42 | | static void dsk_read_sector_data_into_buffer(mess_image *img, int sector_index, int side, char *ptr, int length); |
| 41 | static void dsk_write_sector_data_from_buffer(const device_config *img, int sector_index, int side, const char *ptr, int length, int ddam); |
| 42 | static void dsk_read_sector_data_into_buffer(const device_config *img, int sector_index, int side, char *ptr, int length); |
| 43 | 43 | |
| 44 | 44 | static const floppy_interface dsk_floppy_interface = |
| 45 | 45 | { |
| r2166 | r2167 | |
| 54 | 54 | |
| 55 | 55 | static dsk_drive drives[dsk_NUM_DRIVES]; /* the drives */ |
| 56 | 56 | |
| 57 | | static dsk_drive *get_drive(mess_image *img) |
| 57 | static dsk_drive *get_drive(const device_config *img) |
| 58 | 58 | { |
| 59 | 59 | return &drives[image_index_in_device(img)]; |
| 60 | 60 | } |
| r2166 | r2167 | |
| 98 | 98 | return INIT_PASS; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | | static int dsk_save(mess_image *img, unsigned char **ptr) |
| 101 | static int dsk_save(const device_config *img, unsigned char **ptr) |
| 102 | 102 | { |
| 103 | 103 | int datasize; |
| 104 | 104 | unsigned char *data; |
| r2166 | r2167 | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
| 336 | | static void dsk_seek_callback(mess_image *img, int physical_track) |
| 336 | static void dsk_seek_callback(const device_config *img, int physical_track) |
| 337 | 337 | { |
| 338 | 338 | get_drive(img)->current_track = physical_track; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | | static int get_track_offset(mess_image *img, int side) |
| 341 | static int get_track_offset(const device_config *img, int side) |
| 342 | 342 | { |
| 343 | 343 | dsk_drive *thedrive = get_drive(img); |
| 344 | 344 | side = side & 0x01; |
| 345 | 345 | return thedrive->track_offsets[(thedrive->current_track<<1) + side]; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | | static unsigned char *get_floppy_data(mess_image *img) |
| 348 | static unsigned char *get_floppy_data(const device_config *img) |
| 349 | 349 | { |
| 350 | 350 | return get_drive(img)->data; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | | static void dsk_get_id_callback(mess_image *img, chrn_id *id, int id_index, int side) |
| 353 | static void dsk_get_id_callback(const device_config *img, chrn_id *id, int id_index, int side) |
| 354 | 354 | { |
| 355 | 355 | int id_offset; |
| 356 | 356 | int track_offset; |
| r2166 | r2167 | |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
| 400 | | static void dsk_set_ddam(mess_image *img, int id_index, int side, int ddam) |
| 400 | static void dsk_set_ddam(const device_config *img, int id_index, int side, int ddam) |
| 401 | 401 | { |
| 402 | 402 | int id_offset; |
| 403 | 403 | int track_offset; |
| r2166 | r2167 | |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
| 435 | | static char * dsk_get_sector_ptr_callback(mess_image *img, int sector_index, int side) |
| 435 | static char * dsk_get_sector_ptr_callback(const device_config *img, int sector_index, int side) |
| 436 | 436 | { |
| 437 | 437 | int track_offset; |
| 438 | 438 | int sector_offset; |
| r2166 | r2167 | |
| 480 | 480 | return (char *)(data + track_offset + sector_offset); |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | | static void dsk_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length, int ddam) |
| 483 | static void dsk_write_sector_data_from_buffer(const device_config *img, int side, int index1, const char *ptr, int length, int ddam) |
| 484 | 484 | { |
| 485 | 485 | char * pSectorData; |
| 486 | 486 | |
| r2166 | r2167 | |
| 495 | 495 | dsk_set_ddam(img, index1, side,ddam); |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | | static void dsk_read_sector_data_into_buffer(mess_image *img, int side, int index1, char *ptr, int length) |
| 498 | static void dsk_read_sector_data_into_buffer(const device_config *img, int side, int index1, char *ptr, int length) |
| 499 | 499 | { |
| 500 | 500 | char *pSectorData; |
| 501 | 501 | |
| r2166 | r2167 | |
| 505 | 505 | memcpy(ptr, pSectorData, length); |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | | static int dsk_get_sectors_per_track(mess_image *img, int side) |
| 508 | static int dsk_get_sectors_per_track(const device_config *img, int side) |
| 509 | 509 | { |
| 510 | 510 | int track_offset; |
| 511 | 511 | unsigned char *track_header; |
src/mess/devices/basicdsk.c
| r2166 | r2167 | |
| 24 | 24 | typedef struct |
| 25 | 25 | { |
| 26 | 26 | const char *image_name; /* file name for disc image */ |
| 27 | | mess_image *image_file; /* file handle for disc image */ |
| 27 | const device_config *image_file; /* file handle for disc image */ |
| 28 | 28 | int mode; /* open mode == 0 read only, != 0 read/write */ |
| 29 | 29 | unsigned long image_size; /* size of image file */ |
| 30 | 30 | |
| r2166 | r2167 | |
| 59 | 59 | |
| 60 | 60 | static basicdsk basicdsk_drives[basicdsk_MAX_DRIVES]; |
| 61 | 61 | |
| 62 | | static void basicdsk_seek_callback(mess_image *img, int); |
| 63 | | static int basicdsk_get_sectors_per_track(mess_image *img, int); |
| 64 | | static void basicdsk_get_id_callback(mess_image *img, chrn_id *, int, int); |
| 65 | | static void basicdsk_read_sector_data_into_buffer(mess_image *img, int side, int index1, char *ptr, int length); |
| 66 | | static void basicdsk_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length,int ddam); |
| 62 | static void basicdsk_seek_callback(const device_config *img, int); |
| 63 | static int basicdsk_get_sectors_per_track(const device_config *img, int); |
| 64 | static void basicdsk_get_id_callback(const device_config *img, chrn_id *, int, int); |
| 65 | static void basicdsk_read_sector_data_into_buffer(const device_config *img, int side, int index1, char *ptr, int length); |
| 66 | static void basicdsk_write_sector_data_from_buffer(const device_config *img, int side, int index1, const char *ptr, int length,int ddam); |
| 67 | 67 | |
| 68 | 68 | const floppy_interface basicdsk_floppy_interface = |
| 69 | 69 | { |
| r2166 | r2167 | |
| 76 | 76 | NULL |
| 77 | 77 | }; |
| 78 | 78 | |
| 79 | | static basicdsk *get_basicdsk(mess_image *img) |
| 79 | static basicdsk *get_basicdsk(const device_config *img) |
| 80 | 80 | { |
| 81 | 81 | int drive = image_index_in_device(img); |
| 82 | 82 | assert(drive >= 0); |
| r2166 | r2167 | |
| 118 | 118 | |
| 119 | 119 | /* set data mark/deleted data mark for the sector specified. If ddam!=0, the sector will |
| 120 | 120 | have a deleted data mark, if ddam==0, the sector will have a data mark */ |
| 121 | | void basicdsk_set_ddam(mess_image *img, UINT8 physical_track, UINT8 physical_side, UINT8 sector_id,UINT8 ddam) |
| 121 | void basicdsk_set_ddam(const device_config *img, UINT8 physical_track, UINT8 physical_side, UINT8 sector_id,UINT8 ddam) |
| 122 | 122 | { |
| 123 | 123 | unsigned long ddam_bit_offset, ddam_bit_index, ddam_byte_offset; |
| 124 | 124 | basicdsk *pDisk = get_basicdsk(img); |
| r2166 | r2167 | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /* get dam state for specified sector */ |
| 156 | | static int basicdsk_get_ddam(mess_image *img, UINT8 physical_track, UINT8 physical_side, UINT8 sector_id) |
| 156 | static int basicdsk_get_ddam(const device_config *img, UINT8 physical_track, UINT8 physical_side, UINT8 sector_id) |
| 157 | 157 | { |
| 158 | 158 | unsigned long ddam_bit_offset, ddam_bit_index, ddam_byte_offset; |
| 159 | 159 | basicdsk *pDisk = get_basicdsk(img); |
| r2166 | r2167 | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
| 182 | | void basicdsk_set_calcoffset(mess_image *img, unsigned long (*calcoffset)(UINT8 t, UINT8 h, UINT8 s, |
| 182 | void basicdsk_set_calcoffset(const device_config *img, unsigned long (*calcoffset)(UINT8 t, UINT8 h, UINT8 s, |
| 183 | 183 | UINT8 tracks, UINT8 heads, UINT8 sec_per_track, UINT16 sector_length, UINT8 first_sector_id, UINT16 offset_track_zero)) |
| 184 | 184 | { |
| 185 | 185 | basicdsk *pDisk = get_basicdsk(img); |
| r2166 | r2167 | |
| 188 | 188 | |
| 189 | 189 | /* dir_sector is a relative offset from the start of the disc, |
| 190 | 190 | dir_length is a relative offset from the start of the disc */ |
| 191 | | void basicdsk_set_geometry(mess_image *img, UINT8 tracks, UINT8 heads, UINT8 sec_per_track, UINT16 sector_length, UINT8 first_sector_id, UINT16 offset_track_zero, int track_skipping) |
| 191 | void basicdsk_set_geometry(const device_config *img, UINT8 tracks, UINT8 heads, UINT8 sec_per_track, UINT16 sector_length, UINT8 first_sector_id, UINT16 offset_track_zero, int track_skipping) |
| 192 | 192 | { |
| 193 | 193 | unsigned long N; |
| 194 | 194 | unsigned long ShiftCount; |
| r2166 | r2167 | |
| 510 | 510 | #endif |
| 511 | 511 | |
| 512 | 512 | |
| 513 | | static void basicdsk_get_id_callback(mess_image *img, chrn_id *id, int id_index, int side) |
| 513 | static void basicdsk_get_id_callback(const device_config *img, chrn_id *id, int id_index, int side) |
| 514 | 514 | { |
| 515 | 515 | basicdsk *w = get_basicdsk(img); |
| 516 | 516 | |
| r2166 | r2167 | |
| 530 | 530 | |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | | static int basicdsk_get_sectors_per_track(mess_image *img, int side) |
| 533 | static int basicdsk_get_sectors_per_track(const device_config *img, int side) |
| 534 | 534 | { |
| 535 | 535 | basicdsk *w = get_basicdsk(img); |
| 536 | 536 | |
| r2166 | r2167 | |
| 544 | 544 | return w->sec_per_track; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | | static void basicdsk_seek_callback(mess_image *img, int physical_track) |
| 547 | static void basicdsk_seek_callback(const device_config *img, int physical_track) |
| 548 | 548 | { |
| 549 | 549 | basicdsk *w = get_basicdsk(img); |
| 550 | 550 | assert(w->track_divider); |
| 551 | 551 | w->track = physical_track / w->track_divider; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | | static void basicdsk_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length, int ddam) |
| 554 | static void basicdsk_write_sector_data_from_buffer(const device_config *img, int side, int index1, const char *ptr, int length, int ddam) |
| 555 | 555 | { |
| 556 | 556 | basicdsk *w = get_basicdsk(img); |
| 557 | 557 | |
| r2166 | r2167 | |
| 563 | 563 | basicdsk_set_ddam(img, w->track, side, index1, ddam); |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | | static void basicdsk_read_sector_data_into_buffer(mess_image *img, int side, int index1, char *ptr, int length) |
| 566 | static void basicdsk_read_sector_data_into_buffer(const device_config *img, int side, int index1, char *ptr, int length) |
| 567 | 567 | { |
| 568 | 568 | basicdsk *w = get_basicdsk(img); |
| 569 | 569 | |
src/mess/devices/thomflop.c
| r2166 | r2167 | |
| 119 | 119 | |
| 120 | 120 | |
| 121 | 121 | /* build a sector, with header & space */ |
| 122 | | static int thom_floppy_make_sector( mess_image* img, chrn_id id, UINT8* dst, int sector_size ) |
| 122 | static int thom_floppy_make_sector( const device_config* img, chrn_id id, UINT8* dst, int sector_size ) |
| 123 | 123 | { |
| 124 | 124 | if ( sector_size == 128 ) |
| 125 | 125 | { |
| r2166 | r2167 | |
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | /* build a whole track */ |
| 153 | | static int thom_floppy_make_track( mess_image* img, UINT8* dst, int sector_size, int side ) |
| 153 | static int thom_floppy_make_track( const device_config* img, UINT8* dst, int sector_size, int side ) |
| 154 | 154 | { |
| 155 | 155 | UINT8 space = ( sector_size == 128 ) ? 0xff : 0; |
| 156 | 156 | UINT8* org = dst; |
| r2166 | r2167 | |
| 226 | 226 | |
| 227 | 227 | |
| 228 | 228 | /* build a sector, with header */ |
| 229 | | static int thom_qdd_make_sector( mess_image* img, int sector, UINT8* dst ) |
| 229 | static int thom_qdd_make_sector( const device_config* img, int sector, UINT8* dst ) |
| 230 | 230 | { |
| 231 | 231 | int i; |
| 232 | 232 | dst[ 0 ] = 0x5a; |
| r2166 | r2167 | |
| 240 | 240 | |
| 241 | 241 | |
| 242 | 242 | /* build a whole disk */ |
| 243 | | static int thom_qdd_make_disk ( mess_image* img, UINT8* dst ) |
| 243 | static int thom_qdd_make_disk ( const device_config* img, UINT8* dst ) |
| 244 | 244 | { |
| 245 | 245 | UINT8* org = dst; |
| 246 | 246 | int i; |
| r2166 | r2167 | |
| 340 | 340 | wd17xx_reset(); |
| 341 | 341 | for ( i = 0; i < device_count( IO_FLOPPY ); i++ ) |
| 342 | 342 | { |
| 343 | | mess_image * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 343 | const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 344 | 344 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 345 | 345 | floppy_drive_set_rpm( img, 300. ); |
| 346 | 346 | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
| r2166 | r2167 | |
| 441 | 441 | mc6843_reset(); |
| 442 | 442 | for ( i = 0; i < device_count( IO_FLOPPY ); i++ ) |
| 443 | 443 | { |
| 444 | | mess_image * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 444 | const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 445 | 445 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 446 | 446 | floppy_drive_set_rpm( img, 300. ); |
| 447 | 447 | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
| r2166 | r2167 | |
| 529 | 529 | |
| 530 | 530 | |
| 531 | 531 | |
| 532 | | static void to7_qdd_index_pulse_cb ( mess_image* img, int state ) |
| 532 | static void to7_qdd_index_pulse_cb ( const device_config* img, int state ) |
| 533 | 533 | { |
| 534 | 534 | to7qdd->index_pulse = state; |
| 535 | 535 | |
| r2166 | r2167 | |
| 546 | 546 | |
| 547 | 547 | |
| 548 | 548 | |
| 549 | | static mess_image * to7_qdd_image ( void ) |
| 549 | static const device_config * to7_qdd_image ( void ) |
| 550 | 550 | { |
| 551 | 551 | return image_from_devtype_and_index( IO_FLOPPY, 0 ); |
| 552 | 552 | } |
| r2166 | r2167 | |
| 729 | 729 | case 8: /* floppy status */ |
| 730 | 730 | { |
| 731 | 731 | UINT8 data = 0; |
| 732 | | mess_image* img = to7_qdd_image(); |
| 732 | const device_config* img = to7_qdd_image(); |
| 733 | 733 | if ( ! image_exists( img ) ) |
| 734 | 734 | data |= 0x40; /* disk present */ |
| 735 | 735 | if ( to7qdd->index_pulse ) |
| r2166 | r2167 | |
| 847 | 847 | |
| 848 | 848 | for ( i = 0; i < device_count( IO_FLOPPY ); i++ ) |
| 849 | 849 | { |
| 850 | | mess_image * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 850 | const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 851 | 851 | floppy_drive_set_index_pulse_callback( img, to7_qdd_index_pulse_cb ); |
| 852 | 852 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 853 | 853 | floppy_drive_set_motor_state( img, 1 ); |
| r2166 | r2167 | |
| 944 | 944 | |
| 945 | 945 | |
| 946 | 946 | |
| 947 | | static mess_image * thmfc_floppy_image ( void ) |
| 947 | static const device_config * thmfc_floppy_image ( void ) |
| 948 | 948 | { |
| 949 | 949 | return image_from_devtype_and_index( IO_FLOPPY, thmfc1->drive ); |
| 950 | 950 | } |
| r2166 | r2167 | |
| 958 | 958 | |
| 959 | 959 | |
| 960 | 960 | |
| 961 | | static void thmfc_floppy_index_pulse_cb ( mess_image *img, int state ) |
| 961 | static void thmfc_floppy_index_pulse_cb ( const device_config *img, int state ) |
| 962 | 962 | { |
| 963 | 963 | if ( img != thmfc_floppy_image() ) |
| 964 | 964 | return; |
| r2166 | r2167 | |
| 990 | 990 | |
| 991 | 991 | static int thmfc_floppy_find_sector ( chrn_id* dst ) |
| 992 | 992 | { |
| 993 | | mess_image* img = thmfc_floppy_image(); |
| 993 | const device_config* img = thmfc_floppy_image(); |
| 994 | 994 | chrn_id id; |
| 995 | 995 | int r = 0; |
| 996 | 996 | |
| r2166 | r2167 | |
| 1034 | 1034 | if ( thmfc1->op == THMFC1_OP_WRITE_SECT ) |
| 1035 | 1035 | { |
| 1036 | 1036 | /* TODO: detect ddam (?) */ |
| 1037 | | mess_image * img = thmfc_floppy_image(); |
| 1037 | const device_config * img = thmfc_floppy_image(); |
| 1038 | 1038 | floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector, thmfc1->data + 3, thmfc1->data_size - 3, 0 ); |
| 1039 | 1039 | } |
| 1040 | 1040 | thmfc1->op = THMFC1_OP_RESET; |
| r2166 | r2167 | |
| 1176 | 1176 | if ( i >= 0 ) |
| 1177 | 1177 | { |
| 1178 | 1178 | /* got an id & a data field => write */ |
| 1179 | | mess_image * img = thmfc_floppy_image(); |
| 1179 | const device_config * img = thmfc_floppy_image(); |
| 1180 | 1180 | int sector = (int) thmfc1->data[ i + 1 ] * 256 + |
| 1181 | 1181 | (int) thmfc1->data[ i + 2 ]; |
| 1182 | 1182 | |
| r2166 | r2167 | |
| 1236 | 1236 | if ( !memcmp ( thmfc1->data, header, sizeof( header ) ) ) |
| 1237 | 1237 | { |
| 1238 | 1238 | /* got id field => format */ |
| 1239 | | mess_image * img = thmfc_floppy_image(); |
| 1239 | const device_config * img = thmfc_floppy_image(); |
| 1240 | 1240 | UINT8 track = thmfc1->data[4]; |
| 1241 | 1241 | UINT8 side = thmfc1->data[5]; |
| 1242 | 1242 | UINT8 sector = thmfc1->data[6]; |
| r2166 | r2167 | |
| 1266 | 1266 | case 1: /* STAT1 */ |
| 1267 | 1267 | { |
| 1268 | 1268 | UINT8 data = 0; |
| 1269 | | mess_image * img = thmfc_floppy_image(); |
| 1269 | const device_config * img = thmfc_floppy_image(); |
| 1270 | 1270 | int flags = floppy_drive_get_flag_state( img, -1 ); |
| 1271 | 1271 | if ( thmfc_floppy_is_qdd() ) |
| 1272 | 1272 | { |
| r2166 | r2167 | |
| 1431 | 1431 | |
| 1432 | 1432 | case 2: /* CMD2 */ |
| 1433 | 1433 | { |
| 1434 | | mess_image * img; |
| 1434 | const device_config * img; |
| 1435 | 1435 | int seek = 0, motor; |
| 1436 | 1436 | thmfc1->drive = data & 2; |
| 1437 | 1437 | |
| r2166 | r2167 | |
| 1528 | 1528 | |
| 1529 | 1529 | for ( i = 0; i < device_count( IO_FLOPPY ); i++ ) |
| 1530 | 1530 | { |
| 1531 | | mess_image * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 1531 | const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 1532 | 1532 | floppy_drive_set_index_pulse_callback( img, thmfc_floppy_index_pulse_cb ); |
| 1533 | 1533 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 1534 | 1534 | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
src/mess/image.c
| r2166 | r2167 | |
| 701 | 701 | image_load - load an image into MESS |
| 702 | 702 | -------------------------------------------------*/ |
| 703 | 703 | |
| 704 | | int image_load(mess_image *image, const char *path) |
| 704 | int image_load(const device_config *image, const char *path) |
| 705 | 705 | { |
| 706 | 706 | return image_load_internal(image, path, FALSE, 0, NULL); |
| 707 | 707 | } |
| r2166 | r2167 | |
| 712 | 712 | image_create - create a MESS image |
| 713 | 713 | -------------------------------------------------*/ |
| 714 | 714 | |
| 715 | | int image_create(mess_image *image, const char *path, int create_format, option_resolution *create_args) |
| 715 | int image_create(const device_config *image, const char *path, int create_format, option_resolution *create_args) |
| 716 | 716 | { |
| 717 | 717 | return image_load_internal(image, path, TRUE, create_format, create_args); |
| 718 | 718 | } |
| r2166 | r2167 | |
| 778 | 778 | image_unload - main call to unload an image |
| 779 | 779 | -------------------------------------------------*/ |
| 780 | 780 | |
| 781 | | void image_unload(mess_image *image) |
| 781 | void image_unload(const device_config *image) |
| 782 | 782 | { |
| 783 | 783 | image_slot_data *slot = find_image_slot(image); |
| 784 | 784 | image_unload_internal(slot, FALSE); |
| r2166 | r2167 | |
| 844 | 844 | error |
| 845 | 845 | -------------------------------------------------*/ |
| 846 | 846 | |
| 847 | | const char *image_error(mess_image *image) |
| 847 | const char *image_error(const device_config *image) |
| 848 | 848 | { |
| 849 | 849 | static const char *const messages[] = |
| 850 | 850 | { |
| r2166 | r2167 | |
| 868 | 868 | image_seterror - specifies an error on an image |
| 869 | 869 | -------------------------------------------------*/ |
| 870 | 870 | |
| 871 | | void image_seterror(mess_image *image, image_error_t err, const char *message) |
| 871 | void image_seterror(const device_config *image, image_error_t err, const char *message) |
| 872 | 872 | { |
| 873 | 873 | image_slot_data *slot = find_image_slot(image); |
| 874 | 874 | |
| r2166 | r2167 | |
| 896 | 896 | raised if this happens |
| 897 | 897 | ****************************************************************************/ |
| 898 | 898 | |
| 899 | | void *image_alloctag(mess_image *image, const char *tag, size_t size) |
| 899 | void *image_alloctag(const device_config *image, const char *tag, size_t size) |
| 900 | 900 | { |
| 901 | 901 | image_slot_data *slot = find_image_slot(image); |
| 902 | 902 | return tagpool_alloc(&slot->tagpool, tag, size); |
| r2166 | r2167 | |
| 904 | 904 | |
| 905 | 905 | |
| 906 | 906 | |
| 907 | | void *image_lookuptag(mess_image *image, const char *tag) |
| 907 | void *image_lookuptag(const device_config *image, const char *tag) |
| 908 | 908 | { |
| 909 | 909 | image_slot_data *slot = find_image_slot(image); |
| 910 | 910 | return tagpool_lookup(&slot->tagpool, tag); |
| r2166 | r2167 | |
| 949 | 949 | |
| 950 | 950 | |
| 951 | 951 | |
| 952 | | static void run_hash(mess_image *image, |
| 952 | static void run_hash(const device_config *image, |
| 953 | 953 | void (*partialhash)(char *, const unsigned char *, unsigned long, unsigned int), |
| 954 | 954 | char *dest, unsigned int hash_functions) |
| 955 | 955 | { |
| r2166 | r2167 | |
| 1026 | 1026 | image_device |
| 1027 | 1027 | -------------------------------------------------*/ |
| 1028 | 1028 | |
| 1029 | | const struct IODevice *image_device(mess_image *image) |
| 1029 | const struct IODevice *image_device(const device_config *image) |
| 1030 | 1030 | { |
| 1031 | 1031 | return mess_device_from_core_device(image); |
| 1032 | 1032 | } |
| r2166 | r2167 | |
| 1037 | 1037 | image_exists |
| 1038 | 1038 | -------------------------------------------------*/ |
| 1039 | 1039 | |
| 1040 | | int image_exists(mess_image *image) |
| 1040 | int image_exists(const device_config *image) |
| 1041 | 1041 | { |
| 1042 | 1042 | return image_filename(image) != NULL; |
| 1043 | 1043 | } |
| r2166 | r2167 | |
| 1048 | 1048 | image_slotexists |
| 1049 | 1049 | -------------------------------------------------*/ |
| 1050 | 1050 | |
| 1051 | | int image_slotexists(mess_image *image) |
| 1051 | int image_slotexists(const device_config *image) |
| 1052 | 1052 | { |
| 1053 | 1053 | return TRUE; |
| 1054 | 1054 | } |
| r2166 | r2167 | |
| 1059 | 1059 | image_filename |
| 1060 | 1060 | -------------------------------------------------*/ |
| 1061 | 1061 | |
| 1062 | | const char *image_filename(mess_image *image) |
| 1062 | const char *image_filename(const device_config *image) |
| 1063 | 1063 | { |
| 1064 | 1064 | image_slot_data *slot = find_image_slot(image); |
| 1065 | 1065 | return slot->name; |
| r2166 | r2167 | |
| 1071 | 1071 | image_basename |
| 1072 | 1072 | -------------------------------------------------*/ |
| 1073 | 1073 | |
| 1074 | | const char *image_basename(mess_image *image) |
| 1074 | const char *image_basename(const device_config *image) |
| 1075 | 1075 | { |
| 1076 | 1076 | return osd_basename((char *) image_filename(image)); |
| 1077 | 1077 | } |
| r2166 | r2167 | |
| 1082 | 1082 | image_basename_noext |
| 1083 | 1083 | -------------------------------------------------*/ |
| 1084 | 1084 | |
| 1085 | | const char *image_basename_noext(mess_image *image) |
| 1085 | const char *image_basename_noext(const device_config *image) |
| 1086 | 1086 | { |
| 1087 | 1087 | const char *s; |
| 1088 | 1088 | char *ext; |
| r2166 | r2167 | |
| 1108 | 1108 | image_filetype |
| 1109 | 1109 | -------------------------------------------------*/ |
| 1110 | 1110 | |
| 1111 | | const char *image_filetype(mess_image *image) |
| 1111 | const char *image_filetype(const device_config *image) |
| 1112 | 1112 | { |
| 1113 | 1113 | const char *s; |
| 1114 | 1114 | s = image_filename(image); |
| r2166 | r2167 | |
| 1123 | 1123 | image_filedir |
| 1124 | 1124 | -------------------------------------------------*/ |
| 1125 | 1125 | |
| 1126 | | const char *image_filedir(mess_image *image) |
| 1126 | const char *image_filedir(const device_config *image) |
| 1127 | 1127 | { |
| 1128 | 1128 | image_slot_data *slot = find_image_slot(image); |
| 1129 | 1129 | return slot->dir; |
| r2166 | r2167 | |
| 1135 | 1135 | image_core_file |
| 1136 | 1136 | -------------------------------------------------*/ |
| 1137 | 1137 | |
| 1138 | | core_file *image_core_file(mess_image *image) |
| 1138 | core_file *image_core_file(const device_config *image) |
| 1139 | 1139 | { |
| 1140 | 1140 | image_slot_data *slot = find_image_slot(image); |
| 1141 | 1141 | return slot->file; |
| r2166 | r2167 | |
| 1147 | 1147 | image_typename_id |
| 1148 | 1148 | -------------------------------------------------*/ |
| 1149 | 1149 | |
| 1150 | | const char *image_typename_id(mess_image *image) |
| 1150 | const char *image_typename_id(const device_config *image) |
| 1151 | 1151 | { |
| 1152 | 1152 | const struct IODevice *dev; |
| 1153 | 1153 | int id; |
| r2166 | r2167 | |
| 1175 | 1175 | image_length |
| 1176 | 1176 | -------------------------------------------------*/ |
| 1177 | 1177 | |
| 1178 | | UINT64 image_length(mess_image *image) |
| 1178 | UINT64 image_length(const device_config *image) |
| 1179 | 1179 | { |
| 1180 | 1180 | image_slot_data *slot = find_image_slot(image); |
| 1181 | 1181 | check_for_file(slot); |
| r2166 | r2167 | |
| 1188 | 1188 | image_hash |
| 1189 | 1189 | -------------------------------------------------*/ |
| 1190 | 1190 | |
| 1191 | | const char *image_hash(mess_image *image) |
| 1191 | const char *image_hash(const device_config *image) |
| 1192 | 1192 | { |
| 1193 | 1193 | image_slot_data *slot = find_image_slot(image); |
| 1194 | 1194 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1201 | 1201 | image_crc |
| 1202 | 1202 | -------------------------------------------------*/ |
| 1203 | 1203 | |
| 1204 | | UINT32 image_crc(mess_image *image) |
| 1204 | UINT32 image_crc(const device_config *image) |
| 1205 | 1205 | { |
| 1206 | 1206 | const char *hash_string; |
| 1207 | 1207 | UINT32 crc = 0; |
| r2166 | r2167 | |
| 1219 | 1219 | image_is_writable |
| 1220 | 1220 | -------------------------------------------------*/ |
| 1221 | 1221 | |
| 1222 | | int image_is_writable(mess_image *image) |
| 1222 | int image_is_writable(const device_config *image) |
| 1223 | 1223 | { |
| 1224 | 1224 | image_slot_data *slot = find_image_slot(image); |
| 1225 | 1225 | return slot->writeable; |
| r2166 | r2167 | |
| 1231 | 1231 | image_has_been_created |
| 1232 | 1232 | -------------------------------------------------*/ |
| 1233 | 1233 | |
| 1234 | | int image_has_been_created(mess_image *image) |
| 1234 | int image_has_been_created(const device_config *image) |
| 1235 | 1235 | { |
| 1236 | 1236 | image_slot_data *slot = find_image_slot(image); |
| 1237 | 1237 | return slot->created; |
| r2166 | r2167 | |
| 1243 | 1243 | image_make_readonly |
| 1244 | 1244 | -------------------------------------------------*/ |
| 1245 | 1245 | |
| 1246 | | void image_make_readonly(mess_image *image) |
| 1246 | void image_make_readonly(const device_config *image) |
| 1247 | 1247 | { |
| 1248 | 1248 | image_slot_data *slot = find_image_slot(image); |
| 1249 | 1249 | slot->writeable = 0; |
| r2166 | r2167 | |
| 1255 | 1255 | image_fread |
| 1256 | 1256 | -------------------------------------------------*/ |
| 1257 | 1257 | |
| 1258 | | UINT32 image_fread(mess_image *image, void *buffer, UINT32 length) |
| 1258 | UINT32 image_fread(const device_config *image, void *buffer, UINT32 length) |
| 1259 | 1259 | { |
| 1260 | 1260 | image_slot_data *slot = find_image_slot(image); |
| 1261 | 1261 | check_for_file(slot); |
| r2166 | r2167 | |
| 1268 | 1268 | image_fwrite |
| 1269 | 1269 | -------------------------------------------------*/ |
| 1270 | 1270 | |
| 1271 | | UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length) |
| 1271 | UINT32 image_fwrite(const device_config *image, const void *buffer, UINT32 length) |
| 1272 | 1272 | { |
| 1273 | 1273 | image_slot_data *slot = find_image_slot(image); |
| 1274 | 1274 | check_for_file(slot); |
| r2166 | r2167 | |
| 1281 | 1281 | image_fseek |
| 1282 | 1282 | -------------------------------------------------*/ |
| 1283 | 1283 | |
| 1284 | | int image_fseek(mess_image *image, INT64 offset, int whence) |
| 1284 | int image_fseek(const device_config *image, INT64 offset, int whence) |
| 1285 | 1285 | { |
| 1286 | 1286 | image_slot_data *slot = find_image_slot(image); |
| 1287 | 1287 | check_for_file(slot); |
| r2166 | r2167 | |
| 1294 | 1294 | image_ftell |
| 1295 | 1295 | -------------------------------------------------*/ |
| 1296 | 1296 | |
| 1297 | | UINT64 image_ftell(mess_image *image) |
| 1297 | UINT64 image_ftell(const device_config *image) |
| 1298 | 1298 | { |
| 1299 | 1299 | image_slot_data *slot = find_image_slot(image); |
| 1300 | 1300 | check_for_file(slot); |
| r2166 | r2167 | |
| 1307 | 1307 | image_fgetc |
| 1308 | 1308 | -------------------------------------------------*/ |
| 1309 | 1309 | |
| 1310 | | int image_fgetc(mess_image *image) |
| 1310 | int image_fgetc(const device_config *image) |
| 1311 | 1311 | { |
| 1312 | 1312 | char ch; |
| 1313 | 1313 | if (image_fread(image, &ch, 1) != 1) |
| r2166 | r2167 | |
| 1321 | 1321 | image_feof |
| 1322 | 1322 | -------------------------------------------------*/ |
| 1323 | 1323 | |
| 1324 | | int image_feof(mess_image *image) |
| 1324 | int image_feof(const device_config *image) |
| 1325 | 1325 | { |
| 1326 | 1326 | image_slot_data *slot = find_image_slot(image); |
| 1327 | 1327 | check_for_file(slot); |
| r2166 | r2167 | |
| 1334 | 1334 | image_ptr |
| 1335 | 1335 | -------------------------------------------------*/ |
| 1336 | 1336 | |
| 1337 | | void *image_ptr(mess_image *image) |
| 1337 | void *image_ptr(const device_config *image) |
| 1338 | 1338 | { |
| 1339 | 1339 | image_slot_data *slot = find_image_slot(image); |
| 1340 | 1340 | check_for_file(slot); |
| r2166 | r2167 | |
| 1436 | 1436 | valid even if not mounted |
| 1437 | 1437 | -------------------------------------------------*/ |
| 1438 | 1438 | |
| 1439 | | const char *image_working_directory(mess_image *image) |
| 1439 | const char *image_working_directory(const device_config *image) |
| 1440 | 1440 | { |
| 1441 | 1441 | image_slot_data *slot = find_image_slot(image); |
| 1442 | 1442 | |
| r2166 | r2167 | |
| 1454 | 1454 | directory to use for this image |
| 1455 | 1455 | -------------------------------------------------*/ |
| 1456 | 1456 | |
| 1457 | | void image_set_working_directory(mess_image *image, const char *working_directory) |
| 1457 | void image_set_working_directory(const device_config *image, const char *working_directory) |
| 1458 | 1458 | { |
| 1459 | 1459 | image_slot_data *slot = find_image_slot(image); |
| 1460 | 1460 | |
| r2166 | r2167 | |
| 1474 | 1474 | able to eliminate the need for a unload function. |
| 1475 | 1475 | ****************************************************************************/ |
| 1476 | 1476 | |
| 1477 | | void *image_malloc(mess_image *image, size_t size) |
| 1477 | void *image_malloc(const device_config *image, size_t size) |
| 1478 | 1478 | { |
| 1479 | 1479 | return image_realloc(image, NULL, size); |
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | 1482 | |
| 1483 | 1483 | |
| 1484 | | void *image_realloc(mess_image *image, void *ptr, size_t size) |
| 1484 | void *image_realloc(const device_config *image, void *ptr, size_t size) |
| 1485 | 1485 | { |
| 1486 | 1486 | image_slot_data *slot = find_image_slot(image); |
| 1487 | 1487 | |
| r2166 | r2167 | |
| 1493 | 1493 | |
| 1494 | 1494 | |
| 1495 | 1495 | |
| 1496 | | char *image_strdup(mess_image *image, const char *src) |
| 1496 | char *image_strdup(const device_config *image, const char *src) |
| 1497 | 1497 | { |
| 1498 | 1498 | image_slot_data *slot = find_image_slot(image); |
| 1499 | 1499 | |
| r2166 | r2167 | |
| 1505 | 1505 | |
| 1506 | 1506 | |
| 1507 | 1507 | |
| 1508 | | void image_freeptr(mess_image *image, void *ptr) |
| 1508 | void image_freeptr(const device_config *image, void *ptr) |
| 1509 | 1509 | { |
| 1510 | 1510 | /* should really do something better here */ |
| 1511 | 1511 | image_realloc(image, ptr, 0); |
| r2166 | r2167 | |
| 1520 | 1520 | pertaining to that image in the CRC database |
| 1521 | 1521 | ****************************************************************************/ |
| 1522 | 1522 | |
| 1523 | | const char *image_longname(mess_image *image) |
| 1523 | const char *image_longname(const device_config *image) |
| 1524 | 1524 | { |
| 1525 | 1525 | image_slot_data *slot = find_image_slot(image); |
| 1526 | 1526 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1529 | 1529 | |
| 1530 | 1530 | |
| 1531 | 1531 | |
| 1532 | | const char *image_manufacturer(mess_image *image) |
| 1532 | const char *image_manufacturer(const device_config *image) |
| 1533 | 1533 | { |
| 1534 | 1534 | image_slot_data *slot = find_image_slot(image); |
| 1535 | 1535 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1538 | 1538 | |
| 1539 | 1539 | |
| 1540 | 1540 | |
| 1541 | | const char *image_year(mess_image *image) |
| 1541 | const char *image_year(const device_config *image) |
| 1542 | 1542 | { |
| 1543 | 1543 | image_slot_data *slot = find_image_slot(image); |
| 1544 | 1544 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1547 | 1547 | |
| 1548 | 1548 | |
| 1549 | 1549 | |
| 1550 | | const char *image_playable(mess_image *image) |
| 1550 | const char *image_playable(const device_config *image) |
| 1551 | 1551 | { |
| 1552 | 1552 | image_slot_data *slot = find_image_slot(image); |
| 1553 | 1553 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1556 | 1556 | |
| 1557 | 1557 | |
| 1558 | 1558 | |
| 1559 | | const char *image_extrainfo(mess_image *image) |
| 1559 | const char *image_extrainfo(const device_config *image) |
| 1560 | 1560 | { |
| 1561 | 1561 | image_slot_data *slot = find_image_slot(image); |
| 1562 | 1562 | image_checkhash(slot); |
| r2166 | r2167 | |
| 1577 | 1577 | NVRAM file for an image |
| 1578 | 1578 | -------------------------------------------------*/ |
| 1579 | 1579 | |
| 1580 | | static file_error open_battery_file(mess_image *image, UINT32 openflags, mame_file **file) |
| 1580 | static file_error open_battery_file(const device_config *image, UINT32 openflags, mame_file **file) |
| 1581 | 1581 | { |
| 1582 | 1582 | file_error filerr; |
| 1583 | 1583 | char *basename_noext; |
| r2166 | r2167 | |
| 1600 | 1600 | backed RAM for an image |
| 1601 | 1601 | -------------------------------------------------*/ |
| 1602 | 1602 | |
| 1603 | | void image_battery_load(mess_image *image, void *buffer, int length) |
| 1603 | void image_battery_load(const device_config *image, void *buffer, int length) |
| 1604 | 1604 | { |
| 1605 | 1605 | file_error filerr; |
| 1606 | 1606 | mame_file *file; |
| r2166 | r2167 | |
| 1627 | 1627 | backed RAM for an image |
| 1628 | 1628 | -------------------------------------------------*/ |
| 1629 | 1629 | |
| 1630 | | void image_battery_save(mess_image *image, const void *buffer, int length) |
| 1630 | void image_battery_save(const device_config *image, const void *buffer, int length) |
| 1631 | 1631 | { |
| 1632 | 1632 | file_error filerr; |
| 1633 | 1633 | mame_file *file; |
| r2166 | r2167 | |
| 1651 | 1651 | These provide various ways of indexing images |
| 1652 | 1652 | ****************************************************************************/ |
| 1653 | 1653 | |
| 1654 | | int image_absolute_index(mess_image *image) |
| 1654 | int image_absolute_index(const device_config *image) |
| 1655 | 1655 | { |
| 1656 | 1656 | image_slot_data *slot = find_image_slot(image); |
| 1657 | 1657 | return slot - image->machine->images_data->slots; |
| r2166 | r2167 | |
| 1659 | 1659 | |
| 1660 | 1660 | |
| 1661 | 1661 | |
| 1662 | | mess_image *image_from_absolute_index(int absolute_index) |
| 1662 | const device_config *image_from_absolute_index(int absolute_index) |
| 1663 | 1663 | { |
| 1664 | 1664 | return Machine->images_data->slots[absolute_index].dev; |
| 1665 | 1665 | } |
| r2166 | r2167 | |
| 1674 | 1674 | type/id. |
| 1675 | 1675 | ****************************************************************************/ |
| 1676 | 1676 | |
| 1677 | | mess_image *image_from_device(const struct IODevice *device) |
| 1677 | const device_config *image_from_device(const struct IODevice *device) |
| 1678 | 1678 | { |
| 1679 | 1679 | return device->devconfig; |
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | |
| 1683 | 1683 | |
| 1684 | | mess_image *image_from_devtag_and_index(const char *devtag, int id) |
| 1684 | const device_config *image_from_devtag_and_index(const char *devtag, int id) |
| 1685 | 1685 | { |
| 1686 | 1686 | int indx; |
| 1687 | | mess_image *image = NULL; |
| 1687 | const device_config *image = NULL; |
| 1688 | 1688 | const struct IODevice *dev; |
| 1689 | 1689 | int device_index; |
| 1690 | 1690 | |
| r2166 | r2167 | |
| 1706 | 1706 | |
| 1707 | 1707 | |
| 1708 | 1708 | |
| 1709 | | mess_image *image_from_devtype_and_index(iodevice_t type, int id) |
| 1709 | const device_config *image_from_devtype_and_index(iodevice_t type, int id) |
| 1710 | 1710 | { |
| 1711 | 1711 | int indx; |
| 1712 | | mess_image *image = NULL; |
| 1712 | const device_config *image = NULL; |
| 1713 | 1713 | const struct IODevice *dev; |
| 1714 | 1714 | int device_index; |
| 1715 | 1715 | |
| r2166 | r2167 | |
| 1734 | 1734 | |
| 1735 | 1735 | |
| 1736 | 1736 | |
| 1737 | | iodevice_t image_devtype(mess_image *image) |
| 1737 | iodevice_t image_devtype(const device_config *image) |
| 1738 | 1738 | { |
| 1739 | 1739 | const struct IODevice *iodev = mess_device_from_core_device(image); |
| 1740 | 1740 | assert(iodev != NULL); |
| r2166 | r2167 | |
| 1743 | 1743 | |
| 1744 | 1744 | |
| 1745 | 1745 | |
| 1746 | | int image_index_in_device(mess_image *image) |
| 1746 | int image_index_in_device(const device_config *image) |
| 1747 | 1747 | { |
| 1748 | 1748 | const struct IODevice *iodev = mess_device_from_core_device(image); |
| 1749 | 1749 | assert(iodev != NULL); |
src/mess/image.h
| r2166 | r2167 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | /**************************************************************************** |
| 37 | | A mess_image pointer represents one device entry; this could be an instance |
| 37 | A const device_config pointer represents one device entry; this could be an instance |
| 38 | 38 | of a floppy drive or a printer. The defining property is that either at |
| 39 | 39 | startup or at runtime, it can become associated with a file on the hosting |
| 40 | 40 | machine (for the examples above, a disk image or printer output file |
| 41 | | repsectively). In fact, mess_image might be better renamed mess_device. |
| 41 | repsectively). In fact, const device_config might be better renamed mess_device. |
| 42 | 42 | |
| 43 | 43 | MESS drivers declare what device types each system had and how many. For |
| 44 | | each of these, a mess_image is allocated. Devices can have init functions |
| 44 | each of these, a const device_config is allocated. Devices can have init functions |
| 45 | 45 | that allow the devices to set up any relevant internal data structures. |
| 46 | 46 | It is recommended that devices use the tag allocation system described |
| 47 | 47 | below. |
| r2166 | r2167 | |
| 65 | 65 | ****************************************************************************/ |
| 66 | 66 | |
| 67 | 67 | /* can be called by front ends */ |
| 68 | | int image_load(mess_image *img, const char *name); |
| 69 | | int image_create(mess_image *img, const char *name, int create_format, option_resolution *create_args); |
| 70 | | void image_unload(mess_image *img); |
| 68 | int image_load(const device_config *img, const char *name); |
| 69 | int image_create(const device_config *img, const char *name, int create_format, option_resolution *create_args); |
| 70 | void image_unload(const device_config *img); |
| 71 | 71 | |
| 72 | 72 | /* used to retrieve error information during image loading */ |
| 73 | | const char *image_error(mess_image *img); |
| 73 | const char *image_error(const device_config *img); |
| 74 | 74 | |
| 75 | 75 | /* used for driver init and machine init */ |
| 76 | 76 | void image_unload_all(int ispreload); |
| 77 | 77 | |
| 78 | 78 | /* used to set the error that occured during image loading */ |
| 79 | | void image_seterror(mess_image *img, image_error_t err, const char *message); |
| 79 | void image_seterror(const device_config *img, image_error_t err, const char *message); |
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | |
| r2166 | r2167 | |
| 94 | 94 | raised if this happens |
| 95 | 95 | ****************************************************************************/ |
| 96 | 96 | |
| 97 | | void *image_alloctag(mess_image *img, const char *tag, size_t size); |
| 98 | | void *image_lookuptag(mess_image *img, const char *tag); |
| 97 | void *image_alloctag(const device_config *img, const char *tag, size_t size); |
| 98 | void *image_lookuptag(const device_config *img, const char *tag); |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | |
| r2166 | r2167 | |
| 105 | 105 | These provide information about the device; and about the mounted image |
| 106 | 106 | ****************************************************************************/ |
| 107 | 107 | |
| 108 | | const struct IODevice *image_device(mess_image *image); |
| 109 | | int image_exists(mess_image *image); |
| 110 | | int image_slotexists(mess_image *image); |
| 108 | const struct IODevice *image_device(const device_config *image); |
| 109 | int image_exists(const device_config *image); |
| 110 | int image_slotexists(const device_config *image); |
| 111 | 111 | |
| 112 | | core_file *image_core_file(mess_image *image); |
| 113 | | const char *image_typename_id(mess_image *image); |
| 114 | | const char *image_filename(mess_image *image); |
| 115 | | const char *image_basename(mess_image *image); |
| 116 | | const char *image_basename_noext(mess_image *image); |
| 117 | | const char *image_filetype(mess_image *image); |
| 118 | | const char *image_filedir(mess_image *image); |
| 119 | | const char *image_working_directory(mess_image *image); |
| 120 | | void image_set_working_directory(mess_image *image, const char *working_directory); |
| 121 | | UINT64 image_length(mess_image *image); |
| 122 | | const char *image_hash(mess_image *image); |
| 123 | | UINT32 image_crc(mess_image *image); |
| 112 | core_file *image_core_file(const device_config *image); |
| 113 | const char *image_typename_id(const device_config *image); |
| 114 | const char *image_filename(const device_config *image); |
| 115 | const char *image_basename(const device_config *image); |
| 116 | const char *image_basename_noext(const device_config *image); |
| 117 | const char *image_filetype(const device_config *image); |
| 118 | const char *image_filedir(const device_config *image); |
| 119 | const char *image_working_directory(const device_config *image); |
| 120 | void image_set_working_directory(const device_config *image, const char *working_directory); |
| 121 | UINT64 image_length(const device_config *image); |
| 122 | const char *image_hash(const device_config *image); |
| 123 | UINT32 image_crc(const device_config *image); |
| 124 | 124 | |
| 125 | | int image_is_writable(mess_image *image); |
| 126 | | int image_has_been_created(mess_image *image); |
| 127 | | void image_make_readonly(mess_image *image); |
| 125 | int image_is_writable(const device_config *image); |
| 126 | int image_has_been_created(const device_config *image); |
| 127 | void image_make_readonly(const device_config *image); |
| 128 | 128 | |
| 129 | | UINT32 image_fread(mess_image *image, void *buffer, UINT32 length); |
| 130 | | UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length); |
| 131 | | int image_fseek(mess_image *image, INT64 offset, int whence); |
| 132 | | UINT64 image_ftell(mess_image *image); |
| 133 | | int image_fgetc(mess_image *image); |
| 134 | | int image_feof(mess_image *image); |
| 129 | UINT32 image_fread(const device_config *image, void *buffer, UINT32 length); |
| 130 | UINT32 image_fwrite(const device_config *image, const void *buffer, UINT32 length); |
| 131 | int image_fseek(const device_config *image, INT64 offset, int whence); |
| 132 | UINT64 image_ftell(const device_config *image); |
| 133 | int image_fgetc(const device_config *image); |
| 134 | int image_feof(const device_config *image); |
| 135 | 135 | |
| 136 | | void *image_ptr(mess_image *image); |
| 136 | void *image_ptr(const device_config *image); |
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | |
| r2166 | r2167 | |
| 145 | 145 | able to eliminate the need for a unload function. |
| 146 | 146 | ****************************************************************************/ |
| 147 | 147 | |
| 148 | | void *image_malloc(mess_image *img, size_t size) ATTR_MALLOC; |
| 149 | | char *image_strdup(mess_image *img, const char *src) ATTR_MALLOC; |
| 150 | | void *image_realloc(mess_image *img, void *ptr, size_t size); |
| 151 | | void image_freeptr(mess_image *img, void *ptr); |
| 148 | void *image_malloc(const device_config *img, size_t size) ATTR_MALLOC; |
| 149 | char *image_strdup(const device_config *img, const char *src) ATTR_MALLOC; |
| 150 | void *image_realloc(const device_config *img, void *ptr, size_t size); |
| 151 | void image_freeptr(const device_config *img, void *ptr); |
| 152 | 152 | |
| 153 | 153 | |
| 154 | 154 | |
| r2166 | r2167 | |
| 159 | 159 | pertaining to that image in the CRC database |
| 160 | 160 | ****************************************************************************/ |
| 161 | 161 | |
| 162 | | const char *image_longname(mess_image *img); |
| 163 | | const char *image_manufacturer(mess_image *img); |
| 164 | | const char *image_year(mess_image *img); |
| 165 | | const char *image_playable(mess_image *img); |
| 166 | | const char *image_extrainfo(mess_image *img); |
| 162 | const char *image_longname(const device_config *img); |
| 163 | const char *image_manufacturer(const device_config *img); |
| 164 | const char *image_year(const device_config *img); |
| 165 | const char *image_playable(const device_config *img); |
| 166 | const char *image_extrainfo(const device_config *img); |
| 167 | 167 | |
| 168 | 168 | |
| 169 | 169 | |
| r2166 | r2167 | |
| 174 | 174 | image; typically for cartridges. |
| 175 | 175 | ****************************************************************************/ |
| 176 | 176 | |
| 177 | | void image_battery_load(mess_image *img, void *buffer, int length); |
| 178 | | void image_battery_save(mess_image *img, const void *buffer, int length); |
| 177 | void image_battery_load(const device_config *img, void *buffer, int length); |
| 178 | void image_battery_save(const device_config *img, const void *buffer, int length); |
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | |
| r2166 | r2167 | |
| 185 | 185 | These provide various ways of indexing images |
| 186 | 186 | ****************************************************************************/ |
| 187 | 187 | |
| 188 | | int image_absolute_index(mess_image *image); |
| 189 | | mess_image *image_from_absolute_index(int absolute_index); |
| 188 | int image_absolute_index(const device_config *image); |
| 189 | const device_config *image_from_absolute_index(int absolute_index); |
| 190 | 190 | |
| 191 | 191 | |
| 192 | 192 | |
| r2166 | r2167 | |
| 198 | 198 | type/id. |
| 199 | 199 | ****************************************************************************/ |
| 200 | 200 | |
| 201 | | int image_index_in_device(mess_image *img); |
| 202 | | mess_image *image_from_device(const struct IODevice *dev); |
| 203 | | mess_image *image_from_devtag_and_index(const char *devtag, int id); |
| 201 | int image_index_in_device(const device_config *img); |
| 202 | const device_config *image_from_device(const struct IODevice *dev); |
| 203 | const device_config *image_from_devtag_and_index(const char *devtag, int id); |
| 204 | 204 | |
| 205 | 205 | /* deprecated; as there can be multiple devices of a certain type */ |
| 206 | | iodevice_t image_devtype(mess_image *img); |
| 207 | | mess_image *image_from_devtype_and_index(iodevice_t type, int id); |
| 206 | iodevice_t image_devtype(const device_config *img); |
| 207 | const device_config *image_from_devtype_and_index(iodevice_t type, int id); |
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | |
| r2166 | r2167 | |
| 213 | 213 | Macros for declaring device callbacks |
| 214 | 214 | ****************************************************************************/ |
| 215 | 215 | |
| 216 | | #define DEVICE_INIT(name) int device_init_##name(mess_image *image) |
| 217 | | #define DEVICE_EXIT(name) void device_exit_##name(mess_image *image) |
| 218 | | #define DEVICE_LOAD(name) int device_load_##name(mess_image *image) |
| 219 | | #define DEVICE_CREATE(name) int device_create_##name(mess_image *image, int create_format, option_resolution *create_args) |
| 220 | | #define DEVICE_UNLOAD(name) void device_unload_##name(mess_image *image) |
| 216 | #define DEVICE_INIT(name) int device_init_##name(const device_config *image) |
| 217 | #define DEVICE_EXIT(name) void device_exit_##name(const device_config *image) |
| 218 | #define DEVICE_LOAD(name) int device_load_##name(const device_config *image) |
| 219 | #define DEVICE_CREATE(name) int device_create_##name(const device_config *image, int create_format, option_resolution *create_args) |
| 220 | #define DEVICE_UNLOAD(name) void device_unload_##name(const device_config *image) |
| 221 | 221 | |
| 222 | 222 | #endif /* IMAGE_H */ |
src/mess/machine/d88.c
| r2166 | r2167 | |
| 10 | 10 | |
| 11 | 11 | static d88image d88image_drives[d88image_MAX_DRIVES]; |
| 12 | 12 | |
| 13 | | static void d88image_seek_callback(mess_image *img,int); |
| 14 | | static int d88image_get_sectors_per_track(mess_image *img,int); |
| 15 | | static void d88image_get_id_callback(mess_image *img, chrn_id *, int, int); |
| 16 | | static void d88image_read_sector_data_into_buffer(mess_image *img, int side, int index1, char *ptr, int length); |
| 17 | | static void d88image_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length,int ddam); |
| 13 | static void d88image_seek_callback(const device_config *img,int); |
| 14 | static int d88image_get_sectors_per_track(const device_config *img,int); |
| 15 | static void d88image_get_id_callback(const device_config *img, chrn_id *, int, int); |
| 16 | static void d88image_read_sector_data_into_buffer(const device_config *img, int side, int index1, char *ptr, int length); |
| 17 | static void d88image_write_sector_data_from_buffer(const device_config *img, int side, int index1, const char *ptr, int length,int ddam); |
| 18 | 18 | |
| 19 | 19 | static const floppy_interface d88image_floppy_interface= |
| 20 | 20 | { |
| r2166 | r2167 | |
| 27 | 27 | NULL |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | | static d88image *get_d88image(mess_image *img) |
| 30 | static d88image *get_d88image(const device_config *img) |
| 31 | 31 | { |
| 32 | 32 | return &d88image_drives[image_index_in_device(img)]; |
| 33 | 33 | } |
| r2166 | r2167 | |
| 164 | 164 | return 1; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | | static void d88image_get_id_callback(mess_image *img, chrn_id *id, int id_index, int side) |
| 167 | static void d88image_get_id_callback(const device_config *img, chrn_id *id, int id_index, int side) |
| 168 | 168 | { |
| 169 | 169 | d88image *w = get_d88image(img); |
| 170 | 170 | d88sect *s = &(w->sects[w->track*2+side][id_index]); |
| r2166 | r2167 | |
| 178 | 178 | id->flags = s->flags; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | | static int d88image_get_sectors_per_track(mess_image *img, int side) |
| 181 | static int d88image_get_sectors_per_track(const device_config *img, int side) |
| 182 | 182 | { |
| 183 | 183 | d88image *w = get_d88image(img); |
| 184 | 184 | |
| r2166 | r2167 | |
| 192 | 192 | return w->num_sects[w->track*2+side]; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | | static void d88image_seek_callback(mess_image *img, int physical_track) |
| 195 | static void d88image_seek_callback(const device_config *img, int physical_track) |
| 196 | 196 | { |
| 197 | 197 | d88image *w = get_d88image(img); |
| 198 | 198 | w->track = physical_track; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | | static void d88image_write_sector_data_from_buffer(mess_image *img, int side, int index1, const char *ptr, int length, int ddam) |
| 201 | static void d88image_write_sector_data_from_buffer(const device_config *img, int side, int index1, const char *ptr, int length, int ddam) |
| 202 | 202 | { |
| 203 | 203 | d88image *w = get_d88image(img); |
| 204 | 204 | d88sect *s = &(w->sects[w->track*2+side][index1]); |
| r2166 | r2167 | |
| 211 | 211 | s->flags = ddam ? ID_FLAG_DELETED_DATA : 0; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | | static void d88image_read_sector_data_into_buffer(mess_image *img, int side, int index1, char *ptr, int length) |
| 214 | static void d88image_read_sector_data_into_buffer(const device_config *img, int side, int index1, char *ptr, int length) |
| 215 | 215 | { |
| 216 | 216 | d88image *w = get_d88image(img); |
| 217 | 217 | |
src/mess/machine/mc6843.c
| r2166 | r2167 | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | |
| 113 | | static mess_image* mc6843_floppy_image ( void ) |
| 113 | static const device_config* mc6843_floppy_image ( void ) |
| 114 | 114 | { |
| 115 | 115 | return image_from_devtype_and_index( IO_FLOPPY, mc6843->drive ); |
| 116 | 116 | } |
| r2166 | r2167 | |
| 161 | 161 | |
| 162 | 162 | |
| 163 | 163 | |
| 164 | | static void mc6843_index_pulse_callback(mess_image *img, int state) |
| 164 | static void mc6843_index_pulse_callback(const device_config *img, int state) |
| 165 | 165 | { |
| 166 | 166 | mc6843->index_pulse = state; |
| 167 | 167 | } |
| r2166 | r2167 | |
| 190 | 190 | /* Seek Track Zero bottom half */ |
| 191 | 191 | static void mc6843_finish_STZ( void ) |
| 192 | 192 | { |
| 193 | | mess_image* img = mc6843_floppy_image(); |
| 193 | const device_config* img = mc6843_floppy_image(); |
| 194 | 194 | int i; |
| 195 | 195 | |
| 196 | 196 | /* seek to track zero */ |
| r2166 | r2167 | |
| 219 | 219 | /* Seek bottom half */ |
| 220 | 220 | static void mc6843_finish_SEK( void ) |
| 221 | 221 | { |
| 222 | | mess_image* img = mc6843_floppy_image(); |
| 222 | const device_config* img = mc6843_floppy_image(); |
| 223 | 223 | |
| 224 | 224 | /* seek to track */ |
| 225 | 225 | floppy_drive_seek( img, mc6843->GCR - mc6843->CTAR ); |
| r2166 | r2167 | |
| 237 | 237 | /* preamble to all sector read / write commands, returns 1 if found */ |
| 238 | 238 | static int mc6843_address_search( chrn_id* id ) |
| 239 | 239 | { |
| 240 | | mess_image* img = mc6843_floppy_image(); |
| 240 | const device_config* img = mc6843_floppy_image(); |
| 241 | 241 | int r = 0; |
| 242 | 242 | |
| 243 | 243 | while ( 1 ) |
| r2166 | r2167 | |
| 333 | 333 | static void mc6843_cont_SR( void ) |
| 334 | 334 | { |
| 335 | 335 | chrn_id id; |
| 336 | | mess_image* img = mc6843_floppy_image(); |
| 336 | const device_config* img = mc6843_floppy_image(); |
| 337 | 337 | |
| 338 | 338 | /* sector seek */ |
| 339 | 339 | if ( ! mc6843_address_search_read( &id ) ) |
| r2166 | r2167 | |
| 490 | 490 | case 3: /* Status Register A (STRA) */ |
| 491 | 491 | { |
| 492 | 492 | /* update */ |
| 493 | | mess_image* img = mc6843_floppy_image(); |
| 493 | const device_config* img = mc6843_floppy_image(); |
| 494 | 494 | int flag = floppy_drive_get_flag_state( img, FLOPPY_DRIVE_READY | FLOPPY_DRIVE_HEAD_AT_TRACK_0 | FLOPPY_DRIVE_DISK_WRITE_PROTECTED ); |
| 495 | 495 | mc6843->STRA &= 0xa3; |
| 496 | 496 | if ( flag & FLOPPY_DRIVE_READY ) |
| r2166 | r2167 | |
| 561 | 561 | if ( mc6843->data_idx >= mc6843->data_size ) |
| 562 | 562 | { |
| 563 | 563 | /* end of sector write */ |
| 564 | | mess_image* img = mc6843_floppy_image(); |
| 564 | const device_config* img = mc6843_floppy_image(); |
| 565 | 565 | |
| 566 | 566 | LOG(( "%f $%04x mc6843_w: write sector %i\n", attotime_to_double(timer_get_time()), activecpu_get_previouspc(), mc6843->data_id )); |
| 567 | 567 | |
| r2166 | r2167 | |
| 623 | 623 | if ( (mc6843->data[2] == 0) && (mc6843->data[4] == 0) ) |
| 624 | 624 | { |
| 625 | 625 | /* valid address id field */ |
| 626 | | mess_image* img = mc6843_floppy_image(); |
| 626 | const device_config* img = mc6843_floppy_image(); |
| 627 | 627 | UINT8 track = mc6843->data[1]; |
| 628 | 628 | UINT8 sector = mc6843->data[3]; |
| 629 | 629 | UINT8 filler = 0xe5; /* standard Thomson filler */ |
| r2166 | r2167 | |
| 760 | 760 | /* setup/reset floppy drive */ |
| 761 | 761 | for ( i = 0; i < device_count( IO_FLOPPY ); i++ ) |
| 762 | 762 | { |
| 763 | | mess_image * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 763 | const device_config * img = image_from_devtype_and_index( IO_FLOPPY, i ); |
| 764 | 764 | floppy_drive_set_index_pulse_callback( img, mc6843_index_pulse_callback ); |
| 765 | 765 | floppy_drive_set_motor_state( img, 1 ); |
| 766 | 766 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
src/mess/machine/smc92x4.c
| r2166 | r2167 | |
| 131 | 131 | */ |
| 132 | 132 | static int floppy_read_id(int which, int disk_unit, int head) |
| 133 | 133 | { |
| 134 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 134 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 135 | 135 | UINT8 revolution_count; |
| 136 | 136 | chrn_id id; |
| 137 | 137 | |
| r2166 | r2167 | |
| 163 | 163 | */ |
| 164 | 164 | static int floppy_find_sector(int which, int disk_unit, int cylinder, int head, int check_secnum, int sector, int *sector_data_id, int *sector_len) |
| 165 | 165 | { |
| 166 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 166 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 167 | 167 | UINT8 revolution_count; |
| 168 | 168 | chrn_id id; |
| 169 | 169 | |
| r2166 | r2167 | |
| 207 | 207 | int sector_data_id, sector_len; |
| 208 | 208 | UINT8 buf[MAX_SECTOR_LEN]; |
| 209 | 209 | int i; |
| 210 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 210 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 211 | 211 | |
| 212 | 212 | if (! floppy_find_sector(which, disk_unit, cylinder, head, check_secnum, sector, & sector_data_id, & sector_len)) |
| 213 | 213 | { |
| r2166 | r2167 | |
| 229 | 229 | int sector_data_id, sector_len; |
| 230 | 230 | UINT8 buf[MAX_SECTOR_LEN]; |
| 231 | 231 | int i; |
| 232 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 232 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 233 | 233 | |
| 234 | 234 | if (! floppy_find_sector(which, disk_unit, cylinder, head, check_secnum, sector, & sector_data_id, & sector_len)) |
| 235 | 235 | { |
| r2166 | r2167 | |
| 248 | 248 | |
| 249 | 249 | static void floppy_step(int which, int disk_unit, int direction) |
| 250 | 250 | { |
| 251 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 251 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 252 | 252 | floppy_drive_seek(disk_img, direction); |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | static UINT8 floppy_get_disk_status(int which, int disk_unit) |
| 256 | 256 | { |
| 257 | | mess_image *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 257 | const device_config *disk_img = image_from_devtype_and_index(IO_FLOPPY, disk_unit); |
| 258 | 258 | int status = floppy_status(disk_img, -1); |
| 259 | 259 | int reply; |
| 260 | 260 | |
| r2166 | r2167 | |
| 285 | 285 | unsigned int cylinders, heads, sectors_per_track, bytes_per_sector; |
| 286 | 286 | } hd[10]; |
| 287 | 287 | |
| 288 | | int smc92x4_hd_load(mess_image *image, int disk_unit) |
| 288 | int smc92x4_hd_load(const device_config *image, int disk_unit) |
| 289 | 289 | { |
| 290 | 290 | const hard_disk_info *info; |
| 291 | 291 | |
| r2166 | r2167 | |
| 318 | 318 | return INIT_FAIL; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | | void smc92x4_hd_unload(mess_image *image, int disk_unit) |
| 321 | void smc92x4_hd_unload(const device_config *image, int disk_unit) |
| 322 | 322 | { |
| 323 | 323 | device_unload_mess_hd(image); |
| 324 | 324 | hd[disk_unit].hd_handle = NULL; |
src/mess/formats/thom_dsk.c
| r2166 | r2167 | |
| 44 | 44 | UINT8 cur_track; |
| 45 | 45 | |
| 46 | 46 | /* for write-back */ |
| 47 | | mess_image* image; |
| 47 | const device_config* image; |
| 48 | 48 | UINT8 has_changed; |
| 49 | 49 | |
| 50 | 50 | } thom_floppy_drive; |
| r2166 | r2167 | |
| 200 | 200 | |
| 201 | 201 | |
| 202 | 202 | |
| 203 | | static thom_floppy_drive* thom_floppy_drive_of_image ( mess_image *image ) |
| 203 | static thom_floppy_drive* thom_floppy_drive_of_image ( const device_config *image ) |
| 204 | 204 | { |
| 205 | 205 | return thom_floppy_drives + image_index_in_device( image ); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
| 209 | 209 | |
| 210 | | static void thom_floppy_seek ( mess_image *image, int physical_track ) |
| 210 | static void thom_floppy_seek ( const device_config *image, int physical_track ) |
| 211 | 211 | { |
| 212 | 212 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 213 | 213 | thom_floppy_active( 0 ); |
| r2166 | r2167 | |
| 221 | 221 | |
| 222 | 222 | |
| 223 | 223 | |
| 224 | | static int thom_floppy_get_sectors_per_track( mess_image *image, int side ) |
| 224 | static int thom_floppy_get_sectors_per_track( const device_config *image, int side ) |
| 225 | 225 | { |
| 226 | 226 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 227 | 227 | VLOG(( "thom_floppy_get_sectors_per_track: track=%i/%i dens=%s/%s\n", d->cur_track, d->tracks, |
| r2166 | r2167 | |
| 232 | 232 | |
| 233 | 233 | |
| 234 | 234 | |
| 235 | | static void thom_floppy_get_id ( mess_image* image, chrn_id* id, |
| 235 | static void thom_floppy_get_id ( const device_config* image, chrn_id* id, |
| 236 | 236 | int id_index, int physical_side ) |
| 237 | 237 | { |
| 238 | 238 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| r2166 | r2167 | |
| 278 | 278 | |
| 279 | 279 | |
| 280 | 280 | |
| 281 | | static void thom_floppy_read_sector_data_into_buffer ( mess_image* image, int side, int index1, char *ptr, int length ) |
| 281 | static void thom_floppy_read_sector_data_into_buffer ( const device_config* image, int side, int index1, char *ptr, int length ) |
| 282 | 282 | { |
| 283 | 283 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 284 | 284 | UINT8* src = thom_floppy_sector_ptr( d, index1, d->cur_track, 0 ); |
| r2166 | r2167 | |
| 295 | 295 | |
| 296 | 296 | |
| 297 | 297 | |
| 298 | | static void thom_floppy_write_sector_data_from_buffer ( mess_image *image, int side, int data_id, const char *ptr, int length, int ddam ) |
| 298 | static void thom_floppy_write_sector_data_from_buffer ( const device_config *image, int side, int data_id, const char *ptr, int length, int ddam ) |
| 299 | 299 | { |
| 300 | 300 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 301 | 301 | UINT8* dst = thom_floppy_sector_ptr( d, data_id, d->cur_track, 0 ); |
| r2166 | r2167 | |
| 315 | 315 | |
| 316 | 316 | |
| 317 | 317 | |
| 318 | | static void thom_floppy_format_sector ( mess_image *image, int side, int sector_index, int c, int h, int r, int n, int filler ) |
| 318 | static void thom_floppy_format_sector ( const device_config *image, int side, int sector_index, int c, int h, int r, int n, int filler ) |
| 319 | 319 | { |
| 320 | 320 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 321 | 321 | int sector_size = 128 << n; |
| r2166 | r2167 | |
| 371 | 371 | /*********************** .fd format ************************/ |
| 372 | 372 | |
| 373 | 373 | |
| 374 | | static int thom_floppy_fd_load ( mess_image* image ) |
| 374 | static int thom_floppy_fd_load ( const device_config* image ) |
| 375 | 375 | { |
| 376 | 376 | thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image ); |
| 377 | 377 | int size = image_length( image ); |
| r2166 | r2167 | |
| 462 | 462 | |
| 463 | 463 | |
| 464 | 464 | |
| 465 | | static void thom_floppy_fd_save ( mess_image* image ) |
| 465 | static void thom_floppy_fd_save ( const device_config* image ) |
| 466 | 466 | { |
| 467 | 467 | thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image ); |
| 468 | 468 | unsigned size = d->sides * d->tracks * d->sectors * d->sector_size; |
| r2166 | r2167 | |
| 489 | 489 | */ |
| 490 | 490 | |
| 491 | 491 | |
| 492 | | static int thom_floppy_qd_load ( mess_image* image ) |
| 492 | static int thom_floppy_qd_load ( const device_config* image ) |
| 493 | 493 | { |
| 494 | 494 | thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image ); |
| 495 | 495 | int size = image_length( image ); |
| r2166 | r2167 | |
| 542 | 542 | |
| 543 | 543 | |
| 544 | 544 | |
| 545 | | static void thom_floppy_qd_save ( mess_image* image ) |
| 545 | static void thom_floppy_qd_save ( const device_config* image ) |
| 546 | 546 | { |
| 547 | 547 | thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image ); |
| 548 | 548 | unsigned size = d->sides * d->tracks * d->sectors * d->sector_size; |
| r2166 | r2167 | |
| 593 | 593 | |
| 594 | 594 | |
| 595 | 595 | /* TODO: protection */ |
| 596 | | static int thom_floppy_sap_load ( mess_image* image ) |
| 596 | static int thom_floppy_sap_load ( const device_config* image ) |
| 597 | 597 | { |
| 598 | 598 | int drive = image_index_in_device( image ); |
| 599 | 599 | thom_floppy_drive* d = thom_floppy_drives + drive; |
| r2166 | r2167 | |
| 712 | 712 | |
| 713 | 713 | |
| 714 | 714 | |
| 715 | | static void thom_floppy_sap_save ( mess_image* image ) |
| 715 | static void thom_floppy_sap_save ( const device_config* image ) |
| 716 | 716 | { |
| 717 | 717 | thom_floppy_drive* d = thom_floppy_drives + image_index_in_device( image ); |
| 718 | 718 | unsigned size = d->sides * d->tracks * d->sectors * d->sector_size; |
| r2166 | r2167 | |
| 782 | 782 | |
| 783 | 783 | |
| 784 | 784 | |
| 785 | | int thom_floppy_init ( mess_image *image ) |
| 785 | int thom_floppy_init ( const device_config *image ) |
| 786 | 786 | { |
| 787 | 787 | thom_qdd_compute_map(); |
| 788 | 788 | thom_floppy_reset( thom_floppy_drive_of_image( image ) ); |
| r2166 | r2167 | |
| 791 | 791 | |
| 792 | 792 | |
| 793 | 793 | |
| 794 | | int thom_floppy_load ( mess_image* image ) |
| 794 | int thom_floppy_load ( const device_config* image ) |
| 795 | 795 | { |
| 796 | 796 | const char* typ = image_filetype( image ); |
| 797 | 797 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| r2166 | r2167 | |
| 817 | 817 | |
| 818 | 818 | |
| 819 | 819 | |
| 820 | | void thom_floppy_unload ( mess_image *image ) |
| 820 | void thom_floppy_unload ( const device_config *image ) |
| 821 | 821 | { |
| 822 | 822 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 823 | 823 | const char* typ = image_filetype( image ); |
| r2166 | r2167 | |
| 835 | 835 | |
| 836 | 836 | |
| 837 | 837 | |
| 838 | | int thom_floppy_create ( mess_image *image, int create_format, option_resolution *args ) |
| 838 | int thom_floppy_create ( const device_config *image, int create_format, option_resolution *args ) |
| 839 | 839 | { |
| 840 | 840 | thom_floppy_drive* d = thom_floppy_drive_of_image( image ); |
| 841 | 841 | const char* typ = image_filetype( image ); |