;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.4.0 Tue Oct 12 01:19:56 2004

;--------------------------------------------------------
	.module gets
	.optsdcc -mds390 --model-flat24
	
.flat24 on		; 24 bit flat addressing
dpx = 0x93		; dpx register unknown to assembler
dps = 0x86		; dps register unknown to assembler
dpl1 = 0x84		; dpl1 register unknown to assembler
dph1 = 0x85		; dph1 register unknown to assembler
dpx1 = 0x95		; dpx1 register unknown to assembler
ap = 0x9C		; ap register unknown to assembler
_ap = 0x9C		; _ap register unknown to assembler
mcnt0 = 0xD1		; mcnt0 register unknown to assembler
mcnt1 = 0xD2		; mcnt1 register unknown to assembler
ma = 0xD3		; ma register unknown to assembler
mb = 0xD4		; mb register unknown to assembler
mc = 0xD5		; mc register unknown to assembler
F1 = 0xD1		; F1 user flag unknown to assembler
esp = 0x9B		; ESP user flag unknown to assembler
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl _gets
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
_P4	=	0x0080
_SP	=	0x0081
_DPL	=	0x0082
_DPH	=	0x0083
_DPL1	=	0x0084
_DPH1	=	0x0085
_DPS	=	0x0086
_PCON	=	0x0087
_TCON	=	0x0088
_TMOD	=	0x0089
_TL0	=	0x008a
_TL1	=	0x008b
_TH0	=	0x008c
_TH1	=	0x008d
_CKCON	=	0x008e
_P1	=	0x0090
_EXIF	=	0x0091
_P4CNT	=	0x0092
_DPX	=	0x0093
_DPX1	=	0x0095
_SCON0	=	0x0098
_SBUF0	=	0x0099
_ESP	=	0x009b
_AP	=	0x009c
_ACON	=	0x009d
_P2	=	0x00a0
_P5	=	0x00a1
_P5CNT	=	0x00a2
_IE	=	0x00a8
_P3	=	0x00b0
_IP	=	0x00b8
_SCON1	=	0x00c0
_SBUF1	=	0x00c1
_PMR	=	0x00c4
_MCON	=	0x00c6
_TA	=	0x00c7
_T2CON	=	0x00c8
_T2MOD	=	0x00c9
_RCAP2L	=	0x00ca
_RTL2	=	0x00ca
_RCAP2H	=	0x00cb
_RTH2	=	0x00cb
_TL2	=	0x00cc
_TH2	=	0x00cd
_PSW	=	0x00d0
_MCNT0	=	0x00d1
_MCNT1	=	0x00d2
_MA	=	0x00d3
_MB	=	0x00d4
_MC	=	0x00d5
_WDCON	=	0x00d8
_ACC	=	0x00e0
_EIE	=	0x00e8
_MXAX	=	0x00ea
_B	=	0x00f0
_EIP	=	0x00f8
;--------------------------------------------------------
; special function bits 
;--------------------------------------------------------
_IT0	=	0x0088
_IE0	=	0x0089
_IT1	=	0x008a
_IE1	=	0x008b
_TR0	=	0x008c
_TF0	=	0x008d
_TR1	=	0x008e
_TF1	=	0x008f
_T2	=	0x0090
_T2EX	=	0x0091
_RXD1	=	0x0092
_TXD1	=	0x0093
_INT2	=	0x0094
_INT3	=	0x0095
_INT4	=	0x0096
_INT5	=	0x0097
_RI_0	=	0x0098
_TI_0	=	0x0099
_RB8_0	=	0x009a
_TB8_0	=	0x009b
_REN_0	=	0x009c
_SM2_0	=	0x009d
_SM1_0	=	0x009e
_SM0_0	=	0x009f
_FE_0	=	0x009f
_EX0	=	0x00a8
_ET0	=	0x00a9
_EX1	=	0x00aa
_ET1	=	0x00ab
_ES0	=	0x00ac
_ET2	=	0x00ad
_ES1	=	0x00ae
_EA	=	0x00af
_RXD0	=	0x00b0
_TXD0	=	0x00b1
_INT0	=	0x00b2
_INT1	=	0x00b3
_T0	=	0x00b4
_T1	=	0x00b5
_WR	=	0x00b6
_RD	=	0x00b7
_PX0	=	0x00b8
_PT0	=	0x00b9
_PX1	=	0x00ba
_PT1	=	0x00bb
_PS0	=	0x00bc
_PT2	=	0x00bd
_PS1	=	0x00be
_RI_1	=	0x00c0
_TI_1	=	0x00c1
_RB8_1	=	0x00c2
_TB8_1	=	0x00c3
_REN_1	=	0x00c4
_SM2_1	=	0x00c5
_SM1_1	=	0x00c6
_SM0_1	=	0x00c7
_FE_1	=	0x00c7
_CP_RL	=	0x00c8
_C_T	=	0x00c9
_TR2	=	0x00ca
_EXEN2	=	0x00cb
_TCLK	=	0x00cc
_RCLK	=	0x00cd
_EXF2	=	0x00ce
_TF2	=	0x00cf
_P	=	0x00d0
_F1	=	0x00d1
_OV	=	0x00d2
_RS0	=	0x00d3
_RS1	=	0x00d4
_F0	=	0x00d5
_AC	=	0x00d6
_CY	=	0x00d7
_RWT	=	0x00d8
_EWT	=	0x00d9
_WDRF	=	0x00da
_WDIF	=	0x00db
_PFI	=	0x00dc
_EPFI	=	0x00dd
_POR	=	0x00de
_SMOD_1	=	0x00df
_EX2	=	0x00e8
_EX3	=	0x00e9
_EX4	=	0x00ea
_EX5	=	0x00eb
_EWDI	=	0x00ec
_C1IE	=	0x00ed
_C0IE	=	0x00ee
_CANBIE	=	0x00ef
_PX2	=	0x00f8
_PX3	=	0x00f9
_PX4	=	0x00fa
_PX5	=	0x00fb
_PWDI	=	0x00fc
_C1IP	=	0x00fd
_C0IP	=	0x00fe
_CANBIP	=	0x00ff
;--------------------------------------------------------
; overlayable register banks 
;--------------------------------------------------------
	.area REG_BANK_0	(REL,OVR,DATA)
	.ds 8
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
	.area DSEG    (DATA)
