; 80166 C compiler v5.1 r0               SN077933-093 (C)1996 Tasking Software BV
; options: -x -s -Ms
$EXTEND
$NOMOD166
$STDNAMES(reg.def)
$CASE
$MODEL(SMALL)
	NAME	LITTLE_C
; little.c    1	/******************************************************************************
; little.c    2	* Erzeugung einer Sinuskurve am Bildschirm (Terminalprogramm) mit variabler   *
; little.c    3	* Periodendauer (leds_high_byte) und Amplitude (leds_low_byte)                *
; little.c    4	* Ausgabe ueber die serielle Schnittstelle 0                                  *
; little.c    5	* -> taste a gedrueckt: P2.0: cc0: (pos. Flanke): Periodendauer: kleiner      *
; little.c    6	* -> taste b gedrueckt: P2.1: cc1: (pos. Flanke): Periodendauer: groesser     *
; little.c    7	* -> taste c gedrueckt: P2.2: cc2: (pos. Flanke): Amplitude:     groesser     *
; little.c    8	* -> taste d gedrueckt: P2.3: cc3: (pos. Flanke): Amplitude:     kleiner      *
; little.c    9	*******************************************************************************/
; little.c   10	
; little.c   11	#include <REG167.H>   /* Register Definitionen C167                           */
; little.c   12	#include <math.h>
; little.c   13	#include <stdio.h>
; little.c   14	#include "serio.h"
; little.c   15	
; little.c   16	#define PI 3.141592654
; little.c   17	
; little.c   18	#define PERIODE_0          1
; little.c   19	#define PERIODE_START     10
; little.c   20	#define PERIODE_MIN        0
; little.c   21	#define PERIODE_MAX       31
; little.c   22	
; little.c   23	
; little.c   24	#define AMPLITUDE_START   38
; little.c   25	#define AMPLITUDE_MIN      0
; little.c   26	#define AMPLITUDE_MAX     38
; little.c   27	
; little.c   28	
; little.c   29	#define INTERVALL          1
; little.c   30	#define MITTE             40
; little.c   31	
; little.c   32	
; little.c   33	/********************* Prototypen *********************************************/
; little.c   34	void main (void);                    /*                                       */
; little.c   35	interrupt ( 0x10 ) void cc0 (void);  /* taste a: externer Interrupt           */
; little.c   36	interrupt ( 0x11 ) void cc1 (void);  /* taste b: externer Interrupt           */
; little.c   37	interrupt ( 0x12 ) void cc2 (void);  /* taste c: externer Interrupt           */
; little.c   38	interrupt ( 0x13 ) void cc3 (void);  /* taste d: externer Interrupt           */
; little.c   39	/******************************************************************************/
; little.c   40	
; little.c   41	unsigned int periode, amplitude;
; little.c   42	char huge cFeld[65536];
; little.c   43	
; little.c   44	
; little.c   45	/*============================================================================*/
; little.c   46	void main (void)
; little.c   47	{
	PUBLIC	_main
; step = R9 (automatic)
; x_grad = R7 - R8 (automatic)
; kurve = R6 (automatic)
; index = offset 0 (automatic)
; y = offset 2 (automatic)
; anzahl = offset 4 (automatic)
LITTLE_1_PR	SECTION	CODE WORD PUBLIC 'CPROGRAM'
_main	PROC	FAR
; Stack: 6, CSE: 0 offset 0
	SUB	R0,#06h
; little.c   48	 int anzahl;
; little.c   49	 int index;
; little.c   50	 register int y,kurve;
; little.c   51	 register unsigned long int x_grad;
; little.c   52	 register int step = PERIODE_0;
	MOV	R9,#01h
; little.c   53	
; little.c   54	 periode   = PERIODE_START;
	MOV	R4,#0Ah
	MOV	_periode,R4
; little.c   55	 amplitude = AMPLITUDE_START;
	MOV	R5,#026h
	MOV	_amplitude,R5
; little.c   56	
; little.c   57	
; little.c   58	 CCM0  = 0x1111; /* CAPCOM_1_Kanal_1234: taste_a, taste_b, taste_c, taste_d   */
	MOV	CCM0,#01111h
; little.c   59	 CC0IC = 0x0078; /* IR=0, IE=1, ILVL=14, GLVL=0                               */
	MOV	CC0IC,#078h
; little.c   60	 CC1IC = 0x0079; /* IR=0, IE=1, ILVL=14, GLVL=1                               */
	MOV	CC1IC,#079h
; little.c   61	 CC2IC = 0x007a; /* IR=0, IE=1, ILVL=14, GLVL=2                               */
	MOV	CC2IC,#07Ah
; little.c   62	 CC3IC = 0x007b; /* IR=0, IE=1, ILVL=14, GLVL=3                               */
	MOV	CC3IC,#07Bh
; little.c   63	
; little.c   64	 init_serio();
	CALLS	SEG _init_serio,_init_serio
; little.c   65	
; little.c   66	 IEN=1;
	BSET	IEN
; little.c   67	
; little.c   68	 //****ramtest***********************************************
; little.c   69	 for(index=0; index<=1000; index++)
	MOV	R4,#00h
	MOV	[R0],R4
_29:
; little.c   70		cFeld[index]='.';
	MOVB	RL4,#02Eh
	MOV	R10,#SOF _cFeld
	MOV	R11,#SEG _cFeld
	MOV	R2,[R0]
	MOV	R3,R2
	ASHR	R3,#0Fh
	ADD	R10,R2
	ADDC	R11,R3
	EXTS	R11,#01h
	MOVB	[R10],RL4
	MOV	R4,[R0]
	ADD	R4,#01h
	MOV	[R0],R4
	CMP	R4,#03E8h
	JMPR	cc_SLE,_29
; little.c   71	
; little.c   72	 anzahl=0;
; little.c   73	 for(index=0; index<=1000; index++)
	MOV	R5,#00h
	MOV	[R0],R5
_30:
; little.c   74	 {
; little.c   75		if(cFeld[index]=='.')
	MOV	R4,#SOF _cFeld
	MOV	R5,#SEG _cFeld
	MOV	R10,[R0]
	MOV	R11,R10
	ASHR	R11,#0Fh
	ADD	R4,R10
	ADDC	R5,R11
	EXTS	R5,#01h
	MOVB	RL3,[R4]
	CMPB	RL3,#02Eh
	JMPR	cc_EQ,_32
; little.c   76			printf("t");
; little.c   77		else
; little.c   78		{
; little.c   79			printf("FEHLER im RAM\n");
	MOV	R12,#_4
	CALLS	SEG _printf,_printf
; little.c   80			while(1){} //Loop_for_ever
_31:
	JMPR	cc_UC,_31
_32:
	MOV	R12,#_3
	CALLS	SEG _printf,_printf
	MOV	R4,[R0]
	ADD	R4,#01h
	MOV	[R0],R4
	CMP	R4,#03E8h
	JMPR	cc_SLE,_30
; little.c   81		}
; little.c   82	 }
; little.c   83	
; little.c   84	 //**********************************************************
; little.c   85	
; little.c   86	 while (1)
_33:
; little.c   87	 {
; little.c   88		for (x_grad=0; x_grad<=360*INTERVALL; x_grad=x_grad+step)
	MOV	R7,#00h
	MOV	R8,#00h
_34:
; little.c   89		{
; little.c   90			y=amplitude*sin(periode*(x_grad%360)*(PI/180));
	MOV	R4,R7
	MOV	R5,R8
	MOV	R10,#0168h
	MOV	R11,#00h
	CALLS	SEG __umol,__umol
	MOV	R10,_periode
	MOV	R11,#00h
	CALLS	SEG __mul,__mul
	CALLS	SEG __cuf48,__cuf48
	MOV	R4,#_7
	CALLS	SEG __mlf8n,__mlf8n
	SUB	R0,#08h
	MOV	R4,R0
	CALLS	SEG __putf8n,__putf8n
	CALLS	SEG _sin,_sin
	ADD	R0,#08h
	MOV	R4,_amplitude
	CALLS	SEG __cuf28,__cuf28
	CALLS	SEG __mlf8a,__mlf8a
	CALLS	SEG __cfi82,__cfi82
	MOV	[R0+#02H],R4
; little.c   91	
; little.c   92			if (y>0)
	CMP	R4,#00h
	JMPR	cc_SLE,_39
; little.c   93			{
; little.c   94				for (kurve=1; kurve<MITTE+y; ++kurve)
	MOV	R6,#01h
	JMPR	cc_UC,_38
_35:
; little.c   95				{
; little.c   96					if (kurve+y>MITTE && kurve==MITTE)
	MOV	R4,[R0+#02H]
	ADD	R4,R6
	CMP	R4,#028h
	JMPR	cc_SLE,_37
	CMP	R6,#028h
	JMPR	cc_NE,_37
; little.c   97					   printf("|");
	MOV	R12,#_8
	CALLS	SEG _printf,_printf
_37:
; little.c   98					printf(" ");
	MOV	R12,#_9
	CALLS	SEG _printf,_printf
	ADD	R6,#01h
_38:
	MOV	R4,[R0+#02H]
	ADD	R4,#028h
	CMP	R6,R4
	JMPR	cc_SLT,_35
; little.c   99				}
; little.c  100				printf("*\n");
	MOV	R12,#_10
	CALLS	SEG _printf,_printf
; little.c  101			}
_39:
; little.c  102	
; little.c  103			if (y<0)
	MOV	R4,[R0+#02H]
	CMP	R4,#00h
	JMPR	cc_SGE,_42
; little.c  104			{
; little.c  105				for (kurve=1; kurve<MITTE; ++kurve)
	MOV	R6,#01h
_40:
; little.c  106				{
; little.c  107					if (kurve==(MITTE+y))
	MOV	R4,[R0+#02H]
	ADD	R4,#028h
	CMP	R6,R4
	JMPR	cc_NE,_41
; little.c  108					   printf("\b*");
	MOV	R12,#_11
	CALLS	SEG _printf,_printf
_41:
; little.c  109					printf(" ");
	MOV	R12,#_9
	CALLS	SEG _printf,_printf
	CMPI1	R6,#027h
	JMPR	cc_SLT,_40
; little.c  110				}
; little.c  111				printf("|\n");
	MOV	R12,#_12
	CALLS	SEG _printf,_printf
; little.c  112			}
_42:
; little.c  113	
; little.c  114			if (y==0)
	MOV	R4,[R0+#02H]
	JMPR	cc_NZ,_44
; little.c  115			{
; little.c  116				for (kurve=1; kurve<MITTE; ++kurve)
	MOV	R6,#01h
_43:
; little.c  117				    printf(" ");
	MOV	R12,#_9
	CALLS	SEG _printf,_printf
	CMPI1	R6,#027h
	JMPR	cc_SLT,_43
; little.c  118				printf("*\n");
	MOV	R12,#_10
	CALLS	SEG _printf,_printf
; little.c  119			}
_44:
	MOV	R4,R9
	MOV	R5,R4
	ASHR	R5,#0Fh
	ADD	R7,R4
	ADDC	R8,R5
	CMP	R8,#00h
	JMPR	cc_NE,_45
	CMP	R7,#0168h
_45:
	JMPA	cc_ULE,_34
	JMPA	cc_UC,_33
; little.c  120	
; little.c  121		}
; little.c  122	 }
; little.c  123	
; little.c  124	}
	RETS
_main	ENDP
; little.c  125	/*============================================================================*/
; little.c  126	
; little.c  127	/*============================================================================*/
; little.c  128	interrupt ( 0x10 ) void cc0 (void)
; little.c  129	{
_cc0	PROC TASK LITTLE_TASK INTNO LITTLE_INUM = 010h
	MOV	LITTLE_RB,R0
	SCXT	CP,#LITTLE_RB
	PUSH	DPP0
	MOV	DPP0,#PAG ?BASE_DPP0
	PUSH	DPP2
	MOV	DPP2,#PAG ?BASE_DPP2
; Stack: 0, CSE: 0 offset 0
; little.c  130	 if (periode < PERIODE_MAX)
	MOV	R4,_periode
	CMP	R4,#01Fh
	JMPR	cc_UGE,_46
; little.c  131	    ++periode;
	ADD	R4,#01h
	MOV	_periode,R4
_46:
; little.c  132	}
	POP	DPP2
	POP	DPP0
	POP	CP
	RETI
_cc0	ENDP
; little.c  133	/*============================================================================*/
; little.c  134	
; little.c  135	/*============================================================================*/
; little.c  136	interrupt ( 0x11 ) void cc1 (void)
; little.c  137	{
_cc1	PROC TASK LITTLE_TASK_1 INTNO LITTLE_INUM_1 = 011h
	MOV	LITTLE_RB,R0
	SCXT	CP,#LITTLE_RB
	PUSH	DPP0
	MOV	DPP0,#PAG ?BASE_DPP0
	PUSH	DPP2
	MOV	DPP2,#PAG ?BASE_DPP2
; Stack: 0, CSE: 0 offset 0
; little.c  138	 if (periode > PERIODE_MIN)
	MOV	R4,_periode
	CMP	R4,#00h
	JMPR	cc_ULE,_47
; little.c  139	    --periode;
	SUB	R4,#01h
	MOV	_periode,R4
_47:
; little.c  140	}
	POP	DPP2
	POP	DPP0
	POP	CP
	RETI
_cc1	ENDP
; little.c  141	/*============================================================================*/
; little.c  142	
; little.c  143	/*============================================================================*/
; little.c  144	interrupt ( 0x12 ) void cc2 (void)
; little.c  145	{
_cc2	PROC TASK LITTLE_TASK_2 INTNO LITTLE_INUM_2 = 012h
	MOV	LITTLE_RB,R0
	SCXT	CP,#LITTLE_RB
	PUSH	DPP0
	MOV	DPP0,#PAG ?BASE_DPP0
	PUSH	DPP2
	MOV	DPP2,#PAG ?BASE_DPP2
; Stack: 0, CSE: 0 offset 0
; little.c  146	 if (amplitude < AMPLITUDE_MAX)
	MOV	R4,_amplitude
	CMP	R4,#026h
	JMPR	cc_UGE,_48
; little.c  147	    ++amplitude;
	ADD	R4,#01h
	MOV	_amplitude,R4
_48:
; little.c  148	}
	POP	DPP2
	POP	DPP0
	POP	CP
	RETI
_cc2	ENDP
; little.c  149	/*============================================================================*/
; little.c  150	
; little.c  151	/*============================================================================*/
; little.c  152	interrupt ( 0x13 ) void cc3 (void)
; little.c  153	{
_cc3	PROC TASK LITTLE_TASK_3 INTNO LITTLE_INUM_3 = 013h
	MOV	LITTLE_RB,R0
	SCXT	CP,#LITTLE_RB
	PUSH	DPP0
	MOV	DPP0,#PAG ?BASE_DPP0
	PUSH	DPP2
	MOV	DPP2,#PAG ?BASE_DPP2
; Stack: 0, CSE: 0 offset 0
; little.c  154	 if (amplitude > AMPLITUDE_MIN)
	MOV	R4,_amplitude
	CMP	R4,#00h
	JMPR	cc_ULE,_49
; little.c  155	    --amplitude;
	SUB	R4,#01h
	MOV	_amplitude,R4
_49:
; little.c  156	}
	POP	DPP2
	POP	DPP0
	POP	CP
	RETI
_cc3	ENDP
; little.c  157	/*============================================================================*/
LITTLE_1_PR	ENDS

LITTLE_2_HB	SECTION	HDAT WORD PUBLIC 'CHUGE'
LITTLE_2_HB_ENTRY	LABEL	BYTE
_cFeld	LABEL	BYTE
	DS	65536
	PUBLIC	_cFeld
LITTLE_2_HB	ENDS

LITTLE_3_NB	SECTION	LDAT WORD PUBLIC 'CNEAR'
LITTLE_3_NB_ENTRY	LABEL	BYTE
_amplitude	LABEL	WORD
	DS	2
	PUBLIC	_amplitude
_periode	LABEL	WORD
	DS	2
	PUBLIC	_periode
LITTLE_3_NB	ENDS

LITTLE_4_CO	SECTION	LDAT WORD PUBLIC 'CROM'
_7	LABEL	WORD
	DW	03F91h,0DF46h,0A25Ch,0A311h
_9	DB	020h,00h
_10	DB	02Ah,0Ah,00h
_3	DB	074h,00h
_8	DB	07Ch,00h
_12	DB	07Ch,0Ah,00h
_4	DB	046h,045h,048h,04Ch,045h,052h,020h,069h,06Dh,020h
	DB	052h,041h,04Dh,0Ah,00h
_11	DB	08h,02Ah,00h
LITTLE_4_CO	ENDS

C166_US	SECTION	LDAT WORD GLBUSRSTACK 'CUSTACK'
	DS	6
C166_US	ENDS

C166_BSS	SECTION	PDAT WORD GLOBAL 'CINITROM'
	DW	07h
	DSPTR	LITTLE_2_HB_ENTRY
	DW	00h,01h
	DW	05h,LITTLE_3_NB_ENTRY,04h
C166_BSS	ENDS

$FLOAT(ANSI)
	EXTERN	_sin:FAR
	EXTERN	_printf:FAR
	EXTERN	_init_serio:FAR
	EXTERN	__umol:FAR
	EXTERN	__mul:FAR
	EXTERN	__cuf48:FAR
	EXTERN	__mlf8n:FAR
	EXTERN	__putf8n:FAR
	EXTERN	__cuf28:FAR
	EXTERN	__mlf8a:FAR
	EXTERN	__cfi82:FAR
	EXTERN	__CSTART:FAR
LITTLE_RB	REGDEF	R0-R15
	END
