10

Did Microsoft BASIC (or any of the OEM versions) ever use Z80 only instructions?

For the purposes of this question I'm ignoring the equivalent of BIOS I/O layers which OEMs would have provided.

2 Answers 2

17

If you mean if Microsoft BASIC's core ever used Z80 instructions at all, then I would say no - the code of BASIC is designed using 8080 compatible instructions, and all "drivers" are created as appropriate for the platform.

It may happens that some vendors have modified the code to Z80 in order to "compress" it and free some space for special functions, but it must be considered case by case.

Examples: looking to the MSX BASIC, which is designed for Z80 only, with BASIC core in 8080, and extension and BIOS using IX/IY, 0cbh instructions and alternate register set.

Update: following George's answer I decided to take closer look into the MSX BASIC code (starting 4000 and ending approx 7400), and confirm his words:

  • IX is used 4 times, but it is clearly a patch to access BIOS;
  • JR instructions are used a lot. I think they all also can be easily patched where possible (jumps -128 to +127) in order to save space;
  • LD BC,(nn) and LD (nn),BC are not used at all;
  • LD DE,(nn) is used 17 times, LD (nn),DE is used 15 times, quite a lot;
  • LD SP,(nn) is not used at all, while LD (nn),SP is used twice;
  • EXX is used 3 times;
  • ADC HL,ss is not used, while SBC HL,ss is used 3 times;
  • NEG is not used;
  • RLD/RRD/RLC/RL/RRC are not used;
  • CPI(R)/CPD(R) are not used;
  • IN r,(c)/OUT r,(c) and outi/outd type instructions are not used (first two are used twice, but it is for sure a platform modification;
  • LDI(R)/LDD(R) used only once;
  • SET/RES/BIT n,r are used two times closer to the end of ROM, must be patch;
  • SLA/SRA/SRL not used.

One suspicious instruction more or less massively used is related to loading/storing DE into memory location, closer look into the code revealed the following cases:

  • DE is used in math with HL;
  • DE is used to get error number/line number for error handling;
  • or just as read/store word between two locations.
  • some other local usage, including RST20 and RST28 where it can be easily compressed from EX DE,HL and LD (nn),HL.

Thus I would consider all this stuff to be special changes for the platform which is expected to have Z80 only.

4
  • Based on a quick search, it's possible that the only definitely-Z80 version of Microsoft BASIC other than that for the MSX and its very-close Spectravideo predecessor was for the TRS-80. So this answer is almost an exhaustive search.
    – Tommy
    Apr 18, 2018 at 18:19
  • Makes sense given how much was added to the MSX basic.
    – PeterI
    Apr 19, 2018 at 11:21
  • Curious LDIR would only get used once. I would have expected that it would be useful in at least three places (copy line up, copy line down, and copy string). For which of those was it used?
    – supercat
    Apr 20, 2018 at 13:40
  • 1
    In MSX2 this code fragment is used to transfer data for RAM disk (using LDIR), in MSX1 machine this space, while having some useful code, is never executed (thus space is reused in MSX2 for other purpose).
    – Anonymous
    Apr 20, 2018 at 19:25
13

Yes, Z-80 instructions were used in Microsoft's Z-80 BASIC. For example, look at the TRS-80 Model I or Model III ROM BASIC and you'll find a relative jump JR NZ,0x871 at location 0x88E. The 8080 does not have relative jump instructions. That instruction is part of a routine to shift CDEB right by L bits which is used by the floating point code. Do a PRINT SQR(1) and you'll see the instruction is hit.

However, it is fair to say that no significant changes were made to the BASIC core when ported from 8080 to Z-80. I don't recall any other Z-80 feature besides relative jumps being used in the core routines. I speculate that they did a quick and perhaps automated pass over the code to take advantage of the byte savings from using JR instead of JP and then moved on to machine-specific code which does use Z-80 routines quite significantly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .