Page 1 of 1

Drive A: updated

Posted: Mon Jun 19, 2023 6:48 am
by DJ Sures
The cloud CPM A: has been updated to include Production Dave's game updates. On A: User Area 3 you will find tetris.com, snake.com and invaders.com

Re: Drive A: updated

Posted: Wed Jun 21, 2023 8:29 pm
by productiondave
Yay! Thanks DJ. Did you play the new invaders game?

I noticed some things. I guess it's because the game tries to read and save the high score. It appears to be struggling to do that. I did all my testing on drive C: user area 0 and it seems to be no issue there. I suspect it's something to do with the file io routines i have. They just rely on standard CP/M fileio. I noticed that the files are saved back to USER 0. which must be a CP/M thing I was not aware of. I will look to see if there is a way to make it go to the same USER area. I don't know if this is a cloudCPM thing or general CPM thing so I have to do some more testing.

You might experience delays loading the game, ending a game and returnning to the menu etc. These are the times the score is actually saved. This will apply on SNAKE and TETRIS too.

As these games are not targeted specifically at cloud CP/M I wonder what the best solution is? -

I have tested this on cloudCP/M and Ishkur CP/M. In ishkur CP/M it seems to be okay running in User Area 1 of the B Drive, but dat files are still saved back to user area 0. So that part of the issue is not unique to Cloud CP/M.

I could be making a big deal of nothing here. I'd like to know what other people experienced and if moving the file to C:0> or D:0> helps the situation any.

For now, I suggest folks move the games over to C:0> and play from there. It's trivial to do and will let you have fun.

Code: Select all

A:0> C:
C:0> dir
No file
C:0> A:
A:0> rncmd 3/A:INVADERS.COM 0/C:INVADERS.COM
++++++++++... etc, 
24320 Bytes copied

A:0> C:
C:0> invaders
The process will init the C drive and download one to the cache if you don't have one already.
Then it will copy the game over to C:0>
Then you play the game from C:0> instead of A:3>

Alternatively you can get the binaries and stage them into your D drive using cpmdrive.com - if you do this, I suggest still putting the games into the corresponding folder for User 0.

You can also use a:cloudgui to copy the files over. Before doing this, though, make sure you have a C drive by changing to it first. If you don't have one CloudCPM will download a blank for you and save it in your IA/Store/Temp folder.

I have tested this approach with a clean system - IE: I emptied out the cache in Store/temp on the IA.

Until I figure out the issue with running out of different user areas, this will provide the best experience for you.

For reference the two functions that I think are causing issues are:

Code: Select all

uint16_t getHighScore() {
    uint16_t hs;
    #if BIN_TYPE == BIN_CPM
        FILE * fp = fopen("invaders.dat", "r");
        if (fp) {
            fscanf(fp, "%d", &hs);
        } else {
            hs = 0;
        }
        fclose(fp);
    #else
        hs = 0;
    #endif
    return hs;
}

void setHighScore(uint16_t hs) __z88dk_fastcall {
    #if BIN_TYPE == BIN_CPM
        FILE * fp = fopen("invaders.dat", "w");
        fprintf(fp, "%d", hs);
        fclose(fp);
    #else
        (void)hs;
    #endif
}

Re: Drive A: updated

Posted: Thu Jun 22, 2023 3:38 am
by DJ Sures
You can get the current drive and user area from either using the z88dk cpm.h header or reading the memory address. I’m on my phone so I forget offhand what the address is. But com stores the drive and user area in a memory address in the zero page

Re: Drive A: updated

Posted: Thu Jun 22, 2023 7:51 am
by productiondave
Of course it does. Okay. I'll do some experimenting and see if we can't improve things a bit. I'll keep ya posted

Re: Drive A: updated

Posted: Thu Jun 22, 2023 9:43 am
by productiondave
ok so the data is in address 0x04. Here is the c code that extracts that data in my invaders game tests...

Code: Select all


/* headers */
uint8_t _CCP;
char current_vol;
uint8_t user_area;
char hs_filename[16];

/* code */
void main(void) {
    __asm
    ld      a,(0x0004);
    ld      (__CCP),a
    __endasm;
    current_vol = (_CCP & 0x0f) + 0x41;
    user_area = (_CCP >> 4);
    sprintf(hs_filename, "%d/%c:invaders.dat", user_area, current_vol);
    ...
Thing is, after trying this, the only difference was that the .dat files were being saved in the right place. The performance of opening, reading writing and closing the file again seems very slow on A drive. Perhaps it's due to the number of files. There are a lot of files in A: drive. Maybe that's the issue?

Because on C: it works very fast - no issues at all on C: where I only have maybe 6 files altogether.

Re: Drive A: updated

Posted: Thu Jun 22, 2023 8:29 pm
by DJ Sures
Yeah the speed is slower accessing drives with many files. It’s how the directory records work - lots of little records for files that exceed the max record length. I learned a lot when making the dynamic D:

But you can get the com drive data more efficiently with special function register definition…

Code: Select all

// address 4 : current drive number (0=a, ..., 15=p)
// (uuuudddd) where 'uuuu' is the user number
//            and   'dddd' is the drive number.  
__at (0x0004) uint8_t CPM_USER_DRIVE;

Re: Drive A: updated

Posted: Fri Jun 23, 2023 4:39 am
by productiondave
Cool - okay so that's good to know that I'm not going mad. I might push an update to the games to force writing to the correct user and drive. It makes sense to keep the high score data together with the game binary. And thanks too for the fancy __at (0x0004) uint8_t CPM_USER_DRIVE; thing.