-
Notifications
You must be signed in to change notification settings - Fork 1
/
bios.z80
166 lines (152 loc) · 3.03 KB
/
bios.z80
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
; Definitional includes
include 'memmap.z80'
include 'iomap.z80'
org ROMBASE
di
jp Main
; BIOS call table
SERIAL_INIT_A: jp UartInitA ; 1 0x0004
defb 0x00 ; Padding to line up with RSTs
SERIAL_READ_A: jp ReadA ; 2 0x0008 - FAST!
defb 0x00
SERIAL_INIT_B: jp UartInitB ; 3 0x000C
defb 0x00
SERIAL_WRITE_A: jp WriteA ; 4 0x0010 - FAST!
defb 0x00
RTC_READ: jp GetRTC ; 5 0x0014
defb 0x00
SERIAL_READ_B: jp ReadB ; 6 0x0018 - FAST!
defb 0x00
RTC_WRITE: jp SetRTC ; 7 0x001C
defb 0x00
CF_READ: jp CfReadSectors ; 10 0x0020 - FAST!
defb 0x00
BANK: jp SetMemBank ; 9 0x0024
defb 0x00
SERIAL_WRITE_B: jp WriteB ; 8 0x0028 - FAST!
defb 0x00
PERIODIC_ENABLE: jp EnablePeriodicInt ; 11 0x002C
defb 0x00
MONITOR: jp Monitor ; 14 0x0030 - FAST!
defb 0x00
PERIODIC_DISABLE: jp DisablePeriodicInt ; 13 0x0034
defb 0x00
CF_WRITE: jp CfWriteSectors ; 12 0x0038 - FAST!
USER_NOTIFY: jp 0x000 ; 15
SOMETHING: jp 0x000 ; 16
; DOS call table
DOS_READ_CHAR: jp ReadChar ; 1
DOS_WRITE_CHAR: jp WriteChar ; 2
DOS_STAT_FILE: jp StatFile ; 3
DOS_READ_FILE: jp ReadFile ; 4
DOS_WRITE_FILE: jp WriteFile ; 5
DOS_APPEND_FILE: jp WriteFile ; 6
DOS_DEL_FILE: jp DeleteFile ; 7
DOS_RENAME_FILE: jp RenameFile ; 8
DOS_COPY_FILE: jp ReadSector ; 9
DOS_SLEEP: jp Sleep ; 10
DOS_EXEC_PRG: jp 0x0000 ; 11
DOS_REG_CTRL: jp RegisterCtrlHandlers ; 12
DOS_TERM_PRG: jp TerminateProcess ; 13
DOS_EXEC_CMD: jp DosHandleLine ; 14
DOS_GET_MEM: jp GetSysMemPtr ; 15
; Code generating includes
include 'mmu.z80'
include 'uart.z80'
include 'cf.z80'
include 'rtc.z80'
; Main BIOS entry point
Main:
; Setup memory
ld sp, SYSSTACK
ld a, 1
call SetMemBank
; Initialise variables
ld a, 0
ld (ticks), a
ld hl, uptime
ld b, 8
UptimeZeroLoop:
ld (hl), a
inc hl
djnz UptimeZeroLoop
; Initialise hardware
; call Notify ; Notify(0) turns off both LEDs
call UartInit
call RTCSetup
call InterruptSetup
call CfSetup
; Start DOS
jp Dos
UartInit:
ld a, 10100011b
call SERIAL_INIT_A
ld a, 11100011b
call SERIAL_INIT_B
ret
RTCSetup:
; Set periodic rate to 500ms
ld a, 00001010b
call SetPeriodicIntRate
; Turn on periodic interrupt
call EnablePeriodicInt
ret
InterruptSetup:
; Copy interrupt to RAM
ld de, int_vector
ld hl, IntVector
ld bc, 16
ldir
; Point interrupt vector at interrupt table
ld de, int_vector
ld a, d
ld i, a
; Set interrupt mode 2
im 2
; Enable interrupts
ei
ret
IntVector:
dw diskhandler
dw diskhandler
dw nullhandler
dw nullhandler
dw nullhandler
dw tickhandler
dw nullhandler
dw diskhandler
Sleep:
cp 0
jr z, Microsleep
ld (sleep_countdown), a
ld a, (ticks)
ld (sleep_tick), a
SleepLoop:
ld a, (sleep_countdown)
cp 0
ret z
halt
jr SleepLoop
Microsleep:
ld a, b
cp 0
ret z
ld (microsleep_countdown), a
MicrosleepLoop:
ld a, (microsleep_countdown)
cp 0
ret z
halt
jr MicrosleepLoop
;Notify:
; ld b, a
; bit 0, b
; jr z, Notify1Off
; call Led1On
; jr Notify2
;Notify1Off:
; call Led1Off
;Notify2:
; bit 1, b
; jp z, Led2Off
; jp Led2On