Dunjunz level 24 versions

reminisce about bbc micro & electron games like chuckie egg, repton, elite & exile

Related forum: adventures


joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Dunjunz level 24 versions

Postby joachim » Fri Nov 25, 2016 2:41 am

Well, this is odd. The level 24 of Dunjunz whose difficulty alex16cole laments in his Youtube playthrough (https://www.youtube.com/watch?v=EGJUazFerMo) doesn't appear at all in Stuart Lewis's Dunjunz screenshot maps (http://www.stairwaytohell.com/gamehelp/ ... nz-SL.html). Stuart's level 24 is just a key-chasing exercise on a grid layout (http://www.stairwaytohell.com/gamehelp/ ... -SL-24.png).

The playthrough is on B-Em, whereas the screenshot maps have the MODE 5 graphics of the Electron version (most noticeably, totally different graphic for the energy drainer, which on the BBC had been animated with MODE 2 flashing colours; and different wall graphic on some levels).

So what's going on here? Was level 24 changed for the Electron release? Are any other levels different?

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Tue Nov 29, 2016 3:19 am

Ok, I got as far as extracting the level files from the BBC disk and Electron tape versions, stripping off the mild encryption and working out roughly how the levels are represented. It's hard to make out without a real map editing tool, but it looks as if levels 1, 2, 4, 5, 6, 8, 22 and 24 underwent changes of varying degrees for the Electron version. For example, level 8 lost two wall sections in the bottom left corner near the exit, and level 5 gained an extra key/door pair.

(Don't waste too much time running round level 1 looking for the changes, since they're in the inaccessible part of that level. A wall was added around the edge of the world, presumably so that monsters that spawn there won't walk off it.)

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Tue Nov 29, 2016 10:04 am

Sorry, I should have replied to your original message. Level 24 on the Electron does appear to be as the screenshot map on STH shows. I made some videos showing levels 1-22, 22-24 and 25 but accidentally deleted the 22-24 video :( so I discarded the level 25 video as well since it was really only showing how frustrating it was to play. :)

The level format uses a simple XOR process with a counter to obscure the data, doesn't it? If you can share your information, either here or at Retro Software, that would be interesting. :)

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Tue Nov 29, 2016 10:43 pm

After lots of poking through the level files and main Dunjunz game file, I've figured out where almost everything is. If I wanted to write data back into the level files then I'd need to figure out how to calculate the checksum which I believe is at the start of the file. Anyway, here's a screenshot of level 8 as generated by some tools I wrote today. It's not so useful without labels on the keys and doors, but it's a start. :)

8.png
Level 8 of Dunjunz on the Electron.


Incidentally, I don't see the wall on level 1 that you referred to. Is that on the BBC version?

1.png
Level 1 of Dunjunz on the Electron.

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Wed Nov 30, 2016 12:37 am

Nice work!
davidb wrote:Incidentally, I don't see the wall on level 1 that you referred to. Is that on the BBC version?

You're right, the wall is on the BBC version and I misspoke.
Since nobody on this thread has yet presented the two versions side by side, here's alex16cole's youtube playthrough reaching the bottom left of level 8, to be compared with your screenshot map above: https://youtu.be/5QmeLLGoU94?t=440. Notice that the wall sprites are significantly different between the BBC and Electron, presumably because of the change from MODE 2 to MODE 5.
davidb wrote:If I wanted to write data back into the level files then I'd need to figure out how to calculate the checksum which I believe is at the start of the file.

Funny, looking at the Electron data files (I was too lazy to look at code, I just compared hex dumps of the files to screenshot maps and thought very hard about how I would have coded it) I wondered if the first byte was a checksum. But on the BBC data files it seems to be usually ff. So maybe the BBC version doesn't check the checksums and you could try loading into that?

I found that when levels had been edited between BBC and Electron, even only slightly, the lists of objects at the beginning of the file were in a different order (for example, in Level 1 they are almost exactly backwards except that the exit still comes last), which makes it annoying to diff the files directly but should be no trouble for a tool like the one you've apparently already built :).

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 12:54 am

joachim wrote:Nice work!

Thanks! :D
joachim wrote:You're right, the wall is on the BBC version and I misspoke.
Since nobody on this thread has yet presented the two versions side by side, here's alex16cole's youtube playthrough reaching the bottom left of level 8, to be compared with your screenshot map above: https://youtu.be/5QmeLLGoU94?t=440. Notice that the wall sprites are significantly different between the BBC and Electron, presumably because of the change from MODE 2 to MODE 5.

Possibly. I wonder if the Electron version was done in a hurry. The sprites in the main file are 24 bytes long (8 x 12 pixels with 4 bits per pixel) but they are positioned in 48 byte intervals, so maybe the programmers just converted them to MODE 5 and left the rest of the sprite data in the second 24 bytes of each slot. I haven't actually checked to see if this is the case. :-k

joachim wrote:Funny, looking at the Electron data files (I was too lazy to look at code, I just compared hex dumps of the files to screenshot maps and thought very hard about how I would have coded it) I wondered if the first byte was a checksum. But on the BBC data files it seems to be usually ff. So maybe the BBC version doesn't check the checksums and you could try loading into that?

Maybe I'll try that. I'm just guessing that it's a checksum, of course. If I get a chance I'll try and find the disassemble the code to see what it's doing.

joachim wrote:I found that when levels had been edited between BBC and Electron, even only slightly, the lists of objects at the beginning of the file were in a different order (for example, in Level 1 they are exactly backwards), which makes it annoying to diff the files directly but should be no trouble for a tool like the one you've apparently already built :).

Well, I don't know about that. Experience with other games has taught me never to assume that the BBC version will be just like the Electron one. ;) I should definitely look at the BBC levels, though, just to see what they're like.

I'll try and put the code somewhere tomorrow.

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Wed Nov 30, 2016 1:08 am

By the way, we shouldn't lose this previous thread which claims (haven't checked) to contain Dunjunz editing utilities.

User avatar
billcarr2005
Posts: 1102
Joined: Fri Sep 09, 2005 3:01 pm
Location: UK
Contact:

Re: Dunjunz level 24 versions

Postby billcarr2005 » Wed Nov 30, 2016 1:39 am

Not forgetting there's *EDITOR on the original disk, which allows you to load both BBC and Electron LEVEL files in, and might be easier to dissect than ploughing through the game code.

*LOADing EDITOR
then
*LOADing LEVEL? 2700
then
CALL&214C appears to run the level decryption code

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 8:04 am

Thanks guys. I was hoping someone might have some input based on the game editor. :)

