From 0a25830de9d8b85640dc443be72b661d091996de Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Thu, 18 Oct 2018 22:36:11 +0200 Subject: [PATCH] Added rotate example --- src/test/kc/examples/rotate/balloon.png | Bin 0 -> 1323 bytes src/test/kc/examples/rotate/rotate.kc | 92 ++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/test/kc/examples/rotate/balloon.png create mode 100644 src/test/kc/examples/rotate/rotate.kc diff --git a/src/test/kc/examples/rotate/balloon.png b/src/test/kc/examples/rotate/balloon.png new file mode 100644 index 0000000000000000000000000000000000000000..dd77df5feadddfddbf98f8b9eddc55b27eefea16 GIT binary patch literal 1323 zcmV+`1=RY9P)Hg1+lHrgWSWcKdPn90sKGrRqvPeo9CG3uKX#J{(IASm?@+di}}l?o-=)F3E6 zwD^Ni=!>T7nL9I?X}YoAW$t|Qo$sD|?zw001?ah|SeB6#0T!CBEf+H4bBB+JJu8re zhoBb*p;u8ID_yBf0ya+zcePvJL&AGs+11_tpRKn>9TgyPA7ZoSs0)aX0r00)%XR^J z`jH<$>RKN5V(7OqK*TS4xZz{h!*f1C3ECFkK$#7nA@pGN!$;%jYv zwjAKwmYb0gKL(K8-kPtb5${A?tlI~wzMrJ6wTdBr=Y%%%EaEMQ&o}4FQ^DA)s*}Z> z!FI&AHCpoWI|RUqx?7s@$8!5^Q=anY%X@i5{QA6kNcMelpE>R6eCYFpmMsVT zrI(b06~u#xf1yS}_UGdMvD``!0~u->P=lA4?YN`hilQ z|3tHka)7T{2CGqwjZfMwx$5irQN_*|e4l)UHmiYuz74Yp1t^#>hrJ3-SOXDcC_o0^ z7T9R1gAN8V6s;5)ieI5-7aQlmJn}lUna#nz!j%5V$X|o`xX!dHWQRV27P1=rj;t2b zW$~+pTw@bIek?ZvKPDL<64`^#UNTAck#RBsB6*5DP4<%UA_FqU$I>2EH_cM;u)Q~SI+rg`Rn{L z_AC5qq~L$#SMj%U$6Cz0vP{G5Y*=%5RT^yu;}-DInZ=349rJPVM6C3K^oO)8y(fJr{l>k`ead~!ea?NsT>_Ci%bnxC;Vy6= zb6>{xYV#Ue-+LB$7`JEXmTRm^AtP)R9u{)KHsMiWGV&)32xCG~*nyU<>-!d;FP=Re z4r3qYr~6#KE>;1F`>_J_P5xC?ROxV(DIHdCO*p$HRQI@7^PwV@Pvuf+ z5K}u-6REM(K@W$srgorh0{i?O)v0c>QtHxU-hBdD(>iYJ4b2sIOVX2K8m~4gmYVA5 zh^QEb$V`rCQ-|7ZS{nuL-t>?3n=-o(6I(7vocj#GzCZEo`!3>+v;dYIfPu#&ZWzzX z2i^rZ^Mu;6+rb@?NPG+6)c5T6zxpzGe*M(x+{AON=PiJ>H#?ob-|uwRK0yDg0B4PV z0id6JRRdfL?*IS*%}GQ-R5%gMQ_%_oF$`+Q{{NS|`5**Ob1mFpg`-Jh)C6vhG1m8s zXRTbGbH+XvfUpc5F`IdJLN9{qeL{}D4sQjj7-P8XoD!$^Wkt>ni1|(t=9Q4O`u48L zPV9)gzU>u}1TLLZ*7d%u2mt4jq^^b@))CjUy`n^1$y|KAB1h7_MS(Q3lHK8~0GhCp zyXGC76{s$gNP4fmh@$}A0iE_b}KBJTZa&la<*0WSm5?n*V%) h{}9l1Xs&Ci`3Is1J4vY+Soi<{002ovPDHLkV1n&siSGaa literal 0 HcmV?d00001 diff --git a/src/test/kc/examples/rotate/rotate.kc b/src/test/kc/examples/rotate/rotate.kc new file mode 100644 index 000000000..056b04563 --- /dev/null +++ b/src/test/kc/examples/rotate/rotate.kc @@ -0,0 +1,92 @@ + +// Angles: sf[0.8] : $80=PI, $100 = 2*PI +// Values: sin(x) in [-1;1] sf[0.16] : -1.0: -$7fff 1.0:$7fff + +import "c64" +import "fastmultiply" + +byte* SCREEN = $0400; +byte* SPRITE = $3000; + +byte* COS_LO = $2000; +byte* COS_HI = $2200; +byte* SIN_LO = COS_LO+$40; // sin(x) = cos(x+PI/2) +byte* SIN_HI = COS_HI+$40; // sin(x) = cos(x+PI/2) + +void main() { + asm { sei } + init(); + anim(); +} + +void init() { + mulf_init(); + *SPRITES_ENABLE = %11111111; + byte* sprites_ptr = SCREEN+$3f8; + byte spr_x = 60; + for(byte i: 0..7) { + byte i2 = i<<1; + sprites_ptr[i] = (byte)(SPRITE/$40); + SPRITES_XPOS[i2] = spr_x; + SPRITES_YPOS[i2] = spr_x; + SPRITES_COLS[i] = GREEN; + spr_x += 24; + } + +} + +void anim() { + signed word min = 1000; + signed word max = -1000; + + byte angle = 0; + signed word x = 89; // signed fixed[15.0] + signed word y = 0; + + while(true) { + while(*RASTER!=$ff) {} + (*BORDERCOL)++; + signed word sin_a = (signed word) { SIN_HI[angle], SIN_LO[angle] }; // signed fixed[0.15] + signed word cos_a = (signed word) { COS_HI[angle], COS_LO[angle] }; // signed fixed[0.15] + signed dword xr = mulf16s(cos_a, x)<<1 - mulf16s(sin_a, y)<<1; // signed fixed[16.16] + signed dword yr = mulf16s(cos_a, y)<<1 + mulf16s(sin_a, x)<<1; // signed fixed[16.16] + signed word xpos = ((signed word) >xr) + 89 + 24 + 60; + signed word ypos = ((signed word) >yr) + 89 + 51; + SPRITES_XPOS[0] = xpos; + SPRITES_YPOS[0] = round(min+(ampl/2)+(ampl/2)*cos(rad)) + } + } +}} + +kickasm(pc SPRITE, resource "balloon.png") {{ + .var pic = LoadPicture("balloon.png", List().add($000000, $ffffff)) + .for (var y=0; y<21; y++) + .for (var x=0;x<3; x++) + .byte pic.getSinglecolorByte(x,y) +}}