-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_hicolour_sldshow.c
192 lines (170 loc) · 8.49 KB
/
generate_hicolour_sldshow.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
Small C utility to generate a hicolour slideshow that will load to screen
from top to down.
(c)2018 Miguel Angel Rodriguez Jodar (mcleod_ideafix). ZX Projects.
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mem.h>
/* See PZX specification for PULS and DATA blocks.
Each hicolour screen is loaded as a headerless turbo block with the
following parameters:
leader tone: 1000 pulses of 1500 T
1st sync pulse: 400 T
2nd sync pulse: 800 T
0 bit pulse: 500 T
1 bit pulse: 1000 T
Last byte: 8 bits
Data has NO flag byte at the beginning and NO checksum at the end.
The DATA block expects 12288 bytes of data (two 6144 blocks shuffled so that
they will load from top to bottom, which is what this little program does).
The DATA block has no flag byte nor checksum!!! The turbo loader routine won't use
either of two and they shouldn't be present in the raw PZX file.
*/
#define PULSOZERO 500
#define PULSOUNO 1000
#define PULSOLEADER 1500
#define LENLEADER (0x8000+1000)
#define SYNC1 400
#define SYNC2 800
const unsigned char DataHeader[40] =
{
// PULS (tono guia para este bloque)
0x50, 0x55, 0x4C, 0x53, 0x08, 0x00, 0x00, 0x00, LENLEADER&0xFF, (LENLEADER>>8)&0xFF,
PULSOLEADER&0xFF, (PULSOLEADER>>8)&0xFF,
SYNC1&0xFF, (SYNC1>>8)&0xFF, SYNC2&0xFF, (SYNC2>>8)&0xFF,
// DATA (los datos propiamente dichos)
0x44, 0x41, 0x54, 0x41, 0x10, 0x30, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00,
0x00, 0x00, 0x02, 0x02,
PULSOZERO&0xFF, (PULSOZERO>>8)&0xFF, PULSOZERO&0xFF, (PULSOZERO>>8)&0xFF,
PULSOUNO&0xFF, (PULSOUNO>>8)&0xFF, PULSOUNO&0xFF, (PULSOUNO>>8)&0xFF
};
/* See PZX specification for PAUS block.
the PAUS block here waits for exactly 3.5 seconds (12250000 T).
The loader program shows each picture for 250 interrupt ticks (3 secs) before
calling the loader routine to load the next one
*/
const unsigned char DataTrail[12] =
{
0x50, 0x41, 0x55, 0x53, 0x04, 0x00, 0x00, 0x00, 0x90, 0xEB, 0xBA, 0x00
};
/*
Just a converted PZX dump of the BASIC loader + MC routine, as generated by PASMO
when you specify --tapbas
See project turboloader
*/
const unsigned char BasicLoader[564] = {
0x50, 0x5A, 0x58, 0x54, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x50, 0x55,
0x4C, 0x53, 0x08, 0x00, 0x00, 0x00, 0x7F, 0x9F, 0x78, 0x08, 0x9B, 0x02,
0xDF, 0x02, 0x44, 0x41, 0x54, 0x41, 0x23, 0x00, 0x00, 0x00, 0x98, 0x00,
0x00, 0x80, 0xB1, 0x03, 0x02, 0x02, 0x57, 0x03, 0x57, 0x03, 0xAE, 0x06,
0xAE, 0x06, 0x00, 0x00, 0x6C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20,
0x20, 0x20, 0x47, 0x00, 0x0A, 0x00, 0x47, 0x00, 0x1B, 0x50, 0x55, 0x4C,
0x53, 0x08, 0x00, 0x00, 0x00, 0x97, 0x8C, 0x78, 0x08, 0x9B, 0x02, 0xDF,
0x02, 0x44, 0x41, 0x54, 0x41, 0x59, 0x00, 0x00, 0x00, 0x48, 0x02, 0x00,
0x80, 0xB1, 0x03, 0x02, 0x02, 0x57, 0x03, 0x57, 0x03, 0xAE, 0x06, 0xAE,
0x06, 0xFF, 0x00, 0x0A, 0x0D, 0x00, 0xFD, 0x34, 0x39, 0x31, 0x35, 0x31,
0x0E, 0x00, 0x00, 0xFF, 0xBF, 0x00, 0x0D, 0x00, 0x14, 0x17, 0x00, 0xF4,
0x32, 0x33, 0x36, 0x31, 0x30, 0x0E, 0x00, 0x00, 0x3A, 0x5C, 0x00, 0x2C,
0x32, 0x35, 0x35, 0x0E, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x0D, 0x00, 0x1E,
0x05, 0x00, 0xEF, 0x22, 0x22, 0xAF, 0x0D, 0x00, 0x28, 0x0E, 0x00, 0xF9,
0xC0, 0x34, 0x39, 0x31, 0x35, 0x32, 0x0E, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x0D, 0x84, 0x50, 0x55, 0x4C, 0x53, 0x08, 0x00, 0x00, 0x00, 0x7F, 0x9F,
0x78, 0x08, 0x9B, 0x02, 0xDF, 0x02, 0x44, 0x41, 0x54, 0x41, 0x23, 0x00,
0x00, 0x00, 0x98, 0x00, 0x00, 0x80, 0xB1, 0x03, 0x02, 0x02, 0x57, 0x03,
0x57, 0x03, 0xAE, 0x06, 0xAE, 0x06, 0x00, 0x03, 0x43, 0x3A, 0x5C, 0x43,
0x4F, 0x4D, 0x50, 0x5C, 0x7A, 0x78, 0x19, 0x01, 0x00, 0xC0, 0x00, 0x80,
0x31, 0x50, 0x55, 0x4C, 0x53, 0x08, 0x00, 0x00, 0x00, 0x97, 0x8C, 0x78,
0x08, 0x9B, 0x02, 0xDF, 0x02, 0x44, 0x41, 0x54, 0x41, 0x2B, 0x01, 0x00,
0x00, 0xD8, 0x08, 0x00, 0x80, 0xB1, 0x03, 0x02, 0x02, 0x57, 0x03, 0x57,
0x03, 0xAE, 0x06, 0xAE, 0x06, 0xFF, 0x3E, 0x02, 0xD3, 0xFF, 0x21, 0x00,
0x40, 0x11, 0x01, 0x40, 0x01, 0xFF, 0x17, 0x75, 0xED, 0xB0, 0x21, 0x00,
0x60, 0x11, 0x01, 0x60, 0x01, 0xFF, 0x17, 0x75, 0xED, 0xB0, 0xDD, 0x21,
0x19, 0xC1, 0x06, 0x00, 0x0E, 0x00, 0x78, 0xCD, 0xB0, 0x22, 0xDD, 0x75,
0x00, 0xDD, 0x74, 0x01, 0xDD, 0x23, 0xDD, 0x23, 0x04, 0x78, 0xFE, 0xC0,
0x20, 0xEA, 0x21, 0x1B, 0xC1, 0x22, 0x17, 0xC1, 0xDD, 0x21, 0x00, 0x40,
0x11, 0x00, 0x30, 0xCD, 0x53, 0xC0, 0xAF, 0xD3, 0xFE, 0x06, 0x96, 0x76,
0x10, 0xFD, 0xC3, 0x38, 0xC0, 0xF3, 0x0E, 0x02, 0x2E, 0x00, 0xCD, 0xD2,
0xC0, 0x28, 0xF9, 0x30, 0x6A, 0x78, 0xFE, 0x15, 0x38, 0xF2, 0xCD, 0xD2,
0xC0, 0x28, 0xED, 0x30, 0x5E, 0x78, 0xFE, 0x15, 0x38, 0xE6, 0x2C, 0xC2,
0x58, 0xC0, 0xCD, 0xD2, 0xC0, 0x28, 0xDD, 0x30, 0x4E, 0x78, 0xFE, 0x08,
0x30, 0xF4, 0xCD, 0xD2, 0xC0, 0x28, 0xD1, 0x30, 0x42, 0x78, 0xFE, 0x08,
0x38, 0xE8, 0x79, 0xEE, 0x04, 0x4F, 0x2E, 0x01, 0xCD, 0xEB, 0xC0, 0x28,
0xBD, 0x30, 0x30, 0x3E, 0x1B, 0xB8, 0xCB, 0x15, 0xD2, 0x92, 0xC0, 0xDD,
0x75, 0x00, 0xDD, 0x7C, 0xAC, 0xDD, 0x67, 0xA4, 0xC2, 0xAF, 0xC0, 0xDD,
0x23, 0x1B, 0x7B, 0xE6, 0x3F, 0xC2, 0xC4, 0xC0, 0x2A, 0x17, 0xC1, 0x7E,
0x23, 0x46, 0x23, 0x22, 0x17, 0xC1, 0xDD, 0x60, 0xDD, 0x6F, 0x7A, 0xB3,
0xC2, 0x90, 0xC0, 0x3A, 0x48, 0x5C, 0xE6, 0x07, 0xD3, 0xFE, 0xFB, 0xC9,
0x06, 0x00, 0x26, 0x20, 0x3E, 0x7F, 0xDB, 0xFE, 0x1F, 0xD0, 0x04, 0xC8,
0xA9, 0xA4, 0xCA, 0xD6, 0xC0, 0x79, 0xEE, 0x2F, 0xD3, 0xFE, 0x4F, 0x37,
0xC9, 0x06, 0x00, 0x26, 0x20, 0x3E, 0x7F, 0xDB, 0xFE, 0x1F, 0xD0, 0x04,
0xC8, 0xA9, 0xA4, 0xCA, 0xEF, 0xC0, 0x79, 0xEE, 0x2F, 0xD3, 0xFE, 0x4F,
0x3E, 0x7F, 0xDB, 0xFE, 0x1F, 0xD0, 0x04, 0xC8, 0xA9, 0xA4, 0xCA, 0x02,
0xC1, 0x79, 0xEE, 0x2F, 0xD3, 0xFE, 0x4F, 0x37, 0xC9, 0x19, 0xC1, 0xAD
};
#define LDATA (sizeof DataHeader + 6144*2 + sizeof DataTrail)
void ShuffleScreens (FILE *f, FILE *fpzx)
{
unsigned char *scr1, *scr2, *res, *p;
unsigned line, addr, scan;
scr1 = malloc (6144 * sizeof *scr1);
scr2 = malloc (6144 * sizeof *scr2);
res = malloc (LDATA * sizeof *res);
p = res + sizeof DataHeader; // offset within turbo data block where screen data actually resides
fread (scr1, 1, 6144, f);
fread (scr2, 1, 6144, f);
// copy PZX turbo data definition (pulses, duration, etc) and trail (3.5 secs. pause)
memcpy (res, DataHeader, sizeof DataHeader);
memcpy (res + (sizeof DataHeader + 6144*2), DataTrail, sizeof DataTrail);
for (line=0;line<192;line++)
{
addr = (line/64)*2048+(line%8)*256+((line/8)%8)*32; // get screen (file actually) address for line
for (scan=0;scan<32;scan++)
{
*p=scr1[addr+scan];
p++;
*p=scr2[addr+scan];
p++;
}
}
fwrite (res, 1, LDATA, fpzx); // dump complete turbo data block to PZX output file
free (scr1);
free (scr2);
free (res);
}
void WritePZXHeaderBASICandMC (FILE *fpzx)
{
fwrite (BasicLoader, 1, sizeof BasicLoader, fpzx); // dump basic loader and MC routines to PZX output file
}
int main()
{
FILE *f, *fpzx;
int count;
char nf[256];
count = 1;
fpzx = fopen ("sldshow.pzx", "wb"); // PZX output filename. Change it if you will.
WritePZXHeaderBASICandMC (fpzx);
while (1)
{
sprintf (nf, "scr%02.2d.scr", count++); // hicolour screens are assumed to be named scr01.scr, scr02.scr, scr03.scr, etc.
f = fopen (nf, "rb");
if (!f) // we load screens and add it to the PZX output file until the file sequence is broken
break;
ShuffleScreens (f, fpzx);
fclose (f);
printf ("Added: %s\n", nf);
}
fclose (fpzx);
return 0;
}