From 6b3f0760ca36a071db7042f2cc8131ff5cedbdbe Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sat, 5 Mar 2022 03:01:26 +0100 Subject: [PATCH] added drives --- src/kernel/peripherals/Drive.hx | 67 +++++++++++++++++++++++++++ src/kernel/peripherals/Peripherals.hx | 18 ++++++- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/kernel/peripherals/Drive.hx diff --git a/src/kernel/peripherals/Drive.hx b/src/kernel/peripherals/Drive.hx new file mode 100644 index 0000000..79cc7b9 --- /dev/null +++ b/src/kernel/peripherals/Drive.hx @@ -0,0 +1,67 @@ +package kernel.peripherals; + +class Drive implements IPeripheral { + private final addr:String; + private final native:cc.periphs.Disk; + + @:allow(kernel.peripherals) + private function new(native: cc.periphs.Disk,addr: String) { + this.addr = addr; + this.native = native; + } + + public function getAddr():String { + return this.addr; + } + + public inline function isDiskPresent(): Bool { + return this.native.isDiskPresent(); + } + + /** + The label of the disk, or `null` if either no disk is inserted or the disk doesn't have a label. + **/ + public inline function getDiskLabel(): Null { + return this.native.getDiskLabel(); + } + + public inline function clearDiskLabel() { + this.native.setDiskLabel(); + } + + public inline function setDiskLabel(label: String) { + this.native.setDiskLabel(label); + } + + public inline function hasData():Bool { + return this.native.hasData(); + } + + public inline function hasAudio():Bool { + return this.native.hasAudio(); + } + + public inline function getMountPath():Null { + return this.getMountPath(); + } + + public inline function getAudioTitle(): Null { + return this.native.getAudioTitle(); + } + + public inline function playAudio() { + this.native.playAudio(); + } + + public inline function stopAudio() { + this.native.stopAudio(); + } + + public inline function ejectDisk() { + this.native.ejectDisk(); + } + + public inline function getDiskID(): Int { + return this.native.getDiskID(); + } +} diff --git a/src/kernel/peripherals/Peripherals.hx b/src/kernel/peripherals/Peripherals.hx index 7f58884..7289e35 100644 --- a/src/kernel/peripherals/Peripherals.hx +++ b/src/kernel/peripherals/Peripherals.hx @@ -1,6 +1,5 @@ package kernel.peripherals; -import kernel.net.INetworkInterface; import kernel.peripherals.Modem; import kernel.peripherals.Screen; @@ -19,6 +18,7 @@ class Peripheral { private var screens: Array = []; private var modes: Array = []; + private var drives:Array = []; @:allow(kernel.Init) private function new() { @@ -63,4 +63,20 @@ class Peripheral { var allModems = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "modem"); this.modes = allModems.map(s -> return new Modem((cc.Peripheral.wrap(s) : Dynamic), s)); } + + /** + Get all connected drives. + **/ + public function getDrives(): Array { + return this.drives; + } + + public function getDrive(addr: String): Null { + return this.drives.find(item -> item.getAddr() == addr); + } + + private function findDrives() { + var allDrives = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "drive"); + this.drives = allDrives.map(s -> return new Drive((cc.Peripheral.wrap(s) : Dynamic), s)); + } }