Skip to content

Commit 7952a84

Browse files
authored
Merge pull request #192 from shattered/_463a2165
runtime: minor optimizations and bugfixes
2 parents 9dbcd11 + 569ee40 commit 7952a84

3 files changed

Lines changed: 23 additions & 18 deletions

File tree

rt/msdos/cowgol.coh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ sub AlignUp(in: intptr): (out: intptr) is
1818
out := in;
1919
end sub;
2020

21+
sub get_char(): (c: uint8) is
22+
@asm "mov ah, 1";
23+
@asm "int 0x21";
24+
@asm "mov [",c,"],al";
25+
end sub;
26+
2127
sub print_char(c: uint8) is
2228
if c == 10 then
2329
@asm "mov dl, 13";

rt/unixv7/cowgol.coh

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var LOMEM: [uint8];
22
var HIMEM: [uint8];
3-
3+
44
# NB: apout ignores brk()
55
sub _find_himem() is
66
@asm "mov #0087h, -(sp)"; # ret
@@ -46,27 +46,21 @@ end sub;
4646

4747
sub MemSet(buf: [uint8], byte: uint8, len: uint16) is
4848
var bufend := buf + len;
49-
loop
50-
if buf == bufend then
51-
return;
52-
end if;
49+
while buf != bufend loop
5350
[buf] := byte;
54-
buf := buf + 1;
51+
buf := @next buf;
5552
end loop;
5653
end sub;
5754

5855
sub print_oct_i16(value: uint16) is
59-
var i: uint8 := 5;
56+
var i: uint8 := 5;
6057
print_char(((value >> 15) + '0') as uint8);
61-
loop
62-
var digit := (((value >> 12) & 7) + '0') as uint8;
63-
print_char(digit);
64-
value := value << 3;
65-
i := i - 1;
66-
if i == 0 then
67-
break;
68-
end if;
69-
end loop;
58+
value := value << 1;
59+
while i > 0 loop
60+
print_char(((value >> 13) + '0') as uint8);
61+
value := value << 3;
62+
i := i - 1;
63+
end loop;
7064
end sub;
7165

7266
include "common.coh";

rt/unixv7/file.coh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,15 @@ sub FCBClose(fcb: [FCB]): (errno: uint8) is
139139
FCBFlush(fcb);
140140

141141
var fd := fcb.fd;
142+
errno := 0;
142143
@asm "mov ", fd, ", r0";
143144
@asm "trap 6";
144-
@asm "neg r0";
145-
@asm "mov r0, ", errno;
145+
@asm "adcb ", errno;
146+
@asm "mov r0, ", fd;
147+
148+
if errno != 0 then
149+
errno := fd as uint8;
150+
end if;
146151
end sub;
147152

148153
sub FCBExt(fcb: [FCB]): (len: uint32) is

0 commit comments

Comments
 (0)