!************************************************************************** !* !* Boot-ROM-Code to load an operating system across a TCP/IP network. !* !* Module: misc.S !* Purpose: Routines for different things !* Entries: _random, _far2long, _long2far, _getds, prnchar !* !************************************************************************** !* !* Copyright (C) 1995-2003 Gero Kuhlmann !* !* 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: misc.S,v 1.4 2003/01/25 23:29:41 gkminix Exp $ !* ! !************************************************************************** ! ! Include assembler macros: ! #include #include "libpriv.inc" ! !************************************************************************** ! ! Definitions for the random number generator: ! RANDLOW equ $4E35 ! Low multiplication value RANDHIGH equ $015A ! High multiplication value RANDMUL equ $015A4E35 ! everything together for 386 RANDADD equ 23968 ! !************************************************************************** ! ! BSS segment: ! .bss .lcomm rseed,4 ! seed for random number ! !************************************************************************** ! ! Start code segment. ! .text public _random ! define entry points public _far2long public _long2far #ifndef OPT386 public _getds #endif public prnchar extrn _get_ticks ! !************************************************************************** ! ! Return a integer random number ! Input: 1. Arg - number mask ! Output: random number ! _random: penter (0) #ifdef IS386 mov eax,[rseed] ! check if the seed has already been or eax,eax ! set #else mov dx,word ptr [rseed+0] mov ax,dx ! check if the seed has already been or dx,word ptr [rseed+2] ! set #endif jnz rand1 ! if not set it by reading the timer call near _get_ticks ! tick count #ifdef OPT386 mov [rseed],eax #else mov word ptr [rseed+0],ax mov word ptr [rseed+2],dx #endif rand1: #ifdef IS386 mov eax,#RANDMUL ! multiply the seed with a magic number mul dword ptr [rseed] add eax,#RANDADD ! add another magic number shr eax,#1 ! shift number right one bit mov [rseed],eax ! save new seed getlarg (ebx,0,word) ! get mask and eax,ebx ! prepare return value #else mov dx,#RANDHIGH mul dx ! multiply the seed with a magic number mov bx,ax mov ax,#RANDLOW mul word ptr [rseed+0] mov cx,ax add bx,dx mov ax,#RANDLOW mul word ptr [rseed+2] add bx,ax add cx,#RANDADD ! add another magic number adc bx,#0 shr bx,#1 ! shift number right one bit rcr cx,#1 mov word ptr [rseed+0],cx ! save new seed number mov word ptr [rseed+2],bx getcarg (ax,0) ! get mask and ax,bx ! prepare return value #endif pleave ret ! !************************************************************************** ! ! Convert far pointer into linear long number ! Input: 1. Arg - far pointer ! Output: linear address ! _far2long: penter (0) #ifdef OPT386 getlarg (eax,0,word) ! get far pointer getlarg (edx,1,word) shl edx,#4 add eax,edx #else getcarg (dx,1) ! get far pointer getcarg (ax,0) mov bx,dx shift (shr,dx,12) ! convert into linear address shift (shl,bx,4) add ax,bx adc dx,#0 #endif pleave ret ! !************************************************************************** ! ! Convert linear long number into far pointer ! Input: 1. Arg - long linear address ! Output: far pointer ! _long2far: penter (0) #ifdef OPT386 getcarg (eax,0) ! get long number shl eax,#12 ! convert into far pointer shr ax,#12 #else getcarg (dx,1) ! get long number getcarg (ax,0) mov bx,ax and ax,#$000F shift (shr,bx,4) ! convert into far pointer shift (shl,dx,12) add dx,bx #endif pleave ret ! !************************************************************************** ! ! Return data segment. ! Input: none ! Output: data segment ! #ifndef OPT386 _getds: mov ax,ds ret #endif ! !************************************************************************** ! ! Print a character onto the console screen ! Input: AL - character ! Output: none ! Registers changed: AX ! prnchar: push bx mov ah,#$0E xor bh,bh int INT_VIDEO ! use the BIOS to print character pop bx ret ! !************************************************************************** ! end