1 title 'LDRBIOS for CP/M 3.0'
9 ; IDE Task File Register Definitions
11 IDEDat equ IDEBASE+0 ; Data Register
12 IDEErr equ IDEBASE+1 ; Error Register
13 IDEFeat equ IDEBASE+1 ; Feature Register
14 IDESCnt equ IDEBASE+2 ; Sector Count
15 IDESNum equ IDEBASE+3 ; Sector Number
16 IDECLo equ IDEBASE+4 ; Cylinder Low
17 IDECHi equ IDEBASE+5 ; Cylinder High
18 IDESDH equ IDEBASE+6 ; Drive and Head
19 IDECmd equ IDEBASE+7 ; Command / Status
21 ; IDE Hard disk commands:
23 CmdHome equ 10h ; Recalibrate
24 CmdRd equ 20h ; Read Sector
25 CmdWr equ 30h ; Write Sector
26 CmdInit equ 91h ; Initialize Drive Params
27 CmdId equ 0ECh ; Read ID
28 CmdSF equ 0EFh ; Set Feature
30 ; Partition Table Structures
37 ; (see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html)
39 PARTID1_FAT16 equ 00EH
40 PARTID2_FAT16 equ 006H
55 ?boot: jp boot ; initial entry on cold start
56 ?wboot: jp wboot ; reentry on program exit, warm start
58 ?const: jp const ; return console input status
59 ?conin: jp conin ; return console input character
60 ?cono: jp conout ; send console output character
61 ?list: jp list ; send list output character
62 ?auxo: jp auxout ; send auxilliary output character
63 ?auxi: jp auxin ; return auxilliary input character
65 ?home: jp home ; set disks to logical home
66 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
67 ?sttrk: jp settrk ; set disk track
68 ?stsec: jp setsec ; set disk sector
69 ?stdma: jp setdma ; set disk I/O memory address
70 ?read: jp read ; read physical block(s)
71 ?write: jp write ; write physical block(s)
73 ?lists: jp listst ; return list device status
74 ?sctrn: jp sectrn ; translate logical to physical sector
76 ?conos: jp conost ; return console output status
77 ?auxis: jp auxist ; return aux input status
78 ?auxos: jp auxost ; return aux output status
79 ?dvtbl: jp devtbl ; return address of device def table
80 ?devin: jp cinit ; change baud rate of device
82 ?drtbl: jp getdrv ; return address of disk drive table
83 ?mltio: jp multio ; set multiple record count for disk I/O
84 ?flush: jp flush ; flush BIOS maintained disk caching
86 ?mov: jp move ; block move memory to memory
87 ?tim: jp time ; Signal Time and Date operation
88 ?bnksl: jp bnksel ; select bank for code execution and default DMA
89 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations.
90 ?xmov: jp xmove ; set source and destination banks for one operation
92 jp 0 ; reserved for future expansion
93 jp 0 ; reserved for future expansion
94 jp 0 ; reserved for future expansion
96 ;----------------------------------------------------------------------
99 db (hwini0_e-$)/2 ;count
100 db rcr,CREFSH ;configure DRAM refresh
101 db dcntl,CWAITIO ;wait states
102 db ccr,M_NCD ;No Clock Divide
103 db cmr,PHI_X2 ;X2 Clock Multiplier
104 db omcr,~M_IOC ;Operation Mode Control Register
106 db cbr,SYS$CBR ;Common Base Register
107 db cbar,USR$CBAR ;Common Base Area Register
109 db asext1,0 ;disable BRG
110 db stat1,00000000b ;disable RX, TX interrupt, disable CTS1
111 db cntlb1,10000000b;PS:10 DR:16 Rate:1 --> BR = Phi/160
112 db cntla1,01100101b;RE TE RTS:0 8N2
118 db cr,lf,'CPMLDR error: Unable to locate CP/M partition',cr,lf,0
120 ;-------------------------------------------------------------------------------
122 ; CP/M 3 Disk definition macros
124 maclib cpm3slr.lib ; dpb mcaro
126 ; The dph macro from the lib depends on GENCPM
128 dphldr macro ?trans,?dpb,?csize,?asize,?dirbcb,?dtabcb
130 dw ?trans ; translate table address
131 db 0,0,0,0,0,0,0,0,0 ; BDOS Scratch area
133 dw ?dpb ; disk parameter block
135 dw 0 ; permanently mounted, no checksum vector
140 dw ?csv ; checksum vector
144 dw 0 ; no alloc vector
149 dw ?alv ; allocation vector
158 ?csv ds ?csize ; checksum vector
163 ?alv ds ?asize ; allocation vector
168 ;-------------------------------------------------------------------------------
170 ; dphldr translate$table, - disk parameter header
171 ; disk$parameter$block,
172 ; checksum$size, (optional)
173 ; alloc$size (optional)
177 dphldr 0,dpbsimhd512,0,0,bcb,bcb
186 ; dpb physical$sector$size, - disk parameter block
187 ; physical$sectors$per$track,
190 ; number$dir$entries,
192 ; checksum$vec$size (optional)
195 dpb 512,8,2048,4096,1024,6,8000h
197 ;-------------------------------------------------------------------------------
199 wboot: ; jump vector locations not used
221 ;-------------------------------------------------------------------------------
222 ; output bytes to ports
224 ; hl: tables of port,value pairs:
225 ; db n, port1,val1, port2,val2,... portn,valn
227 ; db 0 ; Terminate table
233 ld c,(hl) ;port address
246 ;-------------------------------------------------------------------------------
247 ; print message @<HL> up to a null
260 ;-------------------------------------------------------------------------------
263 ; Init CPU, MMU, ASCI0
268 ; Init disk partition
278 cp (hl) ; Test, if it has a valid MBR
285 ; Find CP/M paartition
286 ; Look for first CP/M partition and save partition offset
288 ld hl,buffer+512-2-64+PART_TYPE ; Point to partition type of first first partition table entry
290 ld b,4 ; Max # of partition table entries
293 sub (HL) ; Test for CP/M Partition
296 add hl,bc ; Point to partition start (lba)
312 ;-------------------------------------------------------------------------------
322 ;-------------------------------------------------------------------------------
325 ex de,hl ; we are passed source in DE and dest in HL
326 ldir ; use Z80 block move instruction
327 ex de,hl ; need next addresses in same regs
330 ;-------------------------------------------------------------------------------
332 ; Return address of disk parameter header in <HL>
338 ; Home selected drive. Treated as SETTRK(0).
341 ld bc,0 ; same as set track zero
343 ; Set Track. Saves track address from <BC> in @trk.
349 ; Set Sector. Saves sector number from <BC> in @sect.
355 ; Set Disk Memory Address. Saves DMA address from <BC> in @dma.
361 ; Translate sector address. Not needed. Return physical=logical.
368 ;-----------------------------------------------------------------
382 ;-------------------------------------------------------------------------------
383 ; Wait for ready signal with time out
394 and 11000000b ; clears carry
404 ;-------------------------------------------------------------------------------
415 ;-------------------------------------------------------------------------------
416 ; Read partition table
431 ;-------------------------------------------------------------------------------
434 ; compute logical block number (lba) --> cf-controller
436 ; TODO: sectors per track from dpb
437 ; lba = track * 8 + sector
454 ld a,(iy+0) ; add partition start
470 ld a,1 ; number of sectors to read
471 out (IdeSCnt),a ; set sector count
474 out (IdeCmd),a ; command: read sector data
475 ld bc,IdeDat ; I/O address
477 in a,(IdeCmd) ; wait for DRQ to become active
480 inir ; read 512 data bytes (2 x 256)
482 wnb: ; wait while busy
486 rrca ; restore status
487 and 10001001b ; Busy, DRQ, or Error?
488 ret z ; return 0, if everything is ok
492 ;-------------------------------------------------------------------------------