Add initial Wii code
This commit is contained in:
		
							parent
							
								
									9ef7d8e075
								
							
						
					
					
						commit
						9b802afe65
					
				
							
								
								
									
										138
									
								
								wii/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								wii/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,138 @@
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# Clear the implicit built in rules
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
.SUFFIXES:
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
ifeq ($(strip $(DEVKITPPC)),)
 | 
			
		||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
include $(DEVKITPPC)/wii_rules
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# TARGET is the name of the output
 | 
			
		||||
# BUILD is the directory where object files & intermediate files will be placed
 | 
			
		||||
# SOURCES is a list of directories containing source code
 | 
			
		||||
# INCLUDES is a list of directories containing extra header files
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
TARGET		:=	boot
 | 
			
		||||
BUILD		:=	build
 | 
			
		||||
SOURCES		:=	source
 | 
			
		||||
DATA		:=	data
 | 
			
		||||
INCLUDES	:=
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# options for code generation
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE)
 | 
			
		||||
CXXFLAGS	=	$(CFLAGS)
 | 
			
		||||
 | 
			
		||||
LDFLAGS	=	-g $(MACHDEP) -Wl,-Map,$(notdir $@).map
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# any extra libraries we wish to link with the project
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
LIBS	:=	-lwiiuse -lbte -logc -lm
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# list of directories containing libraries, this must be the top level containing
 | 
			
		||||
# include and lib
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
LIBDIRS	:=
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# no real need to edit anything past this point unless you need to add additional
 | 
			
		||||
# rules for different file extensions
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
export OUTPUT	:=	$(CURDIR)/$(TARGET)
 | 
			
		||||
 | 
			
		||||
export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
 | 
			
		||||
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
 | 
			
		||||
 | 
			
		||||
export DEPSDIR	:=	$(CURDIR)/$(BUILD)
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# automatically build a list of object files for our project
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
 | 
			
		||||
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
 | 
			
		||||
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
 | 
			
		||||
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
 | 
			
		||||
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# use CXX for linking C++ projects, CC for standard C
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
ifeq ($(strip $(CPPFILES)),)
 | 
			
		||||
	export LD	:=	$(CC)
 | 
			
		||||
