-- Mcode back-end for ortho - X86 common definitions. -- Copyright (C) 2006 Tristan Gingold -- -- GHDL is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation; either version 2, or (at your option) any later -- version. -- -- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY -- WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- -- You should have received a copy of the GNU General Public License -- along with GCC; see the file COPYING. If not, write to the Free -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. package Ortho_Code.X86 is -- Registers. R_Nil : constant O_Reg := 0; -- Not a value. Used for statements. R_None : constant O_Reg := 1; -- Memory. R_Mem : constant O_Reg := 2; -- Spilled out. R_Spill : constant O_Reg := 3; -- Register or memory. -- THis can only be requested. R_Rm : constant O_Reg := 48; -- Immediat R_Imm : constant O_Reg := 49; -- Immediat, register or memory. -- This can be requested. R_Irm : constant O_Reg := 50; -- Immediat or register. -- This can be requested. R_Ir : constant O_Reg := 51; -- BASE + OFFSET R_B_Off : constant O_Reg := 52; -- BASE+INDEX*SCALE+OFFSET -- This can be requested. R_Sib : constant O_Reg := 53; -- INDEX*SCALE + OFFSET -- This can be requested. R_I_Off : constant O_Reg := 54; -- BASE + INDEX*SCALE R_B_I : constant O_Reg := 55; -- INDEX*SCALE R_I : constant O_Reg := 56; subtype Regs_Imm32 is O_Reg range R_Irm .. R_I_Off; R_Any8 : constant O_Reg := 5; R_Any32 : constant O_Reg := 6; R_Any64 : constant O_Reg := 7; R_Ax : constant O_Reg := 8; R_Cx : constant O_Reg := 9; R_Dx : constant O_Reg := 10; R_Bx : constant O_Reg := 11; R_Sp : constant O_Reg := 12; R_Bp : constant O_Reg := 13; R_Si : constant O_Reg := 14; R_Di : constant O_Reg := 15; R_R8 : constant O_Reg := 16; R_R9 : constant O_Reg := 17; R_R10 : constant O_Reg := 18; R_R11 : constant O_Reg := 19; R_R12 : constant O_Reg := 20; R_R13 : constant O_Reg := 21; R_R14 : constant O_Reg := 22; R_R15 : constant O_Reg := 23; subtype Regs_R8 is O_Reg range R_Ax .. R_Bx; subtype Regs_R32 is O_Reg range R_Ax .. R_Di; subtype Regs_R64 is O_Reg range R_Ax .. R_R15; subtype Regs_R8_R15 is O_Reg range R_R8 .. R_R15; R_St0 : constant O_Reg := 24; R_St1 : constant O_Reg := 25; R_St2 : constant O_Reg := 26; R_St3 : constant O_Reg := 27; R_St4 : constant O_Reg := 28; R_St5 : constant O_Reg := 29; R_St6 : constant O_Reg := 30; R_St7 : constant O_Reg := 31; --R_Any_Fp : constant O_Reg := 24; subtype Regs_Fp is O_Reg range R_St0 .. R_St7; -- Any condition register. R_Any_Cc : constant O_Reg := 32; R_Ov : constant O_Reg := 32; R_No : constant O_Reg := 33; R_Ult : constant O_Reg := 34; R_Uge : constant O_Reg := 35; R_Eq : constant O_Reg := 36; R_Ne : constant O_Reg := 37; R_Ule : constant O_Reg := 38; R_Ugt : constant O_Reg := 39; R_Slt : constant O_Reg := 44; R_Sge : constant O_Reg := 45; R_Sle : constant O_Reg := 46; R_Sgt : constant O_Reg := 47; subtype Regs_Cc is O_Reg range R_Ov .. R_Sgt; R_Edx_Eax : constant O_Reg := 64; R_Ebx_Ecx : constant O_Reg := 65; R_Esi_Edi : constant O_Reg := 66; R_AnyPair : constant O_Reg := 67; subtype Regs_Pair is O_Reg range R_Edx_Eax .. R_Esi_Edi; R_Any_Xmm : constant O_Reg := 79; R_Xmm0 : constant O_Reg := 80; R_Xmm1 : constant O_Reg := R_Xmm0 + 1; R_Xmm2 : constant O_Reg := R_Xmm0 + 2; R_Xmm3 : constant O_Reg := R_Xmm0 + 3; R_Xmm4 : constant O_Reg := R_Xmm0 + 4; R_Xmm5 : constant O_Reg := R_Xmm0 + 5; R_Xmm6 : constant O_Reg := R_Xmm0 + 6; R_Xmm7 : constant O_Reg := R_Xmm0 + 7; R_Xmm8 : constant O_Reg := R_Xmm0 + 8; R_Xmm9 : constant O_Reg := R_Xmm0 + 9; R_Xmm10 : constant O_Reg := R_Xmm0 + 10; R_Xmm11 : constant O_Reg := R_Xmm0 + 11; R_Xmm12 : constant O_Reg := R_Xmm0 + 12; R_Xmm13 : constant O_Reg := R_Xmm0 + 13; R_Xmm14 : constant O_Reg := R_Xmm0 + 14; R_Xmm15 : constant O_Reg := R_Xmm0 + 15; subtype Regs_X86_64_Xmm is O_Reg range R_Xmm0 .. R_Xmm15; subtype Regs_X86_Xmm is O_Reg range R_Xmm0 .. R_Xmm7; subtype Regs_Xmm is O_Reg range R_Xmm0 .. R_Xmm15; subtype Regs_Xmm8_Xmm15 is O_Reg range R_Xmm8 .. R_Xmm15; function Get_Pair_High (Reg : Regs_Pair) return Regs_R32; function Get_Pair_Low (Reg : Regs_Pair) return Regs_R32; function Inverse_Cc (R : O_Reg) return O_Reg; -- Intrinsic subprograms. Intrinsic_Mul_Ov_U64 : constant Int32 := 1; Intrinsic_Div_Ov_U64 : constant Int32 := 2; Intrinsic_Mod_Ov_U64 : constant Int32 := 3; Intrinsic_Mul_Ov_I64 : constant Int32 := 4; Intrinsic_Div_Ov_I64 : constant Int32 := 5; Intrinsic_Mod_Ov_I64 : constant Int32 := 6; Intrinsic_Rem_Ov_I64 : constant Int32 := 7; subtype Intrinsics_X86 is Int32 range Intrinsic_Mul_Ov_U64 .. Intrinsic_Rem_Ov_I64; type O_Reg_Array is array (Natural range <>) of O_Reg; type O_Reg_Bitmap is array (O_Reg range <>) of Boolean; pragma Pack (O_Reg_Bitmap); subtype Regs_R32_Bitmap is O_Reg_Bitmap (Regs_R32); subtype Regs_R64_Bitmap is O_Reg_Bitmap (Regs_R64); subtype Regs_Xmm64_Bitmap is O_Reg_Bitmap (Regs_X86_64_Xmm); -- Registers preserved accross calls. Preserved_Regs_32 : constant Regs_R32_Bitmap := (R_Di | R_Si | R_Bx => True, others => False); Preserved_Regs_Lin64 : constant Regs_R64_Bitmap := (R_Bx | R_R12 | R_R13 | R_R14 | R_R15 => True, others => False); Preserved_Regs_Win64 : constant Regs_R64_Bitmap := (R_Di | R_Si | R_Bx | R_R12 | R_R13 | R_R14 | R_R15 => True, others => False); Preserved_Xmm_Win64 : constant Regs_Xmm64_Bitmap := (R_Xmm6 | R_Xmm7 | R_Xmm8 | R_Xmm9 | R_Xmm1 | R_Xmm11 | R_Xmm12 | R_Xmm13 | R_Xmm14 | R_Xmm15 => True, others => False); end Ortho_Code.X86; 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
/* Copyright 2017 Fred Sundvik
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#if defined(VISUALIZER_ENABLE)

#    include "default_animations.h"
#    include "visualizer.h"
#    ifdef LCD_ENABLE
#        include "lcd_keyframes.h"
#    endif
#    ifdef LCD_BACKLIGHT_ENABLE
#        include "lcd_backlight_keyframes.h"
#    endif

#    ifdef BACKLIGHT_ENABLE
#        include "led_backlight_keyframes.h"
#    endif

#    include "visualizer_keyframes.h"

#    if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)

static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
#        ifdef LCD_ENABLE
    lcd_keyframe_enable(animation, state);
#        endif
#        ifdef LCD_BACKLIGHT_ENABLE
    lcd_backlight_keyframe_enable(animation, state);
#        endif
#        ifdef BACKLIGHT_ENABLE
    led_backlight_keyframe_enable(animation, state);
#        endif
    return false;
}

static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
#        ifdef LCD_ENABLE
    lcd_keyframe_disable(animation, state);
#        endif
#        ifdef LCD_BACKLIGHT_ENABLE
    lcd_backlight_keyframe_disable(animation, state);
#        endif
#        ifdef BACKLIGHT_ENABLE
    led_backlight_keyframe_disable(animation, state);
#        endif
    return false;
}

static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) {
    bool ret = false;
#        ifdef LCD_BACKLIGHT_ENABLE
    ret |= lcd_backlight_keyframe_animate_color(animation, state);
#        endif
#        ifdef BACKLIGHT_ENABLE
    ret |= led_backlight_keyframe_fade_in_all(animation, state);
#        endif
    return ret;
}

static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) {
    bool ret = false;
#        ifdef LCD_BACKLIGHT_ENABLE
    ret |= lcd_backlight_keyframe_animate_color(animation, state);
#        endif
#        ifdef BACKLIGHT_ENABLE
    ret |= led_backlight_keyframe_fade_out_all(animation, state);
#        endif
    return ret;
}

// Don't worry, if the startup animation is long, you can use the keyboard like normal
// during that time
keyframe_animation_t default_startup_animation = {
#        if LCD_ENABLE
    .num_frames = 3,
#        else
    .num_frames = 2,
#        endif
    .loop          = false,
    .frame_lengths = {0,
#        if LCD_ENABLE
                      0,
#        endif
                      gfxMillisecondsToTicks(5000)},
    .frame_functions =
        {
            keyframe_enable,
#        if LCD_ENABLE
            lcd_keyframe_draw_logo,
#        endif
            keyframe_fade_in,
        },
};

keyframe_animation_t default_suspend_animation = {
#        if LCD_ENABLE
    .num_frames = 3,
#        else
    .num_frames = 2,
#        endif
    .loop = false,
    .frame_lengths =
        {
#        if LCD_ENABLE
            0,
#        endif
            gfxMillisecondsToTicks(1000), 0},
    .frame_functions =
        {
#        if LCD_ENABLE
            lcd_keyframe_display_layer_text,
#        endif
            keyframe_fade_out,
            keyframe_disable,
        },
};
#    endif

#    if defined(BACKLIGHT_ENABLE)
#        define CROSSFADE_TIME 1000
#        define GRADIENT_TIME 3000

keyframe_animation_t led_test_animation = {
    .num_frames = 14,
    .loop       = true,
    .frame_lengths =
        {
            gfxMillisecondsToTicks(1000),            // fade in
            gfxMillisecondsToTicks(1000),            // no op (leds on)
            gfxMillisecondsToTicks(1000),            // fade out
            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
            gfxMillisecondsToTicks(GRADIENT_TIME),   // left to rigt (outside in)
            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
            gfxMillisecondsToTicks(GRADIENT_TIME),   // top_to_bottom
            0,                                       // mirror leds
            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
            gfxMillisecondsToTicks(GRADIENT_TIME),   // left_to_right (mirrored, so inside out)
            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade
            gfxMillisecondsToTicks(GRADIENT_TIME),   // top_to_bottom
            0,                                       // normal leds
            gfxMillisecondsToTicks(CROSSFADE_TIME),  // crossfade

        },
    .frame_functions =
        {
            led_backlight_keyframe_fade_in_all,
            keyframe_no_operation,
            led_backlight_keyframe_fade_out_all,
            led_backlight_keyframe_crossfade,
            led_backlight_keyframe_left_to_right_gradient,
            led_backlight_keyframe_crossfade,
            led_backlight_keyframe_top_to_bottom_gradient,
            led_backlight_keyframe_mirror_orientation,
            led_backlight_keyframe_crossfade,
            led_backlight_keyframe_left_to_right_gradient,
            led_backlight_keyframe_crossfade,
            led_backlight_keyframe_top_to_bottom_gradient,
            led_backlight_keyframe_normal_orientation,
            led_backlight_keyframe_crossfade,
        },
};
#    endif

#endif