/*
 **************************************************************************
 *
 * Network driver interface for netboot bootrom
 *
 * Module:  system.S86
 * Purpose: system management functions for DOS simulator
 * Entries: dos0D, dos0E, dos19, dos1A, dos25, dos2E, dos2F, dos30,
 *          dos34, dos35, dos37, dos54
 *
 **************************************************************************
 *
 * Copyright (C) 1995-2007 Gero Kuhlmann <gero@gkminix.han.de>
 *
 *  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
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: system.S86,v 1.5 2007/01/06 18:30:48 gkminix Exp $
 *
 */


/*
 **************************************************************************
 *
 * Include assembler macros:
 *
 */
#include <common.i86>
#include <romconfig.i86>
#include "dossim.i86"

.file __FILE__
.line __LINE__





/*
 **************************************************************************
 *
 * Miscellaneous equates:
 *
 */
#define	DEF_DTA		0x0080		/* default DTA address within PSP */
#define	DOS_MAJOR	3		/* simulate DOS major version 3 */
#define	DOS_MINOR	2		/* simulate DOS minor version 2 */
#define	DOS_OEM		0x6E		/* our own "OEM" number */




.line __LINE__
/*
 **************************************************************************
 *
 * BSS segment
 *
 */
	.bss

	.extern	curr_psp		# current PSP segment
	.extern	dos_active		# DOS active flag



/*
 **************************************************************************
 *
 * Start code segment.
 *
 */
	.text

	.global	dos0D
	.global	dos0E
	.global	dos19		# define entry points
	.global	dos1A
	.global	dos25
	.global	dos2E
	.global	dos2F
	.global	dos30
	.global	dos34
	.global	dos35
	.global	dos37
	.global	dos54



/*
 **************************************************************************
 *
 * Dummy for unused functions.
 * Input:  none
 * Output: AL  -  zero
 * Registers changed: AL
 *
 */
dos54:
dos19:
dos0E:

	xor	al,al

dos37:
dos2E:
dos1A:
dos0D:

	ret



/*
 **************************************************************************
 *
 * Set interrupt vector
 * Input:  AL     -  interrupt number
 *         DS:DX  -  pointer to interrupt routine
 * Output: none
 * Registers changed: none
 *
 */
dos25:

	push	fs
	push	ax
	push	bx
	movzx	bx,al
	shl	bx,2
	xor	ax,ax
	mov	fs,ax
	mov	ax,old_ds[bp]
	cli
	mov	fs:[bx + 0],dx		# save new vector
	mov	fs:[bx + 2],ax
	sti
	pop	bx
	pop	ax
	pop	fs
	ret



/*
 **************************************************************************
 *
 * Return current DTA.
 * Input:  none
 * Output: ES:BX  -  address of current DTA
 * Registers changed: BX, ES
 *
 */
dos2F:

	mov	es,[curr_psp]		# return PSP:0080 as the DTA address
	mov	bx,DEF_DTA
	ret



/*
 **************************************************************************
 *
 * Return DOS version number. This will return 3.2 as the simulated
 * version number. It also returns our own "OEM" number.
 * Input:  none
 * Output: AL    -  major version number
 *         AH    -  minor version number
 *         BH    -  OEM number
 *         BL:CX - serial number (always 0)
 * Registers changed: AX, BX, CX
 *
 */
dos30:

	mov	ax,(DOS_MINOR * 256) + DOS_MAJOR
	mov	bx,(DOS_OEM * 256) + 0
	xor	cx,cx
	ret



/*
 **************************************************************************
 *
 * Return address of DOS active byte (undocumented).
 * Input:  none
 * Output: ES:BX  -  pointer to DOS active byte
 * Registers changed:  BX, ES
 *
 */
dos34:

	mov	bx,ds
	mov	es,bx
	mov	bx,offset dos_active
	ret



/*
 **************************************************************************
 *
 * Return interrupt vector.
 * Input:  AL     -  vector number
 * Output: ES:BX  -  pointer to vector routine
 * Registers changed: BX, ES
 *
 */
dos35:

	xor	bx,bx
	mov	es,bx
	movzx	bx,al
	shl	bx,2
	les	bx,es:[bx]		# get interrupt vector
	ret




/*
 **************************************************************************
 *
 */
	.end

