Train Game Documentation

Instructions

arithmetic_unit

TBI - Toggle bit index

Set: arithmetic_unit

Parameter: Number

Description:

Toggle bit in 'cache' register

Output: Product stored in 'CCH'.

SUB - Subtract

Set: arithmetic_unit

Parameter: Register name or number

Description:

            Subtracts the value in the specified register
            or specified number
            from the 'cache' register.
            Handles overflow/underflow.
        

Output: Difference stored in 'CCH'.

ADD - Add

Set: arithmetic_unit

Parameter: Register name or number

Description:

            Adds the value in the specified register
            or specified number
            to the value in the 'cache' register.
            Handles overflow/underflow.
        

Output: Sum stored in 'CCH'.

SHL - Left shift

Set: arithmetic_unit

Parameter: Number of positions

Description:

            Performs a left bitwise shift on the value
            in the 'cache' register.
            Number of positions to shift is specified
            by the parameter.
            Handles overflow/underflow.
        

Output: Shifted value stored in 'CCH'.

MUL - Multiply

Set: arithmetic_unit

Parameter: Number

Description:

Multiplies the value in the 'cache' register
            by the parameter.

Output: Product stored in 'CCH'.

DIV - Divide

Set: arithmetic_unit

Parameter: Number

Description:

            Divides the value in the 'cache' register
            by the parameter.
            Handles division by zero.
        

Output: Quotient stored in 'CCH'.

GBI - Get bit index

Set: arithmetic_unit

Parameter: Number

Description:

Extract specific bit from 'cache' register
and write it into 'overflow' register. Bits are counted from 0 to 7

0b00000001 in this case bit 0 is 1 and other bits are 0
0b10000000 in this case bit 7 is 1 and other bits are 0

Output: Product stored in 'OFL'.

SHR - Right shift

Set: arithmetic_unit

Parameter: Number of positions

Description:

            Performs a right bitwise shift on the value
            in the 'cache' register.
            Number of positions to shift is specified
            by the parameter.
            Handles overflow/underflow.
        

Output: Shifted value stored in 'CCH'.

train

WTD - Write train data

Set: train

Parameter: direction(2 bits) - empty(2bit) - target speed (4bits)

Description:

            Write train data in order to control it.
        

Output: Nothing

GOT - Get object type

Set: train

Parameter: ID (8 bits) number or register name

Description:

Type table:
0: Nothing
1: Train
2: Station pick
3: Station drop
4: Station fuel
5: Signal Station
6: Signal intersection
7: Signal segment
        

Output: Write number corresponding to the type into 'CCH'

RNX - Read next signal

Set: train

Parameter: direction(2 bits) - empty(2bit) - max distance (4bits)

Description:

            Read signal on a track in specified
direction (High if oposite to the direction of the travel) and
distance (if there is closer signal it will be read first)

If there is intersection before signal instruction will return 0
(Cant determine which one is desired)
        

Output: Reads signal type and data into 'CCH'. 0 if not found

game

IGS - Internal game signal

Set: game

Parameter: number

Description:

            Trigger internal game signal. Mainly made for debuging in game code.
1 - Pause game (Usefull as break point)
        

Output: Nothing

data_unit

NOP - No operation

Set: data_unit

Parameter: Nothing

Description:

            No operation. Does nothing for one tick
        

Output: Nothing

LOD - Load

Set: data_unit

Parameter: Register name or TP1/TP2

Description:

            Loads the value from the specified register or indirectly via TP1/TP2
            into the 'cache' register.
        

Output: Value of register copied to 'CCH'.

SET - Set

Set: data_unit

Parameter: Number or register name

Description:

            Sets the 'cache' register to a specific value
            or to the index of a specified register.
        

Output: 'CCH' register set to value or index.

STR - Store

Set: data_unit

Parameter: Register name or TP1/TP2

Description:

            Stores the value from the 'cache' register
            into the specified register or indirectly via TP1/TP2.
        

Output: Value of 'CCH' copied to register.

logic_unit

JIH - Jump if higher

Set: logic_unit

Parameter: Line number

Description:

            Jumps to the specified program line
            if the value in the 'cache' register
            is higher than the value in the 'overflow' register.
        

Output: Jumps to line if 'CCH' is higher than 'OFL'.

JIE - Jump if equal

Set: logic_unit

Parameter: Line number

Description:

            Jumps to the specified program line if the value
            in the 'cache' register is equal to the value
            in the 'overflow' register.
        

Output: Jumps to line if 'CCH' equals 'OFL'.

JNE - Jump if not equal

Set: logic_unit

Parameter: Line number

Description:

            Jumps to the specified program line if the value
            in the 'cache' register is not equal
            to the value in the 'overflow' register.
        

Output: Jumps to line if 'CCH' not equal to 'OFL'.

JIL - Jump if lower

Set: logic_unit

Parameter: Line number

Description:

            Jumps to the specified program line if the value
            in the 'cache' register
            is lower than the value in the 'overflow' register.
        

Output: Jumps to line if 'CCH' is lower than 'OFL'.

JMP - Jump

Set: logic_unit

Parameter: Line number

Description:

Unconditionally jumps to the specified program line.

Output: Unconditional jump to line.

Registers

train

TD1

Default Value: 0

Description:

            'TD1' (Train Data 1) register contains:
            - Operation mode (1 bit)
            - Empty (1 bit)
            - Direction (2 bits)
            - Fuel (4 bits)
        

TD2

Default Value: 0

