Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

UNLUMP.EXE remade in sdlBasic

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
chronoboy
Into the past with a splash




Joined: 04 Jun 2010
Posts: 162
Location: Canada

PostPosted: Sun Dec 05, 2010 8:00 pm    Post subject: UNLUMP.EXE remade in sdlBasic Reply with quote

Just as a proof of concept which may grow further into something else, here is unlump re-made in sdlBasic, a popular cross-platform Basic language. I going to see if I can read the various files in the lumps as well and render them on an SDL surface. sdlBasic has been ported to the ARM processor, and is used on the open source gaming platform: GP2X.

Using lumpfiles in sdlBasic is really easy, as it has support for memory mapping an entire file at once... less coding overall.

Code:

function getbyte(bnk,ptr)
  dat = peek(bnk,ptr)
  ptr=ptr+1
  return dat
end function

function getdata(bnk,ptr)
  tmp$=""
  do
    byte=getbyte(bnk,ptr)
    if byte = 0 then
      exit do
    end if
    tmp$=tmp$+chr$(byte)
  loop
  return tmp$
end function

function getlong(bnk,ptr)
  dat = getbyte(bnk,ptr)
  size = (dat shl 16)
  dat = getbyte(bnk,ptr)
  size = orBit(size,(dat shl 24))
  dat = getbyte(bnk,ptr)
  size = orBit(size,dat)
  dat = getbyte(bnk,ptr)
  size = orBit(size,(dat shl 8))
  return size
end function

ptr=0
loadBank("test.rpg",0)
if not direxists("unlumped") then
  mkdir("unlumped")
end if
do
  fi$=lCase(getdata(0,ptr))
  size=getlong(0,ptr)
  print "Lump file: "+fi$
  print "Lump size: "+str$(size)
  reserveBank(1,size)
  memCopy(0,ptr,1,0,size-1)
  saveBank("unlumped/"+fi$,1)
  freeBank(1)
  ptr=ptr+size
  if ptr > bankSize(0)-1 then
    exit do
  end if
loop
freeBank(0)


Since there is no internal tracking on the file position, like GET and PUT in traditional BASIC, I needed to use a special variable that points to the current position in memory in the data bank.

This program does not do any password checking before unlumping, however even though it is able to unlump, I am sure CUSTOM will ask for the password even on unlumped directories. My goal would be to read the lumps in directly from the RPG file. Unfortunately, the RPG file does not have a FAT, so I'll need to implement this(which is easy).
_________________
Current project: Chronoboy Adventures

Website: http://www.chronoboy.com/
Back to top
View user's profile Send private message Visit poster's website
chronoboy
Into the past with a splash




Joined: 04 Jun 2010
Posts: 162
Location: Canada

PostPosted: Sun Dec 05, 2010 10:05 pm    Post subject: Reply with quote

Got the code to load an MXS to work perfectly. I added autoback(0) and screenSwap as it showed the image being drawn pixel by pixel.

It successfully loads the first master palette and displays the first image in the MXS file.

Code:

setDisplay(320,200,8,1)
enablePalette(1)
autoback(0)

ptr=0
loadBank("unlumped/palettes.bin",0)
hdrsize=deek(0,0)
recsize=deek(0,2)
reserveBank(1,recsize)
memCopy(0,hdrsize,1,0,recsize-1)
for i = 0 to 255
  r = peek(1,i*3)
  g = peek(1,i*3+1)
  b = peek(1,i*3+2)
  color(i,rgb(r,g,b))
next
freeBank(1)
freeBank(0)

loadBank("unlumped/ohrrpgce.mxs",0)
i=0
for j = 0 to 3
  for y = 0 to 199
    for x = j to 319 step 4
     l=peek(0,i)
     ink(color(l))
     setPixel(x,y)
     i=i+1
   next
  next
next
freeBank(0)
screenSwap
waitkey


I'm not sure what to read next, perhaps the maptiles and then code a way to easily access and display them. Since I got MXS images read, this would only be my next obvious task. Camera and sprite support is basically already built into sdlBasic, all I need to do is code the animations. For the most part, I believe plot-scripting would be most difficult task. I'll post the next bit of code for map displaying next.
_________________
Current project: Chronoboy Adventures

Website: http://www.chronoboy.com/
Back to top
View user's profile Send private message Visit poster's website
chronoboy
Into the past with a splash




Joined: 04 Jun 2010
Posts: 162
Location: Canada

PostPosted: Mon Dec 06, 2010 12:05 am    Post subject: Reply with quote



Can you guess what this is?

I managed to display an entire map, without the animated tiles or additional layers. It's pretty basic right now, but perhaps I might make a custom map editor in high resolution for those out there who don't like editing their maps in the small space that is currently provided.

Code:

function getbyte(bnk,ptr)
  dat = peek(bnk,ptr)
  ptr=ptr+1
  return dat
end function

function getdata(bnk,ptr)
  tmp$=""
  do
    byte=getbyte(bnk,ptr)
    if byte = 0 then
      exit do
    end if
    tmp$=tmp$+chr$(byte)
  loop
  return tmp$
end function

function getlong(bnk,ptr)
  dat = getbyte(bnk,ptr)
  size = (dat shl 16)
  dat = getbyte(bnk,ptr)
  size = orBit(size,(dat shl 24))
  dat = getbyte(bnk,ptr)
  size = orBit(size,dat)
  dat = getbyte(bnk,ptr)
  size = orBit(size,(dat shl 8))
  return size
end function


Code:

include "dataops.sdllib"

sub viewpalette()
x=0
y=0
for i = 0 to 255
  ink(color(i))
  setPixel(x,y)
  x=x+1
  if x>15 then
    y=y+1
    x=0
  end if
next
end sub

sub unlump(fi$,rpgdir$)
ptr=0
loadBank(fi$,0)
if not direxists(rpgdir$) then
  mkdir(rpgdir$)
end if
do
  fi$=lCase(getdata(0,ptr))
  size=getlong(0,ptr)
  print "Lump file: "+fi$
  print "Lump size: "+str$(size)
  reserveBank(1,size)
  memCopy(0,ptr,1,0,size-1)
  ffi$=rpgdir$+"/"+fi$
  saveBank(ffi$,1)
  freeBank(1)
  ptr=ptr+size
  if ptr > bankSize(0)-1 then
    exit do
  end if
loop
freeBank(0)
end sub

sub loadpal(rpgdir$)
ptr=0
loadBank(rpgdir$+"/palettes.bin",0)
hdrsize=deek(0,0)
recsize=deek(0,2)
reserveBank(1,recsize)
memCopy(0,hdrsize,1,0,recsize-1)
for i = 0 to 255
  r = peek(1,i*3)
  g = peek(1,i*3+1)
  b = peek(1,i*3+2)
  color(i,rgb(r,g,b))
next
freeBank(1)
freeBank(0)
end sub

sub loadmxs(fi$,rec,slot)
autoback(0)
loadBank(fi$,0)
i=(rec*64000)
for j = 0 to 3
  for y = 0 to 199
    for x = j to 319 step 4
     l=peek(0,i)
     ink(color(l))
     setPixel(x,y)
     i=i+1
   next
  next
next
freeBank(0)
grab(slot,0,0,320,200)
cls
autoback(1)
end sub


Code:

include "ohr.sdllib"
setDisplay(320*4,200*4,8,1)
enablePalette(1)

sub putTile(x,y,til)
  tilx=0
  tily=0
  do
    if til<16 then
     tilx=til
     exit do
    end if
    if til>15 then
      tily=tily+1
      til=til-16
    end if
  loop
  blt(1,tilx*20,tily*20,20,20,x*20,y*20)
end sub

