Mercurial > public > hwos_code
diff src/color_processor.asm @ 623:c40025d8e750
3.03 beta released
author | heinrichsweikamp |
---|---|
date | Mon, 03 Jun 2019 14:01:48 +0200 |
parents | d866684249bd |
children | cd58f7fc86db |
line wrap: on
line diff
--- a/src/color_processor.asm Wed Apr 10 10:51:07 2019 +0200 +++ b/src/color_processor.asm Mon Jun 03 14:01:48 2019 +0200 @@ -1,8 +1,8 @@ ;============================================================================= ; -; File File color_processor.asm ## V2.98c +; File File color_processor.asm combined next generation V3.03.2 ; -; Decompress and draw an image. +; Decompress and draw an image ; ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. ;============================================================================= @@ -10,27 +10,29 @@ ; 2010-12-13 : [jDG] Creation. ; 2010-12-30 : [jDG] Revised to put temp into ACCESSRAM0 ; -; RATIONALS: The OSTC have a nice color screen, and a std geek attitude impose +; RATIONALS: The OSTC has a nice color screen, and a std geek attitude impose ; to show off ... ;-) ; -; Inputs: TBLPTR points to the image description block. -; win_top, win_leftx2 the Top/Leftx2 corner here to put the image. -; Outputs: None. -; Trashed: TBLPTR, TABLAT, FSR2, PROD, win_width, win_height +; Inputs TBLPTR points to the image description block. +; win_top, win_leftx2 the Top/Leftx2 corner here to put the image. +; Outputs None +; Trashed TBLPTR, TABLAT, FSR2, PROD, win_width, win_height ; ; ImageBloc: ; db widthx2, height -; db nbColors, 0 ; 0 = unused yet, should remain 0 to keep packing happy +; db nbColors, encoding version ; dw color0, color1, color2, color3, ... ; db packed pixels... ; ; Limitations: -; * nbColors <= 127 -; * image width should be even -; * image left border should be on even position, too +; * nbColors <= 126 +; * image width is even +; * image left border is on even column, too ; -; Compressed format: -; - 1-3 bytes pixel count, followed by 1 byte pixel color +; +; Compressed format in encoding version 0 and 1: +; ---------------------------------------------- +; - 1-3 bytes pixel repetition count, followed by 1 byte pixel color ; - bit 7 = 1: byte holds pixel count in bits 6-0 ; - bit 7 = 0: byte holds pixel color in bits 6-0 ; - all pixel count bytes accumulate: @@ -38,6 +40,16 @@ ; - 2 bytes pixel count: 1yyyyyyy 1xxxxxxx -> 14 bit pixel count ; - 3 bytes pixel count: 1zzzzzzz 1yyyyyyy 1xxxxxxx -> 21 bit pixel count ; +; A pixel repetition count of 0 means one single pixel will be drawn, +; a repetition count of 1 means two pixels will be drawn, and so on. +; The image is done when all pixels as of width x high parameters have been printed. +; +; +; Compressed format in encoding version 1: +; ---------------------------------------- +; As above, but the image is done when a color index equaling 127 is encountered. +; +; ; Pixels are written column by column from left to right, with columns down first. ; ;----------------------------------------------------------------------------- @@ -45,160 +57,166 @@ #include "hwos.inc" #include "tft.inc" -color_proc CODE + extern convert_for_display2 + + +color_proc CODE ;----------------------------------------------------------------------------- -; Note: some variables (win_width, win_height) are in BANK 0 ! global color_image color_image: - banksel common ; Bank 1, just to be sure... + tblrd*+ ; read image width (in true width / 2) + movff TABLAT,win_width + tblrd*+ ; read image height + movff TABLAT,win_height + rcall get_colors ; read the colors - ;---- Get image size ----------------------------------------------- - tblrd*+ - movff TABLAT,win_width - tblrd*+ - movff TABLAT,win_height + tstfsz encoding_format ; image encoded in version 0 format? + bra color_image_1 ; NO - ; Compute width * height * 2 : the number of pixels to write. - clrf img_pixels+2 - movf win_width,W ; Compute number of pixels to draw - mulwf win_height ; 0 .. 160x240 - bcf STATUS,C ; BEWARE: mulwf does not reset carry flag! - rlcf PRODL ; x2 --> 0 .. 320x240, might be > 0xFFFF - rlcf PRODH - movff PRODL, img_pixels+0 - movff PRODH, img_pixels+1 - rlcf img_pixels+2 ; Get the upper bit in place - - clrf WREG ; Decrement count to ease end detection - decf img_pixels+0,F - subwfb img_pixels+1,F - subwfb img_pixels+2,F + ; image encoding version 0 format: compute the overall number of pixels - 1 to draw + movf win_width,W ; get width into WREG + mulwf win_height ; multiply by hight + movff PRODL,overall_pixels+0 ; store product, low byte + movff PRODH,overall_pixels+1 ; ... high byte + clrf overall_pixels+2 ; clear upper byte + bcf STATUS,C ; clear carry flag + rlcf overall_pixels+0 ; multiply by 2 via shift left, low byte + rlcf overall_pixels+1 ; ... high byte + rlcf overall_pixels+2 ; ... upper byte + clrf WREG ; decrement by 1 to ease all pixel done detection + decf overall_pixels+0,F ; ... + subwfb overall_pixels+1,F ; ... + subwfb overall_pixels+2,F ; ... - ;---- Send window command -------------------------------------------- - clrf win_width+1 ; x2 on width, for the true box size - rlcf win_width+0 - rlcf win_width+1 - call TFT_box_write - Index_out 0x22 +color_image_1: + clrf win_width+1 ; clear width, high byte + bcf STATUS,C ; clear carry flag + rlcf win_width+0 ; multiply width x 2 to get the true box width + rlcf win_width+1 ; ... + call TFT_box_write ; set output box + Index_out 0x22 ; frame memory data write start - ;---- Read the colors ------------------------------------------------ - rcall get_colors - - ;---- Decode pixels -------------------------------------------------- color_image_loop_xy: - ; Get pixel count - clrf img_count+0 - clrf img_count+1 + ; prepare to read next pixel count and color + clrf pixel_count+0 ; clear number of pixels + clrf pixel_count+1 ; ... - ;---- Decode repetition count -color_image_decode_1: - tblrd*+ ; Get one byte - - btfss TABLAT,7 ; High bit cleared ? - bra color_image_decode_2 ; YES: this is a color byte +color_image_read_byte: + tblrd*+ ; get next byte + btfss TABLAT,7 ; high bit cleared ? + bra color_image_decode_color; YES - this is a color byte + ;bra color_image_decode_count; NO - this is a pixel count byte - rlcf TABLAT,F ; Drop high bit. - movlw .7 ; Move 7 bits -color_image_decode_3: - rlcf TABLAT,F ; Get bit into carry - rlcf img_count+0,F ; Push into pixel count - rlcf img_count+1,F - decfsz WREG - bra color_image_decode_3 ; and loop for each 7 bits - bra color_image_decode_1 ; Decode next byte +color_image_decode_count: + ; decode pixel repetition count + rlcf TABLAT,F ; drop high bit + movlw .7 ; move 7 bits +color_image_decode_count_loop: + rlcf TABLAT,F ; get upper bit into carry + rlcf pixel_count+0,F ; push bit into pixel count (16 bit operation) + rlcf pixel_count+1,F ; ... + decfsz WREG ; decrement loop counter, all bits done? + bra color_image_decode_count_loop ; NO - loop + bra color_image_read_byte ; YES - decode next byte + +color_image_decode_color: + ; check for end-of-image tag (color index = 0x7F) -- it is assumed that no version 0 image contains 127 colors... + movlw 0x7f ; encoding for end-of-image + cpfslt TABLAT ; color index < end-of-image tag? + return ; NO - done -color_image_decode_2: - ;---- Get pixel color into PROD - movf TABLAT,W ; Get color index - addwf WREG ; *2 - lfsr FSR2,buffer ; Reinitialize color table - movff WREG,FSR2L ; LOW(buffer) == 0 - movff POSTINC2,PRODL - movff POSTINC2,PRODH + ; get pixel color into PROD + lfsr FSR2,buffer ; set FSR2 pointer to base address of color table + rlncf TABLAT,W ; get color index * 2 into WREG + movwf FSR2L ; adjust pointer to selected color + movff POSTINC2,PRODL ; read color, low byte + movff POSTINC2,PRODH ; read color, high byte - ; Subtract count-1 from the number of pixel we should do. - movf img_count+0,W ; Make a 24bit subtraction - subwf img_pixels+0,F - movf img_count+1,W - subwfb img_pixels+1,F - movlw 0 - subwfb img_pixels+2,F + tstfsz encoding_format ; image encoded in version 0 format? + bra color_image_pixel ; NO + ; image encoding version 0 format: subtract pixel count from the overall number of pixels to do + movf pixel_count+0,W ; YES - 24 bit subtraction, low byte + subwf overall_pixels+0,F ; ... + movf pixel_count+1,W ; ... high byte + subwfb overall_pixels+1,F ; ... + movlw .0 ; ... upper byte + subwfb overall_pixels+2,F ; ... - infsnz img_count+0 ; Increment count - incf img_count+1 +color_image_pixel: + ; prepare sending of pixels to display + infsnz pixel_count+0 ; increment pixel repetition count by 1 + incf pixel_count+1 ; ... + incf pixel_count+1 ; because decrement is done first, increment high byte once more + bsf tft_rs,0 ; RS_H data + bcf INTCON,GIE ; disable global interrupts + + btfsc screen_type2 ; display type 2 ? + bra color_image_display2 ; YES + movff PRODH,PORTA ; NO - move color high byte to PORTA + movff PRODL,PORTH ; - move color low byte to PORTH - ; Loop sending pixel color - incf img_count+1 ; Because we decrement first, should add one here ! - bsf tft_rs,0 ; RS_H ; Data - bcf INTCON,GIE - -color_image_loop_pixel: - btfsc screen_type2 ; Display 2? - bra color_image_display2 ; Yes - - movff PRODH,PORTA ; Move high byte to PORTA - movff PRODL,PORTH ; Move low byte to PORTH - bcf tft_nwr - bsf tft_nwr - decfsz img_count+0 - bra color_image_loop_pixel - decfsz img_count+1 - bra color_image_loop_pixel - bra color_image_loop_pixel2 - +color_image_pixel1_loop: + bcf tft_nwr ; toggle write signal + bsf tft_nwr ; ... + decfsz pixel_count+0 ; decrement pixel counter, low byte + bra color_image_pixel1_loop ; loop if not zero + decfsz pixel_count+1 ; decrement pixel counter, high byte + bra color_image_pixel1_loop ; loop if not zero + bra color_image_pixel_com ; all pixels transmitted + color_image_display2: - extern convert_for_display2 - call convert_for_display2 ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' -color_image_display2_loop: - movff win_color5,PORTH ; Move high byte to PORTH (DISPLAY is bigendian) - bcf tft_nwr - bsf tft_nwr - movff win_color4,PORTH ; Move low byte to PORTH - bcf tft_nwr - bsf tft_nwr - movff win_color3,PORTH ; Move low(est) byte to PORTH - bcf tft_nwr - bsf tft_nwr - decfsz img_count+0 - bra color_image_display2_loop - decfsz img_count+1 - bra color_image_display2_loop + call convert_for_display2 ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' + ; into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' +color_image_pixel2_loop: + movff win_color5,PORTH ; move upper byte to PORTH (DISPLAY is big endian) + bcf tft_nwr ; toggle write signal + bsf tft_nwr ; ... + movff win_color4,PORTH ; move high byte to PORTH + bcf tft_nwr ; toggle write signal + bsf tft_nwr ; ... + movff win_color3,PORTH ; move low byte to PORTH + bcf tft_nwr ; toggle write signal + bsf tft_nwr ; ... + decfsz pixel_count+0 ; decrement pixel counter, low byte + bra color_image_pixel2_loop ; loop if not zero + decfsz pixel_count+1 ; decrement pixel counter, high byte + bra color_image_pixel2_loop ; loop if not zero -color_image_loop_pixel2: - bsf INTCON,GIE - ; And count (on a 24bit counter) - clrf WREG ; Make a 24bit decrement. - decf img_pixels+0 - subwfb img_pixels+1,F - subwfb img_pixels+2,F +color_image_pixel_com: + bsf INTCON,GIE ; re-enable global interrupts + + tstfsz encoding_format ; image encoded in version 0 format? + bra color_image_loop_xy ; NO - loop to process next byte from image data - bnn color_image_loop_xy ; Not finished ? loop... - - ;---- Closeup -------------------------------------------------------- -; Index_out 0x00 - return + ; image encoding version 0 format: step counter + clrf WREG ; make a 24 bit decrement + decf overall_pixels+0 ; ... + subwfb overall_pixels+1,F ; ... + subwfb overall_pixels+2,F ; ... + bnn color_image_loop_xy ; all pixels done? NO - loop + return ; YES - done global get_colors get_colors: tblrd*+ ; read number of image colors movff TABLAT,lo ; store in lo - tblrd*+ ; skip one spare byte (future flags ?) movf lo,W + tblrd*+ ; read image encoding format + movff TABLAT,encoding_format ; store encoding format lfsr FSR2,buffer ; set up buffer as storage for the colors get_colors_loop: - tblrd*+ - btfss use_custom_colors ; shall custom colors be used? - movff TABLAT,POSTINC2 ; NO - tblrd*+ - btfss use_custom_colors ; shall custom colors be used? - movff TABLAT,POSTINC2 ; NO - decfsz WREG - bra get_colors_loop - - bcf use_custom_colors ; clear custom colors request - return + tblrd*+ ; read color from stored image, low byte + btfss use_custom_colors ; shall use custom colors? + movff TABLAT,POSTINC2 ; NO - copy color read to buffer + tblrd*+ ; read color from stored image, high byte + btfss use_custom_colors ; shall use custom colors? + movff TABLAT,POSTINC2 ; NO - copy color read to buffer + decfsz WREG ; decrement loop counter, done? + bra get_colors_loop ; NO - loop + bcf use_custom_colors ; YES - clear custom colors request + return ; - done END