package millfork.assembly.mos

import millfork.env.StructType
import millfork.node.FieldDesc

/**
  * @author Karol Stasiak
  */
object AddrMode extends Enumeration {
  val Implied,
  Immediate,
  WordImmediate,
  Relative,
  LongRelative,
  ZeroPage,
  ZeroPageX,
  ZeroPageY,
  Absolute,
  AbsoluteX,
  AbsoluteY,
  LongAbsolute,
  LongAbsoluteX,
  Indirect,
  LongIndirect,
  IndexedX,
  IndexedY,
  IndexedSY,
  IndexedZ,
  Stack,
  LongIndexedY,
  LongIndexedZ,
  AbsoluteIndexedX,
  ZeroPageWithRelative,
  ImmediateWithZeroPage,
  ImmediateWithZeroPageX,
  ImmediateWithAbsolute,
  ImmediateWithAbsoluteX,
  TripleAbsolute,
  Undecided,
  RawByte,
  DoesNotExist = Value


  def addrModeToString(am: AddrMode.Value, argument: String): String = {
    am match {
      case Implied => ""
      case Immediate => "#" + argument
      case WordImmediate => "##" + argument
      case AbsoluteX | ZeroPageX => argument + ", X"
      case AbsoluteY | ZeroPageY => argument + ", Y"
      case IndexedX | AbsoluteIndexedX => "(" + argument + ", X)"
      case Stack => argument + ", S"
      case IndexedY => "(" + argument + "), Y"
      case IndexedSY => "(" + argument + ", S), Y"
      case IndexedZ => "(" + argument + "), Z"
      case Indirect => "(" + argument + ")"
      case LongIndexedY => "[" + argument + "], Y"
      case LongIndexedZ => "[" + argument + "], Z"
      case LongIndirect => "[" + argument + "]"
      case ZeroPage => argument // + "\t;zp"
      case LongAbsolute => "FAR " + argument
      case LongAbsoluteX => "FAR " + argument + ", X"
      case _ => argument;
    }
  }
}
