1 | /* CrO2 datassette emulator
|
---|
2 | * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
|
---|
3 | *
|
---|
4 | * Distributed under the terms of the MIT licence.
|
---|
5 | *
|
---|
6 | * Handles device communication through libusb
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include <stdint.h>
|
---|
10 | #include <string.h>
|
---|
11 |
|
---|
12 | class Tape;
|
---|
13 |
|
---|
14 | class Device
|
---|
15 | {
|
---|
16 | public:
|
---|
17 | // Implemented in subclasses object files. Only one of them is linked
|
---|
18 | // and takes care of instanciating itself.
|
---|
19 | static Device& getDevice() throw(const char*);
|
---|
20 |
|
---|
21 | // High-level layer (will call functions below)
|
---|
22 | void write(const Tape& file) throw (const char*);
|
---|
23 |
|
---|
24 | // Low-level layer (to be implemented by subclasses
|
---|
25 | virtual int read(uint8_t* buffer, size_t max) = 0;
|
---|
26 | // Fill the buffer with data from device
|
---|
27 | virtual int write(const uint8_t* buffer, size_t size, int blktype) = 0;
|
---|
28 | virtual uint8_t getStatus() = 0;
|
---|
29 | // Get the status word from the device
|
---|
30 |
|
---|
31 | protected:
|
---|
32 | /* These are the vendor specific commands implemented by our USB device */
|
---|
33 | static const int PSCMD_CONFIG = 0;
|
---|
34 | static const int PSCMD_GET = 1;
|
---|
35 | static const int PSCMD_PUT = 2;
|
---|
36 | static const int PSCMD_STATUS = 3;
|
---|
37 |
|
---|
38 | static const uint32_t vid;
|
---|
39 | static const uint32_t pid;
|
---|
40 | static const char* vendor;
|
---|
41 | static const char* product;
|
---|
42 | private:
|
---|
43 | static bool initOnce;
|
---|
44 | static Device* instance;
|
---|
45 | };
|
---|