Skip to content

Commit 1178398

Browse files
committed
reset, crude autostart
1 parent 0ac0478 commit 1178398

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ imgui.ini
1313
*.ROM
1414
*.cbp
1515
*.layout
16+
*.dll

src/libretro/core.cpp

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ cd /build/src/libretro
2828
make clean
2929
make -j6
3030
31+
current restrictions:
32+
one model
33+
crude autostart
34+
no drive sound
35+
no keyboard remap (positional only)
36+
no joystick remap
37+
no savestate
38+
.ssd/.dsd files only
3139
3240
compilation:
3341
manage static 6502_internal.inl - probably to stay
@@ -36,7 +44,7 @@ make -j6
3644
remove not needed source files + ifdef changes
3745
3846
core options
39-
autoboot on/off
47+
autoboot on/off, combine shift with autostart file name detection
4048
machine model - build in JSON
4149
selectable joypad controls (azop, az/', etc.)
4250
fully customizable joypad controls
@@ -49,7 +57,6 @@ speed / accuracy:
4957
fake interlace - based on register?
5058
5159
functions:
52-
hook up reset
5360
save state
5461
load uef?
5562
LED support
@@ -60,7 +67,6 @@ speed / accuracy:
6067
drive (and relay?) sound
6168
6269
main QoL
63-
load game with disc input (paste?)
6470
intelligent zoom?
6571
keyboard layouts?
6672
@@ -94,6 +100,9 @@ other QoL
94100
#include "b2_libretro_keymap.h"
95101

96102
#define MAX_DISK_COUNT 10
103+
#define PASTE_FRAME 200
104+
size_t frameIndex = 0;
105+
bool autoStartPaste = false;
97106
static struct retro_log_callback logging;
98107
static retro_log_printf_t log_cb;
99108
static retro_environment_t environ_cb;
@@ -151,6 +160,7 @@ BBCMicro *core = (BBCMicro *) 0;
151160
TVOutput tv;
152161
VideoDataUnit vdu;
153162
SoundDataUnit sdu;
163+
static std::shared_ptr<const std::string> COPY_BASIC;
154164

155165
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
156166
{
@@ -237,6 +247,21 @@ static void update_keyboard_cb(bool down, unsigned keycode,
237247
}
238248
}
239249

250+
static void create_core(BBCMicro** newcore)
251+
{
252+
if (*newcore)
253+
{
254+
delete *newcore;
255+
*newcore = (BBCMicro *) 0;
256+
log_cb(RETRO_LOG_DEBUG, "Deleting previous core\n");
257+
}
258+
*newcore = new BBCMicro(&BBC_MICRO_TYPE_B,&DISC_INTERFACE_ACORN_1770,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
259+
(*newcore)->SetOSROM( std::make_shared<std::array<unsigned char, 16384>>(OS12_ROM));
260+
(*newcore)->SetSidewaysROM(15, std::make_shared<std::array<unsigned char, 16384>>(BASIC2_ROM));
261+
(*newcore)->SetSidewaysROM(14, std::make_shared<std::array<unsigned char, 16384>>(acorn_DFS_2_26_rom));
262+
log_cb(RETRO_LOG_DEBUG, "New core created\n");
263+
}
264+
240265
static void check_variables(void)
241266
{
242267
/* struct retro_variable var =
@@ -584,11 +609,12 @@ void retro_init(void)
584609
log_cb(RETRO_LOG_DEBUG, "Creating core...\n");
585610
//core = new BBCMicro(&BBC_MICRO_TYPE_B,&DISC_INTERFACE_ACORN_1770,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
586611
//core = new BBCMicro(&BBC_MICRO_TYPE_B,nullptr,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
587-
core = new BBCMicro(&BBC_MICRO_TYPE_B,&DISC_INTERFACE_ACORN_1770,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
612+
create_core(&core);
613+
/*core = new BBCMicro(&BBC_MICRO_TYPE_B,&DISC_INTERFACE_ACORN_1770,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
588614
589615
core->SetOSROM( std::make_shared<std::array<unsigned char, 16384>>(OS12_ROM));
590616
core->SetSidewaysROM(15, std::make_shared<std::array<unsigned char, 16384>>(BASIC2_ROM));
591-
core->SetSidewaysROM(14, std::make_shared<std::array<unsigned char, 16384>>(acorn_DFS_2_26_rom));
617+
core->SetSidewaysROM(14, std::make_shared<std::array<unsigned char, 16384>>(acorn_DFS_2_26_rom));*/
592618

593619
// tv = TVOutput();
594620

@@ -597,7 +623,6 @@ void retro_init(void)
597623
core->Update(&vdu,&sdu);
598624
updateCount++;
599625

600-
601626
/* core->start();
602627
core->change_resolution(core->currWidth,core->currHeight,environ_cb);*/
603628
}
@@ -690,9 +715,8 @@ void retro_set_video_refresh(retro_video_refresh_t cb)
690715

691716
void retro_reset(void)
692717
{
693-
//printf("retro_reset \n");
694-
695-
/*if(vmThread) vmThread->reset(true);*/
718+
log_cb(RETRO_LOG_INFO, "Machine hard reset\n");
719+
create_core(&core);
696720
}
697721

698722
static void update_input(void)
@@ -769,6 +793,7 @@ static void audio_callback_batch(void)
769793

770794
void retro_run(void)
771795
{
796+
frameIndex++;
772797
// printf("retro_run \n");
773798

774799
bool updated = false;
@@ -1004,6 +1029,15 @@ void retro_run(void)
10041029
/* LED interface */
10051030
/* if (led_state_cb)
10061031
update_led_interface();*/
1032+
if (frameIndex == PASTE_FRAME)
1033+
{
1034+
if (autoStartPaste) {
1035+
core->StartPaste(COPY_BASIC);
1036+
autoStartPaste = false;
1037+
} else {
1038+
core->SetKeyState(BeebKey_Shift,false);
1039+
}
1040+
}
10071041
}
10081042

10091043
bool header_match(const char* buf1, const unsigned char* buf2, size_t length)
@@ -1045,22 +1079,39 @@ bool retro_load_game(const struct retro_game_info *info)
10451079

10461080
if(info != nullptr)
10471081
{
1048-
if (core)
1082+
log_cb(RETRO_LOG_INFO, "Loading game: %s \n",info->path);
1083+
create_core(&core);
1084+
/*if (core)
10491085
{
10501086
delete core;
10511087
core = (BBCMicro *) 0;
10521088
}
1053-
log_cb(RETRO_LOG_INFO, "Loading game: %s \n",info->path);
10541089
10551090
core = new BBCMicro(&BBC_MICRO_TYPE_B,&DISC_INTERFACE_ACORN_1770,BBCMicroParasiteType_None,{},nullptr,0,nullptr,{0});
10561091
core->SetOSROM( std::make_shared<std::array<unsigned char, 16384>>(OS12_ROM));
10571092
core->SetSidewaysROM(15, std::make_shared<std::array<unsigned char, 16384>>(BASIC2_ROM));
1058-
core->SetSidewaysROM(14, std::make_shared<std::array<unsigned char, 16384>>(acorn_DFS_2_26_rom));
1093+
core->SetSidewaysROM(14, std::make_shared<std::array<unsigned char, 16384>>(acorn_DFS_2_26_rom));*/
10591094

1060-
core->SetKeyState(BeebKey_Shift,true);
10611095

10621096
std::string path = info->path;
10631097
core->SetDiscImage(0, DirectDiscImage::CreateForFile(path, nullptr));
1098+
1099+
// Autoboot: if there is [SOMETHING] notice in the filename, use it
1100+
// otherwise press Shift and hope for autoboot
1101+
std::string filename(info->path);
1102+
std::string autostartName;
1103+
size_t ridx = filename.rfind('[');
1104+
size_t lidx = filename.rfind(']');
1105+
if(ridx != std::string::npos)
1106+
{
1107+
autostartName = "CHAIN\""+filename.substr(ridx+1,lidx-ridx-1)+"\"\r";
1108+
log_cb(RETRO_LOG_DEBUG, "Autostart name: %s \n",autostartName.c_str());
1109+
COPY_BASIC = std::make_shared<const std::string>(autostartName.c_str());
1110+
autoStartPaste = true;
1111+
}
1112+
else
1113+
core->SetKeyState(BeebKey_Shift,true);
1114+
10641115
}
10651116

10661117
/*

0 commit comments

Comments
 (0)