Starting a Prince of Persia port...

Got a programming project in mind? Tell everyone about it!
User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Tue Aug 08, 2017 8:34 am

Dethmunk wrote:Its a pretty quick and dirty digitization through Image2BBC, I added the text and tidied a few pixels up. I would probably spend and fair bit of time tidying it up more for proper artwork for a game. :wink:

Wow, these look amazing! OK, I promise I will dust off the code and start looking at this again on my commute home tonight. It might be a while before I need you services to remake the artwork but this is certainly an incentive!

User avatar
Dethmunk
Posts: 165
Joined: Fri Jul 01, 2016 12:29 pm
Location: Guildford
Contact:

Re: Starting a Prince of Persia port...

Postby Dethmunk » Wed Aug 09, 2017 7:07 pm

kieranhj wrote:
Dethmunk wrote:Its a pretty quick and dirty digitization through Image2BBC, I added the text and tidied a few pixels up. I would probably spend and fair bit of time tidying it up more for proper artwork for a game. :wink:

Wow, these look amazing! OK, I promise I will dust off the code and start looking at this again on my commute home tonight. It might be a while before I need you services to remake the artwork but this is certainly an incentive!


LOL. Well I've finished up on WhiteLight (shoot-em-up) for Sarah Walker. Unless she has any last minute tweaks she wants. I do have my own projects I'm currently fiddling with :wink: , but I'm always willing to help when I can. :D
Image

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Thu Aug 10, 2017 9:46 am

Dethmunk wrote:LOL. Well I've finished up on WhiteLight (shoot-em-up) for Sarah Walker. Unless she has any last minute tweaks she wants. I do have my own projects I'm currently fiddling with :wink: , but I'm always willing to help when I can. :D

I just started wading back through the (epic amounts of) PoP code. First step will be to try and get the level rendering code up & running in MODE 1. I think it will be a long while before I require your artistic services but thank you for the offer. I will keep you posted as to my progress and look forward to seeing any new projects you come up with in the meantime.

User avatar
Dethmunk
Posts: 165
Joined: Fri Jul 01, 2016 12:29 pm
Location: Guildford
Contact:

Re: Starting a Prince of Persia port...

Postby Dethmunk » Thu Aug 10, 2017 7:08 pm

kieranhj wrote:
Dethmunk wrote:LOL. Well I've finished up on WhiteLight (shoot-em-up) for Sarah Walker. Unless she has any last minute tweaks she wants. I do have my own projects I'm currently fiddling with :wink: , but I'm always willing to help when I can. :D

I just started wading back through the (epic amounts of) PoP code. First step will be to try and get the level rendering code up & running in MODE 1. I think it will be a long while before I require your artistic services but thank you for the offer. I will keep you posted as to my progress and look forward to seeing any new projects you come up with in the meantime.


No problem... give us a shout when you're ready ;-)

Currently I'm doing a run of ZX Spectrum games...
Foggy's Quest - Finished
Image

Currently finishing... Circuitry :D
Image

They're coded and built with AGD (Arcade Game Designer) for the ZX Spectrum 48k. Might do one more before the end of the year and then dip back onto the BBC Micro.. 8)
Image

User avatar
Dave Footitt
Posts: 773
Joined: Thu Jun 22, 2006 9:31 am
Location: Abandoned Uranium Workings

Re: Starting a Prince of Persia port...

Postby Dave Footitt » Mon Aug 14, 2017 8:16 am

Dethmunk wrote:They're coded and built with AGD (Arcade Game Designer) for the ZX Spectrum 48k. Might do one more before the end of the year and then dip back onto the BBC Micro.. 8)

Love the look of the circuitry one =D>

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Mon Aug 14, 2017 10:39 am

Dethmunk wrote:No problem... give us a shout when you're ready ;-)

Currently I'm doing a run of ZX Spectrum games...

They're coded and built with AGD (Arcade Game Designer) for the ZX Spectrum 48k. Might do one more before the end of the year and then dip back onto the BBC Micro.. 8)

Nice! Would love to see these in the NULA attribute mode for that Speccy style. :)

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Thu Aug 17, 2017 8:16 pm

Finally, some visible progress to report! I have managed to port the level screen plotting code over to the Beeb and then attach my MODE 4 sprite plotting routine to it. This has been quite an epic journey so far, having ported about 9 of the 29 source modules (although not every function within) and already pushing up against the limits of main memory. The fact that the original game makes extensive use of jump tables as the interface between modules has been invaluable, meaning I can compile with stubs and port functions one at a time as required.

The attached ssd images will step through the 24 screens that comprise level 1 and level 4 respectively. If you don't want to download then try the following jsbeeb links: Level 1 Level 4. This is built for a Master so requires PAGE at &E00 and one bank of SWRAM for the background sprites & level data.

As this is a direct port, it is using the same level draw logic from the Apple II game and works on the level description data & sprite data straight from the GitHub source. I have left it in MODE 4 for now because of (a) memory and (b) the Apple II hi-res screen is technically B&W (albeit with artefact colour) so it is easier to test the bit rotation without the complications of additional lookups for MODE 1 conversion.

I'm quite pleased that I have made it this far and a real boost to my conviction that a full Master port is possible. Next step will be to get the high-level main loop in place and see if I can get the main Kid character routines going. Still a lot of work to do. :D
Attachments
pop-beeb-in-mode4.png
Start screen in MODE 4
pop-beeb-plot-level-mode4.zip
Level 1 & level 4 plotted in MODE 4
(22.52 KiB) Downloaded 3 times

User avatar
tricky
Posts: 1735
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Starting a Prince of Persia port...

Postby tricky » Fri Aug 18, 2017 5:29 am

Nice going.

User avatar
jbnbeeb
Posts: 359
Joined: Sat Apr 03, 2010 8:16 pm

Re: Starting a Prince of Persia port...

Postby jbnbeeb » Fri Aug 18, 2017 7:42 am

Looking great Kieran. Well done. Always bowled over by your work!
I've been reading the thread with interest and remember you showing your sprite plotting routine at Cambridge.

As you progress, it'd be great to see a dev diary of sorts - I guess you're doing that now. I'd love to read about how you solve the various issues you're facing.. like squishing all the code and data into SWRAM banks compared to the two 64k banks of the Apple II.
I'm going to ..
ABUG North Halifax June 10-12
Image

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 9:28 am

jbnbeeb wrote:Looking great Kieran. Well done. Always bowled over by your work!
I've been reading the thread with interest and remember you showing your sprite plotting routine at Cambridge.

As you progress, it'd be great to see a dev diary of sorts - I guess you're doing that now. I'd love to read about how you solve the various issues you're facing.. like squishing all the code and data into SWRAM banks compared to the two 64k banks of the Apple II.

Thanks. Yes, memory is going to be a huge challenge... :-k

According to my GitHub check-ins, it's been about 9 days of work to go from the sprite plotting code to getting the level screens drawing. This doesn't include a large amount of research, reading and preparation that went on beforehand! If people are interested I will try to post more work-in-progress updates, although a lot of the time there won't be much to see just many technical details.

I'll see if I can do a quick post after each day's work (not working every day but most week days if I am commuting on the train.) Happy for people to ask questions and I can add more detail or clarify.

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 12:23 pm

OK, back to the start which was the simple sprite plot routine. The PoP sprite data is in a nice easy format and documented in the technical notes provided by Jordan available online.

Code: Select all

<byte> # images in file
<address first image> - starting at &6000
<address second image> - etc.
...
<address first free>

;address 1
<width in bytes><height in bytes>
<data>
;address 2
<width in bytes><height in bytes>
<data>
etc.


Because of memory requirements I discounted converting the sprites into Beeb screen format for the time being (but may revisit this in future.) For now I just wanted to get something displayed on screen, so the simplest way was to convert the sprite data on the fly.

Apple II hi-res screen data is 7 pixels per byte in reversed order (so the lsb is the left-most pixel) with bit 7 providing a colour clock phase. To convert a byte of data we can LSR so that pixels fall into the Carry flag then ROL into a Beeb byte that can be displayed in MODE 4 (msb as the left-most pixel.) Care has to be taken with the bit counts vs byte boundaries and the character row layout of Beeb screen memory.

Colour is a bit harder but essentially once we have a sequence of B&W bits we can use 3 bits at a time as a lookup into a colour table to reproduce artefact colour. More details on this old thread that I unearthed: https://groups.google.com/forum/#!topic/comp.sys.apple2.programmer/iSmIAVA95WA. Obviously we don't have orange on the Beeb but could be replaced by yellow/red dithering potentially.

This plot routine is pretty slow as we're having to LSR & ROL every pixel, but it works and was enough to get me started on the journey. We can worry about optimising the routine later (e.g. with more lookups) or pre-converting to Beeb sprite format etc.

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 12:35 pm

Next step was to port across the two main header files from the Apple II source: EQ.S and GAMEEQ.S. Where "EQ" means "equates". These files contain the labels for every memory location in the code: zero page variables, local, global & game variables, code modules, jump tables, pre-built tables, data addresses for levels, sprites etc.

In general, the "porting" process consists of:

- Copying and renaming the file (so I keep an original close to hand for reference)
- Ensuring all comments start with \ for BeebAsm
- Putting IF / ENDIF statements round grand swathes of code that I'm not ready to deal with yet
- Fix up some standard syntax differences for IF/ENDIF, ORG, SKIP etc.
- Adding an INCLUDE into my master .asm file
- Assembling repeatedly removing / fixing any errors that occur

I'm not sure which assembler was originally used but the syntax is slightly different and it has a couple of more advanced features than BeebAsm, including the ability to identify local labels and variables for reuse. In addition, it is clear that originally each module was compiled independently and then copied to be loaded off disk. I am creating a master .asm file that includes all the other code modules with suitable directives to ensure the code is compiled in the right place in memory etc.

It does mean there are potential for name clashes between variables and (local) labels so I do have to be careful about this. I prefer to go through and fix things up by hand where possible, rather than relying heavily on search & replace, so that I get a feel & better understanding for the code structure as I go. Thankfully this game was written late in the Apple II lifecycle and Jordan was a good programmer enforcing lots of structure & consistency!

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 12:57 pm

My first goal was to get some of the plotting functions ported so I could draw a screen of a level. I identified a function "SURE" in the module FRAMEADV.S that is commented in the code as "Draw entire 10 x 3 screen from scratch". The process then is to move that module over to my Beeb source, comment everything out apart from the SURE function and then go about fixing the errors until it assembles...

- Uncomment ZP and global variables that are in use
- Uncomment additional functions in that code module that are used by SURE
- Repeat

One big challenge with PoP on the Beeb will be ZP variables. The 128KB Apple II has two sets of ZP variables as the entire 64KB banks are switched in & out. For the time-being I am not worrying about this and just letting the assembler allocate them in order until I run out. I doubt that all the variables need to be in ZP, I'll just have to find somewhere to stash the less important ones. Also there is a concept of reused "local" ZP variables in PoP which will use a fixed section of the ZP.

Fixing errors very rapidly starts to pull in additional code modules and particularly tables:

TABLES.S - pre-calculated tables, e.g. multiplication tables
GRAFIX.S - functions to manage all of the graphics lists before they are actually plotted to the screen in a different module (HIRES.S)
BGDATA.S - data tables about pieces of the background (walls, panels, floor etc.)

This turned out to be three days of wading through functions and data tables, having to rename / uncomment / comment out / tweak many lines until it finally built. You feel like you're going down a rabbit hole and hoping to return at some point and not have to abandon the endeavour and start again!

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 1:16 pm

A word on jump tables. The Apple II source makes extensive use of jump tables as the interface between different code modules.

Between EQ.S & GAMEEQ.S all of the jump tables are defined, that is all of the entry points to particular code module are given labels with consistent addresses:

Code: Select all

 *  Auxmem

grafix = $400

dum grafix

gr ds 3
drawall ds 3
controller ds 3
saveblue ds 3

<etc>

So this code module 'grafix' is assembled at $0400 (in auxmem) and the first four entry points are gr, drawall, controller and saveblue. At the top of the GRAFIX.S code module you get this:

Code: Select all

* grafix

org = $400

 org org

 jmp GR
 jmp DRAWALL
 jmp CONTROLLER
 jmp SAVEBLUE

Which means any external code module can just do "JSR drawall" (equivalent to JSR $0403) and this will be routed through the jump table via "jmp DRAWALL". This means that the code within the GRAFIX.S module can move around freely without any external modules having to worry about where the DRAWALL function actually resides. This would have been done back in the day as assembling the entire 128KB of code & data would have been impossible and/or quite a slow process, so you do it in pieces at fixed addresses.

We don't have to do this for BeebAsm as the whole thing can be compiled on a modern PC in seconds but it is very handy for the porting effort as it means we can declare the entire jump table for a module without having to implement any code (yet.) This enables the entire code to be assembled more easily and allows us to implement individual functions or even replace, redirect or stub them out without affecting the rest of the code.

E.g. the top of grafix.asm in the port looks like:

Code: Select all

\ org org
\
.gr BRK            ;jmp GR
.drawall jmp DRAWALL
.controller BRK    ;jmp CONTROLLER
.saveblue BRK      ;jmp SAVEBLUE

I've commented out the ORG command as we're letting the assembler decide where this module lives (for now.) Only the 'drawall' function is implemented whilst the others are replaced with a 'BRK' instruction. If any of those functions get called at runtime then I will get an exception and can find out where the call came from (this is done in the b-em debugger.) I can then either implement a missing function or replace the 'BRK' with 'RTS' and stub the function out for the time being, allowing the code to continue without worrying about porting less important parts.

RobC
Posts: 1579
Joined: Sat Sep 01, 2007 9:41 pm

Re: Starting a Prince of Persia port...

Postby RobC » Fri Aug 18, 2017 1:39 pm

Looking really good - very excited about this.

Having briefly looked at porting it a while back, it's really interesting to read the details too.

User avatar
tricky
Posts: 1735
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Starting a Prince of Persia port...

Postby tricky » Fri Aug 18, 2017 4:55 pm

kieranhj wrote:...although a lot of the time there won't be much to see just many technical details...

:shock: those are the best bits :lol:

User avatar
ctr
Posts: 88
Joined: Wed Jul 16, 2014 2:53 pm

Re: Starting a Prince of Persia port...

Postby ctr » Fri Aug 18, 2017 10:01 pm

kieranhj wrote:I'm not sure which assembler was originally used but the syntax is slightly different and it has a couple of more advanced features than BeebAsm, including the ability to identify local labels and variables for reuse.

In beebasm you can use braces {} to create blocks. Labels and variables are local to a block. You can even nest blocks. So you end up with something like this and the variable "loop" can be reused elsewhere:

Code: Select all

.subroutine
{
    LDY #3
    .loop
    DEY
    BPL loop
    RTS
}

User avatar
kieranhj
Posts: 429
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Starting a Prince of Persia port...

Postby kieranhj » Fri Aug 18, 2017 10:21 pm

ctr wrote:In beebasm you can use braces {} to create blocks. Labels and variables are local to a block. You can even nest blocks. So you end up with something like this and the variable "loop" can be reused elsewhere:

Indeed, and I do like it. But you can't promote labels outside of scope, for example. At least not without the extensions that haven't been adopted as an official release yet.

In addition the Apple assembler used has prefixes for labels that make them local at file scope and also distinguishes between labels and variables that can be reassigned. This is used for generic 'branch rts_variable' statements which mean you don't need to worry about exactly which is the closest RTS statement if you want to return from a function.

All small things but need to be watched out for, particularly when overloading global variable names. My goal is to make this buildable with out of the box tools.

SteveF
Posts: 405
Joined: Fri Aug 28, 2015 8:34 pm

Re: Starting a Prince of Persia port...

Postby SteveF » Sat Aug 19, 2017 12:38 am

Great stuff Kieran, really interesting to see the dev diary posts, so I hope they aren't adding too much extra to the workload!


Return to “projects”

Who is online

Users browsing this forum: No registered users and 1 guest