Silly fun episode XI:

So I was perusing miner 2049er main memory looking for where it draws the words PLAYER 1 and PLAYER2 but I couldn't find it. I finally figured out it was loading the screens from disk.

How to view them? Why just rewrite my memory viewer to load the data from a .dsk file instead. Just read a .dsk file into a lua string and use that as the data source.

I just let the miner 2049er program crash, since it loads some of its code into the first hi-res page and then it won't be competing for the hi-res page 0. I set up the "9" key to re initialize graphics mode.

It's neat to scroll through the disk stepping by blocks of 256 bytes, when it comes across a hi-res screen it's like it's "tuning" into view like a television.

Code
function rem(a) print(a) end
function remp(a,b,c,d) print(a,b,c,d) end
function rem(a) end
function float(f) return string.format("%6.2f",f) end
function hex(a) return string.format("0x%02x",a) end
function calc(line,page) page=page or 0 return line % 8 * 1024 + math.floor(line / 64) * 40 + math.floor((line%64) / 8) * 128 + 8192* (page + 1) end

function iif(a,b,c) if a then return b else return c end end 
function bool10(a) return iif(a,1,0) end

function bin(x,numbits,gap) if x==nil then return nil end gap=gap or "_" numbits=numbits or 8 str="" for i=numbits-1,0,-1 do str=str..iif((x&(2^i))~=0,"1","0")..iif((i%8==0) and (i>0),gap,"") end return str end

function myframedispatcher() if myframedispatchlist ~= nil then for i,j in pairs(myframedispatchlist) do j() end end end

function between(a,b,c) return (a >= b) and (a <= c) end

disksize=143360

function disktovideointerleave(start)
if mydisk==nil then return end
cpu = manager:machine().devices[":maincpu"];mem = cpu.spaces["program"]
for i=0,screenwidth do
for j=0,191 do
xpos = i
ypos = j
      if between(xpos,0,screenwidth-1) and between(ypos,0,191) then
            memaddress=calc(ypos)+xpos
            mempos=start+(memaddress-8192)
       if between(mempos,0,disksize-1) then valuetowrite=mydisk:byte(mempos+1)
          else valuetowrite = iif(mempos%1==0,0xaa,0x55)
       end
       mem:write_u8(memaddress,valuetowrite)
      end
end
end
end


function disktovideo(start,stride)
if mydisk==nil then return end
cpu = manager:machine().devices[":maincpu"];mem = cpu.spaces["program"]
screenwidth=40
mempos=start
for i=0,screenwidth+stride,stride do
for j=0,191 do
for k=0,stride-1 do
      xpos=i+k
      ypos=j
      if between(xpos,0,screenwidth-1) and between(ypos,0,191) then
         memaddress=calc(ypos)+xpos
         if between(mempos,0,disksize-1) then valuetowrite=mydisk:byte(mempos+1)
            else valuetowrite = iif(mempos%1==0,0xaa,0x55)
         end
         mem:write_u8(memaddress,valuetowrite)
      end
      mempos=mempos+1
end
end
end
end


function setgfx()
cpu = manager:machine().devices[":maincpu"];mem = cpu.spaces["program"]
dummy=mem:read_u8(0xc050)  -- display graphics
dummy=mem:read_u8(0xc052)  -- full screen
dummy=mem:read_u8(0xc054)  -- page 1
dummy=mem:read_u8(0xc057)  -- hi res
end

function iskeypressed(keycode) 
inp = manager:machine():input() return inp:code_pressed(inp:code_from_token(keycode))
end

mempos0=0
memorystep=192
blockwidth=1

framecounter=0
keydelay=0
interleavemode=0

function diskviewer()
if keydelay > 0 then keydelay=keydelay-1 end
framecounter=framecounter+1
if framecounter % 5 == 0 then 
   framecounter=0
if interleavemode == 0 then disktovideo(mempos0,blockwidth) else disktovideointerleave(mempos0) end
if     iskeypressed("KEYCODE_1") then 
     if interleavemode == 0 then
          mempos0=mempos0 - (iif(iskeypressed("KEYCODE_LSHIFT"),8*blockwidth,iif(iskeypressed("KEYCODE_LCONTROL"),1,memorystep*blockwidth)))
     else
          mempos0=mempos0 - 256 mempos0 = math.floor(mempos0 / 256) * 256
     end
          mempos0=math.max(0,mempos0)
elseif iskeypressed("KEYCODE_2") then 
     if interleavemode == 0 then
          mempos0=mempos0 + (iif(iskeypressed("KEYCODE_LSHIFT"),8*blockwidth,iif(iskeypressed("KEYCODE_LCONTROL"),1,memorystep*blockwidth)))
     else
         mempos0=mempos0 + 256 mempos0 = math.floor(mempos0 / 256) * 256
     end
          mempos0=math.min(disksize-1,mempos0)
elseif iskeypressed("KEYCODE_BACKSPACE") then myframedispatchlist={} 
elseif iskeypressed("KEYCODE_3") and keydelay==0 then blockwidth=blockwidth-1 blockwidth=math.max(blockwidth,1)   keydelay=20
elseif iskeypressed("KEYCODE_4") and keydelay==0 then blockwidth=blockwidth+1 blockwidth=math.min(blockwidth,128) keydelay=20
elseif iskeypressed("KEYCODE_9") then setgfx()
elseif iskeypressed("KEYCODE_7") then interleavemode=0
elseif iskeypressed("KEYCODE_8") then interleavemode=1 
end
end
manager:machine().screens[":screen"]:draw_text(350,0,"Disk Viewer  File="..iif(diskname==nil,"NO DISK",diskname).."\nAddress="..hex(mempos0).."  Blockwidth="..blockwidth.."\n"..iif(interleavemode==0,"","Hi-res interleave mode\n").."\n\nPress 1,2 = move by column\nshift+1,2 = move by 8 * blocksize\nctrl+1,2 = move by 1\n3,4 = increase/decrease blockwidth\n7 = Hi res interleave mode off\n8= Hi res interleave mode on\n9= Reset Graphics mode\nBackspace = quit",0xffffffff,0xffff0000)
if mydisk==nil then manager:machine().screens[":screen"]:draw_text(0,0,"No Disk Loaded") end
end

myframedispatchlist={} table.insert(myframedispatchlist,diskviewer)

if alreadyregisteredmyframedispatcher==nil then
  emu.register_frame_done(myframedispatcher)
  alreadyregisteredmyframedispatcher=true
end

function clrd() myframedispatchlist={} end

function loaddisk(filename)
   myfile=assert(io.open(filename,"r"))
   mydisk = myfile:read("*all")
   myfile:close()
   diskname=filename
end

function viewdisk(filename)
  loaddisk(filename)
  myframedispatchlist={} table.insert(myframedispatchlist,diskviewer)
end

-- dofile("../../mame205_extract/mame/memviewer_diskviewer_lua.txt")
-- loaddisk("miner 2049er (1982)(micro fun)(clean crack).dsk")

[Linked Image from i.imgur.com]

Last edited by Golden Child; 02/03/19 10:40 AM.