001package jmri.jmrix.loconet.sdf; 002 003/** 004 * Implement the BRANCH_TO macro from the Digitrax sound definition language 005 * 006 * @author Bob Jacobsen Copyright (C) 2007 007 */ 008public class BranchTo extends SdfMacro { 009 010 public BranchTo(int byte1, int byte2) { 011 this.addr = (byte1 & 0x0F) * 256 + byte2; 012 this.skemebase = 0; // probably not right! 013 this.byte1 = byte1; 014 this.byte2 = byte2; 015 } 016 017 @Override 018 public String name() { 019 return "BRANCH_TO"; // NOI18N 020 } 021 022 @Override 023 public int length() { 024 return 2; 025 } 026 027 int byte1, byte2; 028 029 int addr; 030 int skemebase; 031 032 static public SdfMacro match(SdfBuffer buff) { 033 if ((buff.getAtIndex() & 0xF0) != 0xC0) { 034 return null; 035 } 036 int byte1 = buff.getAtIndexAndInc(); 037 int byte2 = buff.getAtIndexAndInc(); 038 return new BranchTo(byte1, byte2); 039 } 040 041 /** 042 * Store into a buffer. 043 */ 044 @Override 045 public void loadByteArray(SdfBuffer buffer) { 046 // data 047 buffer.setAtIndexAndInc(byte1); 048 buffer.setAtIndexAndInc(byte2); 049 050 // store children 051 super.loadByteArray(buffer); 052 } 053 054 @Override 055 public String toString() { 056 return "Branch\n"; // NOI18N 057 } 058 059 @Override 060 public String oneInstructionString() { 061 return name() + ' ' + addr + "; from base of " + skemebase + '\n'; // NOI18N 062 } 063 064 @Override 065 public String allInstructionString(String indent) { 066 return indent + oneInstructionString(); 067 } 068}