2017-10-21 23:40:19 +00:00
|
|
|
mcopy ccommon.macros
|
|
|
|
****************************************************************
|
|
|
|
*
|
|
|
|
* CopyString - copy a string
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* toPtr - location to copy to
|
|
|
|
* fromPtr - location to copy from
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
*
|
2017-06-19 03:07:32 +00:00
|
|
|
CopyString start cc
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
subroutine (4:toPtr,4:fromPtr),0
|
|
|
|
|
|
|
|
short I,M
|
|
|
|
lda [fromPtr]
|
|
|
|
sta [toPtr]
|
|
|
|
tay
|
|
|
|
lb1 lda [fromPtr],Y
|
|
|
|
sta [toPtr],Y
|
|
|
|
dey
|
|
|
|
bne lb1
|
|
|
|
long I,M
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
****************************************************************
|
|
|
|
*
|
|
|
|
* Hash - find hash displacement
|
|
|
|
*
|
|
|
|
* Finds the displacement into an array of pointers using a
|
|
|
|
* hash function.
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* sPtr - points to string to find hash for
|
|
|
|
*
|
|
|
|
* Outputs:
|
|
|
|
* Returns the disp into the hash table
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
*
|
2017-06-19 03:07:32 +00:00
|
|
|
Hash start cc
|
2017-10-21 23:40:19 +00:00
|
|
|
hashSize equ 876 # hash buckets - 1
|
|
|
|
|
2023-03-07 03:54:14 +00:00
|
|
|
disp equ 0 disp into hash table
|
2017-10-21 23:40:19 +00:00
|
|
|
length equ 2 length of string
|
|
|
|
|
|
|
|
subroutine (4:sPtr),4
|
|
|
|
|
|
|
|
lda [sPtr] set the length of the string
|
2023-03-07 03:54:14 +00:00
|
|
|
tax
|
2017-10-21 23:40:19 +00:00
|
|
|
and #$00FF
|
|
|
|
sta length
|
|
|
|
ldy #1 start with char 1
|
2023-03-07 03:54:14 +00:00
|
|
|
txa if 1st char is '~', start with char 6
|
2017-10-21 23:40:19 +00:00
|
|
|
and #$FF00
|
|
|
|
cmp #'~'*256
|
2023-03-07 03:54:14 +00:00
|
|
|
bne lb0
|
2017-10-21 23:40:19 +00:00
|
|
|
ldy #6
|
|
|
|
|
2023-03-07 03:54:14 +00:00
|
|
|
lb0 lda #0 initial value is 0
|
|
|
|
bra lb2 while there are at least 2 chars left
|
|
|
|
lb1 asl a rotate sum left one bit
|
|
|
|
adc [sPtr],Y add in next two bytes
|
|
|
|
iny advance two chars
|
2017-10-21 23:40:19 +00:00
|
|
|
iny
|
2023-03-07 03:54:14 +00:00
|
|
|
lb2 cpy length
|
|
|
|
blt lb1
|
|
|
|
bne lb3 if there is 1 char left then
|
|
|
|
asl a rotate sum left one bit
|
|
|
|
sta disp
|
|
|
|
lda [sPtr],Y
|
|
|
|
and #$00FF and out the high byte
|
|
|
|
adc disp add last byte to the sum
|
|
|
|
sec
|
|
|
|
lb3 sbc #hashSize+1 disp := (sum mod (hashSize+1)) << 2
|
|
|
|
bcs lb3
|
|
|
|
adc #hashSize+1
|
|
|
|
asl a
|
|
|
|
asl a
|
|
|
|
sta disp
|
2017-10-21 23:40:19 +00:00
|
|
|
|
2023-03-07 03:54:14 +00:00
|
|
|
return 2:disp return disp
|
2017-10-21 23:40:19 +00:00
|
|
|
end
|