-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyemu-cpm-boot-sector.asm
63 lines (63 loc) · 1.39 KB
/
pyemu-cpm-boot-sector.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;
; CP/M 2.2 boot sector for Python emulator
;
msize equ 20 ;CP/M memory size in kilobytes
bias equ (msize-20)*1024
ccp equ 3400H+bias ;base of ccp
bdos equ ccp+806h ;base of bdos
bios equ ccp+1600h ;base of bios
;
disk equ 0f9h ;base address of disk ports
dstat equ disk ;status port
dcom equ disk ;command port: 0 = read, 1 = write
ddisk equ disk+1 ;disk port
dtrack equ disk+2 ;track port
dsect equ disk+3 ;sector port
ddmahi equ disk+4 ;DMA address (high) port
ddmalo equ disk+5 ;DMA address (low) port
;
;
org 0
;
mvi e,10 ;try to load up to 10 times
tryld: lxi sp,0100h ;reset the stack
lxi h,ccp ;hl = load destination
mvi d,51 ;total 51 sectors (2 tracks - 1 sector)
mvi b,0 ;start with track 0
mvi c,2 ;start with sector 2 of first track
traclp: mov a,b
out dtrack
sectlp: call ldsect
dcr d
jz bios ;if loaded everything, jump to bios
push b
lxi b,128
dad b ;hl=hl+128
pop b
inr c ;next sector
mov a,c
cpi 27
jc sectlp ;if next < 27 load another sector
inr b ;otherwise, next track
mvi c,1 ;now start with sector 1
jmp traclp
;
; load sector c into address hl
;
ldsect: mov a,c
out dsect
mov a,h
out ddmahi
mov a,l
out ddmalo
mvi a,0 ;"read sector" command
out dcom ;send command
in dstat ;get read sector status
ora a
rz ;return if no errors
; on read error, start over completely
dcr e
jnz tryld ;if e>0, try again
; halt after too many retries
halt: jmp halt ;halt
;