/*
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 */

#ifndef _EMU_BIOS_H
#define _EMU_BIOS_H

#include "emu_defs.h"

#define INT2F_IDLE_MAGIC	0x1680

#define bios_base_addr_com1              0x400
#define bios_base_addr_com2              0x402
#define bios_base_addr_com3              0x404
#define bios_base_addr_com4              0x406
#define bios_base_addr_lpt1              0x408
#define bios_base_addr_lpt2              0x40a
#define bios_base_addr_lpt3              0x40c
#define bios_extended_bios               0x40e
#define bios_configuration               0x410
/* pcjr byte                             0x412 */
#define bios_memory_size                 0x413
/* reserved                              0x415 */
#define bios_keyboard_state              0x417
#define bios_keyboard_leds               0x418
#define bios_keyboard_token              0x419
/* used for keyboard input with Alt-Number */
#define bios_keyboard_buffer_head        0x41a
#define bios_keyboard_buffer_tail        0x41c
#define bios_keyboard_buffer             0x41e
#define bios_drive_recalib_stat          0x43e
#define bios_drive_floppy_stat           0x43f
#define bios_motor_shutoff               0x440
#define bios_disk_status                 0x441
#define bios_fdc_result_buffer           0x442
#define bios_video_mode                  0x449
#define bios_screen_cols                 0x44a
#define bios_video_mem_used              0x44c
#define bios_video_mem_addr              0x44e

#define bios_cursor_x_position(screen)  (0x450 + 2*(screen))
#define bios_cursor_y_position(screen)  (0x451 + 2*(screen))

#define bios_cursor_shape                0x460
#define bios_cursor_last_line            0x460
#define bios_cursor_first_line           0x461
#define bios_current_screen_page         0x462
#define bios_video_port                  0x463
#define bios_vdu_control                 0x465
#define bios_vdu_color_register          0x466
/* 0x467-0x468 is reserved */
#define bios_timer                       0x46c
#define bios_timer_overflow              0x470
#define bios_ctrl_break_flag             0x471
#define bios_ctrl_alt_del_flag           0x472
#define bios_hdrive_stat                 0x474
#define bios_hdrive_count                0x475
#define bios_xt_fdisk_ctrl               0x476
#define bios_hdrive_port_off             0x477
#define bios_lpt1_timeout                0x478
#define bios_lpt2_timeout                0x479
#define bios_lpt3_timeout                0x47a
#define bios_lpt4_timeout                0x47b
#define bios_com1_timeout                0x47c
#define bios_com2_timeout                0x47d
#define bios_com3_timeout                0x47e
#define bios_com4_timeout                0x47f
#define bios_keyboard_buffer_start       0x480
#define bios_keyboard_buffer_end         0x482

#define bios_screen_rows                 0x484
#define bios_font_height                 0x485

#define bios_video_info_0                0x487
#define bios_video_info_1                0x488
#define bios_video_info_2                0x489
#define bios_video_combo                 0x48a

#define bios_floppy_readrate             0x48b
#define bios_hdisk_status                0x48c
#define bios_hdisk_error                 0x48d
#define bios_hdisk_busy                  0x48e
#define bios_combo_disk_card             0x48f
#define bios_media_state                 0x490
#define bios_floppy0_track               0x494
#define bios_floppy1_track               0x495

#define bios_keyboard_flags2             0x496
#define bios_usr_wait_flg_ptr            0x498
#define bios_usr_wait_rtc                0x49c
#define bios_rtc_flag                    0x4a0
#define bios_lana_flags                  0x4a1
#define bios_lana_status0                0x4a2
#define bios_lana_status1                0x4a3
#define bios_hdisk_int_vec               0x4a4
#define bios_video_saveptr               0x4a8
#define bios_print_screen_flag           0x500


#define BIOS_BASE_ADDRESS_COM1          0x400
#define BIOS_BASE_ADDRESS_COM2          0x402
#define BIOS_BASE_ADDRESS_COM3          0x404
#define BIOS_BASE_ADDRESS_COM4          0x406
#define BIOS_ADDRESS_LPT1               0x408
#define BIOS_ADDRESS_LPT2               0x40a
#define BIOS_ADDRESS_LPT3               0x40c
/* 0x40e is reserved */
#define BIOS_CONFIGURATION              0x410
/* 0x412 is reserved */
#define BIOS_MEMORY_SIZE                0x413
/* #define bios_expansion_memory_size      (*(unsigned int   *) 0x415) */
#define BIOS_KEYBOARD_STATE             0x417
#define BIOS_KEYBOARD_LEDS              0x418
#define BIOS_KEYBOARD_TOKEN             0x419
/* used for keyboard input with Alt-Number */
#define BIOS_KEYBOARD_BUFFER_HEAD       0x41a
#define BIOS_KEYBOARD_BUFFER_TAIL       0x41c
/* #define bios_keyboard_buffer            (*(unsigned int   *) 0x41e) */
#define BIOS_DRIVE_ACTIVE               0x43e
#define BIOS_DRIVE_RUNNING              0x43f
#define BIOS_MOTOR_NACHLAUFZEIT         0x440
#define BIOS_DISK_STATUS                0x441
/* #define bios_fdc_result_buffer           0x442) */
#define BIOS_VIDEO_MODE                 0x449
#define BIOS_SCREEN_COLUMNS             0x44a
#define BIOS_VIDEO_MEMORY_USED          0x44c
#define BIOS_VIDEO_MEMORY_ADDRESS       0x44e

