git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 1c1c8f9b4798f984e4d9a93e65a16c895e92ad53
parent 3688b18fc72ac391e2d473c189d2f75091bbb028
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Sat,  5 Oct 2024 22:45:54 -0700

Merge pull request #716 from gbdk-2020/megaduck/laptop_examples

Examples: MegaDuck Laptop: Speech example
Diffstat:
Mgbdk-lib/examples/megaduck/laptop_keyboard/Makefile.targets3+--
Mgbdk-lib/examples/megaduck/laptop_rtc/Makefile.targets3+--
Agbdk-lib/examples/megaduck/laptop_speech/Makefile94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/megaduck/laptop_speech/Makefile.targets54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/megaduck/laptop_speech/Readme.md6++++++
Agbdk-lib/examples/megaduck/laptop_speech/src/main.c105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/include/duck/laptop_io.h13++++++++++---
7 files changed, 271 insertions(+), 7 deletions(-)

diff --git a/gbdk-lib/examples/megaduck/laptop_keyboard/Makefile.targets b/gbdk-lib/examples/megaduck/laptop_keyboard/Makefile.targets @@ -51,4 +51,4 @@ gg: nes-clean: ${MAKE} clean-target EXT=nes nes: - ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes - + ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes diff --git a/gbdk-lib/examples/megaduck/laptop_rtc/Makefile.targets b/gbdk-lib/examples/megaduck/laptop_rtc/Makefile.targets @@ -51,4 +51,4 @@ gg: nes-clean: ${MAKE} clean-target EXT=nes nes: - ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes - + ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes diff --git a/gbdk-lib/examples/megaduck/laptop_speech/Makefile b/gbdk-lib/examples/megaduck/laptop_speech/Makefile @@ -0,0 +1,94 @@ +# If you move this project you can change the directory +# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" +ifndef GBDK_HOME + GBDK_HOME = ../../../ +endif + +LCC = $(GBDK_HOME)bin/lcc + +# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets) +# They can also be built/cleaned individually: "make gg" and "make gg-clean" +# Possible are: gb gbc pocket megaduck sms gg +TARGETS= megaduck # gb pocket megaduck sms gg nes + +# Configure platform specific LCC flags here: +LCCFLAGS_gb = # -Wl-yt0x1B # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) +LCCFLAGS_pocket = # -Wl-yt0x1B # Usually the same as required for .gb +LCCFLAGS_duck = # -Wl-yt0x1B # Usually the same as required for .gb +LCCFLAGS_gbc = # -Wl-yt0x1B -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) +LCCFLAGS_sms = +LCCFLAGS_gg = +LCCFLAGS_nes = + +LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags + +LCCFLAGS += -Wl-j # -Wm-yS -Wm-yoA -Wm-ya4 -autobank -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output +LCCFLAGS += -Wf-MMD -Wf-Wp-MP # Header file dependency output (-MMD) for Makefile use + per-header Phony rules (-MP) +CFLAGS += -Wf-MMD -Wf-Wp-MP # Header file dependency output (-MMD) for Makefile use + per-header Phony rules (-MP) + +# You can set the name of the ROM file here +PROJECTNAME = megaduck_speech + +# EXT?=gb # Only sets extension to default (game boy .gb) if not populated +SRCDIR = src +OBJDIR = obj/$(EXT) +RESDIR = res +BINDIR = build/$(EXT) +MKDIRS = $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation + +BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) +CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) + +ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) +OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) + +# Dependencies (using output from -Wf-MMD -Wf-Wp-MP) +DEPS = $(OBJS:%.o=%.d) + +-include $(DEPS) + +# Builds all targets sequentially +all: $(TARGETS) + +test: + echo $(CSOURCES) + + +# Compile .c files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + +# Compile .c files in "res/" to .o object files +$(OBJDIR)/%.o: $(RESDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(CFLAGS) -c -o $@ $< + +# If needed, compile .c files in "src/" to .s assembly files +# (not required if .c is compiled directly to .o) +$(OBJDIR)/%.s: $(SRCDIR)/%.c + $(LCC) $(CFLAGS) -S -o $@ $< + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) $(CFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(OBJS) + +clean: + @echo Cleaning + @for target in $(TARGETS); do \ + $(MAKE) $$target-clean; \ + done + +# Include available build targets +include Makefile.targets + + +# create necessary directories after Makefile is parsed but before build +# info prevents the command from being pasted into the makefile +ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target +$(info $(shell mkdir -p $(MKDIRS))) +endif diff --git a/gbdk-lib/examples/megaduck/laptop_speech/Makefile.targets b/gbdk-lib/examples/megaduck/laptop_speech/Makefile.targets @@ -0,0 +1,54 @@ + +# Platform specific flags for compiling (only populate if they're both present) +ifneq ($(strip $(PORT)),) +ifneq ($(strip $(PLAT)),) +CFLAGS += -m$(PORT):$(PLAT) +endif +endif + +# Called by the individual targets below to build a ROM +build-target: $(BINS) + +clean-target: + rm -rf $(OBJDIR) + rm -rf $(BINDIR) + +gb-clean: + ${MAKE} clean-target EXT=gb +gb: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb + + +gbc-clean: + ${MAKE} clean-target EXT=gbc +gbc: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc + + +pocket-clean: + ${MAKE} clean-target EXT=pocket +pocket: + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket + + +megaduck-clean: + ${MAKE} clean-target EXT=duck +megaduck: + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck + + +sms-clean: + ${MAKE} clean-target EXT=sms +sms: + ${MAKE} build-target PORT=z80 PLAT=sms EXT=sms + + +gg-clean: + ${MAKE} clean-target EXT=gg +gg: + ${MAKE} build-target PORT=z80 PLAT=gg EXT=gg + +nes-clean: + ${MAKE} clean-target EXT=nes +nes: + ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes diff --git a/gbdk-lib/examples/megaduck/laptop_speech/Readme.md b/gbdk-lib/examples/megaduck/laptop_speech/Readme.md @@ -0,0 +1,6 @@ +# Triggering playback of built-in Speech Phrases + +- Initializes the external controller connected over the serial link port +- Triggers playback of the built-in Speech Phrases + + diff --git a/gbdk-lib/examples/megaduck/laptop_speech/src/main.c b/gbdk-lib/examples/megaduck/laptop_speech/src/main.c @@ -0,0 +1,105 @@ +#include <gbdk/platform.h> +#include <gbdk/console.h> +#include <gb/isr.h> + +#include <stdint.h> +#include <stdbool.h> +#include <stdio.h> + +#include <duck/laptop_io.h> + + +// Send a request for the Laptop Hardware to play one of 6 pre-recorded Speech Phrases +// +// The input range is 1-6 (DUCK_IO_SPEECH_CMD_MIN - DUCK_IO_SPEECH_CMD_MAX) +// Playback of one sample can be interrupted by request for playback of another sample +// +// Returns success or failure +bool duck_io_send_speech_cmd(uint8_t speech_sample_num) { + + duck_io_tx_buf[0] = speech_sample_num; + duck_io_tx_buf_len = DUCK_IO_LEN_PLAY_SPEECH; + + if (duck_io_send_cmd_and_buffer(DUCK_IO_CMD_PLAY_SPEECH)) { + return true; + } else { + return false; + } +} + + + +void main(void) { + + uint8_t gamepad; + uint8_t speech_num = 1u; + + bool megaduck_laptop_init_ok = duck_io_laptop_init(); + + SPRITES_8x8; + SHOW_SPRITES; + SHOW_BKG; + printf("Initializing..\n"); + + if (!megaduck_laptop_init_ok) { + // If laptop hardware is not present then there isn't anything + // for this program to do, so just idle in a loop + printf("Laptop not detected\n" + "or Failed to Initialize"); + while(1) { + vsync(); + } + } + + // Otherwise laptop init succeeded + printf("Laptop Detected!\n"); + + printf("\n" + "Play built-in speech\n" + "\n" + "*START:start speech\n" + "*UP/DOWN change num\n"); + + gotoxy(0,10); printf("Play Num:%d ", speech_num); + + while(1) { + vsync(); + gamepad = joypad(); + + // It is not necessary to turn on audio to play the pre-recorded Speech Phrases + + // Laptop serial command intervals below 20 msec may cause laptop hardware lockup + // Poll for RTC every other frame (~32 msec) + if (sys_time & 0x01u) { + + if (gamepad) { + + switch (gamepad) { + case J_UP: + if (speech_num < DUCK_IO_SPEECH_CMD_MAX) speech_num++; + gotoxy(0,10); printf("Play Num:%d ", speech_num); + break; + + case J_DOWN: + if (speech_num > DUCK_IO_SPEECH_CMD_MIN) speech_num--; + gotoxy(0,10); printf("Play Num:%d ", speech_num); + break; + + case J_START: + if (duck_io_send_speech_cmd(speech_num)) { + gotoxy(0,11); + printf("Speech OK \n"); + } else { + gotoxy(0,11); + printf("Speech FAIL\n"); + } + break; + } + + // Wait for all buttons to be released before continuing + waitpadup(); + } + } + } +} + diff --git a/gbdk-lib/include/duck/laptop_io.h b/gbdk-lib/include/duck/laptop_io.h @@ -32,6 +32,7 @@ #define DUCK_IO_CMD_DONE_OR_OK 0x01u // #define DUCK_IO_CMD_DONE_OR_OK_AND_SOMETHING 0x81u #define DUCK_IO_CMD_ABORT_OR_FAIL 0x04u +#define DUCK_IO_CMD_PLAY_SPEECH 0x05u #define DUCK_IO_CMD_RUN_CART_IN_SLOT 0x08u #define DUCK_IO_CMD_INIT_UNKNOWN_0x09 0x09u /**< May also be PrintScreen related */ #define DUCK_IO_CMD_SET_RTC 0x0Bu /**< Command to set hardware RTC by sending a multi-byte packet */ @@ -46,9 +47,11 @@ // #define DUCK_IO_REPLY_READ_FAIL_MAYBE 0x00u #define DUCK_IO_REPLY_BOOT_OK 0x01u -#define DUCK_IO_LEN_KBD_GET 2u /**< GET Keyboard key payload size: 2 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ -#define DUCK_IO_LEN_RTC_GET 8u /**< GET RTC payload size: 8 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ -#define DUCK_IO_LEN_RTC_SET 8u /**< SET RTC payload size: 8 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ +#define DUCK_IO_LEN_KBD_GET 2u /**< Get Keyboard key payload size: 2 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ +#define DUCK_IO_LEN_RTC_GET 8u /**< Get RTC payload size: 8 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ +#define DUCK_IO_LEN_RTC_SET 8u /**< Set RTC payload size: 8 bytes Payload (excludes 1 length header byte, 1 byte Checksum) */ +#define DUCK_IO_LEN_PLAY_SPEECH 1u /**< Play Speech payload size: 1 byte Payload (excludes 1 length header byte, 1 byte Checksum) */ + // #define MEGADUCK_KBD_BYTE_1_EXPECT 0x0Eu // #define MEGADUCK_SIO_BOOT_OK 0x01u @@ -61,6 +64,10 @@ #define DUCK_IO_TIMEOUT_200_MSEC 200u +// Pre-recorded Speech Samples for playback +#define DUCK_IO_SPEECH_CMD_MIN 1 +#define DUCK_IO_SPEECH_CMD_MAX 6 + // RTC packet byte ordering (all in BCD format) #define DUCK_IO_RTC_YEAR 0u

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.