Author Topic: Screen construction in isometric games  (Read 1110 times)

0 Members and 2 Guests are viewing this topic.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Screen construction in isometric games
« on: 01:29, 15 November 19 »
Hi folks.

Something I've wondered about for a long time is how screens are constructed in isometric games.
For example, when you walk into a new room in Head Over Heels, I'd love to be able to see the screen being drawn and all the objects being placed. It would be a very interesting learning exercise.

I presume that all inks are set to black, the screen is constructed, then all the inks are set to the appropriate colours.
And this is to hide the construction phase.
But it's so interesting to see it happening in something like Last Ninja on the C64, though that game's screen construction is very slow.

I wonder if it's possible to patch a game like HoH, Batman, Knightlore or Alien 8 to skip the code that sets all inks to black when entering a new screen...
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Fessor

  • CPC6128
  • ****
  • Posts: 199
  • Country: de
  • Liked: 164
  • Likes Given: 40
Re: Screen construction in isometric games
« Reply #1 on: 09:35, 15 November 19 »
Here is a great explanation about the Filmation-Engine available: http://retrospec.sgn.net/users/nwalker/filmation/

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 693
  • Country: fr
    • urban exploration
  • Liked: 968
  • Likes Given: 610
Re: Screen construction in isometric games
« Reply #2 on: 11:18, 15 November 19 »
I wonder if it's possible to patch a game like HoH, Batman, Knightlore or Alien 8 to skip the code that sets all inks to black when entering a new screen...


easy with winape and a breakpoint on ink modification
use RASM, the best assembler ever made :p

I will survive

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #3 on: 11:39, 15 November 19 »
Here is a great explanation about the Filmation-Engine available: http://retrospec.sgn.net/users/nwalker/filmation/


That's tremendous, thanks!
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #4 on: 11:42, 15 November 19 »
easy with winape and a breakpoint on ink modification


I'd love to have a try.  :)
What sort of code would I need to look for, in order to find ink modification code?
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 693
  • Country: fr
    • urban exploration
  • Liked: 968
  • Likes Given: 610
Re: Screen construction in isometric games
« Reply #5 on: 12:03, 15 November 19 »
in fact it would be useless  ;D


the screen is built in another buffer in #9000 then copied to the real screen without changing INK, so there is no "inks to black" at all


here is some capture of the memory



use RASM, the best assembler ever made :p

I will survive

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #6 on: 13:36, 15 November 19 »
Oh wow... ok.
That's a shame.

Nonetheless, those screenshots you posted are *very* interesting.
Thanks for taking the time to do those.
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.718
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 952
  • Likes Given: 1676
Re: Screen construction in isometric games
« Reply #7 on: 22:20, 15 November 19 »
Could the Screen Blanking process be using the CTRC to hide the drawing process and simply use it to again to when complete?


A BASIC example of the process:


Code: [Select]
10 MODE 0
20 OUT &BC00,1:OUT &BD00,0
30 LOCATE 10,10:PRINT"A"
40 CALL &BB18
50 OUT &BC00,1:OUT &BD00,40
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 853
  • Liked: 409
  • Likes Given: 72
Re: Screen construction in isometric games
« Reply #8 on: 10:42, 16 November 19 »
Could the Screen Blanking process be using the CTRC to hide the drawing process and simply use it to again to when complete?


A BASIC example of the process:


Code: [Select]
10 MODE 0
20 OUT &BC00,1:OUT &BD00,0
30 LOCATE 10,10:PRINT"A"
40 CALL &BB18
50 OUT &BC00,1:OUT &BD00,40


It would be a way to do it, although generally isn't. There are lots of other reasons for using a back buffer, particularly that you can lay it out as a more idealised version of screen memory and thus avoid having to deal with screen addressing weirdness at the same time as drawing tiles.

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.120
  • Country: br
  • Liked: 1094
  • Likes Given: 1863
