home *** CD-ROM | disk | FTP | other *** search
- page 132,63,1,1
- opt rc
- title 'LPC Vocoder interface protocol handler'
-
- ;***************************************************************
- ;* PROTOCOL.ASM -- LPC Vocoder interface protocol handler *
- ;* *
- ;* Handles a special serial interface protocol for Vocoder *
- ;* *
- ;* Copyright (C) 1992 by Alef Null. All rights reserved. *
- ;* Author(s): Jarkko Vuori, OH2LNS *
- ;* Modification(s): *
- ;* 26-Sep-92: corrected negative pitch problem *
- ;* added block count field to Host-DSP frame *
- ;***************************************************************
-
- section LPCprotocol
- xdef pro_i,get_blk,put_blk
-
- org p:
-
- nolist
- include 'macros'
- list
-
-
- ; Protocol parameters
- sync1 equ $55 ; frame sync words
- sync2 equ $aa
- blks equ 20 ; number of 48-bit block in one frame
-
-
- ; Macro to change state (in reader state machine)
- nxt macro state
- movi state,x:gstate
- jmp <get_blk
- endm
-
-
- ; Initialize protocol handler data structures
- pro_i movi gstate0,x:gstate
- movi 1,x:oblkcnt
-
- rts
-
-
- ; Get one LPC parameter block (if there are any available)
- ; returns C if no block available
- ; NC if block available
- get_blk jsr <getc
- jcs <getend
- move x:gstate,r0
- nop
- jmp (r0)
-
- ; State 0 - first sync word
- gstate0 move #>sync1,a
- cmp x0,a
- jne <get_blk
- nxt gstate1
-
- ; State 1 - second sync word
- gstate1 move #>sync2,a
- cmp x0,a
- jne <gs1a
- nxt gstate2
- gs1a nxt gstate0
-
- ; State 2 - flags byte
- gstate2 move x:<flags,a1
- move #>$ffff00,x1 ; replace lower flag bits
- and x1,a
- or x0,a
- move a1,x:<flags
- nxt gstate3
-
- ; State 3 - p_d byte
- gstate3 move #>128,a ; check if 8-bit negative number
- cmp x0,a x0,x:<p_d
- jgt <_pos
- asl a ; yes, convert to 24-bit negative number -(256 - x0)
- sub x0,a
- neg a
- move a,x:<p_d
- _pos movi blks,x:iblkcnt
- nxt gstate4
-
- ; State 4 - first block byte
- gstate4 move #>@cvi(@pow(2,16-1)),x1 ; shift left 16 bits
- mpy x0,x1,a
- move a0,x:tmpblk
- nxt gstate5
-
- ; State 5 - second block byte
- gstate5 move #>@cvi(@pow(2,8-1)),x1 ; shift left 8 bits
- mpy x0,x1,a x:tmpblk,x0
- move a0,a1
- or x0,a
- move a1,x:tmpblk
- nxt gstate6
-
- ; State 6 - third block byte
- gstate6 move x:tmpblk,a
- or x0,a
- move a1,x:tmpblk
- nxt gstate7
-
- ; State 7 - 4th block byte
- gstate7 move #>@cvi(@pow(2,16-1)),x1 ; shift left 16 bits
- mpy x0,x1,a
- move a0,x:tmpblk+1
- nxt gstate8
-
- ; State 8 - 5th block byte
- gstate8 move #>@cvi(@pow(2,8-1)),x1 ; shift left 8 bits
- mpy x0,x1,a x:tmpblk+1,x0
- move a0,a1
- or x0,a
- move a1,x:tmpblk+1
- nxt gstate9
-
- ; State 9 - last block byte
- gstate9 move x:tmpblk+1,a
- or x0,a #>1,x0
- move a1,x:tmpblk+1
-
- move x:iblkcnt,a ; check if end of frame
- sub x0,a #>gstate4,x0
- jne <_gs9a
- move #blks,a1
- move #>gstate0,x0
- _gs9a move a1,x:iblkcnt
- move x0,x:gstate
-
- move x:tmpblk,a1 ; return block
- move a1,x:lpcin
- move x:tmpblk+1,a1
- move a1,x:lpcin+1
- andi #$fe,ccr
-
- getend rts
-
-
- ; Send one LPC parameter block
- put_blk move x:oblkcnt,a
- move #>1,x0
- sub x0,a #>blks,x0
- move a,x:oblkcnt
- jne _puta
- move x0,x:oblkcnt
-
- move #>sync1,x0 ; put header
- jsr <putc
- move #>sync2,x0
- jsr <putc
- move x:<flags,x0
- jsr <putc
- move x:<p_d,x0
- jsr <putc
-
- _puta move #lpcout,r0
- jsr <wordout
- move #lpcout+1,r0
- jsr <wordout
-
- rts
-
-
- ; Output one word
- wordout
- move x:(r0),a1 ; most significand byte
- lsr a #@pow(2,-15),x1 ; this is needed because 24th bit is sign bit
- move a1,x0
- mpy x0,x1,a #>$ff,x0
- and x0,a
- move a1,x0
- jsr <putc
-
- move x:(r0),x0 ; middle byte
- move #@pow(2,-8),x1
- mpy x0,x1,a #>$ff,x0
- and x0,a
- move a1,x0
- jsr <putc
-
- move x:(r0),a1 ; lest significand byte
- move #>$ff,x0
- and x0,a
- move a1,x0
- jsr <putc
-
- rts
-
-
- ;****************************
- ;* DATA - AREA *
- ;****************************
-
- org x:
-
- gstate ds 1
- tmpblk ds 2
- iblkcnt ds 1
- oblkcnt ds 1
-
- endsec
-
- end
-