From: hackbard Date: Wed, 21 Dec 2011 09:45:29 +0000 (+0100) Subject: -> mapping to an 1/x like behaviour X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;p=my-code%2Fatmel.git -> mapping to an 1/x like behaviour --- diff --git a/beginners/oneoverx.c b/beginners/oneoverx.c new file mode 100644 index 0000000..8962bec --- /dev/null +++ b/beginners/oneoverx.c @@ -0,0 +1,28 @@ +#include +#include +#include + +int main(int argc,char **argv) { + + int i; + + double c,a,o,f; + + a=atof(argv[1]); + c=(1.0-sqrt(1+4*a))/2.0; // -! + o=a/(1-c); + + printf("; f(x) = a / (x+o) + c (a:%f o:%f c:%f)\n",a,o,c); + + for(i=255;i>=0;i--) { + f=a/(1.0*i/255+o)+c; + printf("; %d - %d\n",255-i,255-i+1); + printf(".db 0x%0x, ",(int)(f*255)); + i-=1; + f=a/(1.0*i/255+o)+c; + printf("0x%0x\n",(int)(f*255)); + } + + return 0; +} + diff --git a/beginners/rgb_moritz.asm b/beginners/rgb_moritz.asm index bc3a72a..c3b3984 100644 --- a/beginners/rgb_moritz.asm +++ b/beginners/rgb_moritz.asm @@ -21,6 +21,9 @@ .def rgb_level = r21 .def rgb_dir = r22 .def rgb_upd_cnt = r23 +.def r_map = r24 +.def g_map = r25 +.def b_map = r26 .equ pin_red = 0x01 .equ pin_green = 0x02 .equ pin_blue = 0x04 @@ -107,6 +110,23 @@ mov green,tmp ldi tmp,mid mov blue,tmp +; initial mapping intensities of intensities +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,red +adc ZH,zero +lpm r_map,Z +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,green +adc ZH,zero +lpm g_map,Z +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,blue +adc ZH,zero +lpm b_map,Z + ; rgb propagation init ldi rgb_dir,0x04 @@ -180,6 +200,23 @@ sbrc rgb_dir,2 sub blue,two add blue,one +; update mapping +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,red +adc ZH,zero +lpm r_map,Z +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,green +adc ZH,zero +lpm g_map,Z +ldi ZL,low(INTENSITIES*2) +ldi ZH,high(INTENSITIES*2) +add ZL,blue +adc ZH,zero +lpm b_map,Z + ; power on the leds POWER_LEDS: mov rgb_level,zero @@ -189,19 +226,19 @@ add rgb_upd_cnt,one CHECK_RED: -cp count,red +cp count,r_map brne CHECK_GREEN ori rgb_level,pin_red CHECK_GREEN: -cp count,green +cp count,g_map brne CHECK_BLUE ori rgb_level,pin_green CHECK_BLUE: -cp count,blue +cp count,b_map brne SET_PORTS ori rgb_level,pin_blue @@ -214,3 +251,7 @@ add count,one reti +; intensities +INTENSITIES: +.include "rgb_moritz_intensities.asm" + diff --git a/beginners/rgb_moritz_intensities.asm b/beginners/rgb_moritz_intensities.asm new file mode 100644 index 0000000..815cfd4 --- /dev/null +++ b/beginners/rgb_moritz_intensities.asm @@ -0,0 +1,257 @@ +; f(x) = a / (x+o) + c (a:0.100000 o:0.091608 c:-0.091608) +; 0 - 1 +.db 0x0, 0x0 +; 2 - 3 +.db 0x0, 0x0 +; 4 - 5 +.db 0x0, 0x0 +; 6 - 7 +.db 0x0, 0x0 +; 8 - 9 +.db 0x0, 0x0 +; 10 - 11 +.db 0x0, 0x0 +; 12 - 13 +.db 0x1, 0x1 +; 14 - 15 +.db 0x1, 0x1 +; 16 - 17 +.db 0x1, 0x1 +; 18 - 19 +.db 0x1, 0x1 +; 20 - 21 +.db 0x1, 0x1 +; 22 - 23 +.db 0x2, 0x2 +; 24 - 25 +.db 0x2, 0x2 +; 26 - 27 +.db 0x2, 0x2 +; 28 - 29 +.db 0x2, 0x2 +; 30 - 31 +.db 0x2, 0x2 +; 32 - 33 +.db 0x3, 0x3 +; 34 - 35 +.db 0x3, 0x3 +; 36 - 37 +.db 0x3, 0x3 +; 38 - 39 +.db 0x3, 0x3 +; 40 - 41 +.db 0x3, 0x4 +; 42 - 43 +.db 0x4, 0x4 +; 44 - 45 +.db 0x4, 0x4 +; 46 - 47 +.db 0x4, 0x4 +; 48 - 49 +.db 0x4, 0x4 +; 50 - 51 +.db 0x5, 0x5 +; 52 - 53 +.db 0x5, 0x5 +; 54 - 55 +.db 0x5, 0x5 +; 56 - 57 +.db 0x5, 0x6 +; 58 - 59 +.db 0x6, 0x6 +; 60 - 61 +.db 0x6, 0x6 +; 62 - 63 +.db 0x6, 0x6 +; 64 - 65 +.db 0x6, 0x7 +; 66 - 67 +.db 0x7, 0x7 +; 68 - 69 +.db 0x7, 0x7 +; 70 - 71 +.db 0x7, 0x7 +; 72 - 73 +.db 0x8, 0x8 +; 74 - 75 +.db 0x8, 0x8 +; 76 - 77 +.db 0x8, 0x8 +; 78 - 79 +.db 0x9, 0x9 +; 80 - 81 +.db 0x9, 0x9 +; 82 - 83 +.db 0x9, 0x9 +; 84 - 85 +.db 0xa, 0xa +; 86 - 87 +.db 0xa, 0xa +; 88 - 89 +.db 0xa, 0xa +; 90 - 91 +.db 0xb, 0xb +; 92 - 93 +.db 0xb, 0xb +; 94 - 95 +.db 0xb, 0xc +; 96 - 97 +.db 0xc, 0xc +; 98 - 99 +.db 0xc, 0xc +; 100 - 101 +.db 0xd, 0xd +; 102 - 103 +.db 0xd, 0xd +; 104 - 105 +.db 0xd, 0xe +; 106 - 107 +.db 0xe, 0xe +; 108 - 109 +.db 0xe, 0xf +; 110 - 111 +.db 0xf, 0xf +; 112 - 113 +.db 0xf, 0xf +; 114 - 115 +.db 0x10, 0x10 +; 116 - 117 +.db 0x10, 0x10 +; 118 - 119 +.db 0x11, 0x11 +; 120 - 121 +.db 0x11, 0x11 +; 122 - 123 +.db 0x12, 0x12 +; 124 - 125 +.db 0x12, 0x13 +; 126 - 127 +.db 0x13, 0x13 +; 128 - 129 +.db 0x13, 0x14 +; 130 - 131 +.db 0x14, 0x14 +; 132 - 133 +.db 0x15, 0x15 +; 134 - 135 +.db 0x15, 0x15 +; 136 - 137 +.db 0x16, 0x16 +; 138 - 139 +.db 0x16, 0x17 +; 140 - 141 +.db 0x17, 0x17 +; 142 - 143 +.db 0x18, 0x18 +; 144 - 145 +.db 0x19, 0x19 +; 146 - 147 +.db 0x19, 0x1a +; 148 - 149 +.db 0x1a, 0x1a +; 150 - 151 +.db 0x1b, 0x1b +; 152 - 153 +.db 0x1c, 0x1c +; 154 - 155 +.db 0x1c, 0x1d +; 156 - 157 +.db 0x1d, 0x1e +; 158 - 159 +.db 0x1e, 0x1f +; 160 - 161 +.db 0x1f, 0x20 +; 162 - 163 +.db 0x20, 0x21 +; 164 - 165 +.db 0x21, 0x22 +; 166 - 167 +.db 0x22, 0x23 +; 168 - 169 +.db 0x23, 0x24 +; 170 - 171 +.db 0x24, 0x25 +; 172 - 173 +.db 0x25, 0x26 +; 174 - 175 +.db 0x26, 0x27 +; 176 - 177 +.db 0x28, 0x28 +; 178 - 179 +.db 0x29, 0x2a +; 180 - 181 +.db 0x2a, 0x2b +; 182 - 183 +.db 0x2c, 0x2c +; 184 - 185 +.db 0x2d, 0x2e +; 186 - 187 +.db 0x2f, 0x2f +; 188 - 189 +.db 0x30, 0x31 +; 190 - 191 +.db 0x32, 0x33 +; 192 - 193 +.db 0x33, 0x34 +; 194 - 195 +.db 0x35, 0x36 +; 196 - 197 +.db 0x37, 0x38 +; 198 - 199 +.db 0x39, 0x3a +; 200 - 201 +.db 0x3b, 0x3c +; 202 - 203 +.db 0x3d, 0x3e +; 204 - 205 +.db 0x40, 0x41 +; 206 - 207 +.db 0x42, 0x43 +; 208 - 209 +.db 0x45, 0x46 +; 210 - 211 +.db 0x47, 0x49 +; 212 - 213 +.db 0x4a, 0x4c +; 214 - 215 +.db 0x4d, 0x4f +; 216 - 217 +.db 0x50, 0x52 +; 218 - 219 +.db 0x54, 0x56 +; 220 - 221 +.db 0x58, 0x5a +; 222 - 223 +.db 0x5c, 0x5e +; 224 - 225 +.db 0x60, 0x62 +; 226 - 227 +.db 0x64, 0x67 +; 228 - 229 +.db 0x69, 0x6c +; 230 - 231 +.db 0x6f, 0x71 +; 232 - 233 +.db 0x74, 0x77 +; 234 - 235 +.db 0x7b, 0x7e +; 236 - 237 +.db 0x82, 0x85 +; 238 - 239 +.db 0x89, 0x8d +; 240 - 241 +.db 0x92, 0x96 +; 242 - 243 +.db 0x9b, 0xa0 +; 244 - 245 +.db 0xa5, 0xab +; 246 - 247 +.db 0xb1, 0xb7 +; 248 - 249 +.db 0xbe, 0xc6 +; 250 - 251 +.db 0xcd, 0xd6 +; 252 - 253 +.db 0xdf, 0xe9 +; 254 - 255 +.db 0xf3, 0xff