gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/mos6502/rle_decompress.s
1 .include "global.s"
2
3 .module RLE_DECOMPRESS
4
5 .area _ZP (PAG)
6 rle_cursor:
7 .ds 0x02
8 rle_counter:
9 .ds 0x01
10 rle_current:
11 .ds 0x01
12 rle_code_ptr:
13 .ds 0x02
14
15 .area GBDKOVR (PAG, OVR)
16 _rle_decompress_PARM_2:: .ds 1
17 .rle_output: .ds 2
18
19 .define .out_len "_rle_decompress_PARM_2"
20
21 .area _HOME
22
23 .macro RLE_ADVANCE_CURSOR
24 tya
25 clc
26 adc *rle_cursor
27 sta *rle_cursor
28 lda #0
29 adc *rle_cursor+1
30 sta *rle_cursor+1
31 .endm
32
33 .macro RLE_ADVANCE_OUTPUT
34 tya
35 clc
36 adc *.rle_output
37 sta *.rle_output
38 lda #0
39 adc *.rle_output+1
40 sta *.rle_output+1
41 .endm
42
43 .macro RLE_SET_CODE_PTR code_address
44 lda #<code_address
45 sta *rle_code_ptr
46 lda #>code_address
47 sta *(rle_code_ptr+1)
48 .endm
49
50 _rle_init::
51 sta *rle_cursor
52 stx *(rle_cursor+1)
53 RLE_SET_CODE_PTR _rle_decompress_read_token_entry
54 lda #0x01
55 rts
56
57 _rle_decompress_eof:
58 RLE_SET_CODE_PTR _rle_decompress_eof
59 lda #0
60 rts
61
62 _rle_decompress::
63 jmp [*rle_code_ptr]
64
65 _rle_decompress_read_token_entry:
66 sta *.rle_output
67 stx *(.rle_output+1)
68 ldx *.out_len
69 ldy #0
70 _rle_decompress_read_token:
71 lda [*rle_cursor],y
72 beq _rle_decompress_eof
73 bmi _rle_decompress_read_token_repeat
74 ; RLE_TYPE_RAND
75 sta *rle_counter
76 RLE_SET_CODE_PTR _rle_decompress_process_rand_entry
77 inc *rle_cursor
78 beq 1$
79 jmp _rle_decompress_process_rand
80 1$:
81 inc *rle_cursor+1
82 jmp _rle_decompress_process_rand
83 _rle_decompress_read_token_repeat:
84 ; RLE_TYPE_REPEAT
85 sta *rle_counter
86 RLE_SET_CODE_PTR _rle_decompress_process_repeat_entry
87 inc *rle_cursor
88 beq 2$
89 lda [*rle_cursor],y
90 sta *rle_current
91 inc *rle_cursor
92 bne 1$
93 inc *(rle_cursor+1)
94 1$:
95 jmp _rle_decompress_process_repeat
96 2$:
97 inc *(rle_cursor+1)
98 lda [*rle_cursor],y
99 sta *rle_current
100 inc *rle_cursor
101 jmp _rle_decompress_process_repeat
102
103 _rle_decompress_process_rand_entry:
104 sta *.rle_output
105 stx *(.rle_output+1)
106 ldx *.out_len
107 ldy #0
108 _rle_decompress_process_rand:
109 1$:
110 cpx #0
111 beq _rle_decompress_process_rand_yield
112 lda [*rle_cursor],y
113 sta [*.rle_output],y
114 dex
115 iny
116 dec *rle_counter
117 bne 1$
118 RLE_ADVANCE_CURSOR
119 RLE_ADVANCE_OUTPUT
120 ldy #0
121 jmp _rle_decompress_read_token
122
123 _rle_decompress_process_rand_yield:
124 RLE_ADVANCE_CURSOR
125 lda #1
126 rts
127
128 _rle_decompress_process_repeat_entry:
129 sta *.rle_output
130 stx *(.rle_output+1)
131 ldx *.out_len
132 ldy #0
133 _rle_decompress_process_repeat:
134 lda *rle_current
135 1$:
136 cpx #0
137 beq _rle_decompress_process_repeat_yield
138 sta [*.rle_output],y
139 dex
140 iny
141 inc *rle_counter
142 bne 1$
143 RLE_ADVANCE_OUTPUT
144 ldy #0
145 jmp _rle_decompress_read_token
146
147 _rle_decompress_process_repeat_yield:
148 lda #1
149 rts
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.