From fb7828d26f396f7b26ef93dd0b67059f963a8c06 Mon Sep 17 00:00:00 2001 From: Buschel Date: Sun, 15 May 2011 13:40:02 +0000 Subject: [PATCH] FS#12113: Optimize IRAM configuration for Atari SAP format. Performance gains range from 5% (PP5020), over 13-16% (PP5002, PP5022, PP5024, S5L870x) to 115% (MCF5249, MCF5250). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29883 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/asap.c | 8 ++--- apps/codecs/libasap/acpu.c | 4 +-- apps/codecs/libasap/asap.c | 66 ++++++++++++++++++++----------------- apps/codecs/libasap/asap.h | 4 +-- apps/codecs/libasap/asap_internal.h | 2 +- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/apps/codecs/asap.c b/apps/codecs/asap.c index 5d098eda1..19b39a44c 100644 --- a/apps/codecs/asap.c +++ b/apps/codecs/asap.c @@ -27,7 +27,7 @@ CODEC_HEADER #define CHUNK_SIZE (1024*2) static byte samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */ -static ASAP_State asap; /* asap codec state */ +static ASAP_State asap IBSS_ATTR; /* asap codec state */ /* this is the codec entry point */ enum codec_status codec_main(enum codec_entry_call_reason reason) @@ -76,7 +76,7 @@ enum codec_status codec_run(void) /* Sample depth is 16 bit little endian */ ci->configure(DSP_SET_SAMPLE_DEPTH, 16); /* Stereo or Mono output ? */ - if(asap.module_info.channels ==1) + if(asap.module_info->channels ==1) { ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); bytesPerSample = 2; @@ -89,8 +89,8 @@ enum codec_status codec_run(void) /* reset eleapsed */ ci->set_elapsed(0); - song = asap.module_info.default_song; - duration = asap.module_info.durations[song]; + song = asap.module_info->default_song; + duration = asap.module_info->durations[song]; if (duration < 0) duration = 180 * 1000; diff --git a/apps/codecs/libasap/acpu.c b/apps/codecs/libasap/acpu.c index 0e91f9083..0fd5988b8 100644 --- a/apps/codecs/libasap/acpu.c +++ b/apps/codecs/libasap/acpu.c @@ -286,7 +286,7 @@ FUNC(void, Cpu_RunScanlines, (P(ASAP_State PTR, ast), P(int, scanlines))) cycle = ast _ cycle; if (cycle >= ast _ nearest_event_cycle) { if (cycle >= ast _ next_scanline_cycle) { - if (++ast _ scanline_number == (ast _ module_info.ntsc ? 262 : 312)) + if (++ast _ scanline_number == (ast _ module_info->ntsc ? 262 : 312)) ast _ scanline_number = 0; ast _ cycle = cycle += 9; ast _ next_scanline_cycle += 114; @@ -337,7 +337,7 @@ FUNC(void, Cpu_RunScanlines, (P(ASAP_State PTR, ast), P(int, scanlines))) case 0xb2: case 0xd2: case 0xf2: - ast _ scanline_number = (ast _ scanline_number + scanlines - 1) % (ast _ module_info.ntsc ? 262 : 312); + ast _ scanline_number = (ast _ scanline_number + scanlines - 1) % (ast _ module_info->ntsc ? 262 : 312); scanlines = 1; ast _ cycle = cycle_limit; break; diff --git a/apps/codecs/libasap/asap.c b/apps/codecs/libasap/asap.c index 510807362..1aeb843fa 100644 --- a/apps/codecs/libasap/asap.c +++ b/apps/codecs/libasap/asap.c @@ -23,6 +23,9 @@ #include "asap_internal.h" +static byte s_memory[65536]; +static ASAP_ModuleInfo s_module_info; + #ifdef ASAP_ONLY_INFO #define GET_PLAYER(name) NULL @@ -35,7 +38,7 @@ FUNC(int, ASAP_GetByte, (P(ASAP_State PTR, ast), P(int, addr))) { switch (addr & 0xff1f) { case 0xd014: - return ast _ module_info.ntsc ? 0xf : 1; + return ast _ module_info->ntsc ? 0xf : 1; case 0xd20a: case 0xd21a: return PokeySound_GetRandom(ast, addr, ast _ cycle); @@ -91,7 +94,7 @@ FUNC(void, ASAP_PutByte, (P(ASAP_State PTR, ast), P(int, addr), P(int, data))) else ast _ cycle = ast _ next_scanline_cycle + 106; } - else if ((addr & 0xff00) == ast _ module_info.covox_addr) { + else if ((addr & 0xff00) == ast _ module_info->covox_addr) { V(PokeyState PTR, pst); addr &= 3; if (addr == 0 || addr == 3) @@ -1379,8 +1382,11 @@ FUNC(abool, ASAP_Load, ( P(ASAP_State PTR, ast), P(STRING, filename), P(CONST BYTEARRAY, module), P(int, module_len))) { + /* Set up ast */ + ast _ memory = s_memory; + ast _ module_info = &s_module_info; ast _ silence_cycles = 0; - return parse_file(ast, ADDRESSOF ast _ module_info, filename, module, module_len); + return parse_file(ast, ast _ module_info, filename, module, module_len); } FUNC(void, ASAP_DetectSilence, (P(ASAP_State PTR, ast), P(int, seconds))) @@ -1416,7 +1422,7 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration ast _ current_duration = duration; ast _ blocks_played = 0; ast _ silence_cycles_counter = ast _ silence_cycles; - ast _ extra_pokey_mask = ast _ module_info.channels > 1 ? 0x10 : 0; + ast _ extra_pokey_mask = ast _ module_info->channels > 1 ? 0x10 : 0; ast _ consol = 8; ast _ covox[0] = CAST(byte) 0x80; ast _ covox[1] = CAST(byte) 0x80; @@ -1433,9 +1439,9 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration ast _ timer2_cycle = NEVER; ast _ timer4_cycle = NEVER; ast _ irqst = 0xff; - switch (ast _ module_info.type) { + switch (ast _ module_info->type) { case ASAP_TYPE_SAP_B: - call_6502_init(ast, ast _ module_info.init, song, 0, 0); + call_6502_init(ast, ast _ module_info->init, song, 0, 0); break; case ASAP_TYPE_SAP_C: #ifndef ASAP_ONLY_SAP @@ -1444,8 +1450,8 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration case ASAP_TYPE_CMR: case ASAP_TYPE_CMS: #endif - call_6502_init(ast, ast _ module_info.player + 3, 0x70, ast _ module_info.music, ast _ module_info.music >> 8); - call_6502_init(ast, ast _ module_info.player + 3, 0x00, song, 0); + call_6502_init(ast, ast _ module_info->player + 3, 0x70, ast _ module_info->music, ast _ module_info->music >> 8); + call_6502_init(ast, ast _ module_info->player + 3, 0x00, song, 0); break; case ASAP_TYPE_SAP_D: case ASAP_TYPE_SAP_S: @@ -1453,23 +1459,23 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration ast _ cpu_x = 0x00; ast _ cpu_y = 0x00; ast _ cpu_s = 0xff; - ast _ cpu_pc = ast _ module_info.init; + ast _ cpu_pc = ast _ module_info->init; break; #ifndef ASAP_ONLY_SAP case ASAP_TYPE_DLT: - call_6502_init(ast, ast _ module_info.player + 0x100, 0x00, 0x00, ast _ module_info.song_pos[song]); + call_6502_init(ast, ast _ module_info->player + 0x100, 0x00, 0x00, ast _ module_info->song_pos[song]); break; case ASAP_TYPE_MPT: - call_6502_init(ast, ast _ module_info.player, 0x00, ast _ module_info.music >> 8, ast _ module_info.music); - call_6502_init(ast, ast _ module_info.player, 0x02, ast _ module_info.song_pos[song], 0); + call_6502_init(ast, ast _ module_info->player, 0x00, ast _ module_info->music >> 8, ast _ module_info->music); + call_6502_init(ast, ast _ module_info->player, 0x02, ast _ module_info->song_pos[song], 0); break; case ASAP_TYPE_RMT: - call_6502_init(ast, ast _ module_info.player, ast _ module_info.song_pos[song], ast _ module_info.music, ast _ module_info.music >> 8); + call_6502_init(ast, ast _ module_info->player, ast _ module_info->song_pos[song], ast _ module_info->music, ast _ module_info->music >> 8); break; case ASAP_TYPE_TMC: case ASAP_TYPE_TM2: - call_6502_init(ast, ast _ module_info.player, 0x70, ast _ module_info.music >> 8, ast _ module_info.music); - call_6502_init(ast, ast _ module_info.player, 0x00, song, 0); + call_6502_init(ast, ast _ module_info->player, 0x70, ast _ module_info->music >> 8, ast _ module_info->music); + call_6502_init(ast, ast _ module_info->player, 0x00, song, 0); ast _ tmc_per_frame_counter = 1; break; #endif @@ -1485,11 +1491,11 @@ FUNC(void, ASAP_MutePokeyChannels, (P(ASAP_State PTR, ast), P(int, mask))) FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast))) { - V(int, player) = ast _ module_info.player; + V(int, player) = ast _ module_info->player; PokeySound_StartFrame(ast); - switch (ast _ module_info.type) { + switch (ast _ module_info->type) { case ASAP_TYPE_SAP_B: - call_6502(ast, player, ast _ module_info.fastplay); + call_6502(ast, player, ast _ module_info->fastplay); break; case ASAP_TYPE_SAP_C: #ifndef ASAP_ONLY_SAP @@ -1498,7 +1504,7 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast))) case ASAP_TYPE_CMR: case ASAP_TYPE_CMS: #endif - call_6502(ast, player + 6, ast _ module_info.fastplay); + call_6502(ast, player + 6, ast _ module_info->fastplay); break; case ASAP_TYPE_SAP_D: if (player >= 0) { @@ -1525,10 +1531,10 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast))) dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */ ast _ cpu_pc = player; } - Cpu_RunScanlines(ast, ast _ module_info.fastplay); + Cpu_RunScanlines(ast, ast _ module_info->fastplay); break; case ASAP_TYPE_SAP_S: - Cpu_RunScanlines(ast, ast _ module_info.fastplay); + Cpu_RunScanlines(ast, ast _ module_info->fastplay); { V(int, i) = dGetByte(0x45) - 1; dPutByte(0x45, i); @@ -1538,28 +1544,28 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast))) break; #ifndef ASAP_ONLY_SAP case ASAP_TYPE_DLT: - call_6502(ast, player + 0x103, ast _ module_info.fastplay); + call_6502(ast, player + 0x103, ast _ module_info->fastplay); break; case ASAP_TYPE_MPT: case ASAP_TYPE_RMT: case ASAP_TYPE_TM2: - call_6502(ast, player + 3, ast _ module_info.fastplay); + call_6502(ast, player + 3, ast _ module_info->fastplay); break; case ASAP_TYPE_TMC: if (--ast _ tmc_per_frame_counter <= 0) { ast _ tmc_per_frame_counter = ast _ tmc_per_frame; - call_6502(ast, player + 3, ast _ module_info.fastplay); + call_6502(ast, player + 3, ast _ module_info->fastplay); } else - call_6502(ast, player + 6, ast _ module_info.fastplay); + call_6502(ast, player + 6, ast _ module_info->fastplay); break; #endif } - PokeySound_EndFrame(ast, ast _ module_info.fastplay * 114); + PokeySound_EndFrame(ast, ast _ module_info->fastplay * 114); if (ast _ silence_cycles > 0) { if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey) && PokeySound_IsSilent(ADDRESSOF ast _ extra_pokey)) { - ast _ silence_cycles_counter -= ast _ module_info.fastplay * 114; + ast _ silence_cycles_counter -= ast _ module_info->fastplay * 114; if (ast _ silence_cycles_counter <= 0) return FALSE; } @@ -1606,7 +1612,7 @@ FUNC(void, ASAP_GetWavHeader, ( P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format))) { V(int, use_16bit) = format != ASAP_FORMAT_U8 ? 1 : 0; - V(int, block_size) = ast _ module_info.channels << use_16bit; + V(int, block_size) = ast _ module_info->channels << use_16bit; V(int, bytes_per_second) = ASAP_SAMPLE_RATE * block_size; V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration); V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size; @@ -1629,7 +1635,7 @@ FUNC(void, ASAP_GetWavHeader, ( buffer[19] = 0; buffer[20] = 1; buffer[21] = 0; - buffer[22] = CAST(byte) ast _ module_info.channels; + buffer[22] = CAST(byte) ast _ module_info->channels; buffer[23] = 0; serialize_int(buffer, 24, ASAP_SAMPLE_RATE); serialize_int(buffer, 28, bytes_per_second); @@ -1656,7 +1662,7 @@ PRIVATE FUNC(int, ASAP_GenerateAt, (P(ASAP_State PTR, ast), P(VOIDPTR, buffer), #ifdef ACTIONSCRIPT block_shift = 0; #else - block_shift = (ast _ module_info.channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0); + block_shift = (ast _ module_info->channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0); #endif buffer_blocks = buffer_len >> block_shift; if (ast _ current_duration > 0) { diff --git a/apps/codecs/libasap/asap.h b/apps/codecs/libasap/asap.h index 0758b60bf..1cbf8d010 100644 --- a/apps/codecs/libasap/asap.h +++ b/apps/codecs/libasap/asap.h @@ -179,7 +179,7 @@ typedef struct { int samples; int iir_acc_left; int iir_acc_right; - ASAP_ModuleInfo module_info; + ASAP_ModuleInfo *module_info; int tmc_per_frame; int tmc_per_frame_counter; int current_song; @@ -189,7 +189,7 @@ typedef struct { int silence_cycles_counter; byte poly9_lookup[511]; byte poly17_lookup[16385]; - byte memory[65536]; + byte *memory; } ASAP_State; /* Parses the string in the "mm:ss.xxx" format diff --git a/apps/codecs/libasap/asap_internal.h b/apps/codecs/libasap/asap_internal.h index 5367085c7..def444bc2 100644 --- a/apps/codecs/libasap/asap_internal.h +++ b/apps/codecs/libasap/asap_internal.h @@ -109,7 +109,7 @@ void trace_cpu(const ASAP_State *ast, int pc, int a, int x, int y, int s, int nz #define PutByte(addr, data) do { if (((addr) & 0xf900) == 0xd000) ASAP_PutByte(ast, addr, data); else dPutByte(addr, data); } while (FALSE) #define RMW_GetByte(dest, addr) do { if (((addr) >> 8) == 0xd2) { dest = ASAP_GetByte(ast, addr); ast _ cycle--; ASAP_PutByte(ast, addr, dest); ast _ cycle++; } else dest = dGetByte(addr); } while (FALSE) -#define ASAP_MAIN_CLOCK(ast) ((ast) _ module_info.ntsc ? 1789772 : 1773447) +#define ASAP_MAIN_CLOCK(ast) ((ast) _ module_info->ntsc ? 1789772 : 1773447) #define CYCLE_TO_SAMPLE(cycle) TO_INT(((cycle) * ASAP_SAMPLE_RATE + ast _ sample_offset) / ASAP_MAIN_CLOCK(ast)) #endif /* _ASAP_INTERNAL_H_ */ -- 2.11.4.GIT