RAM:DC00 ; ---------------------------------------------------------------------------
RAM:DC00
RAM:DC00 DISK_ENTRY:
RAM:DC00 F3 di
RAM:DC01 21 A2 00 ld hl, 0A2h ; Do a call and return to detect where we are running from
RAM:DC04 F9 ld sp, hl
RAM:DC05 36 C9 ld (hl), 0C9h
RAM:DC07 CD A2 00 call FDD_IO_ADDRESS
RAM:DC0A EB ex de, hl ; DE = $00A2
RAM:DC0B 2A A0 00 ld hl, (word_A0) ; HL now contains return address off stack $DC0A
RAM:DC0E 2E 00 ld l, 0
RAM:DC10 E5 push hl ; HL = $DC00
RAM:DC11 01 1D 00 ld bc, 1Dh
RAM:DC14 09 add hl, bc ; HL = $DC1D
RAM:DC15 E5 push hl
RAM:DC16 E1 pop hl
RAM:DC17 0E 1A ld c, 1Ah
RAM:DC19 09 add hl, bc ; HL = $DC37
RAM:DC1A 06 BD ld b, 0BDh
RAM:DC1C EB ex de, hl ; DE = $DC37, HL = $00A2
RAM:DC1D 3B dec sp
RAM:DC1E 3B dec sp
RAM:DC1F 1A ld a, (de) ; Copy $DC37 code to $00A2
RAM:DC20 77 ld (hl), a
RAM:DC21 BE cp (hl) ; check we are writing to RAM
RAM:DC22 C0 ret nz
RAM:DC23 23 inc hl
RAM:DC24 13 inc de
RAM:DC25 05 dec b
RAM:DC26 C0 ret nz ; loop to $DC1E while B not ZERO
RAM:DC27 E1 pop hl ; $DC00
RAM:DC28 2A A0 00 ld hl, (word_A0)
RAM:DC2B 11 00 02 ld de, 200h ; $DE00
RAM:DC2E 19 add hl, de
RAM:DC2F 22 A2 00 ld (FDD_IO_ADDRESS), hl ; Controller accessed through 3 mem address ($DE00-$DE02)
RAM:DC32 36 A0 ld (hl), 0A0h
RAM:DC34 C3 D4 00 jp boot_disk ; Jumpt to relocated code in RAM
# Following code is relocated to RAM.
# It does not execute here.
RAM:DC37 DISK_CODE:
RAM:DC37 00 nop
RAM:DC38 00 nop
RAM:DC39 00 nop
RAM:DC3A 00 nop
RAM:DC3B 2A A2 00 ld hl, (FDD_IO_ADDRESS)
RAM:DC3E 7E ld a, (hl)
RAM:DC3F E6 80 and 80h
RAM:DC41 CA A9 00 jp z, wait_data_available
RAM:DC44 7E ld a, (hl)
RAM:DC45 E6 0F and 0Fh
RAM:DC47 A8 xor b
RAM:DC48 C2 A9 00 jp nz, wait_data_available
RAM:DC4B 23 inc hl
RAM:DC4C B6 or (hl)
RAM:DC4D F2 B7 00 jp p, loc_B7
RAM:DC50 23 inc hl
RAM:DC51 7E ld a, (hl)
RAM:DC52 AF xor a
RAM:DC53 EB ex de, hl
RAM:DC54 06 00 ld b, 0
RAM:DC56 00 nop
RAM:DC57 00 nop
RAM:DC58 1A ld a, (de)
RAM:DC59 77 ld (hl), a
RAM:DC5A 23 inc hl
RAM:DC5B 88 adc a, b
RAM:DC5C 47 ld b, a
RAM:DC5D 1A ld a, (de)
RAM:DC5E 77 ld (hl), a
RAM:DC5F 23 inc hl
RAM:DC60 88 adc a, b
RAM:DC61 47 ld b, a
RAM:DC62 0D dec c
RAM:DC63 C2 C3 00 jp nz, read_2_bytes
RAM:DC66 1A ld a, (de)
RAM:DC67 B8 cp b
RAM:DC68 C9 ret
RAM:DC69 ; ---------------------------------------------------------------------------
RAM:DC69
RAM:DC69 RELOC_D4:
RAM:DC69 2A A2 00 ld hl, (FDD_IO_ADDRESS)
RAM:DC6C 36 20 ld (hl), 20h ; ' '
RAM:DC6E 23 inc hl
RAM:DC6F 7E ld a, (hl)
RAM:DC70 2B dec hl
RAM:DC71 E6 24 and 24h ; '$'
RAM:DC73 EE 20 xor 20h ; ' '
RAM:DC75 C2 D4 00 jp nz, boot_disk
RAM:DC78 0E 5E ld c, 5Eh ; '^'
RAM:DC7A CD 49 01 call sub_149
RAM:DC7D 23 inc hl
RAM:DC7E 7E ld a, (hl)
RAM:DC7F 2B dec hl
RAM:DC80 E6 24 and 24h ; '$'
RAM:DC82 EE 20 xor 20h ; ' '
RAM:DC84 C2 D4 00 jp nz, boot_disk
RAM:DC87 23 inc hl
RAM:DC88 7E ld a, (hl)
RAM:DC89 E6 08 and 8
RAM:DC8B 2B dec hl
RAM:DC8C CA 07 01 jp z, SEEK_00
RAM:DC8F 06 08 ld b, 8
RAM:DC91 36 61 ld (hl), 61h ; 'a'
RAM:DC93 0E 0F ld c, 0Fh
RAM:DC95 CD 49 01 call sub_149
RAM:DC98 05 dec b
RAM:DC99 C2 FC 00 jp nz, loc_FC
RAM:DC9C 23 inc hl
RAM:DC9D 7E ld a, (hl)
RAM:DC9E E6 08 and 8
RAM:DCA0 2B dec hl
RAM:DCA1 C2 19 01 jp nz, AT_TRACK_00
RAM:DCA4 36 60 ld (hl), 60h ; '`'
RAM:DCA6 0E 0F ld c, 0Fh
RAM:DCA8 CD 49 01 call sub_149
RAM:DCAB C3 07 01 jp SEEK_00
RAM:DCAE ; ---------------------------------------------------------------------------
RAM:DCAE 21 5F 01 ld hl, 15Fh
RAM:DCB1 CD 37 01 call sub_137
RAM:DCB4 C2 D4 00 jp nz, boot_disk
RAM:DCB7 2A 69 02 ld hl, (word_269)
RAM:DCBA 22 A4 00 ld (word_A4), hl
RAM:DCBD CD 37 01 call sub_137
RAM:DCC0 C2 D4 00 jp nz, boot_disk
RAM:DCC3 2A A4 00 ld hl, (word_A4)
RAM:DCC6 11 0C 00 ld de, 0Ch
RAM:DCC9 19 add hl, de
RAM:DCCA D1 pop de
RAM:DCCB E9 jp (hl)
RAM:DCCC ; ---------------------------------------------------------------------------
RAM:DCCC E5 push hl
RAM:DCCD EB ex de, hl
RAM:DCCE 01 86 00 ld bc, 86h
RAM:DCD1 CD A6 00 call DO_DISK_IO ; on entry DE = Buffer Address, C = words to read
RAM:DCD4 E1 pop hl
RAM:DCD5 C2 37 01 jp nz, sub_137
RAM:DCD8 E5 push hl
RAM:DCD9 7E ld a, (hl)
RAM:DCDA 23 inc hl
RAM:DCDB B6 or (hl)
RAM:DCDC E1 pop hl
RAM:DCDD C9 ret
RAM:DCDE ; ---------------------------------------------------------------------------
RAM:DCDE 7E ld a, (hl)
RAM:DCDF E6 20 and 20h ; ' '
RAM:DCE1 79 ld a, c
RAM:DCE2 C2 51 01 jp nz, loc_151
RAM:DCE5 07 rlca
RAM:DCE6 4F ld c, a
RAM:DCE7 3E FF ld a, 0FFh
RAM:DCE9 D6 01 sub 1
RAM:DCEB B7 or a
RAM:DCEC C2 54 01 jp nz, loc_154
RAM:DCEF 0D dec c
RAM:DCF0 C2 52 01 jp nz, loc_152
RAM:DCF3 C9 ret
RAM:DCF4 ; ---------------------------------------------------------------------------
RAM:DCF4 00 nop
RAM:DCF5 00 nop
RAM:DCF6 00 nop
RAM:DCF7 00 nop
RAM:DCF8 00 nop
RAM:DCF9 00 nop
RAM:DCFA 00 nop
RAM:DCFB 00 nop
RAM:DCFC 00 nop
RAM:DCFD C3 A6 00 jp DO_DISK_IO ; on entry DE = Buffer Address, C = words to read
RAM:DCFD ; ---------------------------------------------------------------------------
#Code from DC37 once it has been re-located to $00A0
RAM:00A0 00 00 word_A0: dw 0 ; DATA XREF: RAM:DC0B↓r
RAM:00A0 ; RAM:DC28↓r
RAM:00A2 00 00 FDD_IO_ADDRESS: dw 0 ; CODE XREF: RAM:DC07↓p
RAM:00A2 ; DATA XREF: DO_DISK_IO↓r ...
RAM:00A4 00 00 word_A4: dw 0 ; DATA XREF: DO_DISK_IO+7F↓w
RAM:00A4 ; DO_DISK_IO+88↓r ...
RAM:00A6
RAM:00A6 ; =============== S U B R O U T I N E =======================================
RAM:00A6
RAM:00A6 ; on entry DE = Buffer Address, C = words to read
RAM:00A6
RAM:00A6 DO_DISK_IO: ; CODE XREF: sub_137+5↓p
RAM:00A6 ; RAM:0168↓j ...
RAM:00A6 2A A2 00 ld hl, (FDD_IO_ADDRESS) ; Set to $DE00 in this case
RAM:00A9
RAM:00A9 wait_data_available: ; CODE XREF: DO_DISK_IO+6↓j
RAM:00A9 ; DO_DISK_IO+D↓j ...
RAM:00A9 7E ld a, (hl)
RAM:00AA E6 80 and 80h
RAM:00AC CA A9 00 jp z, wait_data_available
RAM:00AF 7E ld a, (hl)
RAM:00B0 E6 0F and 0Fh
RAM:00B2
RAM:00B2 loc_B2:
RAM:00B2 A8 xor b
RAM:00B3 C2 A9 00 jp nz, wait_data_available
RAM:00B6 23 inc hl
RAM:00B7
RAM:00B7 loc_B7: ; CODE XREF: DO_DISK_IO+12↓j
RAM:00B7 ; RAM:DC4D↓j
RAM:00B7 B6 or (hl)
RAM:00B8 F2 B7 00 jp p, loc_B7
RAM:00BB 23 inc hl
RAM:00BC 7E ld a, (hl)
RAM:00BD AF xor a
RAM:00BE EB ex de, hl ; HL now == Buffer Address, DE = IO Reg address
RAM:00BF 06 00 ld b, 0
RAM:00C1 00 nop
RAM:00C2 00 nop
RAM:00C3
RAM:00C3 read_2_bytes: ; CODE XREF: DO_DISK_IO+28↓j
RAM:00C3 ; RAM:DC63↓j
RAM:00C3 1A ld a, (de)
RAM:00C4 77 ld (hl), a
RAM:00C5 23 inc hl
RAM:00C6 88 adc a, b ; simple CRC byte
RAM:00C7 47 ld b, a
RAM:00C8 1A ld a, (de)
RAM:00C9 77 ld (hl), a
RAM:00CA 23 inc hl
RAM:00CB 88 adc a, b
RAM:00CC 47 ld b, a
RAM:00CD 0D dec c
RAM:00CE C2 C3 00 jp nz, read_2_bytes
RAM:00D1 1A ld a, (de) ; Compare CRC
RAM:00D2 B8 cp b
RAM:00D3
RAM:00D3 locret_D3:
RAM:00D3 C9 ret
RAM:00D4 ; ---------------------------------------------------------------------------
RAM:00D4
RAM:00D4 boot_disk: ; CODE XREF: DO_DISK_IO+3A↓j
RAM:00D4 ; DO_DISK_IO+49↓j ...
RAM:00D4 2A A2 00 ld hl, (FDD_IO_ADDRESS) ; Set to $DE00 in this case
RAM:00D7 36 20 ld (hl), 20h ; ' ' ; Activate Drive #0
RAM:00D9 23 inc hl
RAM:00DA 7E ld a, (hl)
RAM:00DB 2B dec hl
RAM:00DC E6 24 and 24h ; '$'
RAM:00DE EE 20 xor 20h ; ' '
RAM:00E0 C2 D4 00 jp nz, boot_disk
RAM:00E3 0E 5E ld c, 5Eh ; '^'
RAM:00E5 CD 49 01 call sub_149
RAM:00E8 23 inc hl
RAM:00E9 7E ld a, (hl)
RAM:00EA 2B dec hl
RAM:00EB E6 24 and 24h ; '$'
RAM:00ED EE 20 xor 20h ; ' '
RAM:00EF C2 D4 00 jp nz, boot_disk
RAM:00F2 23 inc hl
RAM:00F3 7E ld a, (hl)
RAM:00F4 E6 08 and 8
RAM:00F6 2B dec hl
RAM:00F7 CA 07 01 jp z, SEEK_00
RAM:00FA 06 08 ld b, 8
RAM:00FC
RAM:00FC loc_FC: ; CODE XREF: DO_DISK_IO+5E↓j
RAM:00FC ; RAM:DC99↓j
RAM:00FC 36 61 ld (hl), 61h ; 'a' ; Step In command
RAM:00FE 0E 0F ld c, 0Fh
RAM:0100 CD 49 01 call sub_149
RAM:0103 05 dec b
RAM:0104 C2 FC 00 jp nz, loc_FC
RAM:0107
RAM:0107 SEEK_00: ; CODE XREF: DO_DISK_IO+51↑j
RAM:0107 ; DO_DISK_IO+70↓j ...
RAM:0107 23 inc hl
RAM:0108 7E ld a, (hl)
RAM:0109 E6 08 and 8 ; TRACK_00 status bit
RAM:010B 2B dec hl
RAM:010C C2 19 01 jp nz, AT_TRACK_00
RAM:010F 36 60 ld (hl), 60h ; '`' ; Step OUT command
RAM:0111 0E 0F ld c, 0Fh
RAM:0113 CD 49 01 call sub_149
RAM:0116 C3 07 01 jp SEEK_00
RAM:0119 ; ---------------------------------------------------------------------------
RAM:0119
RAM:0119 AT_TRACK_00: ; CODE XREF: DO_DISK_IO+66↑j
RAM:0119 ; RAM:DCA1↓j
RAM:0119 21 5F 01 ld hl, 15Fh
RAM:011C CD 37 01 call sub_137
RAM:011F C2 D4 00 jp nz, boot_disk
RAM:0122 2A 69 02 ld hl, (word_269)
RAM:0125 22 A4 00 ld (word_A4), hl
RAM:0128 CD 37 01 call sub_137
RAM:012B C2 D4 00 jp nz, boot_disk
RAM:012E 2A A4 00 ld hl, (word_A4)
RAM:0131 11 0C 00 ld de, 0Ch
RAM:0134 19 add hl, de
RAM:0135 D1 pop de
RAM:0135 ; End of function DO_DISK_IO
RAM:0135
RAM:0136 E9 jp (hl) ; jump to loaded boot sector code
RAM:0137
RAM:0137 ; =============== S U B R O U T I N E =======================================
RAM:0137
RAM:0137
RAM:0137 sub_137: ; CODE XREF: DO_DISK_IO+76↑p
RAM:0137 ; DO_DISK_IO+82↑p ...
RAM:0137 E5 push hl
RAM:0138 EB ex de, hl
RAM:0139 01 86 00 ld bc, 86h
RAM:013C CD A6 00 call DO_DISK_IO ; on entry DE = Buffer Address, C = words to read
RAM:013F E1 pop hl
RAM:0140 C2 37 01 jp nz, sub_137
RAM:0143 E5 push hl
RAM:0144 7E ld a, (hl)
RAM:0145 23 inc hl
RAM:0146 B6 or (hl)
RAM:0147 E1 pop hl
RAM:0147 ; End of function sub_137
RAM:0147
RAM:0148 ; ---------------------------------------------------------------------------
RAM:0148 C9 ret
RAM:0149
RAM:0149 ; =============== S U B R O U T I N E =======================================
RAM:0149
RAM:0149
RAM:0149 sub_149: ; CODE XREF: DO_DISK_IO+3F↑p
RAM:0149 ; DO_DISK_IO+5A↑p ...
RAM:0149 7E ld a, (hl)
RAM:0149 ; End of function sub_149
RAM:0149
RAM:014A ; ---------------------------------------------------------------------------
RAM:014A E6 20 and 20h ; ' '
RAM:014C 79 ld a, c
RAM:014D C2 51 01 jp nz, loc_151
RAM:0150 07 rlca
RAM:0151
RAM:0151 loc_151: ; CODE XREF: RAM:014D↑j
RAM:0151 ; RAM:DCE2↓j
RAM:0151 4F ld c, a
RAM:0152
RAM:0152 loc_152: ; CODE XREF: RAM:015B↓j
RAM:0152 ; RAM:DCF0↓j
RAM:0152 3E FF ld a, 0FFh
RAM:0154
RAM:0154 loc_154: ; CODE XREF: RAM:0157↓j
RAM:0154 ; RAM:DCEC↓j
RAM:0154 D6 01 sub 1
RAM:0156 B7 or a
RAM:0157 C2 54 01 jp nz, loc_154
RAM:015A 0D dec c
RAM:015B C2 52 01 jp nz, loc_152
RAM:015E C9 ret
RAM:015F ; ---------------------------------------------------------------------------
RAM:015F 00 nop
RAM:0160 ; ---------------------------------------------------------------------------
RAM:0160 00 nop
RAM:0161 00 nop
RAM:0162 00 nop
RAM:0163 00 nop
RAM:0164 00 nop
RAM:0165 00 nop
RAM:0166 00 nop
RAM:0167 00 nop
RAM:0168 C3 A6 00 jp DO_DISK_IO ; on entry DE = Buffer Address, C = words to read
RAM:0168 ; ---------------------------------------------------------------------------
RAM:016B 00 db 0