aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--list.s22
2 files changed, 26 insertions, 10 deletions
diff --git a/README.md b/README.md
index 0210740..3e170a7 100644
--- a/README.md
+++ b/README.md
@@ -32,9 +32,17 @@ ready to be used.
As for the memory mapping, please do note that this library needs 4 bytes in
order to store two 16-bit pointers that keep track of the list. By default these
4 bytes are located at \$60-\$63. If that clashes with something from your code,
-simply change these variables, named `List::ptr` and `List::last`. Each of these
-pointers are 16-bit long (hence 2 bytes long), and they don't need to be in
-continguous memory locations.
+you can provide alternative locations by defining `LIST_PTR_ADDRESS` and
+`LIST_LAST_ADDRESS`. So:
+
+```assembly
+;; Let's say that you want one pointer in $80-$81, and the other at $90-$91.
+LIST_PTR_ADDRESS = $80
+LIST_LAST_ADDRESS = $90
+
+;; And then include the library.
+.include "<vendor directory>/list.s"
+```
### Creating a list
diff --git a/list.s b/list.s
index 6fa17b8..96c34f7 100644
--- a/list.s
+++ b/list.s
@@ -58,13 +58,21 @@
;; For more information on the usage and the API check the documentation
;; (README.md file on the https://github.com/mssola/list.nes repository).
.scope List
- ;; NOTE (important): this library needs 4 bytes ($60-$63) to store
- ;; information of this list. These are two 16-bit pointers which are used
- ;; for the subroutines being defined here. If you have a clash with these
- ;; memory addresses, do feel free to change them, but remember that the code
- ;; assumes that both pointers are 16-bit (they don't need to be contiguous).
- ptr = $60
- last = $62
+ ;; NOTE (important): this library needs 4 bytes to store information of this
+ ;; list. These are two 16-bit pointers which are used for the subroutines
+ ;; being defined here. The exact location of these pointers are set to
+ ;; $60-$63 by default, but they can be changed by providing definitions for
+ ;; `LIST_PTR_ADDRESS` and `LIST_LAST_ADDRESS`.
+ .ifdef LIST_PTR_ADDRESS
+ ptr = LIST_PTR_ADDRESS
+ .else
+ ptr = $60
+ .endif
+ .ifdef LIST_LAST_ADDRESS
+ last = LIST_LAST_ADDRESS
+ .else
+ last = $62
+ .endif
;; Set the value of `a` into the list and advance one position without
;; growing the list.