macro define.xlt {
align 4
ILT db \
00h,01h,02h,03h,04h,05h,06h,07h,\
08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh,\
10h,11h,12h,13h,14h,15h,16h,17h,\
18h,19h,1Ah,1Bh,1Ch,1Dh,1Eh,1Fh,\
20h,21h,22h,23h,24h,25h,26h,27h,\
28h,29h,2Ah,2Bh,2Ch,2Dh,2Eh,2Fh,\
30h,31h,32h,33h,34h,35h,36h,37h,\
38h,39h,3Ah,3Bh,3Ch,3Dh,3Eh,3Fh,\
40h,41h,42h,43h,44h,45h,46h,47h,\
48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,\
50h,51h,52h,53h,54h,55h,56h,57h,\
58h,59h,5Ah,5Bh,5Ch,5Dh,5Eh,5Fh,\
60h,41h,42h,43h,44h,45h,46h,47h,\
48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,\
50h,51h,52h,53h,54h,55h,56h,57h,\
58h,59h,5Ah,7Bh,7Ch,7Dh,7Eh,7Fh
TLT db \
00h,80h,80h,80h,80h,80h,80h,80h,\
80h,80h,40h,80h,80h,40h,80h,80h,\
80h,80h,80h,80h,80h,80h,80h,80h,\
80h,80h,80h,80h,80h,80h,80h,80h,\
20h,10h,04h,04h,10h,04h,04h,04h,\
04h,04h,04h,04h,04h,04h,10h,04h,\
01h,01h,01h,01h,01h,01h,01h,01h,\
01h,01h,04h,04h,04h,04h,04h,10h,\
10h,0Ah,0Ah,0Ah,0Ah,0Ah,0Ah,02h,\
0Ah,02h,02h,0Ah,02h,0Ah,02h,02h,\
02h,02h,02h,02h,02h,02h,02h,02h,\
02h,02h,02h,04h,04h,04h,04h,10h,\
04h,0Ah,0Ah,0Ah,0Ah,0Ah,0Ah,02h,\
0Ah,02h,02h,0Ah,02h,0Ah,02h,02h,\
02h,02h,02h,02h,02h,02h,02h,02h,\
02h,02h,02h,04h,04h,04h,04h,80h
}
define.xlt
C.NULL = 00000000b
C.NUMBER = 00000001b
C.ALPHA = 00000010b
C.SYMBOL = 00000100b
C.NUMERIC = 00001000b
C.SYMBOLIC = 00010000b
C.SPACE = 00100000b
C.RETURN = 01000000b
C.IGNORE = 10000000b
C.KEYWORD = 11111111b
C.DIGIT = C.NUMBER or C.NUMERIC
C.NAME = C.ALPHA or C.NUMBER or C.SYMBOLIC
C.SYMBOLS = C.SYMBOL or C.SYMBOLIC
C.ALPHAN = C.ALPHA or C.NUMBER
C.VISIBLE = C.ALPHAN or C.SYMBOLS
C.WHITE = C.SPACE or C.RETURN
C.BLANK = C.WHITE or C.IGNORE
C.END = C.SYMBOL or C.WHITE
C.0 = 0
function is.c, c, type
. a1&0FFh, a3=TLT, a3+a1
. (u8) a1=*a3, a1&a2
endf
macro is.c c, t {
. a1=c, a2=t
is.c
}
macro if.is c, t {
is.c c, C.#t
.if true
}
numeric ZERO.C='0', SPACE.C=' ',\
COMMA.C=',', COLIN.C=':', SEMI.C=';',\
POUND.C='#', ASSIGN.C='=', SLASHB.C='\'
NL equ ,0Dh,0Dh,
macro .if.text.equal a, b
{ !if text.equal, a, b }
macro .if.not.text.equal a, b
{ !if.n text.equal, a, b }
macro .if.text.find a, b
{ !if text.find, a, b }
macro .if.text.find.last a, b
{ !if text.find.last, a, b }
macro .if.text.begins a, b
{ !if text.begins, a, b }
macro .if.text.ends a, b
{ !if text.ends, a, b }
function text.end, t
alias t=a1, c=v1
. c=1
.while c
. (u8) c=*t++
.endw
. t--
endf
function text.n, t
alias t=a1, b=a2, c=v1
. c=1, b=t
.while c
. (u8) c=*t++
.endw
. t--, t-b
endf
function text.write, a, b
alias a=a1, b=a2, c=v1
.forever
. (u8) c=*b++
.if c=0
return
.end
. (u8) *a++=c
.endfv
endf
function text.copy, a, b
alias a=a1, b=a2, c=v1
. c=1
.while c
. (u8) c=*b++
. (u8) *a++=c
.endw
. a--
endf
function text.copy.n, a, b, n
alias a=a1, b=a2,\
n=a3, c=v1
.repeat n
. (u8) c=*b++
. (u8) *a++=c
.if c=0
.break
.end
.endr
. a--
endf
function text.attach, a, b
alias a=a1,\
b=a2, p=v1
. p=b
text.end
. b=p
text.copy
endf
function text.attach.c, t, c
alias t=a1, c=v2
. c=a2
text.end
. (u8) *t++=c, (u8) *t=0
endf
function text.compare, a, b
alias a=a1, b=a2,\
c=v1, d=v2
. c=1, d=c
.while c=d
. (u8) c=*a++
. (u8) d=*b++
.if c=0
.break
.end
.if d=0
.break
.end
.endw
. a=c-d
endf
function text.equal, a, b
text.compare
.if false
return 1
.end
endf 0
function text.find, t, c
alias t=a1,\
c=v1, key=a2
.forever
. (u8) c=*t
.if c=0
return 0
.end
.if c=key
return t
.end
. t++
.endfv
endf
function text.find.last, t, c
alias t=a1, c=a2,\
key=v1, p=v2
. key=c, p=t
. c=1
.while c
. (u8) c=*t++
.endw
. t-2
.while t>p
. (u8) c=*t
.if c=key
return t
.end
. t--
.endw
endf 0
function text.count.c, t, c
alias p=v1, c=v2, n=v3
. p=a1, c=a2, n=0
.while true
get p=text.find p, c
.if true
. p++, n++
.end
.endw
endf n
function text.count.n, t
text.count.c a1, 0Dh
.if a1>0
. a1++
.end
endf
function text.begins, a, b
alias a=a1, b=a2,\
c=v1, d=v2, e=v3
. c=1, d=c
.while c=d
. (u8) c=*a++
. (u8) d=*b++
. e=c|d
.breakz
.endw
.if d<>0
return 0
.end
endf
function text.ends, a, b
alias \
a=v1, b=v2, p=v3
. a=a1, b=a2
text.end
. p=a1, a1=b
text.n
. p-a1, a1=p, a2=b
text.compare
.if false
return 1
.end
endf 0
function text.upper, t
alias t=a1, c=v1
.forever
. (u8) c=*t
.if c=0
return t
.end
.if c>=97
.if c<=122
. c-32
. (u8) *t=c
.end
.end
. t++
.endfv
endf
function text.lower, t
alias t=a1, c=v1
.forever
. (u8) c=*t
.if c=0
return
.end
.if c>=65
.if c<=90
. c+32
. (u8) *t=c
.end
.end
. t++
.endfv
endf
function text.reverse, t
alias t=a1,\
p=a2, s=a3,\
c=v1, d=v2
. s=t, c=1
.while c
. (u8) c=*t++
.endw
. p=t-2, t=s
.while t<p
. (u8) c=*t
. (u8) d=*p
. (u8) *t++=d
. (u8) *p=c
. p--
.endw
. t--
endf
function text.expand, t, n
alias t=v1, p=v2,\
n=v3, tn=v4, a=v5, b=v6
. t=a1, n=a2
get tn=text.n t
. a=t+tn, a--, b=a, a+n
.repeat tn
. (u8) *a=*b, a--, b--
.endr
endf
function text.prefix, a, b
alias a=v1, b=v2, n=v3
. a=a1, b=a2
get n=text.n b
text.expand a, n
text.write a, b
endf
function text.enclose.c, t, b, e
alias t=v1, b=v2, e=v3,\
p=v4, n=v5, c=v6
. t=a1, b=a2, e=a3
get n=text.n t
text.expand t, 1
. p=t, (u8) *p=b, p=t+n, p++
. (u8) *p++=e, (u8) *p=0
endf
function text.align, t, c, n
alias t=v1, c=v2,\
n=v4, p=v5, tn=v6
. t=a1, c=a2, n=a3
get tn=text.n t
.if n=tn
return
.end
.if tn>n
. t+n, (u8) *t=0
return
.end
. n-tn
text.expand t, n
.repeat n
. (u8) *t++=c
.endr
. t+tn, (u8) *t=0
endf
function text.array.equal, ta, t, n
alias ta=v1, t=v2,\
n=v3, i=v4, p=v5
. ta=a1, t=a2, n=a3
.loop i=0 to n
. p=ta[i]
.if.text.equal t, p
return i
.end
.endl
endf -1
macro .if.text.array.equal ta, t {
text.array.equal ta, t, ta#.$
.if r0<>-1
}
function text.array.begins, ta, t, n
alias ta=v1, t=v2,\
n=v3, i=v4, p=v5
. ta=a1, t=a2, n=a3
.loop i=0 to n
. p=ta[i]
.if.text.begins p, t
return i
.end
.endl
endf -1
macro .if.text.array.begins ta, t {
text.array.begins ta, t, ta#.$
.if r0<>-1
}
function u2t, n, t
alias n=a1,\
x=a2, y=a3,\
t=v1, s=v2, c=v3
. t=a2, s=a2
.if n=0
. (u8) *t++=30h
. (u8) *t=0
return t
.end
.while n
. y=n
. x=1999999Ah
. n=n-(n>>>30)
umull c, n, n, x
. x=n<<1
. x=x+(x<<2)
. x=y-x
. c=x+30h
. (u8) *t++=c
.endw
. (u8) *t=0
text.reverse s
endf t
function i2t, n, t
alias n=a1,\
t=a2, sign=a3
. sign=80000000h
.if n&sign
. -n
. (u8) *t++=2Dh
.end
u2t
endf
function h2t, n, t
alias t=v1, s=v2,\
n=v3, x=v4, hex=v5
. n=a1, t=a2, s=t
. hex=_hex
.if n=0
. (u8) *t++=30h
. (u8) *t=0
return t
.end
.while n
. x=n&15
ldrb x, [hex, x]
. (u8) *t++=x
. n>>>4
.endw
. (u8) *t=0
text.reverse s
return t
_hex: db \
'0123456789ABCDEF'
endf t
function b2t, n, t
alias t=v1, s=v2,\
n=v3, x=v4
. n=a1, t=a2, s=t
.if n=0
. (u8) *t++=30h
. (u8) *t=0
return t
.end
.while n
. x=n&1, x+30h
. (u8) *t++=x
. n>>>1
.endw
. (u8) *t=0
text.reverse s
endf t
function t2u, t
alias t=v1,\
c=v2, n=v3
. t=a1, (u8) c=*t
.if c=30h
.while c=30h
. (u8) c=*t++
.endw
. t--
.end
.if c=0
return 0
.end
. n=0
.forever
. (u8) c=*t++
.if c=0
return n
.end
. n+(n<<2), n+n
. n-30h, n+c
.endfv
endf
function t2i, t
alias t=v1,\
c=v2, negate=v3
. t=a1, (u8) c=*t
. negate=0
.if c='-'
. t++, negate=1
.end
t2u t
.if negate
. -a1
.end
endf
function t2h, t
alias t=v1,\
c=v2, n=v3
. t=a1, (u8) c=*t
.if c=30h
.while c=30h
. (u8) c=*t++
.endw
. t--
.end
.if c=0
return 0
.end
. n=0
.forever
. (u8) c=*t++
.if c=0
return n
.end
. n<<4
.if c<=39h
. c-30h
.else.if c>=97
. c-57h
.else
. c-37h
.end
. n+c
.endfv
endf
function t2b, t
alias t=v1,\
c=v2, n=v3
. t=a1, (u8) c=*t
.if c=30h
.while c=30h
. (u8) c=*t++
.endw
. t--
.end
.if c=0
return 0
.end
. n=0
.forever
. (u8) c=*t++
.if c=0
return n
.end
. n<<1, n+c
. n-30h
.endfv
endf
function text.skip.while, t, type
alias t=a1, type=a2,\
c=a3, p=a4, n=v1
.forever
. (u8) c=*t
.if c=0
return 0
.end
.if c=0Ah
. p=line.n, (u32) n=*p
. n++, (u32) *p=n
.end
. p=TLT, p+c
. (u8) c=*p, c&type
.breakz
. t++
.endfv
. (u8) c=*t
.if c=0
return 0
.end
endf
function text.skip.until, t, type
alias t=a1, type=a2,\
c=a3, p=a4, n=v1
.forever
. (u8) c=*t
.if c=0
return 0
.end
.if c=0Ah
. p=line.n, (u32) n=*p
. n++, (u32) *p=n
.end
. p=TLT, p+c
. (u8) c=*p, c&type
.breakn
. t++
.endfv
. (u8) c=*t
.if c=0
return 0
.end
endf
function text.copy.while, a, b, type
alias a=a1, b=a2,\
type=a3, c=a4, p=v1, n=v2
.forever
. (u8) c=*b
.if c=0
go .e
.end
.if c=0Ah
. p=line.n, (u32) n=*p
. n++, (u32) *p=n
.end
. p=TLT, p+c
. (u8) c=*p, c&type
.breakz
. (u8) *a++=*b++
.endfv
.e:
. (u8) *a=0, (u8) c=*b
.if c=0
return 0
.end
endf b
function text.copy.until, a, b, type
alias a=a1, b=a2,\
type=a3, c=a4, p=v1, n=v2
.forever
. (u8) c=*b
.if c=0
return 0
.end
.if c=0Ah
. p=line.n, (u32) n=*p
. n++, (u32) *p=n
.end
. p=TLT, p+c
. (u8) c=*p, c&type
.breakn
. (u8) *a++=*b++
.endfv
. (u8) *a=0, (u8) c=*b
.if c=0
return 0
.end
endf b
macro define.source {
align 4
void source.p, destiny.p, token.p
integer token.type, token.value,\
token.size, line.n, n.lines
}
macro set.source r
{ . r12=source.p, r11=r, (u32) *r12=r11 }
macro set.token r
{ . r12=token.p, r11=r, (u32) *r12=r11 }
macro set.stream s, t {
set.source s
set.token t
}
macro get.source s, t {
. s=source.p, (u32) s=*s
if ~t eq
. t=token.p, (u32) t=*t
end if
}
get.destiny fix get.console
set.destiny fix set.console
save.destiny fix save.console
macro get.token.p t
{ . t=token.p, (u32) t=*t }
macro set.token.x x, v
{ . r12=token#x, r11=v, (u32) *r12=r11 }
macro set.token.type v { set.token.x .type, v }
macro set.token.class v { set.token.x .class, v }
macro set.token.value v { set.token.x .value, v }
macro get.token.value x
{ . x=token.value, (u32) x=*x }
function skip.while, type
alias p=v1, type=v2
. type=a1
get.source p
try p=text.skip.while p, type
set.source p
endf p
function skip.until, type
alias p=v1, type=v2
. type=a1
get.source p
try p=text.skip.until p, type
set.source p
endf p
function copy.while, type
alias p=v1, t=v2, type=v3
. type=a1
get.source p, t
try p=text.copy.while t, p, type
set.source p
endf p
function copy.until, type
alias p=v1, t=v2, type=v3
. type=a1
get.source p, t
try p=text.copy.until t, p, type
set.source p
endf p
macro skip.space { skip.while C.SPACE }
macro skip.white { skip.while C.WHITE }
macro skip.comment { skip.until C.RETURN }
function skip.all
alias s=v1, c=v2
.white:
try skip.white
get.source s
. (u8) c=*s
.if c=0
return 0
.end
.if c=SEMI.C
try skip.comment
go .white
.end
endf 1
function skip.c, key
alias p=v1,\
c=v2, key=v3
. key=a1
skip.space
get.source p
. (u8) c=*p
.if c<>key
return 0
.end
. p++
set.source p
endf p
function vga.xy, x, y
. a3=SCREEN.PITCH, a4=a2*a3
. a4+(a1<<1), a2=@vga, a1=a2+a4
endf
function clear.screen, c
alias vga=a3,\
w=a2, c=a1
. vga=@vga, w=SCREEN.N
.repeat w
. (u16) *vga++=c
.endr
endf
function draw.pixel, x, y, c
alias vga=a1, c=v1
. c=a3
vga.xy
. (u16) *vga=c
endf
function draw.line.h, x, y, w, c
alias vga=a1,\
c=v1, w=v2
. c=a4, w=a3
vga.xy
.repeat w
. (u16) *vga++=c
.endr
endf
function draw.line.v, x, y, h, c
alias vga=a1,\
h=v1, c=v2, pitch=v3
. c=a4, h=a3
vga.xy
. pitch=SCREEN.PITCH
.repeat h
. (u16) *vga=c, vga+pitch
.endr
endf
function draw.box
alias vga=a1, c=v1,\
sw=v2, w=v3, h=v4,\
pitch=a2, wb=a3
. w=a3, sw=w, h=a4
vga.xy
. pitch=SCREEN.PITCH
. wb=w<<1
.repeat h
. w=sw
.repeat w
. (u16) *vga++=c
.endr
. vga+pitch, vga-wb
.endr
endf
macro draw.box x, y, w, h, c {
if ~x eq
. v1=c, a1=x, a2=y, a3=w, a4=h
end if
draw.box
}
function draw.outline
alias c=v1,\
x=v2, y=v3, w=v4, h=v5
. x=a1, y=a2, w=a3, h=a4
vga.xy
draw.line.h x, y, w, c
draw.line.v x, y, h, c
. a1=x+w, a1--
draw.line.v \
a1, y+1, h-1, c
. a2=y+h, a2--
draw.line.h x, a2, w, c
endf
macro draw.outline x, y, w, h, c {
if ~x eq
. a1=x, a2=y, a3=w, a4=h, v1=c
end if
draw.outline
}
function draw.box.t
alias vga=a1, c=v1,\
w=v3, h=v4, sw=v2,\
cl=v5, a=v6,\
pitch=a2,\
wb=a3, sc=v7
. w=a3, sw=w, h=a4
vga.xy
. pitch=SCREEN.PITCH
. wb=w<<1
.repeat h
. w=sw
.repeat w
. (u16) c=*vga
pusha
mix c, cl, a
. c=a1
popa
. (u16) *vga++=c
.endr
. vga+pitch, vga-wb
.endr
endf
macro draw.box.t x, y, w, h, c, a {
. a1=x, a2=y, a3=w, a4=h, v5=c, v6=a
draw.box.t
}
function draw.scanline, x, y, w, p
alias vga=a1,\
p=v1, w=v2
. p=a4, w=a3
vga.xy
.repeat w
. (u16) *vga++=*p++
.endr
endf
function draw.scanline.t, x, y, w, p
alias vga=a1,\
c=a2, key=v2,\
w=v3, p=v1
. p=a4, w=a3
vga.xy
. (u16) key=*p
.repeat w
. (u16) c=*p++
.if c<>key
. (u16) *vga=c
.end
. vga+2
.endr
endf
function draw.scanline.v
alias vga=a1,\
p=v1, c=v2, s=v3,\
cl=v4, x=v5, w=v6,\
n=v7
. w=a3, cl=a4
vga.xy
.repeat w
. (u16) c=*p++
.if c=0
go .next
.end
. x=WHITE
.if c=x
. c=cl
go .draw
.end
. (u16) s=*vga
. n=c&11111b, n<<3
.if n>=252
go .next
.end
.if n<=4
. c=cl
go .draw
.end
pusha
mix s, cl, n
. c=r0
popa
.draw:
. (u16) *vga=c
.next:
. vga+2
.endr
endf
macro draw.scanline.v x, y, w, c, p {
. a1=x, a2=y, a3=w, a4=c, v1=p
draw.scanline.v
}
function draw.bitmap
alias vga=a1,\
image=v1,\
w=v2, h=v3, sw=v4,\
pitch=v5, iwb=v6
. w=a3, h=a4, sw=w
. pitch=SCREEN.PITCH
. iwb=w<<1
vga.xy
.repeat h
. w=sw
.repeat w
. (u16) \
*vga++=*image++
.endr
. vga+pitch, vga-iwb
.endr
endf
macro draw.bitmap p, x, y, w, h {
if ~p eq
. v1=p, a1=x, a2=y, a3=w, a4=h
end if
draw.bitmap
}
function draw.bitmap.t
alias \
vga=a1, image=v1,\
w=v2, h=v3, sw=v4,\
pitch=v5, iwb=v6,\
key=v7, c=a2
. w=a3, h=a4, sw=w
. pitch=SCREEN.PITCH
. iwb=w<<1
. (u16) key=*image
vga.xy
.repeat h
. w=sw
.repeat w
. (u16) c=*image++
.if c<>key
. (u16) *vga++=c
.else
. vga+2
.end
.endr
. vga+pitch, vga-iwb
.endr
endf
macro draw.bitmap.t p, x, y, w, h {
if ~p eq
. v1=p, a1=x, a2=y, a3=w, a4=h
end if
draw.bitmap.t
}
function draw.bitmap.a
alias \
vga=a1, image=v1,\
w=v2, h=v3, sw=v4,\
pitch=v5, iwb=v6,\
key=v7, a=v8, c=r12
. w=a3, h=a4, sw=w
. pitch=SCREEN.PITCH
. iwb=w<<1
. (u16) key=*image
vga.xy
.repeat h
. w=sw
.repeat w
. (u16) c=*image++
.if c<>key
pusha
. (u16) a2=*vga
. a1=c, a3=a
mix
. c=a1
popa
. (u16) *vga++=c
.else
. vga+2
.end
.endr
. vga+pitch, vga-iwb
.endr
endf
macro draw.bitmap.a p, x, y, w, h, a {
if ~p eq
. v1=p, a1=x, a2=y, a3=w, a4=h, v8=a
end if
draw.bitmap.a
}
function draw.fade
alias vga=a1,\
r=v1, g=v2, b=v3,\
rn=v4, gn=v5, bn=v6,\
c1=v7, c2=v8, h=r12
pusha
. c1=v5, c2=v6, h=a4
delta8 c1, c2, 11, h
. rn=a1
delta8 c1, c2, 5, h
. gn=a1
delta8 c1, c2, 0, h
. bn=a1, a1=c1
get.rgb
. r=a1<<8
. g=a2<<8
. b=a3<<8
popa
push a3-a4
vga.xy
pop a3-a4
.repeat h
pusha
get c1=rgb r>>>8,\
g>>>8, b>>>8
popa
. v8=a3
.repeat v8
. (u16) *vga++=c1
.endr
. a2=SCREEN.PITCH
. a1-(a3<<1), a1+a2
. r+rn, g+gn, b+bn
.endr
endf
macro draw.fade x, y, w, h, c1, c2 {
. a1=x, a2=y, a3=w, a4=h, v5=c1, v6=c2
draw.fade
}
function draw.shade
alias \
x=a1, y=a2,\
w=a3, h=a4,\
c1=v5, c2=v6,\
tmp=v7
. h>>>1
pusha
draw.fade \
x, y, w, h,\
c1, c2
popa
. y+h, tmp=c1
. c1=c2, c2=tmp
draw.fade \
x, y, w, h,\
c1, c2
endf
macro draw.shade x, y, w, h, c1, c2 {
. a1=x, a2=y, a3=w, a4=h, v5=c1, v6=c2
draw.shade
}
function draw.black.bar, x, y, w, h
alias \
x=a1, y=a2,\
w=a3, h=a4,\
c1=v5, c2=v6
. h>>>1
pusha
draw.fade x, y, w, h,\
GRAY, GRAY25
popa
pusha
. y+h
draw.fade x, y, w, h,\
BLACK, GRAY25
popa
pusha
. h<<1
draw.outline \
x, y, w, h, GRAY
popa
pusha
draw.line.h \
x, y, w, GRAY.L
popa
endf