1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-21 17:31:31 +00:00

Fix a bunch of /// bugs and save a few II bytes

This commit is contained in:
David Schmenk 2014-06-02 21:14:16 -07:00
parent c1aa4afa4c
commit 68bc161a59
3 changed files with 202 additions and 200 deletions

View File

@ -726,46 +726,6 @@ asm lookuptbl
STA DSTH STA DSTH
BNE - BNE -
end end
def lookupdef(addr, deftbl)
while (deftbl).0 == $20
if (deftbl):3 == addr
return deftbl
fin
deftbl = deftbl + 5
loop
return 0
;asm lookupdef
; LDA ESTKL,X
; STA DSTL
; LDA ESTKH,X
; STA DSTH
; INX
;- LDY #$00
; LDA #$20
; AND (DST),Y
; BEQ ++
; LDY #$03
; LDA (DST),Y
; CMP ESTKL,X
; BNE +++
; INY
; LDA (DST),Y
; CMP ESTKH,X
; BNE ++
;+ LDA DSTL
; LDY DSTH
;++ STA ESTKL,X
; STY ESTKH,X
; RTS
;+++ LDA #$05
; CLC
; ADC DSTL
; STA DSTL
; LDA #$00
; ADC DSTH
; STA DSTH
; BNE -
end
; ;
; CHAR IN ; CHAR IN
; RDKEY() ; RDKEY()
@ -1003,16 +963,27 @@ def lookupextern(esd, index)
return 0 return 0
end end
def adddef(bank, addr, deflast) def adddef(bank, addr, deflast)
(*deflast).0 = $20 word defentry
if bank == 0 defentry = *deflast
(*deflast):1 = $03D6 ; JSR $03D6 (MAIN MEM INTERP) *deflast = defentry + 5
if bank
(defentry):1 = $03DC ; JSR $03DC (AUX MEM INTERP)
else else
(*deflast):1 = $03DC ; JSR $03DC (AUX MEM INTERP) (defentry):1 = $03D6 ; JSR $03D6 (MAIN MEM INTERP)
fin fin
(*deflast):3 = addr (defentry).0 = $20
*deflast = *deflast + 5 (defentry):3 = addr
(*deflast).0 = 0 (defentry).5 = 0 ; NULL out next entry
return *deflast - 5 return defentry
end
def lookupdef(addr, deftbl)
while (deftbl).0 == $20
if (deftbl):3 == addr
return deftbl
fin
deftbl = deftbl + 5
loop
return 0
end end
def loadmod(mod) def loadmod(mod)
word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup
@ -1021,7 +992,6 @@ def loadmod(mod)
word moddep, rld, esd, sym word moddep, rld, esd, sym
byte defbank, str[16], filename[64] byte defbank, str[16], filename[64]
byte header[128] byte header[128]
; ;
; Read the RELocatable module header (first 128 bytes) ; Read the RELocatable module header (first 128 bytes)
; ;
@ -1095,7 +1065,7 @@ def loadmod(mod)
modend = modaddr + modsize modend = modaddr + modsize
rld = modend ; Re-Locatable Directory rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory esd = rld ; Extern+Entry Symbol Directory
while !^esd ; Scan to end of ESD while ^esd ; Scan to end of ESD
esd = esd + 4 esd = esd + 4
loop loop
esd = esd + 1 esd = esd + 1
@ -1121,7 +1091,7 @@ def loadmod(mod)
adddef(defbank, (rld):1 - defofst + defaddr, @deflast) adddef(defbank, (rld):1 - defofst + defaddr, @deflast)
else else
addr = (rld):1 + modfix addr = (rld):1 + modfix
if addr >= modaddr ; Skip fixups to header if uword_isge(addr, modaddr) ; Skip fixups to header
if ^rld & $80 ; WORD sized fixup. if ^rld & $80 ; WORD sized fixup.
fixup = *addr fixup = *addr
else ; BYTE sized fixup. else ; BYTE sized fixup.

View File

