diff --git a/kernel/asmsupt.asm b/kernel/asmsupt.asm index 55525ad..0be4024 100644 --- a/kernel/asmsupt.asm +++ b/kernel/asmsupt.asm @@ -119,6 +119,7 @@ domemcpy: ; And do the built-in byte copy, but do a 16-bit transfer ; whenever possible. shr cx,1 + jcxz memcpy_return rep movsw jnc memcpy_return movsb @@ -180,9 +181,10 @@ FMEMSET: mov bl,8 domemset: - mov ah, al + mov ah, al - shr cx,1 + shr cx,1 + jcxz pascal_return rep stosw jnc pascal_return stosb @@ -390,12 +392,12 @@ FMEMCHR: les di, [bp+8] mov bl, 8 - + + jcxz strchr_retzero repne scasb jne strchr_retzero mov dx, es mov ax, di - dec ax jmp short strchr_found1 ;********************************************************************** diff --git a/kernel/chario.c b/kernel/chario.c index 2d7ec4b..85a04fe 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -218,6 +218,7 @@ STATIC int raw_put_char(int sft_idx, int c) STATIC int cooked_put_char(int sft_idx, int c) { int err = 0; + unsigned char scrpos = scr_pos; /* Test for hold char */ con_hold(sft_idx); @@ -225,23 +226,24 @@ STATIC int cooked_put_char(int sft_idx, int c) switch (c) { case CR: - scr_pos = 0; + scrpos = 0; break; case LF: case BELL: break; case BS: - if (scr_pos > 0) - scr_pos--; + if (scrpos > 0) + scrpos--; break; case HT: do err = raw_put_char(sft_idx, ' '); - while (err >= 0 && ((++scr_pos) & 7)); + while (err >= 0 && ((++scrpos) & 7)); break; default: - scr_pos++; + scrpos++; } + scr_pos = scrpos; if (c != HT) err = raw_put_char(sft_idx, c); return err; diff --git a/kernel/dosfns.c b/kernel/dosfns.c index 1a07743..3357bb8 100644 --- a/kernel/dosfns.c +++ b/kernel/dosfns.c @@ -239,23 +239,25 @@ long DosRWSft(int sft_idx, size_t n, void FAR * bp, int mode) { size_t cnt = (size_t)rc; const char FAR *p = bp; + unsigned char scrpos = scr_pos; while (cnt--) { switch (*p++) { case CR: - scr_pos = 0; + scrpos = 0; break; case LF: case BELL: break; case BS: - --scr_pos; + --scrpos; break; default: - ++scr_pos; + ++scrpos; } } + scr_pos = scrpos; } return rc; } @@ -398,14 +400,9 @@ ULONG DosSeek(unsigned hndl, LONG new_pos, COUNT mode) STATIC long get_free_hndl(void) { psp FAR *p = MK_FP(cu_psp, 0); - unsigned hndl; - - for (hndl = 0; hndl < p->ps_maxfiles; hndl++) - { - if (p->ps_filetab[hndl] == 0xff) - return hndl; - } - return DE_TOOMANY; + UBYTE FAR *q = p->ps_filetab; + UBYTE FAR *r = fmemchr(q, 0xff, p->ps_maxfiles); + return FP_OFF(r) == 0 ? DE_TOOMANY : r - q; } STATIC sft FAR *get_free_sft(COUNT * sft_idx) @@ -442,18 +439,19 @@ STATIC sft FAR *get_free_sft(COUNT * sft_idx) const char FAR *get_root(const char FAR * fname) { /* find the end */ - register unsigned length = fstrlen(fname) - 1; + register unsigned length = fstrlen(fname); char c; /* now back up to first path seperator or start */ - while (length != (unsigned)-1) + fname += length; + while (length) { - c = fname[length]; + length--; + c = *--fname; if (c == '/' || c == '\\' || c == ':') break; - --length; } - return fname + length + 1; + return fname; } /* initialize SFT fields (for open/creat) for character devices */