Skip to content

Commit a89abd4

Browse files
[libc] fix issues with inchar/outchar and fget/fput family
1 parent ee119ba commit a89abd4

File tree

7 files changed

+24
-33
lines changed

7 files changed

+24
-33
lines changed

src/libc/fputc.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ int __attribute__((weak)) fputc(int c, FILE *stream)
55
{
66
int ret;
77

8-
if (stream == NULL ||
9-
stream == stdin)
8+
if (stream == NULL || stream == stdin)
109
{
1110
ret = EOF;
1211
}
13-
else if (stream == stdout ||
14-
stream == stderr)
12+
else if (stream == stdout || stream == stderr)
1513
{
16-
ret = putchar(c);
14+
putchar(c);
15+
ret = c;
1716
}
1817
else
1918
{
@@ -30,5 +29,5 @@ int __attribute__((weak)) fputc(int c, FILE *stream)
3029
stream->err = 1;
3130
}
3231

33-
return ti_PutC((char)c, stream->slot);
32+
return ret;
3433
}

src/libc/fputs.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,5 @@ int __attribute__((weak)) fputs(const char *__restrict str, FILE *__restrict str
1515
i++;
1616
}
1717

18-
if (fputc('\n', stream) == EOF)
19-
{
20-
return EOF;
21-
}
22-
2318
return 1;
2419
}

src/libc/getchar.src

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,5 @@
22

33
section .text
44
public _getchar
5-
_getchar:
6-
call _inchar
7-
ld l,a
8-
rlc l
9-
sbc hl,hl
10-
ld l,a
11-
push hl
12-
call _outchar
13-
pop hl
14-
ret
15-
5+
_getchar := _inchar
166
extern _inchar
17-
extern _outchar

src/crt/inchar.src renamed to src/libc/inchar.src

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,33 @@
44
weak _inchar
55
_inchar:
66
ld iy,$d00080 ; ti.flags
7-
.getchar:
7+
.l:
88
call $2014C ; ti.GetCSC
99
or a,a
10-
jr z,.getchar
10+
jr z,.l
1111
sbc hl,hl
1212
ld l,a
13-
ld de,.lut_char
13+
ld de,.lut
1414
add hl,de
1515
ld a,(hl)
1616
or a,a
17-
jr z,_inchar
17+
jr z,.l
18+
sbc hl,hl
19+
ld l,a
20+
push hl
21+
push hl
22+
call _outchar
23+
pop hl
24+
pop hl
1825
ret
1926

20-
.lut_char:
27+
.lut:
2128
db 0,0,0,0,0,0,0,0,0,10 ;
2229
db 0,'WRMH',0,0 ; + - × ÷ ^ undef
2330
db 0,'Z'+ 1,'VQLG',0,0 ; (-) 3 6 9 ) TAN VARS undef
2431
db 0,'ZUPKFC',0 ; . 2 5 8 ( COS PRGM STAT
2532
db ' YTOJEBX',0 ; 0 1 4 7 , SIN APPS XT?n undef
2633
db 'XSNIDA' ; STO LN LOG x2 x-1 MATH
2734
db 0,0,0,0,0,0,0,0,0,0 ;
35+
36+
extern _outchar

src/libc/include/stdio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct
3636
__BEGIN_DECLS
3737

3838
/* weak user-defined functions */
39-
char inchar(void);
39+
int inchar(void);
4040

4141
void outchar(char character);
4242

src/libc/outchar.src

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ _outchar:
77
ex (sp),hl
88
push de
99
ld iy,$d00080 ; ti.flags
10-
ld a,l
11-
cp a,32
12-
jp nc,$207B8 ; ti.PutC
1310
cp a,10
1411
jp z,$0207F0 ; ti.NewLine
15-
ret
12+
jp $207B8 ; ti.PutC

src/libc/putchar.src

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ _putchar:
77
ex (sp),hl
88
push de
99
push hl
10+
push hl
1011
call _outchar
1112
pop hl
13+
push hl
1214
ret
1315

1416
extern _outchar

0 commit comments

Comments
 (0)