Skip to content

Commit

Permalink
== N64 ==
Browse files Browse the repository at this point in the history
- Changed Color Bars, White & RGB and HCFR to 32 bit color mode
- Added Color High and Low options in Color Bars
- Updated to use rand() and entropy
- Prepared to use different AA as options if useful
  • Loading branch information
ArtemioUrbina committed Aug 14, 2024
1 parent dba28ec commit 84835ea
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 97 deletions.
6 changes: 4 additions & 2 deletions 240psuite/N64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ filesystem/monoscope.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/pluge.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/plugePAL.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/PLUGEBorder.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/color.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI8
filesystem/color_grid.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI8
filesystem/color.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format RGBA32
filesystem/colorlow.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format RGBA32
filesystem/colorhigh.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format RGBA32
filesystem/color_grid.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format RGBA32
filesystem/EBU75.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/SMPTE75.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
filesystem/601701cb.sprite: MKSPRITE_FLAGS=$(MKSPRITE_EXTRA_FLAGS) --format CI4
Expand Down
Binary file modified 240psuite/N64/assets/color.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/color_grid.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/colorhigh.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/colorlow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions 240psuite/N64/filesystem/help/manuallag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
MANUAL LAG TEST (1/3)

The main intention is to show a changing pattern
on the screen, which can be complemented with
audio and vibration on the controller if set.
This should show to some degree any lag when
processing the signal.

As an added feature, the user can click the #GA#G
button when the sprite is aligned with the one on
the background, and the offset in frames from the
actual intersection will be shown on screen. This
can be repeated ten times and the software will
calculate the average. Whenever the button was
pressed before the actual intersection frame, the
#C(cont...)#C
MANUAL LAG TEST (2/3)

result will be ignored (but still shown onscreen).
Button #GCL#G can be used to change the direction
of the sprite from vertical to horizontal, or
display both at the same time.


#ROf course the evaluation is dependent on reflexes
and/or rhythm more than anything.#R The visual and
audio cues are the more revealing aspects which
the user should consider, of course the interactive
factor can give an experienced player the hang of
the system when testing via different connections.

#C(cont...)#C
MANUAL LAG TEST (3/3)

Since a frame is around 16 ms (1000/60) in NTSC
and 20 ms (1000/50) in PAL, that value must be
considered the general error when using the test
results.

106 changes: 72 additions & 34 deletions 240psuite/N64/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ void frameEnableUpscaler(int enable) {
upscaleFrame = enable;
}

