From 922fc587bcd47533f9d9abdbf4873675962504c0 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Tue, 16 May 2023 18:20:57 +0000 Subject: [PATCH] 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. --- common.mk | 16 ++++++--- example/sound.c | 91 ------------------------------------------------- m68k/Makefile | 40 ---------------------- m68k/common.mk | 58 +++++++++++++++++++++++++++++++ m68k/m68k.lds | 3 ++ m68k/main.c | 12 ------- scsp.h | 8 +++-- 7 files changed, 79 insertions(+), 149 deletions(-) delete mode 100644 example/sound.c delete mode 100644 m68k/Makefile create mode 100644 m68k/common.mk delete mode 100644 m68k/main.c diff --git a/common.mk b/common.mk index 85b649d..70ccfaa 100644 --- a/common.mk +++ b/common.mk @@ -3,11 +3,12 @@ OPT ?= -Og AARCH = --isa=sh2 --big AFLAGS = -g -gdwarf-4 + +CARCH = -m2 -mb 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 -CARCH = -m2 -mb TARGET = sh2-none-elf- CC = $(TARGET)gcc @@ -17,6 +18,13 @@ LD = $(TARGET)ld OBJCOPY = $(TARGET)objcopy 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 $(OBJCOPY) -I coff-sh -O elf32-sh -g \ --rename-section .text=.text.$* \ @@ -41,6 +49,9 @@ SYS_IP_OBJ += $(LIB)/smpsys.o %.o: %.cpp $(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@ +%.elf: + $(LD) $(LDFLAGS) -T $(LIB)/sh2.lds $^ -o $@ + %.bin: %.elf $(OBJCOPY) -O binary $< $@ @@ -50,9 +61,6 @@ SYS_IP_OBJ += $(LIB)/smpsys.o --rename-section .data=.rodata,alloc,load,readonly,data,contents \ $< $@ -%.elf: - $(LD) $(LDFLAGS) -T $(LIB)/sh2.lds $^ -o $@ - sys_ip.elf: $(SYS_IP_OBJ) $(LD) --print-memory-usage -T $(LIB)/sys_ip.lds $^ -o $@ diff --git a/example/sound.c b/example/sound.c deleted file mode 100644 index 8fc3b66..0000000 --- a/example/sound.c +++ /dev/null @@ -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; - } -} diff --git a/m68k/Makefile b/m68k/Makefile deleted file mode 100644 index d0f9777..0000000 --- a/m68k/Makefile +++ /dev/null @@ -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 diff --git a/m68k/common.mk b/m68k/common.mk new file mode 100644 index 0000000..f6db4ab --- /dev/null +++ b/m68k/common.mk @@ -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 diff --git a/m68k/m68k.lds b/m68k/m68k.lds index 17cb523..ba4f290 100644 --- a/m68k/m68k.lds +++ b/m68k/m68k.lds @@ -10,12 +10,15 @@ SECTIONS { . = 0x000000; KEEP(*(.vectors)) + KEEP(*(.text.start)) *(.text) + *(.text.*) } > sound_ram .data ALIGN(4) : SUBALIGN(4) { *(.data) + *(.data.*) } > sound_ram .rodata ALIGN(4) : SUBALIGN(4) diff --git a/m68k/main.c b/m68k/main.c deleted file mode 100644 index 482f6b2..0000000 --- a/m68k/main.c +++ /dev/null @@ -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) { - } -} diff --git a/scsp.h b/scsp.h index 664881a..a0ed924 100644 --- a/scsp.h +++ b/scsp.h @@ -134,7 +134,7 @@ static_assert((offsetof (struct scsp, reg)) == 0x100000); // bits -enum slot_bits { +enum loop_bits { LOOP__KYONEX = ( 1 << 12), // (KX) execute KEY_ON LOOP__KYONB = ( 1 << 11), // (KB) record KEY_ON, KEY_OFF LOOP__SBCTL = ( 0b00 << 9), // source bit control @@ -144,7 +144,11 @@ enum slot_bits { LOOP__LPCTL__REVERSE = ( 0b10 << 5 ), // loop control LOOP__LPCTL__ALTERNATIVE = ( 0b11 << 5 ), // loop control 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 {