WiiStrobe/Source

From WiiBrew
Jump to navigation Jump to search

Here is the very simple, very ugly and very short source code for WiiStrobe. Please do not use for educational purposes, other than as an example for bad code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>

#include <wiiuse/wpad.h>

#include "GRRLIB.h"

#define BLACK 0x000000FF
#define WHITE 0xFFFFFFFF
#define RED 0xFF0000FF
#define BLUE 0x0000FFFF

Mtx GXmodelView2D;

int main(int argc, char **argv) {
	
	VIDEO_Init();
	WPAD_Init();
	WPAD_SetIdleTimeout(60);
	
	GRRLIB_InitVideo();
	GRRLIB_Start();	
	VIDEO_WaitVSync();
	
	int freq = 10;
	
	int colset = 0;
	int col = WHITE;
	
	
	while(1){
		
		WPAD_ScanPads();
		
		GRRLIB_Render();
		if(WPAD_ButtonsDown (0) & WPAD_BUTTON_DOWN)
			freq += 1;
		if(WPAD_ButtonsDown (0) & WPAD_BUTTON_UP)
			freq -= 1;
		if(WPAD_ButtonsDown (0) & WPAD_BUTTON_HOME)
			return 0;
		if(WPAD_ButtonsDown (0) & WPAD_BUTTON_HOME)
			break;
		if((WPAD_ButtonsDown (0) & WPAD_BUTTON_LEFT) || (WPAD_ButtonsDown (0) & WPAD_BUTTON_RIGHT)){
			if(colset==0){
				colset = 1;
			}else{
				colset = 0;
			}
		}
		
		GRRLIB_FillScreen(col);
		
		switch (colset) {
			case 0:
				if(col==WHITE)
					col = BLACK;
				else
					col = WHITE;
				break;
			case 1:
				if(col==RED)
					col = BLUE;
				else
					col = RED;
		}
		
		int c = 0;
		
		while(c <= freq){
			GRRLIB_Render();
			c++;
		}
		
	}
	
}