/*
    SPHINX Programming (C) 1993.
    NAME:  WRITE.H--
    DESCRIPTION:  This file contains a collection of procedures for writing
                  text to the screen, all via the BIOS interrupt 0x10.
    LAST MODIFIED:  28 Nov 1993
    PROCEDURES DEFINED IN THIS FILE:
        : void BEEP()
        : word GETXY()
        : void GOTOXY(byte xloc,byte yloc)
        : void WINDOWDOWN(numoflines,attribute,upperleftloc,lowerrightloc)
        : void WINDOWUP(numoflines,attribute,upperleftloc,lowerrightloc)
        : void WRITE(byte character)
        : void WRITEDIGITS(word_value)
        : void WRITEDWORD(dword dword_value)
        : void WRITEHEX(word_value)
        : void WRITEINT(int int_value)
        : void WRITELN()
        : void WRITELONG(long long_value)
        : void WRITESTR(string)
        : void WRITEWORD(word_value)
*/



: void BEEP ()  
/* Outputs a beep from the internal speaker by use of BIOS video interrupt.
*/
{BH = 0x00;
AX = 0x0E07;
$ INT 0x10
}       
/* returns:  AX = 0xE07
             BH = 0
*/


: void GOTOXY ()  /* AL = xloc, BL = yloc */
/* Sets the cursor postion to the location given by xloc and yloc.
   Location values start at zero.
*/
{
DL = AL;
DH = BL;
BH = 0;
AH = 2;
$INT 0x10
}
/* RETURNS:  AX,BX,DX = undefined.
*/


: word GETXY ()
/* Gets the cursor postion on video page zero.
*/
{
BH = 0;
AH = 3;
$INT 0x10
AX = DX;
}
/* RETURNS:  BH = 0
             AH = DH = cursor row
             AL = DL = cursor column
             CH = cursor start line
             CL = cursor end line
*/


: void WRITE ()  /* AL = character to write to screen at cursor */
/* Writes the specified character at the cursor and then advances the
   cursor.  Bell, CR, and LF are treated as special characters and
   supported.
*/
{
BX = 0x0007;
AH = 0xE;
$ INT 0x10
}       
/* returns:  AH = 0xE
             BX = 7
*/



: void WRITELN ()  
/* Moves the cursor to the beginning of the next line */
{
BX = 0x0007;
AX = 0x0E0D;
$ INT 0x10
AL = 0xA;
$ INT 0x10
}       
/* returns:  AX = 0xE0A
             BX = 7
*/


: void WRITESTR ()  /* AX = offset address of string to write at cursor */
{
BX = 0x0007;
$ PUSH SI
SI = AX;
AH = 0xE;
UP:
  $ LODSB
  $ CMP AL,0
  $ JZ DOWN
  $ INT 0x10
  $ JMP SHORT UP
DOWN:
  $ POP SI
}       
/* returns:  AX = undefined
             BX = 7
*/



: void WRITEWORD ()  /* AX = word value to write to screen at cursor */
{
BX = 0x0007;
$ CMP AX,10000
$ JNB DOWN1                               
$ CMP AX,1000
$ JNB DOWN2                               
$ CMP AX,100
$ JNB DOWN3                               
$ CMP AX,10
$ JNB DOWN4
$ JMP SHORT DOWN5
DOWN1:
  DX = 0;
  CX = 10000;
  $ DIV CX
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AX = DX;
DOWN2:
  DX = 0;
  CX = 1000;
  $ DIV CX
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AX = DX;
DOWN3:
  CL = 100;
  $ DIV CL
  DL = AH;
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AL = DL;
  AH = 0;
DOWN4:
  CL = 10;
  $ DIV CL
  DL = AH;
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AL = DL;
DOWN5:
  AL += '0';
  AH = 0xE;
  $ INT 0x10
}       
/* returns:  AX,CX,DX = undefined
             BX = 7
*/



