1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-12 20:29:49 +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 home, gotoxy, viewport, crout, cout, prstr, cin, rdstr
predef syscall predef syscall
predef markheap, allocheap, allocalignheap, releaseheap, availheap predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy, xmemcpy predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle predef uword_isgt, uword_isge, uword_islt, uword_isle
predef execmod predef loadmod, execmod
; ;
; Exported Machine ID. ; Exported Machine ID.
; ;
@ -44,6 +44,7 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE" byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT" byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE" byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD"
byte execstr[] = "EXEC" byte execstr[] = "EXEC"
word exports[] = @clsstr, @home word exports[] = @clsstr, @home
word = @gotoxystr, @gotoxy word = @gotoxystr, @gotoxy
@ -63,6 +64,7 @@ word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle word = @uislestr, @uword_isle
word = @loadstr, @loadmod
word = @execstr, @execmod word = @execstr, @execmod
word = @machidstr, @machid word = @machidstr, @machid
word = 0 word = 0
@ -146,74 +148,72 @@ end
; MEMCPY(DSTADDR, SRCADDR, SIZE) ; MEMCPY(DSTADDR, SRCADDR, SIZE)
; ;
asm memcpy asm memcpy
LDY #$00 INX
LDA ESTKL,X INX
BNE + LDA ESTKL-2,X
LDA ESTKH,X ORA ESTKH-2,X
BEQ CPYMEX BEQ CPYMEX
+ LDA ESTKL+2,X LDA ESTKL-1,X
STA DSTL CMP ESTKL,X
LDA ESTKH+2,X LDA ESTKH-1,X
STA DSTH SBC ESTKH,X
LDA ESTKL+1,X
STA SRCL
LDA ESTKH+1,X
STA SRCH
CMP DSTH
BCC REVCPY BCC REVCPY
BNE FORCPY ;
LDA SRCL ; FORWARD COPY
CMP DSTL ;
BCS FORCPY
REVCPY ; REVERSE DIRECTION COPY
; CLC
LDA ESTKL,X LDA ESTKL,X
ADC DSTL
STA DSTL STA DSTL
LDA ESTKH,X LDA ESTKH,X
ADC DSTH
STA DSTH STA DSTH
CLC LDA ESTKL-1,X
LDA ESTKL,X
ADC SRCL
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH-1,X
ADC SRCH
STA SRCH STA SRCH
INC ESTKH,X INC ESTKH-2,X
REVCPYLP LDY #$00
LDA DSTL FORCPYLP LDA (SRC),Y
BNE +
DEC DSTH
+ DEC DSTL
LDA SRCL
BNE +
DEC SRCH
+ DEC SRCL
LDA (SRC),Y
STA (DST),Y STA (DST),Y
DEC ESTKL,X INY
BNE REVCPYLP
DEC ESTKH,X
BNE REVCPYLP
BEQ CPYMEX
FORCPY INC ESTKH,X
FORCPYLP
LDA (SRC),Y
STA (DST),Y
INC DSTL
BNE + BNE +
INC DSTH INC DSTH
+ INC SRCL
BNE +
INC SRCH INC SRCH
+ DEC ESTKL,X + DEC ESTKL-2,X
BNE FORCPYLP BNE FORCPYLP
DEC ESTKH,X DEC ESTKH-2,X
BNE FORCPYLP BNE FORCPYLP
CPYMEX INX
INX
RTS 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 end
; ;
; Unsigned word comparisons. ; Unsigned word comparisons.

View File

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

View File

@ -1,6 +1,16 @@
import STDLIB import STDLIB
predef romcall, puts predef romcall, puts
end end
;
; ROMCALL return register structure.
;
const acc = 0
const xreg = 1
const yreg = 2
const preg = 3
;
; Hardware constants
;
const speaker=$C030 const speaker=$C030
const showgraphics=$C050 const showgraphics=$C050
const showtext=$C051 const showtext=$C051
@ -21,7 +31,62 @@ const page2=1
byte exitmsg[] = "PRESS ANY KEY TO EXIT.\n" byte exitmsg[] = "PRESS ANY KEY TO EXIT.\n"
byte goodbye[] = "THAT'S ALL FOLKS!\n" byte goodbye[] = "THAT'S ALL FOLKS!\n"
byte i, j, k, w, fmi, fmk, color 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 def textmode
romcall(0, 0, 0, 0, $FB39) romcall(0, 0, 0, 0, $FB39)
end end

View File

