Really loading and running PLASMA code now.

This commit is contained in:
Martin Haye 2014-07-03 16:56:26 -07:00
parent 0f3c02f662
commit f43c51dd74
4 changed files with 86 additions and 90 deletions

View File

@ -584,7 +584,7 @@ class PackPartitions
def readModule(name, path)
{
def num = modules.size() + 1
println "Reading module #$num from '$path'."
//println "Reading module #$num from '$path'."
def bufObj = readBinary(path)
def bufLen = bufObj.position()
@ -607,16 +607,16 @@ class PackPartitions
// Other header stuff
def defCount = ((buf[8] & 0xFF) | ((buf[9] & 0xFF) << 8))
println String.format("asmCodeStart =%04x", asmCodeStart)
println String.format("byteCodeStart=%04x", byteCodeStart)
println String.format("initStart =%04x", initStart)
println String.format("fixupStart =%04x", fixupStart)
println "defCount =$defCount"
//println String.format("asmCodeStart =%04x", asmCodeStart)
//println String.format("byteCodeStart=%04x", byteCodeStart)
//println String.format("initStart =%04x", initStart)
//println String.format("fixupStart =%04x", fixupStart)
//println "defCount =$defCount"
// Sanity checking on the offsets
assert asmCodeStart >= 0 && asmCodeStart < byteCodeStart
assert byteCodeStart >= asmCodeStart && byteCodeStart < fixupStart
assert initStart == 0 || (initStart >= byteCodeStart && initStart < fixupStart)
assert initStart == 0 || (initStart+2 >= byteCodeStart && initStart+2 < fixupStart)
assert fixupStart < buf.length
// Split up the parts now that we know their offsets
@ -626,7 +626,7 @@ class PackPartitions
// Extract offsets of the bytecode functions from the fixup table
def sp = 0
def defs = [initStart-byteCodeStart+2]
def defs = [initStart+2 - byteCodeStart]
def invDefs = [:]
(1..<defCount).each {
assert fixup[sp++] == 2 // code table fixup
@ -666,29 +666,29 @@ class PackPartitions
addr |= (fixup[sp++] & 0xFF) << 8
// Fixups can be in the asm section or in the bytecode section. Figure out which this is.
def inByteCode = (addr >= byteCodeStart)
addr += 2 // apparently offsets don't include the header length
println String.format("Fixup addr=0x%04x, inByteCode=%b", addr, inByteCode)
def inByteCode = (addr >= byteCodeStart)
//println String.format("Fixup addr=0x%04x, inByteCode=%b", addr, inByteCode)
// Figure out which buffer to modify, and the offset within it
def codeBuf = inByteCode ? byteCode : newAsmCode
addr -= inByteCode ? byteCodeStart : asmCodeStart
if (!inByteCode)
addr += stubsSize // account for the stubs we prepended to the asm code
println String.format("...adjusted addr=0x%04x", addr)
//println String.format("...adjusted addr=0x%04x", addr)
def target = (codeBuf[addr] & 0xFF) | ((codeBuf[addr+1] & 0xFF) << 8)
println String.format("...target=0x%04x", target)
//println String.format("...target=0x%04x", target)
if (invDefs.containsKey(target)) {
target = invDefs[target]
println String.format("...translated to def offset 0x%04x", target)
//println String.format("...translated to def offset 0x%04x", target)
}
else {
target -= 0x1000
target -= asmCodeStart
target += stubsSize // account for the stubs we prepended to the asm code
println String.format("...adjusted to target offset 0x%04x", target)
//println String.format("...adjusted to target offset 0x%04x", target)
}
assert target >= 5 && target < newAsmCode.length
@ -924,10 +924,9 @@ class PackPartitions
readCode("render", "src/raycast/build/render.b")
readCode("expand", "src/raycast/build/expand.b")
readCode("fontEngine", "src/font/build/fontEngine.b")
readCode("gameloop", "src/plasma/build/gameloop.b")
println "Reading modules."
readModule("testmod", "/Users/mhaye/LL/repo/PLASMA/src/foo.b")
readModule("gameloop", "src/plasma/build/gameloop.b")
// We have only one font, for now at least.
println "Reading fonts."

View File

@ -50,7 +50,7 @@
relative="true" parallel="false" failonerror="true" verbose="true"
addsourcefile="false">
<fileset dir="${src.dir}" includes="gameloop.pla"/>
<arg value="-A"/>
<arg value="-AM"/>
<redirector logError="yes">
<!-- redirect STDIN; fileset collects relative to its dir, but we need -->
<!-- relative to basedir -->
@ -61,12 +61,13 @@
</apply>
<!-- Assmeble the ACME code -->
<apply executable="acme" dir="${src.dir}"
<apply executable="acme" dir="${build.dir}"
relative="true" parallel="false" failonerror="true" verbose="true">
<fileset dir="${src.dir}" includes="gamestub.s"/>
<arg line="${ASM_SETTINGS}"/>
<fileset dir="${build.dir}" includes="*.a"/>
<mapper type="glob" from="*.a" to="*.b"/>
<arg line="--setpc 4096"/>
<arg value="-o"/>
<arg value="${build.dir}/gameloop.b"/>
<targetfile/>
<srcfile/>
</apply>

View File

@ -1,80 +1,65 @@
;
;==================================================================================================
; Handy constants.
;
const FALSE = 0
const TRUE = !FALSE
;
;==================================================================================================
; Hardware addresses.
;
const keyboard = $C000
const keystrobe = $C010
;
; call() return register structure.
;
const Accum = 0
const Xreg = 1
const Yreg = 2
const Preg = 3
;
; Processor Status (Preg) flag bits.
;
const Cflag = $01
const Zflag = $02
const Iflag = $04
const Dflag = $08
const Bflag = $10
const Vflag = $40
const Sflag = $80
;
; CALL 6502 ROUTINE
; CALL(ADDR, AREG, XREG, YREG, STATUS)
;
asm call
REGVALS = SRC
PHP
LDA ESTKL+4,X
STA TMPL
LDA ESTKH+4,X
STA TMPH
LDA ESTKL,X
PHA
LDA ESTKL+1,X
TAY
LDA ESTKL+3,X
PHA
LDA ESTKL+2,X
INX
INX
INX
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
JMPTMP JMP (TMP)
;==================================================================================================
; Strings.
byte hellostr[] = "Hello, world.\n"
;==================================================================================================
; Definitions used by assembly code
asm __defs
!SOURCE "../plvm02zp.inc"
INTERP = $03D0
LCRDEN = $C080
LCWTEN = $C081
ROMEN = $C082
LCRWEN = $C083
LCBNK2 = $00
LCBNK1 = $08
end
;
;==================================================================================================
; Print a string
asm puts
TXA
PHA
LDA ESTKL,X
STA TMPL
LDA ESTKH,X
STA TMPH
LDY #0
LDA (TMPL),Y
TAX
INY
BIT ROMEN
- LDA (TMPL),Y
ORA #$80
JSR $FDED
INY
DEX
BNE -
BIT LCRDEN+LCBNK2
PLA
TAX
brk
RTS
end
;==================================================================================================
; Main loop.
;
call($FDF0, 65, 0, 0, 0)
call($FDF0, 65, 0, 0, 0)
call($FDF0, 65, 0, 0, 0)
call($FDF0, 13+128, 0, 0, 0)
def func()
puts(@hellostr)
end
func()
func()
done

View File

@ -1610,6 +1610,8 @@ initMem: !zone
ldx #RES_TYPE_MODULE
ldy #1 ; hard coded for now: module #1 is the game loop
jsr mainLoader
stx .callGameLoop+1
sty .callGameLoop+2
; Load the map into main mem
!if DEBUG { +prStr : !text "Loading map.",0 }
lda #QUEUE_LOAD
@ -1631,6 +1633,15 @@ initMem: !zone
lda #FINISH_LOAD
ldx #1 ; keep queue open
jsr mainLoader
LDA #$00 ; INIT FRAME POINTER
STA $E0
LDA #$BF
STA $E1
LDX #$10 ; INIT EVAL STACK INDEX
.callGameLoop:
jsr $1111 ; self-modified with actual address
bit $c081
pla ; get back the font location
tay ; font engine likes *lo* byte in Y
pla