Skip to content

Commit

Permalink
Reorganize build, create a .love package by default.
Browse files Browse the repository at this point in the history
Still copying games in manually at this point, need to figure out
an alternate path for games / saves to go.
  • Loading branch information
zeta0134 committed Dec 5, 2016
1 parent 6230204 commit f7ecee2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
games
love
love/games
*.love
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
love:
@mkdir -p love
cp love_main.lua love/main.lua
cp -R gameboy love
cp -R games love
cp UbuntuMono-R.ttf love
@mkdir -p games

cp love/main.lua main.lua
zip -9 -r LuaGB.love main.lua gameboy games UbuntuMono-R.ttf LICENSE.txt UBUNTU_FONT_LICENSE.txt
rm main.lua

.PHONY : love
25 changes: 25 additions & 0 deletions gameboy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ gameboy.initialize = function()
gameboy.graphics.initialize()
end

gameboy.step = function()
gameboy.graphics.update()
gameboy.input.update()
return process_instruction()
end

gameboy.run_until_vblank = function()
local instructions = 0
while gameboy.graphics.scanline() == 144 and instructions < 100000 do
gameboy.step()
instructions = instructions + 1
end
while gameboy.graphics.scanline() ~= 144 and instructions < 100000 do
gameboy.step()
instructions = instructions + 1
end
end

gameboy.run_until_hblank = function()
old_scanline = gameboy.graphics.scanline()
local instructions = 0
while old_scanline == gameboy.graphics.scanline() and instructions < 100000 do
gameboy.step()
instructions = instructions + 1
end
end

return gameboy
41 changes: 6 additions & 35 deletions love_main.lua → love/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,20 @@ function draw_tilemap(dx, dy, address, scale)
love.graphics.pop()
end

function run_one_opcode()
gameboy.graphics.update()
gameboy.input.update()
return process_instruction()
end

local emulator_running = false

function love.textinput(char)
if char == " " then
run_one_opcode()
gameboy.step()
end
if char == "k" then
for i = 1, 100 do
run_one_opcode()
gameboy.step()
end
end
if char == "l" then
for i = 1, 1000 do
run_one_opcode()
gameboy.step()
end
end
if char == "r" then
Expand All @@ -301,23 +295,10 @@ function love.textinput(char)
emulator_running = false
end
if char == "h" then
old_scanline = gameboy.graphics.scanline()
local instructions = 0
while old_scanline == gameboy.graphics.scanline() and instructions < 100000 do
run_one_opcode()
instructions = instructions + 1
end
gameboy.run_until_hblank()
end
if char == "v" then
local instructions = 0
while gameboy.graphics.scanline() == 144 and instructions < 100000 do
run_one_opcode()
instructions = instructions + 1
end
while gameboy.graphics.scanline() ~= 144 and instructions < 100000 do
run_one_opcode()
instructions = instructions + 1
end
gameboy.run_until_vblank()
end
end

Expand Down Expand Up @@ -387,18 +368,8 @@ function draw_window()
end

function love.update()
local instructions = 0
if emulator_running then
-- Run until a vblank happens, OR we run too many instructions in one go
while gameboy.graphics.scanline() == 144 and instructions < 100000 do
run_one_opcode()
instructions = instructions + 1
end
instructions = 0
while gameboy.graphics.scanline() ~= 144 and instructions < 100000 do
run_one_opcode()
instructions = instructions + 1
end
gameboy.run_until_vblank()
end
end

Expand Down

0 comments on commit f7ecee2

Please sign in to comment.