Request Disk Switch
Table of contents
- Introduction
- (Re)start Request
- Use Disk 1
- Display Disk Change Request
- Verify New Disk
- Sub-Routine for Printing Name of Disk
- Other Sub-Routines Used
- Zero Page Locations Used
- What Calls This
Introduction
Requests a switch, if necessary, to the disk number given in the accumulator.
- 1 — ULTIMA
- 2 — BRITANNIA
- 3 — TOWN
- 4 — DUNGEON
The vector call is to $0842.
0842 4C 68 18 JMP $1868
But the actual routine is at $1868.
We use $DE to store the desire disk number longer term.
1868 85 DE STA $DE
(Re)start Request
186A A5 DE LDA $DE
If the BRITANNIA disk is requested, we branch to handle it differently because we want to allow for drive 2 to have it.
186C C9 02 CMP #$02
186E F0 5F BEQ $18CF
If the DUNGEON disk is requested, we also branch to handle it differently because we want to allow for drive 2 to have it.
1870 C9 04 CMP #$04
1872 F0 5B BEQ $18CF
Use Disk 1
But now, let’s assume we’re just dealing with drive 1.
$DF is a variable used to contain a drive number we want to refer to.
Let’s start off by setting $DF to 0x01
1874 A9 01 LDA #$01
1876 85 DF STA $DF
$D2 contains the number of the disk in drive 1.
If the disk we want is already in drive 1…
1878 A5 DE LDA $DE
187A C5 D2 CMP $D2
…we can branch
187C F0 63 BEQ $18E1
Otherwise…
Display Disk Change Request
$DE should contain the disk number we want and $DF should contain the drive we want it put in.
We print:
PLEASE PLACE THE
{disk name} DISK
INTO DRIVE {drive number}
AND PRESS [ESC]
187E 20 85 0F JSR $0F85
1881 8D D0 CC C5 C1 D3 C5 A0 D0 CC C1 C3 C5 A0 D4 C8 C5 8D 00 "^MPLEASE PLACE THE^M"
Call a subroutine (see below) to print the disk name based on $DE.
1894 20 09 19 JSR $1909
1897 20 85 0F JSR $0F85
1894 A0 C4 C9 D3 CB 8D C9 CE D4 CF A0 C4 D2 C9 D6 C5 A0 00 "DISK^MINTO DRIVE "
Now we get the drive number from $DF and print it using a routine to print the accumulator as a single digit.
18AC A5 DF LDA $DF ; get the drive number from $DF
18AE 20 8B 10 JSR $108B ; print drive number
18B1 20 85 0F JSR $0F85
18B4 8D C1 CE C4 A0 D0 D2 C5 D3 D3 A0 DB C5 D3 C3 DD 8D 00 "^MAND PRESS [ESC]^M"
Now call a routine to take a keypress.
18C6 20 B5 0A JSR $0AB5
If we don’t get ESC (0x9B
), just branch back to take another keypress, otherwise branch to Verify New Disk.
18C9 C9 9B CMP #$9B
18CB D0 F9 BNE $18C6
18CD F0 12 BEQ $18E1
##
We come here if BRITANNIA or DUNGEON disks are requested.
$D1 is the number of disk drives the machine has. If it’s less than 2, we branch back to Use Disk 1.
18CF A5 D1 LDA $D1
18D1 C9 02 CMP #$02
18D3 90 9F BCC $1874
But if we have a second drive, let’s use it. We set $DF to be 0x02
.
18D5 A9 02 LDA #$02
18D7 85 DF STA $DF
$D3 contains the number of the disk we think we have in drive 2. If it’s equal to the desired disk, we can move on to Verify New Disk otherwise, we need to Display Disk Change Request.
18D9 A5 DE LDA $DE
18DB C5 D3 CMP $D3
18DD F0 02 BEQ $18E1
18DF D0 9D BNE $187E
Verify New Disk
We now need to see if the desired disk is indeed in the chosen drive.
We modify the BLOAD
string below with the drive we want to use (stored in $18F8) so the command runs on the right drive. We add (without carry) 0xB0
to the drive number to convert it to the right character code to use in the DOS command.
We then call DOS (by printing a string starting with ^D) to load the DISK
file on the disk in the chosen drive.
18E1 A5 DF LDA $DF
18E3 18 CLC
18E4 69 B0 ADC #$B0
18E6 8D F8 18 STA $18F8
18E9 20 D2 0F JSR $0FD2
18EC 84 C2 CC CF C1 C4 C4 C9 D3 CB AC C4 "^DBLOADDISK,D"
18F8 B1 "1"
18F9 8D 00 "^M"
The DISK
file is a single byte file loaded at $D0.
We take the value of $D0 and store it in $D1+$DF, i.e. $D2 if $DF is 1 and $D3 if $DF is 2.
18FB A6 DF LDX $DF
18FD A5 D0 LDA $D0
18FF 95 D1 STA $D1,X
We then compare it with the desired disk ($DE). If it’s equal, we return, otherwise we (Re)start Request.
1901 C5 DE CMP $DE
1903 F0 03 BEQ $1908
1905 4C 6A 18 JMP $186A
1908 60 RTS
Sub-Routine for Printing Name of Disk
Based on the value of $DE.
First we decrement it by two.
1909 A6 DE LDX $DE
190B CA DEX
190C CA DEX
Now BRITANNIA means X is zero. If not, we branch, but if so, we print “BRITANNIA”.
190D D0 0E BNE $191D
190F 20 85 0F JSR $0F85
1912 C2 D2 C9 D4 C1 CE CE C9 C1 00 "BRITANNIA"
191C 60 RTS
We decrement again.
191D CA DEX
Now TOWNE means X is zero. If not, we branch again, but if so, we print “TOWNE”.
191E D0 0A BNE $192A
1920 20 85 0F JSR $0F85
1923 D4 CF D7 CE C5 00 "TOWNE"
1929 60 RTS
We’re only left with UNDERWORLD now.
192A 20 85 0F JSR $0F85
192D D5 CE C4 C5 D2 D7 CF D2 CC C4 00 "UNDERWORLD"
1938 60 RTS
Other Sub-Routines Used
$0AB5 — get a keypress
$0F85 — display the following null-terminated string at the current cursor location
$0FD2 — print the following null-terminated string via the OS
$108B — display the single digit number in the accumulator at the current cursor location.
Zero Page Locations Used
$D0 — the disk number just loaded (from DISK file)
$D1 — the number of drives the machine has
$D2 — the disk number in drive 1
$D3 — the disk number in drive 2
$DE — desired disk number
$DF — drive to use
What Calls This
This is called three times in ULT4 and once in SAVE.