# File cpm_loader3.asm 0000 ;Retrieves CP/M image from disk and loads it in memory starting at E400h 0000 ;Uses calls to ROM routine for disk read. 0000 ;Reads track 0, sectors 1 to 50 0000 ;This program is loaded into LBA sector 0 of disk, read to loc. 0800h by ROM and executed. 0000 hstbuf: equ 0900h ;will put 256-byte raw sector here 0000 disk_read: equ 0294h ;in 2K ROM 0000 cpm: equ 0FA00h ;CP/M cold start entry 0000 org 0800h 0800 ;Read track 0, sectors 1 to 50 0800 3e 01 ld a,1 ;starting sector -- sector 0 has cpm_loader 0802 32 58 08 ld (sector),a 0805 21 00 e4 ld hl,0E400h ;memory address to place image 0808 22 5a 08 ld (dmaad),hl 080b 3e 00 ld a,0 ;CP/M track 080d 32 59 08 ld (track),a 0810 cd 31 08 rd_trk_0_loop: call read 0813 3a 58 08 ld a,(sector) 0816 fe 32 cp 50 0818 ca 2c 08 jp z,done 081b 3c inc a 081c 32 58 08 ld (sector),a 081f 2a 5a 08 ld hl,(dmaad) 0822 11 80 00 ld de,128 0825 19 add hl,de 0826 22 5a 08 ld (dmaad),hl 0829 c3 10 08 jp rd_trk_0_loop 082c d3 01 done: out (1),a ;switch memory config to all-RAM 082e c3 00 fa jp cpm 0831 0831 read: 0831 ;Read one CP/M sector from disk 0 0831 ;Track number in 'track' 0831 ;Sector number in 'sector' 0831 ;Dma address (location in memory to place the CP/M sector) in 'dmaad' (0-65535) 0831 ; 0831 21 00 09 ld hl,hstbuf ;buffer to place raw disk sector (256 bytes) 0834 3a 58 08 ld a,(sector) 0837 cb 27 sla a ;shifts to match cbios CP/M disk read routine 0839 cb 27 sla a ;which combine sector and disk no. in one byte 083b 4f ld c,a ;LBA bits 0 to 7 083c 3a 59 08 ld a,(track) 083f 47 ld b,a ;LBA bits 8 to 15 0840 1e 00 ld e,00h ;LBA bits 16 to 23 0842 cd 94 02 call disk_read ;subroutine in ROM 0845 ;Transfer top 128-bytes out of buffer to memory 0845 2a 5a 08 ld hl,(dmaad) ;memory location to place data read from disk 0848 11 00 09 ld de,hstbuf ;host buffer 084b 06 80 ld b,128 ;size of CP/M sector 084d 1a rd_sector_loop: ld a,(de) ;get byte from host buffer 084e 77 ld (hl),a ;put in memory 084f 23 inc hl 0850 13 inc de 0851 10 fa djnz rd_sector_loop ;put 128 bytes into memory 0853 db 0f in a,(0fh) ;get status 0855 e6 01 and 01h ;error bit 0857 c9 ret 0858 00 sector: db 00h 0859 00 track: db 00h 085a 00 00 dmaad: dw 0000h 085c end # End of file cpm_loader3.asm 085c