Apple II port to BBC Master computer

Threads about other remakes and ports.

Moderator: English Moderator Team

Post Reply
kieranhj
Efendi
Efendi
Posts: 5
Joined: October 13th, 2017, 3:02 pm

Apple II port to BBC Master computer

Post by kieranhj » October 13th, 2017, 6:08 pm

Hey folks,

I thought I would join your lovely forum and introduce myself. For the last six months or so I have been porting the original Apple II 6502 source & sprites to the BBC Master computer. For those of you outside of the UK, the BBC Micro computer series was created by Acorn in the early 1980's and was a familiar sight in all British schools of the era. Many coders taught themselves to program on this machine and have gone on to have careers in software development (including myself!)

I've always loved Prince of Persia, having played the original PC version back in the day as a teenager. After discovering the Apple II source had been released on GitHub, I decided to take a look. As the BBC Micro uses the same 6502 CPU as the Apple II, the code was very familiar even if the hardware internals and memory mapping of the Apple II were not. Thankfully Jordan Mechner was a surprisingly forward-thinking & careful programmer back in the late 80's and, whilst there was a lot of code, it was well structured with jump table interfaces for every module and a clean separation between gameplay logic and rendering.

Given the RAM requirements, I decided to limit my port to the BBC Master model which comes with 128K RAM as standard. Unfortunately this RAM is not in two simple 64K memory banks but distributed across the memory map in a somewhat inconvenient manner. This was the first of many challenges but I have made considerable progress so far. The game is certainly not complete yet but I have got far enough to share with the folks in the Acorn / BBC Micro enthusiasts scene. For similar reasons, I thought there might be people interested in this project here.

I've been keeping a development blog, of sorts, on the Acorn / BBC Micro enthusiasts forum Stardot, which you can read here: http://www.stardot.org.uk/forums/viewto ... 53&t=13079

You can try out the latest playable build using the online BBC Micro emulator (known as jsbeeb) here: https://bitshifters.github.io/jsbeeb/?d ... del=Master

(The keys are: z left x right ' up / down ; up-left # up-right Enter action. Your keyboard mapping may vary!)

As I said, there is still plenty of work still to do including porting the rest of the gameplay functions (it will crash if you trigger an unimplemented gameplay feature), the cutscenes & attract mode, music & sound effects, updated graphics designed for the BBC Micro screen resolution & colours and likely a whole load more optimisation to remove the flicker & graphical glitches. But it is certainly playable!

All code is posted on my GitHub repo here: https://github.com/kieranhj/pop-beeb and should be easily built by anyone else using the BeebAsm assembler. If anyone here is deeply familiar with the Apple II 6502 source, as I am becoming, I will no doubt be interested to ask you some questions when it comes to some of the gnarlier corners of the code. :)

Let me know what you think!
-kieranhj
Attachments
pop-beeb.png
Prince of Persia for the BBC Master

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3140
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Apple II port to BBC Master computer

Post by Norbert » October 14th, 2017, 7:29 pm

Hey kieranhj. BBC Master, so obscure. :)
Good luck completing the game. Quite a project.

It's too bad that that emulator stops when switching away from its tab.
Because it means players are forced to wait for all the disk drive 'nonsense'.

Hm, "]" seems to be up-right for me.
It would be nice if playing was possible with arrow keys, combined with Shift (as DOS) or/and "x" (as SNES).
Or, if the BBC Master can't deal with 2 keys pressed down at the same time (e.g. left+up arrows), the numeric keypad.

David
The Prince of Persia
The Prince of Persia
Posts: 1496
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Apple II port to BBC Master computer

Post by David » October 14th, 2017, 8:14 pm

Ah, another new PoP port for old hardware! (after the Commodore 64 version)

I tried this. It plays like the original except for the flickers.

I guess you already know, but the hit points are missing from the screen.
kieranhj wrote:
October 13th, 2017, 6:08 pm
(it will crash if you trigger an unimplemented gameplay feature)
I found a crash on level 2:
crash.png
It crashed because of the blue potion, didn't it?

Now that I zoomed in to the checkerboard patterns of the floor, I noticed that the pattern breaks at every 8th pixel (or 7th, depending on how you count it).
I guess that's because of the odd format of the Apple II graphics?
Norbert wrote:
October 14th, 2017, 7:29 pm
It's too bad that that emulator stops when switching away from its tab.
Because it means players are forced to wait for all the disk drive 'nonsense'.
You could move its tab into a separate window. That way the tab is still active within the window, even if the window is not active. (Tested on Firefox.)

Or you could use an offline emulator instead: https://www.zophar.net/bbcmicro.html
I did that too, because the JavaScript emulator is somewhat slow.
Then you need the disc image, you can find its URL within the URL of the JavaScript emulator.
kieranhj wrote:
October 13th, 2017, 6:08 pm
(The keys are: z left x right ' up / down ; up-left # up-right Enter action. Your keyboard mapping may vary!)
I guess your key labels are for the PC UK keyboard, as opposed to the BBC Master keyboard. (The latter has "#" on Shift+3.)

Also, it seems some moves are assigned to another key as well.
For example: A=left, E=right, P=up-left, ]=up-right.
Why is that?
Norbert wrote:
October 14th, 2017, 7:29 pm
It would be nice if playing was possible with arrow keys, combined with Shift (as DOS) or/and "x" (as SNES).
Or, if the BBC Master can't deal with 2 keys down at the same time (e.g. left+up arrows), the numeric keypad.
Or maybe use the Apple II keys? (UIO,JKL)

I think it can handle two keys at once: for example Enter+Z/X does a safe step.

kieranhj
Efendi
Efendi
Posts: 5
Joined: October 13th, 2017, 3:02 pm

Re: Apple II port to BBC Master computer

Post by kieranhj » October 17th, 2017, 9:48 pm

Norbert wrote:
October 14th, 2017, 7:29 pm
Hey kieranhj. BBC Master, so obscure. :)
Good luck completing the game. Quite a project.

It's too bad that that emulator stops when switching away from its tab.
Because it means players are forced to wait for all the disk drive 'nonsense'.

Hm, "]" seems to be up-right for me.
It would be nice if playing was possible with arrow keys, combined with Shift (as DOS) or/and "x" (as SNES).
Or, if the BBC Master can't deal with 2 keys pressed down at the same time (e.g. left+up arrows), the numeric keypad.
Hiya. Thanks for trying it out! You can use a PC/Mac/Linux emulator like BeebEm or b-em and download the disk image (.ssd) for it instead.

The keys are actually BBC keyboard "standard" game mapping: Z X : / Return with ; ] added for up left/right. The BBC can cope with multiple keys pressed down simultaneously but I need to recode the PoP keyboard input to enable this. I will look at perhaps doing several different keyboard mappings if there are some established configurations on other platforms.

kieranhj
Efendi
Efendi
Posts: 5
Joined: October 13th, 2017, 3:02 pm

Re: Apple II port to BBC Master computer

Post by kieranhj » October 17th, 2017, 10:03 pm

David wrote:
October 14th, 2017, 8:14 pm
Ah, another new PoP port for old hardware! (after the Commodore 64 version)

I tried this. It plays like the original except for the flickers.

I guess you already know, but the hit points are missing from the screen.
Hi David, thanks for trying it out and taking time to post. I am currently working on the flickers. Unfortunately I cannot (currently) afford to double-buffer the screen as I'm using a 15K 4bpp buffer whilst the original Apple II used 2x 8K buffers. I could drop down to 2x 2bpp buffers but it would be nice to have a more colourful screen in lieu of the resolution drop.

There are a number of graphics features left to implement from the original, including the energy bars, hit fx and screen flash.
David wrote: I found a crash on level 2:
It crashed because of the blue potion, didn't it?
Yes, the potion sprite is made blue by shifting one pixel to the right on Apple II hires screen. For speed reasons my sprite plotter assumes (asserts) a 0 offset in this instance. An easy fix but annoying if you can't get past the screen, sorry!
David wrote: Now that I zoomed in to the checkerboard patterns of the floor, I noticed that the pattern breaks at every 8th pixel (or 7th, depending on how you count it).
I guess that's because of the odd format of the Apple II graphics?
Good spot! Yes, the original Apple II hires has 7 pixels per byte for a total of 280 pixels across the screen with artefact colour. It's impossible to render the sprites at the required speed without being byte aligned on the target machine. The simplest and most consistent way to achieve this has been to "widen" the graphics to multiples of 8 pixels for a total of 320 pixels across. At the moment I'm just doing a simple offline conversion that is rounding up one pixel in every 7. I have an artist lined up to redo the sprites for me at native resolution. I might look to using the CGA/VGA sprites as a starting point instead of the Apple II graphics.
David wrote: Or you could use an offline emulator instead: https://www.zophar.net/bbcmicro.html
I did that too, because the JavaScript emulator is somewhat slow.
Then you need the disc image, you can find its URL within the URL of the JavaScript emulator.
b-em is my emulator of choice for development. You can download the .ssd disc image from GitHub or using the link, as you say.
David wrote: I guess your key labels are for the PC UK keyboard, as opposed to the BBC Master keyboard. (The latter has "#" on Shift+3.)

Also, it seems some moves are assigned to another key as well.
For example: A=left, E=right, P=up-left, ]=up-right.
Why is that?
Yes, I am in the UK so will be using a UK keyboard. As I mentioned above, the keys are actually BBC "standard" game configuration: Z X : / Return with ; ] added for up left/right. I've no idea where these would end up on a US keyboard I'm afraid! The offline emulators allow you to check & reconfigure your keyboard mapping more easily.
David wrote: Or maybe use the Apple II keys? (UIO,JKL)

I think it can handle two keys at once: for example Enter+Z/X does a safe step.
I will look at supporting the original Apple II keys alongside other options. The BBC can detect multiple key presses at once but I need to recode the input routine. Interestingly it appears as though the Apple II cannot, other than detecting the Apple key as a special case, which is why it is the "action" button!

Thanks again for the feedback. I'll keep you posted with the progress!

David
The Prince of Persia
The Prince of Persia
Posts: 1496
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Apple II port to BBC Master computer

Post by David » October 21st, 2017, 11:10 am

kieranhj wrote:
October 17th, 2017, 10:03 pm
I am currently working on the flickers. Unfortunately I cannot (currently) afford to double-buffer the screen as I'm using a 15K 4bpp buffer whilst the original Apple II used 2x 8K buffers. I could drop down to 2x 2bpp buffers but it would be nice to have a more colourful screen in lieu of the resolution drop.

There are a number of graphics features left to implement from the original, including the energy bars, hit fx and screen flash.
Okay, no need to hurry. :)
kieranhj wrote:
October 17th, 2017, 10:03 pm
Yes, the potion sprite is made blue by shifting one pixel to the right on Apple II hires screen.
It's here: https://github.com/kieranhj/pop-beeb/bl ... g.asm#L692
kieranhj wrote:
October 17th, 2017, 10:03 pm
For speed reasons my sprite plotter assumes (asserts) a 0 offset in this instance. An easy fix but annoying if you can't get past the screen, sorry!
So is the crash an assertion failure?
kieranhj wrote:
October 17th, 2017, 10:03 pm
b-em is my emulator of choice for development.
I also used B-em to play the game, as you can see on my screenshot.
kieranhj wrote:
October 17th, 2017, 10:03 pm
You can download the .ssd disc image from GitHub or using the link, as you say.
How do I access the latest disc image from the GitHub project page?
The pop-beeb.ssd in the repo is a very old version that only draws rooms in black and white.
kieranhj wrote:
October 17th, 2017, 10:03 pm
The BBC can detect multiple key presses at once but I need to recode the input routine. Interestingly it appears as though the Apple II cannot, other than detecting the Apple key as a special case, which is why it is the "action" button!
From what I know, on the Apple II, the keypresses are converted to ASCII codes in hardware, and the result can be read at $C000.
There is no way to see exactly which keys are pressed, or to redefine which keys generate which characters (the assigments are stored in a ROM).
Also, the Apple keys (two of them) share ports with the joystick buttons, and can be read at $C061 and $C062.

Source: http://www.1000bit.it/support/manuali/a ... iieref.pdf (28 MB)
kieranhj wrote:
October 17th, 2017, 10:03 pm
Thanks again for the feedback. I'll keep you posted with the progress!
You're welcome!

kieranhj
Efendi
Efendi
Posts: 5
Joined: October 13th, 2017, 3:02 pm

Re: Apple II port to BBC Master computer

Post by kieranhj » November 13th, 2017, 12:15 pm

David wrote:
October 21st, 2017, 11:10 am
Okay, no need to hurry. :)
Hiya David. Thanks for all the feedback. I was on vacation for a couple of weeks so only just got back to looking at PoP.
David wrote:
October 21st, 2017, 11:10 am
So is the crash an assertion failure?
Yes, the nice thing about the way the original Apple II code is structured is the jump table interface between all the code modules. This allows me to easily stub out functions and trap when unimplemented functions are called during gameplay. I have also added various runtime assertion failures (or a simple equivalent of at least) under a _DEBUG compilation flag, particularly to do bounds checking.
David wrote:
October 21st, 2017, 11:10 am
How do I access the latest disc image from the GitHub project page?
The pop-beeb.ssd in the repo is a very old version that only draws rooms in black and white.
I have various branches on the go in the repo - mostly just cascading checkpoints as I embark on a new feature or sticky piece of refactoring. Best to look for the most recent checkins. I just implemented double-buffering the screen, which makes a massive difference: https://github.com/kieranhj/pop-beeb/tr ... ble-buffer.

Online emulated version here: https://bitshifters.github.io/jsbeeb/?d ... del=Master

There are a couple of bugs still particularly when switching screens but looks very solid, though I say so myself. The colour scheme is all over the place but the sprite routines support 3 colours per sprite chosen from a palette of 16 which should look nice when finished.
David wrote:
October 21st, 2017, 11:10 am
From what I know, on the Apple II, the keypresses are converted to ASCII codes in hardware, and the result can be read at $C000.
There is no way to see exactly which keys are pressed, or to redefine which keys generate which characters (the assigments are stored in a ROM).
Also, the Apple keys (two of them) share ports with the joystick buttons, and can be read at $C061 and $C062.

Source: http://www.1000bit.it/support/manuali/a ... iieref.pdf (28 MB)
Thanks for the link. I had just about figured out this was the case. Fortunately the BBC Micro can scan the keyboard for individual presses, so I can handle a PC style keyboard control with left/right & jump keys simultaneously. Well in theory at least - I'm so tight on RAM after clearing up space for the screen double buffering I'm not currently sure how I'm going to finish the port. :( I guess necessity is the mother of invention! :D

David
The Prince of Persia
The Prince of Persia
Posts: 1496
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Apple II port to BBC Master computer

Post by David » November 19th, 2017, 1:07 pm

kieranhj wrote:
November 13th, 2017, 12:15 pm
I have various branches on the go in the repo - mostly just cascading checkpoints as I embark on a new feature or sticky piece of refactoring.
Best to look for the most recent checkins.
Ah, the branches.
I use them differently: I eventually merge every branch into master.
kieranhj wrote:
November 13th, 2017, 12:15 pm
I just implemented double-buffering the screen, which makes a massive difference:
Indeed: The flickering is gone.
kieranhj wrote:
November 13th, 2017, 12:15 pm
There are a couple of bugs still particularly when switching screens but looks very solid, though I say so myself.
What I can see is the game switches back to the second-to-last picture when I leave the current screen.
kieranhj wrote:
November 13th, 2017, 12:15 pm
The colour scheme is all over the place
I see you changed the guards' colors. For example, the first guard on level 1 has blue face.
Why? This looks a bit odd...

I think I found a new bug. (in pop-beeb-mode2-double-buffer.ssd)
The game crashes here:
crash_2.png
This bug wasn't in the previous version that I tried. (pop-beeb-faster-mode2.ssd)
The debugger in B-em says that execution stops on a BRK at 38CE.

The bug is probably related to two loose floors falling at the same time.
However, it does not happen on level 1. Maybe the guard is also important?

If I don't trigger this bug, then I can complete level 2.

Notes about further levels:

Level 3: Chompers don't move and the skeleton won't wake up.

Level 4: Floors are black. This also means that I can't see spikes' holes.
The mirror appears and I can jump through it. Only the mirror image and the shadow are missing.

Level 5: The game crashes when the shadow would appear. (BRK at A4EA)
The game also crashes when I would drop down to the top of the starting room. (BRK at 203F)
It does not matter which side do I drop or fall down.
crash_level_5_drop_left.png
crash_level_5_drop_left.png (10.93 KiB) Viewed 18 times
I see your port also contains this bug from the Apple II version: viewtopic.php?p=12150#p12150

Post Reply