User avatar
billcarr2005
Posts: 1102
Joined: Fri Sep 09, 2005 3:01 pm
Location: UK
Contact:

Re: Dunjunz level 24 versions

Postby billcarr2005 » Wed Nov 30, 2016 8:15 am

The map decoding seems to take place in a loop around &1F41, starting with

Code: Select all

1F41 LDA #00 ; STA &81 (Y POSITION)
1F45 LDA #00 ; STA &80 (X POSITION)


these are checked against being #&20 (32) for the width and #&30 (48) for the height

Code: Select all

1F55 LDA &80 ; CMP #&20 (32 = WIDTH) ; BNE &1F49
1F5B INC &81
1F5D LDA &81 ; CMP #&30 (48 = HEIGHT) ; BNE &1F45


which leads me to thinking that inbetween is where the heavy lifting is done

Code: Select all

1F49 JSR &2B76
1F4C CMP #&FF ; BEQ 1F53
1F50 JSR &2B62
1F53 INC &80


There's also some manipulation of the newly decrypted level data at

Code: Select all

1F38 JSR &7B00

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 11:37 am

Is that from the editor code? On the Electron, there's a string for the level file name at 0x16d0 and code to load the file starts at 0x1479:

Code: Select all

    1479 : LDA #D0     ; file name address (low byte)
    147B : STA 3E60   
    147E : LDA #16     ; file name address (high byte)
    1480 : STA 3E61   
    1483 : LDX #60     
    1485 : LDY #3E     
    1487 : LDA #3B     
    1489 : STA 3E63  ;   load address (high byte)
    148C : LDA 0212    ; OSFILE address (low byte)
    148F : STA 149B   
    1492 : LDA 0213    ; OSFILE address (high byte)
    1495 : STA 149C   
    1498 : LDA #FF     
    149A : JSR F27D    ; this address is changed by the above writes to 0x149b and 0x149c (so, this just calls OSFILE)
    149D : JMP 0450   

