/*
 * Draw_Buffer_Graphic.c
 *
 *  Created on: 2024/11/18
 *      Author: egaono-electronics
 */

#include "Draw_Buffer_Graphic.h"

#include "ILI9341_SPI_Draw.h"


#include <stdlib.h>



// Graphic 描画Buffer
uint8_t GLB_uint8_aBuffer_Graphic[def_Size_Buffer_Graphic];



//----------------------------------------------------------
// 描画Bufferに1dotの点を描画
//----------------------------------------------------------
// 引数;
// int16_t int16_X : 位置X(X座標)
// int16_t int16_Y : 位置Y(Y座標)

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//-----------------------------------------------------------
void DrawDot_Width_Height(int16_t int16_X, int16_t int16_Y,
                          int16_t int16_Type,
                          int16_t int16_AreaWidth,
                          int16_t int16_AreaHeight,
                          uint8_t *puint8_aDrawBuffer)
{
  uint8_t *puint8_Vpn;

  int16_t int16_GraphWidth;
  int16_t int16_Remain;


  //------------------------------------------------
  // Graph幅を再計算する。 : 8 の倍数に補正する。
  //------------------------------------------------
  int16_GraphWidth = int16_AreaWidth / 8;
  int16_Remain = int16_AreaWidth % 8;
  if(int16_Remain > 0){
    int16_GraphWidth++;
  }
  //------------------------------------------------


  // 表示開始位置が画面外なら何もしないで終了する。
  if(int16_X >= (int16_t)int16_AreaWidth  || int16_X < 0){
    return;
  }
  if(int16_Y >= (int16_t)int16_AreaHeight || int16_Y < 0){
    return;
  }

  puint8_Vpn = puint8_aDrawBuffer
                    + (int32_t)(int16_GraphWidth * int16_Y);

  puint8_Vpn += (int32_t)(int16_X / 8);
  int16_Remain = int16_X % 8;

  if(int16_Type == 0){
    // 点を消す。
    *puint8_Vpn &= ~(0x80 >> int16_Remain);
  }
  else{
    // 黒を描く。
    *puint8_Vpn |= 0x80 >> int16_Remain;
  }
}



//----------------------------------------------------------
// 描画Bufferに1本の直線を描画
//----------------------------------------------------------
// int16_StartX : 開始位置X(X座標)
// int16_StartY : 開始位置Y(Y座標)

