golang: fixed build errors and some refactoring

git-svn-id: svn://kolibrios.org@9298 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad)
2021-11-21 21:10:17 +00:00
parent 7a80e13e25
commit 227e2de7d9
7 changed files with 516 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
PROGRAM=example
OBJS=../syscalls.o colors.go.o colors.gox ../kos.go.o ../kos.gox $(PROGRAM).go.o
GOFLAGS=-m32 -c -nostdlib -nostdinc -fno-stack-protector -fno-split-stack -static -fno-leading-underscore -fno-common -fno-pie -g -I.
GO=gccgo
ASFLAGS=-g -f elf32 -F dwarf
NASM=nasm $(ASFLAGS)
OBJCOPY=objcopy
LDFLAGS=-n -T static.lds -m elf_i386 --no-ld-generated-unwind-info
all: $(OBJS) link
clean:
rm -f $(OBJS) $(PROGRAM).kex
link:
ld $(LDFLAGS) -o $(PROGRAM).kex $(OBJS)
$(OBJCOPY) $(PROGRAM).kex -O binary
%.gox: %.go.o
$(OBJCOPY) -j .go_export $< $@
%.go.o: %.go
$(GO) $(GOFLAGS) -o $@ -c $<
%.o: %.asm
$(NASM) $<

View File

@@ -0,0 +1,20 @@
package colors
const(
Black = 0x000000
Gray = 0x808080
Silver = 0xc0c0c0
White = 0xffffff
Fuchsia = 0xff00ff
Purple = 0x800080
Red = 0xff0000
Maroon = 0x800000
Yellow = 0xffff00
Olive = 0x808000
Lime = 0x00ff00
Green = 0x008000
Aqua = 0x00ffff
Teal = 0x008080
Blue = 0x0000ff
Navy =0x000080
)

View File

@@ -0,0 +1,77 @@
package example
import (
"colors"
"../kos"
)
const (
Btn1 = 2
Btn2 = 3
BtnExit = 1
)
type Button struct { // structure gui button
label string
x int
y int
id int
}
func NewButton() Button {
object := Button{"Text", 0, 0, Btn1} // default data
return object
}
func (button *Button) make() {
kos.CreateButton(button.x, button.y, len(button.label)*15, 30, button.id, colors.Blue)
kos.WriteText(button.x, button.y, 0x11000000|colors.White, button.label)
}
func RedrawAll(bar_pos int) {
kos.Redraw(1)
kos.Window(500, 250, 420, 200, "Example GoLang")
kos.DrawLine(32, 80, 150, 80, colors.Green)
kos.DrawBar(bar_pos, 90, 100, 30, colors.Red)
b1 := NewButton()
b1.label = " <- "
b1.x = 32
b1.y = 128
b1.id = Btn1
b1.make()
b2 := NewButton()
b2.label = " -> "
b2.x = 310
b2.y = 128
b2.id = Btn2
b2.make()
}
func Main() {
var pos = 160
time := kos.GetTime()
kos.DebugOutStr("Time: ")
kos.DebugOutHex(time)
for {
switch kos.Event() {
case kos.EVENT_REDRAW:
RedrawAll(pos)
break
case kos.EVENT_BUTTON:
switch kos.GetButtonID() {
case Btn1:
pos -= 32
RedrawAll(pos)
break
case Btn2:
pos += 32
RedrawAll(pos)
break
case BtnExit:
kos.Exit()
}
}
}
}

View File

@@ -0,0 +1,31 @@
SECTIONS
{
. = 0x00000;
.text :
{
LONG(0x554e454D);
LONG(0x31305445);
LONG(1);
LONG(go.example.Main);
LONG(__end);
LONG(0x10000);
LONG(0x10000);
LONG(0);
LONG(0);
*(.text)
}
.eh_frame : {
*(.eh_frame)
}
.group : {
*(.group)
}
.data : {
*(.data)
}
.rodata : {
*(.rodata)
*(.rodata.*)
}
__end = .;
}