**
**  YUV to RGB/YUV422 conversion routines
**  © 2002 Kakace Productions
**
**
** NOTES :
**      - The scanning functions convert hardware-specific YUV components
**        to their CCIR representation (except that Y is scaled to the
**        range [0; 255]) using ITU BT 601 equations.


                INCDIR  Devkit:NDK_3.9/Include_ASM

                TTL     "FAR"
                MC68020


*--------------------------------------------------------------------------------------------------*


                XDEF    _putCharProc

_putCharProc    move.b  d0,(a3)+                ; For Exec/RawDoFormat()
                rts


; void ComputeFPS(struct EClockVal *t1, struct EClockVal *t2, struct fps_val *fps, ULONG ticspersec);
;                                    8                    12                   16            20
                XDEF    _ComputeFPS

_ComputeFPS     move.l  d2,-(sp)
                movea.l 8(sp),a0                ; t1
                movea.l 12(sp),a1               ; t2

                move.l  4(a1),d1
                sub.l   4(a0),d1
                move.l  (a1),d0
                move.l  (a0),d2
                subx.l  d2,d0                   ; d0/d1 := t2 - t1

                move.l  20(sp),d2               ; ticspersec
                movea.l 16(sp),a0               ; fps
                clr.l   (a0)
                move.l  #'0',4(a0)
                tst.l   d0
                bne.s   .exit

                divul.l  d1,d0:d2
                move.l  d2,(a0)

                mulu.l  #10,d0
                divu.l  d1,d0
                add.l   #'0',d0
                move.l  d0,4(a0)

.exit           move.l  (sp)+,d2
                rts


*--------------------------------------------------------------------------------------------------*
; Conversion functions (to YUV 4:2:2 or 24-bit RGB).
; YUV 4:2:2 is used by PiP (video layer) windows for monitoring purpose. Since the monitoring is
; limited to 360x310 (PAL), we have to convert at most 111600 pixels.
; The RGB conversion is used for monitoring (no PiP window available) or for scanning.


                XDEF    _VLab_411_to_RGB
                XDEF    _VLab_211_to_RGB
                XDEF    _VLab_111_to_RGB
                XDEF    _VLab_211_to_422
                XDEF    _VLab_111_to_422
                XDEF    _VLab_Y_to_422
                XDEF    UV_Table


