home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
io Programmo 27
/
IOPROG_27.ISO
/
SOFT
/
S5JAVA.ZIP
/
s52.java
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Java Source
|
1999-02-25
|
35.0 KB
|
1,168 lines
/* S5 simulator based on DOS/TP, WIN/Delphi and LINUX/FreePascal versions
(C) 1999 Peter Sieg
*/
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class s52 extends Applet implements Runnable
{
Thread timer = null;
Image bg_img;
int i_red, i_green, i_blue;
String s_backimg;
long cnt;
String s_mesg = new String("Test...");
protected static final int i_MAX_AW = 101; // 0-100 1-100 Used
protected static final int i_MAX_EAM_BAUSTEIN = 0; // EAM 0.0-7
String sa_operation[] = new String[i_MAX_AW];
String s_operation = new String();
String sa_operand[] = new String[i_MAX_AW];
String s_operand = new String();
String s_line = new String();
int ia_baustein[] = new int[i_MAX_AW];
int ia_bitnr[] = new int[i_MAX_AW];
int ia_t_wert[] = new int[i_MAX_AW];
int ia_c_wert[] = new int[i_MAX_AW];
int i_baustein, i_bitnr, i_t_wert, i_c_wert;
int i_act_aw, i_anz_aw;
int i_hw_simcode; // which hardware to simulate; load with L K N 7!
int i_yy,i_yn,i_yw,i_yd,i_yo,i_yh,i_ym,i_ys;
boolean b_awl_ok, b_running, b_vkl, b_vka, b_vkb, b_vku, b_error;
Checkbox cb_e_00 = new Checkbox("E 0.0");
Checkbox cb_e_01 = new Checkbox("E 0.1");
Checkbox cb_e_02 = new Checkbox("E 0.2");
Checkbox cb_e_03 = new Checkbox("E 0.3");
Checkbox cb_e_04 = new Checkbox("E 0.4");
Checkbox cb_e_05 = new Checkbox("E 0.5");
Checkbox cb_e_06 = new Checkbox("E 0.6");
Checkbox cb_e_07 = new Checkbox("E 0.7");
Checkbox cb_a_00 = new Checkbox("A 0.0");
Checkbox cb_a_01 = new Checkbox("A 0.1");
Checkbox cb_a_02 = new Checkbox("A 0.2");
Checkbox cb_a_03 = new Checkbox("A 0.3");
Checkbox cb_a_04 = new Checkbox("A 0.4");
Checkbox cb_a_05 = new Checkbox("A 0.5");
Checkbox cb_a_06 = new Checkbox("A 0.6");
Checkbox cb_a_07 = new Checkbox("A 0.7");
Checkbox cb_m_00 = new Checkbox("M 0.0");
Checkbox cb_m_01 = new Checkbox("M 0.1");
Checkbox cb_m_02 = new Checkbox("M 0.2");
Checkbox cb_m_03 = new Checkbox("M 0.3");
Checkbox cb_m_04 = new Checkbox("M 0.4");
Checkbox cb_m_05 = new Checkbox("M 0.5");
Checkbox cb_m_06 = new Checkbox("M 0.6");
Checkbox cb_m_07 = new Checkbox("M 0.7");
Label l_counter = new Label("Counter");
Label l_timer = new Label("Timer");
TextField t_c_00 = new TextField("0",8);
TextField t_c_01 = new TextField("0",8);
TextField t_c_02 = new TextField("0",8);
TextField t_t_00 = new TextField("0",8);
TextField t_t_01 = new TextField("0",8);
TextField t_t_02 = new TextField("0",8);
Label l_date_time= new Label("<empty>");
Label l_accu = new Label("Accu:");
TextField t_accu = new TextField("0",8);
Label l_act_aw = new Label("Actual AW:");
Label l_actual_aw= new Label("<empty>");
Checkbox cb_vka = new Checkbox("VKA");
Checkbox cb_vkb = new Checkbox("VKB");
Button b_load_awl = new Button("Load AWL");
Button b_start_stop= new Button("Start/Stop");
Button b_single_step=new Button("Single Step");
TextField t_awl_name=new TextField("my.awl",24);
public void start()
{
if (timer == null)
{
timer = new Thread(this);
timer.start();
}
}
public void stop()
{
timer = null;
}
public void run()
{
while (timer != null)
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e){}
if (b_running == true) single_step();
}
timer = null;
}
// override imageUpdate method for loading control of background image and stopping of progress thread
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
boolean done = ((flags & (ERROR | FRAMEBITS | ALLBITS)) != 0);
repaint (done ? 0 : 100);
return !done;
}
// overide some methods to display author and parameter infos
public String getAppletInfo()
{
return "S5 like plc simulation (c) 1999 Peter Sieg. For Robin and Heike";
}
public String[][] getParameterInfo()
{
String[][] info =
{
{"backimg","Name of image (GIF or JPG) file for background", "Will be loaded as background image"},
{"red","A color value for the red part. Range 0 to 255", "Used to create background color"},
{"green","A color value for the green part. Range 0 to 255", "Used to create background color"},
{"blue","A color value for the blue part. Range 0 to 255", "Used to create background color"}
};
return info;
}
public void init()
{
resize(500,400); // Set window size (width,height)
setLayout(null); // use free layout with x,y,width and height.
// tracker = new MediaTracker(this);
// get background image parameter or use default
s_line = getParameter("backimg");
if (s_line == null) s_backimg = "backgr.jpg";
else s_backimg = s_line;
bg_img = getImage(getCodeBase(),s_backimg);
// tracker.addImage(bg_img,0);
// get RGB parameter or use defaults
s_line = getParameter("red");
if (s_line == null) i_red = 200;
else i_red = Integer.parseInt(s_line);
if ((i_red < 0) || (i_red > 255)) i_red = 200;
s_line = getParameter("green");
if (s_line == null) i_green = 225;
else i_green = Integer.parseInt(s_line);
if ((i_green < 0) || (i_green > 255)) i_green = 200;
s_line = getParameter("blue");
if (s_line == null) i_blue = 200;
else i_blue = Integer.parseInt(s_line);
if ((i_blue < 0) || (i_blue > 255)) i_blue = 200;
Color backcolor = new Color(i_red, i_green, i_blue); // r,g,b
setBackground(backcolor);
setForeground(Color.black);
add(cb_e_00);
cb_e_00.reshape( 1, 1, 46, 28);
cb_e_00.setForeground(Color.green);
add(cb_e_01);
cb_e_01.reshape( 1, 31, 46, 28);
cb_e_01.setForeground(Color.green);
add(cb_e_02);
cb_e_02.reshape( 1, 61, 46, 28);
cb_e_02.setForeground(Color.green);
add(cb_e_03);
cb_e_03.reshape( 1, 91, 46, 28);
cb_e_03.setForeground(Color.green);
add(cb_e_04);
cb_e_04.reshape( 1, 121, 46, 28);
cb_e_04.setForeground(Color.green);
add(cb_e_05);
cb_e_05.reshape( 1, 151, 46, 28);
cb_e_05.setForeground(Color.green);
add(cb_e_06);
cb_e_06.reshape( 1, 181, 46, 28);
cb_e_06.setForeground(Color.green);
add(cb_e_07);
cb_e_07.reshape( 1, 211, 46, 28);
cb_e_07.setForeground(Color.green);
add(cb_a_00);
cb_a_00.reshape( 51, 1, 46, 28);
cb_a_00.setForeground(Color.red);
add(cb_a_01);
cb_a_01.reshape( 51, 31, 46, 28);
cb_a_01.setForeground(Color.red);
add(cb_a_02);
cb_a_02.reshape( 51, 61, 46, 28);
cb_a_02.setForeground(Color.red);
add(cb_a_03);
cb_a_03.reshape( 51, 91, 46, 28);
cb_a_03.setForeground(Color.red);
add(cb_a_04);
cb_a_04.reshape( 51, 121, 46, 28);
cb_a_04.setForeground(Color.red);
add(cb_a_05);
cb_a_05.reshape( 51, 151, 46, 28);
cb_a_05.setForeground(Color.red);
add(cb_a_06);
cb_a_06.reshape( 51, 181, 46, 28);
cb_a_06.setForeground(Color.red);
add(cb_a_07);
cb_a_07.reshape( 51, 211, 46, 28);
cb_a_07.setForeground(Color.red);
add(cb_m_00);
cb_m_00.reshape( 101, 1, 46, 28);
cb_m_00.setForeground(Color.blue);
add(cb_m_01);
cb_m_01.reshape( 101, 31, 46, 28);
cb_m_01.setForeground(Color.blue);
add(cb_m_02);
cb_m_02.reshape( 101, 61, 46, 28);
cb_m_02.setForeground(Color.blue);
add(cb_m_03);
cb_m_03.reshape( 101, 91, 46, 28);
cb_m_03.setForeground(Color.blue);
add(cb_m_04);
cb_m_04.reshape( 101, 121, 46, 28);
cb_m_04.setForeground(Color.blue);
add(cb_m_05);
cb_m_05.reshape( 101, 151, 46, 28);
cb_m_05.setForeground(Color.blue);
add(cb_m_06);
cb_m_06.reshape( 101, 181, 46, 28);
cb_m_06.setForeground(Color.blue);
add(cb_m_07);
cb_m_07.reshape( 101, 211, 46, 28);
cb_m_07.setForeground(Color.blue);
add(l_counter);
l_counter.reshape( 201, 1, 80, 28);
l_counter.setBackground(Color.magenta);
add(t_c_00);
t_c_00.reshape( 201, 31, 80, 28);
add(t_c_01);
t_c_01.reshape( 201, 61, 80, 28);
add(t_c_02);
t_c_02.reshape( 201, 91, 80, 28);
add(l_timer);
l_timer.reshape( 201, 121, 80, 28);
l_timer.setBackground(Color.cyan);
add(t_t_00);
t_t_00.reshape( 201, 151, 80, 28);
add(t_t_01);
t_t_01.reshape( 201, 181, 80, 28);
add(t_t_02);
t_t_02.reshape( 201, 211, 80, 28);
add(l_date_time);
l_date_time.reshape( 1, 241, 96, 28);
add(l_accu);
l_accu.reshape( 1, 271, 80, 28);
add(t_accu);
t_accu.reshape( 101, 271, 80, 28);
add(l_act_aw);
l_act_aw.reshape( 1, 301, 80, 28);
add(l_actual_aw);
l_actual_aw.reshape(101,301, 80, 28);
l_actual_aw.setForeground(Color.yellow);
add(cb_vka);
cb_vka.reshape( 201, 301, 40, 28);
cb_vka.setForeground(Color.yellow);
add(cb_vkb);
cb_vkb.reshape( 251, 301, 40, 28);
cb_vkb.setForeground(Color.red);
add(b_load_awl);
b_load_awl.reshape( 1, 341, 80, 20);
b_load_awl.setForeground(Color.red);
add(b_start_stop);
b_start_stop.reshape( 101, 341, 80, 20);
b_start_stop.setForeground(Color.red);
add(b_single_step);
b_single_step.reshape(201, 341, 80, 20);
b_single_step.setForeground(Color.red);
add(t_awl_name);
t_awl_name.reshape ( 1, 370,280, 28);
cnt = 0;
i_hw_simcode = 0;
}
public void debug(String s, long i)
{
s_mesg = s;
cnt = i;
repaint();
}
public void load_awl()
{
// this will load a awl file from file system line=aw by line,
// checks the syntax of each line and stores the awl in the
// appropiate variables. If an error occurs, the function will
// abort and initialize the variables to zero (i_anz_aw=0)
debug("Load...",0-cnt);
/* DUMMY LOAD IS HERE
// UNA0.0
sa_operation[1] = "UN";
sa_operand[1] = "A";
ia_baustein[1] = 0;
ia_bitnr[1] = 0;
// =A0.0
sa_operation[2] = "=";
sa_operand[2] = "A";
ia_baustein[2] = 0;
ia_bitnr[2] = 0;
// BE
sa_operation[3] = "BE";
sa_operand[3] = " ";
ia_baustein[3] = 0;
ia_bitnr[3] = 0;
i_act_aw = 1; // start with first aw
i_anz_aw = 3; // total aw, should point to "BE"*
b_awl_ok = true; // overall everything ok to process awl
b_vkl = true; // up to last aw state init with true
b_vku = true; // allow for single and (U) to be true
*/
// real loading, parsing and checking of a awl file starts here
b_error = true; // assume error in file
debug("Before try...",0);
try
{
debug("Inside try...",0);
String s_line; // line from file
String s_token; // token from line
int i_line_nr;
debug("Before f_is...",0);
URL f_is = null;
DataInputStream d_is = null;
// f_is = new URL(getCodeBase(), "my.awl");
f_is = new URL(getCodeBase(), t_awl_name.getText());
debug("Before d_is...",0);
d_is = new DataInputStream(f_is.openStream());
i_line_nr= 0;
i_anz_aw = 0;
debug("Before while...",0);
while ((s_line = d_is.readLine()) != null)
{
i_line_nr++;
debug(s_line,1000+i_line_nr);
// now we have a line from the file. first parse it
// into operation, operand, baustein and bitnr
// make uppercase anyway
s_line = s_line.toUpperCase();
// remove leading and trailing white space chars
s_line = s_line.trim();
StringTokenizer st = new StringTokenizer(s_line," ");
if (st.countTokens() == 4)
{
// if all ok store inside awl arrays. increase i_anz_awl
i_anz_aw++;
s_token = st.nextToken(); // operation
sa_operation[i_anz_aw] = s_token;
s_token = st.nextToken(); // operand
sa_operand[i_anz_aw] = s_token;
s_token = st.nextToken(); // baustein
ia_baustein[i_anz_aw] = Integer.valueOf(s_token).intValue();
s_token = st.nextToken(); // bitnr
ia_bitnr[i_anz_aw] = Integer.valueOf(s_token).intValue();
}
else
{
if (s_line.equals("BE"))
{
i_anz_aw++;
sa_operation[i_anz_aw] = "BE";
sa_operand[i_anz_aw] = "";
ia_baustein[i_anz_aw] = 0;
ia_bitnr[i_anz_aw] = 0;
b_error = false;
}
else b_error = true;
}
}
debug("EOF...",0);
d_is.close();
}
catch (IOException e)
{
b_error= true;
debug("IOError...",-1l);
}
i_act_aw = 1; // start with 1 anyway
if (b_error)
{
b_awl_ok = false; // overall everthing *not* ok to process awl
b_vkl = false; // up to last aw state init with false
// debug("b_error is true",0);
}
else
{
b_awl_ok = true; // overall everthing ok to process awl
b_vkl = true; // up to last aw state init with true
// debug("b_error is false",0);
// init e,a,m to false
cb_e_00.setState(false);
cb_e_01.setState(false);
cb_e_02.setState(false);
cb_e_03.setState(false);
cb_e_04.setState(false);
cb_e_05.setState(false);
cb_e_06.setState(false);
cb_e_07.setState(false);
cb_a_00.setState(false);
cb_a_01.setState(false);
cb_a_02.setState(false);
cb_a_03.setState(false);
cb_a_04.setState(false);
cb_a_05.setState(false);
cb_a_06.setState(false);
cb_a_07.setState(false);
cb_m_00.setState(false);
cb_m_01.setState(false);
cb_m_02.setState(false);
cb_m_03.setState(false);
cb_m_04.setState(false);
cb_m_05.setState(false);
cb_m_06.setState(false);
cb_m_07.setState(false);
// init timer and counter to 0
t_t_00.setText("0");
t_t_01.setText("0");
t_t_02.setText("0");
t_c_00.setText("0");
t_c_01.setText("0");
t_c_02.setText("0");
}
}
public void start_stop()
{
cnt--;
if (b_running)
{
b_running = false;
debug("Stop...",cnt);
}
else
{
b_running = true;
debug("Start...",cnt);
}
}
public void update_date_time()
{
Date now = new Date(); // get actual date and time; put in now
i_yy = now.getYear() + 1900; // number starting with 1900
i_yn = now.getMonth() + 1; // zero based +1 to result in 1-12
i_yd = now.getDate(); // day of month
i_yo = now.getDay(); // Sun=0,Sat=6
i_yh = now.getHours();
i_ym = now.getMinutes();
i_ys = now.getSeconds();
i_yw = (((i_yn-1)*30+i_yd)/7)+1; // simple substitution
// show date and time in label l_date_time
l_date_time.setText(now.toLocaleString());
}
public void do_one_aw(int i)
{
String s_xoperation = new String();
String s_xoperand = new String();
int i_xbaustein, i_xbitnr, i_n;
s_xoperation = sa_operation[i];
s_xoperand = sa_operand[i];
i_xbaustein = ia_baustein[i];
i_xbitnr = ia_bitnr[i];
// b_vka holts the individual state of the operand of the actual aw
// if b_vkl (last b_vkb) and b_vka are true then the total score b_vkb is true
if (s_xoperand.equals("E"))
{
switch (i_xbitnr)
{
case 0: b_vka = cb_e_00.getState(); break;
case 1: b_vka = cb_e_01.getState(); break;
case 2: b_vka = cb_e_02.getState(); break;
case 3: b_vka = cb_e_03.getState(); break;
case 4: b_vka = cb_e_04.getState(); break;
case 5: b_vka = cb_e_05.getState(); break;
case 6: b_vka = cb_e_06.getState(); break;
case 7: b_vka = cb_e_07.getState(); break;
}
}
if (s_xoperand.equals("A"))
{
switch (i_xbitnr)
{
case 0: b_vka = cb_a_00.getState(); break;
case 1: b_vka = cb_a_01.getState(); break;
case 2: b_vka = cb_a_02.getState(); break;
case 3: b_vka = cb_a_03.getState(); break;
case 4: b_vka = cb_a_04.getState(); break;
case 5: b_vka = cb_a_05.getState(); break;
case 6: b_vka = cb_a_06.getState(); break;
case 7: b_vka = cb_a_07.getState(); break;
}
}
if (s_xoperand.equals("M"))
{
switch (i_xbitnr)
{
case 0: b_vka = cb_m_00.getState(); break;
case 1: b_vka = cb_m_01.getState(); break;
case 2: b_vka = cb_m_02.getState(); break;
case 3: b_vka = cb_m_03.getState(); break;
case 4: b_vka = cb_m_04.getState(); break;
case 5: b_vka = cb_m_05.getState(); break;
case 6: b_vka = cb_m_06.getState(); break;
case 7: b_vka = cb_m_07.getState(); break;
}
}
// now the Y? operands are handled to update b_vka
if (s_xoperand.equals("YY")) if (i_yy > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YN")) if (i_yn > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YW")) if (i_yw > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YD")) if (i_yd > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YO")) if (i_yo > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YH")) if (i_yh > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YM")) if (i_ym > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("YS")) if (i_ys > i_xbaustein) b_vka = true;
else b_vka = false;
if (s_xoperand.equals("T")) // b_vka = (t_t_nn == 0)
{
if (i_xbitnr == 0)
{
if (0 == Integer.valueOf(t_t_00.getText()).intValue()) b_vka = true;
else b_vka = false;
}
if (i_xbitnr == 1)
{
if (0 == Integer.valueOf(t_t_01.getText()).intValue()) b_vka = true;
else b_vka = false;
}
if (i_xbitnr == 2)
{
if (0 == Integer.valueOf(t_t_02.getText()).intValue()) b_vka = true;
else b_vka = false;
}
}
if (s_xoperand.equals("Z")) // b_vka = (t_c_nn == 0)
{
if (i_xbitnr == 0)
{
if (0 == Integer.valueOf(t_c_00.getText()).intValue()) b_vka = true;
else b_vka = false;
}
if (i_xbitnr == 1)
{
if (0 == Integer.valueOf(t_c_01.getText()).intValue()) b_vka = true;
else b_vka = false;
}
if (i_xbitnr == 2)
{
if (0 == Integer.valueOf(t_c_02.getText()).intValue()) b_vka = true;
else b_vka = false;
}
}
// b_vka holts the individual state of the operand of the actual aw
// if b_vkl (last b_vkb) and b_vka are true then the total score b_vkb is true
if (s_xoperation.equals("U"))
{
cnt += 10;
if (!b_vku) b_vkl = true;
if ((b_vka == true) && (b_vkl == true)) b_vkb = true;
else b_vkb = false;
}
if (s_xoperation.equals("UN"))
{
cnt += 10;
if (!b_vku) b_vkl = true;
if ((b_vka == false) && (b_vkl == true)) b_vkb = true;
else b_vkb = false;
}
if (s_xoperation.equals("O"))
{
cnt += 10;
if ((b_vka == true) || (b_vkl == true)) b_vkb = true;
else b_vkb = false;
}
if (s_xoperation.equals("ON"))
{
cnt += 10;
if ((b_vka == false) || (b_vkl == true)) b_vkb = true;
else b_vkb = false;
}
if ((s_xoperation.equals("L")) && (b_vkl))
{
if (s_xoperand.equals("K")) // load value (baustein) into accu
{
if (i_xbitnr < 7) t_accu.setText(String.valueOf(i_xbaustein));
else
{
i_hw_simcode = i_xbaustein; // which hardware to simulate
}
}
}
if ((s_xoperation.equals("S")) && (b_vkl)) // set t_t/c_nn to accu; if b_vkl == true set EAM to true
{
if (s_xoperand.equals("T")) // timer
{
if (i_xbitnr == 0)
{
t_t_00.setText(t_accu.getText());
}
if (i_xbitnr == 1)
{
t_t_01.setText(t_accu.getText());
}
if (i_xbitnr == 2)
{
t_t_02.setText(t_accu.getText());
}
}
if (s_xoperand.equals("Z")) // counter
{
if (i_xbitnr == 0)
{
t_c_00.setText(t_accu.getText());
}
if (i_xbitnr == 1)
{
t_c_01.setText(t_accu.getText());
}
if (i_xbitnr == 2)
{
t_c_02.setText(t_accu.getText());
}
}
if (s_xoperand.equals("E"))
{
switch (i_xbitnr)
{
case 0: cb_e_00.setState(true); break;
case 1: cb_e_01.setState(true); break;
case 2: cb_e_02.setState(true); break;
case 3: cb_e_03.setState(true); break;
case 4: cb_e_04.setState(true); break;
case 5: cb_e_05.setState(true); break;
case 6: cb_e_06.setState(true); break;
case 7: cb_e_07.setState(true); break;
}
}
if (s_xoperand.equals("A"))
{
switch (i_xbitnr)
{
case 0: cb_a_00.setState(true); break;
case 1: cb_a_01.setState(true); break;
case 2: cb_a_02.setState(true); break;
case 3: cb_a_03.setState(true); break;
case 4: cb_a_04.setState(true); break;
case 5: cb_a_05.setState(true); break;
case 6: cb_a_06.setState(true); break;
case 7: cb_a_07.setState(true); break;
}
}
if (s_xoperand.equals("M"))
{
switch (i_xbitnr)
{
case 0: cb_m_00.setState(true); break;
case 1: cb_m_01.setState(true); break;
case 2: cb_m_02.setState(true); break;
case 3: cb_m_03.setState(true); break;
case 4: cb_m_04.setState(true); break;
case 5: cb_m_05.setState(true); break;
case 6: cb_m_06.setState(true); break;
case 7: cb_m_07.setState(true); break;
}
}
}
if ((s_xoperation.equals("R")) && (b_vkl)) // set t_t/c_nn to 0; if b_vkl == true set EAM to false
{
if (s_xoperand.equals("T")) // timer
{
if (i_xbitnr == 0)
{
t_t_00.setText("0");
}
if (i_xbitnr == 1)
{
t_t_01.setText("0");
}
if (i_xbitnr == 2)
{
t_t_02.setText("0");
}
}
if (s_xoperand.equals("Z")) // counter
{
if (i_xbitnr == 0)
{
t_c_00.setText("0");
}
if (i_xbitnr == 1)
{
t_c_01.setText("0");
}
if (i_xbitnr == 2)
{
t_c_02.setText("0");
}
}
if (s_xoperand.equals("E"))
{
switch (i_xbitnr)
{
case 0: cb_e_00.setState(false); break;
case 1: cb_e_01.setState(false); break;
case 2: cb_e_02.setState(false); break;
case 3: cb_e_03.setState(false); break;
case 4: cb_e_04.setState(false); break;
case 5: cb_e_05.setState(false); break;
case 6: cb_e_06.setState(false); break;
case 7: cb_e_07.setState(false); break;
}
}
if (s_xoperand.equals("A"))
{
switch (i_xbitnr)
{
case 0: cb_a_00.setState(false); break;
case 1: cb_a_01.setState(false); break;
case 2: cb_a_02.setState(false); break;
case 3: cb_a_03.setState(false); break;
case 4: cb_a_04.setState(false); break;
case 5: cb_a_05.setState(false); break;
case 6: cb_a_06.setState(false); break;
case 7: cb_a_07.setState(false); break;
}
}
if (s_xoperand.equals("M"))
{
switch (i_xbitnr)
{
case 0: cb_m_00.setState(false); break;
case 1: cb_m_01.setState(false); break;
case 2: cb_m_02.setState(false); break;
case 3: cb_m_03.setState(false); break;
case 4: cb_m_04.setState(false); break;
case 5: cb_m_05.setState(false); break;
case 6: cb_m_06.setState(false); break;
case 7: cb_m_07.setState(false); break;
}
}
}
if ((s_xoperation.equals("Z")) && (b_vkl)) // inc/dec t_c_nn R=-1/V=+1
{
if (s_xoperand.equals("V")) // increment t_c_nn +1
{
if (i_xbitnr == 0)
{
i_n = Integer.valueOf(t_c_00.getText()).intValue();
i_n++;
t_c_00.setText(String.valueOf(i_n));
}
if (i_xbitnr == 1)
{
i_n = Integer.valueOf(t_c_01.getText()).intValue();
i_n++;
t_c_01.setText(String.valueOf(i_n));
}
if (i_xbitnr == 2)
{
i_n = Integer.valueOf(t_c_02.getText()).intValue();
i_n++;
t_c_02.setText(String.valueOf(i_n));
}
}
if (s_xoperand.equals("R")) // decrement t_c_nn -1
{
if (i_xbitnr == 0)
{
i_n = Integer.valueOf(t_c_00.getText()).intValue();
if (i_n > 0) i_n--;
t_c_00.setText(String.valueOf(i_n));
}
if (i_xbitnr == 1)
{
i_n = Integer.valueOf(t_c_01.getText()).intValue();
if (i_n > 0) i_n--;
t_c_01.setText(String.valueOf(i_n));
}
if (i_xbitnr == 2)
{
i_n = Integer.valueOf(t_c_02.getText()).intValue();
if (i_n > 0) i_n--;
t_c_02.setText(String.valueOf(i_n));
}
}
}
if (s_xoperation.equals("="))
{
cnt += 10;
if (s_xoperand.equals("E"))
{
switch (i_xbitnr)
{
case 0: cb_e_00.setState(b_vkl); break;
case 1: cb_e_01.setState(b_vkl); break;
case 2: cb_e_02.setState(b_vkl); break;
case 3: cb_e_03.setState(b_vkl); break;
case 4: cb_e_04.setState(b_vkl); break;
case 5: cb_e_05.setState(b_vkl); break;
case 6: cb_e_06.setState(b_vkl); break;
case 7: cb_e_07.setState(b_vkl); break;
}
}
if (s_xoperand.equals("A"))
{
switch (i_xbitnr)
{
case 0: cb_a_00.setState(b_vkl); break;
case 1: cb_a_01.setState(b_vkl); break;
case 2: cb_a_02.setState(b_vkl); break;
case 3: cb_a_03.setState(b_vkl); break;
case 4: cb_a_04.setState(b_vkl); break;
case 5: cb_a_05.setState(b_vkl); break;
case 6: cb_a_06.setState(b_vkl); break;
case 7: cb_a_07.setState(b_vkl); break;
}
}
if (s_xoperand.equals("M"))
{
switch (i_xbitnr)
{
case 0: cb_m_00.setState(b_vkl); break;
case 1: cb_m_01.setState(b_vkl); break;
case 2: cb_m_02.setState(b_vkl); break;
case 3: cb_m_03.setState(b_vkl); break;
case 4: cb_m_04.setState(b_vkl); break;
case 5: cb_m_05.setState(b_vkl); break;
case 6: cb_m_06.setState(b_vkl); break;
case 7: cb_m_07.setState(b_vkl); break;
}
}
}
if (s_xoperation.equals("BE"))
{
cnt += 10;
b_vkl = true;
}
b_vkl = b_vkb; // save last vkb
b_vku = false;
if (s_xoperation.equals("U")) b_vku = true;
if (s_xoperation.equals("UN")) b_vku= true;
}
public void single_step()
{
int i_n;
cnt++;
debug("Step...",cnt);
if (b_awl_ok == true)
{
// show aw in applet
l_actual_aw.setText(sa_operation[i_act_aw]+sa_operand[i_act_aw]
+String.valueOf(ia_baustein[i_act_aw])+"."+String.valueOf(ia_bitnr[i_act_aw]));
do_one_aw(i_act_aw);
// show b_vka and b_vkb state
cb_vka.setState(b_vka);
cb_vkb.setState(b_vkb);
if (i_act_aw < i_anz_aw)
{
i_act_aw++;
}
else
{
i_act_aw = 1;
// update date and time values
update_date_time();
// update t_t_00-02 as pseudo timer
i_n = Integer.valueOf(t_t_00.getText()).intValue();
if (i_n > 0) i_n--;
t_t_00.setText(String.valueOf(i_n));
i_n = Integer.valueOf(t_t_01.getText()).intValue();
if (i_n > 0) i_n--;
t_t_01.setText(String.valueOf(i_n));
i_n = Integer.valueOf(t_t_02.getText()).intValue();
if (i_n > 0) i_n--;
t_t_02.setText(String.valueOf(i_n));
}
}
}
public boolean action(Event evt, Object arg)
{
if (evt.target == b_start_stop)
{
start_stop();
return true; // yes, this event was handled.
}
if (evt.target == b_single_step)
{
single_step();
return true; // yes, this event was handled.
}
if (evt.target == b_load_awl)
{
load_awl();
return true; // yes, this event was handled.
}
return false; // other events should be handled elsewhere.
}
public void pre_paint()
{
Graphics g = getGraphics();
// paint hardware simulation area
// width=196 starting at 302; height=296 starting at 2
g.drawRect(301, 1,197,298);
switch (i_hw_simcode)
{
case 0:
// *************************************************
// start individual hardware simulation routine here
// 1.) first show a_00-a_02 with traffic light
// Color brown = new Color(150, 75, 0); // r,g,b = pcb board brown
// g.setColor(brown);
// g.setColor(Color.gray);
// g.fillRect(310, 10,180,280);
g.setColor(Color.black);
g.fillRect(311, 11, 20, 58);
g.setColor(Color.black);
g.fillRect(311, 70, 40, 40);
// clear round area
g.setColor(Color.white);
g.fillOval(313, 73, 34, 34);
g.setColor(Color.black);
g.fillRect(311,115, 50, 20);
g.fillRect(311,140, 50, 20);
g.setColor(Color.white);
g.fillRect(313,118, 44, 14);
g.fillRect(313,143, 44, 14);
g.setColor(Color.black);
// con lines first relais
g.drawLine(311,128,325,128);
g.drawLine(345,128,360,128);
// con lines second relais
g.drawLine(311,153,325,153);
g.drawLine(345,153,360,153);
break;
// *************************************************
case 1:
// g.setColor(Color.yellow);
// g.setColor(Color.gray);
// g.fillRect(310, 10,180,280);
// paint a 'transport' belt
g.setColor(Color.black);
g.fillRect(320,200,160, 10);
g.fillOval(322,210, 8, 8);
g.fillOval(396,210, 8, 8);
g.fillOval(470,210, 8, 8);
// draw filling nozzle above middle beaker position
g.fillRect(394,110, 10, 30);
g.fillRect(390,125, 18, 10);
// e_03 to show beaker is full
g.fillOval(380,160, 8, 8);
break;
default:
break;
}
// restore color
g.setColor(Color.black);
}
public void upd_paint()
{
Graphics g = getGraphics();
// paint hardware simulation area
// width=196 starting at 302; height=296 starting at 2
switch (i_hw_simcode)
{
case 0:
// *************************************************
// start individual hardware simulation routine here
// 1.) first show a_00-a_02 with traffic light
// a_00 = green
if (cb_a_00.getState()) g.setColor(Color.green);
else g.setColor(Color.black);
g.fillOval(313, 13, 14, 14);
// a_01 = yellow
if (cb_a_01.getState()) g.setColor(Color.yellow);
else g.setColor(Color.black);
g.fillOval(313, 33, 14, 14);
// a_02 = red
if (cb_a_02.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(313, 53, 14, 14);
// restore color
g.setColor(Color.black);
// 2.) show a_03 with spinning ventilator
if (cb_a_03.getState()) g.setColor(Color.blue);
else g.setColor(Color.white);
// draw + middle x=330;y=90
g.fillRect(325, 75, 10, 30);
g.fillRect(315, 85, 30, 10);
// restore color
g.setColor(Color.black);
// 3.) show a_04+a_05 with relais
if (cb_a_04.getState()) g.setColor(Color.orange);
else g.setColor(Color.white);
g.fillRect(325,120, 20, 8);
if (cb_a_05.getState()) g.setColor(Color.magenta);
else g.setColor(Color.white);
g.fillRect(325,145, 20, 8);
break;
// *************************************************
case 1:
// now show status of e_00-e_03 with red light if true, black if false
if (cb_e_00.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(322,210, 8, 8);
if (cb_e_01.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(396,210, 8, 8);
if (cb_e_02.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(470,210, 8, 8);
if (cb_e_03.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(380,160, 8, 8);
// show beaker at pos e_00-e_02 if true
if (cb_e_00.getState())
{
g.setColor(Color.yellow);
g.fillRect(320,160, 19, 39);
}
else // clear beaker position
{
g.setColor(Color.black);
g.drawRect(320,160, 18, 38);
}
if (cb_e_01.getState())
{
g.setColor(Color.yellow);
g.fillRect(390,160, 19, 39);
}
else // clear beaker position
{
g.setColor(Color.black);
g.drawRect(390,160, 18, 38);
}
if (cb_e_02.getState())
{
g.setColor(Color.yellow);
g.fillRect(460,160, 19, 39);
}
else // clear beaker position
{
g.setColor(Color.black);
g.drawRect(460,160, 18, 38);
}
// show transport if a_00 = true with an arrow line
if (cb_a_00.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.drawLine(330,230,460,230);
g.drawLine(440,220,460,230);
g.drawLine(440,240,460,230);
// show filling into beaker if a_03 is true with an arrow line
if (cb_a_03.getState()) g.setColor(Color.red);
else g.setColor(Color.black);
g.drawLine(399,142,399,158);
g.drawLine(393,150,399,158);
g.drawLine(405,150,399,158);
break;
default:
break;
}
// restore color
g.setColor(Color.black);
}
public void update( Graphics g)
{
paint(g);
}
public void paint( Graphics g)
{
// print out the values etc.
// if (tracker.checkAll()) g.drawImage(bg_img,0,0,500,400,this);
g.drawImage(bg_img,0,0,500,400,this);
g.setColor(Color.white);
g.fillRoundRect(302,341, 100, 20,4,2);
g.setColor(Color.black);
g.drawString(s_mesg + cnt, 305, 356);
// paint one time elements of hardware simulation
pre_paint();
// paint updates of hardware simulation area
upd_paint();
}
}