2
* tapeimage.c - Common low-level tape image access.
5
* Andreas Boose <viceteam@t-online.de>
7
* This file is part of VICE, the Versatile Commodore Emulator.
8
* See README for copyright notice.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
38
#include "tapeimage.h"
41
int tape_image_close(tape_image_t *tape_image)
45
switch (tape_image->type) {
47
retval = t64_close((t64_t *)tape_image->data);
50
retval = tap_close((tap_t *)tape_image->data);
54
lib_free(tape_image->name);
55
tape_image->name = NULL;
60
int tape_image_open(tape_image_t *tape_image)
64
int initial_read_only = tape_image->read_only;
66
new_t64_tape = t64_open(tape_image->name, &tape_image->read_only);
67
if (new_t64_tape != NULL) {
68
tape_image->data = (void *)new_t64_tape;
69
tape_image->type = TAPE_TYPE_T64;
73
tape_image->read_only = initial_read_only;
74
new_tap_tape = tap_open(tape_image->name, &tape_image->read_only);
75
if (new_tap_tape != NULL) {
76
tape_image->data = (void *)new_tap_tape;
77
tape_image->type = TAPE_TYPE_TAP;
83
/* ------------------------------------------------------------------------- */
85
int tape_image_create(const char *name, unsigned int type)
87
return tap_create(name);
90
/* ------------------------------------------------------------------------- */
92
void tape_get_header(tape_image_t *tape_image, BYTE *name)
94
switch (tape_image->type) {
96
t64_get_header((t64_t *)tape_image->data, name);
99
tap_get_header((tap_t *)tape_image->data, name);
104
tape_file_record_t *tape_get_current_file_record(tape_image_t *tape_image)
106
static tape_file_record_t rec;
108
memset(rec.name, 0, 17);
110
switch (tape_image->type) {
113
t64_file_record_t *t64_rec;
115
t64_rec = t64_get_current_file_record((t64_t *)tape_image->data);
116
memcpy(rec.name, t64_rec->cbm_name, 16);
117
rec.type = (t64_rec->entry_type == T64_FILE_RECORD_FREE) ? 0 : 1;
118
rec.encoding = TAPE_ENCODING_NONE;
119
rec.start_addr = t64_rec->start_addr;
120
rec.end_addr = t64_rec->end_addr;
125
tape_file_record_t *tape_rec;
127
tape_rec = tap_get_current_file_record((tap_t *)tape_image->data);
128
memcpy(rec.name, tape_rec->name, 16);
129
rec.type = tape_rec->type;
130
rec.encoding = tape_rec->encoding;
131
rec.start_addr = tape_rec->start_addr;
132
rec.end_addr = tape_rec->end_addr;
139
int tape_seek_start(tape_image_t *tape_image)
141
switch (tape_image->type) {
143
return t64_seek_start((t64_t *)tape_image->data);
145
return tap_seek_start((tap_t *)tape_image->data);
150
int tape_seek_to_file(tape_image_t *tape_image, unsigned int file_number)
152
switch (tape_image->type) {
154
return t64_seek_to_file((t64_t *)tape_image->data, file_number);
156
return tap_seek_to_file((tap_t *)tape_image->data, file_number);
161
int tape_seek_to_next_file(tape_image_t *tape_image, unsigned int allow_rewind)
163
switch (tape_image->type) {
165
return t64_seek_to_next_file((t64_t *)tape_image->data, allow_rewind);
167
return tap_seek_to_next_file((tap_t *)tape_image->data, allow_rewind);
172
int tape_read(tape_image_t *tape_image, BYTE *buf, size_t size)
174
switch (tape_image->type) {
176
return t64_read((t64_t *)tape_image->data, buf, size);
178
return tap_read((tap_t *)tape_image->data, buf, size);
183
/* ------------------------------------------------------------------------- */
185
void tape_image_init(void)