******* VLab_Convert/VLab_411_to_RGB ****************************************
*
*   NAME
*   VLab_411_to_RGB -- Convert YUV HiRes to 24-bit RGB.
*
*   SYNOPSIS
*   VLab_411_to_RGB(y, uv, rgb, pixels)
*
*   VOID VLab_411_to_RGB(UBYTE *, UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to 24-bit RGB. U and V values
*   are interpolated linearly.
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   uv     - Pointer to the U,V (chroma) buffer.
*   rgb    - Pointer to the RGB buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
* Basic operations :
*       This function loads yuv components, interpolate the missing uv values
*       (due to the 4:1:1 format), then convert each yuv pixel to RGB.
*
*       Y1U1V1 Y2U1V1 Y3U1V1 Y4U1V1  Y5U2V2 Y6U2V2 Y7U2V2 Y8U2V2  Y9U3V3 ...
*   =>  Y1U1V1 Y2U1V1 Y3U1V1 Y4u4v4  Y5u5v5 Y6u6v6 Y7U2V2 Y8u8v8  Y9u9v9
*       u4 = (3.U1 + 1.U2) / 4          v4 = (3.V1 + 1.V2) / 4
*       u5 = (1.U1 + 1.U2) / 2          v5 = (1.V1 + 1.V2) / 2
*       u6 = (1.U1 + 3.U2) / 4          v6 = (1.V1 + 3.V2) / 4
*       u8 = (3.U2 + 1.U3) / 4          v8 = (3.V2 + 1.V3) / 4
*


_VLab_411_to_RGB
                movem.l d2-d7/a2,-(sp)                  ; 7 registers

ARGBASE         SET    8*4                              ; Offset for the arguments.

                movea.l ARGBASE(sp),a2                  ; Y values
                movea.l ARGBASE+4(sp),a1                ; U,V pairs
                movea.l ARGBASE+8(sp),a0                ; RGB buffer
                move.l  ARGBASE+12(sp),d7               ; size (Y samples)
                moveq   #0,d0
                moveq   #0,d3
                moveq   #0,d4

        ; Main conversion loop.

                move.b  (a1)+,d3                        ; u
                move.w  d3,d5
                move.b  (a1)+,d4                        ; v
                move.w  d4,d6

.conv_loop      move.w  d3,d1
                move.w  d4,d2
                moveq   #0,d0
                add.w   d5,d1
                add.w   d6,d2
                move.b  (a2)+,d0
                addq.w  #1,d1                           ; Round the intermediate results
                addq.w  #1,d2
                lsr.w   #1,d1                           ; (u'+ u) / 2
                lsr.w   #1,d2                           ; (v'+ v) / 2
                bsr     convert_RGB                     ; YUV -> RGB

                move.w  d3,d1                           ; u
                move.w  d4,d2                           ; v
                moveq   #0,d0
                add.w   d1,d1
                add.w   d2,d2
                add.w   d3,d1
                add.w   d4,d2
                add.w   d5,d1
                add.w   d6,d2
                move.b  (a2)+,d0
                addq.w  #2,d1                           ; Round the intermediate results
                addq.w  #2,d2
                lsr.w   #2,d1                           ; (u'+ 3u) / 4
                lsr.w   #2,d2                           ; (v'+ 3v) / 4
                bsr     convert_RGB

                moveq   #0,d0
                move.b  (a2)+,d0                        ; Y
                move.w  d3,d1                           ; u
                move.w  d4,d2                           ; v
                bsr     convert_RGB

                moveq   #0,d0
                move.b  (a2)+,d0
                tst.l   d7
                beq.s   .lastCol

                move.w  d3,d5
                move.w  d4,d6

                move.b  (a1)+,d3                        ; u
                move.b  (a1)+,d4                        ; v

                move.w  d5,d1
                move.w  d6,d2
                add.w   d1,d1
                add.w   d2,d2
                add.w   d5,d1
                add.w   d6,d2
                add.w   d3,d1
                add.w   d4,d2
                addq.w  #2,d1                           ; Round the intermediate results
                addq.w  #2,d2
                lsr.w   #2,d1                           ; (3u'+ u) / 4
                lsr.w   #2,d2                           ; (3v'+ u) / 4
                bra.s   .convert3

.lastCol        move.w  d3,d1                           ; u
                move.w  d4,d2                           ; v

.convert3       bsr     convert_RGB

                subq.l  #4,d7
                bne     .conv_loop

                movem.l (sp)+,d2-d7/a2
                rts


******* VLab_Convert/VLab_211_to_RGB ****************************************
*
*   NAME
*   VLab_211_to_RGB -- Convert YUV LoRes to 24-bit RGB.
*
*   SYNOPSIS
*   VLab_211_to_RGB(y, uv, rgb, pixels)
*
*   VOID VLab_211_to_RGB(UBYTE *, UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to 24-bit RGB. U and V values
*   are interpolated linearly.
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   uv     - Pointer to the U,V (chroma) buffer.
*   rgb    - Pointer to the RGB buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
*


_VLab_211_to_RGB
                movem.l d2-d7/a2,-(sp)                  ; 7 registers

ARGBASE         SET    8*4                              ; Offset for the arguments.

                movea.l ARGBASE(sp),a2                  ; Y values
                movea.l ARGBASE+4(sp),a1                ; U,V pairs
                movea.l ARGBASE+8(sp),a0                ; RGB buffer
                move.l  ARGBASE+12(sp),d7               ; size (Y samples)
                moveq   #0,d0
                moveq   #0,d3
                moveq   #0,d4
                moveq   #0,d5                           ; Flag : First column

                lsr.l   #1,d7
                subq.w  #1,d7                           ; Pixel pair count.

.conv_loop      move.b  (a1)+,d3                        ; u
                move.b  (a1)+,d4                        ; v

                move.w  d3,d1
                move.w  d4,d2
                moveq   #0,d0
                move.b  (a2)+,d0
                tst.w   d5
                beq.s   .firstCol

                add.w   d5,d1
                add.w   d6,d2
                addq.w  #1,d1                           ; Round the intermediate results
                addq.w  #1,d2
                lsr.w   #1,d1                           ; (u'+ u) / 2
                lsr.w   #1,d2                           ; (v'+ v) / 2

.firstCol       bsr     convert_RGB                     ; YUV -> RGB

                moveq   #0,d0
                move.b  (a2)+,d0                        ; Y
                move.w  d3,d1                           ; u
                move.w  d4,d2                           ; v
                bsr     convert_RGB

                move.w  d3,d5
                move.w  d4,d6
                dbra    d7,.conv_loop

                movem.l (sp)+,d2-d7/a2
                rts


******* VLab_Convert/VLab_111_to_RGB ****************************************
*
*   NAME
*   VLab_111_to_RGB -- Convert YUV Thumbnail to 24-bit RGB.
*
*   SYNOPSIS
*   VLab_111_to_RGB(y, uv, rgb, pixels)
*
*   VOID VLab_111_to_RGB(UBYTE *, UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to 24-bit RGB.
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   uv     - Pointer to the U,V (chroma) buffer.
*   rgb    - Pointer to the RGB buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
*


_VLab_111_to_RGB
                movem.l d2-d3/a2,-(sp)                  ; 3 registers

ARGBASE         SET     4*4                             ; Offset for the arguments.

                movea.l ARGBASE(sp),a2                  ; Y values
                movea.l ARGBASE+4(sp),a1                ; U,V pairs
                movea.l ARGBASE+8(sp),a0                ; RGB buffer
                move.l  ARGBASE+12(sp),d3               ; size (Y samples)
                subq.w  #1,d3                           ; Pixel pair count

.conv_loop      moveq   #0,d1
                move.b  (a1)+,d1                        ; u
                moveq   #0,d2
                move.b  (a1)+,d2                        ; v
                moveq   #0,d0
                move.b  (a2)+,d0                        ; Y
                bsr     convert_RGB                     ; YUV -> RGB
                dbra    d3,.conv_loop

                movem.l (sp)+,d2-d3/a2
                rts


******* VLab_Convert/VLab_211_to_422 ****************************************
*
*   NAME
*   VLab_211_to_422 -- Convert YUV LoRes to YUV 4:2:2
*
*   SYNOPSIS
*   VLab_211_to_422(y, uv, dest, pixels)
*
*   VOID VLab_211_to_422(UBYTE *, UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to YUV 4:2:2 (the pixel format
*   is expressed as Y0 U0 Y1 V0).
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   uv     - Pointer to the U,V (chroma) buffer.
*   dest   - Pointer to the YUV 422 buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
*


_VLab_211_to_422
                move.l  a2,-(sp)                ; 1 register

ARGBASE         SET     2*4                     ; Offset for the arguments.

                movea.l ARGBASE(sp),a2          ; Y buffer
                movea.l ARGBASE+4(sp),a1        ; UV buffer
                movea.l ARGBASE+8(sp),a0        ; destBuffer (YUV422)
                move.l  ARGBASE+12(sp),d1       ; numPixels
                lsr.l   #1,d1
                subq.w  #1,d1                   ; Pixel pair count.

.conv_loop      move.b  (a2)+,d0                ; Y0
                lsl.l   #8,d0
                move.b  (a1)+,d0                ; Y0 U0
                lsl.l   #8,d0
                move.b  (a2)+,d0                ; Y0 U0 Y1
                lsl.l   #8,d0
                move.b  (a1)+,d0                ; Y0 U0 Y1 V0
                move.l  d0,(a0)+                ; to destBuffer
                dbra    d1,.conv_loop

                movea.l (sp)+,a2
                rts


******* VLab_Convert/VLab_111_to_422 ****************************************
*
*   NAME
*   VLab_111_to_422 -- Convert YUV Thumbnail to YUV 4:2:2
*
*   SYNOPSIS
*   VLab_111_to_422(y, uv, dest, pixels)
*
*   VOID VLab_111_to_422(UBYTE *, UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to YUV 4:2:2 (the pixel format
*   is expressed as Y0 U0 Y1 V0). Since the destination format requires less
*   chroma values, each U,V pair is mixed then combined with the respective
*   luma values.
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   uv     - Pointer to the U,V (chroma) buffer.
*   dest   - Pointer to the YUV 422 buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
*


_VLab_111_to_422
                movem.l d2/a2,-(sp)             ; 2 registers

ARGBASE         SET    3*4                      ; Offset for the arguments.

                movea.l ARGBASE(sp),a2          ; Y buffer
                movea.l ARGBASE+4(sp),a1        ; UV buffer
                movea.l ARGBASE+8(sp),a0        ; destBuffer (YUV422)
                move.l  ARGBASE+12(sp),d2       ; numPixels
                lsr.l   #1,d2
                subq.w  #1,d2                   ; Pixel pair count.

.conv_loop      moveq   #0,d0
                move.b  (a1)+,d0                ; U0
                swap    d0
                move.b  (a1)+,d0                ; V0
                moveq   #0,d1
                move.b  (a1)+,d1                ; U1
                swap    d1
                move.b  (a1)+,d1                ; V1

                add.l   d1,d0
                addi.l  #$00010001,d0           ; Round the intermediate results.
                lsr.l   #1,d0
                andi.w  #$00FF,d0               ; (U0+U1)/2 (V0+V1)/2

                move.b  (a2)+,d1
                swap    d1
                move.b  (a2)+,d1
                lsl.l   #8,d1
                or.l    d1,d0
                move.l  d0,(a0)+
                dbra    d2,.conv_loop

                movem.l (sp)+,d2/a2
                rts


******* VLab_Convert/VLab_Y_to_422 ******************************************
*
*   NAME
*   VLab_Y_to_422 -- Convert YUV (any resolution) to YUV 4:2:2 (greyscale)
*
*   SYNOPSIS
*   VLab_Y_to_422(y, dest, pixels)
*
*   VOID VLab_Y_to_422(UBYTE *, UBYTE *, ULONG);
*
*   FUNCTION
*   Convert Y datas (CCIR, internal format) to YUV 4:2:2 (the pixel format
*   is expressed as Y0 U0 Y1 V0). Chroma values are all set to 0.
*
*   INPUTS
*   y      - Pointer to the Y (luma) buffer.
*   dest   - Pointer to the YUV 422 buffer.
*   pixels - Number of luma components, which is also the number of the
*            pixels (width * height).
*
*   SEE ALSO
*
*****************************************************************************
*
*


_VLab_Y_to_422  movea.l 4(sp),a1                ; Y buffer
                movea.l 8(sp),a0                ; destBuffer (YUV422)
                move.l  12(sp),d1               ; numPixels
                lsr.l   #1,d1
                subq.w  #1,d1                   ; Pixel pair count.

.conv_loop      move.l  #$80008000,d0           ; [U, V] = [0, 0]
                move.b  (a1)+,d0
                swap    d0
                move.b  (a1)+,d0
                rol.l   #8,d0
                move.l  d0,(a0)+
                dbra    d1,.conv_loop

                rts


*****i* VLab_Convert/Convert_RGB ********************************************
*
*   NAME
*   Convert_RGB -- Convert YUV values to 24-bit RGB (ASM only)
*
*   SYNOPSIS
*   Convert_RGB(rgb,  Y,  U,  V)
*                a0  d0  d1  d2
*
*   VOID Convert_RGB(UBYTE *, UWORD, UWORD, UWORD);
*
*   FUNCTION
*   Convert YUV datas (CCIR, internal format) to 24-bit RGB
*
*   INPUTS
*   rgb - Pointer to the RGB buffer.
*   Y   - Y value [0; 255]
*   U   - U value [16; 240]
*   V   - V value [16; 240]
*
*   NOTES
*   The conversion takes place as follow :
*       R'255 = Y             + 408,583.V
*       G'255 = Y - 100,291.U - 208,120.V
*       B'255 = Y + 516,411.U
*
*   d0, d1 and d2 registers are scratched.
*
*   SEE ALSO
*
*****************************************************************************
*
*


convert_RGB     move.l  d3,-(sp)
                lsl.w   #7,d0                           ; Y * 128

                move.w  ITU_BT601(pc,d2.w*8),d3         ; range : [-22880; 22880]
                add.w   d0,d3                           ; Y + 204.V
                bpl.s   .write_R

                svs     d3
                ext.w   d3                              ; 0 = underflow, $FFFF = overflow.

.write_R        lsr.w   #7,d3
                move.b  d3,(a0)+                        ; R

                move.w  ITU_BT601+2(pc,d2.w*8),d3       ; range : [-11655; 11655]
                move.w  d0,d2
                add.w   ITU_BT601+4(pc,d1.w*8),d3       ; range : [- 5616;  5616]
                sub.w   d3,d2
                bpl.s   .write_G

                svs     d2
                ext.w   d2

.write_G        lsr.w   #7,d2
                move.b  d2,(a0)+                        ; G

                add.w   ITU_BT601+6(pc,d1.w*8),d0       ; range : [-28919; 28919]
                bpl.s   .write_B

                svs     d0
                ext.w   d0

.write_B        lsr.w   #7,d0
                move.b  d0,(a0)+                        ; B
                move.l  (sp)+,d3
                rts


; ITU BT601 table.
;       V1 = V * 408.583 / 2
;       V2 = V * 208.128 / 2
;       U1 = U * 100.291 / 2
;       U2 = U * 516.411 / 2
;                         V1    V2    U1    U2    V1    V2    U1    U2    V1    V2    U1    U2    V1    V2    U1    U2
ITU_BT601       dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $A6A0,$D27A,$EA10,$8F09,$A76C,$D2E2,$EA42,$900C,$A838,$D34A,$EA74,$910E,$A905,$D3B2,$EAA7,$9210
                dc.w    $A9D1,$D41A,$EAD9,$9312,$AA9D,$D482,$EB0B,$9415,$AB6A,$D4EA,$EB3D,$9517,$AC36,$D552,$EB6F,$9619
                dc.w    $AD02,$D5BA,$EBA1,$971B,$ADCE,$D622,$EBD4,$981D,$AE9B,$D68A,$EC06,$9920,$AF67,$D6F2,$EC38,$9A22
                dc.w    $B033,$D75A,$EC6A,$9B24,$B100,$D7C3,$EC9C,$9C26,$B1CC,$D82B,$ECCE,$9D28,$B298,$D893,$ED00,$9E2B
                dc.w    $B365,$D8FB,$ED33,$9F2D,$B431,$D963,$ED65,$A02F,$B4FD,$D9CB,$ED97,$A131,$B5C9,$DA33,$EDC9,$A233
                dc.w    $B696,$DA9B,$EDFB,$A336,$B762,$DB03,$EE2D,$A438,$B82E,$DB6B,$EE5F,$A53A,$B8FB,$DBD3,$EE92,$A63C
                dc.w    $B9C7,$DC3B,$EEC4,$A73E,$BA93,$DCA3,$EEF6,$A841,$BB5F,$DD0B,$EF28,$A943,$BC2C,$DD73,$EF5A,$AA45
                dc.w    $BCF8,$DDDB,$EF8C,$AB47,$BDC4,$DE44,$EFBE,$AC49,$BE91,$DEAC,$EFF1,$AD4C,$BF5D,$DF14,$F023,$AE4E
                dc.w    $C029,$DF7C,$F055,$AF50,$C0F5,$DFE4,$F087,$B052,$C1C2,$E04C,$F0B9,$B154,$C28E,$E0B4,$F0EB,$B257
                dc.w    $C35A,$E11C,$F11D,$B359,$C427,$E184,$F150,$B45B,$C4F3,$E1EC,$F182,$B55D,$C5BF,$E254,$F1B4,$B65F
                dc.w    $C68C,$E2BC,$F1E6,$B762,$C758,$E324,$F218,$B864,$C824,$E38C,$F24A,$B966,$C8F0,$E3F4,$F27C,$BA68
                dc.w    $C9BD,$E45C,$F2AF,$BB6B,$CA89,$E4C4,$F2E1,$BC6D,$CB55,$E52D,$F313,$BD6F,$CC22,$E595,$F345,$BE71
                dc.w    $CCEE,$E5FD,$F377,$BF73,$CDBA,$E665,$F3A9,$C076,$CE86,$E6CD,$F3DB,$C178,$CF53,$E735,$F40E,$C27A
                dc.w    $D01F,$E79D,$F440,$C37C,$D0EB,$E805,$F472,$C47E,$D1B8,$E86D,$F4A4,$C581,$D284,$E8D5,$F4D6,$C683
                dc.w    $D350,$E93D,$F508,$C785,$D41C,$E9A5,$F53A,$C887,$D4E9,$EA0D,$F56D,$C989,$D5B5,$EA75,$F59F,$CA8C
                dc.w    $D681,$EADD,$F5D1,$CB8E,$D74E,$EB45,$F603,$CC90,$D81A,$EBAD,$F635,$CD92,$D8E6,$EC16,$F667,$CE94
                dc.w    $D9B3,$EC7E,$F69A,$CF97,$DA7F,$ECE6,$F6CC,$D099,$DB4B,$ED4E,$F6FE,$D19B,$DC17,$EDB6,$F730,$D29D
                dc.w    $DCE4,$EE1E,$F762,$D39F,$DDB0,$EE86,$F794,$D4A2,$DE7C,$EEEE,$F7C6,$D5A4,$DF49,$EF56,$F7F9,$D6A6
                dc.w    $E015,$EFBE,$F82B,$D7A8,$E0E1,$F026,$F85D,$D8AA,$E1AD,$F08E,$F88F,$D9AD,$E27A,$F0F6,$F8C1,$DAAF
                dc.w    $E346,$F15E,$F8F3,$DBB1,$E412,$F1C6,$F925,$DCB3,$E4DF,$F22E,$F958,$DDB6,$E5AB,$F297,$F98A,$DEB8
                dc.w    $E677,$F2FF,$F9BC,$DFBA,$E743,$F367,$F9EE,$E0BC,$E810,$F3CF,$FA20,$E1BE,$E8DC,$F437,$FA52,$E2C1
                dc.w    $E9A8,$F49F,$FA84,$E3C3,$EA75,$F507,$FAB7,$E4C5,$EB41,$F56F,$FAE9,$E5C7,$EC0D,$F5D7,$FB1B,$E6C9
                dc.w    $ECDA,$F63F,$FB4D,$E7CC,$EDA6,$F6A7,$FB7F,$E8CE,$EE72,$F70F,$FBB1,$E9D0,$EF3E,$F777,$FBE3,$EAD2
                dc.w    $F00B,$F7DF,$FC16,$EBD4,$F0D7,$F847,$FC48,$ECD7,$F1A3,$F8AF,$FC7A,$EDD9,$F270,$F917,$FCAC,$EEDB
                dc.w    $F33C,$F980,$FCDE,$EFDD,$F408,$F9E8,$FD10,$F0DF,$F4D4,$FA50,$FD42,$F1E2,$F5A1,$FAB8,$FD75,$F2E4
                dc.w    $F66D,$FB20,$FDA7,$F3E6,$F739,$FB88,$FDD9,$F4E8,$F806,$FBF0,$FE0B,$F5EA,$F8D2,$FC58,$FE3D,$F6ED
                dc.w    $F99E,$FCC0,$FE6F,$F7EF,$FA6A,$FD28,$FEA1,$F8F1,$FB37,$FD90,$FED4,$F9F3,$FC03,$FDF8,$FF06,$FAF5
                dc.w    $FCCF,$FE60,$FF38,$FBF8,$FD9C,$FEC8,$FF6A,$FCFA,$FE68,$FF30,$FF9C,$FDFC,$FF34,$FF98,$FFCE,$FEFE
                dc.w    $0000,$0000,$0000,$0000,$00CC,$0068,$0032,$0102,$0198,$00D0,$0064,$0204,$0264,$0138,$0096,$0306
                dc.w    $0331,$01A0,$00C8,$0408,$03FD,$0208,$00FA,$050B,$04C9,$0270,$012C,$060D,$0596,$02D8,$015F,$070F
                dc.w    $0662,$0340,$0191,$0811,$072E,$03A8,$01C3,$0913,$07FA,$0410,$01F5,$0A16,$08C7,$0478,$0227,$0B18
                dc.w    $0993,$04E0,$0259,$0C1A,$0A5F,$0548,$028B,$0D1C,$0B2C,$05B0,$02BE,$0E1E,$0BF8,$0618,$02F0,$0F21
                dc.w    $0CC4,$0680,$0322,$1023,$0D90,$06E9,$0354,$1125,$0E5D,$0751,$0386,$1227,$0F29,$07B9,$03B8,$1329
                dc.w    $0FF5,$0821,$03EA,$142C,$10C2,$0889,$041D,$152E,$118E,$08F1,$044F,$1630,$125A,$0959,$0481,$1732
                dc.w    $1326,$09C1,$04B3,$1834,$13F3,$0A29,$04E5,$1937,$14BF,$0A91,$0517,$1A39,$158B,$0AF9,$0549,$1B3B
                dc.w    $1658,$0B61,$057C,$1C3D,$1724,$0BC9,$05AE,$1D3F,$17F0,$0C31,$05E0,$1E42,$18BD,$0C99,$0612,$1F44
                dc.w    $1989,$0D01,$0644,$2046,$1A55,$0D69,$0676,$2148,$1B21,$0DD2,$06A8,$224A,$1BEE,$0E3A,$06DB,$234D
                dc.w    $1CBA,$0EA2,$070D,$244F,$1D86,$0F0A,$073F,$2551,$1E53,$0F72,$0771,$2653,$1F1F,$0FDA,$07A3,$2756
                dc.w    $1FEB,$1042,$07D5,$2858,$20B7,$10AA,$0807,$295A,$2184,$1112,$083A,$2A5C,$2250,$117A,$086C,$2B5E
                dc.w    $231C,$11E2,$089E,$2C61,$23E9,$124A,$08D0,$2D63,$24B5,$12B2,$0902,$2E65,$2581,$131A,$0934,$2F67
                dc.w    $264D,$1382,$0966,$3069,$271A,$13EA,$0999,$316C,$27E6,$1453,$09CB,$326E,$28B2,$14BB,$09FD,$3370
                dc.w    $297F,$1523,$0A2F,$3472,$2A4B,$158B,$0A61,$3574,$2B17,$15F3,$0A93,$3677,$2BE4,$165B,$0AC6,$3779
                dc.w    $2CB0,$16C3,$0AF8,$387B,$2D7C,$172B,$0B2A,$397D,$2E48,$1793,$0B5C,$3A7F,$2F15,$17FB,$0B8E,$3B82
                dc.w    $2FE1,$1863,$0BC0,$3C84,$30AD,$18CB,$0BF2,$3D86,$317A,$1933,$0C25,$3E88,$3246,$199B,$0C57,$3F8A
                dc.w    $3312,$1A03,$0C89,$408D,$33DE,$1A6B,$0CBB,$418F,$34AB,$1AD3,$0CED,$4291,$3577,$1B3C,$0D1F,$4393
                dc.w    $3643,$1BA4,$0D51,$4495,$3710,$1C0C,$0D84,$4598,$37DC,$1C74,$0DB6,$469A,$38A8,$1CDC,$0DE8,$479C
                dc.w    $3974,$1D44,$0E1A,$489E,$3A41,$1DAC,$0E4C,$49A1,$3B0D,$1E14,$0E7E,$4AA3,$3BD9,$1E7C,$0EB0,$4BA5
                dc.w    $3CA6,$1EE4,$0EE3,$4CA7,$3D72,$1F4C,$0F15,$4DA9,$3E3E,$1FB4,$0F47,$4EAC,$3F0B,$201C,$0F79,$4FAE
                dc.w    $3FD7,$2084,$0FAB,$50B0,$40A3,$20EC,$0FDD,$51B2,$416F,$2154,$100F,$52B4,$423C,$21BC,$1042,$53B7
                dc.w    $4308,$2225,$1074,$54B9,$43D4,$228D,$10A6,$55BB,$44A1,$22F5,$10D8,$56BD,$456D,$235D,$110A,$57BF
                dc.w    $4639,$23C5,$113C,$58C2,$4705,$242D,$116E,$59C4,$47D2,$2495,$11A1,$5AC6,$489E,$24FD,$11D3,$5BC8
                dc.w    $496A,$2565,$1205,$5CCA,$4A37,$25CD,$1237,$5DCD,$4B03,$2635,$1269,$5ECF,$4BCF,$269D,$129B,$5FD1
                dc.w    $4C9B,$2705,$12CD,$60D3,$4D68,$276D,$1300,$61D5,$4E34,$27D5,$1332,$62D8,$4F00,$283D,$1364,$63DA
                dc.w    $4FCD,$28A6,$1396,$64DC,$5099,$290E,$13C8,$65DE,$5165,$2976,$13FA,$66E0,$5232,$29DE,$142C,$67E3
                dc.w    $52FE,$2A46,$145F,$68E5,$53CA,$2AAE,$1491,$69E7,$5496,$2B16,$14C3,$6AE9,$5563,$2B7E,$14F5,$6BEB
                dc.w    $562F,$2BE6,$1527,$6CEE,$56FB,$2C4E,$1559,$6DF0,$57C8,$2CB6,$158C,$6EF2,$5894,$2D1E,$15BE,$6FF4
                dc.w    $5960,$2D86,$15F0,$70F7,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
                dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000


; U and V correction table.
; The following table is ordered like this : u0, v0, u1, v2, u2, v2, etc
; For each value delivered by the SAA9051, the table provides the corresponding
; u and v components within CCIR range [-112; 112] + 128.
; SAA9051 range (U) : [-51; 50].
; SAA9051 range (V) : [-54; 53].

UV_Table        dc.b    $81,$81,$83,$83,$86,$85,$88,$87,$8A,$89,$8C,$8C,$8E,$8E,$91,$90
                dc.b    $93,$92,$95,$94,$97,$96,$9A,$98,$9C,$9A,$9E,$9C,$A0,$9E,$A2,$A0
                dc.b    $A5,$A3,$A7,$A5,$A9,$A7,$AB,$A9,$AD,$AB,$B0,$AD,$B2,$AF,$B4,$B1
                dc.b    $B6,$B3,$B9,$B5,$BB,$B7,$BD,$BA,$BF,$BC,$C1,$BE,$C4,$C0,$C6,$C2
                dc.b    $C8,$C4,$CA,$C6,$CD,$C8,$CF,$CA,$D1,$CC,$D3,$CF,$D5,$D1,$D8,$D3
                dc.b    $DA,$D5,$DC,$D7,$DE,$D9,$E0,$DB,$E3,$DD,$E5,$DF,$E7,$E1,$E9,$E3
                dc.b    $EC,$E6,$EE,$E8,$F0,$EA,$F0,$EC,$F0,$EE,$F0,$F0,$F0,$F0,$F0,$F0
                dc.b    $F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0
                dc.b    $10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10
                dc.b    $10,$10,$10,$10,$10,$10,$10,$12,$10,$14,$10,$16,$12,$18,$14,$1A
                dc.b    $17,$1D,$19,$1F,$1B,$21,$1D,$23,$20,$25,$22,$27,$24,$29,$26,$2B
                dc.b    $28,$2D,$2B,$2F,$2D,$31,$2F,$34,$31,$36,$33,$38,$36,$3A,$38,$3C
                dc.b    $3A,$3E,$3C,$40,$3F,$42,$41,$44,$43,$46,$45,$49,$47,$4B,$4A,$4D
                dc.b    $4C,$4F,$4E,$51,$50,$53,$53,$55,$55,$57,$57,$59,$59,$5B,$5B,$5D
                dc.b    $5E,$60,$60,$62,$62,$64,$64,$66,$66,$68,$69,$6A,$6B,$6C,$6D,$6E
                dc.b    $6F,$70,$72,$72,$74,$74,$76,$77,$78,$79,$7A,$7B,$7D,$7D,$7F,$7F

