Announcement

Collapse
No announcement yet.

Day-of-Week in Assembly

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Day-of-Week in Assembly

    I am trying to add some Assembly code (written for DOS, not Windows) that accesses the DoW from the BIOS, and it just locks up (Windows just displays "has stopped responding"). Can this be done at all? Is there a Windows "way" to accomplish this using PB/CC5? Source code is attached if anyone knows how I know not the WinAPI lol

    DVWASM.BAS
    Attached Files

  • #2
    Windows way. PBCC 5 or 6. Easy to convert to PBWin too.
    Code:
    #compile exe
    #dim all
    #include "WinBase.inc"
    function pbmain () as long
      local LocalTime as systemtime
      local DoW_Name as string
      GetLocalTime(LocalTime) 'declare for this in include
      select case LocalTime.wDayOfWeek
        case 0
          DoW_Name = "Sunday"
        case 1
          DoW_Name = "Monday"
        case 2
          DoW_Name = "Tuesday"
        case 3
          DoW_Name = "Wednesday"
        case 4
          DoW_Name = "Thursday"
        case 5
          DoW_Name = "Friday"
        case 6
          DoW_Name = "Saturday"
      end select
      print "Today is "; DoW_Name
      waitkey$
    end function
    Cheers,
    Dale

    Comment


    • #3
      Thank you so much, I will test this shortly!

      Comment


      • #4
        Bingo! Works like a dream, thanks again! I did have to use Win32API.inc vice WinBase.inc but who's counting {chuckle}

        Comment


        • #5
          Thanks Dale

          put in my file!
          [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
          Kerry Farmer

          Comment


          • #6
            Code:
            REM PBCC 6 and PBWIN 10 support PowerTime object which includes date math
            REM https://forum.powerbasic.com/forum/announcements-articles-and-support-faqs/pbcc-online-help-and-commentary/58962-powertime-object
            #BREAK ON
            FUNCTION PBMAIN () AS LONG
             LOCAL date1 AS IPOWERTIME
             date1 = CLASS "PowerTime"
             date1.now
             ShowMembers date1
             WAITKEY$
            END FUNCTION
            
            SUB ShowMembers(obj AS IPOWERTIME)
             ? obj.timestringfull
             ? obj.timestring24
             ? obj.timestring
             ? obj.month
             ? obj.day
             ? obj.year
             ? obj.dayofweek
             ? obj.dayofweekstring
             ? obj.datestringlong
             ? IIF$(obj.isleapyear,"Leap year","Not leap year")
            END SUB
            https://www.tesla.com/roadster

            Comment


            • #7
              Simple BASIC, no APIs or Objects

              Code:
              #COMPILE EXE
              #DIM ALL
              
              FUNCTION PBMAIN () AS LONG
              
                 ? DayOFWeek(DATE$)
              
              END FUNCTION
              
              
              FUNCTION DayOfWeek(strDate AS STRING) AS STRING
                  'Returns Day of Week from a strng formatted as per DATE$
                    LOCAL y,m,d,lngDOW AS LONG
                    LOCAL strDOW AS STRING
                    LOCAL z AS DOUBLE
                    y = VAL(RIGHT$(strDate,4))
                    d = VAL(MID$(strDate,4,2))
                    m = VAL(LEFT$(strDate,2))
                    z = y + (m - 2.85) / 12
                    lngDOW = ((INT(INT(INT(367 * z) - 1.75 * INT(z) + d) -0.75 * INT(0.01 * z)) + 1721119) -3) MOD 7
                  SELECT CASE lngDOW
                  CASE 0
                    strDOW = "Sunday"
                  CASE 1
                    strDOW = "Monday"
                  CASE 2
                    strDOW = "Tuesday"
                  CASE 3
                    strDOW = "Wednesday"
                  CASE 4
                    strDOW = "Thursday"
                  CASE 5
                    strDOW = "Friday"
                  CASE 6
                    strDOW = "Saturday"
                END SELECT
                FUNCTION = strDOW
              END FUNCTION
              :

              Comment


              • #8
                Originally posted by Stuart McLachlan View Post
                Simple BASIC, no APIs or Objects ...
                Aha! Time for Zeller's Congruence again. See https://en.wikipedia.org/wiki/Zeller's_congruence.

                I've used it a lot over the decades before APIs.

                Egbert Zijlema has posted a lot of stuff about it, both here and at http://zijlema.basicguru.eu/


                See also post#22 onwards here:https://forum.powerbasic.com/forum/u...routines/page2

                Comment


                • #9
                  An alternative to calculating the DOW is to look up a calendar, particularly useful if you need to skip weekends and public holidays. For example, if you have a financial application which is calculating a moving average of the "n" days preceding the day in question, you don't want to include data from days on which no trading occurred.

                  Yes, you have to build the calendar table too, which may or may not involve calculation.

                  Comment


                  • #10
                    I particularly like how the POWERTIME object can back up to the beginning of the month.


                    Code:
                    '_________________________________________________________________
                    '
                    ' FUNCTION  CurrentDayOfTheWeek
                    '_________________________________________________________________
                    
                    FUNCTION CurrentDayOfTheWeek AS STRING
                        LOCAL date1 AS IPOWERTIME
                        LOCAL CDOW  AS STRING
                    
                        date1 = CLASS "PowerTime"
                        date1.now
                        CDOW = UCASE$(date1.dayofweekstring)
                        ? "The current day of the week is " + CDOW + "."
                    
                        'Find the DayOfWeek the month started with
                        date1.AddDays(date1.day - (date1.day - 1))
                    
                        ? "The month began with " + UCASE$(date1.dayofweekstring) + "."
                    
                        FUNCTION = CDOW
                    END FUNCTION
                    
                                  

                    Comment


                    • #11
                      Simple BASIC and slightly more pure than normal. Managed to get at least some of the original request for assembler.

                      Code:
                      ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      
                          GLOBAL sarr() as STRING
                      
                      FUNCTION PBmain as LONG
                      
                          LOCAL day as DWORD
                      
                          daytable            ' initialise table
                      
                          ! mov day, 3
                          ! cmp day, 6        ' error checking
                          ! ja pastit
                      
                          StdOut sarr(day)    ' display result
                          Waitkey$
                          Exit FUNCTION
                      
                        pastit:
                          StdOut "Index out of range"
                          Waitkey$
                      
                      End FUNCTION
                      
                      ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      
                       FUNCTION daytable() as DWORD
                      
                          DIM sarr(7) as STRING
                      
                          sarr(0) = "Sunday"
                          sarr(1) = "Monday"
                          sarr(2) = "Tuesday"
                          sarr(3) = "Wednesday"
                          sarr(4) = "Thursday"
                          sarr(5) = "Friday"
                          sarr(6) = "Saturday"
                      
                       END FUNCTION
                      
                      ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      hutch at movsd dot com
                      The MASM Forum

                      www.masm32.com

                      Comment


                      • #12
                        OOPs post #10 should have read this

                        Code:
                        '_________________________________________________________________
                        '
                        ' FUNCTION  CurrentDayOfTheWeek
                        '_________________________________________________________________
                        
                        FUNCTION CurrentDayOfTheWeek AS STRING
                            LOCAL date1 AS IPOWERTIME
                            local CDOW  as string
                        
                            date1 = CLASS "PowerTime"
                            date1.now
                            CDOW = UCASe$(date1.dayofweekstring)
                            '? CDOW
                            'Find the DayOfWeek the month started with
                            date1.AddDays( - (date1.day - 1))
                            gsCurrentMonthBeginsWith = UCASe$(date1.dayofweekstring)
                        
                            ? "The month began with " + gsCurrentMonthBeginsWith + "."
                        
                            FUNCTION = CDOW
                        end function

                        Comment


                        • #13
                          Had a bit more time to play with this one. The example does the conversion both ways, day to number and number to day. Both use a zero based index and while the day to number should not be played with, its a simple to use high level basic function. The example also show how to error check the day numbers so that anything over 6 or under zero is not passed to the function.
                          Code:
                          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                          
                              GLOBAL sarr() as STRING
                          
                          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                          
                          FUNCTION PBmain as LONG
                          
                              DIM sarr(7) as STRING
                          
                              daytable                                    ' initialise table before use
                          
                              LOCAL num as DWORD
                              num = 0
                              ! cmp num, 6                                ' how to perform error checking
                              ! ja pastit                                 ' prevent number < 0 and > 6
                          
                              Do
                                day$ = sarr(num)                          ' get the day string in 1 operation
                                num = daynum(day$)                        ' use day$ to get the day number in 1 operation
                                StdOut day$+" = day number "+format$(num) ' display both
                                ! add num, 1
                              Loop While num <= 6
                          
                              Erase sarr()
                              Waitkey$
                              Exit FUNCTION
                          
                            pastit:
                              Erase sarr()
                              StdOut "Index out of range"
                              Waitkey$
                          
                          End FUNCTION
                          
                          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                          
                           FUNCTION daytable() as DWORD
                          
                              sarr(0) = "Sunday"
                              sarr(1) = "Monday"
                              sarr(2) = "Tuesday"
                              sarr(3) = "Wednesday"
                              sarr(4) = "Thursday"
                              sarr(5) = "Friday"
                              sarr(6) = "Saturday"
                          
                           END FUNCTION
                          
                          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                          
                           FUNCTION daynum(day$) as DWORD
                          
                              LOCAL pstr as DWORD
                              day1$ = lcase$(day$)
                              pstr = StrPtr(day1$)
                          
                              PREFIX "!"
                          
                              mov eax, pstr
                          
                              cmp BYTE PTR [eax+0], "f"
                              jne lbl0
                              cmp BYTE PTR [eax+1], "r"
                              jne notfound
                              cmp BYTE PTR [eax+2], "i"
                              jne notfound
                              cmp BYTE PTR [eax+3], "d"
                              jne notfound
                              cmp BYTE PTR [eax+4], "a"
                              jne notfound
                              cmp BYTE PTR [eax+5], "y"
                              jne notfound
                              cmp BYTE PTR [eax+6], 0
                              jne notfound
                            ; -------------------
                              mov eax, 5 ; friday
                              jmp ExitLabel
                            ; -------------------
                            lbl0:
                              cmp BYTE PTR [eax+0], "m"
                              jne lbl1
                              cmp BYTE PTR [eax+1], "o"
                              jne notfound
                              cmp BYTE PTR [eax+2], "n"
                              jne notfound
                              cmp BYTE PTR [eax+3], "d"
                              jne notfound
                              cmp BYTE PTR [eax+4], "a"
                              jne notfound
                              cmp BYTE PTR [eax+5], "y"
                              jne notfound
                              cmp BYTE PTR [eax+6], 0
                              jne notfound
                            ; -------------------
                              mov eax, 1 ; monday
                              jmp ExitLabel
                            ; -------------------
                            lbl1:
                              cmp BYTE PTR [eax+0], "s"
                              jne lbl2
                              cmp BYTE PTR [eax+1], "a"
                              jne lbl3
                              cmp BYTE PTR [eax+2], "t"
                              jne notfound
                              cmp BYTE PTR [eax+3], "u"
                              jne notfound
                              cmp BYTE PTR [eax+4], "r"
                              jne notfound
                              cmp BYTE PTR [eax+5], "d"
                              jne notfound
                              cmp BYTE PTR [eax+6], "a"
                              jne notfound
                              cmp BYTE PTR [eax+7], "y"
                              jne notfound
                              cmp BYTE PTR [eax+8], 0
                              jne notfound
                            ; -------------------
                              mov eax, 6 ; saturday
                              jmp ExitLabel
                            ; -------------------
                            lbl3:
                              cmp BYTE PTR [eax+1], "u"
                              jne notfound
                              cmp BYTE PTR [eax+2], "n"
                              jne notfound
                              cmp BYTE PTR [eax+3], "d"
                              jne notfound
                              cmp BYTE PTR [eax+4], "a"
                              jne notfound
                              cmp BYTE PTR [eax+5], "y"
                              jne notfound
                              cmp BYTE PTR [eax+6], 0
                              jne notfound
                            ; -------------------
                              mov eax, 0 ; sunday
                              jmp ExitLabel
                            ; -------------------
                            lbl2:
                              cmp BYTE PTR [eax+0], "t"
                              jne lbl4
                              cmp BYTE PTR [eax+1], "h"
                              jne lbl5
                              cmp BYTE PTR [eax+2], "u"
                              jne notfound
                              cmp BYTE PTR [eax+3], "r"
                              jne notfound
                              cmp BYTE PTR [eax+4], "s"
                              jne notfound
                              cmp BYTE PTR [eax+5], "d"
                              jne notfound
                              cmp BYTE PTR [eax+6], "a"
                              jne notfound
                              cmp BYTE PTR [eax+7], "y"
                              jne notfound
                              cmp BYTE PTR [eax+8], 0
                              jne notfound
                            ; -------------------
                              mov eax, 4 ; thursday
                              jmp ExitLabel
                            ; -------------------
                            lbl5:
                              cmp BYTE PTR [eax+1], "u"
                              jne notfound
                              cmp BYTE PTR [eax+2], "e"
                              jne notfound
                              cmp BYTE PTR [eax+3], "s"
                              jne notfound
                              cmp BYTE PTR [eax+4], "d"
                              jne notfound
                              cmp BYTE PTR [eax+5], "a"
                              jne notfound
                              cmp BYTE PTR [eax+6], "y"
                              jne notfound
                              cmp BYTE PTR [eax+7], 0
                              jne notfound
                            ; -------------------
                              mov eax, 2 ; tuesday
                              jmp ExitLabel
                            ; -------------------
                            lbl4:
                              cmp BYTE PTR [eax+0], "w"
                              jne notfound
                              cmp BYTE PTR [eax+1], "e"
                              jne notfound
                              cmp BYTE PTR [eax+2], "d"
                              jne notfound
                              cmp BYTE PTR [eax+3], "n"
                              jne notfound
                              cmp BYTE PTR [eax+4], "e"
                              jne notfound
                              cmp BYTE PTR [eax+5], "s"
                              jne notfound
                              cmp BYTE PTR [eax+6], "d"
                              jne notfound
                              cmp BYTE PTR [eax+7], "a"
                              jne notfound
                              cmp BYTE PTR [eax+8], "y"
                              jne notfound
                              cmp BYTE PTR [eax+9], 0
                              jne notfound
                            ; -------------------
                              mov eax, 3
                              jmp ExitLabel
                            ; -------------------
                          
                            notfound:
                              mov FUNCTION, -1
                              jmp EndLabel
                          
                            ExitLabel:
                              mov FUNCTION, eax
                          
                              END PREFIX
                          
                            EndLabel:
                          
                            END FUNCTION
                          
                          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                          hutch at movsd dot com
                          The MASM Forum

                          www.masm32.com

                          Comment

                          Working...
                          X