Skip to content

Commit 49f8a2e

Browse files
committed
Improve zstring 10bit zscii de/en coding
1 parent 2775eae commit 49f8a2e

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

gork/zmemory.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ func (zmem *ZMemorySequential) DecodeZString(header *ZHeader) string {
150150

151151
if alphabet == 2 && code == 0 {
152152
asciiPart = 1
153-
} else if alphabet == 2 && code == 1 {
154-
ret += "\n"
155153
} else {
156154
ret += string(Alphabets[alphabet][code])
157155
}
@@ -202,8 +200,10 @@ func ZStringEncode(what string) [encodedZstringLen]uint16 {
202200
}
203201

204202
if i < 0 {
205-
// :)
206-
i = strings.IndexByte(Alphabets[2], '?')
203+
// 10 bit zscii
204+
writeChar(0x06)
205+
writeChar(what[c] >> 5)
206+
writeChar(what[c] & 0x1F)
207207
}
208208

209209
writeChar(byte(i + 6))

gork/zmemory_test.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gork
33
import (
44
"encoding/binary"
55
"fmt"
6-
"strings"
76
"testing"
87
)
98

@@ -33,13 +32,15 @@ var encodedZstrings []string = []string{
3332
"i",
3433
"42,",
3534
"$",
35+
"\n",
3636
}
3737
var encodedZstringsExpected [][]uint16 = [][]uint16{
3838
[]uint16{0x7E97, 0xC0A5},
3939
[]uint16{0x23C8, 0xC695},
4040
[]uint16{0x38A5, 0x94A5},
4141
[]uint16{0x1585, 0xA8B3},
42-
[]uint16{0x16A5, 0x94A5},
42+
[]uint16{0x14C1, 0x90A5},
43+
[]uint16{0x14E5, 0x94A5},
4344
}
4445

4546
var byteOrder binary.ByteOrder = binary.BigEndian
@@ -238,7 +239,6 @@ func TestZStringEncode(t *testing.T) {
238239

239240
for i := range encoded {
240241
if encoded[i] != expected[i] {
241-
fmt.Printf("%X %X\n", encoded[i], expected[i])
242242
t.Fail()
243243
}
244244

@@ -251,23 +251,8 @@ func TestZStringEncode(t *testing.T) {
251251
seq := ZMemory(buf)
252252
decoded := seq.DecodeZStringAt(0, nil)
253253

254-
for j := range decoded {
255-
ch := decoded[j]
256-
257-
// default value if not found
258-
expCh := byte('?')
259-
260-
for _, alph := range Alphabets {
261-
if strings.IndexByte(alph, ch) >= 0 {
262-
expCh = ch
263-
break
264-
}
265-
}
266-
267-
if ch != expCh {
268-
t.Fail()
269-
}
270-
254+
if decoded != zstr {
255+
t.Fail()
271256
}
272257
}
273258

0 commit comments

Comments
 (0)