mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-16 09:16:44 +00:00
Unifying codestyle
parent
7349354394
commit
ac743cc654
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
### Manhattan Distance
|
### Manhattan Distance
|
||||||
This simple program calculates the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between the current position of the Cubot and another tile.
|
This simple program calculates the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between the current position of the Cubot and another tile.
|
||||||
```assembly
|
```assembly
|
||||||
@ -23,11 +22,11 @@ counter: DW 0x0000 ; Counter global variable
|
|||||||
PUSH 11 ; x2
|
PUSH 11 ; x2
|
||||||
call manhattanDist ; Execute procedure
|
call manhattanDist ; Execute procedure
|
||||||
|
|
||||||
TEST [counter], 1 ; Display 'ABCD' every other tick
|
TEST [counter], 1 ; Display 'ABCD' every odd tick
|
||||||
JNZ counter_is_odd
|
JNZ counter_is_odd
|
||||||
MOV A, 0xABCD
|
MOV A, 0xABCD
|
||||||
counter_is_odd:
|
|
||||||
|
|
||||||
|
counter_is_odd:
|
||||||
ADD [counter], 1 ; Increment counter
|
ADD [counter], 1 ; Increment counter
|
||||||
MOV B, A
|
MOV B, A
|
||||||
MOV A, 1
|
MOV A, 1
|
||||||
@ -80,6 +79,26 @@ y_is_positive:
|
|||||||
RET 2 ; Return and POP our 2 arguments
|
RET 2 ; Return and POP our 2 arguments
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Dump memory to disk
|
||||||
|
```assembly
|
||||||
|
HWID_FLOPPY equ 0xB
|
||||||
|
|
||||||
|
;**************************************
|
||||||
|
;* dumpMemToDisk()
|
||||||
|
;* Dump entire memory to Floppy Disk
|
||||||
|
dumpMemToDisk:
|
||||||
|
MOV X, 0
|
||||||
|
MOV Y, 0
|
||||||
|
dumpMemToDiskLoop:
|
||||||
|
MOV A, 3 ; WRITE_SECTOR
|
||||||
|
HWI HWID_FLOPPY
|
||||||
|
ADD X, 1
|
||||||
|
ADD Y, 512
|
||||||
|
CMP X, 128
|
||||||
|
JNZ dumpMemToDiskLoop
|
||||||
|
RET
|
||||||
|
```
|
||||||
|
|
||||||
### Constants by hackersoup with help from [contributors](https://github.com/simon987/Much-Assembly-Required/wiki/Assembly-program-examples/_history)
|
### Constants by hackersoup with help from [contributors](https://github.com/simon987/Much-Assembly-Required/wiki/Assembly-program-examples/_history)
|
||||||
<details>
|
<details>
|
||||||
<summary>
|
<summary>
|
||||||
@ -87,7 +106,7 @@ Insert this code before the new code you write for MuchAssemblyRequired, and use
|
|||||||
</summary>
|
</summary>
|
||||||
|
|
||||||
```assembly
|
```assembly
|
||||||
;; Hardware IDs
|
; Hardware IDs
|
||||||
HWID_LEGS equ 0x1
|
HWID_LEGS equ 0x1
|
||||||
HWID_LASER equ 0x2
|
HWID_LASER equ 0x2
|
||||||
HWID_LIDAR equ 0x3
|
HWID_LIDAR equ 0x3
|
||||||
@ -100,86 +119,86 @@ HWID_HOLO equ 0x9
|
|||||||
HWID_BATTERY equ 0xA
|
HWID_BATTERY equ 0xA
|
||||||
HWID_FLOPPY equ 0xB
|
HWID_FLOPPY equ 0xB
|
||||||
|
|
||||||
;; Drill
|
; Drill
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
DRILL_POLL equ 1 ; Cost: 0kJ
|
DRILL_POLL equ 1 ; Cost: 0kJ
|
||||||
;; Get the status of the drill
|
; Get the status of the drill
|
||||||
DRILL_GATHER_SLOW equ 2 ; Cost: 1400kJ
|
DRILL_GATHER_SLOW equ 2 ; Cost: 1400kJ
|
||||||
;; Gather the resource located under the Cubot (4 tick)*
|
; Gather the resource located under the Cubot (4 tick)*
|
||||||
;; Not implemented yet, see:
|
; Not implemented yet, see:
|
||||||
;; https://github.com/simon987/Much-Assembly-Required/issues/10
|
; https://github.com/simon987/Much-Assembly-Required/issues/10
|
||||||
DRILL_GATHER_FAST equ 3 ; Cost: 2000kJ
|
DRILL_GATHER_FAST equ 3 ; Cost: 2000kJ
|
||||||
;; Gather the resource located under the Cubot (1 tick)
|
; Gather the resource located under the Cubot (1 tick)
|
||||||
DRILL_STATUS_OK equ 0
|
DRILL_STATUS_OK equ 0
|
||||||
DRILL_STATUS_FAIL equ 1
|
DRILL_STATUS_FAIL equ 1
|
||||||
|
|
||||||
;; Additional info
|
; Additional info
|
||||||
;; The drill status is either STATUS_OK (0x0000) or STATUS_BUSY = (0x0001).
|
; The drill status is either STATUS_OK (0x0000) or STATUS_BUSY = (0x0001).
|
||||||
;; When trying to activate the mining drill while it is busy, it will fail silently
|
; When trying to activate the mining drill while it is busy, it will fail silently
|
||||||
|
|
||||||
|
|
||||||
;; Inventory
|
; Inventory
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
INV_POLL equ 1 ; Cost: 0kJ
|
INV_POLL equ 1 ; Cost: 0kJ
|
||||||
;; Get the contents of the inventory (B = Item ID, 0x0000 if empty)
|
; Get the contents of the inventory (B = Item ID, 0x0000 if empty)
|
||||||
INV_CLEAR equ 2 ; Cost: 100kJ
|
INV_CLEAR equ 2 ; Cost: 100kJ
|
||||||
;; Safely destroy the contents of the inventory
|
; Safely destroy the contents of the inventory
|
||||||
INV_EMPTY equ 0
|
INV_EMPTY equ 0
|
||||||
|
|
||||||
;; Laser
|
; Laser
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
LASER_WITHDRAW equ 1 ; Cost: 30kJ
|
LASER_WITHDRAW equ 1 ; Cost: 30kJ
|
||||||
;; Withdraw the desired item
|
; Withdraw the desired item
|
||||||
LASER_DEPOSIT equ 2 ; Cost: 30kJ
|
LASER_DEPOSIT equ 2 ; Cost: 30kJ
|
||||||
;; Withdraw the desired item
|
; Withdraw the desired item
|
||||||
|
|
||||||
;; items that can be used with the Laser
|
; items that can be used with the Laser
|
||||||
ITEM_BIOMASS equ 0x1
|
ITEM_BIOMASS equ 0x1
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Specify the desired item by setting the value of the B register with an item ID.
|
; Specify the desired item by setting the value of the B register with an item ID.
|
||||||
|
|
||||||
|
|
||||||
;; Legs
|
; Legs
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
LEGS_SET_DIRECTION equ 1 ; Cost: 20kJ
|
LEGS_SET_DIRECTION equ 1 ; Cost: 20kJ
|
||||||
;; Set the direction
|
; Set the direction
|
||||||
LEGS_SET_DIRECTION_AND_WALK equ 2 ; Cost: 100kJ
|
LEGS_SET_DIRECTION_AND_WALK equ 2 ; Cost: 100kJ
|
||||||
;; Set the direction and walk forward
|
; Set the direction and walk forward
|
||||||
|
|
||||||
LEGS_DIR_NORTH equ 0
|
LEGS_DIR_NORTH equ 0
|
||||||
LEGS_DIR_EAST equ 1
|
LEGS_DIR_EAST equ 1
|
||||||
LEGS_DIR_SOUTH equ 2
|
LEGS_DIR_SOUTH equ 2
|
||||||
LEGS_DIR_WEST equ 3
|
LEGS_DIR_WEST equ 3
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Specify the direction in the B register
|
; Specify the direction in the B register
|
||||||
|
|
||||||
|
|
||||||
;; LiDAR
|
; LiDAR
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
LIDAR_GET_POS equ 1 ; Cost: 0kJ
|
LIDAR_GET_POS equ 1 ; Cost: 0kJ
|
||||||
;; Copy the current (x,y) coordinates in the World in the X and Y registers
|
; Copy the current (x,y) coordinates in the World in the X and Y registers
|
||||||
LIDAR_GET_PATH equ 2 ; Cost: 50kJ
|
LIDAR_GET_PATH equ 2 ; Cost: 50kJ
|
||||||
;; Calculate the shortest path to the specified coordinates and copy it to memory
|
; Calculate the shortest path to the specified coordinates and copy it to memory
|
||||||
LIDAR_GET_MAP equ 3 ; Cost: 10kJ
|
LIDAR_GET_MAP equ 3 ; Cost: 10kJ
|
||||||
;; Generate the current World's map and copy it to memory
|
; Generate the current World's map and copy it to memory
|
||||||
LIDAR_GET_WORLD_POS equ 4 ; Cost: 0kJ
|
LIDAR_GET_WORLD_POS equ 4 ; Cost: 0kJ
|
||||||
;; Copy the current (x,y) coordinates in the Universe in the X and Y registers
|
; Copy the current (x,y) coordinates in the Universe in the X and Y registers
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Theres a lot, see it at:
|
; Theres a lot, see it at:
|
||||||
;; https://github.com/simon987/Much-Assembly-Required/wiki/Hardware:-LiDAR
|
; https://github.com/simon987/Much-Assembly-Required/wiki/Hardware:-LiDAR
|
||||||
|
|
||||||
|
|
||||||
;; Keyboard
|
; Keyboard
|
||||||
;; Version NA
|
; Version NA
|
||||||
KEYBOARD_CLEAR equ 0 ; Cost: 0kJ
|
KEYBOARD_CLEAR equ 0 ; Cost: 0kJ
|
||||||
;; Clear the keypress buffer
|
; Clear the keypress buffer
|
||||||
KEYBOARD_FETCH_KEY equ 1 ; Cost: 0kJ
|
KEYBOARD_FETCH_KEY equ 1 ; Cost: 0kJ
|
||||||
;; Reads the oldest keycode from the buffer into the B register and remove it
|
; Reads the oldest keycode from the buffer into the B register and remove it
|
||||||
|
|
||||||
;; keys to use with Keyboard Hardware
|
; keys to use with Keyboard Hardware
|
||||||
KEY_A equ 0x41
|
KEY_A equ 0x41
|
||||||
KEY_D equ 0x44
|
KEY_D equ 0x44
|
||||||
KEY_E equ 0x45
|
KEY_E equ 0x45
|
||||||
@ -187,71 +206,71 @@ KEY_F equ 0x46
|
|||||||
KEY_S equ 0x53
|
KEY_S equ 0x53
|
||||||
KEY_W equ 0x57
|
KEY_W equ 0x57
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; The keycodes in game are in hexidecimal but in the url below they're in decimal
|
; The keycodes in game are in hexidecimal but in the url below they're in decimal
|
||||||
;; Keycodes: keycode.info
|
; Keycodes: keycode.info
|
||||||
|
|
||||||
|
|
||||||
;; Hologram Projector
|
; Hologram Projector
|
||||||
;; Version 1.1B
|
; Version 1.1B
|
||||||
HOLO_CLEAR equ 0 ; Cost: 0kJ
|
HOLO_CLEAR equ 0 ; Cost: 0kJ
|
||||||
HOLO_DISPLAY_HEX equ 1 ; Cost: 0kJ, Displays value of B register
|
HOLO_DISPLAY_HEX equ 1 ; Cost: 0kJ, Displays value of B register
|
||||||
HOLO_DISPLAY_STRING equ 2 ; Cost: 0kJ, Displays 0-terminated unicode from X register
|
HOLO_DISPLAY_STRING equ 2 ; Cost: 0kJ, Displays 0-terminated unicode from X register
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Setting Register A to anything other than 0 will cause that value to be displayed
|
; Setting Register A to anything other than 0 will cause that value to be displayed
|
||||||
;; Note that the Hologram Projector will clear itself at the end of the tick,
|
; Note that the Hologram Projector will clear itself at the end of the tick,
|
||||||
;; it is only necessary to use CLEAR when you want to cancel a DISPLAY command
|
; it is only necessary to use CLEAR when you want to cancel a DISPLAY command
|
||||||
;; executed within the same tick.
|
; executed within the same tick.
|
||||||
|
|
||||||
|
|
||||||
;; Battery
|
; Battery
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
BATTERY_POLL equ 1 ; Cost: 0kJ
|
BATTERY_POLL equ 1 ; Cost: 0kJ
|
||||||
;; Copy the current charge of the battery in kJ in the B register
|
; Copy the current charge of the battery in kJ in the B register
|
||||||
BATTERY_GET_MAX_CAPACITY equ 2 ; Cost: 0kJ
|
BATTERY_GET_MAX_CAPACITY equ 2 ; Cost: 0kJ
|
||||||
;; Copy the maximum capacity of the battery in the B register
|
; Copy the maximum capacity of the battery in the B register
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Maximum Capacity: 60,000 kJ
|
; Maximum Capacity: 60,000 kJ
|
||||||
;; As of v1.2a, the only way to refill the battery is to use the temporary
|
; As of v1.2a, the only way to refill the battery is to use the temporary
|
||||||
;; REFILL = 0xFFFF value in the A register (See #2)
|
; REFILL = 0xFFFF value in the A register (See #2)
|
||||||
|
|
||||||
|
|
||||||
;; Random Number Generator
|
; Random Number Generator
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
RNG_POLL equ 0 ; Cost: 1kJ
|
RNG_POLL equ 0 ; Cost: 1kJ
|
||||||
;; Copy a randomly generated word into the B register
|
; Copy a randomly generated word into the B register
|
||||||
;; Set to 0 just as a placeholder, can be any number
|
; Set to 0 just as a placeholder, can be any number
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; Random number bounds: 0x0000 - 0xFFFF
|
; Random number bounds: 0x0000 - 0xFFFF
|
||||||
|
|
||||||
|
|
||||||
;; Clock
|
; Clock
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
CLOCK_POLL equ 0 ; Cost: 0kJ
|
CLOCK_POLL equ 0 ; Cost: 0kJ
|
||||||
;; Get the current time in ticks since the beginning of the universe as
|
; Get the current time in ticks since the beginning of the universe as
|
||||||
;; a 32-bit number stored in B:C (least significant bits in C)
|
; a 32-bit number stored in B:C (least significant bits in C)
|
||||||
;; Set to 0 just as a placeholder, can be any number
|
; Set to 0 just as a placeholder, can be any number
|
||||||
|
|
||||||
|
|
||||||
;; Floppy Drive
|
; Floppy Drive
|
||||||
;; Version 1.0B
|
; Version 1.0B
|
||||||
FLOPPY_POLL equ 1 ; Cost: 0kJ
|
FLOPPY_POLL equ 1 ; Cost: 0kJ
|
||||||
;; Get the status of the drive (READY = 0, NO_MEDIA=1)
|
; Get the status of the drive (READY = 0, NO_MEDIA=1)
|
||||||
FLOPPY_READ_SECTOR equ 2 ; Cost: 1kJ
|
FLOPPY_READ_SECTOR equ 2 ; Cost: 1kJ
|
||||||
;; Reads sector X to CPU ram starting at address Y
|
; Reads sector X to CPU ram starting at address Y
|
||||||
FLOPPY_WRITE_SECTOR equ 3 ; Cost: 1kJ
|
FLOPPY_WRITE_SECTOR equ 3 ; Cost: 1kJ
|
||||||
;; Writes sector X from CPU ram starting at Y
|
; Writes sector X from CPU ram starting at Y
|
||||||
|
|
||||||
;; Additional Info
|
; Additional Info
|
||||||
;; The players can upload their own binary data to a floppy disk or
|
; The players can upload their own binary data to a floppy disk or
|
||||||
;; download to a file using the floppy buttons in the editor.
|
; download to a file using the floppy buttons in the editor.
|
||||||
;; Floppies contains 80 tracks with 18 sectors per track. That's
|
; Floppies contains 80 tracks with 18 sectors per track. That's
|
||||||
;; 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44MB)
|
; 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44MB)
|
||||||
;; Read and write operations are synchronous. Track seeking time is 2ms.*
|
; Read and write operations are synchronous. Track seeking time is 2ms.*
|
||||||
;; *Seek time is added to the total execution time, which is not yet calculated as of v1.3a
|
; *Seek time is added to the total execution time, which is not yet calculated as of v1.3a
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -262,10 +281,11 @@ FLOPPY_WRITE_SECTOR equ 3 ; Cost: 1kJ
|
|||||||
.text
|
.text
|
||||||
CALL print_battery
|
CALL print_battery
|
||||||
|
|
||||||
;;;;; void print_battery()
|
;**************************************
|
||||||
; display / print remaing battery charge
|
;* print_battery()
|
||||||
; does not require arguments from stack or register prior to calling
|
;* display / print remaing battery charge
|
||||||
; does not overwrite or alter stack or registers
|
;* does not require arguments from stack or register prior to calling
|
||||||
|
;* does not overwrite or alter stack or registers
|
||||||
print_battery:
|
print_battery:
|
||||||
PUSH A ; store A
|
PUSH A ; store A
|
||||||
PUSH B ; store B
|
PUSH B ; store B
|
||||||
@ -281,24 +301,4 @@ print_battery:
|
|||||||
POP B
|
POP B
|
||||||
POP A
|
POP A
|
||||||
RET
|
RET
|
||||||
```
|
|
||||||
|
|
||||||
### Dump memory to disk
|
|
||||||
```assembly
|
|
||||||
HWID_FLOPPY equ 0xB
|
|
||||||
|
|
||||||
;**************************************
|
|
||||||
;* dumpMemToDisk()
|
|
||||||
;* Dump entire memory to Floppy Disk
|
|
||||||
dumpMemToDisk:
|
|
||||||
MOV X, 0
|
|
||||||
MOV Y, 0
|
|
||||||
dumpMemToDiskLoop:
|
|
||||||
MOV A, 3 ; WRITE_SECTOR
|
|
||||||
HWI HWID_FLOPPY
|
|
||||||
ADD X, 1
|
|
||||||
ADD Y, 512
|
|
||||||
CMP X, 128
|
|
||||||
JNZ dumpMemToDiskLoop
|
|
||||||
RET
|
|
||||||
```
|
```
|
Loading…
x
Reference in New Issue
Block a user