├── .gitignore ├── Makefile ├── audio ├── modplay │ ├── Makefile │ ├── data │ │ └── technique.mod │ └── source │ │ └── template.c ├── mp3player │ ├── Makefile │ ├── data │ │ └── sample.mp3 │ └── source │ │ └── template.c └── oggplayer │ ├── Makefile │ ├── data │ └── sample.ogg │ └── source │ ├── oggplayer.c │ ├── oggplayer.h │ └── template.c ├── devices ├── dvd │ ├── Makefile │ └── readsector │ │ ├── Makefile │ │ └── source │ │ └── dvd.c ├── memcard │ └── MemCardDemo │ │ ├── Makefile │ │ └── source │ │ └── main.c ├── network │ ├── Makefile │ ├── gdbstub │ │ ├── Makefile │ │ └── source │ │ │ └── gdbstub.c │ └── sockettest │ │ ├── Makefile │ │ └── source │ │ └── sockettest.c └── usbgecko │ ├── Makefile │ └── gdbstub │ ├── Makefile │ └── source │ └── gdbstub.c ├── filesystem └── directory │ ├── Makefile │ └── source │ └── directory.c ├── graphics ├── fb │ ├── consoletest │ │ ├── Makefile │ │ └── source │ │ │ └── main.cpp │ └── pageflip │ │ ├── Makefile │ │ └── source │ │ └── flip.c └── gx │ ├── acube │ ├── Makefile │ └── source │ │ └── acube.c │ ├── gxSprites │ ├── Makefile │ ├── source │ │ └── gxsprites.c │ └── textures │ │ ├── ballsprites.png │ │ └── textures.scf │ ├── neheGX │ ├── lesson01 │ │ ├── Makefile │ │ └── source │ │ │ └── lesson1.c │ ├── lesson02 │ │ ├── Makefile │ │ └── source │ │ │ └── lesson2.c │ ├── lesson03 │ │ ├── Makefile │ │ └── source │ │ │ └── lesson3.c │ ├── lesson04 │ │ ├── Makefile │ │ └── source │ │ │ └── lesson4.c │ ├── lesson05 │ │ ├── Makefile │ │ └── source │ │ │ └── lesson5.c │ ├── lesson06 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson6.c │ │ └── textures │ │ │ ├── NeHe.bmp │ │ │ └── NeHe.scf │ ├── lesson07 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson7.c │ │ └── textures │ │ │ ├── crate.bmp │ │ │ └── crate.scf │ ├── lesson08 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson8.c │ │ └── textures │ │ │ ├── Glass.bmp │ │ │ └── glass.scf │ ├── lesson09 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson9.c │ │ └── textures │ │ │ ├── Star.bmp │ │ │ └── startex.scf │ ├── lesson10 │ │ ├── Makefile │ │ ├── data │ │ │ └── world.txt │ │ ├── source │ │ │ └── lesson10.c │ │ └── textures │ │ │ ├── Mud.bmp │ │ │ └── mud.scf │ ├── lesson11 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson11.c │ │ └── textures │ │ │ ├── Tim.bmp │ │ │ └── Tim.scf │ ├── lesson12 │ │ ├── Makefile │ │ ├── source │ │ │ └── lesson12.c │ │ └── textures │ │ │ ├── Cube.bmp │ │ │ └── Cube.scf │ └── lesson19 │ │ ├── Makefile │ │ ├── source │ │ └── lesson19.c │ │ └── textures │ │ ├── Particle.bmp │ │ └── Particle.scf │ ├── texturetest │ ├── Makefile │ ├── source │ │ └── texture.c │ └── textures │ │ ├── drunkentimes.jpg │ │ └── textures.scf │ └── triangle │ ├── Makefile │ └── source │ └── triangle.c ├── system ├── Makefile └── arena1override │ ├── Makefile │ └── source │ └── template.c └── templates ├── application ├── CMakeLists.txt ├── Makefile └── source │ └── template.c └── library ├── .gitignore ├── Makefile ├── README.md ├── include └── templatelib.h └── source └── templatelib.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.dol 2 | *.elf 3 | build/ 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d) 2 | 3 | MAKEFILES := $(shell find . -mindepth 2 -name Makefile) 4 | 5 | #--------------------------------------------------------------------------------- 6 | all: examples 7 | #--------------------------------------------------------------------------------- 8 | @rm -fr bin 9 | @mkdir -p bin 10 | @find . -name "*.dol" ! -path "./bin/*" -exec cp -fv {} bin \; 11 | 12 | #--------------------------------------------------------------------------------- 13 | examples: 14 | #--------------------------------------------------------------------------------- 15 | @for i in $(MAKEFILES); do $(MAKE) -C `dirname $$i` || exit 1; done; 16 | 17 | #--------------------------------------------------------------------------------- 18 | clean: 19 | #--------------------------------------------------------------------------------- 20 | @rm -fr bin 21 | @rm -f *.bz2 22 | @for i in $(MAKEFILES); do $(MAKE) -C `dirname $$i` clean || exit 1; done; 23 | 24 | #--------------------------------------------------------------------------------- 25 | dist: clean 26 | #--------------------------------------------------------------------------------- 27 | @tar -cvjf gamecube-examples-$(DATESTRING).tar.bz2 * 28 | -------------------------------------------------------------------------------- /audio/modplay/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -lmodplay -laesnd -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 77 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 78 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 79 | 80 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 81 | 82 | 83 | #--------------------------------------------------------------------------------- 84 | # build a list of include paths 85 | #--------------------------------------------------------------------------------- 86 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 87 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 88 | -I$(CURDIR)/$(BUILD) \ 89 | -I$(LIBOGC_INC) 90 | 91 | #--------------------------------------------------------------------------------- 92 | # build a list of library paths 93 | #--------------------------------------------------------------------------------- 94 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 95 | -L$(LIBOGC_LIB) 96 | 97 | export OUTPUT := $(CURDIR)/$(TARGET) 98 | .PHONY: $(BUILD) clean 99 | 100 | #--------------------------------------------------------------------------------- 101 | $(BUILD): 102 | @[ -d $@ ] || mkdir -p $@ 103 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 104 | 105 | #--------------------------------------------------------------------------------- 106 | clean: 107 | @echo clean ... 108 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 109 | 110 | #--------------------------------------------------------------------------------- 111 | else 112 | 113 | DEPENDS := $(OFILES:.o=.d) 114 | 115 | #--------------------------------------------------------------------------------- 116 | # main targets 117 | #--------------------------------------------------------------------------------- 118 | $(OUTPUT).dol: $(OUTPUT).elf 119 | $(OUTPUT).elf: $(OFILES) 120 | 121 | $(OFILES_SOURCES) : $(HFILES) 122 | #--------------------------------------------------------------------------------- 123 | # This rule links in binary data with the .mod extension 124 | #--------------------------------------------------------------------------------- 125 | %.mod.o %_mod.h : %.mod 126 | #--------------------------------------------------------------------------------- 127 | @echo $(notdir $<) 128 | $(bin2o) 129 | 130 | -include $(DEPENDS) 131 | 132 | #--------------------------------------------------------------------------------- 133 | endif 134 | #--------------------------------------------------------------------------------- 135 | -------------------------------------------------------------------------------- /audio/modplay/data/technique.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/audio/modplay/data/technique.mod -------------------------------------------------------------------------------- /audio/modplay/source/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // include generated header 8 | #include "technique_mod.h" 9 | 10 | static void *xfb = NULL; 11 | static GXRModeObj *rmode = NULL; 12 | static MODPlay play; 13 | 14 | //--------------------------------------------------------------------------------- 15 | int main(int argc, char **argv) { 16 | //--------------------------------------------------------------------------------- 17 | 18 | // Initialise the video system 19 | VIDEO_Init(); 20 | 21 | // Initialise the attached controllers 22 | PAD_Init(); 23 | 24 | // Initialise the audio subsystem 25 | AESND_Init(); 26 | 27 | // Obtain the preferred video mode from the system 28 | // This will correspond to the settings in the Wii menu 29 | rmode = VIDEO_GetPreferredMode(NULL); 30 | 31 | // Allocate memory for the display in the uncached region 32 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 33 | 34 | // Initialise the console, required for printf 35 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 36 | 37 | // Set up the video registers with the chosen mode 38 | VIDEO_Configure(rmode); 39 | 40 | // Tell the video hardware where our display memory is 41 | VIDEO_SetNextFramebuffer(xfb); 42 | 43 | // Make the display visible 44 | VIDEO_SetBlack(FALSE); 45 | 46 | // Flush the video register changes to the hardware 47 | VIDEO_Flush(); 48 | 49 | // Wait for Video setup to complete 50 | VIDEO_WaitVSync(); 51 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 52 | 53 | 54 | // The console understands VT terminal escape codes 55 | // This positions the cursor on row 2, column 0 56 | // we can use variables for this with format codes too 57 | // e.g. printf ("\x1b[%d;%dH", row, column ); 58 | printf("\x1b[2;0H"); 59 | 60 | printf("Hello World!"); 61 | 62 | MODPlay_Init(&play); 63 | MODPlay_SetMOD(&play,technique_mod); 64 | MODPlay_Start(&play); 65 | 66 | 67 | 68 | while(1) { 69 | 70 | VIDEO_WaitVSync(); 71 | PAD_ScanPads(); 72 | 73 | int buttonsDown = PAD_ButtonsDown(0); 74 | 75 | if( buttonsDown & PAD_BUTTON_A ) { 76 | printf("Button A pressed.\n"); 77 | } 78 | 79 | if (buttonsDown & PAD_BUTTON_START) { 80 | exit(0); 81 | } 82 | } 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /audio/mp3player/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -lmad -lasnd -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 77 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 78 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 79 | 80 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 81 | 82 | #--------------------------------------------------------------------------------- 83 | # build a list of include paths 84 | #--------------------------------------------------------------------------------- 85 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 86 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 87 | -I$(CURDIR)/$(BUILD) \ 88 | -I$(LIBOGC_INC) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # build a list of library paths 92 | #--------------------------------------------------------------------------------- 93 | export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 94 | 95 | export OUTPUT := $(CURDIR)/$(TARGET) 96 | 97 | .PHONY: $(BUILD) clean 98 | 99 | #--------------------------------------------------------------------------------- 100 | $(BUILD): 101 | @[ -d $@ ] || mkdir -p $@ 102 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 103 | 104 | #--------------------------------------------------------------------------------- 105 | clean: 106 | @echo clean ... 107 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 108 | 109 | #--------------------------------------------------------------------------------- 110 | else 111 | 112 | DEPENDS := $(OFILES:.o=.d) 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | $(OUTPUT).dol: $(OUTPUT).elf 118 | $(OUTPUT).elf: $(OFILES) 119 | 120 | $(OFILES_SOURCES) : $(HFILES) 121 | 122 | #--------------------------------------------------------------------------------- 123 | # This rule links in binary data with the .mp3 extension 124 | #--------------------------------------------------------------------------------- 125 | %.mp3.o %_mp3.h : %.mp3 126 | #--------------------------------------------------------------------------------- 127 | @echo $(notdir $<) 128 | $(bin2o) 129 | 130 | -include $(DEPENDS) 131 | 132 | #--------------------------------------------------------------------------------- 133 | endif 134 | #--------------------------------------------------------------------------------- 135 | -------------------------------------------------------------------------------- /audio/mp3player/data/sample.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/audio/mp3player/data/sample.mp3 -------------------------------------------------------------------------------- /audio/mp3player/source/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // include generated header 8 | #include "sample_mp3.h" 9 | 10 | static void *xfb = NULL; 11 | static GXRModeObj *rmode = NULL; 12 | 13 | //--------------------------------------------------------------------------------- 14 | int main(int argc, char **argv) { 15 | //--------------------------------------------------------------------------------- 16 | 17 | // Initialise the video system 18 | VIDEO_Init(); 19 | 20 | // Initialise the attached controllers 21 | PAD_Init(); 22 | 23 | // Initialise the audio subsystem 24 | ASND_Init(); 25 | MP3Player_Init(); 26 | 27 | // Obtain the preferred video mode from the system 28 | // This will correspond to the settings in the Wii menu 29 | rmode = VIDEO_GetPreferredMode(NULL); 30 | 31 | // Allocate memory for the display in the uncached region 32 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 33 | 34 | // Initialise the console, required for printf 35 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 36 | 37 | // Set up the video registers with the chosen mode 38 | VIDEO_Configure(rmode); 39 | 40 | // Tell the video hardware where our display memory is 41 | VIDEO_SetNextFramebuffer(xfb); 42 | 43 | // Make the display visible 44 | VIDEO_SetBlack(FALSE); 45 | 46 | // Flush the video register changes to the hardware 47 | VIDEO_Flush(); 48 | 49 | // Wait for Video setup to complete 50 | VIDEO_WaitVSync(); 51 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 52 | 53 | 54 | // The console understands VT terminal escape codes 55 | // This positions the cursor on row 2, column 0 56 | // we can use variables for this with format codes too 57 | // e.g. printf ("\x1b[%d;%dH", row, column ); 58 | printf("\x1b[2;0H"); 59 | 60 | printf("Playing sample MP3 file...Press HOME to exit.\n"); 61 | 62 | MP3Player_PlayBuffer(sample_mp3, sample_mp3_size, NULL); 63 | 64 | while(1) { 65 | 66 | // Call PAD_ScanPads each loop, this reads the latest controller states 67 | PAD_ScanPads(); 68 | 69 | // PAD_ButtonsDown tells us which buttons were pressed in this loop 70 | // this is a "one shot" state which will not fire again until the button has been released 71 | u32 pressed = PAD_ButtonsDown(0); 72 | 73 | // We return to the launcher application via exit 74 | if ( pressed & PAD_BUTTON_START ) exit(0); 75 | 76 | // Wait for the next frame 77 | VIDEO_WaitVSync(); 78 | } 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /audio/oggplayer/data/sample.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/audio/oggplayer/data/sample.ogg -------------------------------------------------------------------------------- /audio/oggplayer/source/oggplayer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/audio/oggplayer/source/oggplayer.c -------------------------------------------------------------------------------- /audio/oggplayer/source/oggplayer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/audio/oggplayer/source/oggplayer.h -------------------------------------------------------------------------------- /audio/oggplayer/source/template.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * OGG Playback example 3 | * Tantric 2009 4 | ***************************************************************************/ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "oggplayer.h" 12 | 13 | // include generated header 14 | #include "sample_ogg.h" 15 | 16 | static void *xfb = NULL; 17 | static GXRModeObj *rmode = NULL; 18 | 19 | //--------------------------------------------------------------------------------- 20 | int main(int argc, char **argv) { 21 | //--------------------------------------------------------------------------------- 22 | 23 | // Initialise the video system 24 | VIDEO_Init(); 25 | 26 | // Initialise the attached controllers 27 | PAD_Init(); 28 | 29 | // Initialise the audio subsystem 30 | ASND_Init(); 31 | 32 | // Obtain the preferred video mode from the system 33 | // This will correspond to the settings in the Wii menu 34 | rmode = VIDEO_GetPreferredMode(NULL); 35 | 36 | // Allocate memory for the display in the uncached region 37 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 38 | 39 | // Initialise the console, required for printf 40 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 41 | 42 | // Set up the video registers with the chosen mode 43 | VIDEO_Configure(rmode); 44 | 45 | // Tell the video hardware where our display memory is 46 | VIDEO_SetNextFramebuffer(xfb); 47 | 48 | // Make the display visible 49 | VIDEO_SetBlack(FALSE); 50 | 51 | // Flush the video register changes to the hardware 52 | VIDEO_Flush(); 53 | 54 | // Wait for Video setup to complete 55 | VIDEO_WaitVSync(); 56 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 57 | 58 | 59 | // The console understands VT terminal escape codes 60 | // This positions the cursor on row 2, column 0 61 | // we can use variables for this with format codes too 62 | // e.g. printf ("\x1b[%d;%dH", row, column ); 63 | printf("\x1b[2;0H"); 64 | 65 | printf("Playing sample OGG file...Press Start to exit.\n"); 66 | 67 | PlayOgg(sample_ogg, sample_ogg_size, 0, OGG_ONE_TIME); 68 | 69 | while(1) { 70 | 71 | // Call PAD_ScanPads each loop, this reads the latest controller states 72 | PAD_ScanPads(); 73 | 74 | // PAD_ButtonsDown tells us which buttons were pressed in this loop 75 | // this is a "one shot" state which will not fire again until the button has been released 76 | u32 pressed = PAD_ButtonsDown(0); 77 | 78 | // We return to the launcher application via exit 79 | if ( pressed & PAD_BUTTON_START ) break; 80 | 81 | // Wait for the next frame 82 | VIDEO_WaitVSync(); 83 | } 84 | StopOgg(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /devices/dvd/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS:= `ls | egrep -v '^(CVS)$$'` 2 | 3 | all: 4 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; 5 | 6 | clean: 7 | @rm -f *.bz2 8 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; 9 | 10 | -------------------------------------------------------------------------------- /devices/dvd/readsector/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | 108 | #--------------------------------------------------------------------------------- 109 | else 110 | 111 | DEPENDS := $(OFILES:.o=.d) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # main targets 115 | #--------------------------------------------------------------------------------- 116 | $(OUTPUT).dol: $(OUTPUT).elf 117 | $(OUTPUT).elf: $(OFILES) 118 | 119 | #--------------------------------------------------------------------------------- 120 | # This rule links in binary data with the .jpg extension 121 | #--------------------------------------------------------------------------------- 122 | %.jpg.o : %.jpg 123 | #--------------------------------------------------------------------------------- 124 | @echo $(notdir $<) 125 | $(bin2o) 126 | 127 | -include $(DEPENDS) 128 | 129 | #--------------------------------------------------------------------------------- 130 | endif 131 | #--------------------------------------------------------------------------------- 132 | -------------------------------------------------------------------------------- /devices/dvd/readsector/source/dvd.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | libogc - DVD Demo 4 | 5 | Demonstrates reading a sector from DVD 6 | 7 | ---------------------------------------------------------------------------------*/ 8 | 9 | #include 10 | #include // Wrapper to include common libogc headers 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // 2D Video Globals 17 | 18 | GXRModeObj *vmode; // Graphics Mode Object 19 | u32 *xfb = NULL; // Framebuffer 20 | int dvdstatus = 0; 21 | 22 | static u8 dvdbuffer[2048] ATTRIBUTE_ALIGN (32); // One Sector 23 | dvdcmdblk cmdblk; 24 | 25 | /*--------------------------------------------------------------------------------- 26 | Initialise Video 27 | 28 | Before doing anything in libogc, it's recommended to configure a video 29 | output. 30 | ---------------------------------------------------------------------------------*/ 31 | static void Initialise () { 32 | //--------------------------------------------------------------------------------- 33 | 34 | VIDEO_Init (); /* ALWAYS CALL FIRST IN ANY LIBOGC PROJECT! 35 | Not only does it initialise the video 36 | subsystem, but also sets up the ogc os 37 | */ 38 | 39 | PAD_Init (); // Initialise pads for input 40 | 41 | 42 | vmode = VIDEO_GetPreferredMode(NULL); 43 | 44 | // Let libogc configure the mode 45 | VIDEO_Configure (vmode); 46 | 47 | 48 | /* 49 | 50 | Now configure the framebuffer. 51 | Really a framebuffer is just a chunk of memory 52 | to hold the display line by line. 53 | 54 | */ 55 | 56 | xfb = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); 57 | 58 | 59 | // Define a console 60 | console_init (xfb, 20, 64, vmode->fbWidth, vmode->xfbHeight, 61 | vmode->fbWidth * 2); 62 | 63 | // Clear framebuffer to black 64 | VIDEO_ClearFrameBuffer (vmode, xfb, COLOR_BLACK); 65 | VIDEO_ClearFrameBuffer (vmode, xfb, COLOR_BLACK); 66 | 67 | /*** Set the framebuffer to be displayed at next VBlank ***/ 68 | VIDEO_SetNextFramebuffer (xfb); 69 | 70 | VIDEO_SetBlack (0); 71 | 72 | // Update the video for next vblank 73 | VIDEO_Flush (); 74 | 75 | VIDEO_WaitVSync (); // Wait for next Vertical Blank 76 | 77 | if (vmode->viTVMode & VI_NON_INTERLACE) 78 | VIDEO_WaitVSync (); 79 | 80 | } 81 | 82 | //--------------------------------------------------------------------------- 83 | int main () { 84 | //-------------------------------------------------------------------------- 85 | int ret = 0; 86 | int *p; 87 | int j, i; 88 | 89 | Initialise (); // Start video etc 90 | DVD_Init (); // And the DVD subsystem 91 | 92 | printf ("libOGC DVD Example\n"); 93 | printf ("Mounting Disc\n"); 94 | 95 | // This will mount pretty much any disc, original or ISO 96 | DVD_Mount (); 97 | printf ("OK\n"); 98 | 99 | // Read Sector 0 100 | ret = DVD_ReadPrio (&cmdblk, dvdbuffer, 2048, 0, 2); 101 | 102 | if (ret <= 0) { 103 | printf ("Error during read sector 0\n"); 104 | while (1); 105 | } 106 | 107 | printf ("Read %d bytes\n", ret); 108 | p = (int *) dvdbuffer; 109 | 110 | // Identify disc type 111 | j = 0; 112 | 113 | for (i = 0; i < 512; i++) 114 | j += p[i]; 115 | 116 | if (j == 0) { 117 | printf ("Disc is most probably ISO-9660\n"); 118 | } else { 119 | 120 | if (memcmp (dvdbuffer + 32, "GAMECUBE \"EL TORITO\" BOOTLOADER", 31) == 0) { 121 | printf ("Disc is gc-linux bootable\n"); 122 | } else { 123 | 124 | if (memcmp (dvdbuffer, "COBRAMB1", 8) == 0) { 125 | printf ("Disc is multigame image\n"); 126 | } else { 127 | printf ("Disc is gcm\n%s\n", (char *) dvdbuffer + 32); 128 | } 129 | } 130 | } 131 | 132 | while(1) { 133 | 134 | VIDEO_WaitVSync(); 135 | PAD_ScanPads(); 136 | 137 | int buttonsDown = PAD_ButtonsDown(0); 138 | 139 | 140 | if (buttonsDown & PAD_BUTTON_START) { 141 | void (*reload)() = (void(*)())0x80001800; 142 | reload(); 143 | } 144 | } 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /devices/memcard/MemCardDemo/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | 108 | #--------------------------------------------------------------------------------- 109 | else 110 | 111 | DEPENDS := $(OFILES:.o=.d) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # main targets 115 | #--------------------------------------------------------------------------------- 116 | $(OUTPUT).dol: $(OUTPUT).elf 117 | $(OUTPUT).elf: $(OFILES) 118 | 119 | #--------------------------------------------------------------------------------- 120 | # This rule links in binary data with the .jpg extension 121 | #--------------------------------------------------------------------------------- 122 | %.jpg.o : %.jpg 123 | #--------------------------------------------------------------------------------- 124 | @echo $(notdir $<) 125 | $(bin2o) 126 | 127 | -include $(DEPENDS) 128 | 129 | #--------------------------------------------------------------------------------- 130 | endif 131 | #--------------------------------------------------------------------------------- 132 | -------------------------------------------------------------------------------- /devices/memcard/MemCardDemo/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define DemoFileName "MemCardDemo.dat" 10 | 11 | static void *xfb = NULL; 12 | 13 | static u8 SysArea[CARD_WORKAREA_SIZE] ATTRIBUTE_ALIGN(32); 14 | 15 | u32 first_frame = 1; 16 | GXRModeObj *rmode; 17 | void (*PSOreload)() = (void(*)())0x80001800; 18 | 19 | 20 | /*--------------------------------------------------------------------------------- 21 | This function is called if a card is physically removed 22 | ---------------------------------------------------------------------------------*/ 23 | void card_removed(s32 chn,s32 result) { 24 | //--------------------------------------------------------------------------------- 25 | printf("card was removed from slot %c\n",(chn==0)?'A':'B'); 26 | CARD_Unmount(chn); 27 | } 28 | 29 | //--------------------------------------------------------------------------------- 30 | int main() { 31 | //--------------------------------------------------------------------------------- 32 | VIDEO_Init(); 33 | 34 | rmode = VIDEO_GetPreferredMode(NULL); 35 | 36 | PAD_Init(); 37 | 38 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 39 | 40 | VIDEO_Configure(rmode); 41 | 42 | VIDEO_SetNextFramebuffer(xfb); 43 | VIDEO_SetBlack(FALSE); 44 | VIDEO_Flush(); 45 | VIDEO_WaitVSync(); 46 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 47 | console_init(xfb,20,64,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2); 48 | VIDEO_SetNextFramebuffer(xfb); 49 | 50 | printf("Memory Card Demo\n\n"); 51 | 52 | while (1) { 53 | printf("Insert A card in slot B and press A\n"); 54 | 55 | do { 56 | PAD_ScanPads(); 57 | if (PAD_ButtonsDown(0) & PAD_BUTTON_START) PSOreload(); 58 | VIDEO_WaitVSync(); 59 | } while ( !(PAD_ButtonsDown(0) & PAD_BUTTON_A)); 60 | 61 | 62 | printf("Mounting card ...\n"); 63 | 64 | CARD_Init("DEMO","00"); 65 | int SlotB_error = CARD_Mount(CARD_SLOTB, SysArea, card_removed); 66 | 67 | printf("slot B code %d\n",SlotB_error); 68 | 69 | int CardError; 70 | 71 | if (SlotB_error >= 0) { 72 | 73 | unsigned int SectorSize = 0; 74 | CARD_GetSectorSize(CARD_SLOTB,&SectorSize); 75 | 76 | printf("Sector size is %d bytes.\n\n",SectorSize); 77 | 78 | char *CardBuffer = (char *)memalign(32,SectorSize); 79 | 80 | printf("Starting directory\n"); 81 | 82 | card_dir CardDir; 83 | card_file CardFile; 84 | 85 | CardError = CARD_FindFirst(CARD_SLOTB, &CardDir, true); 86 | 87 | bool found = false; 88 | 89 | while ( CARD_ERROR_NOFILE != CardError ) { 90 | printf("%s %s %s\n",CardDir.filename,CardDir.gamecode,CardDir.company); 91 | CardError = CARD_FindNext(&CardDir); 92 | if ( 0 == strcmp (DemoFileName, (char *)CardDir.filename)) found = true; 93 | }; 94 | 95 | printf("Finished directory\n\n"); 96 | 97 | if (found) { 98 | printf("Test file contains :- \n"); 99 | CardError = CARD_Open(CARD_SLOTB ,DemoFileName,&CardFile); 100 | CARD_Read(&CardFile,CardBuffer,SectorSize,0); 101 | printf("%s\n",CardBuffer); 102 | 103 | CARD_Close(&CardFile); 104 | 105 | CARD_Delete(CARD_SLOTB,DemoFileName); 106 | } else { 107 | 108 | printf("writing test file ...\n"); 109 | CardError = CARD_Create(CARD_SLOTB ,DemoFileName,SectorSize,&CardFile); 110 | 111 | if (0 == CardError) { 112 | time_t gc_time; 113 | gc_time = time(NULL); 114 | 115 | sprintf(CardBuffer,"This text was written by MemCardDemo\nat %s\n",ctime(&gc_time)); 116 | 117 | CardError = CARD_Write(&CardFile,CardBuffer,SectorSize,0); 118 | CardError = CARD_Close(&CardFile); 119 | } 120 | } 121 | 122 | CARD_Unmount(CARD_SLOTB); 123 | free(CardBuffer); 124 | 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /devices/network/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS:= `ls | egrep -v '^(CVS)$$'` 2 | 3 | all: 4 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; 5 | 6 | clean: 7 | @rm -f *.bz2 8 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; 9 | 10 | -------------------------------------------------------------------------------- /devices/network/gdbstub/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -ldb -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | #--------------------------------------------------------------------------------- 108 | else 109 | 110 | DEPENDS := $(OFILES:.o=.d) 111 | 112 | #--------------------------------------------------------------------------------- 113 | # main targets 114 | #--------------------------------------------------------------------------------- 115 | $(OUTPUT).dol: $(OUTPUT).elf 116 | $(OUTPUT).elf: $(OFILES) 117 | 118 | #--------------------------------------------------------------------------------- 119 | # This rule links in binary data with the .jpg extension 120 | #--------------------------------------------------------------------------------- 121 | %.jpg.o : %.jpg 122 | #--------------------------------------------------------------------------------- 123 | @echo $(notdir $<) 124 | $(bin2o) 125 | 126 | -include $(DEPENDS) 127 | 128 | #--------------------------------------------------------------------------------- 129 | endif 130 | #--------------------------------------------------------------------------------- 131 | -------------------------------------------------------------------------------- /devices/network/gdbstub/source/gdbstub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void *xfb = NULL; 10 | static GXRModeObj *rmode = NULL; 11 | 12 | /* 13 | Network settings for debugging over tcp with BBA 14 | change these as appropriate for your network 15 | 16 | External C linkage required 17 | */ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | const char *tcp_localip = "192.168.1.10"; 24 | const char *tcp_netmask = "255.255.255.0"; 25 | const char *tcp_gateway = "192.168.1.1"; 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | int main() { 32 | 33 | VIDEO_Init(); 34 | PAD_Init(); 35 | 36 | rmode = VIDEO_GetPreferredMode(NULL); 37 | 38 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 39 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 40 | 41 | VIDEO_Configure(rmode); 42 | VIDEO_SetNextFramebuffer(xfb); 43 | VIDEO_SetBlack(FALSE); 44 | VIDEO_Flush(); 45 | VIDEO_WaitVSync(); 46 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 47 | 48 | /* Configure for use with TCP on default port ( 2828 ) */ 49 | DEBUG_Init(GDBSTUB_DEVICE_TCP,GDBSTUB_DEF_TCPPORT); 50 | 51 | 52 | printf("Waiting for debugger ...\n"); 53 | /* This function call enters the debug stub for the first time */ 54 | /* It's needed to call this if one wants to start debugging. */ 55 | _break(); 56 | 57 | printf("debugger connected ...\n"); 58 | 59 | while(1) 60 | { 61 | VIDEO_WaitVSync(); 62 | PAD_ScanPads(); 63 | 64 | int buttons = PAD_ButtonsDown(0); 65 | 66 | if(buttons & PAD_BUTTON_A) { 67 | printf("Button A pressed.\n"); 68 | } 69 | 70 | if (buttons & PAD_BUTTON_START) { 71 | break; 72 | } 73 | } 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /devices/network/sockettest/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -ldb -lbba -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | #--------------------------------------------------------------------------------- 108 | else 109 | 110 | DEPENDS := $(OFILES:.o=.d) 111 | 112 | #--------------------------------------------------------------------------------- 113 | # main targets 114 | #--------------------------------------------------------------------------------- 115 | $(OUTPUT).dol: $(OUTPUT).elf 116 | $(OUTPUT).elf: $(OFILES) 117 | 118 | #--------------------------------------------------------------------------------- 119 | # This rule links in binary data with the .jpg extension 120 | #--------------------------------------------------------------------------------- 121 | %.jpg.o : %.jpg 122 | #--------------------------------------------------------------------------------- 123 | @echo $(notdir $<) 124 | $(bin2o) 125 | 126 | -include $(DEPENDS) 127 | 128 | #--------------------------------------------------------------------------------- 129 | endif 130 | #--------------------------------------------------------------------------------- 131 | -------------------------------------------------------------------------------- /devices/network/sockettest/source/sockettest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static void *xfb = NULL; 12 | static GXRModeObj *rmode = NULL; 13 | 14 | void *initialise(); 15 | void *httpd (void *arg); 16 | 17 | static lwp_t httd_handle = (lwp_t)NULL; 18 | 19 | //--------------------------------------------------------------------------------- 20 | int main(int argc, char **argv) { 21 | //--------------------------------------------------------------------------------- 22 | s32 ret; 23 | 24 | char localip[16] = {0}; 25 | char gateway[16] = {0}; 26 | char netmask[16] = {0}; 27 | 28 | xfb = initialise(); 29 | 30 | printf ("\nlibogc network demo\n"); 31 | printf("Configuring network ...\n"); 32 | 33 | // Configure the network interface 34 | ret = if_config ( localip, netmask, gateway, TRUE, 20); 35 | if (ret>=0) { 36 | printf ("network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask); 37 | 38 | LWP_CreateThread( &httd_handle, /* thread handle */ 39 | httpd, /* code */ 40 | localip, /* arg pointer for thread */ 41 | NULL, /* stack base */ 42 | 64*1024, /* stack size */ 43 | 50 /* thread priority */ ); 44 | } else { 45 | printf ("network configuration failed!\n"); 46 | } 47 | 48 | while(1) { 49 | 50 | VIDEO_WaitVSync(); 51 | PAD_ScanPads(); 52 | 53 | int buttonsDown = PAD_ButtonsDown(0); 54 | 55 | if (buttonsDown & PAD_BUTTON_START) { 56 | exit(0); 57 | } 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | const static char http_200[] = "HTTP/1.1 200 OK\r\n"; 64 | 65 | const static char indexdata[] = " \ 66 | A test page \ 67 | \ 68 | This small test page has had %d hits. \ 69 | \ 70 | "; 71 | 72 | const static char http_html_hdr[] = "Content-type: text/html\r\n\r\n"; 73 | const static char http_get_index[] = "GET / HTTP/1.1\r\n"; 74 | 75 | //--------------------------------------------------------------------------------- 76 | void *httpd (void *arg) { 77 | //--------------------------------------------------------------------------------- 78 | 79 | int sock, csock; 80 | int ret; 81 | u32 clientlen; 82 | struct sockaddr_in client; 83 | struct sockaddr_in server; 84 | char temp[1026]; 85 | static int hits=0; 86 | 87 | clientlen = sizeof(client); 88 | 89 | sock = net_socket (AF_INET, SOCK_STREAM, IPPROTO_IP); 90 | 91 | if (sock == INVALID_SOCKET) { 92 | printf ("Cannot create a socket!\n"); 93 | } else { 94 | 95 | memset (&server, 0, sizeof (server)); 96 | memset (&client, 0, sizeof (client)); 97 | 98 | server.sin_family = AF_INET; 99 | server.sin_port = htons (80); 100 | server.sin_addr.s_addr = INADDR_ANY; 101 | ret = net_bind (sock, (struct sockaddr *) &server, sizeof (server)); 102 | 103 | if ( ret ) { 104 | 105 | printf("Error %d binding socket!\n", ret); 106 | 107 | } else { 108 | 109 | if ( (ret = net_listen( sock, 5)) ) { 110 | 111 | printf("Error %d listening!\n", ret); 112 | 113 | } else { 114 | 115 | while(1) { 116 | 117 | csock = net_accept (sock, (struct sockaddr *) &client, &clientlen); 118 | 119 | if ( csock < 0 ) { 120 | printf("Error connecting socket %d!\n", csock); 121 | while(1); 122 | } 123 | 124 | printf("Connecting port %d from %s\n", client.sin_port, inet_ntoa(client.sin_addr)); 125 | memset (temp, 0, 1026); 126 | ret = net_recv (csock, temp, 1024, 0); 127 | printf("Received %d bytes\n", ret); 128 | 129 | if ( !strncmp( temp, http_get_index, strlen(http_get_index) ) ) { 130 | hits++; 131 | net_send(csock, http_200, strlen(http_200), 0); 132 | net_send(csock, http_html_hdr, strlen(http_html_hdr), 0); 133 | sprintf(temp, indexdata, hits); 134 | net_send(csock, temp, strlen(temp), 0); 135 | } 136 | 137 | net_close (csock); 138 | 139 | } 140 | } 141 | } 142 | } 143 | return NULL; 144 | } 145 | 146 | //--------------------------------------------------------------------------------- 147 | void *initialise() { 148 | //--------------------------------------------------------------------------------- 149 | 150 | void *framebuffer; 151 | 152 | VIDEO_Init(); 153 | PAD_Init(); 154 | 155 | rmode = VIDEO_GetPreferredMode(NULL); 156 | framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 157 | console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 158 | 159 | VIDEO_Configure(rmode); 160 | VIDEO_SetNextFramebuffer(framebuffer); 161 | VIDEO_SetBlack(FALSE); 162 | VIDEO_Flush(); 163 | VIDEO_WaitVSync(); 164 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 165 | 166 | return framebuffer; 167 | 168 | } 169 | -------------------------------------------------------------------------------- /devices/usbgecko/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS:= `ls | egrep -v '^(CVS)$$'` 2 | 3 | all: 4 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; 5 | 6 | clean: 7 | @rm -f *.bz2 8 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; 9 | 10 | -------------------------------------------------------------------------------- /devices/usbgecko/gdbstub/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -ldb -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | #--------------------------------------------------------------------------------- 108 | else 109 | 110 | DEPENDS := $(OFILES:.o=.d) 111 | 112 | #--------------------------------------------------------------------------------- 113 | # main targets 114 | #--------------------------------------------------------------------------------- 115 | $(OUTPUT).dol: $(OUTPUT).elf 116 | $(OUTPUT).elf: $(OFILES) 117 | 118 | #--------------------------------------------------------------------------------- 119 | # This rule links in binary data with the .jpg extension 120 | #--------------------------------------------------------------------------------- 121 | %.jpg.o : %.jpg 122 | #--------------------------------------------------------------------------------- 123 | @echo $(notdir $<) 124 | $(bin2o) 125 | 126 | -include $(DEPENDS) 127 | 128 | #--------------------------------------------------------------------------------- 129 | endif 130 | #--------------------------------------------------------------------------------- 131 | -------------------------------------------------------------------------------- /devices/usbgecko/gdbstub/source/gdbstub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void *xfb = NULL; 10 | static GXRModeObj *rmode = NULL; 11 | 12 | int main() { 13 | 14 | VIDEO_Init(); 15 | PAD_Init(); 16 | 17 | rmode = VIDEO_GetPreferredMode(NULL); 18 | 19 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 20 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 21 | 22 | VIDEO_Configure(rmode); 23 | VIDEO_SetNextFramebuffer(xfb); 24 | VIDEO_SetBlack(FALSE); 25 | VIDEO_Flush(); 26 | VIDEO_WaitVSync(); 27 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 28 | 29 | /* Configure for use with USB on EXI channel 1 (memcard slot B) */ 30 | /* Other option: GDBSTUB_DEVICE_TCP. Note: second parameter acts as port for this type of device */ 31 | DEBUG_Init(GDBSTUB_DEVICE_USB,1); 32 | 33 | 34 | printf("Waiting for debugger ...\n"); 35 | /* This function call enters the debug stub for the first time */ 36 | /* It's needed to call this if one wants to start debugging. */ 37 | _break(); 38 | 39 | printf("debugger connected ...\n"); 40 | 41 | while(1) 42 | { 43 | VIDEO_WaitVSync(); 44 | PAD_ScanPads(); 45 | 46 | int buttons = PAD_ButtonsDown(0); 47 | 48 | if(buttons & PAD_BUTTON_A) { 49 | printf("Button A pressed.\n"); 50 | } 51 | 52 | if (buttons & PAD_BUTTON_START) { 53 | void (*reload)() = (void(*)())0x80001800; 54 | reload(); 55 | } 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /filesystem/directory/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -lfat -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | #--------------------------------------------------------------------------------- 108 | else 109 | 110 | DEPENDS := $(OFILES:.o=.d) 111 | 112 | #--------------------------------------------------------------------------------- 113 | # main targets 114 | #--------------------------------------------------------------------------------- 115 | $(OUTPUT).dol: $(OUTPUT).elf 116 | $(OUTPUT).elf: $(OFILES) 117 | 118 | #--------------------------------------------------------------------------------- 119 | # This rule links in binary data with the .jpg extension 120 | #--------------------------------------------------------------------------------- 121 | %.jpg.o : %.jpg 122 | #--------------------------------------------------------------------------------- 123 | @echo $(notdir $<) 124 | $(bin2o) 125 | 126 | -include $(DEPENDS) 127 | 128 | #--------------------------------------------------------------------------------- 129 | endif 130 | #--------------------------------------------------------------------------------- 131 | -------------------------------------------------------------------------------- /filesystem/directory/source/directory.c: -------------------------------------------------------------------------------- 1 | // SD Card Directory Listing Demo 2 | // Updated 12/19/2008 by PunMaster 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | static void *xfb = NULL; 17 | static GXRModeObj *rmode = NULL; 18 | 19 | void dirlist(char* path) { 20 | 21 | DIR* pdir = opendir(path); 22 | 23 | if (pdir != NULL) { 24 | 25 | while(true) { 26 | struct dirent* pent = readdir(pdir); 27 | if(pent == NULL) break; 28 | 29 | if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0) { 30 | char dnbuf[PATH_MAX]; 31 | sprintf(dnbuf, "%s/%s", path, pent->d_name); 32 | 33 | struct stat statbuf; 34 | stat(dnbuf, &statbuf); 35 | 36 | if(S_ISDIR(statbuf.st_mode)) { 37 | printf("%s \n", dnbuf); 38 | dirlist(dnbuf); 39 | } else { 40 | printf("%s (%d)\n", dnbuf, (int)statbuf.st_size); 41 | } 42 | } 43 | } 44 | 45 | closedir(pdir); 46 | } else { 47 | printf("opendir() failure.\n"); 48 | } 49 | } 50 | 51 | int main(int argc, char **argv) { 52 | // Initialise the video system 53 | VIDEO_Init(); 54 | 55 | // This function initialises the attached controllers 56 | PAD_Init(); 57 | 58 | // Obtain the preferred video mode from the system 59 | // This will correspond to the settings in the Wii menu 60 | rmode = VIDEO_GetPreferredMode(NULL); 61 | 62 | // Allocate memory for the display in the uncached region 63 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 64 | 65 | // Initialise the console, required for printf 66 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 67 | 68 | // Set up the video registers with the chosen mode 69 | VIDEO_Configure(rmode); 70 | 71 | // Tell the video hardware where our display memory is 72 | VIDEO_SetNextFramebuffer(xfb); 73 | 74 | // Make the display visible 75 | VIDEO_SetBlack(FALSE); 76 | 77 | // Flush the video register changes to the hardware 78 | VIDEO_Flush(); 79 | 80 | // Wait for Video setup to complete 81 | VIDEO_WaitVSync(); 82 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 83 | 84 | // The console understands VT terminal escape codes 85 | // This positions the cursor on row 2, column 0 86 | // we can use variables for this with format codes too 87 | // e.g. printf ("\x1b[%d;%dH", row, column ); 88 | printf("\x1b[2;0H"); 89 | 90 | if(fatInitDefault()) { 91 | dirlist("/"); 92 | } else { 93 | printf("fatInitDefault() failure.\n"); 94 | } 95 | 96 | while(1) { 97 | // Call WPAD_ScanPads each loop, this reads the latest controller states 98 | PAD_ScanPads(); 99 | 100 | // PAD_ButtonsDown tells us which buttons were pressed in this loop 101 | // this is a "one shot" state which will not fire again until the button has been released 102 | u32 pressed = PAD_ButtonsDown(0); 103 | 104 | // We return to the launcher application via exit 105 | if ( pressed & PAD_BUTTON_START ) exit(0); 106 | 107 | // Wait for the next frame 108 | VIDEO_WaitVSync(); 109 | } 110 | 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /graphics/fb/consoletest/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 77 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 78 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 79 | 80 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 81 | 82 | #--------------------------------------------------------------------------------- 83 | # build a list of include paths 84 | #--------------------------------------------------------------------------------- 85 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 86 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 87 | -I$(CURDIR)/$(BUILD) \ 88 | -I$(LIBOGC_INC) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # build a list of library paths 92 | #--------------------------------------------------------------------------------- 93 | export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 94 | 95 | export OUTPUT := $(CURDIR)/$(TARGET) 96 | .PHONY: $(BUILD) clean 97 | 98 | #--------------------------------------------------------------------------------- 99 | $(BUILD): 100 | @[ -d $@ ] || mkdir -p $@ 101 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 102 | 103 | #--------------------------------------------------------------------------------- 104 | clean: 105 | @echo clean ... 106 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 107 | 108 | #--------------------------------------------------------------------------------- 109 | else 110 | 111 | DEPENDS := $(OFILES:.o=.d) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # main targets 115 | #--------------------------------------------------------------------------------- 116 | $(OUTPUT).dol: $(OUTPUT).elf 117 | $(OUTPUT).elf: $(OFILES) 118 | 119 | $(OFILES_SOURCES) : $(HFILES) 120 | 121 | #--------------------------------------------------------------------------------- 122 | # This rule links in binary data with the .jpg extension 123 | #--------------------------------------------------------------------------------- 124 | %.jpg.o %_jpg.h : %.jpg 125 | #--------------------------------------------------------------------------------- 126 | @echo $(notdir $<) 127 | $(bin2o) 128 | 129 | -include $(DEPENDS) 130 | 131 | #--------------------------------------------------------------------------------- 132 | endif 133 | #--------------------------------------------------------------------------------- 134 | -------------------------------------------------------------------------------- /graphics/fb/consoletest/source/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | static void *xfb = NULL; 15 | 16 | u32 first_frame = 1; 17 | GXRModeObj *rmode; 18 | vu16 oldstate; 19 | vu16 keystate; 20 | vu16 keydown; 21 | vu16 keyup; 22 | PADStatus pad[4]; 23 | 24 | 25 | int main() { 26 | 27 | VIDEO_Init(); 28 | 29 | rmode = VIDEO_GetPreferredMode(NULL); 30 | 31 | PAD_Init(); 32 | 33 | 34 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 35 | 36 | VIDEO_Configure(rmode); 37 | 38 | VIDEO_SetNextFramebuffer(xfb); 39 | 40 | VIDEO_SetBlack(FALSE); 41 | VIDEO_Flush(); 42 | VIDEO_WaitVSync(); 43 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 44 | 45 | 46 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*2); 47 | 48 | 49 | time_t gc_time; 50 | gc_time = time(NULL); 51 | 52 | srand(gc_time); 53 | 54 | printf("testing console\n"); 55 | std::cout << "Hello World" << std::endl; 56 | printf("random number is %08x\n",rand()); 57 | 58 | while(1) { 59 | 60 | gc_time = time(NULL); 61 | printf("\x1b[10;0HRTC time is %s ",ctime(&gc_time)); 62 | 63 | VIDEO_WaitVSync(); 64 | PAD_ScanPads(); 65 | 66 | int buttonsDown = PAD_ButtonsDown(0); 67 | 68 | if (buttonsDown & PAD_BUTTON_START) { 69 | exit(0); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /graphics/fb/pageflip/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | 108 | #--------------------------------------------------------------------------------- 109 | else 110 | 111 | DEPENDS := $(OFILES:.o=.d) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # main targets 115 | #--------------------------------------------------------------------------------- 116 | $(OUTPUT).dol: $(OUTPUT).elf 117 | $(OUTPUT).elf: $(OFILES) 118 | 119 | -include $(DEPENDS) 120 | 121 | #--------------------------------------------------------------------------------- 122 | endif 123 | #--------------------------------------------------------------------------------- 124 | -------------------------------------------------------------------------------- /graphics/fb/pageflip/source/flip.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * pflip.c 3 | * 4 | * libogc example for 2D video page flipping without tearing. 5 | * Shows a checkerboard and bouncing square. 6 | ****************************************************************************/ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /*** 2D Video Globals ***/ 14 | GXRModeObj *vmode; /*** Graphics Mode Object ***/ 15 | u32 *xfb[2] = { NULL, NULL }; /*** Framebuffers ***/ 16 | int whichfb = 0; /*** Frame buffer toggle ***/ 17 | 18 | /**************************************************************************** 19 | * CvtRGB 20 | * 21 | * This function simply returns two RGB pixels as one Y1CbY2Cr. 22 | *****************************************************************************/ 23 | u32 24 | CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2) 25 | { 26 | int y1, cb1, cr1, y2, cb2, cr2, cb, cr; 27 | 28 | y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000; 29 | cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000; 30 | cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000; 31 | 32 | y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000; 33 | cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000; 34 | cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000; 35 | 36 | cb = (cb1 + cb2) >> 1; 37 | cr = (cr1 + cr2) >> 1; 38 | 39 | return (y1 << 24) | (cb << 16) | (y2 << 8) | cr; 40 | } 41 | 42 | /**************************************************************************** 43 | * Initialise Video 44 | * 45 | * Before doing anything in libogc, it's recommended to configure a video 46 | * output. 47 | ****************************************************************************/ 48 | static void 49 | Initialise (void) { 50 | 51 | VIDEO_Init(); /*** ALWAYS CALL FIRST IN ANY LIBOGC PROJECT! 52 | Not only does it initialise the video 53 | subsystem, but also sets up the ogc os 54 | ***/ 55 | 56 | PAD_Init(); /*** Initialise pads for input ***/ 57 | 58 | /*** Try to match the current video display mode 59 | using the higher resolution interlaced. 60 | 61 | So NTSC/MPAL gives a display area of 640x480 62 | PAL display area is 640x528 63 | ***/ 64 | 65 | vmode = VIDEO_GetPreferredMode(NULL); 66 | 67 | /*** Let libogc configure the mode ***/ 68 | VIDEO_Configure (vmode); 69 | 70 | /*** Now configure the framebuffer. 71 | Really a framebuffer is just a chunk of memory 72 | to hold the display line by line. 73 | ***/ 74 | 75 | xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); 76 | 77 | /*** I prefer also to have a second buffer for double-buffering. 78 | This is not needed for the console demo. 79 | ***/ 80 | xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); 81 | 82 | 83 | /*** Define a console ***/ 84 | console_init (xfb[0], 20, 64, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth * 2); 85 | 86 | /*** Clear framebuffer to black ***/ 87 | VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK); 88 | VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK); 89 | 90 | /*** Set the framebuffer to be displayed at next VBlank ***/ 91 | VIDEO_SetNextFramebuffer (xfb[0]); 92 | 93 | /*** Get the PAD status updated by libogc ***/ 94 | VIDEO_SetBlack (0); 95 | 96 | /*** Update the video for next vblank ***/ 97 | VIDEO_Flush (); 98 | 99 | VIDEO_WaitVSync (); /*** Wait for VBL ***/ 100 | 101 | if (vmode->viTVMode & VI_NON_INTERLACE) 102 | VIDEO_WaitVSync (); 103 | 104 | } 105 | 106 | 107 | /**************************************************************************** 108 | * Main 109 | * 110 | * Create a checkerboard, and flip it 111 | ****************************************************************************/ 112 | int main () { 113 | u32 *checkerboard; 114 | u32 colour1, colour2, colswap; 115 | int rows, cols; 116 | int height; 117 | int i, j, t, v; 118 | int pos = 0; 119 | int startx, starty; 120 | int directionx, directiony; 121 | PADStatus pads[4]; 122 | 123 | /*** Start libOGC ***/ 124 | Initialise (); 125 | 126 | /*** Allocate a buffer to hold the checkerboard ***/ 127 | height = vmode->xfbHeight + 64; 128 | checkerboard = (u32 *) malloc ((704 * height * 2)); 129 | colour1 = CvtRGB (0x00, 0x00, 0x80, 0x00, 0x00, 0x80); 130 | colour2 = CvtRGB (0x00, 0x00, 0xe0, 0x00, 0x00, 0xe0); 131 | 132 | for (i = 0; i < height; i += 32) { 133 | /*** Draw a line ***/ 134 | colswap = colour1; 135 | colour1 = colour2; 136 | colour2 = colswap; 137 | 138 | for (v = 0; v < 32; v++) 139 | { 140 | for (t = 0; t < 11; t++) 141 | { 142 | for (j = 0; j < 16; j++) 143 | checkerboard[pos++] = colour1; 144 | 145 | for (j = 0; j < 16; j++) 146 | checkerboard[pos++] = colour2; 147 | } 148 | 149 | } 150 | } 151 | 152 | pos = 0; 153 | colour1 = CvtRGB (0xff, 0xff, 0xff, 0xff, 0xff, 0xff); 154 | startx = starty = directionx = directiony = 0; 155 | 156 | while(1) { 157 | 158 | /*** Flip to off screen xfb ***/ 159 | whichfb ^= 1; 160 | 161 | /*** Draw checkerboard ***/ 162 | t = 0; 163 | v = 0; 164 | 165 | for (j = 0; j < vmode->xfbHeight; j++) { 166 | memcpy (&xfb[whichfb][v], &checkerboard[pos + t], 1280); 167 | t += 352; 168 | v += 320; 169 | } 170 | 171 | /*** Draw Bouncing Square ***/ 172 | if (directionx) 173 | startx -= 4; 174 | else 175 | startx += 4; 176 | 177 | if (directiony) 178 | starty -= 2; 179 | else 180 | starty += 2; 181 | 182 | if (startx >= 576) directionx = 1; 183 | 184 | if (starty >= (vmode->xfbHeight - 64)) directiony = 1; 185 | 186 | if (startx < 0) { 187 | startx = 0; 188 | directionx = 0; 189 | } 190 | 191 | if (starty < 0) { 192 | starty = 0; 193 | directiony = 0; 194 | } 195 | 196 | v = (starty * 320) + (startx >> 1); 197 | 198 | for (rows = 0; rows < 64; rows++) { 199 | for (cols = 0; cols < 32; cols++) 200 | xfb[whichfb][v + cols] = colour1; 201 | 202 | v += 320; 203 | } 204 | 205 | /*** Set this as next frame to display ***/ 206 | VIDEO_SetNextFramebuffer (xfb[whichfb]); 207 | VIDEO_Flush (); 208 | VIDEO_WaitVSync (); 209 | 210 | /*** Move the checkerboard along ***/ 211 | pos += 353; 212 | 213 | if (pos == ((352 * 64) + 64)) pos = 0; 214 | 215 | PAD_ScanPads(); 216 | PAD_Read(pads); 217 | if (pads[0].button & PAD_BUTTON_START) { 218 | exit(0); 219 | } 220 | 221 | } 222 | 223 | return 0; 224 | } 225 | -------------------------------------------------------------------------------- /graphics/gx/acube/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 77 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 78 | $(sFILES:.s=.o) $(SFILES:.S=.o) 79 | 80 | #--------------------------------------------------------------------------------- 81 | # build a list of include paths 82 | #--------------------------------------------------------------------------------- 83 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 85 | -I$(CURDIR)/$(BUILD) \ 86 | -I$(LIBOGC_INC) 87 | 88 | #--------------------------------------------------------------------------------- 89 | # build a list of library paths 90 | #--------------------------------------------------------------------------------- 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 92 | -L$(LIBOGC_LIB) 93 | 94 | export OUTPUT := $(CURDIR)/$(TARGET) 95 | .PHONY: $(BUILD) clean 96 | 97 | #--------------------------------------------------------------------------------- 98 | $(BUILD): 99 | @[ -d $@ ] || mkdir -p $@ 100 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 101 | 102 | #--------------------------------------------------------------------------------- 103 | clean: 104 | @echo clean ... 105 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 106 | 107 | #--------------------------------------------------------------------------------- 108 | else 109 | 110 | DEPENDS := $(OFILES:.o=.d) 111 | 112 | #--------------------------------------------------------------------------------- 113 | # main targets 114 | #--------------------------------------------------------------------------------- 115 | $(OUTPUT).dol: $(OUTPUT).elf 116 | $(OUTPUT).elf: $(OFILES) 117 | 118 | -include $(DEPENDS) 119 | 120 | #--------------------------------------------------------------------------------- 121 | endif 122 | #--------------------------------------------------------------------------------- 123 | -------------------------------------------------------------------------------- /graphics/gx/gxSprites/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/gxSprites/textures/ballsprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/gxSprites/textures/ballsprites.png -------------------------------------------------------------------------------- /graphics/gx/gxSprites/textures/textures.scf: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson01/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson01/source/lesson1.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | nehe lesson 1 port to GX by WinterMute 4 | 5 | ---------------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #define DEFAULT_FIFO_SIZE (256*1024) 16 | 17 | static void *frameBuffer[2] = { NULL, NULL}; 18 | GXRModeObj *rmode; 19 | 20 | //--------------------------------------------------------------------------------- 21 | int main( int argc, char **argv ){ 22 | //--------------------------------------------------------------------------------- 23 | f32 yscale; 24 | 25 | u32 xfbHeight; 26 | 27 | Mtx view; 28 | Mtx44 perspective; 29 | 30 | u32 fb = 0; // initial framebuffer index 31 | GXColor background = {0, 0, 0, 0xff}; 32 | 33 | 34 | // init the vi. 35 | VIDEO_Init(); 36 | 37 | rmode = VIDEO_GetPreferredMode(NULL); 38 | PAD_Init(); 39 | 40 | // allocate 2 framebuffers for double buffering 41 | frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 42 | frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 43 | 44 | VIDEO_Configure(rmode); 45 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 46 | VIDEO_SetBlack(FALSE); 47 | VIDEO_Flush(); 48 | VIDEO_WaitVSync(); 49 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 50 | 51 | // setup the fifo and then init the flipper 52 | void *gp_fifo = NULL; 53 | gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); 54 | memset(gp_fifo,0,DEFAULT_FIFO_SIZE); 55 | 56 | GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); 57 | 58 | // clears the bg to color and clears the z buffer 59 | GX_SetCopyClear(background, 0x00ffffff); 60 | 61 | // other gx setup 62 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 63 | yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); 64 | xfbHeight = GX_SetDispCopyYScale(yscale); 65 | GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); 66 | GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); 67 | GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); 68 | GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); 69 | GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 70 | 71 | GX_SetCullMode(GX_CULL_NONE); 72 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 73 | GX_SetDispCopyGamma(GX_GM_1_0); 74 | 75 | // setup our camera at the origin 76 | // looking down the -z axis with y up 77 | guVector cam = {0.0F, 0.0F, 0.0F}, 78 | up = {0.0F, 1.0F, 0.0F}, 79 | look = {0.0F, 0.0F, -1.0F}; 80 | guLookAt(view, &cam, &up, &look); 81 | 82 | 83 | // setup our projection matrix 84 | // this creates a perspective matrix with a view angle of 90, 85 | // and aspect ratio based on the display resolution 86 | f32 w = rmode->viWidth; 87 | f32 h = rmode->viHeight; 88 | guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); 89 | GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); 90 | 91 | while(1) { 92 | 93 | PAD_ScanPads(); 94 | 95 | if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { 96 | exit(0); 97 | } 98 | // do this before drawing 99 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 100 | 101 | 102 | // do this stuff after drawing 103 | GX_DrawDone(); 104 | 105 | fb ^= 1; // flip framebuffer 106 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 107 | GX_SetColorUpdate(GX_TRUE); 108 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 109 | 110 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 111 | 112 | VIDEO_Flush(); 113 | 114 | VIDEO_WaitVSync(); 115 | 116 | 117 | } 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson02/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson02/source/lesson2.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | nehe lesson 2 port to GX by WinterMute 4 | 5 | ---------------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #define DEFAULT_FIFO_SIZE (256*1024) 16 | 17 | static void *frameBuffer[2] = { NULL, NULL}; 18 | GXRModeObj *rmode; 19 | 20 | //--------------------------------------------------------------------------------- 21 | int main( int argc, char **argv ){ 22 | //--------------------------------------------------------------------------------- 23 | f32 yscale; 24 | 25 | u32 xfbHeight; 26 | 27 | Mtx view; 28 | Mtx44 perspective; 29 | Mtx model, modelview; 30 | 31 | u32 fb = 0; // initial framebuffer index 32 | GXColor background = {0, 0, 0, 0xff}; 33 | 34 | 35 | // init the vi. 36 | VIDEO_Init(); 37 | 38 | rmode = VIDEO_GetPreferredMode(NULL); 39 | PAD_Init(); 40 | 41 | // allocate 2 framebuffers for double buffering 42 | frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 43 | frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 44 | 45 | VIDEO_Configure(rmode); 46 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 47 | VIDEO_SetBlack(FALSE); 48 | VIDEO_Flush(); 49 | VIDEO_WaitVSync(); 50 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 51 | 52 | // setup the fifo and then init the flipper 53 | void *gp_fifo = NULL; 54 | gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); 55 | memset(gp_fifo,0,DEFAULT_FIFO_SIZE); 56 | 57 | GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); 58 | 59 | // clears the bg to color and clears the z buffer 60 | GX_SetCopyClear(background, 0x00ffffff); 61 | 62 | // other gx setup 63 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 64 | yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); 65 | xfbHeight = GX_SetDispCopyYScale(yscale); 66 | GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); 67 | GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); 68 | GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); 69 | GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); 70 | GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 71 | 72 | GX_SetCullMode(GX_CULL_NONE); 73 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 74 | GX_SetDispCopyGamma(GX_GM_1_0); 75 | 76 | 77 | // setup the vertex descriptor 78 | // tells the flipper to expect direct data 79 | GX_ClearVtxDesc(); 80 | GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); 81 | 82 | // setup the vertex attribute table 83 | // describes the data 84 | // args: vat location 0-7, type of data, data format, size, scale 85 | // so for ex. in the first call we are sending position data with 86 | // 3 values X,Y,Z of size F32. scale sets the number of fractional 87 | // bits for non float data. 88 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); 89 | 90 | GX_SetNumChans(1); 91 | GX_SetNumTexGens(0); 92 | GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); 93 | GX_SetTevColor(GX_TEVREG1, (GXColor){ 0xFF, 0xFF, 0xFF, 0 }); 94 | GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C1); 95 | GX_SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); 96 | GX_SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A1); 97 | GX_SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); 98 | 99 | // setup our camera at the origin 100 | // looking down the -z axis with y up 101 | guVector cam = {0.0F, 0.0F, 0.0F}, 102 | up = {0.0F, 1.0F, 0.0F}, 103 | look = {0.0F, 0.0F, -1.0F}; 104 | guLookAt(view, &cam, &up, &look); 105 | 106 | 107 | // setup our projection matrix 108 | // this creates a perspective matrix with a view angle of 90, 109 | // and aspect ratio based on the display resolution 110 | f32 w = rmode->viWidth; 111 | f32 h = rmode->viHeight; 112 | guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); 113 | GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); 114 | 115 | while(1) { 116 | 117 | PAD_ScanPads(); 118 | 119 | if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { 120 | exit(0); 121 | } 122 | 123 | // do this before drawing 124 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 125 | 126 | guMtxIdentity(model); 127 | guMtxTransApply(model, model, -1.5f,0.0f,-6.0f); 128 | guMtxConcat(view,model,modelview); 129 | // load the modelview matrix into matrix memory 130 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 131 | 132 | GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); 133 | GX_Position3f32( 0.0f, 1.0f, 0.0f); // Top 134 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 135 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 136 | GX_End(); 137 | 138 | guMtxTransApply(model, model, 3.0f,0.0f,0.0f); 139 | guMtxConcat(view,model,modelview); 140 | // load the modelview matrix into matrix memory 141 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 142 | 143 | GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Draw A Quad 144 | GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left 145 | GX_Position3f32( 1.0f, 1.0f, 0.0f); // Top Right 146 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 147 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 148 | GX_End(); // Done Drawing The Quad 149 | 150 | // do this stuff after drawing 151 | GX_DrawDone(); 152 | 153 | fb ^= 1; // flip framebuffer 154 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 155 | GX_SetColorUpdate(GX_TRUE); 156 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 157 | 158 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 159 | 160 | VIDEO_Flush(); 161 | 162 | VIDEO_WaitVSync(); 163 | 164 | 165 | } 166 | return 0; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson03/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson03/source/lesson3.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | nehe lesson 3 port to GX by WinterMute 4 | 5 | ---------------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #define DEFAULT_FIFO_SIZE (256*1024) 16 | 17 | static void *frameBuffer[2] = { NULL, NULL}; 18 | GXRModeObj *rmode; 19 | 20 | //--------------------------------------------------------------------------------- 21 | int main( int argc, char **argv ){ 22 | //--------------------------------------------------------------------------------- 23 | f32 yscale; 24 | 25 | u32 xfbHeight; 26 | 27 | Mtx view; 28 | Mtx44 perspective; 29 | Mtx model, modelview; 30 | 31 | u32 fb = 0; // initial framebuffer index 32 | GXColor background = {0, 0, 0, 0xff}; 33 | 34 | 35 | // init the vi. 36 | VIDEO_Init(); 37 | 38 | rmode = VIDEO_GetPreferredMode(NULL); 39 | PAD_Init(); 40 | 41 | // allocate 2 framebuffers for double buffering 42 | frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 43 | frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 44 | 45 | VIDEO_Configure(rmode); 46 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 47 | VIDEO_SetBlack(FALSE); 48 | VIDEO_Flush(); 49 | VIDEO_WaitVSync(); 50 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 51 | 52 | // setup the fifo and then init the flipper 53 | void *gp_fifo = NULL; 54 | gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); 55 | memset(gp_fifo,0,DEFAULT_FIFO_SIZE); 56 | 57 | GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); 58 | 59 | // clears the bg to color and clears the z buffer 60 | GX_SetCopyClear(background, 0x00ffffff); 61 | 62 | // other gx setup 63 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 64 | yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); 65 | xfbHeight = GX_SetDispCopyYScale(yscale); 66 | GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); 67 | GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); 68 | GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); 69 | GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); 70 | GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 71 | 72 | GX_SetCullMode(GX_CULL_NONE); 73 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 74 | GX_SetDispCopyGamma(GX_GM_1_0); 75 | 76 | 77 | // setup the vertex descriptor 78 | // tells the flipper to expect direct data 79 | GX_ClearVtxDesc(); 80 | GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); 81 | GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); 82 | 83 | // setup the vertex attribute table 84 | // describes the data 85 | // args: vat location 0-7, type of data, data format, size, scale 86 | // so for ex. in the first call we are sending position data with 87 | // 3 values X,Y,Z of size F32. scale sets the number of fractional 88 | // bits for non float data. 89 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); 90 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); 91 | 92 | GX_SetNumChans(1); 93 | GX_SetNumTexGens(0); 94 | GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); 95 | GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); 96 | 97 | // setup our camera at the origin 98 | // looking down the -z axis with y up 99 | guVector cam = {0.0F, 0.0F, 0.0F}, 100 | up = {0.0F, 1.0F, 0.0F}, 101 | look = {0.0F, 0.0F, -1.0F}; 102 | guLookAt(view, &cam, &up, &look); 103 | 104 | 105 | // setup our projection matrix 106 | // this creates a perspective matrix with a view angle of 90, 107 | // and aspect ratio based on the display resolution 108 | f32 w = rmode->viWidth; 109 | f32 h = rmode->viHeight; 110 | guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); 111 | GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); 112 | 113 | while(1) { 114 | 115 | PAD_ScanPads(); 116 | 117 | if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { 118 | exit(0); 119 | } 120 | 121 | // do this before drawing 122 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 123 | 124 | guMtxIdentity(model); 125 | guMtxTransApply(model, model, -1.5f,0.0f,-6.0f); 126 | guMtxConcat(view,model,modelview); 127 | // load the modelview matrix into matrix memory 128 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 129 | 130 | GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); 131 | GX_Position3f32( 0.0f, 1.0f, 0.0f); // Top 132 | GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red 133 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 134 | GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green 135 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 136 | GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue 137 | GX_End(); 138 | 139 | guMtxTransApply(model, model, 3.0f,0.0f,0.0f); 140 | guMtxConcat(view,model,modelview); 141 | // load the modelview matrix into matrix memory 142 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 143 | 144 | GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Draw A Quad 145 | GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left 146 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 147 | GX_Position3f32( 1.0f, 1.0f, 0.0f); // Top Right 148 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 149 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 150 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 151 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 152 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 153 | GX_End(); // Done Drawing The Quad 154 | 155 | // do this stuff after drawing 156 | GX_DrawDone(); 157 | 158 | fb ^= 1; // flip framebuffer 159 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 160 | GX_SetColorUpdate(GX_TRUE); 161 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 162 | 163 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 164 | 165 | VIDEO_Flush(); 166 | 167 | VIDEO_WaitVSync(); 168 | 169 | 170 | } 171 | return 0; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson04/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson04/source/lesson4.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | nehe lesson 4 port to GX by WinterMute 4 | 5 | ---------------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #define DEFAULT_FIFO_SIZE (256*1024) 16 | 17 | static void *frameBuffer[2] = { NULL, NULL}; 18 | GXRModeObj *rmode; 19 | 20 | //--------------------------------------------------------------------------------- 21 | int main( int argc, char **argv ){ 22 | //--------------------------------------------------------------------------------- 23 | f32 yscale; 24 | 25 | u32 xfbHeight; 26 | 27 | Mtx view; 28 | Mtx44 perspective; 29 | Mtx model, modelview; 30 | 31 | float rtri = 0.0f , rquad = 0.0f; 32 | 33 | u32 fb = 0; // initial framebuffer index 34 | GXColor background = {0, 0, 0, 0xff}; 35 | 36 | 37 | // init the vi. 38 | VIDEO_Init(); 39 | 40 | rmode = VIDEO_GetPreferredMode(NULL); 41 | PAD_Init(); 42 | 43 | // allocate 2 framebuffers for double buffering 44 | frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 45 | frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 46 | 47 | VIDEO_Configure(rmode); 48 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 49 | VIDEO_SetBlack(FALSE); 50 | VIDEO_Flush(); 51 | VIDEO_WaitVSync(); 52 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 53 | 54 | // setup the fifo and then init the flipper 55 | void *gp_fifo = NULL; 56 | gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); 57 | memset(gp_fifo,0,DEFAULT_FIFO_SIZE); 58 | 59 | GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); 60 | 61 | // clears the bg to color and clears the z buffer 62 | GX_SetCopyClear(background, 0x00ffffff); 63 | 64 | // other gx setup 65 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 66 | yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); 67 | xfbHeight = GX_SetDispCopyYScale(yscale); 68 | GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); 69 | GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); 70 | GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); 71 | GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); 72 | GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 73 | 74 | GX_SetCullMode(GX_CULL_NONE); 75 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 76 | GX_SetDispCopyGamma(GX_GM_1_0); 77 | 78 | 79 | // setup the vertex descriptor 80 | // tells the flipper to expect direct data 81 | GX_ClearVtxDesc(); 82 | GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); 83 | GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); 84 | 85 | // setup the vertex attribute table 86 | // describes the data 87 | // args: vat location 0-7, type of data, data format, size, scale 88 | // so for ex. in the first call we are sending position data with 89 | // 3 values X,Y,Z of size F32. scale sets the number of fractional 90 | // bits for non float data. 91 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); 92 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); 93 | 94 | GX_SetNumChans(1); 95 | GX_SetNumTexGens(0); 96 | GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); 97 | GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); 98 | 99 | // setup our camera at the origin 100 | // looking down the -z axis with y up 101 | guVector cam = {0.0F, 0.0F, 0.0F}, 102 | up = {0.0F, 1.0F, 0.0F}, 103 | look = {0.0F, 0.0F, -1.0F}; 104 | guLookAt(view, &cam, &up, &look); 105 | 106 | 107 | // setup our projection matrix 108 | // this creates a perspective matrix with a view angle of 90, 109 | // and aspect ratio based on the display resolution 110 | f32 w = rmode->viWidth; 111 | f32 h = rmode->viHeight; 112 | guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); 113 | GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); 114 | 115 | guVector Yaxis = {0,1,0}; 116 | guVector Xaxis = {1,0,0}; 117 | 118 | while(1) { 119 | 120 | PAD_ScanPads(); 121 | 122 | if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { 123 | exit(0); 124 | } 125 | 126 | // do this before drawing 127 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 128 | 129 | guMtxIdentity(model); 130 | guMtxRotAxisDeg(model, &Yaxis, rtri); 131 | guMtxTransApply(model, model, -1.5f,0.0f,-6.0f); 132 | guMtxConcat(view,model,modelview); 133 | // load the modelview matrix into matrix memory 134 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 135 | 136 | GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); 137 | GX_Position3f32( 0.0f, 1.0f, 0.0f); // Top 138 | GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red 139 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 140 | GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green 141 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 142 | GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue 143 | GX_End(); 144 | 145 | guMtxIdentity(model); 146 | guMtxRotAxisDeg(model, &Xaxis, rquad); 147 | guMtxTransApply(model, model, 1.5f,0.0f,-6.0f); 148 | guMtxConcat(view,model,modelview); 149 | // load the modelview matrix into matrix memory 150 | GX_LoadPosMtxImm(modelview, GX_PNMTX0); 151 | 152 | GX_Begin(GX_QUADS, GX_VTXFMT0, 4); // Draw A Quad 153 | GX_Position3f32(-1.0f, 1.0f, 0.0f); // Top Left 154 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 155 | GX_Position3f32( 1.0f, 1.0f, 0.0f); // Top Right 156 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 157 | GX_Position3f32( 1.0f,-1.0f, 0.0f); // Bottom Right 158 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 159 | GX_Position3f32(-1.0f,-1.0f, 0.0f); // Bottom Left 160 | GX_Color3f32(0.5f,0.5f,1.0f); // Set The Color To Blue 161 | GX_End(); // Done Drawing The Quad 162 | 163 | // do this stuff after drawing 164 | GX_DrawDone(); 165 | 166 | fb ^= 1; // flip framebuffer 167 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 168 | GX_SetColorUpdate(GX_TRUE); 169 | GX_CopyDisp(frameBuffer[fb],GX_TRUE); 170 | 171 | VIDEO_SetNextFramebuffer(frameBuffer[fb]); 172 | 173 | VIDEO_Flush(); 174 | 175 | VIDEO_WaitVSync(); 176 | 177 | rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW ) 178 | rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) 179 | 180 | } 181 | return 0; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson05/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson06/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson06/textures/NeHe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson06/textures/NeHe.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson06/textures/NeHe.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson07/textures/crate.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson07/textures/crate.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson07/textures/crate.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson08/textures/Glass.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson08/textures/Glass.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson08/textures/glass.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson09/textures/Star.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson09/textures/Star.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson09/textures/startex.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson10/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := data 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | %.txt.o %_txt.h : %.txt 127 | #--------------------------------------------------------------------------------- 128 | @echo $(notdir $<) 129 | @$(bin2o) 130 | 131 | #--------------------------------------------------------------------------------- 132 | %.tpl.o %_tpl.h : %.tpl 133 | #--------------------------------------------------------------------------------- 134 | @echo $(notdir $<) 135 | @$(bin2o) 136 | 137 | 138 | -include $(DEPSDIR)/*.d 139 | 140 | #--------------------------------------------------------------------------------- 141 | endif 142 | #--------------------------------------------------------------------------------- 143 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson10/data/world.txt: -------------------------------------------------------------------------------- 1 | NUMPOLYS 36 2 | 3 | // Floor 1 4 | -3.0 0.0 -3.0 0.0 6.0 5 | -3.0 0.0 3.0 0.0 0.0 6 | 3.0 0.0 3.0 6.0 0.0 7 | 8 | -3.0 0.0 -3.0 0.0 6.0 9 | 3.0 0.0 -3.0 6.0 6.0 10 | 3.0 0.0 3.0 6.0 0.0 11 | 12 | // Ceiling 1 13 | -3.0 1.0 -3.0 0.0 6.0 14 | -3.0 1.0 3.0 0.0 0.0 15 | 3.0 1.0 3.0 6.0 0.0 16 | -3.0 1.0 -3.0 0.0 6.0 17 | 3.0 1.0 -3.0 6.0 6.0 18 | 3.0 1.0 3.0 6.0 0.0 19 | 20 | // A1 21 | 22 | -2.0 1.0 -2.0 0.0 1.0 23 | -2.0 0.0 -2.0 0.0 0.0 24 | -0.5 0.0 -2.0 1.5 0.0 25 | -2.0 1.0 -2.0 0.0 1.0 26 | -0.5 1.0 -2.0 1.5 1.0 27 | -0.5 0.0 -2.0 1.5 0.0 28 | 29 | // A2 30 | 31 | 2.0 1.0 -2.0 2.0 1.0 32 | 2.0 0.0 -2.0 2.0 0.0 33 | 0.5 0.0 -2.0 0.5 0.0 34 | 2.0 1.0 -2.0 2.0 1.0 35 | 0.5 1.0 -2.0 0.5 1.0 36 | 0.5 0.0 -2.0 0.5 0.0 37 | 38 | // B1 39 | 40 | -2.0 1.0 2.0 2.0 1.0 41 | -2.0 0.0 2.0 2.0 0.0 42 | -0.5 0.0 2.0 0.5 0.0 43 | -2.0 1.0 2.0 2.0 1.0 44 | -0.5 1.0 2.0 0.5 1.0 45 | -0.5 0.0 2.0 0.5 0.0 46 | 47 | // B2 48 | 49 | 2.0 1.0 2.0 2.0 1.0 50 | 2.0 0.0 2.0 2.0 0.0 51 | 0.5 0.0 2.0 0.5 0.0 52 | 2.0 1.0 2.0 2.0 1.0 53 | 0.5 1.0 2.0 0.5 1.0 54 | 0.5 0.0 2.0 0.5 0.0 55 | 56 | // C1 57 | 58 | -2.0 1.0 -2.0 0.0 1.0 59 | -2.0 0.0 -2.0 0.0 0.0 60 | -2.0 0.0 -0.5 1.5 0.0 61 | -2.0 1.0 -2.0 0.0 1.0 62 | -2.0 1.0 -0.5 1.5 1.0 63 | -2.0 0.0 -0.5 1.5 0.0 64 | 65 | // C2 66 | 67 | -2.0 1.0 2.0 2.0 1.0 68 | -2.0 0.0 2.0 2.0 0.0 69 | -2.0 0.0 0.5 0.5 0.0 70 | -2.0 1.0 2.0 2.0 1.0 71 | -2.0 1.0 0.5 0.5 1.0 72 | -2.0 0.0 0.5 0.5 0.0 73 | 74 | // D1 75 | 76 | 2.0 1.0 -2.0 0.0 1.0 77 | 2.0 0.0 -2.0 0.0 0.0 78 | 2.0 0.0 -0.5 1.5 0.0 79 | 2.0 1.0 -2.0 0.0 1.0 80 | 2.0 1.0 -0.5 1.5 1.0 81 | 2.0 0.0 -0.5 1.5 0.0 82 | 83 | // D2 84 | 85 | 2.0 1.0 2.0 2.0 1.0 86 | 2.0 0.0 2.0 2.0 0.0 87 | 2.0 0.0 0.5 0.5 0.0 88 | 2.0 1.0 2.0 2.0 1.0 89 | 2.0 1.0 0.5 0.5 1.0 90 | 2.0 0.0 0.5 0.5 0.0 91 | 92 | // Upper hallway - L 93 | -0.5 1.0 -3.0 0.0 1.0 94 | -0.5 0.0 -3.0 0.0 0.0 95 | -0.5 0.0 -2.0 1.0 0.0 96 | -0.5 1.0 -3.0 0.0 1.0 97 | -0.5 1.0 -2.0 1.0 1.0 98 | -0.5 0.0 -2.0 1.0 0.0 99 | 100 | // Upper hallway - R 101 | 0.5 1.0 -3.0 0.0 1.0 102 | 0.5 0.0 -3.0 0.0 0.0 103 | 0.5 0.0 -2.0 1.0 0.0 104 | 0.5 1.0 -3.0 0.0 1.0 105 | 0.5 1.0 -2.0 1.0 1.0 106 | 0.5 0.0 -2.0 1.0 0.0 107 | 108 | // Lower hallway - L 109 | -0.5 1.0 3.0 0.0 1.0 110 | -0.5 0.0 3.0 0.0 0.0 111 | -0.5 0.0 2.0 1.0 0.0 112 | -0.5 1.0 3.0 0.0 1.0 113 | -0.5 1.0 2.0 1.0 1.0 114 | -0.5 0.0 2.0 1.0 0.0 115 | 116 | // Lower hallway - R 117 | 0.5 1.0 3.0 0.0 1.0 118 | 0.5 0.0 3.0 0.0 0.0 119 | 0.5 0.0 2.0 1.0 0.0 120 | 0.5 1.0 3.0 0.0 1.0 121 | 0.5 1.0 2.0 1.0 1.0 122 | 0.5 0.0 2.0 1.0 0.0 123 | 124 | 125 | // Left hallway - Lw 126 | 127 | -3.0 1.0 0.5 1.0 1.0 128 | -3.0 0.0 0.5 1.0 0.0 129 | -2.0 0.0 0.5 0.0 0.0 130 | -3.0 1.0 0.5 1.0 1.0 131 | -2.0 1.0 0.5 0.0 1.0 132 | -2.0 0.0 0.5 0.0 0.0 133 | 134 | // Left hallway - Hi 135 | 136 | -3.0 1.0 -0.5 1.0 1.0 137 | -3.0 0.0 -0.5 1.0 0.0 138 | -2.0 0.0 -0.5 0.0 0.0 139 | -3.0 1.0 -0.5 1.0 1.0 140 | -2.0 1.0 -0.5 0.0 1.0 141 | -2.0 0.0 -0.5 0.0 0.0 142 | 143 | // Right hallway - Lw 144 | 145 | 3.0 1.0 0.5 1.0 1.0 146 | 3.0 0.0 0.5 1.0 0.0 147 | 2.0 0.0 0.5 0.0 0.0 148 | 3.0 1.0 0.5 1.0 1.0 149 | 2.0 1.0 0.5 0.0 1.0 150 | 2.0 0.0 0.5 0.0 0.0 151 | 152 | // Right hallway - Hi 153 | 154 | 3.0 1.0 -0.5 1.0 1.0 155 | 3.0 0.0 -0.5 1.0 0.0 156 | 2.0 0.0 -0.5 0.0 0.0 157 | 3.0 1.0 -0.5 1.0 1.0 158 | 2.0 1.0 -0.5 0.0 1.0 159 | 2.0 0.0 -0.5 0.0 0.0 -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson10/textures/Mud.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson10/textures/Mud.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson10/textures/mud.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson11/textures/Tim.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson11/textures/Tim.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson11/textures/Tim.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson12/textures/Cube.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson12/textures/Cube.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson12/textures/Cube.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson19/textures/Particle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/neheGX/lesson19/textures/Particle.bmp -------------------------------------------------------------------------------- /graphics/gx/neheGX/lesson19/textures/Particle.scf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /graphics/gx/texturetest/source/texture.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "textures_tpl.h" 11 | #include "textures.h" 12 | 13 | #define DEFAULT_FIFO_SIZE (256*1024) 14 | 15 | typedef struct tagcamera { 16 | guVector pos; 17 | guVector up; 18 | guVector view; 19 | }camera; 20 | s16 square[] ATTRIBUTE_ALIGN(32) = 21 | { 22 | // x y z 23 | -30, 30, 0, // 0 24 | 30, 30, 0, // 1 25 | 30, -30, 0, // 2 26 | -30, -30, 0, // 3 27 | }; 28 | 29 | // color data 30 | u8 colors[] ATTRIBUTE_ALIGN(32) = { 31 | // r, g, b, a 32 | 0, 255, 0, 0, // 0 purple 33 | 240, 0, 0, 255, // 1 red 34 | 255, 180, 0, 255, // 2 orange 35 | 255, 255, 0, 255, // 3 yellow 36 | 10, 120, 40, 255, // 4 green 37 | 0, 20, 100, 255 // 5 blue 38 | }; 39 | 40 | 41 | static float rotby=0; 42 | 43 | 44 | static void *xfb = NULL; 45 | static u32 do_copy = GX_FALSE; 46 | GXRModeObj *rmode; 47 | GXTexObj texObj; 48 | TPLFile spriteTPL; 49 | 50 | camera cam = {{0.0F, 0.0F, 0.0F}, 51 | {0.0F, 1.0F, 0.0F}, 52 | {0.0F, 0.0F, -1.0F}}; 53 | 54 | void draw_init(); 55 | void draw_vert(u8 pos, u8 c, f32 s, f32 t); 56 | void draw_square(Mtx v); 57 | static void copy_to_xfb(u32 count); 58 | void movecamera(float speed); 59 | 60 | 61 | int main() { 62 | Mtx44 v,p; // view and perspective matrices 63 | GXColor background = {0, 0, 0, 0xff}; 64 | 65 | VIDEO_Init(); 66 | 67 | rmode = VIDEO_GetPreferredMode(NULL); 68 | 69 | PAD_Init(); 70 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 71 | 72 | VIDEO_Configure(rmode); 73 | VIDEO_SetNextFramebuffer(xfb); 74 | VIDEO_SetPostRetraceCallback(copy_to_xfb); 75 | VIDEO_SetBlack(FALSE); 76 | VIDEO_Flush(); 77 | VIDEO_WaitVSync(); 78 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 79 | 80 | void *gp_fifo = NULL; 81 | gp_fifo = MEM_K0_TO_K1(memalign(32,DEFAULT_FIFO_SIZE)); 82 | memset(gp_fifo,0,DEFAULT_FIFO_SIZE); 83 | 84 | GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); 85 | 86 | GX_SetCopyClear(background, 0x00ffffff); 87 | 88 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 89 | GX_SetDispCopyYScale((f32)rmode->xfbHeight/(f32)rmode->efbHeight); 90 | GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); 91 | GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); 92 | GX_SetDispCopyDst(rmode->fbWidth,rmode->xfbHeight); 93 | GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); 94 | GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 95 | 96 | if (rmode->aa) { 97 | GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); 98 | } else { 99 | GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); 100 | } 101 | 102 | GX_SetCullMode(GX_CULL_NONE); 103 | GX_CopyDisp(xfb,GX_TRUE); 104 | GX_SetDispCopyGamma(GX_GM_1_0); 105 | 106 | guPerspective(p, 60, 1.33F, 10.0F, 1000.0F); 107 | GX_LoadProjectionMtx(p, GX_PERSPECTIVE); 108 | 109 | draw_init(); 110 | 111 | while(1) 112 | { 113 | guLookAt(v, &cam.pos, &cam.up, &cam.view); 114 | 115 | GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); 116 | GX_InvVtxCache(); 117 | GX_InvalidateTexAll(); 118 | GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL); 119 | GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); 120 | 121 | GX_SetNumChans(1); 122 | 123 | GX_LoadTexObj(&texObj, GX_TEXMAP0); 124 | 125 | draw_square(v); 126 | 127 | GX_DrawDone(); 128 | do_copy = GX_TRUE; 129 | VIDEO_WaitVSync(); 130 | 131 | PAD_ScanPads(); 132 | 133 | int stickY = PAD_StickY(0); 134 | 135 | if( stickY > 18 || stickY < -18) 136 | movecamera((float) stickY/-18); 137 | 138 | if(PAD_ButtonsDown(0) & PAD_BUTTON_START) { 139 | exit(0); 140 | } 141 | } 142 | return 0; 143 | } 144 | 145 | 146 | void draw_init() { 147 | GX_ClearVtxDesc(); 148 | GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); 149 | GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8); 150 | GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); 151 | 152 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); 153 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); 154 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); 155 | 156 | GX_SetArray(GX_VA_POS, square, 3*sizeof(s16)); 157 | GX_SetArray(GX_VA_CLR0, colors, 4*sizeof(u8)); 158 | 159 | GX_SetNumTexGens(1); 160 | GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); 161 | 162 | GX_InvalidateTexAll(); 163 | 164 | TPL_OpenTPLFromMemory(&spriteTPL, (void *)textures_tpl,textures_tpl_size); 165 | TPL_GetTexture(&spriteTPL,drunkentimes,&texObj); 166 | 167 | GX_LoadTexObj(&texObj, GX_TEXMAP0); 168 | 169 | 170 | } 171 | 172 | void draw_vert(u8 pos, u8 c, f32 s, f32 t) { 173 | GX_Position1x8(pos); 174 | GX_Color1x8(c); 175 | GX_TexCoord2f32(s, t); 176 | } 177 | 178 | void draw_square(Mtx v) { 179 | Mtx m; // model matrix. 180 | Mtx mv; // modelview matrix. 181 | guVector axis = {0,0,1}; 182 | 183 | guMtxIdentity(m); 184 | guMtxRotAxisDeg(m, &axis, rotby); 185 | guMtxTransApply(m, m, 0, 0, -100); 186 | 187 | guMtxConcat(v,m,mv); 188 | GX_LoadPosMtxImm(mv, GX_PNMTX0); 189 | 190 | 191 | GX_Begin(GX_QUADS, GX_VTXFMT0, 4); 192 | draw_vert(0, 0, 0.0, 0.0); 193 | draw_vert(1, 0, 1.0, 0.0); 194 | draw_vert(2, 0, 1.0, 1.0); 195 | draw_vert(3, 0, 0.0, 1.0); 196 | GX_End(); 197 | } 198 | 199 | // copy efb to xfb when ready 200 | static void copy_to_xfb(u32 count) { 201 | if(do_copy==GX_TRUE) { 202 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 203 | GX_SetColorUpdate(GX_TRUE); 204 | GX_CopyDisp(xfb,GX_TRUE); 205 | GX_Flush(); 206 | do_copy = GX_FALSE; 207 | } 208 | } 209 | 210 | void movecamera(float speed) { 211 | guVector v; 212 | 213 | v.x = cam.view.x - cam.pos.x; 214 | v.y = cam.view.y - cam.pos.y; 215 | v.z = cam.view.z - cam.pos.z; 216 | 217 | cam.pos.x += v.x * speed; 218 | cam.pos.z += v.z * speed; 219 | cam.view.x += v.x * speed; 220 | cam.view.z += v.z * speed; 221 | } 222 | 223 | -------------------------------------------------------------------------------- /graphics/gx/texturetest/textures/drunkentimes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/gamecube-examples/bec8651eab0f392f55117e0a209c0c05acbf1425/graphics/gx/texturetest/textures/drunkentimes.jpg -------------------------------------------------------------------------------- /graphics/gx/texturetest/textures/textures.scf: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /graphics/gx/triangle/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | .SECONDARY: 6 | #--------------------------------------------------------------------------------- 7 | ifeq ($(strip $(DEVKITPPC)),) 8 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 9 | endif 10 | 11 | include $(DEVKITPPC)/gamecube_rules 12 | 13 | #--------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # INCLUDES is a list of directories containing extra header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := $(notdir $(CURDIR)) 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | TEXTURES := textures 24 | INCLUDES := 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | 30 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 31 | CXXFLAGS = $(CFLAGS) 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 57 | $(foreach dir,$(TEXTURES),$(CURDIR)/$(dir)) 58 | 59 | export DEPSDIR := $(CURDIR)/$(BUILD) 60 | 61 | #--------------------------------------------------------------------------------- 62 | # automatically build a list of object files for our project 63 | #--------------------------------------------------------------------------------- 64 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 65 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 66 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 67 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 69 | SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf))) 70 | TPLFILES := $(SCFFILES:.scf=.tpl) 71 | 72 | #--------------------------------------------------------------------------------- 73 | # use CXX for linking C++ projects, CC for standard C 74 | #--------------------------------------------------------------------------------- 75 | ifeq ($(strip $(CPPFILES)),) 76 | export LD := $(CC) 77 | else 78 | export LD := $(CXX) 79 | endif 80 | 81 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES)) 82 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 83 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 84 | 85 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES))) 86 | 87 | #--------------------------------------------------------------------------------- 88 | # build a list of include paths 89 | #--------------------------------------------------------------------------------- 90 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 92 | -I$(CURDIR)/$(BUILD) \ 93 | -I$(LIBOGC_INC) 94 | 95 | #--------------------------------------------------------------------------------- 96 | # build a list of library paths 97 | #--------------------------------------------------------------------------------- 98 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 99 | -L$(LIBOGC_LIB) 100 | 101 | export OUTPUT := $(CURDIR)/$(TARGET) 102 | .PHONY: $(BUILD) clean 103 | 104 | #--------------------------------------------------------------------------------- 105 | $(BUILD): 106 | @[ -d $@ ] || mkdir -p $@ 107 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 108 | 109 | #--------------------------------------------------------------------------------- 110 | clean: 111 | @echo clean ... 112 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 113 | 114 | #--------------------------------------------------------------------------------- 115 | else 116 | 117 | #--------------------------------------------------------------------------------- 118 | # main targets 119 | #--------------------------------------------------------------------------------- 120 | $(OUTPUT).dol: $(OUTPUT).elf 121 | $(OUTPUT).elf: $(OFILES) 122 | 123 | $(OFILES_SOURCES) : $(HFILES) 124 | 125 | #--------------------------------------------------------------------------------- 126 | # This rule links in binary data with the .bin extension 127 | #--------------------------------------------------------------------------------- 128 | %.bin.o %_bin.h : %.bin 129 | #--------------------------------------------------------------------------------- 130 | @echo $(notdir $<) 131 | @$(bin2o) 132 | 133 | #--------------------------------------------------------------------------------- 134 | %.tpl.o %_tpl.h : %.tpl 135 | #--------------------------------------------------------------------------------- 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | 140 | -include $(DEPSDIR)/*.d 141 | 142 | #--------------------------------------------------------------------------------- 143 | endif 144 | #--------------------------------------------------------------------------------- 145 | -------------------------------------------------------------------------------- /graphics/gx/triangle/source/triangle.c: -------------------------------------------------------------------------------- 1 | // adapted from the original acube demo by tkcne. 2 | 3 | // enjoy 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | GXRModeObj *screenMode; 12 | static void *frameBuffer; 13 | static vu8 readyForCopy; 14 | #define FIFO_SIZE (256*1024) 15 | 16 | s16 vertices[] ATTRIBUTE_ALIGN(32) = { 17 | 0, 15, 0, 18 | -15, -15, 0, 19 | 15, -15, 0}; 20 | 21 | u8 colors[] ATTRIBUTE_ALIGN(32) = { 22 | 255, 0, 0, 255, // red 23 | 0, 255, 0, 255, // green 24 | 0, 0, 255, 255}; // blue 25 | 26 | void update_screen(Mtx viewMatrix); 27 | static void copy_buffers(u32 unused); 28 | 29 | int main(void) 30 | { 31 | Mtx view; 32 | Mtx44 projection; 33 | PADStatus pads[4]; 34 | GXColor backgroundColor = {0, 0, 0, 255}; 35 | void *fifoBuffer = NULL; 36 | 37 | VIDEO_Init(); 38 | 39 | screenMode = VIDEO_GetPreferredMode(NULL); 40 | 41 | PAD_Init(); 42 | frameBuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(screenMode)); 43 | 44 | VIDEO_Configure(screenMode); 45 | VIDEO_SetNextFramebuffer(frameBuffer); 46 | VIDEO_SetPostRetraceCallback(copy_buffers); 47 | VIDEO_SetBlack(FALSE); 48 | VIDEO_Flush(); 49 | 50 | fifoBuffer = MEM_K0_TO_K1(memalign(32,FIFO_SIZE)); 51 | memset(fifoBuffer, 0, FIFO_SIZE); 52 | 53 | GX_Init(fifoBuffer, FIFO_SIZE); 54 | GX_SetCopyClear(backgroundColor, 0x00ffffff); 55 | GX_SetViewport(0,0,screenMode->fbWidth,screenMode->efbHeight,0,1); 56 | GX_SetDispCopyYScale((f32)screenMode->xfbHeight/(f32)screenMode->efbHeight); 57 | GX_SetScissor(0,0,screenMode->fbWidth,screenMode->efbHeight); 58 | GX_SetDispCopySrc(0,0,screenMode->fbWidth,screenMode->efbHeight); 59 | GX_SetDispCopyDst(screenMode->fbWidth,screenMode->xfbHeight); 60 | GX_SetCopyFilter(screenMode->aa,screenMode->sample_pattern, 61 | GX_TRUE,screenMode->vfilter); 62 | GX_SetFieldMode(screenMode->field_rendering, 63 | ((screenMode->viHeight==2*screenMode->xfbHeight)?GX_ENABLE:GX_DISABLE)); 64 | 65 | GX_SetCullMode(GX_CULL_NONE); 66 | GX_CopyDisp(frameBuffer,GX_TRUE); 67 | GX_SetDispCopyGamma(GX_GM_1_0); 68 | 69 | guVector camera = {0.0F, 0.0F, 0.0F}; 70 | guVector up = {0.0F, 1.0F, 0.0F}; 71 | guVector look = {0.0F, 0.0F, -1.0F}; 72 | 73 | guPerspective(projection, 60, 1.33F, 10.0F, 300.0F); 74 | GX_LoadProjectionMtx(projection, GX_PERSPECTIVE); 75 | 76 | GX_ClearVtxDesc(); 77 | GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); 78 | GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8); 79 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); 80 | GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); 81 | GX_SetArray(GX_VA_POS, vertices, 3*sizeof(s16)); 82 | GX_SetArray(GX_VA_CLR0, colors, 4*sizeof(u8)); 83 | GX_SetNumChans(1); 84 | GX_SetNumTexGens(0); 85 | GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); 86 | GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); 87 | 88 | while (1) 89 | { 90 | guLookAt(view, &camera, &up, &look); 91 | GX_SetViewport(0,0,screenMode->fbWidth,screenMode->efbHeight,0,1); 92 | GX_InvVtxCache(); 93 | GX_InvalidateTexAll(); 94 | update_screen(view); 95 | PAD_Read(pads); 96 | if (pads[0].button & PAD_BUTTON_START) { 97 | void (*reload)() = (void(*)())0x80001800; 98 | reload(); 99 | } 100 | } 101 | return 0; 102 | } 103 | 104 | void update_screen( Mtx viewMatrix ) 105 | { 106 | Mtx modelView; 107 | 108 | guMtxIdentity(modelView); 109 | guMtxTransApply(modelView, modelView, 0.0F, 0.0F, -50.0F); 110 | guMtxConcat(viewMatrix,modelView,modelView); 111 | 112 | GX_LoadPosMtxImm(modelView, GX_PNMTX0); 113 | 114 | GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3); 115 | 116 | GX_Position1x8(0); 117 | GX_Color1x8(0); 118 | GX_Position1x8(1); 119 | GX_Color1x8(1); 120 | GX_Position1x8(2); 121 | GX_Color1x8(2); 122 | 123 | GX_End(); 124 | 125 | GX_DrawDone(); 126 | readyForCopy = GX_TRUE; 127 | 128 | VIDEO_WaitVSync(); 129 | return; 130 | } 131 | 132 | static void copy_buffers(u32 count __attribute__ ((unused))) 133 | { 134 | if (readyForCopy==GX_TRUE) { 135 | GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); 136 | GX_SetColorUpdate(GX_TRUE); 137 | GX_CopyDisp(frameBuffer,GX_TRUE); 138 | GX_Flush(); 139 | readyForCopy = GX_FALSE; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /system/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS:= `ls | egrep -v '^(CVS)$$'` 2 | 3 | DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d) 4 | 5 | all: 6 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then make -C $$i || { exit 1;} fi; done; 7 | 8 | clean: 9 | @rm -f *.bz2 10 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then make -C $$i clean || { exit 1;} fi; done; 11 | 12 | install: 13 | @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then make -C $$i install || { exit 1;} fi; done; 14 | 15 | dist: clean 16 | @tar --exclude=*CVS* --exclude=.svn -cvjf gamecube-examples-$(DATESTRING).tar.bz2 * 17 | -------------------------------------------------------------------------------- /system/arena1override/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := arena1override 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | # rebase dol file with -Wl,--section-start,.init= 32 | 33 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $(TARGET)).map -Wl,--section-start,.init=0x81600000 34 | 35 | #--------------------------------------------------------------------------------- 36 | # any extra libraries we wish to link with the project 37 | #--------------------------------------------------------------------------------- 38 | LIBS := -logc -lm 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export OUTPUT := $(CURDIR)/$(TARGET) 54 | 55 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 56 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 57 | 58 | export DEPSDIR := $(CURDIR)/$(BUILD) 59 | 60 | #--------------------------------------------------------------------------------- 61 | # automatically build a list of object files for our project 62 | #--------------------------------------------------------------------------------- 63 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 64 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 65 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 66 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 67 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 68 | 69 | #--------------------------------------------------------------------------------- 70 | # use CXX for linking C++ projects, CC for standard C 71 | #--------------------------------------------------------------------------------- 72 | ifeq ($(strip $(CPPFILES)),) 73 | export LD := $(CC) 74 | else 75 | export LD := $(CXX) 76 | endif 77 | 78 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 79 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 80 | $(sFILES:.s=.o) $(SFILES:.S=.o) 81 | 82 | #--------------------------------------------------------------------------------- 83 | # build a list of include paths 84 | #--------------------------------------------------------------------------------- 85 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 86 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 87 | -I$(CURDIR)/$(BUILD) \ 88 | -I$(LIBOGC_INC) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # build a list of library paths 92 | #--------------------------------------------------------------------------------- 93 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 94 | -L$(LIBOGC_LIB) 95 | 96 | export OUTPUT := $(CURDIR)/$(TARGET) 97 | .PHONY: $(BUILD) clean 98 | 99 | #--------------------------------------------------------------------------------- 100 | $(BUILD): 101 | @[ -d $@ ] || mkdir -p $@ 102 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 103 | 104 | #--------------------------------------------------------------------------------- 105 | clean: 106 | @echo clean ... 107 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 108 | 109 | #--------------------------------------------------------------------------------- 110 | else 111 | 112 | DEPENDS := $(OFILES:.o=.d) 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | $(OUTPUT).dol: $(OUTPUT).elf 118 | $(OUTPUT).elf: $(OFILES) 119 | 120 | #--------------------------------------------------------------------------------- 121 | # This rule links in binary data with the .jpg extension 122 | #--------------------------------------------------------------------------------- 123 | %.jpg.o : %.jpg 124 | #--------------------------------------------------------------------------------- 125 | @echo $(notdir $<) 126 | $(bin2o) 127 | 128 | -include $(DEPENDS) 129 | 130 | #--------------------------------------------------------------------------------- 131 | endif 132 | #--------------------------------------------------------------------------------- 133 | -------------------------------------------------------------------------------- /system/arena1override/source/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static void *xfb = NULL; 9 | static GXRModeObj *rmode = NULL; 10 | 11 | 12 | // set these variables to the limits of the arena1 area you require 13 | // see the makefile for rebasing the dol 14 | // add -Wl,--section-start,.init= to LDFLAGS 15 | 16 | // The lower limit of arena1 area available for malloc 17 | void *__myArena1Lo = (void*)0x80B00000; 18 | 19 | // The upper limit of arena1, up to start address of rebased dol 20 | void *__myArena1Hi = (void*)0x81600000; 21 | 22 | 23 | void *Initialise(); 24 | 25 | 26 | int main(int argc, char **argv) { 27 | 28 | xfb = Initialise(); 29 | 30 | printf("\nHello World!\n"); 31 | 32 | void *test = malloc(1024); 33 | printf("malloc returned %p\n", test); 34 | 35 | while(1) { 36 | 37 | VIDEO_WaitVSync(); 38 | PAD_ScanPads(); 39 | 40 | int buttonsDown = PAD_ButtonsDown(0); 41 | 42 | if( buttonsDown & PAD_BUTTON_A ) { 43 | printf("Button A pressed.\n"); 44 | } 45 | 46 | if (buttonsDown & PAD_BUTTON_START) { 47 | exit(0); 48 | } 49 | } 50 | 51 | return 0; 52 | } 53 | 54 | void * Initialise() { 55 | 56 | void *framebuffer; 57 | 58 | VIDEO_Init(); 59 | PAD_Init(); 60 | 61 | rmode = VIDEO_GetPreferredMode(NULL); 62 | 63 | framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 64 | console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 65 | 66 | VIDEO_Configure(rmode); 67 | VIDEO_SetNextFramebuffer(framebuffer); 68 | VIDEO_SetBlack(FALSE); 69 | VIDEO_Flush(); 70 | VIDEO_WaitVSync(); 71 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 72 | 73 | return framebuffer; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /templates/application/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) 4 | 5 | project(template LANGUAGES C) 6 | 7 | add_executable(${PROJECT_NAME} source/template.c) 8 | target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR}) 9 | 10 | ogc_create_dol(${PROJECT_NAME}) 11 | 12 | target_compile_options(template PRIVATE -Wall) 13 | 14 | -------------------------------------------------------------------------------- /templates/application/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 77 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 78 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 79 | 80 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 81 | 82 | #--------------------------------------------------------------------------------- 83 | # build a list of include paths 84 | #--------------------------------------------------------------------------------- 85 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 86 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 87 | -I$(CURDIR)/$(BUILD) \ 88 | -I$(LIBOGC_INC) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # build a list of library paths 92 | #--------------------------------------------------------------------------------- 93 | export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 94 | 95 | export OUTPUT := $(CURDIR)/$(TARGET) 96 | .PHONY: $(BUILD) clean 97 | 98 | #--------------------------------------------------------------------------------- 99 | $(BUILD): 100 | @[ -d $@ ] || mkdir -p $@ 101 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 102 | 103 | #--------------------------------------------------------------------------------- 104 | clean: 105 | @echo clean ... 106 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 107 | 108 | #--------------------------------------------------------------------------------- 109 | else 110 | 111 | DEPENDS := $(OFILES:.o=.d) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # main targets 115 | #--------------------------------------------------------------------------------- 116 | $(OUTPUT).dol: $(OUTPUT).elf 117 | $(OUTPUT).elf: $(OFILES) 118 | 119 | $(OFILES_SOURCES) : $(HFILES) 120 | 121 | #--------------------------------------------------------------------------------- 122 | # This rule links in binary data with the .jpg extension 123 | #--------------------------------------------------------------------------------- 124 | %.jpg.o %_jpg.h : %.jpg 125 | #--------------------------------------------------------------------------------- 126 | @echo $(notdir $<) 127 | $(bin2o) 128 | 129 | -include $(DEPENDS) 130 | 131 | #--------------------------------------------------------------------------------- 132 | endif 133 | #--------------------------------------------------------------------------------- 134 | -------------------------------------------------------------------------------- /templates/application/source/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static void *xfb = NULL; 9 | static GXRModeObj *rmode = NULL; 10 | 11 | void *Initialise(); 12 | 13 | int main(int argc, char **argv) { 14 | 15 | xfb = Initialise(); 16 | 17 | printf("\nHello World!\n"); 18 | 19 | while(1) { 20 | 21 | VIDEO_WaitVSync(); 22 | PAD_ScanPads(); 23 | 24 | int buttonsDown = PAD_ButtonsDown(0); 25 | 26 | if( buttonsDown & PAD_BUTTON_A ) { 27 | printf("Button A pressed.\n"); 28 | } 29 | 30 | if (buttonsDown & PAD_BUTTON_START) { 31 | exit(0); 32 | } 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | void * Initialise() { 39 | 40 | void *framebuffer; 41 | 42 | VIDEO_Init(); 43 | PAD_Init(); 44 | 45 | rmode = VIDEO_GetPreferredMode(NULL); 46 | 47 | framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 48 | console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 49 | 50 | VIDEO_Configure(rmode); 51 | VIDEO_SetNextFramebuffer(framebuffer); 52 | VIDEO_SetBlack(FALSE); 53 | VIDEO_Flush(); 54 | VIDEO_WaitVSync(); 55 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 56 | 57 | return framebuffer; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /templates/library/.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | -------------------------------------------------------------------------------- /templates/library/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/gamecube_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(notdir $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # list of directories containing libraries, this must be the top level containing 35 | # include and lib 36 | #--------------------------------------------------------------------------------- 37 | LIBDIRS := 38 | 39 | #--------------------------------------------------------------------------------- 40 | # no real need to edit anything past this point unless you need to add additional 41 | # rules for different file extensions 42 | #--------------------------------------------------------------------------------- 43 | ifneq ($(BUILD),$(notdir $(CURDIR))) 44 | #--------------------------------------------------------------------------------- 45 | 46 | export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a 47 | 48 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 49 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 50 | 51 | export DEPSDIR := $(CURDIR)/$(BUILD) 52 | 53 | #--------------------------------------------------------------------------------- 54 | # automatically build a list of object files for our project 55 | #--------------------------------------------------------------------------------- 56 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 57 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 58 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 59 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 60 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 61 | 62 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 63 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 64 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 65 | 66 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 67 | 68 | #--------------------------------------------------------------------------------- 69 | # build a list of include paths 70 | #--------------------------------------------------------------------------------- 71 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 72 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 73 | -I$(CURDIR)/$(BUILD) \ 74 | -I$(LIBOGC_INC) 75 | 76 | .PHONY: $(BUILD) clean 77 | 78 | #--------------------------------------------------------------------------------- 79 | all: $(BUILD) 80 | 81 | lib: 82 | @[ -d $@ ] || mkdir -p $@ 83 | 84 | $(BUILD): lib 85 | @[ -d $@ ] || mkdir -p $@ 86 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 87 | 88 | #--------------------------------------------------------------------------------- 89 | clean: 90 | @echo clean ... 91 | @rm -fr $(BUILD) lib 92 | 93 | #--------------------------------------------------------------------------------- 94 | else 95 | 96 | DEPENDS := $(OFILES:.o=.d) 97 | 98 | #--------------------------------------------------------------------------------- 99 | # main targets 100 | #--------------------------------------------------------------------------------- 101 | $(OUTPUT) : $(OFILES) 102 | 103 | $(OFILES_SOURCES) : $(HFILES) 104 | 105 | -include $(DEPENDS) 106 | 107 | #--------------------------------------------------------------------------------- 108 | endif 109 | #--------------------------------------------------------------------------------- 110 | -------------------------------------------------------------------------------- /templates/library/README.md: -------------------------------------------------------------------------------- 1 | # template 2 | 3 | This is a template for starting new GameCube library projects. 4 | -------------------------------------------------------------------------------- /templates/library/include/templatelib.h: -------------------------------------------------------------------------------- 1 | #ifndef _templatelib_h_ 2 | #define _templatelib_h_ 3 | 4 | int myLibFunction(); 5 | 6 | #endif // _templatelib_h_ 7 | -------------------------------------------------------------------------------- /templates/library/source/templatelib.c: -------------------------------------------------------------------------------- 1 | int myLibFunction() { 2 | 3 | return 42; 4 | 5 | } 6 | --------------------------------------------------------------------------------