//  Copyright (c) 2025 Jakub Filipowicz <jakubf@gmail.com>
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc.,
//  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef DEV2_H
#define DEV2_H

#include <stdbool.h>

enum dev_cmd_status {
	DEV_STATUS_OK = 0,
	DEV_STATUS_ERR,
	DEV_STATUS_BUSY,
	DEV_STATUS_INVALID,
	DEV_STATUS_NOMEDIUM,
	DEV_STATUS_SEEKERR,
	DEV_STATUS_WRPROTECT,
	DEV_STATUS_WRERR,
	DEV_STATUS_RDERR,
};

typedef struct em400_dev em400_dev_t;

typedef void (*dev_noarg_f)(em400_dev_t *dev);
typedef int (*dev_write_f)(em400_dev_t *dev, char c);

typedef unsigned (*dev_slot_cnt_f)(em400_dev_t *dev);
typedef bool (*dev_can_eject_f)(em400_dev_t *dev, unsigned slot);
typedef int (*dev_load_f)(em400_dev_t *dev, unsigned slot, const char *image_name);
typedef int (*dev_eject_f)(em400_dev_t *dev, unsigned slot);
typedef const char * (*dev_image_f)(em400_dev_t *dev, unsigned slot);

struct em400_dev {
	unsigned type;						// device type
	unsigned slot_count;				// media image slot count

	dev_noarg_f reset;
	dev_noarg_f shutdown;
	dev_write_f write;

	dev_can_eject_f can_eject;			// can the image be ejected now
	dev_load_f load;					// load new image into a slot
	dev_eject_f eject;					// eject image from the slot
	dev_image_f image;					// get the name of image loaded into a slot
};

#endif
