inexorabletash / jsbasic

Applesoft BASIC in JavaScript
https://calormen.com/jsbasic
Other
187 stars 39 forks source link

Simulate most popular Apple II system clock #44

Closed mobluse closed 8 months ago

mobluse commented 2 years ago

I think JSBASIC should support a real time clock, e.g. one that is supported in popular Apple II emulators, see https://en.wikipedia.org/wiki/Apple_II_system_clocks. "When the Thunderware Thunderclock Plus was released in 1980, it quickly became the de facto standard for an Apple II system clock. When Apple Computer released its new ProDOS operating system in 1984, a Thunderclock software driver came built-in. From that point on, all new Apple II system clocks strived to emulate the Thunderclock." The emulator AppleWin seems to support the Thunderclock card.

The clock could be set to current local time by default.

This could solve the problem with games running at different speeds on different computers, and also make it possible to run games both on JSBASIC and on real Apple II with system clock, see https://github.com/inexorabletash/jsbasic/issues/20.

I could play this Tetris game in JS by inserting a delay loop on line 350 that counts to 2000 in my case, but that could have been configured automatically if we had a real time clock in JSBASIC.

inexorabletash commented 8 months ago

Okay, I added basic Thunderclock simulation. To do a game loop you'll want to use the Mountain Clock Format, for example:

20 PRINT CHR$(4);"PR#4"
30 PRINT CHR$(4);"IN#4"
40 INPUT " ";T$
50 PRINT CHR$(4);"PR#0"
60 PRINT CHR$(4);"IN#0"
70 PRINT T$

T$ will be of the format MM/DD hh;mm;ss.fff e.g. "05/12 16;32;55.000" - that's the only format that provides sub-second precision. VAL(RIGHT$(T$,3)) should give you the current milliseconds (0-999), for example.