;******************************************************************************
;            (C) Copyright 1992-1995, Radius, Inc. and Atari Corp.
; Secret and confidential                                   All rights reserved
;******************************************************************************
; This source code and any compilation or derivative thereof is the joint
; property of Radius, Inc. and Atari Corp.  This code is provided pursuant
; to a Software License Agreement and/or Software Development Contract.  This
; code is the proprietary information of Radius, Inc. and Atari Corp. and is
; confidential in nature.  Its use and dissemination by any party other than
; Atari Corp. are strictly limited by the confidential information provisions
; of the Agreement or Contract referenced above.
;******************************************************************************
; 100 14 Sep 95 JPE     Initial revision.
; 101 08 Nov 95 JPE     Official legal banner added (no other changes).
;******************************************************************************

.include    'player.inc'

MakeRGBTables:
        movem.l d0-d3/a0-a2,-(a7)       ; Save registers

        lea     rgbTables,a1            ; Destination address
        lea     scaleFactors,a2         ; Table of scale factors
        move    #6-1,d3                 ; Loop counter for tables

TableLoop:
        movea.l #DECOMP_S,a0            ; Start of GPU code in DRAM
        adda.l  #RGB_OFFSET,a0          ; Add offset to RGB tables
        move    (a2)+,d1                ; Scale factor for this table
        move    #(RGB_SIZE/4)-1,d2      ; Loop counter for entries

EntryLoop:
        move.l  (a0)+,d0                ; Get source value
        mulu    d1,d0                   ; Scale up
        lsr     #3,d0                   ; Divide down
        move.l  d0,(a1)+                ; Save to destination
        dbra    d2,EntryLoop            ; Loop until all entries done

        dbra    d3,TableLoop            ; Loop until all tables done

        movem.l (a7)+,d0-d3/a0-a2       ; Restore registers
        rts

scaleFactors:
        dc.w    7,6,5,4,2,0

        .bss
        .long

rgbTables:
        ds.b    RGB_SIZE                ; 7/8 full scale
        ds.b    RGB_SIZE                ; 3/4 full scale
        ds.b    RGB_SIZE                ; 5/8 full scale
        ds.b    RGB_SIZE                ; 1/2 full scale
        ds.b    RGB_SIZE                ; 1/4 full scale
        ds.b    RGB_SIZE                ; Zero

        .extern DECOMP_S

        .globl  MakeRGBTables
        .globl  rgbTables

        .end
