RunCPM_VGA32 icon indicating copy to clipboard operation
RunCPM_VGA32 copied to clipboard

Add timer.

Open SergeyDr opened this issue 2 years ago • 4 comments

Hello, I use your project with TTGO VGA32. And it's work great! I had made some enhancement with it. Add timer BDOS function, test it and it's work fine. Code very simple. In file cpm.h at line 1362 add: case 240: { unsigned long tmp; tmp = millis(); HL = tmp & 0xFFFF; DE = (tmp >> 16) & 0xFFFF; break;
} BDOS function 240. Return milliseconds from last turn on in DE HL. May be it's need some #ifdef for other boards.... May be assign to another BDOS function. Please include this in next version WBR

SergeyDr avatar Feb 27 '23 08:02 SergeyDr

I would add this function to the main code, but I need your help with something:

If we create a function for Linux, like:

#include <sys/time.h>

unsigned long millis()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}

And one fir Windows like:

#include <windows.h>

unsigned long millis()
{
    static DWORD start = 0;
    DWORD now = GetTickCount();
    if (start == 0) start = now;
    return (now - start);
}

Would they work the same? Can you test? If these yield the same result, then I don't see why we can't add these to the respective abstraction files and make them part of the main code. The one above for ESP32 should also compile the same on any arduino based board, and if so no #ifdef would be needed. This needs to be tested too. Problem is: I am swamped with "real life" projects, so no much time to test these.

MockbaTheBorg avatar Mar 12 '23 15:03 MockbaTheBorg

Never mind ... I see I already had millis() defined for profiling. I will push a new version with this function in.

MockbaTheBorg avatar Mar 12 '23 17:03 MockbaTheBorg

@SergeyDr Do you have a sample code for calling BDOS from MBASIC - maybe for the BDOS Call 248 which @MockbaTheBorg created for us. With such a code I could test compiled versions for Arduino, Linux and Windows ;)

guidol70 avatar Mar 13 '23 15:03 guidol70

@SergeyDr Do you have a sample code for calling BDOS from MBASIC - maybe for the BDOS Call 248 which @MockbaTheBorg created for us. With such a code I could test compiled versions for Arduino, Linux and Windows ;)

MBASIC can't call BDOS directly unfortunately. So we need some wrapper assembly function to pass parameter to BDOS and return result to MBASIC. I wrote sample program that define user function USR1. It's has one parameter - BDOS func (BC register). Also you can pass DE register by POKE at &H9020 (E), &H9021 (D) before USR1 call. If you need it of course. Program in archive Archive.zip

SergeyDr avatar Mar 29 '23 10:03 SergeyDr