Train Layout & LayExp Support Notes June 1993, J.Bird The following notes are reference for future use of the LAYOUT.BAS & LAYEXP.BAS programs used for the setup of required data for the Dragon Train Control System. 1. LAYOUT.BAS This program is the tool for setting up & entering all the data required for a layout. It's principal purpose is to design the track schematic on a grid. Use of a mouse is required, so a D64 is essential (or 32 with a 6551 ACIA mapped at $FF04). The standard mouse driver, MOUSE.BIN is used to control the mouse. In addition, an extender program PUTEOR.BIN is used to enable the use of eXclusive OR graphics with the PUT command (extension 'X'). The layout is formed by building it up from standard blocks shown across the top of the screen. There are 15 blocks in total, labelled 1-15. Blocks are placed on the grid and there ID code stored in the MAP array (30*20 - 0-29 & 0-19). In addition to the schematic of the layout, the entire configuration required for the points, sensors, accessories etc. should also be set up. These devices use one of the 3 standard control modules to operate. The control boards are addressed via the 'B' side of the PIA on the train control system, and therefore allow up to a theoretical 256 byte device limit. However, codes above 127 are used for sensors, as the CB2 control line is switched on the PB7 line and devices accomodate more than 1 id. The 3 board types each take up 8 addresses, and therefore up to 16 boards can be connected. The point modules can switch 4 points, using 2 addresses per point. The accessory modules can switch 4 on/off accessories and 2 on/on accessories using 2 or 4 addresses respectively (the main train control software determines the exact addressing). The sensor modules can support up to eight sensor inputs, using 1 address each. As the layout is built up on screen, you will be required to enter the device codes assigned to points, sensors etc. Every time you place a point, you are required to enter some configuration data about the point - it's ID code (the ID code +1 will also be marked as 'in use' to account for the other address required for the point. In addition to the ID code, other data is entered - keyboard code to switch the point & channel associated with the point. The train channel is the number of the controller which the point will connected to - up to 8. Sensors should also be identified on the finished schematic of the layout. These are marked by clicking the right hand button on the section of track a sensor is placed on. When this occurs, sensor configuration information is also required, again comprising the ID number and the train channel. When a track location is marked, the number stored in the MAP grid has 15 added to it. Hence, if a straight type 1 is marked, it becomes 16. Finally, accessories such as lights, signals etc. have the necessary configuration data entered. This is acheived through one of the options on the utils menu. Every device that needs to be switched has a unique id code assigned as before, along with the key code (0-9) which will switch the device on or off (or on/on). Multiple devices can have the same key code. Finally, a text description is required for the device that is being switched. When an ID code is entered, the following code is marked as 'in-use' for on/off devices, and the following 3 codes marked for 'on/on' devices (such as colour light signals). Semaphore signals should be configured as on/off devices, but use one of the outputs from a point module. The configuration data is stored in the device table (array DV of 127 by 8) structured as follows: DV(id,data) data 0 - hi-res X position of device (points & sensors) 1 - hi-res Y position of device (points & sensors) 2 - screen id code number 1-15 (points & sensors) 3 - train channel no. (points & sensors) 4 } 5 - nearest devices, see LAYEXP for usage 6 } 7 - device ID: 1 = sensor 2 = point 3 = on/off accessory 4 = on/on accessory 8 - keycode (points & accessories) 9 - status (active/inactive - sensor or which dir travel - point) Within the LAYOUT program, elements 4-6 are omitted, hence element 7 is referred to as 4, & element 8 as 5. Element 9 is not created at this time. Centre Marking Prior to saving the data, using 'S' from the utils menu, the centre of the layout must be marked for use by the LAYEXP program. The positioning of the centre is critical to the operation of the LAYEXP program. It is NOT absolute centre of the layout schematic, but is relative to the design of the layout. The LAYEXP program is responsible for tracking devices around the layout. In order to determine the correct direction of travel, it references the centre point. For example, in a loop the train will be travelling from right to left at the top, whilst at the bottom it will be travelling left to right. Marking the centre incorrectly will result in the calculation of direction being incorrect. The centre must be marked on a blank square, and X & Y lines eminating from this point must cross only straights or curves. When the centre position is marked, it is saved in the MAP array as device id 22. The layout is saved through the 'S' option which performs the following: Writes the MAP array to a .DAT file Writes the DV array to a .DEV file Writes the accessory description array to a .DES file 2. LAYEXP - Layout Export Utility By running LAYEXP from BASIC or selecting 'X' from the utils menu within LAYOUT.BAS will start the export program. This utility performs the following: * Reads the .DAT & .DEV files * Creates the hi-res screen as used by the main TRAIN prog. * Fills in the missing data for the DV array (elemnts. 4-6) * Writes the hi-res screen, and the DV array as a block of memory to a .BIN file. LAYEXP is responsible for creating the file necessary for the TRAIN package to utilise. It requires only one input - the name of the layout files written by LAYOUT.BAS. It will then proceed to create the hi-res screen & calculate the missing data for the DV array. Within the DV array, 3 elements (4,5,6) are used to identify the nearest device to the one being processed. In the case of a sensor, only 2 of these elements are used. LAYEXP will work along the track, first in one direction, then the other to calculate the nearest device (be it point or sensor). For points, all 3 directions have this operation performed. As processing progresses the results will be displayed on the screen in the form: DIR n, DEVICE id:type where n is the direction being processed (1 to 3), id is the nearest device id found in this direction, and type is the device type - point or sensor. If no device can be found (ie. the track is a dead end, or reaches the edge of the grid) then a warning is displayed. In addition to this mapping process, LAYEXP checks the validity of data within the DV array for all devices: * ensures that the nearest device is a point/sensor * ensures that consecutive bytes are marked 'in-use' appropriately (accessories included) * ensures the centre has been marked If any of these conditions fail to be met, the program is terminated with an error. In order to map the layout, LAYEXP creates a 15 by 4 array (DR) to contain offsets for the block layout components 1- 15. In the case of straights and curves, the elements contain the correct direction in terms of X & Y relatives. For example, in the case of straight type 1: DR(1,0) DR(1,1) DR(1,2) DR(1,3) -1 0 1 0 indicating that in one direction (DR bytes 0 & 1) will results in moving -1 in the X direction, and 0 in the Y direction, whilst in the other direction (DR bytes 2 & 3) will result in moving +1 in the X direction and 0 in the Y direction. For points, the case is different. Because points are only used as starting points (once detected, a point would become the nearest device and no further tracking is required) the 4 byte array contains the directions a point can go in initially. Obviously a point can only go in 3 so one of these elements is always zero. For example, for device type 7 (the first point): DR(1,0) DR(1,1) DR(1,2) DR(1,3) -1 -1 1 0 this indicates that moving in 1 direction (DR elements 0 & 1) you can either go -1 in the X direction OR -1 in the Y direction depending on the point setting. However, in the other direction you can only go 1 in the X direction so element 3 is ignored. The full set of data used can be seen at the end of the LAYEXP program. The selecting of which pair of DR elements to use is set intially to the first 2, then the 2nd. However, these may swop around as the process continues moves about the layout. As previously explained, in a loop whilst the train may start moving off at the top from right to left (using DR variables 0 & 1, moving -1 in the X direction) by the time it reaches the bottom it will need to go left to right (DR variables 2 & 3 now need to be used moving +1 in the X direction). The decision as to when to swop the elements around is based on the positioning of the centre (as previously explained within the LAYOUT notes). Example of centre positioning. The current layout (LOFT.*) is used as an example. Take the inner loop, and trace the point shown on the right hand side vertical. Assuming the direction of travel was from right to left along the top of line, it can be seen that the correct tracking would be to enter this point, through the curve and follow down the siding (as one direction). If the centre were marked BELOW this point problems would occur. When the tracker reaches the curve coming off the point, the correct way to proceed would be down the siding. However, looking at this same curve used within the sidings in the top left hand corner, it can be seen that the correct direction of travel would be to go left and not down. Therefore at the forementioned point, instead of going down the siding, it would in fact go left and hit the point again. Therefore, the centre needs to be positioned ABOVE this point, ensuring that when the curve is processed the direction had been swopped around. When the DV array has been fully processed, it is POKEd into memory in graphics page 5, with all 9 elements accounted for. The hi-res screen & the DV data is then saved as 1 binary file. FUTURE USAGE The LAYEXP program has only been tested on the LOFT.* files, which obviously do not include every possible arrangement of track layout. Should future layouts be designed, this program may need to be revised should problems occur. ----- end of usage notes, JRB June 1993