#include "FD.h"


extern const
{
	// K1-bus:
	bool	option_a5 = true;		// 1 => use A5 for rd=1/wr=0 selection, use A8 for K1-bus A5
						 			// used when use of WR results in spikes on the k1-bus strobe lines

	uint8 	bSIO_SELECT = 1; 		// the SIO board is jumpered for D1
	uint8	bIDE_SELECT = 2;		// the IDE board uses D2

	uint8	mSIO_SELECT = 0xff - 1<<bSIO_SELECT;
	uint8	mIDE_SELECT = 0xff - 2<<bSIO_SELECT;
};


type FD = {};
//type Device = {};
type BlockDevice = {};
type IdeBlockDevice = {};
type I2cBlockDevice = {};
type SerialDevice = {};
type Range = {};
type File = {};
type FD_Handlers = {};


extern
{
	uint8 	k1_irpt_mask;
	uint8  	sysflags;
	uint32 	systemtime;	// system time: milli seconds since boot
	uint16 	period;		// adjustment counter
	uint32 	timestamp;	// world time: seconds since 1.1.2000
	uint16 	tsmsec;		// adjustment counter
	char* 	romdate;	// 0-delimited
	char* 	romtime;	// 0-delimited

	FD[]	 		devs;
	File[] 			fds;
	FD 				stdin;
	FD 				stdout;
	SerialDevice	sio1A;
	SerialDevice	sio1B;
	IdeBlockDevice 	ide2A;
	IdeBlockDevice 	ide2B;
	I2cBlockDevice 	sio1rom;		// sio i2c eeprom
	I2cBlockDevice 	ide2rom;		// ide i2c eeprom

	OSErr 	errno;

	void  	di			()
	void  	ei			();
	void	ei_all		(); 			// z80.ei and k1-bus.wr_irpt
	void  	select		(uint8)
	uint8 	in			(uint8)
	void	out			(uint8,uint8)
	void	wait		()				// until next irpt
//	void	waitdelay	(float);
//	void	busywait	(uint);			// µsecs
	void	memcpy		( void* z, void* q, uint cnt )
	void	memset		( void* z, uint c, uint cnt )
	void	memclr		( void* z, uint cnt )
	void	set_red_led 	();
	void	set_yellow_led 	();
	void	set_both_leds 	();
	void	clear_both_leds	();
	OSErr	lock_eeprom   	();
	OSErr	unlock_eeprom	();
	void	write_eeprom(void* q, void* z, uint16 cnt);
	void	download_firmware();			// does not return except if user bails out

	void 	abort		()					= opcode abort;	// prints VM's PC to sio1
	void	panic		(uint8 blinkcode);
	void	assert1		(bool);		// on failure the current pc (register bc) is printed
	void 	assert0 	(bool);

    uint 	mem_get_free();
	uint 	mem_get_free_total();
 //	void 	copy(uint[]¢ q, uint qi, uint[]¢ z, uint zi, uint n);
 //	void 	copy(uint8[]¢ q, uint qi, uint8[]¢ z, uint zi, uint n);


	void  download_firmware();
	uint8 fd_function_not_supported();	// returns error 1 = parameter error / function not supported
	void  sio_init_channel(SerialDevice¢, str¢ name, uint8 devselbit, uint8 ch);
	void  ide_init_blockdevice(BlockDevice¢);
	void  i2c_init_blockdevice(BlockDevice¢);
};







