From b30a8e675aa1ea0056dca9d04cd3d6e58db51094 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 20 Jan 2007 23:11:02 +0000 Subject: [PATCH] code940 now plays mp3s git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@22 be3aeb3a-fb24-0410-a615-afba39da0efa --- gp2x/940.c | 93 ----------------------- gp2x/940ctl_ym2612.c | 8 +- gp2x/940init.s | 176 ------------------------------------------- gp2x/940shared.h | 35 --------- gp2x/Makefile | 55 ++------------ gp2x/gp2x.c | 4 + 6 files changed, 13 insertions(+), 358 deletions(-) delete mode 100644 gp2x/940.c delete mode 100644 gp2x/940init.s delete mode 100644 gp2x/940shared.h diff --git a/gp2x/940.c b/gp2x/940.c deleted file mode 100644 index e94bf21..0000000 --- a/gp2x/940.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "940shared.h" - -static _940_data_t *shared_data = (_940_data_t *) 0x100000; -static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x200000; -YM2612 *ym2612_940; -int *mix_buffer; - -// from init.s -void wait_irq(void); -void spend_cycles(int c); -void cache_clean(void); -void cache_clean_flush(void); - -// asm volatile ("mov r0, #0" ::: "r0"); -// asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */ -// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */ - -void Main940(int startvector) -{ - ym2612_940 = &shared_data->ym2612; - mix_buffer = shared_data->mix_buffer; - - // debug - shared_ctl->vstarts[startvector]++; - asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); - - - for (;; shared_ctl->loopc++) - { - int job_num; -/* - while (!shared_ctl->busy) - { - //shared_ctl->waitc++; - spend_cycles(256); - } -*/ - if (!shared_ctl->busy) - { - wait_irq(); - } - - for (job_num = 0; job_num < MAX_940JOBS; job_num++) - { - switch (shared_ctl->jobs[job_num]) - { - case JOB940_YM2612INIT: - shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff; - YM2612Init_(shared_ctl->baseclock, shared_ctl->rate); - break; - - case JOB940_YM2612RESETCHIP: - YM2612ResetChip_(); - break; - - case JOB940_PICOSTATELOAD: - YM2612PicoStateLoad_(); - break; - - case JOB940_YM2612UPDATEONE: { - int i, dw, *wbuff; - if (shared_ctl->writebuffsel == 1) { - wbuff = (int *) shared_ctl->writebuff1; - } else { - wbuff = (int *) shared_ctl->writebuff0; - } - - /* playback all writes */ - for (i = 2048/2; i > 0; i--) { - UINT16 d; - dw = *wbuff++; - d = dw; - if (d == 0xffff) break; - YM2612Write_(d >> 8, d); - d = (dw>>16); - if (d == 0xffff) break; - YM2612Write_(d >> 8, d); - } - - YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo); - break; - } - } - } - - shared_ctl->busy = 0; -// cache_clean_flush(); - cache_clean(); -// asm volatile ("mov r0, #0" ::: "r0"); -// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */ - } -} - diff --git a/gp2x/940ctl_ym2612.c b/gp2x/940ctl_ym2612.c index 4dc320d..35bf4a7 100644 --- a/gp2x/940ctl_ym2612.c +++ b/gp2x/940ctl_ym2612.c @@ -7,7 +7,7 @@ #include #include -#include "940shared.h" +#include "code940/940shared.h" #include "gp2x.h" #include "emu.h" #include "menu.h" @@ -235,11 +235,11 @@ static void wait_busy_940(void) printf("wait iterations: %i\n", i); #else for (i = 0; shared_ctl->busy && i < 0x10000; i++) - spend_cycles(4*1024); + spend_cycles(8*1024); // tested to be best for mp3 dec if (i < 0x10000) return; /* 940 crashed */ - printf("940 crashed (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc); + printf("940 crashed (cnt: %i, ve: ", shared_ctl->loopc); for (i = 0; i < 8; i++) printf("%i ", shared_ctl->vstarts[i]); printf(")\n"); @@ -373,7 +373,7 @@ void YM2612Init_940(int baseclock, int rate) /* now cause 940 to init it's ym2612 stuff */ shared_ctl->baseclock = baseclock; shared_ctl->rate = rate; - shared_ctl->jobs[0] = JOB940_YM2612INIT; + shared_ctl->jobs[0] = JOB940_INITALL; shared_ctl->jobs[1] = 0; shared_ctl->busy = 1; diff --git a/gp2x/940init.s b/gp2x/940init.s deleted file mode 100644 index 771511f..0000000 --- a/gp2x/940init.s +++ /dev/null @@ -1,176 +0,0 @@ -.global code940 - -code940: @ interrupt table: - b .b_reset @ reset - b .b_undef @ undefined instructions - b .b_swi @ software interrupt - b .b_pabort @ prefetch abort - b .b_dabort @ data abort - b .b_reserved @ reserved - b .b_irq @ IRQ - b .b_fiq @ FIQ - -@ test -.b_reset: - mov r12, #0 - b .Begin -.b_undef: - mov r12, #1 - b .Begin -.b_swi: - mov r12, #2 - b .Begin -.b_pabort: - mov r12, #3 - b .Begin -.b_dabort: - mov r12, #4 - b .Begin -.b_reserved: - mov r12, #5 - b .Begin -.b_irq: - mov r12, #6 - mov sp, #0x100000 @ reset stack - sub sp, sp, #4 - mov r1, #0xbe000000 @ assume we live @ 0x2000000 bank - orr r2, r1, #0x3B00 - orr r2, r2, #0x0046 - mvn r3, #0 - strh r3, [r2] @ clear any pending interrupts from the DUALCPU unit - orr r2, r1, #0x4500 - str r3, [r2] @ clear all pending interrupts in irq controller's SRCPND register - orr r2, r2, #0x0010 - str r3, [r2] @ clear all pending interrupts in irq controller's INTPND register - b .Enter -.b_fiq: - mov r12, #7 - b .Begin - -.Begin: - mov sp, #0x100000 @ set the stack top (1M) - sub sp, sp, #4 @ minus 4 - - @ set up memory region 0 -- the whole 4GB address space - mov r0, #(0x1f<<1)|1 @ region data - mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr - mcr p15, 0, r0, c6, c0, 1 - - @ set up region 1 which is the first 2 megabytes. - mov r0, #(0x14<<1)|1 @ region data - mcr p15, 0, r0, c6, c1, 0 - mcr p15, 0, r0, c6, c1, 1 - - @ set up region 2: 64k 0x200000-0x210000 - mov r0, #(0x0f<<1)|1 - orr r0, r0, #0x200000 - mcr p15, 0, r0, c6, c2, 0 - mcr p15, 0, r0, c6, c2, 1 - - @ set up region 3: 64k 0xbe000000-0xbe010000 (hw control registers) - mov r0, #(0x0f<<1)|1 - orr r0, r0, #0xbe000000 - mcr p15, 0, r0, c6, c3, 0 - mcr p15, 0, r0, c6, c3, 1 - - @ set region 1 to be cacheable (so the first 2M will be cacheable) - mov r0, #2 - mcr p15, 0, r0, c2, c0, 0 - mcr p15, 0, r0, c2, c0, 1 - - @ set region 1 to be bufferable too (only data) - mcr p15, 0, r0, c3, c0, 0 - - @ set protection, allow accsess only to regions 1 and 2 - mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0] - mcr p15, 0, r0, c5, c0, 0 - mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no] - mcr p15, 0, r0, c5, c0, 1 - - mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg - orr r0, r0, #1 @ 0x00000001: enable protection unit - orr r0, r0, #4 @ 0x00000004: enable D cache - orr r0, r0, #0x1000 @ 0x00001000: enable I cache - orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus - mcr p15, 0, r0, c1, c0, 0 @ set control reg - - @ flush (invalidate) the cache (just in case) - mov r0, #0 - mcr p15, 0, r0, c7, c6, 0 - -.Enter: - mov r0, r12 - bl Main940 - - @ we should never get here -.b_deadloop: - b .b_deadloop - - - -@ so asm utils are also defined here: -.global spend_cycles @ c - -spend_cycles: - mov r0, r0, lsr #2 @ 4 cycles/iteration - sub r0, r0, #2 @ entry/exit/init -.sc_loop: - subs r0, r0, #1 - bpl .sc_loop - - bx lr - - -@ clean-flush function from ARM940T technical reference manual -.global cache_clean_flush - -cache_clean_flush: - mov r1, #0 @ init line counter -ccf_outer_loop: - mov r0, #0 @ segment counter -ccf_inner_loop: - orr r2, r1, r0 @ make segment and line address - mcr p15, 0, r2, c7, c14, 2 @ clean and flush that line - add r0, r0, #0x10 @ incremet secment counter - cmp r0, #0x40 @ complete all 4 segments? - bne ccf_inner_loop - add r1, r1, #0x04000000 @ increment line counter - cmp r1, #0 @ complete all lines? - bne ccf_outer_loop - bx lr - - -@ clean-only version -.global cache_clean - -cache_clean: - mov r1, #0 @ init line counter -cf_outer_loop: - mov r0, #0 @ segment counter -cf_inner_loop: - orr r2, r1, r0 @ make segment and line address - mcr p15, 0, r2, c7, c10, 2 @ clean that line - add r0, r0, #0x10 @ incremet secment counter - cmp r0, #0x40 @ complete all 4 segments? - bne cf_inner_loop - add r1, r1, #0x04000000 @ increment line counter - cmp r1, #0 @ complete all lines? - bne cf_outer_loop - bx lr - - -.global wait_irq - -wait_irq: - mrs r0, cpsr - bic r0, r0, #0x80 - msr cpsr_c, r0 @ enable interrupts - - mov r0, #0 - mcr p15, 0, r0, c7, c0, 4 @ wait for IRQ -@ mcr p15, 0, r0, c15, c8, 2 - b .b_reserved - -.pool - -@ vim:filetype=ignored: diff --git a/gp2x/940shared.h b/gp2x/940shared.h deleted file mode 100644 index bad0f3c..0000000 --- a/gp2x/940shared.h +++ /dev/null @@ -1,35 +0,0 @@ -#include "../../Pico/sound/ym2612.h" - -enum _940_job_t { - JOB940_YM2612INIT = 1, - JOB940_YM2612RESETCHIP, - JOB940_YM2612UPDATEONE, - JOB940_PICOSTATELOAD, - JOB940_NUMJOBS -}; - -#define MAX_940JOBS 2 - -typedef struct -{ - YM2612 ym2612; /* current state of the emulated YM2612 */ - int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ - short mp3_buffer[2][1152*2]; /* buffer for mp3 decoder's output */ -} _940_data_t; - - -typedef struct -{ - int jobs[MAX_940JOBS]; /* jobs for second core */ - int busy; /* busy status of the 940 core */ - int length; /* number of samples to mix (882 max) */ - int stereo; /* mix samples as stereo, doubles sample count automatically */ - int baseclock; /* ym2612 settings */ - int rate; - int writebuffsel; /* which write buffer to use (from 940 side) */ - UINT16 writebuff0[2048]; /* list of writes to ym2612, 1024 for savestates, 1024 extra */ - UINT16 writebuff1[2048]; - int vstarts[8]; /* debug: number of starts from each of 8 vectors */ - int loopc; /* debug: main loop counter */ - int waitc; /* debug: wait loop counter */ -} _940_ctl_t; diff --git a/gp2x/Makefile b/gp2x/Makefile index 602e4f6..11e6749 100644 --- a/gp2x/Makefile +++ b/gp2x/Makefile @@ -1,8 +1,6 @@ # you may or may not need to change this #devkit_path = x:/stuff/dev/devkitgp2x/ -devkit_path = /usr/local/devkitPro/devkitGP2X/ -lgcc_path = $(devkit_path)lib/gcc/arm-linux/4.0.3/ CROSS = arm-linux- #CROSS = $(devkit_path)bin/arm-linux- @@ -17,7 +15,7 @@ asm_ym2612 = 1 #use_musashi = 1 #up = 1 -DEFINC = -I../.. -I. -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK +DEFINC = -I../.. -I. -DARM -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK COPT_COMMON = -static -s -O3 -ftracer -fstrength-reduce -Wall -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math ifeq "$(profile)" "1" COPT_COMMON += -fprofile-generate @@ -80,7 +78,7 @@ DEFINC += -D_USE_DRZ80 OBJS += ../../cpu/DrZ80/drz80.o endif -all: PicoDrive.gpe code940.bin +all: PicoDrive.gpe PicoDrive.gpe : $(OBJS) @echo $@ @@ -92,15 +90,11 @@ ifeq "$(up)" "1" @cmd //C copy $@ \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ endif -up: # up940 +up: @cp -v PicoDrive.gpe /mnt/gp2x/mnt/sd/games/PicoDrive/ # @cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ -up940: - @cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/ - -# @cmd //C copy code940.bin \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ testrefr.gpe : test.o gp2x.o asmutils.o @echo $@ @@ -133,45 +127,13 @@ testrefr.gpe : test.o gp2x.o asmutils.o @make -C ../../cpu/Cyclone/proj -f Makefile.linux -# stuff for 940 core - -# init, emu_control, emu -OBJS940 += 940init.o 940.o 940ym2612.o -# the asm code seems to be faster when run on 920, but not on 940 for some reason -# OBJS940 += ../../Pico/sound/ym2612_asm.o - -# uClibc library code -OBJS940 += uClibc/memset.o uClibc/s_floor.o uClibc/e_pow.o uClibc/e_sqrt.o uClibc/s_fabs.o -OBJS940 += uClibc/s_scalbn.o uClibc/s_copysign.o uClibc/k_sin.o uClibc/k_cos.o uClibc/s_sin.o -OBJS940 += uClibc/e_rem_pio2.o uClibc/k_rem_pio2.o uClibc/e_log.o uClibc/wrappers.o - -code940.bin : code940.gpe - @echo $@ - @$(OBJCOPY) -O binary $< $@ - -code940.gpe : $(OBJS940) - @echo $@ - @$(LD) -static -e code940 -Ttext 0x0 $^ -L$(lgcc_path) -lgcc -o $@ - -940ym2612.o : ../../Pico/sound/ym2612.c - @echo $@ - @$(GCC) $(COPT_COMMON) -mtune=arm940t $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@ - - # cleanup -clean: clean_pd clean_940 -tidy: tidy_pd tidy_940 - -clean_pd: tidy_pd +clean: tidy @$(RM) PicoDrive.gpe -tidy_pd: +tidy: @$(RM) $(OBJS) # @make -C ../../cpu/Cyclone/proj -f Makefile.linux clean -clean_940: tidy_940 - @$(RM) code940.bin -tidy_940: - @$(RM) code940.gpe $(OBJS940) clean_prof: find ../.. -name '*.gcno' -delete @@ -190,10 +152,3 @@ usbjoy.o : usbjoy.c @echo $< @$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@ -uClibc/e_pow.o : uClibc/e_pow.c - @echo $< - @$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@ - -uClibc/e_sqrt.o : uClibc/e_sqrt.c - @echo $< - @$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@ diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index d1a844f..18c5e48 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -204,6 +204,10 @@ void gp2x_sound_write(void *buff, int len) write(sounddev, buff, len); } +void gp2x_sound_sync(void) +{ + ioctl(sounddev, SOUND_PCM_SYNC, 0); +} void gp2x_sound_volume(int l, int r) { -- 2.39.2