1 TITLE 'CF cold boot loader'
8 ; IDE Task File Register Definitions
10 IDEDat equ IDEBASE+0 ; Data Register
11 IDEErr equ IDEBASE+1 ; Error Register
12 IDEFeat equ IDEBASE+1 ; Feature Register
13 IDESCnt equ IDEBASE+2 ; Sector Count
14 IDESNum equ IDEBASE+3 ; Sector Number
15 IDECLo equ IDEBASE+4 ; Cylinder Low
16 IDECHi equ IDEBASE+5 ; Cylinder High
17 IDESDH equ IDEBASE+6 ; Drive and Head
18 IDECmd equ IDEBASE+7 ; Command / Status
20 ; IDE Hard disk commands:
22 CmdNOP equ 00h ; NOP Command
23 CmdHome equ 10h ; Recalibrate
24 CmdRd equ 20h ; Read Sector
25 CmdWr equ 30h ; Write Sector
26 CmdId equ 0ECh ; Read ID
27 CmdSF equ 0EFh ; Set Feature
29 ; Partition Table Structures
36 ; (see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html)
38 PARTID1_FAT16 equ 00EH
39 PARTID2_FAT16 equ 006H
43 DEBUG equ false ; not used
44 DO_WAIT_NBSY equ false
53 ;-------------------------------------------------------------------------------
62 loadaddr: dw base+100h
65 part_id: db PARTID_CPM
67 stages: db number_of_stages
72 o_part_id equ part_id - para
73 o_stages equ stages - para
74 o_done equ done - para
75 o_result equ result - para
77 ;-------------------------------------------------------------------------------
103 ld (ide_result),hl ;3 9
107 ;-------------------------------------------------------------------------------
133 ; dw 0 ; part_start is 4 byte long, but stack gets free
149 number_of_stages equ ($-stage_table)/2
152 ;-------------------------------------------------------------------------------
153 ; Wait while device is busy with time out
172 ;-------------------------------------------------------------------------------
173 ; Wait for ready signal with time out
185 and 11000000b ; clears carry
193 ;-------------------------------------------------------------------------------
196 ld a,0E0h ; unit 0, lba mode
199 xor a ; execute NOP command
200 call do_ide_cmd ; should return error
204 ld a,CmdHome ; execute RECALIBRATE command
207 ;-------------------------------------------------------------------------------
210 ld a,1 ; Enable 8-bit data transfer.
212 ld a,CmdSF ; Set feature command
217 ;-------------------------------------------------------------------------------
227 ;-------------------------------------------------------------------------------
231 inc h ; Point to last byte of MBR
235 cp (hl) ; Test, if it has a valid MBR
242 ;-------------------------------------------------------------------------------
243 ; Read partition table (lbr)
247 ld bc,1*256 + 0 ; sector 0 (lba)
252 ;-------------------------------------------------------------------------------
253 ; Find CP/M paartition
254 ; Look for first CP/M partition
255 ; and save partition offset
259 ld de,512-2-64+PTYPE ; Point to partition type of first first partition table entry
262 ld b,4 ; Max # of partition table entries
265 sub (HL) ; Test for CP/M Partition
268 add hl,bc ; Point to partition start (lba)
278 ;-------------------------------------------------------------------------------
279 ; Read sec_count sectors, beginning at part_start+sec_start
284 ld bc,(sec_start) ;b=sec_count, c=sec_start
287 ld hl,(part_start) ;add partition offset to sector number
297 ;-------------------------------------------------------------------------------
298 ; Read a number of sectors
300 ; cde: sector number (24 bit)
310 ld a,b ; number of sectors to read
311 out (IdeSCnt),a ; set sector count
314 out (IdeCmd),a ; command: read sector data
316 ld bc,IdeDat ; I/O address
318 in a,(IdeCmd) ; wait for DRQ to become active
321 inir ; read 512 data bytes (2 x 256)
323 wnb: ; wait while busy
327 rrca ; restore status
333 and 10001001b ; Busy, DRQ, or Error?
334 ret ; return 0, if everything is ok
336 ;-------------------------------------------------------------------------------
344 ;-------------------------------------------------------------------------------
347 .printx Error: Program to large to fit in page 0!