; http://www.trs80.nl/nhdd.htm 00010 ; boot for Newdos harddisk for the TRS-80 model I 00020 ; written 5-7-1993 00030 ; Sys0.sys is on sector 5, head 0 of cylinder 0. 00040 ; 00050 STATUS EQU 0CFH ;command/status port 00060 TRACK EQU 0CDH ;cylinder port 00070 SECTOR EQU 0CBH ;sector port 00080 DATA EQU 0C8H ;data port 00090 RDCOMD EQU 020H ;read one sector command 00100 DIRGRN EQU 24H 00110 START EQU 0005H 00120 ; 00130 ORG 4200H 00140 BEGIN DI 00150 LD A,DIRGRN ;DIR granule 00160 LD SP,41E0H 00170 EXX 00180 LD DE,START ;first sector SYS0 00190 LD HL,5100H ;buffer start 00200 EXX 00210 LD HL,51FFH ;buffer start + 255 00220 LOOP1 CALL RDBYTE ;read next byte 00230 CP 20H 00240 JR NC,ERROR 00250 LD C,A ;record type 00260 CALL RDBYTE 00270 LD B,A ;number of bytes 00280 LD A,C 00290 CP 1 ;record type 1 (program code) 00300 JR Z,RTYP01 00310 CP 2 00320 JR Z,RTYP02 ;record type 2 (program entry) 00330 ; 00340 ;here if commentaar (record types 0, 3 - 20h) 00350 ; 00360 REMARK CALL RDBYTE 00370 DJNZ REMARK 00380 JR LOOP1 ;all read 00390 ; 00400 ; record type 01 = program code 00410 ; 00420 RTYP01 CALL RADRES ;address in DE 00430 RTLP01 CALL RDBYTE 00440 LD (DE),A ;store program data 00450 INC DE ;next RAM address 00460 DJNZ RTLP01 00470 JR LOOP1 00480 ; 00490 ; record type 02 = program entry 00500 ; 00510 RTYP02 CALL RADRES ;address in DE 00520 LD A,(DE) ;test byte in SYS0 00530 CP 0A5H ;10100101 pattern 00540 JR NZ,NOSYS ;error message NOSYS 00550 INC DE ;program entry 00560 PUSH DE ;save DE (entry) 00570 EXX ;DE' = sector number 00580 LD E,2 ;read pdrive sector 00590 EXX 00600 LD L,0FFH ;force to read sector 00610 LD DE,0FF3BH ;Newdos pdrive table 00620 LD B,0DH ;13 bytes of first pdrive 00630 RPDRIV CALL RDBYTE 00640 LD (DE),A 00650 INC DE 00660 DJNZ RPDRIV ;end of read first pdrive 00670 CALL RDBYTE ;skip one byte (nr 14) 00680 CALL RDBYTE ;one byte (nr 15) 00690 LD (DE),A 00700 INC DE 00710 CALL RDBYTE ;last byte pdrive (nr 16) 00720 LD (DE),A 00730 INC DE 00740 LD A,0FE ;first address not to zero 00750 SUB E 00760 LD (4D04H),DE ;first address to zero 00770 LD (4D07H),A ;number of bytes to zero 00780 RET ;execute program 00790 ; 00800 ; program load or entry address in DE 00810 ; 00820 RADRES CALL RDBYTE 00830 DEC B ;count one byte 00840 LD E,A ;low address 00850 CALL RDBYTE 00860 DEC B ;count one byte 00870 LD D,A ;high address 00880 RET 00890 ; 00900 ; ERROR message 00910 ; 00920 ERROR LD HL,ERRORM ;address of error message 00930 JR DISPHL ;display text (HL) 00940 NOSYS LD HL,NOSYSM 00950 DISPHL LD A,(HL) 00960 INC HL 00970 CP 03H ;EOM 00980 ENDLES JR Z,ENDLES 00990 CALL 0033H 01000 JR DISPHL ;next byte of message 01010 ; 01020 ERRORM DEFB 1CH ;TOF 01030 DEFB 1FH ;CLS 01040 DEFM 'Hard disk error' 01050 DEFB 03H ;EOM 01060 NOSYSM DEFB 1CH ;TOF 01070 DEFB 1FH ;CLS 01080 DEFM 'No system on hard disk' 01090 DEFB 03H ;EOM 01100 ; 01110 ; Read byte routine (general part...), DE = sector to read, HL = buffer 01120 ; 01130 RDBYTE INC L ;if 00 --> READ NEXT SECTOR 01140 LD A,(HL) 01150 RET NZ 01160 ; 01170 EXX 01180 LD B,05 ;retry count 01190 RDLOOP CALL HWREAD ;hardware dependent READ 01200 JR Z,RDEXIT 01210 DJNZ RDLOOP 01220 EXX ;time out retry count 01230 JP ERROR 01240 RDEXIT CALL NXTSEC ;set to read next sector 01250 EXX 01260 LD A,(HL) 01270 RET 01280 ; 01290 ; 01300 ; Read byte routine (hardware dependent routines) 01310 ; 01320 NXTSEC INC E ;simple 1 side, 1 cylinder 01330 RET 01340 ; 01350 HWREAD LD A,E 01360 OUT (SECTOR),A ;sector register of WD1002-05 01370 LD A,RDCOMD ;READ SINGLE SECTOR 01380 OUT (STATUS),A ;give command 01390 PUSH BC ;save BC 01400 PUSH HL ;start of sector buffer 01410 LD B,00H ;read 256 bytes 01420 LD C,DATA ;data port of WD1002-05 01430 HWLOOP IN A,(STATUS) ;status register 01440 BIT 7,A ;bit 7 --> busy 01450 JR NZ,HWLOOP 01460 BIT 6,A ;bit 6 --> ready 01470 JR Z,HWLOOP 01480 BIT 0,A ;bit 0 --> 1 === ERROR 01490 JR NZ,HWFAIL 01500 INIR ;input 256 bytes from port (C) TO (HL) 01510 XOR A ;A=0; no error 01520 HWFAIL POP HL 01530 POP BC 01540 RET 01550 ; 01660 END BEGIN