Skip to content

Commit

Permalink
Add support for multiple versions, match current archives under 2.0K (#…
Browse files Browse the repository at this point in the history
…52)

* Initial pass at multi-version support, matched 2.0K

* Fixed CI and made it build K, changed default version back to L

* Fixed VERSION_DEFINE not being used after rebase

* Update checkbox matrix for 2.0K

* Update readme instructions, fix ido CI

* Fix NON_MATCHING and document it in the readme

* Change default version to L, fix clean removing all builds, made distclean remove all builds, allow running clean and distclean without setup

* Made build and extracted paths match the base path format, remove unnecessary file compilation flag setting
  • Loading branch information
Mr-Wiseguy authored Aug 31, 2023
1 parent d163fa4 commit 7b04a39
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [L] # [H, I, I_patch, J, K, L]
version: [K, L] # [H, I, I_patch, J, K, L]
suffix: [~, _d, _rom]

steps:
Expand All @@ -32,7 +32,7 @@ jobs:
token: ${{ secrets.SECRETTOKEN }}
path: deps_repo
- name: Get the dependency
run: cp deps_repo/libultra/${{ matrix.version }}/* .
run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }}

- name: Setup
run: make setup -j $(nproc) TARGET=libgultra${{ matrix.suffix }} VERSION=${{ matrix.version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_ido.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [L] # [E, F, G, H, I, I_patch, J, K, L]
version: [K, L] # [E, F, G, H, I, I_patch, J, K, L]
suffix: [~, _rom] # [~, _d, _rom]

steps:
Expand All @@ -32,7 +32,7 @@ jobs:
token: ${{ secrets.SECRETTOKEN }}
path: deps_repo
- name: Get the dependency
run: cp deps_repo/libultra/${{ matrix.version }}/* .
run: cp deps_repo/libultra/${{ matrix.version }}/* base/${{ matrix.version }}

- name: Setup
run: make setup -j $(nproc) TARGET=libultra${{ matrix.suffix }} VERSION=${{ matrix.version }}
Expand Down
43 changes: 33 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ NON_MATCHING ?= 0
# libgultra_rom, libgultra_d, libgultra
# libultra_rom, libultra_d, libultra
TARGET ?= libgultra_rom
VERSION ?= L
CROSS ?= mips-linux-gnu-

BASE_DIR := base_$(TARGET)
BASE_AR := $(TARGET).a
BASE_DIR := extracted/$(VERSION)/$(TARGET)
BASE_AR := base/$(VERSION)/$(TARGET).a
BUILD_ROOT := build
BUILD_DIR := $(BUILD_ROOT)/$(TARGET)
BUILD_DIR := $(BUILD_ROOT)/$(VERSION)/$(TARGET)
BUILD_AR := $(BUILD_DIR)/$(TARGET).a

WORKING_DIR := $(shell pwd)

CPP := cpp -P
AR := ar

VERSION_D := 1
VERSION_E := 2
VERSION_F := 3
VERSION_G := 4
VERSION_H := 5
VERSION_I := 6
VERSION_J := 7
VERSION_K := 8
VERSION_L := 9

VERSION_DEFINE := -DBUILD_VERSION=$(VERSION_$(VERSION)) -DBUILD_VERSION_STRING=\"2.0$(VERSION)\"

ifeq ($(findstring libgultra,$(TARGET)),libgultra)
-include Makefile.gcc
else ifeq ($(findstring libultra,$(TARGET)),libultra)
Expand All @@ -40,8 +53,7 @@ ASM_DIRS := $(shell find asm -type d -not -path "asm/non_matchings*")
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(SRC_DIRS) $(ASM_DIRS),$(wildcard $(dir)/*.s))
O_FILES := $(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) \
$(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f) \
$(foreach f,$(wildcard $(BASE_DIR)/*),$(BUILD_DIR)/$f)
$(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f)
# Because we patch the object file timestamps, we can't use them as the targets since they'll always be older than the C file
# Therefore instead we use marker files that have actual timestamps as the dependencies for the archive
MARKER_FILES := $(O_FILES:.o=.marker)
Expand All @@ -61,6 +73,17 @@ AR_OLD := $(AR)
endif

BASE_OBJS := $(wildcard $(BASE_DIR)/*.o)

# Check to make sure the current version has been set up
ifneq ($(NON_MATCHING),1)
ifeq ($(BASE_OBJS),)
# Ignore this check if the user is currently running setup, clean or distclean
ifeq ($(filter $(MAKECMDGOALS),setup clean distclean),)
$(error Current version ($(TARGET) 2.0$(VERSION)) has not been setup!)
endif
endif
endif

# Try to find a file corresponding to an archive file in any of src/ asm/ or the base directory, prioritizing src then asm then the original file
AR_ORDER = $(foreach f,$(shell $(AR) t $(BASE_AR)),$(shell find $(BUILD_DIR)/src $(BUILD_DIR)/asm $(BUILD_DIR)/$(BASE_DIR) -iname $f -type f -print -quit))
MATCHED_OBJS = $(filter-out $(BUILD_DIR)/$(BASE_DIR)/%,$(AR_ORDER))
Expand All @@ -69,7 +92,7 @@ NUM_OBJS = $(words $(AR_ORDER))
NUM_OBJS_MATCHED = $(words $(MATCHED_OBJS))
NUM_OBJS_UNMATCHED = $(words $(UNMATCHED_OBJS))

$(shell mkdir -p asm $(BASE_DIR) src $(BUILD_DIR)/$(BASE_DIR) $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(BUILD_DIR)/$(dir)))
$(shell mkdir -p asm $(BASE_DIR) src $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(BUILD_DIR)/$(dir)))

.PHONY: all clean distclean setup
all: $(BUILD_AR)
Expand All @@ -85,15 +108,15 @@ ifneq ($(NON_MATCHING),1)
endif

clean:
$(RM) -rf $(BUILD_ROOT)
$(RM) -rf $(BUILD_DIR)

distclean: clean
distclean:
$(MAKE) -C tools distclean
$(RM) -rf $(BASE_DIR)
$(RM) -rf extracted/ $(BUILD_ROOT)

setup:
$(MAKE) -C tools
cd $(BASE_DIR) && $(AR) xo ../$(BASE_AR)
cd $(BASE_DIR) && $(AR) xo $(WORKING_DIR)/$(BASE_AR)
chmod -R +rw $(BASE_DIR)
ifeq ($(COMPILER),ido)
export CROSS=$(CROSS) && ./tools/strip_debug.sh $(BASE_DIR)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.gcc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export COMPILER_PATH := $(WORKING_DIR)/tools/gcc

CFLAGS := -w -nostdinc -c -G 0 -mgp32 -mfp32 -D_LANGUAGE_C
ASFLAGS := -w -nostdinc -c -G 0 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64 -x assembler-with-cpp
CPPFLAGS = -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE)
CPPFLAGS = -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE)
IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/gcc -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips3
ASOPTFLAGS :=
Expand Down
2 changes: 1 addition & 1 deletion Makefile.ido
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export COMPILER_PATH := $(WORKING_DIR)/tools/ido

CFLAGS := -c -Wab,-r4300_mul -G 0 -nostdinc -Xcpluscomm -fullwarn -woff 516,649,838,712
ASFLAGS := -c -Wab,-r4300_mul -G 0 -nostdinc -woff 516,649,838,712
CPPFLAGS = -D_MIPS_SZLONG=32 $(GBIDEFINE) $(PICFLAGS)
CPPFLAGS = -D_MIPS_SZLONG=32 $(GBIDEFINE) $(VERSION_DEFINE) $(PICFLAGS)
IINC = -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/ido -I $(WORKING_DIR)/include/PR
MIPS_VERSION := -mips2 -o32
PICFLAGS := -non_shared
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ Currently this repo supports building the following versions:
| 2.0I | :x: / :x: | :x: / :x: | :x: / :x: |
| 2.0I_patch | :x: / :x: | :x: / :x: | :x: / :x: |
| 2.0J | :x: / :x: | :x: / :x: | :x: / :x: |
| 2.0K | :x: / :x: | :x: / :x: | :x: / :x: |
| 2.0K | :heavy_check_mark: / :heavy_check_mark: | :x: / :heavy_check_mark: | :heavy_check_mark: / :heavy_check_mark: |
| 2.0L | :heavy_check_mark: / :heavy_check_mark: | :x: / :heavy_check_mark: | :heavy_check_mark: / :heavy_check_mark: |
| ique_v1.5 | :x: | :x: | :x: |

## Preparation

After cloning the repo, put a copy of the target archive on the root of this directory.
After cloning the repo, put a copy of the target archive(s) in their correct version folder in `base/`.
For example, if your target archive is libgultra_rom.a 2.0L then you'd place it in `base/L/`.
If you will be building without a target archive by setting `NON_MATCHING` then you can skip this step.

## Build dependencies

Expand All @@ -46,5 +48,12 @@ sudo apt install binutils-mips-linux-gnu

## Building

- `make setup`
- `make`
Run make setup with the proper flags set followed by make with optional jobs.
For example, if building the 2.0L PC archive you'd do the following:

- `make VERSION=L TARGET=libgultra_rom setup`
- `make VERSION=L TARGET=libgultra_rom`

Every target flag combination requires separate a setup command.

If building without a target archive using `NON_MATCHING` then you can skip the setup command.
Empty file added base/J/.gitkeep
Empty file.
Empty file added base/K/.gitkeep
Empty file.
Empty file added base/L/.gitkeep
Empty file.
14 changes: 12 additions & 2 deletions include/PR/os_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
#ifndef _OS_VERSION_H_
#define _OS_VERSION_H_

#define OS_MAJOR_VERSION "2.0K" /* major version */
#define OS_MINOR_VERSION 0 /* patch level */
#define VERSION_D 1
#define VERSION_E 2
#define VERSION_F 3
#define VERSION_G 4
#define VERSION_H 5
#define VERSION_I 6
#define VERSION_J 7
#define VERSION_K 8
#define VERSION_L 9

