Home /Modules/cpu/SLOpticalDrive.sleela

SLOpticalDrive.sleela

lib/cpu/components/SLOpticalDrive.sleela · 106 line(s) · sleela

<< lib/cpu/components/SLOpticalDrive.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLOpticalDrive — a selectable optical drive for a Sleela
     executor build: CD, DVD, or Blu-ray reader/writer. It models the real spec
     that sets its speed: the medium, the base 1× data rate for that medium, the
     drive's speed multiplier (e.g. 52× CD, 16× DVD), and whether it can write.
     The 1× rate differs per medium (CD 150 KB/s, DVD 1,385 KB/s, BD 4,500 KB/s),
     so a "16×" DVD and a "16×" CD are very different throughputs — this class
     makes that explicit.
   
   Family: cpu.components. Selected via SLComponentCatalog. >>
#sleela 2.5
material;
class SLOpticalDrive {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10517;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-09";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  static final int MEDIUM_CD = 0;
  static final int MEDIUM_DVD = 1;
  < Blu-ray >
  static final int MEDIUM_BD  = 2;

  < Base 1x data rate in KB/s for each medium. >
  static final int BASE_CD_KBS = 150;
  static final int BASE_DVD_KBS = 1385;
  static final int BASE_BD_KBS = 4500;

  String partName;
  int medium;
  < the "nnX" rating >
  int speedMultiplier;
  < 1 if it can burn media >
  int writer;
  < disc capacity (CD 700, DVD 4700, BD 25000, ...) >
  int capacityMiB;

  void configure(String name, int mediumId, int multiplier, boolean canWrite, int discMiB) {
    partName = name; medium = mediumId; speedMultiplier = multiplier;
    writer = canWrite ? 1 : 0; capacityMiB = discMiB;
  }

  int baseRateKBs() {
    if (medium == MEDIUM_CD)  { return BASE_CD_KBS; }
    if (medium == MEDIUM_DVD) { return BASE_DVD_KBS; }
    if (medium == MEDIUM_BD)  { return BASE_BD_KBS; }
    return BASE_CD_KBS;
  }

  < Sustained read rate in KB/s = base × multiplier. >
  int readRateKBs() { return baseRateKBs() * speedMultiplier; }
  int readRateMBs() { return readRateKBs() / 1024; }

  < Time in milliseconds to read `mib` megabytes at the drive's rate. >
  int readTimeMs(int mib) { int r = readRateKBs(); if (r <= 0) { return 0; } return (mib * 1024 * 1000) / r; }

  String name()      { return partName; }
  int speed()        { return speedMultiplier; }
  boolean canWrite() { return writer == 1; }
  int capacity()     { return capacityMiB; }

  String mediumName() {
    if (medium == MEDIUM_CD)  { return "CD"; }
    if (medium == MEDIUM_DVD) { return "DVD"; }
    if (medium == MEDIUM_BD)  { return "Blu-ray"; }
    return "optical";
  }
}