Advertisement
Dotsarecool

SML2 Tile Viewer

Jun 30th, 2016
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. local i = 0
  2. local cx = 0
  3. local cy = 0
  4. local p1_cx = 0
  5. local p1_cy = 0
  6. local p2_cx = 0
  7. local p2_cy = 0
  8. local drawn = 0
  9.  
  10. function drawTile(x, y)
  11.     local px = (x * 0x10) - p2_cx + 176
  12.     local py = (y * 0x10) - p2_cy + 168
  13.     if (px > -16 and px < 160 and py > -16 and py < 136) then
  14.         drawn = drawn + 1
  15.         memory.usememorydomain("System Bus")
  16.         local index = 0xB000 + x + 0x100 * y
  17.         while index > 0xFFFF do index = index - 0x10000 end
  18.         local tile = memory.readbyte(index)
  19.        
  20.         if (tile >= 0x04 and tile < 0x08) or (tile >= 0x10 and tile < 0x38) then
  21.             -- solid
  22.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFFFF)
  23.         elseif tile >= 0x38 and tile < 0x48 then
  24.             -- platform
  25.             gui.drawRectangle(px, py, 16, 3, 0xFFFFFFFF, 0xAAFFFFFF)
  26.         elseif tile == 0x48 or tile == 0x49 then
  27.             -- coin
  28.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFF00)
  29.         elseif tile == 0x4A then
  30.             -- level clear and save win
  31.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFF0000)
  32.             gui.drawText(px + 4, py, "!", 0xFF000000)
  33.         elseif tile == 0x4B then
  34.             -- level clear and DON'T save win
  35.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFF0000)
  36.             gui.drawText(px + 4, py, "X", 0xFF000000)
  37.         elseif tile == 0x50 or tile == 0x51 then
  38.             -- spikes
  39.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFFFF)
  40.             gui.drawLine(px, py + 0, px + 3, py + 15, 0xFF000000)
  41.             gui.drawLine(px + 4, py + 15, px + 7, py + 0, 0xFF000000)
  42.             gui.drawLine(px + 8, py + 0, px + 11, py + 15, 0xFF000000)
  43.             gui.drawLine(px + 12, py + 15, px + 15, py + 0, 0xFF000000)
  44.         elseif tile >= 0x4C and tile < 0x58 then
  45.             -- water
  46.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAA0000FF)
  47.         elseif tile == 0x00 or tile == 0x04 then
  48.             -- breakable block
  49.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFFFF)
  50.             gui.drawLine(px + 3, py + 7, px + 4, py + 6, 0xFF000000)
  51.             gui.drawLine(px + 5, py + 6, px + 6, py + 7, 0xFF000000)
  52.             gui.drawLine(px + 9, py + 7, px + 10, py + 6, 0xFF000000)
  53.             gui.drawLine(px + 11, py + 6, px + 12, py + 7, 0xFF000000)
  54.         elseif tile == 0x01 or tile == 0x02 or tile == 0x7E then
  55.             -- ? block
  56.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFFFF)
  57.             gui.drawText(px + 4, py, "?", 0xFF000000)
  58.         elseif tile >= 0x08 and tile < 0x10 then
  59.             -- pipe
  60.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF, 0xAAFFFFFF)
  61.             if tile == 0x08 then
  62.                 gui.drawRectangle(px+4, py, 12, 4, 0xFFFFFFFF, 0xAA00FF00)
  63.             elseif tile == 0x09 then
  64.                 gui.drawRectangle(px, py, 12, 4, 0xFFFFFFFF, 0xAA00FF00)
  65.             elseif tile == 0x0A then
  66.                 gui.drawRectangle(px+4, py + 12, 12, 4, 0xFFFFFFFF, 0xAA00FF00)
  67.             elseif tile == 0x0B then
  68.                 gui.drawRectangle(px, py + 12, 12, 4, 0xFFFFFFFF, 0xAA00FF00)
  69.             elseif tile == 0x0C then
  70.                 gui.drawRectangle(px, py+4, 4, 12, 0xFFFFFFFF, 0xAA00FF00)
  71.             elseif tile == 0x0D then
  72.                 gui.drawRectangle(px, py, 4, 12, 0xFFFFFFFF, 0xAA00FF00)
  73.             elseif tile == 0x0E then
  74.                 gui.drawRectangle(px+12, py+4, 4, 12, 0xFFFFFFFF, 0xAA00FF00)
  75.             elseif tile == 0x0F then
  76.                 gui.drawRectangle(px+12, py, 4, 12, 0xFFFFFFFF, 0xAA00FF00)
  77.             end
  78.         else
  79.             -- empty
  80.             gui.drawRectangle(px, py, 16, 16, 0xFFFFFFFF)
  81.         end
  82.        
  83.         if index == 0xA2D5 then
  84.             gui.drawText(px, py, "!!", 0xFFFF0000)
  85.         end
  86.        
  87.         memory.usememorydomain("Cart RAM")
  88.     end
  89. end
  90.  
  91. -- Start Main --
  92.  
  93. console.writeline("Starting...")
  94. memory.usememorydomain("Cart RAM")
  95.  
  96. while true do
  97.     --gui.drawText(10, 10, "cx: " .. cx)
  98.     --gui.drawText(10, 30, "cy: " .. cy)
  99.    
  100.     p2_cy = p1_cy
  101.     p2_cx = p1_cx
  102.     p1_cy = cy
  103.     p1_cx = cx
  104.  
  105.     cy = memory.read_u16_be(0xF0E)
  106.     cx = memory.read_u16_be(0xF0A)
  107.  
  108.     drawn = 0
  109.     local sx = bit.rshift((cx - 176), 4)
  110.     local sy = bit.rshift((cy - 168), 4)
  111.     local m = 0
  112.     while m < 11 do
  113.         local n = 0
  114.         while n < 10 do
  115.             drawTile(sx + m, sy + n)
  116.             n = n + 1
  117.         end
  118.         m = m + 1
  119.     end
  120.    
  121.     i = i + 1
  122.     --gui.drawText(10, 60, "sx: " .. sx)
  123.     --gui.drawText(10, 75, "sy: " .. sy)
  124.     --gui.drawText(10, 90, "drawn: " .. drawn)
  125.    
  126.     emu.frameadvance()
  127. end
  128.  
  129. console.writeline("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement