1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-12-24 15:29:29 +00:00

Optimized memcpy, uppercase on ][&][+, update test suite

This commit is contained in:
David Schmenk 2014-06-06 19:08:54 -07:00
parent 45f24c105b
commit fc91062291
7 changed files with 416 additions and 359 deletions

View File

@ -13,9 +13,9 @@ const CFFAEntryPtr = $0B
predef home, gotoxy, viewport, crout, cout, prstr, cin, rdstr
predef syscall
predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy, xmemcpy
predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle
predef execmod
predef loadmod, execmod
;
; Exported Machine ID.
;
@ -44,6 +44,7 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD"
byte execstr[] = "EXEC"
word exports[] = @clsstr, @home
word = @gotoxystr, @gotoxy
@ -63,6 +64,7 @@ word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle
word = @loadstr, @loadmod
word = @execstr, @execmod
word = @machidstr, @machid
word = 0
@ -146,74 +148,72 @@ end
; MEMCPY(DSTADDR, SRCADDR, SIZE)
;
asm memcpy
LDY #$00
INX
INX
LDA ESTKL-2,X
ORA ESTKH-2,X
BEQ CPYMEX
LDA ESTKL-1,X
CMP ESTKL,X
LDA ESTKH-1,X
SBC ESTKH,X
BCC REVCPY
;
; FORWARD COPY
;
LDA ESTKL,X
BNE +
LDA ESTKH,X
BEQ CPYMEX
+ LDA ESTKL+2,X
STA DSTL
LDA ESTKH+2,X
LDA ESTKH,X
STA DSTH
LDA ESTKL+1,X
LDA ESTKL-1,X
STA SRCL
LDA ESTKH+1,X
LDA ESTKH-1,X
STA SRCH
CMP DSTH
BCC REVCPY
BNE FORCPY
LDA SRCL
CMP DSTL
BCS FORCPY
REVCPY ; REVERSE DIRECTION COPY
; CLC
LDA ESTKL,X
ADC DSTL
STA DSTL
LDA ESTKH,X
ADC DSTH
STA DSTH
CLC
LDA ESTKL,X
ADC SRCL
STA SRCL
LDA ESTKH,X
ADC SRCH
STA SRCH
INC ESTKH,X
REVCPYLP
LDA DSTL
BNE +
DEC DSTH
+ DEC DSTL
LDA SRCL
BNE +
DEC SRCH
+ DEC SRCL
LDA (SRC),Y
INC ESTKH-2,X
LDY #$00
FORCPYLP LDA (SRC),Y
STA (DST),Y
DEC ESTKL,X
BNE REVCPYLP
DEC ESTKH,X
BNE REVCPYLP
BEQ CPYMEX
FORCPY INC ESTKH,X
FORCPYLP
LDA (SRC),Y
STA (DST),Y
INC DSTL
INY
BNE +
INC DSTH
+ INC SRCL
BNE +
INC SRCH
+ DEC ESTKL,X
+ DEC ESTKL-2,X
BNE FORCPYLP
DEC ESTKH,X
DEC ESTKH-2,X
BNE FORCPYLP
CPYMEX INX
INX
RTS
;
; REVERSE COPY
;
REVCPY ;CLC
LDA ESTKL-2,X
ADC ESTKL,X
STA DSTL
LDA ESTKH-2,X
ADC ESTKH,X
STA DSTH
CLC
LDA ESTKL-2,X
ADC ESTKL-1,X
STA SRCL
LDA ESTKH-2,X
ADC ESTKH-1,X
STA SRCH
INC ESTKH-2,X
DEC DSTH
DEC SRCH
LDY #$FF
REVCPYLP LDA (SRC),Y
STA (DST),Y
DEY
BNE +
DEC DSTH
DEC SRCH
+ DEC ESTKL-2,X
BNE REVCPYLP
DEC ESTKH-2,X
BNE REVCPYLP
CPYMEX RTS
end
;
; Unsigned word comparisons.

View File

@ -5,13 +5,6 @@ const MODADDR = $1000
const symtbl = $0C00
const freemem = $0006
;
; ROMCALL return register structure.
;
const acc = 0
const xreg = 1
const yreg = 2
const preg = 3
;
; System flags: memory allocator screen holes.
;
const restxt1 = $0001
@ -24,11 +17,11 @@ const resxhgr2 = $0020
; Pedefined functions.
;
predef home, gotoxy, viewport, crout, cout, prstr, cin, rdstr
predef syscall, romcall
predef syscall
predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle
predef execmod
predef loadmod, execmod
;
; Standard Library exported functions.
;
@ -42,7 +35,6 @@ byte putsstr[] = "PUTS"
byte getcstr[] = "GETC"
byte getsstr[] = "GETS"
byte sysstr[] = "SYSCALL"
byte romstr[] = "ROMCALL"
byte hpmarkstr[] = "HEAPMARK"
byte hpalignstr[] = "HEAPALLOCALIGN"
byte hpallocstr[] = "HEAPALLOC"
@ -54,6 +46,7 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD"
byte execstr[] = "EXEC"
word exports[] = @clsstr, @home
word = @gotoxystr, @gotoxy
@ -63,7 +56,6 @@ word = @putsstr, @prstr
word = @getcstr, @cin
word = @getsstr, @rdstr
word = @sysstr, @syscall
word = @romstr, @romcall
word = @hpmarkstr, @markheap
word = @hpallocstr,@allocheap
word = @hpalignstr,@allocalignheap
@ -74,6 +66,7 @@ word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle
word = @loadstr, @loadmod
word = @execstr, @execmod
word = @machidstr, MACHID
word = 0
@ -112,50 +105,6 @@ LCBNK1 = $08
!SOURCE "plvm02zp.inc"
end
;
; CALL 6502 ROUTINE
; ROMCALL(AREG, XREG, YREG, STATUS, ADDR)
;
asm romcall
PHP
LDA ESTKL,X
STA TMPL
LDA ESTKH,X
STA TMPH
INX
LDA ESTKL,X
PHA
INX
LDA ESTKL,X
TAY
INX
LDA ESTKL+1,X
PHA
LDA ESTKL,X
INX
STX ESP
TAX
PLA
BIT ROMEN
PLP
JSR JMPTMP
PHP
BIT LCRDEN+LCBNK2
STA REGVALS+0
STX REGVALS+1
STY REGVALS+2
PLA
STA REGVALS+3
LDX ESP
LDA #<REGVALS
LDY #>REGVALS
STA ESTKL,X
STY ESTKH,X
PLP
RTS
REGVALS !FILL 4
JMPTMP JMP (TMP)
end
;
; CALL PRODOS
; SYSCALL(CMD, PARAMS)
;
@ -238,81 +187,77 @@ end
; MEMCPY(DSTADDR, SRCADDR, SIZE)
;
asm memcpy
LDY #$00
INX
INX
LDA ESTKL-2,X
ORA ESTKH-2,X
BEQ CPYMEX
LDA ESTKL-1,X
CMP ESTKL,X
LDA ESTKH-1,X
SBC ESTKH,X
BCC REVCPY
;
; FORWARD COPY
;
LDA ESTKL,X
BNE +
LDA ESTKH,X
BEQ CPYMEX
+ LDA ESTKL+2,X
STA DSTL
LDA ESTKH+2,X
LDA ESTKH,X
STA DSTH
LDA ESTKL+1,X
LDA ESTKL-1,X
STA SRCL
LDA ESTKH+1,X
LDA ESTKH-1,X
STA SRCH
CMP DSTH
BCC REVCPY
BNE FORCPY
LDA SRCL
CMP DSTL
BCS FORCPY
REVCPY ; REVERSE DIRECTION COPY
; CLC
LDA ESTKL,X
ADC DSTL
STA DSTL
LDA ESTKH,X
ADC DSTH
STA DSTH
CLC
LDA ESTKL,X
ADC SRCL
STA SRCL
LDA ESTKH,X
ADC SRCH
STA SRCH
INC ESTKH,X
REVCPYLP
LDA DSTL
BNE +
DEC DSTH
+ DEC DSTL
LDA SRCL
BNE +
DEC SRCH
+ DEC SRCL
LDA (SRC),Y
INC ESTKH-2,X
LDY #$00
FORCPYLP LDA (SRC),Y
STA (DST),Y
DEC ESTKL,X
BNE REVCPYLP
DEC ESTKH,X
BNE REVCPYLP
BEQ CPYMEX
FORCPY INC ESTKH,X
FORCPYLP
LDA (SRC),Y
STA (DST),Y
INC DSTL
INY
BNE +
INC DSTH
+ INC SRCL
BNE +
INC SRCH
+ DEC ESTKL,X
+ DEC ESTKL-2,X
BNE FORCPYLP
DEC ESTKH,X
DEC ESTKH-2,X
BNE FORCPYLP
CPYMEX INX
INX
RTS
;
; REVERSE COPY
;
REVCPY ;CLC
LDA ESTKL-2,X
ADC ESTKL,X
STA DSTL
LDA ESTKH-2,X
ADC ESTKH,X
STA DSTH
CLC
LDA ESTKL-2,X
ADC ESTKL-1,X
STA SRCL
LDA ESTKH-2,X
ADC ESTKH-1,X
STA SRCH
INC ESTKH-2,X
DEC DSTH
DEC SRCH
LDY #$FF
REVCPYLP LDA (SRC),Y
STA (DST),Y
DEY
BNE +
DEC DSTH
DEC SRCH
+ DEC ESTKL-2,X
BNE REVCPYLP
DEC ESTKH-2,X
BNE REVCPYLP
CPYMEX RTS
end
;
; COPY FROM MAIN MEM TO AUX MEM.
;
; MEMXCPY(DIR, DST, SRC, SIZE)
; DIR = 0 : COPY FROM MAIN TO AUX
; DIR = 1 : COPY FROM AUX TO MAIN
; MEMXCPY(DST, SRC, SIZE)
;
asm memxcpy
LDA ESTKL+1,X
@ -330,14 +275,24 @@ asm memxcpy
STA $43
STX ESP
BIT ROMEN
LDA #$00
CMP ESTKL+3,X
SEC
JSR $C311
BIT LCRDEN+LCBNK2
LDX ESP
INX
INX
INX
RTS
end
;
; HOME
;
asm home
STX ESP
BIT ROMEN
JSR $FC58
BIT LCRDEN+LCBNK2
LDX ESP
DEX
RTS
end
;
@ -345,7 +300,17 @@ end
; VIEWPORT(LEFT, TOP, WIDTH, HEIGHT)
;
asm viewport
LDA ESTKL+3,X
LDA ESTKL+1,X
BNE +
LDA ESTKL,X
BNE +
STA ESTKL+3,X
STA ESTKL+2,X
LDA #40
STA ESTKL+1,X
LDA #24
STA ESTKL,X
+ LDA ESTKL+3,X
STA $20
LDA ESTKL+1,X
STA $21
@ -386,19 +351,42 @@ VTAB STX ESP
INX
RTS
end
asm crout
DEX
LDA #$8D
STA ESTKL,X
; FALL THROUGH TO COUT
end
;
; CHAR OUT
; COUT(CHAR)
;
asm cout
LDA ESTKL,X
ORA #$80
BIT $BF98
BMI +
JSR TOUPR
+ ORA #$80
BIT ROMEN
JSR $FDED
BIT LCRDEN+LCBNK2
RTS
end
;
; CHAR IN
; RDKEY()
;
asm cin
BIT ROMEN
JSR $FD0C
BIT LCRDEN+LCBNK2
DEX
LDY #$00
STA ESTKL,X
STY ESTKH,X
RTS
end
;
; PRINT STRING
; PRSTR(STR)
;
@ -410,18 +398,21 @@ asm prstr
STA SRCH
STY ESTKH,X
LDA (SRC),Y
STA ESTKL,X
BEQ +
STA TMP
BEQ ++
BIT ROMEN
- INY
LDA (SRC),Y
ORA #$80
BIT $BF98
BMI +
JSR TOUPR
+ ORA #$80
JSR $FDED
TYA
CMP ESTKL,X
CMP TMP
BNE -
BIT LCRDEN+LCBNK2
+ RTS
++ RTS
end
;
; PRINT BYTE
@ -727,22 +718,6 @@ asm lookuptbl
BNE -
end
;
; CHAR IN
; RDKEY()
;
def cin
return romcall(0, 0, 0, 0, $FD0C).acc
end
;
; HOME
;
def home
return romcall(0, 0, 0, 0, $FC58)
end
def crout
return cout($0D)
end
;
; ProDOS routines
;
def getpfx(path)
@ -1142,7 +1117,7 @@ def loadmod(mod)
;
; Move bytecode to AUX bank.
;
memxcpy(0, defaddr, bytecode, modsize - (bytecode - modaddr))
memxcpy(defaddr, bytecode, modsize - (bytecode - modaddr))
fin
;
; Free up the end-of-module in main memory.

View File

@ -60,9 +60,9 @@ $(CMD): cmd.pla cmdstub.s $(PLVM02) $(PLASM)
acme --setpc 8192 -o $(CMD) cmdstub.s
test: test.pla testlib.pla $(PLVM) $(PLASM)
./$(PLASM) -AM < test.pla > test.a
m4 < test.pla | ./$(PLASM) -AM > test.a
acme --setpc 4094 -o TEST#FE1000 test.a
./$(PLASM) -AM < teslib.pla >testlib.a
m4 < testlib.pla | ./$(PLASM) -AM > testlib.a
acme --setpc 4094 -o TESTLIB#FE1000 testlib.a
./$(PLVM) TEST\#FE1000

View File

@ -1,6 +1,16 @@
import STDLIB
predef romcall, puts
end
;
; ROMCALL return register structure.
;
const acc = 0
const xreg = 1
const yreg = 2
const preg = 3
;
; Hardware constants
;
const speaker=$C030
const showgraphics=$C050
const showtext=$C051
@ -21,7 +31,62 @@ const page2=1
byte exitmsg[] = "PRESS ANY KEY TO EXIT.\n"
byte goodbye[] = "THAT'S ALL FOLKS!\n"
byte i, j, k, w, fmi, fmk, color
asm equates
;*
;* BANK SWITCHED MEM
;*
LCRDEN = $C080
LCWTEN = $C081
ROMEN = $C082
LCRWEN = $C083
LCBNK2 = $00
LCBNK1 = $08
!SOURCE "plvm02zp.inc"
end
;
; CALL 6502 ROUTINE
; ROMCALL(AREG, XREG, YREG, STATUS, ADDR)
;
asm romcall
PHP
LDA ESTKL,X
STA TMPL
LDA ESTKH,X
STA TMPH
INX
LDA ESTKL,X
PHA
INX
LDA ESTKL,X
TAY
INX
LDA ESTKL+1,X
PHA
LDA ESTKL,X
INX
STX ESP
TAX
PLA
BIT ROMEN
PLP
JSR JMPTMP
PHP
BIT LCRDEN+LCBNK2
STA REGVALS+0
STX REGVALS+1
STY REGVALS+2
PLA
STA REGVALS+3
LDX ESP
LDA #<REGVALS
LDY #>REGVALS
STA ESTKL,X
STY ESTKH,X
PLP
RTS
REGVALS !FILL 4
JMPTMP JMP (TMP)
end
def textmode
romcall(0, 0, 0, 0, $FB39)
end

View File

@ -1,22 +1,6 @@
const membank = $FFEF
const MODADDR = $1000
;
; ROMCALL return register structure.
;
const acc = 0
const xreg = 1
const yreg = 2
const preg = 3
;
; System flags: memory allocator screen holes.
;
const restxt1 = $0001
const restxt2 = $0002
const reshgr1 = $0004
const reshgr2 = $0008
const resxhgr1 = $0010
const resxhgr2 = $0020
;
; SOS flags
;
const O_READ = 1
@ -30,7 +14,7 @@ predef syscall, romcall
predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle
predef execmod
predef loadmod, execmod
;
; Exported Machine ID.
;
@ -59,6 +43,7 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD"
byte execstr[] = "EXEC"
word exports[] = @clsstr, @home
word = @gotoxystr, @gotoxy
@ -78,6 +63,7 @@ word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle
word = @loadstr, @loadmod
word = @execstr, @execmod
word = @machidstr, @machid
word = 0
@ -165,72 +151,72 @@ end
; MEMCPY(DSTADDR, SRCADDR, SIZE)
;
asm memcpy
LDY #$00
INX
INX
LDA ESTKL-2,X
ORA ESTKH-2,X
BEQ CPYMEX
LDA ESTKL-1,X
CMP ESTKL,X
LDA ESTKH-1,X
SBC ESTKH,X
BCC REVCPY
;
; FORWARD COPY
;
LDA ESTKL,X
BNE +
LDA ESTKH,X
BEQ CPYMEX
+ LDA ESTKL+2,X
STA DSTL
LDA ESTKH+2,X
LDA ESTKH,X
STA DSTH
LDA ESTKL+1,X
LDA ESTKL-1,X
STA SRCL
LDA ESTKH+1,X
LDA ESTKH-1,X
STA SRCH
CMP DSTH
BCC REVCPY
BNE FORCPY
LDA SRCL
CMP DSTL
BCS FORCPY
REVCPY ; REVERSE DIRECTION COPY
; CLC
LDA ESTKL,X
ADC DSTL
STA DSTL
LDA ESTKH,X
ADC DSTH
STA DSTH
CLC
LDA ESTKL,X
ADC SRCL
STA SRCL
LDA ESTKH,X
ADC SRCH
STA SRCH
INC ESTKH,X
REVCPYLP
LDA DSTL
BNE +
DEC DSTH
+ DEC DSTL
LDA SRCL
BNE +
DEC SRCH
+ DEC SRCL
LDA (SRC),Y
STA (DST),Y
DEC ESTKL,X
BNE REVCPYLP
DEC ESTKH,X
BNE REVCPYLP
BEQ CPYMEX
FORCPY INC ESTKH,X
FORCPYLP
LDA (SRC),Y
INC ESTKH-2,X
LDY #$00
FORCPYLP LDA (SRC),Y
STA (DST),Y
INY
BNE +
INC DSTH
INC SRCH
+ DEC ESTKL,X
+ DEC ESTKL-2,X
BNE FORCPYLP
DEC ESTKH,X
DEC ESTKH-2,X
BNE FORCPYLP
CPYMEX INX
INX
RTS
;
; REVERSE COPY
;
REVCPY ;CLC
LDA ESTKL-2,X
ADC ESTKL,X
STA DSTL
LDA ESTKH-2,X
ADC ESTKH,X
STA DSTH
CLC
LDA ESTKL-2,X
ADC ESTKL-1,X
STA SRCL
LDA ESTKH-2,X
ADC ESTKH-1,X
STA SRCH
INC ESTKH-2,X
DEC DSTH
DEC SRCH
LDY #$FF
REVCPYLP LDA (SRC),Y
STA (DST),Y
DEY
BNE +
DEC DSTH
DEC SRCH
+ DEC ESTKL-2,X
BNE REVCPYLP
DEC ESTKH-2,X
BNE REVCPYLP
CPYMEX RTS
end
;
; COPY FROM MAIN MEM TO EXT MEM.
@ -589,16 +575,16 @@ def close(refnum)
perr = syscall($CC, @params)
return perr
end
def newline(refnum, set, char)
byte params[4]
params.0 = 1
params.1 = refnum
params.2 = set
params.3 = char
perr = syscall($C9, @params)
return perr
end
;def newline(refnum, set, char)
; byte params[4]
;
; params.0 = 1
; params.1 = refnum
; params.2 = set
; params.3 = char
; perr = syscall($C9, @params)
; return perr
;end
def read(refnum, buff, len)
byte params[8]
@ -623,16 +609,16 @@ end
;
; DEVICE I/O
;
def dev_status(devnum, list)
byte params[5]
params.0 = 3
params.1 = devnum
params.2 = 0
params:3 = list
perr = syscall($82, @params)
return params.2
end
;def dev_status(devnum, list)
; byte params[5]
;
; params.0 = 3
; params.1 = devnum
; params.2 = 0
; params:3 = list
; perr = syscall($82, @params)
; return params.2
;end
def dev_control(devnum, code, list)
byte params[5]
@ -692,40 +678,40 @@ def seg_find(search, base, limit, pages, id)
*limit = params:7
return params.9
end
def seg_change(segnum, mode, pages)
byte params[5]
params.0 = 3
params.1 = segnum
params.2 = mode
params:3 = pages
perr = syscall($42, @params)
return params:3
end
def seg_getinfo(segnum, base, limit, pages, id)
byte params[9]
params.0 = 6
params.1 = segnum
params:2 = 0
params:4 = 0
params:6 = 0
params.8 = 0
perr = syscall($43, @params)
*base = params:2
*limit = params:4
*pages = params:6
return params.8
end
def seg_getnum(segaddr)
byte params[4]
params.0 = 2
params:1 = segaddr
params.3 = 0
perr = syscall($44, @params)
return params.3
end
;def seg_change(segnum, mode, pages)
; byte params[5]
;
; params.0 = 3
; params.1 = segnum
; params.2 = mode
; params:3 = pages
; perr = syscall($42, @params)
; return params:3
;end
;def seg_getinfo(segnum, base, limit, pages, id)
; byte params[9]
;
; params.0 = 6
; params.1 = segnum
; params:2 = 0
; params:4 = 0
; params:6 = 0
; params.8 = 0
; perr = syscall($43, @params)
; *base = params:2
; *limit = params:4
; *pages = params:6
; return params.8
;end
;def seg_getnum(segaddr)
; byte params[4]
;
; params.0 = 2
; params:1 = segaddr
; params.3 = 0
; perr = syscall($44, @params)
; return params.3
;end
def seg_release(segnum)
byte params[2]
@ -782,10 +768,19 @@ def gotoxy(x, y)
return cout(y)
end
def viewport(left, top, width, height)
if !width or !height
;
; Reset the full-screen viewport
;
left = 0
top = 0
width = 80
height = 24
fin
cout(1) ; Reset viewport
gotoxy(left, top)
cout(2)
gotoxy(width, height)
gotoxy(width - 1, height - 1)
cout(3)
return gotoxy(0, 0)
end

View File

@ -1,45 +1,55 @@
;
; Declare all imported modules and their data/functions.
; Include all imported modules and their data/functions.
;
import stdlib
predef cls, gotoxy, viewport, puts, putc, getc
end
import testlib
predef puti, putnl
end
const mainentry = 2
;
; Predeclare any functions called before defined.
;
predef ascii, main
include(stdlib.plh)
include(testlib.plh)
;
; Declare all global variables for this module.
;
byte hello[] = "Hello, world.\n"
word defptr = @ascii, @main
word struct[] = 1, 10, 100
word struct[] = 1, 10, 100, 1000, 10000
byte spaces[] = " "
;
; Define functions.
;
def tens(start)
word i
i = start
repeat
print:hex(i)
print:str(@spaces)
print:dec(i)
print:newln()
i = i / 10
until i == 0
end
def ascii
byte i
for i = 32 to 127
i = 32
while i < 128
putc(i)
next
i = i + 1
loop
end
def nums(range)
word i
for i = -10 to range
for i = range downto -range step range/10
puti(i)
putnl
putln
next
end
export def main(range)
cls
nums(range)
nums(*range)
tens(*range*10)
viewport(12, 12, 16, 8)
ascii
viewport(0, 0, 40, 24)
@ -47,11 +57,5 @@ export def main(range)
puts(@hello)
end
export def indirect
word mainptr
mainptr = @main
return defptr:mainentry(struct:2)
end
indirect
main(@struct:6)
done

View File

@ -1,13 +1,30 @@
;
; Declare all imported modules and their data/functions.
; Include all imported modules and their data/functions.
;
import stdlib
predef cls, gotoxy, puts, putc
end
include(stdlib.plh)
;
; Module data.
;
predef puti, puth, putln
export word print[] = @puti, @puth, @putln, @puts, @putc
byte valstr[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
byte loadstr[] = "testlib loaded!"
;
; Define functions.
;
def puth(h)
putc('$')
putc(valstr[(h >> 12) & $0F])
putc(valstr[(h >> 8) & $0F])
putc(valstr[(h >> 4) & $0F])
putc(valstr[ h & $0F])
end
export def puti(i)
if i < 0
putc('-')
@ -20,10 +37,11 @@ export def puti(i)
putc(i % 10 + '0')
fin
end
export def putnl
export def putln
putc($0D)
end
puts(@loadstr)
putnl
putln
done