example/aica/aica_xm: xm offsets
This commit is contained in:
parent
800e3fa254
commit
49203a0b0b
6
base.mk
6
base.mk
@ -123,6 +123,12 @@ endef
|
||||
%.glm.o: %.glm
|
||||
$(BUILD_BINARY_O)
|
||||
|
||||
%.xm.h: %.xm
|
||||
$(BUILD_BINARY_H)
|
||||
|
||||
%.xm.o: %.xm
|
||||
$(BUILD_BINARY_O)
|
||||
|
||||
%.o: %.s
|
||||
$(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@
|
||||
|
||||
|
@ -38,5 +38,13 @@ void main()
|
||||
serial::string("mrwinh: ");
|
||||
wait();
|
||||
serial::integer<uint8_t>(aica_sound.common.MRWINH());
|
||||
while (1);
|
||||
int last_dram = -1;
|
||||
while (1) {
|
||||
wait();
|
||||
int read = aica_wave_memory[0];
|
||||
if (read != last_dram) {
|
||||
serial::integer<uint32_t>(read);
|
||||
}
|
||||
last_dram = read;
|
||||
};
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||
DIR := $(dir $(MAKEFILE_PATH))
|
||||
|
||||
LIB ?= .
|
||||
OPT ?= -O3
|
||||
OPT ?= -O1
|
||||
GENERATED ?=
|
||||
|
||||
AARCH = -march=armv4 -mlittle-endian
|
||||
@ -26,7 +26,7 @@ sh4_interrupt.elf: LDSCRIPT = main.lds
|
||||
sh4_interrupt.elf: start.o sh4_interrupt.o
|
||||
|
||||
xm.elf: LDSCRIPT = main.lds
|
||||
xm.elf: start.o xm.o audio.pcm.o
|
||||
xm.elf: start.o xm.o ../../xm/milkypack01.xm.o
|
||||
|
||||
clean:
|
||||
find -P \
|
||||
|
@ -1,14 +1,97 @@
|
||||
#include "aica/aica.hpp"
|
||||
|
||||
extern void * _sine_start __asm("_binary_audio_pcm_start");
|
||||
#include "xm/xm.h"
|
||||
#include "xm/milkypack01.xm.h"
|
||||
|
||||
extern volatile uint32_t dram[0x200000] __asm("dram");
|
||||
|
||||
constexpr int max_patterns = 64;
|
||||
constexpr int max_instruments = 128;
|
||||
struct xm_state {
|
||||
xm_header_t * header;
|
||||
xm_pattern_header_t * pattern_header[max_patterns];
|
||||
xm_instrument_header_t * instrument_header[max_instruments];
|
||||
xm_sample_header_t * sample_header; // array
|
||||
};
|
||||
|
||||
static xm_state xm = {0};
|
||||
|
||||
int s16(void * buf)
|
||||
{
|
||||
uint8_t * b = (uint8_t *)buf;
|
||||
int16_t v = (b[0] << 0) | (b[1] << 8);
|
||||
return v;
|
||||
}
|
||||
|
||||
int s32(void * buf)
|
||||
{
|
||||
uint8_t * b = (uint8_t *)buf;
|
||||
int32_t v = (b[0] << 0) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
|
||||
return v;
|
||||
}
|
||||
|
||||
int xm_samples_init(int buf, int offset, int number_of_samples)
|
||||
{
|
||||
xm_sample_header_t * sample_header[number_of_samples];
|
||||
for (int i = 0; i < number_of_samples; i++) {
|
||||
sample_header[i] = (xm_sample_header_t *)(buf + offset);
|
||||
offset += (sizeof (xm_sample_header_t));
|
||||
}
|
||||
|
||||
for (int i = 0; i < number_of_samples; i++) {
|
||||
offset += s32(&sample_header[i]->sample_length);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
void print(int i)
|
||||
{
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
asm volatile ("nop");
|
||||
}
|
||||
dram[0] = i;
|
||||
}
|
||||
|
||||
void xm_init()
|
||||
{
|
||||
int buf = (int)(&_binary_xm_milkypack01_xm_start);
|
||||
|
||||
while (xm.header != (xm_header_t *)(buf))
|
||||
xm.header = (xm_header_t *)(buf);
|
||||
|
||||
int offset = s32(&xm.header->header_size) + (offsetof (struct xm_header, header_size));
|
||||
|
||||
int number_of_patterns = s16(&xm.header->number_of_patterns);
|
||||
print(0x12345678);
|
||||
print(number_of_patterns);
|
||||
|
||||
for (int i = 0; i < number_of_patterns; i++) {
|
||||
xm_pattern_header_t * pattern_header = (xm_pattern_header_t *)(buf + offset);
|
||||
|
||||
xm.pattern_header[i] = pattern_header;
|
||||
|
||||
offset += s32(&pattern_header->pattern_header_length) + s16(&pattern_header->packed_pattern_data_size);
|
||||
print(offset);
|
||||
}
|
||||
|
||||
int number_of_instruments = s16(&xm.header->number_of_instruments);
|
||||
for (int i = 0; i < number_of_instruments; i++) {
|
||||
xm_instrument_header_t * instrument_header = (xm_instrument_header_t *)(buf + offset);
|
||||
|
||||
xm.instrument_header[i] = instrument_header;
|
||||
offset += s32(&instrument_header->instrument_size);
|
||||
|
||||
int number_of_samples = s16(&instrument_header->number_of_samples);
|
||||
offset = xm_samples_init(buf, offset, number_of_samples);
|
||||
}
|
||||
|
||||
print(0x11223344);
|
||||
print(offset);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void main()
|
||||
{
|
||||
const uint32_t sine_addr = reinterpret_cast<uint32_t>(&_sine_start);
|
||||
|
||||
volatile uint32_t * slot = reinterpret_cast<volatile uint32_t*>(0x00800000);
|
||||
for (uint32_t i = 0; i < (sizeof (struct aica_channel)) * 64 / 4; i++) {
|
||||
slot[i] = 0;
|
||||
@ -47,16 +130,15 @@ void main()
|
||||
|
||||
uint32_t segment = 0;
|
||||
|
||||
dram[0] = 0x11223344;
|
||||
dram[1] = sine_addr;
|
||||
constexpr uint32_t timer_a_interrupt = (1 << 6);
|
||||
aica_sound.common.scire = timer_a_interrupt;
|
||||
uint32_t next_sa = sine_addr;
|
||||
bool started = 0;
|
||||
|
||||
xm_init();
|
||||
|
||||
while (1) {
|
||||
if (!started || (aica_sound.common.SCIPD() & timer_a_interrupt)) {
|
||||
aica_sound.channel[0].SA(next_sa);
|
||||
//aica_sound.channel[0].SA(next_sa);
|
||||
aica_sound.common.tactl_tima =
|
||||
aica::tactl_tima::TACTL(0) // increment once every 128 samples
|
||||
| aica::tactl_tima::TIMA(256 - 128) // interrupt after 128 counts
|
||||
@ -65,11 +147,6 @@ void main()
|
||||
if (!started) { aica_sound.channel[0].KYONEX(1); started = 1; }
|
||||
|
||||
aica_sound.common.scire = timer_a_interrupt;
|
||||
dram[1] = next_sa;
|
||||
|
||||
segment += 1;
|
||||
if (segment >= 3440) segment = 0;
|
||||
next_sa = sine_addr + (128 * 2) * segment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +161,8 @@ int debug_pattern_headers(void * buf)
|
||||
{
|
||||
xm_header_t * header = (xm_header_t *)buf;
|
||||
int pattern_header_offset = s32(&header->header_size) + (offsetof (struct xm_header, header_size));
|
||||
printf("pattern number of patterns: %08x\n", s16(&header->number_of_patterns));
|
||||
printf("pattern header offset: %08x\n", pattern_header_offset);
|
||||
|
||||
for (int i = 0; i < s16(&header->number_of_patterns); i++) {
|
||||
xm_pattern_header_t * pattern_header = (xm_pattern_header_t *)(((ptrdiff_t)buf) + pattern_header_offset);
|
||||
@ -172,6 +174,7 @@ int debug_pattern_headers(void * buf)
|
||||
printf(" packed_pattern_data_size: %d\n", s16(&pattern_header->packed_pattern_data_size));
|
||||
//debug_pattern(pattern_header);
|
||||
pattern_header_offset += s32(&pattern_header->pattern_header_length) + s16(&pattern_header->packed_pattern_data_size);
|
||||
printf("pattern header offset: %08x\n", pattern_header_offset);
|
||||
}
|
||||
return pattern_header_offset;
|
||||
}
|
||||
@ -303,6 +306,8 @@ int debug_instruments(void * buf, int offset)
|
||||
offset = debug_samples(buf, offset, i, s16(&instrument_header->number_of_samples));
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
@ -318,5 +323,6 @@ int main(int argc, const char *argv[])
|
||||
|
||||
debug_header(buf);
|
||||
int end_of_patterns = debug_pattern_headers(buf);
|
||||
debug_instruments(buf, end_of_patterns);
|
||||
int end_of_instruments = debug_instruments(buf, end_of_patterns);
|
||||
printf("end_of_instruments: %08x\n", end_of_instruments);
|
||||
}
|
||||
|
15
xm/milkypack01.xm.h
Normal file
15
xm/milkypack01.xm.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_xm_milkypack01_xm_start __asm("_binary_xm_milkypack01_xm_start");
|
||||
extern uint32_t _binary_xm_milkypack01_xm_end __asm("_binary_xm_milkypack01_xm_end");
|
||||
extern uint32_t _binary_xm_milkypack01_xm_size __asm("_binary_xm_milkypack01_xm_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user