1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-05 02:30:56 +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
BNE -
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
; RDKEY()
@ -1003,16 +963,27 @@ def lookupextern(esd, index)
return 0
end
def adddef(bank, addr, deflast)
(*deflast).0 = $20
if bank == 0
(*deflast):1 = $03D6 ; JSR $03D6 (MAIN MEM INTERP)
word defentry
defentry = *deflast
*deflast = defentry + 5
if bank
(defentry):1 = $03DC ; JSR $03DC (AUX MEM INTERP)
else
(*deflast):1 = $03DC ; JSR $03DC (AUX MEM INTERP)
(defentry):1 = $03D6 ; JSR $03D6 (MAIN MEM INTERP)
fin
(*deflast):3 = addr
*deflast = *deflast + 5
(*deflast).0 = 0
return *deflast - 5
(defentry).0 = $20
(defentry):3 = addr
(defentry).5 = 0 ; NULL out next entry
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
def loadmod(mod)
word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup
@ -1021,7 +992,6 @@ def loadmod(mod)
word moddep, rld, esd, sym
byte defbank, str[16], filename[64]
byte header[128]
;
; Read the RELocatable module header (first 128 bytes)
;
@ -1095,7 +1065,7 @@ def loadmod(mod)
modend = modaddr + modsize
rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory
while !^esd ; Scan to end of ESD
while ^esd ; Scan to end of ESD
esd = esd + 4
loop
esd = esd + 1
@ -1121,7 +1091,7 @@ def loadmod(mod)
adddef(defbank, (rld):1 - defofst + defaddr, @deflast)
else
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.
fixup = *addr
else ; BYTE sized fixup.

View File

@ -54,7 +54,7 @@ DSTX = XPAGE+DSTH
;*
!MACRO INC_IP {
INY
BNE * + 4
BNE *+4
INC IPH
}
;*
@ -67,21 +67,45 @@ DSTX = XPAGE+DSTH
!WORD 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
STA TMPX
STA SRCX
STA DSTX
STA IFPX ; INIT FRAME POINTER
LDA #<INTERP
LDA #<SEGSTART
STA IFPL
LDA #>INTERP
LDA #>SEGSTART
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
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
;*
@ -110,6 +134,7 @@ XINTERP PLA
DEY
LDA (TMP),Y
STA IPL
STY MEMBANK ; MAP BANK $01
DEY
BEQ FETCHOP
;*
@ -124,35 +149,6 @@ FETCHOP LDA (IP),Y
STA *+4
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
;*
_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 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 LDA ESTKL,X
@ -260,42 +316,6 @@ IDXW LDA ESTKL,X
INX
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
;*
INCR INC ESTKL,X

View File

@ -501,46 +501,6 @@ asm lookuptbl
STA DSTH
BNE -
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
; FILE I/O
@ -595,6 +555,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 read(refnum, buff, len)
byte params[8]
@ -808,18 +778,6 @@ def allocheap(size)
word addr
addr = heap
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)
return 0
fin
@ -868,7 +826,7 @@ end
; cout('$')
; prword(*tbl)
; crout
; tbl = tbl + 2
; tbl = tbl + 2
; loop
;end
def addtbl(dci, val, last)
@ -914,16 +872,40 @@ def lookupextern(esd, index)
fin
esd = esd + 3
loop
prbyte(index)
cout('?')
crout
return 0
end
def adddef(ext, addr, deflast)
(*deflast).0 = $20
(*deflast):1 = interp
(*deflast):3 = addr
(*deflast).5 = ext
*deflast = *deflast + 6
(*deflast).0 = 0
return *deflast - 6
word defentry
defentry = *deflast
*deflast = defentry + 6
(defentry).0 = $20
(defentry):1 = interp
(defentry):3 = addr
(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
def loadmod(mod)
word refnum, rdlen, modsize, bytecode, defofst, defcnt, init, fixup
@ -932,13 +914,13 @@ def loadmod(mod)
word moddep, rld, esd, sym
byte defext, str[16], filename[64]
byte header[128]
;
; Read the RELocatable module header (first 128 bytes)
;
dcitos(mod, @filename)
refnum = open(@filename, O_READ)
if refnum > 0
newline(refnum, 0, $0D)
rdlen = read(refnum, @header, 128)
modsize = header:0
moddep = @header.1
@ -958,11 +940,12 @@ def loadmod(mod)
;
while ^moddep
if !lookupmod(moddep)
close(refnum)
refnum = 0
;close(refnum)
;refnum = 0
if loadmod(moddep) < 0
return perr
fin
cout('!')
fin
moddep = moddep + dcitos(moddep, @str)
loop
@ -976,8 +959,8 @@ def loadmod(mod)
;
; Reset read pointer.
;
refnum = open(@filename, O_READ)
rdlen = read(refnum, @header, 128)
;refnum = open(@filename, O_READ)
;rdlen = read(refnum, @header, 128)
fin
fin
;
@ -1006,7 +989,7 @@ def loadmod(mod)
modend = modaddr + modsize
rld = modend ; Re-Locatable Directory
esd = rld ; Extern+Entry Symbol Directory
while !^esd ; Scan to end of ESD
while ^esd ; Scan to end of ESD
esd = esd + 4
loop
esd = esd + 1
@ -1032,16 +1015,50 @@ def loadmod(mod)
adddef(defext, (rld):1 - defofst + defaddr, @deflast)
else
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.
fixup = *addr
else ; BYTE sized fixup.
else ; BYTE sized fixup.
fixup = ^addr
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.
fixup = fixup + lookupextern(esd, (rld).3)
else ; INTERN fixup.
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)
;
; Bytecode address - replace with call def directory.
@ -1051,7 +1068,7 @@ def loadmod(mod)
fin
if ^rld & $80 ; WORD sized fixup.
*addr = fixup
else ; BYTE sized fixup.
else ; BYTE sized fixup.
^addr = fixup
fin
fin
@ -1097,6 +1114,8 @@ def loadmod(mod)
; Call init routine if it exists.
;
if init
cout('>')
cin
return adddef(defext, init - defofst + defaddr, @deflast)()
fin
return 0
@ -1240,14 +1259,6 @@ def execmod(modfile)
fin
end
;
; Save Symbol Table start.
;
symtbl = *$A000
;
; Request bank $01.
;
seg_request($0120, $019F, $10)
;
; Init console
;
@ -1262,6 +1273,7 @@ crout
;
; Init symbol table.
;
symtbl = allocheap($400)
lastsym = symtbl
^lastsym = 0
stodci(@stdlibstr, heap)