public static ApplesoftProgram fromBinary(List<Byte> binary, int startAddress) {
   ApplesoftProgram program = new ApplesoftProgram();
   int currentAddress = startAddress;
   int pos = 0;
   while (pos < binary.size()) {
     int nextAddress = (binary.get(pos) & 0x0ff) + ((binary.get(pos + 1) & 0x0ff) << 8);
     if (nextAddress == 0) {
       break;
     }
     int length = nextAddress - currentAddress;
     Line l = Line.fromBinary(binary, pos);
     if (l == null) {
       break;
     }
     program.lines.add(l);
     if (l.getLength() != length) {
       System.out.println(
           "Line "
               + l.getNumber()
               + " parsed as "
               + l.getLength()
               + " bytes long, but that leaves "
               + (length - l.getLength())
               + " bytes hidden behind next line");
     }
     pos += length;
     currentAddress = nextAddress;
   }
   return program;
 }
Example #2
0
 /**
  * Calculates and returns the area of the triangle This one uses 1/2 a*b cos(C)
  *
  * @return the area of the triangle
  */
 public double getArea2() {
   Line side1 = new Line(pointA, pointB);
   Line side2 = new Line(pointA, pointC);
   double angleCAB =
       Math.acos(
           ((pointB.getX() - pointA.getX()) * (pointC.getX() - pointA.getX())
                   + (pointB.getY() - pointA.getY()) * (pointC.getY() - pointA.getY()))
               / (side1.getLength() * side2.getLength()));
   double area = 0.5 * side1.getLength() * side2.getLength() * Math.sin(angleCAB);
   return area;
 }
Example #3
0
  public static void main(String args[]) {
    Point p1 = new Point(0, 0);
    Point p2 = new Point(3, 4);
    Line lineA = new Line(p1, p2);
    System.out.println("Line A: " + lineA);
    System.out.println(lineA.getLength());

    Line lineB = new Line(0, 0, 6, 8);
    System.out.println("Line B: " + lineB);
    System.out.println(lineB.getLength());
  }
  public void run() {
    RAM memory = Emulator.computer.memory;
    Emulator.computer.pause();
    int pos = memory.readWordRaw(startingAddressPointer);
    for (Line line : lines) {
      int nextPos = pos + line.getLength() + 1;
      memory.write(pos++, (byte) (nextPos & 0x0ff), false, true);
      memory.write(pos++, (byte) (nextPos >> 8 & 0x0ff), false, true);
      memory.write(pos++, (byte) (line.getNumber() & 0x0ff), false, true);
      memory.write(pos++, (byte) (line.getNumber() >> 8 & 0x0ff), false, true);
      boolean isFirst = true;
      for (Command command : line.getCommands()) {
        if (!isFirst) {
          memory.write(pos++, (byte) ':', false, true);
        }
        isFirst = false;
        for (Command.ByteOrToken part : command.parts) {
          memory.write(pos++, part.getByte(), false, true);
        }
      }
      memory.write(pos++, (byte) 0, false, true);
    }
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);
    memory.write(pos++, (byte) 0, false, true);

    //        Emulator.computer.cpu.setProgramCounter(BASIC_RUN);
    Emulator.computer.resume();
  }
Example #5
0
 /**
  * Calculates and returns the perimeter of the triangle
  *
  * @return the triangle's perimeter
  */
 public double getPerimeter() {
   double perimeter = 0;
   Line[] sides = getSides();
   for (Line l : sides) {
     perimeter += l.getLength();
   }
   return perimeter;
 }
Example #6
0
 public double getArea3() {
   double s = getPerimeter() / 2;
   double product = s;
   for (Line side : getSides()) {
     product *= s - side.getLength();
   }
   return Math.sqrt(product);
 }
Example #7
0
 /**
  * Calculates and returns the area of the triangle This one uses 1/2 b*h
  *
  * @return the area of the triangle
  */
 public double getArea() {
   Line alt = getAltitude();
   Line base = new Line(pointB, pointC);
   double area = 0.5 * alt.getLength() * base.getLength();
   return area;
 }