-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.c
85 lines (66 loc) · 2.27 KB
/
utilities.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* utilities.c: miscellaneous utility routines
Copyright (c) 2011 Philip Kendall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: Philip Kendall <philip-fuse@shadowmagic.org.uk>
*/
#include "config.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* #ifdef HAVE_STRING_H */
#include "internals.h"
#define TZX_HZ 3500000
static const libspectrum_dword tstates_per_ms = TZX_HZ / 1000;
libspectrum_dword
libspectrum_ms_to_tstates( libspectrum_dword ms )
{
return ms * tstates_per_ms;
}
libspectrum_dword
libspectrum_tstates_to_ms( libspectrum_dword tstates )
{
return tstates / tstates_per_ms;
}
void
libspectrum_set_pause_ms( libspectrum_tape_block *block,
libspectrum_dword pause_ms )
{
libspectrum_tape_block_set_pause( block, pause_ms );
libspectrum_tape_block_set_pause_tstates( block,
libspectrum_ms_to_tstates( pause_ms ) );
}
void
libspectrum_set_pause_tstates( libspectrum_tape_block *block,
libspectrum_dword pause_tstates )
{
libspectrum_tape_block_set_pause_tstates( block, pause_tstates );
libspectrum_tape_block_set_pause( block,
libspectrum_tstates_to_ms( pause_tstates ) );
}
size_t
libspectrum_bits_to_bytes( size_t bits )
{
return ( bits + LIBSPECTRUM_BITS_IN_BYTE - 1 ) / LIBSPECTRUM_BITS_IN_BYTE;
}
char*
libspectrum_safe_strdup( const char *src )
{
size_t length;
char *dest = NULL;
if( src ) {
length = strlen( src ) + 1;
dest = libspectrum_new( char, length );
memcpy( dest, src, length );
}
return dest;
}