summaryrefslogtreecommitdiff
path: root/apps/codecs/libasap/asap.c
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-05-15 13:40:02 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-05-15 13:40:02 +0000
commitbf46e634b4bb5bb00e139e05569a19a55b4b1214 (patch)
tree61fba1d534eedb514a206abde7a9ac2f57e0f684 /apps/codecs/libasap/asap.c
parent322bbf7c00881b701f88713a7f4410ed69775475 (diff)
downloadrockbox-bf46e634b4bb5bb00e139e05569a19a55b4b1214.tar.gz
rockbox-bf46e634b4bb5bb00e139e05569a19a55b4b1214.zip
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
Diffstat (limited to 'apps/codecs/libasap/asap.c')
-rw-r--r--apps/codecs/libasap/asap.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/apps/codecs/libasap/asap.c b/apps/codecs/libasap/asap.c
index 510807362a..1aeb843fa3 100644
--- a/apps/codecs/libasap/asap.c
+++ b/apps/codecs/libasap/asap.c
@@ -23,6 +23,9 @@
23 23
24#include "asap_internal.h" 24#include "asap_internal.h"
25 25
26static byte s_memory[65536];
27static ASAP_ModuleInfo s_module_info;
28
26#ifdef ASAP_ONLY_INFO 29#ifdef ASAP_ONLY_INFO
27 30
28#define GET_PLAYER(name) NULL 31#define GET_PLAYER(name) NULL
@@ -35,7 +38,7 @@ FUNC(int, ASAP_GetByte, (P(ASAP_State PTR, ast), P(int, addr)))
35{ 38{
36 switch (addr & 0xff1f) { 39 switch (addr & 0xff1f) {
37 case 0xd014: 40 case 0xd014:
38 return ast _ module_info.ntsc ? 0xf : 1; 41 return ast _ module_info->ntsc ? 0xf : 1;
39 case 0xd20a: 42 case 0xd20a:
40 case 0xd21a: 43 case 0xd21a:
41 return PokeySound_GetRandom(ast, addr, ast _ cycle); 44 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)))
91 else 94 else
92 ast _ cycle = ast _ next_scanline_cycle + 106; 95 ast _ cycle = ast _ next_scanline_cycle + 106;
93 } 96 }
94 else if ((addr & 0xff00) == ast _ module_info.covox_addr) { 97 else if ((addr & 0xff00) == ast _ module_info->covox_addr) {
95 V(PokeyState PTR, pst); 98 V(PokeyState PTR, pst);
96 addr &= 3; 99 addr &= 3;
97 if (addr == 0 || addr == 3) 100 if (addr == 0 || addr == 3)
@@ -1379,8 +1382,11 @@ FUNC(abool, ASAP_Load, (
1379 P(ASAP_State PTR, ast), P(STRING, filename), 1382 P(ASAP_State PTR, ast), P(STRING, filename),
1380 P(CONST BYTEARRAY, module), P(int, module_len))) 1383 P(CONST BYTEARRAY, module), P(int, module_len)))
1381{ 1384{
1385 /* Set up ast */
1386 ast _ memory = s_memory;
1387 ast _ module_info = &s_module_info;
1382 ast _ silence_cycles = 0; 1388 ast _ silence_cycles = 0;
1383 return parse_file(ast, ADDRESSOF ast _ module_info, filename, module, module_len); 1389 return parse_file(ast, ast _ module_info, filename, module, module_len);
1384} 1390}
1385 1391
1386FUNC(void, ASAP_DetectSilence, (P(ASAP_State PTR, ast), P(int, seconds))) 1392FUNC(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
1416 ast _ current_duration = duration; 1422 ast _ current_duration = duration;
1417 ast _ blocks_played = 0; 1423 ast _ blocks_played = 0;
1418 ast _ silence_cycles_counter = ast _ silence_cycles; 1424 ast _ silence_cycles_counter = ast _ silence_cycles;
1419 ast _ extra_pokey_mask = ast _ module_info.channels > 1 ? 0x10 : 0; 1425 ast _ extra_pokey_mask = ast _ module_info->channels > 1 ? 0x10 : 0;
1420 ast _ consol = 8; 1426 ast _ consol = 8;
1421 ast _ covox[0] = CAST(byte) 0x80; 1427 ast _ covox[0] = CAST(byte) 0x80;
1422 ast _ covox[1] = CAST(byte) 0x80; 1428 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
1433 ast _ timer2_cycle = NEVER; 1439 ast _ timer2_cycle = NEVER;
1434 ast _ timer4_cycle = NEVER; 1440 ast _ timer4_cycle = NEVER;
1435 ast _ irqst = 0xff; 1441 ast _ irqst = 0xff;
1436 switch (ast _ module_info.type) { 1442 switch (ast _ module_info->type) {
1437 case ASAP_TYPE_SAP_B: 1443 case ASAP_TYPE_SAP_B:
1438 call_6502_init(ast, ast _ module_info.init, song, 0, 0); 1444 call_6502_init(ast, ast _ module_info->init, song, 0, 0);
1439 break; 1445 break;
1440 case ASAP_TYPE_SAP_C: 1446 case ASAP_TYPE_SAP_C:
1441#ifndef ASAP_ONLY_SAP 1447#ifndef ASAP_ONLY_SAP
@@ -1444,8 +1450,8 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration
1444 case ASAP_TYPE_CMR: 1450 case ASAP_TYPE_CMR:
1445 case ASAP_TYPE_CMS: 1451 case ASAP_TYPE_CMS:
1446#endif 1452#endif
1447 call_6502_init(ast, ast _ module_info.player + 3, 0x70, ast _ module_info.music, ast _ module_info.music >> 8); 1453 call_6502_init(ast, ast _ module_info->player + 3, 0x70, ast _ module_info->music, ast _ module_info->music >> 8);
1448 call_6502_init(ast, ast _ module_info.player + 3, 0x00, song, 0); 1454 call_6502_init(ast, ast _ module_info->player + 3, 0x00, song, 0);
1449 break; 1455 break;
1450 case ASAP_TYPE_SAP_D: 1456 case ASAP_TYPE_SAP_D:
1451 case ASAP_TYPE_SAP_S: 1457 case ASAP_TYPE_SAP_S:
@@ -1453,23 +1459,23 @@ FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration
1453 ast _ cpu_x = 0x00; 1459 ast _ cpu_x = 0x00;
1454 ast _ cpu_y = 0x00; 1460 ast _ cpu_y = 0x00;
1455 ast _ cpu_s = 0xff; 1461 ast _ cpu_s = 0xff;
1456 ast _ cpu_pc = ast _ module_info.init; 1462 ast _ cpu_pc = ast _ module_info->init;
1457 break; 1463 break;
1458#ifndef ASAP_ONLY_SAP 1464#ifndef ASAP_ONLY_SAP
1459 case ASAP_TYPE_DLT: 1465 case ASAP_TYPE_DLT:
1460 call_6502_init(ast, ast _ module_info.player + 0x100, 0x00, 0x00, ast _ module_info.song_pos[song]); 1466 call_6502_init(ast, ast _ module_info->player + 0x100, 0x00, 0x00, ast _ module_info->song_pos[song]);
1461 break; 1467 break;
1462 case ASAP_TYPE_MPT: 1468 case ASAP_TYPE_MPT:
1463 call_6502_init(ast, ast _ module_info.player, 0x00, ast _ module_info.music >> 8, ast _ module_info.music); 1469 call_6502_init(ast, ast _ module_info->player, 0x00, ast _ module_info->music >> 8, ast _ module_info->music);
1464 call_6502_init(ast, ast _ module_info.player, 0x02, ast _ module_info.song_pos[song], 0); 1470 call_6502_init(ast, ast _ module_info->player, 0x02, ast _ module_info->song_pos[song], 0);
1465 break; 1471 break;
1466 case ASAP_TYPE_RMT: 1472 case ASAP_TYPE_RMT:
1467 call_6502_init(ast, ast _ module_info.player, ast _ module_info.song_pos[song], ast _ module_info.music, ast _ module_info.music >> 8); 1473 call_6502_init(ast, ast _ module_info->player, ast _ module_info->song_pos[song], ast _ module_info->music, ast _ module_info->music >> 8);
1468 break; 1474 break;
1469 case ASAP_TYPE_TMC: 1475 case ASAP_TYPE_TMC:
1470 case ASAP_TYPE_TM2: 1476 case ASAP_TYPE_TM2:
1471 call_6502_init(ast, ast _ module_info.player, 0x70, ast _ module_info.music >> 8, ast _ module_info.music); 1477 call_6502_init(ast, ast _ module_info->player, 0x70, ast _ module_info->music >> 8, ast _ module_info->music);
1472 call_6502_init(ast, ast _ module_info.player, 0x00, song, 0); 1478 call_6502_init(ast, ast _ module_info->player, 0x00, song, 0);
1473 ast _ tmc_per_frame_counter = 1; 1479 ast _ tmc_per_frame_counter = 1;
1474 break; 1480 break;
1475#endif 1481#endif
@@ -1485,11 +1491,11 @@ FUNC(void, ASAP_MutePokeyChannels, (P(ASAP_State PTR, ast), P(int, mask)))
1485 1491
1486FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast))) 1492FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
1487{ 1493{
1488 V(int, player) = ast _ module_info.player; 1494 V(int, player) = ast _ module_info->player;
1489 PokeySound_StartFrame(ast); 1495 PokeySound_StartFrame(ast);
1490 switch (ast _ module_info.type) { 1496 switch (ast _ module_info->type) {
1491 case ASAP_TYPE_SAP_B: 1497 case ASAP_TYPE_SAP_B:
1492 call_6502(ast, player, ast _ module_info.fastplay); 1498 call_6502(ast, player, ast _ module_info->fastplay);
1493 break; 1499 break;
1494 case ASAP_TYPE_SAP_C: 1500 case ASAP_TYPE_SAP_C:
1495#ifndef ASAP_ONLY_SAP 1501#ifndef ASAP_ONLY_SAP
@@ -1498,7 +1504,7 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
1498 case ASAP_TYPE_CMR: 1504 case ASAP_TYPE_CMR:
1499 case ASAP_TYPE_CMS: 1505 case ASAP_TYPE_CMS:
1500#endif 1506#endif
1501 call_6502(ast, player + 6, ast _ module_info.fastplay); 1507 call_6502(ast, player + 6, ast _ module_info->fastplay);
1502 break; 1508 break;
1503 case ASAP_TYPE_SAP_D: 1509 case ASAP_TYPE_SAP_D:
1504 if (player >= 0) { 1510 if (player >= 0) {
@@ -1525,10 +1531,10 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
1525 dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */ 1531 dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */
1526 ast _ cpu_pc = player; 1532 ast _ cpu_pc = player;
1527 } 1533 }
1528 Cpu_RunScanlines(ast, ast _ module_info.fastplay); 1534 Cpu_RunScanlines(ast, ast _ module_info->fastplay);
1529 break; 1535 break;
1530 case ASAP_TYPE_SAP_S: 1536 case ASAP_TYPE_SAP_S:
1531 Cpu_RunScanlines(ast, ast _ module_info.fastplay); 1537 Cpu_RunScanlines(ast, ast _ module_info->fastplay);
1532 { 1538 {
1533 V(int, i) = dGetByte(0x45) - 1; 1539 V(int, i) = dGetByte(0x45) - 1;
1534 dPutByte(0x45, i); 1540 dPutByte(0x45, i);
@@ -1538,28 +1544,28 @@ FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
1538 break; 1544 break;
1539#ifndef ASAP_ONLY_SAP 1545#ifndef ASAP_ONLY_SAP
1540 case ASAP_TYPE_DLT: 1546 case ASAP_TYPE_DLT:
1541 call_6502(ast, player + 0x103, ast _ module_info.fastplay); 1547 call_6502(ast, player + 0x103, ast _ module_info->fastplay);
1542 break; 1548 break;
1543 case ASAP_TYPE_MPT: 1549 case ASAP_TYPE_MPT:
1544 case ASAP_TYPE_RMT: 1550 case ASAP_TYPE_RMT:
1545 case ASAP_TYPE_TM2: 1551 case ASAP_TYPE_TM2:
1546 call_6502(ast, player + 3, ast _ module_info.fastplay); 1552 call_6502(ast, player + 3, ast _ module_info->fastplay);
1547 break; 1553 break;
1548 case ASAP_TYPE_TMC: 1554 case ASAP_TYPE_TMC:
1549 if (--ast _ tmc_per_frame_counter <= 0) { 1555 if (--ast _ tmc_per_frame_counter <= 0) {
1550 ast _ tmc_per_frame_counter = ast _ tmc_per_frame; 1556 ast _ tmc_per_frame_counter = ast _ tmc_per_frame;
1551 call_6502(ast, player + 3, ast _ module_info.fastplay); 1557 call_6502(ast, player + 3, ast _ module_info->fastplay);
1552 } 1558 }
1553 else 1559 else
1554 call_6502(ast, player + 6, ast _ module_info.fastplay); 1560 call_6502(ast, player + 6, ast _ module_info->fastplay);
1555 break; 1561 break;
1556#endif 1562#endif
1557 } 1563 }
1558 PokeySound_EndFrame(ast, ast _ module_info.fastplay * 114); 1564 PokeySound_EndFrame(ast, ast _ module_info->fastplay * 114);
1559 if (ast _ silence_cycles > 0) { 1565 if (ast _ silence_cycles > 0) {
1560 if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey) 1566 if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey)
1561 && PokeySound_IsSilent(ADDRESSOF ast _ extra_pokey)) { 1567 && PokeySound_IsSilent(ADDRESSOF ast _ extra_pokey)) {
1562 ast _ silence_cycles_counter -= ast _ module_info.fastplay * 114; 1568 ast _ silence_cycles_counter -= ast _ module_info->fastplay * 114;
1563 if (ast _ silence_cycles_counter <= 0) 1569 if (ast _ silence_cycles_counter <= 0)
1564 return FALSE; 1570 return FALSE;
1565 } 1571 }
@@ -1606,7 +1612,7 @@ FUNC(void, ASAP_GetWavHeader, (
1606 P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format))) 1612 P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format)))
1607{ 1613{
1608 V(int, use_16bit) = format != ASAP_FORMAT_U8 ? 1 : 0; 1614 V(int, use_16bit) = format != ASAP_FORMAT_U8 ? 1 : 0;
1609 V(int, block_size) = ast _ module_info.channels << use_16bit; 1615 V(int, block_size) = ast _ module_info->channels << use_16bit;
1610 V(int, bytes_per_second) = ASAP_SAMPLE_RATE * block_size; 1616 V(int, bytes_per_second) = ASAP_SAMPLE_RATE * block_size;
1611 V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration); 1617 V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration);
1612 V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size; 1618 V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size;
@@ -1629,7 +1635,7 @@ FUNC(void, ASAP_GetWavHeader, (
1629 buffer[19] = 0; 1635 buffer[19] = 0;
1630 buffer[20] = 1; 1636 buffer[20] = 1;
1631 buffer[21] = 0; 1637 buffer[21] = 0;
1632 buffer[22] = CAST(byte) ast _ module_info.channels; 1638 buffer[22] = CAST(byte) ast _ module_info->channels;
1633 buffer[23] = 0; 1639 buffer[23] = 0;
1634 serialize_int(buffer, 24, ASAP_SAMPLE_RATE); 1640 serialize_int(buffer, 24, ASAP_SAMPLE_RATE);
1635 serialize_int(buffer, 28, bytes_per_second); 1641 serialize_int(buffer, 28, bytes_per_second);
@@ -1656,7 +1662,7 @@ PRIVATE FUNC(int, ASAP_GenerateAt, (P(ASAP_State PTR, ast), P(VOIDPTR, buffer),
1656#ifdef ACTIONSCRIPT 1662#ifdef ACTIONSCRIPT
1657 block_shift = 0; 1663 block_shift = 0;
1658#else 1664#else
1659 block_shift = (ast _ module_info.channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0); 1665 block_shift = (ast _ module_info->channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0);
1660#endif 1666#endif
1661 buffer_blocks = buffer_len >> block_shift; 1667 buffer_blocks = buffer_len >> block_shift;
1662 if (ast _ current_duration > 0) { 1668 if (ast _ current_duration > 0) {