added drives

This commit is contained in:
Djeeberjr 2022-03-05 03:01:26 +01:00
parent df77704d1c
commit 6b3f0760ca
2 changed files with 84 additions and 1 deletions

View File

@ -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<String> {
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<String> {
return this.getMountPath();
}
public inline function getAudioTitle(): Null<String> {
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();
}
}

View File

@ -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<Screen> = [];
private var modes: Array<Modem> = [];
private var drives:Array<Drive> = [];
@: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<Drive> {
return this.drives;
}
public function getDrive(addr: String): Null<Drive> {
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));
}
}