loadpal("unlumped")
loadmxs("unlumped/viking.til",1,1)
loadBank("unlumped/viking.t00",0)
width=peek(0,7)
height=peek(0,9)
reserveBank(1,width*height)
memCopy(0,11,1,0,(width*height)-1)
screenOpen(1,width*20,height*20,0,0,320*4,200*4,0)
screen(1)
'autoback(0)
i=0
for y = 0 to height-1
  for x = 0 to width-1
    til=peek(1,i)
    if til>159 then
     til=0
    end if
    putTile(x,y,til)
    i=i+1
  next
next
'grab(2,0,0,320,200)
'zoomImage(2,2,2)
'pasteIcon(0,0,2)
'screenSwap
waitkey


There is all the code needed for sdlBasic in order to render the map in that resolution, which is 4X the normal resolution. Scaling does work, just uncomment the zoomImage and change grab accordingly. Enjoy![/img]
_________________
Current project: Chronoboy Adventures

Website: http://www.chronoboy.com/
Back to top
View user's profile Send private message Visit poster's website
chronoboy
Into the past with a splash




Joined: 04 Jun 2010
Posts: 162
Location: Canada

PostPosted: Mon Dec 06, 2010 1:19 am    Post subject: Reply with quote

Basic mouse map editing WORKS!!!!

Code:

include "ohr.sdllib"
setDisplay(320*4,200*4,8,1)
setCaption("Vikings High-Def map")
enablePalette(1)

sub putTile(x,y,til)
  tilx=0
  tily=0
  do
    if til<16 then
     tilx=til
     exit do
    end if
    if til>15 then
      tily=tily+1
      til=til-16
    end if
  loop
  blt(1,tilx*20,tily*20,20,20,x*20,y*20)
end sub

sub loadmap(map,tset)
mp$=str$(map)
if len(mp$)=1 then
  mp$="0"+mp$
end if
loadmxs("unlumped/viking.til",tset,1)
loadBank("unlumped/viking.t"+mp$,0)
width=peek(0,7)
height=peek(0,9)
reserveBank(1,width*height)
memCopy(0,11,1,0,(width*height)-1)
screenOpen(1,width*20,height*20,0,0,320*4,200*4,0)
screen(1)
autoback(0)
i=0
for y = 0 to height-1
  for x = 0 to width-1
    til=peek(1,i)
    if til>159 then
     til=0
    end if
    putTile(x,y,til)
    i=i+1
  next
next
'grab(2,0,0,width*20,height*20)
'zoomImage(2,2,2)
'pasteIcon(0,0,2)
screenSwap
autoback(1)
freeBank(1)
freeBank(0)
end sub

loadpal("unlumped")
map=0
tset=0
loadmap(map,tset)
x=0
y=0
while not key(k_esc)
  if key(k_up) then
    y=y-20
  end if
  if key(k_down) then
    y=y+20
  end if
  if key(k_left) then
    x=x-20
  end if
  if key(k_right) then
    x=x+20
  end if
  if key(k_comma) then
    map=map-1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_period) then
    map=map+1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_leftbracket) then
    tset=tset-1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_rightbracket) then
    tset=tset+1
    screenClose(1)
    loadmap(map,tset)
  end if
  if mouseButton = 1 then
    x=mouseScreenX(1)
    y=mouseScreenY(1)
    x=int(x/20)
    y=int(y/20)
    putTile(x,y,0)
  end if
  screenOffset(x,y)
  waitVBL
wend


You cannot save the map(yet), and it only supports placing a single tile type, tile index 0. This will change soon, but I can happily say that I am able to draw tile index 0 on the map using my mouse. This version also supports map and tileset changing. Beware, that I did not put any checks, so you can load a negative map or tileset to crash the program.

As soon as I make it able to save back maps, auto-detect the tileset, and choose which tile to place... I'll upload a YouTube video displaying this feat.
_________________
Current project: Chronoboy Adventures

Website: http://www.chronoboy.com/
Back to top
View user's profile Send private message Visit poster's website
chronoboy
Into the past with a splash




Joined: 04 Jun 2010
Posts: 162
Location: Canada

PostPosted: Mon Dec 06, 2010 3:39 am    Post subject: Reply with quote

YouTube video of the tile editor in action: http://www.youtube.com/watch?v=0eg6TeCO3nM

