diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index e0e5d266..275365d3 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -57,6 +57,10 @@ The following features are defined based on the chosen CPU and compilation optio * `INIT_RW_MEMORY` – 1 if the option `ram_init_segment` is defined, 0 otherwise. See [the ROM vs RAM guide](../api/rom-vs-ram.md) for more information. +* `BIG_ENDIAN` – 1 if the platform is big-endian, 0 otherwise (currently all supported platforms are little-endian) + +* `LITTLE_ENDIAN` – 1 if the platform is little-endian, 0 otherwise (currently all supported platforms are little-endian) + * `OPTIMIZE_FOR_SIZE`, `OPTIMIZE_FOR_SPEED`, `OPTIMIZE_INLINE`, `OPTIMIZE_IPO` – 1 if given optimization setting is enabled, 0 otherwise diff --git a/src/main/scala/millfork/CompilationOptions.scala b/src/main/scala/millfork/CompilationOptions.scala index e7e59c1f..17faf7b7 100644 --- a/src/main/scala/millfork/CompilationOptions.scala +++ b/src/main/scala/millfork/CompilationOptions.scala @@ -214,6 +214,8 @@ case class CompilationOptions(platform: Platform, "CPUFEATURE_6502_ILLEGALS" -> toLong(platform.cpuFamily == CpuFamily.M6502 && flag(CompilationFlag.EmitIllegals)), "CPUFEATURE_Z80_ILLEGALS" -> toLong(flag(CompilationFlag.EmitZ80Opcodes) && flag(CompilationFlag.EmitIllegals)), "CPUFEATURE_8085_ILLEGALS" -> toLong(flag(CompilationFlag.EmitIntel8080Opcodes) && flag(CompilationFlag.EmitIllegals)), + "BIG_ENDIAN" -> toLong(Cpu.isBigEndian(platform.cpu)), + "LITTLE_ENDIAN" -> toLong(!Cpu.isBigEndian(platform.cpu)), "INIT_RW_MEMORY" -> toLong(platform.ramInitialValuesBank.isDefined), "SYNTAX_INTEL" -> toLong(platform.cpuFamily == CpuFamily.I80 && flag(CompilationFlag.UseIntelSyntaxForInput)), "SYNTAX_ZILOG" -> toLong(platform.cpuFamily == CpuFamily.I80 && !flag(CompilationFlag.UseIntelSyntaxForInput)), @@ -269,6 +271,11 @@ object CpuFamily extends Enumeration { case Cpu.Motorola6809 => M6809 } } + + def isBigEndian(family: CpuFamily.Value): Boolean = family match { + case M6502 | I80 | I86 | ARM => false + case M6800 | M6809 | M68K => true + } } object Cpu extends Enumeration { @@ -475,6 +482,8 @@ object Cpu extends Enumeration { case CpuFamily.M6809 => 2 case _ => ??? } + + def isBigEndian(cpu: Cpu.Value): Boolean = CpuFamily.isBigEndian(CpuFamily.forType(cpu)) } object CompilationFlag extends Enumeration {