aoineko-fr / MSXgl

The MSX Game Library in C language
113 stars 9 forks source link

Fixed DOS1 functions #5

Closed abekermsx closed 2 years ago

abekermsx commented 2 years ago

I fixed the DOS1 functions so they can be actually used now.

I created a small sample to test, it loads and displays a .GE5 file. Of course, allocating 30375 bytes on the heap is not ideal :P I could work around that but it would be better to have at least read random block added to MSXgl. I'll try to add those myself.

include "msxgl.h"

include "dos.h"

include "memory.h"

fcb file; u8 *data;

void main() { VDP_SetMode(VDP_MODE_SCREEN5); VDP_SetColor(0);

Mem_Set(0, &file, sizeof(fcb));
Mem_Copy("TEST    GE5", &file.name, 11);

DOS_Open(&file);

data = Mem_HeapAlloc(30375);

for (u16 i = 0; i < 30375; i+=128)
{
    DOS_SetTransferAddr(&data[i]);
    DOS_SequentialRead(&file);
}

VDP_WriteVRAM_128K(&data[7], 0, 0, 256*212);
VDP_SetPaletteEntry(0, data[0x07687] + (data[0x07687+1]<<8));
VDP_SetPalette(&data[0x07687+2]);

Mem_HeapFree(30375);
DOS_Close(&file);

while(!Keyboard_IsKeyPressed(KEY_ESC)) {}

}

aoineko-fr commented 2 years ago

Thank you Abekermsx. MSX-DOS will be one of my next focus. I have to read more documentation about it and to create some sample programs.

In your example, you read the file by chunk of 128 bytes. So with a 128 bytes buffer, you could include in the reading loop the copy of that chunks to the VRAM.

abekermsx commented 2 years ago

Yeah I know, but the file contains a BASIC-header so the pixel data is not aligned to 128 bytes. I could work around that but I just wanted to create a minimal example.

I already have a working version with the random block read function. The current fcb struct is not ideal for this kind of operation (for example the file position has to be updated in some bytes in the reserved2 field). Ideally the fcb structure should specify more fields as documented at http://map.grauw.nl/resources/dos2_environment.php#c3_6 but it would be a breaking change (if anybody is using this DOS module).

Some fcb fields have multiple purposes depending on the type of operation (for CP/M compatibility, 128-byte block read/write and random block read/writes) which makes it a bit hard to design a proper struct. Maybe 2 kinds of structs are needed. Or you could just keep this module very low level (just a wrapper for DOS1/2 calls) and introduce a higher level File module.

aoineko-fr commented 2 years ago

Give me few days to read more documentation about disk interface and MSX-DOS and I'll comeback with a solution. Current FCB structure is incorrect and have been introduced recently ; I think it still time to fix it. :)

abekermsx commented 2 years ago

Ok I found out I need to add PUSH IX/POP IX in the functions because the BDOS calls overwrites IX.