Latest code:
Code:

include "ohr.sdllib"
setDisplay(320*4,200*4,8,1)
setCaption("Vikings High-Def map")
enablePalette(1)

common width

sub putTile(x,y,til)
  tilx=0
  tily=0
  tmp=til
  do
    if tmp<16 then
     tilx=tmp
     exit do
    end if
    if tmp>15 then
      tily=tily+1
      tmp=tmp-16
    end if
  loop
  blt(1,tilx*20,tily*20,20,20,x*20,y*20)
end sub

sub savemap(map)
mp$=str$(map)
if len(mp$)=1 then
  mp$="0"+mp$
end if
loadBank("unlumped/viking.t"+mp$,0)
width=peek(0,7)
height=peek(0,9)
memCopy(1,0,0,11,(width*height)-1)
saveBank("unlumped/viking.t"+mp$,0)
freeBank(0)
end sub

sub loadmap(map,tset)
mp$=str$(map)
if len(mp$)=1 then
  mp$="0"+mp$
end if
sngrec=32*2*map+2
sng=deek(4,sngrec)
mus$="unlumped/song"+str$(sng)+".mid"
if fileExists(mus$) then
  loadMusic(mus$)
  playmusic(1)
end if
trec=32*2*map
tset=deek(4,trec)
loadmxs("unlumped/viking.til",tset,1)
loadBank("unlumped/viking.t"+mp$,0)
width=peek(0,7)
height=peek(0,9)
reserveBank(1,width*height)
memCopy(0,11,1,0,(width*height)-1)
screenOpen(1,width*20,height*20,0,0,320*4,200*4,0)
screen(1)
autoback(0)
i=0
for y = 0 to height-1
  for x = 0 to width-1
    til=peek(1,i)
    if til>159 then
     til=0
    end if
    putTile(x,y,til)
    i=i+1
  next
next
'grab(2,0,0,width*20,height*20)
'zoomImage(2,2,2)
'pasteIcon(0,0,2)
screenSwap
autoback(1)
freeBank(0)
end sub

function tilechooser()
screenOpen(2,320,200,640,400,320,200,0)
screenFadein(2,1,1)
while screenFadein(2) = 1
  wait (40)
wend
while mouseButton <> 1
  waitVBL
wend
x=mouseScreenX(2)
y=mouseScreenY(2)
x=int(x/20)
y=int(y/20)
til=(16*y)+x
screenClose(2)
return til
end function

loadBank("unlumped/binsize.bin",0)
maprec=deek(0,4)
print maprec
freeBank(0)
loadBank("unlumped/viking.map",4)

loadpal("unlumped")
map=0
tset=0
loadmap(map,tset)
x=0
y=0
til=0
while not key(k_esc)
  if key(k_up) then
    y=y-20
  end if
  if key(k_down) then
    y=y+20
  end if
  if key(k_left) then
    x=x-20
  end if
  if key(k_right) then
    x=x+20
  end if
  if key(k_comma) then
    savemap(map)
    map=map-1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_period) then
    savemap(map)
    map=map+1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_leftbracket) then
    tset=tset-1
    screenClose(1)
    loadmap(map,tset)
  end if
  if key(k_rightbracket) then
    tset=tset+1
    screenClose(1)
    loadmap(map,tset)
  end if
  if mouseButton = 1 then
    x=mouseScreenX(1)
    y=mouseScreenY(1)
    x=int(x/20)
    y=int(y/20)
    putTile(x,y,til)
    l=(width*y)+x
    poke(1,l,til)
  end if
  if mouseButton = 2 then
    x=mouseScreenX(1)
    y=mouseScreenY(1)
    x=int(x/10)
    y=int(y/10)
  end if
  if mouseButton = 3 then
    til=tilechooser
    screen(1)
  end if
  screenOffset(x,y)
  waitVBL
wend
savemap(map)
freeBank(1)

_________________
Current project: Chronoboy Adventures

Website: http://www.chronoboy.com/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group