~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/tape/tapeimage.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-03-27 13:06:04 UTC
  • mfrom: (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050327130604-zodmv0i60dbbmcik
Tags: 1.16-3
Apply patch from Andreas Jochens <aj@andaco.de> to correct building on
AMD64 and GCC 4.x (closes: #300936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * tapeimage.c - Common low-level tape image access.
 
3
 *
 
4
 * Written by
 
5
 *  Andreas Boose <viceteam@t-online.de>
 
6
 *
 
7
 * This file is part of VICE, the Versatile Commodore Emulator.
 
8
 * See README for copyright notice.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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
 
23
 *  02111-1307  USA.
 
24
 *
 
25
 */
 
26
 
 
27
#include "vice.h"
 
28
 
 
29
#include <stdio.h>
 
30
#include <stdlib.h>
 
31
#include <string.h>
 
32
 
 
33
#include "lib.h"
 
34
#include "log.h"
 
35
#include "t64.h"
 
36
#include "tap.h"
 
37
#include "tape.h"
 
38
#include "tapeimage.h"
 
39
 
 
40
 
 
41
int tape_image_close(tape_image_t *tape_image)
 
42
{
 
43
    int retval = 0;
 
44
 
 
45
    switch (tape_image->type) {
 
46
      case TAPE_TYPE_T64:
 
47
        retval = t64_close((t64_t *)tape_image->data);
 
48
        break;
 
49
      case TAPE_TYPE_TAP:
 
50
        retval = tap_close((tap_t *)tape_image->data);
 
51
        break;
 
52
    }
 
53
 
 
54
    lib_free(tape_image->name);
 
55
    tape_image->name = NULL;
 
56
 
 
57
    return retval;
 
58
}
 
59
 
 
60
int tape_image_open(tape_image_t *tape_image)
 
61
{
 
62
    t64_t *new_t64_tape;
 
63
    tap_t *new_tap_tape;
 
64
    int initial_read_only = tape_image->read_only;
 
65
 
 
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;
 
70
        return 0;
 
71
    }
 
72
 
 
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;
 
78
        return 0;
 
79
    }
 
80
 
 
81
    return -1;
 
82
}
 
83
/* ------------------------------------------------------------------------- */
 
84
 
 
85
int tape_image_create(const char *name, unsigned int type)
 
86
{
 
87
    return tap_create(name);
 
88
}
 
89
 
 
90
/* ------------------------------------------------------------------------- */
 
91
 
 
92
void tape_get_header(tape_image_t *tape_image, BYTE *name)
 
93
{
 
94
    switch (tape_image->type) {
 
95
      case TAPE_TYPE_T64:
 
96
        t64_get_header((t64_t *)tape_image->data, name);
 
97
        break;
 
98
      case TAPE_TYPE_TAP:
 
99
        tap_get_header((tap_t *)tape_image->data, name);
 
100
        break;
 
101
    }
 
102
}
 
103
 
 
104
tape_file_record_t *tape_get_current_file_record(tape_image_t *tape_image)
 
105
{
 
106
    static tape_file_record_t rec;
 
107
 
 
108
    memset(rec.name, 0, 17);
 
109
 
 
110
    switch (tape_image->type) {
 
111
      case TAPE_TYPE_T64:
 
112
        {
 
113
            t64_file_record_t *t64_rec;
 
114
 
 
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;
 
121
            break;
 
122
        }
 
123
      case TAPE_TYPE_TAP:
 
124
        {
 
125
            tape_file_record_t *tape_rec;
 
126
 
 
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;
 
133
            break;
 
134
        }
 
135
    }
 
136
    return &rec;
 
137
}
 
138
 
 
139
int tape_seek_start(tape_image_t *tape_image)
 
140
{
 
141
    switch (tape_image->type) {
 
142
      case TAPE_TYPE_T64:
 
143
        return t64_seek_start((t64_t *)tape_image->data);
 
144
      case TAPE_TYPE_TAP:
 
145
        return tap_seek_start((tap_t *)tape_image->data);
 
146
    }
 
147
    return -1;
 
148
}
 
149
 
 
150
int tape_seek_to_file(tape_image_t *tape_image, unsigned int file_number)
 
151
{
 
152
    switch (tape_image->type) {
 
153
      case TAPE_TYPE_T64:
 
154
        return t64_seek_to_file((t64_t *)tape_image->data, file_number);
 
155
      case TAPE_TYPE_TAP:
 
156
        return tap_seek_to_file((tap_t *)tape_image->data, file_number);
 
157
    }
 
158
    return -1;
 
159
}
 
160
 
 
161
int tape_seek_to_next_file(tape_image_t *tape_image, unsigned int allow_rewind)
 
162
{
 
163
    switch (tape_image->type) {
 
164
      case TAPE_TYPE_T64:
 
165
        return t64_seek_to_next_file((t64_t *)tape_image->data, allow_rewind);
 
166
      case TAPE_TYPE_TAP:
 
167
        return tap_seek_to_next_file((tap_t *)tape_image->data, allow_rewind);
 
168
    }
 
169
    return -1;
 
170
}
 
171
 
 
172
int tape_read(tape_image_t *tape_image, BYTE *buf, size_t size)
 
173
{
 
174
    switch (tape_image->type) {
 
175
      case TAPE_TYPE_T64:
 
176
        return t64_read((t64_t *)tape_image->data, buf, size);
 
177
      case TAPE_TYPE_TAP:
 
178
        return tap_read((tap_t *)tape_image->data, buf, size);
 
179
    }
 
180
    return -1;
 
181
}
 
182
 
 
183
/* ------------------------------------------------------------------------- */
 
184
 
 
185
void tape_image_init(void)
 
186
{
 
187
}
 
188