X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrvutil.c;h=1bc6b785fae836613e4b81fe3c64714e4dc55fb7;hb=7e5607004c3221d55c7992148b2f0d958cf28533;hp=281ee382d2c0f86add90eab561144952a8079886;hpb=579ca009fa70ee40c1f3b52f4c4ddf51387f7b11;p=tpg%2Facess2.git diff --git a/Kernel/drvutil.c b/Kernel/drvutil.c index 281ee382..1bc6b785 100644 --- a/Kernel/drvutil.c +++ b/Kernel/drvutil.c @@ -3,10 +3,85 @@ * Common Driver/Filesystem Helper Functions */ #define DEBUG 0 -#include -#include +#include +#include +#include // === CODE === +// --- Video Driver Helpers --- +Uint64 DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, + tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers) +{ + void *stream = Buffer; + int rem = Length; + int op; + while( rem ) + { + rem --; + op = *(Uint8*)stream; + stream = (void*)((tVAddr)stream + 1); + + if(op > NUM_VIDEO_2DOPS) { + Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Unknown" + " operation %i", op); + } + + if(op*sizeof(void*) > SizeofHandlers) { + Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver does" + " not support op %i", op); + return Length-rem; + } + + switch(op) + { + case VIDEO_2DOP_NOP: break; + + case VIDEO_2DOP_FILL: + if(rem < 12) return Length-rem; + + if(!Handlers->Fill) { + Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver" + " does not support VIDEO_2DOP_FILL"); + return Length-rem; + } + + Handlers->Fill( + Ent, + ((Uint16*)stream)[0], ((Uint16*)stream)[1], + ((Uint16*)stream)[2], ((Uint16*)stream)[3], + ((Uint32*)stream)[2] + ); + + rem -= 12; + stream = (void*)((tVAddr)stream + 12); + break; + + case VIDEO_2DOP_BLIT: + if(rem < 12) return Length-rem; + + if(!Handlers->Blit) { + Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver" + " does not support VIDEO_2DOP_BLIT"); + return Length-rem; + } + + Handlers->Blit( + Ent, + ((Uint16*)stream)[0], ((Uint16*)stream)[1], + ((Uint16*)stream)[2], ((Uint16*)stream)[3], + ((Uint16*)stream)[4], ((Uint16*)stream)[5] + ); + + rem -= 12; + stream = (void*)((tVAddr)stream + 12); + break; + + } + } + return 0; +} + +// --- Disk Driver Helpers --- Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument) { @@ -38,7 +113,7 @@ Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, return leading; } - Buffer += leading; + Buffer = (Uint8*)Buffer + leading; block ++; num = ( Length - leading ) / BlockSize; tailings = Length - num * BlockSize - leading; @@ -64,7 +139,7 @@ Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, { LOG("Reading %i bytes from last block", tailings); block += num; - Buffer += num * BlockSize; + Buffer = (Uint8*)Buffer + num * BlockSize; ret = ReadBlocks(block, 1, tmp, Argument); if(ret != 1) { LEAVE('X', leading + num * BlockSize); @@ -117,7 +192,7 @@ Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, return leading; } - Buffer += leading; + Buffer = (Uint8*)Buffer + leading; block ++; num = ( Length - leading ) / BlockSize; tailings = Length - num * BlockSize - leading; @@ -130,7 +205,7 @@ Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, // Read central blocks if(num) { - LOG("Reading %i blocks", num); + LOG("Writing %i blocks", num); ret = WriteBlocks(block, num, Buffer, Argument); if(ret != num ) { LEAVE('X', leading + ret * BlockSize); @@ -141,9 +216,9 @@ Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, // Read last tailing block if(tailings != 0) { - LOG("Reading %i bytes from last block", tailings); + LOG("Writing %i bytes to last block", tailings); block += num; - Buffer += num * BlockSize; + Buffer = (Uint8*)Buffer + num * BlockSize; // Read ret = ReadBlocks(block, 1, tmp, Argument); if(ret != 1) {