#define set_bios_cursor_x_position(screen, val) \
                        WRITE_BYTE(0x450 + 2*(screen), (val))
#define get_bios_cursor_x_position(screen) \
                        READ_BYTE(0x450 + 2*(screen))


#define set_bios_cursor_y_position(screen, val) \
                        WRITE_BYTE(0x451 + 2*(screen), (val))
#define get_bios_cursor_y_position(screen) \
                        READ_BYTE(0x451 + 2*(screen))


#define BIOS_CURSOR_SHAPE               0x460
#define BIOS_CURSOR_LAST_LINE           0x460
#define BIOS_CURSOR_FIRST_LINE          0x461
#define BIOS_CURRENT_SCREEN_PAGE        0x462
#define BIOS_VIDEO_PORT                 0x463
#define BIOS_VDU_CONTROL                0x465
#define BIOS_VDU_COLOR_REGISTER         0x466
/* 0x467-0x468 is reserved */
#define BIOS_TIMER                      0x46c
#define BIOS_24_HOURS_FLAG              0x470
#define BIOS_KEYBOARD_FLAGS             0x471
#define BIOS_CTRL_ALT_DEL_FLAG          0x472
/* 0x474-0x477 is reserved */
#define BIOS_LPT1_TIMEOUT               0x478
#define BIOS_LPT2_TIMEOUT               0x479
#define BIOS_LPT3_TIMEOUT               0x47a
/* 0x47b is reserved */
#define BIOS_COM1_TIMEOUT               0x47c
#define BIOS_COM2_TIMEOUT               0x47d
/* 0x47e is reserved */
/* 0x47f-0x4ff is unknow for me */
#define BIOS_KEYBOARD_BUFFER_START      0x480
#define BIOS_KEYBOARD_BUFFER_END        0x482

#define BIOS_ROWS_ON_SCREEN_MINUS_1     0x484
#define BIOS_FONT_HEIGHT                0x485

#define BIOS_VIDEO_INFO_0               0x487
#define BIOS_VIDEO_INFO_1               0x488
#define BIOS_VIDEO_INFO_2               0x489
#define BIOS_VIDEO_COMBO                0x48a

#define BIOS_KEYBOARD_FLAGS2            0x496
#define BIOS_PRINT_SCREEN_FLAG          0x500

#define BIOS_VIDEO_SAVEPTR              0x4a8


#define BIT(x)  	(1<<x)

/*
 * int 11h config single bit tests
 */

#define CONF_FLOP	BIT(0)
#define CONF_MATHCO	BIT(1)
#define CONF_MOUSE	BIT(2)
#define CONF_DMA	BIT(8)
#define CONF_GAME	BIT(12)

/*
 * don't use CONF_NSER with num > 4, CONF_NLPT with num > 3, CONF_NFLOP
 * with num > 4
 */
#define CONF_NSER(c,num)	{c&=~(BIT(9)|BIT(10)|BIT(11)); c|=(num<<9);}
#define CONF_NLPT(c,num) 	{c&=~(BIT(14)|BIT(14)); c|=(num<<14);}
#define CONF_NFLOP(c,num) 	{c&=~(CONF_FLOP|BIT(6)|BIT(7)); \
				   if (num) c|=((num-1)<<6)|CONF_FLOP;}

EXTERN Bit16u   configuration INIT(0);	/* The virtual BIOS-configuration */

extern void     bios_init(void);
extern void     bios_reset(void);
extern void     bios_term(void);

extern void     bios_write(Bit8u*);     /* fake write-protection of BIOS */

extern void     bios_int_init(void);
extern void     bios_int_reset(void);
extern void     bios_mem_init(void);
extern void     bios_mem_reset(void);

extern void     int10(Bit8u);
extern void     int13(Bit8u);
extern void     int14(Bit8u);
extern void     int17(Bit8u);

extern void     bios_f000(void);
extern void     bios_f000_end(void);
extern void     DPMI_dummy_start(void);
extern void     DPMI_dummy_end(void);
extern void     DPMI_dpmi_init(void);
extern void     DPMI_return_from_dos(void);
extern void     DPMI_return_from_dos_exec(void);
extern void     DPMI_return_from_dosint(void);
extern void     DPMI_return_from_realmode(void);
extern void     DPMI_return_from_dos_memory(void);
extern void     DPMI_realmode_callback(void);
extern void     DPMI_mouse_callback(void);
extern void     DPMI_raw_mode_switch(void);
extern void     DPMI_save_restore(void);
extern void     DPMI_API_extension(void);
extern void     DPMI_return_from_pm(void);
extern void     DPMI_return_from_exception(void);
extern void     DPMI_return_from_rm_callback(void);
extern void     DPMI_return_from_mouse_callback(void);
extern void     DPMI_exception(void);
extern void     DPMI_interrupt(void);

/*
 * HLT block
 */

#define BIOS_HLT_BLK       0xfc000
#define BIOS_HLT_BLK_SIZE  0x01000

#endif /* _EMU_BIOS_H */
