home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / pcalender_396.lzh / PCalender / PCalender.asm < prev    next >
Assembly Source File  |  1990-10-29  |  12KB  |  490 lines

  1.  
  2. ;       PCalender V1.0
  3. ;    by Preben Nielsen.
  4. ;    Assemble it as case-sensitive.
  5. ;    OPT O+
  6. ;    OPT O1+        ;Tells when a branch could be optimised to short
  7. ;    OPT i+        ;Tells when '#' is probably missing
  8.  
  9. ;MyPref
  10. ; if 'MyPref' is defined, the head of the calender will look like this:
  11. ;    'Mon Tue Wed Thu Fri Sat Sun'
  12. ; otherwise it will look like this:
  13. ;    'Sun Mon Tue Wed Thu Fri Sat'
  14.  
  15.     incdir    "INCLUDE:"
  16.     include "exec/exec_lib.i"
  17.     include "graphics/rastport.i"
  18.     include "graphics/graphics_lib.i"
  19.     include "intuition/intuition.i"
  20.     include "intuition/intuition_lib.i"
  21.     include "libraries/dosextens.i"
  22.     include "devices/inputevent.i"
  23.  
  24.  
  25. StartYear    =1990
  26.  
  27. LowerYear    =1700        ;Range of years the calender display
  28. UpperYear    =2500
  29.  
  30. MonthStep    =1
  31. MonthStepShift    =4
  32. YearStep    =1
  33. YearStepShift    =10
  34.  
  35. xStartB        =4
  36. yStartB        =22
  37. xSizeB        =30
  38. ySizeB        =11
  39. xSpaceB        =2
  40. ySpaceB        =1
  41.  
  42. xStartT        =xStartB+4
  43. yStartT        =yStartB+8
  44.  
  45. WWidth        =2*xStartB+7*(xSizeB+xSpaceB)-xSpaceB
  46. WHeight        =yStartB+6*(ySizeB+ySpaceB)+1
  47.  
  48. WBenchMsg    =0
  49. GfxBase        =4
  50. IntBase        =8
  51. CWindow        =12
  52. Font        =16
  53. Year        =20
  54. Month        =22
  55. ScrHeight    =24
  56. Iconified    =27
  57.  
  58. LoadBase    MACRO
  59.         IFNC        '\1','ExecBase'
  60.         movea.l        \1(A4),A6
  61.         ENDC
  62.         IFC        '\1','ExecBase'
  63.         movea.l        4.W,A6
  64.         ENDC
  65.         ENDM
  66. CallLib        MACRO
  67.         jsr        _LVO\1(A6)
  68.         ENDM
  69. Call        MACRO
  70.         bsr        \1
  71.         ENDM
  72. Push        MACRO
  73.         movem.l        \1,-(SP)
  74.         ENDM
  75. Pop        MACRO
  76.         movem.l        (SP)+,\1
  77.         ENDM
  78.  
  79. IconIDCMP    =MOUSEBUTTONS+CLOSEWINDOW
  80. FullIDCMP    =MOUSEBUTTONS+CLOSEWINDOW+RAWKEY
  81.  
  82.         SECTION CALCODE,CODE
  83. CData        EQUR    A4
  84. Rp        EQUR    A5
  85.  
  86.         lea        DataStart(PC),CData
  87.         LoadBase    ExecBase
  88.         suba.l        A1,A1
  89.         CallLib        FindTask        ;Find us
  90.         movea.l        D0,A2
  91.         tst.l        pr_CLI(A2)        ;pr_CLI
  92.         bne.S        CLIAndWBStartup
  93. WBenchStartup    lea        pr_MsgPort(A2),A0    ;pr_MsgPort
  94.         CallLib        WaitPort        ;wait for a message
  95.         lea        pr_MsgPort(A2),A0
  96.         CallLib        GetMsg            ;then get it
  97.         move.l        D0,WBenchMsg(CData)    ;save it for later reply
  98. CLIAndWBStartup lea        GfxName(PC),A1
  99.         CallLib        OldOpenLibrary
  100.         move.l        D0,GfxBase(CData)
  101.         lea        IntName(PC),A1
  102.         CallLib        OldOpenLibrary
  103.         move.l        D0,IntBase(CData)
  104.         LoadBase    GfxBase
  105.         lea        TxtAttr(PC),A0
  106.         CallLib        OpenFont
  107.         move.l        D0,Font(CData)
  108.         beq.S        Exit
  109. GetAWindow    LoadBase    IntBase
  110.         lea        NW(PC),A0
  111.         move.w        ScrHeight(CData),D1    ;Screen height
  112.         sub.w        nw_Height(A0),D1
  113.         cmp.w        nw_TopEdge(A0),D1
  114.         bgt.S        yPosOk
  115.         move.w        D1,nw_TopEdge(A0)
  116. yPosOk        CallLib        OpenWindow
  117.         move.l        D0,CWindow(CData)
  118.         beq.S        Exit
  119.         movea.l        D0,A0
  120.         movea.l        wd_RPort(A0),Rp        ;RastPort in A5 always
  121.         movea.l        wd_WScreen(A0),A0
  122.         move.w        sc_Height(A0),ScrHeight(CData)
  123.         LoadBase    GfxBase
  124.         movea.l        Font(CData),A0
  125.         movea.l        Rp,A1
  126.         CallLib        SetFont            ;Make sure to use topaz in the right size
  127.         LoadBase    IntBase
  128.         movea.l        CWindow(CData),A0
  129.         lea        WinTitle(PC),A1
  130.         lea        ScrTitle(PC),A2
  131.         CallLib        SetWindowTitles
  132.         bra.S        Main
  133.  
  134. Exit
  135. FreeWindow    LoadBase    IntBase
  136.         move.l        CWindow(CData),D0
  137.         beq.S        FreeIntui
  138.         movea.l        D0,A0
  139.         CallLib        CloseWindow        ;Close window if it is open
  140. FreeIntui    LoadBase    ExecBase
  141.         move.l        IntBase(CData),D0
  142.         beq.S        FreeGfx
  143.         movea.l        D0,A1
  144.         CallLib        CloseLibrary        ;Close intuition if it is open
  145. FreeGfx        move.l        GfxBase(CData),D0
  146.         beq.S        ReplyWB
  147.         movea.l        D0,A1
  148.         CallLib        CloseLibrary        ;Close graphics if it is open
  149. ReplyWB        move.l        WBenchMsg(CData),D0
  150.         beq.S        AllDone
  151.         CallLib        Forbid
  152.         movea.l        D0,A1
  153.         CallLib        ReplyMsg        ;Reply WBenchMessage if we are started from WB
  154. AllDone        moveq        #0,D0
  155.         rts
  156.  
  157. Main
  158. RefreshWindow    tst.w        Iconified(CData)
  159.         bne.S        GetNextMsg
  160.         Call        SetDrMd1        ;Refreshes entire window
  161.         Call        SetBPen1
  162.         Call        SetAPen1
  163.         moveq        #xStartB,D0
  164.         moveq        #11,D1
  165.         move.w        #WWidth-xStartB-1,D2
  166.         moveq        #20,D3
  167.         movea.l        Rp,A1            ;RastPort
  168.         CallLib        RectFill
  169.         moveq        #xStartB+2*(xSizeB+xSpaceB),D0
  170.         moveq        #yStartB+5*(ySizeB+ySpaceB),D1
  171.         move.w        #WWidth-xStartB-1,D2
  172.         move.w        D1,D3
  173.         add.w        #ySizeB-1,D3
  174.         movea.l        Rp,A1            ;RastPort
  175.         CallLib        RectFill
  176.         Call        SetAPen2
  177.         moveq        #xStartT-1,D0
  178.         moveq        #18,D1
  179.         moveq        #27,D2
  180.         lea        WeekTxt(PC),A0
  181.         Call        Txt
  182.         Call        NewYear
  183. GetNextMsg    LoadBase    ExecBase
  184.         movea.l        CWindow(CData),A0
  185.         movea.l        wd_UserPort(A0),A0
  186.         CallLib        WaitPort
  187.         movea.l        CWindow(CData),A0
  188.         movea.l        wd_UserPort(A0),A0
  189.         CallLib        GetMsg
  190.         tst.l        D0
  191.         beq.S        GetNextMsg
  192.         movea.l        D0,A1            ;Message address to A1
  193.         move.l        im_Class(A1),D2        ;Save the event class in D2
  194.         move.w        im_Code(A1),D3        ;Save the event code in D3
  195.         move.w        im_Qualifier(A1),D4    ;Save the event qualifier in D4
  196.         andi.w        #IEQUALIFIER_LSHIFT+IEQUALIFIER_RSHIFT,D4    ;Mask out the shift keys
  197.         CallLib        ReplyMsg        ;Reply the message
  198. CheckWinClose    cmpi.w        #CLOSEWINDOW,D2
  199.         beq        Exit            ;Terminate ?
  200. CheckButtons    cmpi.w        #MOUSEBUTTONS,D2
  201.         bne.S        CheckRawkey
  202.         cmpi.w        #MENUDOWN,D3        ;Pressed the Menu-button ?
  203.         bne.S        CheckRawkey
  204.         LoadBase    IntBase
  205.         not.w        Iconified(CData)
  206.         beq.S        UnIconify
  207. Iconify        moveq        #10,D0
  208.         move.l        #IconIDCMP,D1
  209.         bra.S        ChangeWin
  210. UnIconify    moveq        #WHeight,D0
  211.         move.l        #FullIDCMP,D1
  212. ChangeWin    LoadBase    IntBase
  213.         move.l        CWindow(CData),A0
  214.         lea        NW(PC),A1
  215.         move.l        wd_LeftEdge(A0),nw_LeftEdge(A1)
  216.         move.w        D0,nw_Height(A1)
  217.         move.l        D1,nw_IDCMPFlags(A1)
  218.         CallLib        CloseWindow
  219.         bra        GetAWindow
  220. CheckRawkey    cmpi.w        #RAWKEY,D2
  221.         bne        GetNextMsg        ;No key touched
  222.         cmpi.w        #78,D3            ;A key was touched. Is it an arrow-key ?
  223.         beq.S        ChangeYear
  224.         cmpi.w        #79,D3
  225.         beq.S        ChangeYear
  226.         cmpi.w        #76,D3
  227.         beq.S        ChangeMonth
  228.         cmpi.w        #77,D3
  229.         bne        GetNextMsg
  230. ChangeMonth    lea        Month(CData),A0
  231.         moveq        #MonthStep,D0        ;Step value for months without Shift key
  232.         tst.w        D4
  233.         beq.S        NoMonthShift
  234.         moveq        #MonthStepShift,D0    ;Step value for months with Shift key
  235. NoMonthShift    cmpi.w        #76,D3            ;Which direction
  236.         beq.S        AddMonth
  237.         neg        D0
  238. AddMonth    add.w        (A0),D0
  239.         addi.w        #12,D0
  240.         ext.l        D0
  241.         divu        #12,D0
  242.         swap        D0
  243.         move.w        D0,(A0)            ;0-11
  244.         Call        NewMonth
  245.         bra        GetNextMsg
  246. ChangeYear    lea        Year(CData),A0
  247.         moveq        #YearStep,D0        ;Step value for year without Shift key
  248.         tst.w        D4
  249.         beq.S        NoYearShift
  250.         moveq        #YearStepShift,D0    ;Step value for year with Shift key
  251. NoYearShift    cmpi.w        #78,D3            ;Which direction
  252.         beq.S        AddYear
  253.         neg        D0
  254. AddYear        add.w        (A0),D0
  255.         subi.w        #LowerYear,D0
  256.         addi.w        #UpperYear-LowerYear+1,D0
  257.         ext.l        D0
  258.         divu        #UpperYear-LowerYear+1,D0
  259.         swap        D0
  260.         addi.w        #LowerYear,D0
  261.         move.w        D0,(A0)
  262.         Call        NewYear
  263.         bra        GetNextMsg
  264.  
  265. NewYear        Push        D0-D7/A0-A3
  266.         lea        TempTxt+4(PC),A0    ;Convert the year to ascii
  267.         move.w        Year(CData),D0
  268.         ext.l        D0
  269. ConvertLoop    tst.l        D0            ;A0=end of printbuffer
  270.         ble.S        EndConvert
  271.         divu        #10,D0
  272.         swap        D0
  273.         addi.b        #'0',D0
  274.         move.b        D0,-(A0)
  275.         clr.w        D0
  276.         swap        D0
  277.         bra.S        ConvertLoop
  278. EndConvert    move.w        #xStartT+2*(xSizeB+xSpaceB)+90,D0
  279.         moveq        #yStartT+5*(ySizeB+ySpaceB),D1
  280.         moveq        #4,D2
  281.         lea        TempTxt(PC),A0        ;Print year
  282.         Call        Txt
  283.         move.w        Year(CData),D0
  284.         ext.l        D0
  285.         move.l        D0,D1
  286.         divu        #4,D1            ;Year%4
  287.         swap        D1
  288.         tst.w        D1
  289.         bne.S        NotLeapYear
  290.         move.l        D0,D1
  291.         divu        #400,D1            ;Year%400
  292.         swap        D1
  293.         tst.w        D1
  294.         beq.S        LeapYear
  295.         move.l        D0,D1
  296.         divu        #100,D1
  297.         swap        D1            ;Year%100
  298.         tst.w        D1
  299.         bne.S        LeapYear
  300. NotLeapYear    moveq        #28,D0
  301.         bra.S        LeapYearOrNot
  302. LeapYear    moveq        #29,D0            ;If ((Year%400==0)||((Year%100!=0)&&(Year%4==0)))
  303. LeapYearOrNot    lea        Days+1(PC),A0
  304.         move.b        D0,(A0)            ;Days[1]=28 or Days[1]=28
  305.         move.w        Year(CData),D0
  306.         subq.w        #1,D0
  307.         ext.l        D0
  308.         move.l        D0,D7
  309.         move.l        D0,D6
  310.         move.l        D0,D5
  311.         divu        #4,D7            ;year/4
  312.         divu        #100,D6            ;year/100
  313.         divu        #400,D5            ;year/400
  314.         sub.w        D6,D7            ;D7=Year/4-Year/100
  315.         add.w        D5,D7            ;D7=(Year/4)-(Year/100)+(Year/400)=LeapDays
  316.         add.w        D0,D7            ;D7=(Year/4)-(Year/100)+(Year/400)+(Year*(365 % 7))
  317.     IFND    MyPref
  318.         addq.w        #1,D7
  319.     ENDC
  320.         ext.l        D7
  321.         divu        #7,D7
  322.         swap        D7
  323.         lea        Days(PC),A1
  324.         lea        Offset(PC),A0
  325.         move.b        D7,(A0)
  326.         moveq        #1,D7            ;for (i=1;i<12;i++)
  327. ModLoop        cmpi.w        #12,D7            ; Offset[i]=(Days[i-1]+Offset[i-1])%7;
  328.         bge.S        EndMod
  329.         moveq        #0,D0
  330.         moveq        #0,D1
  331.         move.b        -1(A0,D7.W),D0
  332.         move.b        -1(A1,D7.W),D1
  333.         add.w        D1,D0            ;D0=Days[i-1]+Offset[i-1]
  334.         divu        #7,D0
  335.         swap        D0            ;D0=(Days[i-i]+Offset[i-1])%7
  336.         move.b        D0,0(A0,D7.W)        ;Offset[i]=D0
  337.         addq.w        #1,D7
  338.         bra.S        ModLoop
  339. EndMod        Call        NewMonth
  340.         Pop        D0-D7/A0-A3
  341.         rts
  342.  
  343. NewMonth    Push        D0-D7/A0-A3
  344.         LoadBase    GfxBase
  345.         Call        SetAPen1
  346.         moveq        #yStartB+5*(ySizeB+ySpaceB),D5    ;Draw black squares from the right bottom
  347.         moveq        #xStartB+1*(xSizeB+xSpaceB),D4    ;Special treatment for the first two squares
  348.         bra.S        xLoop
  349. yLoop        move.w        #xStartB+6*(xSizeB+xSpaceB),D4
  350. xLoop        Push        D4-D5
  351.         move.w        D4,D0
  352.         move.w        D5,D1
  353.         move.w        D4,D2
  354.         move.w        D5,D3
  355.         addi.w        #xSizeB-1,D2        ;SizeX
  356.         addi.w        #ySizeB-1,D3        ;SizeY
  357.         movea.l        Rp,A1            ;RastPort
  358.         CallLib        RectFill
  359.         Pop        D4-D5
  360.         subi.w        #xSizeB+xSpaceB,D4
  361.         cmpi.w        #xStartB,D4
  362.         bge.S        xLoop
  363.         subi.w        #ySizeB+ySpaceB,D5
  364.         cmpi.w        #yStartB,D5
  365.         bge.S        yLoop            ;Done Drawing
  366.         Call        SetAPen2
  367.         moveq        #xStartT+2*(xSizeB+xSpaceB)+8,D0
  368.         moveq        #yStartT+5*(ySizeB+ySpaceB),D1
  369.         moveq        #9,D2
  370.         muls        Month(CData),D2
  371.         lea        Months(PC),A0
  372.         adda.w        D2,A0
  373.         moveq        #9,D2
  374.         Call        Txt            ;Write name of month
  375.         lea        Offset(PC),A0
  376.         adda.w        Month(CData),A0        ;Add month
  377.         moveq        #0,D7
  378.         move.b        (A0),D7            ;D7=Offset[Month]; ;D5=x,D6=y
  379.         move.w        D7,D5
  380.         mulu.w        #xSizeB+xSpaceB,D5
  381.         addi.w        #xStartT+3,D5        ;x=(xSize+xSpace)*D7+xStart+3;            
  382.         moveq        #yStartT,D6        ;y=yStart
  383.         lea        Days(PC),A0
  384.         adda.w        Month(CData),A0
  385.         move.b        (A0),D4            ;Days[Month]
  386.         moveq        #0,D3            ;for (i=0;i<Days[Month];i++)
  387. TxtLoop        cmp.b        D4,D3            ;Last day
  388.         bge.S        EndTxtLoop
  389.         move.w        D3,D2
  390.         addq.w        #1,D2
  391.         moveq        #'0',D1
  392.         lea        TempTxt(PC),A0
  393.         move.b        #' ',(A0)        ;If only one digit then start with a ' '
  394.         ext.l        D2
  395.         divu        #10,D2
  396.         add.b        D1,D2
  397.         cmp.b        D1,D2
  398.         beq.S        OnlyOneDigit
  399.         move.b        D2,(A0)
  400. OnlyOneDigit    swap        D2
  401.         add.b        D1,D2
  402.         move.b        D2,1(A0)
  403.         move.w        D5,D0            ;Move(rp,x,y);
  404.         move.w        D6,D1            ;Text(rp,TempText,2);
  405.         moveq        #2,D2
  406.         Call        Txt
  407.         addi.w        #xSizeB+xSpaceB,D5    ;x+=32;
  408.         addq.w        #1,D7            ;if (++M==7) {M=0;x=14;y+=13;}
  409.         cmpi.w        #7,D7
  410.         bne.S        SameLine
  411.         moveq        #0,D7            ;Wrap onto new line
  412.         moveq        #xStartT+3,D5
  413.         addi.w        #ySizeB+ySpaceB,D6
  414. SameLine    addq.w        #1,D3
  415.         bra.S        TxtLoop
  416. EndTxtLoop    Pop        D0-D7/A0-A3
  417.         rts
  418.  
  419. ;D0=x,D1=y,D2=count
  420. Txt        LoadBase    GfxBase
  421.         movea.l        Rp,A1
  422.         CallLib        Move
  423.         move.w        D2,D0
  424.         movea.l        Rp,A1
  425.         CallLib        Text
  426.         rts
  427.  
  428. SetAPen1    moveq        #1,D0
  429.         bra.S        SetPenA
  430. SetAPen2    moveq        #2,D0
  431. SetPenA        movea.l        Rp,A1            ;D0=Color
  432.         LoadBase    GfxBase
  433.         CallLib        SetAPen
  434.         rts
  435.  
  436. SetBPen1    moveq        #1,D0
  437. SetPenB        movea.l        Rp,A1            ;D0=Color
  438.         LoadBase    GfxBase
  439.         CallLib        SetBPen
  440.         rts
  441.  
  442. SetDrMd1    moveq        #1,D0
  443. SetMdDr        movea.l        Rp,A1            ;D0=Mode
  444.         LoadBase    GfxBase
  445.         CallLib        SetDrMd
  446.         rts
  447.  
  448. ;This data is to referenced relative to A4
  449. DataStart    dc.l    0        ;WBenchMsg
  450.         dc.l    0        ;GfxBase
  451.         dc.l    0        ;IntBase
  452.         dc.l    0        ;CWindow
  453.         dc.l    0        ;Font
  454.         dc.w    StartYear    ;Year
  455.         dc.w    0        ;Month
  456.         dc.w    200        ;ScrHeight
  457.         dc.w    -1        ;Iconified    ;Start as iconified
  458.  
  459. NW        dc.w    300,40,WWidth,10        ;Start as iconified
  460.         dc.b    0,1
  461.         dc.l    IconIDCMP
  462.         dc.l    WINDOWDEPTH+WINDOWDRAG+WINDOWCLOSE+ACTIVATE+RMBTRAP+NOCAREREFRESH,0,0,0,0,0
  463.         dc.w    150,50,320,200,WBENCHSCREEN
  464.  
  465. TxtAttr        dc.l    FontName
  466.         dc.w    TOPAZ_EIGHTY
  467.         dc.b    FS_NORMAL,FPB_ROMFONT
  468.  
  469. FontName    dc.b    'topaz.font',0
  470. Offset                        ;Re-Use space below after opening libraries
  471. GfxName        dc.b    'graphics.library',0
  472. TempTxt                        ;Re-Use space below after opening libraries
  473. IntName        dc.b    'intuition.library',0
  474.  
  475. ScrTitle    dc.b    'PCalender V1.0 by Preben Nielsen in 1990. This is Public Domain',0
  476. WinTitle    dc.b    ' PCalender V1.0   ',0
  477.     IFND    MyPref
  478. WeekTxt        dc.b    'Sun Mon Tue Wed Thu Fri Sat'
  479.     ENDC
  480.     IFD    MyPref
  481. WeekTxt        dc.b    'Mon Tue Wed Thu Fri Sat Sun'
  482.     ENDC
  483.  
  484. Months        dc.b    'January  February March    April    '
  485.         dc.b    'May      June     July     August   '
  486.         dc.b    'SeptemberOctober  November December '
  487. Days        dc.b    31,28,31,30,31,30,31,31,30,31,30,31
  488.         END
  489.  
  490.