December 01, 2024, 07:44:57 AM

heartbeat

Started by Hugh Aguilar, September 26, 2024, 01:05:32 AM

Previous topic - Next topic

Hugh Aguilar

Is there any way for the NEO6502 to get a heartbeat without an expansion card?

It would be great if the RP2040 could trigger the 65c02 IRQ regularly, like every millisecond. A heartbeat timer would help a lot in making video-games run at a constant speed. I would expect every video-game would need this, but I can't find any mention of how to do this in the documentation. The Commodore-64 had a "jiffy clock" that provided a heartbeat 60 times per second (this was derived from the AC power supply). As far as I know, all of the Commodore-64 video-games relied on this heartbeat to run at a constant speed.

It is not clear to me how to write a video-game without a heartbeat timer. I have read that Apple-II programmers would time how long their code took for each cycle, then add a delay loop to fill out the time needed to make the cycle take a constant amount of time (typically 10 milliseconds). Ugh! That is a crude technique! I don't want to do that.

If the RP2040 can't do this, then another possibility would be an expansion card with a 65c22 and use one of the timers to provide a heartbeat on the IRQ line. This adds an extra cost to the NEO6502. I would like my software to be usable by anybody who owns the basic NEO6502.

thanks --- Hugh

Hugh Aguilar

Quote from: Hugh Aguilar on September 26, 2024, 01:05:32 AM...another possibility would be an expansion card with a 65c22 and use one of the timers to provide a heartbeat on the IRQ line.

I do have in mind an application that could be done with an expansion card containing a 65c22 and an 8-bit ADC. This would be an oscilloscope. It would display the amperage draw of a machine in real-time on the HDMI display for the purpose of diagnosing problems in the machine. It is somewhat complicated by the fact that the machine goes through stages, so an off-the-shelf oscilloscope doesn't really provide the data the way that I want to see it.

Anyway, right now I just want to learn how the NEO6502 works by writing a video game, but I'm stymied by the lack of a heartbeat timer. Considering that the RP2040 is in control of all of the 65c02 pins, it seems easy and obvious that it should stroke the IRQ on a regular basis. It also seems obvious that games need to run at a constant speed irregardless of how much activity there is on the screen or how fast the processor is running.

Without a heartbeat timer, the NEO6502 fails at real-time video-games. It could still support board games or turtle-graphics in which you just want the code to run as fast as possible.

OS9 on the MC6809 had a heartbeat of 10ms. That should be adequate for video-games. The NEO6502 is faster though, so it could be 1ms. That should be adequate for data-collection on an ADC.

Hugh Aguilar

Quote from: Hugh Aguilar on September 26, 2024, 01:05:32 AMIt would be great if the RP2040 could trigger the 65c02 IRQ regularly, like every millisecond. A heartbeat timer would help a lot in making video-games run at a constant speed.
It seems like tying a timer to the IRQ should be straightforward, given that the RP2040 is in control of all of the 65c02 pins. Even if you can't tie a timer to the IRQ though, just providing an API function to access a millisecond clock on the RP2040 would be adequate --- each cycle of the video game would poll the clock in a delay loop, in order to ensure that each cycle takes the same amount of time (16 milliseconds) --- this would be slightly inaccurate because of the time taken to do the API call, but the errors would average out plus or minus, so the user wouldn't notice.

I said 16 milliseconds which is roughly the same as the Commodore-64 jiffy-clock, rather than 10 milliseconds which is what OS9 used.
The advantage with 16 milliseconds is that, when polling to determine if the cycle is complete, we can use logic operations to check if we are at a 16 millisecond step. If we checked for 10 milliseconds, we would have to do a division.

I think OS9 used 10 milliseconds (100 Hz.) so they could time events by how many seconds were required. This isn't necessary for a video-game.

I'm still working on the Forth system. This would be a lot more fun if people would actually use it for writing video games, but that won't happen without a heartbeat timer. It can still be used for writing board games that just need to run fast. Back in 1990 I wrote an Othello game in ISYS Forth for the Laser-128. It was somewhat slow despite me writing the legal-move generate in assembly-language, and it played poorly (because I didn't know how to deal with the horizon problem, and I still don't know). It might be fun for everybody to write an Othello game and then have the programs compete against each other. That would test NEO6502 users' programming skill, and also test Forth vs C vs Pascal.

I don't think that Chess is a good idea because there is already source-code for that available on the internet, so this would only be a test of people's Googling skill. Borland provided a Chess program written in Turbo Pascal that came with source-code.