File: edges.c

package info (click to toggle)
libspectrum 1.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,156 kB
  • sloc: ansic: 22,793; sh: 4,154; perl: 461; makefile: 178
file content (66 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "test.h"

test_return_t
check_edges( const char *filename, test_edge_sequence_t *edges,
	     int flags_mask )
{
  libspectrum_byte *buffer = NULL;
  size_t filesize = 0;
  libspectrum_tape *tape;
  test_return_t r = TEST_FAIL;
  test_edge_sequence_t *ptr = edges;

  if( read_file( &buffer, &filesize, filename ) ) return TEST_INCOMPLETE;

  tape = libspectrum_tape_alloc();

  if( libspectrum_tape_read( tape, buffer, filesize, LIBSPECTRUM_ID_UNKNOWN,
			     filename ) != LIBSPECTRUM_ERROR_NONE ) {
    libspectrum_tape_free( tape );
    libspectrum_free( buffer );
    return TEST_INCOMPLETE;
  }

  libspectrum_free( buffer );

  while( 1 ) {

    libspectrum_dword tstates;
    int flags;
    libspectrum_error e;

    e = libspectrum_tape_get_next_edge( &tstates, &flags, tape );
    if( e ) {
      libspectrum_tape_free( tape );
      return TEST_INCOMPLETE;
    }

    flags &= flags_mask;

    if( tstates != ptr->length || flags != ptr->flags ) {
      fprintf( stderr, "%s: expected %u tstates and flags %d, got %u tstates and flags %d\n",
	       progname, ptr->length, ptr->flags, tstates, flags );
      break;
    }

    if( tstates != ptr->length ) {
      fprintf( stderr, "%s: expected %u tstates, got %u tstates\n", progname,
	       ptr->length, tstates );
      break;
    }

    if( --ptr->count == 0 ) {
      ptr++;
      if( ptr->length == -1 ) {
	r = TEST_PASS;
	break;
      }
    }
  }

  if( libspectrum_tape_free( tape ) ) return TEST_INCOMPLETE;

  return r;
}