***************************************************************
* (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 1996 *
***************************************************************
* FILE NAME: FDCT.ASM *
* *
* HISTORY: This program is originally written in TMS320C5x *
* assembly language by G. Peake of Texas *
* Instruments, Inc. *
* *
* TRANSLATORS: Rushani Wirasinghe *
* Xiaozhen Zhang *
* *
* DESCRIPTION: *
* - Forward DCT algorithm. *
* - Code written in TMS320C54x assembly language. *
* - Files: Fdct.asm (This file) *
* Dct.doc (DCT Documentation) *
* fdct.cmd (Linker Command File) *
* Fdct_dat.inc *
* - Import Functions: none *
* - Import Data: none *
* - Export Functions: none *
* - Export Data: none *
* *
* LAST DAY MODIFIED: August 23, 1996 *
***************************************************************
.mmregs
.def entry
.sect "INIT"
*
* Initialise
*
entry NOP
NOP
SSBX SXM ; set sign extension mode
SSBX OVM ; enable saturation
LD #0, DP ; set data page
STM 0FFE0h, PMST ; Init PMST reg.
* ||||| | ||||||
* ----+ | |||||+- BRAF - reset block RPT active
* | | ||||+-- TRM - C5X T-reg mode
* | | |||+--- NDX - C5x Index reg mode
* | | ||+---- MP/MC - MC mode
* | | |+----- RAM - SPRAM = @prog
* | | +------ OVLY - SPRAM = @data
* | +-------- AVIS - no addr line visibility
* +------------ IPTR - Interrupt vectors at 000h
*
RSBX FRCT
.include "fdct_dat.inc" ; FDCT data storage declaration
MODE .SET 1 ; MODE=1 TEST ON SIMULATOR
PAGE0 .SET 0
PAGE4 .SET 4
PAGE24 .SET 24d
PAGE25 .SET 25d
B0 .SET 0200h
B1 .SET 0300h
B2 .SET 060h
PA1BIS .SET 1
PA2BIS .SET 2
PA3BIS .SET 3
PA4BIS .SET 4
PA5BIS .SET 5
PA6BIS .SET 6
* Initialization of the registers
.sect "FDCT"
INIT LD #PAGE24, DP
ST #21407, E_P6
ST #8867, F_P6
ST #2000H, ROUND1
TBL: LD #PAGE25, DP
ST #21407, E_P7
ST #8867, F_P7
ST #4000H, ROUND2
ST #40H, ROUND3
START
***********************************************************************
* READ A 8x8 BLOCK AND PLACE IT IN X(M,N) *
* *
***********************************************************************
* IF MODE = SIMULATOR
.IF MODE=1
STM #63, AR0 ; AR0= # of inputs to be taken - 1
STM #X, AR1 ; AR1= address of first input
BEG PORTR #PA1BIS, *AR1+ ; Read and store to addr(AR1)
NOP
NOP
BANZ BEG, *AR0- ; Repeat above code 64 times
; till all 64 pixels are read
.ENDIF
; ******************************************
; * *
; * FIRST STEP : *
; * *
; * CALCULATE INNER TRANSFORM *
; * (PROCESS INPUT ROWS) *
; * *
; ******************************************
STM #3, AR0
STM #X, AR1 ; Reset AR1 to first input
STM #Y00, AR2 ; Set AR2 to first Y block
*********************************************************************
; *
; PROCESS FIRST 8 INPUTS. X(0,0)...X(0,7) -> Y(0,0)...Y(0,7) *
; *
*********************************************************************
DCT1 NOP
NOP
LD #PAGE24, DP
LD *AR1+, 4, A ; + (16)*(X0)
ADD *AR1+, 4, A ; + (16)*(X1)
ADD *AR1+, 4, A ; + (16)*(X2)
ADD *AR1+, 4, A ; + (16)*(X3)
ADD *AR1+, 4, A ; + (16)*(X4)
ADD *AR1+, 4, A ; + (16)*(X5)
ADD *AR1+, 4, A ; + (16)*(X6)
ADD *AR1, 4,A ; + (16)*(X7)
STL A, Y00 ; = Y00
RPTZ A, #7
MACP *AR1-, COEF_F1, A
SFTA A, 4
MAR *AR1+ ; (64)[A*X0+B*X1+C*X2-D*X3-D*X4
ADD ROUND1, A ; -C*X5-B*X6-A*X7] + 4*ROUND1
STH A, 2, Y01 ; = Y01
LD ROUND1, -4, A ; (ROUND1)/16
LD E_P6, T
MAC *AR1+0, A ; + X0*E_P6
MAS *AR1+, A ; - X3*E_P6
MAS *AR1+0, A ; - X4*E_P6
MAC *AR1-, A ; + X7*E_P6
LD F_P6, T
MAC *AR1-, A ; + X6*F_P6
MAS *AR1-0, A ; - X5*F_P6
MAS *AR1-, A ; - X2*F_P6
MAC *AR1-, A ; + X1*F_P6
STH A, 6, Y02 ; Multiply prev summation by 16
; = Y02
RPTZ A, #7
MACP *AR1+, COEFF2, A ; 64(B*X0-D*X1-A*X2-C*X3+C*X4+A*X5
SFTA A, 4
MAR *AR1-
ADD ROUND1, A ; +D*X6-B*X7) + 4*ROUND1
STH A, 2, Y03 ; = Y03
LD *AR1-, 4, A ; X7*16
SUB *AR1-, 4, A ; - X6*16
SUB *AR1-, 4, A ; - X5*16
ADD *AR1-, 4, A ; + X4*16
ADD *AR1-, 4, A ; + X3*16
SUB *AR1-, 4, A ; - X2*16
SUB *AR1-, 4, A ; - X1*16
ADD *AR1, 4, A ; + X0*16
STL A, Y04 ; = Y04
RPTZ A, #7
MACP *AR1+, COEFF3, A ; 8(D*X0-C*X1+B*X2-A*X3+A*X4-B*X5
SFTA A, 4 ; +C*X6-D*X7)
MAR *AR1-
ADD ROUND1, A ; + 4*ROUND1
STH A, 2, Y05 ; = Y05
LD ROUND1, -4, A ; (ROUND1)/16
LD F_P6, T
MAC *AR1-0, A ; + F_P6*X7
MAS *AR1-, A ; - F_P6*X4
MAS *AR1-0, A ; - F_P6*X3
MAC *AR1+, A ; + F_P6*X0
LD E_P6, T
MAS *AR1+, A ; - E_P6*X1
MAC *AR1+0, A ; + E_P6*X2
MAC *AR1+, A ; + E_P6*X5
MAS *AR1+, A ; - E_P6*X6
STH A, 6, Y06 ; Multiply prev summation by 16
; = Y06
RPTZ A, #7
MACP *AR1-, COEF_F4, A ; 64(D*X0-C*X1+B*X2-A*X3+A*X4-B*X5
SFTA A, 4 ; +C*X6-D*X7)
MAR *AR1+
ADD ROUND1, A ; + 4*ROUND1
STH A, 2, Y07 ; = Y07
MAR *+AR1(8) ; Set AR1 to point to the next set
; of 8 inputs
*********************************************************************
; *
; PROCESS SECOND 8 INPUTS. X(1,0)...X(1,7) -> Y(1,0)...Y(1,7) *
; *
*********************************************************************
LD *AR1+, 4, A ; + (16)*(X0)
ADD *AR1+, 4, A ; + (16)*(X1)
ADD *AR1+, 4, A ; + (16)*(X2)
ADD *AR1+, 4, A ; + (16)*(X3)
ADD *AR1+, 4, A ; + (16)*(X4)
ADD *AR1+, 4, A ; + (16)*(X5)
ADD *AR1+, 4, A ; + (16)*(X6)
ADD *AR1, 4, A ; + (16)*(X7)
STL A, Y10 ; = Y10
RPTZ A, #7
MACP *AR1-, COEF_F1, A
SFTA A, 4
MAR *AR1+ ; (64)[A*X0+B*X1+C*X2-D*X3-D*X4
ADD ROUND1, A ; -C*X5-B*X6-A*X7] + 4*ROUND1
STH A, 2, Y11 ; = Y11
LD ROUND1, -4, A ; (ROUND1)/16
LD E_P6, T
MAC *AR1+0, A ; + X0*E_P6
MAS *AR1+, A ; - X3*E_P6
MAS *AR1+0, A ; - X4*E_P6
MAC *AR1-, A ; + X7*E_P6
LD F_P6, T
MAC *AR1-, A ; + X6*F_P6
MAS *AR1-0, A ; - X5*F_P6
MAS *AR1-, A ; - X2*F_P6
MAC *AR1-, A ; + X1*F_P6
STH A, 6, Y12 ; Multiply prev summation by 16
; = Y12
RPTZ A, #7
MACP *AR1+, COEFF2, A ; 64(B*X0-D*X1-A*X2-C*X3+C*X4+A*X5
SFTA A, 4
MAR *AR1-
ADD ROUND1, A ; +D*X6-B*X7) + 4*ROUND1
STH A, 2, Y13 ; = Y13
LD *AR1-, 4, A ; X7*16
SUB *AR1-, 4, A ; - X6*16
SUB *AR1-, 4, A ; - X5*16
ADD *AR1-, 4, A ; + X4*16
ADD *AR1-, 4, A ; + X3*16
SUB *AR1-, 4, A ; - X2*16
SUB *AR1-, 4, A ; - X1*16
ADD *AR1, 4, A ; + X0*16
STL A, Y14 ; = Y14
RPTZ A, #7
MACP *AR1+, COEFF3, A ; 8(D*X0-C*X1+B*X2-A*X3+A*X4-B*X5
SFTA A, 4 ; +C*X6-D*X7)
MAR *AR1-
ADD ROUND1, A ; + 4*ROUND1
STH A, 2, Y15 ; = Y15
LD ROUND1, -4, A ; (ROUND1)/16
LD F_P6, T
MAC *AR1-0, A ; + F_P6*X7
MAS *AR1-, A ; - F_P6*X4
MAS *AR1-0, A ; - F_P6*X3
MAC *AR1+, A ; + F_P6*X0
LD E_P6, T
MAS *AR1+, A ; - E_P6*X1
MAC *AR1+0, A ; + E_P6*X2
MAC *AR1+, A ; + E_P6*X5
MAS *AR1+, A ; - E_P6*X6
STH A, 6, Y16 ; Multiply prev summation by 16
; = Y16
RPTZ A, #7
MACP *AR1-, COEF_F4, A ; 64(D*X0-C*X1+B*X2-A*X3+A*X4-B*X5
SFTA A, 4 ; +C*X6-D*X7)
MAR *AR1+
ADD ROUND1, A ; + 4*ROUND1
STH A, 2, Y17 ; = Y17
MAR *+AR1(8) ; Set AR1 to point to the next set
; of 8 inputs
*********************************************************************
; *
; PROCESS THIRD 8 INPUTS. X(2,0)...X(2,7) -> Y(2,0)...Y(2,7) *
; *
*********************************************************************
LD *AR1+, 4, A ; + (16)*(X0)
ADD *AR1+, 4, A ; + (16)*(X1)
ADD *AR1+, 4, A ; + (16)*(X2)
ADD *AR1+, 4, A ; + (16)*(X3)
ADD *AR1+, 4, A ; + (16)*(X4)
ADD *AR1+, 4, A ; + (16)*(X5)
ADD *AR1+, 4, A ; + (16)*(X6)
ADD *AR1, 4, A ; + (16)*(X7)
STL A, Y20 ; = Y20
RPTZ A, #7
MACP *AR1-, COEF_F1, A
SFTA A, 4
MAR *AR1+ ; (64)[A*X0+B*X1+C*X2-D*X3-D*X4
ADD ROUND1, A ; -C*X5-B*X6-A*X7] + 4*ROUND1
STH A, 2, Y21 ; = Y21
LD ROUND1, -4, A ; (ROUND1)/16
LD E_P6, T
MAC *AR1+0, A ; + X0*E_P6
MAS *AR1+, A ; - X3*E_P6
MAS *AR1+0, A ; - X4*E_P6
MAC *AR1-, A ; + X7*E_P6
LD F_P6, T
|