44#include < ultramodern/ultramodern.hpp>
55#include " librecomp/recomp.h"
66#include " librecomp/addresses.hpp"
7+ #include " librecomp/game.hpp"
78
89// TODO move this out into ultramodern code
910
@@ -22,16 +23,31 @@ void save_clear(uint32_t start, uint32_t size, char value);
2223std::array<char , page_size> write_buffer;
2324
2425extern " C" void osFlashInit_recomp (uint8_t * rdram, recomp_context * ctx) {
26+ if (!recomp::flashram_allowed ()) {
27+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
28+ ULTRAMODERN_QUICK_EXIT ();
29+ }
30+
2531 ctx->r2 = recomp::flash_handle;
2632}
2733
2834extern " C" void osFlashReadStatus_recomp (uint8_t * rdram, recomp_context * ctx) {
35+ if (!recomp::flashram_allowed ()) {
36+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
37+ ULTRAMODERN_QUICK_EXIT ();
38+ }
39+
2940 PTR (u8 ) flash_status = ctx->r4 ;
3041
3142 MEM_B (0 , flash_status) = 0 ;
3243}
3344
3445extern " C" void osFlashReadId_recomp (uint8_t * rdram, recomp_context * ctx) {
46+ if (!recomp::flashram_allowed ()) {
47+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
48+ ULTRAMODERN_QUICK_EXIT ();
49+ }
50+
3551 PTR (u32 ) flash_type = ctx->r4 ;
3652 PTR (u32 ) flash_maker = ctx->r5 ;
3753
@@ -41,23 +57,43 @@ extern "C" void osFlashReadId_recomp(uint8_t * rdram, recomp_context * ctx) {
4157}
4258
4359extern " C" void osFlashClearStatus_recomp (uint8_t * rdram, recomp_context * ctx) {
60+ if (!recomp::flashram_allowed ()) {
61+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
62+ ULTRAMODERN_QUICK_EXIT ();
63+ }
4464
65+ // Nothing to do here.
4566}
4667
4768extern " C" void osFlashAllErase_recomp (uint8_t * rdram, recomp_context * ctx) {
69+ if (!recomp::flashram_allowed ()) {
70+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
71+ ULTRAMODERN_QUICK_EXIT ();
72+ }
73+
4874 save_clear (0 , ultramodern::save_size, 0xFF );
4975
5076 ctx->r2 = 0 ;
5177}
5278
5379extern " C" void osFlashAllEraseThrough_recomp (uint8_t * rdram, recomp_context * ctx) {
80+ if (!recomp::flashram_allowed ()) {
81+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
82+ ULTRAMODERN_QUICK_EXIT ();
83+ }
84+
5485 save_clear (0 , ultramodern::save_size, 0xFF );
5586
5687 ctx->r2 = 0 ;
5788}
5889
5990// This function is named sector but really means page.
6091extern " C" void osFlashSectorErase_recomp (uint8_t * rdram, recomp_context * ctx) {
92+ if (!recomp::flashram_allowed ()) {
93+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
94+ ULTRAMODERN_QUICK_EXIT ();
95+ }
96+
6197 uint32_t page_num = (uint32_t )ctx->r4 ;
6298
6399 // Prevent out of bounds erase
@@ -73,6 +109,11 @@ extern "C" void osFlashSectorErase_recomp(uint8_t * rdram, recomp_context * ctx)
73109
74110// Same naming issue as above.
75111extern " C" void osFlashSectorEraseThrough_recomp (uint8_t * rdram, recomp_context * ctx) {
112+ if (!recomp::flashram_allowed ()) {
113+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
114+ ULTRAMODERN_QUICK_EXIT ();
115+ }
116+
76117 uint32_t page_num = (uint32_t )ctx->r4 ;
77118
78119 // Prevent out of bounds erase
@@ -87,11 +128,21 @@ extern "C" void osFlashSectorEraseThrough_recomp(uint8_t * rdram, recomp_context
87128}
88129
89130extern " C" void osFlashCheckEraseEnd_recomp (uint8_t * rdram, recomp_context * ctx) {
131+ if (!recomp::flashram_allowed ()) {
132+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
133+ ULTRAMODERN_QUICK_EXIT ();
134+ }
135+
90136 // All erases are blocking in this implementation, so this should always return OK.
91137 ctx->r2 = 0 ; // FLASH_STATUS_ERASE_OK
92138}
93139
94140extern " C" void osFlashWriteBuffer_recomp (uint8_t * rdram, recomp_context * ctx) {
141+ if (!recomp::flashram_allowed ()) {
142+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
143+ ULTRAMODERN_QUICK_EXIT ();
144+ }
145+
95146 OSIoMesg* mb = TO_PTR (OSIoMesg, ctx->r4 );
96147 int32_t pri = ctx->r5 ;
97148 PTR (void ) dramAddr = ctx->r6 ;
@@ -109,6 +160,11 @@ extern "C" void osFlashWriteBuffer_recomp(uint8_t * rdram, recomp_context * ctx)
109160}
110161
111162extern " C" void osFlashWriteArray_recomp (uint8_t * rdram, recomp_context * ctx) {
163+ if (!recomp::flashram_allowed ()) {
164+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
165+ ULTRAMODERN_QUICK_EXIT ();
166+ }
167+
112168 uint32_t page_num = ctx->r4 ;
113169
114170 // Copy the write buffer into the save file
@@ -118,6 +174,11 @@ extern "C" void osFlashWriteArray_recomp(uint8_t * rdram, recomp_context * ctx)
118174}
119175
120176extern " C" void osFlashReadArray_recomp (uint8_t * rdram, recomp_context * ctx) {
177+ if (!recomp::flashram_allowed ()) {
178+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
179+ ULTRAMODERN_QUICK_EXIT ();
180+ }
181+
121182 OSIoMesg* mb = TO_PTR (OSIoMesg, ctx->r4 );
122183 int32_t pri = ctx->r5 ;
123184 uint32_t page_num = ctx->r6 ;
@@ -138,5 +199,10 @@ extern "C" void osFlashReadArray_recomp(uint8_t * rdram, recomp_context * ctx) {
138199}
139200
140201extern " C" void osFlashChange_recomp (uint8_t * rdram, recomp_context * ctx) {
202+ if (!recomp::flashram_allowed ()) {
203+ ultramodern::error_handling::message_box (" Attempted to use FlashRAM saving with other save type" );
204+ ULTRAMODERN_QUICK_EXIT ();
205+ }
206+
141207 assert (false );
142208}
0 commit comments