@ -54,7 +54,7 @@ DSTX = XPAGE+DSTH
;* ;*
!MACRO INC_IP { !MACRO INC_IP {
INY INY
BNE * + 4 BNE *+4
INC IPH INC IPH
} }
;* ;*
@ -67,21 +67,45 @@ DSTX = XPAGE+DSTH
!WORD SEGSTART !WORD SEGSTART
!WORD SEGEND-SEGSTART !WORD SEGEND-SEGSTART
+SOS $40, SEGREQ ; ALLOCATE SEG 1 AND MAP IT
BNE FAIL
LDA #$01
STA MEMBANK
LDA #$00 ; CLEAR ALL EXTENDED POINTERS LDA #$00 ; CLEAR ALL EXTENDED POINTERS
STA TMPX STA TMPX
STA SRCX STA SRCX
STA DSTX STA DSTX
STA IFPX ; INIT FRAME POINTER STA IFPX ; INIT FRAME POINTER
LDA #<INTERP LDA #<SEGSTART
STA IFPL STA IFPL
LDA #>INTERP LDA #>SEGSTART
STA IFPH STA IFPH
LDA #<SEGEND ; SAVE END OF SEGMENT FOR SYMBOL TABLE
STA SEGSTART
LDA #>SEGEND
STA SEGSTART+1
LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX
JMP SOSCMD JMP SOSCMD
SEGREQ !BYTE 4
!WORD $2001
!WORD $9F01
!BYTE $11
!BYTE $00
PRHEX PHA
LSR
LSR
LSR
LSR
CLC
ADC #'0'
CMP #':'
BCC +
ADC #6
+ STA $480
PLA
AND #$0F
ADC #'0'
CMP #':'
BCC +
ADC #6
+ STA $880
FAIL RTS
;* ;*
;* SYSTEM INTERPRETER ENTRYPOINT ;* SYSTEM INTERPRETER ENTRYPOINT
;* ;*
@ -110,6 +134,7 @@ XINTERP PLA
DEY DEY
LDA (TMP),Y LDA (TMP),Y
STA IPL STA IPL
STY MEMBANK ; MAP BANK $01
DEY DEY
BEQ FETCHOP BEQ FETCHOP
;* ;*
@ -124,35 +149,6 @@ FETCHOP LDA (IP),Y
STA *+4 STA *+4
JMP (OPTBL) JMP (OPTBL)
;* ;*
;* INTERNAL MULTIPLY ALGORITHM
;*
_MUL STY IPY
LDY #$00
STY TMPL ; PRODL
STY TMPH ; PRODH
LDY #$10
MUL1 LSR ESTKH,X ; MULTPLRH
ROR ESTKL,X ; MULTPLRL
BCC MUL2
LDA ESTKL+1,X ; MULTPLNDL
CLC
ADC TMPL ; PRODL
STA TMPL
LDA ESTKH+1,X ; MULTPLNDH
ADC TMPH ; PRODH
STA TMPH
MUL2 ASL ESTKL+1,X ; MULTPLNDL
ROL ESTKH+1,X ; MULTPLNDH
DEY
BNE MUL1
INX
LDA TMPL ; PRODL
STA ESTKL,X
LDA TMPH ; PRODH
STA ESTKH,X
LDY IPY
RTS
;*
;* INTERNAL DIVIDE ALGORITHM ;* INTERNAL DIVIDE ALGORITHM
;* ;*
_NEG LDA #$00 _NEG LDA #$00
@ -221,6 +217,66 @@ OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E !WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E !WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
;* ;*
;* MUL TOS-1 BY TOS
;*
MUL STY IPY
LDY #$00
STY TMPL ; PRODL
STY TMPH ; PRODH
LDY #$10
MUL1 LSR ESTKH,X ; MULTPLRH
ROR ESTKL,X ; MULTPLRL
BCC MUL2
LDA ESTKL+1,X ; MULTPLNDL
CLC
ADC TMPL ; PRODL
STA TMPL
LDA ESTKH+1,X ; MULTPLNDH
ADC TMPH ; PRODH
STA TMPH
MUL2 ASL ESTKL+1,X ; MULTPLNDL
ROL ESTKH+1,X ; MULTPLNDH
DEY
BNE MUL1
INX
LDA TMPL ; PRODL
STA ESTKL,X
LDA TMPH ; PRODH
STA ESTKH,X
LDY IPY
JMP NEXTOP
;*
;* NEGATE TOS
;*
NEG LDA #$00
SEC
SBC ESTKL,X
STA ESTKL,X
LDA #$00
SBC ESTKH,X
STA ESTKH,X
JMP NEXTOP
;*
;* DIV TOS-1 BY TOS
;*
DIV JSR _DIV
INX
LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1
BCS NEG
JMP NEXTOP
;*
;* MOD TOS-1 BY TOS
;*
MOD JSR _DIV
INX
LDA TMPL ; REMNDRL
STA ESTKL,X
LDA TMPH ; REMNDRH
STA ESTKH,X
LDA DVSIGN ; REMAINDER IS SIGN OF DIVIDEND
BMI NEG
JMP NEXTOP
;*
;* ADD TOS TO TOS-1 ;* ADD TOS TO TOS-1
;* ;*
ADD LDA ESTKL,X ADD LDA ESTKL,X
@ -260,42 +316,6 @@ IDXW LDA ESTKL,X
INX INX
JMP NEXTOP JMP NEXTOP
;* ;*
;* MUL TOS-1 BY TOS
;*
MUL JSR _MUL
JMP NEXTOP
;*
;* NEGATE TOS
;*
NEG LDA #$00
SEC
SBC ESTKL,X
STA ESTKL,X
LDA #$00
SBC ESTKH,X
STA ESTKH,X
JMP NEXTOP
;*
;* DIV TOS-1 BY TOS
;*
DIV JSR _DIV
INX
LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1
BCS NEG
JMP NEXTOP
;*
;* MOD TOS-1 BY TOS
;*
MOD JSR _DIV
INX
LDA TMPL ; REMNDRL
STA ESTKL,X
LDA TMPH ; REMNDRH
STA ESTKH,X
LDA DVSIGN ; REMAINDER IS SIGN OF DIVIDEND
BMI NEG
JMP NEXTOP
;*
;* INCREMENT TOS ;* INCREMENT TOS
;* ;*
INCR INC ESTKL,X INCR INC ESTKL,X

