Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalgrodzinski committed Dec 19, 2023
0 parents commit fd12e0e
Show file tree
Hide file tree
Showing 33 changed files with 892 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
# Windows
thumbs.db

*.exe
*.cpe
/*.obj
*.bin
*.cue
*.sys
*.map
Binary file added DINO.TMD
Binary file not shown.
Binary file added GIULI_BD.TIM
Binary file not shown.
Binary file added GIULI_FR.TIM
Binary file not shown.
Binary file added GIULI_PL.TIM
Binary file not shown.
Binary file added GIULI_TL.TIM
Binary file not shown.
Binary file added GIULI_TR.TIM
Binary file not shown.
Binary file added GIULI_WN.TIM
Binary file not shown.
60 changes: 60 additions & 0 deletions audio.c
@@ -0,0 +1,60 @@
#include "audio.h"

void audio_init() {
SpuCommonAttr common;

SpuInit();
SpuInitMalloc(SPU_MALLOC_MAX, (char*)(SPU_MALLOC_RECSIZ * (SPU_MALLOC_MAX +1)));
common.mask = (SPU_COMMON_MVOLL | SPU_COMMON_MVOLR);
common.mvol.left = common.mvol.right = 0x3fff;
SpuSetCommonAttr(&common);
}

void audio_load_voice(char *buffer, long size, u_long channel) {
SpuVoiceAttr voiceAttr;
u_long spuAddress;

SpuSetTransferMode(SPU_TRANSFER_BY_IO);
spuAddress = SpuMalloc(size);
SpuSetTransferStartAddr(spuAddress);
SpuWrite(buffer, size);
SpuIsTransferCompleted(SPU_TRANSFER_WAIT);

voiceAttr.mask = (
SPU_VOICE_VOLL |
SPU_VOICE_VOLR |
SPU_VOICE_PITCH |
SPU_VOICE_WDSA |
SPU_VOICE_ADSR_AMODE |
SPU_VOICE_ADSR_SMODE |
SPU_VOICE_ADSR_RMODE |
SPU_VOICE_ADSR_AR |
SPU_VOICE_ADSR_DR |
SPU_VOICE_ADSR_SR |
SPU_VOICE_ADSR_RR |
SPU_VOICE_ADSR_SL
);
voiceAttr.voice = SPU_VOICECH(channel);
voiceAttr.volume.left = voiceAttr.volume.right = 0x3fff;
voiceAttr.pitch = 2048;
voiceAttr.addr = spuAddress;

voiceAttr.a_mode = SPU_VOICE_LINEARIncN;
voiceAttr.s_mode = SPU_VOICE_LINEARIncN;
voiceAttr.r_mode = SPU_VOICE_LINEARDecN;
voiceAttr.ar = 0x0;
voiceAttr.dr = 0x0;
voiceAttr.sr = 0x0;
voiceAttr.rr = 0x0;
voiceAttr.sl = 0xf;

SpuSetVoiceAttr(&voiceAttr);
}

void audio_play_voice(u_long channel) {
SpuSetKey(SPU_ON, SPU_VOICECH(channel));
}

void audio_stop_voice(u_long channel) {
SpuSetKey(SPU_OFF, SPU_VOICECH(channel));
}
15 changes: 15 additions & 0 deletions audio.h
@@ -0,0 +1,15 @@
#ifndef AUDIO_H
#define AUDIO_H

#include <sys/types.h>
#include <libspu.h>
#include "types.h"

#define SPU_MALLOC_MAX 36

void audio_init();
void audio_load_voice(char *buffer, long size, u_long channel);
void audio_play_voice(u_long channel);
void audio_stop_voice(u_long channel);

#endif
36 changes: 36 additions & 0 deletions cd.c
@@ -0,0 +1,36 @@
#include "cd.h"

#define CD_SECTOR_SIZE 2048

void cd_init() {
CdInit();
}

cd_File cd_load_file(char *filename) {
cd_File result;
CdlFILE file;
int sectorsCount;
//u_long *buffer;

if(!CdSearchFile(&file, filename)) {
printf("Couldn't find file %s\n", filename);
return result;
}

sectorsCount = (file.size + CD_SECTOR_SIZE - 1)/CD_SECTOR_SIZE;
result.buffer = (char*)malloc3(SECTOR_SIZE * sectorsCount);
printf("Reading file %s, %d sectors\n", filename, sectorsCount);

CdControlB(CdlSetloc, (u_char*)&file.pos, NULL);
//CdReadSync(0, NULL);
CdRead(sectorsCount, (u_long*)result.buffer, CdlModeSpeed);
CdReadSync(0, NULL);

result.size = sectorsCount * CD_SECTOR_SIZE;
return result;
}

void cd_free_file(cd_File file) {
printf("Freeing 0x%08x\n", file.buffer);
free3(file.buffer);
}
18 changes: 18 additions & 0 deletions cd.h
@@ -0,0 +1,18 @@
#ifndef CD_H
#define CD_H

#include <sys/types.h>
#include <kernel.h>
#include <libcd.h>
#include "types.h"

typedef struct cd_File {
char *buffer;
u_long size;
} cd_File;

void cd_init();
cd_File cd_load_file(char *filename);
void cd_free_file(cd_File file);

#endif
Binary file added earth.tmd
Binary file not shown.
Binary file added earth4.tim
Binary file not shown.
Binary file added earth8.tim
Binary file not shown.
Binary file added frog.tim
Binary file not shown.
Binary file added giulieta.tmd
Binary file not shown.
Binary file added lib/mmgmnew.obj
Binary file not shown.
146 changes: 146 additions & 0 deletions main.c
@@ -0,0 +1,146 @@
#include <sys/types.h>
#include <stdio.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>

#include "types.h"
#include "video.h"
#include "audio.h"
#include "pad.h"
#include "cd.h"
#include "sprite.h"
#include "model.h"

VECTOR vec = {0, 0, 1024};
SVECTOR ang = {0, 0, 0};

VECTOR vec2 = {0, 0, 1024};
SVECTOR ang2 = {0, 0, 0};

cd_File file;
model_Model model, model2;
video_Texture texture;
sprite_Sprite sprite, sprite2;


int main() {
int i;

InitHeap3((void*)0x801f0000, 0x00100000);

video_init(VIDEO_HI_RES);
audio_init();
pad_init();
cd_init();

video_set_light_color(ONE, ONE, ONE);

file = cd_load_file("\\EARTH8.TIM;1");
printf("EARTH8.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
texture = video_load_texture(file);
cd_free_file(file);
sprite = sprite_load_sprite(texture);

file = cd_load_file("\\EARTH.TMD;1");
printf("EARTH.TMD start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
model2 = model_load_tmd(file, TRUE, &texture);
cd_free_file(file);

/*file = cd_load_file("\\DINO.TMD;1");
model2 = model_load_tmd(file, TRUE, &texture);
cd_free_file(file);*/

//file = cd_load_file("\\GIULI_TR.TIM;1");
//printf("GIULI_TR.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULI_WN.TIM;1");
//printf("GIULI_WN.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULI_BD.TIM;1");
//printf("GIULI_BD.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULI_TL.TIM;1");
//printf("GIULI_TL.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULI_PL.TIM;1");
//printf("GIULI_PL.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULI_FR.TIM;1");
//printf("GIULI_FR.TIM start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//video_load_texture(file);
//cd_free_file(file);

//file = cd_load_file("\\GIULIETA.TMD;1");
//printf("GIULIETA.TMD start: 0x%08x, size: 0x%08x\n", file.buffer, file.size);
//model = model_load_tmd(file, TRUE, NULL);
//cd_free_file(file);

//file = cd_load_file("\\FROG.TIM;1");
//texture = video_load_texture(file);
//cd_free_file(file);
//sprite2 = sprite_load_sprite(texture);

DrawSync(0);
while(1) {
if (pad_is_pressed(PAD_1, PAD_UP))
vec.vy -= 32;

if (pad_is_pressed(PAD_1, PAD_DOWN))
vec.vy += 32;

if (pad_is_pressed(PAD_1, PAD_LEFT))
vec.vx -= 32;

if (pad_is_pressed(PAD_1, PAD_RIGHT))
vec.vx += 32;

if (pad_is_pressed(PAD_1, PAD_L1))
vec.vz += 32;

if (pad_is_pressed(PAD_1, PAD_L2))
vec.vz -= 32;

if (pad_is_pressed(PAD_1, PAD_CIRCLE))
ang.vy -= 16;

if (pad_is_pressed(PAD_1, PAD_SQUARE))
ang.vy += 16;

if (pad_is_pressed(PAD_1, PAD_TRIANGLE))
ang.vx -= 16;

if (pad_is_pressed(PAD_1, PAD_CROSS))
ang.vx += 16;

if (pad_is_pressed(PAD_1, PAD_R1))
ang.vz -= 16;

if (pad_is_pressed(PAD_1, PAD_R2))
ang.vz += 16;

video_set_camera(vec, ang);
video_init_frame();

//for (i=0; i<model.count; i++)
// video_draw_poly3(&model.polys[i], model.vertices[i], model.colors[i], model.normals[i]);

for (i=0; i<model2.count; i++)
video_draw_poly3(&model2.polys[i], model2.vertices[i], model2.colors[i], model2.normals[i]);

//video_draw_sprite(sprite, 0, 0);
//video_draw_sprite(sprite2, 150, 150);

video_draw();
}
}
34 changes: 34 additions & 0 deletions makefile.mak
@@ -0,0 +1,34 @@
all: video.obj audio.obj pad.obj cd.obj sprite.obj model.obj
ccpsx -Xo$80010000 *.obj lib/mmgmnew.obj main.c -o main.cpe
cpe2x main.cpe
mkpsxiso -y test.xml

video.obj:
ccpsx -c video.c

audio.obj:
ccpsx -c audio.c

pad.obj:
ccpsx -c pad.c

cd.obj:
ccpsx -c cd.c

sprite.obj:
ccpsx -c sprite.c

model.obj:
ccpsx -c model.c

run:
psymake
No$psx test.bin

clean:
del *.obj
del *.cpe
del *.exe
del *.bin
del *.cue
del *.map

0 comments on commit fd12e0e

Please sign in to comment.