white = Color.new(255, 255, 255)
num1 = 0
num2 = 0
operation = 1
answer = 0
remainder = 0
oldpad = Controls.read()
uparrow = Screen.loadImage("/up.bmp")
downarrow = Screen.loadImage("/down.bmp")
while true do
Screen.refresh()
pad = Controls.read()
x,y = Controls.readTouch()
Screen.clear(TOP_SCREEN)
Screen.clear(BOTTOM_SCREEN)
if (Controls.check(pad,KEY_DUP)) and not (Controls.check(oldpad,KEY_DUP)) then
num1 = num1 + 1
end
if (Controls.check(pad,KEY_DDOWN)) and not (Controls.check(oldpad,KEY_DDOWN)) then
num1 = num1 - 1
end
if (Controls.check(pad,KEY_DRIGHT)) and not (Controls.check(oldpad,KEY_DRIGHT)) then
num2 = num2 + 1
end
if (Controls.check(pad,KEY_DLEFT)) and not (Controls.check(oldpad,KEY_DLEFT)) then
num2 = num2 - 1
end
if(Controls.check(pad,KEY_TOUCH)) and not (Controls.check(oldpad, KEY_TOUCH)) then
x,y = Controls.readTouch()
if(x > 19) and (x < 99) and (y > 30) and (y < 55) then
num1 = num1 + 1
elseif(x > 19) and (x < 99) and (y > 160) and (y < 185) then
num1 = num1 - 1
elseif(x > 119) and (x < 199) and (y > 30) and (y < 55) then
if operation == 5 then
operation = 1
else
operation = operation + 1
end
elseif(x > 119) and (x < 199) and (y > 160) and (y < 185) then
if operation == 1 then
operation = 5
else
operation = operation - 1
end
elseif(x > 219) and (x < 299) and (y > 30) and (y < 55) then
num2 = num2 + 1
elseif(x > 219) and (x < 299) and (y > 160) and (y < 185) then
num2 = num2 - 1
end
end
if (Controls.check(pad,KEY_A)) and not (Controls.check(oldpad,KEY_A)) then
operation = 1
answer = num1 + num2
end
if (Controls.check(pad,KEY_B)) and not (Controls.check(oldpad,KEY_B)) then
operation = 2
answer = num1 - num2
end
if (Controls.check(pad,KEY_Y)) and not (Controls.check(oldpad,KEY_Y)) then
operation = 3
if num2 > 0 then
answer = num1 // num2
remainder = num1 % num2
end
end
if (Controls.check(pad,KEY_X)) and not (Controls.check(oldpad,KEY_X)) then
operation = 4
answer = num1 * num2
end
if (Controls.check(pad,KEY_SELECT)) and not (Controls.check(oldpad,KEY_SELECT)) then
operation = 5
answer = num1 ^ num2
end
if (Controls.check(pad, KEY_START)) then
System.exit()
end
Screen.drawImage(20,31,uparrow,BOTTOM_SCREEN)
Screen.drawImage(120,31,uparrow,BOTTOM_SCREEN)
Screen.drawImage(220,31,uparrow,BOTTOM_SCREEN)
Screen.drawImage(20,161,downarrow,BOTTOM_SCREEN)
Screen.drawImage(120,161,downarrow,BOTTOM_SCREEN)
Screen.drawImage(220,161,downarrow,BOTTOM_SCREEN)
if operation == 1 then
answer = num1 + num2
Screen.debugPrint(0,30,num1 .. " + " .. num2 .. " = " .. answer,white,TOP_SCREEN)
elseif operation == 2 then
answer = num1 - num2
Screen.debugPrint(0,30,num1 .. " - " .. num2 .. " = " .. answer,white,TOP_SCREEN)
elseif operation == 3 then
if num2 ~= 0 then
answer = num1 // num2
remainder = num1 % num2
if remainder ~= 0 then
Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer .. "r" .. remainder,white,TOP_SCREEN)
else
Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = " .. answer,white,TOP_SCREEN)
end
else
Screen.debugPrint(0,30,num1 .. " / " .. num2 .. " = UNDEFINED",white,TOP_SCREEN)
end
elseif operation == 4 then
answer = num1 * num2
Screen.debugPrint(0,30,num1 .. " x " .. num2 .. " = " .. answer,white,TOP_SCREEN)
elseif operation == 5 then
answer = num1 ^ num2
Screen.debugPrint(0,30,num1 .. "^" .. num2 .. " = " .. answer,white,TOP_SCREEN)
end
Screen.flip()
oldpad = pad
Screen.waitVblankStart()
end