SHARE
TWEET

Kick Assembler & Exomizer Example

jskogsta Feb 27th, 2020 (edited) 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Define the name and path to the exomizer raw output file
  2. .var bitmap_bitmap_exo = LoadBinary("bitmaps/logo_320x200_bitmap.exo")
  3.  
  4. // Exomizer crunched data file of same bitmap as above
  5. * = $4000 "Bitmap Exomizer"
  6. Bitmap_Exo: .fill bitmap_bitmap_exo.getSize(), bitmap_bitmap_exo.get(i)
  7.  
  8. [File 1: exodecrunch_wrap.asm]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  9.  
  10. //  PROCESSOR 6502
  11. //  ORG $c800
  12.     jsr exod_decrunch
  13.     rts
  14. exod_get_crunched_byte:
  15.     lda opbase + 1
  16.     bne nowrap
  17.     dec opbase + 2
  18. nowrap:
  19.     dec opbase + 1
  20.     // change the $ffff to point to the byte immediately following the last
  21.     // byte of the crunched file data (mem command)
  22. opbase:
  23.     lda $ffff
  24.     rts
  25.     // include the decruncher source
  26. //  INCLUDE exodecrunch.s
  27. #import "code/exodecrunch.asm"          // lets import the exo decrunch routine
  28.  
  29. [File 2: exodecrunch.asm]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  30.  
  31. //
  32. // Exodecrunch code converted to Kick Assembler
  33. // Date: Feb 13th 2019
  34. //
  35. // This code was converted for inlcusion into Kick Assembler projects and
  36. // took the standard Exo V2 supporting DASM code and converted to Kick
  37. // syntax.
  38. //
  39. // Worth noting that I removed the conditional checks for use of literal
  40. // sequences. As such, the data HAS TO BE crunched with the '-c' flag
  41. // to work (see below for details)
  42. //
  43. // .....
  44. //
  45. // Copyright (c) 2002 - 2005 Magnus Lind.
  46. //
  47. // This software is provided 'as-is', without any express or implied warranty.
  48. // In no event will the authors be held liable for any damages arising from
  49. // the use of this software.
  50. //
  51. // Permission is granted to anyone to use this software for any purpose,
  52. // including commercial applications, and to alter it and redistribute it
  53. // freely, subject to the following restrictions:
  54. //
  55. //   1. The origin of this software must not be misrepresented// you must not
  56. //   claim that you wrote the original software. If you use this software in a
  57. //   product, an acknowledgment in the product documentation would be
  58. //   appreciated but is not required.
  59. //
  60. //   2. Altered source versions must be plainly marked as such, and must not
  61. //   be misrepresented as being the original software.
  62. //
  63. //   3. This notice may not be removed or altered from any distribution.
  64. //
  65. //   4. The names of this software and/or it's copyright holders may not be
  66. //   used to endorse or promote products derived from this software without
  67. //   specific prior written permission.
  68. //
  69. // -------------------------------------------------------------------
  70. // The decruncher jsr:s to the get_crunched_byte address when it wants to
  71. // read a crunched byte. This subroutine has to preserve x and y register
  72. // and must not modify the state of the carry flag.
  73. // -------------------------------------------------------------------
  74. // -------------------------------------------------------------------
  75. // this function is the heart of the decruncher.
  76. // It initializes the decruncher zeropage locations and precalculates the
  77. // decrunch tables and decrunches the data
  78. // This function will not change the interrupt status bit and it will not
  79. // modify the memory configuration.
  80. // -------------------------------------------------------------------
  81. // -------------------------------------------------------------------
  82. // if literal sequences is not used (the data was crunched with the -c
  83. // flag) then the following line can be uncommented for shorter code.
  84. //EXOD_LITERAL_SEQUENCES_NOT_USED = 1
  85. // -------------------------------------------------------------------
  86. // zero page addresses used
  87. // -------------------------------------------------------------------
  88. .var exod_zp_len_lo = $a7
  89.  
  90. .var exod_zp_src_lo  = $ae
  91. .var exod_zp_src_hi  = exod_zp_src_lo + 1
  92.  
  93. .var exod_zp_bits_hi = $fc
  94.  
  95. .var exod_zp_bitbuf  = $fd
  96. .var exod_zp_dest_lo = exod_zp_bitbuf + 1   // dest addr lo
  97. .var exod_zp_dest_hi = exod_zp_bitbuf + 2   // dest addr hi
  98.  
  99. .var exod_tabl_bi = exod_decrunch_table
  100. .var exod_tabl_lo = exod_decrunch_table + 52
  101. .var exod_tabl_hi = exod_decrunch_table + 104
  102.  
  103. // -------------------------------------------------------------------
  104. // no code below this comment has to be modified in order to generate
  105. // a working decruncher of this source file.
  106. // However, you may want to relocate the tables last in the file to a
  107. // more suitable address.
  108. // -------------------------------------------------------------------
  109.  
  110. // -------------------------------------------------------------------
  111. // jsr this label to decrunch, it will in turn init the tables and
  112. // call the decruncher
  113. // no constraints on register content, however the
  114. // decimal flag has to be #0 (it almost always is, otherwise do a cld)
  115. exod_decrunch:
  116. // -------------------------------------------------------------------
  117. // init zeropage, x and y regs. (12 bytes)
  118. //
  119.     ldy #0
  120.     ldx #3
  121. exod_init_zp:
  122.     jsr exod_get_crunched_byte
  123.     sta exod_zp_bitbuf - 1,x
  124.     dex
  125.     bne exod_init_zp
  126. // -------------------------------------------------------------------
  127. // calculate tables (50 bytes)
  128. // x and y must be #0 when entering
  129. //
  130. exod_nextone:
  131.     inx
  132.     tya
  133.     and #$0f
  134.     beq exod_shortcut       // starta på ny sekvens
  135.  
  136.     txa         // this clears reg a
  137.     lsr         // and sets the carry flag
  138.     ldx exod_tabl_bi-1,y
  139. exod_rolle:
  140.     rol
  141.     rol exod_zp_bits_hi
  142.     dex
  143.     bpl exod_rolle      // c = 0 after this (rol exod_zp_bits_hi)
  144.  
  145.     adc exod_tabl_lo-1,y
  146.     tax
  147.  
  148.     lda exod_zp_bits_hi
  149.     adc exod_tabl_hi-1,y
  150. exod_shortcut:
  151.     sta exod_tabl_hi,y
  152.     txa
  153.     sta exod_tabl_lo,y
  154.  
  155.     ldx #4
  156.     jsr exod_get_bits       // clears x-reg.
  157.     sta exod_tabl_bi,y
  158.     iny
  159.     cpy #52
  160.     bne exod_nextone
  161.     ldy #0
  162.     beq exod_begin
  163. // -------------------------------------------------------------------
  164. // get bits (29 bytes)
  165. //
  166. // args:
  167. //   x = number of bits to get
  168. // returns:
  169. //   a = #bits_lo
  170. //   x = #0
  171. //   c = 0
  172. //   z = 1
  173. //   exod_zp_bits_hi = #bits_hi
  174. // notes:
  175. //   y is untouched
  176. // -------------------------------------------------------------------
  177. exod_get_bits:
  178.     lda #$00
  179.     sta exod_zp_bits_hi
  180.     cpx #$01
  181.     bcc exod_bits_done
  182. exod_bits_next:
  183.     lsr exod_zp_bitbuf
  184.     bne exod_ok
  185.     pha
  186. exod_literal_get_byte:
  187.     jsr exod_get_crunched_byte
  188.     bcc exod_literal_byte_gotten
  189.     ror
  190.     sta exod_zp_bitbuf
  191.     pla
  192. exod_ok:
  193.     rol
  194.     rol exod_zp_bits_hi
  195.     dex
  196.     bne exod_bits_next
  197. exod_bits_done:
  198.     rts
  199. // -------------------------------------------------------------------
  200. // main copy loop (18(16) bytes)
  201. //
  202. exod_copy_next_hi:
  203.     dex
  204.     dec exod_zp_dest_hi
  205.     dec exod_zp_src_hi
  206. exod_copy_next:
  207.     dey
  208. //  IFNCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  209. //  bcc exod_literal_get_byte
  210. //  ENDIF
  211.     lda (exod_zp_src_lo),y
  212. exod_literal_byte_gotten:
  213.     sta (exod_zp_dest_lo),y
  214. exod_copy_start:
  215.     tya
  216.     bne exod_copy_next
  217. exod_begin:
  218.     txa
  219.     bne exod_copy_next_hi
  220. // -------------------------------------------------------------------
  221. // decruncher entry point, needs calculated tables (21(13) bytes)
  222. // x and y must be #0 when entering
  223. //
  224. //  IFNCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  225. //  inx
  226. //  jsr exod_get_bits
  227. //  tay
  228. //  bne exod_literal_start1
  229. //  ELSE
  230. //  dey
  231. //  ENDIF
  232. exod_begin2:
  233.     inx
  234.     jsr exod_bits_next
  235.     lsr
  236.     iny
  237.     bcc exod_begin2
  238. //  IFCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  239. //  beq exod_literal_start
  240. //  ENDIF
  241.     cpy #$11
  242. //  IFNCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  243. //  bcc exod_sequence_start
  244. //  beq exod_bits_done
  245. //// -------------------------------------------------------------------
  246. //// literal sequence handling (13(2) bytes)
  247. ////
  248. //  ldx #$10
  249. //  jsr exod_get_bits
  250. //exod_literal_start1:
  251. //  sta <exod_zp_len_lo
  252. //  ldx <exod_zp_bits_hi
  253. //  ldy #0
  254. //  bcc exod_literal_start
  255. //exod_sequence_start:
  256. //  ELSE
  257.     bcs exod_bits_done
  258. //  ENDIF
  259. // -------------------------------------------------------------------
  260. // calulate length of sequence (exod_zp_len) (11 bytes)
  261. //
  262.     ldx exod_tabl_bi - 1,y
  263.     jsr exod_get_bits
  264.     adc exod_tabl_lo - 1,y  // we have now calculated exod_zp_len_lo
  265.     sta exod_zp_len_lo
  266. // -------------------------------------------------------------------
  267. // now do the hibyte of the sequence length calculation (6 bytes)
  268.     lda exod_zp_bits_hi
  269.     adc exod_tabl_hi - 1,y  // c = 0 after this.
  270.     pha
  271. // -------------------------------------------------------------------
  272. // here we decide what offset table to use (20 bytes)
  273. // x is 0 here
  274. //
  275.     bne exod_nots123
  276.     ldy exod_zp_len_lo
  277.     cpy #$04
  278.     bcc exod_size123
  279. exod_nots123:
  280.     ldy #$03
  281. exod_size123:
  282.     ldx exod_tabl_bit - 1,y
  283.     jsr exod_get_bits
  284.     adc exod_tabl_off - 1,y // c = 0 after this.
  285.     tay         // 1 <= y <= 52 here
  286. // -------------------------------------------------------------------
  287. // Here we do the dest_lo -= len_lo subtraction to prepare exod_zp_dest
  288. // but we do it backwards:  a - b == (b - a - 1) ^ ~0 (C-syntax)
  289. // (16(16) bytes)
  290.     lda exod_zp_len_lo
  291. exod_literal_start:         // literal enters here with y = 0, c = 1
  292.     sbc exod_zp_dest_lo
  293.     bcc exod_noborrow
  294.     dec exod_zp_dest_hi
  295. exod_noborrow:
  296.     eor #$ff
  297.     sta exod_zp_dest_lo
  298.     cpy #$01        // y < 1 then literal
  299. //  IFNCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  300. //  bcc exod_pre_copy
  301. //  ELSE
  302.     bcc exod_literal_get_byte
  303. //  ENDIF
  304. // -------------------------------------------------------------------
  305. // calulate absolute offset (exod_zp_src) (27 bytes)
  306. //
  307.     ldx exod_tabl_bi,y
  308.     jsr exod_get_bits;
  309.     adc exod_tabl_lo,y
  310.     bcc exod_skipcarry
  311.     inc exod_zp_bits_hi
  312.     clc
  313. exod_skipcarry:
  314.     adc exod_zp_dest_lo
  315.     sta exod_zp_src_lo
  316.     lda exod_zp_bits_hi
  317.     adc exod_tabl_hi,y
  318.     adc exod_zp_dest_hi
  319.     sta exod_zp_src_hi
  320. // -------------------------------------------------------------------
  321. // prepare for copy loop (8(6) bytes)
  322. //
  323.     pla
  324.     tax
  325. //  IFNCONST EXOD_LITERAL_SEQUENCES_NOT_USED
  326. //  sec
  327. //exod_pre_copy:
  328. //  ldy <exod_zp_len_lo
  329. //  jmp exod_copy_start
  330. //  ELSE
  331.     ldy <exod_zp_len_lo
  332.     bcc exod_copy_start
  333. //  ENDIF
  334. // -------------------------------------------------------------------
  335. // two small static tables (6(6) bytes)
  336. //
  337. exod_tabl_bit:
  338.     .byte 2,4,4
  339. exod_tabl_off:
  340.     .byte 48,32,16
  341. // -------------------------------------------------------------------
  342. // end of decruncher
  343. // -------------------------------------------------------------------
  344.  
  345. // -------------------------------------------------------------------
  346. // this 156 byte table area may be relocated. It may also be clobbered
  347. // by other data between decrunches.
  348. // -------------------------------------------------------------------
  349. exod_decrunch_table:
  350.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  351.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  352.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  353.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  354.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  355.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  356.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  357.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  358.     .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  359.     .byte 0,0,0,0,0,0,0,0,0,0,0,0
  360. // -------------------------------------------------------------------
  361. // end of decruncher
  362. // -------------------------------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top