// int16_EndX : 終了位置X(X座標)
// int16_EndY : 終了位置Y(Y座標)

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void DrawLine(int16_t int16_StartX, int16_t int16_StartY,
              int16_t int16_EndX, int16_t int16_EndY,
              int16_t int16_Type,
              int16_t int16_AreaWidth, int16_t int16_AreaHeight,
              uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_Width;
  int16_t int16_Height;
  int16_t int16_FlagX;
  int16_t int16_FlagY;
  int16_t int16_Step;


  int16_FlagX = 0;
  int16_FlagY = 0;

  if(int16_StartX > int16_EndX) {
    int16_FlagX = 1;
  }

  if(int16_StartY > int16_EndY) {
    int16_FlagY = 1;
  }


  // 最初の点を描画
  DrawDot_Width_Height(int16_StartX, int16_StartY, int16_Type,
                       int16_AreaWidth, int16_AreaHeight,
                       puint8_aDrawBuffer);


  // ラインの幅、高さを取得する。
  int16_Width
        = (int16_t)abs((int16_t)(int16_StartX - int16_EndX));
  int16_Height
        = (int16_t)abs((int16_t)(int16_StartY - int16_EndY));

  int16_Step = 0;
  if(int16_Width >= int16_Height){
    // 横長の線を描く(横ループ)。
    while(int16_StartX != int16_EndX){
      if(int16_FlagX == 0){
        int16_StartX++;
      }
      else{
        int16_StartX--;
      }

      int16_Step += int16_Height;

      if(int16_Step >= int16_Width){
        int16_Step -= int16_Width;
        if(int16_FlagY == 0){
          int16_StartY++;
        }
        else{
          int16_StartY--;
        }
      }
      DrawDot_Width_Height(int16_StartX, int16_StartY,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
    }
  }
  else{
    // 縦長の線を描く(縦ループ)。
    while(int16_StartY != int16_EndY){
      if(int16_FlagY == 0){
        int16_StartY++;
      }
      else{
        int16_StartY--;
      }

      int16_Step += int16_Width;

      if(int16_Step >= int16_Height){
        int16_Step -= int16_Height;
        if(int16_FlagX == 0){
          int16_StartX++;
        }
        else{
          int16_StartX--;
        }
      }
      DrawDot_Width_Height(int16_StartX, int16_StartY,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
    }
  }
}



//----------------------------------------------------------
// 描画Bufferに四角を描く(中は空)
//----------------------------------------------------------
// int16_StartX : 開始位置X(X座標)
// int16_StartY : 開始位置Y(Y座標)

// int16_EndX : 終了位置X(X座標)
// int16_EndY : 終了位置Y(Y座標)

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void DrawRect(int16_t int16_StartX, int16_t int16_StartY,
              int16_t int16_EndX, int16_t int16_EndY,
              int16_t int16_Type,
              int16_t int16_AreaWidth, int16_t int16_AreaHeight,
              uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_I;
  int16_t int16_J;


  // X座標開始位置、終了位置の整列
  if(int16_StartX > int16_EndX){
    int16_I  = int16_StartX;
    int16_StartX = int16_EndX;
    int16_EndX = int16_I;
  }

  // Y座標開始位置、終了位置の整列
  if(int16_StartY > int16_EndY){
    int16_I  = int16_StartY;
    int16_StartY = int16_EndY;
    int16_EndY = int16_I;
  }

  int16_I = int16_StartX;
  int16_J = int16_EndX;
  while(int16_StartX <= int16_EndX){
    DrawDot_Width_Height(int16_StartX, int16_StartY,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_EndX, int16_EndY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_StartX, int16_EndY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_EndX, int16_StartY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    int16_StartX++;
    int16_EndX--;
  }
  while(int16_StartY <= int16_EndY){
    DrawDot_Width_Height(int16_I, int16_StartY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_J, int16_EndY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_I, int16_EndY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_J, int16_StartY, int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    int16_StartY++;
    int16_EndY--;
  }
}



//----------------------------------------------------------
// 描画Bufferに四角を描く(塗りつぶす)
//----------------------------------------------------------
// int16_StartX : 開始位置X(X座標)
// int16_StartY : 開始位置Y(Y座標)

// int16_EndX : 終了位置X(X座標)
// int16_EndY : 終了位置Y(Y座標)

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void DrawRectP(int16_t int16_StartX, int16_t int16_StartY,
               int16_t int16_EndX, int16_t int16_EndY,
               int16_t int16_Type,
               int16_t int16_AreaWidth, int16_t int16_AreaHeight,
               uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_I;
  int16_t int16_J;


  // X座標開始位置、終了位置の整列
  if(int16_StartX > int16_EndX){
    int16_I  = int16_StartX;
    int16_StartX = int16_EndX;
    int16_EndX = int16_I;
  }

  // Y座標開始位置、終了位置の整列
  if(int16_StartY > int16_EndY){
    int16_I  = int16_StartY;
    int16_StartY = int16_EndY;
    int16_EndY = int16_I;
  }

  while(int16_StartX <= int16_EndX){
    int16_I = int16_StartY;
    int16_J = int16_EndY;
    while(int16_I <= int16_J){
      DrawDot_Width_Height(int16_StartX, int16_I, int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_EndX, int16_J, int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_StartX, int16_J, int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_EndX, int16_I, int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      int16_I++;
      int16_J--;
    }
    int16_StartX++;
    int16_EndX--;
  }
}



//----------------------------------------------------------
// 描画Bufferに円を描く(中は空)
//----------------------------------------------------------
// int16_CenterX : 円の中心点X(X座標)
// int16_CenterY : 円の中心点Y(Y座標)

// int16_Radius : 円の半径

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void DrawCircle(int16_t int16_CenterX, int16_t int16_CenterY,
                int16_t int16_Radius,
                int16_t int16_Type,
                int16_t int16_AreaWidth, int16_t int16_AreaHeight,
                uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_X;
  int16_t int16_Y;
  int16_t int16_F;


  // 円を描く。
  int16_X = int16_Radius;
  int16_Y = 0;
  int16_F = -2 * int16_Radius + 3;

  while(int16_X >= int16_Y){
    DrawDot_Width_Height(int16_CenterX + int16_X,
                         int16_CenterY + int16_Y,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX + int16_X,
                         int16_CenterY - int16_Y,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX - int16_X,
                         int16_CenterY + int16_Y,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX - int16_X,
                         int16_CenterY - int16_Y,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX + int16_Y,
                         int16_CenterY + int16_X,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX + int16_Y,
                         int16_CenterY - int16_X,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX - int16_Y,
                         int16_CenterY + int16_X,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);
    DrawDot_Width_Height(int16_CenterX - int16_Y,
                         int16_CenterY - int16_X,
                         int16_Type,
                         int16_AreaWidth, int16_AreaHeight,
                         puint8_aDrawBuffer);

    if(int16_F >= 0){
      int16_X--;
      int16_F -= 4 * int16_X;
    }
    int16_Y++;
    int16_F += 4 * int16_Y + 2;
  }
}



//----------------------------------------------------------
// 描画Bufferに円を描く(塗りつぶす)
//----------------------------------------------------------
// int16_CenterX : 円の中心点X(X座標)
// int16_CenterY : 円の中心点Y(Y座標)

// int16_Radius : 円の半径

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void DrawCircleP(int16_t int16_CenterX, int16_t int16_CenterY,
                 int16_t int16_Radius,
                 int16_t int16_Type,
                 int16_t int16_AreaWidth, int16_t int16_AreaHeight,
                 uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_I;
  int16_t int16_X;
  int16_t int16_Y;
  int16_t int16_Height;
  int16_t int16_F;


  // 円を描く。
  int16_X  = int16_Radius;
  int16_Y  = 0;
  int16_F = -2 * int16_Radius + 3;

  int16_Height = 0;

  while(int16_X >= int16_Y){
    for(int16_I = (int16_CenterX - int16_X);
            int16_I <= (int16_CenterX + int16_X); int16_I++){
      DrawDot_Width_Height(int16_I, int16_CenterY + int16_Y,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_I, int16_CenterY - int16_Y,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
    }
    if(int16_Y == int16_Height) {
      DrawDot_Width_Height(int16_CenterX + int16_Y,
                           int16_CenterY + int16_X,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_CenterX + int16_Y,
                           int16_CenterY - int16_X,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_CenterX - int16_Y,
                           int16_CenterY + int16_X,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
      DrawDot_Width_Height(int16_CenterX - int16_Y,
                           int16_CenterY - int16_X,
                           int16_Type,
                           int16_AreaWidth, int16_AreaHeight,
                           puint8_aDrawBuffer);
    }
    else{
      for(int16_I = (int16_CenterX - int16_Y);
              int16_I <= (int16_CenterX + int16_Y); int16_I++){
        DrawDot_Width_Height(int16_I, int16_CenterY + int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);
        DrawDot_Width_Height(int16_I, int16_CenterY - int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);
      }
      int16_Height = int16_Y;
    }

    if(int16_F >= 0){
      int16_X--;
      int16_F -= 4 * int16_X;
    }
    int16_Y++;
    int16_F += 4 * int16_Y + 2;
  }
}



//----------------------------------------------------------
// 描画Bufferに円弧を描く(中は空) :
//----------------------------------------------------------
// int16_CenterX : 円の中心点X(X座標)
// int16_CenterY : 円の中心点Y(Y座標)

// int16_Radius : 円の半径

// int16_t int16_Start : 描画開始位置   0-359
// int16_t int16_End : 描画終了位置   int16_Start-359

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void Draw_Arc(int16_t int16_CenterX, int16_t int16_CenterY,
              int16_t int16_Radius,
              int16_t int16_Start, int16_t int16_End,
              int16_t int16_Type,
              int16_t int16_AreaWidth, int16_t int16_AreaHeight,
              uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_X;
  int16_t int16_Y;
  int16_t int16_F;

  int16_t int16_0_45_Start;
  int16_t int16_0_45_End = 0;
  int16_t int16_0_45_Line = 0;

  int16_t int16_45_90_Start;
  int16_t int16_45_90_End = 0;
  int16_t int16_45_90_Line = 0;

  int16_t int16_90_135_Start;
  int16_t int16_90_135_End = 0;
  int16_t int16_90_135_Line = 0;

  int16_t int16_135_180_Start;
  int16_t int16_135_180_End = 0;
  int16_t int16_135_180_Line = 0;

  int16_t int16_180_225_Start;
  int16_t int16_180_225_End = 0;
  int16_t int16_180_225_Line = 0;

  int16_t int16_225_270_Start;
  int16_t int16_225_270_End = 0;
  int16_t int16_225_270_Line = 0;

  int16_t int16_270_315_Start;
  int16_t int16_270_315_End = 0;
  int16_t int16_270_315_Line = 0;

  int16_t int16_315_360_Start;
  int16_t int16_315_360_End = 0;
  int16_t int16_315_360_Line = 0;


  //----------------------------------------------------
  // 0-45
  //----------------------------------------------------
  if(int16_Start >= 45){
    int16_0_45_Start = -1;
  }
  else{
    int16_0_45_Start = (int16_t)(((float)int16_Start
                        / (float)45) * (float)int16_Radius);

    if(int16_End >= 45){
      int16_0_45_End = int16_Radius;
    }
    else{
      int16_0_45_End = (int16_t)(((float)int16_End
                        / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 45-90
  //----------------------------------------------------
  if((int16_End < 45) || (int16_Start >= 90)){
    int16_45_90_Start = -1;
  }
  else{
    if(int16_Start <= 45){
      int16_45_90_End = int16_Radius;
    }
    else{
      int16_45_90_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start -45)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 90){
      int16_45_90_Start = 0;
    }
    else{
      int16_45_90_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End - 45)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 90-135
  //----------------------------------------------------
  if((int16_End < 90) || (int16_Start >= 135)){
    int16_90_135_Start = -1;
  }
  else{
    if(int16_Start <= 90){
      int16_90_135_Start = 0;
    }
    else{
      int16_90_135_Start
        = (int16_t)(((float)(int16_Start - 90)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 135){
      int16_90_135_End = int16_Radius;
    }
    else{
      int16_90_135_End
        = (int16_t)(((float)(int16_End -90)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 135-180
  //----------------------------------------------------
  if((int16_End < 135) || (int16_Start >= 180)){
    int16_135_180_Start = -1;
  }
  else{
    if(int16_Start <= 135){
      int16_135_180_End = int16_Radius;
    }
    else{
      int16_135_180_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 135)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 180){
      int16_135_180_Start = 0;
    }
    else{
      int16_135_180_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -135)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 180-225
  //----------------------------------------------------
  if((int16_End < 180) || (int16_Start >= 225)){
    int16_180_225_Start = -1;
  }
  else{
    if(int16_Start <= 180){
      int16_180_225_Start = 0;
    }
    else{
      int16_180_225_Start
        = (int16_t)(((float)(int16_Start - 180)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 225){
      int16_180_225_End = int16_Radius;
    }
    else{
      int16_180_225_End
        = (int16_t)(((float)(int16_End -180)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 225-270
  //----------------------------------------------------
  if((int16_End < 225) || (int16_Start >= 270)){
    int16_225_270_Start = -1;
  }
  else{
    if(int16_Start <= 225){
      int16_225_270_End = int16_Radius;
    }
    else{
      int16_225_270_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 225)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 270){
      int16_225_270_Start = 0;
    }
    else{
      int16_225_270_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -225)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 270-315
  //----------------------------------------------------
  if((int16_End < 270) || (int16_Start >= 315)){
    int16_270_315_Start = -1;
  }
  else{
    if(int16_Start <= 270){
      int16_270_315_Start = 0;
    }
    else{
      int16_270_315_Start
        = (int16_t)(((float)(int16_Start - 270)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 315){
      int16_270_315_End = int16_Radius;
    }
    else{
      int16_270_315_End
        = (int16_t)(((float)(int16_End -270)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 315-360
  //----------------------------------------------------
  if((int16_End < 315) || (int16_Start >= 360)){
    int16_315_360_Start = -1;
  }
  else{
    if(int16_Start <= 315){
      int16_315_360_End = int16_Radius;
    }
    else{
      int16_315_360_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 315)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 360){
      int16_315_360_Start = 0;
    }
    else{
      int16_315_360_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -315)
                    / (float)45) * (float)int16_Radius);
    }
  }



  //----------------------------------------------------
  // 円を描く。
  //----------------------------------------------------
  int16_X = int16_Radius;
  int16_Y = 0;
  int16_F = -2 * int16_Radius + 3;

  while(int16_X >= int16_Y){
    if(int16_0_45_Start != -1){
      if((int16_Y >= int16_0_45_Start)
                        && (int16_Y <= int16_0_45_End)){
        DrawDot_Width_Height(int16_CenterX + int16_Y,
                             int16_CenterY - int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 0-45

        if((int16_Start >= 0) && (int16_Start < 45)){
          if((int16_Y >= int16_0_45_Start)
                            && (int16_0_45_Line == 0)){
            int16_0_45_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_Y,
                     int16_CenterY - int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 0) && (int16_End < 45)){
          if(int16_Y >= int16_0_45_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_Y,
                     int16_CenterY - int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_45_90_Start != -1){
      if((int16_Y >= int16_45_90_Start)
                    && (int16_Y <= int16_45_90_End + 1)){
        DrawDot_Width_Height(int16_CenterX + int16_X,
                             int16_CenterY - int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 45-90

        if((int16_Start >= 45) && (int16_Start < 90)){
          if(int16_Y >= int16_45_90_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_X,
                     int16_CenterY - int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 45) && (int16_End < 90)){
          if((int16_Y >= int16_45_90_Start)
                            && (int16_45_90_Line == 0)){
            int16_45_90_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_X,
                     int16_CenterY - int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_90_135_Start != -1){
      if((int16_Y >= int16_90_135_Start)
                            && (int16_Y <= int16_90_135_End)){
        DrawDot_Width_Height(int16_CenterX + int16_X,
                             int16_CenterY + int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 90-135

        if((int16_Start >= 90) && (int16_Start < 135)){
          if((int16_Y >= int16_90_135_Start)
                            && (int16_90_135_Line == 0)){
            int16_90_135_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_X,
                     int16_CenterY + int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 90) && (int16_End < 135)){
          if(int16_Y >= int16_90_135_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_X,
                     int16_CenterY + int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_135_180_Start != -1){
      if((int16_Y >= int16_135_180_Start)
                    && (int16_Y <= int16_135_180_End + 1)){
        DrawDot_Width_Height(int16_CenterX + int16_Y,
                             int16_CenterY + int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 135-180

        if((int16_Start >= 135) && (int16_Start < 180)){
          if(int16_Y >= int16_135_180_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_Y,
                     int16_CenterY + int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 135) && (int16_End < 180)){
          if((int16_Y >= int16_135_180_Start)
                            && (int16_135_180_Line == 0)){
            int16_135_180_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX + int16_Y,
                     int16_CenterY + int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_180_225_Start != -1){
      if((int16_Y >= int16_180_225_Start)
                        && (int16_Y <= int16_180_225_End)){
        DrawDot_Width_Height(int16_CenterX - int16_Y,
                             int16_CenterY + int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 180-225

        if((int16_Start >= 180) && (int16_Start < 225)){
          if((int16_Y >= int16_180_225_Start)
                            && (int16_180_225_Line == 0)){
            int16_180_225_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_Y,
                     int16_CenterY + int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 180) && (int16_End < 225)){
          if(int16_Y >= int16_180_225_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_Y,
                     int16_CenterY + int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_225_270_Start != -1){
      if((int16_Y >= int16_225_270_Start)
                    && (int16_Y <= int16_225_270_End + 1)){
        DrawDot_Width_Height(int16_CenterX - int16_X,
                             int16_CenterY + int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 225-270

        if((int16_Start >= 225) && (int16_Start < 270)){
          if(int16_Y >= int16_225_270_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_X,
                     int16_CenterY + int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 225) && (int16_End < 270)){
          if((int16_Y >= int16_225_270_Start)
                            && (int16_225_270_Line == 0)){
            int16_225_270_Line = 1;
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_X,
                     int16_CenterY + int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_270_315_Start != -1){
      if((int16_Y >= int16_270_315_Start)
                    && (int16_Y <= int16_270_315_End)){
        DrawDot_Width_Height(int16_CenterX - int16_X,
                             int16_CenterY - int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 270-315

        if((int16_Start >= 270) && (int16_Start < 315)){
          if((int16_Y >= int16_270_315_Start)
                         && (int16_270_315_Line == 0)){
            int16_270_315_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_X,
                     int16_CenterY - int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 270) && (int16_End < 315)){
          if(int16_Y >= int16_270_315_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_X,
                     int16_CenterY - int16_Y,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_315_360_Start != -1){
      if((int16_Y >= int16_315_360_Start)
                    && (int16_Y <= int16_315_360_End + 1)){
        DrawDot_Width_Height(int16_CenterX - int16_Y,
                             int16_CenterY - int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 315-360

        if((int16_Start >= 315) && (int16_Start < 360)){
          if(int16_Y >= int16_315_360_End){
            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_Y,
                     int16_CenterY - int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
        else if((int16_End >= 315) && (int16_End < 360)){
          if((int16_Y >= int16_315_360_Start)
                            && (int16_315_360_Line == 0)){
            int16_315_360_Line = 1;

            DrawLine(int16_CenterX, int16_CenterY,
                     int16_CenterX - int16_Y,
                     int16_CenterY - int16_X,
                     int16_Type,
                     int16_AreaWidth, int16_AreaHeight,
                     puint8_aDrawBuffer);
          }
        }
      }
    }


    if(int16_F >= 0){
      int16_X--;
      int16_F -= 4 * int16_X;

      if(int16_0_45_Start > 0){
        int16_0_45_Start--;
      }
      if(int16_0_45_End > 0){
        int16_0_45_End--;
      }

      if(int16_45_90_Start > 0){
        int16_45_90_Start--;
      }
      if(int16_45_90_End > 0){
        int16_45_90_End--;
      }

      if(int16_90_135_Start > 0){
        int16_90_135_Start--;
      }
      if(int16_90_135_End > 0){
        int16_90_135_End--;
      }

      if(int16_135_180_Start > 0){
        int16_135_180_Start--;
      }
      if(int16_135_180_End > 0){
        int16_135_180_End--;
      }

      if(int16_180_225_Start > 0){
        int16_180_225_Start--;
      }
      if(int16_180_225_End > 0){
        int16_180_225_End--;
      }

      if(int16_225_270_Start > 0){
        int16_225_270_Start--;
      }
      if(int16_225_270_End > 0){
        int16_225_270_End--;
      }

      if(int16_270_315_Start > 0){
        int16_270_315_Start--;
      }
      if(int16_270_315_End > 0){
        int16_270_315_End--;
      }

      if(int16_315_360_Start > 0){
        int16_315_360_Start--;
      }
      if(int16_315_360_End > 0){
        int16_315_360_End--;
      }
    }

    int16_Y++;
    int16_F += 4 * int16_Y + 2;
  }
}



//----------------------------------------------------------
// 描画Bufferに円弧を描く(塗りつぶす)
//----------------------------------------------------------
// int16_CenterX : 円の中心点X(X座標)
// int16_CenterY : 円の中心点Y(Y座標)

// int16_Radius : 円の半径

// int16_t int16_Start : 描画開始位置   0-359
// int16_t int16_End : 描画終了位置   int16_Start-359

// int16_Type :
//    0 : 描画dot OFF
//    1 : 描画dot ON

// int16_t int16_AreaWidth : 描画領域の幅
// int16_t int16_AreaHeight : 描画領域の高さ

// uint8_t *puint8_aDrawBuffer : 描画Bufferのポインタ


// 戻り値:
//    なし
//----------------------------------------------------------
void Draw_Arc_P(int16_t int16_CenterX, int16_t int16_CenterY,
                int16_t int16_Radius,
                int16_t int16_Start, int16_t int16_End,
                int16_t int16_Type,
                int16_t int16_AreaWidth, int16_t int16_AreaHeight,
                uint8_t *puint8_aDrawBuffer)
{
  int16_t int16_X;
  int16_t int16_Y;
  int16_t int16_F;

  int16_t int16_0_45_Start;
  int16_t int16_0_45_End = 0;

  int16_t int16_45_90_Start;
  int16_t int16_45_90_End = 0;

  int16_t int16_90_135_Start;
  int16_t int16_90_135_End = 0;

  int16_t int16_135_180_Start;
  int16_t int16_135_180_End = 0;

  int16_t int16_180_225_Start;
  int16_t int16_180_225_End = 0;

  int16_t int16_225_270_Start;
  int16_t int16_225_270_End = 0;

  int16_t int16_270_315_Start;
  int16_t int16_270_315_End = 0;

  int16_t int16_315_360_Start;
  int16_t int16_315_360_End = 0;


  //----------------------------------------------------
  // 0-45
  //----------------------------------------------------
  if(int16_Start >= 45){
    int16_0_45_Start = -1;
  }
  else{
    int16_0_45_Start
      = (int16_t)(((float)int16_Start
                    / (float)45) * (float)int16_Radius);

    if(int16_End >= 45){
      int16_0_45_End = int16_Radius;
    }
    else{
      int16_0_45_End
        = (int16_t)(((float)int16_End
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 45-90
  //----------------------------------------------------
  if((int16_End < 45) || (int16_Start >= 90)){
    int16_45_90_Start = -1;
  }
  else{
    if(int16_Start <= 45){
      int16_45_90_End = int16_Radius;
    }
    else{
      int16_45_90_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start -45)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 90){
      int16_45_90_Start = 0;
    }
    else{
      int16_45_90_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End - 45)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 90-135
  //----------------------------------------------------
  if((int16_End < 90) || (int16_Start >= 135)){
    int16_90_135_Start = -1;
  }
  else{
    if(int16_Start <= 90){
      int16_90_135_Start = 0;
    }
    else{
      int16_90_135_Start
        = (int16_t)(((float)(int16_Start - 90)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 135){
      int16_90_135_End = int16_Radius;
    }
    else{
      int16_90_135_End
        = (int16_t)(((float)(int16_End -90)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 135-180
  //----------------------------------------------------
  if((int16_End < 135) || (int16_Start >= 180)){
    int16_135_180_Start = -1;
  }
  else{
    if(int16_Start <= 135){
      int16_135_180_End = int16_Radius;
    }
    else{
      int16_135_180_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 135)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 180){
      int16_135_180_Start = 0;
    }
    else{
      int16_135_180_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -135)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 180-225
  //----------------------------------------------------
  if((int16_End < 180) || (int16_Start >= 225)){
    int16_180_225_Start = -1;
  }
  else{
    if(int16_Start <= 180){
      int16_180_225_Start = 0;
    }
    else{
      int16_180_225_Start
        = (int16_t)(((float)(int16_Start - 180)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 225){
      int16_180_225_End = int16_Radius;
    }
    else{
      int16_180_225_End
        = (int16_t)(((float)(int16_End -180)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 225-270
  //----------------------------------------------------
  if((int16_End < 225) || (int16_Start >= 270)){
    int16_225_270_Start = -1;
  }
  else{
    if(int16_Start <= 225){
      int16_225_270_End = int16_Radius;
    }
    else{
      int16_225_270_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 225)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 270){
      int16_225_270_Start = 0;
    }
    else{
      int16_225_270_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -225)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 270-315
  //----------------------------------------------------
  if((int16_End < 270) || (int16_Start >= 315)){
    int16_270_315_Start = -1;
  }
  else{
    if(int16_Start <= 270){
      int16_270_315_Start = 0;
    }
    else{
      int16_270_315_Start
        = (int16_t)(((float)(int16_Start - 270)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 315){
      int16_270_315_End = int16_Radius;
    }
    else{
      int16_270_315_End
        = (int16_t)(((float)(int16_End -270)
                    / (float)45) * (float)int16_Radius);
    }
  }


  //----------------------------------------------------
  // 315-360
  //----------------------------------------------------
  if((int16_End < 315) || (int16_Start >= 360)){
    int16_315_360_Start = -1;
  }
  else{
    if(int16_Start <= 315){
      int16_315_360_End = int16_Radius;
    }
    else{
      int16_315_360_End
        = int16_Radius
        - (int16_t)(((float)(int16_Start - 315)
                    / (float)45) * (float)int16_Radius);
    }

    if(int16_End >= 360){
      int16_315_360_Start = 0;
    }
    else{
      int16_315_360_Start
        = int16_Radius
        - (int16_t)(((float)(int16_End -315)
                    / (float)45) * (float)int16_Radius);
    }
  }



  //----------------------------------------------------
  // 円を描く。
  //----------------------------------------------------
  int16_X = int16_Radius;
  int16_Y = 0;
  int16_F = -2 * int16_Radius + 3;

  while(int16_X >= int16_Y){
    if(int16_0_45_Start != -1){
      if((int16_Y >= int16_0_45_Start)
                    && (int16_Y <= int16_0_45_End)){
        DrawDot_Width_Height(int16_CenterX + int16_Y,
                             int16_CenterY - int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 0-45

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX + int16_Y,
                 int16_CenterY - int16_X,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_45_90_Start != -1){
      if((int16_Y >= int16_45_90_Start)
                    && (int16_Y <= int16_45_90_End)){
        DrawDot_Width_Height(int16_CenterX + int16_X,
                             int16_CenterY - int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 45-90

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX + int16_X,
                 int16_CenterY - int16_Y,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_90_135_Start != -1){
      if((int16_Y >= int16_90_135_Start)
                    && (int16_Y <= int16_90_135_End)){
        DrawDot_Width_Height(int16_CenterX + int16_X,
                             int16_CenterY + int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 90-135

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX + int16_X,
                 int16_CenterY + int16_Y,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_135_180_Start != -1){
      if((int16_Y >= int16_135_180_Start)
                    && (int16_Y <= int16_135_180_End)){
        DrawDot_Width_Height(int16_CenterX + int16_Y,
                             int16_CenterY + int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 135-180

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX + int16_Y,
                 int16_CenterY + int16_X,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_180_225_Start != -1){
      if((int16_Y >= int16_180_225_Start)
                    && (int16_Y <= int16_180_225_End)){
        DrawDot_Width_Height(int16_CenterX - int16_Y,
                             int16_CenterY + int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 180-225

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX - int16_Y,
                 int16_CenterY + int16_X,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_225_270_Start != -1){
      if((int16_Y >= int16_225_270_Start)
                    && (int16_Y <= int16_225_270_End)){
        DrawDot_Width_Height(int16_CenterX - int16_X,
                             int16_CenterY + int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 225-270

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX - int16_X,
                 int16_CenterY + int16_Y,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_270_315_Start != -1){
      if((int16_Y >= int16_270_315_Start)
                    && (int16_Y <= int16_270_315_End)){
        DrawDot_Width_Height(int16_CenterX - int16_X,
                             int16_CenterY - int16_Y,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 270-315

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX - int16_X,
                 int16_CenterY - int16_Y,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_315_360_Start != -1){
      if((int16_Y >= int16_315_360_Start)
                    && (int16_Y <= int16_315_360_End)){
        DrawDot_Width_Height(int16_CenterX - int16_Y,
                             int16_CenterY - int16_X,
                             int16_Type,
                             int16_AreaWidth, int16_AreaHeight,
                             puint8_aDrawBuffer);  // 315-360

        DrawLine(int16_CenterX, int16_CenterY,
                 int16_CenterX - int16_Y,
                 int16_CenterY - int16_X,
                 int16_Type,
                 int16_AreaWidth, int16_AreaHeight,
                 puint8_aDrawBuffer);
      }
    }


    if(int16_F >= 0){
      int16_X--;
      int16_F -= 4 * int16_X;

      if(int16_0_45_Start > 0){
        int16_0_45_Start--;
      }
      if(int16_0_45_End > 0){
        int16_0_45_End--;
      }

      if(int16_45_90_Start > 0){
        int16_45_90_Start--;
      }
      if(int16_45_90_End > 0){
        int16_45_90_End--;
      }

      if(int16_90_135_Start > 0){
        int16_90_135_Start--;
      }
      if(int16_90_135_End > 0){
        int16_90_135_End--;
      }

      if(int16_135_180_Start > 0){
        int16_135_180_Start--;
      }
      if(int16_135_180_End > 0){
        int16_135_180_End--;
      }

      if(int16_180_225_Start > 0){
        int16_180_225_Start--;
      }
      if(int16_180_225_End > 0){
        int16_180_225_End--;
      }

      if(int16_225_270_Start > 0){
        int16_225_270_Start--;
      }
      if(int16_225_270_End > 0){
        int16_225_270_End--;
      }

      if(int16_270_315_Start > 0){
        int16_270_315_Start--;
      }
      if(int16_270_315_End > 0){
        int16_270_315_End--;
      }

      if(int16_315_360_Start > 0){
        int16_315_360_Start--;
      }
      if(int16_315_360_End > 0){
        int16_315_360_End--;
      }
    }

    int16_Y++;
    int16_F += 4 * int16_Y + 2;
  }
}
