--[COLORS]----------------------------------------------
white = Color.new(255,255,255)
black = Color.new(0,0,0)
yellow = Color.new(255,192,128)

background = Image.load("\IMAGES/BACKGROUND.png")
background2 = Image.load("\IMAGES/BACKGROUND2.png")
System.oaenable()
Click = Sound.load("\Audio/Click.wav")
BITS = 24


IntraFont.init()
IntraFont.load("flash0:/font/ltn8.pgf",3)
fwhite = IntraFont.color(255,255,255,255)
fblack = IntraFont.color(0,0,0,128)


--------------------------------------------------------
function subnet()
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 0

while true do

oldpad = pad
pad = Controls.read()
--[SCREEN]----------------------------------------------
screen:clear()


screen:blit(0,0,background2)
screen:print(100,70,"   "..OCTET1.."     ",white)
screen:print(190,70,"   "..OCTET2.."     ",white)
screen:print(280,70,"   "..OCTET3.."      ",white)
screen:print(370,70,"   "..OCTET4.."",white)
screen:print(430,100,""..BITS.."",white)

screen:print(433,90,"+",white)
screen:print(433,110,"-",white)

Gu.start3d()
IntraFont.print(8,106,"Bits",1,fwhite,fblack)
IntraFont.print(8,76,"Subnet",1,fwhite,fblack)

IntraFont.print(22,15,"Subnet Calculator",1,fwhite,fblack)
IntraFont.print(162,252,"Modify Bit",1,fwhite,fblack)
IntraFont.print(271,252,"Switch To IP Calculator",1,fwhite,fblack)

Gu.end3d()
--------------------------------------------------------
--[MAIN]------------------------------------------------
if BITS==-1 then
BITS = 0
end

if BITS==33 then
BITS = 32
end

if BITS== 0 then
OCTET1 = 0
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 1 then
OCTET1 = 128
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 2 then
OCTET1 = 192
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 3 then
OCTET1 = 224
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 4 then
OCTET1 = 240
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 5 then
OCTET1 = 248
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 6 then
OCTET1 = 252
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 7 then
OCTET1 = 254
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end

if BITS== 8 then
OCTET1 = 255
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
end


if BITS== 9 then
OCTET1 = 255
OCTET2 = 128
OCTET3 = 0
OCTET4 = 0
end

if BITS== 10 then
OCTET1 = 255
OCTET2 = 192
OCTET3 = 0
OCTET4 = 0
end

if BITS== 11 then
OCTET1 = 255
OCTET2 = 224
OCTET3 = 0
OCTET4 = 0
end

if BITS== 12 then
OCTET1 = 255
OCTET2 = 240
OCTET3 = 0
OCTET4 = 0
end

if BITS== 13 then
OCTET1 = 255
OCTET2 = 248
OCTET3 = 0
OCTET4 = 0
end

if BITS== 14 then
OCTET1 = 255
OCTET2 = 252
OCTET3 = 0
OCTET4 = 0
end

if BITS== 15 then
OCTET1 = 255
OCTET2 = 254
OCTET3 = 0
OCTET4 = 0
end

if BITS== 16 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 0
OCTET4 = 0
end


if BITS== 17 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 128
OCTET4 = 0
end

if BITS== 18 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 192
OCTET4 = 0
end

if BITS== 19 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 224
OCTET4 = 0
end

if BITS== 20 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 240
OCTET4 = 0
end

if BITS== 21 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 248
OCTET4 = 0
end

if BITS== 22 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 252
OCTET4 = 0
end

if BITS== 23 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 254
OCTET4 = 0
end

if BITS== 24 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 0
end


if BITS== 25 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 128
end

if BITS== 26 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 192
end

if BITS== 27 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 224
end

if BITS== 28 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 240
end

if BITS== 29 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 248
end

if BITS== 30 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 252
end

if BITS== 31 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 254
end

if BITS== 32 then
OCTET1 = 255
OCTET2 = 255
OCTET3 = 255
OCTET4 = 255
end
--------------------------------------------------------
--[CONTROLS]--------------------------------------------

anaY = pad:analogY()

if BITS < 32 then
	if anaY < -100 then
		Click:play()
		BITS = BITS + 1
		screen:print(433,90,"+",yellow)
	end
	if pad:up() and oldpad:up() ~= pad:up() then
		Click:play()
		BITS = BITS + 1
		screen:print(433,90,"+",yellow)

	end
end