The code at 0x450 unscrambles the data, accumulating a value that it checks against a value in a lookup table at 0x490:

Code: Select all

    0450 : LDY #00     
    0452 : STY 70     
    0454 : STY 72      ; value (0x72) = 0
    0456 : LDA #3B     
    0458 : STA 71      ; address (0x70,0x71) = 0x3b00
loop:
    045A : LDA (70),Y  ; load data
    045C : EOR 70      ; EOR with low address byte (0-255)
    045E : STA (70),Y  ; store unscrambled data
    0460 : CLC         
    0461 : ADC 72      ; add current total to the data byte
    0463 : STA 72      ; and store it

    0465 : INC 70      ; end of loop checks
    0467 : BNE 046B   
    0469 : INC 71     
    046B : LDA 70     
    046D : CMP #B0     
    046F : BNE 045A   
    0471 : LDA 71     
    0473 : CMP #3D     
    0475 : BNE 045A   

    0477 : LDX 169F    ; X=level number
    047A : LDA 72      ; load the calculated value
    047C : CMP 0490,X  ; compare it to the stored value for this level
    047F : BEQ 0484    ; exit if equal
    0481 : JSR D9CD    ; otherwise do something else, probably resets
    0484 : RTS         

Since we have the code to calculate the checksum - simply adding together all the unscrambled values in the file - and know that we have to compare the low byte of the result with the value in the lookup table then we can write code to generate the first byte in the file. That's the next step! :D

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 4:50 pm

I've put some tools in this repository. Thanks to the discussion here, I've also been able to patch the game slightly so that the level files can be compressed more effectively and will now fit into two ROMs, useful for those who want to install it on the Mega Games Cartridge. :D

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Wed Nov 30, 2016 10:23 pm

Having seen that the level file format is significantly dependent on (object x, object y, object type) data rather than a simple array, I've started to wonder how well the game supports having multiple objects on the same square.