Description:

            'TD2' (Train Data 2) register contains:
            - Current speed (4 bits)
            - Target speed (4 bits)
        

TD3

Default Value: 0

Description:

            'TD3' (Train Data 3) register contains:
            - Position X (8 bits)
        

TD4

Default Value: 0

Description:

            'TD4' (Train Data 4) register contains:
            - Position Y (8 bits)
        

TD5

Default Value: 0

Description:

            'TD5' (Train Data 5) register contains:
            - Selected wagon (4 bits, read-only)
            - Amount of wagons (4 bits, read-only)
        

TD6

Default Value: 0

Description:

            'TD6' (Train Data 6) register contains:
            - Wagon full (1 bit)
            - Wagon loading (1 bit)
            - Wagon type (4 bits)
        

TD7

Default Value: 0

Description:

            'TD7' (Train Data 7) register contains:
            - Wagon position X (8 bits)
        

TD8

Default Value: 0

Description:

            'TD8' (Train Data 8) register contains:
            - Wagon position Y (8 bits)
        

special

CCH

Default Value: 0

Description:

            'CCH' (Cache) register is used for temporary storage
and manipulation of data.
        

OFL

Default Value: 0

Description:

'OFL' (Overflow) register stores the overflow or
underflow value from arithmetic operations.
It is used for other operations as well.
For that check Instructions documentation
        

INT

Default Value: 0

Description:

When a INT (Interrupt) signal is received (for example from crossing)
Program will jump to the line specified in this register.
        

IPC

Default Value: 0

Description:

'IPC' (Instruction Pointer Counter) register holds the address of the next
instruction to be executed.
        

LAR

Default Value: 0

Description:

            'LAR' (Local Address Register) holds address that will be used to communicate
            with other devices on the network.
        

RTC

Default Value: 0

Description:

            Real time clock. Value in this register is incremented by 1 every second
        

VR1

Default Value: 0

Description:

'VR1' (Variable 1) register stores an index to access
other registers indirectly through 'TP1'.
        

VR2

Default Value: 0

Description:

'VR2' (Variable 2) register stores an index to access
other registers indirectly through 'TP2'.
        

data

D01

Default Value: 0

Description:

            'D01' to 'D08' registers are general-purpose blocks.
        

D02

Default Value: 0

Description:

            'D01' to 'D08' registers are general-purpose blocks.
        

D03

Default Value: 0

Description:

            'D01' to 'D08' registers are general-purpose blocks.
        

D04

Default Value: 0

Description:

            'D02' to 'D08' registers are general-purpose blocks.
        

D05

Default Value: 0

Description:

            'D01' to 'D08' registers are general-purpose blocks.
        

D06

Default Value: 0

Description:

            'D02' to 'D08' registers are general-purpose blocks.
        

D07

Default Value: 0

Description:

            'D01' to 'D08' registers are general-purpose blocks.
        

D08

Default Value: 0

Description:

            'D02' to 'D08' registers are general-purpose blocks.
        

shared

S01

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S02

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S03

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S04

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S05

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S06

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S07

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

S08

Default Value: 0

Description:

            'S01' to 'S08' registers are shared between all trains.
        

Examples

Data operations

1: // Move and increment value of registers
2: LOD D01 // Load D01 value to CCH
3: ADD 1 // Increment CCH by 1
4: STR D01 // Store CCH value to D01
5: SET 0b11111111 // Set CCH value to 255
6: STR D02 // Store CCH value to D02
7: JMP 1 // Jump back to line 1 and do it again

Train runs at speed for 5 seconds and then stops

1: // Train runs at speed for 5 seconds and then stops
2: SET 0 // Set Cache(CCH) register to 0
3: STR RTC // Store Cache value to RTC aka reset it
4: SET 5 // Set Cache to 5
5: STR OFL // Store value from cache to OFL (So we can use it to compare later)
6: WTD 4 // Set train speed to 4
7: LOD RTC // Load value from RTC to CCH (So we can use it to compare later)
8: JNE 7 // If CCH (With value from RTC) is not same as OFL jump to line 7
9: WTD 0 // 5 seconds passed set train speed to 0

Train directions

1: // Directions are bits 7 and 8
2: WTD 0b00000001 // West
3: WTD 0b01000001 // North
4: WTD 0b10000001 // East
5: WTD 0b11000001 // South

Objects

station_fuel

Description: When the train wagon is stoped here it will be automaticaly emptied. If succesfull then funds are added to the player

Type ID: 4

Amount of items left to process

signal_station

Description: Triggers interupt when locomotive is on this block. Sends its own 'LAR' into 'CCH'

Type ID: 5

{4 bits empty}
{2 bits distance to station}
{2 bits direction to station}

station_drop

Description: When the train wagon is stoped here it will be automaticaly emptied. If succesfull then funds are added to the player

Type ID: 3

Amount of items left to process

station_pick

Description: When the train wagon is stoped here it will be automaticaly filled up

Type ID: 2

Amount of items to pick up

signal_segment

Description: Triggers interupt when locomotive is on this block. Sends its own 'LAR' into 'CCH'

Type ID: 7

{4 bits empty}
{1 bit high when train west}
{1 bits high when train north}
{1 bits high when train east}
{1 bits high when train south}

signal_intersection

Description: Triggers interupt when locomotive is on this block. Sends its own 'LAR' into 'CCH'

Type ID: 6

{4 bits empty}
{1 bit high when valid west}
{1 bits high when valid north}
{1 bits high when valid east}
{1 bits high when valid south}