diff --git a/Hardware:-LiDAR.md b/Hardware:-LiDAR.md index 2ee46d5..3b6d11f 100644 --- a/Hardware:-LiDAR.md +++ b/Hardware:-LiDAR.md @@ -14,29 +14,48 @@ Hardware ID: `0x0003` | `3` | `LIDAR_GET_MAP` | `10 kJ` | Generate the current World's map and copy it to memory starting at the address specified in the X register | | `4` | `LIDAR_GET_WORLD_POS` | `0 kJ` | Copy the current (x,y) coordinates in the Universe in the X and Y registers | -`LIDAR_GET_PATH` generates a path as a direction sequence of 1 word each starting at memory address `0x0000`. You indicate the coordinates of the destination with the X and Y registers, and specify the desired range (Manhattan distance from the destination) with the B register. For example, if you want to get within 1 tile of a biomass blob, specify a distance of `1`. The last word in the sequence is `0xAAAA` to indicate the end of the path. A single value of `0xFFFF` is set at memory address `0x0000` to indicate an invalid path. -`NORTH` = `0x0000` -`EAST` = `0x0001` -`SOUTH` = `0x0002` -`WEST` = `0x0003` +#### LIDAR_GET_PATH +Generates a path as a sequence of words, each representing a direction. The generated path starts at the address `0x0000` but varies in length. It is terminated with the word `0xAAAA`, which represents the end of the path. A single value of `0xFFFF` is set at memory address `0x0000` to indicate an invalid path. If a path could not be generated, then the memory at address `0x0000` is set to `0xFFFF` (Note: The path terminator is not written for invalid paths). +The coordinates of the destination are indicated with the X and Y registers. The desired range (Manhattan distance from the destination) is specified with the B register. For example, if you want to get within 1 tile of a biomass blob, specify a distance of `1`. -`LIDAR_GET_MAP` generates a map of the current world as a tile sequence of 256 words starting at the memory address in the X register, each word representing a tile. The LiDAR starts reading the tiles west to east, north to south: (0,0) (1,0) (2,0) ... (15,0) (0,1) (1,1) ... +##### Directions +| Direction | Value | +| :-------- | :------- | +| North | `0x0000` | +| East | `0x0001` | +| South | `0x0002` | +| West | `0x0003` | -Each tile is encoded as a bit field: -`1000 0000 0000 0000` (`0x8000`) : Blocked (wall) tile -`0100 0000 0000 0000` (`0x4000`) : Biomass -`0010 0000 0000 0000` (`0x2000`) : Factory -`0001 0000 0000 0000` (`0x1000`) : Radio Tower -`0000 1000 0000 0000` (`0x0800`) : Vault -`0000 0100 0000 0000` (`0x0400`) : Electric Box -`0000 0010 0000 0000` (`0x0200`) : Iron tile -`0000 0001 0000 0000` (`0x0100`) : Copper tile -`0000 0000 1000 0000` (`0x0080`) : Cubot -`0000 0000 0100 0000` (`0x0040`) : NPC -`0000 0000 0010 0000` (`0x0020`) : Portal -`0000 0000 0001 0000` (`0x0010`) : -`0000 0000 0000 1000` (`0x0008`) : -`0000 0000 0000 0100` (`0x0004`) : -`0000 0000 0000 0010` (`0x0002`) : -`0000 0000 0000 0001` (`0x0001`) : \ No newline at end of file +##### Example generated path +The memory of a 4 tile path consisting of moving the Cubot north twice, once west, and then once east would look like: + +| Address | `0x00` | `0x01` | `0x02` | `0x03` | `0x04` | +| ------- | ------ | ------ | ------ | ------ | -------- | +| Value | `0x00` | `0x00` | `0x03` | `0x01` | `0xAAAA` | + +#### LIDAR_GET_MAP +Generates a map of the current world as a sequence of 256 words, each word representing a tile. The starting address of the generated map must be specified with the X register. The LiDAR reads the tiles west to east, north to south: (0,0) (1,0) (2,0) ... (15,0) (0,1) (1,1) ... The first 16 words will be the north-most row from west to east, the next 16 words will be the next row down (south), etc. Ending with the south-east most tile. + +Each tile is encoded as a bit field. Tiles may contain more than one thing, in which case the value is the bit fields of each thing it contains `OR`'d together. For example, a tile with copper and an NPC would have the bit field `0000 0001 0100 0000` (`0x0140`). + +##### Tile content bit fields +| Bit field | Value | Content | +| :---------------------| :------- | :------------------- | +| `1000 0000 0000 0000` | `0x8000` | Blocked (wall) tile | +| `0100 0000 0000 0000` | `0x4000` | Biomass | +| `0010 0000 0000 0000` | `0x2000` | Factory | +| `0001 0000 0000 0000` | `0x1000` | Radio Tower | +| `0000 1000 0000 0000` | `0x0800` | Vault | +| `0000 0100 0000 0000` | `0x0400` | Electric Box | +| `0000 0010 0000 0000` | `0x0200` | Iron tile | +| `0000 0001 0000 0000` | `0x0100` | Copper tile | +| `0000 0000 1000 0000` | `0x0080` | Cubot | +| `0000 0000 0100 0000` | `0x0040` | NPC | +| `0000 0000 0010 0000` | `0x0020` | Portal | +| `0000 0000 0001 0000` | `0x0010` | | +| `0000 0000 0000 1000` | `0x0008` | | +| `0000 0000 0000 0100` | `0x0004` | | +| `0000 0000 0000 0010` | `0x0002` | | +| `0000 0000 0000 0001` | `0x0001` | | +| `0000 0000 0000 0000` | `0x0000` | Nothing | \ No newline at end of file