org &4000

	;; Main Routine

	ld a,0
	call &bc0e		;; Set Screen Mode 0

	call setupcols		;; CALL to Setup Screen Inks
	call drawimg		;; Main Routine to Draw using SCR FILL BOX
	call resval		;; Reset values so program can execute again once Exit.
	call &bb18		;; KM WAIT KEY, Waits for any key to be pressed 
	ld a,2
	call &bc0e		;; Set Screen Mode 2
	ret			;; Program exits here

.setupcols
	ld hl,cols		;; Adress of Cols (Colours) points to HL Register
	ld a,0			;; Accumulator contains PEN Colour
.inkloop
	ld c,(hl)		;; Place INK value into C
	ld b,c			;; And B
	push af			;; Preserve Accumulator by PUSHing onto the Stack
	push hl			;; Preserve HL Reigister by PUSHing onto the Stack
	call &bc32		;; SCR SET INK, Entry: A = Ink no, B = First Colour, 
				;; C = Second Colour. Exit: AF & HL are corrupt. 
	pop hl			;; Restore previous HL Register by POPing off the stack
	pop af			;; Restore previous Accumulator value by POPing off the stack
	inc hl			;; hl = hl + 1
	inc a			;; a = a + 1
	cp 10			;; Does A = 10?
	jr c,inkloop		;; Loop back to inkloop if A <> 10
	ret			;; Return to Main routine

.drawimg
	ld hl,(bubptr)		;; Address of INK values goes into HL
	ld a,(hl)		;; Accumulator contains the contents that address points at,
				;; in this case the encoded INK value.

	push af			;; Those values are then PUSHed onto Stack to protect

	ld a,(column)		;; Contents of Column is loaded into Accumulator 
	ld h,a			;; and then put into H register
	ld d,a			;; and D register

	ld a,(row)		;; Contents of Row is loaded into Accumulator
	ld l,a			;; and then put into L register
	ld e,a			;; and E register

	pop af			;; Accumulator can now be restored to hold encoded INK value

	call &bc44		;; SCR FILL BOX Routine, Entry = all the above registers are
				;; used, H, D, L & E work using Text Based Co-ordinates & 
				;; accumulator uses Encoded INK to draw an 8 x 8 pixel shape.
 
	ld hl,(bubptr)		;;
	inc hl			;; Increase Address of pointer to INK values
	ld (bubptr),hl		;;
	
	ld a,(column)		;;
	inc a			;; Increase Address of Column
	ld (column),a		;;

	ld a,(fcount)		;; 
	inc a			;; Increment First Counter for X Co-ordinate Position
	ld (fcount),a		;;

	ld b,a			;; If the First Counter hasn't reached the value
	ld a,(xval)		;; in the X Co-ordinate Position (xval), then
	cp b			;; Return to the start (drawimg), otherwise continue
	jr nz,drawimg		;; to the second part adjust the Y Co-ordinate position. 

	ld a,(fcount)		;; 
	xor a			;; First Counter Position (fcount) must return to 0
	ld (fcount),a		;; 
	ld (column),a		;; Column can also return to 0

	ld a,(row)		;;
	inc a			;; Increment the Top Row Position
	ld (row),a		;;

	ld a,(scount)		;;
	inc a			;; Increment Second Counter for Y Co-ordinate Position
	ld (scount),a		;;

	ld b,a			;; If the Second Counter hasn't reached the value
	ld a,(yval)		;; in the Y Co-ordinate Position (yval), then
	cp b			;; Return to the start (drawimg), otherwise proceed
	jr nz,drawimg		;; to the end of this cycle.
	
	ret			;; Return to Main Routine

.resval
	xor a			;; Fancy way of Returning Accumulator to 0. 
	ld (fcount),a		;;
	ld (scount),a		;;
	ld (column),a		;; Return all these Variables back to 0
	ld (row),a		;; 
	ld hl,bub		;; Restore original address to the inks
	ld (bubptr),hl		;; by returning the address of the inks to the Pointer
	ret			;; Return to Main Routine

.cols	defb 0,26,0,0,3,0,1,2,4,16	;; Setup INKs using these colours

.fcount	defb 0			;; Value of First Counter (used during the X Co-ordinate Position)
.scount defb 0			;; Value of Second Counter (used during the Y Co-ordinate Position)

.column defb 0			;; Position of Column

.row defb 0			;; Position of Row


.yval   defb 22			;; Image to be draw is 22 columns in height
.xval   defb 11			;; By 11 Rows Across as defined in 'bub'

.bubptr defw bub

.bub				;; Dimension 11 x 22 in size
	defb &00,&30,&30,&30,&30,&30,&30,&00,&00,&00,&00
	defb &00,&30,&30,&30,&30,&30,&30,&30,&30,&30,&00
	defb &00,&30,&30,&30,&30,&30,&30,&c3,&30,&30,&00
	defb &00,&30,&30,&30,&30,&30,&30,&c3,&30,&30,&00
	defb &30,&30,&30,&30,&30,&30,&c3,&c3,&c3,&30,&30
	defb &30,&30,&30,&30,&c0,&00,&c3,&00,&c0,&30,&30
	defb &30,&c3,&30,&c3,&c0,&00,&c3,&00,&c0,&30,&30
	defb &00,&c3,&30,&c3,&c0,&00,&c3,&00,&c0,&30,&30
	defb &00,&c3,&c3,&c3,&c0,&00,&c3,&00,&c0,&30,&00
	defb &00,&30,&c3,&c3,&c0,&c0,&c3,&c0,&c3,&c3,&00
	defb &00,&30,&c3,&c3,&c3,&c0,&c3,&c0,&c3,&c3,&00
	defb &00,&30,&c3,&c3,&c3,&c3,&c3,&c3,&c3,&c3,&00
	defb &00,&fc,&30,&c3,&c3,&c3,&00,&c3,&c3,&c3,&00
	defb &fc,&fc,&fc,&c3,&c3,&c3,&c3,&c3,&c3,&03,&00
	defb &fc,&fc,&fc,&03,&fc,&fc,&fc,&03,&fc,&03,&00	
	defb &fc,&fc,&c3,&03,&fc,&fc,&fc,&03,&c3,&c3,&00
	defb &fc,&c3,&c3,&c3,&03,&03,&03,&03,&c3,&c3,&00
	defb &00,&c3,&c3,&03,&3c,&c0,&3c,&c0,&03,&c3,&00
	defb &00,&03,&03,&03,&03,&3c,&3c,&3c,&3c,&03,&00
	defb &00,&03,&03,&03,&03,&03,&03,&03,&03,&03,&03
	defb &00,&30,&3c,&3c,&3c,&00,&3c,&3c,&3c,&3c,&30
	defb &00,&30,&30,&30,&30,&00,&30,&30,&30,&30,&30

;; Masks to be used in PENs

;; pen 0 = &00
;; pen 1 = &c0
;; pen 4 = &30
;; pen 6 = &3c
;; pen 7 = &FC
;; pen 8 = &03
;; pen 9 = &c3