if BITS > 0 then
	if anaY > 100 then
		Click:play()
		BITS = BITS - 1
		screen:print(433,110,"-",yellow)
	end
	if pad:down() and oldpad:down() ~= pad:down() then
		Click:play()
		BITS = BITS - 1
		screen:print(433,110,"-",yellow)
	end
end

if pad:square() and oldpad:square() ~= pad:square() then
return
end

--------------------------------------------------------
--------------------------------------------------------
screen.flip()
screen.waitVblankStart()
end
end
----------------------------------------[FUNCTION END]--

MARKERPOS = 1
MARKERX = 40
MARKERY = 90
MARKER2Y = 110
OCTET1 = 0
OCTET2 = 0
OCTET3 = 0
OCTET4 = 0
IPCLASS = "C"
A = 1
B = 1
C = 0
D = 0
E = 0
F = 0
G = 0
H = 0
A1 = 0
B1 = 0
C1 = 0
D1 = 0
E1 = 0
F1 = 0
G1 = 0
H1 = 0
I = 1
J = 0
K = 1
L = 0
M = 1
N = 0
O = 0
P = 0
I1 = 0
J1 = 0
K1 = 0
L1 = 0
M1 = 0
N1 = 0
O1 = 0
P1 = 0
Q = 0
R = 0
S = 0
T = 0
U = 0
V = 0
W = 0
X = 0
Q1 = 0
R1 = 0
S1 = 0
T1 = 0
U1 = 0
V1 = 0
W1 = 0
X1 = 0

Y = 0
Z = 0
AA = 0
AB = 0
AC = 0
AD = 0
AE = 0
AF = 1

Y1 = 0
Z1 = 0
AA1 = 0
AB1 = 0
AC1 = 0
AD1 = 0
AE1 = 0
AF1 = 0

oldpad = Controls.read()
while true do


oldpad = pad
pad = Controls.read()
--[SCREEN]----------------------------------------------
screen:clear()

screen:blit(0,0,background)

Gu.start3d()

screen:print(MARKERX,MARKERY,"+",white)
screen:print(MARKERX,MARKER2Y,"-",white)
screen:print(100,100,""..A.."",white)
screen:print(110,100,""..B.."",white)
screen:print(120,100,""..C.."",white)
screen:print(130,100,""..D.."",white)
screen:print(140,100,""..E.."",white)
screen:print(150,100,""..F.."",white)
screen:print(160,100,""..G.."",white)
screen:print(170,100,""..H.."",white)

screen:print(190,100,""..I.."",white)
screen:print(200,100,""..J.."",white)
screen:print(210,100,""..K.."",white)
screen:print(220,100,""..L.."",white)
screen:print(230,100,""..M.."",white)
screen:print(240,100,""..N.."",white)
screen:print(250,100,""..O.."",white)
screen:print(260,100,""..P.."",white)

screen:print(280,100,""..Q.."",white)
screen:print(290,100,""..R.."",white)
screen:print(300,100,""..S.."",white)
screen:print(310,100,""..T.."",white)
screen:print(320,100,""..U.."",white)
screen:print(330,100,""..V.."",white)
screen:print(340,100,""..W.."",white)
screen:print(350,100,""..X.."",white)

screen:print(370,100,""..Y.."",white)
screen:print(380,100,""..Z.."",white)
screen:print(390,100,""..AA.."",white)
screen:print(400,100,""..AB.."",white)
screen:print(410,100,""..AC.."",white)
screen:print(420,100,""..AD.."",white)
screen:print(430,100,""..AE.."",white)
screen:print(440,100,""..AF.."",white)

screen:print(100,70,"   "..OCTET1.."     ",white)
screen:print(190,70,"   "..OCTET2.."     ",white)
screen:print(280,70,"   "..OCTET3.."      ",white)
screen:print(370,70,"   "..OCTET4.."",white)

IntraFont.print(345,130,"Selected Bit: "..MARKERPOS.."",1,fwhite,fblack)
IntraFont.print(95,130,""..IPCLASS.."",1,fwhite,fblack)
IntraFont.print(8,130,"Class",1,fwhite,fblack)
IntraFont.print(8,106,"Binary",1,fwhite,fblack)
IntraFont.print(8,76,"Address",1,fwhite,fblack)
IntraFont.print(22,15,"IP Address Calculator",1,fwhite,fblack)
IntraFont.print(42,252,"Select Bit",1,fwhite,fblack)
IntraFont.print(162,252,"Modify Bit",1,fwhite,fblack)
IntraFont.print(271,252,"Switch To Subnet Calculator",1,fwhite,fblack)
Gu.end3d()

--------------------------------------------------------
--[MAIN]------------------------------------------------

