Тёмный

What's a Leap Year? Calculating on Commodore 64 

8-Bit Show And Tell
Подписаться 56 тыс.
Просмотров 12 тыс.
50% 1

2024 is a leap year, and February 29th is Leap Day! Can we calculate leap years on a Commodore 64 in BASIC and 6502 Assembly Language? Of course we can. We also learn about why we have leap years, Julian and Gregorian calendars, question if it's Simon's or Simons' BASIC, figure out binary long division, notice some strange coincidences, and see Robin's ancestors in some 1962 movie footage that is barely on-topic. It's fun!
Download the D64 with the source code:
8bitshowandtell.com/downloads...
To support 8-Bit Show And Tell:
Become a patron: / 8bitshowandtell
One-time donation: paypal.me/8BitShowAndTell
2nd channel: / @8-bitshowandtell247
Things mentioned in this video:
codebase64.org/doku.php?id=ba...
www.c64-wiki.com/wiki/Simons%...
github.com/adrianglz64/snappyrom
store.go4retro.com/easyflash-3/
www.tfw8b.com/product/kung-fu...
turbo.style64.org/
Index:
0:00 About leap years
2:50 Julian Calendar leap year calculation in C64 BASIC
7:35 Gregorian Calendar calculation in Simons' BASIC
10:06 Assembly language version - load and run
12:11 Walk-through: main loop
16:45 Checking if leap year (divisible by 4)
18:34 Divide by 100
22:34 Gregorian checks, printing, tabs
27:05 A strange coincidence? Thanks!

Наука

Опубликовано:

 

