From eecc39834949e6affbf3268cb5405a296cd12216 Mon Sep 17 00:00:00 2001 From: Javier Degirolmo Date: Mon, 22 Apr 2013 05:30:00 -0300 Subject: Now you can change the sample rate of PCM instruments --- c/echo.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'c/echo.c') diff --git a/c/echo.c b/c/echo.c index dcc844c..b4368da 100644 --- a/c/echo.c +++ b/c/echo.c @@ -97,14 +97,14 @@ void echo_send_command(uint8_t cmd) { } //*************************************************************************** -// echo_send_command_ex +// echo_send_command_addr // Sends a raw command to Echo. An address parameter is taken. //--------------------------------------------------------------------------- // param cmd: command to send // param addr: address parameter //*************************************************************************** -void echo_send_command_ex(uint8_t cmd, const void *addr) { +void echo_send_command_addr(uint8_t cmd, const void *addr) { // Since we need to split the address into multiple bytes we put it in an // integer. This is a bad practice in general, period, but since we don't // care about portability here we can afford to do it this time. @@ -134,6 +134,34 @@ void echo_send_command_ex(uint8_t cmd, const void *addr) { Z80_RELEASE(); } +//*************************************************************************** +// echo_send_command_byte +// Sends a raw command to Echo. A byte parameter is taken. +//--------------------------------------------------------------------------- +// param cmd: command to send +// param byte: parameter +//*************************************************************************** + +void echo_send_command_byte(uint8_t cmd, uint8_t byte) { + // We need access to Z80 bus + Z80_REQUEST(); + + // Is Echo busy yet? + while (z80_ram[0x1FFF] != 0x00) { + Z80_RELEASE(); + int16_t i; + for (i = 0x3FF; i >= 0; i--); + Z80_REQUEST(); + } + + // Write the command + z80_ram[0x1FFF] = cmd; + z80_ram[0x1FFC] = byte; + + // Done with the Z80 + Z80_RELEASE(); +} + //*************************************************************************** // echo_play_bgm // Starts playing background music. @@ -142,7 +170,7 @@ void echo_send_command_ex(uint8_t cmd, const void *addr) { //*************************************************************************** void echo_play_bgm(const void *ptr) { - echo_send_command_ex(ECHO_CMD_PLAYBGM, ptr); + echo_send_command_addr(ECHO_CMD_PLAYBGM, ptr); } //*************************************************************************** @@ -171,7 +199,7 @@ void echo_resume_bgm(void) { //*************************************************************************** void echo_play_sfx(const void *ptr) { - echo_send_command_ex(ECHO_CMD_PLAYSFX, ptr); + echo_send_command_addr(ECHO_CMD_PLAYSFX, ptr); } //*************************************************************************** @@ -183,6 +211,17 @@ void echo_stop_sfx(void) { echo_send_command(ECHO_CMD_STOPSFX); } +//*************************************************************************** +// echo_set_pcm_rate +// Changes the playback rate of PCM. +//--------------------------------------------------------------------------- +// param rate: new rate (timer A value) +//*************************************************************************** + +void echo_set_pcm_rate(uint8_t rate) { + echo_send_command_byte(ECHO_CMD_SETPCMRATE, rate); +} + //*************************************************************************** // echo_get_status // Retrieves Echo's current status. -- cgit v1.2.3