@ -1,22 +1,6 @@
const membank = $FFEF const membank = $FFEF
const MODADDR = $1000 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 ; SOS flags
; ;
const O_READ = 1 const O_READ = 1
@ -30,7 +14,7 @@ predef syscall, romcall
predef markheap, allocheap, allocalignheap, releaseheap, availheap predef markheap, allocheap, allocalignheap, releaseheap, availheap
predef memset, memcpy predef memset, memcpy
predef uword_isgt, uword_isge, uword_islt, uword_isle predef uword_isgt, uword_isge, uword_islt, uword_isle
predef execmod predef loadmod, execmod
; ;
; Exported Machine ID. ; Exported Machine ID.
; ;
@ -59,6 +43,7 @@ byte uisgtstr[] = "ISUGT"
byte uisgestr[] = "ISUGE" byte uisgestr[] = "ISUGE"
byte uisltstr[] = "ISULT" byte uisltstr[] = "ISULT"
byte uislestr[] = "ISULE" byte uislestr[] = "ISULE"
byte loadstr[] = "LOAD"
byte execstr[] = "EXEC" byte execstr[] = "EXEC"
word exports[] = @clsstr, @home word exports[] = @clsstr, @home
word = @gotoxystr, @gotoxy word = @gotoxystr, @gotoxy
@ -78,6 +63,7 @@ word = @uisgtstr, @uword_isgt
word = @uisgestr, @uword_isge word = @uisgestr, @uword_isge
word = @uisltstr, @uword_islt word = @uisltstr, @uword_islt
word = @uislestr, @uword_isle word = @uislestr, @uword_isle
word = @loadstr, @loadmod
word = @execstr, @execmod word = @execstr, @execmod
word = @machidstr, @machid word = @machidstr, @machid
word = 0 word = 0
@ -165,72 +151,72 @@ end
; MEMCPY(DSTADDR, SRCADDR, SIZE) ; MEMCPY(DSTADDR, SRCADDR, SIZE)
; ;
asm memcpy asm memcpy
LDY #$00 INX
LDA ESTKL,X INX
BNE + LDA ESTKL-2,X
LDA ESTKH,X ORA ESTKH-2,X
BEQ CPYMEX BEQ CPYMEX
+ LDA ESTKL+2,X LDA ESTKL-1,X
STA DSTL CMP ESTKL,X
LDA ESTKH+2,X LDA ESTKH-1,X
STA DSTH SBC ESTKH,X
LDA ESTKL+1,X
STA SRCL
LDA ESTKH+1,X
STA SRCH
CMP DSTH
BCC REVCPY BCC REVCPY
BNE FORCPY ;
LDA SRCL ; FORWARD COPY
CMP DSTL ;
BCS FORCPY
REVCPY ; REVERSE DIRECTION COPY
; CLC
LDA ESTKL,X LDA ESTKL,X
ADC DSTL
STA DSTL STA DSTL
LDA ESTKH,X LDA ESTKH,X
ADC DSTH
STA DSTH STA DSTH
CLC LDA ESTKL-1,X
LDA ESTKL,X
ADC SRCL
STA SRCL STA SRCL
LDA ESTKH,X LDA ESTKH-1,X
ADC SRCH
STA SRCH STA SRCH
INC ESTKH,X INC ESTKH-2,X
REVCPYLP LDY #$00
LDA DSTL FORCPYLP LDA (SRC),Y
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
STA (DST),Y STA (DST),Y
INY INY
BNE + BNE +
INC DSTH INC DSTH
INC SRCH INC SRCH
+ DEC ESTKL,X + DEC ESTKL-2,X
BNE FORCPYLP BNE FORCPYLP
DEC ESTKH,X DEC ESTKH-2,X
BNE FORCPYLP BNE FORCPYLP
CPYMEX INX
INX
RTS 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 end
; ;
; COPY FROM MAIN MEM TO EXT MEM. ; COPY FROM MAIN MEM TO EXT MEM.
@ -589,16 +575,16 @@ def close(refnum)
perr = syscall($CC, @params) perr = syscall($CC, @params)
return perr return perr
end end
def newline(refnum, set, char) ;def newline(refnum, set, char)
byte params[4] ; byte params[4]
;
params.0 = 1 ; params.0 = 1
params.1 = refnum ; params.1 = refnum
params.2 = set ; params.2 = set
params.3 = char ; params.3 = char
perr = syscall($C9, @params) ; perr = syscall($C9, @params)
return perr ; return perr
end ;end
def read(refnum, buff, len) def read(refnum, buff, len)
byte params[8] byte params[8]
@ -623,16 +609,16 @@ end
; ;
; DEVICE I/O ; DEVICE I/O
; ;
def dev_status(devnum, list) ;def dev_status(devnum, list)
byte params[5] ; byte params[5]
;
params.0 = 3 ; params.0 = 3
params.1 = devnum ; params.1 = devnum
params.2 = 0 ; params.2 = 0
params:3 = list ; params:3 = list
perr = syscall($82, @params) ; perr = syscall($82, @params)
return params.2 ; return params.2
end ;end
def dev_control(devnum, code, list) def dev_control(devnum, code, list)
byte params[5] byte params[5]
@ -692,40 +678,40 @@ def seg_find(search, base, limit, pages, id)
*limit = params:7 *limit = params:7
return params.9 return params.9
end end
def seg_change(segnum, mode, pages) ;def seg_change(segnum, mode, pages)
byte params[5] ; byte params[5]
;
params.0 = 3 ; params.0 = 3
params.1 = segnum ; params.1 = segnum
params.2 = mode ; params.2 = mode
params:3 = pages ; params:3 = pages
perr = syscall($42, @params) ; perr = syscall($42, @params)
return params:3 ; return params:3
end ;end
def seg_getinfo(segnum, base, limit, pages, id) ;def seg_getinfo(segnum, base, limit, pages, id)
byte params[9] ; byte params[9]
;
params.0 = 6 ; params.0 = 6
params.1 = segnum ; params.1 = segnum
params:2 = 0 ; params:2 = 0
params:4 = 0 ; params:4 = 0
params:6 = 0 ; params:6 = 0
params.8 = 0 ; params.8 = 0
perr = syscall($43, @params) ; perr = syscall($43, @params)
*base = params:2 ; *base = params:2
*limit = params:4 ; *limit = params:4
*pages = params:6 ; *pages = params:6
return params.8 ; return params.8
end ;end
def seg_getnum(segaddr) ;def seg_getnum(segaddr)
byte params[4] ; byte params[4]
;
params.0 = 2 ; params.0 = 2
params:1 = segaddr ; params:1 = segaddr
params.3 = 0 ; params.3 = 0
perr = syscall($44, @params) ; perr = syscall($44, @params)
return params.3 ; return params.3
end ;end
def seg_release(segnum) def seg_release(segnum)
byte params[2] byte params[2]
@ -782,10 +768,19 @@ def gotoxy(x, y)
return cout(y) return cout(y)
end end
def viewport(left, top, width, height) 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 cout(1) ; Reset viewport
gotoxy(left, top) gotoxy(left, top)
cout(2) cout(2)
gotoxy(width, height) gotoxy(width - 1, height - 1)
cout(3) cout(3)
return gotoxy(0, 0) return gotoxy(0, 0)
end 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 include(stdlib.plh)
predef puti, putnl include(testlib.plh)
end
const mainentry = 2
;
; Predeclare any functions called before defined.
;
predef ascii, main
; ;
; Declare all global variables for this module. ; Declare all global variables for this module.
; ;
byte hello[] = "Hello, world.\n" byte hello[] = "Hello, world.\n"
word defptr = @ascii, @main word struct[] = 1, 10, 100, 1000, 10000
word struct[] = 1, 10, 100 byte spaces[] = " "
; ;
; Define functions. ; 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 def ascii
byte i byte i
for i = 32 to 127 i = 32
while i < 128
putc(i) putc(i)
next i = i + 1
loop
end end
def nums(range) def nums(range)
word i word i
for i = -10 to range for i = range downto -range step range/10
puti(i) puti(i)
putnl putln
next next
end end
export def main(range) export def main(range)
cls cls
nums(range) nums(*range)
tens(*range*10)
viewport(12, 12, 16, 8) viewport(12, 12, 16, 8)
ascii ascii
viewport(0, 0, 40, 24) viewport(0, 0, 40, 24)
@ -47,11 +57,5 @@ export def main(range)
puts(@hello) puts(@hello)
end end
export def indirect main(@struct:6)
word mainptr
mainptr = @main
return defptr:mainentry(struct:2)
end
indirect
done 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 include(stdlib.plh)
end
;
; 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!" byte loadstr[] = "testlib loaded!"
; ;
; Define functions. ; 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) export def puti(i)
if i < 0 if i < 0
putc('-') putc('-')
@ -20,10 +37,11 @@ export def puti(i)
putc(i % 10 + '0') putc(i % 10 + '0')
fin fin
end end
export def putnl
export def putln
putc($0D) putc($0D)
end end
puts(@loadstr) puts(@loadstr)
putnl putln
done done