void rdpqSetDrawMode() {
rdpq_set_mode_copy(1);
void rdpqSetDrawMode(int type) {
if(current_bitdepth == DEPTH_32_BPP)
rdpq_set_mode_standard();
else {
rdpq_set_mode_copy(type);
rdpq_mode_antialias(current_rdp_aa_filter);
}
}

void rdpqStart() {
Expand All @@ -75,7 +80,7 @@ void rdpqStart() {
else
rdpq_attach(__disp, NULL);

rdpqSetDrawMode();
rdpqSetDrawMode(1);
}

void rdpqEnd() {
Expand Down Expand Up @@ -121,7 +126,7 @@ void rdpqDrawImage(image* data) {
rdpq_sprite_blit(data->tiles, data->x, data->y, &(rdpq_blitparms_t) {
.flip_x = data->flipH, .flip_y = data->flipV
});
rdpqSetDrawMode();
rdpqSetDrawMode(1);
}

if(upscaleFrame)
Expand Down Expand Up @@ -152,7 +157,7 @@ void rdpqDrawImageXY(image* data, int x, int y) {
rdpq_sprite_blit(data->tiles, x, y, &(rdpq_blitparms_t) {
.flip_x = data->flipH, .flip_y = data->flipV
});
rdpqSetDrawMode();
rdpqSetDrawMode(1);
}

if(upscaleFrame)
Expand Down Expand Up @@ -308,11 +313,17 @@ int copyMenuFB() {
return 0;
freeMenuFB();

// only allow this in 8MB expanded systems
// reason is, although it works it ends up leading to memory
// fragmentation even if allocated from boot
// since constant resolution changes deallocate and reallocate
// libDragon's framebuffers (safe buffer)
// ATM don't allow it to happen when in 32bpp since it draws
// incorerctly with rdpq_tex_blit
if(current_bitdepth == DEPTH_32_BPP)
return 0;

// only allow 480i in 8MB expanded systems
// reason is: although it works, it ends up leading to memory
// fragmentation even if allocated from boot since constant
// resolution changes deallocate and reallocate libDragon's
// framebuffers (safe buffer)

if(getDispHeight() > 240 && (get_memory_size() / 0x100000) < 8)
return 0;

Expand All @@ -329,7 +340,7 @@ int copyMenuFB() {
}

rdpq_attach(__menu_fb, NULL);
rdpq_set_mode_copy(0);
rdpqSetDrawMode(0);
rdpq_tex_blit(__disp, 0, 0, NULL);
rdpq_detach();

Expand All @@ -351,14 +362,15 @@ void freeMenuFB() {
}

void drawMenuFB() {
surface_t *target = NULL;

if(!__menu_fb || !__disp)
return;
surface_t *target = NULL;

target = upscaleFrame ? __upscale_fb : __disp;

rdpq_attach(target, NULL);
rdpq_set_mode_copy(0);
rdpqSetDrawMode(0);
rdpq_clear(RGBA32(0, 0, 0, 0xff));
// check if we are using a FB from a different resolution and adjust
if(target->height == __menu_fb->height && target->width > __menu_fb->width)
Expand All @@ -371,32 +383,58 @@ void drawMenuFB() {
void darkenMenuFB(int amount) {
if(!__menu_fb)
return;

if(surface_get_format(__menu_fb) != FMT_RGBA16)
return;

uint16_t *pixels = (uint16_t*)__menu_fb->buffer;
unsigned int len = TEX_FORMAT_PIX2BYTES(surface_get_format(__menu_fb), __menu_fb->width * __menu_fb->height)/2;
if(surface_get_format(__menu_fb) == FMT_RGBA16) {
uint16_t *pixels = (uint16_t*)__menu_fb->buffer;
unsigned int len = TEX_FORMAT_PIX2BYTES(surface_get_format(__menu_fb), __menu_fb->width * __menu_fb->height)/2;

for(unsigned int i = 0; i < len; i++) {
color_t color;
for(unsigned int i = 0; i < len; i++) {
color_t color;

color = color_from_packed16(pixels[i]);

color = color_from_packed16(pixels[i]);
if(color.r > amount)
color.r -= amount;
else
color.r = 0;
if(color.g > amount)
color.g -= amount;
else
color.g = 0;
if(color.b > amount)
color.b -= amount;
else
color.b = 0;

if(color.r > amount)
color.r -= amount;
else
color.r = 0;
if(color.g > amount)
color.g -= amount;
else
color.g = 0;
if(color.b > amount)
color.b -= amount;
else
color.b = 0;
pixels[i] = graphics_convert_color(color);
}

}

pixels[i] = graphics_convert_color(color);
if(surface_get_format(__menu_fb) == FMT_RGBA32) {
uint32_t *pixels = (uint32_t *)__menu_fb->buffer;
unsigned int len = TEX_FORMAT_PIX2BYTES(surface_get_format(__menu_fb), __menu_fb->width * __menu_fb->height)/4;

for(unsigned int i = 0; i < len; i++) {
color_t color;

color = color_from_packed32(pixels[i]);

if(color.r > amount)
color.r -= amount;
else
color.r = 0;
if(color.g > amount)
color.g -= amount;
else
color.g = 0;
if(color.b > amount)
color.b -= amount;
else
color.b = 0;

pixels[i] = graphics_convert_color(color);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions 240psuite/N64/mcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ int draw3DScene(SceneData *scene, int frames, uint8_t color, int type, int contr
frames = origFrames;
}

if(scene->camPos.v[2] < 44.0)
scene->camPos.v[2] = 44.0f;
if(scene->camPos.v[2] < 45.0)
scene->camPos.v[2] = 45.0f;
if(scene->camPos.v[2] > 590.0)
scene->camPos.v[2] = 590.0;
}
Expand Down
9 changes: 6 additions & 3 deletions 240psuite/N64/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ void selectVideoMode(int useBack) {
x = back->x + 48;
y = back->y + 17;

drawStringC(y, 0xff, 0xff, 0xff, "240p Test Suite Video Modes"); y += 6*fh;
drawStringC(y, 0xff, 0xff, 0xff, "240p Test Suite Video Modes");
if(current_bitdepth == DEPTH_32_BPP)
drawStringS(x+160, y+fh, 0xff, 0xff, 0x00, "32 Bit Mode");
y += 6*fh;

drawStringC(y, 0x00, 0xff, 0x00, "Please select the desired mode"); y += 3*fh;

Expand Down Expand Up @@ -307,7 +310,7 @@ void drawCredits(int usebuffer) {
drawStringS(x+5, y, 0xff, 0xff, 0xff, data); y += fh;

drawStringS(x, y, 0x00, 0xff, 0x00, "SDK:"); y += fh;
drawStringS(x+5, y, 0xff, 0xff, 0xff, "libDragon + tiny 3D"); y += fh; y2 = y;
drawStringS(x+5, y, 0xff, 0xff, 0xff, "libDragon & tiny 3D"); y += fh; y2 = y;
drawStringS(x2, y2, 0x00, 0xff, 0x00, "Monoscope:"); y2 += fh;
drawStringS(x2+5, y2, 0xff, 0xff, 0xff, "Keith Raney\n(@khmr33)"); y2 += 2*fh;
drawStringS(x2+5, y2, 0xff, 0xff, 0xff, "@FirebrandX"); y2 += fh;
Expand Down Expand Up @@ -556,7 +559,7 @@ void SD_blink_cycle(image *sd) {
{
if(!is_blinking) {
// 2% chance every frame after 240
if(RANDN(100) < 98) {
if(rand()%100 < 98) {
is_blinking = 1;
blink_counter = 230;
rdpqDrawImage(SD_b1);
Expand Down
63 changes: 45 additions & 18 deletions 240psuite/N64/patterns.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,29 @@ void drawPLUGE() {
freeImage(&back);
}

#define NUM_CBARS 4

void drawColorbars() {
int end = 0, pattern = 0;
image *back = NULL, *grid = NULL;
int end = 0, sel = 1, pattern = 0, reload = 1;
image *back = NULL;
char *colors[NUM_CBARS] = { "rom:/colorlow.sprite",
"rom:/color.sprite",
"rom:/colorhigh.sprite",
"rom:/color_grid.sprite" };
joypad_buttons_t keys;

back = loadImage("rom:/color.sprite");
if(!back)
return;
grid = loadImage("rom:/color_grid.sprite");
if(!grid) {
freeImage(&back);
return;
}

changeBitDepthOnVBlank(1);
while(!end) {
if(reload) {
freeImage(&back);
back = loadImage(colors[sel]);
reload = 0;
}

getDisplay();

rdpqStart();
if(!pattern)
rdpqDrawImage(back);
else
rdpqDrawImage(grid);
rdpqDrawImage(back);
rdpqEnd();

checkMenu(COLORBARSHELP, NULL);
Expand All @@ -137,14 +138,36 @@ void drawColorbars() {
keys = controllerButtonsDown();

checkStart(keys);
if(keys.a)
if((sel == 1 || sel == 3) && keys.a) {
pattern = !pattern;
if(pattern)
sel = 3;
else
sel = 1;
reload = 1;
}

if(sel != 3) {
if(keys.l) {
if(sel > 0) {
sel --;
reload = 1;
}
}

if(keys.r) {
if(sel < 2) {
sel ++;
reload = 1;
}
}
}
if(keys.b)
end = 1;
}

freeImage(&back);
freeImage(&grid);

changeBitDepthOnVBlank(0);
}

void drawEBUSMPTE(unsigned int ebu) {
Expand Down Expand Up @@ -286,6 +309,7 @@ void drawWhiteScreen() {
// white
cr = cg = cb = IRE_100;
er = eb = eg = IRE_100;
changeBitDepthOnVBlank(1);
while(!end) {
getDisplay();

Expand Down Expand Up @@ -461,6 +485,7 @@ void drawWhiteScreen() {
break;
}
}
changeBitDepthOnVBlank(0);
}

void drawSharpness() {
Expand Down Expand Up @@ -809,6 +834,7 @@ void drawHCFR() {
if(hcfr_type == MENU_CANCEL)
return;

changeBitDepthOnVBlank(1);
while(!done) {
int r, g, b;

Expand Down Expand Up @@ -862,6 +888,7 @@ void drawHCFR() {

checkStart(keys);
}
changeBitDepthOnVBlank(0);
}

#define NUM_CONV 5
Expand Down
Loading

0 comments on commit 84835ea

Please sign in to comment.