Last active
February 2, 2020 10:51
-
-
Save Pokechu22/96fb6dd6e6e8fc378605bd912e0e6ab0 to your computer and use it in GitHub Desktop.
Wii/Gamecube DI Inquiry hardware test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build_gc/ | |
build_wii/ | |
*.elf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdio.h> | |
#include <gccore.h> | |
#ifdef HW_RVL | |
#include <wiiuse/wpad.h> | |
#endif | |
static u32 buf[8] __attribute__((aligned(32))); | |
static void *xfb = NULL; | |
static GXRModeObj *rmode = NULL; | |
#ifdef HW_RVL | |
volatile u32* DI_REGS = (volatile u32*)0xCD806000; | |
#else | |
volatile u32* DI_REGS = (volatile u32*)0xCC006000; | |
#endif | |
#define DISR DI_REGS[0] | |
#define DICVR DI_REGS[1] | |
#define DICMDBUF0 DI_REGS[2] | |
#define DICMDBUF1 DI_REGS[3] | |
#define DICMDBUF2 DI_REGS[4] | |
#define DIMAR DI_REGS[5] | |
#define DILENGTH DI_REGS[6] | |
#define DICR DI_REGS[7] | |
#define DIIMMBUF DI_REGS[8] | |
#define DICFG DI_REGS[9] | |
void Initialise(void) { | |
VIDEO_Init(); | |
PAD_Init(); | |
#ifdef HW_RVL | |
WPAD_Init(); | |
#endif | |
rmode = VIDEO_GetPreferredMode(NULL); | |
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); | |
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); | |
VIDEO_Configure(rmode); | |
VIDEO_SetNextFramebuffer(xfb); | |
VIDEO_SetBlack(FALSE); | |
VIDEO_Flush(); | |
VIDEO_WaitVSync(); | |
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); | |
} | |
bool ExitPressed(void) { | |
#ifdef HW_RVL | |
WPAD_ScanPads(); | |
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) { | |
return true; | |
} | |
#endif | |
PAD_ScanPads(); | |
if (PAD_ButtonsDown(0) & PAD_BUTTON_START) { | |
return true; | |
} | |
return false; | |
} | |
//--------------------------------------------------------------------------------- | |
int main() { | |
//--------------------------------------------------------------------------------- | |
Initialise(); | |
printf("Sending Inquiry\n"); | |
DICMDBUF0 = 0x12000000; | |
DICMDBUF1 = 0; | |
DILENGTH = 0x20; | |
DIMAR = MEM_VIRTUAL_TO_PHYSICAL(buf); | |
DICR = 3; // Start DMA transfer | |
while (DICR & 1) { // Transfer in progress | |
VIDEO_WaitVSync(); | |
} | |
for (int i = 0; i < 8; i++) { | |
printf("buf[%d]: %08x\n", i, buf[i]); | |
} | |
printf("Checking error. DISR: %08x\n", DISR); | |
DICMDBUF0 = 0xE0000000; | |
DICR = 1; // Start immediate transfer | |
while (DICR & 1) { // Transfer in progress | |
VIDEO_WaitVSync(); | |
} | |
printf("Error: %08x (DISR: %08x)\n", DIIMMBUF, DISR); | |
printf("Press HOME or start to exit\n"); | |
do { | |
VIDEO_WaitVSync(); | |
} while (!ExitPressed()); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------------------------------------------------- | |
# Clear the implicit built in rules | |
#--------------------------------------------------------------------------------- | |
.SUFFIXES: | |
#--------------------------------------------------------------------------------- | |
ifeq ($(strip $(DEVKITPPC)),) | |
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC") | |
endif | |
include $(DEVKITPPC)/gamecube_rules | |
#--------------------------------------------------------------------------------- | |
# TARGET is the name of the output | |
# BUILD is the directory where object files & intermediate files will be placed | |
# SOURCES is a list of directories containing source code | |
# INCLUDES is a list of directories containing extra header files | |
#--------------------------------------------------------------------------------- | |
TARGET := InquiryTest_GC | |
BUILD := build_gc | |
SOURCES := . | |
DATA := data | |
INCLUDES := | |
#--------------------------------------------------------------------------------- | |
# options for code generation | |
#--------------------------------------------------------------------------------- | |
CFLAGS = -g -O0 -Wextra -Wall $(MACHDEP) $(INCLUDE) | |
CXXFLAGS = $(CFLAGS) | |
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map | |
#--------------------------------------------------------------------------------- | |
# any extra libraries we wish to link with the project | |
#--------------------------------------------------------------------------------- | |
LIBS := -logc -lm | |
#--------------------------------------------------------------------------------- | |
# list of directories containing libraries, this must be the top level containing | |
# include and lib | |
#--------------------------------------------------------------------------------- | |
LIBDIRS := | |
#--------------------------------------------------------------------------------- | |
# no real need to edit anything past this point unless you need to add additional | |
# rules for different file extensions | |
#--------------------------------------------------------------------------------- | |
ifneq ($(BUILD),$(notdir $(CURDIR))) | |
#--------------------------------------------------------------------------------- | |
export OUTPUT := $(CURDIR)/$(TARGET) | |
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | |
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) | |
export DEPSDIR := $(CURDIR)/$(BUILD) | |
#--------------------------------------------------------------------------------- | |
# automatically build a list of object files for our project | |
#--------------------------------------------------------------------------------- | |
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | |
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | |
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | |
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) | |
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | |
#--------------------------------------------------------------------------------- | |
# use CXX for linking C++ projects, CC for standard C | |
#--------------------------------------------------------------------------------- | |
ifeq ($(strip $(CPPFILES)),) | |
export LD := $(CC) | |
else | |
export LD := $(CXX) | |
endif | |
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) | |
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) | |
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) | |
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) | |
#--------------------------------------------------------------------------------- | |
# build a list of include paths | |
#--------------------------------------------------------------------------------- | |
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ | |
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | |
-I$(CURDIR)/$(BUILD) \ | |
-I$(LIBOGC_INC) | |
#--------------------------------------------------------------------------------- | |
# build a list of library paths | |
#--------------------------------------------------------------------------------- | |
export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | |
#export LIBPATHS := -L/mnt/c/Pokechu22/Git_/libogc/lib/wii/ $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | |
export OUTPUT := $(CURDIR)/$(TARGET) | |
.PHONY: $(BUILD) clean | |
#--------------------------------------------------------------------------------- | |
$(BUILD): | |
@[ -d $@ ] || mkdir -p $@ | |
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.gc | |
#--------------------------------------------------------------------------------- | |
clean: | |
@echo clean ... | |
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol | |
#--------------------------------------------------------------------------------- | |
run: | |
wiiload $(TARGET).dol | |
#--------------------------------------------------------------------------------- | |
else | |
DEPENDS := $(OFILES:.o=.d) | |
#--------------------------------------------------------------------------------- | |
# main targets | |
#--------------------------------------------------------------------------------- | |
$(OUTPUT).dol: $(OUTPUT).elf | |
$(OUTPUT).elf: $(OFILES) | |
$(OFILES_SOURCES) : $(HFILES) | |
#--------------------------------------------------------------------------------- | |
# This rule links in binary data with the .jpg extension | |
#--------------------------------------------------------------------------------- | |
%.jpg.o %_jpg.h : %.jpg | |
#--------------------------------------------------------------------------------- | |
@echo $(notdir $<) | |
$(bin2o) | |
-include $(DEPENDS) | |
#--------------------------------------------------------------------------------- | |
endif | |
#--------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------------------------------------------------- | |
# Clear the implicit built in rules | |
#--------------------------------------------------------------------------------- | |
.SUFFIXES: | |
#--------------------------------------------------------------------------------- | |
ifeq ($(strip $(DEVKITPPC)),) | |
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC") | |
endif | |
include $(DEVKITPPC)/wii_rules | |
#--------------------------------------------------------------------------------- | |
# TARGET is the name of the output | |
# BUILD is the directory where object files & intermediate files will be placed | |
# SOURCES is a list of directories containing source code | |
# INCLUDES is a list of directories containing extra header files | |
#--------------------------------------------------------------------------------- | |
TARGET := InquiryTest_Wii | |
BUILD := build_wii | |
SOURCES := . | |
DATA := data | |
INCLUDES := | |
#--------------------------------------------------------------------------------- | |
# options for code generation | |
#--------------------------------------------------------------------------------- | |
CFLAGS = -g -O0 -Wextra -Wall $(MACHDEP) $(INCLUDE) | |
CXXFLAGS = $(CFLAGS) | |
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map | |
#--------------------------------------------------------------------------------- | |
# any extra libraries we wish to link with the project | |
#--------------------------------------------------------------------------------- | |
LIBS := -lwiiuse -lbte -logc -lm | |
#--------------------------------------------------------------------------------- | |
# list of directories containing libraries, this must be the top level containing | |
# include and lib | |
#--------------------------------------------------------------------------------- | |
LIBDIRS := | |
#--------------------------------------------------------------------------------- | |
# no real need to edit anything past this point unless you need to add additional | |
# rules for different file extensions | |
#--------------------------------------------------------------------------------- | |
ifneq ($(BUILD),$(notdir $(CURDIR))) | |
#--------------------------------------------------------------------------------- | |
export OUTPUT := $(CURDIR)/$(TARGET) | |
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | |
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) | |
export DEPSDIR := $(CURDIR)/$(BUILD) | |
#--------------------------------------------------------------------------------- | |
# automatically build a list of object files for our project | |
#--------------------------------------------------------------------------------- | |
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | |
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | |
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | |
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) | |
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | |
#--------------------------------------------------------------------------------- | |
# use CXX for linking C++ projects, CC for standard C | |
#--------------------------------------------------------------------------------- | |
ifeq ($(strip $(CPPFILES)),) | |
export LD := $(CC) | |
else | |
export LD := $(CXX) | |
endif | |
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) | |
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) | |
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) | |
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) | |
#--------------------------------------------------------------------------------- | |
# build a list of include paths | |
#--------------------------------------------------------------------------------- | |
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ | |
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | |
-I$(CURDIR)/$(BUILD) \ | |
-I$(LIBOGC_INC) | |
#--------------------------------------------------------------------------------- | |
# build a list of library paths | |
#--------------------------------------------------------------------------------- | |
export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | |
#export LIBPATHS := -L/mnt/c/Pokechu22/Git_/libogc/lib/wii/ $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | |
export OUTPUT := $(CURDIR)/$(TARGET) | |
.PHONY: $(BUILD) clean | |
#--------------------------------------------------------------------------------- | |
$(BUILD): | |
@[ -d $@ ] || mkdir -p $@ | |
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.wii | |
#--------------------------------------------------------------------------------- | |
clean: | |
@echo clean ... | |
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol | |
#--------------------------------------------------------------------------------- | |
run: | |
wiiload $(TARGET).dol | |
#--------------------------------------------------------------------------------- | |
else | |
DEPENDS := $(OFILES:.o=.d) | |
#--------------------------------------------------------------------------------- | |
# main targets | |
#--------------------------------------------------------------------------------- | |
$(OUTPUT).dol: $(OUTPUT).elf | |
$(OUTPUT).elf: $(OFILES) | |
$(OFILES_SOURCES) : $(HFILES) | |
#--------------------------------------------------------------------------------- | |
# This rule links in binary data with the .jpg extension | |
#--------------------------------------------------------------------------------- | |
%.jpg.o %_jpg.h : %.jpg | |
#--------------------------------------------------------------------------------- | |
@echo $(notdir $<) | |
$(bin2o) | |
-include $(DEPENDS) | |
#--------------------------------------------------------------------------------- | |
endif | |
#--------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment