;
; patterndisplay.inc: lights up the 16x12 pattern display
;  leds
;
; TODO: FINISH THIS
;
; column (== led_counter) is preselected with rd0 - rd3.
; row (== led_scaler) should be selected with rd4 - rd7.
;
; column has values between 0 - 15.
; row has values between 0 - 11.
;
; counters are updated in keysleds.inc and should not
;  be altered here!
;
; author: Marko Kanala, raato ]a t[ mulletronic.com
;
; LICENSE
; Creative Commons Attribution-NonCommercial-ShareALike 2.5
;
; You are free:
;
; * to copy, distribute, display, and perform the work
; * to make derivative works
;
; Under the following conditions:
;	
; 1. Attribution. You must attribute the work in the manner specified by the 
;    author or licensor.
; 2. Noncommercial. You may not use this work for commercial purposes.
; 3. Share Alike. If you alter, transform, or build upon this work, you may 
;    distribute the resulting work only under a license identical to this one.
;
; * For any reuse or distribution, you must make clear to others the license 
;   terms of this work.
; * Any of these conditions can be waived if you get permission from the 
;   copyright holder.
;
; Your fair use and other rights are in no way affected by the above.
;
; This is a human-readable summary of the Legal Code.
; See full license at http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode
;
; Copyright: Marko Kanala (raato@mulletronic.com).
;

do_patterndisplay:
	IFNOTINMODE	MODE_FILL, do_patterndisplay_notfill
	lfsr	FSR0, fillpattern + PAT_TRIGS + 1
	bra		do_patterndisplay_cont
do_patterndisplay_notfill:
	lfsr	FSR0, pattern + PAT_TRIGS + 1
do_patterndisplay_cont:
	movf	led_scaler, W
	addwf	FSR0L
	addwf	FSR0L
	; FSR0 points to the correct trigger row

	movlw	-8
	addwf	led_counter, W			; W = led_counter - 8
	bnn		pd_go

	; column 7 or lesser, select the second byte of row
	addlw	8						; W = led_counter
	decf	FSR0L

pd_go:
	; now FSR0 points to correct byte in pattern data
	;  and WREG is the bit to be checked
	call	get_bit
	andwf	INDF0, W
	bnz		pd_lit
	
	; retain lower 4 bits of led mux and 
	;  select the correct row from 154 mux
	swapf	led_scaler, W
	iorwf	led_counter, W
	; disable mux to shut off the led
	bsf		PORT_LEDBUS, PAT_DISP_LIT_PIN
	movwf	LAT_LEDMUX
	return

pd_lit:	

	; retain lower 4 bits of led mux and 
	;  select the correct row from 154 mux
	swapf	led_scaler, W
	iorwf	led_counter, W
	; enable mux to light up the led
	bcf		PORT_LEDBUS, PAT_DISP_LIT_PIN
	movwf	LAT_LEDMUX
	return

External Labels :

get_bit