ref: e7a3ba05929c27b3cc5b1f5c2725ab8dba9efb43
parent: 50734c961c436c4e4a996f120befcab5ee74d15e
author: yenatch <[email protected]>
date: Mon Apr 13 17:30:51 EDT 2015
Add a macro for enumeration. "enum" is like "const" but uses variables instead. This might not be desired. It has been moved to the top of macros.asm so that included macros can be enumerated.
--- a/macros.asm
+++ b/macros.asm
@@ -1,3 +1,5 @@
+INCLUDE "macros/enum.asm"
+
INCLUDE "macros/event.asm"
INCLUDE "macros/sound.asm"
INCLUDE "macros/text.asm"
@@ -112,17 +114,6 @@
db $ff
ENDM
-
-; Constant enumeration
-
-const_def: MACRO
-const_value SET 0
-ENDM
-
-const: MACRO
-\1 EQU const_value
-const_value SET const_value + 1
-ENDM
sine_wave: MACRO
--- /dev/null
+++ b/macros/enum.asm
@@ -1,0 +1,31 @@
+; Enumerate variables
+
+enum_start: macro
+if _NARG >= 1
+__enum__ = \1
+else
+__enum__ = 0
+endc
+if _NARG >= 2
+__enumdir__ = \2
+else
+__enumdir__ = +1
+endc
+endm
+
+enum: macro
+\1 = __enum__
+__enum__ = __enum__ + __enumdir__
+endm
+
+
+; Enumerate constants
+
+const_def: MACRO
+const_value = 0
+ENDM
+
+const: MACRO
+\1 EQU const_value
+const_value = const_value + 1
+ENDM