OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [mp3/] [sw/] [mad-xess/] [fsyst.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 291 simons
#ifdef HAVE_CONFIG_H
2
# include "config.h"
3
#endif
4
 
5
#ifndef EMBED
6
# include <assert.h>
7
# include <string.h>
8
#else
9
# warning assert checking disabled
10
# define assert(x)
11
#endif
12
 
13
#include "fsyst.h"
14
 
15
/* Return next file.  */
16
 
17
inline struct file_struct *
18
next_file (struct file_struct *file) {
19
  return (struct file_struct *)((unsigned char *)file + swap(file->length));
20
}
21
 
22
/* Returns file, that holds track number.  */
23
 
24
struct file_struct *
25
find_track_no (int no, struct file_struct *root) {
26
  assert(swap(root->type) == FT_ROOT);
27
  while (swap(root->type) != FT_END) {
28
    if (swap(root->type) == FT_TRACK_NO && swap(root->data[0]) == no)
29
      return root;
30
    root = next_file (root);
31
  }
32
  return 0;
33
}
34
 
35
/* Returns track name from file struct, pointing at FT_TRACK_NO.  */
36
 
37
char *
38
track_name (struct file_struct *fs) {
39
  assert(swap(fs->type) == FT_TRACK_NO);
40
  fs = next_file (fs);
41
  if (swap(fs->type) == FT_TRACK_NAME)
42
    return (char *)&fs->data[0];
43
  else
44
    return "";
45
}
46
 
47
/* Returns track data from file struct, pointing at FT_TRACK_NO.  */
48
 
49
struct file_struct *
50
track_data (struct file_struct *fs) {
51
  assert(swap(fs->type) == FT_TRACK_NO);
52
  fs = next_file (fs);
53
  if (swap(fs->type) == FT_TRACK_NAME)
54
    fs = next_file (fs);
55
  assert (swap(fs->type) == FT_TRACK_DATA);
56
  return fs;
57
}
58
 
59
/* Finds last record.  */
60
 
61
inline struct file_struct *
62
end_file (struct file_struct *root) {
63
  assert(swap(root->type) == FT_ROOT);
64
  while (swap(root->type) != FT_END)
65
    root = next_file (root);
66
  return root;
67
}
68
 
69
/* Adds file to the end of file list.  Returns new file address, if
70
   sucessful, otherwise NULL.  */
71
 
72
struct file_struct *
73
add_file (struct file_struct *root, struct file_struct *file) {
74
  struct file_struct *end = end_file (root);
75
  memcpy (end, file, file->length);
76
  file = end;
77
  end = next_file (end);
78
  end->type = swap(FT_END);
79
  end->length = swap(0);
80
  return file;
81
}
82
 
83
/* Initializes filesystem at root.  */
84
 
85
void
86
init_fsyst (struct file_struct *root) {
87
  root->type = swap(FT_ROOT);
88
  root->length = swap(sizeof (struct file_struct) - sizeof (unsigned int));
89
  root = next_file (root);
90
  root->type = swap(FT_END);
91
  root->length = swap(0);
92
}
93
 
94
#ifndef EMBED
95
unsigned int swap (unsigned int x) {
96
  return (x & 0xFF) << 24
97
    | (x & 0xFF00) << 8
98
    | (x & 0xFF0000) >> 8
99
    | (x & 0xFF000000) >> 24;
100
}
101
#endif
102
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.