{ lang run-time header file }

proc char hi(int a)
  asm
    mov  ax, [a]
    mov  al, ah
    xor  ah, ah
  end
end

proc char lo(int a)
  asm
    mov  ax, [a]
    xor  ah, ah
  end
end

public proc putchar(char a)
  asm
    mov  ah, 2
    mov  dl, [a]
    int  0x21
  end
end

public proc putstr(word a)
  while lo(^a)>0
    putchar(^a)
    a+=1
  end
end

public proc putcrlf
  putchar(13)
  putchar(10)
end

public proc puthex(int a)
char i
begin
  if a>0
    i=a%16
    if i<10
      i+='0'
    else
      i+='A'-10
    end
    puthex(a/16)
    putchar(i)
  end
end

public proc putword(word a)
  if a>0
    putword(a/10)
    putchar('0'+a%10)
  end
end

public proc putint(int a)
  if a==0
    putchar('0')
    ret
  elsif a>0x7fff
    putchar('-')
    a=-a
  end
  putword(a)
end

public proc halt(char a)
  asm
    mov  ah, 0x4C
    mov  al, [a]
    int  0x21
  end
end

public proc strlen(word a)
int i
begin
  i=0
  while lo(^(a+i))>0
    i+=1
  end
  ret(i)
end

public proc char getchar
  asm
    mov  ah, 0x01
    int  0x21
    xor  ah, ah
  end
end

public proc char getch
  asm
    mov  ah, 0x08
    int  0x21
    xor  ah, ah
  end
end

public proc getstr(int adr len)
int count
char s
begin
  if len==0
    len=strlen(adr)
  end
  count=1
  s=0
  while s<>13&count<len
    s=getchar
    if s<>13
      adr^=s
      count+=1
      adr+=1
    end
  end
end