diff --git a/asm_routines/random16.s b/asm_routines/random16.s new file mode 100644 index 00000000..a5e18fe8 --- /dev/null +++ b/asm_routines/random16.s @@ -0,0 +1,45 @@ +; 16-bit 6502 Random Number Generator + +; Linear feedback shift register PRNG by White Flame +; http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng + +; The Apple II KEYIN routine increments this field +; while waiting for keypress + +SEEDL = $4E +SEEDH = $4F + +XOR_MAGIC = $7657 ; "vW" + +random16: + + lda SEEDL + beq lowZero ; $0000 and $8000 are special values // ; Do a normal shift + asl SEEDL + lda SEEDH + rol + bcc noEor + +doEor: + ; high byte is in .A + eor #>XOR_MAGIC + sta SEEDH + lda SEEDL + eor #xsize/2) { +; x_velocity=-x_velocity; +; } + +; /* Draw rocket */ +; for(cs=1;cs<=max_steps;cs++) { +; y_even_older=y_old; +; y_old=ypos_h; +; x_even_older=x_old; +; x_old=xpos_l; + +; /* Move rocket */ +; xpos_l=xpos_l+x_velocity; + +; /* 16 bit add */ +; add16(&ypos_h,&ypos_l,y_velocity_h,y_velocity_l); + +; /* adjust Y velocity, slow it down */ +;// c=0; +;// a=y_velocity_l; +;// adc(0x20); // 0x20 = 0.125 +;// y_velocity_l=a; +;// a=y_velocity_h; +;// adc(0); +;// y_velocity_h=a; +; sadd16(&y_velocity_h,&y_velocity_l,0x00,0x20); + +; /* if we went higher, adjust peak */ +; if (ypos_h=(xsize-margin)) { +; cs=max_steps; // too far right +; } + +; if (ypos_h<=margin) { +; cs=max_steps; // too far up +; } + + +; // if falling downward +; if (y_velocity_h>0) { +; // if too close to ground, explode +; if (ypos_h>=ysize-margin) { +; cs=max_steps; +; } +; // if fallen a bit past peak, explode +; if (ypos_h>ysize-(ysize-peak)/2) { +; cs=max_steps; +; } +; } + +; // if not done, draw rocket +; if (csXOR_MAGIC + sta SEEDH + lda SEEDL + eor #xsize/2) { + if (xpos_l>xsize/2) { x_velocity=-x_velocity; } @@ -170,10 +200,10 @@ label_180: y_even_older=y_old; y_old=ypos_h; x_even_older=x_old; - x_old=xpos; + x_old=xpos_l; /* Move rocket */ - xpos=xpos+x_velocity; + xpos_l=xpos_l+x_velocity; /* 16 bit add */ add16(&ypos_h,&ypos_l,y_velocity_h,y_velocity_l); @@ -192,11 +222,11 @@ label_180: if (ypos_h=(xsize-margin)) { + if (xpos_l>=(xsize-margin)) { cs=max_steps; // too far right } @@ -221,7 +251,7 @@ label_180: if (cs