TUTORIAL: How to make a clock
-----------------------
Makefile:
Code:
TARGET = clock
OBJS = main.o
INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
STDLIBS= -losl -lpng -lz \
-lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LIBS=$(STDLIBS)$(YOURLIBS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = clock
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Our Code:
Code:
#include <oslib/oslib.h>
PSP_MODULE_INFO("Relógio", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int hours = 0;
int minutes = 0;
int seconds = 0;
int miliseconds = 0;
int main()
{
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslInitConsole();
while(!osl_quit)
{
oslReadKeys();
if (hours> 24) hours= 1;
if (minutes > 60)
{
hours++;
minutes = 1;
}
if (seconds > 60)
{
minutes ++;
seconds = 1;
}
if (miliseconds > 60)
{
seconds ++;
miliseconds = 1;
}
if (miliseconds < 61)
{
miliseconds++;
}
oslSetTextColor(RGBA(255,0,0,255));
oslPrintf_xy(150,100,"hours :");
oslSetTextColor(RGBA(255,255,255,255));
oslPrintf_xy(200,100,"%i",hours );
oslSetTextColor(RGBA(255,0,0,255));
oslPrintf_xy(150,120,"minutes :");
oslSetTextColor(RGBA(255,255,255,255));
oslPrintf_xy(213,120,"%i",minutes );
oslSetTextColor(RGBA(255,0,0,255));
oslPrintf_xy(150,140,"seconds :");
oslSetTextColor(RGBA(255,255,255,255));
oslPrintf_xy(220,140,"%i",seconds );
oslSyncFrame();
}
oslEndGfx();
oslQuit();
return 0;
}
oslSetTextColor(RGBA(255,0,0,255));
set the text color to red
Note: it only print on the screen the seconds, minutes and hours, it doesnt print on the screen the microseconds.
We need the microseconds variable to make the seconds.
But if you need help post here.