m68k: library-ifiy
This makes the m68k make rules usable from other makefiles. This also adds scsp start address macros. The sound.c example-fragment is deleted, as a better version now exists in saturn-examples.
This commit is contained in:
parent
e591797e23
commit
922fc587bc
16
common.mk
16
common.mk
@ -3,11 +3,12 @@ OPT ?= -Og
|
|||||||
|
|
||||||
AARCH = --isa=sh2 --big
|
AARCH = --isa=sh2 --big
|
||||||
AFLAGS = -g -gdwarf-4
|
AFLAGS = -g -gdwarf-4
|
||||||
|
|
||||||
|
CARCH = -m2 -mb
|
||||||
CFLAGS += -falign-functions=4 -ffunction-sections -fdata-sections -fshort-enums -ffreestanding -nostdlib
|
CFLAGS += -falign-functions=4 -ffunction-sections -fdata-sections -fshort-enums -ffreestanding -nostdlib
|
||||||
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 $(OPT)
|
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 $(OPT)
|
||||||
LDFLAGS = --gc-sections --no-warn-rwx-segment --print-memory-usage --entry=_start
|
LDFLAGS = --gc-sections --no-warn-rwx-segment --print-memory-usage --entry=_start
|
||||||
CXXFLAGS = -fno-exceptions -fno-rtti
|
CXXFLAGS = -fno-exceptions -fno-rtti
|
||||||
CARCH = -m2 -mb
|
|
||||||
|
|
||||||
TARGET = sh2-none-elf-
|
TARGET = sh2-none-elf-
|
||||||
CC = $(TARGET)gcc
|
CC = $(TARGET)gcc
|
||||||
@ -17,6 +18,13 @@ LD = $(TARGET)ld
|
|||||||
OBJCOPY = $(TARGET)objcopy
|
OBJCOPY = $(TARGET)objcopy
|
||||||
OBJDUMP = $(TARGET)objdump
|
OBJDUMP = $(TARGET)objdump
|
||||||
|
|
||||||
|
define BUILD_BINARY_O
|
||||||
|
$(OBJCOPY) \
|
||||||
|
-I binary -O elf32-sh -B sh2 \
|
||||||
|
--rename-section .data=.data.$(basename $@) \
|
||||||
|
$< $@
|
||||||
|
endef
|
||||||
|
|
||||||
$(LIB)/sys_%.o: $(LIB)/segasmp/lib/sys_%.o
|
$(LIB)/sys_%.o: $(LIB)/segasmp/lib/sys_%.o
|
||||||
$(OBJCOPY) -I coff-sh -O elf32-sh -g \
|
$(OBJCOPY) -I coff-sh -O elf32-sh -g \
|
||||||
--rename-section .text=.text.$* \
|
--rename-section .text=.text.$* \
|
||||||
@ -41,6 +49,9 @@ SYS_IP_OBJ += $(LIB)/smpsys.o
|
|||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@
|
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@
|
||||||
|
|
||||||
|
%.elf:
|
||||||
|
$(LD) $(LDFLAGS) -T $(LIB)/sh2.lds $^ -o $@
|
||||||
|
|
||||||
%.bin: %.elf
|
%.bin: %.elf
|
||||||
$(OBJCOPY) -O binary $< $@
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
@ -50,9 +61,6 @@ SYS_IP_OBJ += $(LIB)/smpsys.o
|
|||||||
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
|
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
|
||||||
$< $@
|
$< $@
|
||||||
|
|
||||||
%.elf:
|
|
||||||
$(LD) $(LDFLAGS) -T $(LIB)/sh2.lds $^ -o $@
|
|
||||||
|
|
||||||
sys_ip.elf: $(SYS_IP_OBJ)
|
sys_ip.elf: $(SYS_IP_OBJ)
|
||||||
$(LD) --print-memory-usage -T $(LIB)/sys_ip.lds $^ -o $@
|
$(LD) --print-memory-usage -T $(LIB)/sys_ip.lds $^ -o $@
|
||||||
|
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
//
|
|
||||||
// scsp
|
|
||||||
//
|
|
||||||
|
|
||||||
// The SCSP will initialize the internal registers, etc. for about 30µ sec
|
|
||||||
// after the reset has been released. For this reason, access is not allowed
|
|
||||||
// during the 30µ sec.
|
|
||||||
|
|
||||||
// Before downloading anything, make sure to set MEM4MB bit to 1 and DAC18B
|
|
||||||
// bit to 0 within the sound CPU (address) 10400H address.
|
|
||||||
|
|
||||||
smpc.reg.COMREG = COMREG__SNDON;
|
|
||||||
while (smpc.reg.OREG31 != 0b00000110) {}
|
|
||||||
for (long i = 0; i < 807; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs
|
|
||||||
|
|
||||||
scsp.reg.common[0] = SCSP__0__MEM4MB | SCSP__0__DAC18B;
|
|
||||||
|
|
||||||
u16 * m68k_main_start = (u16 *)&_binary_m68k_main_bin_start;
|
|
||||||
u32 m68k_main_size = (u32)&_binary_m68k_main_bin_size;
|
|
||||||
copy_16(m68k_main_start, &scsp.ram.u16[0], m68k_main_size);
|
|
||||||
|
|
||||||
smpc.reg.COMREG = COMREG__SNDOFF;
|
|
||||||
while (smpc.reg.OREG31 != 0b00000111) {}
|
|
||||||
for (long i = 0; i < 807; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs
|
|
||||||
|
|
||||||
smpc.reg.COMREG = COMREG__SNDON;
|
|
||||||
while (smpc.reg.OREG31 != 0b00000110) {}
|
|
||||||
for (long i = 0; i < 807; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs
|
|
||||||
|
|
||||||
scsp.reg.common[0] = SCSP__0__MEM4MB | SCSP__0__DAC18B;
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
static signed int left_phase;
|
|
||||||
|
|
||||||
static void fill_data(int16_t * output, int len)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
*output++ = (signed short)left_phase;
|
|
||||||
left_phase += 327 / 2;
|
|
||||||
if (left_phase >= 32767) left_phase = -32768;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "scsp.h"
|
|
||||||
|
|
||||||
void main_sound(void)
|
|
||||||
{
|
|
||||||
while ((smpc.reg.SF & 0x01) == 1);
|
|
||||||
|
|
||||||
smpc.reg.SF = 1;
|
|
||||||
|
|
||||||
smpc.reg.COMREG = COMREG__SNDON;
|
|
||||||
while ((smpc.reg.SF & 0x01) == 1);
|
|
||||||
while (smpc.reg.OREG31 != 0b00000110) {}
|
|
||||||
|
|
||||||
for (long i = 0; i < 807; i++) { asm volatile ("nop"); } // wait for (way) more than 30µs
|
|
||||||
|
|
||||||
scsp.reg.common[0] = SCSP__0__MEM4MB | SCSP__0__DAC18B | 15;
|
|
||||||
|
|
||||||
left_phase = 0;
|
|
||||||
fill_data((int16_t*)&scsp.ram.u16[0], 44100);
|
|
||||||
|
|
||||||
scsp_slot& slot = scsp.reg.slot[0];
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
left_phase = 0;
|
|
||||||
fill_data((int16_t*)&scsp.ram.u16[0], 44100);
|
|
||||||
|
|
||||||
slot.field[0] = (1 << 11) | (1 << 5); // kx
|
|
||||||
slot.field[1] = 0; // start_addr
|
|
||||||
slot.field[2] = 0; // loop start address
|
|
||||||
slot.field[3] = 44100; // loop end address
|
|
||||||
slot.field[4] = 31; // d2r d1r ar
|
|
||||||
//slot.field[5] = (1 << 14) | (0xf << 10) | 0; // krs dl rr (key_decay_release)
|
|
||||||
slot.field[5] = 31; // krs dl rr (key_decay_release)
|
|
||||||
slot.field[6] = 1 << 3; // tl (attenuation)
|
|
||||||
slot.field[7] = 0; // mdl mdxsl mdysl (fm_data)
|
|
||||||
slot.field[8] = 0; // oct fns (ofc_fns)
|
|
||||||
slot.field[9] = 0; // lfof plfows (lfo_data)
|
|
||||||
slot.field[10] = 0; // isel imxl (input_sel)
|
|
||||||
slot.field[11] = (7 << 13); // disdl dipan efpan (pan_send)
|
|
||||||
|
|
||||||
slot.field[0] |= (1 << 12);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < 800000; i++) { asm volatile ("nop"); }
|
|
||||||
|
|
||||||
slot.field[0] |= (1 << 12);
|
|
||||||
slot.field[0] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
ARCH = -march=68000 -mcpu=68ec000
|
|
||||||
AARCH = $(ARCH)
|
|
||||||
AFLAGS = -g -gdwarf-4
|
|
||||||
|
|
||||||
CFLAGS += -ffunction-sections -fshort-enums -ffreestanding -nostdlib
|
|
||||||
CFLAGS += -Wall -Werror -Wfatal-errors -g -gdwarf-4 -Og
|
|
||||||
CARCH = $(ARCH)
|
|
||||||
|
|
||||||
TARGET = m68k-none-elf-
|
|
||||||
CC = $(TARGET)gcc
|
|
||||||
AS = $(TARGET)as
|
|
||||||
LD = $(TARGET)ld
|
|
||||||
OBJCOPY = $(TARGET)objcopy
|
|
||||||
OBJDUMP = $(TARGET)objdump
|
|
||||||
|
|
||||||
all: main.bin
|
|
||||||
|
|
||||||
%.o: %.s
|
|
||||||
$(AS) $(AARCH) $(AFLAGS) $< -o $@
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
%.elf:
|
|
||||||
$(LD) --print-memory-usage -T m68k.lds $^ -o $@
|
|
||||||
|
|
||||||
%.bin: %.elf
|
|
||||||
$(OBJCOPY) -O binary $< $@
|
|
||||||
|
|
||||||
MAIN_OBJ = vectors.o main.o
|
|
||||||
|
|
||||||
main.elf: $(MAIN_OBJ)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.iso *.o *.bin *.elf
|
|
||||||
|
|
||||||
.SUFFIXES:
|
|
||||||
.INTERMEDIATE:
|
|
||||||
.SECONDARY:
|
|
||||||
.PHONY: all clean
|
|
58
m68k/common.mk
Normal file
58
m68k/common.mk
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
LIB ?= .
|
||||||
|
OPT ?= -Og
|
||||||
|
|
||||||
|
ARCH = -march=68000 -mcpu=68000
|
||||||
|
|
||||||
|
AARCH = $(ARCH)
|
||||||
|
AFLAGS = -g -gdwarf-4
|
||||||
|
|
||||||
|
CARCH = $(ARCH) -mtune=68000
|
||||||
|
CFLAGS += -falign-functions=4 -ffunction-sections -fdata-sections -fshort-enums -ffreestanding -nostdlib
|
||||||
|
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 $(OPT)
|
||||||
|
LDFLAGS = --gc-sections --no-warn-rwx-segment --print-memory-usage --entry=start
|
||||||
|
CXXFLAGS = -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
|
TARGET = m68k-none-elf-
|
||||||
|
CC = $(TARGET)gcc
|
||||||
|
CXX = $(TARGET)g++
|
||||||
|
AS = $(TARGET)as
|
||||||
|
LD = $(TARGET)ld
|
||||||
|
OBJCOPY = $(TARGET)objcopy
|
||||||
|
OBJDUMP = $(TARGET)objdump
|
||||||
|
|
||||||
|
define BUILD_BINARY_O
|
||||||
|
$(OBJCOPY) \
|
||||||
|
-I binary -O elf32-m68k -B m68k \
|
||||||
|
--rename-section .data=.data.$(basename $@) \
|
||||||
|
$< $@
|
||||||
|
endef
|
||||||
|
|
||||||
|
all: main.bin
|
||||||
|
|
||||||
|
%.o: %.s
|
||||||
|
$(AS) $(AARCH) $(AFLAGS) $< -o $@
|
||||||
|
|
||||||
|
%.o: %.S
|
||||||
|
$(CC) $(CFLAGS) $(CARCH) -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) $(CARCH) -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@
|
||||||
|
|
||||||
|
%.elf:
|
||||||
|
$(LD) $(LDFLAGS) -T $(LIB)/m68k/m68k.lds $^ -o $@
|
||||||
|
|
||||||
|
%.bin: %.elf
|
||||||
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
|
#OBJ = vectors.o main.o
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.iso *.o *.bin *.elf *.cue
|
||||||
|
|
||||||
|
.SUFFIXES:
|
||||||
|
.INTERMEDIATE:
|
||||||
|
.SECONDARY:
|
||||||
|
.PHONY: all clean
|
@ -10,12 +10,15 @@ SECTIONS
|
|||||||
{
|
{
|
||||||
. = 0x000000;
|
. = 0x000000;
|
||||||
KEEP(*(.vectors))
|
KEEP(*(.vectors))
|
||||||
|
KEEP(*(.text.start))
|
||||||
*(.text)
|
*(.text)
|
||||||
|
*(.text.*)
|
||||||
} > sound_ram
|
} > sound_ram
|
||||||
|
|
||||||
.data ALIGN(4) : SUBALIGN(4)
|
.data ALIGN(4) : SUBALIGN(4)
|
||||||
{
|
{
|
||||||
*(.data)
|
*(.data)
|
||||||
|
*(.data.*)
|
||||||
} > sound_ram
|
} > sound_ram
|
||||||
|
|
||||||
.rodata ALIGN(4) : SUBALIGN(4)
|
.rodata ALIGN(4) : SUBALIGN(4)
|
||||||
|
12
m68k/main.c
12
m68k/main.c
@ -1,12 +0,0 @@
|
|||||||
#include "../scsp.h"
|
|
||||||
|
|
||||||
#define MVOL(n) (n << 0)
|
|
||||||
|
|
||||||
void start(void)
|
|
||||||
{
|
|
||||||
scsp.reg.common[0] = SCSP__0__MEM4MB | SCSP__0__DAC18B | MVOL(15);
|
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
}
|
|
||||||
}
|
|
8
scsp.h
8
scsp.h
@ -134,7 +134,7 @@ static_assert((offsetof (struct scsp, reg)) == 0x100000);
|
|||||||
|
|
||||||
// bits
|
// bits
|
||||||
|
|
||||||
enum slot_bits {
|
enum loop_bits {
|
||||||
LOOP__KYONEX = ( 1 << 12), // (KX) execute KEY_ON
|
LOOP__KYONEX = ( 1 << 12), // (KX) execute KEY_ON
|
||||||
LOOP__KYONB = ( 1 << 11), // (KB) record KEY_ON, KEY_OFF
|
LOOP__KYONB = ( 1 << 11), // (KB) record KEY_ON, KEY_OFF
|
||||||
LOOP__SBCTL = ( 0b00 << 9), // source bit control
|
LOOP__SBCTL = ( 0b00 << 9), // source bit control
|
||||||
@ -144,7 +144,11 @@ enum slot_bits {
|
|||||||
LOOP__LPCTL__REVERSE = ( 0b10 << 5 ), // loop control
|
LOOP__LPCTL__REVERSE = ( 0b10 << 5 ), // loop control
|
||||||
LOOP__LPCTL__ALTERNATIVE = ( 0b11 << 5 ), // loop control
|
LOOP__LPCTL__ALTERNATIVE = ( 0b11 << 5 ), // loop control
|
||||||
LOOP__PCM8B = ( 1 << 4 ), // (8B) 8bit signed PCM
|
LOOP__PCM8B = ( 1 << 4 ), // (8B) 8bit signed PCM
|
||||||
LOOP__SA = (0b0000 << 0 ), // start address
|
#define LOOP__SA(n) ((((n) >> 16) & 0b1111) << 0) // start address
|
||||||
|
};
|
||||||
|
|
||||||
|
enum sa_bits {
|
||||||
|
#define SA__SA(n) ((n) & 0xffff)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eg_bits {
|
enum eg_bits {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user