Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua Pivot #9

Merged
merged 29 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a41a951
working lua
phy1um Sep 5, 2021
2299b39
add simple lua GS interface
phy1um Sep 5, 2021
5b32105
add gs/lua abstraction
phy1um Oct 6, 2021
6466d67
simple lua example of hardware iface
phy1um Oct 8, 2021
be2065d
add entire wip state
phy1um Oct 9, 2021
798e570
working base draw example
phy1um Oct 9, 2021
4b84527
getting ready for drawing
phy1um Oct 10, 2021
9b6f58a
remove prints, increase drawbuffer size, catch error when drawbuffer …
phy1um Oct 11, 2021
7ee29f1
add utility scripts
phy1um Oct 11, 2021
94f62c0
better buffer interface, better init interface
phy1um Oct 11, 2021
ecb3bef
add more scripts
phy1um Oct 11, 2021
9208c3a
improve lua apis, rename test files
phy1um Oct 12, 2021
8f93244
added texture support, not working
phy1um Oct 13, 2021
9b9e82d
added texture support, not working
phy1um Oct 13, 2021
d492285
working texture basics
phy1um Oct 14, 2021
a2edb83
texture loading so close i can taste it
phy1um Oct 14, 2021
9e402d5
working texture + tga for 32bit (with alpha)
phy1um Oct 14, 2021
7f344bc
make texture loading not part of PS2PROG.start, cleanup logging
phy1um Oct 14, 2021
62face0
allow colour blending on textures
phy1um Oct 14, 2021
8741cbc
working pad abstraction in Lua
phy1um Oct 15, 2021
1a38ae7
tweaking logging and numbers
phy1um Oct 15, 2021
d4829e2
remove unused files in new system
phy1um Oct 15, 2021
a44b794
formatter
phy1um Oct 15, 2021
3945ba4
update TODOs
phy1um Oct 15, 2021
28274b4
add texture assets and font license
phy1um Oct 15, 2021
b4060b5
add some license info
phy1um Oct 15, 2021
ec74074
add missing padlua source file
phy1um Oct 15, 2021
09f26f5
add missing name and year to license
phy1um Oct 15, 2021
9e7f9f0
add scripts to asset build
phy1um Oct 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ dkms.conf
# python stuff
**/__pycache__/
**/*.bin

dist/*
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2021 Tom Marks

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

45 changes: 33 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,61 @@ BIN=dist/test.elf
PS2HOST?=192.168.20.99

DOCKER_IMG=ps2build
DOCKERFLAGS=--user "$(shell id -u):$(shell id -g)"
DOCKER?=sudo docker
DOCKERFLAGS=--user "$(1000):$(1000)"
DOCKER?=docker

LUA_BRANCH=ee-v5.4.4

include .lintvars

dist: $(BIN) assets

.PHONY: assets
assets:
assets: scripts
if ! [ -d dist ]; then mkdir dist; fi
$(MAKE) -C asset
cp asset/*.bin dist/
cp asset/*.tga dist/
cp distfiles/* dist/
cp LICENSE dist/

$(BIN): src/test.elf
if ! [ -d dist ]; then mkdir dist; fi
cp src/test.elf dist/test.elf

.PHONY: src/test.elf
src/test.elf:
$(MAKE) PLATFORM=ps2 -C src test.elf
$(MAKE) platform=PS2 -C src test.elf


.PHONY: scripts
scripts:
if ! [ -d dist/script ]; then mkdir -p dist/script; fi
cp script/* dist/script

# TODO(phy1um): update ISO building to include everything in dist/
# TODO(Tom Marks): update ISO building to include everything in dist/
$(ISO_TGT): $(EE_BIN)
mkisofs -l -o $(ISO_TGT) $(BIN) dist/SYSTEM.CNF

.PHONY: docker-elf
docker-elf:
$(DOCKER) run -v $(shell pwd):/src $(DOCKER_IMG) make $(BIN)
$(DOCKER) run $(DOCKERFLAGS) -v $(shell pwd):/src $(DOCKER_IMG) make $(BIN)


.PHONY: clean
clean:
clean:
$(MAKE) -C src clean
$(MAKE) -C asset clean
rm -rf dist/

.PHONY: run
run:
PCSX2 --elf=$(PWD)/$(BIN)
run: scripts
PCSX2 --elf=$(PWD)/$(BIN)

# TODO(phy1um): this could be improved, hard-coded ELF name is bad
# TODO(Tom Marks): this could be improved, hard-coded ELF name is bad
.PHONY: runps2
runps2:
cp dist && ps2client -h $(PS2HOST) -t 10 execee host:test.elf
runps2: scripts
ps2client -h $(PS2HOST) -t 10 execee host:test.elf

.PHONY: resetps2
resetps2:
Expand All @@ -59,8 +68,20 @@ resetps2:
lint:
cpplint --filter=$(CPPLINT_FILTERS) --counting=total --linelength=$(CPPLINT_LINE_LENGTH) --extensions=c,h --recursive .

.PHONY: lualint
lualint:
luac5.1 -p script/*.lua

.PHONY: format
format:
$(DOCKER) run $(DOCKERFLAGS) -v $(shell pwd):/workdir unibeautify/clang-format -i -sort-includes **/*.c **/*.h

deps:
git clone https://github.com/ps2dev/lua --depth 1 --branch $(LUA_BRANCH) --single-branch src/lua

lua-samples:
$(DOCKER) run $(DOCKERFLAGS) -v $(shell pwd):/src $(DOCKER_IMG) make -C src/lua/sample

docker-image:
$(DOCKER) build -t $(DOCKER_IMG) .

Binary file added asset/bigfont.tga
Binary file not shown.
2 changes: 2 additions & 0 deletions asset/font.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPLEEN
https://github.com/fcambus/spleen
Binary file added asset/test.tga
Binary file not shown.
25 changes: 25 additions & 0 deletions distfiles/spleen.font.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2018-2021, Frederic Cambus
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

31 changes: 31 additions & 0 deletions indirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import socket
import subprocess
import sys

SERVER_IP = "0.0.0.0"
SERVER_PORT = int(sys.argv[1])
is_running = True

def run_command(msg):
parts = list(map(lambda x: x.decode("utf-8").strip(), msg.split(b" ")))
print("got cmd " + parts[0])
if parts[0] == "make":
subprocess.run(parts, stdout=cl, stderr=cl)
else:
print("no matching action for cmd")

server = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
server.bind((SERVER_IP, SERVER_PORT))
server.listen(5)

try:
while is_running == True:
cl, addr = server.accept()
print("got connection from client")
msg = cl.recv(1024)
print("running message")
output = run_command(msg)
cl.close()
finally:
server.close()
113 changes: 113 additions & 0 deletions script/draw2d.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
local GIF = require("gif")
local P = require("ps2const")

local DRAW_NONE = 0
local DRAW_GEOM = 1
local DRAW_SPRITE = 2

local DRAW_FMT_GEOM = {1,5,5,5}
local DRAW_FMT_SPRITE = {2,1,5,2,1,5}
local DB_SIZE = 5000

local draw = {
col = {r=255, g=255, b=255, a=0x80},
state = DRAW_NONE,
loopCount = 0,
tagLoopPtr = 0,
currentTexPtr = 0,
buf = nil,
kc = 0,
rawtri = 0,

}

function draw:newBuffer()
self.state = DRAW_NONE
self.loopCount = 0
self.tagLoopPtr = 0
self.buf = RM.getDrawBuffer(DB_SIZE)
end

function draw:getBuffer()
return self.buf
end

function draw:setColour(r,g,b,a)
self.col.r = r
self.col.g = g
self.col.b = b
self.col.a = a
end

function draw:rect(x, y, w, h)
draw:triangle(x, y, x+w, y, x, y+h)
draw:triangle(x, y+h, x+w, y+h, x+w, y)
end

function draw:sprite(tex, x, y, w, h, u1, v1, u2, v2)
if self.loopCount > 10000 then self:kick() end
if self.buf.size - self.buf.head < 80 then self:kick() end
if self.state ~= DRAW_SPRITE or self.currentTexPtr ~= tex.basePtr then
if self.state ~= DRAW_NONE then self:kick() end
local pb = math.floor(tex.basePtr/64)
local pw = math.floor(tex.width/64)
GIF.tag(self.buf, GIF.PACKED, 4, false, {0xe})
GIF.texA(self.buf, 0x80, 0x80)
GIF.tex1(self.buf, true, 0, true, 0, 0)
self.buf:settex(0, pb, pw, tex.format, math.floor(log2(tex.width)), math.floor(log2(tex.height)), 0, 1, 0, 0, 0)
-- GIF.mipTbp1(self.buf, 0, pb, pw, pb, pw, pb, pw)
-- GIF.mipTbp2(self.buf, 0, pb, pw, pb, pw, pb, pw)
GIF.primAd(self.buf, P.PRIM.SPRITE, false, true, false)
--GIF.packedRGBAQ(self.buf, self.col.r, self.col.g, self.col.b, self.col.a)
self.tagLoopPtr = GIF.tag(self.buf, 0, 1, false, DRAW_FMT_SPRITE)
self.loopCount = 0
self.state = DRAW_SPRITE
end
local ix = math.floor(x)
local iy = math.floor(y)
local ix2 = math.floor(x+w)
local iy2 = math.floor(y+h)
GIF.packedST(self.buf, u1, v1)
GIF.packedRGBAQ(self.buf, self.col.r, self.col.g, self.col.b, self.col.a)
GIF.packedXYZ2(self.buf, 0x8000 + (ix*16), 0x8000 + (iy*16), 0)
GIF.packedST(self.buf, u2, v2)
GIF.packedRGBAQ(self.buf, self.col.r, self.col.g, self.col.b, self.col.a)
GIF.packedXYZ2(self.buf, 0x8000 + (ix2*16), 0x8000 + (iy2*16), 0)
self.loopCount = self.loopCount + 1
end

function draw:triangle(x1, y1, x2, y2, x3, y3)
if self.loopCount > 10000 then self:kick() end
if self.buf.size - self.buf.head < 80 then self:kick() end
if self.state ~= DRAW_GEOM then
if self.state ~= DRAW_NONE then self:kick() end
GIF.tag(self.buf, 0, 1, false, {0xe})
GIF.primAd(self.buf, P.PRIM.TRI, false, false, false)
self.tagLoopPtr = GIF.tag(self.buf, 0, 1, false, DRAW_FMT_GEOM)
self.loopCount = 0
self.state = DRAW_GEOM
end
GIF.packedRGBAQ(self.buf, self.col.r, self.col.g, self.col.b, self.col.a)
GIF.packedXYZ2(self.buf, 0x8000 + (x1*16), 0x8000 + (y1*16), 0)
GIF.packedXYZ2(self.buf, 0x8000 + (x2*16), 0x8000 + (y2*16), 0)
GIF.packedXYZ2(self.buf, 0x8000 + (x3*16), 0x8000 + (y3*16), 0)
self.loopCount = self.loopCount + 1
self.rawtri = self.rawtri + 1
end

function draw:kick()
local nloop = self.buf:read(self.tagLoopPtr)
if nloop - 0x8000 > 0 then
print("kick EOP")
self.buf:write(self.tagLoopPtr, 0x8000 + self.loopCount)
else
self.buf:write(self.tagLoopPtr, self.loopCount)
end
DMA.send(self.buf, DMA.GIF)
self:newBuffer()
self.kc = self.kc + 1
end

return draw


Loading