Skip to content

Commit 296e93a

Browse files
authored
fixed cecb dump (#39)
Added a partial _cecb_seek() to get cecb dump working.
1 parent 2540de3 commit 296e93a

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

build/unix/libcecb/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ CFLAGS += -I../../../include -Wall
1010
$(RANLIB) $@
1111

1212
libcecb.a: libcecbbulkerase.o libcebcopen.o libcecbgs.o libcecbwav.o \
13-
libcecbcas.o libcecbread.o libcecbwrite.o libcecbtokenize.o
13+
libcecbcas.o libcecbread.o libcecbwrite.o libcecbtokenize.o \
14+
libcecbseek.o
1415

1516
clean:
1617
$(RM) *.o *.a

include/cecbpath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ error_code _cecb_bulkerase(char *path, int sample_rate, int bits_per_sample, dou
128128
error_code _cecb_create(cecb_path_id *path, char *pathlist, int mode, int file_type, int data_type, int gap, int ml_load_address, int ml_exec_address);
129129
error_code _cecb_open(cecb_path_id *path, char *pathlist, int mode );
130130
error_code _cecb_close(cecb_path_id path);
131+
error_code _cecb_seek(cecb_path_id path, int pos, int mode);
131132
error_code _cecb_parse_cas( cecb_path_id path );
132133
error_code _cecb_parse_riff( cecb_path_id path );
133134
error_code _cecb_read( cecb_path_id path, void *buffer, u_int *size );

libcecb/libcecbseek.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/********************************************************************
2+
* seek.c - Disk BASIC Seek routine
3+
*
4+
* $Id$
5+
********************************************************************/
6+
7+
#include <stdlib.h>
8+
#include <string.h>
9+
10+
#include "cocotypes.h"
11+
#include "cecbpath.h"
12+
13+
14+
error_code _cecb_seek(cecb_path_id path, int pos, int mode)
15+
{
16+
error_code ec = 0;
17+
18+
19+
if (path->israw == 1)
20+
{
21+
ec = fseek(path->fd, pos, mode);
22+
}
23+
else
24+
{
25+
switch (mode)
26+
{
27+
case SEEK_SET:
28+
if (pos != 0 )
29+
{
30+
fprintf( stderr,
31+
"_cecb_seek(): SEEK_SET only implemented if pos is zero.\n");
32+
ec = -1;
33+
}
34+
35+
if (path->filepos == 0 ) break;
36+
37+
if ((path->tape_type == CAS) || (path->tape_type == C10))
38+
{
39+
path->cas_current_byte = path->cas_start_byte;
40+
path->cas_current_bit = path->cas_start_bit;
41+
fseek(path->fd, path->cas_current_byte, SEEK_SET);
42+
}
43+
else
44+
{
45+
fseek(path->fd, path->wav_data_start, SEEK_SET);
46+
path->wav_current_sample = path->wav_start_sample;
47+
if (path->wav_bits_per_sample == 8)
48+
{
49+
fseek(path->fd, path->wav_start_sample, SEEK_CUR);
50+
}
51+
else if (path->wav_bits_per_sample == 16)
52+
{
53+
fseek(path->fd, path->wav_start_sample*2, SEEK_CUR);
54+
}
55+
else
56+
{
57+
fprintf(stderr, "_cecb_seek: unknown bits per sample\n");
58+
ec = -1;
59+
}
60+
}
61+
62+
path->filepos = pos;
63+
path->eof_flag = 0;
64+
break;
65+
66+
case SEEK_CUR:
67+
fprintf(stderr,
68+
"_cecb_seek(): SEEK_CUR not implemented.\n");
69+
ec = -1;
70+
break;
71+
72+
case SEEK_END:
73+
fprintf(stderr,
74+
"_cecb_seek(): SEEK_END not implemented.\n");
75+
ec = -1;
76+
break;
77+
}
78+
}
79+
80+
81+
return ec;
82+
}
83+

libcoco/libcocoseek.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ error_code _coco_seek(coco_path_id path, int pos, int mode)
3333
break;
3434

3535
case CECB:
36-
fprintf(stderr,
37-
"_coco_seek not implemented in libcecb yet.\n");
38-
ec = -1;
36+
ec = _cecb_seek(path->path.cecb, pos, mode);
3937
break;
4038
}
4139

0 commit comments

Comments
 (0)