Skip to content

Commit

Permalink
Fix VGM loop points
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Sep 30, 2024
1 parent 3c00063 commit 59eda01
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src-md/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -2597,19 +2597,25 @@ bump_fm:
13:
/* EOF reached */
move.l fm_loop,d0
add.w d3,d0
andi.w #0x0FFF,d0 /* 4KB buffer */
andi.l #0x01FF,d0 /* 1 read buffer */
add.l d3,d0
andi.l #0x0FFF,d0 /* 4KB buffer */
move.l d0,fm_loop2 /* offset to z80 loop start */

/* reset */
jsr vgm_reset /* restart at start of compressed data */
move.w #0,offs68k
move.w d3,offsz80
move.w #7,preread_cnt /* refill buffer if room */
bra.w 7f
move.l fm_loop,d2
andi.l #0xFE00,d2
beq.b 14f
move.l d2,-(sp)
jsr vgm_read2
addq.l #4,sp
move.l d0,d2
andi.l #0x7FFF,d2 /* amount data pre-read (with wrap around) */
14:
move.w d2,offs68k
move.w d3,offsz80
move.w #7,preread_cnt /* refill buffer if room */
bra.w 7f

5:
Expand All @@ -2625,8 +2631,12 @@ bump_fm:

/* music ended, check for loop */
tst.w fm_rep
beq.w 7f /* no repeat, leave FM_IDX as 0 */
bne.b 50f /* repeat, loop vgm */
/* no repeat, reset FM */
jsr rst_ym2612
bra.w 7f

50:
move.l fm_loop2,d0
z80wr FM_START,d0
lsr.w #8,d0
Expand Down
5 changes: 3 additions & 2 deletions src-md/scd_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#define CHUNK_BLOCKS (1<<CHUNK_SHIFT)
#define CHUNK_SIZE (CHUNK_BLOCKS*BLOCK_SIZE)

#define MCD_DISC_BUFFER (void*)(MCD_WORDRAM + 0x20000 - CHUNK_SIZE)
#define MD_DISC_BUFFER (void*)(MD_WORDRAM + 0x20000 - CHUNK_SIZE)
#define DISC_BUFFER_WORDRAM_OFS (0x20000 - CHUNK_SIZE)
#define MCD_DISC_BUFFER (void*)(MCD_WORDRAM + DISC_BUFFER_WORDRAM_OFS)
#define MD_DISC_BUFFER (void*)(MD_WORDRAM + DISC_BUFFER_WORDRAM_OFS)

extern int64_t scd_open_file(const char *name);
extern void scd_read_sectors(void *ptr, int lba, int len, void (*wait)(void));
Expand Down
8 changes: 7 additions & 1 deletion src-md/vgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define VGM_WORDRAM_OFS 0x3000
#define VGM_READAHEAD 0x200
#define VGM_LZSS_BUF_SIZE 0x8000
#define VGM_MAX_SIZE 0x18000
#define VGM_MAX_SIZE 0x18800

#define VGM_USE_PWM_FOR_DAC

Expand Down Expand Up @@ -48,6 +48,7 @@ void lzss_reset(lzss_state_t* lzss) __attribute__((section(".data"), aligned(16)

int vgm_setup(void* fm_ptr) __attribute__((section(".data"), aligned(16)));
int vgm_read(void) __attribute__((section(".data"), aligned(16)));
int vgm_read2(int length) __attribute__((section(".data"), aligned(16)));

extern int64_t scd_open_file(const char *name);
extern void scd_read_sectors(void *ptr, int lba, int len, void (*wait)(void));
Expand Down Expand Up @@ -161,6 +162,11 @@ int vgm_read(void)
return lzss_read(&vgm_lzss, VGM_READAHEAD);
}

int vgm_read2(int length)
{
return lzss_read(&vgm_lzss, length);
}

void *vgm_cache_scd(const char *name, int offset, int length)
{
int64_t lo;
Expand Down

0 comments on commit 59eda01

Please sign in to comment.