4 ms·
Has anyone rewritten this in something modern? Probably less than 100 lines of Python, for example. Can skip load/save, .... I think he uses the C64 ROMs to
by melling 7y ago
Has anyone rewritten this in something modern? Probably less than 100 lines of Python, for example. Can skip load/save, .... I think he uses the C64 ROMs to get the bitmaps. All those pokes around 1024 are writes to the screen RAM.
# READ Bitmap for selected character from C64 ROM
310 k=asc(a$)
320 if a$>="0" and a$<="9" then k=k+64:goto340 # process numbers 0..9
330 if a$ < "a" or a$ > "z" then 500 # Maybe a function key
340 gosub 970:print "fetch ";a$
350 l%=0
360 k=(k-64)*8+53248
370 poke56333,127:poke 1,peek(1)and251
380 fori=0to6:poke49408+i,peek(k+i):next # Copy character's image from character ROM (53248) to RAM
390 poke 1,peek(1) or 4:poke 56333,129
#
# Look up bits that make character 6x7 = 42 values
# Lighted dots are stored as 1 and background dots as −1
400 for i = 0 to 6
410 j% = peek(49408+i)/2 # byte value - divide by 2 is shift right. Removes first bit
420 for k=1 to 6 # 6 wide
430 l%=l%+1 # counter 1..42
440 f1%(l%) = -1 + (2 * (j% and 1)) # 2 * (1 or 0) => field[counter] = 1 or -1
450 j%=j%/2 # Shifting right again to get the next bit in first position for the AND operator. xxxx xxx1
460 next k
470 next i
# Function keys
510 if j%=1 then gosub 1000:goto 280 # train()
520 if j%=5 then gosub 1080:goto 90 # print_matrix()
530 if j%=2 then gosub 1210:goto 280 # randomize_ten_percent()
540 if j%=6 then gosub 1680:goto 280 # clear_memory()
550 if j%=3 then gosub 1290:goto 280 # recall_pattern()
560 if j%=7 then print chr$(147);:close15:end
570 if j%=4 then gosub 1800:goto 90 # save_to_disk()
580 if j%=8 then gosub 1990:goto 90 # restore_from_disk()
1000 rem train on pattern in f1% def train()
1010 gosub 970:print "training"
1020 for i = 1 to 42
1030 for j = 1 to 42
1040 m%(i,j)=m%(i,j)+f1%(i)*f1%(j) # matrix[i][j] = matrix[i][j] + field1[i] * field1[j]
1050 next j
1060 next i
1070 return
1210 rem randomise 10 percent of f1% def randomize_ten_percent()
1220 gosub 970:print "random"
1230 for i=1 to 42
1240 if rnd(0) > 0.1 then 1260 # Skip > 10%
1250 f1%(i)=-f1%(i) # negate
1260 next i
1270 gosub 750 # update field f2 on screen
1280 return
- tenebrisalietum 7y agoThe "poke56333,127" is disabling the background keyboard reading IRQ by disabling the "IRQ on timer out" function of the CIA 1 used to trigger it. This is needed because the "poke 1" that follows maps in the 4K character ROM over the I/O devices at D000-DFFF; if you don't do this the system would freeze.