Re: Screen construction in isometric games
« Reply #9 on: 19:11, 17 November 19 »
Something I've wondered about for a long time is how screens are constructed in isometric games.
For example, when you walk into a new room in Head Over Heels, I'd love to be able to see the screen being drawn and all the objects being placed. It would be a very interesting learning exercise.

I presume that all inks are set to black, the screen is constructed, then all the inks are set to the appropriate colours.
And this is to hide the construction phase.

I wonder if it's possible to patch a game like HoH, Batman, Knightlore or Alien 8 to skip the code that sets all inks to black when entering a new screen...
Well, my favorites CPC games are Batman and HoH. And because that I disassembled those games a lot of moons ago. Jon Ritman's isometric code is well optimized and it doesn't need an extra buffer. Both games work exactly as you said, they put black inks and then build the screen. Of course, both games are very easy to patch for using other palette than a black one. For patching those games, open WinApe, load the games (I used the cpc-power original floppy versions):
Code: [Select]
In Batman change the memory address $032A from $08 to $07 (for using the palette number 7, for example).
In Head Over Heels change the memory address $04F9 from $08 to $07 (in the same way than before).
And you will see how the screen is built, but as I said the Ritman code for drawing is well optimized and I don't know if it would be helpful for you:

It would be a way to do it, although generally isn't. There are lots of other reasons for using a back buffer, particularly that you can lay it out as a more idealised version of screen memory and thus avoid having to deal with screen addressing weirdness at the same time as drawing tiles.
I would love to hear a few of those reasons for using a back buffer.

Because for me, the only reason in a CPC game for using a back buffer so big as the actual screen, it is because that game is an speccy port. A decent CPC game that need so big buffer, it would use a double buffer instead (saving the stupid LDI/LDIR copy pass) and a rupture for splitting the HUD from the game area.

Knightlore and Alien 8 are speccy ports. They use the typical Ultimate routine of drawing the graphics downside for hoping the raster only will catch once... not in CPC, mate, because you need to copy more data. And the screen is dumped from the buffer to the video ram using LDIRs. All that make those games super slow if you compare with Ritman's games. Even the sprite routine could be a lot better and use a minimal ram buffer for preparing the sprites in those Ultimate games.



Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #10 on: 02:11, 18 November 19 »
Thanks Syx.
That's really fantastic information.
I'm impressed with how HoH constructs the screen.
(HoH is also my favourite CPC game of all time).

Considering the z-ordering that would have to occur when positioning objects on the screen, I'm surprised (and *very* impressed) by what John Ritman did.

I wonder if Ultimate's games can be patched to use stack-based screen-redraw instead of LDI-based.
How would I go about disassembling the code?
(And does the disassembler tell us what the execution address is?)

[EDIT] It's really cool playing HoH with the small patch.
Very weird to see the screen being drawn, but fascinating.
Interesting how all the colours revert to some sort of defaults when changing screen, and then change to the correct colours for the screen being entered.
« Last Edit: 02:27, 18 November 19 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Fessor

  • CPC6128
  • ****
  • Posts: 199
  • Country: de
  • Liked: 164
  • Likes Given: 40
Re: Screen construction in isometric games
« Reply #11 on: 02:24, 18 November 19 »
If you know the Addresses (Load-Address, Entry-Point) you can use ghidra to REassemble binarys and try to reconstruct a sourcefile.
https://ghidra-sre.org/

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #12 on: 02:27, 18 November 19 »
If you know the Addresses (Load-Address, Entry-Point) you can use ghidra to REassemble binarys and try to reconstruct a sourcefile.
https://ghidra-sre.org/


Thanks!
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.120
  • Country: br
  • Liked: 1094
  • Likes Given: 1863
Re: Screen construction in isometric games
« Reply #13 on: 15:44, 18 November 19 »
You are welcome @ervin :)

If I remember well, Batman and HoH use exactly the same algorithm for building the screens. HoH has minor optimizations, but nothing too fancy, Ritman was most focused in good data structures than hyperfast routines.