3 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 159   
@brick6347
@brick6347 5 месяцев назад
The Ukrainian Church only adopted the Gregorian calendar in 2023. I live in Poland, but right on the border with Ukraine (about 5km), and probably a third of our town belongs to the Ukrainian church, not to mention a lot of refugees right now. I'm rather used to them celebrating Christmas on Jan 6, so it came as a bit of shock last year to see the supermarkets, trains etc. at breaking point. The change basically doubled the demand, but the supply chain hadn't managed to keep up. Every shop was like the Toyko metro in rush hour! Hopefully this year it'll work itself out! You'd think "witnessed a change from Julian to Gregorian calendar" wouldn't be something you'd put on your CV in 2024, but there you go.
@timsmith2525
@timsmith2525 5 месяцев назад
Binary division was very difficult for me to understand, but once I got it, it's beautifully simple.
@evileyeball
@evileyeball 5 месяцев назад
Your Great Grandpa was born in 1889, Mine was 1888 and lived to 1988 Edward Dearing 12/9/1888-1/8/1988 99 Years 30 Days
@xcoder1122
@xcoder1122 5 месяцев назад
Here's another fun fact: Why is February shorter than any other month? There are two reasons: 1. the month of July was named after Julius Cesar and was 31 days long. Emperor Augustus also wanted to have his own month, which is why we have the name August, but this month would only have been 30 days long, according to the 31-30 rule. Since Augustus definitely didn't want a shorter month than Caesar, this month also had to have 31 days, which is why both July and August have 31 days, even though they are back-to-back, which messes up the 31-30 rule. So much for that curiosity. But if you add a day to August, you have to take that day away from another month, and that day was taken from February, reducing it from 29 to 28 days. But wait a minute, why did February only have 29 days and why take a day out of the month when it's already the shortest? That brings us to number 2. 2. In the Roman calendar, February was the last month of the year. The new year began on March 1. This was changed by the Christians so that the new year would correspond better with the birth of Jesus, after all, this birth was chosen as the new reference date (before and after Christ, aka BC and AD). As February is the last month of the year, there were simply not enough days left to give it 30 days. If you divide the days according to the 31-30 rule, there are only 29 days left for the last month. And since it was the last month, Augustus had no problem taking another day from the end of the year to make his own month 31 days as well. Oh well... I'm afraid the next question will be: Why the 31-30 rule at all? The answer is: Originally there was no 31-30 rule. There was a 30-29 rule. The reason for this is that the calendar was not based on the sun, but on the moon, and a lunar cycle lasts about 29.5 days. Do you see the problem? So if you set the months at 29 days, you fall behind, and if you set them at 30 days, you get ahead of them, so they had to alternate between 30 and 29 to stay in sync. However, this meant that the year was far too short and the seasons shifted over time, which was pretty bad for agricultural planning. So they had to lengthen the year without introducing too many changes, thus they simply added a day to every single month and ended up with the 31-30 rule. Only now the year was too long, so they had to take away a day, and that day was taken from the last month, so that month was already shorter before Augustus stole another day from it. Naturally when they figured out, that they actually do need an extra day every 4 years, that extra day was re-added to the very last month as well, since it was the shortest, so February was alternating between 29 and 30 days prior to Augustus. In hindsight, the calendar was quite logical and well designed, it was just one Emperor who had to mess it up, followed by Christians who had to mess it up even more, yet those same Christians at least fixed it again later on, when Pope Gregory XIII realized, that years don't have 365.25 but in fact 365.2425 days. Except that this is also wrong because a year has 365.2422 days. But let's not nitpick, the error is only one day in 3,030 years, yet since the earth rotation is not constant, it fluctuates, the average error is only about one day every 7,700 years, which is pretty good, considering the Julian calendar went wrong 1 day every 128 years. The solution to the remaining inaccuracy would be to not have a leap year whenever the year is dividable by 4000. While this would fix the situation right now, the fix has never been adopted for the very simple reason that while the earth rotation around the sun is pretty constant, the earth rotation around itself is not and constantly gets slower, meaning days constantly get longer and this has to be taken into account as well. Currently every 100 years a day gets 2.3 milliseconds longer. That's not a lot but we know that a few billion years ago a day on earth was only 19 hours long. So instead of planing ahead and creating super complicated rules, the current idea is to go with the current rules and should we ever notice that we lost an entire day in the future, we just drop a leap year; the world just agrees that a year, that normally would be a leap year, is not a leap year and the problem is fixed again for another 8000 years or so.
@code_explorations
@code_explorations 5 месяцев назад
Fantastic essay. Thanks!
@evileyeball
@evileyeball 5 месяцев назад
This is why If I get a time machine I want to go to February 30th 1712 in Sweeden February 30 was a day that happened in Sweden, 1712.[4] This occurred because, instead of changing from the Julian calendar to the Gregorian calendar by omitting a block of consecutive days, as had been done in other countries, the Swedish Empire planned to change gradually by omitting all leap days from 1700 to 1740, inclusive. Although the leap day was omitted in February 1700, the Great Northern War began later that year, diverting the attention of the Swedes from their calendar so that they did not omit leap days on the next two occasions; 1704 and 1708 remained leap years.[5]
@jandjrandr
@jandjrandr 5 месяцев назад
All I can say about this is that dates are hard and the more you research them the harder you realize they are. We have done as good a job as possible making the Gregorian calendar work though.
@scottcooper3107
@scottcooper3107 5 месяцев назад
Another way of checking if a year is divisible by 4 evenly, is to do ...IF (Y AND 3)=0 THEN PRINT Y, ...... I found this little trick a few years ago when learning assembly. You can use the AND trick instead of Modulus if you are dividing by numbers that are powers of 2. 2 4 8 16 32 64 and so on. If you were doing MOD(Y,16)=0, and since 16 is a power of 2, you can do (Y AND 15)=0. The 15 comes from subtracting 1 from 16. Thank you for your videos. I always learn something new.
@melkiorwiseman5234
@melkiorwiseman5234 5 месяцев назад
This method won't work when the year number happens to also be evenly divisible by 100, which stops it from being a leap year... unless the year number is also evenly divisible by 400. 😄
@phill6859
@phill6859 5 месяцев назад
​@@melkiorwiseman5234if you store 2 digit years from 80-79 (representing 1980 to 2079) then leap year calculations are easy. Preparing for y2k was fun.
@dans.8198
@dans.8198 5 месяцев назад
⁠@@melkiorwiseman5234This method is the correct/fastest way to discard non-multiples of 4. The 100 and 400 rules are checked later, if this check passes.
@pe1dnn
@pe1dnn 5 месяцев назад
Even faster, as soon as you find the first year divisible by 4 keep adding 4 years instead of one, then you do not have to check it it is divisible by 4. Or start year by int(year/4) and add 1 and multiply by 4 every time you want to show the year. If divisible by 25 it is not a leap year unless it is also divisible by 100. Saves a lot of loops...
@KkkKkk-re9il
@KkkKkk-re9il 5 месяцев назад
​​@@pe1dnn, this speeds up the algorithm by 400% compared to the one in the video. The OP's "and instead of mod" optimization speeds and it up by an additional 200%. 800% in total.
@cheeseparis1
@cheeseparis1 5 месяцев назад
How to learn WAY MORE than "what is a leap year?" in 30 minutes. Thanks so much! Too bad I didn't check your channel in 1984 when I was playing with 6502 assembly language
@markjreed
@markjreed 5 месяцев назад
When coding a leap year function in BASIC, I like to take advantage of the fact that function parameters are dynamically scoped: 10 DEF FNLY(Y)=(FNYM(4)=0) AND ((FNYM(400)=0) OR FNYM(100)) 20 DEF FNYM(N)=Y-N*INT(Y/N) Inside the YM ("Y mod") function, the value of Y is inherited from the calling scope. When the caller is the LY ("leap year?") function, Y is whatever was passed in.
@mikegarland4500
@mikegarland4500 5 месяцев назад
I feel like SO many machine language / assembly programs overlook that very important option to be able to STOP ml program execution at 14:56 -glad to see you implementing that. And I know I've seen you do it other times, too, but it seems to be so rare.
@NickKravitz
@NickKravitz 5 месяцев назад
Gregorian leap year logic led to one of the few deliberate bugs in modern software. Lotus 1-2-3, the most popular spreadsheet software in the 1980s used simplified logic and added a leap day to 1900. The developers of Microsoft Excel recognized this was incorrect but chose backwards compatibility over correctness and added a leap day to 1900 also. It is worth mentioning that the earth's rotation speed is slowing so the leap year logic may need to be readjusted in the future. Leap seconds are added occasionally which always create havoc on computer systems.
@weedmanwestvancouverbc9266
@weedmanwestvancouverbc9266 5 месяцев назад
I remember having a discussion with somebody when I was learning Fortran from Control Data Institute in the early 80s about this
@MichaelDoornbos
@MichaelDoornbos 5 месяцев назад
Any chance you remember what version of 1-2-3 has this? I’d like to try it just for fun.
@codahighland
@codahighland 5 месяцев назад
Leap seconds are deprecated. The last one will be in 2035.
@codahighland
@codahighland 5 месяцев назад
​@@MichaelDoornbosAll of them.
@classicnosh
@classicnosh 4 месяца назад
I'm glad you shared that site detailing how to convert 32-bit hexadecimal to decimal values. I can't remember the title but I lost that book ages ago, it had a lot of really amazing 6502 algorithms and it gave pointers on how to use these routines on Apple II, C64, and Atari 800.
@Skawo
@Skawo 5 месяцев назад
The divisible by 100 rule might seem esoteric to us but on the other hand we're privileged to have lived to experience the 400 rule applying, which is far more unique :v
@martsmiscmix
@martsmiscmix 5 месяцев назад
Apart from enjoying the programming masterclass this video touched me in a couple of unexpected ways. Firstly, I had overlooked the "missing days" in 1582, and as someone born on October 9th (the same birthday as John Lennon, ya know!) I think I may have dodged a bullet there, somehow! The other thing was your mention of your great grandfather. My maternal Grandad (a feisty Welshman who spent some time in Alberta around the time of the Depression) was born in 1899 so missed a leap day early in his life in the Gregorian way. Not long before he passed away in 1977 he was gracious enough to seem to take an interest in my early electronics projects. I remember him sitting in his "special chair" examining my newly built two transistor signal injector/tracer and inquiring what it did!
@jack002tuber
@jack002tuber 4 месяца назад
Great stuff! I love the reference to the read and write of the cursor position. I did some math on finding PI on 3/14, but didn't take on ML. What a great program there. Lots of things to know
@guessundheit6494
@guessundheit6494 5 месяцев назад
The 4-100-400 rule means 250 minus 10 plus 2 or 3, which is 242 or 243 leap years, depending on the millennia. The difference between the orbit and the year (0.2422) is within one day every thousand years. 7:10 - Not according to microshaft's excel.
@DavidYoud
@DavidYoud 5 месяцев назад
@10:10 All your Kung Fu Flash usage encouraged me to recently pick one up at VCF SoCal. @19:03 That divide-by-100 assembly routine is indeed beautiful! Thanks for highlighting that. @25:38 Yup, dyslexic programmers can get totally tripped up here. Cartesian-wise, X axis is left/right, which specifies a column (which runs up/down). Likewise, Y axis is up/down, which specifies a row (which runs left/right). However, with the routine at $FFF0, X specifies the up/down, and Y specifies the left/right, the opposite of what I'd expect (e.g., the starting cursor position at bootup would be returned as X=6, Y=0). Worse, p215 of COMPUTE!'s "Mapping the Commodore 64" gets it backwards, stating "the .Y and .X registers are loaded with the desired row and column positions respectively". (Then again, I'm dyslexic, so I may have flipped something here...)
@8_Bit
@8_Bit 5 месяцев назад
Cool, the Kung Fu Flash is such a handy little cart. And that TFW8b version is just so cute, too, because of the stubby little case. I noticed that mistake in Mapping, it confused me too!!
@timsmith2525
@timsmith2525 5 месяцев назад
I love how methodical you are in your explanations. Thanks for another interesting video!
@keopsequinox1624
@keopsequinox1624 5 месяцев назад
I never had a c64 but I always enjoy your videos and I watch them all ;)
@TheUtuber999
@TheUtuber999 4 месяца назад
That was a fun exercise. Thanks, Robin! I was able to shave a couple Jiffies off execution time by utilizing the division algorithm code from 6502 org - it shifts eight bits in its mathematical loop, which saves a lot of cycles during execution.
@TheUtuber999
@TheUtuber999 4 месяца назад
Here is the section that was changed... printifleapyear ;is year evenly divisible by 4 lda temp and #3 beq mod100 notleap rts mod100 ;divide by 100 lda temp+1 ldx #8 ;8 bits asl temp l1 rol a bcs l2 cmp #100 bcc l3 l2 sbc #100 sec l3 rol temp dex bne l1 ;remainder in accumulator ;is basically mod 100 cmp #0 bne isleap lda temp and #3 ;basically mod 400 bne notleap isleap ;all other cases are a leap ;year, print through basic
@lrander
@lrander 5 месяцев назад
And I thought everyone had leap day on the 24th, like we do here in Denmark. This is because Caesar's solution to the leap years was not to add the 29th, but to extend the 24th to 48 hours - ie. there were two days with the date 24th of February in leap years...
@raythomas4812
@raythomas4812 5 месяцев назад
Great Video . I love seeing the C64 font - so many many fond memories
@cpm1003
@cpm1003 4 месяца назад
That is an excellent assembly routine for division! I am using it on an ATMEGA328P to make a new control panel for my 30 year old treadmill. There were a couple of things that tripped me up though. Firstly, the bpl operation means that the loop actually runs 17 times for a 16 bit division. I originally assumed that it was 16, and this gave me some very strange results. Secondly, the carry flag on an ATMEGA after a subtraction is set opposite from the 6502 family. I believe this is due to it using 2's complement vs. 1's complement on the 6502. I may be kinda weird, but I thoroughly enjoy programming in assembly. 😁
@AbAb-th5qe
@AbAb-th5qe 5 месяцев назад
I already knew this, but commenting for the algorithm's benefit.
@jeffryan7672
@jeffryan7672 5 месяцев назад
Very timely post. I shared your CBM Basic program with my 8Bit afterschool club today. Thank you.
@RudysRetroIntel
@RudysRetroIntel 5 месяцев назад
Yet another great video. Thanks for sharing
@Lemon_Inspector
@Lemon_Inspector 5 месяцев назад
If a number in base N ends with 00, then it's divisible by N². All you need now is to also represent the year in base 20 and you're set!
@Devire666
@Devire666 5 месяцев назад
7:05 Ha, that's a cute and amusing comment. 10:00 Yep, we definitely want more Simon's (or even Simons') Basic.
@JustWasted3HoursHere
@JustWasted3HoursHere 5 месяцев назад
I always thought it was named after a guy named Simon something, but actually Simons was his _last_ name,* so Simons' BASIC is the correct one. * David Simons
@hey_imriver
@hey_imriver 5 месяцев назад
Lovely video as always. Also, it's always cool to see how much faster Assembly is than anything else and that people managed to write whole games with it back in the day
@nrnoble
@nrnoble 5 месяцев назад
Thanks for the full implementation of leap years. Most people generally understand that it is every four years, never knowing there are exceptions as explained in this video. When the video started I was wondering if leap year was going to be simplified to every four years and ignoring the full math required for a correct calculation.
@evileyeball
@evileyeball 5 месяцев назад
My cousin has a daughter who is turing 4 this year or if you count actual birthdays she's had then she's turning 1 as she was born on the leap day. It's really cool.
@jeffstack4217
@jeffstack4217 5 месяцев назад
Absolutely some of your best work here bro! For me, it's when the conspectus is focused on the obscure that produce some of your greatest videos. Going all the way back to the beginning with the 'Spaces' video and also notable the WandaVision episode. I especially enjoyed this episodes subject matter, because, (I'll raise my hand) I never really cared to look into the reason behind Leap Years, it was something I was just content in not caring about. Until I watched this video, LoL. I was grateful for the informative background, the subtle detail to the little BASIC routines you whipped together, (even mentioning the purpose of the comma, lol) and of course, busting out some SIMON'S BASIC of all things and all that a preface to an in depth delve into an ML version! Kudos brother!! Fantastic video! If I may, On behalf of myself and your 54+ THOUSAND other subs, "Thank you for all your efforts!"
@8_Bit
@8_Bit 5 месяцев назад
Thanks Jeff, nice to hear from you!
@infindebula
@infindebula 3 месяца назад
Of course, if your loop counter incremented in steps of 4 instead of 1 (whether in assembly or BASIC), you'd speed things up a lot by having fewer loop iterations and fewer calculations per iteration. The only small caveat is that you'd need a bit more code to find the first leap year in the year range before you start looping.
@user-eh8nx8rz8x
@user-eh8nx8rz8x 5 месяцев назад
Robin, you should do a video on Lemonade Stand. I remember as a kid, the way the program counted money never looked right but would get it correct at the end. A great Canadian program.
@8_Bit
@8_Bit 4 месяца назад
Is Lemonade Stand Canadian? I thought it was one of the Minnesota "MECC" games.
@DarkMoe
@DarkMoe 5 месяцев назад
my 99% experience with assembly code, is writting emulators, so seeing someone coding it natively is always very interesting. Nice job as always !
@acousticpsalms
@acousticpsalms 5 месяцев назад
Hey friend! Thanks for the explanation. We just got back from a birthday party for a leap year baby. He's had 60 years around the sun but just turned 15. I told him it's time he started acting his age. He's the chaplain here at the college. I hope you and the fam are keeping well.
@AureliusR
@AureliusR 5 месяцев назад
Yay leap day! Love your vids so much.
@goranjosic
@goranjosic 5 месяцев назад
I think that the last version of the calendar we use was perfected by a scientist Milan Milanković - and it is currently the most accurate version in current use.
@liquidatedrice5274
@liquidatedrice5274 5 месяцев назад
Got recommended this today, 29th Feb!
@vhm14u2c
@vhm14u2c 5 месяцев назад
On a Linux or Unix prompt enter ‘cal 1752’ and checkout month of September. Can see when it was implemented for computers.
@TheUtuber999
@TheUtuber999 4 месяца назад
That's hilarious. 😆
@scottfromderby
@scottfromderby 5 месяцев назад
Feel privileged to have seen this on leap day. Thanks Robin!!
@MichaelDoornbos
@MichaelDoornbos 5 месяцев назад
SCIENCE! As a kid, it took me forever to figure out how to use "The Visible Solar System" on my C64. Just tried it now, and I still had to look at the manual ;-) 6:28 "If I could derail us further" could easily be a single sentence to describe me. I feel better that I'm not the only one. 10:05 Thumbs up for more Simon's (and Super Expander) 21:50 Great explanation of this code 27:45 Hey, that's neat!
@8_Bit
@8_Bit 5 месяцев назад
Visible Solar System has such cryptic/bizarre controls. I don't understand how so many of those early titles will have messages like "Press F1 to start" but then not give any other on-screen directions, especially for things that are far less obvious than pressing F1. The worst thing about VSS though is that you use cursor down and right as expected, but it does NOT use the shifted equivalent for up or left... instead you need to use the back arrow and exponent keys!! Unbelievable.
@rotordave81
@rotordave81 5 месяцев назад
I was going to comment that my favourite part was when the characters lined up with your illustrative calculation of month days, then you shared your wonderful family memory, and finished with my favourite BLE song. Maybe in 12000AD they'll find a C64 and use it to calculate if it's supposed to be a leap year. Only to give up on waiting for an answer from BASIC and so have to learn assembly. They finally have it ready to run... They type
@weedmanwestvancouverbc9266
@weedmanwestvancouverbc9266 5 месяцев назад
Robin, the the Royal Astronomical Society of Canada publishes an annual guide and has a really detailed explanation on the leap year and leap seconds.
@eekee6034
@eekee6034 5 месяцев назад
Came for the simple coding, stayed for the mindblowing Earth-moon animation at 0:43 :) I want to know how that's done! I mean, I've seen some spectacular things on 8-bits, starting with a first person perspective flight sim on a ZX81, (awesome achievement, terrible result thanks to 1bpp graphics, ;) but I still don't know how they're done. [EDIT: "Simple"? I forgot the 6502 has no division op. That's some interesting code.]
@TheGreatAtario
@TheGreatAtario 5 месяцев назад
The current rules still let us slowly drift off from astronomical observation. I read once that we'd be much closer to true if the rule was to skip a leap year every 128 years instead of the 100/400 thing. This idea pleases me since 128 is also a power of 2.
@rbebut1
@rbebut1 5 месяцев назад
EDUCATIONAL! THANK YOU!
@MartinFarrell1972
@MartinFarrell1972 5 месяцев назад
I tried your code on a C16 (emulator, but was my computer in the 80's), it ran fine. Will try on Commander X16, and color Maximite 2. I have the C64 maxi so I know it will run on that.
@benanderson89
@benanderson89 5 месяцев назад
Instead of doing a divide by four, couldn't you AND the low byte with 0x03 and check for zero instead? I know it's needed for the MOD, technically, but since you're also already doing the divide routine anyway you could divide by 400 after doing the AND check and you're doing less work overall. LDA lobyte AND #$03 BEQ divide400 JMP notleap
@alexanderharringer1323
@alexanderharringer1323 5 месяцев назад
How about using "STEP 4" instead of checking every number for MOD 4? It would make the Programm run more than 4 times faster...
@hugovangalen
@hugovangalen 5 месяцев назад
LOL "and then we'll print out why? because it's a leap year"
@bbartky
@bbartky 5 месяцев назад
Fun video, Robin! Very cool way to show programming in Basic and Assembly. 👍 Also, a bit of trivia here. While the English-speaking world wasn’t as slow as Greece to adopt the Gregorian Calendar, it didn’t adopt it until 1752, which was much later than most of Western Europe. I remember reading a letter from an elderly Thomas Jefferson explaining the change to someone who was much younger
@cbmeeks
@cbmeeks 5 месяцев назад
No surprises that many people don't know this. Especially since we actually have Flat Earthers walking around these days. Great video!
@8_Bit
@8_Bit 5 месяцев назад
Even flat earthers have to account for leap years somehow :)
@cbmeeks
@cbmeeks 5 месяцев назад
@@8_BitYou would think so. But I don't put too much faith in people who believe we live on a coin. LOL!
@rotordave81
@rotordave81 5 месяцев назад
Wow that assembly language version was only slightly more work than the BASIC version. I wonder why it never caught on more widely? I think I finally found peace with myself as a simple C# developer.
@TheStevenWhiting
@TheStevenWhiting 5 месяцев назад
Appears they made a mistake in Auss with the petrol pumps.
@DAVIDGREGORYKERR
@DAVIDGREGORYKERR 5 месяцев назад
if you have the hard book called the computer tutor there is a a 6502 machine code divide routine that you might use.
@beastworm
@beastworm 5 месяцев назад
Watching on 29/02/2024! Love your videos Robin! (and yes, I use DD/MM/YYYY)
@skeleton_craftGaming
@skeleton_craftGaming 5 месяцев назад
DD/MM/YYYY is better than MM/DD/YYYY
@csbruce
@csbruce 5 месяцев назад
@@skeleton_craftGaming: ISO YYYY-MM-DD is better than both since it's unambiguous.
@skeleton_craftGaming
@skeleton_craftGaming 5 месяцев назад
@@csbruce I'm not disagreeing
@davidmcgill1000
@davidmcgill1000 5 месяцев назад
@@csbruce People really need more exposure to that format. It helps a ton with looking at a list of items sorted by date.
@chrisdixon5241
@chrisdixon5241 5 месяцев назад
Great video, nice to see it also done in Assembly! From a pure performance point of view, in this instance wouldn't it be better to compare the low byte first as the stopping condition, since it will only match 1 time in every 100 years, versus the high byte which will match every year for the target century? Seems like a few wasted cpu cycles doing extra compares as we close in on the end year... why yes, now that you ask, I did grow up with 8-bit machines and spend far too much time on optimising my code :)
@olik136
@olik136 5 месяцев назад
so if they had made the rule just "every forth year" instead of divisible by 4 you would have to implement an offset and then basically calculate the same thing?
@JamesJameson
@JamesJameson 5 месяцев назад
US Navy here, we still use Julian dates (at least in the aviation community)
@8_Bit
@8_Bit 5 месяцев назад
I believe those YYDDD "Julian" dates are still Gregorian based; that is January 14, 2024 would be expressed as 24014. If it was based on the actual Julian Calendar, then it would be 13 days earlier, so the same day would be 24001. January 13th, 2024 (Gregorian) would be 23365 (True Julian Calendar Julian Dates) :)
@MichaelDoornbos
@MichaelDoornbos 5 месяцев назад
I’m a Navy veteran. Yes, the US Armed Forces use the Julian date to write the day and year, but still adhere to the Gregorian calendar to calculate leap years.
@MrZoolook
@MrZoolook 5 месяцев назад
To test for mod 4, you could use if (y/4)int(y/4) To use normal basic to test for divisibility by hundreds, you could try: if (y/4)int(y/4) or (y/400)int(y/400) then dummy=1 else print y, The dummy=1 is because since this tests for two negatives rather than a positive, you are just going to skip over the case of 'true'. Its ugly as sin, but it gets around an even uglier mod statement, and the need for expansions.
@gaeshows1938
@gaeshows1938 5 месяцев назад
A year is actually 365.25 days long
@8_Bit
@8_Bit 5 месяцев назад
What kind of year is actually 365.25 days long? A solar year? A calendar year? If so, which calendar? Or is it some other kind of year?
@pe1dnn
@pe1dnn 5 месяцев назад
If you are going to by picky, a day is not actually a 360 degree revolution of the earth. Because the earth travels around the sun in one year we even would have gotten one day when the earth would not rotate at all. A full revolution of the earth takes 23.9344696 hours, but because the earth is also in orbit around the sun it takes 24 hours for the sun to be exactly south again each day. By orbiting around the sun we make one rotation of the earth more than there are days. So a year is about 366.25 earth rotations but about 365.25 days (almost). Fascinating...
@OverUnity7734
@OverUnity7734 5 месяцев назад
If our calendar had 13 months, every month would have 28 days (4 weeks). But would still be off by one day every four years.
@8_Bit
@8_Bit 5 месяцев назад
13 * 28 is only 364 days, so it seems one month would need 29 days?
@OverUnity7734
@OverUnity7734 5 месяцев назад
@@8_Bit Oh, no, something is wrong with my calculator!
@8_Bit
@8_Bit 5 месяцев назад
@@OverUnity7734 Should have used a Commodore 64! :)
@stuartmcconnachie
@stuartmcconnachie 5 месяцев назад
Your loop end check is slightly flawed because it doesn’t perform carry between low and high bytes. Granted in this case I don’t think it matters because of the end value chosen, and because you’re always incrementing by one. ;) To correctly compare multibyte unsigned integers for year
@8_Bit
@8_Bit 5 месяцев назад
What end value would cause it to fail? I see how it could fail if it was being incremented by more than 1.
@breakbumper
@breakbumper 5 месяцев назад
I am the expert on correct apostrophe usage. You will use the apostrophe correctly if you know whats good for you.
@evileyeball
@evileyeball 5 месяцев назад
At the end you went past 999.M41
@automateTec
@automateTec 5 месяцев назад
Can the for-next loop skip odd years?
@8_Bit
@8_Bit 5 месяцев назад
Yes, it could even skip by 4 at a time and thus completely eliminate the check for evenly divisible by 4. But it was a (probably unstated in the video) goal of mine to have it take the year as an input, and then decide if it was or wasn't a leap year based on that number. Due to the repeating 400 year cycle of leap years, I'm sure it would even be fairly easy to create a loop that would generate a list of leap years without any division or branching at all but that seems like a challenge for 4 years from now :)
@leomiliades7341
@leomiliades7341 3 месяца назад
Hi Robin, many thanks for your videos - I enjoy watching you!!! I have a bread bin Commodore 64 connected via a "composite to HDMI" adapter to my Smart TV. The image is not that great due to resolution differences but I can read the characters and play games fine. However, I see the screens you show are crystal clear. How can I get such clarity in mine? Will a device such as RetroTINK-2X make my screen like yours? Can you give me some direction? I'd be interested to know what you use. Many thanks!! Leo M., Chicago
@8_Bit
@8_Bit 3 месяца назад
Hi Leo, I use a ClonerAlliance Box Pro which converts from composite (or VGA) to HDMI, and also allows me to record to a USB memory stick at the same time. I'm happy with it, but it's also pretty expensive. It was actually cheaper when I bought it 4-5 years ago; seems unusual for tech to go up in price. RetroTink-2X is probably a good option but I've never used it myself. Adrian's Digital Basement seems to have good success with his, not sure what model it is though.
@Okurka.
@Okurka. 5 месяцев назад
I get paid per month; I hate leap years.
@G.B...
@G.B... 5 месяцев назад
Simon's/Simons' Basic is way better than the built-in C64 Basic, and definitely deserves a few videos. In fact, C64 Basic sucks big time and should never be used - but I understand you can't ditch it in this channel. Let's be honest though, real men do it in Assembly (even if execution time in Basic is not as issue). Assembly it is, not because it is always necessary (in this case it isn't) but because we can. 😆
@DotArve
@DotArve 5 месяцев назад
Dunno if this would simplify your assembly code; but, you: If a number is divisible by 25, then the year is a leap year only if divisible by 16. All other numbers follow divisibility by 4. This, slightly ugly JS one-liner prints all leap years below 3000: i=0;while(i
@AureliusR
@AureliusR 5 месяцев назад
Hey Robin, at 15:40 or so, why did you use bne instead of bcs? Isn't it a bit clearer to branch on carry to show that that's what the branch is really doing? EDIT: Also it's so cool seeing my name in the credits :D
@8_Bit
@8_Bit 5 месяцев назад
I couldn't use bcs because INC doesn't affect carry at all, it only affects N and Z. If INC did affect carry, it would be set or cleared exactly the same as Z anyway so the designers probably thought it's best to preserve carry. I think that's especially true for INX/INY use.
@AureliusR
@AureliusR 5 месяцев назад
@@8_Bit Wait, so even if INC/INX/INY overflows from FF to 00 it doesn't set carry?
@8_Bit
@8_Bit 5 месяцев назад
@@AureliusR Correct. Carry is unaffected by any of the increment and decrement opcodes.
@freemesy
@freemesy 5 месяцев назад
Is it not possible to use NEXT 4 in for loop in basic to get rid of checking the modulus of divide by 4? But this is only works if the start year can be divided by4 without modulus. Maybe worth a check to use this kind of loop. Or not. :)
@8_Bit
@8_Bit 5 месяцев назад
Yes, that would be another way to approach it. I wanted to actually show how to determine if a given year was or wasn't a leap year as it was probably more instructive/useful this way. But it could be interesting to try to make a leap year list generator without any modulus or branching at all, including for the 100 and 400 rules.
@freemesy
@freemesy 5 месяцев назад
What if we check the number could be divided by 4 without modulus in assembly with OR%11111100. If it gives back %11111100 then this number could be divided by4 without mod, becuase the last 2 bits is zero.
@hivebrain
@hivebrain 5 месяцев назад
Leap years are skipped every 4000 years too.
@MrGN-yy6op
@MrGN-yy6op 4 месяца назад
orthodox church uses Julian calendar btw
@soulcorazon
@soulcorazon 3 месяца назад
🤓🤓🤓🤓🤓🤓🤓
@MrGN-yy6op
@MrGN-yy6op 3 месяца назад
@@soulcorazon why the nerd emojis? I'm just giving some info
@terosaarela4555
@terosaarela4555 5 месяцев назад
The leap years seem also to be olympic years.
@pe1dnn
@pe1dnn 5 месяцев назад
There were Olympic games in 1900 in Paris... en.wikipedia.org/wiki/1900_Summer_Olympics
@terosaarela4555
@terosaarela4555 5 месяцев назад
Yes, hence leap years are olympic years but not vice versa.
@AppliedCryogenics
@AppliedCryogenics 5 месяцев назад
Kind of irresponsible to deliberately include the Y64k bug in your code, don't you think? Sure, this might only be demo code, but how can you be sure management won't put it into a mission critical system before the year 65536?
@Lion_McLionhead
@Lion_McLionhead 5 месяцев назад
All hail our roman rulers.
@DAVIDGREGORYKERR
@DAVIDGREGORYKERR 5 месяцев назад
START: LDA #$00 STA QUOT STA RMNDR LDX #$08 LDA DVDHI SEC SBC DIVSR LOOP0:PHP ROL QUOT ASL DVDLO ROL A PLP BCC CONT1 SBC DIVSR JMP CONT2 CONT1:ADC DIVSR CONT2:DEX BNE LOOP0 BCS EXIT ADC DIVSR CLC EXIT: ROL QUOT STA RMNDR RTS DIVSR: DB $F9 DVDLO: DB $E8 DVDHI: DB $FD QUOT: DB $00 RMNDR:DB $00 Sorry for shouting but some machines don't have lower case.
@jack002tuber
@jack002tuber 4 месяца назад
Question about Simons' Basic cart. I have one, none of the string functions works right. INSERT, INST, PLACE, none works right. What's up with that?
@8_Bit
@8_Bit 4 месяца назад
Can you give an example I can try out? Strangely, these add-on string functions don't have a $ at the end of them even though the C= original ones do.
@jack002tuber
@jack002tuber 4 месяца назад
@@8_Bit The worst one is this: print place("x","yyyy") keeps returning 1 and it should be 0
@8_Bit
@8_Bit 4 месяца назад
@@jack002tuber Yeah, that's pretty bad. At a quick glance, it looks like the code is expecting the parameters to be string variables, and not string constants. It also seems to work better in program mode; string constants in immediate mode are actually handled weirdly by Commodore BASIC so maybe it's just that edge case that's actually buggy in Simons' BASIC.
@jack002tuber
@jack002tuber 4 месяца назад
@@8_BitI did place("A","1234") and it returns 4, change A to B or anything, always 4
@jack002tuber
@jack002tuber 4 месяца назад
Ah. in a program it does work right. SIGH.
@cjhickspe1399
@cjhickspe1399 5 месяцев назад
They did an amazing job of calculating this back in the day but we should have re-defined the second rather than dork around with extra days and missing leap years.
@CommodoreGreg
@CommodoreGreg 5 месяцев назад
If you did that then the days eventually wouldn't match the sun position. Morning would gradually move to ridiculous times like 2PM.
@cjhickspe1399
@cjhickspe1399 5 месяцев назад
​@@CommodoreGreg I am saying align the base time increment (in this case the second) with the planet's speed. You can still have 365 days and 24 hours and so on but the definition of the second is off which is we have leap days, to correct for it.
@berndeckenfels
@berndeckenfels 5 месяцев назад
@@cjhickspe1399no, seconds are not the cause since years depends on days and they are just not aligned. But there is also an (irregular) second, that one also can’t be fixed by redefining second length (because irregular)
@csbruce
@csbruce 5 месяцев назад
From your thumbnail, I see you've got the 100- and 400-year rules in place. They'll have to add a new rule in a few thousand years, since there are 365.242189 ephemeris days in a tropical Earth-orbit year, but 365.2425 days in a Gregorian-calendar year, an error of one day too many every 3215 years. Maybe they'll add 1000- and 4000-year exceptions to leap days. BTW, what's the deal with calling them "leap days" when you're not leaping over anything; you're going *through* an extra thing. *NON*-leap years should be called "Leap Years"! (Cue "Seinfeld" music.) 3:30 You could also do «Y=INT(Y/4)*4», or «Y/4=INT(Y/4)», or, in this case, «(Y AND 3)=0». 4:12 What percentage of the people you polled had even *heard* of the "Gregorian" Calendar? 5:21 Monthly renters were annoyed about paying for 10 days that never happened! 6:20 "In our lifetimes"… I guess you're right, since the oldest person currently alive is slightly under 117. 7:44 Good call - multiple Simons are better than one! 9:00 In general, you need to be careful about the precedence of your ANDs and ORs. 16:06 I /guess/ this works. The method I've seen for 16-bit comparisons is «LDA year+0 : CMP #end : BCC loop». The first CMP acts as an SEC:SBC, so it's a 16-bit subtraction. Your method might not work if the increment is anything greater than 1 (e.g., start=0, increment=257, limit=100). 16:51 Divisibility by 4 is trivial here, too: «LDA year+0 : AND #$03 : BEQ yep». 17:12 Yeah, so they gave us Carry and non-Carry versions of the shifting operations, but not for Add and Subtract! 19:26 Huh? Dividing by 10 for binary→decimal conversion is needlessly slow. Just use the binary-shift/BCD-add method popularized by Jim Butterfield. 19:51 I take it that kids don't learn long-division anymore. The sad thing is, this is still how even the most modern CPUs implement it, since there's no general method that's faster. The trouble is that it contains conditional branching, which means you have to run it in multiple steps, which is slow. It's faster to substitute a multiplication if you can, since multiplication is unconditional, so hardware makers can take the long-multiplication from Elementary School and expand it out into a bit-shifted array of adder cells (or equivalent) and execute the multiplication in one clock cycle. Here, year / 100 = year * 0.01. For integer operations, you just take a fine enough approximation of a binary fraction of 0.01 and run it with an implied decimal (binary) point. 25:01 Instead of a tab index, you could just track the column value to use with Kernal PLOT, and set it back to 0 with a CR when you go past 30. 30:08 They'll definitely need to change the leap rules by the year 12000.
@mikegarland4500
@mikegarland4500 5 месяцев назад
as a kid I remember asking that very question, since nothing seemed to offset by the exact amount.. it was always a little above or below, so that eventually it would just get off again.
@davidmcgill1000
@davidmcgill1000 5 месяцев назад
I'd hope by that point a new better calendar would have been created. Eventually it's all gonna be very useless once humanity starts leaving Earth to settle elsewhere.
@8_Bit
@8_Bit 5 месяцев назад
That would be really cool if there were 1000 and 4000 year rules added too. Does the math work out pretty close? I suppose there's still some leeway there with which ones are or are not leap years. I wish there was a reason to have a recurring but ultra-rare Feb. 30th.
@csbruce
@csbruce 5 месяцев назад
@: Oh, I guess 1000 isn't divisible by 400. They could just do ÷100 = No, ÷400 = Yes, ÷3200 = No. They'll have to add something else in the year 681600.
@bbartky
@bbartky 5 месяцев назад
@@8_BitYea, I’ve read that the calendar will be off a day in the year 4000 CE. 😂 Also, the talk of traveling to the stars in science fiction got me thinking. It’s a common trope in SF to use our calendar in other solar systems as a way of standardization (e.g, Foundation, Dune, and many others). And speaking of Dune, I saw _Dune: Part 2_ on Sunday and I think it’s one of the best SF movies ever made. Thank you, 🇨🇦, for giving us director Denis Villeneuve! 😊
@tonym2464
@tonym2464 5 месяцев назад
As an Irishman trying to guess your great grandfather's nationality from the accent you used, I'm going to say, Mexican?
@8_Bit
@8_Bit 5 месяцев назад
Close: he was Canadian.
@donwald3436
@donwald3436 5 месяцев назад
I want SIMONS BASIC not SIMONS BASIC.
@defacube
@defacube 5 месяцев назад
Who's watching this on Feb 29th (sorry I must do this) 👇
@melkiorwiseman5234
@melkiorwiseman5234 5 месяцев назад
Calculating a leap year isn't as simple as just every fourth year you have a leap year. The calculation needs to be more complicated because even adding one day every four years still allows "slippage" so that the movement of the Earth around the Sun gets out of synch with the years. Here's how to do it, really: First, divide the year number by 4. If it does not divide evenly, it's not a leap year, otherwise it might be a leap year and you go to the next step. Second, divide the year number by 100. If it does not divide evenly then it's a leap year, otherwise it might not be a leap year and you go to the next step. Finally, you divide the year number by 400. If it does not divide evenly then it's not a leap year, otherwise it is a leap year. It's a complicated procedure but it was calculated to keep the years and the Earth's days lined up accurately for at least a few thousand more years before any great adjustment will be needed.
@Okurka.
@Okurka. 5 месяцев назад
Did you even watch the video?
@melkiorwiseman5234
@melkiorwiseman5234 5 месяцев назад
@@Okurka. I included the information just in case someone didn't want to watch the whole video. Besides, the way I worded it is slightly different from how it was worded in the video, and I've discovered that sometimes, re-wording something can help a person understand it when they didn't understand the first explanation.
@Okurka.
@Okurka. 5 месяцев назад
@@melkiorwiseman5234 TL;DR
@skeleton_craftGaming
@skeleton_craftGaming 5 месяцев назад
I'm a leap year
Далее
This Function Destroys Programs: MS-BASIC's VAL()
24:34
Fixing a Bug in Rodnay Zaks' "Programming the 6502"
43:38
The 6502 Rotate Right Myth
9:16
Просмотров 49 тыс.
Leap Years: we can do better
12:16
Просмотров 962 тыс.
Coding Challenge: 3D on Apple II
45:40
Просмотров 324 тыс.
Новые iPhone 16 и 16 Pro Max
0:42
Просмотров 2,3 млн
iPhone socket cleaning #Fixit
0:30
Просмотров 18 млн