Skip to content

Commit

Permalink
== N64 ==
Browse files Browse the repository at this point in the history
- Added fade for splash screens
- Changed a few assets to palette versions
- Improved frame stats
- Added a preliminary version of the scroll test
  • Loading branch information
ArtemioUrbina committed Jul 18, 2024
1 parent 533843d commit ce0a885
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 42 deletions.
97 changes: 80 additions & 17 deletions 240psuite/N64/240pSuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
#include "font.h"
#include "image.h"
#include "controller.h"
#include "tests.h"

void drawIntro(void);
void drawPatternsMenu(void);
void drawPatternsColorMenu(void);
void drawPatternsGeometryMenu(void);
void drawVideoTestsMenu(void);

int main(void)
{
int sel = 1, reload = 1;
Expand All @@ -40,7 +41,8 @@ int main(void)
initN64();
loadFont();

//drawIntro();
drawIntro();

while(1) {
int c = 1, x = 55, y = 90;
int r = 0xFF, g = 0xFF, b = 0xFF;
Expand All @@ -67,7 +69,7 @@ int main(void)
waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

if(keys.d_up)
sel--;
Expand Down Expand Up @@ -134,7 +136,7 @@ void drawPatternsMenu(void)
waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

if(keys.d_up)
sel--;
Expand Down Expand Up @@ -213,7 +215,7 @@ void drawPatternsColorMenu(void)
waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

if(keys.d_up)
sel--;
Expand Down Expand Up @@ -280,7 +282,7 @@ void drawPatternsGeometryMenu(void)
waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

if(keys.d_up)
sel--;
Expand Down Expand Up @@ -356,7 +358,7 @@ void drawVideoTestsMenu(void)
waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

if(keys.d_up)
sel--;
Expand All @@ -376,6 +378,9 @@ void drawVideoTestsMenu(void)

switch(sel)
{
case 5:
drawScroll();
break;
case 14:
exit = 1;
break;
Expand All @@ -390,32 +395,90 @@ void drawVideoTestsMenu(void)
freeImage(&sd);
}

void drawIntro()
#define LOGO_HOLD 60
#define FADE_STEPS 20
#define FADE_HOLD 10

void fadeStep(uint16_t *colorRaw)
{
color_t color;

color = color_from_packed16(*colorRaw);
color.r = (color.r > 0) ? (color.r - color.r/FADE_STEPS) : 0;
color.g = (color.g > 0) ? (color.g - color.g/FADE_STEPS) : 0;
color.b = (color.b > 0) ? (color.b - color.b/FADE_STEPS) : 0;
*colorRaw = color_to_packed16(color);
}

void drawSplash(char *name, int delay)
{
int delay = 90;
joypad_buttons_t keys;
sprite_t *ld = NULL;
sprite_t *logo = NULL;
uint16_t *pal = NULL;

ld = sprite_load("rom:/libdragon.sprite");
if(!ld)
logo = sprite_load(name);
if(!logo)
return;

pal = sprite_get_palette(logo);
if(!pal)
{
freeImage(&logo);
return;
}

while(delay) {
getDisplay();

rdpqStart();
rdpqDrawImage(ld, (dW - ld->width)/2, (dH - ld->height)/2);
rdpqClearScreen();
rdpqDrawImage(logo, (dW - logo->width)/2, (dH - logo->height)/2);
rdpqEnd();

waitVsync();

joypad_poll();
keys = Controller_ButtonsDown();
keys = controllerButtonsDown();

delay --;
if(keys.a || keys.b)
if(keys.a || keys.b || keys.start)
delay = 0;
}

freeImage(&ld);
delay = FADE_STEPS;
while(delay) {
getDisplay();

rdpqStart();
rdpqClearScreen();
rdpqDrawImage(logo, (dW - logo->width)/2, (dH - logo->height)/2);
rdpqEnd();

for(unsigned int c = 0; c < 16; c++)
fadeStep(&pal[c]);

waitVsync();

delay --;
}

delay = FADE_HOLD;
while(delay) {
getDisplay();

rdpqStart();
rdpqClearScreen();
rdpqEnd();

waitVsync();

delay --;
}

freeImage(&logo);
}

void drawIntro()
{
drawSplash("rom:/libdragon.sprite", LOGO_HOLD);
}
2 changes: 1 addition & 1 deletion 240psuite/N64/240pn64.pnproj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Project name="240pn64"><File path="240pSuite.c"></File><File path="Makefile"></File><File path="font.c"></File><File path="font.h"></File><File path="system.c"></File><File path="system.h"></File><File path="image.c"></File><File path="image.h"></File><File path="video.c"></File><File path="video.h"></File><File path="controller.c"></File><File path="controller.h"></File></Project>
<Project name="240pn64"><File path="240pSuite.c"></File><File path="Makefile"></File><File path="font.c"></File><File path="font.h"></File><File path="system.c"></File><File path="system.h"></File><File path="image.c"></File><File path="image.h"></File><File path="video.c"></File><File path="video.h"></File><File path="controller.c"></File><File path="controller.h"></File><File path="tests.c"></File><File path="tests.h"></File></Project>
6 changes: 5 additions & 1 deletion 240psuite/N64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ filesystem/%.sprite: assets/%.png
@$(N64_MKSPRITE) $(MKSPRITE_FLAGS) -o filesystem "$<"

filesystem/240pSuite-font.sprite: MKSPRITE_FLAGS=
filesystem/mainbg.sprite: MKSPRITE_FLAGS=
filesystem/mainbg.sprite: MKSPRITE_FLAGS=--format CI4
filesystem/sd.sprite: MKSPRITE_FLAGS=--format CI4
filesystem/grid.sprite: MKSPRITE_FLAGS=
filesystem/donna.sprite: MKSPRITE_FLAGS=
filesystem/sonicback.sprite: MKSPRITE_FLAGS=--format CI8
filesystem/sonicfloor.sprite: MKSPRITE_FLAGS=--format CI4
filesystem/libdragon.sprite: MKSPRITE_FLAGS=--format CI4

$(BUILD_DIR)/240pSuite.dfs: $(ASSETS_CONV)
$(BUILD_DIR)/240pSuite.elf: $(src:%.c=$(BUILD_DIR)/%.o)
Expand Down
Binary file modified 240psuite/N64/assets/libdragon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 240psuite/N64/assets/mainbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 240psuite/N64/assets/sonicback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 240psuite/N64/assets/sonicfloor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 11 additions & 7 deletions 240psuite/N64/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
int JoyCountX = 0;
int JoyCountY = 0;

joypad_buttons_t Controller_ButtonsDown()
joypad_buttons_t controllerButtonsDown()
{
joypad_inputs_t pad_inputs;
joypad_buttons_t pad_pressed;
Expand Down Expand Up @@ -84,13 +84,15 @@ joypad_buttons_t Controller_ButtonsDown()
}
}

//if(held.c[0].C_down && held.c[0].R && held.c[0].L)
//reset_video();
#ifdef DEBUG_BENCHMARK
if(pad_pressed.l && pad_pressed.l)
resetVideo();
#endif
return pad_pressed;
}


