Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Shift Register Simulator: Noise Generator
- '(c)2021, @_sorceress
- DEFINT A-W
- SCREEN 12
- 'bitmasks for each tap
- DIM SHARED Q(8): Q(1) = 1%: FOR i = 2 TO 8: Q(i) = 2 * Q(i - 1): NEXT
- SR1 = 1 'pre-load the first register
- DO
- 'display current state
- COLOR 7: LOCATE 3, 1: PRINT "SR1"; TAB(27); "SR2"; TAB(53); "SR3"
- FOR i = 1 TO 8: b = Tap(SR1, i): COLOR 9 + 5 * b: PRINT b;: NEXT
- PRINT TAB(27);
- FOR i = 1 TO 8: b = Tap(SR2, i): COLOR 9 + 5 * b: PRINT b;: NEXT
- PRINT TAB(53);
- FOR i = 1 TO 8: b = Tap(SR3, i): COLOR 9 + 5 * b: PRINT b;: NEXT
- 'scope the output tap
- y = Tap(SR1, 8)
- 'and a low pass filter of the output
- y2 = y2 + (y - y2) * 8000 / 60000 'cutoff f / generator f
- t = t + 1
- IF t MOD 1 = 0 THEN 'optional time division for the oscilloscope
- x = (x + 1) MOD 640
- LINE (x, 204)-(x, 332), 0
- LINE (x + 1, 204)-(x + 1, 332), 8
- PSET (x, 300 - 64 * y), 9 + 5 * y
- PSET (x, 300 - 64 * y2old), 2
- LINE -(x, 300 - 64 * y2), 2
- y2old = y2
- _DISPLAY
- _LIMIT 60
- END IF
- 'wiring the registers together
- SR1Data = Tap(SR3, 2) XOR Tap(SR3, 7) 'feedback
- SR2Data = Tap(SR1, 8) 'chaining SR1 and SR2
- SR3Data = Tap(SR2, 8) 'chaining SR2 and SR3
- 'clock
- SR1 = (SR1 AND 127&) * 2 + SR1Data
- SR2 = (SR2 AND 127&) * 2 + SR2Data
- SR3 = (SR3 AND 127&) * 2 + SR3Data
- LOOP
- END
- FUNCTION Tap (SR%, bit%)
- Tap = SGN(SR% AND Q(bit%))
- END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment