gb_decompress.s (1954B)
1; GB-Deompress routine 2; Compatible with GBTD 3 4 .include "global.s" 5 6 .title "GB Decompress" 7 .module GBDecompress 8 9 .area _CODE 10 11; hl = source; de = dest 12_gb_decompress:: 13 pop hl 14 pop de 15 ex (sp), hl 16 ex de, hl 17 push bc 18 push de 191$: 20 ld a, (hl) ; load command 21 inc hl 22 or a 23 jr z, 9$ ; exit, if last byte 24 bit 7, a 25 jr nz, 5$ ; string functions 26 bit 6, a 27 jr nz, 3$ 28 ; RLE byte 29 and #63 ; calc counter 30 inc a 31 ld b, a 32 ld a, (hl) 33 inc hl 342$: 35 ld (de), a 36 inc de 37 dec b 38 jr nz, 2$ 39 jr 1$ ; next command 403$: ; RLE word 41 and #63 42 inc a 43 ld c, (hl) ; load word into bc 44 inc hl 45 ld b, (hl) 46 inc hl 47 ex de, hl 484$: 49 ld (hl), c 50 inc hl 51 ld (hl), b 52 inc hl 53 dec a 54 jr nz, 4$ 55 ex de, hl 56 jr 1$ ; next command 575$: 58 bit 6, a 59 jr nz, 7$ 60 ; string repeat 61 and #63 62 inc a 63 push hl 64 ld c, (hl) 65 inc hl 66 ld b, (hl) 67 ld h, d 68 ld l, e 69 add hl, bc 70 ld c, a 71 ld b, #0 72 ldir 73 pop hl 74 inc hl 75 inc hl 76 jr 1$ ; next command 777$: ; string copy 78 and #63 79 inc a 80 ld c, a 81 ld b, #0 82 ldir 83 jr 1$ ; next command 849$: 85 pop hl 86 ex de, hl 87 or a ; clear carry flag 88 sbc hl, de 89 pop bc 90 ret