;HL is now the pointer to the buffer
;
;PatternRAM is 24 bytes of RAM used to draw the patterns used
;BufferPointer is 2 bytes to store the pointer for the buffer
;Both are obviously short term storage and can be reused immediately
;
ld (BufferPointer),hl
push af
push bc
ld b,0
push bc
push de
push de
ld hl,PatternRAM
ld (hl),0
ld de,PatternRAM+1
ld bc,24
ldir
pop de
ld a,e
rrca
rrca
rrca
and 15
ld h,0
ld l,a
ld a,e
and 7
push af
ld b,a
ld a,255
jr z,$04
srl a
djnz $FC
ld de,PatternRAM
add hl,de
ld (hl),a
pop af
cpl
and 7
inc a
ld b,a
pop af
sub b
bit 7,a
jr z,$0F
and 7
or a
jr z,$06
ld b,a
xor a
scf
rra
djnz $FC
and (hl)
ld (hl),a
jr $15
inc hl
cp 8
jr c, $06
ld (hl),255
sub 8
jr $F5
or a
jr z,$06
ld b,a
xor a
scf
rra
djnz $FC
ld (hl),a
pop hl
add hl,hl
add hl,hl
ld b,h
ld c,l
add hl,hl
add hl,bc
ld bc,(BufferPointer)
or (hl)
add a,h
add hl,bc
push hl
push de
ld hl,PatternRAM-1
ld de,PatternRAM+11
inc de
inc hl
ld a,(hl)
or a
jr z,$FA
srl a
xor (hl)
ld (de),a
inc hl
ld a,(hl)
dec hl
or a
jr nz,$09
ld a,(hl)
srl a
add a,(hl)
cpl
and (hl)
ld (de),a
jr $11
inc de
inc hl
ld a,l
cp 248
jr z,$04
ld a,(hl)
or a
jr nz,$F5
dec de
dec hl
ld a,(hl)
add a,a
xor (hl)
ld (de),a
pop de
pop hl
pop bc
pop af
or a
jr nz,$11
ld c,12
ld de,PatternRAM
ld a,(de)
cpl
and (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
djnz $F0
ret
dec a
jr nz,$10
ld c,12
ld de,PatternRAM
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $F1
ret
dec a
jr nz,$10
ld c,12
ld de,PatternRAM
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $F1
ret
dec a
jr nz,$24
ld c,12
ld de,PatternRAM
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
dec b
ret z
dec b
jr z,$0F
ld c,12
ld de,PatternRAM+12
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $F1
inc b
jr $DC
dec a
jr nz,$26
ld c,12
ld de,PatternRAM
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
dec b
ret z
dec b
jr z,$10
ld c,12
ld de,PatternRAM+12
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
djnz $F0
inc b
jr $DA
dec a
jr nz,$24
ld c,12
ld de,PatternRAM
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
dec b
ret z
dec b
jr z,$0F
ld c,12
ld de,PatternRAM+12
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $F1
inc b
jr $DC
dec a
jr nz,$34
ld c,12
ld de,PatternRAM
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
dec b
ret z
dec b
jr z,$1F
push hl
ld c,12
ld de,PatternRAM
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
pop hl
ld c,12
ld de,PatternRAM+12
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $E1
inc b
jr $CC
dec a
jr nz,$33
ld c,12
ld de,PatternRAM
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
dec b
ret z
dec b
jr z,$1E
push hl
ld c,12
ld de,PatternRAM
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
pop hl
ld c,12
ld de,PatternRAM+12
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $E2
inc b
jr $CD
dec a
jr nz,$34
ld c,12
ld de,PatternRAM
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
dec b
ret z
dec b
jr z,$1E
push hl
ld c,12
ld de,PatternRAM
ld a,(de)
or (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
pop hl
ld c,12
ld de,PatternRAM+12
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
djnz $E2
inc b
jr $CC
dec a
jr nz,$35
ld c,12
ld de,PatternRAM
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
dec b
ret z
dec b
jr z,$1F
push hl
ld c,12
ld de,PatternRAM
ld a,(de)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F8
pop hl
ld c,12
ld de,PatternRAM+12
ld a,(de)
and (hl)
xor (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
djnz $E1
inc b
jr $CB
dec a
jr nz,$37
dec b
ret z
di
push hl
exx
ld bc,12
pop hl
add hl,bc
exx
ld c,12
ld de,PatternRAM
push de
exx
pop de
exx
ld a,(de)
cpl
and (hl)
exx
ld b,a
ld a,(de)
and (hl)
or b
inc de
inc hl
exx
ld (hl),a
inc de
inc hl
dec c
jr nz,$EF
djnz $E4
ld c,12
ld de,PatternRAM
ld a,(de)
cpl
and (hl)
ld (hl),a
inc de
inc hl
dec c
jr nz,$F7
ei
ret
dec a
jr nz,$40
di
push bc
ld de,12
add hl,de
djnz $FD
dec hl
push hl
exx
ld de,65524
pop hl
add hl,de
exx
pop bc
dec b
ret z
ld c,12
ld de,PatternRAM+11
push de
exx
pop de
exx
ld a,(de)
cpl
and (hl)
exx
ld b,a
ld a,(de)
and (hl)
or b
dec de
dec hl
exx
ld (hl),a
dec de
dec hl
dec c
jr nz,$EF
djnz $E4
ld c,12
ld de,PatternRAM+11
ld a,(de)
cpl
and (hl)
ld (hl),a
dec de
dec hl
dec c
jr nz,$F7
ei
ret
dec a
jr nz,$03
nop
nop
nop
nop
ret