source: svn/trunk/newcon3bcm2_21bu/dta/src/dcc/src/bdcc608transcoder.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 61.5 KB
RevLine 
[2]1/***************************************************************************
2 *     Copyright (c) 2002-2006, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bdcc608transcoder.c $
11 * $brcm_Revision: 11 $
12 * $brcm_Date: 10/11/06 3:21p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/lib/ccgfx/source/bdcc608transcoder.c $
19 *
20 * 11   10/11/06 3:21p btosi
21 * PR22275: reduced noise on the serial console by changing a few
22 * BDCC_DBG_WRN's into BDCC_DBG_MSG's
23 *
24 * 10   10/11/06 3:03p btosi
25 * PR22275: refactoring to make the code easier to follow
26 *
27 * 9   10/4/06 1:57p btosi
28 * PR22275: fixed issues with the selection of the 608 service (CC 1-4)
29 * need to pass"Field" and "Channel" to BDCC_608_TranscodeReset, treat
30 * "Field" as a zero-based index.
31 *
32 * 8   7/28/06 1:27p btosi
33 * PR22275: cleaned up build warnings
34 *
35 * 7   7/17/06 1:20p btosi
36 * PR22275: added BDCC_608_P_CmdSendDeleteWindows; part of an attempt to
37 * recycle surfaces
38 *
39 * 6   5/10/06 6:49p shyam
40 * PR 8365 : Make it comiler warning free and ANSI C compliant
41 *
42 * 5   4/6/06 2:51p btosi
43 * PR3541: adding use of the BDBG_MODULE macro for integration with the
44 * RNG200 build
45 *
46 * 4   5/17/05 7:43p shyam
47 * PR 8365 : Making it work at runtime
48 *
49 * 3   5/9/05 3:44p shyam
50 * PR 8365 : Refinements
51 *
52 * 2   4/18/05 2:36p shyam
53 * PR 8365 : Under development
54 *
55 * 1   3/17/05 6:22p shyam
56 * PR 8365 : Add other sub-modules of ccgfx
57 *
58 ***************************************************************************/
59
60/***************************************************************************
61 *                            Theory Of Operation
62 *                            -------------------
63 *
64 * 608 modes
65 *
66 * EIA-608 Closed Captioning defines 3 captioning modes:  RollUp, PopOn
67 *    and PaintOn.
68 *
69 *
70 * 708 windows
71 *
72 * EIA-708-B defines 8 windows.  This transcoder design uses window 0 for RollUp;
73 * windows 0-3 or 4-7 for PaintOn; and windows 0-7 for PopOn.  For RollUp, window
74 * 0 is defined as either 2, 3 or 4 rows and full column width.  For PaintOn, 4
75 * 1-row windows are used, either 0-3 or 4-7 depending on the mode when PaintOn
76 * was initiated.  For PopOn, all 8 windows are used.  In this case, 4 are displayed
77 * while the other 4 are loaded with new characters.
78 *
79 * 608 state machine
80 *
81 * This design uses a state machine to track the captioning mode.  Each state also
82 * defines which windows are visible.
83 *
84 * ctrl vs data
85 * channel
86 * command buffers
87 * pen and window styles 2,2
88 *
89 ***************************************************************************/
90/* Includes */
91#include "bdcc.h"
92#include "bdcc_kernel.h"
93#include "bdcc608transcoder.h"
94#include "bdccgfx.h"
95#include "bdccpriv.h"
96
97BDBG_MODULE(bdcc_608trans);
98
99/* Defines */
100#define CheckParity(b)                  (!((b) & 0x80))
101#define GetDataChan(b1)                 (((b1) >> 3) & 1) ;
102#define ForceDataChan0(b1)              ((b1) & 0xF7)
103
104#define BDCC_P_NUM_608_STATE_INPUTS             16
105#define RGB222(r,g,b)                   (((r)<<4) | ((g)<<2) | (b))
106
107typedef enum BDCC_608_P_State
108{
109        BDCC_608_P_State_eIdle,
110        BDCC_608_P_State_eRollUp2,
111        BDCC_608_P_State_eRollUp3,
112        BDCC_608_P_State_eRollUp4,
113        BDCC_608_P_State_ePopOn1,
114        BDCC_608_P_State_ePopOn2,
115        BDCC_608_P_State_ePaintOn1,
116        BDCC_608_P_State_ePaintOn2,
117        BDCC_608_P_State_ePaintOn02,
118        BDCC_608_P_State_eNoChange
119} BDCC_608_P_State ;
120
121typedef struct BDCC_608_P_WindowCmds
122{
123        unsigned char           DefineWindow[7] ;
124        unsigned char           SetPenColor[4] ;
125        unsigned char           SetPenAttr[3] ;
126        unsigned char           SetPenLocation[3] ;
127} BDCC_608_P_WindowCmds ;
128
129
130typedef struct BDCC_608_TranscoderObject
131{
132        BDCC_608_P_State eState ;
133        int                             CurrentWindow ;
134        int                             bLastPairWasCtrl ;
135        unsigned char   LastB1 ;
136        unsigned char   LastB2 ;
137        int                             SelectedDataChan ;
138        int                             CurrentDataChan ;
139        int                             SelectedField ;
140        BDCC_CBUF               *pOutBuf         ;
141        int                             fBegLine ;
142        int                             TextOrXDSMode ;
143
144        BDCC_608_P_WindowCmds Cmds[8] ;
145
146        struct
147        {
148                int             fRowAssigned ;
149                int             RowAssigned ;
150        } WndInfo[8] ;
151#if 0
152        struct
153        {
154                int             WndId1 ; // one based
155        } RowInfo[15] ;
156#endif 
157} BDCC_608_TranscoderObject;
158
159typedef enum
160{
161        BDCC_608_P_Color_eWhite         = RGB222(3,3,3),
162        BDCC_608_P_Color_eGreen         = RGB222(0,3,0),
163        BDCC_608_P_Color_eBlue          = RGB222(0,0,3),
164        BDCC_608_P_Color_eCyan          = RGB222(2,2,3),
165        BDCC_608_P_Color_eRed           = RGB222(3,0,0),
166        BDCC_608_P_Color_eYellow        = RGB222(3,3,0),
167        BDCC_608_P_Color_eMagenta       = RGB222(3,0,3)
168} BDCC_608_P_Color ;
169
170typedef struct
171{
172        BDCC_608_P_State                NextState ;
173        char *                  CmdStr ;
174} BDCC_608_P_StateInputDecisions ;
175
176typedef struct BDCC_608_P_StateDecisions
177{
178        int                                             WndVisible[8] ;         /* DefWnd set vis & BegLine set vis */
179        int                                             WndRowCount[8] ;        /* DefWnd set rc */
180        unsigned char                   ClrWndMask ;            /* state trans clear windows */
181        unsigned char                   DisplayedMask ;         /* erase memory/nondisp memory */
182        BDCC_608_P_StateInputDecisions  Decisions[BDCC_P_NUM_608_STATE_INPUTS] ;
183} BDCC_608_P_StateDecisions ;
184
185typedef enum BDCC_608_P_CtrlMisc
186{
187        BDCC_608_P_CtrlMisc_eRCL        = 0x20, /* ResumeCaptionLoading */
188        BDCC_608_P_CtrlMisc_eBS         = 0x21, /* BackSp */
189        BDCC_608_P_CtrlMisc_eAOF        = 0x22, /* Reserved */
190        BDCC_608_P_CtrlMisc_eAON        = 0x23, /* Reserved */
191        BDCC_608_P_CtrlMisc_eDER        = 0x24, /* DeleteToEndOfRow */
192        BDCC_608_P_CtrlMisc_eRU2        = 0x25, /* RollUp2 */
193        BDCC_608_P_CtrlMisc_eRU3        = 0x26, /* RollUp3 */
194        BDCC_608_P_CtrlMisc_eRU4        = 0x27, /* RollUp4 */
195        BDCC_608_P_CtrlMisc_eFON        = 0x28, /* FlashOn */
196        BDCC_608_P_CtrlMisc_eRDC        = 0x29, /* ResumeDirectCaptioning */
197        BDCC_608_P_CtrlMisc_eTR         = 0x2A, /* TextRestart */
198        BDCC_608_P_CtrlMisc_eRTD        = 0x2B, /* ResumeTextDisplay */
199        BDCC_608_P_CtrlMisc_eEDM        = 0x2C, /* EraseDispMem */
200        BDCC_608_P_CtrlMisc_eCR         = 0x2D, /* CReturn */
201        BDCC_608_P_CtrlMisc_eENM        = 0x2E, /* EraseNonDispMem */
202        BDCC_608_P_CtrlMisc_eEOC        = 0x2F  /* EndOfCaption */
203} BDCC_608_P_CtrlMisc ;
204
205#define BDCC_608_P_MinSingleByteCode    0x20
206
207
208static void BDCC_608_P_ProcessCtrl(BDCC_608_hTranscoder h608Transcoder, unsigned char b1, unsigned char b2) ;
209static void BDCC_608_P_ProcessChar(BDCC_608_hTranscoder h608Transcoder, unsigned char b);
210static void BDCC_608_P_ProcessCharSpecial(BDCC_608_hTranscoder h608Transcoder,unsigned char b2);
211static void BDCC_608_P_ProcessCtrl2(BDCC_608_hTranscoder h608Transcoder, unsigned char b1, unsigned char b2);
212static void BDCC_608_P_ExecuteCmdStr(BDCC_608_hTranscoder h608Transcoder, char * pCmdStr);
213static void BDCC_608_P_ProcessCtrlMisc(BDCC_608_hTranscoder h608Transcoder, unsigned char b2);
214static void BDCC_608_P_ProcessCtrlPAC(BDCC_608_hTranscoder h608Transcoder, int Row, unsigned char b2PAC);
215static void BDCC_608_P_ProcessCtrlMidRow(BDCC_608_hTranscoder h608Transcoder, unsigned char b2);
216static void BDCC_608_P_CmdSendDefineAllWindows(BDCC_608_hTranscoder h608Transcoder);
217static void BDCC_608_P_CmdSendDefineWindow(BDCC_608_hTranscoder h608Transcoder, int wnd);
218#if 0
219static void BDCC_608_P_CmdSendDelay(BDCC_608_hTranscoder h608Transcoder, unsigned char tenths);
220static void BDCC_608_P_CmdSendShowWindows(BDCC_608_hTranscoder h608Transcoder, unsigned char mask);
221#endif
222static void BDCC_608_P_CmdSendClearWindows(BDCC_608_hTranscoder h608Transcoder, unsigned char mask);
223/* comment out for now to cleanup building warning */
224/* static void BDCC_608_P_CmdSendDeleteWindows( BDCC_608_hTranscoder h608Transcoder,    unsigned char mask);*/
225static void BDCC_608_P_CmdSendPenLocation(BDCC_608_hTranscoder h608Transcoder, int wnd);
226static void BDCC_608_P_CmdSendPenColor(BDCC_608_hTranscoder h608Transcoder, int wnd);
227static void BDCC_608_P_CmdSendSetCurrentWindow(BDCC_608_hTranscoder h608Transcoder, int wnd);
228static void BDCC_608_P_CmdSendPenAttr(BDCC_608_hTranscoder h608Transcoder, int wnd);
229static void BDCC_608_P_CmdSetVisible(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
230static void BDCC_608_P_CmdSetRowCount(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
231static void BDCC_608_P_CmdSetUnderline(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
232static void BDCC_608_P_CmdSetFlash(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
233static void BDCC_608_P_CmdSetItalics(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
234static void BDCC_608_P_CmdSetRow(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
235static void BDCC_608_P_CmdSetAnchorRow(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
236static void BDCC_608_P_CmdSetCol(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
237static void BDCC_608_P_CmdSetColor(BDCC_608_hTranscoder h608Transcoder, int wnd, int val);
238static void BDCC_608_P_ProcessChar2(BDCC_608_hTranscoder h608Transcoder,unsigned char b) ;
239static void BDCC_608_P_ProcessCtrlTab(BDCC_608_hTranscoder h608Transcoder, unsigned char b2) ;
240static void BDCC_608_P_EraseDisplayedMem(BDCC_608_hTranscoder h608Transcoder) ;
241static void BDCC_608_P_EraseNonDisplayedMem(BDCC_608_hTranscoder h608Transcoder) ;
242static void BDCC_608_P_CmdSendCarriageReturn(BDCC_608_hTranscoder h608Transcoder);
243static void BDCC_608_P_CmdSendSpace(BDCC_608_hTranscoder h608Transcoder);
244static void BDCC_608_P_CmdSendBackSpace(BDCC_608_hTranscoder h608Transcoder);
245static void BDCC_608_P_CmdSendFlip(BDCC_608_hTranscoder h608Transcoder);
246static void BDCC_608_P_ResetRows(BDCC_608_hTranscoder h608Transcoder, unsigned char WndMask);
247static void BDCC_608_P_ConsiderTextOrXDS(unsigned char b1,unsigned char b2,int * pTextOrXDSMode);
248static void BDCC_608_P_ProcessCharExtended(BDCC_608_hTranscoder h608Transcoder,unsigned char b1, unsigned char b2);
249static void BDCC_608_P_ProcessCtrlExtendedAttr(BDCC_608_hTranscoder h608Transcoder,unsigned char b1, unsigned char b2);
250static void BDCC_608_P_ProcessCtrlSpecialAssignment(BDCC_608_hTranscoder h608Transcoder,unsigned char b1, unsigned char b2);
251static void BDCC_608_P_ProcessCtrlUnknown(BDCC_608_hTranscoder h608Transcoder,unsigned char b1, unsigned char b2);
252static unsigned char BDCC_608_P_ConvertParity(unsigned char in);
253static int BDCC_608_P_WndFromRow(BDCC_608_hTranscoder h608Transcoder, int Row, BDCC_608_P_State eState) ;
254
255static const BDCC_608_P_WindowCmds DefaultCmds =
256{
257        /* DefineWindow */              {0x98,0x18,0x00,0x00,0x60,0x1F,0x12}, /* 0x0a for solid fill*/
258        /* SetPenColor */               {0x91,0x3F,0x00,0x00},
259        /* SetPenAttr */                {0x90,0x05,0x01},
260        /* SetPenLocation */    {0x92,0x00,0x00}
261} ;
262
263static const BDCC_608_P_StateDecisions StateDecisions[] =
264{
265        { /* BDCC_608_P_State_eIdle */ {0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,1,1}, 0xFF, 0x00,
266        {
267                /* RCL */ {BDCC_608_P_State_ePopOn1,    ""},
268                /* BS  */ {BDCC_608_P_State_eNoChange,  ""},
269                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
270                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
271                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
272                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
273                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
274                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
275                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
276                /* RDC */ {BDCC_608_P_State_ePaintOn1,  ""},
277                /* TR  */ {BDCC_608_P_State_eNoChange,  ""},
278                /* RTD */ {BDCC_608_P_State_eNoChange,  ""},
279                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
280                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
281                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
282                /* EOC */ {BDCC_608_P_State_ePopOn1,    ""},
283        }
284        },
285        { /* BDCC_608_P_State_eRollUp2 */ {1,0,0,0,0,0,0,0}, {2,1,1,1,1,1,1,1}, 0x00, 0x01,
286        {
287                /* RCL */ {BDCC_608_P_State_ePopOn1,    ""},
288                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
289                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
290                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
291                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
292                /* RU2 */ {BDCC_608_P_State_eNoChange,  ""},
293                /* RU3 */ {BDCC_608_P_State_eRollUp3,   ""},
294                /* RU4 */ {BDCC_608_P_State_eRollUp4,   ""},
295                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
296                /* RDC */ {BDCC_608_P_State_ePaintOn02, ""},
297                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
298                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
299                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
300                /* CR  */ {BDCC_608_P_State_eNoChange,  "R"},
301                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
302                /* EOC */ {BDCC_608_P_State_ePopOn2,    ""},
303        }
304        },
305        { /* BDCC_608_P_State_eRollUp3 */ {1,0,0,0,0,0,0,0}, {3,1,1,1,1,1,1,1}, 0x00, 0x01,
306        {
307                /* RCL */ {BDCC_608_P_State_ePopOn1,    ""},
308                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
309                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
310                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
311                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
312                /* RU2 */ {BDCC_608_P_State_eRollUp2,   ""},
313                /* RU3 */ {BDCC_608_P_State_eNoChange,  ""},
314                /* RU4 */ {BDCC_608_P_State_eRollUp4,   ""},
315                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
316                /* RDC */ {BDCC_608_P_State_ePaintOn02, ""},
317                /* TR  */ {BDCC_608_P_State_eNoChange/*BDCC_608_P_State_eIdle note.eg*/,                ""},
318                /* RTD */ {BDCC_608_P_State_eNoChange/*BDCC_608_P_State_eIdle note.eg*/,                ""},
319                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
320                /* CR  */ {BDCC_608_P_State_eNoChange,  "R"},
321                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
322                /* EOC */ {BDCC_608_P_State_ePopOn2,    ""},
323        }
324        },
325        { /* BDCC_608_P_State_eRollUp4 */ {1,0,0,0,0,0,0,0}, {4,1,1,1,1,1,1,1}, 0x00, 0x01,
326        {
327                /* RCL */ {BDCC_608_P_State_ePopOn1,    ""},
328                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
329                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
330                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
331                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
332                /* RU2 */ {BDCC_608_P_State_eRollUp2,   ""},
333                /* RU3 */ {BDCC_608_P_State_eRollUp3,   ""},
334                /* RU4 */ {BDCC_608_P_State_eNoChange,  ""},
335                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
336                /* RDC */ {BDCC_608_P_State_ePaintOn02, ""},
337                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
338                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
339                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
340                /* CR  */ {BDCC_608_P_State_eNoChange,  "R"},
341                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
342                /* EOC */ {BDCC_608_P_State_ePopOn2,    ""},
343        }
344        },
345        { /* BDCC_608_P_State_ePopOn1 */ {1,1,1,1,0,0,0,0}, {-1,1,1,1,1,1,1,1}, 0xF0, 0x0F,
346        {
347                /* RCL */ {BDCC_608_P_State_eNoChange,  ""},
348                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
349                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
350                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
351                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
352                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
353                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
354                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
355                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
356                /* RDC */ {BDCC_608_P_State_ePaintOn1,  ""},
357                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
358                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
359                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
360                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
361                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
362                /* EOC */ {BDCC_608_P_State_ePopOn2,    "f"},
363        }
364        },
365        { /* BDCC_608_P_State_ePopOn2 */ {0,0,0,0,1,1,1,1}, {1,1,1,1,1,1,1,1}, 0x0F, 0xF0,
366        {
367                /* RCL */ {BDCC_608_P_State_eNoChange,  ""},
368                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
369                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
370                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
371                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
372                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
373                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
374                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
375                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
376                /* RDC */ {BDCC_608_P_State_ePaintOn2,  ""},
377                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
378                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
379                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
380                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
381                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
382                /* EOC */ {BDCC_608_P_State_ePopOn1,    "f"},
383        }
384        },
385        { /* BDCC_608_P_State_ePaintOn1 */ {1,1,1,1,0,0,0,0}, {1,1,1,1,1,1,1,1}, 0x00, 0x0F,
386        {
387                /* RCL */ {BDCC_608_P_State_ePopOn1,    ""},
388                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
389                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
390                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
391                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
392                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
393                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
394                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
395                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
396                /* RDC */ {BDCC_608_P_State_eNoChange,  ""},
397                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
398                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
399                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
400                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
401                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
402                /* EOC */ {BDCC_608_P_State_ePopOn2,    ""},
403        }
404        },
405        { /* BDCC_608_P_State_ePaintOn2 */ {0,0,0,0,1,1,1,1}, {1,1,1,1,1,1,1,1}, 0x00, 0xF0,
406        {
407                /* RCL */ {BDCC_608_P_State_ePopOn2,    ""},
408                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
409                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
410                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
411                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
412                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
413                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
414                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
415                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
416                /* RDC */ {BDCC_608_P_State_eNoChange,  ""},
417                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
418                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
419                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
420                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
421                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
422                /* EOC */ {BDCC_608_P_State_ePopOn1,    ""},
423        }
424        },
425        { /* BDCC_608_P_State_ePaintOn02 */ {1,0,0,0,1,1,1,1}, {-1,1,1,1,1,1,1,1}, 0x00, 0xF1,
426        {
427                /* RCL */ {BDCC_608_P_State_ePopOn2,    ""},
428                /* BS  */ {BDCC_608_P_State_eNoChange,  "b"},
429                /* AOF */ {BDCC_608_P_State_eNoChange,  ""},
430                /* AON */ {BDCC_608_P_State_eNoChange,  ""},
431                /* DER */ {BDCC_608_P_State_eNoChange,  ""},
432                /* RU2 */ {BDCC_608_P_State_eRollUp2,   "en"},
433                /* RU3 */ {BDCC_608_P_State_eRollUp3,   "en"},
434                /* RU4 */ {BDCC_608_P_State_eRollUp4,   "en"},
435                /* FON */ {BDCC_608_P_State_eNoChange,  "s"},
436                /* RDC */ {BDCC_608_P_State_eNoChange,  ""},
437                /* TR  */ {BDCC_608_P_State_eNoChange,          ""},
438                /* RTD */ {BDCC_608_P_State_eNoChange,          ""},
439                /* EDM */ {BDCC_608_P_State_eNoChange,  "e"},
440                /* CR  */ {BDCC_608_P_State_eNoChange,  ""},
441                /* ENM */ {BDCC_608_P_State_eNoChange,  "n"},
442                /* EOC */ {BDCC_608_P_State_ePopOn1,    ""},
443        }
444        },
445} ;
446
447/**************************************************************************
448 *
449 * Function:            DccTranscode_Init
450 *
451 * Inputs:                     
452 *                                      h608Transcoder                          - object to init
453 *                                      Field                           - defines 608 field, 1 or 2
454 *                                      Channel                         - defines 608 CC channel, 1 or 2
455 *
456 * Outputs:             
457 *                                      h608Transcoder                          - object state is modified
458 *
459 * Returns:                     dccSuccess or a standard DCCERR error code
460 *
461 * Description:
462 *
463 * This function initializes a 608-708 Transcoder session object.
464 *
465 **************************************************************************/
466BDCC_Error BDCC_608_TranscodeOpen(
467        BDCC_608_hTranscoder            *ph608Transcoder,       
468        int                                             Field, 
469        int                                             Channel
470        )
471{
472        int wnd;
473        BDCC_608_hTranscoder hHandle;
474        BDCC_Error      ret = BDCC_Error_eSuccess;
475
476        BDCC_ASSERT(ph608Transcoder);
477
478        if ( Field != 1 && Field != 2 )
479        {
480                return(BDCC_Error_eInvalidParameter) ;
481        }
482
483        /* allocate the Transcoder handle */
484        hHandle = (BDCC_608_hTranscoder)BKNI_Malloc( sizeof(BDCC_608_TranscoderObject));
485        if(hHandle == NULL)
486        {
487                return BDCC_Error_eNoMemory;
488        }
489
490        *ph608Transcoder = hHandle;
491       
492        BKNI_Memset(hHandle, 0, sizeof(BDCC_608_TranscoderObject)) ;
493        hHandle->SelectedDataChan = Channel - 1 ;
494        hHandle->SelectedField = Field - 1;
495
496        for ( wnd = 0 ; wnd < 8 ; wnd++ )
497        {
498                hHandle->Cmds[wnd] = DefaultCmds ;
499                hHandle->Cmds[wnd].DefineWindow[0] = 0x98 | wnd ;
500        }
501
502        return(ret);
503       
504} /* DccTranscode_Init */
505
506/**************************************************************************
507 *
508 * Function:            BDCC_608_TranscodeReset
509 *
510 * Inputs:                     
511 *                                      BDCC_608_hTranscoder                            - object to init
512 *
513 * Outputs:             
514 *
515 * Returns:                     BDCC_Error_eSuccess or a standard BDCC_Error error code
516 *
517 * Description:
518 *
519 * This function resets a 608-708 Transcoder session object.
520 *
521 **************************************************************************/
522BDCC_Error BDCC_608_TranscodeReset(
523        BDCC_608_hTranscoder            h608Transcoder,
524        int                                             Field, 
525        int                                             Channel
526        )
527{
528        int wnd;
529
530        BKNI_Memset(h608Transcoder, 0, sizeof(BDCC_608_TranscoderObject)) ;
531        h608Transcoder->SelectedDataChan = Channel - 1 ;
532        h608Transcoder->SelectedField = Field - 1;
533
534        for ( wnd = 0 ; wnd < 8 ; wnd++ )
535        {
536                h608Transcoder->Cmds[wnd] = DefaultCmds ;
537                h608Transcoder->Cmds[wnd].DefineWindow[0] = 0x98 | wnd ;
538        }
539
540        return BDCC_Error_eSuccess ;
541}
542
543/**************************************************************************
544 *
545 * Function:            BCCGFX_TranscodeClose
546 *
547 * Inputs:                     
548 *                                      BDCC_608_hTranscoder    - object to Close
549 *
550 * Outputs:             
551 *                                      h608Transcoder          - Handle is freed
552 *
553 * Returns:                     None
554 *
555 * Description:
556 *
557 * This function closes a 608-708 Transcoder session object.
558 *
559 **************************************************************************/
560void BDCC_608_TranscodeClose(
561        BDCC_608_hTranscoder    h608Transcoder
562        )
563{
564        BDCC_ASSERT(h608Transcoder);
565
566        /* Free the memory allocated for Transcoder handle */
567        BKNI_Free( h608Transcoder );
568        return ;
569}
570
571
572
573/**************************************************************************
574 *
575 * Function:            BDCC_608_TranscodeProcess
576 *
577 * Inputs:                     
578 *                                      h608Transcoder                          - object, previously init'ed
579 *                                      pInBuf                          - input buffer
580 *
581 * Outputs:             
582 *                                      pOutBuf                         - output buffer
583 *
584 * Returns:                     dccSuccess or a standard DCCERR error code
585 *
586 * Description:
587 *
588 * This function reads (field,cc_byte1,cc_byte2) triplets from the
589 * input circular buffer and writes DTVCC EIA-708-B codes to the
590 * output buffer.
591 *
592 **************************************************************************/
593BDCC_Error BDCC_608_TranscodeProcess(
594        BDCC_608_hTranscoder    h608Transcoder,
595        BDCC_CBUF                                       *pInBuf,
596        BDCC_CBUF                                       *pOutBuf
597        )
598{
599        unsigned int                    InputBufTriplets ;
600        unsigned int                    curTriplet ;
601        unsigned char *         pCurTriplet ;
602        unsigned char                   b1, b2 ;
603        int                                     bThisPairWasCtrl ;
604       
605        /*
606         * Validate Arguments
607         */
608
609        /*
610         * Prep output buffers.
611         */
612        h608Transcoder->pOutBuf = pOutBuf ;
613
614        InputBufTriplets = pInBuf->NumBytes / 3 ;
615        BDCC_CBUF_ResetPeek(pInBuf) ;
616        BDCC_CBUF_ResetPost(pOutBuf) ;
617
618        for ( curTriplet=0 ; curTriplet < InputBufTriplets ; curTriplet++ )
619        {
620                pCurTriplet = BDCC_CBUF_PeekPtr(pInBuf, 3) ;
621                BDCC_CBUF_UpdatePeek(pInBuf) ;
622
623                if ( h608Transcoder->SelectedField == pCurTriplet[0] )
624                {
625                        /*
626                         * ConvertParity converts bit 7 from
627                         * parity_bit to parity_error
628                         */
629                        b1 = BDCC_608_P_ConvertParity(pCurTriplet[1]) ;
630                        b2 = BDCC_608_P_ConvertParity(pCurTriplet[2]) ;
631                        if ( (BDCC_P_DUMP_STREAM_FLAG & BDCC_P_608TRANSCODER)  &&  (b1 || b2) )
632                        {
633                                BDCC_DBG_WRN(("Dump XCoding (%02x,%02x)\n", b1, b2)) ;
634                        }
635
636                        /*
637                         * The following logic is almost verbatim from
638                         * the FCC spec for 608.  The goal here is qualify
639                         * the 2 bytes of data call ProcessChar() for the
640                         * displayable codes and ProcessCtrl() for the
641                         * 2-byte control codes.  Note that ProcessChar()
642                         * will substitute 0x7F (block) if its input fails
643                         * parity.
644                         */
645                         /*
646                         ** We can break the 608 codes into roughly 5 sets
647                         **
648                         ** - Standard Characters: single bytes that are  ~equivalent to ASCII
649                         **   ( processed in "BDCC_608_P_ProcessChar2()" )
650                         **
651                         ** - Special Characters: two bytes
652                         **   ( processed in "BDCC_608_P_ProcessCharSpecial()" )
653                         **
654                         ** - Mid-Row codes, Miscellaneous Control, PAC (Preamble Address Codes)
655                         **   ( processed in "BDCC_608_P_ProcessCtrl2()" )
656                         */
657
658                        bThisPairWasCtrl = 0 ;
659                        if ( (b1&0x7F) < BDCC_608_P_MinSingleByteCode )
660                        {
661                                if ( !CheckParity(b2) )
662                                {
663                                        /* if 2nd fails parity, ignore pair */
664                                }
665                                else
666                                {
667                                        /* 1st not checked, 2nd good */
668                                        if ( h608Transcoder->bLastPairWasCtrl   
669                                         &&   b2 == h608Transcoder->LastB2   
670                                         &&   (!CheckParity(b1) || b1 == h608Transcoder->LastB1))
671                                        {
672                                                /* ignore redundant, doesn't matter if b1 fails parity */
673                                                BDCC_DBG_MSG(("ignoring redundant 0x%02x 0x%02x\n", b1, b2)) ;
674                                                bThisPairWasCtrl = 1 ;
675                                        }
676                                        else
677                                        {
678                                                /* not expecting redundant ctrl or this is new ctrl */
679                                                if ( !CheckParity(b1) )
680                                                {
681                                                        /* 1st failed parity */
682                                                        BDCC_608_P_ProcessChar(h608Transcoder, 0x7F) ;
683                                                        BDCC_608_P_ProcessChar(h608Transcoder, b2) ;
684                                                }
685                                                else
686                                                {
687                                                        /* 1st good */
688                                                        BDCC_608_P_ProcessCtrl(h608Transcoder, b1, b2) ;
689                                                        bThisPairWasCtrl = 1 ;
690                                                }
691                                        }
692                                }
693                        }
694                        else
695                        {
696                                /* not ctrl */
697                                BDCC_608_P_ProcessChar(h608Transcoder, b1) ;
698                                BDCC_608_P_ProcessChar(h608Transcoder, b2) ;
699                        }
700
701                        if ( bThisPairWasCtrl )
702                        {
703                                h608Transcoder->LastB1 = b1 ;
704                                h608Transcoder->LastB2 = b2 ;
705                        }
706                        h608Transcoder->bLastPairWasCtrl = bThisPairWasCtrl ;
707                }
708        } /* for (each triplet) */
709
710        return(BDCC_Error_eSuccess) ;
711
712} /* BDCC_608_TranscodeProcess */
713
714
715
716                        /****************************
717                         *
718                         * Internal Functions -- 1st Level
719                         *
720                         ****************************/
721
722/**************************************************************************
723 *
724 * Function:            ProcessCtrl
725 *
726 * Inputs:                     
727 *                                      h608Transcoder                          - object, previously init'ed
728 *                                      b1                                      - 1st byte of CC pair
729 *                                      b2                                      - 2nd byte of CC pair
730 *
731 * Outputs:             
732 *
733 * Returns:                     <void>
734 *
735 * Description:
736 *
737 * This is the first layer of control processing.  Here we merely qualify the
738 * channel, 0 or 1.  We also force the channel to chan 0 (encoded in b1)
739 * so that the lower control layers can assume this.
740 *
741 **************************************************************************/
742void BDCC_608_P_ProcessCtrl(
743        BDCC_608_hTranscoder h608Transcoder, 
744        unsigned char b1, 
745        unsigned char b2)
746{
747        h608Transcoder->CurrentDataChan = GetDataChan(b1) ;
748
749        /*
750         * are we enterring or leaving Text mode or XDS?
751         */
752        BDCC_608_P_ConsiderTextOrXDS(b1,b2,&h608Transcoder->TextOrXDSMode) ;
753       
754        if ( (!h608Transcoder->TextOrXDSMode) 
755         &&  (h608Transcoder->CurrentDataChan == h608Transcoder->SelectedDataChan) )
756        {
757                /*
758                 * Now that we've filtered to the correct
759                 * channel, let's remap chan 1 to chan 0
760                 * so that all lower level code can assume
761                 * chan 0
762                 */
763                b1 = ForceDataChan0(b1) ;
764               
765                BDCC_608_P_ProcessCtrl2(h608Transcoder,b1,b2) ;
766        }
767}
768
769
770/**************************************************************************
771 *
772 * Function:            ProcessChar
773 *
774 * Inputs:                     
775 *                                      h608Transcoder                          - object, previously init'ed
776 *                                      b                                       - CC character
777 *
778 * Outputs:             
779 *
780 * Returns:                     <void>
781 *
782 * Description:
783 *
784 * This is the first layer of data processing.  Here we merely qualify the
785 * channel, 0 or 1. 
786 *
787 **************************************************************************/
788void BDCC_608_P_ProcessChar(
789        BDCC_608_hTranscoder h608Transcoder, 
790        unsigned char b)
791{
792        if ( (!h608Transcoder->TextOrXDSMode) 
793         &&  (h608Transcoder->CurrentDataChan == h608Transcoder->SelectedDataChan) )
794        {
795                BDCC_608_P_ProcessChar2(h608Transcoder,b) ;
796        }
797} /* ProcessChar */
798
799
800
801
802
803                        /****************************
804                         *
805                         * Internal Functions -- Lower Levels
806                         *
807                         ****************************/
808
809/**************************************************************************
810 *
811 * Function:            ProcessCtrl2
812 *
813 * Inputs:                     
814 *                                      h608Transcoder                          - object, previously init'ed
815 *                                      b1                                      - 1st byte of CC pair
816 *                                      b2                                      - 2nd byte of CC pair
817 *
818 * Outputs:             
819 *
820 * Returns:                     <void>
821 *
822 * Description:
823 *
824 * This function classifies the control pair as one of: Preamble Address
825 * Code, Mid-Row Code or Misc Code and calls the appropriate handler.
826 *
827 **************************************************************************/
828void BDCC_608_P_ProcessCtrl2(
829        BDCC_608_hTranscoder h608Transcoder, 
830        unsigned char b1, 
831        unsigned char b2)
832{
833        unsigned char b2PAC;
834
835        /*
836        ** If bit '6' of the least significant byte is set, this is a PAC (Preamble Address Code).
837        */
838        int isPAC = b2 & 0x40 ;
839       
840        int iRowNum=0;
841
842        /*
843        ** Process PAC (Preamble Address Codes)
844        */
845        if ( isPAC )
846        {
847            /*
848            ** Now look at bits (10:8,5) to determine which row has been specified.
849            */
850        switch ( b1 )
851        {
852                case 0x10 :
853                        /* PAC row 11 */
854                iRowNum = 11;
855                break ;
856               
857            case 0x11 :
858                /* PAC rows 1,2 */
859                iRowNum = ( b2 & 0x20 ) ? 2 : 1 ;
860                break ;
861               
862            case 0x12 :
863                /* PAC rows 3,4 */
864                iRowNum = ( b2 & 0x20 ) ? 4 : 3 ;
865                break ;
866               
867            case 0x13 :
868                /* PAC rows 12,13 */
869                iRowNum = ( b2 & 0x20 ) ? 13 : 12;
870                break ;
871
872            case 0x14 :
873                /* Misc or PAC rows 14,15 */
874                iRowNum = ( b2 & 0x20 ) ? 15 : 14 ;
875                break ;
876               
877            case 0x15 :
878                /* PAC rows 5,6 */
879                iRowNum = ( b2 & 0x20 ) ? 6 : 5 ;
880                break ;
881               
882            case 0x16 :
883                /* PAC rows 7,8 */
884                iRowNum = ( b2 & 0x20 ) ? 8 : 7 ;
885                break ;
886               
887            case 0x17 :
888                /* Tab or PAC rows 9,10 */
889                iRowNum = ( b2 & 0x20 ) ? 10 : 9 ;
890                break ;
891               
892            default:
893                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
894                break;
895            }   /* end of switch( b1 ) */       
896
897            b2PAC = b2 & 0x1F ;
898
899            /*
900            ** If "iRowNum" hasn't been set, this isn't a valid PAC code.
901            */
902            if ( iRowNum )
903                BDCC_608_P_ProcessCtrlPAC( h608Transcoder, iRowNum, b2PAC );
904       
905        }   /* end of if ( PAC ) */
906
907        /*
908        ** Process the Mid-Row,  Miscellaneous Control and "other" control codes.
909        */
910        else
911        {
912
913            switch ( b1 )
914            {
915            case 0x10 :
916                /* extended attributes? Where are these defined? */
917                if ( b2 & 0x20 )
918                                BDCC_608_P_ProcessCtrlExtendedAttr(h608Transcoder,b1,b2) ;
919                        else
920                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
921                        break ;
922                       
923                case 0x11 :
924                /*          ** mid-row codes, range ( 0x1120:0x112F )
925                ** special (two byte characters), range ( 0x1130:0x113F )
926                */
927                        if ( (b2 & 0xF0) == 0x20 )
928                                BDCC_608_P_ProcessCtrlMidRow(h608Transcoder, b2) ;
929                        else if ( (b2 & 0xF0) == 0x30 )
930                                BDCC_608_P_ProcessCharSpecial(h608Transcoder, b2) ;
931                        else
932                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
933                        break ;
934
935                case 0x12 :
936                /* extended characters? Where are these defined? */
937                if ( (b2 & 0xE0) == 0x20 ) /* 0x20's and 0x30's */
938                                BDCC_608_P_ProcessCharExtended(h608Transcoder, b1, b2) ;
939                        else
940                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
941                        break ;
942
943                case 0x13 :
944                /* extended characters? Where are these defined? */
945                if ( (b2 & 0xE0) == 0x20 ) /* 0x20's and 0x30's */
946                                BDCC_608_P_ProcessCharExtended(h608Transcoder, b1, b2) ;
947                        else
948                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
949                        break ;
950
951                case 0x14 :
952                /*
953                ** miscellaneous control codes, range ( 0x1420:0x142F )
954                */
955                        if ( (b2 & 0xF0) == 0x20 )
956                                BDCC_608_P_ProcessCtrlMisc(h608Transcoder, b2) ;
957                        else
958                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
959                        break ;
960
961                case 0x15 :
962                        if ( (b2 & 0xF0) == 0x20 )
963                        {
964                                /* accomodation for field 2, see EIA/CEA-608-B Sect. 8.4 */
965                                BDCC_608_P_ProcessCtrlMisc(h608Transcoder, b2) ;
966                        }
967                        else
968                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
969                        break ;
970
971                case 0x16 :
972                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
973                        break ;
974
975                case 0x17 :
976                /* Tab */
977                                switch ( b2 )
978                                {
979                                        case 0x21 :
980                                        case 0x22 :
981                                        case 0x23 :
982                    /*
983                    ** Tab codes, range ( 0x1721:0x1723 )
984                    */
985                                                BDCC_608_P_ProcessCtrlTab(h608Transcoder, b2) ;
986                                                break ;
987               
988                                        case 0x2D :
989                                        case 0x2E :
990                                        case 0x2F :
991                                                BDCC_608_P_ProcessCtrlExtendedAttr(h608Transcoder,b1,b2) ;
992                                                break ;
993               
994                                        case 0x24 :
995                                        case 0x25 :
996                                        case 0x26 :
997                                        case 0x27 :
998                                        case 0x28 :
999                                        case 0x29 :
1000                                        case 0x2A :
1001                                                BDCC_608_P_ProcessCtrlSpecialAssignment(h608Transcoder,b1,b2) ;
1002                                                break ;
1003
1004                                        default :
1005                                                BDCC_608_P_ProcessCtrlUnknown(h608Transcoder,b1,b2) ;
1006                                                break ;
1007                                }
1008
1009                        break ;
1010           
1011            }   /* end of switch( b1 ) */
1012           
1013        }   /* end of else ( not PAC ) */
1014
1015} /* ProcessCtrl2 */
1016
1017
1018/**************************************************************************
1019 *
1020 * Function:            ProcessCtrl_Misc
1021 *
1022 * Inputs:                     
1023 *                                      h608Transcoder                          - object, previously init'ed
1024 *                                      b2                                      - 2nd byte of CC pair
1025 *
1026 * Outputs:             
1027 *
1028 * Returns:                     <void>
1029 *
1030 * Description:
1031 *
1032 * This function operates on the Misc Control Codes.  These codes are
1033 * responsible for advancing our state machine, so the state machine is
1034 * evaluated here.
1035 *
1036 **************************************************************************/
1037void BDCC_608_P_ProcessCtrlMisc(
1038        BDCC_608_hTranscoder h608Transcoder, 
1039        unsigned char b2)
1040{
1041        BDCC_608_P_State NextState ;
1042       
1043        /*
1044         * execute any commands for this transition
1045         */
1046        BDCC_608_P_ExecuteCmdStr(h608Transcoder, StateDecisions[h608Transcoder->eState].Decisions[b2&0x0F].CmdStr) ;
1047
1048        /*
1049         * update the state
1050         */
1051        NextState = StateDecisions[h608Transcoder->eState].Decisions[b2&0x0F].NextState ;
1052        if ( NextState != BDCC_608_P_State_eNoChange )
1053        {
1054                BDCC_DBG_MSG(("ProcessCtrl_Misc:  changing state from %d to %d, b2 is 0x%02x\n", h608Transcoder->eState, NextState, b2)) ;
1055                h608Transcoder->eState = NextState ;
1056                if ( b2 != BDCC_608_P_CtrlMisc_eEOC ) /* don't clear on EOC (flip) */
1057                        BDCC_608_P_CmdSendClearWindows(h608Transcoder, StateDecisions[h608Transcoder->eState].ClrWndMask) ;
1058                BDCC_608_P_CmdSendDefineAllWindows(h608Transcoder) ;
1059                if ( NextState == BDCC_608_P_State_eRollUp2   ||   NextState == BDCC_608_P_State_eRollUp3   ||   NextState == BDCC_608_P_State_eRollUp4 )
1060                        h608Transcoder->CurrentWindow = 0 ;
1061                BDCC_608_P_CmdSendSetCurrentWindow(h608Transcoder, h608Transcoder->CurrentWindow) ;
1062        }
1063/*      Cmd_Send_Delay(h608Transcoder, 10) ; // testing only */
1064       
1065} /* ProcessCtrl_Misc */
1066
1067
1068/**************************************************************************
1069 *
1070 * Function:            ProcessCtrl_PAC
1071 *
1072 * Inputs:                     
1073 *                                      h608Transcoder                          - object, previously init'ed
1074 *                                      Row                                     - row decoded from 1st byte
1075 *                                      b2PAC                           - 2nd byte of CC pair, cooked
1076 *
1077 * Outputs:             
1078 *
1079 * Returns:                     <void>
1080 *
1081 * Description:
1082 *
1083 * This function operates on the Preamble Address Codes.
1084 *
1085 **************************************************************************/
1086void BDCC_608_P_ProcessCtrlPAC(
1087        BDCC_608_hTranscoder h608Transcoder, 
1088        int Row, 
1089        unsigned char b2PAC)
1090{
1091        int wnd ;
1092        int fPenLocation = 0 ;
1093
1094
1095        if ( h608Transcoder->eState == BDCC_608_P_State_eRollUp2
1096         ||  h608Transcoder->eState == BDCC_608_P_State_eRollUp3
1097         ||  h608Transcoder->eState == BDCC_608_P_State_eRollUp4 ) 
1098        {
1099                wnd = 0 ;
1100        }
1101        else
1102        {
1103                wnd = BDCC_608_P_WndFromRow(h608Transcoder, Row, h608Transcoder->eState) ;
1104        }
1105
1106        h608Transcoder->CurrentWindow = wnd ;
1107
1108        BDCC_608_P_CmdSetUnderline(h608Transcoder, wnd, b2PAC & 1) ;
1109        b2PAC &= ~1 ;
1110        BDCC_608_P_CmdSetFlash(h608Transcoder, wnd, 0) ;
1111        BDCC_608_P_CmdSetItalics(h608Transcoder, wnd, 0) ;
1112        BDCC_608_P_CmdSetAnchorRow(h608Transcoder, wnd, Row) ; /* column is 0 */
1113        h608Transcoder->WndInfo[wnd].fRowAssigned = 1 ;
1114        BDCC_608_P_CmdSetCol(h608Transcoder, wnd, 0) ;
1115
1116        switch ( b2PAC )
1117        {
1118                case 0x00 :
1119                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eWhite) ;
1120                        break ;
1121                case 0x02 :
1122                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eGreen) ;
1123                        break ;
1124                case 0x04 :
1125                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eBlue) ;
1126                        break ;
1127                case 0x06 :
1128                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eCyan) ;
1129                        break ;
1130                case 0x08 :
1131                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eRed) ;
1132                        break ;
1133                case 0x0A :
1134                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eYellow) ;
1135                        break ;
1136                case 0x0C :
1137                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eMagenta) ;
1138                        break ;
1139                case 0x0E :
1140                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eWhite) ;
1141                        BDCC_608_P_CmdSetItalics(h608Transcoder, wnd, 1) ;
1142                        break ;
1143
1144                case 0x10 :
1145                case 0x12 :
1146                case 0x14 :
1147                case 0x16 :
1148                case 0x18 :
1149                case 0x1A :
1150                case 0x1C :
1151                case 0x1E :
1152                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eWhite) ;
1153                        BDCC_608_P_CmdSetCol(h608Transcoder, wnd, (b2PAC - 0x10) * 2) ;
1154                        fPenLocation = 1 ;
1155                        break ;
1156        }
1157
1158        BDCC_608_P_CmdSendDefineWindow(h608Transcoder, wnd) ;
1159        BDCC_608_P_CmdSendPenColor(h608Transcoder, wnd) ;
1160        BDCC_608_P_CmdSendPenAttr(h608Transcoder, wnd) ;
1161
1162        if ( h608Transcoder->eState == BDCC_608_P_State_eRollUp2 ) 
1163        {
1164                BDCC_608_P_CmdSetRow(h608Transcoder, wnd, 1) ;
1165                fPenLocation = 1 ;
1166        }
1167        else if ( h608Transcoder->eState == BDCC_608_P_State_eRollUp3 ) 
1168        {
1169                BDCC_608_P_CmdSetRow(h608Transcoder, wnd, 2) ;
1170                fPenLocation = 1 ;
1171        }
1172        else if ( h608Transcoder->eState == BDCC_608_P_State_eRollUp4 ) 
1173        {
1174                BDCC_608_P_CmdSetRow(h608Transcoder, wnd, 3) ;
1175                fPenLocation = 1 ;
1176        }
1177        else 
1178        {
1179                BDCC_608_P_CmdSetRow(h608Transcoder, wnd, 0) ;
1180                fPenLocation = 1 ;
1181        }
1182
1183        if ( fPenLocation )
1184        {
1185                BDCC_608_P_CmdSendPenLocation(h608Transcoder, wnd) ;
1186        }
1187
1188        h608Transcoder->fBegLine = 1 ;
1189
1190} /* ProcessCtrl_PAC */
1191
1192
1193/**************************************************************************
1194 *
1195 * Function:            ProcessCtrl_MidRow
1196 *
1197 * Inputs:                     
1198 *                                      h608Transcoder                          - object, previously init'ed
1199 *                                      b2                                      - 2nd byte of CC pair
1200 *
1201 * Outputs:             
1202 *
1203 * Returns:                     <void>
1204 *
1205 * Description:
1206 *
1207 * This function operates on the Mid-Row Codes.
1208 *
1209 **************************************************************************/
1210void BDCC_608_P_ProcessCtrlMidRow(
1211        BDCC_608_hTranscoder h608Transcoder, 
1212        unsigned char b2)
1213{
1214        int wnd = h608Transcoder->CurrentWindow ;
1215       
1216        BDCC_608_P_CmdSetUnderline(h608Transcoder, wnd, b2 & 1) ;
1217        BDCC_608_P_CmdSetItalics(h608Transcoder, wnd, 0) ;
1218
1219        switch ( b2 & 0x0E )
1220        {
1221                case 0x00 :
1222                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eWhite) ;
1223                        break ;
1224                case 0x02 :
1225                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eGreen) ;
1226                        break ;
1227                case 0x04 :
1228                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eBlue) ;
1229                        break ;
1230                case 0x06 :
1231                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eCyan) ;
1232                        break ;
1233                case 0x08 :
1234                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eRed) ;
1235                        break ;
1236                case 0x0A :
1237                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eYellow) ;
1238                        break ;
1239                case 0x0C :
1240                        BDCC_608_P_CmdSetColor(h608Transcoder, wnd,BDCC_608_P_Color_eMagenta) ;
1241                        break ;
1242                case 0x0E :
1243                        BDCC_608_P_CmdSetItalics(h608Transcoder, wnd, 1) ;
1244                        break ;
1245        }
1246       
1247        BDCC_608_P_CmdSendPenColor(h608Transcoder, wnd) ;
1248        BDCC_608_P_CmdSendPenAttr(h608Transcoder, wnd) ;
1249        BDCC_608_P_CmdSendSpace(h608Transcoder) ;
1250
1251} /* ProcessCtrl_MidRow */
1252
1253
1254/**************************************************************************
1255 *
1256 * Function:            ExecuteCmdStr
1257 *
1258 * Inputs:                     
1259 *                                      h608Transcoder                          - object, previously init'ed
1260 *                                      pCmdStr                         - 2nd byte of CC pair
1261 *
1262 * Outputs:             
1263 *
1264 * Returns:                     <void>
1265 *
1266 * Description:
1267 *
1268 * This function sequentially calls processing functions based on the
1269 * supplied command string.  Used for doing processing based on state
1270 * transitions.
1271 *
1272 **************************************************************************/
1273void BDCC_608_P_ExecuteCmdStr(
1274        BDCC_608_hTranscoder h608Transcoder, 
1275        char * pCmdStr)
1276{
1277        char * p ;
1278       
1279        for ( p=pCmdStr ; *p ; p++ )
1280        {
1281                switch ( *p )
1282                {
1283                        case 'e' :
1284                                BDCC_608_P_EraseDisplayedMem(h608Transcoder) ;
1285                                break ;
1286                        case 'n' :
1287                                BDCC_608_P_EraseNonDisplayedMem(h608Transcoder) ;
1288                                break ;
1289                        case 'R' :
1290                                BDCC_608_P_CmdSendCarriageReturn(h608Transcoder) ;
1291                                break ;
1292                        case 's' :
1293                                BDCC_608_P_CmdSendSpace(h608Transcoder) ;
1294                                break ;
1295                        case 'f' :
1296                                BDCC_608_P_CmdSendFlip(h608Transcoder) ;
1297                                break ;
1298                        case 'b' :
1299                                BDCC_608_P_CmdSendBackSpace(h608Transcoder) ;
1300                                break ;
1301                        /* etc */
1302                }
1303        }
1304       
1305} /* ExecuteCmdStr */
1306
1307
1308
1309/**************************************************************************
1310 *
1311 * Function:            ConvertParity
1312 *
1313 * Inputs:                     
1314 *                                      in                              - input byte
1315 *
1316 * Outputs:             
1317 *
1318 * Returns:                     converted byte
1319 *
1320 * Description:
1321 *
1322 * ConvertParity() examines the input byte and determines whether or
1323 * not it has a parity error, based on ODD parity.  The upper bit is
1324 * converted from the parity bit to the parity error bit, meaning the
1325 * high bit of the output byte is 1 iff there was a parity error on the
1326 * input byte.
1327 *
1328 **************************************************************************/
1329unsigned char BDCC_608_P_ConvertParity(unsigned char in)
1330{
1331#if 0
1332        return(in & 0x7F) ;
1333#else
1334        static unsigned char ParityErrorArray[] = {1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1} ;
1335        unsigned char temp = ((in & 0x0F) ^ (in >> 4)) ;
1336        return((ParityErrorArray[temp]<<7) | (in&0x7F)) ;
1337#endif
1338}
1339
1340
1341/**************************************************************************
1342 *
1343 * Function:            Cmd_Send_DefineAllWindows
1344 *
1345 * Inputs:                     
1346 *                                      h608Transcoder                          - object, previously init'ed
1347 *
1348 * Outputs:             
1349 *
1350 * Returns:                     <void>
1351 *
1352 * Description:
1353 *
1354 * This function sends a DefineWindow command to all 8 windows.
1355 *
1356 **************************************************************************/
1357void BDCC_608_P_CmdSendDefineAllWindows(BDCC_608_hTranscoder h608Transcoder)
1358{
1359        int i ;
1360
1361        /*
1362         * first hide windows
1363         */
1364        for ( i=0 ; i < 8 ; i++ )
1365        {
1366                if ( ! StateDecisions[h608Transcoder->eState].WndVisible[i] )
1367                {
1368                   /* BDCC_608_P_CmdSendDeleteWindows(h608Transcoder, i);*/
1369                        BDCC_608_P_CmdSendDefineWindow(h608Transcoder, i) ;
1370        }
1371        }
1372        /*
1373         * then show windows
1374         */
1375        for ( i=0 ; i < 8 ; i++ )
1376        {
1377                if ( StateDecisions[h608Transcoder->eState].WndVisible[i] )
1378                        BDCC_608_P_CmdSendDefineWindow(h608Transcoder, i) ;
1379        }
1380}
1381
1382/**************************************************************************
1383 *
1384 * Function:            Cmd_Send_DefineWindow
1385 *
1386 * Inputs:                     
1387 *                                      h608Transcoder                          - object, previously init'ed
1388 *                                      wnd                                     - window
1389 *
1390 * Outputs:             
1391 *
1392 * Returns:                     <void>
1393 *
1394 * Description:
1395 *
1396 * This function sends a DefineWindow command to a window.
1397 *
1398 **************************************************************************/
1399void BDCC_608_P_CmdSendDefineWindow(
1400        BDCC_608_hTranscoder h608Transcoder, 
1401        int wnd)
1402{
1403        /*
1404         * first, overlay those values that are
1405         * defined by the state -- visible and rowcount
1406         */
1407        BDCC_DBG_MSG(("transcoder Cmd_Send_DefineWindow wnd %d state %d rc %d vis %d\n", 
1408                wnd, h608Transcoder->eState, StateDecisions[h608Transcoder->eState].WndRowCount[wnd],
1409                StateDecisions[h608Transcoder->eState].WndVisible[wnd] && h608Transcoder->WndInfo[wnd].fRowAssigned)) ;
1410        BDCC_608_P_CmdSetVisible(h608Transcoder, wnd, StateDecisions[h608Transcoder->eState].WndVisible[wnd] && h608Transcoder->WndInfo[wnd].fRowAssigned) ;
1411        if ( StateDecisions[h608Transcoder->eState].WndRowCount[wnd] >= 0 )
1412                BDCC_608_P_CmdSetRowCount(h608Transcoder, wnd, StateDecisions[h608Transcoder->eState].WndRowCount[wnd]) ;
1413
1414         /*
1415          * then, send it
1416          */
1417         BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, h608Transcoder->Cmds[wnd].DefineWindow, sizeof(h608Transcoder->Cmds[wnd].DefineWindow)) ;
1418}
1419
1420
1421/**************************************************************************
1422 *
1423 * Function:            Cmd_Send_SetCurrentWindow
1424 *
1425 * Inputs:                     
1426 *                                      h608Transcoder                          - object, previously init'ed
1427 *                                      wnd                                     - window
1428 *
1429 * Outputs:             
1430 *
1431 * Returns:                     <void>
1432 *
1433 * Description:
1434 *
1435 * This function sends a SetCurrentWindow command.
1436 *
1437 **************************************************************************/
1438void BDCC_608_P_CmdSendSetCurrentWindow(
1439        BDCC_608_hTranscoder h608Transcoder, 
1440        int wnd)
1441{
1442        static unsigned char Cmd[1] = {0x80} ;
1443        Cmd[0] = 0x80 | wnd ;
1444        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, Cmd, sizeof(Cmd)) ;
1445}
1446
1447
1448/**************************************************************************
1449 *
1450 * Function:            Cmd_Send_PenColor
1451 *
1452 * Inputs:                     
1453 *                                      h608Transcoder                          - object, previously init'ed
1454 *                                      wnd                                     - window
1455 *
1456 * Outputs:             
1457 *
1458 * Returns:                     <void>
1459 *
1460 * Description:
1461 *
1462 * This function sends a SetPenColor command to a window.
1463 *
1464 **************************************************************************/
1465void BDCC_608_P_CmdSendPenColor(
1466        BDCC_608_hTranscoder h608Transcoder, 
1467        int wnd)
1468{
1469         BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, h608Transcoder->Cmds[wnd].SetPenColor, sizeof(h608Transcoder->Cmds[wnd].SetPenColor)) ;
1470}
1471
1472
1473/**************************************************************************
1474 *
1475 * Function:            Cmd_Send_PenAttr
1476 *
1477 * Inputs:                     
1478 *                                      h608Transcoder                          - object, previously init'ed
1479 *                                      wnd                                     - window
1480 *
1481 * Outputs:             
1482 *
1483 * Returns:                     <void>
1484 *
1485 * Description:
1486 *
1487 * This function sends a SetPenAttributes command to a window.
1488 *
1489 **************************************************************************/
1490void BDCC_608_P_CmdSendPenAttr(
1491        BDCC_608_hTranscoder h608Transcoder, 
1492        int wnd)
1493{
1494         BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, h608Transcoder->Cmds[wnd].SetPenAttr, sizeof(h608Transcoder->Cmds[wnd].SetPenAttr)) ;
1495}
1496
1497
1498/**************************************************************************
1499 *
1500 * Function:            Cmd_Send_PenLocation
1501 *
1502 * Inputs:                     
1503 *                                      h608Transcoder                          - object, previously init'ed
1504 *                                      wnd                                     - window
1505 *
1506 * Outputs:             
1507 *
1508 * Returns:                     <void>
1509 *
1510 * Description:
1511 *
1512 * This function sends a SetPenLocation command to a window.
1513 *
1514 **************************************************************************/
1515void BDCC_608_P_CmdSendPenLocation(
1516        BDCC_608_hTranscoder h608Transcoder, 
1517        int wnd)
1518{
1519         BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, h608Transcoder->Cmds[wnd].SetPenLocation, sizeof(h608Transcoder->Cmds[wnd].SetPenLocation)) ;
1520}
1521
1522
1523/**************************************************************************
1524 *
1525 * Function:            Cmd_Send_Delay
1526 *
1527 * Inputs:                     
1528 *                                      h608Transcoder                          - object, previously init'ed
1529 *                                      tenths                          - delay, in tenths of second
1530 *
1531 * Outputs:             
1532 *
1533 * Returns:                     <void>
1534 *
1535 * Description:
1536 *
1537 * This function sends a Delay command.
1538 *
1539 **************************************************************************/
1540#if 0
1541void BDCC_608_P_CmdSendDelay(
1542        BDCC_608_hTranscoder h608Transcoder,
1543        unsigned char tenths)
1544{
1545        static unsigned char DelayCmd[2] = {0x8d, 0x00} ;
1546        DelayCmd[1] = tenths ;
1547        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, DelayCmd, sizeof(DelayCmd)) ;
1548}
1549#endif
1550
1551/**************************************************************************
1552 *
1553 * Function:            Cmd_Send_ClearWindows
1554 *
1555 * Inputs:                     
1556 *                                      h608Transcoder                          - object, previously init'ed
1557 *                                      tenths                          - delay, in tenths of second
1558 *
1559 * Outputs:             
1560 *
1561 * Returns:                     <void>
1562 *
1563 * Description:
1564 *
1565 * This function sends a ClearWindow command with the supplied mask.
1566 *
1567 **************************************************************************/
1568
1569 /* comment out for now to cleanup building warning */
1570#if 0
1571void BDCC_608_P_CmdSendDeleteWindows(
1572        BDCC_608_hTranscoder h608Transcoder,
1573        unsigned char mask)
1574{
1575        static unsigned char DelWndCmd[2] = {0x8C, 0x00} ;
1576        DelWndCmd[1] = mask ;
1577        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, DelWndCmd, sizeof(DelWndCmd)) ;
1578        BDCC_608_P_ResetRows(h608Transcoder, mask) ;
1579}
1580#endif
1581/**************************************************************************
1582 *
1583 * Function:            Cmd_Send_ClearWindows
1584 *
1585 * Inputs:                     
1586 *                                      h608Transcoder                          - object, previously init'ed
1587 *                                      tenths                          - delay, in tenths of second
1588 *
1589 * Outputs:             
1590 *
1591 * Returns:                     <void>
1592 *
1593 * Description:
1594 *
1595 * This function sends a ClearWindow command with the supplied mask.
1596 *
1597 **************************************************************************/
1598void BDCC_608_P_CmdSendClearWindows(
1599        BDCC_608_hTranscoder h608Transcoder, 
1600        unsigned char mask)
1601{
1602        static unsigned char ClrWndCmd[2] = {0x88, 0x00} ;
1603        ClrWndCmd[1] = mask ;
1604        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, ClrWndCmd, sizeof(ClrWndCmd)) ;
1605        BDCC_608_P_ResetRows(h608Transcoder, mask) ;
1606}
1607
1608/**************************************************************************
1609 *
1610 * Function:            BDCC_608_P_SetByteField
1611 *
1612 * Inputs:                     
1613 *                                      mask                            - bit mask for byte
1614 *                                      shift                           - bit shift for byte
1615 *                                      val                                     - bit value for byte
1616 *
1617 * Outputs:             
1618 *                                      pByte                           - output byte
1619 *
1620 * Returns:                     <void>
1621 *
1622 * Description:
1623 *
1624 * This function sets a bit field within a byte.
1625 *
1626 **************************************************************************/
1627void BDCC_608_P_SetByteField(unsigned char * pByte, unsigned char mask, int shift, int val)
1628{
1629        *pByte &= ~ mask ;
1630        *pByte |= (mask & (val << shift)) ;
1631}
1632
1633
1634/**************************************************************************
1635 *
1636 * Function:            Cmd_SetXxx
1637 *
1638 * Inputs:                     
1639 *                                      h608Transcoder                          - object, previously init'ed
1640 *                                      wnd                                     - window id
1641 *                                      val                                     - value
1642 *
1643 * Outputs:             
1644 *                                     
1645 *
1646 * Returns:                     <void>
1647 *
1648 * Description:
1649 *
1650 * These functions set various fields within the DTVCC command buffers.
1651 *
1652 **************************************************************************/
1653void BDCC_608_P_CmdSetVisible(
1654        BDCC_608_hTranscoder h608Transcoder, 
1655        int wnd, 
1656        int val)
1657{
1658        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].DefineWindow[1], 0x20, 5, (unsigned char)val) ;
1659}
1660
1661void BDCC_608_P_CmdSetRowCount(
1662        BDCC_608_hTranscoder h608Transcoder, 
1663        int wnd, 
1664        int val)
1665{
1666        BDCC_DBG_MSG(("transcoder BDCC_608_P_CmdSetRowCount: setting row count  for wnd %d to rc-1 = %d\n", wnd, val-1)) ;
1667        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].DefineWindow[4], 0x0F, 0, (unsigned char)val-1) ;
1668}
1669
1670void BDCC_608_P_CmdSetUnderline(
1671        BDCC_608_hTranscoder h608Transcoder, 
1672        int wnd, 
1673        int val)
1674{
1675        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenAttr[2], 0x40, 6, (unsigned char)val) ;
1676}
1677
1678void BDCC_608_P_CmdSetFlash(
1679        BDCC_608_hTranscoder h608Transcoder, 
1680        int wnd, 
1681        int val)
1682{
1683        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenColor[1], 0xC0, 6, (unsigned char)val) ;
1684}
1685
1686void BDCC_608_P_CmdSetItalics(
1687        BDCC_608_hTranscoder h608Transcoder, 
1688        int wnd, 
1689        int val)
1690{
1691        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenAttr[2], 0x80, 7, (unsigned char)val) ;
1692}
1693
1694void BDCC_608_P_CmdSetRow(
1695        BDCC_608_hTranscoder h608Transcoder, 
1696        int wnd, 
1697        int val)
1698{
1699        BDCC_DBG_MSG(("608 Transcoder: setting row %d for wnd %d\n", val, wnd)) ;
1700        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenLocation[1], 0x0F, 0, (unsigned char)val) ;
1701}
1702
1703void BDCC_608_P_CmdSetAnchorRow(
1704        BDCC_608_hTranscoder h608Transcoder, 
1705        int wnd, 
1706        int val)
1707{
1708        BDCC_DBG_MSG(("608 Transcoder: setting ANCHOR row %d for wnd %d\n", ((val*BDCC_P_CYGRID75)/BDCC_P_CY15), wnd)) ;
1709        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].DefineWindow[2], 0x7F, 0, (unsigned char)((val*BDCC_P_CYGRID75)/BDCC_P_CY15)) ;
1710}
1711
1712void BDCC_608_P_CmdSetCol(
1713        BDCC_608_hTranscoder h608Transcoder, 
1714        int wnd, 
1715        int val)
1716{
1717        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenLocation[2], 0x3F, 0, (unsigned char)val) ;
1718}
1719
1720void BDCC_608_P_CmdSetColor(
1721        BDCC_608_hTranscoder h608Transcoder, 
1722        int wnd, 
1723        int val)
1724{
1725        BDCC_608_P_SetByteField(&h608Transcoder->Cmds[wnd].SetPenColor[1], 0x3F, 0, (unsigned char)val) ;
1726}
1727
1728
1729/**************************************************************************
1730 *
1731 * Function:            ProcessChar2
1732 *
1733 * Inputs:                     
1734 *                                      h608Transcoder                          - object, previously init'ed
1735 *                                      b                                       - character
1736 *
1737 * Outputs:             
1738 *                                     
1739 *
1740 * Returns:                     <void>
1741 *
1742 * Description:
1743 *
1744 * This function translates a 608 character to a 708 character and
1745 * outputs it.
1746 *
1747 **************************************************************************/
1748void BDCC_608_P_ProcessChar2(
1749        BDCC_608_hTranscoder h608Transcoder,
1750        unsigned char b)
1751{
1752        if ( b )
1753        {
1754                BDCC_DBG_MSG(("ProcessChar2:  0x%02x  '%c'\n", b, b)) ;
1755        }
1756#if 0
1757        if ( h608Transcoder->fBegLine )
1758        {
1759                Space(h608Transcoder) ;
1760                h608Transcoder->fBegLine = 0 ;
1761
1762                wnd = h608Transcoder->CurrentWindow ;
1763                if ( StateDecisions[h608Transcoder->eState].WndVisible[wnd] )
1764                        Cmd_Send_ShowWindows(h608Transcoder, (unsigned char)(1<<wnd)) ;
1765        }
1766#endif
1767        /*
1768         * check the character for parity
1769         * if it fails, change it to the
1770         * solid block char
1771         */
1772        if ( b & 0x80 )
1773        {
1774                /* parity error, convert to solid block */
1775                b = 0x7F ;
1776        }
1777       
1778        /*
1779         * First, translate those chars that don't
1780         * map directly to 708
1781         */
1782        switch ( b )
1783        {
1784                case 0x2A : b = 0xE1 ; break ;
1785                case 0x5C : b = 0xE9 ; break ;
1786                case 0x5E : b = 0xED ; break ;
1787                case 0x5F : b = 0xF3 ; break ;
1788                case 0x60 : b = 0xFA ; break ;
1789                case 0x7B : b = 0xE7 ; break ;
1790                case 0x7C : b = 0xF7 ; break ;
1791                case 0x7D : b = 0xD1 ; break ;
1792                case 0x7E : b = 0xF1 ; break ;
1793
1794                case 0x7F :
1795                        /* the solid block is a 2-byte code in 708 */
1796                        b = 0x10 ;
1797                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &b, 1) ;
1798                        b = 0x30 ;
1799                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &b, 1) ;
1800                        return ;
1801        }
1802
1803        /*
1804         * send it out
1805         */
1806        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &b, 1) ;
1807       
1808}
1809
1810
1811/**************************************************************************
1812 *
1813 * Function:            ProcessChar_Special
1814 *
1815 * Inputs:                     
1816 *                                      h608Transcoder                          - object, previously init'ed
1817 *                                      b2                                      - 2nd byte
1818 *
1819 * Outputs:             
1820 *                                     
1821 *
1822 * Returns:                     <void>
1823 *
1824 * Description:
1825 *
1826 * This function translates a 608 character to a 708 character and
1827 * outputs it.
1828 *
1829 **************************************************************************/
1830void BDCC_608_P_ProcessCharSpecial(
1831        BDCC_608_hTranscoder h608Transcoder,
1832        unsigned char b2)
1833{
1834        static unsigned char SpecialChar[] = {0xAE,0xBA,0xBD,0xBF,0x39,0xA2,0xA3,0x7F,0xE0,0x20,0xE8,0xE2,0xEA,0xEE,0xF4,0xFB} ;
1835#if 0
1836        if ( h608Transcoder->fBegLine )
1837        {
1838                int wnd ;
1839               
1840                Space(h608Transcoder) ;
1841                h608Transcoder->fBegLine = 0 ;
1842
1843                wnd = h608Transcoder->CurrentWindow ;
1844                if ( StateDecisions[h608Transcoder->eState].WndVisible[wnd] )
1845                        Cmd_Send_ShowWindows(h608Transcoder, (unsigned char)(1<<wnd)) ;
1846        }
1847#endif
1848        if ( (b2 & 0xF0) == 0x30 )
1849        {
1850                b2 = SpecialChar[b2 & 0x0F] ;
1851                if ( b2 < 0x40 )
1852                {
1853                        unsigned char ext1 = 0x10 ;
1854                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &ext1, 1) ;
1855                }
1856                BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &b2, 1) ;
1857        }
1858}
1859
1860
1861struct
1862{
1863        unsigned char First ;
1864        unsigned char Second ;
1865} ExtendedChars[] =
1866{
1867        /*
1868         * Table 5:  Spanish
1869         */
1870        {0xC1, 0x00},
1871        {0xC9, 0x00},
1872        {0xD3, 0x00},
1873        {0xDA, 0x00},
1874        {0xDC, 0x00},
1875        {0xFC, 0x00},
1876        {0x10, 0x31},
1877        {0xA1, 0x00},
1878       
1879        /*
1880         * Table 6:  Misc
1881         */
1882        {0x2A, 0x00},
1883        {0x27, 0x00},
1884        {0x10, 0x7D},
1885        {0xA9, 0x00},
1886        {0x10, 0x3D},
1887        {0x10, 0x35},
1888        {0x10, 0x33},
1889        {0x10, 0x34},
1890       
1891        /*
1892         * Table 7:  French
1893         */
1894        {0xC0, 0x00},
1895        {0xC2, 0x00},
1896        {0xC7, 0x00},
1897        {0xC8, 0x00},
1898        {0xCA, 0x00},
1899        {0xCB, 0x00},
1900        {0xEB, 0x00},
1901        {0xCE, 0x00},
1902        {0xCF, 0x00},
1903        {0xEF, 0x00},
1904        {0xD4, 0x00},
1905        {0xD9, 0x00},
1906        {0xF9, 0x00},
1907        {0xDB, 0x00},
1908        {0xAB, 0x00},
1909        {0xBB, 0x00},
1910       
1911        /*
1912         * Table 8:  Portugese
1913         */
1914        {0xC3, 0x00},
1915        {0xE3, 0x00},
1916        {0xCD, 0x00},
1917        {0xCC, 0x00},
1918        {0xEC, 0x00},
1919        {0xD2, 0x00},
1920        {0xF2, 0x00},
1921        {0xD5, 0x00},
1922        {0xF5, 0x00},
1923        {0x7B, 0x00},
1924        {0x7D, 0x00},
1925        {0x5C, 0x00},
1926        {0x5E, 0x00},
1927        {0x5F, 0x00},
1928        {0x7C, 0x00},
1929        {0x7E, 0x00},
1930       
1931        /*
1932         * Table 9:  German
1933         */
1934        {0xC4, 0x00},
1935        {0xE4, 0x00},
1936        {0xD6, 0x00},
1937        {0xF6, 0x00},
1938        {0xDF, 0x00},
1939        {0xA5, 0x00},
1940        {0xA4, 0x00},
1941        {0x10, 0x7A},
1942       
1943        /*
1944         * Table 10:  Danish
1945         */
1946        {0xC5, 0x00},
1947        {0xE5, 0x00},
1948        {0xD8, 0x00},
1949        {0xF8, 0x00},
1950        {0x10, 0x7F},
1951        {0xAC, 0x00},
1952        {0x10, 0x7C},
1953        {0x00, 0x00},
1954} ;
1955
1956void BDCC_608_P_ProcessCharExtended(
1957        BDCC_608_hTranscoder h608Transcoder,
1958        unsigned char b1, 
1959        unsigned char b2)
1960{
1961        int ExtIndex ;
1962        unsigned char outChar ;
1963       
1964        if ( ((b1 & 0xFE) != 0x12)   ||   ((b2 & 0xE0) != 0x20) )
1965        {
1966                BDCC_DBG_ERR(("ProcessChar_Extended:  unknown (%02X,%02X)\n", b1,b2)) ;
1967                return ;
1968        }
1969
1970        /*
1971         * first, there's an implied backspace
1972         */
1973        BDCC_608_P_CmdSendBackSpace(h608Transcoder) ;
1974       
1975        /*
1976         * there are 64 extended chars
1977         * the b1/b2 bit pattern will be truncated
1978         * to produce a 6 bit array index
1979         * ---b1----  ---b2----
1980         * 0001 001x  001x xxxx
1981         */
1982        ExtIndex = b2 & 0x1F ;
1983        if ( b1 & 1 )
1984                ExtIndex |= 0x20 ;
1985
1986        outChar = ExtendedChars[ExtIndex].First ;
1987        if ( outChar == 0x10 )
1988        {
1989                /* 2 byte code */
1990                BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &outChar, 1) ;
1991                outChar = ExtendedChars[ExtIndex].Second ;
1992        }
1993        BDCC_DBG_MSG(("ProcessChar_Extended: (%02X,%02X) translated to %02X\n",b1,b2,outChar)) ;
1994        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &outChar, 1) ;
1995       
1996} /* ProcessChar_Extended */
1997
1998
1999void BDCC_608_P_ProcessCtrlExtendedAttr(
2000        BDCC_608_hTranscoder h608Transcoder,
2001        unsigned char b1, 
2002        unsigned char b2)
2003{
2004        BSTD_UNUSED(h608Transcoder) ;
2005        BDCC_DBG_MSG(("ProcessCtrl_ExtendedAttr:  (%02X,%02X)\n", b1,b2)) ;
2006} /* ProcessCtrl_ExtendedAttr */
2007
2008
2009void BDCC_608_P_ProcessCtrlSpecialAssignment(
2010        BDCC_608_hTranscoder h608Transcoder,
2011        unsigned char b1, 
2012        unsigned char b2)
2013{
2014        BSTD_UNUSED(h608Transcoder) ;
2015        BDCC_DBG_MSG(("ProcessCtrl_SpecialAssignment:  (%02X,%02X)\n", b1,b2)) ;
2016} /* ProcessCtrl_SpecialAssignment */
2017
2018
2019void BDCC_608_P_ProcessCtrlUnknown(
2020        BDCC_608_hTranscoder h608Transcoder,
2021        unsigned char b1, 
2022        unsigned char b2)
2023{
2024        BSTD_UNUSED(h608Transcoder) ;
2025        BDCC_DBG_MSG(("ProcessCtrl_Unknown:  (%02X,%02X)\n", b1,b2)) ;
2026} /* ProcessCtrl_Unknown */
2027
2028
2029
2030/**************************************************************************
2031 *
2032 * Function:            ProcessCtrl_Tab
2033 *
2034 * Inputs:                     
2035 *                                      h608Transcoder                          - object, previously init'ed
2036 *                                      b2                                      - character
2037 *
2038 * Outputs:             
2039 *                                     
2040 *
2041 * Returns:                     <void>
2042 *
2043 * Description:
2044 *
2045 * This function performs the handling of the tab misc control codes.
2046 *
2047 **************************************************************************/
2048void BDCC_608_P_ProcessCtrlTab(
2049        BDCC_608_hTranscoder h608Transcoder, 
2050        unsigned char b2)
2051{
2052        static unsigned char tsp[2] = {0x10,0x20} ;
2053
2054        switch ( b2 )
2055        {
2056                case 0x23 :
2057                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, tsp, 2) ;
2058                        /* fall thru */
2059                case 0x22 :
2060                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, tsp, 2) ;
2061                        /* fall thru */
2062                case 0x21 :
2063                        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, tsp, 2) ;
2064                        break ;
2065                default :
2066                        BDCC_DBG_ERR(("ProcessCtrl_Tab unknown code %02x\n", b2)) ;
2067                        break ;
2068        }
2069}
2070
2071
2072/**************************************************************************
2073 *
2074 * Function:            EraseDisplayedMem
2075 *
2076 * Inputs:                     
2077 *                                      h608Transcoder                          - object, previously init'ed
2078 *
2079 * Outputs:             
2080 *                                     
2081 *
2082 * Returns:                     <void>
2083 *
2084 * Description:
2085 *
2086 * EraseDisplayedMem clears the displayed windows.
2087 *
2088 **************************************************************************/
2089void BDCC_608_P_EraseDisplayedMem(BDCC_608_hTranscoder h608Transcoder)
2090{
2091        BDCC_608_P_CmdSendClearWindows(h608Transcoder, StateDecisions[h608Transcoder->eState].DisplayedMask) ;
2092}
2093
2094
2095/**************************************************************************
2096 *
2097 * Function:            EraseNonDisplayedMem
2098 *
2099 * Inputs:                     
2100 *                                      h608Transcoder                          - object, previously init'ed
2101 *
2102 * Outputs:             
2103 *                                     
2104 *
2105 * Returns:                     <void>
2106 *
2107 * Description:
2108 *
2109 * EraseNonDisplayedMem clears the non-displayed windows.
2110 *
2111 **************************************************************************/
2112void BDCC_608_P_EraseNonDisplayedMem(BDCC_608_hTranscoder h608Transcoder)
2113{
2114        BDCC_608_P_CmdSendClearWindows(h608Transcoder, (unsigned char)(~(StateDecisions[h608Transcoder->eState].DisplayedMask))) ;
2115}
2116
2117
2118/**************************************************************************
2119 *
2120 * Function:            CarriageReturn
2121 *
2122 * Inputs:                     
2123 *                                      h608Transcoder                          - object, previously init'ed
2124 *
2125 * Outputs:             
2126 *                                     
2127 *
2128 * Returns:                     <void>
2129 *
2130 * Description:
2131 *
2132 * CR handler.
2133 *
2134 **************************************************************************/
2135void BDCC_608_P_CmdSendCarriageReturn(BDCC_608_hTranscoder h608Transcoder)
2136{
2137        unsigned char cr = 0x0d ;
2138        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &cr, 1) ;
2139        h608Transcoder->fBegLine = 1 ;
2140}
2141
2142void BDCC_608_P_CmdSendSpace(BDCC_608_hTranscoder h608Transcoder)
2143{
2144        unsigned char sp = 0x20 ;
2145        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &sp, 1) ;
2146}
2147
2148void BDCC_608_P_CmdSendBackSpace(BDCC_608_hTranscoder h608Transcoder)
2149{
2150        unsigned char sp = 0x08 ;
2151        BDCC_CBUF_WritePtr(h608Transcoder->pOutBuf, &sp, 1) ;
2152}
2153
2154void BDCC_608_P_CmdSendFlip(BDCC_608_hTranscoder h608Transcoder)
2155{
2156        BSTD_UNUSED(h608Transcoder) ;
2157        BDCC_DBG_MSG(("Flip\n")) ;
2158}
2159
2160
2161/**************************************************************************
2162 *
2163 * Function:            WndFromRow
2164 *
2165 * Inputs:                     
2166 *                                      h608Transcoder                          - object, previously init'ed
2167 *                                      eState                          - current 608 state
2168 *
2169 * Outputs:             
2170 *                                      window according to the row and the state
2171 *                                     
2172 *
2173 * Returns:                     <void>
2174 *
2175 * Description:
2176 *
2177 * WndFromRow returns the window id for the given row and state.
2178 *
2179 **************************************************************************/
2180int BDCC_608_P_WndFromRow(
2181        BDCC_608_hTranscoder h608Transcoder, 
2182        int Row, 
2183        BDCC_608_P_State eState)
2184{
2185        int wnd ;
2186        int offset ;
2187
2188        if ( eState == BDCC_608_P_State_ePopOn2 || eState == BDCC_608_P_State_ePaintOn1 )
2189                offset = 0 ;
2190        else
2191                offset = 4 ;
2192
2193        for ( wnd=offset ; wnd < offset+4 ; wnd++ )
2194        {
2195                if ( h608Transcoder->WndInfo[wnd].fRowAssigned   &&   h608Transcoder->WndInfo[wnd].RowAssigned == Row )
2196                {
2197                        /* already have a wnd assigned to this row */
2198                        return(wnd) ;
2199                }
2200        }
2201
2202        for ( wnd=offset ; wnd < offset+4 ; wnd++ )
2203        {
2204                if ( ! h608Transcoder->WndInfo[wnd].fRowAssigned )
2205                {
2206                        h608Transcoder->WndInfo[wnd].fRowAssigned = 1 ;
2207                        h608Transcoder->WndInfo[wnd].RowAssigned = Row ;
2208                        return(wnd) ;
2209                }
2210        }
2211
2212        BDCC_DBG_ERR(("WndFromRow:  dccError can't assign wnd for row %d\n", Row)) ;
2213        return(0) ;
2214}
2215
2216void BDCC_608_P_ResetRows(
2217        BDCC_608_hTranscoder h608Transcoder, 
2218        unsigned char WndMask)
2219{
2220        int wnd ;
2221        unsigned char mask ;
2222
2223        for ( wnd=0 , mask=1 ; wnd < 8 ; wnd++ , mask <<= 1 )
2224        {
2225                if ( mask & WndMask )
2226                {
2227                        h608Transcoder->WndInfo[wnd].fRowAssigned = 0 ;
2228                }
2229        }
2230}
2231
2232
2233void BDCC_608_P_ConsiderTextOrXDS(
2234        unsigned char b1,
2235        unsigned char b2,
2236        int * pTextOrXDSMode)
2237{
2238        b1 &= 0x7F ;
2239        b2 &= 0x7F ;
2240        switch ( b1 )
2241        {
2242                case 0x14 :
2243                case 0x15 :
2244                case 0x1c :
2245                case 0x1d:
2246                        switch ( b2 )
2247                        {
2248                                case BDCC_608_P_CtrlMisc_eEOC :
2249                                case BDCC_608_P_CtrlMisc_eRCL :
2250                                case BDCC_608_P_CtrlMisc_eRDC :
2251                                case BDCC_608_P_CtrlMisc_eRU2 :
2252                                case BDCC_608_P_CtrlMisc_eRU3 :
2253                                case BDCC_608_P_CtrlMisc_eRU4 :
2254                                        /* caption mode */
2255                                        BDCC_DBG_MSG(("ConsiderTextOrXDS:  b2=%02X  CAPTION\n", b2)) ;
2256                                        *pTextOrXDSMode = 0 ;
2257                                        break ;
2258
2259                                case BDCC_608_P_CtrlMisc_eRTD :
2260                                case BDCC_608_P_CtrlMisc_eTR :
2261                                        /* text mode */
2262                                        BDCC_DBG_MSG(("ConsiderTextOrXDS:  b2=%02X  TEXT\n", b2)) ;
2263                                        *pTextOrXDSMode = 1 ;
2264                                        break ;
2265                        }
2266                        break ;
2267
2268                case 0x0f :
2269                        /* end of XDS mode */
2270                        BDCC_DBG_MSG(("ConsiderTextOrXDS:  b1=%02X  END XDS -> CAPTION\n", b1)) ;
2271                        *pTextOrXDSMode = 0 ;
2272                        break ;
2273                       
2274                default :
2275                        if ( (b1 >= 0x01) && (b1 <= 0x0F) )
2276                        {
2277                                /* XDS mode */
2278                                BDCC_DBG_MSG(("ConsiderTextOrXDS:  b1=%02X  XDS\n", b1)) ;
2279                                *pTextOrXDSMode = 2 ;
2280                        }
2281                        else
2282                        {
2283                                /* all other control codes don't change the mode */
2284                                BDCC_DBG_MSG(("ConsiderTextOrXDS:  b1=%02X  No Change %d\n", b1, *pTextOrXDSMode)) ;
2285                        }
2286        }
2287
2288}
2289
2290
2291
Note: See TracBrowser for help on using the repository browser.