// *************************************************************************
// KI21-30 Three-Dimensional Array 								S215 11 0919
// *************************************************************************

#include "s215-header23-f46-NWDT.h"

//=========================================================================
#pragma code

//||||||||||||||||||||||||| BEGINNING OF MAIN PROGRAM ||||||||||||||||||||||
void main (void)
{
unsigned char
	row, column, element, number;			
short
	xarray[2][3][4] =  //2 rows, 3 columns, 4 elements.
		//Row numbers: 0 and 1. Column numbers: 0, 1, and 2. 
		//Element numbers: 0, 1, 2, and 3.	
		{
		{{  0,   1,   2,   3},{ 10,  11,  12,  13}, { 20,  21,  22,  23}},
		{{100, 101, 102, 103},{110, 111, 112, 113}, {120, 121, 122, 123}},
		},
	*x = &xarray[0][0][0];  	//Pointer to first element of xarray 
#define XARRAY x, 2, 3, 4	//xarray parameters (pointer to array; numbers
							// of rows, columns, and elements)

InitPorts();

while (1==1)
{
//||||||||||||||||||||||||||||| PRIMARY LOOP |||||||||||||||||||||||||||||||
/*
Switches 7 and 6 select the row.
Switches 3 and 2 select the column.
Switches 1 and 0 select the element.

|   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
|<==== Row ====>|               |<==== Col ====>|<== Element ==>|   
*/

row = 
column = 
element = 

//If "row" is too large, display "Error" and keep getting numbers from 
//switches 7 and 6 until "row" contains a number that's OK.
while (row > 1) 
{	Error();
	row = 
}

//If "column" is too large, display "Error" and keep getting numbers from 
//switches 3 and 2 until "column" contains a number that's OK.
while (column > 2)
{	

}

//If "element" is too large, display "Error" and keep getting numbers from 
//switches 1 and 0 until "element" contains a number that's OK.
while (element > 3)
{	

}

number = TDArray(row, column, element, XARRAY);
DispFP(number, 0);
//||||||||||||||||||||||||| END OF PRIMARY LOOP ||||||||||||||||||||||||||||		
}
}
//||||||||||||||||||||||||||| END OF MAIN PROGRAM ||||||||||||||||||||||||||

