Difference between revisions of "Simple ROM selection command code"

From BeebWiki
Jump to: navigation, search
(Created page with "Category:6502Category:Programming Sideways ROMs usually need to recognise a command to start up or to select a simple filing system. The following code provides the si...")

Revision as of 01:08, 8 March 2015

Sideways ROMs usually need to recognise a command to start up or to select a simple filing system. The following code provides the simplest way of doing this. It simply matches the name of the ROM itself.

 \ --------------------
 \ SERVICE 4 - *Command
 \ --------------------
 .Serv4
 TYA:PHA:DEY:LDX #&FF
 .Serv4Lp
 INX:INY:LDA (&F2),Y
 CMP #ASC".":BEQ Serv4Dot
 CMP #ASC"!":BCC Serv4End
 CMP &8009,X:BEQ Serv4Lp      :\ Match with ROM title
 EOR #&20                     :\ Change case
 CMP &8009,X:BEQ Serv4Lp      :\ Match with ROM title
 .Serv4Quit
 PLA:TAY:LDA #4:RTS           :\ Restore A,Y and return unclaimed
 .Serv4End
 LDA &8009,X:BNE Serv4Quit
 .Serv4Dot
 LDA #142:LDX &F4:JMP OSBYTE  :\ Select myself as a language
 or
 JSR SelectFS:PLA:LDA #0:RTS  :\ Select myself as a filing system

Note that X does not need to be restored on exiting a service call handler as the MOS immediately fetches X from &F4 on return from the call.

A better way of recognising a minimal command to start a filing system is to actually match the string in the filing system information block.

 \ --------------------
 \ SERVICE 4 - *Command
 \ --------------------
 .Serv4
 TYA:PHA:DEY:LDX #&FF
 .Serv4Lp
 INX:INY:LDA (&F2),Y
 CMP #ASC".":BEQ Serv4Dot
 CMP #ASC"!":BCC Serv4End
 CMP Serv25Info,X:BEQ Serv4Lp :\ Match with FS Info Block
 EOR #&20                     :\ Change case
 CMP Serv25Info,X:BEQ Serv4Lp :\ Match with FS Info Block
 .Serv4Quit
 PLA:TAY:LDA #4:RTS           :\ Restore A,Y and return unclaimed
 .Serv4End
 LDA &8009,X:BNE Serv4Quit
 .Serv4Dot
 JSR SelectFS:PLA:LDA #0:RTS :\ Select myself as a filing system
 
 \ ----------------------------
 \ SERVICE &25 - Return FS Info
 \ ----------------------------
 .Serv25
 LDX #0
 .Serv25lp
 LDA Serv25Info,X:STA (&F2),Y :\ Copy FS Info to MOS workspace
 INY:INX:CPX #11:BNE Serv25lp :\ Copy 11 bytes
 LDA #&25:RTS
 .Serv25Info
 EQUS "MyFS    "              :\ Filing system name
 EQUB lowchannel              :\ Lowest channel number
 EQUB highchannel             :\ Highest channel number
 EQUB fsnumber                :\ Filing system number

It can also be convenient for other code that refers to filing system numbers and channels to reference the Filing System Info directly, for example:

 .fsc07                       :\ Request filing system handle range
 LDX Serv25Info+8             :\ Lowest channel number
 LDY Serv25Info+9             :\ Highest channel number
 RTS
 
 .args00                      :\ Return filing system number
 LDA Serv25Info+10:RTS
 
 .SelectFS
 LDY Serv25Info+10            :\ Set Y=my filing system number
 .Serv12
 CPY Serv25Info+10
 BEQ SelectMyFS:RTS           :\ If not my FS number, return
 .SelectMyFS
 ...

WikiSysop (talk) 23:08, 7 March 2015 (UTC)