From 2ef79d6894e41f68fafa5aa080d275de2fe2eaf7 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 30 Jul 2018 18:16:50 +0200 Subject: [PATCH] Minor improvements for Intel 8080 and ZX Spectrum --- docs/lang/preprocessor.md | 14 +++++++++-- include/stdio_zxspectrum.mfk | 12 +++------ include/stdlib.mfk | 4 +-- include/{stdlib_z80.mfk => stdlib_i80.mfk} | 22 ++++++++++------ include/zxspectrum.ini | 1 - include/zxspectrum_8080.ini | 29 ++++++++++++++++++++++ src/main/scala/millfork/Platform.scala | 8 ++++-- 7 files changed, 66 insertions(+), 24 deletions(-) rename include/{stdlib_z80.mfk => stdlib_i80.mfk} (67%) create mode 100644 include/zxspectrum_8080.ini diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index 48b3de26..2339996a 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -30,9 +30,19 @@ You can also define feature values using the `-D` command line option. ### Built-in features -* `ARCH_6502` – 1 if compiling for 6502, 0 otherwise +* `ARCH_6502` – 1 if compiling for 6502, 0 otherwise -* `ARCH_Z80` – 1 if compiling for Z80, 0 otherwise +* `CPUFEATURE_65C02` – 1 if compiling for 65C02-compatible processor, 0 otherwise + +* `CPUFEATURE_65CE02` – 1 if compiling for 65CE02-compatible processor, 0 otherwise + +* `ARCH_I80` – 1 if compiling for Intel 8080-like processor, 0 otherwise + +* `CPUFEATURE_8080` – 1 if compiling for Intel 8080-compatible processor, 0 otherwise + +* `CPUFEATURE_GAMEBOY` – 1 if compiling for Sharp LR35902-compatible processor, 0 otherwise + +* `CPUFEATURE_Z80` – 1 if compiling for Z80-compatible processor, 0 otherwise ### Commonly used features diff --git a/include/stdio_zxspectrum.mfk b/include/stdio_zxspectrum.mfk index 07accb56..64e5c489 100644 --- a/include/stdio_zxspectrum.mfk +++ b/include/stdio_zxspectrum.mfk @@ -7,9 +7,7 @@ import stdio void putstr(pointer str, byte len) { asm { - ? LD HL,(str) - ? LD D, H - ? LD E, L + ? LD DE,(str) ? LD A,(len) ? LD B, 0 ? LD C, A @@ -20,12 +18,8 @@ void putstr(pointer str, byte len) { void putstrz(pointer str) { word length = strzlen(str) asm { - ? LD HL,(str) - ? LD D, H - ? LD E, L - ? LD HL,(length) - ? LD B, H - ? LD C, L + ? LD DE,(str) + ? LD BC,(length) CALL 8252 } } \ No newline at end of file diff --git a/include/stdlib.mfk b/include/stdlib.mfk index 834426cb..29a8b16b 100644 --- a/include/stdlib.mfk +++ b/include/stdlib.mfk @@ -2,8 +2,8 @@ #if ARCH_6502 import stdlib_6502 -#elseif ARCH_Z80 -import stdlib_z80 +#elseif ARCH_I80 +import stdlib_i80 #else #warn Unsupported architecture #endif diff --git a/include/stdlib_z80.mfk b/include/stdlib_i80.mfk similarity index 67% rename from include/stdlib_z80.mfk rename to include/stdlib_i80.mfk index dc1f302b..fb9d8ddb 100644 --- a/include/stdlib_z80.mfk +++ b/include/stdlib_i80.mfk @@ -1,7 +1,7 @@ // target-independent things -#if not(ARCH_Z80) -#warn stdlib_z80 module should be only used on 6502-compatible targets +#if not(ARCH_I80) +#warn stdlib_i80 module should be only used on Intel 8080-like targets #endif macro asm void poke(word const addr, byte a) { @@ -21,10 +21,14 @@ macro asm void enable_irq() { } asm byte hi_nibble_to_hex(byte a) { - SRL A - SRL A - SRL A - SRL A +#if CPUFEATURE_GAMEBOY + SWAP A +#else + RR A + RR A + RR A + RR A +#endif JP lo_nibble_to_hex } @@ -32,7 +36,11 @@ asm byte lo_nibble_to_hex(byte a) { AND $F ADD A,$30 CP $3A +#if CPUFEATURE_GAMEBOY | CPUFEATURE_Z80 JR C,_lo_nibble_to_hex_lbl +#else + JP C,_lo_nibble_to_hex_lbl +#endif ADD A,$7 _lo_nibble_to_hex_lbl: RET @@ -41,5 +49,3 @@ _lo_nibble_to_hex_lbl: macro asm void panic() { CALL _panic } - -array __constant8 = [8] diff --git a/include/zxspectrum.ini b/include/zxspectrum.ini index 0e0e3699..2da69fb3 100644 --- a/include/zxspectrum.ini +++ b/include/zxspectrum.ini @@ -1,4 +1,3 @@ -;DON'T USE THIS ;a single-load ZX Spectrum 48k program [compilation] arch=z80 diff --git a/include/zxspectrum_8080.ini b/include/zxspectrum_8080.ini new file mode 100644 index 00000000..39d94c4d --- /dev/null +++ b/include/zxspectrum_8080.ini @@ -0,0 +1,29 @@ +;a single-load ZX Spectrum 48k program +;using just the Intel 8080 instruction set +[compilation] +arch=i8080 +encoding=sinclair +modules=default_panic,zxspectrum,stdlib + +[allocation] +segments=default,slowram +segment_default_start=$8000 +segment_default_datastart=after_code +segment_default_end=$ffff +segment_slowram_start=$5ccb +segment_slowram_end=$7fff + +[define] +ZX_SPECTRUM=1 +WIDESCREEN=0 +KEYBOARD=1 +; TODO: ? +JOYSTICKS=1 +HAS_BITMAP_MODE=1 + +[output] +style=single +format=tap +extension=tap + + diff --git a/src/main/scala/millfork/Platform.scala b/src/main/scala/millfork/Platform.scala index fb68666b..342040df 100644 --- a/src/main/scala/millfork/Platform.scala +++ b/src/main/scala/millfork/Platform.scala @@ -238,10 +238,14 @@ object Platform { def builtInCpuFeatures(cpu: Cpu.Value): Map[String, Long] = { Map[String, Long]( "ARCH_6502" -> toLong(CpuFamily.forType(cpu) == CpuFamily.M6502), + "CPUFEATURE_65C02" -> toLong(Cpu.defaultFlags(cpu).contains(CompilationFlag.EmitCmosOpcodes)), + "CPUFEATURE_65CE02" -> toLong(Cpu.defaultFlags(cpu).contains(CompilationFlag.Emit65CE02Opcodes)), "ARCH_I80" -> toLong(CpuFamily.forType(cpu) == CpuFamily.I80), - "ARCH_Z80" -> toLong(cpu == Cpu.Z80 || cpu == Cpu.EZ80), + "CPUFEATURE_Z80" -> toLong(Cpu.defaultFlags(cpu).contains(CompilationFlag.EmitZ80Opcodes)), + "CPUFEATURE_8080" -> toLong(Cpu.defaultFlags(cpu).contains(CompilationFlag.EmitIntel8080Opcodes)), + "CPUFEATURE_GAMEBOY" -> toLong(Cpu.defaultFlags(cpu).contains(CompilationFlag.EmitSharpOpcodes)), "ARCH_X86" -> toLong(CpuFamily.forType(cpu) == CpuFamily.I86), - "ARCH_6500" -> toLong(CpuFamily.forType(cpu) == CpuFamily.M6800), + "ARCH_6800" -> toLong(CpuFamily.forType(cpu) == CpuFamily.M6800), "ARCH_ARM" -> toLong(CpuFamily.forType(cpu) == CpuFamily.ARM), "ARCH_68K" -> toLong(CpuFamily.forType(cpu) == CpuFamily.M68K), "HAS_HARDWARE_MULTIPLY" -> (cpu match {