//
// Cherry.swift
// Cherry
//
// Created by Jarrod Norwell on 20/1/2026.
//
import Foundation
/*
enum GC_Keys
{
Keypad_8 = 0x01,
Keypad_4 = 0x02,
Keypad_5 = 0x03,
Key_Blue = 0x04,
Keypad_7 = 0x05,
Keypad_Hash = 0x06,
Keypad_2 = 0x07,
Key_Purple = 0x08,
Keypad_Asterisk = 0x09,
Keypad_0 = 0x0A,
Keypad_9 = 0x0B,
Keypad_3 = 0x0C,
Keypad_1 = 0x0D,
Keypad_6 = 0x0E,
Key_Up = 0x10,
Key_Right = 0x11,
Key_Down = 0x12,
Key_Left = 0x13,
Key_Left_Button = 0x14,
Key_Right_Button = 0x15
};
enum GC_Controllers
{
Controller_1 = 0,
Controller_2 = 1
};
*/
public enum CVButton : Int32 {
case k_8 = 1,
k_4 = 2,
k_5 = 3,
k_blue = 4,
k_7 = 5,
k_hash = 6,
k_2 = 7,
k_purple = 8,
k_asterisk = 9,
k_0 = 10,
k_9 = 11,
k_3 = 12,
k_1 = 13,
k_6 = 14,
k_up = 16,
k_right = 17,
k_down = 18,
k_left = 19,
k_left_button = 20,
k_right_button = 21
}
public actor Cherry {
private var emulator: CherryEmulator = .shared()
public init() {}
public func insert(_ cartridge: URL) -> Bool {
emulator.insert(cartridge)
}
public func start() {
emulator.start()
}
public func stop() {
emulator.stop()
}
public var isPaused: Bool {
get {
emulator.isPaused()
}
set {
pause(newValue)
}
}
public func pause(_ pause: Bool) {
emulator.pause(pause)
}
public func framebuffer(_ buffer: @escaping (UnsafeMutablePointer<UInt8>) -> Void) {
emulator.fb = buffer
}
public func button(button: CVButton, player: Int, pressed: Bool) {
emulator.button(button.rawValue, player: Int32(player), pressed: pressed)
}
}