rle_decompress.s (1566B)
1 .include "global.s" 2 3 .module RLE_DECOMPRESS 4 5 .area _DATA 6 7rle_cursor: 8 .ds 0x02 9rle_counter: 10 .ds 0x01 11rle_current: 12 .ds 0x01 13 14 .area _CODE 15 16_rle_init:: 17 ld (rle_cursor), hl 18 xor a 19 ld hl, #rle_counter 20 ld (hl), a 21 inc hl 22 ld (hl), a 23 ld l, #1 24 ret 25 26_rle_decompress:: 27 ;; Pop the return address 28 pop hl 29 pop de 30 dec sp 31 ex (sp), hl 32 ld b, h 33 34 ld hl, (rle_cursor) 35 36 ld a, l 37 or h 38 ret z 39 40 ld a, (rle_counter) 41 or a 42 ld c, a 43 jr z, 1$ 44 45 ld a, (rle_current) 46 bit 7, c 47 jr nz, 10$ 48 jr 11$ 491$: 50 ;; Fetch the run 51 ld c, (hl) 52 inc hl 53 ;; Negative means a run 548$: 55 bit 7, c 56 jr z, 2$ 57 ;; Expanding a run 58 ld a, (hl) 59 inc hl 603$: 61 ld (de), a 62 inc de 63 64 dec b 65 jr z, 6$ 6610$: 67 inc c 68 jr NZ, 3$ 69 jr 1$ 702$: 71 ;; Zero means end of a block 72 inc c 73 dec c 74 jr z, 4$ 75 ;; Expanding a block 765$: 77 ldi 78 inc bc 79 80 dec b 81 jr z, 6$ 8211$: 83 dec c 84 jr NZ, 5$ 85 jr 1$ 864$: 87 ;; save state and exit 88 ld hl, #0 89 ld (rle_cursor), hl 90 ld (rle_counter), hl 91 ret 926$: 93 ;; save state and exit 94 ld (rle_cursor), hl 95 ld hl, #rle_counter 96 ld (hl), c 97 inc hl 98 ld (hl), a 99 ld l, #1 100 ret