joypad_buttons_t Controller_ButtonsHeld()
joypad_buttons_t controllerButtonsHeld()
{
joypad_inputs_t pad_inputs;
joypad_buttons_t pad_pressed;
Expand All @@ -109,8 +111,10 @@ joypad_buttons_t Controller_ButtonsHeld()
pad_pressed.d_up = 1;
if (y < -JOYTHSHLD)
pad_pressed.d_down = 1;

//if(held.c[0].C_down && held.c[0].R && held.c[0].L)
//reset_video();

#ifdef DEBUG_BENCHMARK
if(pad_pressed.l && pad_pressed.l)
resetVideo();
#endif
return pad_pressed;
}
4 changes: 2 additions & 2 deletions 240psuite/N64/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

#include <libdragon.h>

joypad_buttons_t Controller_ButtonsDown();
joypad_buttons_t Controller_ButtonsHeld();
joypad_buttons_t controllerButtonsDown();
joypad_buttons_t controllerButtonsHeld();
3 changes: 2 additions & 1 deletion 240psuite/N64/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

void rdpqDrawImage(sprite_t* tiles, float x, float y)
{
rdpq_sprite_blit(tiles, x, y, NULL);
if(tiles)
rdpq_sprite_blit(tiles, x, y, NULL);
}

void rdpqClearScreen()
Expand Down
120 changes: 120 additions & 0 deletions 240psuite/N64/tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 240p Test Suite for Nintendo 64
* Copyright (C)2024 Artemio Urbina
*
* This file is part of the 240p Test Suite
*
* The 240p Test Suite is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The 240p Test Suite is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 240p Test Suite; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "system.h"
#include "video.h"
#include "font.h"
#include "image.h"
#include "controller.h"
#include "tests.h"

void drawScroll()
{
int end = 0, x = 0, y = 0, currentframe = 0;
int speed = 1, acc = -1, pause = 0, vertical = 0;
sprite_t *sonicback, *overlay;
joypad_buttons_t keys;

sonicback = sprite_load("rom:/sonicback.sprite");
overlay = sprite_load("rom:/sonicfloor.sprite");

while(!end)
{
getDisplay();

rdpqStart();
if(x > 0)
rdpqDrawImage(sonicback, x-256, 0);
rdpqDrawImage(sonicback, x, 0);
if(x < 64)
rdpqDrawImage(sonicback, x+256, 0);

if(x > 0)
rdpqDrawImage(overlay, 2*x-256, 48);
rdpqDrawImage(overlay, 2*x, 48);
if(x < 64)
rdpqDrawImage(overlay, 2*x+256, 48);
// Extra gap
if(x < -96)
rdpqDrawImage(overlay, 2*x+512, 48);

rdpqEnd();

waitVsync();

joypad_poll();
keys = controllerButtonsDown();

if(keys.d_up)
speed += 1;

if(keys.d_down)
speed -= 1;

if(keys.b)
end = 1;

if(keys.a)
pause = !pause;

if(keys.c_left)
acc *= -1;

if(keys.c_right)
vertical = !vertical;

if(speed > 16)
speed = 16;

if(speed < 1)
speed = 1;

if(!pause)
{
if(!vertical)
x += speed * acc;
else
y -= speed * acc;
}

if(x < -128)
x = 128 - speed;
if(x > 128)
x = -128 + speed;

if(y < -7)
y = 0;
if(y > 7)
y = 0;

if(!vertical)
{
currentframe ++;
if(currentframe > 10)
{
currentframe = 0;
}
}
}

freeImage(&sonicback);
freeImage(&overlay);
}
6 changes: 6 additions & 0 deletions 240psuite/N64/tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef TESTS_H
#define TESTS_H

void drawScroll();

#endif
Loading

0 comments on commit ce0a885

Please sign in to comment.