OCTET1 = A1 + B1 + C1 + D1 + E1 + F1 + G1 + H1
OCTET2 = I1 + J1 + K1 + L1 + M1 + N1 + O1 + P1
OCTET3 = Q1 + R1 + S1 + T1 + U1 + V1 + W1 + X1
OCTET4 = Y1 + Z1 + AA1 + AB1 + AC1 + AD1 + AE1 + AF1

if A == 1 then
A1 = 128
else
A1 = 0
end

if B == 1 then
B1 = 64
else
B1 = 0
end

if C == 1 then
C1 = 32
else
C1 = 0
end

if D == 1 then
D1 = 16
else
D1 = 0
end

if E == 1 then
E1 = 8
else
E1 = 0
end

if F == 1 then
F1 = 4
else
F1 = 0
end

if G == 1 then
G1 = 2
else
G1 = 0
end

if H == 1 then
H1 = 1
else
H1 = 0
end

if I == 1 then
I1 = 128
else
I1 = 0
end

if J == 1 then
J1 = 64
else
J1 = 0
end

if K == 1 then
K1 = 32
else
K1 = 0
end

if L == 1 then
L1 = 16
else
L1 = 0
end

if M == 1 then
M1 = 8
else
M1 = 0
end

if N == 1 then
N1 = 4
else
N1 = 0
end

if O == 1 then
O1 = 2
else
O1 = 0
end

if P == 1 then
P1 = 1
else
P1 = 0
end


if Q == 1 then
Q1 = 128
else
Q1 = 0
end

if R == 1 then
R1 = 64
else
R1 = 0
end

if S == 1 then
S1 = 32
else
S1 = 0
end

if T == 1 then
T1 = 16
else
T1 = 0
end

if U == 1 then
U1 = 8
else
U1 = 0
end

if V == 1 then
V1 = 4
else
V1 = 0
end

if W == 1 then
W1 = 2
else
W1 = 0
end

if X == 1 then
X1 = 1
else
X1 = 0
end



if Y == 1 then
Y1 = 128
else
Y1 = 0
end

if Z == 1 then
Z1 = 64
else
Z1 = 0
end

if AA == 1 then
AA1 = 32
else
AA1 = 0
end

if AB == 1 then
AB1 = 16
else
AB1 = 0
end

if AC == 1 then
AC1 = 8
else
AC1 = 0
end

if AD == 1 then
AD1 = 4
else
AD1 = 0
end

if AE == 1 then
AE1 = 2
else
AE1 = 0
end

if AF == 1 then
AF1 = 1
else
AF1 = 0
end

--------------------------------------------------------
--[MARKER]----------------------------------------------
if MARKERPOS == 0 then
MARKERPOS = 1
end

if MARKERPOS == 33 then
MARKERPOS = 32
end


if MARKERPOS == 1 then
MARKERX = 100
end

if MARKERPOS == 2 then
MARKERX = 110
end

if MARKERPOS == 3 then
MARKERX = 120
end

if MARKERPOS == 4 then
MARKERX = 130
end

if MARKERPOS == 5 then
MARKERX = 140
end

if MARKERPOS == 6 then
MARKERX = 150
end

if MARKERPOS == 7 then
MARKERX = 160
end

if MARKERPOS == 8 then
MARKERX = 170
end

if MARKERPOS == 9 then
MARKERX = 190
end

if MARKERPOS == 10 then
MARKERX = 200
end

if MARKERPOS == 11 then
MARKERX = 210
end

if MARKERPOS == 12 then
MARKERX = 220
end

if MARKERPOS == 13 then
MARKERX = 230
end

if MARKERPOS == 14 then
MARKERX = 240
end

if MARKERPOS == 15 then
MARKERX = 250
end

if MARKERPOS == 16 then
MARKERX = 260
end


if MARKERPOS == 17 then
MARKERX = 280
end

if MARKERPOS == 18 then
MARKERX = 290
end

if MARKERPOS == 19 then
MARKERX = 300
end

if MARKERPOS == 20 then
MARKERX = 310
end

if MARKERPOS == 21 then
MARKERX = 320
end

if MARKERPOS == 22 then
MARKERX = 330
end

if MARKERPOS == 23 then
MARKERX = 340
end

if MARKERPOS == 24 then
MARKERX = 350
end


if MARKERPOS == 25 then
MARKERX = 370
end

if MARKERPOS == 26 then
MARKERX = 380
end

if MARKERPOS == 27 then
MARKERX = 390
end

if MARKERPOS == 28 then
MARKERX = 400
end

if MARKERPOS == 29 then
MARKERX = 410
end

