#include "lvm_int.h"
// === PROTOTYPES ===
+ int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest);
+ int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source);
// === CODE ===
// --------------------------------------------------------------------
// Managment / Initialisation
// --------------------------------------------------------------------
-int LVM_AddVolume(const char *Name, int FD)
+int LVM_AddVolumeVFS(const char *Name, int FD)
{
- // Make dummy volume descriptor (for the read code)
+ return LVM_AddVolume(Name, (void*)FD, LVM_int_VFSReadEmul, LVM_int_VFSWriteEmul);
+}
+
+int LVM_AddVolume(const char *Name, void *Ptr, tLVM_ReadFcn Read, tLVM_WriteFcn Write)
+{
+ tLVM_Vol dummy_vol;
+// tLVM_Vol *real_vol;
+ dummy_vol.Ptr = Ptr;
+ dummy_vol.Read = Read;
+ dummy_vol.Write = Write;
+
// Determine Type
// Type->CountSubvolumes
// --------------------------------------------------------------------
size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest)
{
- size_t rv;
- rv = VFS_ReadAt(
- Volume->BackingDescriptor,
- BlockNum * Volume->BlockSize,
- BlockCount * Volume->BlockSize,
- Dest
- );
- return rv / Volume->BlockSize;
+ return Volume->Read(Volume->Ptr, BlockNum, BlockCount, Dest);
}
size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src)
{
+ return Volume->Write(Volume->Ptr, BlockNum, BlockCount, Src);
+}
+
+int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest)
+{
+ size_t blocksize;
size_t rv;
- rv = VFS_WriteAt(
- Volume->BackingDescriptor,
- BlockNum * Volume->BlockSize,
- BlockCount * Volume->BlockSize,
- Src
- );
- return rv / Volume->BlockSize;
+
+ blocksize = 512; // TODO: Don't assume
+
+ rv = VFS_ReadAt( (int)Arg, BlockStart * blocksize, BlockCount * blocksize, Dest );
+ rv /= blocksize;
+ return rv;
+}
+
+int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source)
+{
+ size_t blocksize;
+ size_t rv;
+
+ blocksize = 512; // TODO: Don't assume
+
+ rv = VFS_WriteAt( (int)Arg, BlockStart * blocksize, BlockCount * blocksize, Source );
+ rv /= blocksize;
+ return rv;
}
memcpy( Buffer, info->FileData + Offset, Length );
+ VFS_MarkAvaliable( &info->Node, 0 );
+
return Length;
}
static const char *csaDevIOCtls[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL};
int HID_Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data)
{
+ tJoystick_NumValue *numval = Data;
+ tHID_Mouse *info = Node->ImplPtr;
switch(ID)
{
BASE_IOCTLS(DRV_TYPE_JOYSTICK, "USBMouse", 0x050, csaDevIOCtls);
+
+ case JOY_IOCTL_GETSETAXISLIMIT:
+ if( !numval || !CheckMem(numval, sizeof(*numval)) )
+ return -1;
+ if(numval->Num < 0 || numval->Num >= MAX_AXIES)
+ return 0;
+ if(numval->Value != -1)
+ info->AxisLimits[numval->Num] = numval->Value;
+ return info->AxisLimits[numval->Num];
+
+ case JOY_IOCTL_GETSETAXISPOSITION:
+ if( !numval || !CheckMem(numval, sizeof(*numval)) )
+ return -1;
+ if(numval->Num < 0 || numval->Num >= MAX_AXIES)
+ return 0;
+ if(numval->Value != -1)
+ info->Axies[numval->Num].CursorPos = numval->Value;
+ return info->Axies[numval->Num].CursorPos;
}
return -1;
}
Sint32 _ReadBits(void *Data, int Offset, int Length)
{
int dest_ofs = 0;
+ int rem = Length;
Uint32 rv = 0;
Uint8 *bytes = (Uint8*)Data + Offset / 8;
rv = (*bytes >> Offset);
dest_ofs = Offset & 7;
- Length -= Offset & 7;
+ rem = Length - (Offset & 7);
bytes ++;
}
// Body bytes
- while( Length >= 8 )
+ while( rem >= 8 )
{
rv |= *bytes << dest_ofs;
dest_ofs += 8;
- Length -= 8;
+ rem -= 8;
bytes ++;
}
- if( Length )
+ if( rem )
{
- rv |= (*bytes & ((1 << Length)-1)) << dest_ofs;
-
+ rv |= (*bytes & ((1 << rem)-1)) << dest_ofs;
}
// Do sign extension
info = USB_GetDeviceDataPtr(Dev);
if( !info ) return ;
- Log_Debug("USBMouse", "info = %p", info);
-
ofs = 0;
for( int i = 0; i < info->nMappings; i ++ )
{
return ;
value = _ReadBits(Data, ofs, info->Mappings[i].BitSize);
+ LOG("%i+%i: value = %i", ofs, info->Mappings[i].BitSize, value);
ofs += info->Mappings[i].BitSize;
if( dest == 0xFF ) continue ;
info->Axies[i].CursorPos = newpos;
}
- Log_Debug("USBMouse", "New Pos (%i,%i,%i)",
- info->Axies[0].CursorPos, info->Axies[1].CursorPos, info->Axies[2].CursorPos
- );
+// Log_Debug("USBMouse", "New Pos (%i,%i,%i)",
+// info->Axies[0].CursorPos, info->Axies[1].CursorPos, info->Axies[2].CursorPos
+// );
+ VFS_MarkAvaliable( &info->Node, 1 );
}
// ----------------------------------------------------------------------------
info->FileHeader = (void*)info->FileData;
info->Axies = (void*)(info->FileHeader + 1);
info->Buttons = (void*)(info->Axies + MAX_AXIES);
+ info->FileHeader->NAxies = MAX_AXIES;
+ info->FileHeader->NButtons = MAX_BUTTONS;
+
+ for( int i = 0; i < MAX_AXIES; i ++ ) {
+ info->Axies[i].MinValue = -10;
+ info->Axies[i].MaxValue = 10;
+ }
+
LOG("Initialised new mouse at %p", info);