Skip to content

Commit 7eb0790

Browse files
committed
fix strings.hash() on 6502 CPU's. NOTE: now takes string pointer in AY instead of R0 on all platforms
1 parent 2fdd554 commit 7eb0790

File tree

8 files changed

+17
-55
lines changed

8 files changed

+17
-55
lines changed

compiler/res/prog8lib/strings.p8

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,18 @@ fail clc ; yes, no match found, return with c=0
391391
}}
392392
}
393393

394-
asmsub hash(str string @R0) -> ubyte @A {
394+
asmsub hash(str string @AY) -> ubyte @A {
395395
; experimental 8 bit hashing function.
396396
; hash(-1)=179; clear carry; hash(i) = ROL hash(i-1) XOR string[i]
397397
; On the English word list in /usr/share/dict/words it seems to have a pretty even distribution
398398
%asm {{
399+
sta P8ZP_SCRATCH_W1
400+
sty P8ZP_SCRATCH_W1+1
399401
lda #179
400402
sta P8ZP_SCRATCH_REG
401403
ldy #0
402404
clc
403-
- lda (cx16.r0),y
405+
- lda (P8ZP_SCRATCH_W1),y
404406
beq +
405407
rol P8ZP_SCRATCH_REG
406408
eor P8ZP_SCRATCH_REG

compiler/res/prog8lib/virtual/strings.p8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ strings {
179179
sub hash(str st) -> ubyte {
180180
; experimental 8 bit hashing function.
181181
; hash(-1)=179; hash(i) = ROL hash(i-1) XOR string[i]
182-
; (experimental because the quality of the resulting hash value still has to be determined)
182+
; On the English word list in /usr/share/dict/words it seems to have a pretty even distribution
183183
ubyte hashcode = 179
184184
ubyte ix
185185
sys.clear_carry()

docs/source/_static/symboldumps/skeletons-c128.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ strings {
238238
endswith (str st, str suffix) -> bool
239239
find (uword string @AY, ubyte character @X) -> ubyte @A, bool @Pc
240240
findstr (str haystack, str needle) -> ubyte
241-
hash (str string @R0) -> ubyte @A
241+
hash (str string @AY) -> ubyte @A
242242
isdigit (ubyte petsciichar @A) -> bool @Pc
243243
isletter (ubyte petsciichar @A) -> bool @Pc
244244
islower (ubyte petsciichar @A) -> bool @Pc

docs/source/_static/symboldumps/skeletons-c64.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ strings {
365365
endswith (str st, str suffix) -> bool
366366
find (uword string @AY, ubyte character @X) -> ubyte @A, bool @Pc
367367
findstr (str haystack, str needle) -> ubyte
368-
hash (str string @R0) -> ubyte @A
368+
hash (str string @AY) -> ubyte @A
369369
isdigit (ubyte petsciichar @A) -> bool @Pc
370370
isletter (ubyte petsciichar @A) -> bool @Pc
371371
islower (ubyte petsciichar @A) -> bool @Pc

docs/source/_static/symboldumps/skeletons-cx16.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ strings {
673673
endswith (str st, str suffix) -> bool
674674
find (uword string @AY, ubyte character @X) -> ubyte @A, bool @Pc
675675
findstr (str haystack, str needle) -> ubyte
676-
hash (str string @R0) -> ubyte @A
676+
hash (str string @AY) -> ubyte @A
677677
isdigit (ubyte petsciichar @A) -> bool @Pc
678678
isletter (ubyte petsciichar @A) -> bool @Pc
679679
islower (ubyte petsciichar @A) -> bool @Pc

docs/source/_static/symboldumps/skeletons-pet32.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ strings {
189189
endswith (str st, str suffix) -> bool
190190
find (uword string @AY, ubyte character @X) -> ubyte @A, bool @Pc
191191
findstr (str haystack, str needle) -> ubyte
192-
hash (str string @R0) -> ubyte @A
192+
hash (str string @AY) -> ubyte @A
193193
isdigit (ubyte petsciichar @A) -> bool @Pc
194194
isletter (ubyte petsciichar @A) -> bool @Pc
195195
islower (ubyte petsciichar @A) -> bool @Pc

docs/source/todo.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TODO
22
====
33

4+
45
...
56

67

@@ -56,6 +57,7 @@ IR/VM
5657
Libraries
5758
---------
5859
- Add split-word array sorting routines to sorting module?
60+
- cx16: _irq_dispatcher now only dispatches a single irq source, better to ROL/BCC to handle *all* possible (multiple) sources.
5961
- See if the raster interrupt handler on the C64 can be tweaked to be a more stable raster irq
6062
- pet32 target: make syslib more complete (missing kernal routines)?
6163
- need help with: PET disk routines (OPEN, SETLFS etc are not exposed as kernal calls)

examples/test.p8

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,15 @@
11
%zeropage basicsafe
22
%import textio
3+
%import strings
4+
35
main {
46
sub start() {
5-
byte @shared a = -1
6-
byte @shared b = -15
7-
ubyte @shared ub = 2
8-
const byte ca = -1
9-
const byte cb = -15
10-
const ubyte cub = 2
7+
str name1 = sc:"irmen de jong 123456789 the quick brown fox"
8+
str name2 = sc:"jumps over the lazy frog"
119

12-
txt.print_ub( a & b )
13-
txt.spc()
14-
txt.print_ub( a | b )
15-
txt.spc()
16-
txt.print_ub( a ^ b )
17-
txt.spc()
18-
txt.print_b( a << ub )
19-
txt.spc()
20-
txt.print_b( a >> ub )
21-
txt.nl()
22-
txt.print_ub( ca & cb )
23-
txt.spc()
24-
txt.print_ub( ca | cb )
25-
txt.spc()
26-
txt.print_ub( ca ^ cb )
27-
txt.spc()
28-
txt.print_b( ca << cub )
29-
txt.spc()
30-
txt.print_b( ca >> cub )
31-
txt.nl()
32-
33-
word @shared aw = -1
34-
word @shared bw = -15
35-
uword @shared uw = 2
36-
const word caw = -1
37-
const word cbw = -15
38-
const uword cuw = 2
39-
40-
txt.print_uw( aw & bw )
41-
txt.spc()
42-
txt.print_uw( aw | bw )
43-
txt.spc()
44-
txt.print_uw( aw ^ bw )
45-
txt.nl()
46-
txt.print_uw( caw & cbw )
47-
txt.spc()
48-
txt.print_uw( caw | cbw )
49-
txt.spc()
50-
txt.print_uw( caw ^ cbw )
51-
txt.nl()
52-
txt.print_w( cbw << cuw )
10+
txt.print_ub(strings.hash(name1))
5311
txt.spc()
54-
txt.print_w( cbw >> cuw )
12+
txt.print_ub(strings.hash(name2))
5513
txt.nl()
5614
}
5715
}

0 commit comments

Comments
 (0)