Skip to content

update to hhk3 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ghcr.io/classpaddev/hollyhock-3:v2.1.1 AS toolchain

FROM mcr.microsoft.com/devcontainers/base:debian12 AS base

# Install required packages KEEP IN SYNC (+clangd bear python nano)
RUN apt-get update -y && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
make libncurses6 zstd zlib1g \
gawk wget bzip2 xz-utils unzip \
patch libstdc++6 rsync git mold \
nano clangd-19 bear python3 python-is-python3
RUN apt-get install -y --reinstall ca-certificates
COPY --from=toolchain /toolchain /toolchain
COPY --from=toolchain /sdk /sdk
ENV PATH=$PATH:/toolchain/bin
ENV SDK_DIR=/sdk
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.makefile-tools",
"ms-vscode.cpptools-themes",
"ms-vscode.cpptools",
"xaver.clang-format",
"llvm-vs-code-extensions.vscode-clangd",
"ZixuanWang.linkerscript",
"ms-azuretools.vscode-docker",
"ms-python.python"
]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

runs-on: ubuntu-latest
container:
image: ghcr.io/classpaddev/hollyhock-3
image: ghcr.io/classpaddev/hollyhock-3:v2.1.1
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
peanut-sdl
peanut-debug
tags
.vscode
.cache
compile_commands.json
obj
dist
*.hhk
*.bin
*.elf
*.hh3

# OS items
.DS_Store
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"clangd.arguments": [
"--query-driver=/toolchain/bin/sh4a_nofpueb-elf-*"
],
"clangd.path": "clangd-19"
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make -j",
"problemMatcher": [
"$gcc"
]
}
]
}
56 changes: 22 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,66 @@
# The .hhk file is the original format, the bin file is a newer format.
APP_NAME:=CPBoy

ifndef SDK_DIR
$(error You need to define the SDK_DIR environment variable, and point it to the sdk/ folder)
endif
SDK_DIR?=/sdk

AS:=sh4aeb-elf-gcc
AS:=sh4a_nofpueb-elf-gcc
AS_FLAGS:=

COMMON_FLAGS:=-fshort-wchar -O2 -m4a-nofpu -ffunction-sections -fdata-sections #-flto
COMMON_FLAGS:=-Ofast -gdwarf-5 -ffunction-sections -fdata-sections -flto=auto -ffat-lto-objects #-fstack-protector-all
INCLUDES:=-I $(SDK_DIR)/include/
WARNINGS:=-Wall -Wextra

CC:=sh4aeb-elf-gcc
CC:=sh4a_nofpueb-elf-gcc
CC_FLAGS:=$(COMMON_FLAGS) $(INCLUDES) $(WARNINGS)

CXX:=sh4aeb-elf-g++
CXX:=sh4a_nofpueb-elf-g++
CXX_FLAGS:=-fno-exceptions -fno-rtti -Wno-write-strings $(COMMON_FLAGS) $(INCLUDES) $(WARNINGS)

LD:=$(CXX)
LD_FLAGS:= $(COMMON_FLAGS) $(WARNINGS) -Wno-undef -Wl,--gc-sections
LD_FLAGS:=$(COMMON_FLAGS) $(WARNINGS) -Wl,-Ttext-segment,0x8C052800 -Wno-undef -Wl,--gc-sections #-fno-lto -v

READELF:=sh4aeb-elf-readelf
OBJCOPY:=sh4aeb-elf-objcopy
READELF:=sh4a_nofpueb-elf-readelf
OBJCOPY:=sh4a_nofpueb-elf-objcopy
STRIP:=sh4a_nofpueb-elf-strip

SOURCEDIR = src
BUILDDIR = obj
OUTDIR = dist
BINDIR = $(OUTDIR)/CPBoy/bin

AS_SOURCES:=$(shell find $(SOURCEDIR) -name '*.s')
AS_SOURCES:=$(shell find $(SOURCEDIR) -name '*.S')
CC_SOURCES:=$(shell find $(SOURCEDIR) -name '*.c')
CXX_SOURCES:=$(shell find $(SOURCEDIR) -name '*.cpp')
OBJECTS := $(addprefix $(BUILDDIR)/,$(AS_SOURCES:.s=.o)) \
OBJECTS := $(addprefix $(BUILDDIR)/,$(AS_SOURCES:.S=.o)) \
$(addprefix $(BUILDDIR)/,$(CC_SOURCES:.c=.o)) \
$(addprefix $(BUILDDIR)/,$(CXX_SOURCES:.cpp=.o))

APP_HH3:=$(OUTDIR)/$(APP_NAME).hh3
APP_ELF:=$(OUTDIR)/$(APP_NAME).elf
APP_BIN:=$(OUTDIR)/$(APP_NAME).bin
IL_BIN:=$(BINDIR)/il.bin
Y_BIN:=$(BINDIR)/y.bin

bin: $(APP_BIN) $(IL_BIN) $(Y_BIN) Makefile
.DEFAULT_GOAL=all

hhk: $(APP_ELF) Makefile
hh3: $(APP_HH3) Makefile
elf: $(APP_ELF) Makefile

all: $(APP_ELF) $(APP_BIN) $(IL_BIN) $(Y_BIN) Makefile
all: $(APP_ELF) $(APP_HH3) Makefile

clean:
rm -rf $(BUILDDIR) $(OUTDIR)

