From 8ff169d1e64679699b6edac6afd823362582baeb Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Wed, 4 Jan 2017 09:17:13 -0800 Subject: [PATCH] Now loading and successfully relocating ProRWTS and PLASMA. --- Platform/Apple/tools/PLASMA/src/PLVM02#4000 | Bin 0 -> 2434 bytes Platform/Apple/tools/PLASMA/src/plvm02.s | 3 - Platform/Apple/tools/PackPartitions/build.xml | 3 +- .../src/org/badvision/A2PackPartitions.groovy | 86 +++++++--- .../src/org/badvision/Lx47Algorithm.java | 18 +-- Platform/Apple/tools/ProRWTS/Makefile | 2 +- Platform/Apple/tools/ProRWTS/PRORWTS2#4000 | Bin 0 -> 1608 bytes Platform/Apple/tools/ProRWTS/PRORWTS2.S | 6 +- Platform/Apple/virtual/src/core/decomp.s | 70 ++++++-- Platform/Apple/virtual/src/core/loader.s | 151 ++++++++++++++++++ Platform/Apple/virtual/src/core/mem.s | 2 +- 11 files changed, 282 insertions(+), 59 deletions(-) create mode 100644 Platform/Apple/tools/PLASMA/src/PLVM02#4000 create mode 100644 Platform/Apple/tools/ProRWTS/PRORWTS2#4000 create mode 100644 Platform/Apple/virtual/src/core/loader.s diff --git a/Platform/Apple/tools/PLASMA/src/PLVM02#4000 b/Platform/Apple/tools/PLASMA/src/PLVM02#4000 new file mode 100644 index 0000000000000000000000000000000000000000..b9274cb2868f69b80399a3028e992f4349019a42 GIT binary patch literal 2434 zcmc&$UuauZ7{ATzn$``Yn3@NL`rtt6ATRCuA{K;^Vjlz<_#m#JkxV;5r0Qd!J&*^d zE%f5{Pzl2;xgfZ>9ibxYxqFytKzr`Jx%b9_kfyyiSy3D5z1!Lc<9AMSlQg#5d@_W? zIltfU`_A`$=ieQkCBw5sejgo`$5EdwprA}qe_F^MT?ppruG8oAOZ}_2=yv+C<;n3& z+d?XIH~qx&8{?Pg5$J+J8I|M}w1L*As<~Qlxn4)R(*kuo>JBH#WKw1AW!|o;72Q>P zwHLHsw4%19?P%AvzqRA~Gx|yWMg6QksC}wm)tB@@;a1@^ zwVtw0TCZ6jS}$8~SzlPQ)|b|v^=R?E;*Z5Yi@m?rgz3U;p;ibQZyHJCZS!OEo)I=r znXj0io8OuRbI08JpMU=?|B;8v|5Wia$bYNY1Nko%ekeR^yktnm&j;q8h@9&|ZsMGP zJZU{9m0}XCo&;-`7GT-;CU=AcvJ=Qj2eLNuQqZ`m{lbTpsc7$$3r7fe#3VAKhzh1N zs;E{cYXVlrJOY5~(I!9!MroI5ZZjRi%0wO6ScTS+1yMQeyklQECaReD4hP97P0`xmxm_DCGl~C`{S0Gs<{D-gRu5C;z%~%F zusDm9?~!ge2V6IEAwb$TY!|a-^u4vnre%X~W|NP^ODxy;I?uL=&TVG$S&lcS>cVqC zHe%=?U>@HFrr@#vo8^{WG_spIKlgkqd7n5y(XPWmqGr$pE(iWPQ_;UJQ^ zO?YnLpB5JEYGc>>WShcd!OmgYQnd31rqr<7k1_RuL|5IIJ=b>P9R*_n^3V?98QYHT z0ip-cJVUO*#8Bwdm>Mb_l^lTG(%|gPuJ#EgN`xIu300aJT-MZb=UJHf;-Vt;8nk zW9-s_FCKpBpmhKTGPUEFrWQ(=RH3Ci=>Sa6TqWQ#KxK9rpp677CEyc@!4iN{8~O*i CpeS7c literal 0 HcmV?d00001 diff --git a/Platform/Apple/tools/PLASMA/src/plvm02.s b/Platform/Apple/tools/PLASMA/src/plvm02.s index c454193c..ccdb4e7e 100644 --- a/Platform/Apple/tools/PLASMA/src/plvm02.s +++ b/Platform/Apple/tools/PLASMA/src/plvm02.s @@ -113,9 +113,6 @@ INTERP = $03D0 LDA #$BF STA PPH STA IFPH - LDX #$FE ; INIT STACK POINTER (YES, $FE. SEE GETS) - TXS - LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX RTS PAGE0 = * diff --git a/Platform/Apple/tools/PackPartitions/build.xml b/Platform/Apple/tools/PackPartitions/build.xml index 85887a4a..f9461593 100644 --- a/Platform/Apple/tools/PackPartitions/build.xml +++ b/Platform/Apple/tools/PackPartitions/build.xml @@ -28,7 +28,8 @@ - + + diff --git a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy index aa95555d..ece59c8b 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy @@ -1205,6 +1205,14 @@ class A2PackPartitions return wrapByteArray(arr) } + def unwrapByteBuffer(buf) { + def len = buf.position() + def out = new byte[len] + buf.position(0) + buf.get(out) + return out + } + def readFont(name, path) { def num = fonts.size() + 1 @@ -1231,7 +1239,7 @@ class A2PackPartitions //def uncomp = new byte[inLen] //lx47.decompress(outputData, 0, uncomp, 0, inLen) //assert uncomp == inputData - + // Verify the stream comes out right with overlapped decompression def underlap = 2 def buf = new byte[inLen+underlap] @@ -1240,7 +1248,7 @@ class A2PackPartitions lx47.decompress(buf, initialOffset, buf, 0, inLen) def uncomp = Arrays.copyOfRange(buf, 0, inLen) assert uncomp == inputData - + uncompTotal += inLen lx47Savings += savings lz4Total += lz4Len @@ -1252,7 +1260,7 @@ class A2PackPartitions println String.format("lz47 usize=%d savings=%d SKIP", inLen, savings) } } - + // Transform the LZ4 format to something we call "LZ4M", where the small offsets are stored // as one byte instead of two. In our data, that's about 1/3 of the offsets. // @@ -1354,9 +1362,7 @@ class A2PackPartitions { // First, grab the uncompressed data into a byte array def uncompressedLen = buf.position() - def uncompressedData = new byte[uncompressedLen] - buf.position(0) - buf.get(uncompressedData) + def uncompressedData = unwrapByteBuffer(buf) // Now compress it with LZ4 assert uncompressedLen < 327678 : "data block too big" @@ -1369,7 +1375,7 @@ class A2PackPartitions // Then recompress to LZ4M (pretty much always smaller) def recompressedLen = recompress(compressedData, compressedLen, uncompressedData, uncompressedLen) - testLx47(uncompressedData, uncompressedLen, recompressedLen) + //testLx47(uncompressedData, uncompressedLen, recompressedLen) // If we saved at least 20 bytes, take the compressed version. if ((uncompressedLen - recompressedLen) >= 20) { @@ -1448,12 +1454,9 @@ class A2PackPartitions hdrBuf.put((byte)(hdrEnd & 0xFF)) hdrBuf.put((byte)(hdrEnd >> 8)) hdrBuf.position(hdrEnd) - def hdrData = new byte[hdrEnd] - hdrBuf.position(0) - hdrBuf.get(hdrData) // Finally, write out each chunk's data, including the header. - stream.write(hdrData) + stream.write(unwrapByteBuffer(hdrBuf)) chunks.each { stream.write(it.buf.data, 0, it.buf.len) } @@ -1467,6 +1470,7 @@ class A2PackPartitions def prevUserDir = System.getProperty("user.dir") def result def errBuf = new ByteArrayOutputStream() + println "Nested: prog=$programName inDir=$inDir inDir=$inDir inFile=$inFile outFile=$outFile" try { System.setProperty("user.dir", new File(inDir).getAbsolutePath()) @@ -1620,18 +1624,50 @@ class A2PackPartitions def assembleCore(inDir) { if (binaryStubsOnly) - return addToCache("sysCode", sysCode, "mem", 1, ByteBuffer.allocate(1)) + return addToCache("sysCode", sysCode, "core", 1, ByteBuffer.allocate(1)) + // Read in all the parts of the LegendOS core system and combine them together + // with block headers. inDir = "build/" + inDir - def hash = getLastDep(new File(inDir, "mem.s")) - if (grabFromCache("sysCode", sysCode, "mem", hash)) - return - - println "Assembling mem.s" - new File(inDir + "build").mkdir() - String[] args = ["acme", "-o", "build/cmd.sys#2000", "mem.s"] - runNestedvm(acme.Acme.class, "ACME assembler", args, inDir, null, null) - addToCache("sysCode", sysCode, "mem", hash, readBinary(inDir + "build/cmd.sys#2000")) + new File(inDir + "build").mkdirs() + println "Created dir ${new File(inDir + "build")}" + def outBuf = ByteBuffer.allocate(50000) + def compressor = new Lx47Algorithm() + ["loader", "decomp", "PRORWTS", "PLVM02", "mem"].each { name -> + def code + if (name == "PRORWTS") + code = readBinary(jitCopy(new File("build/tools/ProRWTS/PRORWTS2#4000")).toString()) + else if (name == "PLVM02") + code = readBinary(jitCopy(new File("build/tools/PLASMA/src/PLVM02#4000")).toString()) + else { + def hash = getLastDep(new File(inDir, "${name}.s")) + if (!grabFromCache("sysCode", sysCode, name, hash)) { + println "Assembling ${name}.s" + String[] args = ["acme", "-o", "build/$name", "${name}.s"] + runNestedvm(acme.Acme.class, "ACME assembler", args, inDir, null, null) + addToCache("sysCode", sysCode, name, hash, readBinary(inDir + "build/$name")) + } + code = sysCode[name].buf + } + println "Processing $name." + def compressed = (name ==~ /loader|decomp/) ? + code : wrapByteArray(compressor.compress(unwrapByteBuffer(code))) + if (name != "loader") { + // Uncompressed size first + outBuf.put((byte) (code.position() & 0xFF)) + outBuf.put((byte) (code.position() >> 8)) + // Then compressed size + outBuf.put((byte) (compressed.position() & 0xFF)) + outBuf.put((byte) (compressed.position() >> 8)) + } + compressed.flip() + outBuf.put(compressed) + } + + // Write out the result + new File("build/src/core/build/LEGENDOS.SYSTEM.sys#2000").withOutputStream { stream -> + stream.write(unwrapByteBuffer(outBuf)) + } } def compileModule(moduleName, codeDir, verbose = true) @@ -2699,11 +2735,9 @@ end def createImage() { - // Copy the PLASMA VM file to the output directory - copyIfNewer(jitCopy(new File("build/tools/PLASMA/src/PLVM02.SYSTEM.sys")), new File("build/root/PLVM02.SYSTEM.sys")) - - // Copy the memory manager to the output directory - copyIfNewer(new File("build/src/core/build/cmd.sys#2000"), new File("build/root/cmd.sys#2000")) + // Copy the combined core executable to the output directory + copyIfNewer(new File("build/src/core/build/LEGENDOS.SYSTEM.sys#2000"), + new File("build/root/LEGENDOS.SYSTEM.sys#2000")) // If we preserved a previous save game, copy it to the new image. def prevSave = new File("build/prevGame/game.1.save.\$f1") diff --git a/Platform/Apple/tools/PackPartitions/src/org/badvision/Lx47Algorithm.java b/Platform/Apple/tools/PackPartitions/src/org/badvision/Lx47Algorithm.java index 7bf6d13e..c9f8e418 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/badvision/Lx47Algorithm.java +++ b/Platform/Apple/tools/PackPartitions/src/org/badvision/Lx47Algorithm.java @@ -19,7 +19,7 @@ public class Lx47Algorithm void addDebug(String format, Object... arguments) { String str = String.format(format, arguments); - //System.out.println("Gen: " + str); + System.out.println("Gen: " + str); debugs.add(str); } @@ -275,10 +275,10 @@ public class Lx47Algorithm int pos = input_index - optimal[input_index].lits + 1; while (optimal[input_index].lits > 0) { int n = Math.min(255, optimal[input_index].lits); - addDebug("lits l=%d", n); + addDebug("lits l=$%02x", n); w.writeLiteralLen(n); for (i = 0; i < n; i++, pos++) { - addDebug("lit $%x", input_data[pos]); + addDebug("lit $%02x", input_data[pos]); w.writeByte(input_data[pos]); } optimal[input_index].lits -= n; @@ -289,12 +289,12 @@ public class Lx47Algorithm // Sequence. If two in a row, insert a zero-length lit str if (!prevIsLit) { - addDebug("lits l=0"); + addDebug("lits l=$00"); w.writeBit(0); } // Now write sequence info - addDebug("seq l=%d o=%d", optimal[input_index].len, optimal[input_index].offset); + addDebug("seq l=$%02x o=$%04x", optimal[input_index].len, optimal[input_index].offset); w.writeCodePair(optimal[input_index].len, optimal[input_index].offset); prevIsLit = false; } @@ -305,7 +305,7 @@ public class Lx47Algorithm // EOF marker if (!prevIsLit) { - addDebug("lits l=0"); + addDebug("lits l=$00"); w.writeBit(0); } addDebug("EOF"); @@ -393,10 +393,10 @@ public class Lx47Algorithm // Check for literal string while (true) { len = r.readLiteralLen(); - chkDebug("lits l=%d", len); + chkDebug("lits l=$%02x", len); for (int i=0; i> 16; - chkDebug("seq l=%d o=%d", len, off); + chkDebug("seq l=$%02x o=$%04x", len, off); while (len-- > 0) { output_data[outPos] = output_data[outPos - off]; ++outPos; diff --git a/Platform/Apple/tools/ProRWTS/Makefile b/Platform/Apple/tools/ProRWTS/Makefile index 0c877d01..87d5b31d 100644 --- a/Platform/Apple/tools/ProRWTS/Makefile +++ b/Platform/Apple/tools/ProRWTS/Makefile @@ -1,5 +1,5 @@ .SUFFIXES = -PRORWTS = PRORWTS2\#800 +PRORWTS = PRORWTS2\#4000 all: $(PRORWTS) diff --git a/Platform/Apple/tools/ProRWTS/PRORWTS2#4000 b/Platform/Apple/tools/ProRWTS/PRORWTS2#4000 new file mode 100644 index 0000000000000000000000000000000000000000..bbf0a7083f3c4f7a4b85aadb303137908407ffc2 GIT binary patch literal 1608 zcmb`HZ)h839LF!0w4~GN=5&O)xkI;^l%jp%i>mFG^e&e)tJ>w#bVD3LC}soM^o0n5 z^hNH-LhrnxNcy639KEuHB_t?F(RNq1wn@?L2{MLzF+uE^cCbBnP5;a^J)cAi!?yUz12ihq~lKce_=D1XZkkCQENe%Ql* z+?_59ACLk|mWB7pa#=V*3TH{-94TBSg%T;;A!Q3UQ07h&*p)e-CyU|pT(JE!WDNy8 zDT<|2H0zVFJneUZA^=b3Y1h-~LY^)S!2MB&LZ5k=rA1ux6^|*tMZb76(@kedI@ey9 z2e;)I!dZZIXbc95DoV>(LJW?^W0MbP)&}ymlG{RBkFRYyz94!1;ec+H;rSxU)`7S z6h<`b*~67Gx1O@0&MWoKV|}P)2oDz9bGwU#z0rTUts#KRIlB&;GjUbxi##laiKJK& zuVwK{##$lTbdX1C{LHO$Rc>P}q~hQSyAm8{h;xu-oT4p-u|a7!l7z=9NLe0Raf((H zHXc^`S&H+Hg`j=>1kncLz^zo%O&joah4Cvvzv5+m3OXW=O07BuH(0O25N@dSBf0yP z@F2s6JE99n`sf0~GEG5{h27&Jg(>2>=lm(0WfZSpq5P>;){9D@WXssPww{1Hx$Y^f zGJ&nwiPvpnSo|71kgTkm!1PwO6TJ_2#sQ3=kK#@6pgyI+%B9S(x~m#N zr%g47L`#7V{hCl?eU~q&m+Ow7hE>p_^?|i$wD-;Xk|owHRbpP`4J6J60<4*ES?xQV zt!x)@3y!=0Fkut%DNLEfXDv?w~E8SOcz?e1>qX1swb1JCw@;gM#4q`7+cmw zssNU^3@{_7%CMTJPKS-w`lx&FY2Jv8=%E5f!$y6KV5^g1!*y&lY?Q&DN$@+`W2Or= zeJH-GCYL68by851qhF{8hE>TnvoyU#^cZpQmt>t;n&>x(w~(=xl)|S>BR#1u%cW5i zF|1CQX#K9^6t?>CYOZAhTP=Xaj@+VTn_ikY`ENYh0>z-xrcwSz3bb1!lfG%*P2cIg z_zzs4!0cgt3oiX3xb|-Y*O5A0)@{f##JMc4XRJCg1jX+VS>RE!K752My+M{yCu<1) zhpg7ek+r-<*3rk3MQ%sd@-}4Y6PRHq;t+wac{Oi?uB#2SCjVcw>X$jz*BqiljSH*C Xyd3(Kr%Ei@TPpoBeO)SEznc9UngTfm literal 0 HcmV?d00001 diff --git a/Platform/Apple/tools/ProRWTS/PRORWTS2.S b/Platform/Apple/tools/ProRWTS/PRORWTS2.S index 7cd0b36f..e21beb32 100755 --- a/Platform/Apple/tools/ProRWTS/PRORWTS2.S +++ b/Platform/Apple/tools/ProRWTS/PRORWTS2.S @@ -3,7 +3,7 @@ ;license:BSD-3-Clause !cpu 6502 -*=$800 +*=$4000 ;place no code before init label below. @@ -28,7 +28,7 @@ ;i.e. running from main if accessing main, running from aux if accessing aux bounds_check = 0 ;set to 1 to prevent access beyond the end of the file ;but limits file size to 64k-2 bytes. - load_high = 1 ;set to 1 to load to top of RAM (either main or banked, enables a himem check) + load_high = 0 ;set to 1 to load to top of RAM (either main or banked, enables a himem check) load_banked = 1 ;set to 1 to load into banked RAM instead of main RAM lc_bank = 1 ;load into specified bank (1 or 2) if load_banked=1 @@ -40,7 +40,7 @@ reloc = $fb00 ;page-aligned, as high as possible, the ideal value will be shown on mismatch } ;PASS2 } else { ;load_high - reloc = $d000 ;page-aligned, but otherwise wherever you want + reloc = $ef00 ;page-aligned, but otherwise wherever you want } ;load_high } else { ;load_banked !if load_high = 1 { diff --git a/Platform/Apple/virtual/src/core/decomp.s b/Platform/Apple/virtual/src/core/decomp.s index 3ea93d7c..e73d36c3 100644 --- a/Platform/Apple/virtual/src/core/decomp.s +++ b/Platform/Apple/virtual/src/core/decomp.s @@ -9,18 +9,10 @@ ;**************************************************************************************** ;@com.wudsn.ide.asm.hardware=APPLE2 -; Memory manager +; Lx47 Decompressor ; ------------------ -; -; See detailed description in mem.i -* = $2000 ; PLASMA loader loads us initially at $2000 - -; Use hi-bit ASCII for Apple II -!convtab "../include/hiBitAscii.ct" - -; Global definitions -!source "../include/global.i" +* = $DF00 tmp = $2 ; len 2 pTmp = $4 ; len 2 @@ -30,6 +22,13 @@ pSrc = $C ; len 2 pDst = $E ; len 2 pEnd = $10 ; len 2 +cout = $FDED +prbyte = $FDDA +crout = $FD8E +rdkey = $FD0C + +DEBUG = 0 + ; Decompress from pSrc to pDst, stop at pEnd. The source and dest can overlap, as long as the ; source block ends (at least) 2 bytes beyond the end of the dest block, e.g. ; DDDDDDDDDDDDDDD @@ -43,8 +42,9 @@ decomp !zone { .lits asl bits ; get bit that tells us whether there's a literal string bne + ; ran out of bits in bit buffer? .lits2 jsr .getbts ; get more bits -+ bcc .seq ; if bit was zero, no literals: go straight to sequence ++ bcc .endchk ; if bit was zero, no literals: go straight to sequence (after end check) jsr .gamma ; Yes we have literals. Get the count. + !if DEBUG { jsr .dbg1 } tax cpx #255 ; special case: long literal marked by len=255; chk and save to carry - lda (pSrc),y @@ -62,7 +62,8 @@ decomp !zone { cmp pEnd lda pDst+1 sbc pEnd+1 - bcs .ret + ;bcs .ret + bcs .chk .seq lda (pSrc),y inc pSrc @@ -79,9 +80,9 @@ decomp !zone { sta tmp jsr .gamma lsr - rol tmp + ror tmp lsr - rol tmp + ror tmp sta tmp+1 .gotoff lda pDst clc ; effectively add 1 to offset. @@ -97,6 +98,7 @@ decomp !zone { adc #1 ; A>=1 + sec + 1 => final len 3 or more tax .gotlen + !if DEBUG { jsr .dbg2 } - lda (pTmp),y sta (pDst),y iny @@ -109,7 +111,7 @@ decomp !zone { ldy #0 ; back to 0 as expected by lits section bcc .lits inc pDst+1 - bcs .lits ; always taken + jmp .lits ; Read an Elias Gamma value into A. Destroys X. Sets carry. .gamma lda #1 @@ -134,4 +136,42 @@ decomp !zone { sta bits txa .ret rts + +.chk ora pDst + eor pEnd + beq .ret + brk + +!if DEBUG { +.dbg1 pha + lda #'L'|$80 + jsr cout + pla + pha +.dbgEnd jsr prbyte + jsr crout +;- bit $C000 +; bpl - +; bit $C010 + pla + rts + +.dbg2 pha + lda #'S'|$80 + jsr cout + txa + jsr prbyte + lda #' '|$80 + jsr cout + lda tmp + clc + adc #1 + pha + lda tmp+1 + adc #0 + jsr prbyte + pla + jmp .dbgEnd +} + } ; end of zone diff --git a/Platform/Apple/virtual/src/core/loader.s b/Platform/Apple/virtual/src/core/loader.s new file mode 100644 index 00000000..7ab159ea --- /dev/null +++ b/Platform/Apple/virtual/src/core/loader.s @@ -0,0 +1,151 @@ +;**************************************************************************************** +; Copyright (C) 2017 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1 +; (the "License"); you may not use this file except in compliance with the License. +; You may obtain a copy of the License at . +; Unless required by applicable law or agreed to in writing, software distributed under +; the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +; ANY KIND, either express or implied. See the License for the specific language +; governing permissions and limitations under the License. +;**************************************************************************************** + +;@com.wudsn.ide.asm.hardware=APPLE2 +; LegendOS bootstrapping loader +; ----------------------------- + +; Use hi-bit ASCII for Apple II +!convtab "../include/hiBitAscii.ct" + +; Handy global defs +!source "../include/global.i" + +DEBUG = 0 + +* = $2000 + +tmp = $2 ; len 2 +pTmp = $4 ; len 2 +bits = $6 ; len 1 + +pSrc = $C ; len 2 +pDst = $E ; len 2 +pEnd = $10 ; len 2 + +pData = $80 ; len 2 +pRun = $82 ; len 2 + +decomp = $DF00 + +init ; Init pointer to blocks we're going to move/decompress + lda #dataStart + sta pData+1 + ; temporary: copy ROM so we can debug decompressor + bit setLcWr ; read from ROM, write to LC ram + bit setLcWr + ldy #0 + sty pSrc + ldx #$f8 +-- stx pSrc+1 +- lda (pSrc),y + sta (pSrc),y + iny + bne - + inx + bne -- + ; First is the decompressor itself (special: just copy one page) + jsr getBlk + bit setLcRW+lcBank1 ; switch in target bank + bit setLcRW+lcBank1 +- lda (pSrc),y +.st sta decomp,y + iny + bne - + ; Next comes ProRWTS + jsr runBlk + ; Then PLASMA + jsr runBlk + ; And finally the memory mgr (fall through) +runBlk jsr getBlk ; get block size and calc pointers +!if DEBUG { + lda #1 ; turn on printer + jsr $FE95 + jsr debug +} + bit setLcRW+lcBank1 + jsr decomp ; decompress the code +!if DEBUG { + lda #"R" + jsr ROM_cout + jsr ROM_crout +} + jmp $4000 ; and run it so it'll relocate itself + +getByte ldy #0 + lda (pData),y + inc pData + bne + + inc pData+1 ++ rts + +getWord jsr getByte + pha + jsr getByte + tax + pla + clc + rts + +getBlk ; Get uncompressed len from the block header, + ; and calculate dest end (based on start of $4000) + jsr getWord + sta pEnd + txa + adc #$40 + sta pEnd+1 + + ; Get compressed len + jsr getWord + pha ; save lo byte of len + + ; We're now looking at start of compressed data. Record that pointer. + lda pData + sta pSrc + lda pData+1 + sta pSrc+1 + + ; We always decompress to $4000 + sty pDst ; Y already zero + lda #$40 + sta pDst+1 + + ; Add compressed length to get to start of next block + pla ; get len back + adc pData + sta pData + txa + adc pData+1 + sta pData+1 + + rts + +!if DEBUG { +debug jsr ROM_crout + lda #"B" + jsr ROM_cout + lda pSrc+1 + ldx pSrc + jsr .pr + lda pDst+1 + ldx pDst + jsr .pr + lda pEnd+1 + ldx pEnd + jsr ROM_prntax + jmp ROM_crout +.pr jsr ROM_prntax + lda #" " + jmp ROM_cout +} + +dataStart = * \ No newline at end of file diff --git a/Platform/Apple/virtual/src/core/mem.s b/Platform/Apple/virtual/src/core/mem.s index d7e3a571..abd25272 100644 --- a/Platform/Apple/virtual/src/core/mem.s +++ b/Platform/Apple/virtual/src/core/mem.s @@ -14,7 +14,7 @@ ; ; See detailed description in mem.i -* = $2000 ; PLASMA loader loads us initially at $2000 +* = $4000 ; PLASMA loader loads us initially at $2000 ; Use hi-bit ASCII for Apple II !convtab "../include/hiBitAscii.ct"