fixed primes.p8

This commit is contained in:
Irmen de Jong 2019-02-25 01:37:05 +01:00
parent 2f1249489b
commit 588133d418
3 changed files with 17 additions and 13 deletions

View File

@ -4,18 +4,14 @@
~ main {
ubyte[256] sieve
ubyte candidate_prime = 2
ubyte candidate_prime = 2 ; is increased in the loop
sub start() {
memset(sieve, 256, false) ; clear the sieve
memset(sieve, 256, false) ; clear the sieve, to reset starting situation on subsequent runs
; calculate primes
; @todo fix this, it misses some primes....
c64scr.print("prime numbers up to 255:\n\n")
ubyte amount
ubyte amount=0
while true {
ubyte prime = find_next_prime()
if prime==0
@ -25,13 +21,14 @@
amount++
}
c64.CHROUT('\n')
c64scr.print("amount of primes: ")
c64scr.print("number of primes (expected 54): ")
c64scr.print_ub(amount)
c64.CHROUT('\n')
}
sub find_next_prime() -> ubyte {
while sieve[candidate_prime] {
candidate_prime++
if candidate_prime==0
@ -40,7 +37,7 @@
; found next one, mark the multiples and return it.
sieve[candidate_prime] = true
uword multiple = candidate_prime**2
uword multiple = candidate_prime
while multiple < len(sieve) {
sieve[lsb(multiple)] = true
multiple += candidate_prime

View File

@ -8,7 +8,7 @@
const ubyte startYpos = boardOffsetY - 2
ubyte lines = 0
ubyte score = 0
uword score = 0
ubyte xpos = startXpos
ubyte ypos = startYpos
ubyte nextBlock = rnd() % 7

View File

@ -7,7 +7,12 @@
; @todo see problem in looplabelproblem.p8
; @todo fix primes.p8 (it misses some primes)
; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars)
; word ww2; byte bb; ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
; uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
; uword ypos=4; ypos += 5000 ; @todo fix "cannot assign word to uword"
sub start() {
@ -21,8 +26,10 @@
bb2 = bb*55
ww2 = ww*55
ww2 = bb * 55.w ; @todo why is this resulting in a byte?
ypos += 5000 ; @todo fix "cannot assign word to uword"
;uword x = sin8u(bb) as uword + 50 ; @todo fix "cannot assign word to uword"
;ypos += 5000 ; @todo fix "cannot assign word to uword"
ww2 = bb * 55.w ; @todo why is this compiling, but resulting in a byte?
c64scr.print_w(ww2)
c64.CHROUT('\n')
ww2 = (bb as word)*55