fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ibmpc: Add a DOS device driver for the host clock

+325
+2
src/arch/ibmpc/pceutils/Makefile.inc
··· 26 26 pcever 27 27 28 28 PCEUTILS_BAS_SYS := \ 29 + pceclock \ 29 30 pceemm \ 30 31 pcehimem 31 32 ··· 47 48 endif 48 49 49 50 51 + $(rel)/pceclock.sys: $(rel)/pceclock.asm $(PCEUTILS_SDP) 50 52 $(rel)/pceemm.sys: $(rel)/pceemm.asm $(PCEUTILS_SDP) 51 53 $(rel)/pceexit.com: $(rel)/pceexit.asm $(PCEUTILS_SDP) 52 54 $(rel)/pcehimem.sys: $(rel)/pcehimem.asm $(PCEUTILS_SDP)
+323
src/arch/ibmpc/pceutils/pceclock.asm
··· 1 + ;----------------------------------------------------------------------------- 2 + ; pce 3 + ;----------------------------------------------------------------------------- 4 + 5 + ;----------------------------------------------------------------------------- 6 + ; File name: pceclock.asm 7 + ; Created: 2012-02-11 by Hampa Hug <hampa@hampa.ch> 8 + ; Copyright: (C) 2012-2017 Hampa Hug <hampa@hampa.ch> 9 + ;----------------------------------------------------------------------------- 10 + 11 + ;----------------------------------------------------------------------------- 12 + ; This program is free software. You can redistribute it and / or modify it 13 + ; under the terms of the GNU General Public License version 2 as published 14 + ; by the Free Software Foundation. 15 + ; 16 + ; This program is distributed in the hope that it will be useful, but 17 + ; WITHOUT ANY WARRANTY, without even the implied warranty of 18 + ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 19 + ; Public License for more details. 20 + ;----------------------------------------------------------------------------- 21 + 22 + 23 + %include "pce.inc" 24 + 25 + 26 + section .text 27 + 28 + 29 + drv_start: 30 + dd 0xffffffff ; link to next driver 31 + dw 0x8008 ; flags, clock character device 32 + dw drv_strategy ; strategy offset 33 + dw drv_interrupt ; interrupt offset 34 + db "CLOCK$ " ; driver name 35 + 36 + drv_funcs: 37 + dw drv_init ; 00 38 + dw drv_unknown ; 01 39 + dw drv_unknown ; 02 40 + dw drv_unknown ; 03 41 + dw drv_read ; 04 42 + dw drv_unknown ; 05 43 + dw drv_input_status ; 06 44 + dw drv_unknown ; 07 45 + dw drv_write ; 08 46 + dw drv_write ; 09 47 + drv_funcs_end: 48 + 49 + 50 + reqadr dd 0 51 + time dd 0, 0 52 + month_days db 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 53 + 54 + 55 + %define PCE_USE_HOOK_CHECK 1 56 + %define PCE_USE_HOOK_STOP 0 57 + %define PCE_USE_HOOK 1 58 + 59 + %include "pce-lib.inc" 60 + 61 + 62 + ;----------------------------------------------------------------------------- 63 + ; strategy function 64 + ;----------------------------------------------------------------------------- 65 + drv_strategy: 66 + mov [cs:reqadr + 0], bx 67 + mov [cs:reqadr + 2], es 68 + retf 69 + 70 + 71 + ;----------------------------------------------------------------------------- 72 + ; interrupt function 73 + ; 74 + ; request: 75 + ; 0 1 record length 76 + ; 1 1 unit number 77 + ; 2 1 function 78 + ; 3 2 status 79 + ; 5 8 reserved 80 + ;----------------------------------------------------------------------------- 81 + drv_interrupt: 82 + pushf 83 + push ax 84 + push bx 85 + push si 86 + push ds 87 + 88 + lds bx, [cs:reqadr] 89 + 90 + xor ah, ah 91 + mov al, [bx + 2] ; function 92 + shl ax, 1 93 + 94 + cmp ax, (drv_funcs_end - drv_funcs) 95 + jae .err 96 + 97 + mov si, ax 98 + 99 + call [cs:drv_funcs + si] 100 + 101 + .done: 102 + mov word [bx + 3], ax ; status 103 + 104 + pop ds 105 + pop si 106 + pop bx 107 + pop ax 108 + popf 109 + retf 110 + 111 + .err: 112 + call drv_unknown 113 + jmp .done 114 + 115 + 116 + ;----------------------------------------------------------------------------- 117 + ; unknown function 118 + ;----------------------------------------------------------------------------- 119 + drv_unknown: 120 + mov ax, 0x8103 121 + ret 122 + 123 + 124 + ;----------------------------------------------------------------------------- 125 + ; func 04: read 126 + ; 13 1 media descriptor 127 + ; 14 4 buffer 128 + ; 18 2 byte count 129 + ;----------------------------------------------------------------------------- 130 + drv_read: 131 + push cx 132 + push dx 133 + push di 134 + push es 135 + push bx 136 + 137 + cmp word [bx + 18], 6 ; byte count 138 + jb .err 139 + 140 + les di, [bx + 14] ; buffer 141 + 142 + mov ax, PCE_HOOK_GET_TIME_LOCAL 143 + call pce_hook ; get host time 144 + jc .err 145 + 146 + mov word [es:di + 2], cx ; hours / minutes 147 + mov word [es:di + 4], dx ; seconds / centiseconds 148 + 149 + cmp bh, 11 ; month 150 + ja .err 151 + 152 + sub ax, 1980 ; year 153 + jc .err 154 + 155 + mov cx, ax 156 + shr ax, 1 157 + shr ax, 1 158 + mov dx, 4 * 365 + 1 159 + mul dx 160 + 161 + inc ax ; leap day 162 + 163 + and cl, 3 164 + jnz .next_year 165 + 166 + cmp bh, 2 ; check if jan or feb 167 + sbb ax, 0 ; subtract leap day 168 + jmp .leap 169 + 170 + .next_year: 171 + add ax, 365 172 + dec cl 173 + jnz .next_year 174 + 175 + .leap: 176 + mov cx, bx ; month / mday 177 + or ch, ch ; month 178 + jz .last_month 179 + 180 + mov bx, month_days 181 + 182 + .next_month: 183 + add al, [cs:bx] ; days in month 184 + adc ah, 0 185 + inc bx 186 + dec ch 187 + jnz .next_month 188 + 189 + .last_month: 190 + xor ch, ch 191 + add ax, cx ; day of month 192 + 193 + mov word [es:di], ax ; days since 1980-01-01 194 + 195 + mov cx, 6 ; byte count 196 + mov ax, 0x0100 ; status 197 + 198 + .done: 199 + pop bx 200 + mov word [bx + 18], cx ; byte count 201 + pop es 202 + pop di 203 + pop dx 204 + pop cx 205 + ret 206 + 207 + .err: 208 + xor cx, cx ; byte count 209 + mov ax, 0x8100 ; status 210 + jmp .done 211 + 212 + 213 + ;----------------------------------------------------------------------------- 214 + ; func 06: input status 215 + ;----------------------------------------------------------------------------- 216 + drv_input_status: 217 + mov ax, 0x0100 218 + ret 219 + 220 + 221 + ;----------------------------------------------------------------------------- 222 + ; func 08: write 223 + ; 13 1 media descriptor 224 + ; 14 4 buffer 225 + ; 18 2 byte count 226 + ;----------------------------------------------------------------------------- 227 + drv_write: 228 + mov ax, 0x8100 229 + ret 230 + 231 + 232 + drv_end: 233 + 234 + 235 + ;----------------------------------------------------------------------------- 236 + ; func 00: init driver 237 + ; 13 1 units 238 + ; 14 4 end address 239 + ; 18 4 param address 240 + ;----------------------------------------------------------------------------- 241 + drv_init: 242 + push si 243 + 244 + mov si, msg_init 245 + call print_string 246 + 247 + call pce_hook_check 248 + jc .nopce 249 + 250 + push bx 251 + push cx 252 + push dx 253 + mov ax, PCE_HOOK_GET_TIME_LOCAL 254 + call pce_hook 255 + pop dx 256 + pop cx 257 + pop bx 258 + jc .nortc 259 + 260 + mov word [bx + 14], drv_end ; end address 261 + mov word [bx + 16], cs 262 + 263 + xor ax, ax 264 + mov byte [bx + 13], al ; units 265 + mov word [bx + 18], ax ; param address 266 + mov word [bx + 20], ax 267 + mov word [bx + 23], ax ; message flag 268 + 269 + mov ax, 0x0100 ; status 270 + 271 + .done: 272 + mov si, msg_nl 273 + call print_string 274 + 275 + pop si 276 + ret 277 + 278 + .nopce: 279 + mov si, msg_nopce 280 + call print_string 281 + jmp .err 282 + 283 + .nortc: 284 + mov si, msg_nortc 285 + call print_string 286 + 287 + .err: 288 + mov word [bx + 14], 0x0000 ; end address 289 + mov word [bx + 16], cs 290 + 291 + mov ax, 0x8100 ; status 292 + jmp .done 293 + 294 + 295 + ;----------------------------------------------------------------------------- 296 + ; print the string at CS:SI 297 + ;----------------------------------------------------------------------------- 298 + print_string: 299 + push ax 300 + push bx 301 + push si 302 + 303 + .next: 304 + cs 305 + lodsb 306 + or al, al 307 + jz .done 308 + mov ah, 0x0e 309 + mov bx, 0x0007 310 + int 0x10 311 + jmp .next 312 + 313 + .done: 314 + pop si 315 + pop bx 316 + pop ax 317 + ret 318 + 319 + 320 + msg_init db "PCE clock driver version ", PCE_VERSION_STR 321 + msg_nl db 0x0d, 0x0a, 0x00 322 + msg_nopce db "pceclock: not running under PCE", 0x0d, 0x0a, 0x00 323 + msg_nortc db "pceclock: RTC not supported", 0x0d, 0x0a, 0x00