Added checksum
This commit is contained in:
parent
6884561c77
commit
140529c35e
|
@ -0,0 +1,50 @@
|
|||
|0100
|
||||
;data1a hash emit/long #0a18 DEO
|
||||
;data1b hash emit/long #0a18 DEOk DEO
|
||||
|
||||
;data2a hash emit/long #0a18 DEO
|
||||
;data2b hash emit/long #0a18 DEOk DEO
|
||||
|
||||
;data3a hash emit/long #0a18 DEO
|
||||
;data3b hash emit/long #0a18 DEOk DEO
|
||||
|
||||
;data4a hash emit/long #0a18 DEO
|
||||
;data4b hash emit/long #0a18 DEOk DEO
|
||||
|
||||
#010f DEO BRK
|
||||
|
||||
( hash function: run two 16-bit LCGs in parallel )
|
||||
( )
|
||||
( upper fn: x1=x0*9283+cc ; a is #2443 x0 is #1234 )
|
||||
( lower fn: y1=y0*4493+cc ; b is #118d y1 is #abcd )
|
||||
@hash ( s* -> x* y* )
|
||||
STH2 LIT2 2443 LIT2 1234 ( a* x0* [s*] )
|
||||
STH2r LIT2r 118d LIT2r abcd ( a* x0* s* [b* y0*] )
|
||||
&loop ( a* x* s* [b* y*] )
|
||||
LDAk DUP ?&ok ( a* x* s* c^ [b* y*] )
|
||||
POP POP2 NIP2 ( x* [b* y*] )
|
||||
STH2r POP2r JMP2r ( x* y* )
|
||||
&ok ( a* x* s* c^ [b* y*] )
|
||||
DUP STH2 STH2 ( a* x* [b* y* cc* s*] )
|
||||
OVR2 MUL2 OVR2r ( a* ax* [b* y* cc* s* cc*] )
|
||||
STH2r ADD2 STH2r STH2r ( a* ax+cc* s* cc* [b* y*] )
|
||||
OVR2r MUL2r STH2 ADD2r ( a* ax+cc* s* [b* by+cc*] )
|
||||
INC2 !&loop ( a* ax+cc s+1* [b* by+cc*] )
|
||||
|
||||
@emit ( n* -> )
|
||||
&long SWP2 emit/short
|
||||
&short SWP emit/byte
|
||||
&byte DUP #04 SFT emit/char
|
||||
&char #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r
|
||||
|
||||
@data1a "abc 00
|
||||
@data1b "ebc 00
|
||||
|
||||
@data2a "wigjewigjewigjewigjewigjewigjcncmnbegejgiwejgieg 00
|
||||
@data2b "wigjewigjewigjewigjewigjewigjcmcmnbegejgiwejgieg 00
|
||||
|
||||
@data3a "zzjiewgew 00
|
||||
@data3b "zzjiewge 00
|
||||
|
||||
@data4a "this 20 "is 20 "a 20 "test 00
|
||||
@data4b "this 20 "is 20 "a 20 "test. 00
|
|
@ -0,0 +1,38 @@
|
|||
// verified this matches hash.tal for tests
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uint32_t hash(uint8_t *input) {
|
||||
uint16_t x = 0x1234;
|
||||
uint16_t y = 0xabcd;
|
||||
uint16_t a = 0x2443;
|
||||
uint16_t b = 0x118d;
|
||||
uint8_t c;
|
||||
uint16_t cc;
|
||||
|
||||
while (c = *input) {
|
||||
cc = (c << 8) | c;
|
||||
x = (x * a) + cc;
|
||||
y = (y * b) + cc;
|
||||
input++;
|
||||
}
|
||||
|
||||
return (x << 16) | y;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("data1a %08x\n", hash("abc"));
|
||||
printf("data1b %08x\n", hash("ebc"));
|
||||
printf("\n");
|
||||
printf("data2a %08x\n", hash("wigjewigjewigjewigjewigjewigjcncmnbegejgiwejgieg"));
|
||||
printf("data2b %08x\n", hash("wigjewigjewigjewigjewigjewigjcmcmnbegejgiwejgieg"));
|
||||
printf("\n");
|
||||
printf("data3a %08x\n", hash("zzjiewgew"));
|
||||
printf("data3b %08x\n", hash("zzjiewge"));
|
||||
printf("\n");
|
||||
printf("data4a %08x\n", hash("this is a test"));
|
||||
printf("data4b %08x\n", hash("this is a test."));
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
( usage: uxncli checksum.rom file.bin )
|
||||
|
||||
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|
||||
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|
||||
|0000
|
||||
|
||||
@src $40
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
;await-src .Console/vector DEO2
|
||||
;dict/input pstr #0a18 DEO
|
||||
|
||||
BRK
|
||||
|
||||
@await-src ( -> )
|
||||
|
||||
.Console/read DEI .src skey
|
||||
?on-ready
|
||||
|
||||
BRK
|
||||
|
||||
@on-ready ( -> )
|
||||
|
||||
;src hash plong #0a18 DEO
|
||||
#010f DEO
|
||||
|
||||
BRK
|
||||
|
||||
@hash ( filename* -- x* y* )
|
||||
|
||||
.File/name DEO2
|
||||
#0001 .File/length DEO2
|
||||
#1234 ,&x STR2 #abcd ,&y STR2
|
||||
#2443 ,&a STR2 #118d ,&b STR2
|
||||
&w
|
||||
;&c .File/read DEO2
|
||||
.File/success DEI2 #0000 EQU2 ?&end
|
||||
[ LIT &c $1 ] DUP DUP2
|
||||
[ LIT2 &x $2 ] [ LIT2 &a $2 ] MUL2 ADD2 ,&x STR2
|
||||
[ LIT2 &y $2 ] [ LIT2 &b $2 ] MUL2 ADD2 ,&y STR2
|
||||
!&w
|
||||
&end
|
||||
,&x LDR2 ,&y LDR2
|
||||
|
||||
JMP2r
|
||||
|
||||
@scap ( str* -- end* )
|
||||
LDAk #00 NEQ [ JMP JMP2r ] &w INC2 LDAk ?&w JMP2r
|
||||
@sput ( chr str* -- )
|
||||
scap STA JMP2r
|
||||
@skey ( key buf -- proc )
|
||||
OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
|
||||
@pstr ( str* -- )
|
||||
&w LDAk #18 DEO INC2 LDAk ?&w POP2 JMP2r
|
||||
@plong ( a* b* -> )
|
||||
SWP2 plong/s
|
||||
&s SWP plong/b
|
||||
&b DUP #04 SFT plong/c
|
||||
&c #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r
|
||||
@dict
|
||||
&input "Input(.tal): 20 $1
|
||||
|
|
@ -0,0 +1 @@
|
|||
wigjewigjewigjewigjewigjewigjcncmnbegejgiwejgieg
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
aabbccddŒ
|
|
@ -0,0 +1,102 @@
|
|||
( decompressor )
|
||||
|
||||
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1
|
||||
|a0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|b0 @File2 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|
||||
|0000
|
||||
|
||||
@input-size $2
|
||||
|
||||
@src $30
|
||||
@ptr $1
|
||||
|
||||
|0100
|
||||
|
||||
(
|
||||
@|vectors )
|
||||
|
||||
@ready-src ( -> ) ;&await .Console/vector DEO2 BRK
|
||||
&await ( -> ) .Console/read DEI .src skey ?on-ready BRK
|
||||
|
||||
@on-ready ( -> )
|
||||
|
||||
;src decompress
|
||||
;mem pstr #0a18 DEO
|
||||
( halt ) #010f DEO
|
||||
|
||||
BRK
|
||||
|
||||
@decompress ( str* -- )
|
||||
|
||||
;mem .ptr STZ2
|
||||
.File1/name DEO2
|
||||
#0001 .input-size STZ2
|
||||
&stream
|
||||
.input-size LDZ2 .File1/length DEO2
|
||||
;&b
|
||||
DUP2 .File1/read DEO2
|
||||
LDA decompress/run
|
||||
.File1/success DEI2 ORA ?&stream
|
||||
|
||||
JMP2r
|
||||
&b $1
|
||||
|
||||
&run ( byte -- )
|
||||
|
||||
DUP #80 AND ?&dict
|
||||
( literal )
|
||||
#00 SWP INC2
|
||||
DUP2 .File1/length DEO2
|
||||
.ptr LDZ2
|
||||
DUP2 .File1/read DEO2
|
||||
ADD2 .ptr STZ2
|
||||
|
||||
JMP2r
|
||||
|
||||
&dict ( byte -- )
|
||||
|
||||
#7f AND
|
||||
DUP #40 AND ?&dict3
|
||||
( byte )
|
||||
#00 SWP !&opc
|
||||
|
||||
&dict3 ( byte -- )
|
||||
|
||||
( hb )
|
||||
#3f AND
|
||||
( lb )
|
||||
#0001 .File1/length DEO2
|
||||
;&b
|
||||
DUP2 .File1/read DEO2
|
||||
LDA
|
||||
|
||||
&opc #0004 ADD2
|
||||
|
||||
;&b
|
||||
DUP2 .File1/read DEO2
|
||||
LDA INC
|
||||
|
||||
© ( length* offset -- )
|
||||
|
||||
#00 SWP #0000 SWP2 SUB2 .ptr LDZ2 ADD2 STH2
|
||||
#0000
|
||||
&l
|
||||
DUP2 STH2kr ADD2 LDA .ptr LDZ2 STH2k STA
|
||||
STH2r INC2 .ptr STZ2
|
||||
INC2 GTH2k ?&l
|
||||
POP2 POP2
|
||||
POP2r
|
||||
|
||||
JMP2r
|
||||
|
||||
(
|
||||
@|stdlib )
|
||||
|
||||
@pstr ( str* -- ) LDAk ?&w POP2 JMP2r &w LDAk #18 DEO INC2 LDAk ?&w POP2 JMP2r
|
||||
@skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
|
||||
@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r
|
||||
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r
|
||||
|
||||
@mem
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
( decompressor )
|
||||
|
||||
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1
|
||||
|a0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|b0 @File2 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
||||
|
||||
|0000
|
||||
|
||||
@input-size $2
|
||||
|
||||
@src $30
|
||||
@dst $30
|
||||
@ptr $1
|
||||
|
||||
|0100
|
||||
|
||||
(
|
||||
@|vectors )
|
||||
|
||||
@ready-src ( -> ) ;&await .Console/vector DEO2 BRK
|
||||
&await ( -> ) .Console/read DEI .src skey ?ready-dst BRK
|
||||
@ready-dst ( -> ) ;&await .Console/vector DEO2 BRK
|
||||
&await ( -> ) .Console/read DEI .dst skey ?on-ready BRK
|
||||
|
||||
@on-ready ( -> )
|
||||
|
||||
;src decompress
|
||||
;mem pstr #0a18 DEO
|
||||
( debug ) #010e DEO
|
||||
( halt ) #010f DEO
|
||||
|
||||
BRK
|
||||
|
||||
@decompress ( str* -- )
|
||||
|
||||
;mem .ptr STZ2
|
||||
.File1/name DEO2
|
||||
#0001 .input-size STZ2
|
||||
&stream
|
||||
.input-size LDZ2 .File1/length DEO2
|
||||
;&b
|
||||
DUP2 .File1/read DEO2
|
||||
LDA decompress/run
|
||||
.File1/success DEI2 ORA ?&stream
|
||||
|
||||
JMP2r
|
||||
&b $1
|
||||
|
||||
&run ( byte -- )
|
||||
|
||||
DUP #80 AND ?&dict
|
||||
( literal )
|
||||
#00 SWP INC2 !do-literal
|
||||
|
||||
&dict ( byte -- )
|
||||
|
||||
#7f AND
|
||||
DUP #40 AND ?&dict3
|
||||
( 1 byte )
|
||||
#00 SWP #0004 ADD2
|
||||
( offset )
|
||||
;&b .File1/read DEO2
|
||||
;&b LDA INC
|
||||
|
||||
!do-copy
|
||||
|
||||
&dict3 ( byte -- )
|
||||
|
||||
( hb )
|
||||
#3f AND
|
||||
( lb )
|
||||
#0001 .File1/length DEO2
|
||||
;&b .File1/read DEO2
|
||||
;&b LDA #0004 ADD2
|
||||
( offset )
|
||||
;&b .File1/read DEO2
|
||||
;&b LDA INC
|
||||
|
||||
!do-copy
|
||||
|
||||
@do-copy ( length* offset -- )
|
||||
|
||||
#00 SWP #0000 SWP2 SUB2 .ptr LDZ2 ADD2 STH2
|
||||
#0000
|
||||
&l
|
||||
DUP2 STH2kr ADD2 LDA do-append
|
||||
INC2 GTH2k ?&l
|
||||
POP2 POP2
|
||||
POP2r
|
||||
|
||||
JMP2r
|
||||
|
||||
@do-append ( byte -- )
|
||||
|
||||
.ptr LDZ2 STH2k STA
|
||||
STH2r INC2 .ptr STZ2
|
||||
|
||||
JMP2r
|
||||
|
||||
@do-literal ( length* -- )
|
||||
|
||||
DUP2 .File1/length DEO2
|
||||
.ptr LDZ2
|
||||
DUP2 .File1/read DEO2
|
||||
ADD2 .ptr STZ2
|
||||
|
||||
JMP2r
|
||||
|
||||
(
|
||||
@|stdlib )
|
||||
|
||||
@pstr ( str* -- ) LDAk ?&w POP2 JMP2r &w LDAk #18 DEO INC2 LDAk ?&w POP2 JMP2r
|
||||
@skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
|
||||
@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r
|
||||
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r
|
||||
|
||||
@mem
|
||||
|
|
@ -0,0 +1 @@
|
|||
aabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaab
|
Loading…
Reference in New Issue