export { numbargs, lhs, thiscall, returnto, sleep, seconds, useconds, floatformat, datetime, datetime2, emergency_outs, emergency_outch, emergency_outno, devctl, devctlv, strlen, random, zero_remainder, dt2_year, dt2_month, dt2_day, dt2_dow, dt2_hour, dt2_minute, dt2_second, dt2_millisec } manifest { dt2_year = selector 13 : 19 : 0, dt2_month = selector 4 : 15 : 0, dt2_day = selector 5 : 10 : 0, dt2_dow = selector 3 : 7 : 0, dt2_hour = selector 5 : 27 : 1, dt2_minute = selector 6 : 21 : 1, dt2_second = selector 6 : 15 : 1, dt2_millisec = selector 10 : 5 : 1 } let numbargs() be { assembly { load R1, [FP] load R1, [R1+2] div R1, 2 } } let lhs() be { assembly { load R1, [FP] load R1, [R1+2] and R1, 1 rsub R1, 0 } } let thiscall() be { assembly { load R1, [FP] } } let returnto(frame, value) be { assembly { load R2, FP load R4, [] load R1, [] load SP, R2 load R2, [R2] comp R2, R4 jcond neq, PC-4 load R5, [SP+1] add SP, 2 load FP, R2 jump R5 } } let emergency_outs(s) be { let i = 0; while true do { let c = byte i of s; if c = 0 then break; assembly { type [] } i +:= 1 } } let emergency_outch(c) be { assembly { type [] } } let emergency_outno(n) be { let pnum(n) be { if n > 9 then pnum(n / 10); assembly { load r1, [] mod r1, 10 add r1, '0' type r1 } } if n < 0 then { assembly { type '-' } n := - n } pnum(n) } let strlen(s) be { let i = 0; until byte i of s = 0 do i +:= 1; resultis i } let zero_remainder(buff, pos, size) be { let szch = size << 2; if pos >= szch then return; for i = 1 to (szch - pos) bitand 3 do { byte pos of buff := 0; pos +:= 1 } pos >>:= 2; $memory_zero(buff + pos, size - pos) } let devctl(op) be { let p = vec(16), r = 0, n = numbargs(); for i = 0 to n - 1 do p ! i := (@ op) ! i; assembly { load R2, [

] peri R1, R2 store R1, [] } resultis r } let devctlv(p) be { let r = 0; assembly { load R2, [

] peri R1, R2 store R1, [] } resultis r } let floatformat(val, fmt, dst) be { devctl(dc$floatformat, val, fmt, dst); resultis dst } let seconds() be { let n = 0; assembly { load R1, $SECONDS store R1, [] peri R1, } } let useconds(v) be { let p = vec(2); p ! 1 := v; assembly { load r1, $USECONDS load r2, [

] store r1, [r2] peri r1, r2 } } let sleep(n) be { let endtime = seconds() + n; until seconds() >= endtime do assembly { pause 100 } } let datetime(t, v) be { let p = vec 3; if t = -1 then t := seconds(); p ! 1 := t; p ! 2 := v; assembly { load R1, $DATETIME load R2, [

] store R1, [R2] peri R1, R2 } } let datetime2(tsec, tusec, v) be { let p = vec 3, x = vec 7, now = vec 2; if tsec = -1 then { useconds(now); tsec := now ! 0; tusec := now ! 1 } p ! 1 := tsec; p ! 2 := x; assembly { load R1, $DATETIME load R2, [

] store R1, [R2] peri R1, R2 } dt2_year of v := x ! 0; dt2_month of v := x ! 1; dt2_day of v := x ! 2; dt2_dow of v := x ! 3; dt2_hour of v := x ! 4; dt2_minute of v := x ! 5; dt2_second of v := x ! 6; dt2_millisec of v := tusec / 1000 } let random(max) be { static { seed = 872364821 }; if max < 0 then { seed := seconds(); return } seed := seed * 628191 + 361; resultis (seed bitand 0x7FFFFFFF) rem (max + 1) }