if MARKERPOS == 30 then
MARKERX = 420
end

if MARKERPOS == 31 then
MARKERX = 430
end

if MARKERPOS == 32 then
MARKERX = 440
end
--------------------------------------------------------
--[CONTROLS]--------------------------------------------
anaX = pad:analogX()

if MARKERPOS < 32 then
	if anaX > 100 then
		Click:play()
		MARKERPOS = MARKERPOS + 1
	end
	if pad:right() and oldpad:right() ~= pad:right() then
		Click:play()
		MARKERPOS = MARKERPOS + 1
	end
end

if MARKERPOS > 1 then
	if anaX < -100 then
		Click:play()
		MARKERPOS = MARKERPOS - 1
	end
	if pad:left() and oldpad:left() ~= pad:left() then
		Click:play()
		MARKERPOS = MARKERPOS - 1
	end
end

if pad:up() and oldpad:up() ~= pad:up() then
	Click:play()
	screen:print(MARKERX,MARKERY,"+",yellow)
end

if pad:down() and oldpad:down() ~= pad:down() then
	Click:play()
	screen:print(MARKERX,MARKER2Y,"-",yellow)
end

if pad:square() and oldpad:square() ~= pad:square() then
subnet()
end

--if pad:start() and oldpad:start() ~= pad:start() then
--return
--end

--BIT CHANGE
if MARKERPOS == 1 and pad:up() and oldpad:up() ~= pad:up() then
A = 1
end

if MARKERPOS == 1 and pad:down() and oldpad:down() ~= pad:down() then
A = 0
end

if MARKERPOS == 2 and pad:up() and oldpad:up() ~= pad:up() then
B = 1
end

if MARKERPOS == 2 and pad:down() and oldpad:down() ~= pad:down() then
B = 0
end

if MARKERPOS == 3 and pad:up() and oldpad:up() ~= pad:up() then
C = 1
end

if MARKERPOS == 3 and pad:down() and oldpad:down() ~= pad:down() then
C = 0
end

if MARKERPOS == 4 and pad:up() and oldpad:up() ~= pad:up() then
D = 1
end

if MARKERPOS == 4 and pad:down() and oldpad:down() ~= pad:down() then
D = 0
end

if MARKERPOS == 5 and pad:up() and oldpad:up() ~= pad:up() then
E = 1
end

if MARKERPOS == 5 and pad:down() and oldpad:down() ~= pad:down() then
E = 0
end

if MARKERPOS == 6 and pad:up() and oldpad:up() ~= pad:up() then
F = 1
end

if MARKERPOS == 6 and pad:down() and oldpad:down() ~= pad:down() then
F = 0
end

if MARKERPOS == 7 and pad:up() and oldpad:up() ~= pad:up() then
G = 1
end

if MARKERPOS == 7 and pad:down() and oldpad:down() ~= pad:down() then
G = 0
end

if MARKERPOS == 8 and pad:up() and oldpad:up() ~= pad:up() then
H = 1
end

if MARKERPOS == 8 and pad:down() and oldpad:down() ~= pad:down() then
H = 0
end


if MARKERPOS == 9 and pad:up() and oldpad:up() ~= pad:up() then
I = 1
end

if MARKERPOS == 9 and pad:down() and oldpad:down() ~= pad:down() then
I = 0
end

if MARKERPOS == 10 and pad:up() and oldpad:up() ~= pad:up() then
J = 1
end

if MARKERPOS == 10 and pad:down() and oldpad:down() ~= pad:down() then
J = 0
end

if MARKERPOS == 11 and pad:up() and oldpad:up() ~= pad:up() then
K = 1
end

if MARKERPOS == 11 and pad:down() and oldpad:down() ~= pad:down() then
K = 0
end

if MARKERPOS == 12 and pad:up() and oldpad:up() ~= pad:up() then
L = 1
end

if MARKERPOS == 12 and pad:down() and oldpad:down() ~= pad:down() then
L = 0
end

if MARKERPOS == 13 and pad:up() and oldpad:up() ~= pad:up() then
M = 1
end

if MARKERPOS == 13 and pad:down() and oldpad:down() ~= pad:down() then
M = 0
end

if MARKERPOS == 14 and pad:up() and oldpad:up() ~= pad:up() then
N = 1
end

if MARKERPOS == 14 and pad:down() and oldpad:down() ~= pad:down() then
N = 0
end

if MARKERPOS == 15 and pad:up() and oldpad:up() ~= pad:up() then
O = 1
end

if MARKERPOS == 15 and pad:down() and oldpad:down() ~= pad:down() then
O = 0
end

