1 /*
2 * fflush(fp)
3 *
4 * Only really valid for TCP net connections
5 *
6 * --------
7 * $Id: fflush.c,v 1.4 2016-03-06 21:36:52 dom Exp $
8 */
9
10 #ifdef Z80
11 #define STDIO_ASM
12 #endif
13
14 #include <stdio.h>
15
16
fflush(FILE * fp)17 int fflush(FILE *fp)
18 {
19 #asm
20 IF __CPU_R2K__ | __CPU_R3K__
21 ld hl,(sp + 2)
22 ELSE
23 pop bc
24 pop hl
25 push hl
26 push bc
27 ENDIF
28 IF !__CPU_INTEL__ && !__CPU_GBZ80__ && !_CPU_GBZ80__
29 ld e,(hl)
30 inc hl
31 ld d,(hl)
32 inc hl
33 ld a,(hl)
34 and _IOUSE|_IOEXTRA
35 cp _IOUSE|_IOEXTRA
36 jr nz,fflush_error ;not used
37 push ix ;save callers ix
38 dec hl
39 dec hl ;hl = fp
40 IF __CPU_R2K__ | __CPU_R3K__
41 ld hl,ix
42 ld hl,(ix+fp_extra)
43 ELSE
44 push hl
45 pop ix
46 ld l,(ix+fp_extra)
47 ld h,(ix+fp_extra+1)
48 ENDIF
49 ld a,__STDIO_MSG_FLUSH
50 call l_jphl
51 pop ix ;restore callers
52 IF __CPU_R2K__ | __CPU_R3K__
53 bool hl
54 rr hl
55 ELSE
56 ld hl,0
57 IF __CPU_GBZ80__
58 ld d,h
59 ld e,l
60 ENDIF
61 ENDIF
62 ret
63 ENDIF
64 .fflush_error
65 ld hl,-1 ; EOF
66 IF __CPU_GBZ80__
67 ld d,h
68 ld e,l
69 ENDIF
70 #endasm
71 }
72
73
74
75
76
77