1 ; **************************************************************************** 2 ; date8086.s (date0.s) - by Erdogan Tan - 31/05/2022 3 ; ---------------------------------------------------------------------------- 4 ; Retro UNIX 8086 v1 - date - print and set the date 5 ; 6 ; [ Last Modification: 02/06/2022 ] 7 ; 8 ; Derived from (original) UNIX v5 'date.c' source Code 9 ; Ref: 10 ; www.tuhs.org (https://minnie.tuhs.org) 11 ; **************************************************************************** 12 ; [ v5root.tar.gz - usr/source/s1/date.c (archive date: 27-11-1974) ] 13 ; - usr/source/s3/ctime.c (archive date: 27-11-1974) 14 15 ; Assembler: NASM v2.15 16 ; ((nasm date0.s -l date0.txt -o date0 -Z error.txt)) 17 18 ; date1.s - 02/06/2022 - Retro UNIX 386 v1 & v1.1 & V1.2 19 ; date0.s - 02/06/2022 - Retro UNIX 8086 v1 (16 bit 'date1.s') 20 21 ;; (unix) v5man.pdf (page 45) 22 ;; -------------------------- 23 ;; 24 ;;NAME 25 ;; date - print and set the date 26 ;;SYNOPSIS 27 ;; date [ mmddhhmm[yy] ] 28 ;;DESCRIPTION 29 ;; If no argument is given, the current date is printed to the second. 30 ;; If an argument is given, the current date is set. 31 ;; The first num is the month number; dd is the day number in the month; 32 ;; hh is the hour number (24 hour sys), the 2'nd mm is the minute number; 33 ;; yy is the last 2 digits of the year number and is optional. 34 ;; 35 ;; For example: 36 ;; date 10080045 37 ;; 38 ;; sets the date to Oct 8, 12:45 AM. 39 ;; 40 ;; The current year is the default if no year is mentioned. 41 ;; 42 43 ; 12/01/2022 (Retro UNIX 386 v1.2) 44 ; 13/10/2015 45 46 ; UNIX v1 system calls 47 _rele equ 0 48 _exit equ 1 49 _fork equ 2 50 _read equ 3 51 _write equ 4 52 _open equ 5 53 _close equ 6 54 _wait equ 7 55 _creat equ 8 56 _link equ 9 57 _unlink equ 10 58 _exec equ 11 59 _chdir equ 12 60 _time equ 13 61 _mkdir equ 14 62 _chmod equ 15 63 _chown equ 16 64 _break equ 17 65 _stat equ 18 66 _seek equ 19 67 _tell equ 20 68 _mount equ 21 69 _umount equ 22 70 _setuid equ 23 71 _getuid equ 24 72 _stime equ 25 73 _quit equ 26 74 _intr equ 27 75 _fstat equ 28 76 _emt equ 29 77 _mdate equ 30 78 _stty equ 31 79 _gtty equ 32 80 _ilgins equ 33 81 _sleep equ 34 ; Retro UNIX 8086 v1 feature only ! 82 _msg equ 35 ; Retro UNIX 386 v1 feature only ! 83 _geterr equ 36 ; Retro UNIX 386 v1 feature only ! 84 ; 12/01/2022 - Retro UNIX 386 v1.2 85 ; Retro UNIX 386 v2 system calls 86 _setgid equ 37 87 _getgid equ 38 88 _sysver equ 39 ; (get) Retro Unix 386 version 89 90 ;;; 91 ESCKey equ 1Bh 92 EnterKey equ 0Dh 93 94 ;%macro sys 1-4 95 ; ; 03/09/2015 96 ; ; 13/04/2015 97 ; ; Retro UNIX 386 v1 system call. 98 ; %if %0 >= 2 99 ; mov ebx, %2 100 ; %if %0 >= 3 101 ; mov ecx, %3 102 ; ;%if %0 = 4 103 ; %if %0 >= 4 ; 11/03/2022 104 ; mov edx, %4 105 ; %endif 106 ; %endif 107 ; %endif 108 ; mov eax, %1 109 ; int 30h 110 ;%endmacro 111 112 %macro sys 1-4 113 ; Retro UNIX 8086 v1 system call. 114 %if %0 >= 2 115 mov bx, %2 116 %if %0 >= 3 117 mov cx, %3 118 %if %0 >= 4 119 mov dx, %4 120 %endif 121 %endif 122 %endif 123 mov ax, %1 124 int 20h 125 %endmacro 126 127 ;; Retro UNIX 386 v1 system call format: 128 ;; sys systemcall (eax) , , 129 130 ;; 11/03/2022 131 ;; Note: Above 'sys' macro has limitation about register positions; 132 ;; ebx, ecx, edx registers must not be used after their 133 ;; positions in sys macro. 134 ;; for example: 135 ;; 'sys _write, 1, msg, ecx' is defective, because 136 ;; ecx will be used/assigned before edx in 'sys' macro. 137 ;; correct order may be: 138 ;; 'sys _write, 1, msg, eax ; (eax = byte count) 139 140 ; Retro UNIX 8086 v1 system call format: 141 ; sys systemcall (ax) , , 142 143 ;----------------------------------------------------------------- 144 ; text - code 145 ;----------------------------------------------------------------- 146 147 [BITS 16] ; 16-bit intructions (for 8086 & 80386 real mode) 148 149 [ORG 0] 150 151 START_CODE: 152 ; 02/06/2022 153 ; (32 bit to 16 bit conversions for Retro UNIX 8086 v1) 154 ; 02/06/2022 155 ; 31/05/2022 156 00000000 58 pop ax ; number of arguments 157 00000001 5A pop dx ; argv[0] 158 ;;mov [argc], ax 159 ;mov [argc], al 160 161 ;cmp ax, 2 162 00000002 3C01 cmp al, 1 163 00000004 7625 jna short dt_2 ; print current date time 164 dt_0: 165 ; set date & time 166 ; ((date [ mmddhhmm[yy] ])) 167 00000006 5D pop bp ; word [cbp] ; argv[1] 168 169 ;if(gtime()) { 170 ; write(1, "bad conversion\n", 15); 171 ; exit(); 172 173 00000007 E84200 call gtime 174 0000000A 730B jnc short dt_1 175 176 0000000C B8[4C03] mov ax, msg_bad 177 dt_p_x: 178 0000000F E84B01 call print_msg 179 sys _exit 113 <1> 114 <1> %if %0 >= 2 115 <1> mov bx, %2 116 <1> %if %0 >= 3 117 <1> mov cx, %3 118 <1> %if %0 >= 4 119 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 00000012 B80100 <1> mov ax, %1 124 00000015 CD20 <1> int 20h 180 dt_1: 181 ;if(stime(timbuf) < 0) 182 ; write(1, "no permission\n", 14); 183 184 sys _stime, [timbuf], [timbuf+2] 113 <1> 114 <1> %if %0 >= 2 115 00000017 8B1E[7403] <1> mov bx, %2 116 <1> %if %0 >= 3 117 0000001B 8B0E[7603] <1> mov cx, %3 118 <1> %if %0 >= 4 119 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 0000001F B81900 <1> mov ax, %1 124 00000022 CD20 <1> int 20h 185 00000024 7305 jnc short dt_2 186 dt_err: 187 00000026 B8[5F03] mov ax, msg_no_perm 188 00000029 EBE4 jmp short dt_p_x 189 dt_2: 190 ;time(timbuf); 191 ;cbp = cbuf; 192 ;ctime(timbuf); 193 ;write(1, cbuf, 20); 194 ;tzn = tzname[localtime(timbuf)[8]]; 195 ;if (tzn) 196 ; write(1, tzn, 3); 197 ;write(1, cbuf+19, 6); 198 199 0000002B B8[5C03] mov ax, nextline 200 0000002E E82C01 call print_msg 201 202 sys _time 113 <1> 114 <1> %if %0 >= 2 115 <1> mov bx, %2 116 <1> %if %0 >= 3 117 <1> mov cx, %3 118 <1> %if %0 >= 4 119 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 00000031 B80D00 <1> mov ax, %1 124 00000034 CD20 <1> int 20h 203 ;mov [timbuf], ax 204 ;mov [timbuf+2], dx 205 206 ; dx:ax = unix epoch time 207 00000036 E83C01 call ctime 208 209 sys _write, 1, cbuf, 25 113 <1> 114 <1> %if %0 >= 2 115 00000039 BB0100 <1> mov bx, %2 116 <1> %if %0 >= 3 117 0000003C B9[FD02] <1> mov cx, %3 118 <1> %if %0 >= 4 119 0000003F BA1900 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 00000042 B80400 <1> mov ax, %1 124 00000045 CD20 <1> int 20h 210 211 00000047 B8[5C03] mov ax, nextline 212 0000004A EBC3 jmp short dt_p_x 213 214 ;----------------------------------------------------------------- 215 216 gtime: 217 ; INPUT: 218 ; bp = input string to be converted 219 ; (to unix epoch time) 220 ; OUTPUT: 221 ; cf = 0 -> OK 222 ; cf = 1 -> bad input 223 224 ;t = gpair(); 225 ;if(t<1 || t>12) 226 ; goto bad; 227 ;d = gpair(); 228 ;if(d<1 || d>31) 229 ; goto bad; 230 ;h = gpair(); 231 ;if(h == 24) { 232 ; h = 0; 233 ; d++; 234 235 0000004C E8E300 call gpair 236 0000004F 7253 jc short _bad 237 00000051 08D2 or dl, dl 238 00000053 744E jz short bad 239 00000055 80FA0C cmp dl, 12 240 00000058 7749 ja short bad 241 0000005A 8916[7803] mov [_t_], dx 242 0000005E E8D100 call gpair 243 00000061 7241 jc short _bad 244 00000063 20D2 and dl, dl 245 00000065 743C jz short bad 246 00000067 80FA1F cmp dl, 31 247 0000006A 7737 ja short bad 248 0000006C 8916[7A03] mov [_d_], dx 249 00000070 E8BF00 call gpair 250 00000073 722F jc short _bad 251 00000075 80FA18 cmp dl, 24 252 00000078 7729 ja short bad 253 0000007A 7202 jb short gtime_1 254 0000007C 28D2 sub dl, dl ; 0 255 gtime_1: 256 0000007E 8916[7C03] mov [_h_], dx 257 00000082 E8AD00 call gpair 258 00000085 721D jc short _bad 259 00000087 80FA3B cmp dl, 59 260 0000008A 7717 ja short bad 261 0000008C 8916[7E03] mov [_m_], dx 262 263 ;m = gpair(); 264 ;if(m<0 || m>59) 265 ; goto bad; 266 ;y = gpair(); 267 ;if (y<0) { 268 ; time(nt); 269 ; y = localtime(nt)[5]; 270 271 ;call time 272 sys _time 113 <1> 114 <1> %if %0 >= 2 115 <1> mov bx, %2 116 <1> %if %0 >= 3 117 <1> mov cx, %3 118 <1> %if %0 >= 4 119 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 00000090 B80D00 <1> mov ax, %1 124 00000093 CD20 <1> int 20h 273 ; dx:ax = time (in unix epoch format) 274 275 00000095 E83D01 call gmtime 276 277 00000098 E89700 call gpair 278 0000009B 7308 jnc short gtime_2 279 0000009D 8B16[9502] mov dx, [year] 280 000000A1 EB10 jmp short gtime_4 281 bad: 282 ;return(1); 283 000000A3 F9 stc 284 _bad: 285 000000A4 C3 retn 286 gtime_2: 287 000000A5 B8D007 mov ax, 2000 288 000000A8 3B06[9502] cmp ax, [year] ; 2000 289 000000AC 7603 jna short gtime_3 290 000000AE B86C07 mov ax, 1900 291 gtime_3: 292 000000B1 01C2 add dx, ax 293 gtime_4: 294 000000B3 8916[8003] mov [_y_], dx 295 296 ;timbuf[0] = 0; 297 ;timbuf[1] = 0; 298 ;y =+ 1900; 299 ;for(i=1970; i100) 469 ; return(-1); 470 ;if(*cp == 0) 471 ; return(-1); 472 ;if ((d = *cp++ - '0') < 0 || d > 9) 473 ; return(-1); 474 ;cbp = cp; 475 ;return (c+d); 476 477 00000132 31D2 xor dx, dx 478 479 00000134 89EE mov si, bp ; word [cbp] ; argv[1] 480 00000136 AC lodsb 481 00000137 20C0 and al, al 482 00000139 7420 jz short gp_c 483 0000013B 2C30 sub al, '0' 484 0000013D 721B jb short gp_x 485 ;cmp al, 10 ; ':'-'0' 486 ;ja short gp_c 487 0000013F 3C09 cmp al, 9 488 00000141 7718 ja short gp_c 489 00000143 B40A mov ah, 10 490 00000145 F6E4 mul ah 491 ;; (ax >= 0 and ax <= 100) 492 ; (ax >= 0 and ax <= 90) 493 00000147 88C2 mov dl, al 494 00000149 AC lodsb 495 0000014A 08C0 or al, al 496 0000014C 740D jz short gp_c 497 0000014E 2C30 sub al, '0' 498 00000150 7208 jb short gp_x 499 00000152 3C09 cmp al, 9 500 00000154 7705 ja short gp_c 501 502 00000156 89F5 mov bp, si 503 504 00000158 00C2 add dl, al 505 506 ; (dx >= 0 and dx <= 99) 507 gp_x: 508 0000015A C3 retn 509 gp_c: 510 0000015B F9 stc 511 0000015C C3 retn 512 513 ;----------------------------------------------------------------- 514 515 print_msg: 516 ; ax = asciiz string address 517 0000015D 89C6 mov si, ax 518 0000015F 4E dec si 519 nextchr: 520 00000160 46 inc si 521 00000161 803C00 cmp byte [si], 0 522 00000164 77FA ja short nextchr 523 ;cmp [si], 0Dh 524 ;ja short nextchr 525 00000166 29C6 sub si, ax 526 ; si = asciiz string length 527 ; 528 sys _write, 1, ax, si 113 <1> 114 <1> %if %0 >= 2 115 00000168 BB0100 <1> mov bx, %2 116 <1> %if %0 >= 3 117 0000016B 89C1 <1> mov cx, %3 118 <1> %if %0 >= 4 119 0000016D 89F2 <1> mov dx, %4 120 <1> %endif 121 <1> %endif 122 <1> %endif 123 0000016F B80400 <1> mov ax, %1 124 00000172 CD20 <1> int 20h 529 ; 530 00000174 C3 retn 531 532 ;----------------------------------------------------------------- 533 ; ctime, localtime, asctime, gmtime functions 534 535 %include 'ctime.s' ; 02/06/2022 536 <1> ; **************************************************************************** 537 <1> ; 538 <1> ; CTIME.INC (Retro Unix 8086 v1 - /bin/ls - list file or directory) 539 <1> ; ---------------------------------------------------------------------------- 540 <1> ; 541 <1> ; RETRO UNIX 8086 (Retro Unix == Turkish Rational Unix) 542 <1> ; Operating System Project (v0.1) by ERDOGAN TAN (Beginning: 11/07/2012) 543 <1> ; Retro UNIX 8086 v1 - /bin/ls file 544 <1> ; 545 <1> ; [ Last Modification: 02/06/2022 ] 546 <1> ; 547 <1> ; Derivation from UNIX Operating System (v1.0 for PDP-11) 548 <1> ; (Original) Source Code by Ken Thompson (Bell Laboratories, 1971-1972) 549 <1> ; 550 <1> ; **************************************************************************** 551 <1> ; 552 <1> ; Derived from 'ctime.c' file of original UNIX v5 (usr/source/s3/ctime.c) 553 <1> ; 554 <1> ; LS0.ASM, 19/11/2013 - 24/11/2013 555 <1> ; include ctime.inc 556 <1> ; 557 <1> ; **************************************************************************** 558 <1> ; ctime1.s (02/06/2022 NASM version of 'ctime1.asm') -NASM 2.15- 559 <1> ; ctime1.asm (26/02/2022) -MASM 6.14- 560 <1> ; ctime0.asm (28/11/2013) 561 <1> 562 <1> ; .8086 563 <1> 564 <1> ;timezone equ 5*60*60 565 <1> 566 <1> 567 <1> ctime: ; ctime(at) 568 <1> ; int *at; 569 <1> ; { 570 <1> ; return(asctime(localtime(at))); 571 <1> ; } 572 <1> 573 <1> ; DX:AX = unix epoch time (in seconds) 574 <1> 575 <1> ;call localtime 576 <1> ;call asctime 577 <1> 578 <1> ;retn 579 <1> 580 <1> localtime: 581 <1> ; localtime(tim) 582 <1> ; int tim[]; 583 <1> ; { 584 <1> ; register int *t, *ct, dayno; 585 <1> ; int daylbegin, daylend; 586 <1> ; int copyt[2]; 587 <1> ; t = copyt; 588 <1> ; t[0] = tim[0]; 589 <1> ; t[1] = tim[1]; 590 <1> ; dpadd(t, -timezone); 591 <1> ; ct = gmtime(t); 592 <1> ; dayno = ct[YDAY]; 593 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 594 <1> ; dayno==5 && ct[HOUR]>=2))) { 595 <1> ; daylight =| 1; 596 <1> ; daylbegin = -1; 597 <1> ; daylend = 367; 598 <1> ; } else { 599 <1> ; daylbegin = sunday(ct, 119); /* last Sun in Apr */ 600 <1> ; daylend = sunday(ct, 303); /* last Sun in Oct */ 601 <1> ; } 602 <1> ; if (daylight && 603 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 604 <1> ; (dayno ; dpadd(t, 1*60*60); 606 <1> ; ct = gmtime(t); 607 <1> ; ct[ISDAY]++; 608 <1> ; } 609 <1> ; return(ct); 610 <1> ; } 611 <1> 612 <1> ;sub ax, timezone 613 <1> ;sbb dx, 0 614 <1> 615 <1> ;push dx 616 <1> ;push ax 617 <1> 618 00000175 E85D00 <1> call gmtime 619 <1> 620 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 621 <1> ; dayno==5 && ct[HOUR]>=2))) { 622 <1> ;cmp byte [nixonflg], 0 623 <1> ;jna short lt1 624 <1> ;cmp word [year], 1974 625 <1> ;jb short lt1 626 <1> ;ja short lt0 627 <1> ;cmp word [yday], 5 628 <1> ;jb short lt1 629 <1> ;ja short lt0 630 <1> ;cmp word [hour], 2 631 <1> ;jb short lt1 632 <1> ; nixonflag > 0 633 <1> ;lt0: 634 <1> ;mov word [daylight], 1 635 <1> ;mov word [daylbegin], -1 636 <1> ;mov word [daylend], 367 637 <1> ; ;jmp short lt2 638 <1> 639 <1> ; } else { 640 <1> ;lt1: 641 <1> ; mov cx, 119 642 <1> ; call sunday ; sunday(ct, 119); /* last Sun in Apr */ 643 <1> ; mov word [daylbegin], cx 644 <1> ; mov cx, 303 645 <1> ; call sunday ; sunday(ct, 303); /* last Sun in Oct */ 646 <1> ; mov word [daylend], cx 647 <1> ;lt2: 648 <1> ; if (daylight && 649 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 650 <1> ; (dayno 652 <1> ; pop ax 653 <1> ; pop dx 654 <1> 655 <1> ;cmp byte [daylight], 0 656 <1> ;jna short lt5 657 <1> 658 <1> ;mov cx, word [yday] 659 <1> 660 <1> ;cmp cx, word [daylbegin] 661 <1> ;jb short lt5 662 <1> ;ja short lt3 663 <1> ;cmp word [hour], 2 664 <1> ;jb short lt5 665 <1> ;jmp short lt4 666 <1> ;lt3: 667 <1> ;cmp cx, word [daylend] 668 <1> ;jb short lt4 669 <1> ;ja short lt5 670 <1> ;cmp word [hour], 1 671 <1> ;jnb short lt5 672 <1> ;lt4: 673 <1> ;add ax, 1*60*60 674 <1> ;adc dx, 0 675 <1> ;call gmtime 676 <1> ;inc word [isday] 677 <1> ;lt5: 678 <1> ; } 679 <1> ; return(ct); 680 <1> ; } 681 <1> 682 <1> ;retn 683 <1> 684 <1> ; 26/02/2022 (Retro UNIX 8086 v1, 2022 modification) 685 <1> asctime: 686 <1> ; asctime(t) 687 <1> ;int *t; 688 <1> ;{ 689 <1> ; register char *cp, *ncp; 690 <1> ; register int *tp; 691 <1> ; 692 <1> ; cp = cbuf; 693 <1> ; for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;); 694 <1> ; ncp = &"SunMonTueWedThuFriSat"[3*t[6]]; 695 <1> ; cp = cbuf; 696 <1> ; *cp++ = *ncp++; 697 <1> ; *cp++ = *ncp++; 698 <1> ; *cp++ = *ncp++; 699 <1> ; cp++; 700 <1> ; tp = &t[4]; 701 <1> ; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3]; 702 <1> ; *cp++ = *ncp++; 703 <1> ; *cp++ = *ncp++; 704 <1> ; *cp++ = *ncp++; 705 <1> ; cp = numb(cp, *--tp); 706 <1> ; cp = numb(cp, *--tp+100); 707 <1> ; cp = numb(cp, *--tp+100); 708 <1> ; cp = numb(cp, *--tp+100); 709 <1> ; cp =+ 2; 710 <1> ; cp = numb(cp, t[YEAR]); 711 <1> ; return(cbuf); 712 <1> ;} 713 <1> 714 <1> ;;mov di, cbuf 715 <1> ;;mov si, ncp0 716 <1> ;;mov cx, 13 717 <1> ;;movsw 718 <1> ; 719 00000178 BF[FD02] <1> mov di, cbuf 720 <1> ;mov si, word [wday] 721 <1> ;shl si, 1 722 <1> ;shl si, 1 723 <1> ;add si, ncp1 724 <1> ;movsw 725 <1> ;movsw 726 0000017B 8B36[9302] <1> mov si, word [month] 727 0000017F D1E6 <1> shl si, 1 728 00000181 D1E6 <1> shl si, 1 729 00000183 81C6[C902] <1> add si, ncp2 - 4 730 00000187 A5 <1> movsw 731 00000188 A5 <1> movsw 732 00000189 A1[9102] <1> mov ax, word [day] 733 <1> ;mov cx, 10 734 0000018C B10A <1> mov cl, 10 735 0000018E E8E200 <1> call numb 736 00000191 B020 <1> mov al, 20h 737 00000193 AA <1> stosb 738 <1> ; 739 00000194 A1[9502] <1> mov ax, word [year] 740 00000197 B564 <1> mov ch, 100 741 00000199 F6F5 <1> div ch 742 0000019B 50 <1> push ax ; 743 0000019C 98 <1> cbw ; century (19, 20) 744 0000019D E8D300 <1> call numb 745 000001A0 58 <1> pop ax 746 000001A1 88E0 <1> mov al, ah 747 000001A3 98 <1> cbw ; year (0 to 99) 748 000001A4 E8CC00 <1> call numb 749 000001A7 B020 <1> mov al, 20h 750 000001A9 AA <1> stosb 751 <1> ; 752 000001AA 8B36[9702] <1> mov si, word [wday] 753 000001AE D1E6 <1> shl si, 1 754 000001B0 D1E6 <1> shl si, 1 755 000001B2 81C6[B102] <1> add si, ncp1 756 000001B6 A5 <1> movsw 757 000001B7 A5 <1> movsw 758 <1> ; 759 000001B8 A1[8F02] <1> mov ax, word [hour] 760 000001BB E8B500 <1> call numb 761 000001BE B03A <1> mov al, ':' 762 000001C0 AA <1> stosb 763 000001C1 A1[8D02] <1> mov ax, word [minute] 764 000001C4 E8AC00 <1> call numb 765 000001C7 B03A <1> mov al, ':' 766 000001C9 AA <1> stosb 767 000001CA A1[8B02] <1> mov ax, word [second] 768 000001CD E8A300 <1> call numb 769 000001D0 B020 <1> mov al, 20h 770 000001D2 AA <1> stosb 771 <1> ;mov ax, word [year] 772 <1> ;mov ch, 100 773 <1> ;div ch 774 <1> ;push ax ; 775 <1> ;cbw ; century (19, 20) 776 <1> ;call numb 777 <1> ;pop ax 778 <1> ;mov al, ah 779 <1> ;cbw ; year (0 to 99) 780 <1> ;call numb 781 <1> ;mov al, 20h 782 <1> ;stosb 783 <1> ;xor al, al 784 <1> ;stosb 785 <1> 786 <1> ; 26/02/2022 787 000001D3 AA <1> stosb 788 <1> 789 000001D4 C3 <1> retn 790 <1> 791 <1> gmtime: 792 <1> ; 24/11/2013 (yday, wday) 793 <1> ; Retro UNIX 8086 v1 - UNIX.ASM (20/06/2013) 794 <1> ; Retro UNIX 8086 v1 feature/procedure only! 795 <1> ; 'convert_from_epoch' procedure prototype: 796 <1> ; UNIXCOPY.ASM, 10/03/2013 797 <1> ; 30/11/2012 798 <1> ; Derived from DALLAS Semiconductor 799 <1> ; Application Note 31 (DS1602/DS1603) 800 <1> ; 6 May 1998 801 <1> ; 802 <1> ; INPUT: 803 <1> ; DX:AX = Unix (Epoch) Time 804 <1> ; 805 <1> ; ((Modified registers: AX, DX, CX, BX)) 806 <1> ; 807 000001D5 B93C00 <1> mov cx, 60 808 000001D8 E88900 <1> call div32 809 <1> ;mov word [imin], ax ; whole minutes 810 <1> ;mov word [imin]+2, dx ; since 1/1/1970 811 000001DB 891E[8B02] <1> mov word [second], bx ; leftover seconds 812 <1> ;mov cx, 60 813 000001DF E88200 <1> call div32 814 <1> ;mov word [ihrs], ax ; whole hours 815 <1> ;mov word [ihrs]+2, dx ; since 1/1/1970 816 000001E2 891E[8D02] <1> mov word [minute], bx ; leftover minutes 817 <1> ;mov cx, 24 818 000001E6 B118 <1> mov cl, 24 819 000001E8 E87900 <1> call div32 820 <1> ;mov word [iday], ax ; whole days 821 <1> ; since 1/1/1970 822 000001EB A3[9702] <1> mov word [wday], ax ; 24/11/2013 823 <1> ;mov word [iday]+2, dx ; DX = 0 824 000001EE 891E[8F02] <1> mov word [hour], bx ; leftover hours 825 000001F2 05DB02 <1> add ax, 365+366 ; whole day since 826 <1> ; 1/1/1968 827 <1> ;adc dx, 0 ; DX = 0 828 <1> ;mov word [iday], ax 829 000001F5 50 <1> push ax 830 000001F6 B9B505 <1> mov cx, (4*365)+1 ; 4 years = 1461 days 831 000001F9 E86800 <1> call div32 832 000001FC 59 <1> pop cx 833 <1> ;mov word [lday], ax ; count of quadyrs (4 years) 834 000001FD 53 <1> push bx 835 <1> ;mov word [qday], bx ; days since quadyr began 836 000001FE 83FB3C <1> cmp bx, 31 + 29 ; if past feb 29 then 837 00000201 F5 <1> cmc ; add this quadyr's leap day 838 00000202 83D000 <1> adc ax, 0 ; to # of qadyrs (leap days) 839 <1> ;mov word [lday], ax ; since 1968 840 <1> ;mov cx, word [iday] 841 00000205 91 <1> xchg cx, ax ; CX = lday, AX = iday 842 00000206 29C8 <1> sub ax, cx ; iday - lday 843 00000208 B96D01 <1> mov cx, 365 844 <1> ;xor dx, dx ; DX = 0 845 <1> ; AX = iday-lday, DX = 0 846 0000020B E85600 <1> call div32 847 <1> ;mov word [iyrs], ax ; whole years since 1968 848 <1> ; jday = iday - (iyrs*365) - lday 849 <1> ;mov word [jday], bx ; days since 1/1 of current year 850 0000020E 05B007 <1> add ax, 1968 ; compute year 851 00000211 A3[9502] <1> mov word [year], ax 852 00000214 89C2 <1> mov dx, ax 853 <1> ;mov ax, word [qday] 854 00000216 58 <1> pop ax 855 00000217 3D6D01 <1> cmp ax, 365 ; if qday <= 365 and qday >= 60 856 0000021A 7707 <1> ja short gmt_1 ; jday = jday +1 857 0000021C 83F83C <1> cmp ax, 60 ; if past 2/29 and leap year then 858 0000021F F5 <1> cmc ; add a leap day to the # of whole 859 00000220 83D300 <1> adc bx, 0 ; days since 1/1 of current year 860 <1> gmt_1: 861 <1> ;mov word [jday], bx 862 <1> ;mov word [yday], bx ; 24/11/2013 863 00000223 B90C00 <1> mov cx, 12 ; estimate month 864 00000226 87CB <1> xchg cx, bx ; CX = jday, BX = month 865 00000228 B86E01 <1> mov ax, 366 ; mday, max. days since 1/1 is 365 866 0000022B 83E203 <1> and dx, 11b ; year mod 4 (and dx, 3) 867 <1> gmt_2: ; Month calculation ; 0 to 11 (11 to 0) 868 0000022E 39C1 <1> cmp cx, ax ; mday = # of days passed from 1/1 869 00000230 7315 <1> jnb short gmt_3 870 00000232 4B <1> dec bx ; month = month - 1 871 00000233 D1E3 <1> shl bx, 1 872 00000235 8B87[9902] <1> mov ax, word DMonth[BX] ; # elapsed days at 1st of month 873 00000239 D1EB <1> shr bx, 1 ; bx = month - 1 (0 to 11) 874 0000023B 83FB01 <1> cmp bx, 1 ; if month > 2 and year mod 4 = 0 875 0000023E 76EE <1> jna short gmt_2 ; then mday = mday + 1 876 00000240 08D2 <1> or dl, dl ; if past 2/29 and leap year then 877 00000242 75EA <1> jnz short gmt_2 ; add leap day (to mday) 878 00000244 40 <1> inc ax ; mday = mday + 1 879 00000245 EBE7 <1> jmp short gmt_2 880 <1> gmt_3: 881 00000247 43 <1> inc bx ; -> bx = month, 1 to 12 882 00000248 891E[9302] <1> mov word [month], bx 883 0000024C 29C1 <1> sub cx, ax ; day = jday - mday + 1 884 0000024E 41 <1> inc cx 885 0000024F 890E[9102] <1> mov word [day], cx 886 <1> 887 <1> ; ax, bx, cx, dx is changed at return 888 <1> ; output -> 889 <1> ; [year], [month], [day], [hour], [minute], [second] 890 <1> ; [yday] -> 24/11/2013 891 <1> ; [wday] -> 24/11/2013 892 <1> ; 893 <1> ; 24/11/2013 894 00000253 A1[9702] <1> mov ax, word [wday] ; [iday] 895 00000256 30D2 <1> xor dl, dl ; xor dx, dx 896 <1> ; dx = 0 897 00000258 83C004 <1> add ax, 4 898 <1> ; NOTE: January 1, 1970 was THURSDAY 899 <1> ; ch = 0 900 0000025B B107 <1> mov cl, 7 901 0000025D F7F1 <1> div cx 902 0000025F 8916[9702] <1> mov word [wday], dx ; week of the day, 0 to 6 903 <1> ; 0 = sunday ... 6 = saturday 904 <1> ;mov word [isday], 0 905 <1> 906 00000263 C3 <1> retn 907 <1> 908 <1> div32: 909 <1> ; Input: 910 <1> ; DX:AX = 32 bit dividend 911 <1> ; CX = 16 bit divisor 912 <1> ; Output: 913 <1> ; DX:AX = 32 bit quotient 914 <1> ; BX = 16 bit remainder 915 00000264 89D3 <1> mov bx, dx 916 00000266 93 <1> xchg ax, bx 917 00000267 31D2 <1> xor dx, dx 918 00000269 F7F1 <1> div cx ; at first, divide DX 919 0000026B 93 <1> xchg ax, bx ; remainder is in DX 920 <1> ; now, BX has quotient 921 <1> ; save remainder 922 0000026C F7F1 <1> div cx ; so, DX_AX divided and 923 <1> ; AX has quotient 924 <1> ; DX has remainder 925 0000026E 87D3 <1> xchg dx, bx ; finally, BX has remainder 926 <1> 927 00000270 C3 <1> retn 928 <1> 929 <1> ;sunday: 930 <1> ; sunday(at, ad) 931 <1> ; int *at; 932 <1> ; { 933 <1> ; register int *t, d; 934 <1> ; t = at; 935 <1> ; d = ad; 936 <1> ; d = ad + dysize(t[YEAR]) - 365; 937 <1> ; return(d - (d - t[YDAY] + t[WDAY] + 700) % 7); 938 <1> ; } 939 <1> 940 <1> ;mov dx, word [year] 941 <1> ;call dysize 942 <1> ;sub ax, 365 943 <1> ;add cx, ax 944 <1> ; test word [year], 11b 945 <1> ; jnz short @f 946 <1> ; CX = 119 (77h) or CX = 303 (12Fh) 947 <1> ;inc cx 948 <1> ; inc cl 949 <1> ;@@: 950 <1> ; mov ax, cx 951 <1> ; add ax, word [wday] 952 <1> ;adc ax, 700 953 <1> ; add ax, 700 954 <1> ; sub ax, word [yday] 955 <1> ;xor dx, dx 956 <1> ; mov bx, 7 957 <1> ;div bx 958 <1> ; div bl 959 <1> ; sub cx, bx 960 <1> ; retn 961 <1> 962 <1> ;dysize: 963 <1> ; dysize(y) 964 <1> ; { 965 <1> ; if((y%4) == 0) 966 <1> ; return(366); 967 <1> ; return(365); 968 <1> ; } 969 <1> 970 <1> ; mov ax, 365 971 <1> ; test dx, 11b 972 <1> ; jnz short @f 973 <1> ; ;inc ax 974 00000271 FEC0 <1> inc al 975 <1> ;@@: 976 <1> ; retn 977 <1> 978 <1> 979 <1> numb: ; AX = 0 to 99 980 <1> ; 981 <1> ; numb(acp, n) 982 <1> ; { 983 <1> ; register char *cp; 984 <1> ; 985 <1> ; cp = acp; 986 <1> ; cp++; 987 <1> ; if (n>=10) 988 <1> ; *cp++ = (n/10)%10 + '0'; 989 <1> ; else 990 <1> ; *cp++ = ' '; 991 <1> ; *cp++ = n%10 + '0'; 992 <1> ; return(cp); 993 <1> ; } 994 <1> ; 995 <1> ;mov cl, 10 996 00000273 83F80A <1> cmp ax, 10 997 00000276 7306 <1> jnb short nb1 998 00000278 88C4 <1> mov ah, al 999 0000027A 30C0 <1> xor al, al ; 0 1000 0000027C EB04 <1> jmp short nb2 1001 <1> nb1: 1002 0000027E F6F1 <1> div cl 1003 00000280 88E2 <1> mov dl, ah 1004 <1> nb2: 1005 00000282 0430 <1> add al, '0' 1006 00000284 AA <1> stosb ; digit 1 1007 00000285 88E0 <1> mov al, ah 1008 00000287 0430 <1> add al, '0' 1009 00000289 AA <1> stosb ; digit 2 1010 0000028A C3 <1> retn 1011 <1> 1012 <1> 1013 <1> ;;; DATA 1014 <1> 1015 <1> ;daylight: db 1 ; int daylight 1; /* Allow daylight conversion */ 1016 <1> ;nixonflg: db 0 ; int nixonflg 0; /* Daylight time all year around */ 1017 <1> ;daylbegin: dw 0 1018 <1> ;daylend: dw 0 1019 <1> 1020 <1> ct: 1021 <1> ; 24/11/2013 (re-order) 1022 <1> ; 1023 <1> ; Retro UNIX 8086 v1 - UNIX.ASM 1024 <1> ; 09/04/2013 epoch variables 1025 <1> ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013 1026 <1> ; 1027 <1> 1028 0000028B 0000 <1> second: dw 0 1029 0000028D 0000 <1> minute: dw 0 1030 0000028F 0000 <1> hour: dw 0 1031 00000291 0100 <1> day: dw 1 1032 00000293 0100 <1> month: dw 1 1033 00000295 B207 <1> year: dw 1970 1034 00000297 0000 <1> wday: dw 0 ; 24/11/2013 1035 <1> ;yday: dw 0 ; 24/11/2013 1036 <1> ;isday: dw 0 ; 24/11/2013 1037 <1> 1038 <1> DMonth: 1039 00000299 0000 <1> dw 0 1040 0000029B 1F00 <1> dw 31 1041 0000029D 3B00 <1> dw 59 1042 0000029F 5A00 <1> dw 90 1043 000002A1 7800 <1> dw 120 1044 000002A3 9700 <1> dw 151 1045 000002A5 B500 <1> dw 181 1046 000002A7 D400 <1> dw 212 1047 000002A9 F300 <1> dw 243 1048 000002AB 1101 <1> dw 273 1049 000002AD 3001 <1> dw 304 1050 000002AF 4E01 <1> dw 334 1051 <1> 1052 <1> ;ncp0: db "Day Mon 00 00:00:00 1970", 0, 0 1053 000002B1 53756E204D6F6E2054- <1> ncp1: db "Sun Mon Tue Wed Thu Fri Sat " 1053 000002BA 756520576564205468- <1> 1053 000002C3 752046726920536174- <1> 1053 000002CC 20 <1> 1054 000002CD 4A616E20466562204D- <1> ncp2: db "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec " 1054 000002D6 617220417072204D61- <1> 1054 000002DF 79204A756E204A756C- <1> 1054 000002E8 204175672053657020- <1> 1054 000002F1 4F6374204E6F762044- <1> 1054 000002FA 656320 <1> 1055 <1> 1056 <1> cbuf: ; char cbuf[26] 1057 000002FD 00 <1> times 26 db 0 1058 00000317 00 <1> db 0 ; 02/06/2022 1059 <1> 1060 <1> ;; ctime.c (Unix v5) 1061 <1> ; 1062 <1> ;# 1063 <1> ;/* 1064 <1> ; * This routine converts time as follows. 1065 <1> ; * The epoch is 0000 Jan 1 1970 GMT. 1066 <1> ; * The argument time is in seconds since then. 1067 <1> ; * The localtime(t) entry returns a pointer to an array 1068 <1> ; * containing 1069 <1> ; * seconds (0-59) 1070 <1> ; * minutes (0-59) 1071 <1> ; * hours (0-23) 1072 <1> ; * day of month (1-31) 1073 <1> ; * month (0-11) 1074 <1> ; * year-1970 1075 <1> ; * weekday (0-6, Sun is 0) 1076 <1> ; * day of the year 1077 <1> ; * daylight savings flag 1078 <1> ; * 1079 <1> ; * The routine corrects for daylight saving 1080 <1> ; * time and will work in any time zone provided 1081 <1> ; * "timezone" is adjusted to the difference between 1082 <1> ; * Greenwich and local standard time (measured in seconds). 1083 <1> ; * In places like Michigan "daylight" must 1084 <1> ; * be initialized to 0 to prevent the conversion 1085 <1> ; * to daylight time. 1086 <1> ; * 1087 <1> ; * "nixonflg,", if set to 1, will 1088 <1> ; * cause daylight savings time all year around 1089 <1> ; * independently of "daylight". 1090 <1> ; * 1091 <1> ; * The routine does not work 1092 <1> ; * in Saudi Arabia which runs on Solar time. 1093 <1> ; * 1094 <1> ; * asctime(tvec)) 1095 <1> ; * where tvec is produced by localtime 1096 <1> ; * returns a ptr to a character string 1097 <1> ; * that has the ascii time in the form 1098 <1> ; * Thu Jan 01 00:00:00 1970n0\; * 01234567890123456789012345 1100 <1> ; * 0 1 2 1101 <1> ; * 1102 <1> ; * ctime(t) just calls localtime, then asctime. 1103 <1> ; */ 1104 <1> ;char cbuf[26]; 1105 <1> ;int dmsize[12] 1106 <1> ;{ 1107 <1> ; 31, 1108 <1> ; 28, 1109 <1> ; 31, 1110 <1> ; 30, 1111 <1> ; 31, 1112 <1> ; 30, 1113 <1> ; 31, 1114 <1> ; 31, 1115 <1> ; 30, 1116 <1> ; 31, 1117 <1> ; 30, 1118 <1> ; 31 1119 <1> ;}; 1120 <1> ; 1121 <1> ;int timezone 5*60*60; 1122 <1> ;int tzname[] 1123 <1> ;{ 1124 <1> ; "EST", 1125 <1> ; "EDT", 1126 <1> ;}; 1127 <1> ;int daylight 1; /* Allow daylight conversion */ 1128 <1> ;int nixonflg 0; /* Daylight time all year around */ 1129 <1> ; 1130 <1> ;#define SEC 0 1131 <1> ;#define MIN 1 1132 <1> ;#define HOUR 2 1133 <1> ;#define MDAY 3 1134 <1> ;#define MON 4 1135 <1> ;#define YEAR 5 1136 <1> ;#define WDAY 6 1137 <1> ;#define YDAY 7 1138 <1> ;#define ISDAY 8 1139 <1> ; 1140 <1> ;ctime(at) 1141 <1> ;int *at; 1142 <1> ;{ 1143 <1> ; return(asctime(localtime(at))); 1144 <1> ;} 1145 <1> ; 1146 <1> ;localtime(tim) 1147 <1> ;int tim[]; 1148 <1> ;{ 1149 <1> ; register int *t, *ct, dayno; 1150 <1> ; int daylbegin, daylend; 1151 <1> ; int copyt[2]; 1152 <1> ; 1153 <1> ; t = copyt; 1154 <1> ; t[0] = tim[0]; 1155 <1> ; t[1] = tim[1]; 1156 <1> ; dpadd(t, -timezone); 1157 <1> ; ct = gmtime(t); 1158 <1> ; dayno = ct[YDAY]; 1159 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 1160 <1> ; dayno==5 && ct[HOUR]>=2))) { 1161 <1> ; daylight =| 1; 1162 <1> ; daylbegin = -1; 1163 <1> ; daylend = 367; 1164 <1> ; } else { 1165 <1> ; daylbegin = sunday(ct, 119); /* last Sun in Apr */ 1166 <1> ; daylend = sunday(ct, 303); /* last Sun in Oct */ 1167 <1> ; } 1168 <1> ; if (daylight && 1169 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 1170 <1> ; (dayno ; dpadd(t, 1*60*60); 1172 <1> ; ct = gmtime(t); 1173 <1> ; ct[ISDAY]++; 1174 <1> ; } 1175 <1> ; return(ct); 1176 <1> ;} 1177 <1> ; 1178 <1> ;sunday(at, ad) 1179 <1> ;int *at; 1180 <1> ;{ 1181 <1> ; register int *t, d; 1182 <1> ; 1183 <1> ; t = at; 1184 <1> ; d = ad; 1185 <1> ; d = ad + dysize(t[YEAR]) - 365; 1186 <1> ; return(d - (d - t[YDAY] + t[WDAY] + 700) % 7); 1187 <1> ;} 1188 <1> ; 1189 <1> ;gmtime(tim) 1190 <1> ;int tim[]; 1191 <1> ;{ 1192 <1> ; register int d0, d1; 1193 <1> ; register *tp; 1194 <1> ; static xtime[9]; 1195 <1> ; extern int ldivr; 1196 <1> ; 1197 <1> ; /* 1198 <1> ; * break initial number into 1199 <1> ; * multiples of 8 hours. 1200 <1> ; * (28800 = 60*60*8) 1201 <1> ; */ 1202 <1> ; 1203 <1> ; d0 = ldiv(tim[0], tim[1], 28800); 1204 <1> ; d1 = ldivr; 1205 <1> ; tp = &xtime[0]; 1206 <1> ; 1207 <1> ; /* 1208 <1> ; * generate hours:minutes:seconds 1209 <1> ; */ 1210 <1> ; 1211 <1> ; *tp++ = d1%60; 1212 <1> ; d1 =/ 60; 1213 <1> ; *tp++ = d1%60; 1214 <1> ; d1 =/ 60; 1215 <1> ; d1 =+ (d0%3)*8; 1216 <1> ; d0 =/ 3; 1217 <1> ; *tp++ = d1; 1218 <1> ; 1219 <1> ; /* 1220 <1> ; * d0 is the day number. 1221 <1> ; * generate day of the week. 1222 <1> ; */ 1223 <1> ; 1224 <1> ; xtime[WDAY] = (d0+4)%7; 1225 <1> ; 1226 <1> ; /* 1227 <1> ; * year number 1228 <1> ; */ 1229 <1> ; for(d1=70; d0 >= dysize(d1); d1++) 1230 <1> ; d0 =- dysize(d1); 1231 <1> ; xtime[YEAR] = d1; 1232 <1> ; xtime[YDAY] = d0; 1233 <1> ; 1234 <1> ; /* 1235 <1> ; * generate month 1236 <1> ; */ 1237 <1> ; 1238 <1> ; if (dysize(d1)==366) 1239 <1> ; dmsize[1] = 29; 1240 <1> ; for(d1=0; d0 >= dmsize[d1]; d1++) 1241 <1> ; d0 =- dmsize[d1]; 1242 <1> ; dmsize[1] = 28; 1243 <1> ; *tp++ = d0+1; 1244 <1> ; *tp++ = d1; 1245 <1> ; xtime[ISDAY] = 0; 1246 <1> ; return(xtime); 1247 <1> ;} 1248 <1> ; 1249 <1> ;asctime(t) 1250 <1> ;int *t; 1251 <1> ;{ 1252 <1> ; register char *cp, *ncp; 1253 <1> ; register int *tp; 1254 <1> ; 1255 <1> ; cp = cbuf; 1256 <1> ; for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;); 1257 <1> ; ncp = &"SunMonTueWedThuFriSat"[3*t[6]]; 1258 <1> ; cp = cbuf; 1259 <1> ; *cp++ = *ncp++; 1260 <1> ; *cp++ = *ncp++; 1261 <1> ; *cp++ = *ncp++; 1262 <1> ; cp++; 1263 <1> ; tp = &t[4]; 1264 <1> ; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3]; 1265 <1> ; *cp++ = *ncp++; 1266 <1> ; *cp++ = *ncp++; 1267 <1> ; *cp++ = *ncp++; 1268 <1> ; cp = numb(cp, *--tp); 1269 <1> ; cp = numb(cp, *--tp+100); 1270 <1> ; cp = numb(cp, *--tp+100); 1271 <1> ; cp = numb(cp, *--tp+100); 1272 <1> ; cp =+ 2; 1273 <1> ; cp = numb(cp, t[YEAR]); 1274 <1> ; return(cbuf); 1275 <1> ;} 1276 <1> ; 1277 <1> ;dysize(y) 1278 <1> ;{ 1279 <1> ; if((y%4) == 0) 1280 <1> ; return(366); 1281 <1> ; return(365); 1282 <1> ;} 1283 <1> ; 1284 <1> ; 1285 <1> ;numb: 1286 <1> ; 1287 <1> ; 1288 <1> ;numb(acp, n) 1289 <1> ;{ 1290 <1> ; register char *cp; 1291 <1> ; cp = acp; 1292 <1> ; cp++; 1293 <1> ; if (n>=10) 1294 <1> ; *cp++ = (n/10)%10 + '0'; 1295 <1> ; else 1296 <1> ; *cp++ = ' '; 1297 <1> ; *cp++ = n%10 + '0'; 1298 <1> ; return(cp); 1299 <1> ;} 1300 <1> ; 536 ; (ctime.s file last modification date: 02/06/2022) 537 538 ;----------------------------------------------------------------- 539 ; data - initialized data 540 ;----------------------------------------------------------------- 541 542 ;;argc: dw 0 543 ;argc: db 0 544 545 ; ---------------------------------------------------------------- 546 547 ;program_msg: 548 ;db 0Dh, 0Ah 549 00000318 526574726F20554E49- db 'Retro UNIX 8086 v1 DATE by Erdogan TAN - 02/06/2022' 549 00000321 582038303836207631- 549 0000032A 204441544520627920- 549 00000333 4572646F67616E2054- 549 0000033C 414E202D2030322F30- 549 00000345 362F32303232 550 ;db 0Dh, 0Ah, 0 551 0000034B 00 db 0 552 553 ;usage_msg: 554 ; db 0Dh, 0Ah 555 ; db 'usage: date [ mmddhhmm[yy] ]' ; (unix v5) 556 557 ;nextline: 558 ; db 0Dh, 0Ah, 0 559 560 msg_bad: 561 0000034C 0D0A db 0Dh, 0Ah 562 0000034E 62616420636F6E7665- db 'bad conversion' 562 00000357 7273696F6E 563 nextline: 564 0000035C 0D0A00 db 0Dh, 0Ah, 0 565 566 msg_no_perm: 567 0000035F 0D0A db 0Dh, 0Ah 568 00000361 6E6F207065726D6973- db 'no permission' 568 0000036A 73696F6E 569 0000036E 0D0A00 db 0Dh, 0Ah, 0 570 571 ;----------------------------------------------------------------- 572 ; bss - uninitialized data 573 ;----------------------------------------------------------------- 574 575 00000371 90 align 4 576 577 bss_start: 578 579 ABSOLUTE bss_start 580 581 00000374 ???????? timbuf: resd 1 ; (unix epoch time, 32 bit) 582 583 00000378 ???? _t_: resw 1 ; month 584 0000037A ???? _d_: resw 1 ; day 585 0000037C ???? _h_: resw 1 ; hour 586 0000037E ???? _m_: resw 1 ; minute 587 00000380 ???? _y_: resw 1 ; year 588 00000382 ???? resw 1 589 590 ; 31/05/2022 591 ;----------------------------------------------------------------- 592 ; Original UNIX v5 - date - c source code (date.s) 593 ;----------------------------------------------------------------- 594 ; UNIX V5 source code: see www.tuhs.org for details. 595 ;----------------------------------------------------------------- 596 ; v5root.tar.gz - usr/source/s1/date.c (archive date: 27-11-1974) 597 598 ;int timbuf[2]; 599 ;char *cbp; 600 ; 601 ;char *tzname[2]; 602 ;int dmsize[]; 603 ;char cbuf[]; 604 ;char *cbp; 605 ; 606 ;struct { 607 ; char name[8]; 608 ; char tty; 609 ; char fill1; 610 ; int wtime[2]; 611 ; int fill2; 612 ;} wtmp[2]; 613 ; 614 ;main(argc, argv) 615 ;int argc, **argv; 616 ;{ 617 ; register char *tzn; 618 ; extern int timezone, *localtime(); 619 ; int wf; 620 ; 621 ; if(argc > 1) { 622 ; cbp = argv[1]; 623 ; if(gtime()) { 624 ; write(1, "bad conversion\n", 15); 625 ; exit(); 626 ; } 627 ; if (*cbp != 's') { 628 ; /* convert to Greenwich time, on assumption of Standard time. */ 629 ; dpadd(timbuf, timezone); 630 ; /* Now fix up to local daylight time. */ 631 ; if (localtime(timbuf)[8]) 632 ; dpadd(timbuf, -1*60*60); 633 ; } 634 ; time(wtmp[0].wtime); 635 ; wtmp[0].tty = '|'; 636 ; if(stime(timbuf) < 0) 637 ; write(1, "no permission\n", 14); 638 ; if ((wf = open("/usr/adm/wtmp", 1)) >= 0) { 639 ; time(wtmp[1].wtime); 640 ; wtmp[1].tty = '}'; 641 ; seek(wf, 0, 2); 642 ; write(wf, wtmp, 32); 643 ; } 644 ; } 645 ; time(timbuf); 646 ; cbp = cbuf; 647 ; ctime(timbuf); 648 ; write(1, cbuf, 20); 649 ; tzn = tzname[localtime(timbuf)[8]]; 650 ; if (tzn) 651 ; write(1, tzn, 3); 652 ; write(1, cbuf+19, 6); 653 ;} 654 ; 655 ;gtime() 656 ;{ 657 ; register int i; 658 ; register int y, t; 659 ; int d, h, m; 660 ; extern int *localtime(); 661 ; int nt[2]; 662 ; 663 ; if (*cbp == 's') 664 ; return(spidertime()); 665 ; t = gpair(); 666 ; if(t<1 || t>12) 667 ; goto bad; 668 ; d = gpair(); 669 ; if(d<1 || d>31) 670 ; goto bad; 671 ; h = gpair(); 672 ; if(h == 24) { 673 ; h = 0; 674 ; d++; 675 ; } 676 ; m = gpair(); 677 ; if(m<0 || m>59) 678 ; goto bad; 679 ; y = gpair(); 680 ; if (y<0) { 681 ; time(nt); 682 ; y = localtime(nt)[5]; 683 ; } 684 ; if (*cbp == 'p') 685 ; h =+ 12; 686 ; if (h<0 || h>23) 687 ; goto bad; 688 ; timbuf[0] = 0; 689 ; timbuf[1] = 0; 690 ; y =+ 1900; 691 ; for(i=1970; i100) 736 ; return(-1); 737 ; if(*cp == 0) 738 ; return(-1); 739 ; if ((d = *cp++ - '0') < 0 || d > 9) 740 ; return(-1); 741 ; cbp = cp; 742 ; return (c+d); 743 ;} 744 ; 745 ;/* 746 ; * get time from spider network. 747 ; */ 748 ;char asktime[] {0226, 0207, 0205}; 749 ; 750 ;spidertime() 751 ;{ 752 ; register tiuf, n; 753 ; static char buf[10]; 754 ; struct { char ch[4]; }; 755 ; int c; 756 ; 757 ; if ((tiuf = open("/dev/tiu/d0", 2)) < 0) 758 ; return(1); 759 ; /* get trouble */ 760 ; snstat(tiuf, &c, 3); 761 ; /* set signal */ 762 ; c = 3; 763 ; snstat(tiuf, &c, 0); 764 ; write(tiuf, asktime, 3); 765 ; snstat(tiuf, &c, 3); 766 ; n = read(tiuf, buf, 10); 767 ; /* get signal byte */ 768 ; snstat(tiuf, &c, 1); 769 ; if (c!=3 || buf[0]!=012 || buf[5]!=0177600) 770 ; return(1); 771 ; timbuf[0].ch[0] = buf[2]; 772 ; timbuf[0].ch[1] = buf[1]; 773 ; timbuf[0].ch[2] = buf[4]; 774 ; timbuf[0].ch[3] = buf[3]; 775 ; return(0); 776 ;}