;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
	.area OSEG    (OVR,DATA)
;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
	.area ISEG    (DATA)
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
	.area BSEG    (BIT)
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
	.area XSEG    (XDATA)
_gets_str_1_1::
	.ds 4
_gets_count_1_1::
	.ds 2
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
	.area XISEG   (XDATA)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area GSINIT  (CODE)
	.area GSFINAL (CODE)
	.area GSINIT  (CODE)
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area HOME    (CODE)
	.area CSEG    (CODE)
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area CSEG    (CODE)
;------------------------------------------------------------
;Allocation info for local variables in function 'gets'
;------------------------------------------------------------
;str                       Allocated with name '_gets_str_1_1'
;s                         Allocated to registers r5 r0 r7 r6 
;c                         Allocated to registers r4 
;count                     Allocated with name '_gets_count_1_1'
;------------------------------------------------------------
;	gets.c:3: char * gets(const char *str) {
;	genFunction 
;	-----------------------------------------
;	 function gets
;	-----------------------------------------
_gets:
	ar2 = 0x02
	ar3 = 0x03
	ar4 = 0x04
	ar5 = 0x05
	ar6 = 0x06
	ar7 = 0x07
	ar0 = 0x00
	ar1 = 0x01
;	genReceive 
	mov     dps, #1
	mov     dptr, #_gets_str_1_1
	mov	a,dpl
	movx	@dptr,a
	inc	dptr
	mov	a,dph
	movx	@dptr,a
	inc	dptr
	mov	a,dpx
	movx	@dptr,a
	inc	dptr
	mov	a,b
	movx	@dptr,a
	mov	dps,#0
;	gets.c:4: char *s=str;
;	genAssign 
	mov	dptr,#_gets_str_1_1
;	genAssign: resultIsFar = FALSE
	movx	a,@dptr
	mov	r5,a
	inc	dptr
	movx	a,@dptr
	mov	r0,a
	inc	dptr
	movx	a,@dptr
	mov	r7,a
	inc	dptr
	movx	a,@dptr
	mov	r6,a
;	gets.c:6: unsigned int count=0;
;	genAssign 
;	genAssign: resultIsFar = TRUE
	mov	dptr,#_gets_count_1_1
	clr	a
	movx	@dptr,a
	inc	dptr
	movx	@dptr,a
;	gets.c:8: while (1) {
;	genLabel 
00109$:
;	gets.c:9: c=getchar();
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
	lcall	_getchar
	mov	r4,dpl
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	genAssign 
;	genAssign: resultIsFar = TRUE
;	gets.c:10: switch(c) {
;	genCmpEq 
;	gencjneshort
	mov	a,r4
	cjne	a,#0x08,00118$
; Peephole 132   changed ljmp to sjmp
	sjmp 00103$
00118$:
;	genCmpEq 
;	gencjneshort
	mov	a,r4
	cjne	a,#0x0A,00119$
	ljmp	00104$
00119$:
;	genCmpEq 
;	gencjneshort
	mov	a,r4
	cjne	a,#0x0D,00120$
	ljmp	00104$
00120$:
;	genGoto 
	ljmp	00106$
;	gets.c:19: break;
;	genLabel 
00103$:
;	gets.c:12: if (count) {
;	genIfx 
	mov	dptr,#_gets_count_1_1
	movx	a,@dptr
	mov	b,a
	inc	dptr
	movx	a,@dptr
	orl	b,a
	mov	a,b
;	genIfxJump
; Peephole 110   removed ljmp by inverse jump logic
	jz  00109$
00121$:
;	gets.c:13: putchar ('\b');
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,#0x08
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:14: putchar (' ');
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,#0x20
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:15: putchar ('\b');
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,#0x08
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:16: s--;
;	genMinus 
	mov	a,r5
	add	a,#0xFF
	mov	r5,a
	mov	a,r0
	addc	a,#0xFF
	mov	r2,a
	mov	a,r7
	addc	a,#0xFF
	mov	r3,a
;	genAssign 
;	genAssign: resultIsFar = FALSE
	mov	ar0,r2
	mov	ar7,r3
;	gets.c:17: count--;
;	genMinus 
	mov	dptr,#_gets_count_1_1
	movx	a,@dptr
	add	a,#0xFF
	mov	r2,a
	inc	dptr
	movx	a,@dptr
	addc	a,#0xFF
	mov	r3,a
;	genAssign 
;	genAssign: resultIsFar = TRUE
	mov	dptr,#_gets_count_1_1
	mov	a,r2
	movx	@dptr,a
	inc	dptr
	mov	a,r3
	movx	@dptr,a
;	gets.c:19: break;
;	genGoto 
	ljmp	00109$
;	gets.c:22: putchar('\r');
;	genLabel 
00104$:
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,#0x0D
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:23: putchar('\n');
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,#0x0A
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:24: *s=0;
;	genPointerSet 
	mov	dpl,r5
	mov	dph,r0
	mov	dpx,r7
	mov	b,r6
; Peephole 180   changed mov to clr
	clr  a
	lcall	__gptrput
;	gets.c:25: return str;
;	genRet 
	mov     dps, #1
	mov     dptr, #_gets_str_1_1
	movx	a,@dptr
	mov	dpl,a
	inc	dptr
	movx	a,@dptr
	mov	dph,a
	inc	dptr
	movx	a,@dptr
	mov	dpx,a
	inc	dptr
	movx	a,@dptr
	mov	b,a
	mov	dps,#0
;	gets.c:27: *s++=c;
;	genLabel 
; Peephole 132   changed ljmp to sjmp
	sjmp 00111$
00106$:
;	genPointerSet 
	mov	dpl,r5
	mov	dph,r0
	mov	dpx,r7
	mov	b,r6
	mov	a,r4
	lcall	__gptrput
	inc	dptr
	mov	r5,dpl
	mov	r0,dph
	mov	r7,dpx
	mov	r6,b
;	gets.c:28: count++;
;	genPlus 
	mov	dptr,#_gets_count_1_1
;	Swapped plus args.
	movx	a,@dptr
	add	a,#0x01
	movx	@dptr,a
	inc	dptr
	movx	a,@dptr
	addc	a,#0x00
	movx	@dptr,a
;	gets.c:29: putchar(c);
;	genCall 
	push	ar5
	push	ar6
	push	ar7
	push	ar0
;	genSend argreg = 1, size = 1 
	mov	dpl,r4
	lcall	_putchar
	pop	ar0
	pop	ar7
	pop	ar6
	pop	ar5
;	gets.c:31: }
;	genGoto 
	ljmp	00109$
;	genLabel 
00111$:
;	genEndFunction 
	ret
	.area CSEG    (CODE)
	.area XINIT   (CODE)
