--*****************************************************************************
local Draw= {}
--*****************************************************************************
--Coordinates is the top-left pixel of the 3x5 digit.
--Used for drawing compact, colored numbers.
local Px,Li= gui.pixel, gui.line
Draw[0]= function(x,y,c) -- ###
Li(x ,y ,x ,y+4,c)-- # #
Li(x+2,y ,x+2,y+4,c)-- # #
Px(x+1,y ,c) -- # #
Px(x+1,y+4,c) -- ###
end
Draw[1]= function(x,y,c) -- #
Li(x ,y+4,x+2,y+4,c)-- ##
Li(x+1,y ,x+1,y+3,c)-- #
Px(x ,y+1,c) -- #
end -- ###
Draw[2]= function(x,y,c) -- ###
Li(x ,y ,x+2,y ,c)-- #
Li(x ,y+3,x+2,y+1,c)-- ###
Li(x ,y+4,x+2,y+4,c)-- #
Px(x ,y+2,c) -- ###
Px(x+2,y+2,c)
end
Draw[3]= function(x,y,c) -- ###
Li(x ,y ,x+1,y ,c)-- #
Li(x ,y+2,x+1,y+2,c)-- ###
Li(x ,y+4,x+1,y+4,c)-- #
Li(x+2,y ,x+2,y+4,c)-- ###
end
Draw[4]= function(x,y,c) -- # #
Li(x ,y ,x ,y+2,c)-- # #
Li(x+2,y ,x+2,y+4,c)-- ###
Px(x+1,y+2,c) -- #
end -- #
Draw[5]= function(x,y,c) -- ###
Li(x ,y ,x+2,y ,c)-- #
Li(x ,y+1,x+2,y+3,c)-- ###
Li(x ,y+4,x+2,y+4,c)-- #
Px(x ,y+2,c) -- ###
Px(x+2,y+2,c)
end
Draw[6]= function(x,y,c) -- ###
Li(x ,y ,x+2,y ,c)-- #
Li(x ,y+1,x ,y+4,c)-- ###
Li(x+2,y+2,x+2,y+4,c)-- # #
Px(x+1,y+2,c) -- ###
Px(x+1,y+4,c)
end
-- ###
Draw[7]= function(x,y,c) -- #
Li(x ,y ,x+1,y ,c)-- ##
Li(x+2,y ,x+1,y+4,c)-- #
end -- #
Draw[8]= function(x,y,c) -- ###
Li(x ,y ,x ,y+4,c)-- # #
Li(x+2,y ,x+2,y+4,c)-- ###
Px(x+1,y ,c) -- # #
Px(x+1,y+2,c) -- ###
Px(x+1,y+4,c)
end
Draw[9]= function(x,y,c) -- ###
Li(x ,y ,x ,y+2,c)-- # #
Li(x+2,y ,x+2,y+3,c)-- ###
Li(x ,y+4,x+2,y+4,c)-- #
Px(x+1,y ,c) -- ###
Px(x+1,y+2,c)
end
Draw[10]=function(x,y,c) -- #
Li(x ,y+1,x ,y+4,c)-- # #
Li(x+2,y+1,x+2,y+4,c)-- # #
Px(x+1,y ,c) -- ###
Px(x+1,y+3,c) -- # #
end
Draw[11]=function(x,y,c) -- ##
Li(x ,y ,x ,y+4,c)-- # #
Li(x+1,y ,x+2,y+1,c)-- ##
Li(x+1,y+4,x+2,y+3,c)-- # #
Px(x+1,y+2,c) -- ##
end
Draw[12]=function(x,y,c) -- #
Li(x ,y+1,x ,y+3,c)-- # #
Li(x+1,y ,x+2,y+1,c)-- #
Li(x+1,y+4,x+2,y+3,c)-- # #
end -- #
Draw[13]=function(x,y,c) -- ##
Li(x ,y ,x ,y+4,c)-- # #
Li(x+2,y+1,x+2,y+3,c)-- # #
Px(x+1,y ,c) -- # #
Px(x+1,y+4,c) -- ##
end
Draw[14]=function(x,y,c) -- ###
Li(x ,y ,x ,y+4,c)-- #
Li(x+1,y ,x+2,y ,c)-- ##
Li(x+1,y+4,x+2,y+4,c)-- #
Px(x+1,y+2,c) -- ###
end
Draw[15]=function(x,y,c) -- ###
Li(x ,y ,x ,y+4,c)-- #
Li(x+1,y ,x+2,y ,c)-- ##
Px(x+1,y+2,c) -- #
end -- #
--*****************************************************************************
local function __DN_AnyBase(right, y, Number, c, bkgnd, div)
--*****************************************************************************
-- Works with any base from 2 to 16. Paints the input number.
-- Returns the x position where it would paint another digit.
-- It only works with integers. Rounds fractions toward zero.
if div < 2 then return end -- Prevents the function from never returning.
local Digit= {}
local Negative= false
if Number < 0 then
Number= -Number
Negative= true
end
Number= math.floor(Number)
c= c or "white"
bkgnd= bkgnd or "clear"
local i= 0
if Number < 1 then
Digit[1]= 0
i= 1
end
while (Number >= 1) do
i= i+1
Digit[i]= Number % div
Number= math.floor(Number/div)
end
if Negative then i= i+1 end
local x= right - i*4
gui.box(x+1, y-1, right+1, y+5,bkgnd,bkgnd)
i= 1
while Draw[Digit[i]] do
Draw[Digit[i]](right-2,y,c)
right= right-4
i=i+1
end
if Negative then
gui.line(right, y+2,right-2,y+2,c)
right= right-4
end
return right
end
--*****************************************************************************
local function DrawNum(right, y, Number, c, bkgnd)
--*****************************************************************************
-- Paints the input number as right-aligned. Decimal version.
return __DN_AnyBase(right, y, Number, c, bkgnd, 10)
end
--*****************************************************************************
local function DrawNumx(right, y, Number, c, bkgnd)
--*****************************************************************************
-- Paints the input number as right-aligned. Hexadecimal version.
return __DN_AnyBase(right, y, Number, c, bkgnd, 16)
end
-------------------------------------------------------------------------------
local R1u,R1s= memory.readbyte, memory.readbytesigned
local R2u,R2s= memory.readword, memory.readwordsigned
--*****************************************************************************
local function DisplayLandings()
--*****************************************************************************
local c= 0
for i= 0, 13 do
local addr= 0x0300 + i
if R1u(addr) == 3 then
local loc= R1u(addr+0x10)
local X,Y= (loc%0x10)*16 +11 , math.floor(loc/0x10)*16 +41
DrawNumx(X,Y,R1u(addr+0x20),"white","black")
end
if R1u(addr) ~= 0 then
c= c+1
end
end
DrawNum(7,9,c,"white","black")
end
--*****************************************************************************
local function DisplayField()
--*****************************************************************************
for x= 1, 15 do
local X= x*16 - 5
for y= 1, 12 do
local Y= y*16 +19
local addr= 0x03D0 + x + y*0x10
local v= R1u(addr)
local clr= "green"
if v >= 0x80 then clr= "grey" end
if v > 1 then
DrawNumx(X,Y,v,clr,"black")
end
end
end
end
local plclr= {[0]= "orange","cyan"}
--*****************************************************************************
local function DisplayPlayer() --An up-to-date box would be lovely, eh?
--*****************************************************************************
for pl= 0, 1 do
local loc= R1u(0x00D1 + pl)
local X,Y= (loc%0x10)*16 , math.floor(loc/0x10)*16 +32
local clr= "clear"
if R1u(0x00D3 + pl) ~= 0 then clr= nil end
gui.box(X,Y,X+15,Y+15,clr,plclr[pl])
end
end
--*****************************************************************************
local function ObjectStats()
--*****************************************************************************
for i= 0, 11 do
local X= 10 + 10*i
local addr= 0x0300 + i
local clr= "green"
if R1u(addr) == 0 then clr= "grey" end
for j= 0,12 do
local Y= 9 + 6*j
DrawNumx(X,Y,R1u(addr+0x10*j),clr,"black")
end
end
end
--*****************************************************************************
local function Scoring()
--*****************************************************************************
gui.box(120,8,144,15,"black","black")
local v= R1u(0x0154)+R1u(0x0155)*0x100+R1u(0x0156)*0x10000
for i= 0, 5 do
local digit= v%16
Draw[digit](141-4*i,9,"white")
v= math.floor(v/16)
end
gui.box( 40,8, 64,15,"black","black")
local v= R1u(0x00BA)+R1u(0x00BB)*0x100+R1u(0x00BC)*0x10000
for i= 0, 5 do
local digit= v%16
Draw[digit]( 61-4*i,9,"white")
v= math.floor(v/16)
end
end
--*****************************************************************************
local function BasicHUD()
--*****************************************************************************
-- ObjectStats()
DisplayPlayer()
DisplayLandings()
DisplayField()
Scoring()
DrawNumx(220, 10,R1u(0x00D1),"orange","black") -- Pos P1
DrawNumx(230, 10,R1u(0x00D2),"cyan" ,"black") -- Pos P2
DrawNumx(220, 20,R1u(0x00D3),"orange","black") -- Hold P1
DrawNumx(230, 20,R1u(0x00D4),"cyan" ,"black") -- Hold P2
end
gui.register(BasicHUD)