#define OS_MAJOR_VERSION BUILD_VERSION_STRING /* major version */
#define OS_MINOR_VERSION 0 /* patch level */

#endif /* !_OS_VERSION_H_ */
9 changes: 9 additions & 0 deletions src/debug/threadprofilestop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ void osThreadProfileStop(void) {

#ifndef NDEBUG
if (__osThprofFlag == 0) {
#if BUILD_VERSION >= VERSION_L
__osRestoreInt(saveMask);
__osError(138, 0);
#else
__osError(138, 0);
__osRestoreInt(saveMask);
#endif
return;
}
#endif
Expand All @@ -23,9 +28,13 @@ void osThreadProfileStop(void) {
thprof[id].time += now_time - __osThprofLastTimer;
} else {
#ifndef NDEBUG
#if BUILD_VERSION >= VERSION_L
__osRestoreInt(saveMask);
#endif
__osError(147, 1, id);
#if BUILD_VERSION >= VERSION_L
saveMask = __osDisableInt();
#endif
#endif
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/io/conteepprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ s32 osEepromProbe(OSMesgQueue* mq) {
}
}

#if BUILD_VERSION >= VERSION_L
__osEepromRead16K = 0;
#endif
__osSiRelAccess();
return ret;
}
7 changes: 6 additions & 1 deletion src/io/conteepread.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "siint.h"

