Skip to content

Commit

Permalink
Replaced ScripProxy with MediaFileProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jun 7, 2024
1 parent 417a3cc commit 078cb7d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 70 deletions.
2 changes: 2 additions & 0 deletions Emulator/Media/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ Script::isCompatible(std::istream &stream)
return true;
}

/*
void
Script::execute(VirtualC64 &c64)
{
string s((char *)data, size);
try { c64.retroShell.execScript(s); } catch (util::Exception &) { }
}
*/

}
2 changes: 1 addition & 1 deletion Emulator/Media/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Script : public AnyFile {
//

// Executes the script
void execute(VirtualC64 &c64);
// void execute(VirtualC64 &c64);
};

}
9 changes: 9 additions & 0 deletions Emulator/Misc/RetroShell/RetroShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ RetroShell::execScript(const string &contents)
}

void
RetroShell::execScript(const MediaFile &file)
{
if (file.type() != FILETYPE_SCRIPT) throw VC64Error(ERROR_FILE_TYPE_MISMATCH);

string s((char *)file.getData(), file.getSize());
try { execScript(s); } catch (util::Exception &) { }
}

void
RetroShell::abortScript()
{
{ SYNCHRONIZED
Expand Down
1 change: 1 addition & 0 deletions Emulator/Misc/RetroShell/RetroShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class RetroShell : public SubComponent {
void execScript(std::stringstream &ss) throws;
void execScript(const std::ifstream &fs) throws;
void execScript(const string &contents) throws;
void execScript(const class MediaFile &script) throws;
void abortScript();

private:
Expand Down
6 changes: 6 additions & 0 deletions Emulator/VirtualC64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,12 @@ RetroShellAPI::execScript(const string &contents)
retroShell->execScript(contents);
}

void
RetroShellAPI::execScript(const MediaFile &file)
{
retroShell->execScript(file);
}

void
RetroShellAPI::setStream(std::ostream &os)
{
Expand Down
1 change: 1 addition & 0 deletions Emulator/VirtualC64.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ struct RetroShellAPI : API {
void execScript(std::stringstream &ss);
void execScript(const std::ifstream &fs);
void execScript(const string &contents);
void execScript(const MediaFile &file);

/// @}

Expand Down
7 changes: 3 additions & 4 deletions GUI/Layers/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ class Console: Layer {

}

func runScript(script: ScriptProxy) {

// open()
script.execute(emu)
func runScript(script: MediaFileProxy) {

emu.retroShell.executeScript(script)
isDirty = true
}
}
24 changes: 12 additions & 12 deletions GUI/MediaManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class MediaManager {
return try MediaFileProxy.make(with: newUrl, type: .SNAPSHOT)

case .SCRIPT:
return try ScriptProxy.make(with: newUrl)
return try MediaFileProxy.make(with: newUrl, type: .SCRIPT)

case .CRT:
return try MediaFileProxy.make(with: newUrl, type: .CRT)
Expand Down Expand Up @@ -253,7 +253,7 @@ class MediaManager {
}
}

func addMedia(proxy: AnyFileProxy,
func addMedia(proxy: AnyFileProxy, // TODO: Change type to MediaFileProxy
drive: DriveProxy? = nil,
options: [Option] = []) throws {

Expand Down Expand Up @@ -294,15 +294,15 @@ class MediaManager {
drive!.insertMedia(proxy, protected: options.contains(.protect))
}

case .SCRIPT:

debug(.media, "Script")
console.runScript(script: proxy)

default:
break
}

case let proxy as ScriptProxy:

debug(.media, "Script")
console.runScript(script: proxy)

default:
fatalError()
}
Expand Down Expand Up @@ -347,15 +347,15 @@ class MediaManager {
controller.renderer.rotateLeft()
}

case .SCRIPT:

debug(.media, "Script")
console.runScript(script: proxy)

default:
break
}

case let proxy as ScriptProxy:

debug(.media, "Script")
console.runScript(script: proxy)

default:
fatalError()
}
Expand Down
16 changes: 1 addition & 15 deletions Proxy/EmulatorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ using namespace vc64;
@class MyController;
@class RecorderProxy;
@class RetroShellProxy;
@class ScriptProxy;
@class SIDProxy;
@class VICIIProxy;
@class VideoPortProxy;
Expand Down Expand Up @@ -611,6 +610,7 @@ struct GuardInfo {
- (NSString *)getText;
- (void)pressKey:(char)c;
- (void)pressSpecialKey:(RetroShellKey)key;
- (void)executeScript:(MediaFileProxy *)file;

@end

Expand Down Expand Up @@ -688,20 +688,6 @@ struct GuardInfo {
@end


//
// Script
//

@interface ScriptProxy : AnyFileProxy <MakeWithFile, MakeWithBuffer> { }

+ (instancetype)makeWithFile:(NSString *)path exception:(ExceptionWrapper *)ex;
+ (instancetype)makeWithBuffer:(const void *)buf length:(NSInteger)len exception:(ExceptionWrapper *)ex;

- (void)execute:(EmulatorProxy *)proxy;

@end


//
// Folder
//
Expand Down
43 changes: 5 additions & 38 deletions Proxy/EmulatorProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,11 @@ - (void)pressSpecialKey:(RetroShellKey)key
[self shell]->press(key);
}

- (void)executeScript:(MediaFileProxy *)file
{
[self shell]->execScript(*(MediaFile *)file->obj);
}

@end


Expand Down Expand Up @@ -1333,44 +1338,6 @@ - (void)writeToFile:(NSString *)path exception:(ExceptionWrapper *)ex
@end


//
// Script proxy
//

@implementation ScriptProxy

- (Script *)script
{
return (Script *)obj;
}

+ (instancetype)make:(Script *)file
{
return file ? [[self alloc] initWith:file] : nil;
}

+ (instancetype)makeWithFile:(NSString *)path exception:(ExceptionWrapper *)ex
{
try { return [self make: new Script([path fileSystemRepresentation])]; }
catch (VC64Error &error) { [ex save:error]; return nil; }
}

+ (instancetype)makeWithBuffer:(const void *)buf length:(NSInteger)len exception:(ExceptionWrapper *)ex
{
try { return [self make: new Script((u8 *)buf, len)]; }
catch (VC64Error &error) { [ex save:error]; return nil; }
}

- (void)execute:(EmulatorProxy *)proxy
{
VirtualC64 *c64 = (VirtualC64 *)proxy->obj;

[self script]->execute(*c64);
}

@end


//
// FileSystem
//
Expand Down

0 comments on commit 078cb7d

Please sign in to comment.