if MARKERPOS == 16 and pad:up() and oldpad:up() ~= pad:up() then
P = 1
end

if MARKERPOS == 16 and pad:down() and oldpad:down() ~= pad:down() then
P = 0
end


if MARKERPOS == 17 and pad:up() and oldpad:up() ~= pad:up() then
Q = 1
end

if MARKERPOS == 17 and pad:down() and oldpad:down() ~= pad:down() then
Q = 0
end

if MARKERPOS == 18 and pad:up() and oldpad:up() ~= pad:up() then
R = 1
end

if MARKERPOS == 18 and pad:down() and oldpad:down() ~= pad:down() then
R = 0
end

if MARKERPOS == 19 and pad:up() and oldpad:up() ~= pad:up() then
S = 1
end

if MARKERPOS == 19 and pad:down() and oldpad:down() ~= pad:down() then
S = 0
end

if MARKERPOS == 20 and pad:up() and oldpad:up() ~= pad:up() then
T = 1
end

if MARKERPOS == 20 and pad:down() and oldpad:down() ~= pad:down() then
T = 0
end

if MARKERPOS == 21 and pad:up() and oldpad:up() ~= pad:up() then
U = 1
end

if MARKERPOS == 21 and pad:down() and oldpad:down() ~= pad:down() then
U = 0
end

if MARKERPOS == 22 and pad:up() and oldpad:up() ~= pad:up() then
V = 1
end

if MARKERPOS == 22 and pad:down() and oldpad:down() ~= pad:down() then
V = 0
end

if MARKERPOS == 23 and pad:up() and oldpad:up() ~= pad:up() then
W = 1
end

if MARKERPOS == 23 and pad:down() and oldpad:down() ~= pad:down() then
W = 0
end

if MARKERPOS == 24 and pad:up() and oldpad:up() ~= pad:up() then
X = 1
end

if MARKERPOS == 24 and pad:down() and oldpad:down() ~= pad:down() then
X = 0
end


if MARKERPOS == 25 and pad:up() and oldpad:up() ~= pad:up() then
Y = 1
end

if MARKERPOS == 25 and pad:down() and oldpad:down() ~= pad:down() then
Y = 0
end

if MARKERPOS == 26 and pad:up() and oldpad:up() ~= pad:up() then
Z = 1
end

if MARKERPOS == 26 and pad:down() and oldpad:down() ~= pad:down() then
Z = 0
end

if MARKERPOS == 27 and pad:up() and oldpad:up() ~= pad:up() then
AA = 1
end

if MARKERPOS == 27 and pad:down() and oldpad:down() ~= pad:down() then
AA = 0
end

if MARKERPOS == 28 and pad:up() and oldpad:up() ~= pad:up() then
AB = 1
end

if MARKERPOS == 28 and pad:down() and oldpad:down() ~= pad:down() then
AB = 0
end

if MARKERPOS == 29 and pad:up() and oldpad:up() ~= pad:up() then
AC = 1
end

if MARKERPOS == 29 and pad:down() and oldpad:down() ~= pad:down() then
AC = 0
end

if MARKERPOS == 30 and pad:up() and oldpad:up() ~= pad:up() then
AD = 1
end

if MARKERPOS == 30 and pad:down() and oldpad:down() ~= pad:down() then
AD = 0
end

if MARKERPOS == 31 and pad:up() and oldpad:up() ~= pad:up() then
AE = 1
end

if MARKERPOS == 31 and pad:down() and oldpad:down() ~= pad:down() then
AE = 0
end

if MARKERPOS == 32 and pad:up() and oldpad:up() ~= pad:up() then
AF = 1
end

if MARKERPOS == 32 and pad:down() and oldpad:down() ~= pad:down() then
AF = 0
end

if (OCTET1 == 127) and (OCTET2 == 0) and (OCTET3 == 0) and (OCTET4 == 1) and (OCTET1 + OCTET2 + OCTET3 + OCTET4 == 128)then
IPCLASS = "Loopback"
end
if OCTET1 < 127 and OCTET1 > -1 then
IPCLASS = "A"
end
if OCTET1 < 192 and OCTET1 > 127 then
IPCLASS = "B"
end
if OCTET1 < 224 and OCTET1 > 191 then
IPCLASS = "C"
end
if OCTET1 < 240 and OCTET1 > 223 then
IPCLASS = "D"
end
if OCTET1 < 256 and OCTET1 > 239 then
IPCLASS = "E"
end
--------------------------------------------------------

screen.flip()
screen.waitVblankStart()
end 