And the PCW version of those games are based in the CPC code, too. Load HoH in the CP/M Box emulator, go to the debugger and change the value in the RAM address $051D from $C9 to $00. And you will see the same effect over the PCW version. This version has a nice extra, the double screens are in the native PCW resolution, the equivalent to mode 2 in CPC; and they look superb.

Considering the z-ordering that would have to occur when positioning objects on the screen, I'm surprised (and *very* > impressed) by what John Ritman did.
If you change the WinApe timing (Settings > General) to the minimum (5%), you will see how take more time when the z-ordering is more complex, for example, in that first screen when the draw routine has to draw the right door over the floor.

I wonder if Ultimate's games can be patched to use stack-based screen-redraw instead of LDI-based.
Sure, and even having a nice unrolled LDI sequence should help something with the speed. If I remember well, there was enough space for it.

How would I go about disassembling the code?
(And does the disassembler tell us what the execution address is?)
For a lot of things, you can use the WinApe debugger, that is good enough for researching algorithms fast. I used for example for making the list with games using hardware scroll.

But, in the old days, I used dz80 or something like that, but it was a very boring and time consuming task, because you need to write the address with code and data in a text file for disassembly the binary better. Later I discovered the old ms dos free version of IDA, the one that supported z80, and after using an interactive disassembler, you will never go back to the old way. Those days, as Fessor recommended, the best option is using Ghidra, because it is open source and very active... and it doesn't cost a fortune like IDA :P

But in the case of using a disassembler, even if the most recommendable way would be to discover the loading and execution address. There is a easy and fast way, load the game in WinApe, start the game, then go to the debugger, save all the memory to a file and write in a paper the PC address, where the screen is, if interrupts were enabled, ... Load that file in the disassembler and set the start address for disassembling the code from the PC address that you wrote before. Remember that if a game uses interrupts, the interrupt handler would be in $0038. Mark places with data... And then go on, after a while you will be able to understand and see which bytes sequences are code: $C9 (RET), $C3 xx xx (JP $xxxx), $CD xx xx (CALL $xxxx), ...


Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #14 on: 16:11, 18 November 19 »
Thank you Syx!
REALLY great info!
One day when I have some spare time, I might look into that LDI sequence.
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.120
  • Country: br
  • Liked: 1094
  • Likes Given: 1863
Re: Screen construction in isometric games
« Reply #15 on: 18:51, 18 November 19 »
One day when I have some spare time, I might look into that LDI sequence.
Maybe by that day, we have a CPC emulator that includes more features for helping with boring disassembly tasks. Something in the line of the memory trace dumps used by Skoolkit or the advanced disassembler/profiler included in emulators like Emulicious. Although for example, a way of using breakpoints to machine events like when the tape or floppy motor stop, it could help to automatize things like finding the execution address ;)

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.120
  • Country: br
  • Liked: 1094
  • Likes Given: 1863
Re: Screen construction in isometric games
« Reply #16 on: 20:50, 18 November 19 »
And looking in my folder of isometric games research, I found a document from Jon Ritman explaining a few interesting things about his engine to one of the guys that made an HoH remake in the middle of last decade. I am going to attached it to this thread just in case it is not well known.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.298
  • Country: au
    • index.php?action=treasury
  • Liked: 953
  • Likes Given: 1063
Re: Screen construction in isometric games
« Reply #17 on: 00:49, 19 November 19 »
And looking in my folder of isometric games research, I found a document from Jon Ritman explaining a few interesting things about his engine to one of the guys that made an HoH remake in the middle of last decade. I am going to attached it to this thread just in case it is not well known.

Thanks for the pdf - it's *very* interesting.
There are some techniques in there I would never have thought of, like splitting tall objects. Very clever.

Yes, that remake was absolutely fantastic.
It was very generous of Jon to discuss his techniques like that.
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline dthrone

  • CPC6128
  • ****
  • Posts: 158
  • Country: gb
    • SOHDE
  • Liked: 113
  • Likes Given: 153
Re: Screen construction in isometric games
« Reply #18 on: 01:43, 19 November 19 »
Nice doc!  :)