diff --git a/src-md/Makefile b/src-md/Makefile index a7bcc8d35..e34c78c84 100644 --- a/src-md/Makefile +++ b/src-md/Makefile @@ -10,7 +10,7 @@ LIBPATH = -L$(ROOTDIR)/m68k-elf/lib -L$(ROOTDIR)/m68k-elf/lib/gcc/m68k-elf/12.1. INCPATH = -I$. -I$(ROOTDIR)/m68k-elf/include -I$(ROOTDIR)/m68k-elf/m68k-elf/include -I../liblzss HWCCFLAGS = -m68000 -Wall -O1 -c -fomit-frame-pointer -fno-lto -CCFLAGS = -m68000 -Wall -Os -c -fomit-frame-pointer -flto +CCFLAGS = -m68000 -Wall -Os -c -fomit-frame-pointer -fno-lto -DUSE_SCD_IN_RAM ASFLAGS = -m68000 --register-prefix-optional LINKFLAGS = -T $(LDSCRIPTSDIR)/mars-md.ld -Wl,-Map=output.map -nostdlib -flto diff --git a/src-md/crt0.s b/src-md/crt0.s index 60576e3f4..24a7349f2 100644 --- a/src-md/crt0.s +++ b/src-md/crt0.s @@ -276,6 +276,10 @@ init_hardware: rts + .data + +| Put remaining code in data section to lower bus contention for the rom. + | void write_byte(void *dst, unsigned char val) .global write_byte write_byte: @@ -321,11 +325,6 @@ read_long: move.l (a0),d0 rts - - .data - -| Put remaining code in data section to lower bus contention for the rom. - .global do_main do_main: move.b #1,0xA15107 /* set RV */ diff --git a/src-md/scd_pcm.c b/src-md/scd_pcm.c index db08b172e..a3b32687b 100644 --- a/src-md/scd_pcm.c +++ b/src-md/scd_pcm.c @@ -22,19 +22,27 @@ extern unsigned int read_long(unsigned int src); static scd_cmd_t scd_cmds[MAX_SCD_CMDS]; static int16_t num_scd_cmds; +static void scd_delay(void) SCD_CODE_ATTR; +static char wait_cmd_ack(void) SCD_CODE_ATTR; +static void wait_do_cmd(char cmd) SCD_CODE_ATTR; + static char wait_cmd_ack(void) { char ack = 0; - while (!ack) + do { + scd_delay(); ack = read_byte(0xA1200F); // wait for acknowledge byte in sub comm port + } while (!ack); return ack; } static void wait_do_cmd(char cmd) { - while (read_byte(0xA1200F)) ; // wait until Sub-CPU is ready to receive command + while (read_byte(0xA1200F)) { + scd_delay(); // wait until Sub-CPU is ready to receive command + } write_byte(0xA1200E, cmd); // set main comm port to command } @@ -222,3 +230,11 @@ int scd_flush_cmd_queue(void) num_scd_cmds = 0; return i; } + +static void scd_delay(void) +{ + int cnt = 5; + do { + asm __volatile("nop"); + } while (--cnt); +} diff --git a/src-md/scd_pcm.h b/src-md/scd_pcm.h index b9ecbfc76..770752727 100644 --- a/src-md/scd_pcm.h +++ b/src-md/scd_pcm.h @@ -1,5 +1,11 @@ #include +#ifdef USE_SCD_IN_RAM +#define SCD_CODE_ATTR __attribute__((section(".data"), aligned(16))) +#else +#define SCD_CODE_ATTR +#endif + // scd_init_pcm initializes the PCM driver void scd_init_pcm(void); @@ -16,7 +22,7 @@ void scd_init_pcm(void); // otherwise a new memory block will be allocated from the available memory pool // once the driver runs out of memory, no further allocations will be possible and // the driver will have to be re-initialized by calling scd_init_pcm -void scd_upload_buf(uint16_t buf_id, const uint8_t *data, uint32_t data_len); +void scd_upload_buf(uint16_t buf_id, const uint8_t *data, uint32_t data_len) SCD_CODE_ATTR; // scd_upload_buf starts playback on source from the start of the buffer // source is a virtual playback channel, one or two hardware channels can be mapped @@ -33,12 +39,12 @@ void scd_upload_buf(uint16_t buf_id, const uint8_t *data, uint32_t data_len); // returned value: if the passed src_id is 255, then thew newly allocated source id, // if the allocation has failed, a value of 0 is returned // otherwise the originally passed value of src_id is returned -uint8_t scd_play_src(uint8_t src_id, uint16_t buf_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop); +uint8_t scd_play_src(uint8_t src_id, uint16_t buf_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop) SCD_CODE_ATTR; // scd_punpause_src pauses or unpauses the source // // value range for src_id: [1, 8] -uint8_t scd_punpause_src(uint8_t src_id, uint8_t paused); +uint8_t scd_punpause_src(uint8_t src_id, uint8_t paused) SCD_CODE_ATTR; // scd_update_src updates the frequency, panning, volume and autoloop property for the source // @@ -48,44 +54,44 @@ uint8_t scd_punpause_src(uint8_t src_id, uint8_t paused); // values for vol: [0, 255] // values for autoloop: [0, 255], a boolean: the source will automatically loopf from the start after // reaching the end of the playback buffer -void scd_update_src(uint8_t src_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop); +void scd_update_src(uint8_t src_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop) SCD_CODE_ATTR; // scd_stop_src stops playback on the given source // // value range for src_id: [1, 8] -void scd_stop_src(uint8_t src_id); +void scd_stop_src(uint8_t src_id) SCD_CODE_ATTR; // scd_rewind_src sets position for the given source to the start of the playback buffer // // value range for src_id: [1, 8] -void scd_rewind_src(uint8_t src_id); +void scd_rewind_src(uint8_t src_id) SCD_CODE_ATTR; // scd_getpos_for_src returns playback position for the given source // // value range for src_id: [1, 8] // // returned value: current read position in PCM memory of the ricoh chip for the first channel of the source -uint16_t scd_getpos_for_src(uint8_t src_id); +uint16_t scd_getpos_for_src(uint8_t src_id) SCD_CODE_ATTR; // scd_clear_pcm stops playback on all channels -void scd_clear_pcm(void); +void scd_clear_pcm(void) SCD_CODE_ATTR; // returns playback status mask for all sources // if a source is active, it will have its bit set to 1 in the mask: // bit 0 for source id 1, bit 1 for source id 2, etc -int scd_get_playback_status(void); +int scd_get_playback_status(void) SCD_CODE_ATTR; // queues a scd_play_src call, always returns 0 -uint8_t scd_queue_play_src(uint8_t src_id, uint16_t buf_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop); +uint8_t scd_queue_play_src(uint8_t src_id, uint16_t buf_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop) SCD_CODE_ATTR; // queues a scd_update_src call -void scd_queue_update_src(uint8_t src_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop); +void scd_queue_update_src(uint8_t src_id, uint16_t freq, uint8_t pan, uint8_t vol, uint8_t autoloop) SCD_CODE_ATTR; // queues a scd_stop_src call -void scd_queue_stop_src(uint8_t src_id); +void scd_queue_stop_src(uint8_t src_id) SCD_CODE_ATTR; // queues a scd_clear_pcm call -void scd_queue_clear_pcm(void); +void scd_queue_clear_pcm(void) SCD_CODE_ATTR; // flushes the command queue -int scd_flush_cmd_queue(void); +int scd_flush_cmd_queue(void) SCD_CODE_ATTR;