Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.92 KB | None | 0 0
  1. //
  2. // Switch bank in VIC-II
  3. //
  4. // Args:
  5. // bank: bank number to switch to. Valid values: 0-3.
  6. //
  7. .macro SwitchVICBank(bank) {
  8. //
  9. // The VIC-II chip can only access 16K bytes at a time. In order to
  10. // have it access all of the 64K available, we have to tell it to look
  11. // at one of four banks.
  12. //
  13. // This is controller by bits 0 and 1 in $dd00 (PORT A of CIA #2).
  14. //
  15. // +------+-------+----------+-------------------------------------+
  16. // | BITS | BANK | STARTING | VIC-II CHIP RANGE |
  17. // | | | LOCATION | |
  18. // +------+-------+----------+-------------------------------------+
  19. // | 00 | 3 | 49152 | ($C000-$FFFF)* |
  20. // | 01 | 2 | 32768 | ($8000-$BFFF) |
  21. // | 10 | 1 | 16384 | ($4000-$7FFF)* |
  22. // | 11 | 0 | 0 | ($0000-$3FFF) (DEFAULT VALUE) |
  23. // +------+-------+----------+-------------------------------------+
  24. .var bits=%11
  25.  
  26. .if (bank==0) .eval bits=%11
  27. .if (bank==1) .eval bits=%10
  28. .if (bank==2) .eval bits=%01
  29. .if (bank==3) .eval bits=%00
  30.  
  31. .print "bits=%" + toBinaryString(bits)
  32.  
  33. //
  34. // Set Data Direction for CIA #2, Port A to output
  35. //
  36. lda $dd02
  37. and #%11111100 // Mask the bits we're interested in.
  38. ora #$03 // Set bits 0 and 1.
  39. sta $dd02
  40.  
  41. //
  42. // Tell VIC-II to switch to bank
  43. //
  44. lda $dd00
  45. and #%11111100
  46. ora #bits
  47. sta $dd00
  48. }
  49.  
  50.  
  51. //
  52. // Enter hires bitmap mode (a.k.a. standard bitmap mode)
  53. //
  54. .macro SetHiresBitmapMode() {
  55. //
  56. // Clear extended color mode (bit 6) and set bitmap mode (bit 5)
  57. //
  58. lda $d011
  59. and #%10111111
  60. ora #%00100000
  61. sta $d011
  62.  
  63. //
  64. // Clear multi color mode (bit 4)
  65. //
  66. lda $d016
  67. and #%11101111
  68. sta $d016
  69. }
  70.  
  71. .macro ResetStandardBitMapMode() {
  72. lda $d011
  73. and #%11011111
  74. sta $d011
  75. }
  76.  
  77. //
  78. // Set location of bitmap.
  79. //
  80. // Args:
  81. // address: Address relative to VIC-II bank address.
  82. // Valid values: $0000 (bitmap at $0000-$1FFF)
  83. // $2000 (bitmap at $2000-$3FFF)
  84. //
  85. .macro SetBitmapAddress(address) {
  86. //
  87. // In standard bitmap mode the location of the bitmap area can
  88. // be set to either BANK address + $0000 or BANK address + $2000
  89. //
  90. // By setting bit 3, we can configure which of the locations to use.
  91. //
  92.  
  93. .var bits=0
  94.  
  95. lda $d018
  96.  
  97. .if (address == $0000) {
  98. and #%11110111
  99. }
  100.  
  101. .if (address == $2000) {
  102. ora #%00001000
  103. }
  104.  
  105. sta $d018
  106. }
  107.  
  108. .macro FillBitmap(addr, value) {
  109. ldx #$00
  110. lda #value
  111. !loop:
  112. sta addr,x
  113. sta (addr + $100),x
  114. sta (addr + $200),x
  115. sta (addr + $300),x
  116. sta (addr + $400),x
  117. sta (addr + $500),x
  118. sta (addr + $600),x
  119. sta (addr + $700),x
  120. sta (addr + $800),x
  121. sta (addr + $900),x
  122. sta (addr + $a00),x
  123. sta (addr + $b00),x
  124. sta (addr + $c00),x
  125. sta (addr + $d00),x
  126. sta (addr + $e00),x
  127. sta (addr + $f00),x
  128. sta (addr + $1000),x
  129. sta (addr + $1100),x
  130. sta (addr + $1200),x
  131. sta (addr + $1300),x
  132. sta (addr + $1400),x
  133. sta (addr + $1500),x
  134. sta (addr + $1600),x
  135. sta (addr + $1700),x
  136. sta (addr + $1800),x
  137. sta (addr + $1900),x
  138. sta (addr + $1a00),x
  139. sta (addr + $1b00),x
  140. sta (addr + $1c00),x
  141. sta (addr + $1d00),x
  142. sta (addr + $1e00),x
  143. sta (addr + $1f00),x
  144. dex
  145. bne !loop-
  146. }
  147.  
  148. //
  149. // Switch location of screen memory.
  150. //
  151. // Args:
  152. // address: Address relative to current VIC-II bank base address.
  153. // Valid values: $0000-$3c00. Must be a multiple of $0400.
  154. //
  155. .macro SetScreenMemory(address) {
  156. //
  157. // The most significant nibble of $D018 selects where the screen is
  158. // located in the current VIC-II bank.
  159. //
  160. // +------------+-----------------------------+
  161. // | | LOCATION* |
  162. // | BITS +---------+-------------------+
  163. // | | DECIMAL | HEX |
  164. // +------------+---------+-------------------+
  165. // | 0000XXXX | 0 | $0000 |
  166. // | 0001XXXX | 1024 | $0400 (DEFAULT) |
  167. // | 0010XXXX | 2048 | $0800 |
  168. // | 0011XXXX | 3072 | $0C00 |
  169. // | 0100XXXX | 4096 | $1000 |
  170. // | 0101XXXX | 5120 | $1400 |
  171. // | 0110XXXX | 6144 | $1800 |
  172. // | 0111XXXX | 7168 | $1C00 |
  173. // | 1000XXXX | 8192 | $2000 |
  174. // | 1001XXXX | 9216 | $2400 |
  175. // | 1010XXXX | 10240 | $2800 |
  176. // | 1011XXXX | 11264 | $2C00 |
  177. // | 1100XXXX | 12288 | $3000 |
  178. // | 1101XXXX | 13312 | $3400 |
  179. // | 1110XXXX | 14336 | $3800 |
  180. // | 1111XXXX | 15360 | $3C00 |
  181. // +------------+---------+-------------------+
  182. //
  183. .var bits = (address / $0400) << 4
  184.  
  185. lda $d018
  186. and #%00001111
  187. ora #bits
  188. sta $d018
  189. }
  190.  
  191. //
  192. // Fill screen memory with a value.
  193. //
  194. // Args:
  195. // address: Absolute base address of screen memory.
  196. // value: byte value to fill screen memory with
  197. //
  198. .macro FillScreenMemory(address, value) {
  199. //
  200. // Screen memory is 40 * 25 = 1000 bytes ($3E8 bytes)
  201. //
  202. ldx #$00
  203. lda #value
  204. !loop:
  205. sta address,x
  206. sta (address + $100),x
  207. sta (address + $200),x
  208. dex
  209. bne !loop-
  210.  
  211. ldx #$e8
  212. !loop:
  213. sta (address + $2ff),x // Start one byte below the area we're clearing
  214. // That way we can bail directly when zero without an additional comparison
  215. dex
  216. bne !loop-
  217. }
  218.  
  219. //
  220. // Makes program halt until space is pressed. Useful when debugging.
  221. //
  222. .macro WaitForSpace() {
  223. checkdown:
  224. lda $dc01
  225. cmp #$ef
  226. bne checkdown
  227.  
  228. checkup:
  229. lda $dc01
  230. cmp #$ef
  231. beq checkup
  232. }
  233.  
  234. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235.  
  236. PNGtoHIRES
  237. ~~~~~~~~~~
  238.  
  239. By: TWW/CTR
  240.  
  241. USAGE
  242. ~~~~~
  243.  
  244. :PNGtoHIRES("Filename.png", BitmapMemoryAddress, ScreenMemoryColors)
  245.  
  246. @SIGNATURE void PNGtoHIRES (STR Filename.png ,U16 BitmapMemoryAddress, U16 ScreenMemoryColors)
  247. @AUTHOR tww@creators.no
  248.  
  249. @PARAM Filename.png - Filename & path to picture file
  250. @PARAM BitmapMemoryAddress - Memorylocation for output of bmp-data
  251. @PARAM ScreenMemoryColors - Memorylocation for output of Char-data
  252.  
  253.  
  254. EXAMPLES
  255. ~~~~~~~~
  256.  
  257. :PNGtoHIRES("something.png", $2000, $2000+8000)
  258.  
  259.  
  260. NOTES
  261. ~~~~~
  262.  
  263. For now, only handles 320x200
  264.  
  265.  
  266. IMPROVEMENTS
  267. ~~~~~~~~~~~~
  268.  
  269. Add variable picture sizes
  270. Handle assertions if the format is unsupported (size, color restrictions etc.)
  271.  
  272. TODO
  273. ~~~~
  274.  
  275.  
  276. BUGS
  277. ~~~~
  278.  
  279.  
  280. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  281.  
  282. .macro PNGtoHIRES(PNGpicture,BMPData,ColData) {
  283.  
  284. .var Graphics = LoadPicture(PNGpicture)
  285.  
  286. // Graphics RGB Colors. Must be adapted to the graphics
  287.  
  288. .const C64Black = 000 * 65536 + 000 * 256 + 000
  289. .const C64White = 255 * 65536 + 255 * 256 + 255
  290. .const C64Red = 104 * 65536 + 055 * 256 + 043
  291. .const C64Cyan = 112 * 65536 + 164 * 256 + 178
  292. .const C64Purple = 111 * 65536 + 061 * 256 + 134
  293. .const C64Green = 088 * 65536 + 141 * 256 + 067
  294. .const C64Blue = 053 * 65536 + 040 * 256 + 121
  295. .const C64Yellow = 184 * 65536 + 199 * 256 + 111
  296. .const C64L_brown = 111 * 65536 + 079 * 256 + 037
  297. .const C64D_brown = 067 * 65536 + 057 * 256 + 000
  298. .const C64L_red = 154 * 65536 + 103 * 256 + 089
  299. .const C64D_grey = 068 * 65536 + 068 * 256 + 068
  300. .const C64Grey = 108 * 65536 + 108 * 256 + 108
  301. .const C64L_green = 154 * 65536 + 210 * 256 + 132
  302. .const C64L_blue = 108 * 65536 + 094 * 256 + 181
  303. .const C64L_grey = 149 * 65536 + 149 * 256 + 149
  304.  
  305. // Add the colors neatly into a Hashtable for easy lookup reference
  306. .var ColorTable = Hashtable()
  307. .eval ColorTable.put(C64Black,0)
  308. .eval ColorTable.put(C64White,1)
  309. .eval ColorTable.put(C64Red,2)
  310. .eval ColorTable.put(C64Cyan,3)
  311. .eval ColorTable.put(C64Purple,4)
  312. .eval ColorTable.put(C64Green,5)
  313. .eval ColorTable.put(C64Blue,6)
  314. .eval ColorTable.put(C64Yellow,7)
  315. .eval ColorTable.put(C64L_brown,8)
  316. .eval ColorTable.put(C64D_brown,9)
  317. .eval ColorTable.put(C64L_red,10)
  318. .eval ColorTable.put(C64D_grey,11)
  319. .eval ColorTable.put(C64Grey,12)
  320. .eval ColorTable.put(C64L_green,13)
  321. .eval ColorTable.put(C64L_blue,14)
  322. .eval ColorTable.put(C64L_grey,15)
  323.  
  324. .pc = BMPData "Hires Bitmap"
  325.  
  326. .var ScreenMem = List()
  327. .for (var Line = 0 ; Line < 200 ; Line = Line + 8) {
  328. .for (var Block = 0 ; Block < 320 ; Block=Block+8) {
  329. .var Coll1 = Graphics.getPixel(Block,Line)
  330. .var Coll2 = 0
  331. .for (var j = 0 ; j < 8 ; j++ ) {
  332. .var ByteValue = 0
  333. .for (var i = 0 ; i < 8 ; i++ ) {
  334. .if (Graphics.getPixel(Block,Line) != Graphics.getPixel(Block+i,Line+j)) .eval ByteValue = ByteValue + pow(2,7-i)
  335. .if (Graphics.getPixel(Block,Line) != Graphics.getPixel(Block+i,Line+j)) .eval Coll2 = Graphics.getPixel(Block+i,Line+j)
  336. }
  337. .byte ByteValue
  338. }
  339. .var BlockColor = [ColorTable.get(Coll2)]*16+ColorTable.get(Coll1)
  340. .eval ScreenMem.add(BlockColor)
  341. }
  342. }
  343. .pc = ColData "Hires Color Data"
  344. ScreenMemColors:
  345. .for (var i = 0 ; i < 1000 ; i++ ) {
  346. .byte ScreenMem.get(i)
  347. }
  348. }
  349.  
  350. //
  351. // Stabilize the IRQ so that the handler function is called exactly when the
  352. // line scan begins.
  353. //
  354. // If an interrupt is registered when the raster reaches a line, an IRQ is
  355. // triggered on the first cycle of that line scan. This means that the code we
  356. // want to esecute at that line will not be called immediately. There's quite
  357. // a lot of housekeeping that needs to be done before we get called.
  358. //
  359. // What's worse is that it isn't deterministic how many cycles will pass from
  360. // when the raster starts at the current line untill we get the call.
  361. //
  362. // First, the CPU needs to finish its current operation. This can mean a delay
  363. // of 0 to 7 cycles, depending on what operation is currently running.
  364. //
  365. // Then we spend 7+13 cycles invoking the interrupt handler and pushing stuff to
  366. // the stack.
  367. //
  368. // So all in all we're being called between 20 and 27 cycles after the current line
  369. // scan begins.
  370. //
  371. // This macro removes that uncertainty by registering a new irq on the next line,
  372. // after that second interrupt is registered, it calls nop's until a line change
  373. // should occur.
  374. //
  375. // Now we know that the cycle type of the current op is only one cycle, so the only
  376. // uncertainty left is wether ran one extra cycle or not. We can determine that by
  377. // loading and comparing the current raster line ($d012) with itself. If they're not
  378. // equal, we switched raster line between the load and the compare -> we're ready to go.
  379. //
  380. // If they're equal, we haven't switched yet but we know we'll switch at the next cycle.
  381. // So we just wait an extra cycle in this case.
  382. //
  383. .macro StabilizeRaster() {
  384. //
  385. // Register a new irq handler for the next line.
  386. //
  387. lda #<stabilizedirq
  388. sta $fffe
  389. lda #>stabilizedirq
  390. sta $ffff
  391. inc $d012
  392.  
  393. //
  394. // ACK the current IRQ
  395. //
  396. lda #$ff
  397. sta $d019
  398.  
  399. // Save the old stack pointer so we can just restore the stack as it was
  400. // before the stabilizing got in the way.
  401. tsx
  402.  
  403. // Enable interrupts and call nop's until the end of the current line
  404. // should be reached
  405. cli
  406.  
  407. nop
  408. nop
  409. nop
  410. nop
  411. nop
  412. nop
  413. nop
  414. nop
  415. // Add one more nop if NTSC
  416.  
  417. // Here's or second irq handler
  418. stabilizedirq:
  419.  
  420. // Reset the SP so it looks like the extra irq stuff never happened
  421. txs
  422.  
  423. //
  424. // Wait for line to finish.
  425. //
  426.  
  427. // PAL-63 // NTSC-64 // NTSC-65
  428. //---------//------------//-----------
  429. ldx #$08 // ldx #$08 // ldx #$09
  430. dex // dex // dex
  431. bne *-1 // bne *-1 // bne *-1
  432. bit $00 // nop
  433. // nop
  434.  
  435. //
  436. // Check at exactly what point we go to the next line
  437. //
  438. lda $d012
  439. cmp $d012
  440. beq *+2 // If we haven't changed line yet, wait an extra cycle.
  441.  
  442. // Here our real logic can start running.
  443. }
  444.  
  445. .macro RasterInterrupt(address, line) {
  446. //
  447. // Address to jump to when raster reaches line.
  448. // Since we have the kernal banked out, we set the address
  449. // of our interrupt routine directly in $fffe-$ffff instead
  450. // of in $0314-$0315.
  451. //
  452. // If the kernal isn't banked out, it will push registers on the stack,
  453. // check if the interrupt is caused by a brk instruction, and eventually
  454. // call the interrupt function stored in the $0134-$0315 vector.
  455. //
  456. lda #<address
  457. sta $fffe // Instead of $0314 as we have no kernal rom
  458. lda #>address
  459. sta $ffff // Instead of $0315 as we have no kernal rom
  460.  
  461. //
  462. // Configure line to trigger interrupt at
  463. //
  464. /* .if(line > $ff) { */
  465. lda $d011
  466. ora #%10000000
  467. sta $d011
  468.  
  469. lda #>line
  470. sta $d012
  471. /* } else { */
  472. /* lda $d011 */
  473. /* and #%01111111 */
  474. /* sta $d011 */
  475. /* */
  476. /* lda #line */
  477. /* sta $d012 */
  478. /* } */
  479. }
  480.  
  481. .plugin "se.triad.kickass.CruncherPlugins"
  482.  
  483. .var vic_bank=1
  484. .var vic_base=$4000*vic_bank // A VIC-II bank indicates a 16K region
  485. .var vic_bank2=2
  486. .var vic_base2=$4000*vic_bank2 // A VIC-II bank indicates a 16K region
  487. .var screen_memory=$0000 + vic_base
  488. .var bitmap_address=$2000 + vic_base
  489.  
  490. .var screen_memory2=$0000 + vic_base2
  491. .var bitmap_address2=$2000 + vic_base2
  492.  
  493. .var music = LoadSid("music.sid")
  494.  
  495. BasicUpstart2(start)
  496.  
  497. start:
  498.  
  499. sei
  500.  
  501. // Turn off interrupts from the two CIA chips.
  502. // Used by the kernal to flash cursor and scan
  503. // keyboard.
  504. lda #$7f
  505. sta $dc0d //Turn off CIA 1 interrupts
  506. sta $dd0d //Turn off CIA 2 interrupts
  507.  
  508. // Reading these registers we ack any pending CIA interrupts.
  509. // Otherwise, we might get a trailing interrupt after setup.
  510. lda $dc0d
  511. lda $dd0d
  512.  
  513. // Tell VIC-II to start generating raster interrupts
  514. lda #$01
  515. sta $d01a //Turn on raster interrupts
  516.  
  517. // Bank out BASIC and KERNAL.
  518. // This causes the CPU to see RAM instead of KERNAL and
  519. // BASIC ROM at $E000-$FFFF and $A000-$BFFF respectively.
  520. //
  521. // This causes the CPU to see RAM everywhere except for
  522. // $D000-$E000, where the VIC-II, SID, CIA's etc are located.
  523. //
  524. lda #$35
  525. sta $01
  526.  
  527.  
  528. lda #<nmi_nop
  529. sta $fffa
  530. lda #>nmi_nop
  531. sta $fffb
  532.  
  533. lda #$00
  534. sta $dd0e // Stop timer A
  535. sta $dd04 // Set timer A to 0, NMI will occure immediately after start
  536. sta $dd0e
  537.  
  538. lda #$81
  539. sta $dd0d // Set timer A as source for NMI
  540.  
  541. lda #$01
  542. sta $dd0e // Start timer A -> NMI
  543.  
  544.  
  545. lda #0
  546. sta $d020
  547. sta $d021
  548.  
  549. :B2_DECRUNCH(crunch_screen1)
  550. :B2_DECRUNCH(crunch_screen2)
  551. :B2_DECRUNCH(crunch_music)
  552. ldx #0
  553. ldy #0
  554. lda #music.startSong //<- Here we get the startsong and init address from the sid file
  555. jsr music.init
  556.  
  557. SwitchVICBank(vic_bank)
  558. SetHiresBitmapMode()
  559. SetScreenMemory(screen_memory - vic_base)
  560. SetBitmapAddress(bitmap_address - vic_base)
  561.  
  562. RasterInterrupt(mainirq, $35)
  563.  
  564. cli
  565.  
  566.  
  567. loop:
  568.  
  569. lda frame
  570. cmp #$80
  571. bne no_switch
  572. lda #0
  573. sta frame
  574. inc base
  575.  
  576. lda base
  577. cmp #2
  578. bne no_zero
  579. lda #0
  580. sta base
  581.  
  582. no_zero:
  583.  
  584. lda base
  585. cmp #0
  586. beq switch0
  587. bne switch1
  588.  
  589. switch0:
  590. SwitchVICBank(1)
  591. jmp no_switch
  592. switch1:
  593. SwitchVICBank(2)
  594. jmp no_switch
  595.  
  596.  
  597. no_switch:
  598.  
  599. jmp loop
  600.  
  601. nmi_nop:
  602. //
  603. // This is the irq handler for the NMI. Just returns without acknowledge.
  604. // This prevents subsequent NMI's from interfering.
  605. //
  606. rti
  607.  
  608. mainirq:
  609. //
  610. // Since the kernal is switced off, we need to push the
  611. // values of the registers to the stack ourselves so
  612. // that they're restored when we're done.
  613. //
  614. // If we don't do anything advanced like calling cli to let another
  615. // irq occur, we don't need to use the stack.
  616. //
  617. // In that case it's faster to:
  618. //
  619. // sta restorea+1
  620. // stx restorex+1
  621. // sty restorey+1
  622. //
  623. // ... do stuff ...
  624. //
  625. // lda #$ff
  626. // sta $d019
  627. //
  628. // restorea: lda #$00
  629. // restorex: ldx #$00
  630. // restorey: ldy #$00
  631. // rti
  632. //
  633. pha
  634. txa
  635. pha
  636. tya
  637. pha
  638.  
  639. //
  640. // Stabilize raster using double irq's.
  641. StabilizeRaster()
  642.  
  643. inc frame
  644. lda frame
  645. sta $d020
  646.  
  647. jsr music.play
  648.  
  649. //
  650. // Reset the raster interrupt since the stabilizing registered another
  651. // function.
  652. // We can also register another irq for something further down the screen
  653. // or at next frame.
  654. //
  655. RasterInterrupt(mainirq, $35)
  656.  
  657. //
  658. // Restore the interrupt condition so that we can get
  659. // another one.
  660. //
  661. lda #$ff
  662. sta $d019 //ACK interrupt so it can be called again
  663.  
  664. //
  665. // Restore the values of the registers and return.
  666. //
  667. pla
  668. tay
  669. pla
  670. tax
  671. pla
  672. rti
  673.  
  674. frame:
  675. .byte 0
  676.  
  677. base:
  678. .byte 0
  679.  
  680. .const B2_ZP_BASE = $03
  681. // ByteBoozer Decruncher /HCL May.2003
  682. // B2 Decruncher December 2014
  683.  
  684. .label zp_base = B2_ZP_BASE
  685. .label bits = zp_base
  686. .label put = zp_base + 2
  687.  
  688. .macro B2_DECRUNCH(addr) {
  689. ldy #<addr
  690. ldx #>addr
  691. jsr Decrunch
  692. }
  693.  
  694. .macro GetNextBit() {
  695. asl bits
  696. bne DgEnd
  697. jsr GetNewBits
  698. DgEnd:
  699. }
  700.  
  701. .macro GetLen() {
  702. lda #1
  703. GlLoop:
  704. :GetNextBit()
  705. bcc GlEnd
  706. :GetNextBit()
  707. rol
  708. bpl GlLoop
  709. GlEnd:
  710. }
  711.  
  712. Decrunch:
  713. sty Get1+1
  714. sty Get2+1
  715. sty Get3+1
  716. stx Get1+2
  717. stx Get2+2
  718. stx Get3+2
  719.  
  720. ldx #0
  721. jsr GetNewBits
  722. sty put-1,x
  723. cpx #2
  724. bcc *-7
  725. lda #$80
  726. sta bits
  727. DLoop:
  728. :GetNextBit()
  729. bcs Match
  730. Literal:
  731. // Literal run.. get length.
  732. :GetLen()
  733. sta LLen+1
  734.  
  735. ldy #0
  736. LLoop:
  737. Get3:
  738. lda $feed,x
  739. inx
  740. bne *+5
  741. jsr GnbInc
  742. L1: sta (put),y
  743. iny
  744. LLen:
  745. cpy #0
  746. bne LLoop
  747.  
  748. clc
  749. tya
  750. adc put
  751. sta put
  752. bcc *+4
  753. inc put+1
  754.  
  755. iny
  756. beq DLoop
  757.  
  758. // Has to continue with a match..
  759.  
  760. Match:
  761. // Match.. get length.
  762. :GetLen()
  763. sta MLen+1
  764.  
  765. // Length 255 -> EOF
  766. cmp #$ff
  767. beq End
  768.  
  769. // Get num bits
  770. cmp #2
  771. lda #0
  772. rol
  773. :GetNextBit()
  774. rol
  775. :GetNextBit()
  776. rol
  777. tay
  778. lda Tab,y
  779. beq M8
  780.  
  781. // Get bits < 8
  782. M_1:
  783. :GetNextBit()
  784. rol
  785. bcs M_1
  786. bmi MShort
  787. M8:
  788. // Get byte
  789. eor #$ff
  790. tay
  791. Get2:
  792. lda $feed,x
  793. inx
  794. bne *+5
  795. jsr GnbInc
  796. jmp Mdone
  797. MShort:
  798. ldy #$ff
  799. Mdone:
  800. //clc
  801. adc put
  802. sta MLda+1
  803. tya
  804. adc put+1
  805. sta MLda+2
  806.  
  807. ldy #$ff
  808. MLoop:
  809. iny
  810. MLda:
  811. lda $beef,y
  812. sta (put),y
  813. MLen:
  814. cpy #0
  815. bne MLoop
  816.  
  817. //sec
  818. tya
  819. adc put
  820. sta put
  821. bcc *+4
  822. inc put+1
  823.  
  824. jmp DLoop
  825.  
  826. End:
  827. rts
  828.  
  829. GetNewBits:
  830. Get1:
  831. ldy $feed,x
  832. sty bits
  833. rol bits
  834. inx
  835. bne GnbEnd
  836. GnbInc:
  837. inc Get1+2
  838. inc Get2+2
  839. inc Get3+2
  840. GnbEnd:
  841. rts
  842.  
  843. Tab:
  844. // Short offsets
  845. .byte %11011111 // 3
  846. .byte %11111011 // 6
  847. .byte %00000000 // 8
  848. .byte %10000000 // 10
  849. // Long offsets
  850. .byte %11101111 // 4
  851. .byte %11111101 // 7
  852. .byte %10000000 // 10
  853. .byte %11110000 // 13
  854.  
  855.  
  856. // crunched data
  857.  
  858. .label crunch_music = *
  859. .modify B2() {
  860. .pc = music.location "Music"
  861. .fill music.size, music.getData(i)
  862. }
  863.  
  864.  
  865. .label crunch_screen1 = *
  866. .modify B2() {
  867. .pc=$4000
  868. :PNGtoHIRES("test.png", bitmap_address, screen_memory)
  869. }
  870.  
  871. .label crunch_screen2 = *
  872. .modify B2() {
  873. .pc=$8000
  874. :PNGtoHIRES("test_a.png", bitmap_address2, screen_memory2)
  875. }
  876.  
  877.  
  878. .print "vic_bank: " + toHexString(vic_bank)
  879. .print "vic_base: " + toHexString(vic_base)
  880. .print "screen_memory: " + toHexString(screen_memory)
  881. .print "bitmap_address: " + toHexString(bitmap_address)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement