Skip to content

Commit de11d13

Browse files
author
Ben Hoyt
committed
Fix issue with indexing of plain "string" types
1 parent d43247b commit de11d13

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-25
lines changed

converted/elements.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,14 @@ func ElementTransporterTick(statId int16) {
584584
func ElementTransporterDraw(x, y int16, ch *byte) {
585585
stat := &Board.Stats[GetStatIdAt(x, y)]
586586
if stat.StepX == 0 {
587-
*ch = Ord(TransporterNSChars[stat.StepY*2+3+CurrentTick/stat.Cycle%4])
587+
*ch = Ord(TransporterNSChars[stat.StepY*2+3+CurrentTick/stat.Cycle%4-1])
588588
} else {
589-
*ch = Ord(TransporterEWChars[stat.StepX*2+3+CurrentTick/stat.Cycle%4])
589+
*ch = Ord(TransporterEWChars[stat.StepX*2+3+CurrentTick/stat.Cycle%4-1])
590590
}
591591
}
592592

593593
func ElementStarDraw(x, y int16, ch *byte) {
594-
*ch = Ord(StarAnimChars[CurrentTick%4+1])
594+
*ch = Ord(StarAnimChars[CurrentTick%4+1-1])
595595
Board.Tiles[x][y].Color++
596596
if Board.Tiles[x][y].Color > 15 {
597597
Board.Tiles[x][y].Color = 9

converted/errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
./oop.go:675:17: cannot use Board.Stats[labelStatId].Data (type *string) as type *uintptr in assignment
2626
./oop.go:781:23: invalid operation: OopChar + OopReadLineToEnd(statId, position) (mismatched types byte and string)
2727
./sounds.go:107:18: cannot use drum.Data[i - 1] (type uint16) as type int16 in argument to Sound
28-
./sounds.go:169:26: cannot use SoundFreqTable[Ord(SoundBuffer[SoundBufferPos]) - 1] (type uint16) as type int16 in argument to Sound
28+
./sounds.go:169:26: cannot use SoundFreqTable[Ord(SoundBuffer[SoundBufferPos - 1]) - 1] (type uint16) as type int16 in argument to Sound
2929
./sounds.go:274:3: duplicate case '3' (value 51) in switch
3030
previous case at ./sounds.go:225:8
3131
./sounds.go:298:17: cannot use &SoundTimerHandler (type *func()) as type *uintptr in assignment
3232
./sounds.go:298:19: cannot take the address of SoundTimerHandler
33-
./txtwind.go:51:12: cannot assign to input[i]
33+
./txtwind.go:51:14: cannot assign to input[i - 1]
3434
./txtwind.go:117:32: invalid operation: state.Lines[lpos - 1][0] (type *string does not support indexing)

converted/game.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ func SidebarPromptSlider(editable bool, x, y int16, prompt string, value *byte)
343343
newValue int16
344344
startChar, endChar byte
345345
)
346-
if prompt[Length(prompt)-2] == ';' {
347-
startChar = prompt[Length(prompt)-1]
348-
endChar = prompt[Length(prompt)]
346+
if prompt[Length(prompt)-2-1] == ';' {
347+
startChar = prompt[Length(prompt)-1-1]
348+
endChar = prompt[Length(prompt)-1]
349349
prompt = Copy(prompt, 1, Length(prompt)-3)
350350
} else {
351351
startChar = '1'
@@ -393,15 +393,15 @@ func SidebarPromptChoice(editable bool, y int16, prompt, choiceStr string, resul
393393
VideoWriteText(63, y+2, 0x1E, choiceStr)
394394
choiceCount = 1
395395
for i = 1; i <= Length(choiceStr); i++ {
396-
if choiceStr[i] == ' ' {
396+
if choiceStr[i-1] == ' ' {
397397
choiceCount++
398398
}
399399
}
400400
for {
401401
j = 0
402402
i = 1
403403
for j < int16(*result) && i < Length(choiceStr) {
404-
if choiceStr[i] == ' ' {
404+
if choiceStr[i-1] == ' ' {
405405
j++
406406
}
407407
i++

converted/input.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func InputUpdate() {
183183
}
184184
}
185185
if Length(InputKeyBuffer) != 0 {
186-
InputKeyPressed = InputKeyBuffer[1]
186+
InputKeyPressed = InputKeyBuffer[0]
187187
if Length(InputKeyBuffer) == 1 {
188188
InputKeyBuffer = ""
189189
} else {

converted/oop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func OopFindString(statId int16, s string) (OopFindString int16) {
160160
cmpPos = pos
161161
for {
162162
OopReadChar(statId, &cmpPos)
163-
if UpCase(s[wordPos]) != UpCase(OopChar) {
163+
if UpCase(s[wordPos-1]) != UpCase(OopChar) {
164164
goto NoMatch
165165
}
166166
wordPos++

converted/sounds.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ func SoundTimerHandler() {
163163
NoSound()
164164
SoundIsPlaying = false
165165
} else {
166-
if SoundBuffer[SoundBufferPos] == '\x00' {
166+
if SoundBuffer[SoundBufferPos-1] == '\x00' {
167167
NoSound()
168-
} else if SoundBuffer[SoundBufferPos] < '\xf0' {
169-
Sound(SoundFreqTable[Ord(SoundBuffer[SoundBufferPos])-1])
168+
} else if SoundBuffer[SoundBufferPos-1] < '\xf0' {
169+
Sound(SoundFreqTable[Ord(SoundBuffer[SoundBufferPos-1])-1])
170170
} else {
171-
SoundPlayDrum(&SoundDrumTable[Ord(SoundBuffer[SoundBufferPos])-240])
171+
SoundPlayDrum(&SoundDrumTable[Ord(SoundBuffer[SoundBufferPos-1])-240])
172172
}
173173

174174
SoundBufferPos++
175-
SoundDurationCounter = SoundDurationMultiplier * Ord(SoundBuffer[SoundBufferPos])
175+
SoundDurationCounter = SoundDurationMultiplier * Ord(SoundBuffer[SoundBufferPos-1])
176176
SoundBufferPos++
177177
}
178178
}
@@ -200,7 +200,7 @@ func SoundParse(input string) (SoundParse string) {
200200
noteDuration = 1
201201
for Length(input) != 0 {
202202
noteTone = -1
203-
switch UpCase(input[1]) {
203+
switch UpCase(input[0]) {
204204
case 'T':
205205
noteDuration = 1
206206
AdvanceInput()
@@ -236,7 +236,7 @@ func SoundParse(input string) (SoundParse string) {
236236
}
237237
AdvanceInput()
238238
case 'A', 'B', 'C', 'D', 'E', 'F', 'G':
239-
switch UpCase(input[1]) {
239+
switch UpCase(input[0]) {
240240
case 'C':
241241
noteTone = 0
242242
AdvanceInput()
@@ -259,7 +259,7 @@ func SoundParse(input string) (SoundParse string) {
259259
noteTone = 11
260260
AdvanceInput()
261261
}
262-
switch UpCase(input[1]) {
262+
switch UpCase(input[0]) {
263263
case '!':
264264
noteTone--
265265
AdvanceInput()
@@ -272,7 +272,7 @@ func SoundParse(input string) (SoundParse string) {
272272
output += "\x00" + Chr(byte(noteDuration))
273273
AdvanceInput()
274274
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
275-
output += Chr(Ord(input[1])+0xF0-Ord('0')) + Chr(byte(noteDuration))
275+
output += Chr(Ord(input[0])+0xF0-Ord('0')) + Chr(byte(noteDuration))
276276
AdvanceInput()
277277
default:
278278
AdvanceInput()

converted/txtwind.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var (
4848
func UpCaseString(input string) (UpCaseString string) {
4949
var i int16
5050
for i = 1; i <= Length(input); i++ {
51-
input[i] = string(UpCase(input[i]))
51+
input[i-1] = string(UpCase(input[i-1]))
5252
}
5353
UpCaseString = input
5454
return
@@ -179,7 +179,7 @@ func TextWindowPrint(state *TTextWindowState) {
179179
for iLine = 1; iLine <= state.LineCount; iLine++ {
180180
line = *state.Lines[iLine-1]
181181
if Length(line) > 0 {
182-
switch line[1] {
182+
switch line[0] {
183183
case '$':
184184
line = Delete(line, 1, 1)
185185
for iChar = (80 - Length(line)) / 2; iChar >= 1; iChar-- {

converted/zzt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ func ParseArguments() {
99
)
1010
for i = 1; i <= ParamCount; i++ {
1111
pArg = ParamStr(i)
12-
if pArg[1] == '/' {
13-
switch UpCase(pArg[2]) {
12+
if pArg[0] == '/' {
13+
switch UpCase(pArg[1]) {
1414
case 'T':
1515
SoundTimeCheckCounter = 0
1616
UseSystemTimeForElapsed = false

converter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,10 @@ func (c *converter) varExpr(expr Expr, suppressStar bool) {
11811181
min = spec.Min.(*ConstExpr).Value.(int)
11821182
case *StringSpec:
11831183
min = 1
1184+
case *IdentSpec:
1185+
if strings.ToLower(spec.Type.Name) == "string" {
1186+
min = 1
1187+
}
11841188
}
11851189

11861190
c.print("[")

0 commit comments

Comments
 (0)