From d16b1bd72e13234cab8f9b4eda04d7fb466dc30f Mon Sep 17 00:00:00 2001 From: 4am Date: Fri, 5 Nov 2021 18:39:20 -0400 Subject: [PATCH] prep for future work on search cache --- Makefile | 10 +++ bin/buildcache.py | 131 +++++++++++++++++++++++++++++++++++++ res/CACHE00.IDX | Bin 0 -> 2261 bytes res/CACHE01.IDX | Bin 0 -> 2385 bytes res/CACHE10.IDX | Bin 0 -> 2961 bytes res/CACHE11.IDX | Bin 0 -> 3495 bytes res/notes/search-cache.txt | 71 ++++++++++++++++++++ 7 files changed, 212 insertions(+) create mode 100755 bin/buildcache.py create mode 100644 res/CACHE00.IDX create mode 100644 res/CACHE01.IDX create mode 100644 res/CACHE10.IDX create mode 100644 res/CACHE11.IDX create mode 100644 res/notes/search-cache.txt diff --git a/Makefile b/Makefile index a6f2c0f80..21728c942 100644 --- a/Makefile +++ b/Makefile @@ -213,6 +213,16 @@ attract: compress bin/check-attract-mode.sh bin/generate-mini-attract-mode.sh +cache: md + awk -F= '/^00/ { print $$2 }' < res/GAMES.CONF | bin/buildcache.py > build/cache00.a + awk -F= '/^0/ { print $$2 }' < res/GAMES.CONF | bin/buildcache.py > build/cache01.a + awk -F= '/^.0/ { print $$2 }' < res/GAMES.CONF | bin/buildcache.py > build/cache10.a + awk -F= '!/^$$|^#|^\[/ { print $$2 }' < res/GAMES.CONF | bin/buildcache.py > build/cache11.a + $(ACME) -o res/CACHE00.IDX build/cache00.a + $(ACME) -o res/CACHE01.IDX build/cache01.a + $(ACME) -o res/CACHE10.IDX build/cache10.a + $(ACME) -o res/CACHE11.IDX build/cache11.a + mount: dsk osascript bin/V2Make.scpt "`pwd`" bin/4cade.vii build/"$(DISK)" diff --git a/bin/buildcache.py b/bin/buildcache.py new file mode 100755 index 000000000..6529c80f9 --- /dev/null +++ b/bin/buildcache.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 + +from collections import OrderedDict +from pprint import pprint +from string import ascii_lowercase +from sys import stdin + +def score(inputbuffer, displayname): + if len(inputbuffer) > len(displayname): + return 0, False + likely = True + startat = 0 + score = 0 + for c in inputbuffer: + x = 10 + y = displayname[startat:].find(c) + if y < 0: + return 0, False + if y == 0: + x = 80 + elif (startat > 0) and (displayname[startat+y-1] == " "): + x = 90 + else: + likely = False + score += x + startat += y + 1 + score = int((score/len(displayname)) + (score/len(inputbuffer))+0.99) + if (inputbuffer[0] == displayname[0]) and (score < 85): + score += 15 + return score, likely + +def best(keys, games): + gameindex = 0 + bestscore = -1 + bestindex = -1 + bestlikely = False + for game in games: + gamescore, likely = score(keys, game) + if (gamescore > bestscore): + bestscore = gamescore + bestindex = gameindex + bestlikely = likely + gameindex += 1 + if not bestlikely: + return 0 + return bestindex + +def main(): + games = [line.strip().lower() for line in stdin] + cache = OrderedDict() + for a in ascii_lowercase: + index1 = best(a, games) + if not index1: continue + cache[a] = OrderedDict() + cache[a][" "] = index1 + for b in ascii_lowercase: + index2 = best(a+b, games) + if not index2: continue + cache[a][b] = OrderedDict() + if index2 != index1: + cache[a][b][" "] = index2 + for c in ascii_lowercase: + index3 = best(a+b+c, games) + if not index3: continue + cache[a][b][c] = OrderedDict() + if index3 != index2: + cache[a][b][c][" "] = index3 + for d in ascii_lowercase: + index4 = best(a+b+c+d, games) + if not index4: continue + if index4 != index3: + cache[a][b][c][d] = index4 + if (len(cache[a][b][c]) == 1) and (" " in cache[a][b][c]): + cache[a][b][c] = cache[a][b][c][" "] + elif not cache[a][b][c]: + del cache[a][b][c] + if (len(cache[a][b]) == 1) and (" " in cache[a][b]): + cache[a][b] = cache[a][b][" "] + elif not cache[a][b]: + del cache[a][b] + if (len(cache[a]) == 1) and (" " in cache[a]): + cache[a] = cache[a][" "] + elif not cache[a]: + del cache[a] + + print('*=$B000') + for a in cache: + print(f' !text "{a}"') + if type(cache[a]) == int: + print(f' !word {cache[a]}') + else: + print(f' !word _{a}') + print(' !byte 0') + + for a in cache: + if type(cache[a]) == int: continue + print(f'_{a}') + for b in cache[a]: + print(f' !text "{b}"') + if type(cache[a][b]) == int: + print(f' !word {cache[a][b]}') + else: + print(f' !word _{a}{b}') + print(' !byte 0') + + for a in cache: + if type(cache[a]) == int: continue + for b in cache[a]: + if type(cache[a][b]) == int: continue + print(f'_{a}{b}') + for c in cache[a][b]: + print(f' !text "{c}"') + if type(cache[a][b][c]) == int: + print(f' !word {cache[a][b][c]}') + else: + print(f' !word _{a}{b}{c}') + print(' !byte 0') + + for a in cache: + if type(cache[a]) == int: continue + for b in cache[a]: + if type(cache[a][b]) == int: continue + for c in cache[a][b]: + if type(cache[a][b][c]) == int: continue + print(f'_{a}{b}{c}') + for d in cache[a][b][c]: + print(f' !text "{d}"') + print(f' !word {cache[a][b][c][d]}') + print(' !byte 0') + +main() diff --git a/res/CACHE00.IDX b/res/CACHE00.IDX new file mode 100644 index 0000000000000000000000000000000000000000..ffc25544ee1d0063aa16fca26dc02228de998050 GIT binary patch literal 2261 zcmYL~eVi3#701696tlouK7k1u7Zy@7phR8*Q^3kVOVgB>N_uAQ?7hRzy)(?**~?v( zKus|)c}<8UR4nB~w7Yla&ZH5bZ6KH?+DD)lp$tPrAbK&h>^!^h@vrCiob!9m+|Qo# zJ*%#6Gn(7XHEp?FZPwworuW+NgWC&}+HIqKj?>yI za}L*v<8e>c{Jv3eCE@328A)YiR2>tMor=0DGNzH68d+1YZ;ISmk)Mys*AO;K`pc+m zF|H+l9l=*g?%&5?U6eje@PVFLS=?HzJ*#7AmF3JlC@00X*QJ2QX63mIQ z^*!t+DRiSH|rnmkg?p*m{ubi9I@T&O+w2+)F|qz&sak zQWBgim-DpE>`ktZp60TClEKrNUOH3IfsbG`VD`mspgb)hI}9~Fu^MoPpeJ~sSo)#{ zAcIWy0@SUEIRNW??0z_fM50xl=!fAZ&Ol01r7BhW<6a2HAT$&or!)vZOE_4Zji@0Q zLqrY57>3zMenFy%xjSiHCNIZg4%d8?Rwv#gN$^Bc86n=`s4L|7G|njeQKClTo>rHk z#v)`1R?cTAwI$wI{IP`NsEiTgMAUf9E3mgD8nzutIEu;ys=C|++}-lYt1zxa03G~edY42O;@%_2-ITv0$0E#or8ffH{S+5d zT8w{6N+GQH!c4~ zLVrc}fp>`Dh+N)8oxuI4s5ekYagT~RjPpAF-$b269l=dl$W1WTnVH@t;pyGMQ=*y;$@TIkP@KsMkl= z?hrc9>;>$L2?j}#k9JYtU)0A?`ViVr?}!HcfihIXB=`y3Muh0D|9cnfi$=P13Dx0} zy;Q?Zb_Btv#D6*Y(aaswjp}D9PS9*(j1|Wi98LZ-3c_Rl7KAL#kOs(_4Pg#V0ohhP z|EI^UN?t!G4LK$=c>ucguRbYl`8 literal 0 HcmV?d00001 diff --git a/res/CACHE01.IDX b/res/CACHE01.IDX new file mode 100644 index 0000000000000000000000000000000000000000..aa4864c8c0ff512eb672837694499d4673ebedaa GIT binary patch literal 2385 zcmYL~dz4jm7018786JXzGQ1riPBJk{hC?QdhKdWs!a_423-R?kk9+T#IWNxR-noN@ zR3Jg5Nk|ic53&R#=FWKzsfl7BK?{f|9$7}Zs77pMkgu}+y94#tZ~yk*XP>j~{(iof z&+3xfx|Gf?bx)Vp+m)-S*>}TzDe@MebPqM;CN!cypq(fSPpQ)5WWkXsJ@VVKKdJ&a&EH9iV{eXQIWYxl;+YS>!rJ_c_U z{1pgRQ~7(~Ml3%LWpS)^LSGh}t7Ch8>}-wQDE3~Ai|eWBN8nqaZh`h{tnZD@XJK!F z^DNvg@HSDo3;J^~e+qjW+^qT^@`O~mG}W$1bBq;c zraG7{r>>rQUg{5J!BAGJXOKoR{h_otoT5>TuS(?xrjBNM1GC0ZYAn;nF>^e#$J2#@ z524vLP-~&DPmO*c75f7ybsm&Ka5ksjAi7*2+LSt|Lxk3S@d$$>Dg#8NAQD3%*FzZw zy&is)LYf4=Bh~6*PlV9-IBFRNJ{BZ%NDbh-Q)Mi)(a=YtbqtJyDHY11HWKoY)EEbg z2A!Zmqv)pwWC?RG*dgQCSvX-V5zM0j+&MU1SiP#@sAW z0fN<5jhfcz~eD`BpL^=$!U$12LMg#9QT-+})K9gjizF71xsTnlpz ztTk}e%=d*8`q`P=@p}l!me;`#W%6-ozo*Kd!C%jm6Ht4hoy-a+p}z$(ls*R` z?g`8(%^r<|2sYRPspdCyop3hX$?KXkNSx&cQEssdjj!b9m|QQE?|5JvoEBm zKa&SC=b9dGAYDc2X$TrUUO+8$)9dZUpO|Tn5)=>S2y+mAuH&~aVJejJO373F01>R?< ze;V>vV&U{Y;6D#@h9Der3w2C~AuMDb3Pg2&0f` zpWg8+di!BOJ431C;K!gGqv)IhV7y7UlR_RO2J~rw1kf%Penx1(`4_6&|Np|zt8TW2 e(PsO0>h=HM@&>T#@&<@aQdFi*((;_q4F3gELdo6$ literal 0 HcmV?d00001 diff --git a/res/CACHE10.IDX b/res/CACHE10.IDX new file mode 100644 index 0000000000000000000000000000000000000000..51222583040d7a23fb0d559402d7dfe4617068de GIT binary patch literal 2961 zcmY+Gdze&p8OOh`1eOIv6c>eMxFfLKLKGH6fn}Ekf#oV73%_&b%*2J3TB#=lTD#do5Hs@N5(d*HO zAL9$eA%0WMPKB!c! z+ML$jNSpi9(L-tHEZomoL?n)+B~Y+EDHqeB4w>*Rq;|>Z*I@R_Sgpw|%OLP=66G0b zZbn{`391>z&V+hUWO+tild0X1(K?VmjEv_pW)F(KoT=+YR&R0+WZbiv*g%Spr^b5; zfhrQ$GtxJ*a@TBdDk;6Qp-KvuW+NlBs*=^FlWAt7Fr?T#|+1Mfz!5~G#q(;b4$PV*h8HwFlMI&7&Q|G!nq!P$Ipq4=E2IuuG0%Z^f zvq}lfQSeuJ5dZWZ5Cgy~&kN3bjX-~hBUyO>l)g}VL;E1h-3DIxkN9|RNS|c2K`=_- zT;uv~h}ND|3bhozQHB80aHu2UduJGo;jl))ZSNI?qaclfIU4Mxf_cV3>gI)edt6)n zy~dHOs)k(Vv4@Nao;eB8X`VgXi%mj&B0tu6h=nYf47D5u7fpdGJgpL@;#rj}sDN3C zLN*8Hd~Q4dQ4QanlMqrpZ5oWI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`E_`l$M#Q(_0thfM!gL;KiHtQu0S785}ANW&F&%^RNZAk;a+*V(* z=`CEh@tq5)Ey-WwY6z+97d8~XT~f+?H#uFn=tklWlJDRwKsS9-FlT=X_A98_N9-Eh zG)vJb_2YP0=9?utmcFn_C0P~ZRPf~gJTjX^B}r4LXoT=Ix@iG>Msb60IHtJbGpVrR X75<7Bd@y=JR4lgM|M9xJY_t literal 0 HcmV?d00001 diff --git a/res/CACHE11.IDX b/res/CACHE11.IDX new file mode 100644 index 0000000000000000000000000000000000000000..e1b521d3a93aeb4765000b794473ca855ab78275 GIT binary patch literal 3495 zcmY+Gd$?6&9>>4G(#<96pmfouCMqJ8qLe}^b;OM6bW(cP+H3E<&RMs!E_yUh-n}vAuiy23*M8Qszn||Cv$iSA zx2ffA;Un9$L2Z$-ZPEI+*ez}P#cNzDC>5zkbQ)sEQbv!oS(CQ=rQNA%PeC9MpN+)AbW%&V zT*JqjA?&oWIIWrpFHdXh(y>P9zfYS{*w3fkJ!$Wav>zaNH;vFO5G_zz5WN}Rt%%=- z=EZzLE5yfXWf{~Z&~8U$74#!%EigC1UY2p!W`f@${wR`<@ikAN;Yl<;4s$E4 zUu2v%cZ^Ui|>#Fv5qSC9`^K*8BwaVK|?_Jq+&E7! ze8yvtXwNENB78h)PiG^0v$1_y{r#-*P1f$3b82#KZ}PuFP(uivO2KIy`jhCFQ~FVO z1ZkslksET+0i@rUGy9Mo$+;m47UvMUki^QIa(_AQ1{Z|02i z$(%#hJ30GM&N-HAnoREH@LPg4z@M$#CkcC;Q5Kl^UoGg>WB8J)QymG&J^u z-&&B5RR+N6312?%c)1(v!`azT216Z!@F3`eVT53v1^-Uop91mAf;JfTL`WHq;@u$- zBf)ZIak3^6Iv-+VK^+NgIRAOjFapNb0uPd`*LJ?)Tqya1F$&gT_|I{D8N^EkWi<5B zkUAd&DC3}C3Mu`IVU2@39>HtX#feZR!k!F9K}GwQLpe~09xQO}epF~V##?nzQDg*I z-HP^1IK7Hq-(q|w5;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rD3jP%rf@p-hyHPeEGoV* z6Hu>$btRHlapP+F5sAuCzC0T>ek4PCt>JWl*4p+6Lv&tC*2u&w#zGQ$uhKune#*sRXv&-mvK})0;e4rV=SKQY(>l2^@?$*tKS9Sy=%h4IRj*N#q*5LFUa6j2 omDm3i?odUYRV8|?W490$NHGtN;K2 literal 0 HcmV?d00001 diff --git a/res/notes/search-cache.txt b/res/notes/search-cache.txt new file mode 100644 index 000000000..caf8ddeab --- /dev/null +++ b/res/notes/search-cache.txt @@ -0,0 +1,71 @@ +; Search cache +; +; each record is 3 bytes +; byte 0: +; character or 0 (EOF) +; bytes 1-2: +; byte 2 bit 7=1 -> absolute address of subindex +; byte 2 bit 7=0 -> numerical index into gSearchStore +; +Root + !text "a" + !word a + + ;...b-z... + + !byte 0 ; EOF -> no cache hit +a + !text " " ; 'a' matches game index 1 + !word 1 + !text "a" + !word aa + !text "b" + !word ab + !text "c" + !word ac + !text "d" + !word ad + !text "f" + !word af + !text "g" + !word ag + !text "i" + !word ai + !text "l" + !word al + !text "m" + !word am + !text "n" + !word an + !text "p" + !word ap + !text "q" + !word aq + !text "r" + !word ar + !text "s" + !word as + !text "t" + !word at + !text "u" + !word au + !text "x" + !word ax + !text "z" + !word az + !byte 0 ; EOF -> no cache hit + +; +;... b-z indexes ... +; + +aa + !text " " ; 'aa' -> game index 3 + !word 3 + !text "a" ; 'aaa' -> 23 + !word 23 + !text "m" ; 'aam' -> 6 + !word 6 + !text "s" ; 'aas' -> 29 + !word 29 + !byte 0 ; EOF -> no cache hit