;Alto->8086 small-c compiler rev 2.0
C←CODE SEGMENT

$INCLUDE(8086LIB.D)

$INCLUDE(runtime.DEC)

ASSUME CS:C←CODE, DS:C←DATA

; #include <Env.h>

; extern SetTmr();

; extern int TmrExp();

; extern int FetchW();

; extern CallDebugger();

; int EqStr(s1, s2)
←EqStr:

;   char *s1, *s2;
PUSH BP
MOV BP,SP
PUSH CX
PUSH BX

;   {

;   while (*s1 != 0) if (LC(*s1++) != LC(*s2++)) return(false);
X1:

;	DI ← ←s1
MOV DI,[BP-2]
MOV AL,[DI]
OR AL,AL
JZ X2
INC WORD PTR [BP-2]

;	BX ← ←s1
MOV BX,[BP-2]
MOV AL,[BX-1]
CBW
MOV BX,AX
CALL ←LC
PUSH BX
INC WORD PTR [BP-4]

;	BX ← ←s2
MOV BX,[BP-4]
MOV AL,[BX-1]
CBW
MOV BX,AX
CALL ←LC
POP CX
CMP CX,BX
JZ X3
XOR BX,BX
MOV SP,BP
POP BP
RET;
X3:
JR X1
X2:

;   if (*s2 != 0) return (false);

;	DI ← ←s2
POP DI
PUSH DI
MOV AL,[DI]
OR AL,AL
JZ X4
XOR BX,BX
MOV SP,BP
POP BP
RET;
X4:

;   return(true);
MOV BX,0FFFFX
MOV SP,BP
POP BP
RET;

;   };

; int IsDigit(c)
←IsDigit:

;   char c;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   if (c >= '0' && c <= '9') return(true);

;	AL ← ←c
POP AX
PUSH AX
CMP AL,030X
JL X6

;	AL ← ←c
POP AX
PUSH AX
CMP AL,039X
JG X6
MOV AL,1
JR X7
X6:
XOR AL,AL
X7:
OR AL,AL
JZ X5
MOV BX,0FFFFX
MOV SP,BP
POP BP
RET;

;   else return(false);
X5:
XOR BX,BX
MOV SP,BP
POP BP
RET;

;   };

; int LC(c)
←LC:

;   char c;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';

;	AL ← ←c
POP AX
PUSH AX
CMP AL,041X
JL X9

;	AL ← ←c
POP AX
PUSH AX
CMP AL,05AX
JG X9
MOV AL,1
JR X10
X9:
XOR AL,AL
X10:
OR AL,AL
JZ X8

;	AL ← ←c
POP AX
ADD AL,0BFX
ADD AL,061X

;	←c ← AL
PUSH AX
X8:

;   return (c);

;	BX ← ←c
POP BX
PUSH BX
XOR BH,BH
MOV SP,BP
POP BP
RET;

;   };

; int UC(c)
←UC:

;   char c;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   if (c >= 'a' && c <= 'z') c = c - 'a' + 'A';

;	AL ← ←c
POP AX
PUSH AX
CMP AL,061X
JL X12

;	AL ← ←c
POP AX
PUSH AX
CMP AL,07AX
JG X12
MOV AL,1
JR X13
X12:
XOR AL,AL
X13:
OR AL,AL
JZ X11

;	AL ← ←c
POP AX
ADD AL,09FX
ADD AL,041X

;	←c ← AL
PUSH AX
X11:

;   return (c);

;	BX ← ←c
POP BX
PUSH BX
XOR BH,BH
MOV SP,BP
POP BP
RET;

;   };

; CallSwat(code)
←CallSwat:

;   int code;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   CallDebugger(code);

;	BX ← ←code
POP BX
PUSH BX
CALL ←CallDebugger

;   };
MOV SP,BP
POP BP
RET;

; Timer(t)
←Timer:

;   int t[];
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   t[1] = FetchW(clkhi);

;	BX ← ←t
POP BX
PUSH BX
PUSH BX
MOV BX,0DA20X
CALL ←FetchW
MOV CX,BX
POP BX
MOV [BX+2],CX

;   t[0] = FetchW(clklo);
MOV BX,0DA1EX
CALL ←FetchW
MOV CX,BX

;	BX ← ←t
POP BX
PUSH BX
MOV [BX],CX

;   if (t[1] != FetchW(clkhi)) Timer(t);

;	BX ← ←t
POP BX
PUSH BX
MOV CX,[BX+2]
PUSH CX
MOV BX,0DA20X
CALL ←FetchW
POP CX
CMP CX,BX
JZ X14

;	BX ← ←t
POP BX
PUSH BX
CALL ←Timer
X14:

;   };
MOV SP,BP
POP BP
RET;

; Dismiss(ms)
←Dismiss:

;   int ms;
PUSH BP
MOV BP,SP
PUSH BX

;   {

;   int tmr;
PUSH DX

;   SetTmr(ms, &tmr);
;&←tmr
LEA BX,[BP-4]

;	CX ← ←ms
MOV CX,[BP-2]
CALL ←SetTmr

;   while (!TmrExp(&tmr)) Block();
X15:
;&←tmr
LEA BX,[BP-4]
CALL ←TmrExp
OR BX,BX
JNZ X16
CALL ←Block
JR X15
X16:

;   };
MOV SP,BP
POP BP
RET;

; Externals Declared Here
PUBLIC ←EqStr
PUBLIC ←LC
PUBLIC ←IsDigit
PUBLIC ←UC
PUBLIC ←CallSwat
PUBLIC ←Timer
PUBLIC ←Dismiss

C←CODE ENDS

; Number of Bytes of Code = 0130X, (304)