Version 4 achieves 1m 25s only if you remove the variable names from the two NEXT statements. i.e. Instead of NEXT J and NEXT I Just use NEXT Otherwise, Version 4 takes 1m 29s if you leave the variable names in the NEXT statements.
This was a fun experiment to try. I used a slightly different method of counting down from 100,000 to zero, then read the number of heads vs tails and displayed the results in BASIC... _ML code:_ *=$33c ; sys 828 jmp init heads: !byte 0,0,0 repcount: !byte $a0,$86,$01 ; $186a0 = 100,000 dec init: lda #$80 sta $d40f sta $d412 reset_count: lda #$a0 sta repcount lda #$86 sta repcount+1 lda #$01 sta repcount+2 lda #$00 sta heads sta heads+1 sta heads+2 loop: ldx #$03 - dex bne - lda $d41b and #$01 beq + inc heads bne + inc heads+1 bne + inc heads+2 + dec repcount bne loop dec repcount+1 bne loop dec repcount+2 bpl loop rts _BASIC code:_ 10 sys828:h=peek(831)+peek(832)*256 20 b=100000:t=b-h:print"heads:"h;int(h/b*1000)/10"%" 30 print"tails:"t;int(t/b*1000)/10"%" _Output:_ heads: 50198 50.1 % tails: 49802 49.8 %
You could have done it in it's orginal form in FORTRAN with FORTRAN64 by Abacus for the C64, it makes stand alone programs that run on a stock C64 and it's compiled and fast.
About 10:05: hmm... doesn't look like a coin flip, or the noise generator of the SID is bad. Maybe it is good on a real machine, since you work in an emulator, don't you? From 0-255 are 256 numbers, so 50% is checking if x
The problem was that the SID takes 16-17 cycles to generate a new number and the loop was cycling at about 15 causing duplicates and throwing off the expected 50-50 ratio. Inserting two NOPs between cycles solved the problem, I just never updated the video (maybe I should, I've optimized the code even more and got the time down to just over 19 seconds. There is a good video on the 8 Bit Show and Tell channel (@8_Bit) that demonstrates how the SID works: ua-cam.com/video/-ADjfx79wNg/v-deo.html
@@retrooldguy9880 Thank you. That was also an intresting video. First of all i thought the SID is a "true" random number generator, but it is "only" a "pseudo" random generator. You videos are nice. I am looking forward new ones.
Thanks for the teaching video.
Really interesting video, I really enjoyed it. I hope you'll make more videos on the C64. Thank you so much for sharing.
Version 4 achieves 1m 25s only if you remove the variable names from the two NEXT statements.
i.e. Instead of NEXT J and NEXT I
Just use NEXT
Otherwise, Version 4 takes 1m 29s if you leave the variable names in the NEXT statements.
This was a fun experiment to try. I used a slightly different method of counting down from 100,000 to zero, then read the number of heads vs tails and displayed the results in BASIC...
_ML code:_
*=$33c ; sys 828
jmp init
heads: !byte 0,0,0
repcount: !byte $a0,$86,$01 ; $186a0 = 100,000 dec
init:
lda #$80
sta $d40f
sta $d412
reset_count:
lda #$a0
sta repcount
lda #$86
sta repcount+1
lda #$01
sta repcount+2
lda #$00
sta heads
sta heads+1
sta heads+2
loop:
ldx #$03
-
dex
bne -
lda $d41b
and #$01
beq +
inc heads
bne +
inc heads+1
bne +
inc heads+2
+
dec repcount
bne loop
dec repcount+1
bne loop
dec repcount+2
bpl loop
rts
_BASIC code:_
10 sys828:h=peek(831)+peek(832)*256
20 b=100000:t=b-h:print"heads:"h;int(h/b*1000)/10"%"
30 print"tails:"t;int(t/b*1000)/10"%"
_Output:_
heads: 50198 50.1 %
tails: 49802 49.8 %
My BASIC only version looks like this : (PAL Vice 3.8)
10ti$="000000":k=.5:m=10:n=1000
15fori=1tom
20forj=1ton
25h=h-(rnd(0)
Interesting!
You could have done it in it's orginal form in FORTRAN with FORTRAN64 by Abacus for the C64, it makes stand alone programs that run on a stock C64 and it's compiled and fast.
About 10:05: hmm... doesn't look like a coin flip, or the noise generator of the SID is bad. Maybe it is good on a real machine, since you work in an emulator, don't you? From 0-255 are 256 numbers, so 50% is checking if x
The problem was that the SID takes 16-17 cycles to generate a new number and the loop was cycling at about 15 causing duplicates and throwing off the expected 50-50 ratio. Inserting two NOPs between cycles solved the problem, I just never updated the video (maybe I should, I've optimized the code even more and got the time down to just over 19 seconds. There is a good video on the 8 Bit Show and Tell channel (@8_Bit) that demonstrates how the SID works: ua-cam.com/video/-ADjfx79wNg/v-deo.html
@@retrooldguy9880 Thank you. That was also an intresting video. First of all i thought the SID is a "true" random number generator, but it is "only" a "pseudo" random generator.
You videos are nice. I am looking forward new ones.