changeset 142:8b75ba28d641

Screen-flipping custom function. - Fix bank safe addressings.
author JeanDo
date Fri, 07 Jan 2011 03:01:02 +0100
parents 622da16b768f
children e82e0df6d0ea
files code_part1/OSTC_code_asm_part1/aa_wordprocessor.asm code_part1/OSTC_code_asm_part1/color_processor.asm code_part1/OSTC_code_asm_part1/definitions.asm code_part1/OSTC_code_asm_part1/menu_logbook.asm code_part1/OSTC_code_asm_part1/oled_samsung.asm code_part1/OSTC_code_asm_part1/pled_outputs.asm code_part1/OSTC_code_asm_part1/start.asm
diffstat 7 files changed, 247 insertions(+), 194 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/aa_wordprocessor.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/aa_wordprocessor.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -59,7 +59,7 @@
         	aa_bitlen					; Count of pixels when decoding bitmaps.
         	aa_start:2					; PROM ptr to start of encoded bitmap
         	aa_end:2					; and end of it.
-        	aa_colorDiv:2				; Current color, divided by 2 or 4
+        	aa_temp:2				; Current color, divided by 2 or 4
     ENDC
 
 ; Flags allocation:
@@ -254,82 +254,6 @@
 		return
 
 ;------------------------------------------------------------------------------
-; Fast macros to write to OLED display.
-; Adding a call/return adds 3 words and a pipeline flush, hence make it
-; nearly twice slower...
-;
-; Input	 : commande as macro parameter.
-; Output : NONE
-; Trash  : WREG
-;
-AA_CMD_WRITE macro cmd
-		movlw	cmd
-		rcall   PLED_CmdWrite
-;		bcf		oled_rs				    ; Cmd mode
-;		movwf	PORTD,A
-;		bcf		oled_rw				    ; Tick the clock
-;		bsf		oled_rw
-		endm
-;
-; Input	 : PRODH:L as 16bits data.
-; Output : NONE
-; Trash  : NONE
-;
-AA_DATA_WRITE_PROD	macro
-        rcall   PLED_DataWrite_PROD
-;		bsf		oled_rs				    ; Data mode
-;		movff	PRODH,PORTD			    ; NOTE: OLED is BIGENDIAN!
-;		bcf		oled_rw				    ; Tick the clock
-;		bsf		oled_rw
-;		movff	PRODL,PORTD
-;		bcf		oled_rw				    ; Tick the clock
-;		bsf		oled_rw
-		endm
-
-;------------------------------------------------------------------------------
-; Output OLED Window Address commands.
-; Inputs : win_top, win_leftx2, win_height, aa_width.
-; Output : PortD commands.
-; Trashed: PROD
-;
-aa_box_cmd:
-		movf	win_leftx2,W,BANKED	    ; Compute left = 2*leftx2
-		mullw	2
-		AA_CMD_WRITE	0x35		    ; this is the left border
-		AA_DATA_WRITE_PROD
-
-		movf	aa_width+0,W,ACCESS	    ; right = left + width - 1
-		addwf	PRODL,F,A
-		movf	aa_width+1,W,ACCESS
-		addwfc	PRODH,F,A
-		decf	PRODL,F,A			    ; decrement result
-		bc		aa_box_cmd_1		    ; No borrow (/Carry) ? skip propagating.
-		decf	PRODH,F,A
-aa_box_cmd_1:			
-		AA_CMD_WRITE	0x36		    ; Write and the right border
-		AA_DATA_WRITE_PROD
-
-		movf	win_top,W,BANKED	    ; Write top / bottom window
-		movwf	PRODH,A				    ; (remember PRODH output first)
-		addwf	win_height,W,BANKED
-		decf	WREG,A
-		movwf	PRODL,A				    ; And PRODL is later...
-		AA_CMD_WRITE	0x37
-		AA_DATA_WRITE_PROD
-
-		movf	win_top,W,BANKED	    ; Start ptr top
-		mullw	1					    ; Load into PRODH:L
-		AA_CMD_WRITE	0x20
-		AA_DATA_WRITE_PROD
-
-		movf	win_leftx2,W,BANKED	    ; Start ptr left
-		mullw	2
-		AA_CMD_WRITE	0x21
-		AA_DATA_WRITE_PROD
-
-		return
-
-;------------------------------------------------------------------------------
 ; Decode a compressed char.
 ; Inputs	aa_start, aa_end, win_height, win_invert, win_color1, win_color2
 ; Output	none
@@ -396,34 +320,34 @@
 		clrf	PRODL				    ; We will accumulate result here...
 		clrf	PRODH
 
-		; Take color div 2 into aa_colorDiv. Max red = 15/31
+		; Take color div 2 into aa_temp. Max red = 15/31
 		rrcf	win_color1,W,BANKED	    ; xRRRRxGG
 		andlw	b'01111011'			    ; 0RRRR0GG (don't change C)
-		movwf	aa_colorDiv+0,ACCESS
+		movwf	aa_temp+0,ACCESS
 		rrcf	win_color2,W,BANKED	    ; GGGxBBBB
 		andlw	b'11101111'			    ; GGG0BBBB
-		movwf	aa_colorDiv+1,ACCESS
+		movwf	aa_temp+1,ACCESS
 
 		btfss	aa_color_half,ACCESS
 		bra		aa_decode_12
 
-		movff	aa_colorDiv+0,PRODH	    ; Add color/2 if bit set.
-		movff	aa_colorDiv+1,PRODL	    ; OLED is big endian, so swap here.
+		movff	aa_temp+0,PRODH         ; Add color/2 if bit set.
+		movff	aa_temp+1,PRODL         ; OLED is big endian, so swap here.
 aa_decode_12:
 		btfss	aa_color_quart,ACCESS
 		bra		aa_decode_3
 
 		; Divide it once again by 2. Max red = 7/31.
-		rrcf	aa_colorDiv+0,W,ACCESS  ; xxRRRxxG
-		andlw	b'00111001'			    ; 00RRR00G (don't change C)
-		movwf	aa_colorDiv+0,ACCESS
-		rrcf	aa_colorDiv+1,W,ACCESS  ; GGGxxBBB
-		andlw	b'11100111'			    ; GGG00BBB
-		movwf	aa_colorDiv+1,ACCESS
+		rrcf	aa_temp+0,W,ACCESS      ; xxRRRxxG
+		andlw	b'00111001'             ; 00RRR00G (don't change C)
+		movwf	aa_temp+0,ACCESS
+		rrcf	aa_temp+1,W,ACCESS      ; GGGxxBBB
+		andlw	b'11100111'             ; GGG00BBB
+		movwf	aa_temp+1,ACCESS
 
-		movf	aa_colorDiv+1,W,ACCESS  ; Add color/4
+		movf	aa_temp+1,W,ACCESS      ; Add color/4
 		addwf	PRODL,F				    ; NOTE: 7/31+15/31=22/31,
-		movf	aa_colorDiv+0,W,ACCESS  ; hence composants won't overlap.
+		movf	aa_temp+0,W,ACCESS      ; hence composants won't overlap.
 		addwfc	PRODH,F				    ; In right order, to propagate carry.
 
 		bra		aa_decode_3			    ; Done.
@@ -470,7 +394,7 @@
 		movlb	HIGH win_top            ; Switch to bank 0...
 
 		rcall	aa_string_width		    ; Set win_height, compute win_width
-		rcall	aa_box_cmd			    ; Use that for the box.
+		rcall	PLED_box_write		    ; Use that for the box.
 
 		; Restart the loop for each char to print
 		lfsr	FSR2, letter		    ; FSR2 pointer to start of string.
--- a/code_part1/OSTC_code_asm_part1/color_processor.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/color_processor.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -53,7 +53,7 @@
 ;Temporary overlay (in bank 0), ACCESS area
     CBLOCK  0x000
         img_colors
-        img_width:2                     ; SHOULD be @1, because of aa_box_cmd
+        img_width:2                     ; SHOULD be @1, because of PLED_box_write
         img_pixelsL
         img_pixelsH
         img_pixelsU
@@ -64,7 +64,7 @@
 
 ;-----------------------------------------------------------------------------
 color_image:
-        movlb   HIGH(img_width)         ; Switch to bank 0.
+        movlb   HIGH(win_height)        ; Switch to bank 0.
 
         ;---- Get image parameters -------------------------------------------
         tblrd*+                     
@@ -100,7 +100,7 @@
         clrf    img_width+1             ; x2 on width, for the true box size.
         rlcf    img_width+0
         rlcf    img_width+1
-        call    aa_box_cmd
+        call    PLED_box_write
         AA_CMD_WRITE 0x22
 
         ;---- Decode pixels --------------------------------------------------
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -54,7 +54,6 @@
 #DEFINE warn_ceiling	d'6'
 #DEFINE	warn_gas_in_gaslist	d'7'
 
-
 ;Configuration bits
 	CONFIG	OSC = IRCIO67        ;Internal oscillator block, port function on RA6 and RA7
 	CONFIG	FCMEN = OFF          ;Fail-Safe Clock Monitor disabled
@@ -75,6 +74,8 @@
 	CONFIG	LVP = OFF            ;Single-Supply ICSP disabled
 	CONFIG	STVREN = OFF         ;Stack full/underflow will not cause Reset
 
+;=============================================================================
+
     CBLOCK  0x800
         c_code_data_stack:.64       ; Reserve space for C-code data space. Eg.when calling log.
     endc
@@ -94,12 +95,13 @@
 	letter:.026					;letter buffer
 	win_color1
 	win_color2
-	win_top
-	win_height					; String (and font) height
-	win_leftx2
-	win_width 					; String width (more than 255 for aa_wordprocessor !)
+	win_top                     ; Box/text position (0..239).
+	win_height					; Box/text height (1..240)
+	win_leftx2                  ; Box/text position (0..159)
+	win_width 					; box width (1..160)
 	win_font
 	win_invert
+	win_flags                   ; flip_screen flag, transparent fonts, etc...
 	ENDC
 
 	CBLOCK	0x100				;Bank 1
@@ -290,7 +292,6 @@
 ;	sleeptime_since_last_charge:2; Sleeptime in hours since last complete charge
 
 	debug_char:6				; For debugmode
-	debug_temp					; For debugmode
 	
 	apnoe_mins					; single descent minutes for Apnoe mode
 	apnoe_secs					; single descent seconds for Apnoe mode
@@ -478,6 +479,9 @@
 #DEFINE	oled_nreset			PORTE,1 ;0
 #DEFINE	oled_e_nwr			PORTE,2 ;0
 
+; Bank0 flags
+#DEFINE win_flip_screen     win_flags,0 ; 180° rotation of the OLED screen.
+
 ; Flags
 #DEFINE	FLAG_scale			flag1,0	; Wordprocessor
 #DEFINE	FLAG_truncated		flag1,1	; Wordprocessor
--- a/code_part1/OSTC_code_asm_part1/menu_logbook.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/menu_logbook.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -520,10 +520,11 @@
 
 	call		profile_display_fill		; In this column between this row (xC+0) and the last row (apnoe_mins)
 	movff		xC+0,apnoe_mins				; Store last row for fill routine
+	incf		timeout_counter3,F
+
 	movf		xC+0,W
 	call		PLED_SetRow					; 0...259
 
-	incf		timeout_counter3,F
 	movf		timeout_counter3,W
 	call		PLED_SetColumnPixel			; pixel x2
 	call		PLED_standard_color
@@ -593,12 +594,13 @@
 	movff		apnoe_mins,xC+1		; Copy
 profile_display_fill_down2:			; Loop	
 	decf		xC+1,F
+
 	movf		xC+1,W				; Row
 	call		PLED_SetRow			; 0...259
 
 	call		PLED_standard_color
+	call		PLED_PxlWrite_Single; Write one Pixel
 
-	call		PLED_PxlWrite_Single; Write one Pixel
 	movf		xC+0,W
 	cpfseq		xC+1				; Loop until xC+1=xC+0
 	bra			profile_display_fill_down2
@@ -608,12 +610,13 @@
 	movff		xC+0,xC+1			; Copy
 profile_display_fill_up2:			; Loop	
 	decf		xC+1,F
+
 	movf		xC+1,W				; Row
 	call		PLED_SetRow			; 0...259
 
-	call	PLED_standard_color
+	call	    PLED_standard_color
+	call		PLED_PxlWrite_Single; Write one Pixel
 
-	call		PLED_PxlWrite_Single; Write one Pixel
 	movf		apnoe_mins,W
 	cpfseq		xC+1				; Loop until xC+1=apnoe_mins
 	bra			profile_display_fill_up2
--- a/code_part1/OSTC_code_asm_part1/oled_samsung.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/oled_samsung.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -18,9 +18,11 @@
 ; hardware routines for S6E6D6 Samsung OLED Driver IC
 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
 ; written: 090801
-; last updated: 090830
-; known bugs:
-; ToDo: Optimise PLED_box calls
+; History:
+; 2009-08-30: [MH] last updated.
+; 2011-01-07: [jDG] Added flip_screen option
+; known bugs: pixel-write (loogbok curves) not done yet...
+; ToDo:
 
 WIN_FONT 	macro	win_font_input
 			movlw	win_font_input
@@ -46,29 +48,31 @@
 			movlw	win_color_input
 			call	PLED_set_color
 			endm
-	
+
+;=============================================================================
+
 word_processor:						; word_processor:
-	clrf	POSTINC2				; Required, to mark end of string.
-	call	aa_wordprocessor
-	movlb	b'00000001'				; Back to Rambank1
-	return
+    clrf	POSTINC2				; Required, to mark end of string.
+    call	aa_wordprocessor
+    movlb	b'00000001'				; Back to Rambank1
+    return
 
-; -----------------------------
+;=============================================================================
 ; PLED_SetColumnPixel:
-; -----------------------------
+;
 PLED_SetColumnPixel:
-	movff	WREG,win_leftx2		 ; d'0' ... d'159'
-	mullw   2                   ; Copy to PROD, times 2.
+	movff	WREG,win_leftx2             ; d'0' ... d'159'
+	mullw   2                           ; Copy to PROD, times 2.
 
-	movlw	0x21				; Start Address Vertical (.0 - .319)
+	movlw	0x21				        ; Start Address Vertical (.0 - .319)
 	rcall	PLED_CmdWrite
 	bra     PLED_DataWrite_PROD
 
-; -----------------------------
+;=============================================================================
 ; PLED_SetRow:
 ; Backup WREG --> win_top, for the next write pixel.
 ; Setup OLED pixel horizontal address.
-; -----------------------------
+;
 PLED_SetRow:		
 	movff  	WREG,win_top                ; d'0' ... d'239'
 	mullw   1                           ; Copy row to PRODH:L
@@ -76,9 +80,9 @@
 	rcall	PLED_CmdWrite
 	bra     PLED_DataWrite_PROD		
 
-; -----------------------------
+;=============================================================================
 ; PLED Write Two Pixel
-; -----------------------------
+;
 
 PLED_PxlWrite:
     rcall   PLED_PxlWrite_Single        ; Write first pixel.
@@ -125,28 +129,168 @@
 	return
 
 ;=============================================================================
+; Fast macros to write to OLED display.
+; Adding a call/return adds 3 words and a pipeline flush, hence make it
+; nearly twice slower...
+;
+; Input	 : commande as macro parameter.
+; Output : NONE
+; Trash  : WREG
+;
+AA_CMD_WRITE macro cmd
+		movlw	cmd
+		rcall   PLED_CmdWrite
+;		bcf		oled_rs				    ; Cmd mode
+;		movwf	PORTD,A
+;		bcf		oled_rw				    ; Tick the clock
+;		bsf		oled_rw
+		endm
+;
+; Input	 : PRODH:L as 16bits data.
+; Output : NONE
+; Trash  : NONE
+;
+AA_DATA_WRITE_PROD	macro
+        rcall   PLED_DataWrite_PROD
+;		bsf		oled_rs				    ; Data mode
+;		movff	PRODH,PORTD			    ; NOTE: OLED is BIGENDIAN!
+;		bcf		oled_rw				    ; Tick the clock
+;		bsf		oled_rw
+;		movff	PRODL,PORTD
+;		bcf		oled_rw				    ; Tick the clock
+;		bsf		oled_rw
+		endm
+
+;=============================================================================
+; Output OLED Window Address commands.
+; Inputs : win_top, win_leftx2, win_height, aa_width.
+; Output : PortD commands.
+; Trashed: PROD
+;
+PLED_box_write:
+		movff	win_leftx2,WREG         ; Compute left = 2*leftx2 --> PROD
+		mullw	2
+
+        movff   win_flags,WREG          ; BEWARE: bank0 bit-test
+    	btfsc   WREG,0                  ; 180° rotation ?
+    	bra     PLED_box_flip_H         ; YES: 
+
+        ;---- Normal horizontal window ---------------------------------------
+        ; Output 0x35 left,
+        ;        0x36 right ==  left + width - 1.
+		AA_CMD_WRITE	0x35		    ; this is the left border
+		AA_DATA_WRITE_PROD              ; Output left
+		AA_CMD_WRITE	0x21            ; Also the horizontal first pix coord.
+		AA_DATA_WRITE_PROD
+		
+		movf	aa_width+0,W,ACCESS	    ; right = left + width - 1
+		addwf	PRODL,F
+		movf	aa_width+1,W,ACCESS
+		addwfc	PRODH,F
+		decf	PRODL,F,A			    ; decrement result
+		btfss   STATUS,C
+		decf	PRODH,F,A
+
+		AA_CMD_WRITE	0x36		    ; Write and the right border
+		AA_DATA_WRITE_PROD
+
+		bra     PLED_box_noflip_H
+
+        ;---- Flipped horizontal window --------------------------------------
+PLED_box_flip_H:
+        ; Output 0x36 flipped(left)  = 319-left
+        ;        0x35 flipped(right) = 319-right = 320 - left - width
+        movf    PRODL,W                 ; 16bits 319 - PROD --> PROD
+        sublw   LOW(.319)               ; 319-W --> W
+        movwf   PRODL
+        movf    PRODH,W
+        btfss   STATUS,C                ; Borrow = /CARRY
+        incf    WREG
+        sublw   HIGH(.319)
+        movwf   PRODH
+		AA_CMD_WRITE	0x36		    ; this is the left border
+		AA_DATA_WRITE_PROD              ; Output left
+		AA_CMD_WRITE	0x21
+		AA_DATA_WRITE_PROD
+
+        movf    aa_width+0,W            ; 16bits PROD - width --> PROD
+        subwf   PRODL,F                 ; PRODL - WREG --> PRODL
+        movf    aa_width+1,W
+        subwfb  PRODH,F
+        infsnz  PRODL                   ; PROD+1 --> PROD
+        incf    PRODH
+		AA_CMD_WRITE	0x35		    ; this is the left border
+		AA_DATA_WRITE_PROD              ; Output left
+
+PLED_box_noflip_H:
+        movff   win_flags,WREG          ; BEWARE: bank0 bit-test
+    	btfsc   WREG,0                  ; 180° rotation ?
+    	bra     PLED_box_flip_V
+
+        ;---- Normal vertical window -----------------------------------------
+        ; Output 0x37 (top) (bottom)
+		movff	win_top,PRODH           ; top --> PRODH (first byte)
+		movff   win_height,WREG
+		addwf   PRODH,W
+		decf	WREG
+		movwf	PRODL                   ; top+height-1 --> PRODL (second byte)
+
+		AA_CMD_WRITE	0x37
+		AA_DATA_WRITE_PROD
+
+        movff   PRODH,PRODL
+        clrf    PRODH                   ; Start pixel V coord == top.
+		AA_CMD_WRITE	0x20
+		AA_DATA_WRITE_PROD
+
+		return
+
+        ;---- Flipped vertical window ----------------------------------------
+        ; Output 0x37 flipped(bottom) = 239-bottom = 240 - top - height
+        ;             flipped(top)    = 239-top
+PLED_box_flip_V:
+		movff   win_top,PRODL
+		movff   win_height,WREG
+		addwf   PRODL,W
+		sublw   .240                    ; 240 - top - height
+		movwf   PRODH                   ; First byte
+
+		movf	PRODL,W
+		sublw   .239                    ; 249-top
+		movwf   PRODL                   ; --> second byte.
+
+		AA_CMD_WRITE	0x37
+		AA_DATA_WRITE_PROD
+
+        clrf    PRODH                   ; Start pixel V coord.
+		AA_CMD_WRITE	0x20
+		AA_DATA_WRITE_PROD
+
+		return
+
+;=============================================================================
 ; PLED_frame : draw a frame around current box with current color.
 ; Inputs:  win_top, win_leftx2, win_height, win_width, win_color1, win_color2
 ; Outputs: (none)
 ; Trashed: WREG, PROD, aa_start:2, aa_end:2, win_leftx2, win_width:1
 
-PLED_frame: 
-    movff   win_top,aa_start+0              ; Backup everything.
+PLED_frame:
+    movff   win_top,aa_start+0          ; Backup everything.
     movff   win_height,aa_start+1
     movff   win_leftx2,aa_end+0
     movff   win_width,aa_end+1
 
     ;---- TOP line -----------------------------------------------------------
-    movlw   1                               ; row ~ height=1
+    movlw   1                           ; row ~ height=1
     movff   WREG,win_height
     rcall   PLED_box
 
     ;---- BOTTOM line --------------------------------------------------------
-    movff   aa_start+0,PRODL                ; Get back top,
-    movff   aa_start+1,WREG                 ; and height
-    addwf   PRODL,W                         ; top+height
-    decf    WREG                            ; top+height-1
-    movff   WREG,win_top                    ; top+height-1 --> top
+    movff   aa_start+0,PRODL             ; Get back top,
+    movff   aa_start+1,WREG              ; and height
+    addwf   PRODL,W                      ; top+height
+    decf    WREG                         ; top+height-1
+    movff   WREG,win_top                 ; top+height-1 --> top
     rcall   PLED_box                        
 
     ;---- LEFT column --------------------------------------------------------
@@ -172,74 +316,46 @@
 
 PLED_box:
     ;---- Define Window ------------------------------------------------------
-	movlw	0x35				; VerticalStartAddress HIGH:LOW
-	rcall	PLED_CmdWrite
-	movff	win_leftx2,WREG
-	mullw   2
-	rcall	PLED_DataWrite_PROD
-
-	movlw	0x36				; VerticalEndAddress HIGH:LOW
-	rcall	PLED_CmdWrite
-	movff   win_width,PRODL     ; Bank-safe addressing
-	movff	win_leftx2,WREG
-	addwf   PRODL,W             ; left+width
-	decf    WREG                ; left+width-1
-	mullw   2                   ; times 2 --> rightx2
-	rcall	PLED_DataWrite_PROD
-
-	movlw	0x37				; HorizontalAddress START:END
-	rcall	PLED_CmdWrite
-	movff	win_top,PRODH       ; Start row.
-	movff   win_height,PRODL    ; height
-    movf    PRODH,W
-    addwf   PRODL,F             ; top + height
-    decf    PRODL,F             ; top + height - 1 --> bottom.
-	rcall	PLED_DataWrite_PROD
-
-    ;---- Start pointer ------------------------------------------------------
-	movlw	0x20				; Start Address Horizontal (.0 - .239)
-	rcall	PLED_CmdWrite
-	movff	win_top,WREG
-	mullw   1
-	rcall	PLED_DataWrite_PROD
-
-	movlw	0x21				; Start Address Vertical (.0 - .319)
-	rcall	PLED_CmdWrite
-	movff	win_leftx2,WREG
-	mullw   2
-	rcall	PLED_DataWrite_PROD
+	movff	win_width,WREG
+	bcf     STATUS,C
+	rlcf    WREG
+	movwf   aa_width
+	movlw   0
+	rlcf    WREG
+	movwf   aa_width+1
+	rcall   PLED_box_write
 
     ;---- Fill Window --------------------------------------------------------
-	movlw	0x22					; Start Writing Data to GRAM
+	movlw	0x22					        ; Start Writing Data to GRAM
 	rcall	PLED_CmdWrite
 
-	movff	win_height,PRODH
-	bsf		oled_rs					; Data!
+	movff	win_width,PRODH
+	bsf		oled_rs					        ; Data!
 
-PLED_box2:                          ; Loop height times
-	movff	win_width,PRODL
-PLED_box3:                          ; loop width times
+PLED_box2:                                  ; Loop height times
+	movff	win_height,PRODL
+PLED_box3:                                  ; loop width times
 	movff	win_color1,PORTD
 	bcf		oled_rw
-	bsf		oled_rw					; Upper
+	bsf		oled_rw					        ; Upper
 	movff	win_color2,PORTD
 	bcf		oled_rw
-	bsf		oled_rw					; Lower
+	bsf		oled_rw					        ; Lower
 
 	movff	win_color1,PORTD
 	bcf		oled_rw
-	bsf		oled_rw					; Upper
+	bsf		oled_rw					        ; Upper
 	movff	win_color2,PORTD
 	bcf		oled_rw
-	bsf		oled_rw					; Lower
+	bsf		oled_rw					        ; Lower
 
 	decfsz	PRODL,F
 	bra		PLED_box3
 	decfsz	PRODH,F
 	bra		PLED_box2
 
-	movlw	0x00					; NOP, to stop Address Update Counter
-	bra     PLED_CmdWrite			; Returns...
+	movlw	0x00					        ; NOP, to stop Address Update Counter
+	bra     PLED_CmdWrite                   ; returns...
 
 ;=============================================================================
 ; PLED_ClearScreen: An optimized version of PLEX_box, for full screen black.
@@ -375,9 +491,15 @@
 
 	movlw	0x03				; Entry Mode (S6E63D6 Datasheet page 46)
 	rcall	PLED_CmdWrite
-	movlw	0x00				; =b'00000000' 	CLS MDT1 MDT0 	BGR 	X  	X  	X  	SS  65k Color
+	movlw	0x00				; CLS MDT1 MDT0 	BGR 	X  	X  	X  	SS  65k Color
 	rcall	PLED_DataWrite
-	movlw	b'00110000'			; =b'00110000'	X  	X 	 I/D1 	I/D0 	X  	X  	X 	AM
+
+	; Change direction for block-writes of pixels
+    lfsr    FSR0,win_flags
+	btfss   INDF0,0             ; BANK-SAFE bit test.
+	movlw	b'00110000'			; [normal]  X  	X 	 I/D1 	I/D0 	X  	X  	X 	AM
+	btfsc   INDF0,0
+    movlw   b'00000000'         ; [flipped] X  	X 	 I/D1 	I/D0 	X  	X  	X 	AM
 	rcall	PLED_DataWrite
 
 	movlw	0x18
--- a/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -84,20 +84,19 @@
 	endm
 
 PLED_color_code1:				; Color-codes the output, if required
-	movwf	debug_temp
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_depth		; CF43 [mBar], 16Bit
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_cns			; CF44 [%]
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_gf			; CF45 [%]
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_ppo2		; CF46 [cBar]
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_velocity	; CF47 [m/min]
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_ceiling		; Show warning if CF41=1 and current depth>shown ceiling
-	dcfsnz	debug_temp,F
+	dcfsnz	WREG
 	bra		PLED_color_code_gaslist		; Color-code current row in Gaslist (%O2 in "EEDATA")
 
 
@@ -244,20 +243,18 @@
 	call	PLED_warnings_color
 	return
 
-ostc_debug	macro debug_temp
-	movlw	debug_temp
+ostc_debug	macro value
+	movlw	value
 	call	ostc_debug1
 	endm
 
 ostc_debug1:
-	movwf	debug_temp
-
 	movff	debug_char+4,debug_char+5		; Save for background debugger
 	movff	debug_char+3,debug_char+4
 	movff	debug_char+2,debug_char+3
 	movff	debug_char+1,debug_char+2
 	movff	debug_char+0,debug_char+1
-	movff	debug_temp,debug_char+0
+	movff	WREG,debug_char+0
 
 	btfss	debug_mode				; Are we in debugmode?
 	return							; No, return!
--- a/code_part1/OSTC_code_asm_part1/start.asm	Thu Jan 06 18:36:22 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/start.asm	Fri Jan 07 03:01:02 2011 +0100
@@ -133,6 +133,9 @@
 	GETCUSTOM8	d'48'				; time correction value
 	movff	WREG, time_correction_value	; store in Bank0 register
 
+	GETCUSTOM8	d'63'				; OLED flip_screen flag(s).
+	movff	WREG,win_flags          ; store in Bank0 register
+
 	clrf	flag1					; clear all flags
 	clrf	flag2
 	clrf	flag3
@@ -148,8 +151,8 @@
 	clrf	flag13
 	clrf	flag14
 	clrf	flag15
-	call	gassetup_sort_gaslist			; Sorts Gaslist according to change depth
-	call	PLED_boot				; PLED boot (Incl. Clear Screen!)
+	call	gassetup_sort_gaslist       ; Sorts Gaslist according to change depth
+	call	PLED_boot                   ; PLED boot (Incl. Clear Screen!)
 	WIN_TOP		.0
 	WIN_LEFT	.0
 	WIN_FONT 	FT_SMALL