: void WRITEINT ()  /* AX = int value to write to screen at cursor */
{
BX = 0x0007;
IF( int AX < 0 )
    {DX = AX;
    AX = 0x0E2D;
    $ INT 0x10     
    AX = DX;
    -AX;
    }
$ CMP AX,10000
$ JNB DOWN1                               
$ CMP AX,1000
$ JNB DOWN2                               
$ CMP AX,100
$ JNB DOWN3                               
$ CMP AX,10
$ JNB DOWN4
$ JMP SHORT DOWN5
DOWN1:
  DX = 0;
  CX = 10000;
  $ DIV CX
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AX = DX;
DOWN2:
  DX = 0;
  CX = 1000;
  $ DIV CX
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AX = DX;
DOWN3:
  CL = 100;
  $ DIV CL
  DL = AH;
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AL = DL;
  AH = 0;
DOWN4:
  CL = 10;
  $ DIV CL
  DL = AH;
  AL += '0';
  AH = 0xE;
  $ INT 0x10
  AL = DL;
DOWN5:
  AL += '0';
  AH = 0xE;
  $ INT 0x10
}       
/* returns:  AX,CX,DX = undefined
             BX = 7
*/


: void WRITEDWORD ()  /* EAX = dword value to write to screen at cursor */
{
DI = FALSE;
SI = 9;
ECX = 1000000000;
loop(SI)
    {
    EDX = 0;
    $ DIV ECX;
    IF( AL > 0 )
        DI = TRUE;
    IF( DI == TRUE )
        {AL += '0';
        AH = 0xE;
        BX = 0x0007;
        $ INT 0x10
        }
    EBX = EDX;
    EAX = ECX / 10;
    ECX = EAX;
    EAX = EBX;
    }

AL += '0';
AH = 0xE;
BX = 0x0007;
$ INT 0x10
}       
/* returns:  EAX,EBX,ECX,EDX,DI = undefined
             SI = 0
*/


: void WRITELONG ()  /* EAX = long value to write to screen at cursor */
{
IF( long EAX < 0 )
    {EDX = EAX;
    AX = 0x0E2D;
    BX = 0x0007;
    $ INT 0x10     
    EAX = EDX;
    -EAX;
    }
DI = FALSE;
SI = 9;
ECX = 1000000000;
loop(SI)
    {
    EDX = 0;
    $ DIV ECX;
    IF( AL > 0 )
        DI = TRUE;
    IF( DI == TRUE )
        {AL += '0';
        AH = 0xE;
        BX = 0x0007;
        $ INT 0x10
        }
    EBX = EDX;
    EAX = ECX / 10;
    ECX = EAX;
    EAX = EBX;
    }

AL += '0';
AH = 0xE;
BX = 0x0007;
$ INT 0x10
}       
/* returns:  EAX,EBX,ECX,EDX,DI = undefined
             SI = 0
*/


: void WRITEDIGITS ()  /* AX = word value to display all digits at cursor */
{
BX = 0x0007;
DX = 0;
CX = 10000;
$ DIV CX
AL += '0';
AH = 0xE;
$ INT 0x10
AX = DX;
DX = 0;
CX = 1000;
$ DIV CX
AL += '0';
AH = 0xE;
$ INT 0x10
AX = DX;
CL = 100;
$ DIV CL
DL = AH;
AL += '0';
AH = 0xE;
$ INT 0x10
AL = DL;
AH = 0;
CL = 10;
$ DIV CL
DL = AH;
AL += '0';
AH = 0xE;
$ INT 0x10
AL = DL;
AL += '0';
AH = 0xE;
$ INT 0x10
}       
/* returns:  AX,CX,DX = undefined
             BX = 7
*/


: void WINDOWDOWN () // (numoflines,attribute,upperleftloc,lowerrightloc);
{AH = 6;
BH = BL;
$INT 0x10
}


: void WINDOWUP () // (numoflines,attribute,upperleftloc,lowerrightloc);
{AH = 7;
BH = BL;
$INT 0x10
}


: void WRITEHEX ()  /* AX = word value to write */
{
BX = 7;
DX = AX;

$ SHR AX,12
IF( AL >= 10 )
   AL += 'A'-10-'0';
AL += '0';
AH = 0xE;
$ INT 0x10
   
AX = DX;
$ SHR AX,8
AL &= 0x0F;
IF( AL >= 10 )
   AL += 'A'-10-'0';
AL += '0';
AH = 0xE;
$ INT 0x10
   
AX = DX;
$ SHR AX,4
AL &= 0x0F;
IF( AL >= 10 )
   AL += 'A'-10-'0';
AL += '0';
AH = 0xE;
$ INT 0x10

AL = DL;
AL &= 0x0F;
IF( AL >= 10 )
   AL += 'A'-10-'0';
AL += '0';
AH = 0xE;
$ INT 0x10
}


/* end of WRITE.H-- */