Archived
1
0

Init commit

This commit is contained in:
sweetbread
2023-06-11 03:21:00 +03:00
commit dc685b3d93
8 changed files with 700 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
PROGRAM=example
OBJS=../syscalls.o ../runtime.go.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 -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) $<
+20
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
)
+79
View File
@@ -0,0 +1,79 @@
package example
import (
"colors"
"../kos"
)
const (
Btn1 = 2
Btn2 = 3
BtnExit = 1
)
type Button struct {
label string
x int
y int
id int
}
func NewButton(label string, x int, y int, id int) Button {
return Button{
label: label,
x: x,
y: y,
id: id,
}
}
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(barPos int) {
kos.Redraw(1)
kos.Window(500, 250, 420, 200, "GoLang")
kos.DrawLine(32, 80, 150, 80, colors.Green)
kos.DrawBar(barPos, 90, 100, 30, colors.Red)
str1 := "123"
str2 := "222"
if str1 == str2 || str2 == "222" {
kos.WriteText(50,50,0,"==")
} else {
kos.WriteText(50,50,0,"!=")
}
b1 := NewButton(" <- ", 32, 128, Btn1)
b1.make()
b2 := NewButton(" -> ", 310, 128, Btn2)
b2.make()
}
func Main() {
pos := 160
for {
switch kos.Event() {
case kos.EVENT_REDRAW:
RedrawAll(pos)
case kos.EVENT_BUTTON:
switch kos.GetButtonID() {
case Btn1:
pos -= 32
RedrawAll(pos)
case Btn2:
pos += 32
RedrawAll(pos)
case BtnExit:
kos.Exit()
}
}
}
}