forked from captainjack64/hacktv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syster.h
executable file
·146 lines (113 loc) · 4.05 KB
/
syster.h
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
/* Nagravision Syster encoder for hacktv */
/*=======================================================================*/
/* Copyright 2018 Alex L. James */
/* Copyright 2018 Philip Heron <[email protected]> */
/* */
/* 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 <http://www.gnu.org/licenses/>. */
#ifndef _SYSTER_H
#define _SYSTER_H
#include <stdint.h>
#include "video.h"
#define NG_SAMPLE_RATE 4437500
#define NG_VBI_WIDTH 284
#define NG_VBI_BYTES 28
#define NG_MSG_BYTES 84
#define NG_FIELD_1_START 23
#define NG_FIELD_2_START 336
#define NG_LINES_PER_FIELD 287
#define D11_FIELD_1_START 23
#define D11_FIELD_2_START 335
#define D11_LINES_PER_FIELD 286
#define D11_FIELDS 6
#define NG_ENCRYPT 1
#define NG_DECRYPT 0
/* Cut and rotate defines */
#define SCNR_WIDTH (NG_SAMPLE_RATE / 25 / 625) /* 284 */
#define SCNR_LEFT 46
#define SCNR_TOTAL_CUTS 230
#define RANDOM_ECM 0
#define STATIC_ECM 1
/* NG_DELAY_LINES needs to be long enough for the scrambler to access any
* line in the next field from at least the last 32 lines of the current.
* This is a safe amount and can probably be reduced. */
#define NG_DELAY_LINES (625 + NG_FIELD_1_START + NG_LINES_PER_FIELD - (NG_FIELD_2_START + NG_LINES_PER_FIELD - 32))
/* Entitlement control messages */
typedef struct {
uint64_t cw;
uint8_t ecm[16];
} ng_ecm_t;
typedef struct {
char *id; /* Provider string */
uint8_t key[8]; /* DES decryption key */
uint8_t data[8]; /* Programme provider data */
/*
data[0] = window (operator?)
data[1] = channel
data[2] = audience (0x11 = free access)
data[3] = ??
data[4] = date
data[5] = date
data[6] = PPV date
data[7] = PPV date
*/
char *date; /* Broadcast date */
int vbioffset; /* VBI offset */
int t; /* Key table to use */
} ng_mode_t;
typedef struct {
uint8_t flags;
/* ECM */
ng_ecm_t *blocks;
ng_mode_t *mode;
int id;
/* Permute tables */
const uint8_t *table;
/* VBI */
int16_t *lut;
uint8_t vbi[10][NG_VBI_BYTES];
int vbi_seq;
int block_seq;
/* EMM */
int next_ppua;
/* PRBS state */
uint64_t cw;
uint32_t sr1;
uint32_t sr2;
/* PRNG seed values */
int s; /* 0, ..., 127 */
int r; /* 0, ..., 255 */
/* The line order for the next field (0-287) */
int order[NG_LINES_PER_FIELD];
/* Syster delay line */
int16_t *delay;
int16_t *delay_line[NG_DELAY_LINES];
/* D11 delay values */
int ng_delay;
int d11_line_delay[D11_LINES_PER_FIELD * D11_FIELDS];
/* Audio inversion FIR filter */
int16_t *firli, *firlq; /* Left channel, I + Q */
int16_t *firri, *firrq; /* Right channel, I + Q */
int mixx;
int firx;
int video_scale[8520];
} ng_t;
extern int ng_init(ng_t *s, vid_t *vs);
extern void ng_free(ng_t *s);
extern void ng_invert_audio(ng_t *s, int16_t *audio, size_t samples);
extern int ng_render_line(vid_t *s, void *arg, int nlines, vid_line_t **lines);
extern int d11_init(ng_t *s, vid_t *vid, char *mode);
extern int d11_render_line(vid_t *s, void *arg, int nlines, vid_line_t **lines);
extern int systercnr_init(ng_t *s, vid_t *vid, char *mode);
extern int systercnr_render_line(vid_t *s, void *arg, int nlines, vid_line_t **lines);
#endif