Skip to content

Instantly share code, notes, and snippets.

@brunobord
Last active December 27, 2020 01:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunobord/46e5a8c04102e0511535f0e5910900bc to your computer and use it in GitHub Desktop.
Save brunobord/46e5a8c04102e0511535f0e5910900bc to your computer and use it in GitHub Desktop.
Various Digirule programs

Various Digirule 2U programs

  • d6.asm a six-sided dice roller
  • k2000.asm K2000-like flash-light.
  • k2000-loop.asm same as above, with 2 loops (This version is stored in fewer RAM slots, but it's slower because of an extra instruction).
  • fibonacci.asm a basic Fibonacci series computation, displayed on the Data LEDs. The maximum result will be 233, and then it "crashes", all Data LEDs will blink as if it was an error signal.
  • christmas.asm a XMas light using RANDA for the data LEDs + Speed for blinking delay.
  • christmas-advanced.asm Expanded version, still using a random SPEED + blinking both DATA & ADR LEDs.

How can I use this?

In order to test these programs you can either:

// Christmas Lights - Advanced
// In this version we will light randomly both the ADR LEDs and the Data LEDs
// Still using a random SPEED
SPEED 0 // Setting fastest speed for the RAND operations
COPYLR 4 _sr
RANDA
COPYAR spd+1 // Assigning random SPEED
RANDA
COPYAR data+1 // Assigning random lights on DATA LEDs
RANDA
COPYAR adr+1 // Assigning random lights on ADR LEDs
:spd
SPEED 0 // This speed will be changed by the first COPYAR
:data
COPYLR 255 _dr // This value will be changed by the second COPYAR
:adr
COPYLR 255 _ar // This value will be changed by the third COPYAR
JUMP 0 // Back to start
// Christmas Lights
SPEED 0 // Setting fastest speed for the RAND operations
RANDA
COPYAR spd+1 // Assigning Speed for Data LEDs
RANDA
COPYAR data+1 // Assigning random lights
:spd
SPEED 0 // This speed will be changed by the first COPYAR
:data
COPYLR 255 _dr // This value will be changed by the second COPYAR
JUMP 0 // Back to start
// Six-sided dice roller
// It'll roll a d6 and will wait for the LED button #7 to re-roll another one.
:start
// pick a random number - store it in the Accumulator
RANDA
:loop
COPYAR _dr // copy the last value of the acc at addr 255
SUBLA 6 // substract 6 to the acc
BCRSS 1 _sr // if the carry bit is 1 => out of the loop
JUMP loop // if the carry bit is 0 => go on
// This value is [0..5]
INCR _dr // increment it by one => [1..6]
// Waiting for button 7 to be pushed
:waitButton
BTSTSS 7 _br
JUMP waitButton
// Next! We're rolling another one
JUMP start
// Fibonacci
// This program computes the results of fibonacci, displaying them via
// the Data LEDs up to 233 and then "crashes" (all LEDs are blinking).
SPEED 200
COPYLA 1 // Reset accumulator
COPYLR 1 32 // 32 is our "intermediate" registry
:loop
COPYAR _dr // Copy the fib(n) value to the LEDs
COPYRA 32 // fib(n-1) to the ACC
ADDRA _dr // + fib(n)
COPYRR _dr 32 // Saving the previous result into the intermediate slot
BTSTSS _c, _sr // If there's an overflow => go to error
JUMP loop
:error // Error "message"
COPYLR 255 _dr
COPYLR 0 _dr
JUMP error
// K2000-style using two loops.
// It uses less RAM, but is slower, because you're using an more
// instructions than the simpler one with no loop.
:start
SPEED 80
COPYLR 224 _dr
:mainLoop
COPYLR 5 42
:loopRight
SHIFTRR _dr
DECRJZ 42
JUMP loopRight
COPYLR 5 42
:loopLeft
SHIFTRL _dr
DECRJZ 42
JUMP loopLeft
JUMP mainLoop
// K2000 style with DATA LEDs
// Dummy, but faster than using two loops.
:setup
SPEED 92
COPYLR 224 _dr
:loop
SHIFTRR _dr
SHIFTRR _dr
SHIFTRR _dr
SHIFTRR _dr
SHIFTRR _dr
SHIFTRL _dr
SHIFTRL _dr
SHIFTRL _dr
SHIFTRL _dr
SHIFTRL _dr
JUMP loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment