--*****************************************************************************
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 CarDisp() -- Dem CPU cars, man! Needs to see 'em, I say!
--*****************************************************************************
for i= 0, 2 do
local X= 61 + 51*i
local addr= 0x0520+i*16
local clr,tmr= "green","grey"
local dst= "grey"
local ID= R1s(addr)
if ID < 0 then clr,tmr= "grey","green"
else
dst= "green"
local distance= R1u(addr+2)
if distance >= 103 then dst= "orange" end
if distance >= 112 then dst= "white" end
if distance >= 124 then dst= "orange" end
end
DrawNumx(X+10, 9,R1u(addr+ 0),clr,"black") -- ID
DrawNum( X+20, 9,R1u(addr+ 3),tmr,"black") -- Respawn timer
DrawNum( X+30, 9,R1u(addr+ 6),tmr,"black") -- Respawn timer init
DrawNum( X+12, 16,R1u(addr+ 1),clr,"black") -- Speed
DrawNum( X+26, 16,R1u(addr+ 2),dst,"black") -- Dist main
DrawNumx(X+34, 16,R1u(addr+ 7),clr,"black") -- Dist sub
DrawNum (X+26, 23,R1s(addr+ 8),clr,"black") -- X offset (lane shift)
DrawNumx(X+34, 23,R1u(addr+11),clr,"black") -- X sub
DrawNumx(X+ 8, 31,R1u(addr+ 4),clr,"black") -- Unknowns
DrawNumx(X+16, 31,R1u(addr+ 5),clr,"black")
DrawNumx(X+24, 31,R1u(addr+ 9),tmr,"black")
DrawNumx(X+32, 31,R1u(addr+10),clr,"black")
DrawNumx(X+ 8, 38,R1u(addr+12),clr,"black")
DrawNumx(X+16, 38,R1u(addr+13),clr,"black")
DrawNumx(X+24, 38,R1u(addr+14),clr,"black")
DrawNumx(X+32, 38,R1u(addr+15),clr,"black")
end
--[[for i= 0, 2 do
for j= 0, 15 do
DrawNumx(10+10*i,9+7*j,R1u(0x0520+i*16+j),"white","black")
end
end]]--
end
--*****************************************************************************
local function BasicHUD()
--*****************************************************************************
DrawNum( 117,204,R1u(0x0038),"white" ,"black") -- Speed (main)
DrawNumx(125,204,R1u(0x0058),"grey" ,"black") -- Speed (sub)
DrawNum( 62,182,R2u(0x0029),"yellow","black") -- Frame timer (dec)
DrawNumx( 62,189,R2u(0x0029),"yellow","black") -- Frame timer (hex)
DrawNum( 62,204,R1u(0x0062),"white" ,"black") -- Game timer
DrawNum( 137,188,R1s(0x03B0),"cyan" ,"black") -- Road curve
DrawNum( 117,188,R2s(0x0030,0x003F),"green","black") --Hor-Pos
CarDisp()
local Dist= R1u(0x008F)*84*256 + R1u(0x0031)*256 + R1u(0x0068)
DrawNum( 116,218,Dist ,"White" ,"black") -- Distance traveled
local Lost= R2u(0x0029)*255 - Dist - 121975
DrawNum( 150,218,Lost ,"orange","black") -- Diff from theoretical
if Dist >= 2084864 then
DrawNum(116,225,Dist-2084864,"orange","black")
end
Dist= math.floor(Dist/2084864 * 256) - 1
if Dist >= 255 then gui.line(0,180,255 ,180,"orange")
elseif Dist >= 0 then gui.line(0,180,Dist,180,"green") end
end
gui.register(BasicHUD)
--Calibrated for first course.
--No guarantees distance calcs work on other courses.