assemblydelayz80cpm

Waiting for some time on Z80 CP/M


I want to write a game loop on CP/M 2.X (Z80) and would need to wait for some time e.g. a second. I've looked at BDOS but did not find a function, a loop depends on processor (emulation speed), interrupts like vertical blank do not exist.

Any ideas on how to write a game loop?

[Edit]

The z88dk CP/M lib says

Not (of course) CPM 1.x and 2.x, which have no real-time functions; ,nor QX/M, its clock is not BCD based.

There were action games like LADDER so there should be a way for a game loop.

[Edit2]

I could let the user check 5 secs with two keypresses and measure the speed (double loop) once to config the game - but only as a last resort.


Solution

  • There's no portable way of waiting for a certain amount of time under CP/M 2.2. CP/M doesn't require or use a real time clock or any kind of timer, and so you can't even assume one is present in the system, let alone that it uses any kind of common interface.

    Turbo Pascal's Delay function worked by assuming a certain CPU frequency, one that was configured when Turbo Pascal was installed. The CP/M game Ladder was written in Turbo Pascal and used its Delay function, so it also assumed a certain CPU frequency. If you played on a faster or slower CPU the game would play faster or slower than intended.

    The simplest solution would be to implement your own delay function that assumed a certain CPU frequency. I believe 4 MHz was the most common Z80 speed for CP/M. You can make this a configurable option so users can change the assumed CPU speed. You're probably also going to want to give users the option of changing the terminal type, just like Ladder did, as there are many possible terminals that can be used with CP/M.