Porting of my game GENIUS to BBC Micro platform

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Thu Dec 15, 2016 3:38 pm

Hi everybody!

I recently coded a game for Apple II, ported to Commodore 64 and I'm starting to port it to BBC Micro as well.
Here's a link of the C64 version preview:
https://www.youtube.com/watch?v=YZxC1Ln8kIM
Here's a review of Apple II version:
https://www.youtube.com/watch?v=gR8NiYggJVA

The game needs 2 pages for page flipping animation + 1 for background restoring. The code of the animation graphic engine is completely indipendent from special Graphic features of the video chips of the various platforms, to make it more easy to port as it is.

I have approx 24 Kb of code/data to stack for the complete game and will need 1 floppy for loading levels configurations every 10 levels.

in Apple II:
1 hires 280x192 page needs 8kb and color is encoded in even odd pairs of bits plus bit 7, so some restrictions but no additional color memory needed.
so 3 pages are in total 24 kb.
48kram model: swaps 8Kb on disk at each level change, reusing some data memory areas for page 3 background saving.
64k ram models: have all avaialble.

in Commodore 64:
1 hires 320x200 page needs 9Kb (1kb for color memory).
so 3 pages are in total 27 kb.
64k ram:no swapping on level change is needed.

in BBC Micro:
1 hires 320x256 page needs 10Kb 2 colors or 20Kb 4 colors.
so 3 pages are in total 30kb or 60kb
A goal would be to make a 2 color version for BBC Micro models with 64k and a 4 color version for BBC Micros with 128 Kbytes available,
autodetecting the model.
I could do the swapping of the 8k as I did in Apple II for the background saving memory at each level chance in the 64kb configuration...
Are there restriction on what addresses the video chip che refer to while page 1/2 flipping? Can video chip refer to expanded memory or only refers to
user memory base?

The 64k BBC micro models, with propery bank switching, are allowing complete 64k of ram? or are there process (shadow memory ...) that allow more that 64k?

Any idea about how to stack/map the code and what usage of particular ram memory (shadow, sideways..) could allow me to get it to work?
Thanks in advance for any tips!

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Porting of my game GENIUS to BBC Micro platform

Postby jgharston » Thu Dec 15, 2016 4:15 pm

Twinspirit32 wrote:The 64k BBC micro models, with propery bank switching, are allowing complete 64k of ram? or are there process (shadow memory ...) that allow more than 64k?

The video hardware can only see memory in the lower 32K, 0000-7FFF. On the Master if you disable ABSOLUTELY EVERY MOS FEATURE(*) you can page in a bank of sideways RAM at 8000-BFFF and the private workspace RAM at C000-DFFF and have RAM contiguous from 0000 to DFFF.

(*)Put an NMI at &D00 and point the interupt vector at &204/5 to LDA &FC:RTI and do not make ANY MOS calls.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Re: Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Thu Dec 15, 2016 4:25 pm

Thanks a lot for your reply!
So it's not possible to have 2 graphic pages of 20k each addressable/switchable from video chip for making a page flipping of a mode 1 20k 4 color 320x256 mode?

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Porting of my game GENIUS to BBC Micro platform

Postby jgharston » Thu Dec 15, 2016 4:43 pm

Twinspirit32 wrote:Thanks a lot for your reply!
So it's not possible to have 2 graphic pages of 20k each addressable/switchable from video chip for making a page flipping of a mode 1 20k 4 color 320x256 mode?

It is on the Master as there are two banks of video memory, both mapped into the lower 32K. You select which bank is displayed with bit 0 of ACCCON (access control) at &FE34. ?&FE34=8 causes bank 0 to be displayed, ?&FE34=9 causes bank 1 to be displayed; bit 2 controls which bank the CPU can see, so ?&FE34=8 and the CPU can read/write bank 0, ?&FE34=12 and the CPU can read/write bank 1. &FE34 is read/write so you can set/reset bits with TSB and TRB and toggle bits with LDA &FE34:EOR #xx:STA &FE34.

Edit: so, the following will flip between banks:
REPEAT:?&FE34=8:A%=INKEY(100):?&FE34=9:A%=INKEY(100):UNTIL FALSE

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Re: Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Thu Dec 15, 2016 5:21 pm

What base address is ULA chip referring to? Where can the pages be located? Is it programmable in different address or fixed? What doc/book would you suggest me to read for these low level concept of register settings for Machine coding?

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

Re: Porting of my game GENIUS to BBC Micro platform

Postby tricky » Thu Dec 15, 2016 7:13 pm

I can't speak for the master, but I use the advanced user guide for the model b; I think there is an updated one for b+, master, compact etc.
There is shadow ram for the model b, made by Watford electronics, I'm not too sure of the details, but I did support it for holding sound samples for my AstroBlaster game.
There was a survey a while back and more than half the responders had sideways ram. It does sound like you may be better off targeting the master.
For my games, I usually use mode1, but resized to 256*256 requiring 16k.
If you did the 256*256 2 colour version, you could page flip the graphics without extra hardware and just use sideways ram (maybe 2 banks).

User avatar
danielj
Posts: 5344
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester

Re: Porting of my game GENIUS to BBC Micro platform

Postby danielj » Thu Dec 15, 2016 7:35 pm

I've put new thread at the top, PM me if you want things added to it, but for the time being it's got the expanded advanced user guide in it!

d.

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Porting of my game GENIUS to BBC Micro platform

Postby jgharston » Thu Dec 15, 2016 9:59 pm

Twinspirit32 wrote:What base address is ULA chip referring to? Where can the pages be located? Is it programmable in different address or fixed? What doc/book would you suggest me to read for these low level concept of register settings for Machine coding?
The ULA takes whatever data is continously squirted at it continuously by the CRTC. It knows nothing about and has no control over what addresses the video data comes from, that is entirely the provenance of the CRTC.

tricky wrote:I can't speak for the master, but I use the advanced user guide for the model b; I think there is an updated one for b+, master, compact etc.
The New Advanced User Guide is updated to cover the B+ and Master.
(Edit: See here, thanks danielj!)

tricky wrote:There is shadow ram for the model b, made by Watford electronics, I'm not too sure of the details, but I did support it for holding sound samples for my AstroBlaster game.
The BBC shadow RAM systems are only capable of displaying the one bank of video memory. The CPU can access two banks of memory - the shadow RAM and the video RAM - but the video hardware is only capable of display the one single bank of video RAM. If you want to do screen paging with a BBC shadow RAM system you have to copy the data between the shadow bank and the video bank. Manually. Slowly.
Last edited by jgharston on Thu Dec 15, 2016 10:09 pm, edited 1 time in total.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Re: Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Thu Dec 15, 2016 10:04 pm

Thanks great! Thanks everybody for the help and feedback!

So my game actually would need only an original resolution of 280x192 actually, Can I resize mode 1 to use only that portion of the graphics?
Is there a way to make sorts of clipboards and save memory? I would use only the 280x192 in center screen if possible and not the 320x256.
How can you instruct the Beebs to use only a resized part of the Mode 1 and maybe save room for the main game code?

:)

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

Re: Porting of my game GENIUS to BBC Micro platform

Postby RobC » Thu Dec 15, 2016 11:12 pm

Twinspirit32 wrote:So my game actually would need only an original resolution of 280x192 actually, Can I resize mode 1 to use only that portion of the graphics?
Is there a way to make sorts of clipboards and save memory? I would use only the 280x192 in center screen if possible and not the 320x256.
How can you instruct the Beebs to use only a resized part of the Mode 1 and maybe save room for the main game code?

All this is covered in chapter 18 of the Advanced User Guide.

You can decrease the screen size by programming the 6845/CRTC horizontal displayed register (R1) to display 70 CRTC characters:

Code: Select all

LDA #1
STA $FE00
LDA #70
STA $FE01


You can centralise the smaller screen by programming CRTC horizontal sync register (R2) to something like 93 (I haven't tried this but I think it's the correct value):

Code: Select all

LDA #2
STA $FE00
LDA #93
STA $FE01


You can reduce the number of vertical rows by programming the vertical displayed register (R6). 192 pixels is 24 rows:

Code: Select all

LDA #6
STA $FE00
LDA #24
STA $FE01


You then have to centralise the screen by programming the vertical total register (R4). You program it with the value you want minus 1. Again, I haven't tried it but I think 41 is the correct value for 192 pixels:

Code: Select all

LDA #4
STA $FE00
LDA #41
STA $FE01


You can then raise the screen start address (R12,R13) to recover the memory you've saved. 280 x 192 pixels in mode 1 is 13,440 bytes so would give a start address of 0x4B80. You divide this by 8 before programming into R12 and R13:

Code: Select all

LDA #12
STA $FE00
LDA #9
STA $FE01
LDA #13
STA $FE00
LDA #70
STA $FE01


Note that you can only perform hardware scrolling on certain screen sizes due to the way the wrap-around works. So, it's out of the picture for a 280 x 192 screen.

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Porting of my game GENIUS to BBC Micro platform

Postby jgharston » Thu Dec 15, 2016 11:23 pm

RobC wrote:You can then raise the screen start address (R12,R13) to recover the memory you've saved. 280 x 192 pixels in mode 1 is 13,440 bytes so would give a start address of 0x4B80. (...) Note that you can only perform hardware scrolling on certain screen sizes due to the way the wrap-around works. So, it's out of the picture for a 280 x 192 screen.
If using another 3K is acceptable, program the hardware to use 16K wraparound with an initial start address of &4000. Setting the screen memory map is fiddly, so it's usually easier to, eg go into MODE 3 when you first start and then frob the CRTC to get the screen shape you need.

What hardware scrolling means (from memory the C64 doesn't have this) is that if you have, eg, a 16K screen map, then the video system sees the top 16K of video memory, from &4000 to &7FFF. The displayed screen starts in the top lefthand corner defined by R12 and R13. If that is set so the bottom of the screen is at an address logically higher than &7FFF it wraps around to &4000.

As an example, setting R12/13 to &5000 means that the top three quarters of the displayed screen is the memory contents from &5000 to &7FFF and the bottom quarter is the memory contents from &4000 to &4FFF. It means that when scrolling the screen you don't need to physically move all the memory contents, this display "moves" itself and the program only needs to deal with blanking out the next bit of the screen moved into view.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

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

Re: Porting of my game GENIUS to BBC Micro platform

Postby tricky » Thu Dec 15, 2016 11:54 pm

Twinspirit32 wrote:...280x192...

So, if you did do a mono model B version, you would only need one bank of Sideways RAM (16KB) + 32KB - 20KB (3 screens) - 24KB (code and data) leaving 4KB, about what you need to keep the OS happy with a little bit of fitting around what would be being used. Or you can shut the OS out and then you only lose 4 bytes, 5 if you want nice BREAK behavior.
Jonathan (jgharston), could you claim the NMI first and then not even put an RTI at &D00? It does seem the right thing to do (to me).

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Porting of my game GENIUS to BBC Micro platform

Postby jgharston » Fri Dec 16, 2016 12:27 pm

tricky wrote:Jonathan (jgharston), could you claim the NMI first and then not even put an RTI at &D00? It does seem the right thing to do (to me).
Normally yes, but if you're shutting out the OS then the OS/etc is never going to try and claim the NMIs, so just sticking an NMI at &D00 is sufficient. If you're going to keep the MOS live and make MOS calls you need to claim the NMIs and NMI workspace - and be prepared for somebody else to claim them away from you if you make any filing system calls.

You've reminded me that to take over the whole machine and ensure a clean Break restart you need to set:
&204/5=>LDA &FC:RTI
?&D00 = RTI
?&258 = 3 so Break does a memory-wipe restart
?&287 = 0 (or anything other than &4C) to disable the Break Intercept
and probably &202/3 => a suitable restart point to catch BRK opcode

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Re: Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Fri Dec 16, 2016 3:11 pm

That's marvellous! Thansk everybody for the precious help! It seems that it will be fun, and it's great to see such great possibilities to set a custom situation to work with graphics!
I will dig into all this soon! Will keep you posted.
Thanks a lot for now! :)

User avatar
danielj
Posts: 5344
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester

Re: Porting of my game GENIUS to BBC Micro platform

Postby danielj » Thu Dec 29, 2016 2:27 pm

:D - I see you're interviewed in this month's retrogamer! Good job!

d.

Twinspirit32
Posts: 9
Joined: Thu Dec 15, 2016 1:42 pm

Re: Porting of my game GENIUS to BBC Micro platform

Postby Twinspirit32 » Sat Jan 14, 2017 9:54 am

I will have to get a copy of that! :) Is it number 163? I've been completing the porting of GENIUS to Commodore Plus 4 lately, I thougt it was great to include also that machine on the list, but next will be BBC Micro! :D


Return to “programming”

Who is online

Users browsing this forum: No registered users and 1 guest