Skip to content

Commit

Permalink
Start of tcell video code; Fix plain string indexing off-by-1 error
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Apr 23, 2020
1 parent 2df5e28 commit 4ca1abf
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
zztgo
.idea/
*.ZZT
*.hex
6 changes: 3 additions & 3 deletions elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ func ElementTransporterTick(statId int16) {
func ElementTransporterDraw(x, y int16, ch *byte) {
stat := &Board.Stats[GetStatIdAt(x, y)]
if stat.StepX == 0 {
*ch = Ord(TransporterNSChars[stat.StepY*2+3+CurrentTick/stat.Cycle%4])
*ch = Ord(TransporterNSChars[stat.StepY*2+3+CurrentTick/stat.Cycle%4-1])
} else {
*ch = Ord(TransporterEWChars[stat.StepX*2+3+CurrentTick/stat.Cycle%4])
*ch = Ord(TransporterEWChars[stat.StepX*2+3+CurrentTick/stat.Cycle%4-1])
}
}

func ElementStarDraw(x, y int16, ch *byte) {
*ch = Ord(StarAnimChars[CurrentTick%4+1])
*ch = Ord(StarAnimChars[CurrentTick%4])
Board.Tiles[x][y].Color++
if Board.Tiles[x][y].Color > 15 {
Board.Tiles[x][y].Color = 9
Expand Down
18 changes: 11 additions & 7 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main // unit: Game

import (
"os"
"time"
)

// interface uses: GameVars, TxtWind
Expand Down Expand Up @@ -284,8 +285,6 @@ func BoardDrawTile(x, y int16) {
} else {
if tile.Element == E_TEXT_WHITE {
VideoWriteText(x-1, y-1, 0x0F, Chr(Board.Tiles[x][y].Color))
} else if VideoMonochrome {
VideoWriteText(x-1, y-1, byte((int16(tile.Element-E_TEXT_MIN)+1)*16), Chr(Board.Tiles[x][y].Color))
} else {
VideoWriteText(x-1, y-1, byte((int16(tile.Element-E_TEXT_MIN)+1)*16+0x0F), Chr(Board.Tiles[x][y].Color))
}
Expand All @@ -295,6 +294,7 @@ func BoardDrawTile(x, y int16) {
} else {
VideoWriteText(x-1, y-1, 0x07, "\xb0")
}
VideoShow() // TODO: very inefficient
}

func BoardDrawBorder() {
Expand Down Expand Up @@ -353,9 +353,9 @@ func SidebarPromptSlider(editable bool, x, y int16, prompt string, value *byte)
newValue int16
startChar, endChar byte
)
if prompt[Length(prompt)-2] == ';' {
startChar = prompt[Length(prompt)-1]
endChar = prompt[Length(prompt)]
if prompt[Length(prompt)-3] == ';' {
startChar = prompt[Length(prompt)-2]
endChar = prompt[Length(prompt)-1]
prompt = Copy(prompt, 1, Length(prompt)-3)
} else {
startChar = '1'
Expand Down Expand Up @@ -400,15 +400,15 @@ func SidebarPromptChoice(editable bool, y int16, prompt, choiceStr string, resul
VideoWriteText(63, y+2, 0x1E, choiceStr)
choiceCount = 1
for i = 1; i <= Length(choiceStr); i++ {
if choiceStr[i] == ' ' {
if choiceStr[i-1] == ' ' {
choiceCount++
}
}
for {
j = 0
i = 1
for j < int16(*result) && i < Length(choiceStr) {
if choiceStr[i] == ' ' {
if choiceStr[i-1] == ' ' {
j++
}
i++
Expand Down Expand Up @@ -1319,6 +1319,7 @@ func GamePlayLoop(boardChanged bool) {

GameDrawSidebar()
GameUpdateSidebar()

if JustStarted {
// TODO: GameAboutScreen()
if Length(StartupWorldFileName) != 0 {
Expand Down Expand Up @@ -1397,6 +1398,9 @@ func GamePlayLoop(boardChanged bool) {
}
}
if CurrentStatTicked > Board.StatCount && !GamePlayExitRequested {
time.Sleep(10*time.Millisecond) // TODO
VideoShow() // TODO

if SoundHasTimeElapsed(&TickTimeCounter, TickTimeDuration) {
CurrentTick++
if CurrentTick > 420 {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/benhoyt/zztgo

go 1.13

require github.com/gdamore/tcell v1.3.0
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2 changes: 1 addition & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func InputUpdate() {
}
}
if Length(InputKeyBuffer) != 0 {
InputKeyPressed = InputKeyBuffer[1]
InputKeyPressed = InputKeyBuffer[0]
if Length(InputKeyBuffer) == 1 {
InputKeyBuffer = ""
} else {
Expand Down
29 changes: 0 additions & 29 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,6 @@ func GetTime(h, m, s, s100 *uint16) {

var Time int16 // TODO

func VideoWriteText(x, y int16, color byte, text string) {
// TODO
}

func VideoMove(x, y, chars int16, data interface{}, toVideo bool) {
// TODO
}

func VideoHideCursor() {} // TODO
func VideoShowCursor() {} // TODO
func VideoInstall(columns, borderColor int16) {} // TODO
func VideoUninstall() {} // TODO
func ClrScr() {} // TODO

func TextColor(color byte) {
// TODO
}

const (
Blue = 1
LightGray = 7
)

func GotoXY(x, y int16) {
// TODO
}

var VideoMonochrome bool

func Delay(milliseconds int16) {
time.Sleep(time.Duration(milliseconds) * time.Millisecond)
}
Expand Down
2 changes: 1 addition & 1 deletion oop.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func OopFindString(statId int16, s string) (OopFindString int16) {
cmpPos = pos
for {
OopReadChar(statId, &cmpPos)
if UpCase(s[wordPos]) != UpCase(OopChar) {
if UpCase(s[wordPos-1]) != UpCase(OopChar) {
goto NoMatch
}
wordPos++
Expand Down
18 changes: 9 additions & 9 deletions sounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ func SoundTimerHandler() {
NoSound()
SoundIsPlaying = false
} else {
if SoundBuffer[SoundBufferPos] == '\x00' {
if SoundBuffer[SoundBufferPos-1] == '\x00' {
NoSound()
} else if SoundBuffer[SoundBufferPos] < '\xf0' {
Sound(SoundFreqTable[Ord(SoundBuffer[SoundBufferPos])-1])
} else if SoundBuffer[SoundBufferPos-1] < '\xf0' {
Sound(SoundFreqTable[Ord(SoundBuffer[SoundBufferPos-1])-1])
} else {
SoundPlayDrum(&SoundDrumTable[Ord(SoundBuffer[SoundBufferPos])-240])
SoundPlayDrum(&SoundDrumTable[Ord(SoundBuffer[SoundBufferPos-1])-240])
}

SoundBufferPos++
SoundDurationCounter = SoundDurationMultiplier * Ord(SoundBuffer[SoundBufferPos])
SoundDurationCounter = SoundDurationMultiplier * Ord(SoundBuffer[SoundBufferPos-1])
SoundBufferPos++
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ func SoundParse(input string) (SoundParse string) {
noteDuration = 1
for Length(input) != 0 {
noteTone = -1
switch UpCase(input[1]) {
switch UpCase(input[0]) {
case 'T':
noteDuration = 1
AdvanceInput()
Expand Down Expand Up @@ -237,7 +237,7 @@ func SoundParse(input string) (SoundParse string) {
}
AdvanceInput()
case 'A', 'B', 'C', 'D', 'E', 'F', 'G':
switch UpCase(input[1]) {
switch UpCase(input[0]) {
case 'C':
noteTone = 0
AdvanceInput()
Expand All @@ -260,7 +260,7 @@ func SoundParse(input string) (SoundParse string) {
noteTone = 11
AdvanceInput()
}
switch UpCase(input[1]) {
switch UpCase(input[0]) {
case '!':
noteTone--
AdvanceInput()
Expand All @@ -273,7 +273,7 @@ func SoundParse(input string) (SoundParse string) {
output += "\x00" + Chr(byte(noteDuration))
AdvanceInput()
case '0', '1', '2', '4', '5', '6', '7', '8', '9':
output += Chr(Ord(input[1])+0xF0-Ord('0')) + Chr(byte(noteDuration))
output += Chr(Ord(input[0])+0xF0-Ord('0')) + Chr(byte(noteDuration))
AdvanceInput()
default:
AdvanceInput()
Expand Down
Loading

0 comments on commit 4ca1abf

Please sign in to comment.