home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / desqview / dvcalndr.zip / DVCAL.ASM next >
Assembly Source File  |  1993-08-18  |  13KB  |  525 lines

  1.  
  2. .MODEL tiny
  3.  
  4. COMMENT # 
  5.  
  6.                                DVCAL.COM
  7.                                Version 1.0
  8.                                No future versions anticipated
  9.  
  10.                                Written in MASM 6.1   8/93
  11.                                Copyright: Miles Pawski
  12.                                All rights reserved.
  13.  
  14.                                Calendar utility.  DV aware.
  15.                                Valid from 1900 through 2021
  16.   
  17.                                Page-up or Page-down through the months
  18.                                and years. 
  19.  
  20.                                Uses int 21h, function 2ah to get date info.
  21.  
  22.                                EGA+ only.
  23.  
  24.                                This code may be compiled with MASM 6.0-6.1
  25.                                by doing the following: ML dvcal.asm         
  26.  
  27.  #
  28.  
  29. make_table_two macro
  30. local i,t                  ;individual screen offsets for all possible day
  31.  t=4                       ;positions in calendar
  32.  i = (t*160)+(2*2)
  33.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  34.  t=t+1
  35.  i = (t*160)+(2*2)
  36.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  37.  t=t+1
  38.  i = (t*160)+(2*2)
  39.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  40.  t=t+1
  41.  i = (t*160)+(2*2)
  42.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  43.  t=t+1
  44.  i = (t*160)+(2*2)
  45.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  46.  t=t+1
  47.  i = (t*160)+(2*2)
  48.  WORD i,i+8,i+16,i+24,i+32,i+40,i+48 
  49.  endm
  50.  
  51.  
  52. make_year_table macro     ;makes year table BYTE "1900" through BYTE "2021"  
  53. a  TEXTEQU <19>           ;make first two letters "19"
  54. yr TEXTEQU <>             ;initialize empty work string
  55. num = 00                  ;start at 1900
  56.  
  57.  REPEAT 122
  58.   n TEXTEQU %num          ;convert numerical num to text string n
  59.   q SIZESTR n             ;q = length of n       
  60.   IF q EQ 1               ;if n is 1 digit long (1,2,3,4...9)
  61.     n CATSTR <0>,n        ;add a leading zero  
  62.   ELSEIF q EQ 0           ;if n is 0 digits long (happens with 0 value)
  63.     n CATSTR <0>,<0>      ;make n = "00"  
  64.   ENDIF
  65.   yr CATSTR <">,a,n,<">   ;year string: a=first 2 digits;n=last two digits      
  66. % Echo BYTE yr            ;check values during assembly
  67.   BYTE yr                 ;actual data entry
  68.   num = num + 1           ;increase numerical num  
  69.   IF num EQ 100           ;century change
  70.     a TEXTEQU <20>        ;make first two letters "20"     
  71.     num = 00              ;zero counter
  72.   ENDIF
  73.   endm
  74. endm
  75.  
  76.  delay2 PROTO near C,count:WORD
  77.  
  78.  
  79. .DATA
  80.  
  81.  main_panel label BYTE
  82.    BYTE  "╔═════════════════════════════╗"
  83.    BYTE  "║                             ║"
  84.    BYTE  "║ $─────────────────────────% ║"
  85.    BYTE  "║ &S   M   T   W   T   F   S% ║" 
  86.    BYTE  "║                             ║"
  87.    BYTE  "║                             ║" 
  88.    BYTE  "║                             ║"
  89.    BYTE  "║                             ║" 
  90.    BYTE  "║                             ║"
  91.    BYTE  "║                             ║" 
  92.    BYTE  "║$───────────────────────────%║"
  93.    BYTE  "║$Esc-Cancel    PgUp&",24,"$PgDn&",25,"%║"
  94.    BYTE  "╚═════════════════════════════╝"
  95.  
  96.  
  97.    dow_table label BYTE
  98.      BYTE 0,1,2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3,4,5,6,
  99.           0,1,2,3,4,5,6,0,1,2,3,4,5,6
  100.  
  101.    draw_table_one label WORD
  102.      WORD (0*160)
  103.      WORD (1*160)
  104.      WORD (2*160)
  105.      WORD (3*160)
  106.      WORD (4*160)
  107.      WORD (5*160)
  108.      WORD (6*160)
  109.      WORD (7*160)
  110.      WORD (8*160)
  111.      WORD (9*160)
  112.      WORD (10*160)
  113.      WORD (11*160)
  114.      WORD (12*160)
  115.  
  116.    draw_table_two label WORD
  117.       make_table_two
  118.  
  119.    day_table label BYTE
  120.     BYTE  " 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10" 
  121.     BYTE  "11","12","13","14","15","16","17","18","19","20"   
  122.     BYTE  "21","22","23","24","25","26","27","28","29","30"  
  123.     BYTE  "31"     
  124.  
  125.    day_count_table_1  label BYTE
  126.     BYTE 31,28,31,30,31,30,31,31,30,31,30,31
  127.  
  128.    day_count_table_2  label BYTE
  129.     BYTE 31,29,31,30,31,30,31,31,30,31,30,31
  130.  
  131.    year_table label BYTE
  132.      make_year_table
  133.  
  134.    month_table label BYTE
  135.     BYTE "JANUARY         "
  136.     BYTE "FEBRUARY        "
  137.     BYTE "MARCH           "
  138.     BYTE "APRIL           "
  139.     BYTE "MAY             "
  140.     BYTE "JUNE            "
  141.     BYTE "JULY            "
  142.     BYTE "AUGUST          "
  143.     BYTE "SEPTEMBER       "
  144.     BYTE "OCTOBER         "
  145.     BYTE "NOVEMBER        "
  146.     BYTE "DECEMBER        "    
  147.  
  148.  
  149.    leap_year_flag    BYTE     00h
  150.    month             BYTE     ?
  151.    year              WORD     ?
  152.    day               BYTE     ?
  153.    dow               BYTE     ?  
  154.    start_day         BYTE     ?
  155.    end_day           BYTE     ?
  156.    days_in_month     BYTE     ?
  157.    sorry             BYTE     "Sorry, EGA/VGA+ color monitor only..."      
  158.    mp                BYTE     "DVCAL.COM    Copyright: Miles Pawski",13,10,
  159.                               "Version 1.0  CIS: 70473,527"        
  160.  
  161.    PAGE_UP           EQU     4900h
  162.    PAGE_DOWN         EQU     5100h
  163.    BLUE_ON_WHITE     EQU     01110001y
  164.    RED_ON_WHITE      EQU     01110100y    
  165.    BLACK_ON_WHITE    EQU     01110000y
  166.  
  167. .CODE
  168. .STARTUP
  169.  
  170.    mov ax,1a00h
  171.    int 10h
  172.    .IF al != 1ah                       ;check for vga/ega video card
  173.        .IF bl != 4 && bl != 8
  174.            mov ah,40h
  175.            mov bx,1
  176.            mov cx,SIZEOF sorry
  177.            mov dx,offset sorry
  178.            int 21h
  179.            .EXIT 
  180.        .ENDIF
  181.    .ENDIF
  182.  
  183.  
  184.   mov ah,40h
  185.   mov bx,1
  186.   mov cx,SIZEOF mp
  187.   mov dx,offset mp
  188.   int 21h
  189.  
  190.   invoke delay2,40
  191.  
  192.  
  193.   mov ah,06h      ;select scroll function 06h to CLEAR THE SCREEN
  194.   mov al,0        ;0 means blank the screen
  195.   mov bh,2        ;attribute 0
  196.   mov ch,0        ;start at row 0
  197.   mov cl,0        ;start at column 0
  198.   mov dh,24       ;end at row 24
  199.   mov dl,79       ;end at column 79
  200.   int 10h         ;do it
  201.  
  202.    mov ah,02h
  203.    mov bh,00h
  204.    mov dh,25                 ;put cursor off page
  205.    mov dl,00h
  206.    int 10h
  207.   
  208.  
  209.    mov di,0b800h
  210.    mov es,di
  211.  
  212.    mov cx,"DE"
  213.    mov dx,"SQ"
  214.    mov ax,2b01h     ;in DESQview?
  215.    int 21h
  216.    cmp al,0ffh
  217.    je @F   
  218.   
  219.      mov ah,0feh    ;if in DV, get DV's video buffer segment
  220.      int 10h        ;which is returned in es
  221.                     ;es will now have either 0b800h or DV's own segment
  222.    @@:              ;many times they are the same. es never changes here. 
  223.  
  224.  
  225.    xor dx,dx
  226.    mov ah,BLUE_ON_WHITE
  227.    mov si,offset main_panel
  228.    .REPEAT
  229.       mov bx,dx
  230.       shl bx,1
  231.       mov di,draw_table_one[bx]   ;fill the box with info fields
  232.       mov cx,31
  233.       @@:
  234.         lodsb
  235.         .IF al=="%"                       ;return to blue on white
  236.             mov al,32
  237.             mov ah,BLUE_ON_WHITE
  238.         .ELSEIF al=="$"                   ;black on white
  239.             mov al,32
  240.             mov ah,BLACK_ON_WHITE
  241.         .ELSEIF al=="&"                   ;red on white
  242.             mov al,32
  243.             mov ah,RED_ON_WHITE
  244.         .ENDIF
  245.         stosw
  246.         loop @B
  247.       inc dx
  248.    .UNTIL dx == 13
  249.  
  250.  
  251.  mov ah,2ah                               ;get date info
  252.  int 21h
  253.  
  254.  mov year,cx                              ;store in variables
  255.  mov dow,al
  256.  mov day,dl
  257.  mov month,dh 
  258.  
  259.  
  260.  test cx,3
  261.  .IF ZERO? 
  262.     mov leap_year_flag,01h              ;see if leap year
  263.  .ELSE                                  ;evenly divisible by 4
  264.     mov leap_year_flag,00h              ;bits 0 & 1 will be clear
  265.  .ENDIF
  266.  
  267.  
  268.  mov si,offset dow_table
  269.  add si,42                              ;go to end of table
  270.  std
  271.  xor cx,cx
  272.  mov cl,day                             ;go back and find match of dow
  273.  mov al,dow
  274.  @@:
  275.    dec si
  276.    cmp al,[si]                          ;al==day of week
  277.    loopne @B
  278.  
  279.    xor ax,ax
  280.    mov al,day
  281.    dec al                               ;0 orient day
  282.    sub si,ax                            ;go back in table to find day
  283.    mov bl,[si]                          ;of week in which month starts
  284.    mov start_day,bl 
  285.  
  286.  
  287.    cld
  288.    xor bx,bx
  289.    mov bl,month
  290.    dec bl
  291.    xor cx,cx
  292.    .IF leap_year_flag == 01h
  293.       mov cl,day_count_table_2[bx]      ;load days in month table
  294.    .ELSE
  295.       mov cl,day_count_table_1[bx]
  296.    .ENDIF
  297.       mov days_in_month,cl              ;get days in month count
  298.  
  299.    mov bl,start_day
  300.    mov dl,dow_table[bx]                
  301.    add dl,cl                            ;cl== days in month
  302.    mov bl,dl
  303.    dec bl
  304.    mov dl,dow_table[bx]                 ;calculate last day of month (dow)
  305.    mov end_day,dl   
  306.  
  307.  start_over:
  308.    mov dx,4
  309.    mov ah,BLACK_ON_WHITE
  310.    mov al,32
  311.    .REPEAT                              ;clear the entries in box
  312.      mov bx,dx
  313.      shl bx,1
  314.      mov di,draw_table_one[bx]
  315.      add di,4
  316.      mov cx,26
  317.      rep stosw
  318.      inc dx
  319.    .UNTIL dx == 10
  320.  
  321.    xor cx,cx
  322.    mov cl,days_in_month
  323.    mov bl,start_day                     ;move into screen table to start at
  324.    shl bx,1                             ;the proper day 
  325.    mov si,offset day_table
  326.    mov ah,BLACK_ON_WHITE
  327.    push bx
  328.    .REPEAT
  329.      mov di,draw_table_two[bx]          ;write the days of month in box
  330.      lodsb
  331.      stosw
  332.      lodsb
  333.      stosw 
  334.      add bx,2
  335.    .UNTILCXZ
  336.    pop bx
  337.  
  338.    xor ax,ax
  339.    mov al,day
  340.    dec al                               ;0 adjust
  341.    shl ax,1
  342.    add bx,ax
  343.    mov di,draw_table_two[bx]
  344.    inc di                               ;attribute byte
  345.    mov al,00001110y                     ;bright yellow on black
  346.    stosb                                ;highlite the day         
  347.    inc di
  348.    stosb 
  349.  
  350.  xor bx,bx
  351.  mov bl,month
  352.  dec bl                                 ;make 0 start for table
  353.  mov si,offset month_table
  354.  shl bx,1
  355.  shl bx,1
  356.  shl bx,1
  357.  shl bx,1                               ;write the month
  358.  add si,bx          
  359.  mov di,(1*160)+(3*2)
  360.  mov ah,BLACK_ON_WHITE
  361.  mov cx,16
  362.  @@:
  363.    lodsb
  364.    stosw
  365.    loop @B
  366.  
  367.  mov bx,year
  368.  sub bx,1900
  369.  shl bx,1
  370.  shl bx,1
  371.  mov si,offset year_table             ;write the year
  372.  add si,bx
  373.  mov cx,4
  374.  mov di,(1*160)+(24*2)
  375.  mov ah,BLACK_ON_WHITE
  376.  @@:
  377.     lodsb
  378.     stosw
  379.     loop @B  
  380.  
  381. getkey:
  382.  
  383. mov ah,00h
  384. int 16h
  385.   .IF ax==PAGE_DOWN
  386.     .IF month > 1
  387.        dec month
  388.     .ELSE
  389.        .IF year==1900
  390.          jmp getkey
  391.        .ENDIF
  392.        mov month,12
  393.        dec year
  394.        mov cx,year  
  395.        test cx,3
  396.       .IF ZERO? 
  397.         mov leap_year_flag,01h
  398.       .ELSE
  399.         mov leap_year_flag,00h
  400.       .ENDIF
  401.     .ENDIF 
  402.      mov al,start_day
  403.      .IF al > 0                         ;days code 0-6 (Sun through Sat)
  404.        dec al
  405.      .ELSE
  406.        mov al,6
  407.      .ENDIF
  408.     mov end_day,al                      ;going backwards, end day of preivous
  409.                                         ;month in one day less than start 
  410.    xor bx,bx                            ;day of present month.
  411.    mov bl,month
  412.    dec bl
  413.    xor cx,cx
  414.    .IF leap_year_flag == 01h            ;load month table 
  415.       mov cl,day_count_table_2[bx]
  416.    .ELSE
  417.       mov cl,day_count_table_1[bx]
  418.    .ENDIF
  419.       mov days_in_month,cl
  420.  
  421.       mov si,offset dow_table
  422.       add si,42   
  423.       std
  424.       mov al,end_day
  425.     @@:
  426.       dec si
  427.       cmp al,[si]              ;find end day match
  428.       loopne @B
  429.       cld
  430.  
  431.       xor ax,ax
  432.       mov al,days_in_month
  433.       dec ax                   ;go back to start of month to
  434.       sub si,ax                ;get start day offset 
  435.  
  436.       mov al,[si]
  437.       mov start_day,al
  438.     jmp start_over
  439.   .ELSEIF ax==PAGE_UP
  440.     .IF month < 12
  441.        inc month
  442.     .ELSE
  443.        .IF year==2021
  444.           jmp getkey
  445.        .ENDIF  
  446.        mov month,1
  447.        inc year
  448.      mov cx,year  
  449.      test cx,3
  450.      .IF ZERO? 
  451.         mov leap_year_flag,01h
  452.      .ELSE
  453.         mov leap_year_flag,00h
  454.      .ENDIF
  455.     .ENDIF 
  456.  
  457.      mov al,end_day
  458.      .IF al < 6              ;days coded 0-6 (Sun through Sat)  
  459.        inc al
  460.      .ELSE
  461.        mov al,0
  462.      .ENDIF
  463.     mov start_day,al
  464.  
  465.    xor bx,bx
  466.    mov bl,month
  467.    dec bl
  468.    xor cx,cx
  469.    .IF leap_year_flag == 01h
  470.       mov cl,day_count_table_2[bx]
  471.    .ELSE
  472.       mov cl,day_count_table_1[bx]
  473.    .ENDIF
  474.       mov days_in_month,cl
  475.  
  476.       mov si,offset dow_table
  477.       dec si
  478.       mov al,start_day
  479.     @@:
  480.       inc si
  481.       cmp al,[si]
  482.       loopne @B
  483.  
  484.       xor ax,ax
  485.       mov al,days_in_month
  486.       dec ax                       ;go forward to find end day (dow)
  487.       add si,ax                    ;calculate end day of week of month
  488.  
  489.       mov al,[si]
  490.       mov end_day,al
  491.     jmp start_over
  492.  
  493.   .ELSEIF al==27
  494.      .EXIT
  495.   .ENDIF
  496.  jmp getkey
  497.  
  498.  delay2 proc near C,count:WORD
  499.      mov di,40h
  500.      mov es,di
  501.      mov di,6ch
  502.      mov dx,word ptr es:[di]
  503.      mov bx,dx              ;save clock count
  504.      mov ax,dx
  505.      xor si,si              ;zero si for counter
  506.      mov si,count
  507.      add bx,si
  508.      .IF CARRY?
  509.       @@:
  510.         mov dx,word ptr es:[di]
  511.         cmp dx,ax
  512.         jae @B
  513.      .ENDIF
  514.  @@:        
  515.     mov dx,word ptr es:[di]
  516.     cmp dx,bx             ; compare to start + count
  517.     jb @B                ;if over total, then leave
  518.     ret    
  519.  delay2 endp
  520.  
  521.  
  522.  
  523. END
  524.  
  525.