⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem_play.asm

📁 一款MP3 Player Firmware 的原代码,非常有参考价值
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; MP3 Player, Download and Play from DRAM (no hard drive);   http://www.pjrc.com/tech/mp3; Copyright (c) 2000, PJRC.COM, LLC; This program is free software; you can redistribute it and/or; modify it under the terms of the GNU General Public License; as published by the Free Software Foundation; either version 2; of the License, or (at your option) any later version.; This program is distributed in the hope that it will be useful,; but WITHOUT ANY WARRANTY; without even the implied warranty of; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the; GNU General Public License for more details.; You should have received a copy of the GNU General Public License; along with this program; if not, write to the Free Software; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.; As a specific exception to the GPL, the executable object code built; from this source code may be combined with hardware configuration data; files.  A hardware configuration data file is a set of data that is; transmitted to an intergrated circuit that is not a general purpose; microprocessor or microcontroller, in order to establish its normal; operation.  The process of combining the executable ojbect code built; from the GPL licensed source code with the hardware configuration data; shall be considered an aggregation of another work not based on the; Program.  While the GPL does not restrict use of the program, any; use restriction associated with the hardware configuration data (for; example, that it only be used with particular hardware) shall apply; to the combined file which includes a copy of the hardware configuration; data.; Contact: paul@pjrc.com.equ    location, 0x3000        ;where this program will exist; registers implemented in the DRAM, IDE, and DMA controller.equ    dram_page_cfg,  0xFF00.equ    irq_ident,      0xFF50.equ    dma_mp3_src,    0xFF28.equ    dma_mp3_count,  0xFF2A.equ    dma_mp3_go,     0xFF59.equ    irq_dma_mp3_ack,0xFF5D; library functions in bank1 (bank switch special calling).equ    call_bank1, 0x0FE0.equ    xdownload, 0xA040.equ    sta013_init, 0xA043.equ    alt_xdownload, 0xA049.equ    sta013_rd, 0xA04C.equ    sta013_wr, 0xA04F.equ	paulmon2, 0x006D;internal memory usage.equ	dl_buf, 0x10		;4 bytes.equ	simm_size, 0x14		;1 byte  (0=4M, 1=8M, 2=16M, 3=32M).equ	last_block, 0x15	;2 bytes  ;*************************************************************;**                                                         **;**         Download MP3 file (uuencoded 4k blocks)         **;**                                                         **;*************************************************************.org    location.db     0xA5,0xE5,0xE0,0xA5     ;signiture bytes.db     254,'W',0,0             ;id.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;user defined.db     255,255,255,255         ;length and checksum (255=unused).db     "Download MP3 to DRAM",0.org    location+64             ;executable code begins here	acall	init_memory_mgr	mov	dptr, #msg_begin_dl	lcall	pstr	mov	r2, #40			;always start at block 40	mov	r3, #0	mov	a, #1	acall	map_block		;map block 40 (info) to 0x1000	mov	dptr, #0x1000	clr	a	mov	r4, #128clr_info_loop:	movx	@dptr, a		;clear first 128 bytes of block 40	inc	dptr	djnz	r4, clr_info_loopwait_line_start:	mov	r4, #0wait_line:	acall	cincheck_e:cjne	r4, #0, check_n	cjne	a, #'e', check_crlf	inc	r4	sjmp	wait_linecheck_n:cjne	r4, #1, check_d	cjne	a, #'n', check_crlf	inc	r4	sjmp	wait_linecheck_d:cjne	r4, #2, check_crlf	cjne	a, #'d', check_crlf	ajmp	finish_dlcheck_crlf:	add	a, #256 - 13			;CR ok between lines	jz	wait_line_start	add	a, #(256 - 10 + 13) & 255	;LF ok between lines	jz	wait_line_start	add	a, #256 + 10 - 32		;offset to # bytes	add	a, #256 - 46	jc	err_dl				;# bytes must be 1 to 45	add	a, #46	mov	r1, a				;r1 counts number of bytes	mov	a, #'.'	acall	cout	mov	r0, #dl_buf	mov	a, dph				;check that dptr is in block	anl	a, #0xF0	add	a, #256 - 0x20	jz	wait_data	acall	next_block	mov	a, #2	acall	map_block			;download into 0x2000 to 0x2FFF	mov	dptr, #0x2000wait_data:	acall	cin	add	a, #256 - 32	mov	@r0, a	inc	r0	add	a, #256 - 65	jc	err_dl	add	a, #32 + 65 - 27	jz	abort_dl	cjne	r0, #dl_buf+4, wait_dataextract_1st_byte:	mov	a, dl_buf+0	anl	a, #0x3F	rl	a	rl	a	mov	r4, a	mov	a, dl_buf+1	anl	a, #0x30	swap	a	orl	a, r4	movx	@dptr, a	inc	dptr	dec	r1	mov	a, r1	jz	wait_line_startextract_2nd_byte:	mov	a, dl_buf+1	anl	a, #0x0F	swap	a	mov	r4, a	mov	a, dl_buf+2	anl	a, #0x3C	rr	a	rr	a	orl	a, r4	movx	@dptr, a	inc	dptr	dec	r1	mov	a, r1	jnz	extract_3rd_byte	ajmp	wait_line_startextract_3rd_byte:	mov	a, dl_buf+2	anl	a, #0x03	rr	a	rr	a	mov	r4, a	mov	a, dl_buf+3	anl	a, #0x3F	orl	a, r4	movx	@dptr, a	inc	dptr	dec	r1	mov	a, r1	mov	r0, #dl_buf	jnz	wait_data	ajmp	wait_line_start	;abort on any errorerr_dl:	mov	dptr, #mesg_error	lcall	pstr	;should have a loop here to swallow up incoming bytes	;until a brief time with no bytes received.	ret	;user pressed escabort_dl:	mov	dptr, #mesg_abort	lcall	pstr	ret	;the download was a success, and it's time to write	;the last block numberfinish_dl:	mov	dptr, #0x1000	mov	a, #'M'	movx	@dptr, a	inc	dptr	mov	a, #'P'	movx	@dptr, a	inc	dptr	mov	a, #'3'	movx	@dptr, a	inc	dptr	mov	a, simm_size	movx	@dptr, a	inc	dptr	mov	a, r2	movx	@dptr, a	inc	dptr	mov	a, r3	movx	@dptr, a	mov	dptr, #msg_dl_ok	lcall	pstr	ret;*************************************************************;**                                                         **;**             Play MP3 File From DRAM Memory              **;**                                                         **;*************************************************************.org    location+0x200.db     0xA5,0xE5,0xE0,0xA5     ;signiture bytes.db     254,'S',0,0             ;id.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;user defined.db     255,255,255,255         ;length and checksum (255=unused).db     "MP3 Play From DRAM",0.org    location+0x200+64       ;executable code begins here        mov     dptr, #mesg_sta013_cfg        lcall   pstr        mov     dptr, #sta013_init        lcall   call_bank1        jnc     sta013_ok	mov     dptr, #mesg_error        lcall   pstr	ljmp	paulmon2sta013_ok:        mov     dptr, #mesg_ok        lcall   pstrplay_from_dram:	;first, check that block 40 is mapped at 0x1000	mov	dptr, #dram_page_cfg + 2	movx	a, @dptr	cjne	a, #40, err_dram	inc	dptr	movx	a, @dptr	cjne	a, #0, err_dram		;now read the 6 bytes of heading info at 0x1000	mov	dptr, #0x1000	movx	a, @dptr	cjne	a, #'M', err_mp3	inc	dptr	movx	a, @dptr	cjne	a, #'P', err_mp3	inc	dptr	movx	a, @dptr	cjne	a, #'3', err_mp3	inc	dptr	movx	a, @dptr	mov	simm_size, a	anl	a, #11111100b	jnz	err_mp3	inc	dptr	movx	a, @dptr	mov	last_block+0, a		;read "last block"	inc	dptr	movx	a, @dptr	mov	last_block+1, a	mov	r2, #40	mov	r3, #0	sjmp	play_mp3_fileerr_dram:	mov	dptr, #msg_err_dram	acall	pstr	reterr_mp3:	mov	dptr, #msg_err_mp3	acall	pstr	retplay_mp3_file:	mov	dptr, #msg_play1	acall	pstr	mov	a, r3	acall	phex	mov	a, r2	acall	phex	mov	dptr, #msg_play2	acall	pstr	mov	a, last_block+1	acall	phex	mov	a, last_block+0	acall	phex	acall	newlineplay_loop:	acall	next_block	mov	a, #2	acall	map_block		;map 4k block of mp3 file at 0x2000        mov     dptr, #dma_mp3_src        clr     a        movx    @dptr, a                ;write LSB of src addr        inc     dptr	mov	a, #0x20        movx    @dptr, a                ;write MSB of src addr        mov     dptr, #dma_mp3_count        mov     a, #0        movx    @dptr, a                ;write LSB of length        inc     dptr        mov     a, #8        movx    @dptr, a                ;write MSB of length	mov     dptr, #irq_dma_mp3_ack        movx    @dptr, a                ;clear any previous interrupt        mov     dptr, #dma_mp3_go        movx    @dptr, a                ;begin the transfer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -