Add gint target

This commit is contained in:
duarteapcoelho 2022-11-27 08:29:26 +00:00
parent 9749f08077
commit 96c4b8bdcf
26 changed files with 480 additions and 212 deletions

3
.gitignore vendored
View File

@ -4,5 +4,8 @@ prizm/*
sdl/*
!sdl/Makefile
gint/*
!gint/Makefile
resources/models/models.h
resources/models/models.blend1

View File

@ -1,17 +1,23 @@
SOURCES = $(wildcard src/*)
all: sdl prizm
all: sdl prizm gint
sdl: sdl/racing
prizm: prizm/racing.g3a
gint: gint/racing.g3a
clean:
make $(MFLAGS) -C sdl/ clean
make $(MFLAGS) -C prizm/ clean
make $(MFLAGS) -C gint/ clean
sdl/racing: $(SOURCES)
make $(MFLAGS) -C sdl/
prizm/racing.g3a: $(SOURCES)
make $(MFLAGS) -C prizm/
gint/racing.g3a: $(SOURCES)
make $(MFLAGS) -C gint/

View File

@ -31,13 +31,18 @@ A 3D, multiplayer racing game for casio fx-CG50 calculators
- If you connect the cable while one calculator is in the menu, it might start trying to receive files. To avoid this, only connect the cable while the game is running on both calculators.
## How to build
### Linux
- Either set up the Prizm SDK ([PrizmSDK Setup Guide](https://prizm.cemetech.net/index.php/PrizmSDK_Setup_Guide))
### gint version (doesn't support multiplayer yet)
#### Linux
- Install gint ([https://gitea.planet-casio.com/Lephenixnoir/gint](https://gitea.planet-casio.com/Lephenixnoir/gint))
- Run `make gint`
### prizm sdk version
#### Linux
- Set up the Prizm SDK ([PrizmSDK Setup Guide](https://prizm.cemetech.net/index.php/PrizmSDK_Setup_Guide))
- Set the FXCGSDK environment variable to where you installed libfxcg (`export FXCGSDK=...`), or put the prizm_racing directory in `libfxcg/projects/prizm_racing`.
- Run `make prizm`
- If you want to compile the SDL version (used for testing), install sdl2 and sdl2-ttf and run `make sdl`. The binary will be in `sdl/racing`, but it must be run from the prizm_racing directory (with `sdl/racing`)
### Windows
#### Windows
- Download the Prizm SDK ([https://github.com/Jonimoose/libfxcg/releases](https://github.com/Jonimoose/libfxcg/releases))
- Make sure the path to the SDK doesn't contain any spaces
- Put the `prizm_racing` directory in `PrizmSDK/projects/prizm_racing`
@ -53,8 +58,7 @@ A 3D, multiplayer racing game for casio fx-CG50 calculators
- To improve performance, the cones that are too far away from the camera are replaced with a simpler model and the ones even further away aren't drawn at all.
#### Potential rendering performance improvements
- Use DMA to clear the screen
- Draw the grass without using the 3D renderer (maybe using DMA)
- Use DMA to clear the screen and draw the grass (in progress)
- Clip models before clipping triangles
### Multiplayer

32
gint/Makefile Normal file
View File

@ -0,0 +1,32 @@
CC = sh-elf-g++
CFLAGS += -Wall -Wextra -Ofast -funroll-loops -DGINT
CFLAGS += -DFXCG50 -DTARGET_FXCG50 -m4-nofpu -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields
LDFLAGS = -m4-nofpu -mb -nostdlib -Wl,--no-warn-rwx-segments -T fxcg50.ld -lgint-cg -lc -lgcc -lgint-cg
INCLUDES =
SRCDIR = ../src
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(patsubst $(SRCDIR)/%,%,$(SOURCES:.cpp=.o))
DEPS = $(patsubst $(SRCDIR)/%,%,$(SOURCES:.cpp=.d))
racing.g3a: racing.bin
mkg3a racing.bin racing.g3a -n basic:racing -i uns:../resources/icons/unselected.bmp -i sel:../resources/icons/selected.bmp
racing.bin: racing
sh-elf-objcopy -O binary -R .bss -R .gint_bss racing racing.bin
racing: $(OBJECTS)
@echo "Linking..."
$(CC) $^ -o racing $(LDFLAGS)
%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ -MMD $< -MF "$(patsubst $(SRCDIR)/%,%,$(<:.cpp=.d))"
clean:
rm racing.g3a racing.bin racing $(OBJECTS) $(DEPS) -f
.PHONY: clean
-include $(DEPS)

View File

@ -5,7 +5,7 @@ file = open(os.path.dirname(__file__) + "/../../src/models.h", "w")
file.truncate(0)
for object in bpy.data.objects:
if object.type == 'MESH':
file.write("Triangle " + object.name + "_triangles[" + str(len(object.data.polygons)) + "] = {\n")
file.write("#ifdef GINT\nstatic\n#endif\nTriangle " + object.name + "_triangles[" + str(len(object.data.polygons)) + "] = {\n")
for polygon in object.data.polygons:
file.write("\t{\n")
for vertex in polygon.vertices:

36
src/display-gint.cpp Normal file
View File

@ -0,0 +1,36 @@
#ifdef GINT
#include "display.h"
Color newColor(int r, int g, int b){
return {
.r = r,
.g = g,
.b = b,
.color = ((r & 0b11111000)<<8) + ((g & 0b11111100)<<3)+(b>>3),
};
}
namespace Display {
int textHeight = 0;
void init(){
dsize("a", NULL, NULL, &textHeight);
}
void clear(Color color){
dclear(color.color);
}
void destroy(){}
int textWidth(const char *text){
int w;
dsize(text, NULL, &w, NULL);
return w;
}
void drawText(int x, int y, const char *text, Color color){
dtext(x, y, color.color, text);
}
void show() {
dupdate();
}
};
#endif

27
src/display-gint.h Normal file
View File

@ -0,0 +1,27 @@
#include <gint/display.h>
#define DISPLAY_WIDTH DWIDTH
#define DISPLAY_HEIGHT DHEIGHT
struct Color {
int r;
int g;
int b;
color_t color;
};
namespace Display {
inline void fillRect(int x, int y, int w, int h, Color color){
color_t *s = (color_t*)gint_vram;
s+=(y*DISPLAY_WIDTH)+x;
while(h--){
unsigned w2=w;
while(w2--)
*s++=color.color;
s+=DISPLAY_WIDTH-w;
}
}
inline void drawPoint(int x, int y, Color color){
gint_vram[DISPLAY_WIDTH*y + x] = color.color;
}
};

View File

@ -1,7 +1,6 @@
#ifdef PRIZM
#include "display.h"
#include "util.h"
#include <fxcg/display.h>
Color newColor(int r, int g, int b){
return {

28
src/display-prizm.h Normal file
View File

@ -0,0 +1,28 @@
#include <fxcg/display.h>
#define DISPLAY_WIDTH LCD_WIDTH_PX
#define DISPLAY_HEIGHT LCD_HEIGHT_PX
struct Color {
int r;
int g;
int b;
unsigned short color;
};
namespace Display {
extern unsigned short *VRAMAddress;
inline void fillRect(int x, int y, int w, int h, Color color){
unsigned short*s=VRAMAddress;
s+=(y*384)+x;
while(h--){
unsigned w2=w;
while(w2--)
*s++=color.color;
s+=384-w;
}
}
inline void drawPoint(int x, int y, Color color){
*(VRAMAddress + x + y * DISPLAY_WIDTH) = color.color;
}
};

View File

@ -1,7 +1,5 @@
#ifdef SDL
#include "display.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
SDL_Window *window;
SDL_Renderer *renderer;

29
src/display-sdl.h Normal file
View File

@ -0,0 +1,29 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#define DISPLAY_WIDTH 384
#define DISPLAY_HEIGHT 216
struct Color {
int r;
int g;
int b;
};
extern SDL_Renderer *renderer;
namespace Display {
inline void fillRect(int x, int y, int w, int h, Color color){
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_RenderFillRect(renderer, &rect);
}
inline void drawPoint(int x, int y, Color color){
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_RenderDrawPoint(renderer, x, y);
}
};

View File

@ -1 +0,0 @@
#include "display.h"

View File

@ -1,38 +1,21 @@
#pragma once
#ifdef PRIZM
#include <fxcg/display.h>
#ifdef GINT
#include "display-gint.h"
#endif
#define DISPLAY_WIDTH LCD_WIDTH_PX
#define DISPLAY_HEIGHT LCD_HEIGHT_PX
#ifdef PRIZM
#include "display-prizm.h"
#endif
#ifdef CE
#include "display-ce.h"
#endif
#ifdef SDL
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#define DISPLAY_WIDTH 384
#define DISPLAY_HEIGHT 216
extern SDL_Renderer *renderer;
#include "display-sdl.h"
#endif
struct Color {
int r;
int g;
int b;
#ifdef PRIZM
unsigned short color;
bool operator != (Color o){
return color != o.color;
}
#endif
#ifdef SDL
bool operator != (Color o){
return r != o.r || g != o.g || b != o.b;
}
#endif
};
Color newColor(int r, int g, int b);
namespace Display {
@ -43,36 +26,4 @@ namespace Display {
void clear(Color color);
int textWidth(const char *text);
void drawText(int x, int y, const char *text, Color color);
#ifdef PRIZM
extern unsigned short *VRAMAddress;
inline void fillRect(int x, int y, int w, int h, Color color){
unsigned short*s=VRAMAddress;
s+=(y*384)+x;
while(h--){
unsigned w2=w;
while(w2--)
*s++=color.color;
s+=384-w;
}
}
inline void drawPoint(int x, int y, Color color){
*(VRAMAddress + x + y * DISPLAY_WIDTH) = color.color;
}
#endif
#ifdef SDL
inline void fillRect(int x, int y, int w, int h, Color color){
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_RenderFillRect(renderer, &rect);
}
inline void drawPoint(int x, int y, Color color){
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_RenderDrawPoint(renderer, x, y);
}
#endif
};

30
src/input-gint.cpp Normal file
View File

@ -0,0 +1,30 @@
#ifdef GINT
#include "input.h"
#include "util.h"
#include <gint/drivers/keydev.h>
uint8_t keyState[12];
uint8_t lastKeyState[12];
namespace Input {
bool keyDown(int key){
int row = (key >> 4);
int col = 0x80 >> (key & 0x7);
return (keyState[row] & col) != 0;
}
bool keyDownLast(int key){
int row = (key >> 4);
int col = 0x80 >> (key & 0x7);
return (lastKeyState[row] & col) != 0;
}
void init(){
}
void _updateKeys(){
while(pollevent().type != KEYEV_NONE);
memcpy(lastKeyState, keyState, sizeof(uint8_t)*12);
memcpy(keyState, keydev_std()->state_now, sizeof(uint8_t)*12);
}
};
#endif

61
src/input-gint.h Normal file
View File

@ -0,0 +1,61 @@
#include <gint/keycodes.h>
#define KEY_MENU KEY_MENU
#define KEY_EXIT KEY_EXIT
#define KEY_EXE KEY_EXE
#define KEY_AC KEY_ACON
#define KEY_DEL KEY_DEL
#define KEY_OPTN KEY_OPTN
#define KEY_VARS KEY_VARS
#define KEY_0 KEY_0
#define KEY_1 KEY_1
#define KEY_2 KEY_2
#define KEY_3 KEY_3
#define KEY_4 KEY_4
#define KEY_5 KEY_5
#define KEY_6 KEY_6
#define KEY_7 KEY_7
#define KEY_8 KEY_8
#define KEY_9 KEY_9
#define KEY_A -1
#define KEY_B -1
#define KEY_C -1
#define KEY_D -1
#define KEY_E -1
#define KEY_F -1
#define KEY_G -1
#define KEY_H -1
#define KEY_I -1
#define KEY_J -1
#define KEY_K -1
#define KEY_L -1
#define KEY_M -1
#define KEY_N -1
#define KEY_O -1
#define KEY_P -1
#define KEY_Q -1
#define KEY_R -1
#define KEY_S -1
#define KEY_T -1
#define KEY_U -1
#define KEY_V -1
#define KEY_W -1
#define KEY_X -1
#define KEY_Y -1
#define KEY_Z -1
#define KEY_F1 KEY_F1
#define KEY_F2 KEY_F2
#define KEY_F3 KEY_F3
#define KEY_F4 KEY_F4
#define KEY_F5 KEY_F5
#define KEY_F6 KEY_F6
#define KEY_UP KEY_UP
#define KEY_DOWN KEY_DOWN
#define KEY_LEFT KEY_LEFT
#define KEY_RIGHT KEY_RIGHT
#define KEY_SHIFT KEY_SHIFT

View File

@ -2,6 +2,7 @@
#include "input.h"
#include "util.h"
#define keyboard_register ((unsigned short*)0xA44B0000)
unsigned short lastkey[8] = {0,0,0,0,0,0,0,0};
unsigned short holdkey[8] = {0,0,0,0,0,0,0,0};

61
src/input-prizm.h Normal file
View File

@ -0,0 +1,61 @@
#include <fxcg/keyboard.h>
#define KEY_MENU KEY_PRGM_MENU
#define KEY_EXIT KEY_PRGM_EXIT
#define KEY_EXE 31
#define KEY_AC 10
#define KEY_DEL 44
#define KEY_OPTN 68
#define KEY_VARS 58
#define KEY_0 KEY_PRGM_0
#define KEY_1 KEY_PRGM_1
#define KEY_2 KEY_PRGM_2
#define KEY_3 KEY_PRGM_3
#define KEY_4 KEY_PRGM_4
#define KEY_5 KEY_PRGM_5
#define KEY_6 KEY_PRGM_6
#define KEY_7 KEY_PRGM_7
#define KEY_8 KEY_PRGM_8
#define KEY_9 KEY_PRGM_9
#define KEY_A 76
#define KEY_B 66
#define KEY_C 56
#define KEY_D 46
#define KEY_E 36
#define KEY_F 26
#define KEY_G 75
#define KEY_H 65
#define KEY_I 55
#define KEY_J 45
#define KEY_K 35
#define KEY_L 25
#define KEY_M 74
#define KEY_N 64
#define KEY_O 54
#define KEY_P 73
#define KEY_Q 63
#define KEY_R 53
#define KEY_S 43
#define KEY_T 33
#define KEY_U 72
#define KEY_V 62
#define KEY_W 52
#define KEY_X 42
#define KEY_Y 32
#define KEY_Z 71
#define KEY_F1 79
#define KEY_F2 69
#define KEY_F3 59
#define KEY_F4 49
#define KEY_F5 39
#define KEY_F6 29
#define KEY_UP KEY_PRGM_UP
#define KEY_DOWN KEY_PRGM_DOWN
#define KEY_LEFT KEY_PRGM_LEFT
#define KEY_RIGHT KEY_PRGM_RIGHT
#define KEY_SHIFT 78

61
src/input-sdl.h Normal file
View File

@ -0,0 +1,61 @@
#include <SDL2/SDL.h>
#define KEY_MENU SDL_SCANCODE_TAB
#define KEY_EXIT SDL_SCANCODE_ESCAPE
#define KEY_EXE SDL_SCANCODE_SPACE
#define KEY_AC SDL_SCANCODE_BACKSPACE
#define KEY_DEL SDL_SCANCODE_DELETE
#define KEY_OPTN SDL_SCANCODE_BACKSPACE
#define KEY_VARS SDL_SCANCODE_BACKSPACE
#define KEY_0 SDL_SCANCODE_0
#define KEY_1 SDL_SCANCODE_1
#define KEY_2 SDL_SCANCODE_2
#define KEY_3 SDL_SCANCODE_3
#define KEY_4 SDL_SCANCODE_4
#define KEY_5 SDL_SCANCODE_5
#define KEY_6 SDL_SCANCODE_6
#define KEY_7 SDL_SCANCODE_7
#define KEY_8 SDL_SCANCODE_8
#define KEY_9 SDL_SCANCODE_9
#define KEY_A SDL_SCANCODE_A
#define KEY_B SDL_SCANCODE_B
#define KEY_C SDL_SCANCODE_C
#define KEY_D SDL_SCANCODE_D
#define KEY_E SDL_SCANCODE_E
#define KEY_F SDL_SCANCODE_F
#define KEY_G SDL_SCANCODE_G
#define KEY_H SDL_SCANCODE_H
#define KEY_I SDL_SCANCODE_I
#define KEY_J SDL_SCANCODE_J
#define KEY_K SDL_SCANCODE_K
#define KEY_L SDL_SCANCODE_L
#define KEY_M SDL_SCANCODE_M
#define KEY_N SDL_SCANCODE_N
#define KEY_O SDL_SCANCODE_O
#define KEY_P SDL_SCANCODE_P
#define KEY_Q SDL_SCANCODE_Q
#define KEY_R SDL_SCANCODE_R
#define KEY_S SDL_SCANCODE_S
#define KEY_T SDL_SCANCODE_T
#define KEY_U SDL_SCANCODE_U
#define KEY_V SDL_SCANCODE_V
#define KEY_W SDL_SCANCODE_W
#define KEY_X SDL_SCANCODE_X
#define KEY_Y SDL_SCANCODE_Y
#define KEY_Z SDL_SCANCODE_Z
#define KEY_F1 SDL_SCANCODE_F1
#define KEY_F2 SDL_SCANCODE_F2
#define KEY_F3 SDL_SCANCODE_F3
#define KEY_F4 SDL_SCANCODE_F4
#define KEY_F5 SDL_SCANCODE_F5
#define KEY_F6 SDL_SCANCODE_F6
#define KEY_UP SDL_SCANCODE_UP
#define KEY_DOWN SDL_SCANCODE_DOWN
#define KEY_LEFT SDL_SCANCODE_LEFT
#define KEY_RIGHT SDL_SCANCODE_RIGHT
#define KEY_SHIFT SDL_SCANCODE_LSHIFT

View File

@ -1,133 +1,19 @@
#pragma once
#ifdef GINT
#include "input-gint.h"
#endif
#ifdef PRIZM
#include <fxcg/keyboard.h>
#include "input-prizm.h"
#endif
#define KEY_MENU KEY_PRGM_MENU
#define KEY_EXIT KEY_PRGM_EXIT
#define KEY_EXE 31
#define KEY_AC 10
#define KEY_DEL 44
#define KEY_OPTN 68
#define KEY_VARS 58
#define KEY_0 KEY_PRGM_0
#define KEY_1 KEY_PRGM_1
#define KEY_2 KEY_PRGM_2
#define KEY_3 KEY_PRGM_3
#define KEY_4 KEY_PRGM_4
#define KEY_5 KEY_PRGM_5
#define KEY_6 KEY_PRGM_6
#define KEY_7 KEY_PRGM_7
#define KEY_8 KEY_PRGM_8
#define KEY_9 KEY_PRGM_9
#define KEY_A 76
#define KEY_B 66
#define KEY_C 56
#define KEY_D 46
#define KEY_E 36
#define KEY_F 26
#define KEY_G 75
#define KEY_H 65
#define KEY_I 55
#define KEY_J 45
#define KEY_K 35
#define KEY_L 25
#define KEY_M 74
#define KEY_N 64
#define KEY_O 54
#define KEY_P 73
#define KEY_Q 63
#define KEY_R 53
#define KEY_S 43
#define KEY_T 33
#define KEY_U 72
#define KEY_V 62
#define KEY_W 52
#define KEY_X 42
#define KEY_Y 32
#define KEY_Z 71
#define KEY_F1 79
#define KEY_F2 69
#define KEY_F3 59
#define KEY_F4 49
#define KEY_F5 39
#define KEY_F6 29
#define KEY_UP KEY_PRGM_UP
#define KEY_DOWN KEY_PRGM_DOWN
#define KEY_LEFT KEY_PRGM_LEFT
#define KEY_RIGHT KEY_PRGM_RIGHT
#define KEY_SHIFT 78
#define keyboard_register ((unsigned short*)0xA44B0000)
#ifdef CE
#include "input-ce.h"
#endif
#ifdef SDL
#include <SDL2/SDL.h>
#define KEY_MENU SDL_SCANCODE_TAB
#define KEY_EXIT SDL_SCANCODE_ESCAPE
#define KEY_EXE SDL_SCANCODE_SPACE
#define KEY_AC SDL_SCANCODE_BACKSPACE
#define KEY_DEL SDL_SCANCODE_DELETE
#define KEY_OPTN SDL_SCANCODE_BACKSPACE
#define KEY_VARS SDL_SCANCODE_BACKSPACE
#define KEY_0 SDL_SCANCODE_0
#define KEY_1 SDL_SCANCODE_1
#define KEY_2 SDL_SCANCODE_2
#define KEY_3 SDL_SCANCODE_3
#define KEY_4 SDL_SCANCODE_4
#define KEY_5 SDL_SCANCODE_5
#define KEY_6 SDL_SCANCODE_6
#define KEY_7 SDL_SCANCODE_7
#define KEY_8 SDL_SCANCODE_8
#define KEY_9 SDL_SCANCODE_9
#define KEY_A SDL_SCANCODE_A
#define KEY_B SDL_SCANCODE_B
#define KEY_C SDL_SCANCODE_C
#define KEY_D SDL_SCANCODE_D
#define KEY_E SDL_SCANCODE_E
#define KEY_F SDL_SCANCODE_F
#define KEY_G SDL_SCANCODE_G
#define KEY_H SDL_SCANCODE_H
#define KEY_I SDL_SCANCODE_I
#define KEY_J SDL_SCANCODE_J
#define KEY_K SDL_SCANCODE_K
#define KEY_L SDL_SCANCODE_L
#define KEY_M SDL_SCANCODE_M
#define KEY_N SDL_SCANCODE_N
#define KEY_O SDL_SCANCODE_O
#define KEY_P SDL_SCANCODE_P
#define KEY_Q SDL_SCANCODE_Q
#define KEY_R SDL_SCANCODE_R
#define KEY_S SDL_SCANCODE_S
#define KEY_T SDL_SCANCODE_T
#define KEY_U SDL_SCANCODE_U
#define KEY_V SDL_SCANCODE_V
#define KEY_W SDL_SCANCODE_W
#define KEY_X SDL_SCANCODE_X
#define KEY_Y SDL_SCANCODE_Y
#define KEY_Z SDL_SCANCODE_Z
#define KEY_F1 SDL_SCANCODE_F1
#define KEY_F2 SDL_SCANCODE_F2
#define KEY_F3 SDL_SCANCODE_F3
#define KEY_F4 SDL_SCANCODE_F4
#define KEY_F5 SDL_SCANCODE_F5
#define KEY_F6 SDL_SCANCODE_F6
#define KEY_UP SDL_SCANCODE_UP
#define KEY_DOWN SDL_SCANCODE_DOWN
#define KEY_LEFT SDL_SCANCODE_LEFT
#define KEY_RIGHT SDL_SCANCODE_RIGHT
#define KEY_SHIFT SDL_SCANCODE_LSHIFT
#include "input-sdl.h"
#endif
namespace Input {

View File

@ -10,6 +10,11 @@
#include "car.h"
#include "track.h"
#ifdef GINT
#include <gint/gint.h>
#include <gint/mmu.h>
#endif
#ifdef PRIZM
#include <fxcg/system.h>
#include <fxcg/serial.h>
@ -21,12 +26,19 @@ vec3<float> cameraPos = {0, 0, 0};
vec3<float> cameraSpeed = {0, 0, 0};
float cameraAngle = 0;
int main(){
fp st[SIN_SAMPLES];
sinTable = st;
createSinTable();
#ifdef GINT
static GALIGNED(32) fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
#include "models.h"
#endif
int main(){
#ifndef GINT
fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
#include "models.h"
#endif
Rasterizer::depthBuffer = depthBuffer;
createSinTable();
Triangle simpleConeTriangles[] = {
{
@ -57,9 +69,6 @@ int main(){
Input::init();
fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
Rasterizer::depthBuffer = depthBuffer;
srand(0);
Triangle sunTriangles[2] = {
@ -171,6 +180,9 @@ int main(){
#endif
if(Input::keyPressed(KEY_MENU)){
#ifdef GINT
gint_osmenu();
#endif
#ifdef PRIZM
while(Input::keyDown(KEY_MENU))
Input::update();
@ -184,12 +196,14 @@ int main(){
Bdisp_EnableColor(1);
GetKey(&k);
Time::update();
continue;
#endif
#ifdef SDL
return 0;
#endif
int t = Time::delta;
Time::update();
Time::delta = t;
}
car.processInput();
@ -241,12 +255,10 @@ int main(){
car.render(view);
char buffer[20];
#ifdef SDL
sprintf(buffer, "%d", (int)(1.0f / (Time::delta / 128.0f)));
#endif
#ifdef PRIZM
// sprintf(fpsBuffer, "%d", (int)Time::delta);
itoa((int)(1.0f / (Time::delta / 128.0f)), (unsigned char*)buffer);
#else
sprintf(buffer, "%d", (int)(1.0f / (Time::delta / 128.0f)));
#endif
Display::drawText(0, 0, "FPS: ", newColor(255, 255, 255));
Display::drawText(Display::textWidth("FPS: "), 0, buffer, newColor(255, 255, 255));
@ -257,11 +269,10 @@ int main(){
speed = (1.0f / car.speed.i_length()) * 128.0f / 1000.0f * 3600.0f;
else
speed = 0;
#ifdef SDL
sprintf(buffer, "%d", (int)speed);
#endif
#ifdef PRIZM
itoa((int)speed, (unsigned char*)buffer);
#else
sprintf(buffer, "%d", (int)speed);
#endif
Display::drawText(0, DISPLAY_HEIGHT-Display::textHeight, "SPEED: ", newColor(255, 255, 255));
Display::drawText(Display::textWidth("SPEED: "), DISPLAY_HEIGHT-Display::textHeight, buffer, newColor(255, 255, 255));

View File

@ -1,3 +1,6 @@
#ifdef GINT
static
#endif
Triangle car_triangles[230] = {
{
{0.794, 0.294, -0.380},
@ -1610,6 +1613,9 @@ Triangle car_triangles[230] = {
newColor(203, 2, 1)
},
};
#ifdef GINT
static
#endif
Triangle cone_triangles[22] = {
{
{0.328, -0.679, 0.328},

View File

@ -3,6 +3,20 @@
#include "rmath.h"
#include "time.h"
#ifdef GINT
#include <gint/dma.h>
#include <gint/mmu.h>
void cache_ocbp(void *buffer, size_t size){
for(int i = 0; i < size / 32; i++) {
__asm__("ocbp @%0" :: "r"(buffer));
buffer += 32;
}
}
void *mmu_translate_uram(void *ptr){
return mmu_uram() + ((uint32_t)ptr - 0x08100000);
}
#endif
struct Plane {
vec3<fp> n;
fp d;
@ -36,9 +50,16 @@ namespace Rasterizer {
}
void reset(){
#ifdef GINT
fp v = -1;
fp *depthBuffer_P1 = (fp*) mmu_translate_uram(depthBuffer);
cache_ocbp(depthBuffer, RENDER_WIDTH*RENDER_HEIGHT*sizeof(fp));
dma_memset(depthBuffer_P1, *((uint32_t*)&v), RENDER_WIDTH*RENDER_HEIGHT*sizeof(fp));
#else
for(int i = 0; i < RENDER_WIDTH*RENDER_HEIGHT; i++){
depthBuffer[i] = -1;
}
#endif
}
void setFOV(int fov){

View File

@ -36,7 +36,7 @@ float _float_sin(float x) {
return _float_cos(x - HALF_PI);
}
fp *sinTable = nullptr;
static fp sinTable[SIN_SAMPLES];
fp _fp_sin(fp x){
return fp(_float_sin((float)x));
}

View File

@ -20,7 +20,6 @@ inline fp fp_floor(fp x){
}
#define SIN_SAMPLES 1000
extern fp *sinTable;
void createSinTable();
fp _fp_sin(fp x);

12
src/time-gint.cpp Normal file
View File

@ -0,0 +1,12 @@
#ifdef GINT
#include "time.h"
#include <gint/rtc.h>
namespace Time {
void init(){}
void update(){
const float lastTime = time;
time = rtc_ticks();
delta = time - lastTime;
}
};
#endif

View File

@ -1,5 +1,12 @@
#pragma once
#ifdef GINT
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <gint/kmalloc.h>
#endif
#ifdef PRIZM
#include <fxcg/heap.h>
#include <fxcg/misc.h>