;; This function will generate a lookup table of pixel masks.
;; This table can be used to plot masked sprites onto a mode 0 display.
;; 
;;
;; call init_mask_table to initialise.
;; 
;; 
;; NOTES:
;; - This code is for mode 0.
;; - The pen which will be plotted transparent is 0.
;; - Relocate mask_table to an address which is on a 256 byte boundary. (i.e. 
;; it's low byte is 0). This will allow you to access it much quicker.

.init_mask_table
ld hl,mask_table						;; base address of the mask table
ld b,0							;; counter
ld c,0							;; initial pixel value

.mmt1
ld d,0							;; initialise initial mask

ld a,c
and &aa							;; isolate bits used to define the pen for the left pixel.
jr z,mmt2

;; the pixel is transparent

;; update mask so that it will keep the left pixel from the 
;; screen's byte
ld a,d
or &aa
ld d,a

.mmt2
ld a,c
and &55							;; isolate bits used to define the pen for the left pixel.
jr z,mmt3

;; the pixel is transparent

;; update mask so that it will keep the right pixel from the 
;; screen's byte
ld a,d
or &55
ld d,a

.mmt3
ld a,d
cpl 
ld (hl),a						;; store final mask in table
inc hl							;; increment position in table
inc c							;; increment pixel value
djnz mmt1						;; loop
ret

.mask_table defs 256