OSPifRam __osEepPifRam ALIGNED(16);
#if BUILD_VERSION >= VERSION_L
s32 __osEepromRead16K;
#endif
static void __osPackEepReadData(u8 address);

s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) {
Expand All @@ -31,9 +33,12 @@ s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) {
if (address >= EEP16K_MAXBLOCKS) {
// not technically possible
ret = CONT_RANGE_ERROR;
} else {
}
#if BUILD_VERSION >= VERSION_L
else {
__osEepromRead16K = 1;
}
#endif
break;
default:
ret = CONT_NO_RESPONSE_ERROR;
Expand Down
7 changes: 6 additions & 1 deletion src/io/conteepwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) {
u8* ptr = (u8*)&__osEepPifRam.ramarray;
__OSContEepromFormat eepromformat;
OSContStatus sdata;
#if BUILD_VERSION > VERSION_K
u8 temp[8];
#endif

__osSiGetAccess();
ret = __osEepStatus(mq, &sdata);
Expand All @@ -28,12 +30,15 @@ s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) {
if (address >= EEP16K_MAXBLOCKS) {
// not technically possible
ret = CONT_RANGE_ERROR;
} else if (__osEepromRead16K) {
}
#if BUILD_VERSION >= VERSION_L
else if (__osEepromRead16K) {
__osEepromRead16K = 0;
__osSiRelAccess();
osEepromRead(mq, (address ^ 1), temp);
__osSiGetAccess();
}
#endif
break;
default:
ret = CONT_NO_RESPONSE_ERROR;
Expand Down

0 comments on commit 7b04a39

Please sign in to comment.