else
 | 
			
		||||
	export LD	:=	$(CXX)
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
export OFILES_BIN	:=	$(addsuffix .o,$(BINFILES))
 | 
			
		||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
 | 
			
		||||
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
 | 
			
		||||
 | 
			
		||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# build a list of include paths
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
export INCLUDE	:=	$(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
 | 
			
		||||
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
 | 
			
		||||
					-I$(CURDIR)/$(BUILD) \
 | 
			
		||||
					-I$(LIBOGC_INC)
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# build a list of library paths
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
export LIBPATHS	:= -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
 | 
			
		||||
 | 
			
		||||
export OUTPUT	:=	$(CURDIR)/$(TARGET)
 | 
			
		||||
.PHONY: $(BUILD) clean
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
$(BUILD):
 | 
			
		||||
	@[ -d $@ ] || mkdir -p $@
 | 
			
		||||
	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
clean:
 | 
			
		||||
	@echo clean ...
 | 
			
		||||
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
run:
 | 
			
		||||
	wiiload $(TARGET).dol
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
else
 | 
			
		||||
 | 
			
		||||
DEPENDS	:=	$(OFILES:.o=.d)
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# main targets
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
$(OUTPUT).dol: $(OUTPUT).elf
 | 
			
		||||
$(OUTPUT).elf: $(OFILES)
 | 
			
		||||
 | 
			
		||||
$(OFILES_SOURCES) : $(HFILES)
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# This rule links in binary data with the .jpg extension
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
%.jpg.o	%_jpg.h :	%.jpg
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
	@echo $(notdir $<)
 | 
			
		||||
	$(bin2o)
 | 
			
		||||
 | 
			
		||||
-include $(DEPENDS)
 | 
			
		||||
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
endif
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								wii/icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								wii/icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 11 KiB  | 
							
								
								
									
										39
									
								
								wii/meta.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								wii/meta.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
<!--
 | 
			
		||||
 For more information, see:
 | 
			
		||||
   <https://wiibrew.org/wiki/Homebrew_Channel#Configuring_Applications>.
 | 
			
		||||
 | 
			
		||||
 The icon.png should be a PNG with 128x48 dimensions. See:
 | 
			
		||||
   <https://wiibrew.org/wiki/Homebrew_Channel#Adding_an_Icon>.
 | 
			
		||||
   <https://wiibrew.org/wiki/Homebrew_Channel_icons>.
 | 
			
		||||
-->
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 | 
			
		||||
<app version="1">
 | 
			
		||||
    <!-- The name of the application -->
 | 
			
		||||
    <name>wii-pong</name>
 | 
			
		||||
 | 
			
		||||
    <!-- The name of the person or group that wrote the code for the program. -->
 | 
			
		||||
    <coder>alex</coder>
 | 
			
		||||
 | 
			
		||||
    <!-- The version of the application. -->
 | 
			
		||||
    <version></version>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
     The data the application was released. It has to be a timestamp using
 | 
			
		||||
     this format: YYYYmmddHHMMSS
 | 
			
		||||
    -->
 | 
			
		||||
    <release_date></release_date>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
     This is displayed on the main menu of the Homebrew Channel (before you
 | 
			
		||||
     select an application) and is used as a space to add a few words to
 | 
			
		||||
     describe the program.
 | 
			
		||||
    -->
 | 
			
		||||
    <short_description></short_description>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
     This is displayed once the application is chosen. It describes the program
 | 
			
		||||
     and its function in great detail, and can be used to elaborate on a
 | 
			
		||||
     program's controls.
 | 
			
		||||
    -->
 | 
			
		||||
    <long_description></long_description>
 | 
			
		||||
</app>
 | 
			
		||||
							
								
								
									
										37
									
								
								wii/source/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								wii/source/main.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
 | 
			
		||||
#include <gccore.h>
 | 
			
		||||
#include <wiiuse/wpad.h>
 | 
			
		||||
 | 
			
		||||
#include "screen.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	auto screen = Screen{};
 | 
			
		||||
 | 
			
		||||
	WPAD_Init();
 | 
			
		||||
 | 
			
		||||
	Paddle my_paddle{ screen.height(), 15, 5 };
 | 
			
		||||
 | 
			
		||||
	auto exit = false;
 | 
			
		||||
	while (!exit)
 | 
			
		||||
	{
 | 
			
		||||
		// Call WPAD_ScanPads each loop, this reads the latest controller states
 | 
			
		||||
		WPAD_ScanPads();
 | 
			
		||||
		const auto pressed = WPAD_ButtonsDown(0);
 | 
			
		||||
		if (pressed & WPAD_BUTTON_HOME)
 | 
			
		||||
			exit = true;
 | 
			
		||||
 | 
			
		||||
		// Clear the frame buffer.
 | 
			
		||||
		screen.clear();
 | 
			
		||||
 | 
			
		||||
		// drawing goes here
 | 
			
		||||
 | 
			
		||||
		// Wait for the next frame
 | 
			
		||||
		screen.wait_for_vsync();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								wii/source/screen.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								wii/source/screen.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
			
		||||
#include "screen.h"
 | 
			
		||||
 | 
			
		||||
#include <gccore.h>
 | 
			
		||||
 | 
			
		||||
Screen::Screen()
 | 
			
		||||
{
 | 
			
		||||
    // Initialise the video system
 | 
			
		||||
    VIDEO_Init();
 | 
			
		||||
 | 
			
		||||
    // Obtain the preferred video mode from the system
 | 
			
		||||
	// This will correspond to the settings in the Wii menu
 | 
			
		||||
    _rmode = VIDEO_GetPreferredMode(NULL);
 | 
			
		||||
 | 
			
		||||
    // Allocate memory for the display in the uncached region
 | 
			
		||||
    _xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(_rmode));
 | 
			
		||||
 | 
			
		||||
    // Set up the video registers with the chosen mode
 | 
			
		||||
	VIDEO_Configure(_rmode);
 | 
			
		||||
 | 
			
		||||
	// Tell the video hardware where our display memory is
 | 
			
		||||
	VIDEO_SetNextFramebuffer(_xfb);
 | 
			
		||||
 | 
			
		||||
	// Make the display visible
 | 
			
		||||
	VIDEO_SetBlack(FALSE);
 | 
			
		||||
 | 
			
		||||
	// Flush the video register changes to the hardware
 | 
			
		||||
	VIDEO_Flush();
 | 
			
		||||
 | 
			
		||||
	// Wait for Video setup to complete
 | 
			
		||||
	VIDEO_WaitVSync();
 | 
			
		||||
	if (_rmode->viTVMode & VI_NON_INTERLACE)
 | 
			
		||||
		VIDEO_WaitVSync();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screen::clear() noexcept
 | 
			
		||||
{
 | 
			
		||||
	VIDEO_ClearFrameBuffer(_rmode, _xfb, COLOR_BLACK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screen::draw(int x, int y, uint16_t colour) noexcept
 | 
			
		||||
{
 | 
			
		||||
	reinterpret_cast<uint16_t*>(_xfb)[(y * _rmode->fbWidth) + x] = colour;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Screen::wait_for_vsync() const noexcept
 | 
			
		||||
{
 | 
			
		||||
	VIDEO_WaitVSync();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Screen::width() const noexcept
 | 
			
		||||
{
 | 
			
		||||
	return _rmode->fbWidth;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Screen::height() const noexcept
 | 
			
		||||
{
 | 
			
		||||
	return _rmode->xfbHeight;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										43
									
								
								wii/source/screen.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								wii/source/screen.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
 | 
			
		||||
#include <gccore.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/// Class for drawing to the screen, simple abstraction around the raw
 | 
			
		||||
/// framebuffer.
 | 
			
		||||
class Screen final
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    /// Constructor.
 | 
			
		||||
    ///
 | 
			
		||||
    /// \remarks Automatically selects the display settings.
 | 
			
		||||
    Screen();
 | 
			
		||||
 | 
			
		||||
    /// Clear the screen.
 | 
			
		||||
    void clear() noexcept;
 | 
			
		||||
 | 
			
		||||
    /// Draw a pixel to the screen.
 | 
			
		||||
    ///
 | 
			
		||||
    /// \param x The x-coordinate to draw to.
 | 
			
		||||
    /// \param y The y-coordinate to draw to.
 | 
			
		||||
    /// \param colour The colour value to draw to the coordinate.
 | 
			
		||||
    void draw(int x, int y, uint16_t colour) noexcept;
 | 
			
		||||
 | 
			
		||||
    /// Wait for a v-sync.
 | 
			
		||||
    void wait_for_vsync() const noexcept;
 | 
			
		||||
 | 
			
		||||
    /// \return The width of the screen in pixels.
 | 
			
		||||
    int width() const noexcept;
 | 
			
		||||
 | 
			
		||||
    /// \return The height of the screen in pixels.
 | 
			
		||||
    int height() const noexcept;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    /// The allocated framebuffer.
 | 
			
		||||
    void* _xfb;
 | 
			
		||||
 | 
			
		||||
    /// The rendermode object.
 | 
			
		||||
    GXRModeObj* _rmode;
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user