diff --git a/CEdev/examples/library_examples/graphics/demo_0/src/main.c b/CEdev/examples/library_examples/graphics/demo_0/src/main.c index 97ce283f2..1b45b2a6b 100644 --- a/CEdev/examples/library_examples/graphics/demo_0/src/main.c +++ b/CEdev/examples/library_examples/graphics/demo_0/src/main.c @@ -13,6 +13,8 @@ /* Shared libraries */ #include +#define FONT_WIDTH 8 + /* Put function prototypes here */ void print_string_centered(const char *str); @@ -45,5 +47,5 @@ void main(void) { /* Prints a screen centered string */ void print_string_centered(const char *str) { - gfx_PrintStringXY(str, (LCD_WIDTH-gfx_GetStringWidth(str)) / 2, (LCD_HEIGHT-gfx_FontHeight()) / 2); + gfx_PrintStringXY(str, (LCD_WIDTH-gfx_GetStringWidth(str)) / 2, (LCD_HEIGHT-FONT_WIDTH) / 2); } diff --git a/CEdev/examples/library_examples/graphics/demo_10/src/main.c b/CEdev/examples/library_examples/graphics/demo_10/src/main.c index 5d0a70a10..28073e068 100644 --- a/CEdev/examples/library_examples/graphics/demo_10/src/main.c +++ b/CEdev/examples/library_examples/graphics/demo_10/src/main.c @@ -16,6 +16,7 @@ /* Use some random color as the transparent one */ #define TRANSPARENT_COLOR 10 #define FONT_WIDTH 8 +#define FONT_HEIGHT 8 /* Put function prototypes here */ @@ -38,7 +39,7 @@ void main(void) { gfx_SetMonospaceFont( FONT_WIDTH ); /* Print some upside down text */ - printu(my_str, (LCD_WIDTH - gfx_GetStringWidth(my_str)) / 2, (LCD_HEIGHT - gfx_FontHeight()) / 2); + printu(my_str, (LCD_WIDTH - gfx_GetStringWidth(my_str)) / 2, (LCD_HEIGHT - FONT_HEIGHT) / 2); /* Wait for key */ while(!os_GetCSC()); diff --git a/CEdev/examples/library_examples/graphics/demo_8/src/main.c b/CEdev/examples/library_examples/graphics/demo_8/src/main.c index c1db01001..215345dcc 100644 --- a/CEdev/examples/library_examples/graphics/demo_8/src/main.c +++ b/CEdev/examples/library_examples/graphics/demo_8/src/main.c @@ -21,8 +21,6 @@ /* Put all your code here */ void main(void) { - unsigned x_offset = 0, y_offset = 0; - /* Initialize the 8bpp graphics */ gfx_Begin( gfx_8bpp ); @@ -34,7 +32,7 @@ void main(void) { /* Draw a line on the buffer */ //gfx_FillScreen( gfx_black ); - gfx_Line( 0, 0, 319, 239 ); + gfx_Line( 0, 0, LCD_WIDTH-1, LCD_HEIGHT-1 ); /* Wait for a key */ while( !os_GetCSC() ); diff --git a/CEdev/examples/library_examples/graphics/demo_9/src/main.c b/CEdev/examples/library_examples/graphics/demo_9/src/main.c index 6015b9638..fc8faaf34 100644 --- a/CEdev/examples/library_examples/graphics/demo_9/src/main.c +++ b/CEdev/examples/library_examples/graphics/demo_9/src/main.c @@ -16,6 +16,7 @@ /* Use some random color as the transparent one */ #define TRANSPARENT_COLOR 10 #define FONT_WIDTH 8 +#define FONT_HEIGHT 8 /* Put function prototypes here */ @@ -50,7 +51,7 @@ void main(void) { /* Configure the font to normal size, clipped, and monospaced */ gfx_SetTextScale(1,1); - gfx_SetTextConfig( GFX_TEXT_CLIP ); + gfx_SetTextConfig( gfx_text_clip ); gfx_SetMonospaceFont( FONT_WIDTH ); /* Graphics routines draw to the back buffer */ diff --git a/CEdev/include/lib/ce/graphx.h b/CEdev/include/lib/ce/graphx.h index 5c300c775..5190808f7 100644 --- a/CEdev/include/lib/ce/graphx.h +++ b/CEdev/include/lib/ce/graphx.h @@ -172,7 +172,7 @@ typedef enum { gfx_tile_16_pixel, /**< Set when using 16 pixel tiles */ gfx_tile_32_pixel, /**< Set when using 32 pixel tiles */ gfx_tile_64_pixel, /**< Set when using 64 pixel tiles */ - gfx_tile_128_pixel, /**< Set when using 128 pixel tiles */ + gfx_tile_128_pixel /**< Set when using 128 pixel tiles */ } gfx_tilemap_type_t; /** @@ -906,6 +906,16 @@ gfx_image_t *gfx_RotateSpriteCC(gfx_image_t *sprite_in, gfx_image_t *sprite_out) */ gfx_image_t *gfx_RotateSpriteHalf(gfx_image_t *sprite_in, gfx_image_t *sprite_out); +/** + * Resizes a sprite to new dimensions + * + * Place new image dimensions in sprite_out; i.e. sprite_out->width = 80; sprite_out->height = 20. + * @param sprite_in Input sprite to scale + * @param sprite_out Pointer to where scaled sprite will be stored + * @returns A pointer to sprite_out + */ +gfx_image_t *gfx_ScaleSprite(gfx_image_t *sprite_in, gfx_image_t *sprite_out); + /** * Creates a temporary character sprite * @@ -930,11 +940,20 @@ void gfx_SetFontData(uint8_t *data); */ void gfx_SetFontSpacing(uint8_t *spacing); +/** + * Sets the height in pixels of each character + * + * The default value is 8 pixels + * @param height New font height in pixels + * @returns Previous height of font in pixels + */ +uint8_t gfx_SetFontHeight(uint8_t height); + /** * Sets monospaced font * * @param spacing Distance between characters - * @note To disable monospaced font set to 0 + * @note To disable monospaced font, set to 0 */ void gfx_SetMonospaceFont(uint8_t spacing); @@ -955,15 +974,6 @@ unsigned int gfx_GetStringWidth(const char *string); */ unsigned int gfx_GetCharWidth(const char c); -/** - * Gets pixel height of a character - * - * @param c Character to get height of - * @returns Height in pixels of character - */ -#define gfx_GetCharHeight(c) \ -8 - /** * Sets the clipping window * diff --git a/CEdev/include/lib/ce/tice.h b/CEdev/include/lib/ce/tice.h index 3711d6b3a..a5eeb0867 100644 --- a/CEdev/include/lib/ce/tice.h +++ b/CEdev/include/lib/ce/tice.h @@ -650,6 +650,11 @@ void os_ResetFlagBits(int16_t offset_pattern); */ uint16_t os_GetKey(void); +/** + * @brief Scan code type + */ +typedef uint8_t sk_key_t; + /** * Performs an OS call to get the keypad scan code * @@ -658,11 +663,6 @@ uint16_t os_GetKey(void); */ sk_key_t os_GetCSC(void); -/** - * @brief Scan code type - */ -typedef uint8_t sk_key_t; - /** * Runs the calulator at 6 MHz */ diff --git a/CEdev/lib/src/buildexamples.bat b/CEdev/lib/src/buildexamples.bat index 37d4d956b..c13127695 100644 --- a/CEdev/lib/src/buildexamples.bat +++ b/CEdev/lib/src/buildexamples.bat @@ -7,11 +7,11 @@ REM ---------------------------------------------------- echo -- Cleaning examples... cd /D %CEDEV%\examples -for /D %%a in (demo*) do cd %%a && make && cd .. +for /D %%a in (demo*) do cd %%a && make -B && cd .. cd /D %CEDEV%\examples\library_examples\fileio -for /D %%a in (demo*) do cd %%a && make && cd .. +for /D %%a in (demo*) do cd %%a && make -B && cd .. cd /D %CEDEV%\examples\library_examples\graphics -for /D %%a in (demo*) do cd %%a && make && cd .. +for /D %%a in (demo*) do cd %%a && make -B && cd .. cd /D %CEDEV%\examples\library_examples\keypad -for /D %%a in (demo*) do cd %%a && make && cd .. +for /D %%a in (demo*) do cd %%a && make -B && cd .. cd %CEDEV%\lib\src diff --git a/CEdev/lib/src/graphics/graphx/graphics_lib.asm b/CEdev/lib/src/graphics/graphx/graphics_lib.asm index 0edca4a17..593681ed5 100644 --- a/CEdev/lib/src/graphics/graphx/graphics_lib.asm +++ b/CEdev/lib/src/graphics/graphx/graphics_lib.asm @@ -30,8 +30,8 @@ .function "gfx_SetTextBGColor",_SetTextBGColorC .function "gfx_SetTextFGColor",_SetTextFGColorC .function "gfx_SetTextTransparentColor",_SetTextTransparentColorC - .function "gfx_SetCustomFontData",_SetCustomFontData - .function "gfx_SetCustomFontSpacing",_SetCustomFontSpacing + .function "gfx_SetFontData",_SetFontData + .function "gfx_SetFontSpacing",_SetFontSpacing .function "gfx_SetMonospaceFont",_SetMonospaceFont .function "gfx_GetStringWidth",_GetStringWidth .function "gfx_GetCharWidth",_GetCharWidth @@ -83,7 +83,7 @@ ;------------------------------------------------------------------------------- ; v2 functions - Can no longer move/delete ;------------------------------------------------------------------------------- - .function "gfx_LZDecompressSprite",_LZDecompressSprite + .function "gfx_LZDecompressSprite_Deprecated",_LZDecompressSprite_Deprecated .function "gfx_SetTextScale",_SetTextScale ;------------------------------------------------------------------------------- ; v3 functions - Can no longer move/delete @@ -98,7 +98,11 @@ .function "gfx_Lighten",_Lighten .function "gfx_Darken",_Darken ;------------------------------------------------------------------------------- - +; v5 functions +;------------------------------------------------------------------------------- + .function "gfx_SetFontHeight",_SetFontHeight + .function "gfx_ScaleSprite",_ScaleSprite + .beginDependencies .endDependencies @@ -2891,6 +2895,7 @@ TextYPos_SMC = $+1 ld bc,(TextData_ASM) \.r ; get text data array add hl,bc ld iy,0 +FONT_HEIGHT_SMC_3 =$+2 ld ixl,8 jr _PrintLargeFont_ASM ; SMC the jump LargeFontJump_SMC =$-1 @@ -3006,6 +3011,7 @@ CHasFixedWidth: ld bc,(TextData_ASM) \.r ; get text data array add hl,bc ; de = draw location ld de,tmpCharData \.r ; store pixel data into temporary sprite +FONT_HEIGHT_SMC_2 =$+2 ld iyl,8 ld iyh,a ; ixh = char width ld (tmpCharDataSprite),a \.r ; store width of character we are drawing @@ -3186,6 +3192,7 @@ GetHasFixedWidth: ld de,tmpCharDataSprite \.r ex de,hl push hl ; save pointer to sprite +FONT_HEIGHT_SMC_1 =$+2 ld a,8 ld iyh,a ; ixh = char width ld (hl),a ; store width of character we are drawing @@ -3239,7 +3246,27 @@ TColor_SMC_4 =$-1 ret ;------------------------------------------------------------------------------- -_SetCustomFontData: +_SetFontHeight: +; Sets the height of the font in pixels +; Arguments: +; arg0 : New font height +; Returns: +; Previous font height + pop hl + pop de + push de + push hl + ld hl,FONT_HEIGHT_SMC_1 \.r + ld a,(hl) ; a = old height + ld (hl),e + ld hl,FONT_HEIGHT_SMC_2 \.r + ld (hl),e + ld hl,FONT_HEIGHT_SMC_3 \.r + ld (hl),e ; store new height + ret + +;------------------------------------------------------------------------------- +_SetFontData: ; Sets the font to be custom ; Arguments: ; arg0 : Pointer to font data @@ -3259,7 +3286,7 @@ _: ld (TextData_ASM),hl \.r ; save pointer to custom font ret ;------------------------------------------------------------------------------- -_SetCustomFontSpacing: +_SetFontSpacing: ; Sets the font to be custom spacing ; Arguments: ; arg0 : Pointer to font spacing @@ -3669,7 +3696,7 @@ _Reserved: ret ;------------------------------------------------------------------------------- -_LZDecompressSprite: +_LZDecompressSprite_Deprecated: ; Decompresses a sprite that is LZ77 compressed from ConvPNG ld hl,-23 call __frameset @@ -3987,13 +4014,170 @@ _: ld a,(de) pop ix ret +;------------------------------------------------------------------------------- +_ScaleSprite: +; Scale an image using an output buffer + scf + sbc hl,hl + ld (hl),2 + + ld hl,-27 + call __frameset + + or a,a + sbc hl,hl + ld (ix-24),hl ; uint8_t *PrevSource = null + ld (ix-20),hl ; uint8_t Err = 0 + + ld hl,(ix+9) + ld a,(hl) + ld (ix-1),a ; uint8_t TgtWidth = sprite_out->width + ld (TgtWidth),a \.r + ld (TgtWidth_2),a \.r + inc hl + ld a,(hl) + ld (TgtHeight),a \.r ; uint8_t TgtHeight = sprite_out->height + ld iyh,a ; uint8_t NumPixels = TgtHeight + ld e,a + inc hl + ld (ix-4),hl ; uint8_t *Target = sprite_out->data + ld hl,(ix+6) + ld a,(hl) + ld c,a + ld (SrcWidth),a \.r ; uint8_t SrcWidth = sprite_in->width + inc hl + ld d,(hl) ; uint8_t SrcHeight = sprite_in->height + inc hl + push hl ; uint8_t *Source = sprite_in->data + + xor a,a + ld b,8 +_: sla d + rla + cp a,e + jr c,+_ + sub e + inc d +_: djnz --_ + ld e,c + mlt de + ld (FractPart),a \.r ; uint8_t FractPart = SrcHeight % TgtHeight + ld (IntPart),de \.r ; uint8_t IntPart = (SrcHeight / TgtHeight) * SrcWidth + + ld d,c + ld e,(ix-1) + xor a,a + ld b,8 +_: sla d + rla + cp a,e + jr c,+_ + sub e + inc d +_: djnz --_ + ld (FractPartWidth),a \.r ; uint8_t FractPartWidth = SrcWidth % TgtWidth; + ld a,d + ld (IntPartWidth),a \.r ; uint8_t IntPartWidth = SrcWidth / TgtWidth + + pop de + jp WhileNumPixelsLoop \.r ; while (NumPixels-- > 0) +WhileNumPixels: + ld hl,(ix-24) + or a,a + sbc hl,de + push de + ld bc,0 + jr nz,Source_NotEq_Prev ; if (Source == PrevSource) + ld c,(ix-1) + or a,a + sbc hl,hl + ld l,c + ex de,hl + ld hl,(ix-4) + push hl + or a,a + sbc hl,de + pop de + ldir ; memcpy(Target, Target-TgtWidth, TgtWidth) + ld (ix-4),de ; Target += TgtWidth + jr DoneLine +Source_NotEq_Prev: + ld (ix-24),de ; PrevSource = Source; uint8_t *SourceLine = Source; +TgtWidth_2 =$+2 + ld iyl,0 ; uint8_t NumPixelsLine = TgtWidth; + or a,a + sbc hl,hl + push ix + ld ix,(ix-4) + jr WhileNumPixelsLineStart ; while (NumPixelsLine-- > 0) +WhileNumPixelsLineLoop: + push hl + ld a,(de) + ld (ix),a + inc ix ; *Target++ = *SourceLine +IntPartWidth =$+1 + ld hl,0 + add hl,de + ex de,hl ; SourceLine += IntPartWidth + pop hl +FractPartWidth =$+1 + ld c,0 + add hl,bc +TgtWidth =$+1 + ld c,0 + or a,a + sbc hl,bc ; if (ErrLine >= TgtWidth) + jr c,WhileNumPixelsLine + inc de ; SourceLine++ + jr WhileNumPixelsLineStart +WhileNumPixelsLine: + add hl,bc ; Errline -= TgtWidth +WhileNumPixelsLineStart: + ld a,iyl + dec iyl + or a,a + jr nz,WhileNumPixelsLineLoop + lea hl,ix + pop ix + ld (ix-4),hl +DoneLine: + pop de +IntPart =$+1 + ld hl,0 + add hl,de + ex de,hl ; Source += IntPart +FractPart =$+1 + ld c,0 + ld hl,(ix-20) + add hl,bc + ld (ix-20),hl ; Err += FractPart +TgtHeight =$+1 + ld c,0 + or a,a + sbc hl,bc ; if (Err >= TgtHeight) + jr c,WhileNumPixelsLoop + ld (ix-20),hl ; Err -= tgtheight; +SrcWidth =$+1 + ld hl,0 + add hl,de + ex de,hl ; Source += SrcWidth; +WhileNumPixelsLoop: + ld a,iyh + dec iyh + or a,a + jp nz,WhileNumPixels \.r + ld hl,(ix+9) ; return sprite_out; + ld sp,ix + pop ix + ret + ;------------------------------------------------------------------------------- ; Inner library routines ;------------------------------------------------------------------------------- ;------------------------------------------------------------------------------- _LZ_ReadVarSize_ASM: -; LZ Decompression Subroutine +; LZ Decompression Subroutine (This should no longer be accessible by the API) push ix ld ix,0 lea de,ix