summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/bcreader.h
blob: 95e49c4715b6cffa6d505ccc7b58ffda08d7265d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/*********************************************************************

    bcreader.h

    Generic barcode reader emulation.

*********************************************************************/

#ifndef __BCREADER_H_
#define __BCREADER_H_

#define MCFG_BARCODE_READER_ADD( _tag ) \
	MCFG_DEVICE_ADD( _tag, BARCODE_READER, 0 )

#define MCFG_BARCODE_READER_REMOVE( _tag ) \
	MCFG_DEVICE_REMOVE( _tag )


// ======================> barcode_reader_device

class barcode_reader_device : public device_t
{
public:
	// construction/destruction
	barcode_reader_device(const machine_config &mconfig, std::string tag, device_t *owner, UINT32 clock);

	void write_code(const char *barcode, int len);
	int get_pending_code() { return m_new_code; }
	int get_byte_length() { return m_byte_length; }
	UINT8 read_code();
	int read_pixel();

	// TODO: add checksum validation!
	bool is_valid(int len) { return (len != 12 && len != 13 && len != 8) ? FALSE : TRUE; }
	void decode(int len);

protected:
	// device-level overrides
	virtual void device_start() override;

	UINT8 m_byte_data[13];
	UINT8 m_pixel_data[100];
	int m_byte_length;
	int m_pixel_length;
	int m_byte_count;
	int m_pixel_count;
	int m_new_code;
};


// device type definition
extern const device_type BARCODE_READER;

// device type iterator
typedef device_type_iterator<&device_creator<barcode_reader_device>, barcode_reader_device> barcode_reader_device_iterator;


#endif