View File

@ -501,46 +501,6 @@ asm lookuptbl
STA DSTH STA DSTH
BNE - BNE -
end end
def lookupdef(addr, deftbl)
while (deftbl).0 == $20
if (deftbl):3 == addr
return deftbl
fin
deftbl = deftbl + 6
loop
return 0
;asm lookupdef
; LDA ESTKL,X
; STA DSTL
; LDA ESTKH,X
; STA DSTH
; INX
;- LDY #$00
; LDA #$20
; AND (DST),Y
; BEQ ++
; LDY #$03
; LDA (DST),Y
; CMP ESTKL,X
; BNE +++
; INY
; LDA (DST),Y
; CMP ESTKH,X
; BNE ++
;+ LDA DSTL
; LDY DSTH
;++ STA ESTKL,X
; STY ESTKH,X
; RTS
;+++ LDA #$05
; CLC
; ADC DSTL
; STA DSTL
; LDA #$00
; ADC DSTH
; STA DSTH
; BNE -
end
; ;
; SOS routines ; SOS routines
; FILE I/O ; FILE I/O
@ -595,6 +555,16 @@ def close(refnum)
perr = syscall($CC, @params) perr = syscall($CC, @params)
return perr return perr
end 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) def read(refnum, buff, len)
byte params[8] byte params[8]
@ -808,18 +778,6 @@ def allocheap(size)
word addr word addr
addr = heap addr = heap
heap = heap + size heap = heap + size
if systemflags & reshgr1
if uword_isle(addr, $4000) and uword_isgt(heap, $2000)
addr = $4000
heap = addr + size
fin
fin
if systemflags & reshgr2
if uword_isle(addr, $6000) and uword_isgt(heap, $4000)
addr = $6000
heap = addr + size
fin
fin
if uword_isge(heap, @addr) if uword_isge(heap, @addr)
return 0 return 0
fin fin
@ -868,7 +826,7 @@ end
; cout('$') ; cout('$')
; prword(*tbl) ; prword(*tbl)
; crout ; crout
; tbl = tbl + 2 ; tbl = tbl + 2
; loop ; loop
;end ;end
def addtbl(dci, val, last) def addtbl(dci, val, last)
@ -914,16 +872,40 @@ def lookupextern(esd, index)
fin fin
esd = esd + 3 esd = esd + 3
loop loop
prbyte(index)
cout('?')
crout
return 0 return 0
end end
def adddef(ext, addr, deflast) def adddef(ext, addr, deflast)
(*deflast).0 = $20 word defentry
(*deflast):1 = interp defentry = *deflast
(*deflast):3 = addr *deflast = defentry + 6
(*deflast).5 = ext (defentry).0 = $20
*deflast = *deflast + 6 (defentry):1 = interp
(*deflast).0 = 0 (defentry):3 = addr
return *deflast - 6 (defentry):5 = ext ; ext is byte, so this nulls out next entry
;prword(defentry)
;cout('@')
;prword(addr)
;crout
return defentry
end
def lookupdef(addr, deftbl)
while (deftbl).0 == $20
if (deftbl):3 == addr
;prword(addr)
;cout('>')
;prword(deftbl)
;crout
return deftbl
fin
deftbl = deftbl + 6
loop
prword(addr)
cout('?')
crout
return 0
end end
def loadmod(mod) def loadmod(mod)
word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup
@ -932,13 +914,13 @@ def loadmod(mod)
word moddep, rld, esd, sym word moddep, rld, esd, sym
byte defext, str[16], filename[64] byte defext, str[16], filename[64]
byte header[128] byte header[128]
; ;
; Read the RELocatable module header (first 128 bytes) ; Read the RELocatable module header (first 128 bytes)
; ;
dcitos(mod, @filename) dcitos(mod, @filename)
refnum = open(@filename, O_READ) refnum = open(@filename, O_READ)
if refnum > 0 if refnum > 0
newline(refnum, 0, $0D)
rdlen = read(refnum, @header, 128) rdlen = read(refnum, @header, 128)
modsize = header:0 modsize = header:0
moddep = @header.1 moddep = @header.1
@ -958,11 +940,12 @@ def loadmod(mod)
; ;
while ^moddep while ^moddep
if !lookupmod(moddep) if !lookupmod(moddep)
close(refnum) ;close(refnum)
refnum = 0 ;refnum = 0
if loadmod(moddep) < 0 if loadmod(moddep) < 0
return perr return perr
fin fin
cout('!')
fin fin
moddep = moddep + dcitos(moddep, @str) moddep = moddep + dcitos(moddep, @str)
loop loop
@ -976,8 +959,8 @@ def loadmod(mod)
; ;
; Reset read pointer. ; Reset read pointer.
; ;
refnum = open(@filename, O_READ) ;refnum = open(@filename, O_READ)
rdlen = read(refnum, @header, 128) ;rdlen = read(refnum, @header, 128)
fin fin
fin fin
; ;
@ -1006,7 +989,7 @@ def loadmod(mod)
modend = modaddr + modsize modend = modaddr + modsize
rld = modend ; Re-Locatable Directory rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory esd = rld ; Extern+Entry Symbol Directory
while !^esd ; Scan to end of ESD while ^esd ; Scan to end of ESD
esd = esd + 4 esd = esd + 4
loop loop
esd = esd + 1 esd = esd + 1
@ -1032,16 +1015,50 @@ def loadmod(mod)
adddef(defext, (rld):1 - defofst + defaddr, @deflast) adddef(defext, (rld):1 - defofst + defaddr, @deflast)
else else
addr = (rld):1 + modfix addr = (rld):1 + modfix
if addr >= modaddr ; Skip fixups to header if uword_isge(addr, modaddr) ; Skip fixups to header
;if uword_isge(addr, modend)
; cout('<')
; prword((rld):1)
; cout('>')
; prword(rld)
; crout
;fin
if ^rld & $80 ; WORD sized fixup. if ^rld & $80 ; WORD sized fixup.
fixup = *addr fixup = *addr
else ; BYTE sized fixup. else ; BYTE sized fixup.
fixup = ^addr fixup = ^addr
fin fin
if uword_isge(fixup, modend)
cout('<')
cout('<')
prword(*addr);fixup)
cout('@')
prword(addr)
cout('>')
cout('>')
prword(^rld)
crout
fin
if ^rld & $10 ; EXTERN reference. if ^rld & $10 ; EXTERN reference.
fixup = fixup + lookupextern(esd, (rld).3) fixup = fixup + lookupextern(esd, (rld).3)
else ; INTERN fixup. else ; INTERN fixup.
fixup = fixup + modfix - MODADDR fixup = fixup + modfix - MODADDR
if uword_isge(fixup, modend)
prword(@(modaddr).$62)
cout('=')
prword((modaddr).$62)
crout
cout('<')
cout('<')
cout('<')
prword(fixup)
cout('>')
cout('>')
cout('>')
prword(rld)
cin
crout
fin
if uword_isge(fixup, bytecode) if uword_isge(fixup, bytecode)
; ;
; Bytecode address - replace with call def directory. ; Bytecode address - replace with call def directory.
@ -1051,7 +1068,7 @@ def loadmod(mod)
fin fin
if ^rld & $80 ; WORD sized fixup. if ^rld & $80 ; WORD sized fixup.
*addr = fixup *addr = fixup
else ; BYTE sized fixup. else ; BYTE sized fixup.
^addr = fixup ^addr = fixup
fin fin
fin fin
@ -1097,6 +1114,8 @@ def loadmod(mod)
; Call init routine if it exists. ; Call init routine if it exists.
; ;
if init if init
cout('>')
cin
return adddef(defext, init - defofst + defaddr, @deflast)() return adddef(defext, init - defofst + defaddr, @deflast)()
fin fin
return 0 return 0
@ -1240,14 +1259,6 @@ def execmod(modfile)
fin fin
end end
;
; Save Symbol Table start.
;
symtbl = *$A000
;
; Request bank $01.
;
seg_request($0120, $019F, $10)
; ;
; Init console ; Init console
; ;
@ -1262,6 +1273,7 @@ crout
; ;
; Init symbol table. ; Init symbol table.
; ;
symtbl = allocheap($400)
lastsym = symtbl lastsym = symtbl
^lastsym = 0 ^lastsym = 0
stodci(@stdlibstr, heap) stodci(@stdlibstr, heap)