📄 m_jcode.asm
字号:
;------------------------------------------------------------------------------
; Program : m_jcode.asm
; Version : I
; Date : Sept 00
; Purpose : For demo new adpcm algorithm (JCODE).
; : using D/A output.
; Resource :
; Timer 1 : not used.
; Timer 2 : speech sampling interrupt, 8k sampling rate.
; Description :
; Using D-version ICE target board.
; MCU : dual clock, 4MHz Crystal, 32768Hz Slow clock.
; To play the voice, press any Port D key(s).
; Usage :
; 1. For demonstrate how to link with jadpcm.obj for JCODE
; voice output.
; 2. Function call inside nc_main.obj
; a. .tc_int() - for initialize the variables.
; b. .tc_play() - calling within interrupt routine.
; - a 7-bit encoded data is placed in
; - a variable named as voice.
; 3. RAM used.
; Total of 15 bytes used.
; a. b_talk_end - 0ffh : means the voice is being stopped.
; - 0 : means the voice is being played.
; b. speechtpp,high,low - 3 bytes, for storing the speech pointer.
; c. Other - see below RAM declaration.
;
; 4. Procedure
; a. turn on voc and pwmc.
; b. play head if nescessary (for d/a output).
; c. setup .speechtpp,high,low
; d. call .tc_int()
; e. setup timer 1 or 2 for speech sampling time.
; f. enable timer 1 or 2 for speech playing
; g. check b_talk_end to know when speech ends.
;
;--------------------------------------------------------------------------
;------------------------------
; constant declaration
;------------------------------
t8ksample equ 332 ;(4M/1.5/8000)-1
silence_level equ 40h
pcm_end_code equ 0xff
;------------------------------
; RAM declaration
;------------------------------
.area DATA(ABS,PAG)
acc: .ds 1
mirr_flag: .ds 1
;--------------------------------------------------------------
; The following RAM is used for JCODE encoding.
; It can be released when not in used JCODE voice playing.
;--------------------------------------------------------------
speechlow:: .ds 1
speechhigh:: .ds 1
speechtpp:: .ds 1
b_talk_end:: .ds 1
voice:: .ds 1
v_int_tpl:: .ds 1
v_int_tph:: .ds 1
v_talk_data:: .ds 1
x:: .ds 1
p_voice:: .ds 1
q_index:: .ds 1
s_data:: .ds 1
k:: .ds 1
j:: .ds 1
b_talk_high:: .ds 1
;------------------------------
; main program
;------------------------------
.area RCODE(ABS)
org 0x00
br main
org 0x03
br ttrap1
org 0x06
br int1
org 0x09
br tc1
org 0x0c
br tc2
org 0x0f
br int2
.STARTUP::
.area CODE
tc1:
reti
ttrap1:
rett
int1:
reti
int2:
reti
;----------------------------------------------------------------------
;
; function : tc2() interrupt service function
;
;----------------------------------------------------------------------
tc2:
;save acc., flag
sta acc
lda r_op1
sta mirr_flag
;play JCODE routine
lda b_talk_end
cmpe #00
brnz tc2_ret
;call JCODE library
call .tc_play
lda voice
sta r_pwmc
tc2_ret:
;restore acc. and flag
lda mirr_flag
sta r_op1
lda acc
reti
;------------------------------------------------------
;
; function : play_head()
;
;------------------------------------------------------
play_head:
lda #0
play_head_l0:
sta r_pwmc
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
inca
cmpe #silence_level
brnz play_head_l0
play_head_ed:
ret
;------------------------------------------------------
;
; function : play_tail()
;
;------------------------------------------------------
play_tail:
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
call dummy_loop
lda voice
deca
sta voice
sta r_pwmc
cmpe #0
brnz play_tail
ret
;------------------------------------------
;
; function : dummy_loop()
;
;------------------------------------------
dummy_loop:
br dummy_loop0
dummy_loop0:
br dummy_loop1
dummy_loop1:
ret
;------------------------------------------------------
;
; function : turn on voc and play_head
;
;------------------------------------------------------
on_voc_head:
lda #00h
sta r_pwmc
lda #06h
sta r_voc ;on pwm, d/a
lda #87h
sta r_pwmc
call play_head
lda #0f7h
sta r_pwmc
ret
;------------------------------------------------------
;
; function : turn off voc and play_tail
;
;------------------------------------------------------
off_voc_tail:
lda #087h
sta r_pwmc
call play_tail
lda #00H
sta r_voc
lda #080h
sta r_pwmc
ret
;-----------------------------------------------------------------------------
;
; main program
;
;-----------------------------------------------------------------------------
main:
lda #0
sta r_pp
sta r_dp
clr_loop:
lda #0
sta i
lda r_dp
cmpe #07fh
brz clr_end
incdp
br clr_loop
clr_end:
;setup i/o port
lda #0ffh ;set port c and port d be high (i/p).
sta r_prtc
sta r_prtd
lda #07fh ;set sp to 7fh
sta r_sp
;---------------------------------------------------------------------------
;
; demo mode
;
;---------------------------------------------------------------------------
demo_d80:
lda r_prtd
cmpe #0ffh
brz demo_d80
play_voice:
lda #0ffh
sta b_talk_end
call on_voc_head ;on voc and play head
;setup the speech pointer
lda #<v1
sta speechlow
lda #>v1
sta speechhigh
lda #00h
sta speechtpp
call .tc_int ;initialize the jcode1 algorithm RAM
;setup tc2 counter for 8khz
lda #>t8ksample
sta r_t2h
lda #<t8ksample
sta r_t2l
lda #00011000b ;normal, fast clock, enable INT,
;use TC2, use TC1 , z=0, c=0
sta r_op1
lda #00000010b ;enable tc2
sta r_ier
;loop until voice end
demo_voice_loop:
lda b_talk_end ;00=>play, 0ffh=>stop
cmpe #0
brz demo_voice_loop
;voice end
lda #00000000b ;off TC2, off TC1 , z=0, c=0
sta r_op1
lda #00000000b ;disable tc2
sta r_ier
call off_voc_tail ;off voc and play tail
br demo_d80
;------------------------------------
;
; END OF PROGRAM
;
;------------------------------------
v1:
.include "8khvo.inc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -