Example 6502 source for creating a ROM.

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
User avatar
Neil
Posts: 60
Joined: Thu Apr 17, 2008 12:56 pm
Location: Northampton
Contact:

Example 6502 source for creating a ROM.

Post by Neil »

Hi all,

I wanted to write a Utility ROM for use when developing my own projects. I soon realized that there are only a few books that cover this in the detail that I needed.

Therefore, to help others, I have put together a simple example of a ROM that handles the help and if called, executes one of the three commands that is built in it.

https://github.com/MadFly-Team/BBCMicro-Rom-Example

I have taken one of the BASIC examples in Bruce Smiths wonderful book 'Advanced Sideways RAM users guide', and converted and modified it to be in assembler, for building with Beebasm.

I have tested it on my BBC Master (switching to BBC-B, BBC-B+ and also MOS 3.2 and MOS 3.5). I also tested it in Beebem.
If you get the urge to clone and try it, I would love your feedback. Please bare in mine, I have only just created the repo and there is the first draft of the README.md.

thanks, Neil
---------------------------------------------------
We live for the one, we die for the one!
User avatar
HJimbo
Posts: 24
Joined: Sun Oct 22, 2023 11:48 pm
Contact:

Re: Example 6502 source for creating a ROM.

Post by HJimbo »

thks

:)
BBC Model B: Aries B20 , Aries B12
BBC Master 128K: Pi Tube
CoPro 65C102, Replay Rom, ATPL ROM/RAM Brd, 2X 5.25 Drv
User avatar
Neil
Posts: 60
Joined: Thu Apr 17, 2008 12:56 pm
Location: Northampton
Contact:

Re: Example 6502 source for creating a ROM.

Post by Neil »

HJimbo wrote: Mon Mar 04, 2024 11:53 pm thks

:)
:D You are most welcome!
---------------------------------------------------
We live for the one, we die for the one!
tom_seddon
Posts: 889
Joined: Tue Aug 30, 2005 12:42 am
Contact:

Re: Example 6502 source for creating a ROM.

Post by tom_seddon »

Regarding the zero page useage - service ROMs aren't allowed to use the $00...$8f region - that area is reserved for the current language ROM. Smith's book describes $70...$8f as the "user area", but that's only true when using the BASIC ROM. Other language ROMs are not obliged to not use this for their own workspace. And anyway, even in the BASIC ROM case, it's still a bit rude, because the user of your ROM might be using this area for something themselves!
Master Reference Manual pt 1, pg F.6-1 wrote: &0000–&008F Language workspace.

Programs should not use this area of memory unless they are allowed to do so by the current language. Some languages make part of this page available to other programs (BASIC, for example, reserves locations &70 – &8F for the user) – but this is NOT guaranteed
$a8...$af would be a better region to use for TEMPPTRL, TEMPPTRH and TEMPSTORE.

The hard-coded $38/$39 could go there as well - or, alternatively, push high byte of address-1 then low byte of address-1 onto the stack and do an RTS. Then no zero page required!

(If you still need more zero page, with care you can also use $b0...$bf, which is available for general use but may get overwritten by any filing system call. If you're not writing output (OSWRCH can make a filing system call when spooling!) or reading input (OSRDCH can make a filing system call when execing!) then this region can come in handy too.)

--Tom
User avatar
Neil
Posts: 60
Joined: Thu Apr 17, 2008 12:56 pm
Location: Northampton
Contact:

Re: Example 6502 source for creating a ROM.

Post by Neil »

tom_seddon wrote: Tue Mar 05, 2024 2:43 am Regarding the zero page useage - service ROMs aren't allowed to use the $00...$8f region - that area is reserved for the current language ROM. Smith's book describes $70...$8f as the "user area", but that's only true when using the BASIC ROM. Other language ROMs are not obliged to not use this for their own workspace. And anyway, even in the BASIC ROM case, it's still a bit rude, because the user of your ROM might be using this area for something themselves!
Master Reference Manual pt 1, pg F.6-1 wrote: &0000–&008F Language workspace.

Programs should not use this area of memory unless they are allowed to do so by the current language. Some languages make part of this page available to other programs (BASIC, for example, reserves locations &70 – &8F for the user) – but this is NOT guaranteed
$a8...$af would be a better region to use for TEMPPTRL, TEMPPTRH and TEMPSTORE.

The hard-coded $38/$39 could go there as well - or, alternatively, push high byte of address-1 then low byte of address-1 onto the stack and do an RTS. Then no zero page required!

(If you still need more zero page, with care you can also use $b0...$bf, which is available for general use but may get overwritten by any filing system call. If you're not writing output (OSWRCH can make a filing system call when spooling!) or reading input (OSRDCH can make a filing system call when execing!) then this region can come in handy too.)

--Tom
Brill Tom, I will change that, many thanks for reviewing and pointing out the hard coded references, I normally hate magic numbers, missed them. I am sure the 8 bytes at &a8 will be fine. Good call with pushing the high then low bytes to stack and RTS, it's been a while since I have done 8 bit coding.

Cheers, Neil
---------------------------------------------------
We live for the one, we die for the one!
Post Reply

Return to “programming”