-
Notifications
You must be signed in to change notification settings - Fork 1
/
slt.c
164 lines (117 loc) · 3.71 KB
/
slt.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* slt.c: SLT data handling routines
Copyright (c) 2004 Philip Kendall
$Id: slt.c 3389 2007-12-03 12:54:17Z fredm $
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: [email protected]
*/
#include <config.h>
#include <string.h>
#include <libspectrum.h>
#include "module.h"
#include "settings.h"
#include "slt.h"
#include "spectrum.h"
#include "ui/ui.h"
/* .slt level data */
static libspectrum_byte *slt[256];
static size_t slt_length[256];
static libspectrum_byte *slt_screen; /* The screenshot from the .slt file */
static int slt_screen_level; /* The level of the screenshot.
Not used for anything AFAIK */
static void slt_from_snapshot( libspectrum_snap *snap );
static void slt_to_snapshot( libspectrum_snap *snap );
static module_info_t slt_module_info = {
NULL,
NULL,
NULL,
slt_from_snapshot,
slt_to_snapshot,
};
int
slt_init( void )
{
module_register( &slt_module_info );
return 0;
}
int
slt_trap( libspectrum_word address, libspectrum_byte level )
{
size_t length;
libspectrum_byte *data;
if( !settings_current.slt_traps ) return 0;
if( slt_length[ level ] ) {
length = slt_length[ level ];
data = slt[ level ];
while( length-- ) writebyte( address++, *data++ );
}
return 0;
}
static void
slt_from_snapshot( libspectrum_snap *snap )
{
size_t i;
for( i=0; i<256; i++ ) {
slt_length[i] = libspectrum_snap_slt_length( snap, i );
if( slt_length[i] ) {
slt[i] = memory_pool_allocate( slt_length[i] *
sizeof( libspectrum_byte ) );
if( !slt[i] ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__,
__LINE__ );
return;
}
memcpy( slt[i], libspectrum_snap_slt( snap, i ),
libspectrum_snap_slt_length( snap, i ) );
}
}
if( libspectrum_snap_slt_screen( snap ) ) {
slt_screen = memory_pool_allocate( 6912 * sizeof( libspectrum_byte ) );
if( !slt_screen ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__, __LINE__ );
return;
}
memcpy( slt_screen, libspectrum_snap_slt_screen( snap ), 6912 );
slt_screen_level = libspectrum_snap_slt_screen_level( snap );
}
}
static void
slt_to_snapshot( libspectrum_snap *snap )
{
size_t i;
libspectrum_byte *buffer;
for( i=0; i<256; i++ ) {
libspectrum_snap_set_slt_length( snap, i, slt_length[i] );
if( slt_length[i] ) {
libspectrum_byte *buffer;
buffer = malloc( slt_length[i] * sizeof(libspectrum_byte) );
if( !buffer ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__,
__LINE__ );
return;
}
memcpy( buffer, slt[i], slt_length[i] );
libspectrum_snap_set_slt( snap, i, buffer );
}
}
if( slt_screen ) {
buffer = malloc( 6912 * sizeof( libspectrum_byte ) );
if( !buffer ) {
ui_error( UI_ERROR_ERROR, "Out of memory at %s:%d", __FILE__, __LINE__ );
return;
}
memcpy( buffer, slt_screen, 6912 );
libspectrum_snap_set_slt_screen( snap, buffer );
libspectrum_snap_set_slt_screen_level( snap, slt_screen_level );
}
}