Certainly you can create a few such cases by playing the unmodified game: for example, if a character holding a key dies while on a drainer then the game displays the drainer, corpse and key all flickering on the same square and it behaves roughly how you expect (in fact, there's the trick of dying while on a drainer so that the drainer can then be destroyed without reflecting weapons: https://youtu.be/EGJUazFerMo?t=290). But I don't know whether you could put a key on a drainer in the level file and have it work similarly. And it's hard to guess what the effect of putting two keys (or two doors) in the same square would be.

(The other flickering I remember seeing is on Electron Dunjunz, the potion sprite used to sometimes cause corrupted data to be drawn into the square below. I suspect this is some kind of confirmation of David's theory that the sprite size was hastily converted from 48 bytes to 24.)

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 11:03 pm

I'll have to play with the level data a bit and see what happens. I get the feeling that multiple collectable objects will not be supported - once the bit in the bitmap that seems to be for these kinds of items is set then there won't be a chance to collect a second or third item. Energy drainers and keys are stored separately, so that would explain why they can coexist, and I would expect the players' characters to be treated independently of items.

I was just surprised that there's a fairly small limit to the number of items on each level. I seem to remember that Icarus (by the same author) is different in that respect.

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Wed Nov 30, 2016 11:44 pm

davidb wrote:I'll have to play with the level data a bit and see what happens. I get the feeling that multiple collectable objects will not be supported - once the bit in the bitmap that seems to be for these kinds of items is set then there won't be a chance to collect a second or third item.

Well, it turns out that you can just pile on the objects. Shows what I know! :shock: It's not a good idea to put the key on the same square as the door it opens, however. :)

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Sat Dec 03, 2016 8:42 pm

davidb wrote:
davidb wrote:I'll have to play with the level data a bit and see what happens. I get the feeling that multiple collectable objects will not be supported - once the bit in the bitmap that seems to be for these kinds of items is set then there won't be a chance to collect a second or third item.

Well, it turns out that you can just pile on the objects. Shows what I know! :shock: It's not a good idea to put the key on the same square as the door it opens, however. :)


In fact there's an example of multiple collectable objects on a square in the data for Electron level 5. The leftmost key in the bottom row — the key at (14, 44) (11, 46) which opens the small room with two keys just to its right at (14, 44) — is actually two keys, both in the same spot, which both open the same door! You can see this in your Electron playthrough: at https://youtu.be/FHao3B5Gppw?t=1439 the fighter is juggling three keys on a square, and a few seconds later one has been used on a door, one is in the fighter's possession and one is still left on the ground.

This is also the only difference between Electron and BBC on level 5: the BBC has one key as you'd expect.
Last edited by joachim on Sat Dec 03, 2016 9:59 pm, edited 1 time in total.

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Sat Dec 03, 2016 9:31 pm

joachim wrote:In fact there's an example of multiple collectable objects on a square in the data for Electron level 5. The leftmost key in the bottom row — the key at (14, 44) which opens the small room with two keys just to its right — is actually two keys, both in the same spot, which both open the same door! You can see this in your Electron playthrough: at https://youtu.be/FHao3B5Gppw?t=1439 the fighter is juggling three keys on a square, and a few seconds later one has been used on a door, one is in the fighter's possession and one is still left on the ground.

Yes, that did confuse me a bit!

I've updated my mapping tools a bit, though not really to take that feature into account. Key 13 at the bottom of the map sits on the same square as key 1, whose door does not appear on the level. :)
Attachments
5.png
Level 5 of Dunjunz.

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Sat Dec 03, 2016 10:05 pm

davidb wrote:I've updated my mapping tools a bit, though not really to take that feature into account. Key 13 at the bottom of the map sits on the same square as key 1, whose door does not appear on the level. :)


Well, the level data says that door 1 is in the same place as door 13. Your level-reading code throws that away when it builds a map (x,y) -> door number, but the game may allow you to unlock the door with either key.

By the way, your comment in textmap.py claims "Teleporter - transports to the square above the next in the list", but in your playthrough of level 5 the teleporters do not transport you in the order of the numbers on the map you have posted. Either the order needs to be reversed or (more likely at a guess) the teleporters just take you to the next teleporter in left-to-right top-to-bottom order and the order in which they're stored in the level data does not matter.

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Sat Dec 03, 2016 10:33 pm

joachim wrote:Well, the level data says that door 1 is in the same place as door 13. Your level-reading code throws that away when it builds a map (x,y) -> door number, but the game may allow you to unlock the door with either.


Yes, there are two keys and two doors there. The second door will reappear even if the first one is opened, but you can walk through it or collect the second key and open it as well. This is presumably because the game clears the bit in the bitmap it uses to recorded which squares on the map are solid when the first door is opened.

I've updated the code to show multiple numbers for keys and doors for any cases where this type of things occurs.

joachim
Posts: 115
Joined: Wed Jun 21, 2006 1:20 am

Re: Dunjunz level 24 versions

Postby joachim » Sat Dec 03, 2016 10:49 pm

davidb wrote:Yes, there are two keys and two doors there. The second door will reappear even if the first one is opened, but you can walk through it or collect the second key and open it as well. This is presumably because the game clears the bit in the bitmap it uses to recorded which squares on the map are solid when the first door is opened.

Wow, that's comprehensively researched, thank you.

Sounds like you understand why there are two bitmaps in the level data, too, which is something I don't really get. Why isn't there just one bitmap showing where the walls are, and then you can assume that everything that isn't set in the bitmap and isn't in the object list is empty space?

User avatar
davidb
Posts: 1901
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Dunjunz level 24 versions

Postby davidb » Sat Dec 03, 2016 11:21 pm

joachim wrote:Wow, that's comprehensively researched, thank you.

I merely played the level until I got to that point. :)

joachim wrote:Sounds like you understand why there are two bitmaps in the level data, too, which is something I don't really get. Why isn't there just one bitmap showing where the walls are, and then you can assume that everything that isn't set in the bitmap and isn't in the object list is empty space?

When I started looking at the level data I noticed that the second bitmap is all set apart from where there are collectable items. However, not every clear bit in the bitmap corresponds to a collectable. For example, on level 7, the starting room contains four pairs of boots and a key, but there are other squares that are clear in the bitmap. The "!" characters represent these:

Code: Select all

########
#k!   !#
#      #
#  SS  #
#  SS  |
# !    #
#B!B!BB#
########


Maybe the level creator put objects there originally, then deleted them, but somehow the bits were not set to their default values. Or perhaps I'm not interpreting them correctly.
Attachments
7.png
The starting room of level 7.
(1.48 KiB) Not downloaded yet


Return to “software: classic games”

Who is online

Users browsing this forum: No registered users and 6 guests