Skip to content

Commit

Permalink
Add a frame skip setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydr8gon committed Dec 11, 2024
1 parent aa72ea0 commit bceba0b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
19 changes: 19 additions & 0 deletions src/main.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
.globl framebuffer
.globl fps_emulate
.globl fps_display
.globl skip_native
.globl skip_emulate
.globl frame_count

.globl _start
Expand All @@ -33,6 +35,8 @@ framebuffer: .word FRAMEBUFFER1
fps_native: .byte 0
fps_emulate: .byte 0
fps_display: .byte 0
skip_native: .byte 0
skip_emulate: .byte 0
frame_count: .byte 0

.section .boot
Expand Down Expand Up @@ -262,6 +266,21 @@ pi_wait2:
nop

check_frame:
// Ignore V-blanks to match the frames being skipped
la k1, skipped_set
lbu k0, (k1)
srl k0, k0, 2
la k1, skip_native
lbu k1, (k1)
sub k0, k0, k1
blez k0, skip_reset
li k0, 0
addi k0, k1, 1
skip_reset:
la k1, skip_native
bnez k0, input_update
sb k0, (k1)

// Continue if the next frame is ready; otherwise just update input
la k0, frame_count
lbu k1, (k0)
Expand Down
14 changes: 11 additions & 3 deletions src/menu.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

.globl layer_set
.globl precision_set
.globl skipped_set
.globl audio_set

.globl update_menu
Expand All @@ -31,6 +32,7 @@
counter_set: .byte 0 << 2
layer_set: .byte 0 << 2
precision_set: .byte 2 << 2
skipped_set: .byte 0 << 2
audio_set: .byte 1 << 2
left_str: .string "<"
right_str: .string ">"
Expand All @@ -40,6 +42,7 @@ title_str: .string "SODIUM64 SETTINGS"
counter_str: .string "FPS COUNTER"
layer_str: .string "SUB LAYER ORDER"
precision_str: .string "FRAME PRECISION"
skipped_str: .string "FRAMES SKIPPED"
audio_str: .string "AUDIO OUTPUT"

.align 4
Expand All @@ -53,16 +56,21 @@ medium_str: .string " MEDIUM "
high_str: .string " HIGH "
higher_str: .string " HIGHER "
max_str: .string " MAX "
zero_str: .string " 0 "
one_str: .string " 1 "
two_str: .string " 2 "
three_str: .string " 3 "

.align 4
menu_items: .word counter_str, layer_str, precision_str, audio_str, 0
menu_opts: .word toggle_opts, layer_opts, precision_opts, toggle_opts
menu_sets: .word counter_set, layer_set, precision_set, audio_set
menu_items: .word counter_str, layer_str, precision_str, skipped_str, audio_str, 0
menu_opts: .word toggle_opts, layer_opts, precision_opts, skipped_opts, toggle_opts
menu_sets: .word counter_set, layer_set, precision_set, skipped_set, audio_set

.align 4
toggle_opts: .word off_str, on_str, 0
layer_opts: .word back_str, front_str, 0
precision_opts: .word lower_str, low_str, medium_str, high_str, higher_str, max_str, 0
skipped_opts: .word zero_str, one_str, two_str, three_str, 0

.text
.set noreorder
Expand Down
51 changes: 36 additions & 15 deletions src/ppu.S
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,34 @@ end_fill:

.align 5
rsp_frame:
// Alternate indices for queued frame values each frame
// Make a final frame section and get alternating queue indices
lbu t5, queue_id // Next
lhu a0, cur_line
move t4, ra
jal make_section
xori t6, t5, 4 // Current

// Skip rendering frames based on the setting
lbu t0, skipped_set
srl t0, t0, 2
lbu t1, skip_emulate
bge t1, t0, skip_reset
li t0, 0
addi t0, t1, 1

skip_reset:
// Update the skip counter and the section pointer if not skipped
la t1, skip_emulate
bnez t0, ignore_frame
sb t0, (t1)
sb t6, queue_id
lw t0, sect_queues(t6)
sw t0, section_ptr

// Set initial values for palette conversion
lbu t0, brightness
lw t4, pal_queues(t5)
addi t4, t4, 0x7F8
lw v1, pal_queues(t5)
addi v1, v1, 0x7F8
li t6, 0x1FE

update_dpal:
Expand Down Expand Up @@ -459,11 +478,11 @@ update_dpal:
// Set a color in the palette queue and loop until finished
sll t3, t2, 16
or t2, t2, t3
sw t2, 0(t4)
sw t2, 4(t4)
sw t2, 0(v1)
sw t2, 4(v1)
addi t6, t6, -2
bnez t6, update_dpal
addi t4, t4, -8
addi v1, v1, -8

// Copy OAM to the queue for the next frame
la t0, oam
Expand Down Expand Up @@ -499,20 +518,12 @@ vram_loop:
bne t0, t1, vram_loop
addi t0, t0, 0x20

// Make a final frame section and reset the pointer
lhu a0, cur_line
move t4, ra
jal make_section
xori t6, t5, 4
lw t0, sect_queues(t6)
sw t0, section_ptr

rsp_wait:
// Wait until the RSP is finished rendering
lw t0, 0xA4040010 // SP_STATUS
andi t0, t0, 0x1 // Halt
beqz t0, rsp_wait
nop
xori t6, t5, 0x4

// Update the software-rendered UI
lw a0, DMEM(FRAMEBUFFER)(t6)
Expand All @@ -527,7 +538,10 @@ menu_return:
lbu t1, fps_emulate
addi t0, t0, 1
sb t0, frame_count
lbu t2, skipped_set
addi t1, t1, 1
srl t2, t2, 2
add t1, t1, t2
sb t1, fps_emulate
li t0, 0x80 // Set VI mask
sw t0, 0xA430000C // MI_MASK
Expand Down Expand Up @@ -572,6 +586,13 @@ frame_wait:
jr t4
sw t0, 0x0010(t1) // SP_STATUS

ignore_frame:
// Reset the section pointer and reuse it for the next frame
lw t0, sect_queues(t5)
sw t0, section_ptr
jr t4
nop

.align 5
vram_trans8: // t0: address, t6: return - t1: output
// Perform 8-bit translation on a VRAM address
Expand Down

0 comments on commit bceba0b

Please sign in to comment.