$(APP_BIN): $(APP_ELF)
$(OBJCOPY) --remove-section=.oc_mem* --set-section-flags .bss=alloc,load,contents,data --output-target=binary $(APP_ELF) $@
%.hh3: %.elf
$(STRIP) -o $@ $^

$(IL_BIN): $(APP_ELF)
$(APP_ELF): $(OBJECTS) $(SDK_DIR)/libsdk.a
mkdir -p $(dir $@)
$(OBJCOPY) --only-section=.oc_mem.il* --output-target=binary $(APP_ELF) $@

$(Y_BIN): $(APP_ELF)
mkdir -p $(dir $@)
$(OBJCOPY) --only-section=.oc_mem.y* --output-target=binary $(APP_ELF) $@

$(APP_ELF): $(OBJECTS) $(SDK_DIR)/libsdk.a linker.ld
mkdir -p $(dir $@)
$(LD) -T linker.ld -Wl,-Map [email protected] -o $@ $(LD_FLAGS) $(OBJECTS) -L$(SDK_DIR) -lsdk
$(LD) -Wl,-Map [email protected] -o $@ $(LD_FLAGS) $(OBJECTS) -L$(SDK_DIR) -lsdk

# We're not actually building sdk.o, just telling the user they need to do it
# themselves. Just using the target to trigger an error when the file is
# required but does not exist.
$(SDK_DIR)/libsdk.a:
@echo "You need to build the SDK before using it. Run make in the SDK directory, and check the README.md in the SDK directory for more information" && exit 1

$(BUILDDIR)/%.o: %.s
$(BUILDDIR)/%.o: %.S
mkdir -p $(dir $@)
$(AS) -c $< -o $@ $(AS_FLAGS)

Expand All @@ -88,6 +77,5 @@ $(BUILDDIR)/%.o: %.c
$(BUILDDIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CXX) -c $< -o $@ $(CXX_FLAGS)
@$(READELF) $@ -S | grep ".ctors" > /dev/null && echo "ERROR: Global constructors aren't supported." && rm $@ && exit 1 || exit 0

.PHONY: bin hhk all clean
.PHONY: elf hh3 all clean
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ You will need to have the [Hollyhock-3 CFW](https://github.com/ClasspadDev/holly
├── run.bin (Hollyhock launcher)
├── CPBoy.bin (Main CPBoy executable)
└── CPBoy/
├── bin/
| ├── il.bin
| └── y.bin
└── roms/
└── ** Put your roms in here **
```
Expand Down
67 changes: 0 additions & 67 deletions linker.ld

This file was deleted.

44 changes: 1 addition & 43 deletions src/cas/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdint.h>
#include <string.h>
#include <sdk/os/mcs.hpp>
#include <sdk/os/mcs.h>
#include "cpu/cpg.h"
#include "cpu/cmt.h"
#include "cpu/dmac.h"
Expand All @@ -11,27 +11,8 @@
#include "../core/error.h"
#include "../helpers/fileio.h"

// All external binaries have to be defined here
const char *bin_files[] = {
"il.bin",
"y.bin"
};

void *load_addresses[] = {
IL_MEMORY,
Y_MEMORY_0
};

uint8_t load_bins(const char **bin_files, void **load_addresses, size_t bin_count);

uint8_t setup_cas()
{
// Load external binaries
if (load_bins(bin_files, load_addresses, sizeof(load_addresses) / sizeof(void *)))
{
return 1;
}

// Enable DMA Controller
POWER_MSTPCR0->DMAC = 0;
DMAC_DMAOR->raw = 0;
Expand Down Expand Up @@ -62,26 +43,3 @@ void restore_cas()
// Restore clock speed
cpg_set_pll_mul(CPG_PLL_MUL_DEFAULT);
}

uint8_t load_bins(const char **bin_files, void **load_addresses, size_t bin_count)
{
for (size_t i = 0; i < bin_count; i++)
{
char bin_path[MAX_FILENAME_LEN] = DIRECTORY_BIN "\\" ;
strlcat(bin_path, bin_files[i], sizeof(bin_path));

size_t bin_size;

if (get_file_size(bin_path, &bin_size))
{
return 1;
}

if (read_file(bin_path, load_addresses[i], bin_size))
{
return 1;
}
}

return 0;
}
21 changes: 21 additions & 0 deletions src/cas/cpu/stack.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define _CONCAT(a, b) a##b
#define CONCAT(a, b) _CONCAT(a, b)
#define G(l) CONCAT(__USER_LABEL_PREFIX__, l)

.global G(on_alt_stack)

.text
.align 2
G(on_alt_stack):
// r4 - void *stack
// r5 - void (*fun)(void *arg1)
// r6 - void *arg1
mov.l r15, @-r4
sts.l pr, @-r4
mov r5, r1
mov r4, r15
jsr @r1
mov r6, r4
lds.l @r15+, pr
rts
mov.l @r15+, r15
5 changes: 1 addition & 4 deletions src/cas/cpu/stack.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include <stdint.h>

extern "C"
void *set_stack_ptr(void *ptr);

extern "C"
void *get_stack_ptr();
void on_alt_stack(void *stack, void (*fun)(void *arg1), void *arg1);
13 changes: 0 additions & 13 deletions src/cas/cpu/stack.s

This file was deleted.

13 changes: 0 additions & 13 deletions src/cas/display.h

This file was deleted.

Loading