Skip to content

Commit ee6db7d

Browse files
committed
Don't crash when N64's framebuffer exceeds 8MB. Wrap aroudn in that case.
1 parent 73ad38c commit ee6db7d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ri/controller.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "common.h"
1414

1515
#define MAX_RDRAM_SIZE 0x800000U
16+
#define MAX_RDRAM_SIZE_MASK (MAX_RDRAM_SIZE - 1U)
1617

1718
enum rdram_register {
1819
#define X(reg) reg,

vi/controller.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ void vi_cycle(struct vi_controller *vi) {
122122
window->frame_type = 0;
123123

124124
// Copy the frame data into a temporary buffer.
125-
copy_size = sizeof(bus->ri->ram) - (vi->regs[VI_ORIGIN_REG] & 0xFFFFFF);
125+
copy_size = sizeof(bus->ri->ram) - (vi->regs[VI_ORIGIN_REG] & MAX_RDRAM_SIZE_MASK);
126126

127127
if (copy_size > sizeof(vi->window->frame_buffer))
128128
copy_size = sizeof(vi->window->frame_buffer);
129129

130130
memcpy(&bus, vi, sizeof(bus));
131131
memcpy(vi->window->frame_buffer,
132-
bus->ri->ram + (vi->regs[VI_ORIGIN_REG] & 0xFFFFFF),
132+
bus->ri->ram + (vi->regs[VI_ORIGIN_REG] & MAX_RDRAM_SIZE_MASK),
133133
copy_size);
134134

135135
cen64_mutex_unlock(&vi->window->render_mutex);

0 commit comments

Comments
 (0)