├── .clang-format ├── .github └── workflows │ ├── format.yml │ └── report.yml ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── Makefile ├── README.md ├── bin └── cc1-27 ├── config ├── check.sled00038.sha ├── splat.sled00038.croc.yml └── symbols.sled00038.croc.txt ├── diff_settings.py ├── disks ├── .gitignore ├── README └── sled00038 │ └── .gitignore ├── hasm └── func_8005402C.s ├── include ├── common.h ├── include_asm.h ├── macro.inc ├── macros.h ├── psyq │ ├── abs.h │ ├── asm.h │ ├── assert.h │ ├── autopad.h │ ├── convert.h │ ├── ctype.h │ ├── fs.h │ ├── gtemac.h │ ├── gtenom.h │ ├── gtereg.h │ ├── inline_a.h │ ├── inline_c.h │ ├── inline_o.h │ ├── kernel.h │ ├── libcd.h │ ├── libcomb.h │ ├── libds.h │ ├── libetc.h │ ├── libgpu.h │ ├── libgs.h │ ├── libgte.h │ ├── libgun.h │ ├── libmath.h │ ├── libmcrd.h │ ├── libpress.h │ ├── libsio.h │ ├── libsn.h │ ├── libsnd.h │ ├── libspu.h │ ├── libtap.h │ ├── limits.h │ ├── malloc.h │ ├── memory.h │ ├── qsort.h │ ├── r3000.h │ ├── rand.h │ ├── romio.h │ ├── setjmp.h │ ├── stdarg.h │ ├── stddef.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── strings.h │ └── sys │ │ ├── errno.h │ │ ├── fcntl.h │ │ ├── file.h │ │ ├── ioctl.h │ │ └── types.h └── types.h ├── src └── croc │ └── 3038.c └── tools ├── decompile.py ├── m2ctx.py ├── report_progress.py ├── requirements-debian.txt └── requirements-python.txt /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignArrayOfStructures: None 7 | AlignConsecutiveMacros: false # might want to change into AcrossComments 8 | AlignConsecutiveAssignments: false # might want to change into AcrossComments 9 | AlignConsecutiveBitFields: false # might want to change into AcrossComments 10 | AlignConsecutiveDeclarations: false # might want to change into AcrossComments 11 | AlignEscapedNewlines: Right 12 | AlignOperands: Align 13 | AlignTrailingComments: true 14 | AllowAllArgumentsOnNextLine: true 15 | AllowAllParametersOfDeclarationOnNextLine: true 16 | AllowShortEnumsOnASingleLine: true 17 | AllowShortBlocksOnASingleLine: Never 18 | AllowShortCaseLabelsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: All 20 | AllowShortLambdasOnASingleLine: All 21 | AllowShortIfStatementsOnASingleLine: Never 22 | AllowShortLoopsOnASingleLine: false 23 | AlwaysBreakAfterDefinitionReturnType: None 24 | AlwaysBreakAfterReturnType: None 25 | AlwaysBreakBeforeMultilineStrings: false 26 | AlwaysBreakTemplateDeclarations: MultiLine 27 | AttributeMacros: 28 | - __capability 29 | BinPackArguments: true 30 | BinPackParameters: true 31 | BraceWrapping: 32 | AfterCaseLabel: false 33 | AfterClass: false 34 | AfterControlStatement: Never 35 | AfterEnum: false 36 | AfterFunction: false 37 | AfterNamespace: false 38 | AfterObjCDeclaration: false 39 | AfterStruct: false 40 | AfterUnion: false 41 | AfterExternBlock: false 42 | BeforeCatch: false 43 | BeforeElse: false 44 | BeforeLambdaBody: false 45 | BeforeWhile: false 46 | IndentBraces: false 47 | SplitEmptyFunction: true 48 | SplitEmptyRecord: true 49 | SplitEmptyNamespace: true 50 | BreakBeforeBinaryOperators: None 51 | BreakBeforeConceptDeclarations: true 52 | BreakBeforeBraces: Attach 53 | BreakBeforeInheritanceComma: false 54 | BreakInheritanceList: BeforeColon 55 | BreakBeforeTernaryOperators: true 56 | BreakConstructorInitializersBeforeComma: false 57 | BreakConstructorInitializers: BeforeColon 58 | BreakAfterJavaFieldAnnotations: false 59 | BreakStringLiterals: true 60 | ColumnLimit: 80 61 | CommentPragmas: '^ IWYU pragma:' 62 | QualifierAlignment: Left 63 | CompactNamespaces: false 64 | ConstructorInitializerIndentWidth: 4 65 | ContinuationIndentWidth: 4 66 | Cpp11BracedListStyle: true 67 | DeriveLineEnding: true 68 | DerivePointerAlignment: false 69 | DisableFormat: false 70 | EmptyLineAfterAccessModifier: Never 71 | EmptyLineBeforeAccessModifier: LogicalBlock 72 | ExperimentalAutoDetectBinPacking: false 73 | PackConstructorInitializers: NextLine 74 | BasedOnStyle: '' 75 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 76 | AllowAllConstructorInitializersOnNextLine: true 77 | FixNamespaceComments: true 78 | ForEachMacros: 79 | - foreach 80 | - Q_FOREACH 81 | - BOOST_FOREACH 82 | IfMacros: 83 | - KJ_IF_MAYBE 84 | IncludeBlocks: Preserve 85 | IncludeCategories: 86 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 87 | Priority: 2 88 | SortPriority: 0 89 | CaseSensitive: false 90 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 91 | Priority: 3 92 | SortPriority: 0 93 | CaseSensitive: false 94 | - Regex: '.*' 95 | Priority: 1 96 | SortPriority: 0 97 | CaseSensitive: false 98 | IncludeIsMainRegex: '(Test)?$' 99 | IncludeIsMainSourceRegex: '' 100 | IndentAccessModifiers: false 101 | IndentCaseLabels: false 102 | IndentCaseBlocks: false 103 | IndentGotoLabels: true 104 | IndentPPDirectives: None 105 | IndentExternBlock: AfterExternBlock 106 | IndentRequires: false 107 | IndentWidth: 4 108 | IndentWrappedFunctionNames: false 109 | InsertTrailingCommas: None 110 | JavaScriptQuotes: Leave 111 | JavaScriptWrapImports: true 112 | KeepEmptyLinesAtTheStartOfBlocks: true 113 | LambdaBodyIndentation: Signature 114 | MacroBlockBegin: '' 115 | MacroBlockEnd: '' 116 | MaxEmptyLinesToKeep: 1 117 | NamespaceIndentation: None 118 | ObjCBinPackProtocolList: Auto 119 | ObjCBlockIndentWidth: 2 120 | ObjCBreakBeforeNestedBlockParam: true 121 | ObjCSpaceAfterProperty: false 122 | ObjCSpaceBeforeProtocolList: true 123 | PenaltyBreakAssignment: 2 124 | PenaltyBreakBeforeFirstCallParameter: 19 125 | PenaltyBreakComment: 300 126 | PenaltyBreakFirstLessLess: 120 127 | PenaltyBreakOpenParenthesis: 1 128 | PenaltyBreakString: 1000 129 | PenaltyBreakTemplateDeclaration: 10 130 | PenaltyExcessCharacter: 1000000 131 | PenaltyReturnTypeOnItsOwnLine: 60 132 | PenaltyIndentedWhitespace: 1 133 | PointerAlignment: Left 134 | PPIndentWidth: -1 135 | ReferenceAlignment: Pointer 136 | ReflowComments: true 137 | RemoveBracesLLVM: false 138 | SeparateDefinitionBlocks: Leave 139 | ShortNamespaceLines: 1 140 | SortIncludes: Never 141 | SortJavaStaticImport: Before 142 | SortUsingDeclarations: true 143 | SpaceAfterCStyleCast: false 144 | SpaceAfterLogicalNot: false 145 | SpaceAfterTemplateKeyword: true 146 | SpaceBeforeAssignmentOperators: true 147 | SpaceBeforeCaseColon: false 148 | SpaceBeforeCpp11BracedList: false 149 | SpaceBeforeCtorInitializerColon: true 150 | SpaceBeforeInheritanceColon: true 151 | SpaceBeforeParens: ControlStatements 152 | SpaceBeforeParensOptions: 153 | AfterControlStatements: true 154 | AfterForeachMacros: true 155 | AfterFunctionDefinitionName: false 156 | AfterFunctionDeclarationName: false 157 | AfterIfMacros: true 158 | AfterOverloadedOperator: false 159 | BeforeNonEmptyParentheses: false 160 | SpaceAroundPointerQualifiers: Before 161 | SpaceBeforeRangeBasedForLoopColon: true 162 | SpaceInEmptyBlock: false 163 | SpaceInEmptyParentheses: false 164 | SpacesBeforeTrailingComments: 1 165 | SpacesInAngles: Never 166 | SpacesInConditionalStatement: false 167 | SpacesInContainerLiterals: true 168 | SpacesInCStyleCastParentheses: false 169 | SpacesInLineCommentPrefix: 170 | Minimum: 1 171 | Maximum: 1 172 | SpacesInParentheses: false 173 | SpacesInSquareBrackets: false 174 | SpaceBeforeSquareBrackets: false 175 | BitFieldColonSpacing: Both 176 | Standard: Latest 177 | StatementAttributeLikeMacros: 178 | - Q_EMIT 179 | StatementMacros: 180 | - Q_UNUSED 181 | - QT_REQUIRE_VERSION 182 | TabWidth: 4 183 | UseTab: Never 184 | WhitespaceSensitiveMacros: 185 | - STRINGIZE 186 | - PP_STRINGIZE 187 | - BOOST_PP_STRINGIZE 188 | - NS_SWIFT_NAME 189 | - CF_SWIFT_NAME 190 | ... 191 | -------------------------------------------------------------------------------- /.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | name: Format code 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**/*.c' 7 | - '**/*.h' 8 | pull_request_target: 9 | paths-ignore: 10 | - '.github/workflows/**' 11 | - '**/*.c' 12 | - '**/*.h' 13 | 14 | jobs: 15 | test: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Install requirements 19 | run: sudo apt-get install clang-format 20 | - name: Install python 21 | uses: actions/setup-python@v5 22 | with: 23 | python-version: '3.10' 24 | - name: Install black 25 | run: pip install black pyyaml mapfile-parser==2.1.4 26 | - name: Clone main repository 27 | uses: actions/checkout@v2 28 | - name: Format code 29 | run: make format 30 | - name: Check if files have been modified 31 | id: git-check 32 | run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi) 33 | - name: Push changes 34 | if: steps.git-check.outputs.modified == 'true' 35 | run: | 36 | git config --global user.name 'Formatting bot' 37 | git config --global user.email 'xeeynamo@users.noreply.github.com' 38 | git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} 39 | git commit -am "Format code" 40 | git push 41 | -------------------------------------------------------------------------------- /.github/workflows/report.yml: -------------------------------------------------------------------------------- 1 | name: Update progress 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - 'src/*.c' 9 | - 'src/**/*.c' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | update-progress: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Clone main repository 17 | uses: actions/checkout@v2 18 | - name: Clone asset repository 19 | uses: actions/checkout@v2 20 | with: 21 | ref: 'gh-report' 22 | path: 'gh-report' 23 | - name: Set-up Python 24 | uses: actions/setup-python@v2 25 | with: 26 | python-version: '3.x' 27 | - name: Generate report 28 | run: | 29 | mkdir -p gh-report/assets 30 | python tools/report_progress.py CROC.EXE 1058 src/croc > gh-report/assets/progress-sled00038-croc.json 31 | - name: Commit report 32 | run: | 33 | git config --global user.name 'GitHub Action' 34 | git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' 35 | git add -A 36 | git commit -m 'Update progress' || true 37 | git push 38 | working-directory: gh-report -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ctx.c 2 | ctx.c.m2c 3 | *.ld 4 | *auto.*.txt 5 | __pycache__ 6 | 7 | asm/*/*.s 8 | asm/*/data/*.s 9 | asm/*/nonmatchings/*.s 10 | asm/*/nonmatchings/*/*.s 11 | asm/*/nonmatchings/*/*/*.s 12 | assets/ 13 | build/ 14 | expected/ 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/splat"] 2 | path = tools/splat 3 | url = https://github.com/ethteck/splat.git 4 | [submodule "tools/asm-differ"] 5 | path = tools/asm-differ 6 | url = https://github.com/simonlindholm/asm-differ.git 7 | [submodule "tools/m2c"] 8 | path = tools/m2c 9 | url = https://github.com/matt-kempster/m2c.git 10 | [submodule "tools/maspsx"] 11 | path = tools/maspsx 12 | url = git@github.com:mkst/maspsx.git 13 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "libcd.h": "c", 4 | "common.h": "c", 5 | "types.h": "c" 6 | } 7 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .SECONDEXPANSION: 2 | .SECONDARY: 3 | 4 | # Binaries 5 | BUILD := sled00038 6 | BOOT := boot 7 | CROC := croc 8 | 9 | # Compilers 10 | CROSS := mipsel-linux-gnu- 11 | AS := $(CROSS)as 12 | CC := ./bin/cc1-27 13 | LD := $(CROSS)ld 14 | CPP := $(CROSS)cpp 15 | OBJCOPY := $(CROSS)objcopy 16 | AS_FLAGS += -Iinclude -march=r3000 -mtune=r3000 -no-pad-sections -O1 17 | CC_FLAGS += -mips1 -mcpu=3000 -quiet -G0 -Wall -fno-builtin -mno-abicalls -funsigned-char -O1 18 | CPP_FLAGS += -Iinclude -Iinclude/psyq -undef -Wall -lang-c -fno-builtin -gstabs 19 | CPP_FLAGS += -Dmips -D__GNUC__=2 -D__OPTIMIZE__ -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D_LANGUAGE_C -DLANGUAGE_C 20 | 21 | # Directories 22 | ASM_DIR := asm 23 | SRC_DIR := src 24 | INCLUDE_DIR := include 25 | BUILD_DIR := build 26 | CONFIG_DIR := config 27 | TOOLS_DIR := tools 28 | 29 | # Files 30 | CROC_ASM_DIRS := $(ASM_DIR)/$(CROC) $(ASM_DIR)/$(CROC)/psxsdk $(ASM_DIR)/$(CROC)/data 31 | CROC_SRC_DIRS := $(SRC_DIR)/$(CROC) $(SRC_DIR)/$(CROC)/psxsdk 32 | CROC_S_FILES := $(foreach dir,$(CROC_ASM_DIRS),$(wildcard $(dir)/*.s)) \ 33 | $(foreach dir,$(CROC_ASM_DIRS),$(wildcard $(dir)/**/*.s)) 34 | CROC_C_FILES := $(foreach dir,$(CROC_SRC_DIRS),$(wildcard $(dir)/*.c)) \ 35 | $(foreach dir,$(CROC_SRC_DIRS),$(wildcard $(dir)/**/*.c)) 36 | CROC_O_FILES := $(foreach file,$(CROC_S_FILES),$(BUILD_DIR)/$(file).o) \ 37 | $(foreach file,$(CROC_C_FILES),$(BUILD_DIR)/$(file).o) 38 | CROC_TARGET := $(BUILD_DIR)/$(CROC) 39 | 40 | # Tooling 41 | PYTHON := python3 42 | SPLAT_DIR := $(TOOLS_DIR)/splat 43 | SPLAT_APP := $(SPLAT_DIR)/split.py 44 | SPLAT := $(PYTHON) $(SPLAT_APP) 45 | ASMDIFFER_DIR := $(TOOLS_DIR)/asm-differ 46 | ASMDIFFER_APP := $(ASMDIFFER_DIR)/diff.py 47 | M2CTX_APP := $(TOOLS_DIR)/m2ctx.py 48 | M2CTX := $(PYTHON) $(M2CTX_APP) 49 | M2C_DIR := $(TOOLS_DIR)/m2c 50 | M2C_APP := $(M2C_DIR)/m2c.py 51 | M2C := $(PYTHON) $(M2C_APP) 52 | M2C_ARGS := -P 4 53 | MASPSX_DIR := $(TOOLS_DIR)/maspsx 54 | MASPSX_APP := $(MASPSX_DIR)/maspsx.py 55 | MASPSX := $(PYTHON) $(MASPSX_APP) --expand-div --aspsx-version=2.56 56 | 57 | define list_src_files 58 | $(foreach dir,$(ASM_DIR)/$(1),$(wildcard $(dir)/**.s)) 59 | $(foreach dir,$(ASM_DIR)/$(1)/data,$(wildcard $(dir)/**.s)) 60 | $(foreach dir,$(ASM_DIR)/$(1)/psxsdk,$(wildcard $(dir)/**.s)) 61 | $(foreach dir,$(SRC_DIR)/$(1),$(wildcard $(dir)/**.c)) 62 | $(foreach dir,$(SRC_DIR)/$(1)/psxsdk,$(wildcard $(dir)/**.c)) 63 | endef 64 | 65 | define list_o_files 66 | $(foreach file,$(call list_src_files,$(1)),$(BUILD_DIR)/$(file).o) 67 | endef 68 | 69 | define link 70 | $(LD) -o $(2) \ 71 | -Map $(BUILD_DIR)/$(1).map \ 72 | -T $(1).ld \ 73 | -T $(CONFIG_DIR)/undefined_syms_auto.$(BUILD).$(1).txt \ 74 | -T $(CONFIG_DIR)/undefined_funcs_auto.$(BUILD).$(1).txt \ 75 | --no-check-sections \ 76 | -nostdlib \ 77 | -s 78 | endef 79 | 80 | all: build check 81 | build: croc 82 | clean: 83 | git clean -fdx asm/ 84 | git clean -fdx $(BUILD_DIR) 85 | git clean -fdx config/ 86 | format: 87 | clang-format -i $$(find $(SRC_DIR)/ -type f -name "*.c") 88 | clang-format -i $$(find $(SRC_DIR)/ -type f -name "*.h") 89 | clang-format -i $$(find $(INCLUDE_DIR)/ -type f -name "*.h") 90 | black tools/*.py 91 | check: 92 | sha1sum --check config/check.sled00038.sha 93 | expected: check 94 | rm -rf expected/build 95 | cp -r build expected/ 96 | 97 | croc.elf: $(CROC_O_FILES) 98 | $(LD) -o $@ \ 99 | -Map $(CROC_TARGET).map \ 100 | -T $(CROC).ld \ 101 | -T $(CONFIG_DIR)/undefined_syms_auto.$(CROC).txt \ 102 | --no-check-sections \ 103 | -nostdlib \ 104 | -s 105 | 106 | croc: croc_dirs $(BUILD_DIR)/CROC.EXE 107 | $(BUILD_DIR)/CROC.EXE: $(BUILD_DIR)/$(CROC).elf 108 | $(OBJCOPY) -O binary $< $@ 109 | $(BUILD_DIR)/$(CROC).elf: $(call list_o_files,croc) 110 | $(call link,croc,$@) 111 | 112 | %_dirs: 113 | $(foreach dir,$(ASM_DIR)/$* $(ASM_DIR)/$*/data $(SRC_DIR)/$*,$(shell mkdir -p $(BUILD_DIR)/$(dir))) 114 | 115 | $(BUILD_DIR)/%.elf: $$(call list_o_files,$$*) 116 | $(call link,$*,$@) 117 | 118 | extract: extract_croc 119 | extract_croc: require-tools 120 | $(SPLAT) $(CONFIG_DIR)/splat.sled00038.croc.yml 121 | $(CONFIG_DIR)/symbols.%.txt: 122 | 123 | decompile: $(M2C_APP) 124 | $(M2CTX) src/croc/3038.c 125 | $(M2C_APP) $(M2C_ARGS) --target mipsel-gcc-c --context ctx.c asm/croc/nonmatchings/3038/$(FUNC).s 126 | 127 | require-tools: $(SPLAT_APP) $(ASMDIFFER_APP) 128 | update-dependencies: require-tools $(M2CTX_APP) $(M2C_APP) 129 | pip3 install -r $(TOOLS_DIR)/requirements-python.txt 130 | 131 | $(SPLAT_APP): 132 | git submodule init $(SPLAT_DIR) 133 | git submodule update $(SPLAT_DIR) 134 | pip3 install -r $(SPLAT_DIR)/requirements.txt 135 | $(ASMDIFFER_APP): 136 | git submodule init $(ASMDIFFER_DIR) 137 | git submodule update $(ASMDIFFER_DIR) 138 | $(M2CTX_APP): 139 | curl -o $@ https://raw.githubusercontent.com/ethteck/m2ctx/main/m2ctx.py 140 | $(M2C_APP): 141 | git submodule init $(M2C_DIR) 142 | git submodule update $(M2C_DIR) 143 | python3 -m pip install --upgrade pycparser 144 | $(MASPSX_APP): 145 | git submodule init $(MASPSX_DIR) 146 | git submodule update $(MASPSX_DIR) 147 | 148 | $(BUILD_DIR)/%.s.o: %.s 149 | $(AS) $(AS_FLAGS) -o $@ $< 150 | $(BUILD_DIR)/%.bin.o: %.bin 151 | $(LD) -r -b binary -o -Map %.map $@ $< 152 | $(BUILD_DIR)/%.c.o: %.c $(MASPSX_APP) 153 | $(CPP) $(CPP_FLAGS) $< | $(CC) $(CC_FLAGS) | $(MASPSX) | $(AS) $(AS_FLAGS) -o $@ 154 | 155 | SHELL = /bin/bash -e -o pipefail 156 | 157 | .PHONY: all, clean, format, check, expected 158 | .PHONY: croc, boot 159 | .PHONY: extract_croc, extract_boot 160 | .PHONY: require-tools, update-dependencies 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Croc: Legend of Gobbos decompilation 2 | 3 | Creates a full decompilation in C that compiles the same identical binary used the commercial video game Croc: Legend of Gobbos for PlayStation 1. 4 | 5 | This decompilation is based on the European demo SLED-00038. This was decided as it is the only known build that contains symbols. This would theorically allow a much faster decompilation. Once the decompilation is complete, the plan is to migrate the existing symbols to the retail build SLUS-00530. 6 | 7 | ## Progress 8 | 9 | | Version | File name | Progress 10 | |--------------|------------|---------- 11 | | `SLED-00038` | `CROC.EXE` | ![progress](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Xeeynamo/croc/gh-report/assets/progress-sled00038-croc.json) 12 | | `SLED-00038` | `DEMOFMV` | N/A 13 | 14 | ## How to setup the project (assuming Ubuntu 20.04/Debian 11 or Windows with WSL) 15 | 16 | 1. Inside the folder of your choice `git clone https://github.com/Xeeynamo/croc.git` 17 | 1. Run `sudo apt-get install -y $(cat tools/requirements-debian.txt)` 18 | 1. Run `make update-dependencies` 19 | 1. Copy the content of the disk inside `disks/{game_version}` 20 | 21 | ## How to build 22 | 23 | 1. Run `make extract` to generate the assembly files in the `asm/` directory 24 | 1. Run `make all` to compile the binaries in the `build/` directory 25 | 26 | In case there are any changes in the `config/` folder, you might need to run `make clean` to reset the extraction. 27 | 28 | Some non-matching functions are present in the source preprocessed by the macro `NON_MATCHING`. You can still compile the game binaries by running `CPP_FLAGS=-DNON_MATCHING make`. In theory they might be logically equivalent in-game, but I cannot promise that. Few of them could match by tuning or changing the compiler. 29 | 30 | ## How to decompile 31 | 32 | 1. Run `make clean extract all expected` at least once 33 | 1. Look for one of those function which hasn't successfully decompiled yet (eg. `INCLUDE_ASM("asm/croc/nonmatchings/3038", BackGroundTextureLoad);`) 34 | 1. Run `FUNC=BackGroundTextureLoad make decompile` to dump the decompiled code on the console 35 | 1. Replace the `INCLUDE_ASM(...);` you targeted with the console output content 36 | 1. and invoke `python3 ./tools/asm-differ/diff.py -mwo BackGroundTextureLoad` 37 | 38 | You will probably have some differences from your compiled code to the original; keep refactoring the code and move variables around until you have a 100% match. 39 | 40 | There are a few tricks to make the process more streamlined: 41 | 42 | 1. Use [decomp.me](https://decomp.me/) with the PSY-Q 4.0 compiler. 43 | 1. The “context” section of decomp.me, is provided by the previous command `make decompile` as mentioned in the how to decompile. 44 | 1. Use [decomp-permuter](https://github.com/simonlindholm/decomp-permuter) to solve some mismatches 45 | 1. Use [this](https://github.com/mkst/sssv/wiki/Jump-Tables) and [this](https://github.com/pmret/papermario/wiki/GCC-2.8.1-Tips-and-Tricks) guide to understand how some compiler patterns work 46 | 1. Use the `#ifndef NON_MATCHING` if your code is logically equivalent but you cannot yet fully match it 47 | 48 | ## Troubleshooting 49 | 50 | ### Not getting an "OK" on Ubuntu 22.04 51 | 52 | Debian>=12 and Ubuntu>=22.04 uses `binutils-mipsel-linux-gnu`>=2.38 which, for some unknown reasons, it generates broken binaries. You need to downgrade to 2.34 or 2.35 with the following: 53 | 54 | ```shell 55 | curl -L -o binutils-mipsel-linux-gnu_2.35.2-2cross2_amd64.deb http://ftp.de.debian.org/debian/pool/main/b/binutils-mipsen/binutils-mipsel-linux-gnu_2.35.2-2cross2_amd64.deb 56 | dpkg -i binutils-mipsel-linux-gnu_2.35.2-2cross2_amd64.deb 57 | rm binutils-mipsel-linux-gnu_2.35.2-2cross2_amd64.deb 58 | ``` 59 | -------------------------------------------------------------------------------- /bin/cc1-27: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/bin/cc1-27 -------------------------------------------------------------------------------- /config/check.sled00038.sha: -------------------------------------------------------------------------------- 1 | 254c7884d46f21b70a94ed2e694cb17fe27996f9 build/CROC.EXE -------------------------------------------------------------------------------- /config/splat.sled00038.croc.yml: -------------------------------------------------------------------------------- 1 | options: 2 | platform: psx 3 | basename: croc 4 | base_path: .. 5 | target_path: disks/sled00038/CROC.EXE 6 | asm_path: asm/croc 7 | asset_path: assets/croc 8 | src_path: src/croc 9 | compiler: GCC 10 | symbol_addrs_path: config/symbols.sled00038.croc.txt 11 | undefined_funcs_auto_path: config/undefined_funcs_auto.sled00038.croc.txt 12 | undefined_syms_auto_path: config/undefined_syms_auto.sled00038.croc.txt 13 | find_file_boundaries: yes 14 | use_legacy_include_asm: no 15 | migrate_rodata_to_functions: no 16 | section_order: 17 | - ".rodata" 18 | - ".text" 19 | - ".data" 20 | - ".bss" 21 | segments: 22 | - [0x800, header] 23 | - name: croc 24 | type: code 25 | start: 0x00000800 26 | vram: 0x80010000 27 | subalign: 4 28 | subsegments: 29 | - [0x800, rodata] # rdata 30 | - [0x3038, c] # text 31 | - [0x5B154, data] # data 32 | - [0x64340, data] # sdata 33 | - [0x64738, data] # bss 34 | - [0x64800] 35 | -------------------------------------------------------------------------------- /diff_settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | 6 | def add_custom_arguments(parser): 7 | parser.add_argument( 8 | "--version", 9 | default="sled00038", 10 | dest="version", 11 | help="Decide what version of the game to use (list of builds in disks/README)", 12 | ) 13 | parser.add_argument( 14 | "--overlay", 15 | default="croc", 16 | dest="overlay", 17 | help="Defines which overlay to use for the diff", 18 | ) 19 | 20 | def apply(config, args): 21 | version = args.version or os.getenv("VERSION") or "sled00038" 22 | name = args.overlay or "croc" 23 | config["arch"] = "mipsel" 24 | config['baseimg'] = f'disks/{version}/' + (f"/{name}.PRG").upper() 25 | config['myimg'] = f'build/' + (f"/{name}.exe").upper() 26 | config['mapfile'] = f'build/{name}.map' 27 | config['source_directories'] = [f'src/{name}', 'include', f'asm/{name}'] 28 | -------------------------------------------------------------------------------- /disks/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !README 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /disks/README: -------------------------------------------------------------------------------- 1 | # Croc builds 2 | 3 | * `proto1996`: [Download](https://hiddenpalace.org/Croc:_Legend_of_the_Gobbos_(Aug_11,_1996_prototype)) 4 | * `proto1997`: [Download](https://hiddenpalace.org/Croc:_Legend_of_the_Gobbos_(Feb_28,_1997_prototype)) 5 | * `sled00038`: [Redump](http://redump.org/disc/15564/) 6 | * `sles00593`: [Redump](http://redump.org/disc/1137/) 7 | * `slus00530`: [Redump](http://redump.org/disc/3301/) 8 | * `slps01055`: [Redump](http://redump.org/disc/15262/) 9 | * `slpm80173`: [Redump](http://redump.org/disc/57322/) 10 | -------------------------------------------------------------------------------- /disks/sled00038/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /hasm/func_8005402C.s: -------------------------------------------------------------------------------- 1 | .set noat /* allow manual use of $at */ 2 | .set noreorder /* don't insert nops after branches */ 3 | 4 | glabel func_8005402C 5 | /* 4482C 8005402C */ .word 0x15097350 6 | /* 44830 80054030 */ .word 0x00409F9C # invalid instruction 7 | .size func_8005402C, . - func_8005402C 8 | -------------------------------------------------------------------------------- /include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include "include_asm.h" 5 | #include "macros.h" 6 | #include "types.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /include/include_asm.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_ASM_H 2 | #define INCLUDE_ASM_H 3 | 4 | #define STRINGIFY_(x) #x 5 | #define STRINGIFY(x) STRINGIFY_(x) 6 | 7 | #ifndef PERMUTER 8 | 9 | #ifndef INCLUDE_ASM 10 | 11 | #define INCLUDE_ASM(FOLDER, NAME) \ 12 | __asm__(".section .text\n" \ 13 | "\t.align\t2\n" \ 14 | "\t.globl\t" #NAME "\n" \ 15 | "\t.ent\t" #NAME "\n" #NAME ":\n" \ 16 | ".include \"" FOLDER "/" #NAME ".s\"\n" \ 17 | "\t.set reorder\n" \ 18 | "\t.set at\n" \ 19 | "\t.end\t" #NAME); 20 | #endif 21 | 22 | // omit .global 23 | __asm__(".include \"macro.inc\"\n"); 24 | 25 | #else 26 | #define INCLUDE_ASM(FOLDER, NAME) 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/macro.inc: -------------------------------------------------------------------------------- 1 | .macro glabel label 2 | .global \label 3 | \label: 4 | .endm 5 | .macro jlabel label 6 | .global \label 7 | \label: 8 | .endm 9 | 10 | .macro .def # 11 | .endm 12 | 13 | .macro move a, b 14 | addu \a, \b, $zero 15 | .endm 16 | -------------------------------------------------------------------------------- /include/macros.h: -------------------------------------------------------------------------------- 1 | #define SQ(x) ((x) * (x)) 2 | #define ABS(x) ((x) >= 0 ? (x) : -(x)) 3 | #define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) 4 | #define DECR(x) ((x) == 0 ? 0 : --(x)) 5 | 6 | #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) 7 | #define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) 8 | #define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) 9 | 10 | #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) 11 | #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) 12 | -------------------------------------------------------------------------------- /include/psyq/abs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:abs.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _ABS_H 9 | #define _ABS_H 10 | 11 | #ifndef ABS 12 | #define ABS(x) (((x) >= 0) ? (x) : (-(x))) 13 | #endif /* abs */ 14 | 15 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 16 | defined(c_plusplus) 17 | extern "C" { 18 | #endif 19 | extern int abs(int); 20 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 21 | defined(c_plusplus) 22 | } 23 | #endif 24 | 25 | #endif /* _ABS_H */ 26 | -------------------------------------------------------------------------------- /include/psyq/asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:asm.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | #ifndef _ASM_H 8 | #define _ASM_H 9 | 10 | #define R0 $0 11 | #define R1 $1 12 | #define R2 $2 13 | #define R3 $3 14 | #define R4 $4 15 | #define R5 $5 16 | #define R6 $6 17 | #define R7 $7 18 | #define R8 $8 19 | #define R9 $9 20 | #define R10 $10 21 | #define R11 $11 22 | #define R12 $12 23 | #define R13 $13 24 | #define R14 $14 25 | #define R15 $15 26 | #define R16 $16 27 | #define R17 $17 28 | #define R18 $18 29 | #define R19 $19 30 | #define R20 $20 31 | #define R21 $21 32 | #define R22 $22 33 | #define R23 $23 34 | #define R24 $24 35 | #define R25 $25 36 | #define R26 $26 37 | #define R27 $27 38 | #define R28 $28 39 | #define R29 $29 40 | #define R30 $30 41 | #define R31 $31 42 | 43 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 44 | defined(__cplusplus) || defined(c_plusplus) 45 | #else 46 | #define zero $0 /* wired zero */ 47 | #define AT $1 /* assembler temp */ 48 | #define v0 $2 /* return value */ 49 | #define v1 $3 50 | #define a0 $4 /* argument registers */ 51 | #define a1 $5 52 | #define a2 $6 53 | #define a3 $7 54 | #define t0 $8 /* caller saved */ 55 | #define t1 $9 56 | #define t2 $10 57 | #define t3 $11 58 | #define t4 $12 59 | #define t5 $13 60 | #define t6 $14 61 | #define t7 $15 62 | #define s0 $16 /* callee saved */ 63 | #define s1 $17 64 | #define s2 $18 65 | #define s3 $19 66 | #define s4 $20 67 | #define s5 $21 68 | #define s6 $22 69 | #define s7 $23 70 | #define t8 $24 /* code generator */ 71 | #define t9 $25 72 | #define k0 $26 /* kernel temporary */ 73 | #define k1 $27 74 | #define gp $28 /* global pointer */ 75 | #define sp $29 /* stack pointer */ 76 | #define fp $30 /* frame pointer */ 77 | #define ra $31 /* return address */ 78 | #endif 79 | 80 | /* register offset */ 81 | #define R_R0 0 82 | #define R_R1 1 83 | #define R_R2 2 84 | #define R_R3 3 85 | #define R_R4 4 86 | #define R_R5 5 87 | #define R_R6 6 88 | #define R_R7 7 89 | #define R_R8 8 90 | #define R_R9 9 91 | #define R_R10 10 92 | #define R_R11 11 93 | #define R_R12 12 94 | #define R_R13 13 95 | #define R_R14 14 96 | #define R_R15 15 97 | #define R_R16 16 98 | #define R_R17 17 99 | #define R_R18 18 100 | #define R_R19 19 101 | #define R_R20 20 102 | #define R_R21 21 103 | #define R_R22 22 104 | #define R_R23 23 105 | #define R_R24 24 106 | #define R_R25 25 107 | #define R_R26 26 108 | #define R_R27 27 109 | #define R_R28 28 110 | #define R_R29 29 111 | #define R_R30 30 112 | #define R_R31 31 113 | #define R_EPC 32 114 | #define R_MDHI 33 115 | #define R_MDLO 34 116 | #define R_SR 35 117 | #define R_CAUSE 36 118 | #define NREGS 40 119 | 120 | /* 121 | * compiler defined bindings 122 | */ 123 | #define R_ZERO R_R0 124 | #define R_AT R_R1 125 | #define R_V0 R_R2 126 | #define R_V1 R_R3 127 | #define R_A0 R_R4 128 | #define R_A1 R_R5 129 | #define R_A2 R_R6 130 | #define R_A3 R_R7 131 | #define R_T0 R_R8 132 | #define R_T1 R_R9 133 | #define R_T2 R_R10 134 | #define R_T3 R_R11 135 | #define R_T4 R_R12 136 | #define R_T5 R_R13 137 | #define R_T6 R_R14 138 | #define R_T7 R_R15 139 | #define R_S0 R_R16 140 | #define R_S1 R_R17 141 | #define R_S2 R_R18 142 | #define R_S3 R_R19 143 | #define R_S4 R_R20 144 | #define R_S5 R_R21 145 | #define R_S6 R_R22 146 | #define R_S7 R_R23 147 | #define R_T8 R_R24 148 | #define R_T9 R_R25 149 | #define R_K0 R_R26 150 | #define R_K1 R_R27 151 | #define R_GP R_R28 152 | #define R_SP R_R29 153 | #define R_FP R_R30 154 | #define R_RA R_R31 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /include/psyq/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId$ 3 | */ 4 | /* 5 | * File:assert.h 6 | */ 7 | 8 | #ifndef _ASSERT_H 9 | #define _ASSERT_H 10 | 11 | #ifdef NDEBUG 12 | 13 | #define _assert(x) 14 | #define assert(x) 15 | 16 | #else 17 | 18 | #define _assert(x) \ 19 | { \ 20 | if (!(x)) { \ 21 | printf("Assertion failed: file \"%s\", line %d\n", __FILE__, \ 22 | __LINE__); \ 23 | exit(1); \ 24 | } \ 25 | } 26 | #define assert(x) _assert(x) 27 | 28 | #endif 29 | 30 | #endif /* _ASSERT_H */ 31 | -------------------------------------------------------------------------------- /include/psyq/autopad.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/autopad.h -------------------------------------------------------------------------------- /include/psyq/convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:convert.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | #ifndef _CONVERT_H 8 | #define _CONVERT_H 9 | 10 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 11 | defined(c_plusplus) 12 | extern "C" { 13 | #endif 14 | extern int atoi(char*); 15 | extern long atol(char*); 16 | extern long strtol(char*, char**, int); 17 | extern unsigned long strtoul(char*, char**, int); 18 | extern long labs(long); 19 | 20 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 21 | defined(c_plusplus) 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/psyq/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:ctype.h 3 | * character handling macro definitions 4 | */ 5 | /* 6 | * $PSLibId$ 7 | */ 8 | 9 | #ifndef _CTYPE_H 10 | #define _CTYPE_H 11 | 12 | #define _U 0x01 /* upper case letter */ 13 | #define _L 0x02 /* lower case letter */ 14 | #define _N 0x04 /* digit */ 15 | #define _S \ 16 | 0x08 /* space, tab, newline, vertical tab, formfeed, or \ 17 | carriage return */ 18 | #define _P 0x10 /* punctuation character */ 19 | #define _C 0x20 /* control character or delete */ 20 | #define _X 0x40 /* hexadecimal digit [0-9a-fA-F]*/ 21 | #define _B 0x80 /* blank (space) */ 22 | 23 | extern char _ctype_[]; 24 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 25 | defined(c_plusplus) 26 | extern "C" { 27 | #endif 28 | extern char toupper(char); 29 | extern char tolower(char); 30 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 31 | defined(c_plusplus) 32 | } 33 | #endif 34 | 35 | #define isalpha(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_U | _L)) 36 | #define isupper(c) ((_ctype_ + 1)[(unsigned char)(c)] & _U) 37 | #define islower(c) ((_ctype_ + 1)[(unsigned char)(c)] & _L) 38 | #define isdigit(c) ((_ctype_ + 1)[(unsigned char)(c)] & _N) 39 | #define isxdigit(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_X | _N)) 40 | #define isspace(c) ((_ctype_ + 1)[(unsigned char)(c)] & _S) 41 | #define ispunct(c) ((_ctype_ + 1)[(unsigned char)(c)] & _P) 42 | #define isalnum(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_U | _L | _N)) 43 | #define isprint(c) \ 44 | ((_ctype_ + 1)[(unsigned char)(c)] & (_P | _U | _L | _N | _B)) 45 | #define isgraph(c) ((_ctype_ + 1)[(unsigned char)(c)] & (_P | _U | _L | _N)) 46 | #define iscntrl(c) ((_ctype_ + 1)[(unsigned char)(c)] & _C) 47 | #define isascii(c) ((unsigned)(c) <= 0x7f) 48 | #define toascii(c) ((unsigned char)(c) & 0x7f) 49 | #define _toupper(c) ((unsigned char)(c) - 'a' + 'A') 50 | #define _tolower(c) ((unsigned char)(c) - 'A' + 'a') 51 | 52 | #endif _CTYPE_H 53 | -------------------------------------------------------------------------------- /include/psyq/fs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:fs.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _FS_H 9 | #define _FS_H 10 | 11 | #define EXSTKSZ 1024 12 | 13 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 14 | defined(__cplusplus) || defined(c_plusplus) 15 | /* device table */ 16 | struct device_table { 17 | char* dt_string; /* device name */ 18 | int (*dt_init)(); /* device init routine */ 19 | int (*dt_open)(); /* device open routine */ 20 | int (*dt_strategy)(); /* device strategy routine, returns cnt */ 21 | int (*dt_close)(); /* device close routine */ 22 | int (*dt_ioctl)(); /* device ioctl routine */ 23 | int dt_type; /* device "type" */ 24 | int dt_fs; /* file system type */ 25 | char* dt_desc; /* device description */ 26 | }; 27 | #endif 28 | 29 | /* device types */ 30 | #define DTTYPE_CHAR 0x1 /* character device */ 31 | #define DTTYPE_CONS 0x2 /* can be console */ 32 | #define DTTYPE_BLOCK 0x4 /* block device */ 33 | #define DTTYPE_RAW 0x8 /* raw device that uses fs switch */ 34 | 35 | /* File structure types */ 36 | #define DTFS_NONE 0 /* no file structure on device */ 37 | #define DTFS_BFS 1 /* bfs protocol */ 38 | #define DTFS_DVH 2 /* disk volume header */ 39 | #define DTFS_TPD 3 /* boot tape directory */ 40 | #define DTFS_NCP 4 /* Network console protocol */ 41 | #define DTFS_BSD42 5 /* 4.2 BSD file system */ 42 | #define DTFS_SYSV 6 /* System V file system */ 43 | #define DTFS_BOOTP 7 /* bootp protocol */ 44 | #define DTFS_EFS 8 /* sgi extent file system */ 45 | #define DTFS_AUTO -1 /* determined from partition table */ 46 | 47 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 48 | defined(__cplusplus) || defined(c_plusplus) 49 | struct fs_table { 50 | int (*fs_init)(); /* fs init routine */ 51 | int (*fs_open)(); /* fs open routine */ 52 | int (*fs_read)(); /* fs read routine, returns count */ 53 | int (*fs_write)(); /* fs write routine, return count */ 54 | int (*fs_ioctl)(); /* fs ioctl routine */ 55 | int (*fs_close)(); /* fs close routine */ 56 | }; 57 | #endif 58 | 59 | /* character device flags */ 60 | #define DB_RAW 0x1 /* don't interpret special chars */ 61 | #define DB_STOPPED 0x2 /* stop output */ 62 | 63 | /* character device buffer */ 64 | #define CBUFSIZE 1024 65 | 66 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 67 | defined(__cplusplus) || defined(c_plusplus) 68 | struct device_buf { 69 | int db_flags; /* character device flags */ 70 | char* db_in; /* pts at next free char */ 71 | char* db_out; /* pts at next filled char */ 72 | char db_buf[CBUFSIZE]; /* circular buffer for input */ 73 | }; 74 | #endif 75 | 76 | /* circular buffer functions */ 77 | #define CIRC_EMPTY(x) ((x)->db_in == (x)->db_out) 78 | #define CIRC_FLUSH(x) ((x)->db_in = (x)->db_out = (x)->db_buf) 79 | #define CIRC_STOPPED(x) ((x)->db_flags & DB_STOPPED) 80 | 81 | #define IOB_INODE 316 82 | #define IOB_FS 8196 83 | 84 | /* io block */ 85 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 86 | defined(__cplusplus) || defined(c_plusplus) 87 | struct iob { 88 | int i_flgs; /* see F_ below */ 89 | int i_ctlr; /* controller board */ 90 | int i_unit; /* pseudo device unit */ 91 | int i_part; /* disk partition */ 92 | char* i_ma; /* memory address of i/o buffer */ 93 | int i_cc; /* character count of transfer */ 94 | off_t i_offset; /* seek offset in file */ 95 | daddr_t i_bn; /* 1st block # of next read */ 96 | int i_fstype; /* file system type */ 97 | int i_errno; /* error # return */ 98 | unsigned int i_devaddr; /* csr address */ 99 | struct device_table* i_dp; /* pointer into device_table */ 100 | char* i_buf; /* i/o buffer for blk devs */ 101 | #if 0 102 | char i_ino_dir[IOB_INODE]; /* inode or disk/tape directory */ 103 | char i_fs_tape[IOB_FS]; /* file system or tape header */ 104 | #endif 105 | }; 106 | #endif 107 | 108 | #ifndef NULL 109 | #define NULL 0 110 | #endif 111 | 112 | /* file flags */ 113 | #define F_READ 0x0001 /* file opened for reading */ 114 | #define F_WRITE 0x0002 /* file opened for writing */ 115 | #define F_NBLOCK 0x0004 /* non-blocking io */ 116 | #define F_SCAN 0x0008 /* device should be scanned */ 117 | 118 | /* Request codes */ 119 | #define READ 1 120 | #define WRITE 2 121 | 122 | #define DEVIOCTL(io, cmd, arg) (*(io)->i_dp->dt_ioctl)(io, cmd, arg) 123 | #define DEVREAD(io) (*(io)->i_dp->dt_strategy)(io, READ) 124 | #define DEVWRITE(io) (*(io)->i_dp->dt_strategy)(io, WRITE) 125 | 126 | #define NIOB 4 /* max number of open files */ 127 | #define NBUF 4 /* buffer for iob */ 128 | 129 | #ifdef DEBUG 130 | #define ASSERT(EX) \ 131 | if (!(EX)) \ 132 | assfail("EX", __FILE__, __LINE__) 133 | #else 134 | #define ASSERT(x) 135 | #endif DEBUG 136 | 137 | #endif /* _FS_H */ 138 | -------------------------------------------------------------------------------- /include/psyq/gtemac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId: Run-time Library Release 3.7$ 3 | */ 4 | /* 5 | * GTE inline functions(Simple) 6 | */ 7 | #define gte_RotTransPers(r1, r2, r3, r4, r5) \ 8 | { \ 9 | gte_ldv0(r1); \ 10 | gte_rtps(); \ 11 | gte_stsxy(r2); \ 12 | gte_stdp(r3); \ 13 | gte_stflg(r4); \ 14 | gte_stszotz(r5); \ 15 | } 16 | 17 | #define gte_RotTransPers3(r1, r2, r3, r4, r5, r6, r7, r8, r9) \ 18 | { \ 19 | gte_ldv3(r1, r2, r3); \ 20 | gte_rtpt(); \ 21 | gte_stsxy3(r4, r5, r6); \ 22 | gte_stdp(r7); \ 23 | gte_stflg(r8); \ 24 | gte_stszotz(r9); \ 25 | } 26 | 27 | #define gte_RotTrans(r1, r2, r3) \ 28 | { \ 29 | gte_ldv0(r1); \ 30 | gte_rt(); \ 31 | gte_stlvnl(r2); \ 32 | gte_stflg(r3); \ 33 | } 34 | 35 | #define gte_LocalLight(r1, r2) \ 36 | { \ 37 | gte_ldv0(r1); \ 38 | gte_ll(); \ 39 | gte_stlvl(r2); \ 40 | } 41 | 42 | #define gte_LightColor(r1, r2) \ 43 | { \ 44 | gte_ldlvl(r1); \ 45 | gte_lc(); \ 46 | gte_stlvl(r2); \ 47 | } 48 | 49 | #define gte_DpqColorLight(r1, r2, r3, r4) \ 50 | { \ 51 | gte_ldlvl(r1); \ 52 | gte_ldrgb(r2); \ 53 | gte_lddp(r3); \ 54 | gte_dpcl(); \ 55 | gte_strgb(r4); \ 56 | } 57 | 58 | #define gte_DpqColor(r1, r2, r3) \ 59 | { \ 60 | gte_ldrgb(r1); \ 61 | gte_lddp(r2); \ 62 | gte_dpcs(); \ 63 | gte_strgb(r3); \ 64 | } 65 | 66 | #define gte_DpqColor3(r1, r2, r3, r4, r5, r6, r7) \ 67 | { \ 68 | gte_ldrgb3(r1, r2, r3); \ 69 | gte_lddp(r4); \ 70 | gte_dpct(); \ 71 | gte_strgb3(r5, r6, r7); \ 72 | } 73 | 74 | #define gte_Intpl(r1, r2, r3) \ 75 | { \ 76 | gte_ldlvl(r1); \ 77 | gte_lddp(r2); \ 78 | gte_intpl(); \ 79 | gte_strgb(r3); \ 80 | } 81 | 82 | #define gte_Square12(r1, r2) \ 83 | { \ 84 | gte_ldlvl(r1); \ 85 | gte_sqr12(); \ 86 | gte_stlvnl(r2); \ 87 | } 88 | 89 | #define gte_Square0(r1, r2) \ 90 | { \ 91 | gte_ldlvl(r1); \ 92 | gte_sqr0(); \ 93 | gte_stlvnl(r2); \ 94 | } 95 | 96 | #define gte_NormalColor(r1, r2) \ 97 | { \ 98 | gte_ldv0(r1); \ 99 | gte_ncs(); \ 100 | gte_strgb(r2); \ 101 | } 102 | 103 | #define gte_NormalColor3(r1, r2, r3, r4, r5, r6) \ 104 | { \ 105 | gte_ldv3(r1, r2, r3); \ 106 | gte_nct(); \ 107 | gte_strgb3(r4, r5, r6); \ 108 | } 109 | 110 | #define gte_NormalColorDpq(r1, r2, r3, r4) \ 111 | { \ 112 | gte_ldv0(r1); \ 113 | gte_ldrgb(r2); \ 114 | gte_lddp(r3); \ 115 | gte_ncds(); \ 116 | gte_strgb(r4); \ 117 | } 118 | 119 | #define gte_NormalColorDpq3(r1, r2, r3, r4, r5, r6, r7, r8) \ 120 | { \ 121 | gte_ldv3(r1, r2, r3); \ 122 | gte_ldrgb(r4); \ 123 | gte_lddp(r5); \ 124 | gte_ncdt(); \ 125 | gte_strgb3(r6, r7, r8); \ 126 | } 127 | 128 | #define gte_NormalColorCol(r1, r2, r3) \ 129 | { \ 130 | gte_ldv0(r1); \ 131 | gte_ldrgb(r2); \ 132 | gte_nccs(); \ 133 | gte_strgb(r3); \ 134 | } 135 | 136 | #define gte_NormalColorCol3(r1, r2, r3, r4, r5, r6, r7) \ 137 | { \ 138 | gte_ldv3(r1, r2, r3); \ 139 | gte_ldrgb(r4); \ 140 | gte_ncct(); \ 141 | gte_strgb3(r5, r6, r7); \ 142 | } 143 | 144 | #define gte_ColorDpq(r1, r2, r3, r4) \ 145 | { \ 146 | gte_ldlvl(r1); \ 147 | gte_ldrgb(r2); \ 148 | gte_lddp(r3); \ 149 | gte_cdp(); \ 150 | gte_strgb(r4); \ 151 | } 152 | 153 | #define gte_ColorCol(r1, r2, r3) \ 154 | { \ 155 | gte_ldlvl(r1); \ 156 | gte_ldrgb(r2); \ 157 | gte_cc(); \ 158 | gte_strgb(r3); \ 159 | } 160 | 161 | #define gte_NormalClip(r1, r2, r3, r4) \ 162 | { \ 163 | gte_ldsxy3(r1, r2, r3); \ 164 | gte_nclip(); \ 165 | gte_stopz(r4); \ 166 | } 167 | 168 | #define gte_AverageZ3(r1, r2, r3, r4) \ 169 | { \ 170 | gte_ldsz3(r1, r2, r3); \ 171 | gte_avsz3(); \ 172 | gte_stotz(r4); \ 173 | } 174 | 175 | #define gte_AverageZ4(r1, r2, r3, r4, r5) \ 176 | { \ 177 | gte_ldsz4(r1, r2, r3, r4); \ 178 | gte_avsz4(); \ 179 | gte_stotz(r5); \ 180 | } 181 | 182 | #define gte_OuterProduct12(r1, r2, r3) \ 183 | { \ 184 | gte_ldopv1(r1); \ 185 | gte_ldopv2(r2); \ 186 | gte_op12(); \ 187 | gte_stlvnl(r3); \ 188 | } 189 | 190 | #define gte_OuterProduct0(r1, r2, r3) \ 191 | { \ 192 | gte_ldopv1(r1); \ 193 | gte_ldopv2(r2); \ 194 | gte_op0(); \ 195 | gte_stlvnl(r3); \ 196 | } 197 | 198 | #define gte_OuterProduct12SVL(r1, r2, r3) \ 199 | { \ 200 | gte_ldopv1SV(r1); \ 201 | gte_ldopv2SV(r2); \ 202 | gte_op12(); \ 203 | gte_stlvnl(r3); \ 204 | } 205 | 206 | #define gte_OuterProduct0SVL(r1, r2, r3) \ 207 | { \ 208 | gte_ldopv1SV(r1); \ 209 | gte_ldopv2SV(r2); \ 210 | gte_op0(); \ 211 | gte_stlvnl(r3); \ 212 | } 213 | 214 | #define gte_OuterProduct12SV(r1, r2, r3) \ 215 | { \ 216 | gte_ldopv1SV(r1); \ 217 | gte_ldopv2SV(r2); \ 218 | gte_op12(); \ 219 | gte_stsv(r3); \ 220 | } 221 | 222 | #define gte_OuterProduct0SV(r1, r2, r3) \ 223 | { \ 224 | gte_ldopv1SV(r1); \ 225 | gte_ldopv2SV(r2); \ 226 | gte_op0(); \ 227 | gte_stsv(r3); \ 228 | } 229 | 230 | #define gte_Lzc(r1, r2) \ 231 | { \ 232 | gte_ldlzc(r1); \ 233 | gte_nop(); \ 234 | gte_nop(); \ 235 | gte_stlzc(r2); \ 236 | } 237 | 238 | /* 239 | * GTE inline functions(Combination) 240 | * 4 vertices functions can't be replaced by equivalent macros 241 | * because they use OR of flags after rtpt & rtps 242 | * Please write directry in your program. 243 | */ 244 | #define gte_RotAverage3(r1, r2, r3, r4, r5, r6, r7, r8, r9) \ 245 | { \ 246 | gte_ldv3(r1, r2, r3); \ 247 | gte_rtpt(); \ 248 | gte_stsxy3(r4, r5, r6); \ 249 | gte_stdp(r7); \ 250 | gte_stflg(r8); \ 251 | gte_avsz3(); \ 252 | gte_stotz(r9); \ 253 | } 254 | 255 | #define gte_RotNclip3(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) \ 256 | { \ 257 | gte_ldv3(r1, r2, r3); \ 258 | gte_rtpt(); \ 259 | gte_stflg(r9); \ 260 | gte_nclip(); \ 261 | gte_stopz(r10); \ 262 | gte_stsxy3(r4, r5, r6); \ 263 | gte_stdp(r7); \ 264 | gte_stszotz(r8); \ 265 | } 266 | 267 | #define gte_RotAverageNclip3(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) \ 268 | { \ 269 | gte_ldv3(r1, r2, r3); \ 270 | gte_rtpt(); \ 271 | gte_stflg(r9); \ 272 | gte_nclip(); \ 273 | gte_stopz(r10); \ 274 | gte_stsxy3(r4, r5, r6); \ 275 | gte_stdp(r7); \ 276 | gte_avsz3(); \ 277 | gte_stotz(r8); \ 278 | } 279 | 280 | #define gte_RotColorDpq(r1, r2, r3, r4, r5, r6, r7) \ 281 | { \ 282 | gte_ldv0(r1); \ 283 | gte_rtps(); \ 284 | gte_stsxy(r4); \ 285 | gte_stflg(r6); \ 286 | gte_ldv0(r2); \ 287 | gte_ldrgb(r3); \ 288 | gte_ncds(); \ 289 | gte_strgb(r5); \ 290 | gte_stszotz(r7); \ 291 | } 292 | 293 | #define gte_RotColorDpq3( \ 294 | r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15) \ 295 | { \ 296 | gte_ldv3(r1, r2, r3); \ 297 | gte_rtpt(); \ 298 | gte_stsxy3(r8, r9, r10); \ 299 | gte_stflg(r14); \ 300 | gte_ldv3(r4, r5, r6); \ 301 | gte_ldrgb(r7); \ 302 | gte_ncdt(); \ 303 | gte_strgb3(r11, r12, r13); \ 304 | gte_stszotz(r15); \ 305 | } 306 | 307 | #define gte_RotAverageNclipColorDpq3( \ 308 | r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16) \ 309 | { \ 310 | gte_ldv3(r1, r2, r3); \ 311 | gte_rtpt(); \ 312 | gte_stflg(r15); \ 313 | gte_nclip(); \ 314 | gte_stopz(r16); \ 315 | gte_ldv3(r4, r5, r6); \ 316 | gte_ldrgb(r7); \ 317 | gte_ncdt(); \ 318 | gte_stsxy3(r8, r9, r10); \ 319 | gte_strgb3(r11, r12, r13); \ 320 | gte_avsz3(); \ 321 | gte_stotz(r14); \ 322 | } 323 | 324 | #define gte_RotAverageNclipColorCol3( \ 325 | r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16) \ 326 | { \ 327 | gte_ldv3(r1, r2, r3); \ 328 | gte_rtpt(); \ 329 | gte_stflg(r15); \ 330 | gte_nclip(); \ 331 | gte_stopz(r16); \ 332 | gte_ldv3(r4, r5, r6); \ 333 | gte_ldrgb(r7); \ 334 | gte_ncct(); \ 335 | gte_stsxy3(r8, r9, r10); \ 336 | gte_strgb3(r11, r12, r13); \ 337 | gte_avsz3(); \ 338 | gte_stotz(r14); \ 339 | } 340 | 341 | #define gte_LoadAverage12(r1, r2, r3, r4, r5) \ 342 | { \ 343 | gte_lddp(r3); \ 344 | gte_ldlvl(r1); \ 345 | gte_gpf12(); \ 346 | gte_lddp(r4); \ 347 | gte_ldlvl(r2); \ 348 | gte_gpl12(); \ 349 | gte_stlvl(r5); \ 350 | } 351 | 352 | #define gte_LoadAverage0(r1, r2, r3, r4, r5) \ 353 | { \ 354 | gte_lddp(r3); \ 355 | gte_ldlvl(r1); \ 356 | gte_gpf0(); \ 357 | gte_lddp(r4); \ 358 | gte_ldlvl(r2); \ 359 | gte_gpl0(); \ 360 | gte_stlvl(r5); \ 361 | } 362 | 363 | #define gte_LoadAverageShort12(r1, r2, r3, r4, r5) \ 364 | { \ 365 | gte_lddp(r3); \ 366 | gte_ldsv(r1); \ 367 | gte_gpf12(); \ 368 | gte_lddp(r4); \ 369 | gte_ldsv(r2); \ 370 | gte_gpl12(); \ 371 | gte_stsv(r5); \ 372 | } 373 | 374 | #define gte_LoadAverageShort0(r1, r2, r3, r4, r5) \ 375 | { \ 376 | gte_lddp(r3); \ 377 | gte_ldsv(r1); \ 378 | gte_gpf0(); \ 379 | gte_lddp(r4); \ 380 | gte_ldsv(r2); \ 381 | gte_gpl0(); \ 382 | gte_stsv(r5); \ 383 | } 384 | 385 | #define gte_LoadAverageByte(r1, r2, r3, r4, r5) \ 386 | { \ 387 | gte_lddp(r3); \ 388 | gte_ldbv(r1); \ 389 | gte_gpf12(); \ 390 | gte_lddp(r4); \ 391 | gte_ldbv(r2); \ 392 | gte_gpl12(); \ 393 | gte_stbv(r5); \ 394 | } 395 | 396 | #define gte_LoadAverageCol(r1, r2, r3, r4, r5) \ 397 | { \ 398 | gte_lddp(r3); \ 399 | gte_ldcv(r1); \ 400 | gte_gpf12(); \ 401 | gte_lddp(r4); \ 402 | gte_ldcv(r2); \ 403 | gte_gpl12(); \ 404 | gte_stcv(r5); \ 405 | } 406 | 407 | /* 408 | * 409 | */ 410 | #define gte_MulMatrix0(r1, r2, r3) \ 411 | { \ 412 | gte_SetRotMatrix(r1); \ 413 | gte_ldclmv(r2); \ 414 | gte_rtir(); \ 415 | gte_stclmv(r3); \ 416 | gte_ldclmv((char*)r2 + 2); \ 417 | gte_rtir(); \ 418 | gte_stclmv((char*)r3 + 2); \ 419 | gte_ldclmv((char*)r2 + 4); \ 420 | gte_rtir(); \ 421 | gte_stclmv((char*)r3 + 4); \ 422 | } 423 | 424 | #define gte_ApplyMatrix(r1, r2, r3) \ 425 | { \ 426 | gte_SetRotMatrix(r1); \ 427 | gte_ldv0(r2); \ 428 | gte_rtv0(); \ 429 | gte_stlvnl(r3); \ 430 | } 431 | 432 | #define gte_ApplyMatrixSV(r1, r2, r3) \ 433 | { \ 434 | gte_SetRotMatrix(r1); \ 435 | gte_ldv0(r2); \ 436 | gte_rtv0(); \ 437 | gte_stsv(r3); \ 438 | } 439 | 440 | #define gte_CompMatrix(r1, r2, r3) \ 441 | { \ 442 | gte_MulMatrix0(r1, r2, r3); \ 443 | gte_SetTransMatrix(r1); \ 444 | gte_ldlv0((char*)r2 + 20); \ 445 | gte_rt(); \ 446 | gte_stlvnl((char*)r3 + 20); \ 447 | } 448 | 449 | #define gte_ApplyRotMatrix(r1, r2) \ 450 | { \ 451 | gte_ldv0(r1); \ 452 | gte_rtv0(); \ 453 | gte_stlvnl(r2); \ 454 | } 455 | -------------------------------------------------------------------------------- /include/psyq/gtenom.h: -------------------------------------------------------------------------------- 1 | ; 2 | ; 3 | $PSLibId$; 4 | 5 | ; 6 | ; 7 | gtenom.h; 8 | Copyright(C) 1995, 1996, 1997 Sony Computer Entertainment Inc.; 9 | All rights reserved.; 10 | 11 | read_sz_fifo3 macro reg1, reg2, reg3 mfc2 reg1, r17 mfc2 reg2, r18 mfc2 reg3, 12 | r19 nop endm 13 | 14 | read_sz_fifo4 macro reg1, 15 | reg2, reg3, reg4 mfc2 reg1, r16 mfc2 reg2, r17 mfc2 reg3, r18 mfc2 reg4, 16 | r19 nop endm 17 | 18 | read_szx macro reg1 mfc2 reg1, 19 | r16 nop endm 20 | 21 | read_sz0 macro reg1 mfc2 reg1, 22 | r17 nop endm 23 | 24 | read_sz1 macro reg1 mfc2 reg1, 25 | r18 nop endm 26 | 27 | read_sz2 macro reg1 mfc2 reg1, 28 | r19 nop endm 29 | 30 | read_sxsy_fifo3 macro reg1, 31 | reg2, reg3 mfc2 reg1, r12 mfc2 reg2, r13 mfc2 reg3, 32 | r14 nop endm 33 | 34 | read_sxsy0 macro reg1 mfc2 reg1, 35 | r12 nop endm 36 | 37 | read_sxsy1 macro reg1 mfc2 reg1, 38 | r13 nop endm 39 | 40 | read_sxsy2 macro reg1 mfc2 reg1, 41 | r14 nop endm 42 | 43 | read_rgb_fifo macro reg1, 44 | reg2, reg3 mfc2 reg1, r20 mfc2 reg2, r21 mfc2 reg3, 45 | r22 nop endm 46 | 47 | read_rgb0 macro reg1 mfc2 reg1, 48 | r20 nop endm 49 | 50 | read_rgb1 macro reg1 mfc2 reg1, 51 | r21 nop endm 52 | 53 | read_rgb2 macro reg1 mfc2 reg1, 54 | r22 nop endm 55 | 56 | read_flag macro reg1 cfc2 reg1, 57 | r31 nop endm 58 | 59 | read_p macro reg1 mfc2 reg1, 60 | r8 nop endm 61 | 62 | read_otz macro reg1 mfc2 reg1, 63 | r7 nop endm 64 | 65 | read_opz macro reg1 mfc2 reg1, 66 | r24 nop endm 67 | 68 | read_mt macro reg1, 69 | reg2, reg3 mfc2 reg1, r25 mfc2 reg2, r26 mfc2 reg3, 70 | r27 nop endm 71 | 72 | store_sxsy_fifo3 macro reg1, 73 | reg2, reg3 swc2 r12, (reg1)swc2 r13, (reg2)swc2 r14, 74 | (reg3)nop endm 75 | 76 | store_sxsy0 macro reg1 swc2 r12, 77 | (reg1)nop endm 78 | 79 | store_sxsy1 macro reg1 swc2 r13, 80 | (reg1)nop endm 81 | 82 | store_sxsy2 macro reg1 swc2 r14, 83 | (reg1)nop endm 84 | 85 | store_rgb_fifo macro reg1, 86 | reg2, reg3 swc2 r20, (reg1)swc2 r21, (reg2)swc2 r22, 87 | (reg3)nop endm 88 | 89 | store_rgb0 macro reg1 swc2 r20, 90 | (reg1)nop endm 91 | 92 | store_rgb1 macro reg1 swc2 r21, 93 | (reg1)nop endm 94 | 95 | store_rgb2 macro reg1 swc2 r22, 96 | (reg1)nop endm 97 | 98 | set_trans_matrix macro reg1, 99 | reg2, reg3 ctc2 reg1, r5 ctc2 reg2, r6 ctc2 reg3, r7 nop endm 100 | -------------------------------------------------------------------------------- /include/psyq/gtereg.h: -------------------------------------------------------------------------------- 1 | ; 2 | ; 3 | $PSLibId$; 4 | 5 | ; 6 | ; 7 | gtereg.h; 8 | Copyright(C) 1995, 1996, 1997 Sony Computer Entertainment Inc.; 9 | All rights reserved.; 10 | 11 | ; 12 | ; 13 | GTE data registers; 14 | C2_VXY0 equs 15 | "r0" C2_VZ0 equs "r1" C2_VXY1 equs "r2" C2_VZ1 equs "r3" C2_VXY2 equs 16 | "r4" C2_VZ2 equs "r5" C2_RGB equs "r6" C2_OTZ equs "r7" 17 | 18 | C2_IR0 equs "r8" C2_IR1 equs "r9" C2_IR2 equs "r10" C2_IR3 equs 19 | "r11" C2_SXY0 equs "r12" C2_SXY1 equs "r13" C2_SXY2 equs "r14" C2_SXYP equs 20 | "r15" 21 | 22 | C2_SZ0 equs "r16" C2_SZ1 equs "r17" C2_SZ2 equs "r18" C2_SZ3 equs 23 | "r19" C2_RGB0 equs "r20" C2_RGB1 equs "r21" C2_RGB2 equs "r22" 24 | 25 | C2_MAC0 equs "r24" C2_MAC1 equs "r25" C2_MAC2 equs "r26" C2_MAC3 equs 26 | "r27" C2_IRGB equs "r28" C2_ORGB equs "r29" C2_LZCS equs "r30" C2_LZCR equs 27 | "r31" 28 | 29 | ; 30 | ; 31 | GTE control registers; 32 | C2_R11R12 equs 33 | "r0" C2_R13R21 equs "r1" C2_R22R23 equs "r2" C2_R31R32 equs "r3" C2_R33 equs 34 | "r4" C2_TRX equs "r5" C2_TRY equs "r6" C2_TRZ equs "r7" 35 | 36 | C2_L11L12 equs "r8" C2_L13L21 equs "r9" C2_L22L23 equs "r10" C2_L31L32 equs 37 | "r11" C2_L33 equs "r12" C2_RBK equs "r13" C2_GBK equs "r14" C2_BBK equs 38 | "r15" 39 | 40 | C2_LR1LR2 equs "r16" C2_LR3LG1 equs "r17" C2_LG2LG3 equs 41 | "r18" C2_LB1LB2 equs "r19" C2_LB3 equs "r20" C2_RFC equs "r21" C2_GFC equs 42 | "r22" C2_BFC equs "r23" 43 | 44 | C2_OFX equs "r24" C2_OFY equs "r25" C2_H equs "r26" C2_DQA equs 45 | "r27" C2_DQB equs "r28" C2_ZSF3 equs "r29" C2_ZSF4 equs "r30" C2_FLAG equs 46 | "r31" 47 | -------------------------------------------------------------------------------- /include/psyq/inline_a.h: -------------------------------------------------------------------------------- 1 | ; 2 | $PSLibId$; 3 | ; Macro definitions of DMPSX version 3 for Assembler programs 4 | ; 5 | inline_a.h; 6 | Copyright(C) 1996, Sony Computer Entertainment Inc.; 7 | All rights reserved.; 8 | 9 | ; 10 | ; 11 | GTE commands with 2 nops; 12 | nRTPS macro nop nop dw $0000007f endm 13 | 14 | nRTPT macro nop nop dw $000000bf endm 15 | 16 | nDCPL macro nop nop dw $00000dff endm 17 | 18 | nDPCS macro nop nop dw $00000e3f endm 19 | 20 | nDPCT macro nop nop dw $00000e7f endm 21 | 22 | nINTPL macro nop nop dw $00000ebf endm 23 | 24 | nNCS macro nop nop dw $00000f7f endm 25 | 26 | nNCT macro nop nop dw $00000fbf endm 27 | 28 | nNCDS macro nop nop dw $00000fff endm 29 | 30 | nNCDT macro nop nop dw $0000103f endm 31 | 32 | nNCCS macro nop nop dw $0000107f endm 33 | 34 | nNCCT macro nop nop dw $000010bf endm 35 | 36 | nCDP macro nop nop dw $000010ff endm 37 | 38 | nCC macro nop nop dw $0000113f endm 39 | 40 | nNCLIP macro nop nop dw $0000117f endm 41 | 42 | nAVSZ3 macro nop nop 43 | dw $000011bf endm 44 | 45 | nAVSZ4 macro nop 46 | nop dw $000011ff endm 47 | 48 | nMVMVA macro 49 | sf, 50 | mx, v, cv, 51 | lm nop nop dw $000013bf | sf << 25 | mx << 23 | v << 21 | cv << 19 | 52 | lm << 18 endm 53 | 54 | nSQR macro sf nop nop dw $000013ff | 55 | sf << 25 endm 56 | 57 | nOP macro sf nop nop dw $0000143f | 58 | sf << 25 endm 59 | 60 | nGPF macro sf nop nop dw $0000147f | 61 | sf << 25 endm 62 | 63 | nGPL macro sf nop nop dw $000014bf | 64 | sf << 25 endm 65 | 66 | ; 67 | ; 68 | GTE commands without nops; 69 | RTPS macro dw $0000007f endm 70 | 71 | RTPT macro dw $000000bf endm 72 | 73 | DCPL macro dw $00000dff endm 74 | 75 | DPCS macro dw $00000e3f endm 76 | 77 | DPCT macro dw $00000e7f endm 78 | 79 | INTPL macro dw $00000ebf endm 80 | 81 | NCS macro dw $00000f7f endm 82 | 83 | NCT macro dw $00000fbf endm 84 | 85 | NCDS macro dw $00000fff endm 86 | 87 | NCDT macro dw $0000103f endm 88 | 89 | NCCS macro dw $0000107f endm 90 | 91 | NCCT macro dw $000010bf endm 92 | 93 | CDP macro dw $000010ff endm 94 | 95 | CC macro dw $0000113f endm 96 | 97 | NCLIP macro dw $0000117f endm 98 | 99 | AVSZ3 macro dw $000011bf endm 100 | 101 | AVSZ4 macro dw 102 | $000011ff endm 103 | 104 | MVMVA macro 105 | sf, 106 | mx, v, cv, 107 | lm dw $000013bf | sf << 25 | mx << 23 | v << 21 | cv << 19 | 108 | lm << 18 endm 109 | 110 | SQR macro sf dw $000013ff | 111 | sf << 25 endm 112 | 113 | OP macro sf dw $0000143f | 114 | sf << 25 endm 115 | 116 | GPF macro sf dw $0000147f | 117 | sf << 25 endm 118 | 119 | GPL macro sf dw $000014bf | 120 | sf << 25 endm 121 | -------------------------------------------------------------------------------- /include/psyq/kernel.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/kernel.h -------------------------------------------------------------------------------- /include/psyq/libcd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/libcd.h -------------------------------------------------------------------------------- /include/psyq/libcomb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId$ 3 | */ 4 | /* 5 | * File:libcomb.h 6 | */ 7 | #ifndef _LIBCOMB_H_ 8 | #define _LIBCOMB_H_ 9 | 10 | /* status bits */ 11 | #define COMB_CTS 0x100 12 | #define COMB_DSR 0x80 13 | #define COMB_FE 0x20 14 | #define COMB_OE 0x10 15 | #define COMB_PERROR 0x8 16 | #define COMB_TXU 0x4 17 | #define COMB_RXRDY 0x2 18 | #define COMB_TXRDY 0x1 19 | 20 | /* control bits */ 21 | #define COMB_BIT_DTR 0x1 22 | #define COMB_BIT_RTS 0x2 23 | 24 | /* 25 | * Prototypes 26 | */ 27 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 28 | defined(c_plusplus) 29 | extern "C" { 30 | #endif 31 | 32 | extern void AddCOMB(void); 33 | extern void DelCOMB(void); 34 | extern void ChangeClearSIO(long); 35 | extern long _comb_control(unsigned long, unsigned long, unsigned long); 36 | 37 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 38 | defined(c_plusplus) 39 | } 40 | #endif 41 | #endif /*_LIBCOMB_H_*/ 42 | -------------------------------------------------------------------------------- /include/psyq/libds.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/libds.h -------------------------------------------------------------------------------- /include/psyq/libetc.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId$ */ 2 | #ifndef _LIBETC_H_ 3 | #define _LIBETC_H_ 4 | 5 | /* 6 | * (C) Copyright 1993/1994 Sony Corporation,Tokyo,Japan. All Rights Reserved 7 | * 8 | * libetc.h: Pad Interface 9 | */ 10 | extern int PadIdentifier; 11 | /* 12 | * PAD I/O (SIO Pad) 13 | */ 14 | #define PADLup (1 << 12) 15 | #define PADLdown (1 << 14) 16 | #define PADLleft (1 << 15) 17 | #define PADLright (1 << 13) 18 | #define PADRup (1 << 4) 19 | #define PADRdown (1 << 6) 20 | #define PADRleft (1 << 7) 21 | #define PADRright (1 << 5) 22 | #define PADi (1 << 9) 23 | #define PADj (1 << 10) 24 | #define PADk (1 << 8) 25 | #define PADl (1 << 3) 26 | #define PADm (1 << 1) 27 | #define PADn (1 << 2) 28 | #define PADo (1 << 0) 29 | #define PADh (1 << 11) 30 | #define PADL1 PADn 31 | #define PADL2 PADo 32 | #define PADR1 PADl 33 | #define PADR2 PADm 34 | #define PADstart PADh 35 | #define PADselect PADk 36 | 37 | #define MOUSEleft (1 << 3) 38 | #define MOUSEright (1 << 2) 39 | 40 | /* 41 | * PAD utility macro: _PAD(x,y) 42 | * x: controller ID (0 or 1) 43 | * y: PAD assign macro 44 | * 45 | * Example: _PAD(0,PADstart) ... PADstart of controller 1 46 | * _PAD(1,PADLup) ... PADLup of controller 2 47 | */ 48 | #define _PAD(x, y) ((y) << ((x) << 4)) 49 | 50 | /* scratch pad address 0x1f800000 - 0x1f800400 */ 51 | #define getScratchAddr(offset) ((u_long*)(0x1f800000 + offset * 4)) 52 | 53 | /* 54 | * Video Mode: NTSC/PAL 55 | */ 56 | #define MODE_NTSC 0 57 | #define MODE_PAL 1 58 | 59 | /* 60 | * Prototypes 61 | */ 62 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 63 | defined(c_plusplus) 64 | extern "C" { 65 | #endif 66 | int CheckCallback(void); 67 | void PadInit(int mode); 68 | int ResetCallback(void); 69 | int RestartCallback(void); 70 | int StopCallback(void); 71 | int VSync(int mode); 72 | int VSyncCallback(void (*f)()); 73 | long GetVideoMode(void); 74 | long SetVideoMode(long mode); 75 | u_long PadRead(int id); 76 | void PadStop(void); 77 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 78 | defined(c_plusplus) 79 | } 80 | #endif 81 | #endif /* _LIBETC_H_ */ 82 | -------------------------------------------------------------------------------- /include/psyq/libgpu.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId$ */ 2 | #ifndef _LIBGPU_H_ 3 | #define _LIBGPU_H_ 4 | /* 5 | * (C) Copyright 1993-1995 Sony Corporation,Tokyo,Japan. All Rights Reserved 6 | * 7 | * libgpu.h: Graphic Primitive Structures Database 8 | * 9 | * Primitive list: 10 | * 11 | * Name |Size*1|Shade |Vertex |Texture| Function 12 | * ---------+------+-------+-------+-------+------------------------ 13 | * POLY_F3 | 5 |Flat | 3 |OFF | Flat Triangle 14 | * POLY_FT3 | 8 |Flat | 3 |ON | Flat Textured Triangle 15 | * POLY_G3 | 7 |Gouraud| 3 |OFF | Gouraud Triangle 16 | * POLY_GT3 |10 |Gouraud| 3 |ON | Gouraud Textured Triangle 17 | * POLY_F4 | 6 |Flat | 4 |OFF | Flat Quadrangle 18 | * POLY_FT4 |10 |Flat | 4 |ON | Flat Textured Quadrangle 19 | * POLY_G4 | 9 |Gouraud| 4 |OFF | Gouraud Quadrangle 20 | * POLY_GT4 |12 |Gouraud| 4 |ON | Gouraud Textured Quadrangle 21 | * ---------+------+-------+-------+-------+------------------------ 22 | * LINE_F2 | 4 |Flat | 2 | - | unconnected Flat Line 23 | * LINE_G2 | 5 |Gouraud| 2 | - | unconnected Gouraud Line 24 | * LINE_F3 | 6 |Flat | 3 | - | 3-connected Flat Line 25 | * LINE_G3 | 8 |Gouraud| 3 | - | 3-connected Gouraud Line 26 | * LINE_F4 | 7 |Flat | 4 | - | 4-connected Flat Line 27 | * LINE_G4 |10 |Gouraud| 4 | - | 4-connected Gouraud Line 28 | * ---------+------+-------+-------+-------+------------------------ 29 | * SPRT | 5 |Flat | 1 |ON | free size Sprite 30 | * SPRT_16 | 4 |Flat | 1 |ON | 16x16 Sprite 31 | * SPRT_8 | 4 |Flat | 1 |ON | 8x8 Sprite 32 | * ---------+------+-------+-------+-------+------------------------ 33 | * TILE | 4 |Flat | 1 |OFF | free size Sprite 34 | * TILE_16 | 3 |Flat | 1 |OFF | 16x16 Sprite 35 | * TILE_8 | 3 |Flat | 1 |OFF | 8x8 Sprite 36 | * TILE_1 | 3 |Flat | 1 |OFF | 1x1 Sprite 37 | * ---------+------+-------+-------+-------+------------------------ 38 | * DR_TWIN | 3 | - | - | - | Texture Window 39 | * DR_AREA | 3 | - | - | - | Drawing Area 40 | * DR_OFFSET| 3 | - | - | - | Drawing Offset 41 | * DR_MODE | 3 | - | - | - | Drawing Mode 42 | * DR_ENV |16 | - | - | - | Drawing Environment 43 | * DR_MOVE | 6 | - | - | - | MoveImage 44 | * DR_LOAD |16 | - | - | - | LoadImage 45 | * DR_TPAGE | 2 | - | - | - | Drawing TPage 46 | * 47 | * *1: in long-word 48 | * 49 | * Texture Attributes: 50 | * abr: ambient rate 51 | * abr 0 1 2 3 52 | * ------------------------------------- 53 | * Front 0.5 1.0 0.5 -1.0 54 | * Back 0.5 1.0 1.0 1.0 55 | * 56 | * tp: texture mode 57 | * tp 0 1 2 58 | * ----------------------------- 59 | * depth 4bit 8bit 16bit 60 | * color CLUT CLUT DIRECT 61 | */ 62 | 63 | /* 64 | * Externals 65 | */ 66 | extern int (*GPU_printf)(); /* printf() object */ 67 | 68 | /* 69 | * Time-out Cycle 70 | */ 71 | #define WAIT_TIME 0x800000 72 | 73 | /* 74 | * General Macros 75 | */ 76 | #define limitRange(x, l, h) ((x) = ((x) < (l) ? (l) : (x) > (h) ? (h) : (x))) 77 | 78 | /* 79 | * Set/Add Vector/Rectangle Attributes 80 | */ 81 | #define setVector(v, _x, _y, _z) (v)->vx = _x, (v)->vy = _y, (v)->vz = _z 82 | 83 | #define applyVector(v, _x, _y, _z, op) \ 84 | (v)->vx op _x, (v)->vy op _y, (v)->vz op _z 85 | 86 | #define copyVector(v0, v1) \ 87 | (v0)->vx = (v1)->vx, (v0)->vy = (v1)->vy, (v0)->vz = (v1)->vz 88 | 89 | #define addVector(v0, v1) \ 90 | (v0)->vx += (v1)->vx, (v0)->vy += (v1)->vy, (v0)->vz += (v1)->vz 91 | 92 | #define dumpVector(str, v) \ 93 | GPU_printf("%s=(%d,%d,%d)\n", str, (v)->vx, (v)->vy, (v)->vz) 94 | 95 | #define dumpMatrix(x) \ 96 | GPU_printf("\t%5d,%5d,%5d\n", (x)->m[0][0], (x)->m[0][1], (x)->m[0][2]), \ 97 | GPU_printf( \ 98 | "\t%5d,%5d,%5d\n", (x)->m[1][0], (x)->m[1][1], (x)->m[1][2]), \ 99 | GPU_printf( \ 100 | "\t%5d,%5d,%5d\n", (x)->m[2][0], (x)->m[2][1], (x)->m[2][2]) 101 | 102 | #define setRECT(r, _x, _y, _w, _h) \ 103 | (r)->x = (_x), (r)->y = (_y), (r)->w = (_w), (r)->h = (_h) 104 | 105 | /* 106 | * Set Primitive Attributes 107 | */ 108 | #define setTPage(p, tp, abr, x, y) ((p)->tpage = GetTPage(tp, abr, x, y)) 109 | 110 | #define setClut(p, x, y) ((p)->clut = GetClut(x, y)) 111 | 112 | /* 113 | * Set Primitive Colors 114 | */ 115 | #define setRGB0(p, _r0, _g0, _b0) (p)->r0 = _r0, (p)->g0 = _g0, (p)->b0 = _b0 116 | 117 | #define setRGB1(p, _r1, _g1, _b1) (p)->r1 = _r1, (p)->g1 = _g1, (p)->b1 = _b1 118 | 119 | #define setRGB2(p, _r2, _g2, _b2) (p)->r2 = _r2, (p)->g2 = _g2, (p)->b2 = _b2 120 | 121 | #define setRGB3(p, _r3, _g3, _b3) (p)->r3 = _r3, (p)->g3 = _g3, (p)->b3 = _b3 122 | 123 | /* 124 | * Set Primitive Screen Points 125 | */ 126 | #define setXY0(p, _x0, _y0) (p)->x0 = (_x0), (p)->y0 = (_y0) 127 | 128 | #define setXY2(p, _x0, _y0, _x1, _y1) \ 129 | (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1) 130 | 131 | #define setXY3(p, _x0, _y0, _x1, _y1, _x2, _y2) \ 132 | (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1), \ 133 | (p)->x2 = (_x2), (p)->y2 = (_y2) 134 | 135 | #define setXY4(p, _x0, _y0, _x1, _y1, _x2, _y2, _x3, _y3) \ 136 | (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1), \ 137 | (p)->x2 = (_x2), (p)->y2 = (_y2), (p)->x3 = (_x3), (p)->y3 = (_y3) 138 | 139 | #define setXYWH(p, _x0, _y0, _w, _h) \ 140 | (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x0) + (_w), (p)->y1 = (_y0), \ 141 | (p)->x2 = (_x0), (p)->y2 = (_y0) + (_h), (p)->x3 = (_x0) + (_w), \ 142 | (p)->y3 = (_y0) + (_h) 143 | 144 | /* 145 | * Set Primitive Width/Height 146 | */ 147 | #define setWH(p, _w, _h) (p)->w = _w, (p)->h = _h 148 | 149 | /* 150 | * Set Primitive Texture Points 151 | */ 152 | #define setUV0(p, _u0, _v0) (p)->u0 = (_u0), (p)->v0 = (_v0) 153 | 154 | #define setUV3(p, _u0, _v0, _u1, _v1, _u2, _v2) \ 155 | (p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u1), (p)->v1 = (_v1), \ 156 | (p)->u2 = (_u2), (p)->v2 = (_v2) 157 | 158 | #define setUV4(p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3) \ 159 | (p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u1), (p)->v1 = (_v1), \ 160 | (p)->u2 = (_u2), (p)->v2 = (_v2), (p)->u3 = (_u3), (p)->v3 = (_v3) 161 | 162 | #define setUVWH(p, _u0, _v0, _w, _h) \ 163 | (p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u0) + (_w), (p)->v1 = (_v0), \ 164 | (p)->u2 = (_u0), (p)->v2 = (_v0) + (_h), (p)->u3 = (_u0) + (_w), \ 165 | (p)->v3 = (_v0) + (_h) 166 | 167 | /* 168 | * Dump Primivie Parameters 169 | */ 170 | #define dumpRECT(r) \ 171 | GPU_printf("(%d,%d)-(%d,%d)\n", (r)->x, (r)->y, (r)->w, (r)->h) 172 | 173 | #define dumpWH(p) GPU_printf("(%d,%d)\n", (p)->w, (p)->h) 174 | #define dumpXY0(p) GPU_printf("(%d,%d)\n", (p)->x0, (p)->y0) 175 | #define dumpUV0(p) GPU_printf("(%d,%d)\n", (p)->u0, (p)->v0) 176 | 177 | #define dumpXY2(p) \ 178 | GPU_printf("(%d,%d)-(%d,%d)\n", (p)->x0, (p)->y0, (p)->x1, (p)->y1) 179 | 180 | #define dumpXY3(p) \ 181 | GPU_printf("(%d,%d)-(%d,%d)-(%d,%d)\n", (p)->x0, (p)->y0, (p)->x1, \ 182 | (p)->y1, (p)->x2, (p)->y2) 183 | 184 | #define dumpUV3(p) \ 185 | GPU_printf("(%d,%d)-(%d,%d)-(%d,%d)\n", (p)->u0, (p)->v0, (p)->u1, \ 186 | (p)->v1, (p)->u2, (p)->v2) 187 | 188 | #define dumpXY4(p) \ 189 | GPU_printf("(%d,%d)-(%d,%d)-(%d,%d)-(%d,%d)\n", (p)->x0, (p)->y0, (p)->x1, \ 190 | (p)->y1, (p)->x2, (p)->y2, (p)->x3, (p)->y3) 191 | 192 | #define dumpUV4(p) \ 193 | GPU_printf("(%d,%d)-(%d,%d)-(%d,%d)-(%d,%d)\n", (p)->u0, (p)->v0, (p)->u1, \ 194 | (p)->v1, (p)->u2, (p)->v2, (p)->u3, (p)->v3) 195 | 196 | #define dumpRGB0(p) GPU_printf("(%3d,%3d,%3d)\n", (p)->r0, (p)->g0, (p)->b0) 197 | 198 | #define dumpRGB1(p) GPU_printf("(%3d,%3d,%3d)\n", (p)->r1, (p)->g1, (p)->b1) 199 | 200 | #define dumpRGB2(p) GPU_printf("(%3d,%3d,%3d)\n", (p)->r2, (p)->g2, (p)->b2) 201 | 202 | #define dumpRGB3(p) GPU_printf("(%3d,%3d,%3d)\n", (p)->r3, (p)->g3, (p)->b3) 203 | 204 | /* 205 | * Primitive Handling Macros 206 | */ 207 | #define setlen(p, _len) (((P_TAG*)(p))->len = (u_char)(_len)) 208 | #define setaddr(p, _addr) (((P_TAG*)(p))->addr = (u_long)(_addr)) 209 | #define setcode(p, _code) (((P_TAG*)(p))->code = (u_char)(_code)) 210 | 211 | #define getlen(p) (u_char)(((P_TAG*)(p))->len) 212 | #define getcode(p) (u_char)(((P_TAG*)(p))->code) 213 | #define getaddr(p) (u_long)(((P_TAG*)(p))->addr) 214 | 215 | #define nextPrim(p) (void*)((((P_TAG*)(p))->addr) | 0x80000000) 216 | #define isendprim(p) ((((P_TAG*)(p))->addr) == 0xffffff) 217 | 218 | #define addPrim(ot, p) setaddr(p, getaddr(ot)), setaddr(ot, p) 219 | #define addPrims(ot, p0, p1) setaddr(p1, getaddr(ot)), setaddr(ot, p0) 220 | 221 | #define catPrim(p0, p1) setaddr(p0, p1) 222 | #define termPrim(p) setaddr(p, 0xffffffff) 223 | 224 | #define setSemiTrans(p, abe) \ 225 | ((abe) ? setcode(p, getcode(p) | 0x02) : setcode(p, getcode(p) & ~0x02)) 226 | 227 | #define setShadeTex(p, tge) \ 228 | ((tge) ? setcode(p, getcode(p) | 0x01) : setcode(p, getcode(p) & ~0x01)) 229 | 230 | #define getTPage(tp, abr, x, y) \ 231 | ((((tp) & 0x3) << 7) | (((abr) & 0x3) << 5) | (((y) & 0x100) >> 4) | \ 232 | (((x) & 0x3ff) >> 6) | (((y) & 0x200) << 2)) 233 | 234 | #define getClut(x, y) ((y << 6) | ((x >> 4) & 0x3f)) 235 | 236 | #define dumpTPage(tpage) \ 237 | GPU_printf("tpage: (%d,%d,%d,%d)\n", ((tpage) >> 7) & 0x003, \ 238 | ((tpage) >> 5) & 0x003, ((tpage) << 6) & 0x7c0, \ 239 | (((tpage) << 4) & 0x100) + (((tpage) >> 2) & 0x200)) 240 | 241 | #define dumpClut(clut) \ 242 | GPU_printf("clut: (%d,%d)\n", (clut & 0x3f) << 4, (clut >> 6)) 243 | 244 | #define _get_mode(dfe, dtd, tpage) \ 245 | ((0xe1000000) | ((dtd) ? 0x0200 : 0) | ((dfe) ? 0x0400 : 0) | \ 246 | ((tpage) & 0x9ff)) 247 | 248 | #define setDrawTPage(p, dfe, dtd, tpage) \ 249 | setlen(p, 1), ((u_long*)(p))[1] = _get_mode(dfe, dtd, tpage) 250 | 251 | /* Primitive Lentgh Code */ 252 | /*-------------------------------------------------------------------- */ 253 | /* */ 254 | #define setPolyF3(p) setlen(p, 4), setcode(p, 0x20) 255 | #define setPolyFT3(p) setlen(p, 7), setcode(p, 0x24) 256 | #define setPolyG3(p) setlen(p, 6), setcode(p, 0x30) 257 | #define setPolyGT3(p) setlen(p, 9), setcode(p, 0x34) 258 | #define setPolyF4(p) setlen(p, 5), setcode(p, 0x28) 259 | #define setPolyFT4(p) setlen(p, 9), setcode(p, 0x2c) 260 | #define setPolyG4(p) setlen(p, 8), setcode(p, 0x38) 261 | #define setPolyGT4(p) setlen(p, 12), setcode(p, 0x3c) 262 | 263 | #define setSprt8(p) setlen(p, 3), setcode(p, 0x74) 264 | #define setSprt16(p) setlen(p, 3), setcode(p, 0x7c) 265 | #define setSprt(p) setlen(p, 4), setcode(p, 0x64) 266 | 267 | #define setTile1(p) setlen(p, 2), setcode(p, 0x68) 268 | #define setTile8(p) setlen(p, 2), setcode(p, 0x70) 269 | #define setTile16(p) setlen(p, 2), setcode(p, 0x78) 270 | #define setTile(p) setlen(p, 3), setcode(p, 0x60) 271 | #define setLineF2(p) setlen(p, 3), setcode(p, 0x40) 272 | #define setLineG2(p) setlen(p, 4), setcode(p, 0x50) 273 | #define setLineF3(p) setlen(p, 5), setcode(p, 0x48), (p)->pad = 0x55555555 274 | #define setLineG3(p) setlen(p, 7), setcode(p, 0x58), (p)->pad = 0x55555555 275 | #define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), (p)->pad = 0x55555555 276 | #define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), (p)->pad = 0x55555555 277 | 278 | /* 279 | * Rectangle: 280 | */ 281 | typedef struct { 282 | short x, y; /* offset point on VRAM */ 283 | short w, h; /* width and height */ 284 | } RECT; 285 | 286 | typedef struct { 287 | int x, y; /* offset point on VRAM */ 288 | int w, h; /* width and height */ 289 | } RECT32; 290 | 291 | /* 292 | * Environment 293 | */ 294 | typedef struct { 295 | u_long tag; 296 | u_long code[15]; 297 | } DR_ENV; /* Packed Drawing Environment */ 298 | 299 | typedef struct { 300 | RECT clip; /* clip area */ 301 | short ofs[2]; /* drawing offset */ 302 | RECT tw; /* texture window */ 303 | u_short tpage; /* texture page */ 304 | u_char dtd; /* dither flag (0:off, 1:on) */ 305 | u_char dfe; /* flag to draw on display area (0:off 1:on) */ 306 | u_char isbg; /* enable to auto-clear */ 307 | u_char r0, g0, b0; /* initital background color */ 308 | DR_ENV dr_env; /* reserved */ 309 | } DRAWENV; 310 | 311 | typedef struct { 312 | RECT disp; /* display area */ 313 | RECT screen; /* display start point */ 314 | u_char isinter; /* interlace 0: off 1: on */ 315 | u_char isrgb24; /* RGB24 bit mode */ 316 | u_char pad0, pad1; /* reserved */ 317 | } DISPENV; 318 | 319 | /* 320 | * Polygon Primitive Definitions 321 | */ 322 | typedef struct { 323 | unsigned addr : 24; 324 | unsigned len : 8; 325 | u_char r0, g0, b0, code; 326 | } P_TAG; 327 | 328 | typedef struct { 329 | u_char r0, g0, b0, code; 330 | } P_CODE; 331 | 332 | typedef struct { 333 | u_long tag; 334 | u_char r0, g0, b0, code; 335 | short x0, y0; 336 | short x1, y1; 337 | short x2, y2; 338 | } POLY_F3; /* Flat Triangle */ 339 | 340 | typedef struct { 341 | u_long tag; 342 | u_char r0, g0, b0, code; 343 | short x0, y0; 344 | short x1, y1; 345 | short x2, y2; 346 | short x3, y3; 347 | } POLY_F4; /* Flat Quadrangle */ 348 | 349 | typedef struct { 350 | u_long tag; 351 | u_char r0, g0, b0, code; 352 | short x0, y0; 353 | u_char u0, v0; 354 | u_short clut; 355 | short x1, y1; 356 | u_char u1, v1; 357 | u_short tpage; 358 | short x2, y2; 359 | u_char u2, v2; 360 | u_short pad1; 361 | } POLY_FT3; /* Flat Textured Triangle */ 362 | 363 | typedef struct { 364 | u_long tag; 365 | u_char r0, g0, b0, code; 366 | short x0, y0; 367 | u_char u0, v0; 368 | u_short clut; 369 | short x1, y1; 370 | u_char u1, v1; 371 | u_short tpage; 372 | short x2, y2; 373 | u_char u2, v2; 374 | u_short pad1; 375 | short x3, y3; 376 | u_char u3, v3; 377 | u_short pad2; 378 | } POLY_FT4; /* Flat Textured Quadrangle */ 379 | 380 | typedef struct { 381 | u_long tag; 382 | u_char r0, g0, b0, code; 383 | short x0, y0; 384 | u_char r1, g1, b1, pad1; 385 | short x1, y1; 386 | u_char r2, g2, b2, pad2; 387 | short x2, y2; 388 | } POLY_G3; /* Gouraud Triangle */ 389 | 390 | typedef struct { 391 | u_long tag; 392 | u_char r0, g0, b0, code; 393 | short x0, y0; 394 | u_char r1, g1, b1, pad1; 395 | short x1, y1; 396 | u_char r2, g2, b2, pad2; 397 | short x2, y2; 398 | u_char r3, g3, b3, pad3; 399 | short x3, y3; 400 | } POLY_G4; /* Gouraud Quadrangle */ 401 | 402 | typedef struct { 403 | u_long tag; 404 | u_char r0, g0, b0, code; 405 | short x0, y0; 406 | u_char u0, v0; 407 | u_short clut; 408 | u_char r1, g1, b1, p1; 409 | short x1, y1; 410 | u_char u1, v1; 411 | u_short tpage; 412 | u_char r2, g2, b2, p2; 413 | short x2, y2; 414 | u_char u2, v2; 415 | u_short pad2; 416 | } POLY_GT3; /* Gouraud Textured Triangle */ 417 | 418 | typedef struct { 419 | u_long tag; 420 | u_char r0, g0, b0, code; 421 | short x0, y0; 422 | u_char u0, v0; 423 | u_short clut; 424 | u_char r1, g1, b1, p1; 425 | short x1, y1; 426 | u_char u1, v1; 427 | u_short tpage; 428 | u_char r2, g2, b2, p2; 429 | short x2, y2; 430 | u_char u2, v2; 431 | u_short pad2; 432 | u_char r3, g3, b3, p3; 433 | short x3, y3; 434 | u_char u3, v3; 435 | u_short pad3; 436 | } POLY_GT4; /* Gouraud Textured Quadrangle */ 437 | 438 | /* 439 | * Line Primitive Definitions 440 | */ 441 | typedef struct { 442 | u_long tag; 443 | u_char r0, g0, b0, code; 444 | short x0, y0; 445 | short x1, y1; 446 | } LINE_F2; /* Unconnected Flat Line */ 447 | 448 | typedef struct { 449 | u_long tag; 450 | u_char r0, g0, b0, code; 451 | short x0, y0; 452 | u_char r1, g1, b1, p1; 453 | short x1, y1; 454 | } LINE_G2; /* Unconnected Gouraud Line */ 455 | 456 | typedef struct { 457 | u_long tag; 458 | u_char r0, g0, b0, code; 459 | short x0, y0; 460 | short x1, y1; 461 | short x2, y2; 462 | u_long pad; 463 | } LINE_F3; /* 2 connected Flat Line */ 464 | 465 | typedef struct { 466 | u_long tag; 467 | u_char r0, g0, b0, code; 468 | short x0, y0; 469 | u_char r1, g1, b1, p1; 470 | short x1, y1; 471 | u_char r2, g2, b2, p2; 472 | short x2, y2; 473 | u_long pad; 474 | } LINE_G3; /* 2 connected Gouraud Line */ 475 | 476 | typedef struct { 477 | u_long tag; 478 | u_char r0, g0, b0, code; 479 | short x0, y0; 480 | short x1, y1; 481 | short x2, y2; 482 | short x3, y3; 483 | u_long pad; 484 | } LINE_F4; /* 3 connected Flat Line Quadrangle */ 485 | 486 | typedef struct { 487 | u_long tag; 488 | u_char r0, g0, b0, code; 489 | short x0, y0; 490 | u_char r1, g1, b1, p1; 491 | short x1, y1; 492 | u_char r2, g2, b2, p2; 493 | short x2, y2; 494 | u_char r3, g3, b3, p3; 495 | short x3, y3; 496 | u_long pad; 497 | } LINE_G4; /* 3 connected Gouraud Line */ 498 | 499 | /* 500 | * Sprite Primitive Definitions 501 | */ 502 | typedef struct { 503 | u_long tag; 504 | u_char r0, g0, b0, code; 505 | short x0, y0; 506 | u_char u0, v0; 507 | u_short clut; 508 | short w, h; 509 | } SPRT; /* free size Sprite */ 510 | 511 | typedef struct { 512 | u_long tag; 513 | u_char r0, g0, b0, code; 514 | short x0, y0; 515 | u_char u0, v0; 516 | u_short clut; 517 | } SPRT_16; /* 16x16 Sprite */ 518 | 519 | typedef struct { 520 | u_long tag; 521 | u_char r0, g0, b0, code; 522 | short x0, y0; 523 | u_char u0, v0; 524 | u_short clut; 525 | } SPRT_8; /* 8x8 Sprite */ 526 | 527 | /* 528 | * Tile Primitive Definitions 529 | */ 530 | typedef struct { 531 | u_long tag; 532 | u_char r0, g0, b0, code; 533 | short x0, y0; 534 | short w, h; 535 | } TILE; /* free size Tile */ 536 | 537 | typedef struct { 538 | u_long tag; 539 | u_char r0, g0, b0, code; 540 | short x0, y0; 541 | } TILE_16; /* 16x16 Tile */ 542 | 543 | typedef struct { 544 | u_long tag; 545 | u_char r0, g0, b0, code; 546 | short x0, y0; 547 | } TILE_8; /* 8x8 Tile */ 548 | 549 | typedef struct { 550 | u_long tag; 551 | u_char r0, g0, b0, code; 552 | short x0, y0; 553 | } TILE_1; /* 1x1 Tile */ 554 | 555 | /* 556 | * Special Primitive Definitions 557 | */ 558 | typedef struct { 559 | u_long tag; 560 | u_long code[2]; 561 | } DR_MODE; /* Drawing Mode */ 562 | 563 | typedef struct { 564 | u_long tag; 565 | u_long code[2]; 566 | } DR_TWIN; /* Texture Window */ 567 | 568 | typedef struct { 569 | u_long tag; 570 | u_long code[2]; 571 | } DR_AREA; /* Drawing Area */ 572 | 573 | typedef struct { 574 | u_long tag; 575 | u_long code[2]; 576 | } DR_OFFSET; /* Drawing Offset */ 577 | 578 | typedef struct { /* MoveImage */ 579 | u_long tag; 580 | u_long code[5]; 581 | } DR_MOVE; 582 | 583 | typedef struct { /* LoadImage */ 584 | u_long tag; 585 | u_long code[3]; 586 | u_long p[13]; 587 | } DR_LOAD; 588 | 589 | typedef struct { 590 | u_long tag; 591 | u_long code[1]; 592 | } DR_TPAGE; /* Drawing TPage */ 593 | 594 | /* 595 | * Font Stream Parameters 596 | */ 597 | #define FNT_MAX_ID 8 /* max number of stream ID */ 598 | #define FNT_MAX_SPRT 1024 /* max number of sprites in all streams */ 599 | 600 | /* 601 | * Multi-purpose Sony-TMD primitive 602 | */ 603 | typedef struct { 604 | u_long id; 605 | u_char r0, g0, b0, p0; /* Color of vertex 0 */ 606 | u_char r1, g1, b1, p1; /* Color of vertex 1 */ 607 | u_char r2, g2, b2, p2; /* Color of vertex 2 */ 608 | u_char r3, g3, b3, p3; /* Color of vertex 3 */ 609 | u_short tpage, clut; /* texture page ID, clut ID */ 610 | u_char u0, v0, u1, v1; /* texture corner point */ 611 | u_char u2, v2, u3, v3; 612 | 613 | /* independent vertex model */ 614 | SVECTOR x0, x1, x2, x3; /* 3D corner point */ 615 | SVECTOR n0, n1, n2, n3; /* 3D corner normal vector */ 616 | 617 | /* Common vertex model */ 618 | SVECTOR* v_ofs; /* offset to vertex database */ 619 | SVECTOR* n_ofs; /* offset to normal database */ 620 | 621 | u_short vert0, vert1; /* index of vertex */ 622 | u_short vert2, vert3; 623 | u_short norm0, norm1; /* index of normal */ 624 | u_short norm2, norm3; 625 | 626 | } TMD_PRIM; 627 | 628 | /* 629 | * Multi-purpose TIM image 630 | */ 631 | typedef struct { 632 | u_long mode; /* pixel mode */ 633 | RECT* crect; /* CLUT rectangle on frame buffer */ 634 | u_long* caddr; /* CLUT address on main memory */ 635 | RECT* prect; /* texture image rectangle on frame buffer */ 636 | u_long* paddr; /* texture image address on main memory */ 637 | } TIM_IMAGE; 638 | 639 | /* 640 | * Prototypes 641 | */ 642 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 643 | defined(c_plusplus) 644 | extern "C" { 645 | #ifndef _FNTPRINT_ 646 | #define _FNTPRINT_ 647 | extern int FntPrint(...); 648 | #endif /* _FNTPRINT_ */ 649 | #ifndef _KANJIFNTPRINT_ 650 | #define _KANJIFNTPRINT_ 651 | extern int KanjiFntPrint(...); 652 | #endif /* _KANJIFNTPRINT_ */ 653 | #else 654 | #ifndef _FNTPRINT_ 655 | #define _FNTPRINT_ 656 | extern int FntPrint(); 657 | #endif /* _FNTPRINT_ */ 658 | #ifndef _KANJIFNTPRINT_ 659 | #define _KANJIFNTPRINT_ 660 | extern int KanjiFntPrint(); 661 | #endif /* _KANJIFNTPRINT_ */ 662 | #endif 663 | 664 | extern DISPENV* GetDispEnv(DISPENV* env); 665 | extern DISPENV* PutDispEnv(DISPENV* env); 666 | extern DISPENV* SetDefDispEnv(DISPENV* env, int x, int y, int w, int h); 667 | extern DRAWENV* GetDrawEnv(DRAWENV* env); 668 | extern DRAWENV* PutDrawEnv(DRAWENV* env); 669 | extern DRAWENV* SetDefDrawEnv(DRAWENV* env, int x, int y, int w, int h); 670 | extern TIM_IMAGE* ReadTIM(TIM_IMAGE* timimg); 671 | extern TMD_PRIM* ReadTMD(TMD_PRIM* tmdprim); 672 | extern int CheckPrim(char* s, u_long* p); 673 | extern int ClearImage(RECT* rect, u_char r, u_char g, u_char b); 674 | extern int ClearImage2(RECT* rect, u_char r, u_char g, u_char b); 675 | extern int DrawSync(int mode); 676 | extern int FntOpen(int x, int y, int w, int h, int isbg, int n); 677 | extern int GetGraphDebug(void); 678 | extern int GetTimSize(u_char* sjis); 679 | extern int IsEndPrim(void* p); 680 | extern int KanjiFntOpen(int x, int y, int w, int h, int dx, int dy, int cx, 681 | int cy, int isbg, int n); 682 | extern void KanjiFntClose(void); 683 | extern int Krom2Tim(u_char* sjis, u_long* taddr, int dx, int dy, int cdx, 684 | int cdy, u_int fg, u_int bg); 685 | extern int LoadImage(RECT* rect, u_long* p); 686 | extern int MargePrim(void* p0, void* p1); 687 | extern int MoveImage(RECT* rect, int x, int y); 688 | extern int OpenTIM(u_long* addr); 689 | extern int OpenTMD(u_long* tmd, int obj_no); 690 | extern int ResetGraph(int mode); 691 | extern int SetGraphDebug(int level); 692 | extern int StoreImage(RECT* rect, u_long* p); 693 | extern u_long* ClearOTag(u_long* ot, int n); 694 | extern u_long* ClearOTagR(u_long* ot, int n); 695 | extern u_long* FntFlush(int id); 696 | extern u_long* KanjiFntFlush(int id); 697 | extern u_long DrawSyncCallback(void (*func)()); 698 | extern u_short GetClut(int x, int y); 699 | extern u_short GetTPage(int tp, int abr, int x, int y); 700 | extern u_short LoadClut(u_long* clut, int x, int y); 701 | extern u_short LoadClut2(u_long* clut, int x, int y); 702 | extern u_short LoadTPage( 703 | u_long* pix, int tp, int abr, int x, int y, int w, int h); 704 | extern void* NextPrim(void* p); 705 | extern void AddPrim(void* ot, void* p); 706 | extern void AddPrims(void* ot, void* p0, void* p1); 707 | extern void CatPrim(void* p0, void* p1); 708 | extern void DrawOTag(u_long* p); 709 | extern void DrawOTagIO(u_long* p); 710 | extern void DrawOTagEnv(u_long* p, DRAWENV* env); 711 | extern void DrawPrim(void* p); 712 | extern void DumpClut(u_short clut); 713 | extern void DumpDispEnv(DISPENV* env); 714 | extern void DumpDrawEnv(DRAWENV* env); 715 | extern void DumpOTag(u_long* p); 716 | extern void DumpTPage(u_short tpage); 717 | extern void FntLoad(int tx, int ty); 718 | extern void SetDispMask(int mask); 719 | extern void SetDrawArea(DR_AREA* p, RECT* r); 720 | extern void SetDrawEnv(DR_ENV* dr_env, DRAWENV* env); 721 | extern void SetDrawLoad(DR_LOAD* p, RECT* rect); 722 | extern void SetDrawMode(DR_MODE* p, int dfe, int dtd, int tpage, RECT* tw); 723 | extern void SetDrawTPage(DR_TPAGE* p, int dfe, int dtd, int tpage); 724 | extern void SetDrawMove(DR_MOVE* p, RECT* rect, int x, int y); 725 | extern void SetDrawOffset(DR_OFFSET* p, u_short* ofs); 726 | extern void SetDumpFnt(int id); 727 | extern void SetLineF2(LINE_F2* p); 728 | extern void SetLineF3(LINE_F3* p); 729 | extern void SetLineF4(LINE_F4* p); 730 | extern void SetLineG2(LINE_G2* p); 731 | extern void SetLineG3(LINE_G3* p); 732 | extern void SetLineG4(LINE_G4* p); 733 | extern void SetPolyF3(POLY_F3* p); 734 | extern void SetPolyF4(POLY_F4* p); 735 | extern void SetPolyFT3(POLY_FT3* p); 736 | extern void SetPolyFT4(POLY_FT4* p); 737 | extern void SetPolyG3(POLY_G3* p); 738 | extern void SetPolyG4(POLY_G4* p); 739 | extern void SetPolyGT3(POLY_GT3* p); 740 | extern void SetPolyGT4(POLY_GT4* p); 741 | extern void SetSemiTrans(void* p, int abe); 742 | extern void SetShadeTex(void* p, int tge); 743 | extern void SetSprt(SPRT* p); 744 | extern void SetSprt16(SPRT_16* p); 745 | extern void SetSprt8(SPRT_8* p); 746 | extern void SetTexWindow(DR_TWIN* p, RECT* tw); 747 | extern void SetTile(TILE* p); 748 | extern void SetTile1(TILE_1* p); 749 | extern void SetTile16(TILE_16* p); 750 | extern void SetTile8(TILE_8* p); 751 | extern void TermPrim(void* p); 752 | extern u_long* BreakDraw(void); 753 | extern void ContinueDraw(u_long* insaddr, u_long* contaddr); 754 | extern int IsIdleGPU(int max_count); 755 | extern int GetODE(void); 756 | 757 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 758 | defined(c_plusplus) 759 | } 760 | #endif 761 | #endif /* _LIBGPU_H_ */ 762 | -------------------------------------------------------------------------------- /include/psyq/libgte.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/libgte.h -------------------------------------------------------------------------------- /include/psyq/libgun.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId: Runtime Library Release 3.6$ */ 2 | #ifndef _LIBGUN_H_ 3 | #define _LIBGUN_H_ 4 | 5 | /* 6 | * Copyright (C) 1996 Sony Computer Entertainment America. All Rights Reserved 7 | * libetc.h: Light Gun Interface 8 | */ 9 | 10 | /* 11 | * Prototypes 12 | */ 13 | 14 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 15 | defined(c_plusplus) 16 | extern "C" { 17 | #endif 18 | void InitGUN(char* bufA, long lenA, char* bufB, long lenB, char* buf1, 19 | char* buf2, long len); 20 | void RemoveGUN(void); 21 | void SelectGUN(int ch, unsigned char mask); 22 | void StartGUN(void); 23 | void StopGUN(void); 24 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 25 | defined(c_plusplus) 26 | } 27 | #endif 28 | #endif /* _LIBGUN_H_ */ 29 | -------------------------------------------------------------------------------- /include/psyq/libmath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId$ 3 | */ 4 | 5 | #ifndef _LIBMATH_H_ 6 | #define _LIBMATH_H_ 7 | 8 | /* 9 | libmath.h 10 | */ 11 | #define _ABS(x) ((x) < 0 ? -(x) : (x)) 12 | #define fabs(x) _ABS(x) 13 | 14 | extern int math_errno; 15 | extern int math_err_point; 16 | 17 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 18 | defined(c_plusplus) 19 | extern "C" { 20 | #endif 21 | 22 | double pow(double, double), exp(double); 23 | double log(double), log10(double); 24 | double floor(double), ceil(double); 25 | double fmod(double, double), modf(double, double*); 26 | double sin(double), cos(double), tan(double); 27 | double asin(double), acos(double); 28 | double atan(double), atan2(double, double); 29 | double sinh(double), cosh(double), tanh(double); 30 | double sqrt(double); 31 | double hypot(double, double); 32 | double ldexp(double, int), frexp(double, int*); 33 | 34 | double atof(char*); 35 | double strtod(char*, char**); 36 | int printf2(char*, ...); 37 | int sprintf2(char*, char*, ...); 38 | 39 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 40 | defined(c_plusplus) 41 | } 42 | #endif 43 | 44 | #endif /* _LIBMATH_H_ */ 45 | -------------------------------------------------------------------------------- /include/psyq/libmcrd.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEMCARD_H_ 2 | #define _MEMCARD_H_ 3 | /* 4 | * File:libmcrd.h Rev. 4.0 5 | */ 6 | /* 7 | * $PSLibId$ 8 | */ 9 | #include 10 | 11 | typedef void (*MemCB)(unsigned long cmds, unsigned long rslt); 12 | 13 | #define McFuncExist (1) 14 | #define McFuncAccept (2) 15 | #define McFuncReadFile (3) 16 | #define McFuncWriteFile (4) 17 | #define McFuncReadData (5) 18 | #define McFuncWriteData (6) 19 | 20 | #define McErrNone (0) 21 | #define McErrCardNotExist (1) 22 | #define McErrCardInvalid (2) 23 | #define McErrNewCard (3) 24 | #define McErrNotFormat (4) 25 | #define McErrFileNotExist (5) 26 | #define McErrAlreadyExist (6) 27 | #define McErrBlockFull (7) 28 | #define McErrExtend (0x8000) 29 | 30 | extern void MemCardInit(long flg); 31 | extern void MemCardEnd(void); 32 | extern void MemCardStart(void); 33 | extern void MemCardStop(void); 34 | extern long MemCardExist(long chan); 35 | extern long MemCardAccept(long chan); 36 | extern long MemCardOpen(long chan, char* fnam, unsigned long flag); 37 | extern void MemCardClose(void); 38 | extern long MemCardReadData(long* adrs, long ofs, long bytes); 39 | extern long MemCardReadFile( 40 | long chan, char* fnam, long* adrs, long ofs, long bytes); 41 | extern long MemCardWriteData(long* adrs, long ofs, long bytes); 42 | extern long MemCardWriteFile( 43 | long chan, char* fnam, long* adrs, long ofs, long bytes); 44 | extern long MemCardCreateFile(long chan, char* fnam, long blocks); 45 | extern long MemCardDeleteFile(long chan, char* fnam); 46 | extern long MemCardFormat(long chan); 47 | extern long MemCardUnformat(long chan); 48 | extern long MemCardSync(long mode, unsigned long* cmds, unsigned long* rslt); 49 | extern MemCB MemCardCallback(MemCB func); 50 | extern long MemCardGetDirentry(long chan, char* name, struct DIRENTRY* pdir, 51 | long* files, long ofs, long max); 52 | #endif /* _MEMCARD_H_ */ 53 | -------------------------------------------------------------------------------- /include/psyq/libpress.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId$ */ 2 | #ifndef _LIBPRESS_H_ 3 | #define _LIBPRESS_H_ 4 | /* 5 | * (C) Copyright 1995 Sony Corporation,Tokyo,Japan. All Rights Reserved 6 | * 7 | * libpress.h: Prototypes for libpress 8 | * 9 | */ 10 | /* DecDCTvlc Table */ 11 | typedef u_short DECDCTTAB[34816]; 12 | 13 | /* DecDCTEnv */ 14 | typedef struct { 15 | u_char iq_y[64]; /* IQ (Y): zig-zag order */ 16 | u_char iq_c[64]; /* IQ (Cb,Cr): zig-zag order */ 17 | short dct[64]; /* IDCT coef (reserved) */ 18 | } DECDCTENV; 19 | 20 | typedef struct { 21 | short* src; /* 16-bit strait PCM */ 22 | short* dest; /* PlayStation original waveform data */ 23 | short* work; /* scratch pad or NULL */ 24 | long size; /* size (unit: byte) of source data */ 25 | long loop_start; /* loop start point (unit: byte) of source data */ 26 | char loop; /* whether loop or not */ 27 | char byte_swap; /* source data is 16-bit big endian (1) / little endian (0) 28 | */ 29 | char proceed; /* proceeding ? whole (0) / start (1) / cont. (2) / end (4) */ 30 | char pad4; /* reserved */ 31 | } ENCSPUENV; 32 | 33 | #define ENCSPU_ENCODE_ERROR (-1) 34 | #define ENCSPU_ENCODE_WHOLE 0 35 | #define ENCSPU_ENCODE_START (1 << 0) 36 | #define ENCSPU_ENCODE_CONTINUE (1 << 1) 37 | #define ENCSPU_ENCODE_END (1 << 2) 38 | 39 | #define ENCSPU_ENCODE_LOOP 1 40 | #define ENCSPU_ENCODE_NO_LOOP 0 41 | 42 | #define ENCSPU_ENCODE_ENDIAN_LITTLE 0 43 | #define ENCSPU_ENCODE_ENDIAN_BIG 1 44 | 45 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 46 | defined(c_plusplus) 47 | extern "C" { 48 | #endif 49 | extern void DecDCTReset(int mode); 50 | extern DECDCTENV* DecDCTGetEnv(DECDCTENV* env); 51 | extern DECDCTENV* DecDCTPutEnv(DECDCTENV* env); 52 | extern int DecDCTBufSize(u_long* bs); 53 | extern int DecDCTvlc(u_long* bs, u_long* buf); 54 | extern int DecDCTvlc2(u_long* bs, u_long* buf, DECDCTTAB table); 55 | extern int DecDCTvlcSize(int size); 56 | extern int DecDCTvlcSize2(int size); 57 | extern void DecDCTvlcBuild(u_short* table); 58 | extern void DecDCTin(u_long* buf, int mode); 59 | extern void DecDCTout(u_long* buf, int size); 60 | extern int DecDCTinSync(int mode); 61 | extern int DecDCToutSync(int mode); 62 | extern int DecDCTinCallback(void (*func)()); 63 | extern int DecDCToutCallback(void (*func)()); 64 | 65 | extern long EncSPU(ENCSPUENV* env); 66 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 67 | defined(c_plusplus) 68 | } 69 | #endif 70 | #endif /* _LIBPRESS_H_ */ 71 | -------------------------------------------------------------------------------- /include/psyq/libsio.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId: Runtime Library Release 4.0$ */ 2 | #ifndef _LIBSIO_H_ 3 | #define _LIBSIO_H_ 4 | 5 | /* 6 | * Copyright (C) 1996,1997 Sony Computer Entertainment Inc. All Rights Reserved 7 | * libsio.h: Sio Interface 8 | */ 9 | 10 | /* status bits */ 11 | #define SR_IRQ 0x200 12 | #define SR_CTS 0x100 13 | #define SR_DSR 0x80 14 | #define SR_FE 0x20 15 | #define SR_OE 0x10 16 | #define SR_PERROR 0x8 17 | #define SR_TXU 0x4 18 | #define SR_RXRDY 0x2 19 | #define SR_TXRDY 0x1 20 | 21 | #define SIO_CTS 0x100 22 | #define SIO_DSR 0x80 23 | #define SIO_FE 0x20 24 | #define SIO_OE 0x10 25 | #define SIO_PERROR 0x8 26 | #define SIO_TXU 0x4 27 | #define SIO_RXRDY 0x2 28 | #define SIO_TXRDY 0x1 29 | 30 | /* control bits */ 31 | #define CR_DSRIEN 0x1000 32 | #define CR_RXIEN 0x800 33 | #define CR_TXIEN 0x400 34 | #define CR_BUFSZ_1 0x0 35 | #define CR_BUFSZ_2 0x100 36 | #define CR_BUFSZ_4 0x200 37 | #define CR_BUFSZ_8 0x300 38 | #define CR_INTRST 0x40 39 | #define CR_RTS 0x20 40 | #define CR_ERRRST 0x10 41 | #define CR_BRK 0x8 42 | #define CR_RXEN 0x4 43 | #define CR_DTR 0x2 44 | #define CR_TXEN 0x1 45 | 46 | #define SIO_BIT_DTR CR_DTR 47 | #define SIO_BIT_RTS CR_RTS 48 | 49 | /* mode bits */ 50 | #define MR_SB_00 0x0 51 | #define MR_SB_01 0x40 52 | #define MR_SB_10 0x80 53 | #define MR_SB_11 0xC0 54 | #define MR_P_EVEN 0x20 55 | #define MR_PEN 0x10 56 | #define MR_CHLEN_5 0x0 57 | #define MR_CHLEN_6 0x4 58 | #define MR_CHLEN_7 0x8 59 | #define MR_CHLEN_8 0xC 60 | #define MR_BR_1 0x1 61 | #define MR_BR_16 0x2 62 | #define MR_BR_64 0x3 63 | 64 | /* 65 | * Prototypes 66 | */ 67 | 68 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 69 | defined(c_plusplus) 70 | extern "C" { 71 | #endif 72 | extern long AddSIO(int); 73 | extern long DelSIO(void); 74 | extern long _sio_control(unsigned long, unsigned long, unsigned long); 75 | extern int Sio1Callback(void (*func)()); 76 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 77 | defined(c_plusplus) 78 | } 79 | #endif 80 | #endif /* _LIBSIO_H_ */ 81 | -------------------------------------------------------------------------------- /include/psyq/libsn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId: Runtime Library Version 3.4$ 3 | */ 4 | #ifndef _LIBSN_H_ 5 | #define _LIBSN_H_ 6 | 7 | /* 8 | ** LIBSN.H declare libary functions provided by LIBSN.LIB 9 | ** 10 | ** 05/02/94 ADB 11 | ** 21/03/94 ADB added user notes as comments 12 | ** 18/09/94 ADB added PCcreat() - it was missing before 13 | ** 31/05/95 ADB added PSYQpause() for new debug stub 4.04 14 | ** 20/09/95 ADB added SNFlushCache - but removed after email from Tom Boyd 15 | ** 10/01/96 modified for c++ by yoshi@SCEI 16 | */ 17 | 18 | #define pollhost() asm("break 1024") /* inline to keep variable scope */ 19 | #define PSYQpause() asm("break 1031") /* inline to keep variable scope */ 20 | 21 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 22 | defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | ** FILESERVER FUNCTIONS: 28 | ** 29 | ** NOTE: For PCread and PCwrite do not load files by passing extreme 30 | ** values for count as you might on UNIX as this will cause the full 31 | ** amount specified to be transferred - the file will be padded to 32 | ** that length with zeroes which may over-write memory beyond the 33 | ** end of the file. 34 | ** 35 | ** If you are unsure of the length of a file which you are about 36 | ** to read into memory then perform a 37 | ** len = PClseek( fd, 0, 2); 38 | ** This will set len to the length of the file which you can then 39 | ** pass to a PCread() function call. 40 | ** 41 | */ 42 | 43 | /* 44 | ** re-initialise PC filing system, close open files etc 45 | ** 46 | ** passed: void 47 | ** 48 | ** return: error code (0 if no error) 49 | */ 50 | int PCinit(void); 51 | 52 | /* 53 | ** open a file on PC host 54 | ** 55 | ** passed: PC file pathname, open mode, permission flags 56 | ** 57 | ** return: file-handle or -1 if error 58 | ** 59 | ** note: perms should be zero (it is ignored) 60 | ** 61 | ** open mode: 0 => read only 62 | ** 1 => write only 63 | ** 2 => read/write 64 | */ 65 | int PCopen(char* name, int flags, int perms); 66 | 67 | /* 68 | ** create (and open) a file on PC host 69 | ** 70 | ** passed: PC file pathname, open mode, permission flags 71 | ** 72 | ** return: file-handle or -1 if error 73 | ** 74 | ** note: perms should be zero (it is ignored) 75 | */ 76 | int PCcreat(char* name, int perms); 77 | 78 | /* 79 | ** seek file pointer to new position in file 80 | ** 81 | ** passed: file-handle, seek offset, seek mode 82 | ** 83 | ** return: absolute value of new file pointer position 84 | ** 85 | ** (mode 0 = rel to start, mode 1 = rel to current fp, mode 2 = rel to end) 86 | */ 87 | int PClseek(int fd, int offset, int mode); 88 | 89 | /* 90 | ** read bytes from file on PC 91 | ** 92 | ** passed: file-handle, buffer address, count 93 | ** 94 | ** return: count of number of bytes actually read 95 | ** 96 | ** note: unlike assembler function this provides for full 32 bit count 97 | */ 98 | int PCread(int fd, char* buff, int len); 99 | 100 | /* 101 | ** write bytes to file on PC 102 | ** 103 | ** passed: file-handle, buffer address, count 104 | ** 105 | ** return: count of number of bytes actually written 106 | ** 107 | ** note: unlike assembler function this provides for full 32 bit count 108 | */ 109 | int PCwrite(int fd, char* buff, int len); 110 | 111 | /* 112 | ** close an open file on PC 113 | ** 114 | ** passed: file-handle 115 | ** 116 | ** return: negative if error 117 | ** 118 | */ 119 | int PCclose(int fd); 120 | 121 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 122 | defined(c_plusplus) 123 | } 124 | #endif 125 | 126 | #endif /* _LIBSN_H_ */ 127 | -------------------------------------------------------------------------------- /include/psyq/libsnd.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBSND_H_ 2 | #define _LIBSND_H_ 3 | 4 | /***************************************************************** 5 | * 6 | * $RCSfile: libsnd.h,v $ 7 | * 8 | * Copyright (C) 1994 by Sony Computer Entertainment Inc. 9 | * All Rights Reserved. 10 | * 11 | * Sony Computer Entertainment Inc. Development Department 12 | * 13 | *****************************************************************/ 14 | /* 15 | * $PSLibId$ 16 | */ 17 | 18 | #include 19 | 20 | /* 21 | * Macro 22 | */ 23 | #define SSPLAY_INFINITY 0 24 | #define SS_NOTICK 0x1000 25 | #define SS_NOTICK0 0 26 | #define SS_TICK60 1 27 | #define SS_TICK240 2 28 | #define SS_TICK120 3 29 | #define SS_TICK50 4 30 | #define SS_TICKVSYNC 5 31 | #define SS_TICKMODE_MAX 6 32 | #define SSPLAY_PAUSE 0 33 | #define SSPLAY_PLAY 1 34 | #define SS_SOFF 0 35 | #define SS_SON 1 36 | #define SS_MIX 0 37 | #define SS_REV 1 38 | #define SS_SERIAL_A 0 39 | #define SS_SERIAL_B 1 40 | #define SS_MUTE_OFF 0 41 | #define SS_MUTE_ON 1 42 | 43 | #define SS_IMEDIATE 0 44 | #define SS_IMMEDIATE 0 45 | #define SS_WAIT_COMPLETED 1 46 | 47 | #define SS_REV_TYPE_OFF 0 48 | #define SS_REV_TYPE_ROOM 1 49 | #define SS_REV_TYPE_STUDIO_A 2 50 | #define SS_REV_TYPE_STUDIO_B 3 51 | #define SS_REV_TYPE_STUDIO_C 4 52 | #define SS_REV_TYPE_HALL 5 53 | #define SS_REV_TYPE_SPACE 6 54 | #define SS_REV_TYPE_ECHO 7 55 | #define SS_REV_TYPE_DELAY 8 56 | #define SS_REV_TYPE_PIPE 9 57 | #define SSSKIP_TICK 0 58 | #define SSSKIP_NOTE4 1 59 | #define SSSKIP_NOTE8 2 60 | #define SSSKIP_BAR 3 61 | 62 | #define SS_SEQ_TABSIZ 176 63 | 64 | #ifndef NULL 65 | #define NULL 0 66 | #endif 67 | 68 | /* 69 | * Vag & Vab Structure 70 | */ 71 | typedef struct VabHdr { /* VAB Bank Headdings */ 72 | 73 | long form; /* always 'VABp' */ 74 | long ver; /* VAB file version number */ 75 | long id; /* VAB id */ 76 | unsigned long fsize; /* VAB file size */ 77 | unsigned short reserved0; /* system reserved */ 78 | unsigned short ps; /* # of the programs in this bank */ 79 | unsigned short ts; /* # of the tones in this bank */ 80 | unsigned short vs; /* # of the vags in this bank */ 81 | unsigned char mvol; /* master volume for this bank */ 82 | unsigned char pan; /* master panning for this bank */ 83 | unsigned char attr1; /* bank attributes1 */ 84 | unsigned char attr2; /* bank attributes2 */ 85 | unsigned long reserved1; /* system reserved */ 86 | 87 | } VabHdr; /* 32 byte */ 88 | 89 | typedef struct ProgAtr { /* Program Headdings */ 90 | 91 | unsigned char tones; /* # of tones */ 92 | unsigned char mvol; /* program volume */ 93 | unsigned char prior; /* program priority */ 94 | unsigned char mode; /* program mode */ 95 | unsigned char mpan; /* program pan */ 96 | char reserved0; /* system reserved */ 97 | short attr; /* program attribute */ 98 | unsigned long reserved1; /* system reserved */ 99 | unsigned long reserved2; /* system reserved */ 100 | 101 | } ProgAtr; /* 16 byte */ 102 | 103 | typedef struct VagAtr { /* VAG Tone Headdings */ 104 | 105 | unsigned char prior; /* tone priority */ 106 | unsigned char mode; /* play mode */ 107 | unsigned char vol; /* tone volume*/ 108 | unsigned char pan; /* tone panning */ 109 | unsigned char center; /* center note */ 110 | unsigned char shift; /* center note fine tune */ 111 | unsigned char min; /* minimam note limit */ 112 | unsigned char max; /* maximam note limit */ 113 | unsigned char vibW; /* vibrate depth */ 114 | unsigned char vibT; /* vibrate duration */ 115 | unsigned char porW; /* portamento depth */ 116 | unsigned char porT; /* portamento duration */ 117 | unsigned char pbmin; /* under pitch bend max */ 118 | unsigned char pbmax; /* upper pitch bend max */ 119 | unsigned char reserved1; /* system reserved */ 120 | unsigned char reserved2; /* system reserved */ 121 | unsigned short adsr1; /* adsr1 */ 122 | unsigned short adsr2; /* adsr2 */ 123 | short prog; /* parent program*/ 124 | short vag; /* vag reference */ 125 | short reserved[4]; /* system reserved */ 126 | 127 | } VagAtr; /* 32 byte */ 128 | 129 | /* 130 | * Volume Structure 131 | */ 132 | typedef struct { 133 | unsigned short left; /* L Channel */ 134 | unsigned short right; /* R Channel */ 135 | } SndVolume; 136 | 137 | /* 138 | * CallBack 139 | */ 140 | typedef void (*SsMarkCallbackProc)(short, short, short); 141 | 142 | /* 143 | * Prototype 144 | */ 145 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 146 | defined(c_plusplus) 147 | extern "C" { 148 | #endif 149 | extern short SsVabOpenHead(unsigned char*, short); 150 | extern short SsVabOpenHeadSticky(unsigned char*, short, unsigned long); 151 | extern short SsVabTransBody(unsigned char*, short); 152 | extern short SsVabTransBodyPartly(unsigned char*, unsigned long, short); 153 | extern short SsVabTransfer(unsigned char*, unsigned char*, short, short); 154 | extern short SsVabTransCompleted(short); 155 | extern void SsVabClose(short); 156 | 157 | extern void SsInit(void); 158 | extern void SsInitHot(void); 159 | extern void SsSetTableSize(char*, short, short); 160 | extern void SsSetTickMode(long); 161 | extern int SsSetTickCallback(void (*cb)()); 162 | extern void SsStart(void); 163 | extern void SsStart2(void); 164 | extern void SsEnd(void); 165 | extern void SsQuit(void); 166 | 167 | extern void SsSeqCalledTbyT(void); 168 | 169 | extern short SsSeqOpen(unsigned long*, short); 170 | extern void SsSeqPlay(short, char, short); 171 | extern void SsSeqPause(short); 172 | extern void SsSeqReplay(short); 173 | extern void SsSeqStop(short); 174 | extern void SsSeqSetVol(short, short, short); 175 | extern void SsSeqSetNext(short, short); 176 | extern void SsSeqSetCrescendo(short, short, long); 177 | extern void SsSeqSetDecrescendo(short, short, long); 178 | extern void SsSeqSetAccelerando(short, long, long); 179 | extern void SsSeqSetRitardando(short, long, long); 180 | extern void SsSeqClose(short); 181 | 182 | extern short SsSepOpen(unsigned long*, short, short); 183 | extern void SsSepPlay(short, short, char, short); 184 | extern void SsSepPause(short, short); 185 | extern void SsSepReplay(short, short); 186 | extern void SsSepStop(short, short); 187 | extern void SsSepSetVol(short, short, short, short); 188 | extern void SsSepSetCrescendo(short, short, short, long); 189 | extern void SsSepSetDecrescendo(short, short, short, long); 190 | extern void SsSepSetAccelerando(short, short, long, long); 191 | extern void SsSepSetRitardando(short, short, long, long); 192 | extern void SsSepClose(short); 193 | 194 | extern long SsVoKeyOn(long, long, unsigned short, unsigned short); 195 | extern long SsVoKeyOff(long, long); 196 | 197 | extern void SsSetMVol(short, short); 198 | extern void SsGetMVol(SndVolume*); 199 | extern void SsSetRVol(short, short); 200 | extern void SsGetRVol(SndVolume*); 201 | extern void SsSetMute(char); 202 | extern char SsGetMute(void); 203 | extern void SsSetSerialAttr(char, char, char); 204 | extern char SsGetSerialAttr(char, char); 205 | extern void SsSetSerialVol(char, short, short); 206 | extern void SsGetSerialVol(char, SndVolume*); 207 | extern void SsSetNck(short); 208 | extern short SsGetNck(void); 209 | extern void SsSetNoiseOn(short, short); 210 | extern void SsSetNoiseOff(void); 211 | extern void SsSetMono(void); 212 | extern void SsSetStereo(void); 213 | extern void SsSetTempo(short, short, short); 214 | extern void SsSetLoop(short, short, short); 215 | extern short SsIsEos(short, short); 216 | extern void SsPlayBack(short, short, short); 217 | extern void SsSetMarkCallback(short, short, SsMarkCallbackProc); 218 | extern char SsSetReservedVoice(char); 219 | 220 | extern short SsUtKeyOn(short, short, short, short, short, short, short); 221 | extern short SsUtKeyOff(short, short, short, short, short); 222 | extern short SsUtKeyOnV(short voice, short vabId, short prog, short tone, 223 | short note, short fine, short voll, short volr); 224 | extern short SsUtKeyOffV(short voice); 225 | extern short SsUtPitchBend(short, short, short, short, short); 226 | extern short SsUtChangePitch(short, short, short, short, short, short, short); 227 | extern short SsUtChangeADSR( 228 | short, short, short, short, unsigned short, unsigned short); 229 | extern short SsUtSetVabHdr(short, VabHdr*); 230 | extern short SsUtGetVabHdr(short, VabHdr*); 231 | extern short SsUtSetProgAtr(short, short, ProgAtr*); 232 | extern short SsUtGetProgAtr(short, short, ProgAtr*); 233 | extern short SsUtSetVagAtr(short, short, short, VagAtr*); 234 | extern short SsUtGetVagAtr(short, short, short, VagAtr*); 235 | extern short SsUtSetDetVVol(short, short, short); 236 | extern short SsUtGetDetVVol(short, short*, short*); 237 | extern short SsUtSetVVol(short, short, short); 238 | extern short SsUtGetVVol(short, short*, short*); 239 | extern short SsUtAutoVol(short, short, short, short); 240 | extern short SsUtAutoPan(short, short, short, short); 241 | extern void SsUtReverbOn(void); 242 | extern void SsUtReverbOff(void); 243 | extern short SsUtSetReverbType(short); 244 | extern short SsUtGetReverbType(void); 245 | extern void SsUtSetReverbDepth(short, short); 246 | extern void SsUtSetReverbFeedback(short); 247 | extern void SsUtSetReverbDelay(short); 248 | extern void SsUtAllKeyOff(short); 249 | extern void SsSetAutoKeyOffMode(short mode); 250 | extern void SsUtFlush(void); 251 | extern short SsVabFakeHead(unsigned char*, short, unsigned long); 252 | extern short SsVabFakeBody(short); 253 | extern unsigned long SsUtGetVBaddrInSB(short); 254 | extern long SsUtGetVagAddr(short vabId, short vagId); 255 | extern unsigned long SsUtGetVagAddrFromTone( 256 | short vabId, short progId, short toneId); 257 | extern void SsSetNext(short, short, short, short); 258 | extern void SsSeqGetVol(short, short, short*, short*); 259 | extern void SsChannelMute(short, short, long); 260 | extern short SsSeqOpenJ(unsigned long*, short); 261 | extern short SsSepOpenJ(unsigned long*, short, short); 262 | extern unsigned char* SsGetCurrentPoint(short, short); 263 | extern long SsGetChannelMute(short, short); 264 | 265 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 266 | defined(c_plusplus) 267 | } 268 | #endif 269 | 270 | /* 271 | * for function table 272 | */ 273 | 274 | #define CC_NUMBER 0 275 | #define CC_BANKCHANGE 1 276 | #define CC_DATAENTRY 2 277 | #define CC_MAINVOL 3 278 | #define CC_PANPOT 4 279 | #define CC_EXPRESSION 5 280 | #define CC_DAMPER 6 281 | #define CC_NRPN1 7 282 | #define CC_NRPN2 8 283 | #define CC_RPN1 9 284 | #define CC_RPN2 10 285 | #define CC_EXTERNAL 11 286 | #define CC_RESETALL 12 287 | 288 | #define DE_PRIORITY 0 289 | #define DE_MODE 1 290 | #define DE_LIMITL 2 291 | #define DE_LIMITH 3 292 | #define DE_ADSR_AR_L 4 293 | #define DE_ADSR_AR_E 5 294 | #define DE_ADSR_DR 6 295 | #define DE_ADSR_SL 7 296 | #define DE_ADSR_SR_L 8 297 | #define DE_ADSR_SR_E 9 298 | #define DE_ADSR_RR_L 10 299 | #define DE_ADSR_RR_E 11 300 | #define DE_ADSR_SR 12 301 | #define DE_VIB_TIME 13 302 | #define DE_PORTA_DEPTH 14 303 | #define DE_REV_TYPE 15 304 | #define DE_REV_DEPTH 16 305 | #define DE_ECHO_FB 17 306 | #define DE_ECHO_DELAY 18 307 | #define DE_DELAY 19 308 | 309 | typedef struct { 310 | void (*noteon)(); 311 | void (*programchange)(); 312 | void (*pitchbend)(); 313 | void (*metaevent)(); 314 | void (*control[13])(); 315 | void (*ccentry[20])(); 316 | } _SsFCALL; 317 | 318 | extern void _SsNoteOn(short, short, unsigned char, unsigned char); 319 | extern void _SsSetProgramChange(short, short, unsigned char); 320 | extern void _SsGetMetaEvent(short, short, unsigned char); 321 | extern void _SsSetPitchBend(short, short); 322 | extern void _SsSetControlChange(short, short, unsigned char); 323 | extern void _SsContBankChange(short, short); 324 | extern void _SsContDataEntry(short, short, unsigned char); 325 | extern void _SsContMainVol(short, short, unsigned char); 326 | extern void _SsContPanpot(short, short, unsigned char); 327 | extern void _SsContExpression(short, short, unsigned char); 328 | extern void _SsContDamper(short, short, unsigned char); 329 | extern void _SsContExternal(short, short, unsigned char); 330 | extern void _SsContNrpn1(short, short, unsigned char); 331 | extern void _SsContNrpn2(short, short, unsigned char); 332 | extern void _SsContRpn1(short, short, unsigned char); 333 | extern void _SsContRpn2(short, short, unsigned char); 334 | extern void _SsContResetAll(short, short); 335 | 336 | extern void _SsSetNrpnVabAttr0( 337 | short, short, short, VagAtr, short, unsigned char); 338 | extern void _SsSetNrpnVabAttr1( 339 | short, short, short, VagAtr, short, unsigned char); 340 | extern void _SsSetNrpnVabAttr2( 341 | short, short, short, VagAtr, short, unsigned char); 342 | extern void _SsSetNrpnVabAttr3( 343 | short, short, short, VagAtr, short, unsigned char); 344 | extern void _SsSetNrpnVabAttr4( 345 | short, short, short, VagAtr, short, unsigned char); 346 | extern void _SsSetNrpnVabAttr5( 347 | short, short, short, VagAtr, short, unsigned char); 348 | extern void _SsSetNrpnVabAttr6( 349 | short, short, short, VagAtr, short, unsigned char); 350 | extern void _SsSetNrpnVabAttr7( 351 | short, short, short, VagAtr, short, unsigned char); 352 | extern void _SsSetNrpnVabAttr8( 353 | short, short, short, VagAtr, short, unsigned char); 354 | extern void _SsSetNrpnVabAttr9( 355 | short, short, short, VagAtr, short, unsigned char); 356 | extern void _SsSetNrpnVabAttr10( 357 | short, short, short, VagAtr, short, unsigned char); 358 | extern void _SsSetNrpnVabAttr11( 359 | short, short, short, VagAtr, short, unsigned char); 360 | extern void _SsSetNrpnVabAttr12( 361 | short, short, short, VagAtr, short, unsigned char); 362 | extern void _SsSetNrpnVabAttr13( 363 | short, short, short, VagAtr, short, unsigned char); 364 | extern void _SsSetNrpnVabAttr14( 365 | short, short, short, VagAtr, short, unsigned char); 366 | extern void _SsSetNrpnVabAttr15( 367 | short, short, short, VagAtr, short, unsigned char); 368 | extern void _SsSetNrpnVabAttr16( 369 | short, short, short, VagAtr, short, unsigned char); 370 | extern void _SsSetNrpnVabAttr17( 371 | short, short, short, VagAtr, short, unsigned char); 372 | extern void _SsSetNrpnVabAttr18( 373 | short, short, short, VagAtr, short, unsigned char); 374 | extern void _SsSetNrpnVabAttr19( 375 | short, short, short, VagAtr, short, unsigned char); 376 | 377 | extern void dmy_nothing1(short, short, unsigned char, unsigned char); 378 | extern void dmy_SsNoteOn(short, short, unsigned char, unsigned char); 379 | extern void dmy_SsSetProgramChange(short, short, unsigned char); 380 | extern void dmy_SsGetMetaEvent(short, short, unsigned char); 381 | extern void dmy_SsSetPitchBend(short, short); 382 | extern void dmy_SsSetControlChange(short, short, unsigned char); 383 | extern void dmy_SsContBankChange(short, short); 384 | extern void dmy_SsContDataEntry(short, short, unsigned char); 385 | extern void dmy_SsContMainVol(short, short, unsigned char); 386 | extern void dmy_SsContPanpot(short, short, unsigned char); 387 | extern void dmy_SsContExpression(short, short, unsigned char); 388 | extern void dmy_SsContDamper(short, short, unsigned char); 389 | extern void dmy_SsContExternal(short, short, unsigned char); 390 | extern void dmy_SsContNrpn1(short, short, unsigned char); 391 | extern void dmy_SsContNrpn2(short, short, unsigned char); 392 | extern void dmy_SsContRpn1(short, short, unsigned char); 393 | extern void dmy_SsContRpn2(short, short, unsigned char); 394 | extern void dmy_SsContResetAll(short, short); 395 | extern void dmy_SsSetNrpnVabAttr0( 396 | short, short, short, VagAtr, short, unsigned char); 397 | extern void dmy_SsSetNrpnVabAttr1( 398 | short, short, short, VagAtr, short, unsigned char); 399 | extern void dmy_SsSetNrpnVabAttr2( 400 | short, short, short, VagAtr, short, unsigned char); 401 | extern void dmy_SsSetNrpnVabAttr3( 402 | short, short, short, VagAtr, short, unsigned char); 403 | extern void dmy_SsSetNrpnVabAttr4( 404 | short, short, short, VagAtr, short, unsigned char); 405 | extern void dmy_SsSetNrpnVabAttr5( 406 | short, short, short, VagAtr, short, unsigned char); 407 | extern void dmy_SsSetNrpnVabAttr6( 408 | short, short, short, VagAtr, short, unsigned char); 409 | extern void dmy_SsSetNrpnVabAttr7( 410 | short, short, short, VagAtr, short, unsigned char); 411 | extern void dmy_SsSetNrpnVabAttr8( 412 | short, short, short, VagAtr, short, unsigned char); 413 | extern void dmy_SsSetNrpnVabAttr9( 414 | short, short, short, VagAtr, short, unsigned char); 415 | extern void dmy_SsSetNrpnVabAttr10( 416 | short, short, short, VagAtr, short, unsigned char); 417 | extern void dmy_SsSetNrpnVabAttr11( 418 | short, short, short, VagAtr, short, unsigned char); 419 | extern void dmy_SsSetNrpnVabAttr12( 420 | short, short, short, VagAtr, short, unsigned char); 421 | extern void dmy_SsSetNrpnVabAttr13( 422 | short, short, short, VagAtr, short, unsigned char); 423 | extern void dmy_SsSetNrpnVabAttr14( 424 | short, short, short, VagAtr, short, unsigned char); 425 | extern void dmy_SsSetNrpnVabAttr15( 426 | short, short, short, VagAtr, short, unsigned char); 427 | extern void dmy_SsSetNrpnVabAttr16( 428 | short, short, short, VagAtr, short, unsigned char); 429 | extern void dmy_SsSetNrpnVabAttr17( 430 | short, short, short, VagAtr, short, unsigned char); 431 | extern void dmy_SsSetNrpnVabAttr18( 432 | short, short, short, VagAtr, short, unsigned char); 433 | extern void dmy_SsSetNrpnVabAttr19( 434 | short, short, short, VagAtr, short, unsigned char); 435 | 436 | extern _SsFCALL SsFCALL; 437 | 438 | #if 0 439 | jt_SsInit () 440 | { 441 | SsFCALL.noteon = _SsNoteOn; 442 | SsFCALL.programchange = _SsSetProgramChange; 443 | SsFCALL.metaevent = _SsGetMetaEvent; 444 | SsFCALL.pitchbend = _SsSetPitchBend; 445 | SsFCALL.control [CC_NUMBER] = _SsSetControlChange; 446 | SsFCALL.control [CC_BANKCHANGE] = _SsContBankChange; 447 | SsFCALL.control [CC_MAINVOL] = _SsContMainVol; 448 | SsFCALL.control [CC_PANPOT] = _SsContPanpot; 449 | SsFCALL.control [CC_EXPRESSION] = _SsContExpression; 450 | SsFCALL.control [CC_DAMPER] = _SsContDamper; 451 | SsFCALL.control [CC_NRPN1] = _SsContNrpn1; 452 | SsFCALL.control [CC_NRPN2] = _SsContNrpn2; 453 | SsFCALL.control [CC_RPN1] = _SsContRpn1; 454 | SsFCALL.control [CC_RPN2] = _SsContRpn2; 455 | SsFCALL.control [CC_EXTERNAL] = _SsContExternal; 456 | SsFCALL.control [CC_RESETALL] = _SsContResetAll; 457 | SsFCALL.control [CC_DATAENTRY] = _SsContDataEntry; 458 | SsFCALL.ccentry [DE_PRIORITY] = _SsSetNrpnVabAttr0; 459 | SsFCALL.ccentry [DE_MODE] = _SsSetNrpnVabAttr1; 460 | SsFCALL.ccentry [DE_LIMITL] = _SsSetNrpnVabAttr2; 461 | SsFCALL.ccentry [DE_LIMITH] = _SsSetNrpnVabAttr3; 462 | SsFCALL.ccentry [DE_ADSR_AR_L] = _SsSetNrpnVabAttr4; 463 | SsFCALL.ccentry [DE_ADSR_AR_E] = _SsSetNrpnVabAttr5; 464 | SsFCALL.ccentry [DE_ADSR_DR] = _SsSetNrpnVabAttr6; 465 | SsFCALL.ccentry [DE_ADSR_SL] = _SsSetNrpnVabAttr7; 466 | SsFCALL.ccentry [DE_ADSR_SR_L] = _SsSetNrpnVabAttr8; 467 | SsFCALL.ccentry [DE_ADSR_SR_E] = _SsSetNrpnVabAttr9; 468 | SsFCALL.ccentry [DE_ADSR_RR_L] = _SsSetNrpnVabAttr10; 469 | SsFCALL.ccentry [DE_ADSR_RR_E] = _SsSetNrpnVabAttr11; 470 | SsFCALL.ccentry [DE_ADSR_SR] = _SsSetNrpnVabAttr12; 471 | SsFCALL.ccentry [DE_VIB_TIME] = _SsSetNrpnVabAttr13; 472 | SsFCALL.ccentry [DE_PORTA_DEPTH] = _SsSetNrpnVabAttr14; 473 | SsFCALL.ccentry [DE_REV_TYPE] = _SsSetNrpnVabAttr15; 474 | SsFCALL.ccentry [DE_REV_DEPTH] = _SsSetNrpnVabAttr16; 475 | SsFCALL.ccentry [DE_ECHO_FB] = _SsSetNrpnVabAttr17; 476 | SsFCALL.ccentry [DE_ECHO_DELAY] = _SsSetNrpnVabAttr18; 477 | SsFCALL.ccentry [DE_DELAY] = _SsSetNrpnVabAttr19; 478 | } 479 | #endif 480 | 481 | /* ---------------------------------------------------------------- 482 | * End on File 483 | * ---------------------------------------------------------------- */ 484 | #endif /* _LIBSND_H_ */ 485 | /* DON'T ADD STUFF AFTER THIS */ 486 | -------------------------------------------------------------------------------- /include/psyq/libspu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xeeynamo/croc/f30ff1ee6721a172e270adcecab72b5b8a5e9bb1/include/psyq/libspu.h -------------------------------------------------------------------------------- /include/psyq/libtap.h: -------------------------------------------------------------------------------- 1 | /* $PSLibId: Runtime Library Release 3.7$ */ 2 | #ifndef _LIBTAP_H_ 3 | #define _LIBTAP_H_ 4 | 5 | /* 6 | * Copyright (C) 1996 Sony Computer Entertainment Inc. All Rights Reserved 7 | * libtap.h: Multi Tap Interface 8 | */ 9 | 10 | /* 11 | * Prototypes 12 | */ 13 | 14 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 15 | defined(c_plusplus) 16 | extern "C" { 17 | #endif 18 | extern long InitTAP(char*, long, char*, long); 19 | extern long StartTAP(void); 20 | extern long StopTAP(void); 21 | extern long SendTAP(char*, long, char*, long); 22 | extern void EnableTAP(void); 23 | extern void DisableTAP(void); 24 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 25 | defined(c_plusplus) 26 | } 27 | #endif 28 | #endif /* _LIBTAP_H_ */ 29 | -------------------------------------------------------------------------------- /include/psyq/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:limits.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _LIMITS_H 9 | #define _LIMITS_H 10 | /* 11 | * This file specifies the sizes of intergral types as required by the 12 | * proposed ANSI C standard. 13 | */ 14 | 15 | #define CHAR_BIT 8 16 | #define SCHAR_MIN (-128) 17 | #define SCHAR_MAX 127 18 | #define UCHAR_MAX 255 19 | #define CHAR_MIN SCHAR_MIN 20 | #define CHAR_MAX SCHAR_MAX 21 | #define SHRT_MIN (-32768) 22 | #define SHRT_MAX 32767 23 | #define USHRT_MAX 65535 24 | #define INT_MIN (-2147483648) 25 | #define INT_MAX 2147483647 26 | #define UINT_MAX 4294967295 27 | #define LONG_MIN (-2147483648) 28 | #define LONG_MAX 2147483647 29 | #define ULONG_MAX 4294967295 30 | 31 | #define USI_MAX 4294967295 /* max decimal value of an "unsigned" */ 32 | #define WORD_BIT 32 /* # of bits in a "word" or "int" */ 33 | 34 | #ifndef MB_LEN_MAX 35 | #define MB_LEN_MAX 4 36 | #endif 37 | 38 | #endif /* _LIMITS_H */ 39 | -------------------------------------------------------------------------------- /include/psyq/malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:malloc.h 3 | */ 4 | /* 5 | * $PSLibId: Run-time Library Release 3.7$ 6 | */ 7 | #ifndef _MALLOC_H 8 | #define _MALLOC_H 9 | 10 | #ifndef _SIZE_T 11 | #define _SIZE_T 12 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 13 | #endif 14 | #ifndef NULL 15 | #define NULL 0 /* null pointer constant */ 16 | #endif 17 | 18 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 19 | defined(c_plusplus) 20 | extern "C" { 21 | #endif 22 | extern void InitHeap(unsigned long*, unsigned long); 23 | extern void free(void*); 24 | extern void* malloc(size_t); 25 | extern void* calloc(size_t, size_t); 26 | extern void* realloc(void*, size_t); 27 | extern void InitHeap2(unsigned long*, unsigned long); 28 | extern void free2(void*); 29 | extern void* malloc2(size_t); 30 | extern void* calloc2(size_t, size_t); 31 | extern void* realloc2(void*, size_t); 32 | extern void InitHeap3(unsigned long*, unsigned long); 33 | extern void free3(void*); 34 | extern void* malloc3(size_t); 35 | extern void* calloc3(size_t, size_t); 36 | extern void* realloc3(void*, size_t); 37 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 38 | defined(c_plusplus) 39 | } 40 | #endif 41 | 42 | #endif /* _MALLOC_H */ 43 | -------------------------------------------------------------------------------- /include/psyq/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:memory.h 3 | * memory functions pseudo definition header 4 | */ 5 | /* 6 | * $PSLibId$ 7 | */ 8 | 9 | #ifndef _MEMORY_H 10 | #define _MEMORY_H 11 | 12 | #ifndef _SIZE_T 13 | #define _SIZE_T 14 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 15 | #endif 16 | 17 | #ifndef NULL 18 | #define NULL 0 /* null pointer constant */ 19 | #endif 20 | 21 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 22 | defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | /* To avoid conflicting */ 26 | extern void* memcpy(/* unsigned char *, unsigned char *, int */); 27 | extern void* memmove(unsigned char*, unsigned char*, int); 28 | /* To avoid conflicting */ 29 | extern int memcmp(/* unsigned char *, unsigned char *, int */); 30 | extern void* memchr(unsigned char*, unsigned char, int); 31 | extern void* memset(unsigned char*, unsigned char, int); 32 | 33 | extern void* bcopy(unsigned char*, unsigned char*, int); /* src,dest */ 34 | extern void* bzero(unsigned char*, int); 35 | extern int bcmp(unsigned char*, unsigned char*, int); 36 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 37 | defined(c_plusplus) 38 | } 39 | #endif 40 | 41 | #endif /* _MEMORY_H */ 42 | -------------------------------------------------------------------------------- /include/psyq/qsort.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:qsort.h 3 | * memory functions pseudo definition header 4 | */ 5 | /* 6 | * $PSLibId$ 7 | */ 8 | 9 | #ifndef _QSORT_H 10 | #define _QSORT_H 11 | 12 | #ifndef _SIZE_T 13 | #define _SIZE_T 14 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 15 | #endif 16 | 17 | #ifndef NULL 18 | #define NULL 0 /* null pointer constant */ 19 | #endif 20 | 21 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 22 | defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | extern void qsort(void*, size_t, size_t, int (*)()); 26 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 27 | defined(c_plusplus) 28 | } 29 | #endif 30 | 31 | #endif /* _QSORT_H */ 32 | -------------------------------------------------------------------------------- /include/psyq/r3000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:r3000.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | #ifndef _R3000_H 8 | #define _R3000_H 9 | /* 10 | * Segment base addresses and sizes 11 | */ 12 | #define K0BASE 0x80000000 13 | #define K0SIZE 0x20000000 14 | #define K1BASE 0xA0000000 15 | #define K1SIZE 0x20000000 16 | #define K2BASE 0xC0000000 17 | #define K2SIZE 0x20000000 18 | 19 | /* 20 | * Exception vectors 21 | */ 22 | #define UT_VEC K0BASE /* utlbmiss vector */ 23 | #define E_VEC (K0BASE + 0x80) /* exception vector */ 24 | #define R_VEC (K1BASE + 0x1fc00000) /* reset vector */ 25 | 26 | /* 27 | * Address conversion macros 28 | */ 29 | #define K0_TO_K1(x) ((unsigned)(x) | 0xA0000000) /* kseg0 to kseg1 */ 30 | #define K1_TO_K0(x) ((unsigned)(x) & 0x9FFFFFFF) /* kseg1 to kseg0 */ 31 | #define K0_TO_PHYS(x) ((unsigned)(x) & 0x1FFFFFFF) /* kseg0 to physical */ 32 | #define K1_TO_PHYS(x) ((unsigned)(x) & 0x1FFFFFFF) /* kseg1 to physical */ 33 | #define PHYS_TO_K0(x) ((unsigned)(x) | 0x80000000) /* physical to kseg0 */ 34 | #define PHYS_TO_K1(x) ((unsigned)(x) | 0xA0000000) /* physical to kseg1 */ 35 | 36 | /* 37 | * Address predicates 38 | */ 39 | #define IS_KSEG0(x) ((unsigned)(x) >= K0BASE && (unsigned)(x) < K1BASE) 40 | #define IS_KSEG1(x) ((unsigned)(x) >= K1BASE && (unsigned)(x) < K2BASE) 41 | #define IS_KSEG2(x) ((unsigned)(x) >= K2BASE && (unsigned)(x) < KPTEBASE) 42 | #define IS_KPTESEG(x) ((unsigned)(x) >= KPTEBASE) 43 | #define IS_KUSEG(x) ((unsigned)(x) < K0BASE) 44 | 45 | /* 46 | * Cache size constants 47 | */ 48 | #define MINCACHE +(4 * 1024) /* leading plus for mas's benefit */ 49 | #define MAXCACHE +(64 * 1024) /* leading plus for mas's benefit */ 50 | 51 | /* 52 | * Status register 53 | */ 54 | #define SR_CUMASK 0xf0000000 /* coproc usable bits */ 55 | 56 | #define SR_CU3 0x80000000 /* Coprocessor 3 usable */ 57 | #define SR_CU2 0x40000000 /* Coprocessor 2 usable */ 58 | #define SR_CU1 0x20000000 /* Coprocessor 1 usable */ 59 | #define SR_CU0 0x10000000 /* Coprocessor 0 usable */ 60 | 61 | #define SR_BEV 0x00400000 /* use boot exception vectors */ 62 | 63 | /* Cache control bits */ 64 | #define SR_TS 0x00200000 /* TLB shutdown */ 65 | #define SR_PE 0x00100000 /* cache parity error */ 66 | #define SR_CM 0x00080000 /* cache miss */ 67 | #define SR_PZ 0x00040000 /* cache parity zero */ 68 | #define SR_SWC 0x00020000 /* swap cache */ 69 | #define SR_ISC 0x00010000 /* Isolate data cache */ 70 | 71 | #define SR_MM_MODE 0x00010000 /* lwl/swl/etc become scache/etc */ 72 | #define lcache lwl 73 | #define scache swl 74 | #define flush lwr $0, 75 | #define inval swr $0, 76 | 77 | /* 78 | * Interrupt enable bits 79 | * (NOTE: bits set to 1 enable the corresponding level interrupt) 80 | */ 81 | #define SR_IMASK 0x0000ff00 /* Interrupt mask */ 82 | #define SR_IMASK8 0x00000000 /* mask level 8 */ 83 | #define SR_IMASK7 0x00008000 /* mask level 7 */ 84 | #define SR_IMASK6 0x0000c000 /* mask level 6 */ 85 | #define SR_IMASK5 0x0000e000 /* mask level 5 */ 86 | #define SR_IMASK4 0x0000f000 /* mask level 4 */ 87 | #define SR_IMASK3 0x0000f800 /* mask level 3 */ 88 | #define SR_IMASK2 0x0000fc00 /* mask level 2 */ 89 | #define SR_IMASK1 0x0000fe00 /* mask level 1 */ 90 | #define SR_IMASK0 0x0000ff00 /* mask level 0 */ 91 | 92 | #define SR_IBIT8 0x00008000 /* bit level 8 */ 93 | #define SR_IBIT7 0x00004000 /* bit level 7 */ 94 | #define SR_IBIT6 0x00002000 /* bit level 6 */ 95 | #define SR_IBIT5 0x00001000 /* bit level 5 */ 96 | #define SR_IBIT4 0x00000800 /* bit level 4 */ 97 | #define SR_IBIT3 0x00000400 /* bit level 3 */ 98 | #define SR_IBIT2 0x00000200 /* bit level 2 */ 99 | #define SR_IBIT1 0x00000100 /* bit level 1 */ 100 | 101 | #define SR_KUO 0x00000020 /* old kernel/user, 0 => k, 1 => u */ 102 | #define SR_IEO 0x00000010 /* old interrupt enable, 1 => enable */ 103 | #define SR_KUP 0x00000008 /* prev kernel/user, 0 => k, 1 => u */ 104 | #define SR_IEP 0x00000004 /* prev interrupt enable, 1 => enable */ 105 | #define SR_KUC 0x00000002 /* cur kernel/user, 0 => k, 1 => u */ 106 | #define SR_IEC 0x00000001 /* cur interrupt enable, 1 => enable */ 107 | 108 | #define SR_IMASKSHIFT 8 109 | 110 | #define SR_FMT \ 111 | "\20\40BD\26TS\25PE\24CM\23PZ\22SwC\21IsC\20IM7\17IM6\16IM5\15IM4\14IM3" \ 112 | "\13IM2\12IM1\11IM0\6KUo\5IEo\4KUp\3IEp\2KUc\1IEc" 113 | 114 | /* 115 | * Cause Register 116 | */ 117 | #define CAUSE_BD 0x80000000 /* Branch delay slot */ 118 | #define CAUSE_CEMASK 0x30000000 /* coprocessor error */ 119 | #define CAUSE_CESHIFT 28 120 | 121 | /* Interrupt pending bits */ 122 | #define CAUSE_IP8 0x00008000 /* External level 8 pending */ 123 | #define CAUSE_IP7 0x00004000 /* External level 7 pending */ 124 | #define CAUSE_IP6 0x00002000 /* External level 6 pending */ 125 | #define CAUSE_IP5 0x00001000 /* External level 5 pending */ 126 | #define CAUSE_IP4 0x00000800 /* External level 4 pending */ 127 | #define CAUSE_IP3 0x00000400 /* External level 3 pending */ 128 | #define CAUSE_SW2 0x00000200 /* Software level 2 pending */ 129 | #define CAUSE_SW1 0x00000100 /* Software level 1 pending */ 130 | 131 | #define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */ 132 | #define CAUSE_IPSHIFT 8 133 | 134 | #define CAUSE_EXCMASK 0x0000003C /* Cause code bits */ 135 | #define CAUSE_EXCSHIFT 2 136 | 137 | #define CAUSE_FMT \ 138 | "\20\40BD\36CE1\35CE0\20IP8\17IP7\16IP6\15IP5\14IP4\13IP3\12SW2\11SW1\1IN" \ 139 | "T" 140 | 141 | /* Cause register exception codes */ 142 | 143 | #define EXC_CODE(x) ((x) << 2) 144 | 145 | /* Hardware exception codes */ 146 | #define EXC_INT EXC_CODE(0) /* interrupt */ 147 | #define EXC_MOD EXC_CODE(1) /* TLB mod */ 148 | #define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */ 149 | #define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */ 150 | #define EXC_RADE EXC_CODE(4) /* Read Address Error */ 151 | #define EXC_WADE EXC_CODE(5) /* Write Address Error */ 152 | #define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */ 153 | #define EXC_DBE EXC_CODE(7) /* Data Bus Error */ 154 | #define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */ 155 | #define EXC_BREAK EXC_CODE(9) /* BREAKpoint */ 156 | #define EXC_II EXC_CODE(10) /* Illegal Instruction */ 157 | #define EXC_CPU EXC_CODE(11) /* CoProcessor Unusable */ 158 | #define EXC_OV EXC_CODE(12) /* OVerflow */ 159 | 160 | /* software exception codes */ 161 | #define SEXC_SEGV EXC_CODE(16) /* Software detected seg viol */ 162 | #define SEXC_RESCHED EXC_CODE(17) /* resched request */ 163 | #define SEXC_PAGEIN EXC_CODE(18) /* page-in request */ 164 | #define SEXC_CPU EXC_CODE(19) /* coprocessor unusable */ 165 | 166 | /* 167 | * Coprocessor 0 registers 168 | */ 169 | #define C0_INX $0 /* tlb index */ 170 | #define C0_RAND $1 /* tlb random */ 171 | #define C0_TLBLO $2 /* tlb entry low */ 172 | 173 | #define C0_CTXT $4 /* tlb context */ 174 | 175 | #define C0_PIDMASK $6 /* Mips2 */ 176 | 177 | #define C0_BADVADDR $8 /* bad virtual address */ 178 | 179 | #define C0_TLBHI $10 /* tlb entry hi */ 180 | #define C0_PID $10 /* Mips2 */ 181 | 182 | #define C0_SR $12 /* status register */ 183 | #define C0_CAUSE $13 /* exception cause */ 184 | #define C0_EPC $14 /* exception pc */ 185 | #define C0_PRID $15 /* revision identifier */ 186 | #define C0_ERREG $16 /* Mips2 */ 187 | 188 | /* 189 | * Coprocessor 0 operations 190 | */ 191 | #define C0_READI 0x1 /* read ITLB entry addressed by C0_INDEX */ 192 | #define C0_WRITEI 0x2 /* write ITLB entry addressed by C0_INDEX */ 193 | #define C0_WRITER 0x6 /* write ITLB entry addressed by C0_RAND */ 194 | #define C0_PROBE 0x8 /* probe for ITLB entry addressed by TLBHI */ 195 | #define C0_RFE 0x10 /* restore for exception */ 196 | 197 | /* 198 | * Flags for the nofault handler. 0 means no fault is expected. 199 | */ 200 | #define NF_BADADDR 1 /* badaddr, wbadaddr */ 201 | #define NF_COPYIO 2 /* copyin, copyout */ 202 | #define NF_ADDUPC 3 /* addupc */ 203 | #define NF_FSUMEM 4 /* fubyte, subyte, fuword, suword */ 204 | #define NF_USERACC 5 /* useracc */ 205 | #define NF_SOFTFP 6 /* softfp */ 206 | #define NF_REVID 7 /* revision ids */ 207 | #define NF_NENTRIES 8 208 | 209 | /* 210 | * TLB size constants 211 | */ 212 | #define TLBWIREDBASE 0 /* WAG for now */ 213 | #define NWIREDENTRIES 8 /* WAG for now */ 214 | #define TLBRANDOMBASE NWIREDENTRIES 215 | #define NRANDOMENTRIES (NTLBENTRIES - NWIREDENTRIES) 216 | #define NTLBENTRIES 64 /* WAG for now */ 217 | 218 | #define TLBRAND_RANDMASK 0x00003f00 219 | #define TLBRAND_RANDSHIFT 8 220 | 221 | /* 222 | * Chip interrupt vector 223 | */ 224 | #define NC0VECS 8 225 | #ifndef LOCORE 226 | #ifdef KERNEL 227 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 228 | defined(c_plusplus) 229 | extern "C" { 230 | #endif 231 | extern int (*c0vec_tbl[])(); 232 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 233 | defined(c_plusplus) 234 | } 235 | #endif 236 | #endif 237 | #endif !LOCORE 238 | 239 | #define BRK_KERNEL 0xf1 240 | #define EXCEPT_NORM 1 241 | #define EXCEPT_UTLB 2 242 | #define EXCEPT_BRKPT 3 243 | #define EXCEPT_DB 4 244 | #define EXCEPT_GDB 4 245 | #define EXCEPT_INT 9 246 | #define EXCEPT_ELSE 0xff 247 | #endif /* _R3000_H */ 248 | -------------------------------------------------------------------------------- /include/psyq/rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:rand.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _RAND_H 9 | #define _RAND_H 10 | 11 | #define RAND_MAX 32767 12 | 13 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 14 | defined(c_plusplus) 15 | extern "C" { 16 | #endif 17 | extern int rand(void); 18 | extern void srand(unsigned int); 19 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 20 | defined(c_plusplus) 21 | } 22 | #endif 23 | 24 | #endif /* _RAND_H */ 25 | -------------------------------------------------------------------------------- /include/psyq/romio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * romio.h 3 | * 4 | * rom monitor i/o 5 | */ 6 | /* 7 | * $PSLibId$ 8 | */ 9 | 10 | #ifndef _ROMIO_H 11 | #define _ROMIO_H 12 | 13 | #include 14 | 15 | #endif /* _ROMIO_H */ 16 | -------------------------------------------------------------------------------- /include/psyq/setjmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId$ 3 | */ 4 | /* 5 | * File:setjmp.h 6 | * simple non-local-jump for single task environment 7 | */ 8 | 9 | #ifndef _SETJMP_H 10 | #define _SETJMP_H 11 | 12 | /* jmp_buf indices */ 13 | #define JB_PC 0 14 | #define JB_SP 1 15 | #define JB_FP 2 16 | #define JB_S0 3 17 | #define JB_S1 4 18 | #define JB_S2 5 19 | #define JB_S3 6 20 | #define JB_S4 7 21 | #define JB_S5 8 22 | #define JB_S6 9 23 | #define JB_S7 10 24 | #define JB_GP 11 25 | 26 | #define JB_SIZE 12 27 | 28 | #if defined(LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) || \ 29 | defined(__cplusplus) || defined(c_plusplus) 30 | typedef int jmp_buf[JB_SIZE]; 31 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 32 | defined(c_plusplus) 33 | extern "C" { 34 | #endif 35 | extern int setjmp(jmp_buf); 36 | extern void longjmp(jmp_buf, int); 37 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 38 | defined(c_plusplus) 39 | } 40 | #endif 41 | #endif 42 | 43 | #endif /* _SETJMP_H */ 44 | -------------------------------------------------------------------------------- /include/psyq/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:stdarg.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _STDARG_H 9 | #define _STDARG_H 10 | 11 | #define __va_rounded_size(TYPE) \ 12 | (((sizeof(TYPE) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) 13 | 14 | #define va_start(AP, LASTARG) \ 15 | (AP = ((char*)&(LASTARG) + __va_rounded_size(LASTARG))) 16 | 17 | #define va_end(AP) AP = (char*)NULL 18 | 19 | #define va_arg(AP, TYPE) \ 20 | (AP = ((char*)(AP)) += __va_rounded_size(TYPE), \ 21 | *((TYPE*)((char*)(AP)-__va_rounded_size(TYPE)))) 22 | 23 | typedef void* va_list; 24 | 25 | #endif /* _STDARG_H */ 26 | -------------------------------------------------------------------------------- /include/psyq/stddef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:stddef.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _STDDEF_H 9 | #define _STDDEF_H 10 | 11 | #ifndef _SIZE_T 12 | #define _SIZE_T 13 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 14 | #endif 15 | 16 | #ifndef _WCHAR_T 17 | #define _WCHAR_T 18 | typedef unsigned long wchar_t; /* type of a wide character */ 19 | #endif 20 | 21 | #ifndef _UCHAR_T 22 | #define _UCHAR_T 23 | typedef unsigned char u_char; 24 | #endif 25 | 26 | #ifndef _USHORT_T 27 | #define _USHORT_T 28 | typedef unsigned short u_short; 29 | #endif 30 | 31 | #ifndef _UINT_T 32 | #define _UINT_T 33 | typedef unsigned int u_int; 34 | #endif 35 | 36 | #ifndef _ULONG_T 37 | #define _ULONG_T 38 | typedef unsigned long u_long; 39 | #endif 40 | 41 | #ifndef WEOF 42 | #define WEOF 0xffffffff 43 | #endif 44 | 45 | #ifndef NULL 46 | #define NULL 0 /* null pointer constant */ 47 | #endif 48 | 49 | #endif /* _STDDEF_H */ 50 | -------------------------------------------------------------------------------- /include/psyq/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $PSLibId$ 3 | */ 4 | /* 5 | * File:stdio.h 6 | */ 7 | 8 | #ifndef _STDIO_H 9 | #define _STDIO_H 10 | 11 | #define BUFSIZ 1024 12 | #define EOF (-1) 13 | 14 | #ifndef SEEK_SET 15 | #define SEEK_SET 0 16 | #endif 17 | #ifndef SEEK_CUR 18 | #define SEEK_CUR 1 19 | #endif 20 | #ifndef SEEK_END 21 | #define SEEK_END 2 22 | #endif 23 | 24 | #ifndef _SIZE_T 25 | #define _SIZE_T 26 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 27 | #endif 28 | 29 | /* under constraction now */ 30 | 31 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 32 | defined(c_plusplus) 33 | extern "C" { 34 | #endif 35 | extern int printf(char* fmt, ...); /**/ 36 | extern int sprintf(char* buffer, char* fmt, ...); 37 | 38 | extern char getc(int); /**/ 39 | extern char getchar(void); 40 | extern char* gets(char*); 41 | extern void putc(char, int); /**/ 42 | extern void putchar(char); 43 | extern void puts(char*); 44 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 45 | defined(c_plusplus) 46 | } 47 | #endif 48 | 49 | #endif /* _STDIO_H */ 50 | -------------------------------------------------------------------------------- /include/psyq/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:stdlib.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _STDLIB_H 9 | #define _STDLIB_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 19 | defined(c_plusplus) 20 | extern "C" { 21 | #endif 22 | 23 | extern void* bsearch(unsigned char*, unsigned char*, size_t, size_t, int (*)()); 24 | extern void exit(); 25 | 26 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 27 | defined(c_plusplus) 28 | } 29 | #endif 30 | 31 | #endif /* _STDLIB_H */ 32 | -------------------------------------------------------------------------------- /include/psyq/string.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_H 2 | #define _STRING_H 3 | 4 | /***************************************************************** 5 | * -*- c -*- 6 | * $RCSfile: string.h,v $ 7 | * 8 | * Copyright (C) 1994, 1995 by Sony Computer Entertainment Inc. 9 | * All Rights Reserved. 10 | * 11 | * Sony Computer Entertainment Inc. R & D Division 12 | * 13 | * $Id: string.h,v 1.1 1995/04/04 12:30:26 kaol Exp $ 14 | * 15 | *****************************************************************/ 16 | /* 17 | * $PSLibId$ 18 | */ 19 | 20 | #include 21 | 22 | /* ---------------------------------------------------------------- 23 | * End on File 24 | * ---------------------------------------------------------------- */ 25 | #endif /* _STRING_H_ */ 26 | /* DON'T ADD STUFF AFTER THIS */ 27 | -------------------------------------------------------------------------------- /include/psyq/strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:strings.h 3 | * string functions pseudo definition header 4 | */ 5 | /* 6 | * $PSLibId$ 7 | */ 8 | 9 | #ifndef _STRINGS_H 10 | #define _STRINGS_H 11 | 12 | #define LMAX 256 13 | 14 | #ifndef NULL 15 | #define NULL 0 /* null pointer constant */ 16 | #endif 17 | 18 | #ifndef _SIZE_T 19 | #define _SIZE_T 20 | typedef unsigned int size_t; /* result type of the sizeof operator (ANSI) */ 21 | #endif 22 | 23 | #include 24 | 25 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 26 | defined(c_plusplus) 27 | extern "C" { 28 | #endif 29 | extern char* strcat(char*, char*); 30 | extern char* strncat(char*, char*, int); 31 | extern int strcmp(/* char *, char * */); /* To avoid conflicting */ 32 | extern int strncmp(char*, char*, int); 33 | extern char* strcpy(/* char *, char * */); /* To avoid conflicting */ 34 | extern char* strncpy(char*, char*, int); 35 | extern int strlen(/* char * */); /* To avoid conflicting */ 36 | extern char* index(char*, char); 37 | extern char* rindex(char*, char); 38 | 39 | extern char* strchr(char*, char); 40 | extern char* strrchr(char*, char); 41 | extern char* strpbrk(char*, char*); 42 | extern int strspn(char*, char*); 43 | extern int strcspn(char*, char*); 44 | extern char* strtok(char*, char*); 45 | extern char* strstr(char*, char*); 46 | #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || \ 47 | defined(c_plusplus) 48 | } 49 | #endif 50 | 51 | #define strdup(p) (strcpy(malloc(strlen(p) + 1), p);) 52 | 53 | #endif /* _STRINGS_H */ 54 | -------------------------------------------------------------------------------- /include/psyq/sys/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Error codes 3 | * $RCSfile: errno.h,v $ 4 | * $Id: errno.h,v 1.4 1995/04/04 12:28:55 kaol Exp $ 5 | */ 6 | /* 7 | * $PSLibId$ 8 | */ 9 | 10 | #ifndef _ERRNO_H 11 | #define _ERRNO_H 12 | 13 | /* Error codes */ 14 | 15 | #define EPERM 1 /* Not owner */ 16 | #define ENOENT 2 /* No such file or directory */ 17 | #define ESRCH 3 /* No such process */ 18 | #define EINTR 4 /* Interrupted system call */ 19 | #define EIO 5 /* I/O error */ 20 | #define ENXIO 6 /* No such device or address */ 21 | #define E2BIG 7 /* Arg list too long */ 22 | #define ENOEXEC 8 /* Exec format error */ 23 | #define EBADF 9 /* Bad file number */ 24 | #define ECHILD 10 /* No children */ 25 | #define EAGAIN 11 /* No more processes */ 26 | #define ENOMEM 12 /* Not enough core */ 27 | #define EACCES 13 /* Permission denied */ 28 | #define EFAULT 14 /* Bad address */ 29 | #define ENOTBLK 15 /* Block device required */ 30 | #define EBUSY 16 /* Mount device busy */ 31 | #define EEXIST 17 /* File exists */ 32 | #define EXDEV 18 /* Cross-device link */ 33 | #define ENODEV 19 /* No such device */ 34 | #define ENOTDIR 20 /* Not a directory*/ 35 | #define EISDIR 21 /* Is a directory */ 36 | #define EINVAL 22 /* Invalid argument */ 37 | #define ENFILE 23 /* File table overflow */ 38 | #define EMFILE 24 /* Too many open files */ 39 | #define ENOTTY 25 /* Not a typewriter */ 40 | #define ETXTBSY 26 /* Text file busy */ 41 | #define EFBIG 27 /* File too large */ 42 | #define ENOSPC 28 /* No space left on device */ 43 | #define ESPIPE 29 /* Illegal seek */ 44 | #define EROFS 30 /* Read-only file system */ 45 | #define EFORMAT 31 /* Bad file format */ 46 | #define EPIPE 32 /* Broken pipe */ 47 | 48 | /* math software */ 49 | #define EDOM 33 /* Argument too large */ 50 | #define ERANGE 34 /* Result too large */ 51 | 52 | /* non-blocking and interrupt i/o */ 53 | #define EWOULDBLOCK 35 /* Operation would block */ 54 | #define EINPROGRESS 36 /* Operation now in progress */ 55 | #define EALREADY 37 /* Operation already in progress */ 56 | 57 | extern int errno; 58 | 59 | #endif /* _ERRNO_H */ 60 | -------------------------------------------------------------------------------- /include/psyq/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:fcntl.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _SYS_FCNTL_H 9 | #define _SYS_FCNTL_H 10 | 11 | /* flags */ 12 | #define FREAD 0x0001 /* readable */ 13 | #define FWRITE 0x0002 /* writable */ 14 | #define FNBLOCK 0x0004 /* non-blocking reads */ 15 | #define FRLOCK 0x0010 /* read locked (non-shared) */ 16 | #define FWLOCK 0x0020 /* write locked (non-shared) */ 17 | #define FAPPEND 0x0100 /* append on each write */ 18 | #define FCREAT 0x0200 /* create if nonexistant */ 19 | #define FTRUNC 0x0400 /* truncate to zero length */ 20 | #define FSCAN 0x1000 /* scan type */ 21 | #define FRCOM 0x2000 /* remote command entry */ 22 | #define FNBUF 0x4000 /* no ring buf. and console interrupt */ 23 | #define FASYNC 0x8000 /* asyncronous i/o */ 24 | 25 | #endif /* _SYS_FCNTL_H */ 26 | -------------------------------------------------------------------------------- /include/psyq/sys/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:file.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _SYS_FILE_H 9 | #define _SYS_FILE_H 10 | 11 | #include 12 | 13 | /* Flag for open() */ 14 | #define O_RDONLY FREAD 15 | #define O_WRONLY FWRITE 16 | #define O_RDWR FREAD | FWRITE 17 | #define O_CREAT FCREAT /* open with file create */ 18 | #define O_NOBUF FNBUF /* no device buffer and console interrupt */ 19 | #define O_NBLOCK FNBLOCK /* non blocking mode */ 20 | #define O_NOWAIT FASYNC /* asyncronous i/o */ 21 | 22 | #ifndef SEEK_SET 23 | #define SEEK_SET 0 24 | #endif 25 | #ifndef SEEK_CUR 26 | #define SEEK_CUR 1 27 | #endif 28 | #ifndef SEEK_END 29 | #define SEEK_END 2 30 | #endif 31 | 32 | #endif /* _SYS_FILE_H */ 33 | -------------------------------------------------------------------------------- /include/psyq/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:ioctl.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _SYS_IOCTL_H 9 | #define _SYS_IOCTL_H 10 | 11 | #ifndef NULL 12 | #define NULL 0 13 | #endif 14 | 15 | #ifndef EOF 16 | #define EOF (-1) /* EOF from getc() */ 17 | #endif 18 | 19 | /* general */ 20 | #define FIOCNBLOCK (('f' << 8) | 1) /* set non-blocking io */ 21 | #define FIOCSCAN (('f' << 8) | 2) /* scan for input */ 22 | 23 | /* tty and sio */ 24 | #define TIOCRAW (('t' << 8) | 1) /* disable xon/xoff control */ 25 | #define TIOCFLUSH (('t' << 8) | 2) /* flush input buffer */ 26 | #define TIOCREOPEN (('t' << 8) | 3) /* reopen */ 27 | #define TIOCBAUD (('t' << 8) | 4) /* set baud rate */ 28 | #define TIOCEXIT (('t' << 8) | 5) /* console interrup */ 29 | #define TIOCDTR (('t' << 8) | 6) /* control DTR line */ 30 | #define TIOCRTS (('t' << 8) | 7) /* control RTS line */ 31 | #define TIOCLEN (('t' << 8) | 8) /* stop<<16 | char */ 32 | /* stop 0:none 1:1 2:1.5 3:2bit */ 33 | /* char 0:5 1:6 2:7 3:8bit */ 34 | #define TIOCPARITY (('t' << 8) | 9) /* parity 0:none 1:e 3:o */ 35 | #define TIOSTATUS (('t' << 8) | 10) /* return status */ 36 | #define TIOERRRST (('t' << 8) | 11) /* error reset */ 37 | #define TIOEXIST (('t' << 8) | 12) /* exist test with DTR/CTS */ 38 | #define TIORLEN (('t' << 8) | 13) /* receive buffer length */ 39 | 40 | /* disk */ 41 | #define DIOFORMAT (('d' << 8) | 1) /* format */ 42 | 43 | #endif /* _SYS_IOCTL_H */ 44 | -------------------------------------------------------------------------------- /include/psyq/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File:types.h 3 | */ 4 | /* 5 | * $PSLibId$ 6 | */ 7 | 8 | #ifndef _SYS_TYPES_H 9 | #define _SYS_TYPES_H 10 | 11 | /* 12 | * Basic system types and major/minor device constructing/busting macros. 13 | */ 14 | 15 | /* major part of a device */ 16 | #define major(x) ((int)(((unsigned)(x) >> 8) & 0377)) 17 | 18 | /* minor part of a device */ 19 | #define minor(x) ((int)((x) & 0377)) 20 | 21 | /* make a device number */ 22 | #define makedev(x, y) ((dev_t)(((x) << 8) | (y))) 23 | 24 | #ifndef _UCHAR_T 25 | #define _UCHAR_T 26 | typedef unsigned char u_char; 27 | #endif 28 | #ifndef _USHORT_T 29 | #define _USHORT_T 30 | typedef unsigned short u_short; 31 | #endif 32 | #ifndef _UINT_T 33 | #define _UINT_T 34 | typedef unsigned int u_int; 35 | #endif 36 | #ifndef _ULONG_T 37 | #define _ULONG_T 38 | typedef unsigned long u_long; 39 | #endif 40 | #ifndef _SYSIII_USHORT 41 | #define _SYSIII_USHORT 42 | typedef unsigned short ushort; /* sys III compat */ 43 | #endif 44 | #ifndef __psx__ 45 | #ifndef _SYSV_UINT 46 | #define _SYSV_UINT 47 | typedef unsigned int uint; /* sys V compat */ 48 | #endif 49 | #ifndef _SYSV_ULONG 50 | #define _SYSV_ULONG 51 | typedef unsigned long ulong; /* sys V compat */ 52 | #endif 53 | #endif /* ! __psx__ */ 54 | 55 | typedef struct _physadr { 56 | int r[1]; 57 | }* physadr; 58 | typedef struct label_t { 59 | int val[12]; 60 | } label_t; 61 | 62 | typedef struct _quad { 63 | long val[2]; 64 | } quad; 65 | typedef long daddr_t; 66 | typedef char* caddr_t; 67 | typedef long* qaddr_t; /* should be typedef quad * qaddr_t; */ 68 | typedef u_long ino_t; 69 | typedef long swblk_t; 70 | 71 | #ifndef _SIZE_T 72 | #define _SIZE_T 73 | typedef unsigned int size_t; 74 | #endif 75 | 76 | typedef long time_t; 77 | typedef short dev_t; 78 | typedef long off_t; 79 | typedef u_short uid_t; 80 | typedef u_short gid_t; 81 | 82 | #define NBBY 8 /* number of bits in a byte */ 83 | 84 | #endif /* _SYS_TYPES_H */ 85 | -------------------------------------------------------------------------------- /include/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #ifndef VERSION_PC 5 | typedef char int8_t; 6 | typedef short int16_t; 7 | typedef int int32_t; 8 | typedef long long int64_t; 9 | typedef unsigned char uint8_t; 10 | typedef unsigned short uint16_t; 11 | typedef unsigned int uint32_t; 12 | typedef unsigned long long uint64_t; 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #ifdef _MSC_VER 19 | typedef unsigned char u_char; 20 | typedef unsigned short u_short; 21 | typedef unsigned long long u_long; 22 | #endif 23 | 24 | typedef signed char s8; 25 | typedef signed short s16; 26 | typedef signed int s32; 27 | typedef signed long long s64; 28 | typedef unsigned char u8; 29 | typedef unsigned short u16; 30 | typedef unsigned int u32; 31 | typedef unsigned long long u64; 32 | 33 | typedef signed char byte; 34 | typedef enum { false, true } bool; 35 | 36 | #ifndef NULL 37 | #define NULL (0) 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tools/decompile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import argparse 4 | import io 5 | import os 6 | import subprocess 7 | import tempfile 8 | from contextlib import redirect_stdout 9 | from pathlib import Path 10 | import re 11 | from enum import Enum 12 | import m2ctx 13 | import m2c.m2c.main as m2c 14 | 15 | 16 | # gets the root directory of the project 17 | # the way it works is that it looks for the directory 'src' 18 | def get_root_dir(): 19 | def search_root_dir(base_dir): 20 | for dir in os.listdir(base_dir): 21 | if os.path.isdir(dir) and dir == "src": 22 | return os.path.normpath(base_dir) 23 | return search_root_dir(os.path.join(base_dir, "..")) 24 | 25 | script_dir = os.path.dirname(os.path.realpath(__file__)) 26 | return search_root_dir(base_dir=script_dir) 27 | 28 | 29 | def get_all_c_files(src_dir): 30 | c_files_list = list() 31 | for root, dirs, files in os.walk(src_dir): 32 | for f in files: 33 | if f.endswith(".c"): 34 | c_files_list.append(os.path.join(root, f)) 35 | return c_files_list 36 | 37 | 38 | # global variables 39 | root_dir = get_root_dir() 40 | asm_dir = os.path.join(root_dir, "asm") 41 | src_dir = os.path.join(root_dir, "src") 42 | src_files = get_all_c_files(src_dir) 43 | 44 | 45 | class NonMatchingFunc(object): 46 | def __init__(self, nonmatching_path): 47 | split = nonmatching_path.split("/") 48 | 49 | self.asm_path = nonmatching_path 50 | self.name = os.path.splitext(os.path.basename(nonmatching_path))[0] 51 | self.overlay_name = split[split.index("nonmatchings") - 1] 52 | self.text_offset = split[split.index("nonmatchings") + 1] 53 | 54 | assumed_path = "/".join(split[split.index("nonmatchings") + 1 : -1]) + ".c" 55 | c_paths = [src for src in src_files if src.endswith(assumed_path)] 56 | assert len(c_paths) == 1 57 | self.src_path = c_paths[0] 58 | 59 | 60 | def get_nonmatching_functions(base_path, func_name) -> list: 61 | function_list = list() 62 | for root, dirs, files in os.walk(base_path): 63 | if "/nonmatchings/" in root: 64 | for f in files: 65 | if f == f"{func_name}.s": 66 | full_path = os.path.join(root, f) 67 | function = NonMatchingFunc(full_path) 68 | function_list.append(function) 69 | return function_list 70 | 71 | 72 | def get_c_context(src_file) -> str: 73 | return m2ctx.import_c_file(src_file) 74 | 75 | 76 | def run_m2c(func: NonMatchingFunc, ctx_str: str): 77 | with tempfile.NamedTemporaryFile( 78 | mode="w", encoding="utf-8", suffix=".c" 79 | ) as tmp_ctx: 80 | tmp_ctx.writelines(ctx_str) 81 | tmp_ctx.flush() 82 | options = m2c.parse_flags( 83 | [ 84 | "-P", 85 | "4", 86 | "--pointer-style", 87 | "left", 88 | "--knr", 89 | "--indent-switch-contents", 90 | "--comment-style", 91 | "oneline", 92 | "--target", 93 | "mipsel-gcc-c", 94 | "--context", 95 | tmp_ctx.name, 96 | func.asm_path, 97 | ] 98 | ) 99 | 100 | with redirect_stdout(io.StringIO()) as f: 101 | m2c.run(options) 102 | return f.getvalue() 103 | 104 | 105 | def guess_unknown_type(dec: str) -> str: 106 | ret = "" 107 | for line in dec.splitlines(): 108 | if line.find("?") == -1: 109 | line = line 110 | elif line.startswith("? func"): 111 | line = line.replace("? func_", "/*?*/ void func_") 112 | elif line.startswith("extern ? D_"): 113 | line = line.replace("extern ? D_", "extern /*?*/s32 D_") 114 | elif line.startswith("extern ?* D_"): 115 | line = line.replace("extern ?* D_", "extern /*?*/u8* D_") 116 | ret += line + "\n" 117 | return ret 118 | 119 | 120 | class InjectRes(Enum): 121 | SUCCESS = 0 122 | NOT_INJECTED = 1 123 | NOT_COMPILABLE = 2 124 | NON_MATCHING = 3 125 | UNKNOWN_ERROR = -1 126 | 127 | 128 | # check if the overlay can be compiled 129 | def check_injected_code(func) -> InjectRes: 130 | compile_result = subprocess.run( 131 | f"make {func.overlay_name}", 132 | cwd=root_dir, 133 | shell=True, 134 | check=False, 135 | capture_output=True, 136 | ) 137 | if compile_result.returncode == 0: 138 | # good news, the code was compilable 139 | # now checking for the checksum... 140 | check_result = subprocess.run( 141 | "make check", cwd=root_dir, shell=True, check=False, capture_output=True 142 | ) 143 | if check_result.returncode == 0: 144 | # decompilation successful! There is nothing else to do 145 | return InjectRes.SUCCESS 146 | else: 147 | return InjectRes.NON_MATCHING 148 | else: 149 | return InjectRes.NOT_COMPILABLE 150 | 151 | 152 | def inject_decompiled_function_into_file(func: NonMatchingFunc, dec: str) -> InjectRes: 153 | with open(func.src_path) as file: 154 | lines = [line.rstrip() for line in file] 155 | 156 | # this portion of code NEEDS to be resiliant; if there is an exception 157 | # while writing the file content, the original source code where the 158 | # function is supposed to be injected will be lost. 159 | try: 160 | # assume function matches 161 | found = False 162 | newcode = "" 163 | for line in lines: 164 | if line.startswith("INCLUDE_ASM(") and func.name in line: 165 | newcode += dec 166 | found = True 167 | else: 168 | newcode += line + "\n" 169 | with open(func.src_path, "w") as file: 170 | file.writelines(newcode) 171 | 172 | if not found: 173 | return InjectRes.NOT_INJECTED 174 | result = check_injected_code(func) 175 | if result == InjectRes.SUCCESS: 176 | return result 177 | 178 | newcode = "" 179 | for line in lines: 180 | if line.startswith("INCLUDE_ASM(") and func.name in line: 181 | newcode += "//#ifndef NON_MATCHING\n" 182 | newcode += f"//{line}\n" 183 | newcode += "//#else\n" 184 | newcode += dec 185 | newcode += "//#endif\n" 186 | else: 187 | newcode += line + "\n" 188 | with open(func.src_path, "w") as file: 189 | file.writelines(newcode) 190 | 191 | return result 192 | 193 | except Exception as e: 194 | with open(func.src_path, "w") as file: 195 | for line in lines: 196 | file.write(line) 197 | file.write("\n") 198 | raise e 199 | 200 | 201 | def show_asm_differ_command(func: NonMatchingFunc): 202 | isStage = True 203 | if ( 204 | func.overlay_name == "dra" 205 | or func.overlay_name == "ric" 206 | or func.overlay_name.startswith("tt_") 207 | or func.overlay_name == "main" 208 | ): 209 | isStage = False 210 | 211 | tool_path = os.path.join(root_dir, "tools/asm-differ/diff.py") 212 | tool_path = os.path.relpath(tool_path) 213 | overlay_name = f"st/{func.overlay_name}" if isStage else func.overlay_name 214 | print(f"python3 {tool_path} -mwo --overlay {overlay_name} {func.name}") 215 | 216 | 217 | def resolve_jumptables(func: NonMatchingFunc): 218 | filepath = func.asm_path 219 | with open(filepath, "r+") as asm_file: 220 | lines = asm_file.readlines() 221 | for i, line in enumerate(lines): 222 | if "jr" in line and "$ra" not in line: 223 | print(f"\nJump table call at line {i}") 224 | jumpreg = line.split()[-1] 225 | if "nop" not in lines[i - 1]: 226 | break 227 | print("good nop") 228 | # Build a regex to search for the standard jump table setup 229 | lw_regex = "lw\s*\\" + jumpreg + ", %lo\(([^)]*)\)\(\$at\)" 230 | lwcheck = re.search(lw_regex, lines[i - 2]) 231 | if lwcheck == None: 232 | break 233 | jumptable_name = lwcheck.group(1) 234 | print(f"Jumptable: {jumptable_name}") 235 | addu_regex = "addu\s*\$at, \$at, \$" 236 | adducheck = re.search(addu_regex, lines[i - 3]) 237 | if adducheck == None: 238 | print("Couldn't get the addu") 239 | print(lines[i - 3]) 240 | break 241 | print("Good addu") 242 | lui_regex = "lui\s*\$at, %hi\(" + jumptable_name + "\)" 243 | luicheck = re.search(lui_regex, lines[i - 4]) 244 | if luicheck == None: 245 | break 246 | print("Good lui") 247 | # Confirmed the jump table is as expected. Now find it. 248 | # Look in all rodata and data files. 249 | paths = list(Path("asm").rglob("*.rodata.s")) 250 | paths += list(Path("asm").rglob("*.data.s")) 251 | for rodata_file in paths: 252 | with open(rodata_file) as f: 253 | rodata = f.read() 254 | if jumptable_name in rodata: 255 | print("Found jump table in rodata") 256 | all_rodata_lines = rodata.split("\n") 257 | outlines = [".section .rodata"] 258 | for line in all_rodata_lines: 259 | if jumptable_name in line or len(outlines) > 1: 260 | outlines.append(line) 261 | if len(line) == 0: 262 | print("Outputting") 263 | print(outlines) 264 | asm_file.write("\n".join(outlines)) 265 | break 266 | 267 | 268 | def decompile(func_name: str, number_occurrence: int = None, force: bool = False): 269 | funcs = get_nonmatching_functions(asm_dir, func_name) 270 | if len(funcs) == 0: 271 | print(f"function {func_name} not found or already decompiled") 272 | 273 | if force: 274 | funcs = funcs[:1] 275 | elif number_occurrence and number_occurrence < len(funcs): 276 | funcs = [funcs[number_occurrence]] 277 | else: 278 | if len(funcs) > 1: 279 | print( 280 | f"{len(funcs)} occurrences found for '{func_name}' in the following overlays:" 281 | ) 282 | for n, func in enumerate(funcs): 283 | print(f"[{n}] {func.overlay_name} at {func.asm_path}") 284 | print("invoke this decompiler again with the -n or -f parameter.") 285 | os._exit(-1) 286 | func = funcs[0] 287 | 288 | # print(f"func: {func.name}") 289 | # print(f"overlay: {func.overlay_name}") 290 | # print(f"text: {func.text_offset}") 291 | # print(f"asm: {func.asm_path}") 292 | # print(f"src: {func.src_path}") 293 | resolve_jumptables(func) 294 | 295 | ctx = get_c_context(func.src_path) 296 | dec = run_m2c(func, ctx) 297 | dec_res = guess_unknown_type(dec) 298 | inject_res = inject_decompiled_function_into_file(func, dec_res) 299 | if inject_res == InjectRes.SUCCESS: 300 | print(f"function '{func.name}' decompiled successfully!") 301 | elif inject_res == InjectRes.NON_MATCHING: 302 | print(f"function '{func.name}' decompiled but not matching") 303 | show_asm_differ_command(func) 304 | elif inject_res == InjectRes.NOT_COMPILABLE: 305 | print(f"function '{func.name}' decompiled but cannot be compiled") 306 | show_asm_differ_command(func) 307 | elif inject_res == InjectRes.NOT_INJECTED: 308 | print(f"function '{func.name}' might already be decompiled") 309 | else: 310 | print("unhandled error!") 311 | 312 | 313 | if __name__ == "__main__": 314 | parser = argparse.ArgumentParser(description="automatically decompiles a function") 315 | parser.add_argument("function", help="function name to decompile") 316 | parser.add_argument( 317 | "-n", 318 | "--number-occurrence", 319 | help="the occurrence number in case multiple functions with the same name are found", 320 | type=int, 321 | default=None, 322 | required=False, 323 | ) 324 | parser.add_argument( 325 | "-f", 326 | "--force", 327 | help="force decompiling only the first occurrence", 328 | default=None, 329 | required=False, 330 | action="store_true", 331 | ) 332 | 333 | args = parser.parse_args() 334 | decompile(args.function, args.number_occurrence, args.force) 335 | -------------------------------------------------------------------------------- /tools/m2ctx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import os 5 | import sys 6 | import subprocess 7 | import tempfile 8 | 9 | script_dir = os.path.dirname(os.path.realpath(__file__)) 10 | root_dir = os.path.abspath(os.path.join(script_dir, "..")) 11 | src_dir = root_dir + "src/" 12 | 13 | # Project-specific 14 | CPP_FLAGS = [ 15 | "-Iinclude", 16 | "-Isrc", 17 | "-Iver/current/build/include", 18 | "-D_LANGUAGE_C", 19 | "-DF3DEX_GBI_2", 20 | "-D_MIPS_SZLONG=32", 21 | "-DSCRIPT(...)={}", 22 | "-D__attribute__(...)=", 23 | "-D__asm__(...)=", 24 | "-ffreestanding", 25 | "-DM2CTX", 26 | ] 27 | 28 | 29 | def import_c_file(in_file) -> str: 30 | in_file = os.path.relpath(in_file, root_dir) 31 | cpp_command = ["gcc", "-E", "-P", "-dM", *CPP_FLAGS, in_file] 32 | cpp_command2 = ["gcc", "-E", "-P", *CPP_FLAGS, in_file] 33 | 34 | with tempfile.NamedTemporaryFile(suffix=".c") as tmp: 35 | stock_macros = subprocess.check_output( 36 | ["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8" 37 | ) 38 | 39 | out_text = "" 40 | try: 41 | out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") 42 | out_text += subprocess.check_output( 43 | cpp_command2, cwd=root_dir, encoding="utf-8" 44 | ) 45 | except subprocess.CalledProcessError: 46 | print( 47 | "Failed to preprocess input file, when running command:\n" 48 | + " ".join(cpp_command), 49 | file=sys.stderr, 50 | ) 51 | sys.exit(1) 52 | 53 | if not out_text: 54 | print("Output is empty - aborting") 55 | sys.exit(1) 56 | 57 | for line in stock_macros.strip().splitlines(): 58 | out_text = out_text.replace(line + "\n", "") 59 | return out_text 60 | 61 | 62 | def main(): 63 | parser = argparse.ArgumentParser( 64 | description="""Create a context file which can be used for m2c / decomp.me""" 65 | ) 66 | parser.add_argument( 67 | "c_file", 68 | help="""File from which to create context""", 69 | ) 70 | args = parser.parse_args() 71 | 72 | output = import_c_file(args.c_file) 73 | 74 | with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f: 75 | f.write(output) 76 | 77 | 78 | if __name__ == "__main__": 79 | main() 80 | -------------------------------------------------------------------------------- /tools/report_progress.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import glob 5 | import json 6 | import os 7 | 8 | parser = argparse.ArgumentParser( 9 | description="Report progress for a specific decompiled file" 10 | ) 11 | parser.add_argument("name", metavar="name", type=str, help="Name of the original file") 12 | parser.add_argument( 13 | "count", 14 | metavar="count", 15 | type=int, 16 | help="Total function count to calculate the percentage progress", 17 | ) 18 | parser.add_argument( 19 | "source", 20 | metavar="src", 21 | type=str, 22 | help="file name or directory that contains the source code", 23 | ) 24 | args = parser.parse_args() 25 | 26 | 27 | def fileLineCount(filePath, funcGetLineScore): 28 | n = 0 29 | with open(filePath, "rt") as f: 30 | for line in f: 31 | n += funcGetLineScore(line) 32 | return n 33 | 34 | 35 | def getSourceFilepaths(path): 36 | if os.path.isfile(path): 37 | return [path] 38 | else: 39 | return glob.glob(path + "/**/*.c", recursive=True) 40 | 41 | 42 | def getPercentage(totalFuncCount, remainingFuncCount): 43 | ratio = 1 - (remainingFuncCount / totalFuncCount) 44 | return repr(round(ratio * 100, 1)) + "%" 45 | 46 | 47 | def getColor(totalFuncCount, remainingFuncCount): 48 | if remainingFuncCount == 0: 49 | return "brightgreen" 50 | else: 51 | return "yellow" 52 | 53 | 54 | def isIncludeAsm(line): 55 | return "INCLUDE_ASM" in line 56 | 57 | 58 | def isPartiallyDecompiled(line): 59 | return "#ifndef NON_MATCHING" in line 60 | 61 | 62 | def getLineScore(line): 63 | if isIncludeAsm(line) == True: 64 | return 1.0 65 | if isPartiallyDecompiled(line) == True: 66 | return -0.25 67 | return 0.0 68 | 69 | 70 | remainingNonmatchingFuncCount = 0 71 | for filePath in getSourceFilepaths(args.source): 72 | remainingNonmatchingFuncCount += fileLineCount(filePath, getLineScore) 73 | 74 | report = { 75 | "schemaVersion": 1, 76 | "label": args.name, 77 | "message": getPercentage(args.count, remainingNonmatchingFuncCount), 78 | "color": getColor(args.count, remainingNonmatchingFuncCount), 79 | } 80 | 81 | print(json.dumps(report)) 82 | -------------------------------------------------------------------------------- /tools/requirements-debian.txt: -------------------------------------------------------------------------------- 1 | gcc-mipsel-linux-gnu binutils-mips-linux-gnu clang-format -------------------------------------------------------------------------------- /tools/requirements-python.txt: -------------------------------------------------------------------------------- 1 | -r n64splat/requirements.txt 2 | pre-commit 3 | black 4 | pycparser 5 | watchdog 6 | tqdm 7 | intervaltree 8 | colorama 9 | python-Levenshtein 10 | cxxfilt --------------------------------------------------------------------------------