more scanline shader parameters
[zxemut.git] / lstape.d
bloba37905b80280c18243ac0807cc07286518ba41a3
1 /* ZX Spectrum Emulator
2 * Copyright (C) 2017 Ketmar // Invisible Vector
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module lstape;
18 version(Posix) {
19 pragma(lib, "spectrum");
21 enum LibSpectrumHere = true;
23 extern(C) nothrow @nogc:
26 const int LIBSPECTRUM_TAPE_FLAGS_BLOCK; /* End of block */
27 const int LIBSPECTRUM_TAPE_FLAGS_STOP; /* Stop tape */
28 const int LIBSPECTRUM_TAPE_FLAGS_STOP48; /* Stop tape if in 48K mode */
29 const int LIBSPECTRUM_TAPE_FLAGS_NO_EDGE; /* Edge isn't really an edge */
30 const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW; /* Set level low */
31 const int LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH; /* Set level high */
32 const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_SHORT;/* Short edge; used for loader acceleration */
33 const int LIBSPECTRUM_TAPE_FLAGS_LENGTH_LONG; /* Long edge; used for loader acceleration */
34 const int LIBSPECTRUM_TAPE_FLAGS_TAPE; /* Tape has finished */
37 alias libspectrum_byte = ubyte;
38 alias libspectrum_dword = uint;
40 /* The states which a block can be in */
41 alias libspectrum_tape_state_type = int;
42 enum /*libspectrum_tape_state_type*/ : int {
43 LIBSPECTRUM_TAPE_STATE_INVALID = 0,
45 LIBSPECTRUM_TAPE_STATE_PILOT, /* Pilot pulses */
46 LIBSPECTRUM_TAPE_STATE_SYNC1, /* First sync pulse */
47 LIBSPECTRUM_TAPE_STATE_SYNC2, /* Second sync pulse */
48 LIBSPECTRUM_TAPE_STATE_DATA1, /* First edge of a data bit */
49 LIBSPECTRUM_TAPE_STATE_DATA2, /* Second edge of a data bit */
50 LIBSPECTRUM_TAPE_STATE_PAUSE, /* The pause at the end of a block */
51 LIBSPECTRUM_TAPE_STATE_TAIL, /* The pulse at the end of a block */
55 /* The various errors which can occur */
56 alias libspectrum_error = int;
57 enum /*libspectrum_error*/ : int {
58 LIBSPECTRUM_ERROR_NONE = 0,
60 LIBSPECTRUM_ERROR_WARNING,
62 LIBSPECTRUM_ERROR_MEMORY,
63 LIBSPECTRUM_ERROR_UNKNOWN,
64 LIBSPECTRUM_ERROR_CORRUPT,
65 LIBSPECTRUM_ERROR_SIGNATURE,
66 LIBSPECTRUM_ERROR_SLT, /* .slt data found at end of a .z80 file */
67 LIBSPECTRUM_ERROR_INVALID, /* Invalid parameter supplied */
69 LIBSPECTRUM_ERROR_LOGIC = -1,
73 /* Various types of file we might manage to identify */
74 alias libspectrum_id_t = int;
75 enum /*libspectrum_id_t*/ : int {
76 /* These types present in all versions of libspectrum */
78 LIBSPECTRUM_ID_UNKNOWN = 0, /* Unidentified file */
79 LIBSPECTRUM_ID_RECORDING_RZX, /* RZX input recording */
80 LIBSPECTRUM_ID_SNAPSHOT_SNA, /* .sna snapshot */
81 LIBSPECTRUM_ID_SNAPSHOT_Z80, /* .z80 snapshot */
82 LIBSPECTRUM_ID_TAPE_TAP, /* Z80-style .tap tape image */
83 LIBSPECTRUM_ID_TAPE_TZX, /* TZX tape image */
85 /* Below here, present only in 0.1.1 and later */
87 /* The next entry is deprecated in favour of the more specific
88 LIBSPECTRUM_ID_DISK_CPC and LIBSPECTRUM_ID_DISK_ECPC */
89 LIBSPECTRUM_ID_DISK_DSK, /* .dsk +3 disk image */
91 LIBSPECTRUM_ID_DISK_SCL, /* .scl TR-DOS disk image */
92 LIBSPECTRUM_ID_DISK_TRD, /* .trd TR-DOS disk image */
93 LIBSPECTRUM_ID_CARTRIDGE_DCK, /* .dck Timex cartridge image */
95 /* Below here, present only in 0.2.0 and later */
97 LIBSPECTRUM_ID_TAPE_WARAJEVO, /* Warajevo-style .tap tape image */
99 LIBSPECTRUM_ID_SNAPSHOT_PLUSD, /* DISCiPLE/+D snapshot */
100 LIBSPECTRUM_ID_SNAPSHOT_SP, /* .sp snapshot */
101 LIBSPECTRUM_ID_SNAPSHOT_SNP, /* .snp snapshot */
102 LIBSPECTRUM_ID_SNAPSHOT_ZXS, /* .zxs snapshot (zx32) */
103 LIBSPECTRUM_ID_SNAPSHOT_SZX, /* .szx snapshot (Spectaculator) */
105 /* Below here, present only in 0.2.1 and later */
107 LIBSPECTRUM_ID_COMPRESSED_BZ2, /* bzip2 compressed file */
108 LIBSPECTRUM_ID_COMPRESSED_GZ, /* gzip compressed file */
110 /* Below here, present only in 0.2.2 and later */
112 LIBSPECTRUM_ID_HARDDISK_HDF, /* .hdf hard disk image */
113 LIBSPECTRUM_ID_CARTRIDGE_IF2, /* .rom Interface 2 cartridge image */
115 /* Below here, present only in 0.3.0 and later */
117 LIBSPECTRUM_ID_MICRODRIVE_MDR, /* .mdr microdrive cartridge */
118 LIBSPECTRUM_ID_TAPE_CSW, /* .csw tape image */
119 LIBSPECTRUM_ID_TAPE_Z80EM, /* Z80Em tape image */
121 /* Below here, present only in 0.4.0 and later */
123 LIBSPECTRUM_ID_TAPE_WAV, /* .wav tape image */
124 LIBSPECTRUM_ID_TAPE_SPC, /* SP-style .spc tape image */
125 LIBSPECTRUM_ID_TAPE_STA, /* Speculator-style .sta tape image */
126 LIBSPECTRUM_ID_TAPE_LTP, /* Nuclear ZX-style .ltp tape image */
127 LIBSPECTRUM_ID_COMPRESSED_XFD, /* xfdmaster (Amiga) compressed file */
128 LIBSPECTRUM_ID_DISK_IMG, /* .img DISCiPLE/+D disk image */
129 LIBSPECTRUM_ID_DISK_MGT, /* .mgt DISCiPLE/+D disk image */
131 /* Below here, present only in 0.5.0 and later */
133 LIBSPECTRUM_ID_DISK_UDI, /* .udi generic disk image */
134 LIBSPECTRUM_ID_DISK_FDI, /* .fdi generic disk image */
135 LIBSPECTRUM_ID_DISK_CPC, /* .dsk plain CPC +3 disk image */
136 LIBSPECTRUM_ID_DISK_ECPC, /* .dsk extended CPC +3 disk image */
137 LIBSPECTRUM_ID_DISK_SAD, /* .sad generic disk image */
138 LIBSPECTRUM_ID_DISK_TD0, /* .td0 generic disk image */
140 /* Below here, present only in 1.0.0 and later */
142 LIBSPECTRUM_ID_DISK_OPD, /* .opu/.opd Opus Discovery disk image */
144 /* Below here, present only in 1.1.0 and later */
146 LIBSPECTRUM_ID_TAPE_PZX, /* PZX tape image */
148 LIBSPECTRUM_ID_AUX_POK, /* POKE file */
150 /* Below here, present only in 1.2.0 and later */
152 LIBSPECTRUM_ID_DISK_D80, /* .d80/.d40 Didaktik disk image */
154 /* Below here, present only in 1.2.2 and later */
156 LIBSPECTRUM_ID_COMPRESSED_ZIP, /* zip compressed file */
160 /* A linked list of tape blocks */
161 struct libspectrum_tape {}
162 struct libspectrum_tape_block {}
163 //alias libspectrum_tape_iterator = libspectrum_tape_iterator_s;
164 //struct libspectrum_tape_iterator_s {}
166 libspectrum_dword libspectrum_tape_block_length (libspectrum_tape_block* block);
168 libspectrum_tape *libspectrum_tape_alloc ();
170 /* Free the memory used by the blocks in a libspectrum_tape object, but
171 not the object itself; useful if you're about to read a new tape into
172 a current object. */
173 libspectrum_error libspectrum_tape_clear (libspectrum_tape* tape);
175 libspectrum_error libspectrum_tape_free (libspectrum_tape* tape);
177 /* Take the tape image of type `type' of `length' bytes starting at
178 `buffer' and convert it to a `libspectrum_tape' structure. If `type'
179 is `LIBSPECTRUM_ID_UNKNOWN', guess the file format via
180 `libspectrum_identify_file'; `filename' is generally used only to help
181 with the identification process and can be set to NULL (or anything
182 else) if `type' is not `LIBSPECTRUM_ID_UNKNOWN' unless the tape is a
183 WAV file where the underlying audiofile library will reread the
184 file and will not use the buffer. Tape images compressed with
185 bzip2 or gzip will be automatically and transparently decompressed.
187 libspectrum_error libspectrum_tape_read (libspectrum_tape* tape, const(libspectrum_byte)* buffer, size_t length, libspectrum_id_t type, const(char)* filename=null);
189 /* Take the snapshot in `tape and serialise it as a `type' format file
190 into `*buffer'. On entry, '*buffer' is assumed to be allocated
191 '*length' bytes, and will grow if necessary; if '*length' is zero,
192 '*buffer' can be uninitialised on entry.
194 libspectrum_error libspectrum_tape_write (libspectrum_byte** buffer, size_t* length, libspectrum_tape* tape, libspectrum_id_t type);
196 /* Does this tape structure actually contain a tape? */
197 int libspectrum_tape_present (const(libspectrum_tape)* tape);
199 /* This is the main workhorse function of the tape routines and will
200 return in `tstates' the number of tstates until the next edge should
201 occur from `tape'. `flags' will be set to the bitwise or of the
202 following:
204 LIBSPECTRUM_TAPE_FLAGS_BLOCK The current block ends with this edge
205 LIBSPECTRUM_TAPE_FLAGS_STOP User code should stop playing the tape after this edge
206 LIBSPECTRUM_TAPE_FLAGS_STOP48 User code should stop playing the tape after this edge if it was emulating a 48K machine.
207 The desired behaviour for things like the TC2048 is undefined in the .tzx format :-(
208 LIBSPECTRUM_TAPE_FLAGS_LEVEL_LOW The input signal from the tape should be forced low at this edge
209 LIBSPECTRUM_TAPE_FLAGS_LEVEL_HIGH The input signal from the tape should be forced high at this edge
210 LIBSPECTRUM_TAPE_FLAGS_NO_EDGE This "edge" isn't really an edge and doesn't change the input signal from the tape.
212 libspectrum_error libspectrum_tape_get_next_edge (libspectrum_dword* tstates, int* flags, libspectrum_tape* tape);
214 /* Get the current block from the tape */
215 libspectrum_tape_block* libspectrum_tape_current_block (libspectrum_tape* tape);
217 /* Get the state of the active block on the tape */
218 libspectrum_tape_state_type libspectrum_tape_state (libspectrum_tape* tape);
220 /* Set the state of the active block on the tape */
221 libspectrum_error libspectrum_tape_set_state (libspectrum_tape* tape, libspectrum_tape_state_type state);
223 /* Peek at the next block on the tape */
224 libspectrum_tape_block* libspectrum_tape_peek_next_block (libspectrum_tape* tape);
226 /* Peek at the last block on the tape */
227 libspectrum_tape_block* libspectrum_tape_peek_last_block (libspectrum_tape* tape);
229 /* Cause the next block on the tape to be active, initialise it and return it */
230 libspectrum_tape_block* libspectrum_tape_select_next_block (libspectrum_tape* tape);
232 /* Return in `n' the position of the current block on the tape. The first
233 block is block 0, the second block 1, etc.
235 libspectrum_error libspectrum_tape_position (int* n, libspectrum_tape* tape);
237 /* Select the nth block on the tape */
238 libspectrum_error libspectrum_tape_nth_block (libspectrum_tape* tape, int n);
240 /* Append a block to the current tape */
241 //void libspectrum_tape_append_block (libspectrum_tape* tape, libspectrum_tape_block* block);
243 //void libspectrum_tape_remove_block (libspectrum_tape* tape, libspectrum_tape_iterator it);
245 //libspectrum_error libspectrum_tape_insert_block (libspectrum_tape* tape, libspectrum_tape_block* block, size_t position);
247 /*** Routines for iterating through a tape ***/
249 libspectrum_tape_block* libspectrum_tape_iterator_init (libspectrum_tape_iterator* iterator, libspectrum_tape* tape);
250 libspectrum_tape_block* libspectrum_tape_iterator_current (libspectrum_tape_iterator iterator);
251 libspectrum_tape_block* libspectrum_tape_iterator_next (libspectrum_tape_iterator* iterator);
254 } else {
255 enum LibSpectrumHere = false;