1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Andree Buschmann 2011-05-15 13:40:02 +00:00
parent 322bbf7c00
commit bf46e634b4
5 changed files with 45 additions and 39 deletions

View file

@ -27,7 +27,7 @@ CODEC_HEADER
#define CHUNK_SIZE (1024*2) #define CHUNK_SIZE (1024*2)
static byte samples[CHUNK_SIZE] IBSS_ATTR; /* The sample buffer */ 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 */ /* this is the codec entry point */
enum codec_status codec_main(enum codec_entry_call_reason reason) 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 */ /* Sample depth is 16 bit little endian */
ci->configure(DSP_SET_SAMPLE_DEPTH, 16); ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
/* Stereo or Mono output ? */ /* Stereo or Mono output ? */
if(asap.module_info.channels ==1) if(asap.module_info->channels ==1)
{ {
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
bytesPerSample = 2; bytesPerSample = 2;
@ -89,8 +89,8 @@ enum codec_status codec_run(void)
/* reset eleapsed */ /* reset eleapsed */
ci->set_elapsed(0); ci->set_elapsed(0);
song = asap.module_info.default_song; song = asap.module_info->default_song;
duration = asap.module_info.durations[song]; duration = asap.module_info->durations[song];
if (duration < 0) if (duration < 0)
duration = 180 * 1000; duration = 180 * 1000;

View file

@ -286,7 +286,7 @@ FUNC(void, Cpu_RunScanlines, (P(ASAP_State PTR, ast), P(int, scanlines)))
cycle = ast _ cycle; cycle = ast _ cycle;
if (cycle >= ast _ nearest_event_cycle) { if (cycle >= ast _ nearest_event_cycle) {
if (cycle >= ast _ next_scanline_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 _ scanline_number = 0;
ast _ cycle = cycle += 9; ast _ cycle = cycle += 9;
ast _ next_scanline_cycle += 114; ast _ next_scanline_cycle += 114;
@ -337,7 +337,7 @@ FUNC(void, Cpu_RunScanlines, (P(ASAP_State PTR, ast), P(int, scanlines)))
case 0xb2: case 0xb2:
case 0xd2: case 0xd2:
case 0xf2: 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; scanlines = 1;
ast _ cycle = cycle_limit; ast _ cycle = cycle_limit;
break; break;

View file

@ -23,6 +23,9 @@
#include "asap_internal.h" #include "asap_internal.h"
static byte s_memory[65536];
static ASAP_ModuleInfo s_module_info;
#ifdef ASAP_ONLY_INFO #ifdef ASAP_ONLY_INFO
#define GET_PLAYER(name) NULL #define GET_PLAYER(name) NULL
@ -35,7 +38,7 @@ FUNC(int, ASAP_GetByte, (P(ASAP_State PTR, ast), P(int, addr)))
{ {
switch (addr & 0xff1f) { switch (addr & 0xff1f) {
case 0xd014: case 0xd014:
return ast _ module_info.ntsc ? 0xf : 1; return ast _ module_info->ntsc ? 0xf : 1;
case 0xd20a: case 0xd20a:
case 0xd21a: case 0xd21a:
return PokeySound_GetRandom(ast, addr, ast _ cycle); 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 else
ast _ cycle = ast _ next_scanline_cycle + 106; 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); V(PokeyState PTR, pst);
addr &= 3; addr &= 3;
if (addr == 0 || addr == 3) if (addr == 0 || addr == 3)
@ -1379,8 +1382,11 @@ FUNC(abool, ASAP_Load, (
P(ASAP_State PTR, ast), P(STRING, filename), P(ASAP_State PTR, ast), P(STRING, filename),
P(CONST BYTEARRAY, module), P(int, module_len))) 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; 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))) 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 _ current_duration = duration;
ast _ blocks_played = 0; ast _ blocks_played = 0;
ast _ silence_cycles_counter = ast _ silence_cycles; 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 _ consol = 8;
ast _ covox[0] = CAST(byte) 0x80; ast _ covox[0] = CAST(byte) 0x80;
ast _ covox[1] = 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 _ timer2_cycle = NEVER;
ast _ timer4_cycle = NEVER; ast _ timer4_cycle = NEVER;
ast _ irqst = 0xff; ast _ irqst = 0xff;
switch (ast _ module_info.type) { switch (ast _ module_info->type) {
case ASAP_TYPE_SAP_B: 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; break;
case ASAP_TYPE_SAP_C: case ASAP_TYPE_SAP_C:
#ifndef ASAP_ONLY_SAP #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_CMR:
case ASAP_TYPE_CMS: case ASAP_TYPE_CMS:
#endif #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, 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, 0x00, song, 0);
break; break;
case ASAP_TYPE_SAP_D: case ASAP_TYPE_SAP_D:
case ASAP_TYPE_SAP_S: 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_x = 0x00;
ast _ cpu_y = 0x00; ast _ cpu_y = 0x00;
ast _ cpu_s = 0xff; ast _ cpu_s = 0xff;
ast _ cpu_pc = ast _ module_info.init; ast _ cpu_pc = ast _ module_info->init;
break; break;
#ifndef ASAP_ONLY_SAP #ifndef ASAP_ONLY_SAP
case ASAP_TYPE_DLT: 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; break;
case ASAP_TYPE_MPT: 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, 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, 0x02, ast _ module_info->song_pos[song], 0);
break; break;
case ASAP_TYPE_RMT: 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; break;
case ASAP_TYPE_TMC: case ASAP_TYPE_TMC:
case ASAP_TYPE_TM2: 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, 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, 0x00, song, 0);
ast _ tmc_per_frame_counter = 1; ast _ tmc_per_frame_counter = 1;
break; break;
#endif #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))) 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); PokeySound_StartFrame(ast);
switch (ast _ module_info.type) { switch (ast _ module_info->type) {
case ASAP_TYPE_SAP_B: case ASAP_TYPE_SAP_B:
call_6502(ast, player, ast _ module_info.fastplay); call_6502(ast, player, ast _ module_info->fastplay);
break; break;
case ASAP_TYPE_SAP_C: case ASAP_TYPE_SAP_C:
#ifndef ASAP_ONLY_SAP #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_CMR:
case ASAP_TYPE_CMS: case ASAP_TYPE_CMS:
#endif #endif
call_6502(ast, player + 6, ast _ module_info.fastplay); call_6502(ast, player + 6, ast _ module_info->fastplay);
break; break;
case ASAP_TYPE_SAP_D: case ASAP_TYPE_SAP_D:
if (player >= 0) { 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 */ dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */
ast _ cpu_pc = player; ast _ cpu_pc = player;
} }
Cpu_RunScanlines(ast, ast _ module_info.fastplay); Cpu_RunScanlines(ast, ast _ module_info->fastplay);
break; break;
case ASAP_TYPE_SAP_S: 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; V(int, i) = dGetByte(0x45) - 1;
dPutByte(0x45, i); dPutByte(0x45, i);
@ -1538,28 +1544,28 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
break; break;
#ifndef ASAP_ONLY_SAP #ifndef ASAP_ONLY_SAP
case ASAP_TYPE_DLT: case ASAP_TYPE_DLT:
call_6502(ast, player + 0x103, ast _ module_info.fastplay); call_6502(ast, player + 0x103, ast _ module_info->fastplay);
break; break;
case ASAP_TYPE_MPT: case ASAP_TYPE_MPT:
case ASAP_TYPE_RMT: case ASAP_TYPE_RMT:
case ASAP_TYPE_TM2: case ASAP_TYPE_TM2:
call_6502(ast, player + 3, ast _ module_info.fastplay); call_6502(ast, player + 3, ast _ module_info->fastplay);
break; break;
case ASAP_TYPE_TMC: case ASAP_TYPE_TMC:
if (--ast _ tmc_per_frame_counter <= 0) { if (--ast _ tmc_per_frame_counter <= 0) {
ast _ tmc_per_frame_counter = ast _ tmc_per_frame; 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 else
call_6502(ast, player + 6, ast _ module_info.fastplay); call_6502(ast, player + 6, ast _ module_info->fastplay);
break; break;
#endif #endif
} }
PokeySound_EndFrame(ast, ast _ module_info.fastplay * 114); PokeySound_EndFrame(ast, ast _ module_info->fastplay * 114);
if (ast _ silence_cycles > 0) { if (ast _ silence_cycles > 0) {
if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey) if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey)
&& PokeySound_IsSilent(ADDRESSOF ast _ extra_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) if (ast _ silence_cycles_counter <= 0)
return FALSE; return FALSE;
} }
@ -1606,7 +1612,7 @@ FUNC(void, ASAP_GetWavHeader, (
P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format))) 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, 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, bytes_per_second) = ASAP_SAMPLE_RATE * block_size;
V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration); V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration);
V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size; V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size;
@ -1629,7 +1635,7 @@ FUNC(void, ASAP_GetWavHeader, (
buffer[19] = 0; buffer[19] = 0;
buffer[20] = 1; buffer[20] = 1;
buffer[21] = 0; buffer[21] = 0;
buffer[22] = CAST(byte) ast _ module_info.channels; buffer[22] = CAST(byte) ast _ module_info->channels;
buffer[23] = 0; buffer[23] = 0;
serialize_int(buffer, 24, ASAP_SAMPLE_RATE); serialize_int(buffer, 24, ASAP_SAMPLE_RATE);
serialize_int(buffer, 28, bytes_per_second); 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 #ifdef ACTIONSCRIPT
block_shift = 0; block_shift = 0;
#else #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 #endif
buffer_blocks = buffer_len >> block_shift; buffer_blocks = buffer_len >> block_shift;
if (ast _ current_duration > 0) { if (ast _ current_duration > 0) {

View file

@ -179,7 +179,7 @@ typedef struct {
int samples; int samples;
int iir_acc_left; int iir_acc_left;
int iir_acc_right; int iir_acc_right;
ASAP_ModuleInfo module_info; ASAP_ModuleInfo *module_info;
int tmc_per_frame; int tmc_per_frame;
int tmc_per_frame_counter; int tmc_per_frame_counter;
int current_song; int current_song;
@ -189,7 +189,7 @@ typedef struct {
int silence_cycles_counter; int silence_cycles_counter;
byte poly9_lookup[511]; byte poly9_lookup[511];
byte poly17_lookup[16385]; byte poly17_lookup[16385];
byte memory[65536]; byte *memory;
} ASAP_State; } ASAP_State;
/* Parses the string in the "mm:ss.xxx" format /* Parses the string in the "mm:ss.xxx" format

View file

@ -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 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 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)) #define CYCLE_TO_SAMPLE(cycle) TO_INT(((cycle) * ASAP_SAMPLE_RATE + ast _ sample_offset) / ASAP_MAIN_CLOCK(ast))
#endif /* _ASAP_INTERNAL_H_ */ #endif /* _ASAP_INTERNAL_H_ */