;; Plot Image. Courtesy of CPM User.

	org &4000

	ld a,1					
	call &bc0e				;; Set Screen Mode 1
	
	ld hl,data_colour			;; Address of Data Colour
	ld (addrcolour),hl			;; Place this into Address Colour
.loop	
	ld hl,(addrcolour)			;; Place Contents of Address Colour into HL
	ld a,(hl)				;; Put Contents of HL into A
	call do_colour	

	ld de,(xpos)				;; XPOS data into DE
	ld hl,(ypos)				;; YPOS data into HL
	call &bbea				;; GRA ABSOLUTE PLOT

	ld hl,(xpos)				;; Obtain Contents of XPOS
	inc hl					;; Is 16bit Value so Increment  
	inc hl					;; Twice
	ld (xpos),hl				;; Place next value into XPOS
	
	ld a,(fcount)				;; First Counter Position into A
	inc a					;; Increment this		
	ld (fcount),a				;; Put New Value into First Count Position
	ld b,a					;; Put this value into B

	ld a,(xlcount)				;; Place First Counter Marker into A

	cp b					;; Has value of B reached A value
	jr nz,loop				;; If No Loop back, otherwise continue

	ld a,(fcount)				;; At this stage fcount equals 8
	xor a					;; This will make it 0 again
	ld (fcount),a				;; And put that value into fcount

	ld hl,(ypos)				;; YPOS of data can now be Incremented
	inc hl					;; Again 16bit Value means Incrementing
	inc hl					;; it Twice
	ld (ypos),hl				;; And put that value into YPOS.

	ld a,(xpos)				;; Value of XPOS needs to return back to where it was.
	sub 16					;; Subtracting 16 will resolve this.
	ld (xpos),a				;; New Value goes into XPOS.
	
	ld a,(scount)				;; Second counter goes into A
	inc a					;; Increase it.
	ld (scount),a				;; Place back into Second Counter
	ld b,a					;; Put value of Second counter into B

	ld a,(ylcount)				;; Place Y-counting position into A

	cp b					;; Compare A to value of B
	jr nz,loop				;; If reached exit, otherwise return
	
	ld a,0					;; \
	ld hl,fcount				;; \\
	ld (hl),a				;; Returns loop values back to 0 
	ld hl,scount				;; //
	ld (hl),a				;; /
	
	ld hl,100				;; Return the value of ypos
	ld (ypos),hl				;; back to it's original place.

	ret					;; Program exits here.

.do_colour
  	call &bbde				;; GRA SET PEN - A = Pen Colour
  	ld hl,(addrcolour)			;; Take address of address colour
  	inc hl					;; Increment it by 1
  	ld (addrcolour),hl			;; Put this value into Address Colour
  	ret					;; Return to Main Loop Routine.
	
.fcount defb 0
.scount defb 0
.xlcount	
	defb 8					;; Number of times to loop across.
.ylcount
	defb 8					;; Number of times to loop down
.xpos	defw 100				;; Left Position the image
.ypos	defw 100				;; Bottom Position of the image.
.data_colour
 	defb 1,1,0,1,0,1,1,0
 	defb 0,3,3,3,3,3,0,0
 	defb 0,0,2,2,2,0,0,0
 	defb 0,0,2,2,2,0,0,0
 	defb 0,0,2,2,2,0,0,0
 	defb 0,0,2,2,2,0,0,0
 	defb 0,0,2,2,2,0,0,0
 	defb 0,0,0,1,0,0,0,0

.addrcolour
 	defw 0					;; This points to the address position
						;; within the data colour.