Тёмный

43-Year-Old INPUT Bug Fixed: From C64 to VIC-20 

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

The Commodore VIC-20 and earlier versions of the Commodore 64 have a bug in their BASIC INPUT statement. If the programmer-specified prompt is longer than a screen line, then the prompt gets stored along with the user's response in the variable. In the case of a numeric variable, this causes an endless ?REDO FROM START error loop. After demonstrating the bug and that it was fixed in C64 KERNAL V3, and how to quickly identify what KERNAL version your C64 has, we'll get to the cause of the bug in KERNAL V2 and the way it was fixed in KERNAL V3, and see if we can't backport this fix to the VIC-20 in the form of a patch. Finally, our very own Mr. Doornbos demonstrates the patched VIC-20 KERNAL on real hardware using a ROM Emulator.
Links mentioned:
Mr. Doornbos' blog: imapenguin.com/
My previous KERNAL revisions video: • All the Commodore 64 K...
To support 8-Bit Show And Tell:
Become a patron: / 8bitshowandtell
One-time donation: paypal.me/8BitShowAndTell
2nd channel: / @8-bitshowandtell247
More info about the ROM Emulator:
mygeekyhobby.com/2020/07/05/e...
github.com/Kris-Sekula/EPROM-...
VIC-20 KERNAL ROM patch:
The patch should be applied to VIC-20 KERNAL ROM binary file kernal.901486-06.bin (NTSC) or kernal.901486-07.bin (PAL).
30 bytes at offset $597 of file: 20 7e ea a9 15 e8 b4 d9 30 06 18 69 16 e8 10 f6 85 d5 4c b2 ea e4 c9 f0 03 4c 19 e7 60 ea
2 bytes at offset $63D: ac e5
Index:
0:00 INPUT example
1:40 Demonstrating the bug on VIC
3:54 Demonstrating the bug on C64, fixed on KERNAL V3
5:55 How to identify your C64 KERNAL version
9:21 KERNAL V2 Bug Walkthrough
14:26 KERNAL V2 Bug Explanation
20:08 KERNAL V3 Bug Fix
26:40 Backport the C64 V3 Fix to the VIC-20?
28:55 The VIC-20 Patch
31:25 Testing the patch: Mr. Doornbos: imapenguin.com
34:40 Thanks to my patrons

Наука

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

 

3 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 96   
@markjreed
@markjreed 6 месяцев назад
The C128 allows logical lines up to 160 characters, so it's back to having up to 4 lines linked together like the VIC-20 (at least on the 40-column display).. making that loop a little less redundant there.
@pasixty6510
@pasixty6510 26 дней назад
At some time then, programming our VC20s, we found out to make the input prompt not too long, to avoid weird behaviour. But we were so much believing in the machine, we never dared to suspect it to be a bug. Nice to watch your revelations after so many years. Thank you!
@00Skyfox
@00Skyfox 6 месяцев назад
I really appreciate how in depth you go with the C64 and VIC20 code and explain everything so thoroughly down to the machine language level.👍
@theuglycamel8122
@theuglycamel8122 6 месяцев назад
Fantastic video as usual. Your channel is always my first recommendation to every new Commodore owner I meet online. I've started my own playlist of Basic/Assembly youtubers as a sudo-101 class. Your videos make up about 80 percent of that playlist! Keep on keepin on man!
@8_Bit
@8_Bit 6 месяцев назад
Thank you :)
@MichaelDoornbos
@MichaelDoornbos 6 месяцев назад
That’s some high quality plywood you have in the basement there Sir…. Just want to say that I appreciate all of the hard work that you do to dive deep like this.
@noland65
@noland65 6 месяцев назад
This bug seems to have been introduced with the VIC-20 by that loop tying up to 4 physical lines. On the 40-column PETs, which combine up to 2 physical rows into a logical line, just like the C64, neither of the various ROM version has this. (Tested with the (patched) ROM 1 for the PET 2001, ROM 2 (AKA 3) and ROM 4, both for the graphical and the business keyboard.)
@8_Bit
@8_Bit 6 месяцев назад
Thanks for looking into it.
@FadkinsDiet
@FadkinsDiet 6 месяцев назад
The PET does have a different bug: at an INPUT if you enter nothing after the ? And hit return, instead of storing an empty string or a ?REDO FROM START the program exits with a syntax error.
@noland65
@noland65 6 месяцев назад
@@FadkinsDiet I always thought this to be an admitteldy weird feature, but given that you get the "?REDO FROM START" prompt on any other type error, this may well be a legitimate bug.
@andyc8257
@andyc8257 6 месяцев назад
Coming from Sinclair and Amstrad machines, it's kind of bonkers to think INPUT actually reads values out of screen RAM rather than just buffering what is typed in. I guess because those machines have bitmapped displays (and thus reading characters back is more heavyweight) they did the more logically sensible thing.
@dktr2
@dktr2 6 месяцев назад
As a kid, I used to write all sorts of nonsense in BASIC, and I came across this error. I couldn't understand what was going on, so I abandoned some idea because of it ;)
@stevejennings3960
@stevejennings3960 6 месяцев назад
6:07 love the creaky c64 cartridge sound
@merman1974
@merman1974 6 месяцев назад
Another interesting video, I was always intrigued by how BASIC and the Kernal interacted. When I started learning machine code, I would often use Kernal routines.
@jandjrandr
@jandjrandr 6 месяцев назад
Definitely great insight into the deep internals of the C64/VIC20 and all their quirkiness. That bug is truly an odd miss, but interesting that it actually was fixed in later revisions.
@martsmiscmix
@martsmiscmix 6 месяцев назад
My, what an epic episode! This made my brain hurt quite a lot (in a good way, of course!) By a very strange coincidence, the "EPROM Emulator" project came up in a local newsgroup discussion only very recently, and here is a perfect example of of it being used in the manner for which it was designed! That put the "icing on the cake" for me 😀
@BobCat0
@BobCat0 6 месяцев назад
I'd been watching your videos for a while, and then I saw Jeri mention you during a VCF talk! Little did I know I had a picture of you drinking beer on my C64DTV :)
@8_Bit
@8_Bit 6 месяцев назад
It's actually our friend and colleague Adrian Gonzalez drinking beer with Jim Butterfield in that particular picture. But there is another picture of Jeri, Adrian, and me also hidden in the C64DTV :)
@markjreed
@markjreed 6 месяцев назад
Patched my copy of the ROM file used by VICE and the fix is working great. Thanks!
@csbruce
@csbruce 6 месяцев назад
2:47 The input also includes the prompt if you move the cursor off the line and then back. 14:43 They could have used a 3-byte bitmap instead of sacrificing 26 bytes of valuable zero-page space. (217‒242 is 26 bytes.) The screen-line high-byte offsets could also have been a ROM table. I still run into logical/physical line problems with Vim on Linux with mouse copy & paste in X-Term.
@csbruce
@csbruce 6 месяцев назад
They could also cut the size of the ROM line-address tables in half by LSR-ing the given line number, looking up line ÷ 2, and ADC-ing #40 to the result if AND #$01 is non-zero. Takes a little more code space and execution time, but there'd be a net saving of ROM space. Or, they could replace the ROM table with ASL:ASL:ADC originalLineNum:ASL:ASL:ASL = line × 40.
@matthewrease2376
@matthewrease2376 6 месяцев назад
The Commodore OS basically being a living text editor is insane. Like if I were using Notepad, but pressing enter on a line sent it to command prompt...
@8_Bit
@8_Bit 6 месяцев назад
Insane, but also fun. By the way, pressing shift+return allows a new line without any processing happening. It's handy.
@argoneum
@argoneum 6 месяцев назад
Some say that Emacs is OS 😸
@markjreed
@markjreed 6 месяцев назад
@@argoneumwith lisp as its shell, and having a large number of powerful features, lacking only a decent text editor...
@FadkinsDiet
@FadkinsDiet 6 месяцев назад
Many modern languages have something similar to this. It's called a REPL, which stands for read eval pront loop. Some even let you save the whole session as a "notebook". Very common in AI development and big data analysis.
@matthewrease2376
@matthewrease2376 6 месяцев назад
@@8_Bit I've always loved editors that let you add lines without doing anything via that method. Neat that it's been around so long, I thought it was a more modern concept.
@DavidYoud
@DavidYoud 6 месяцев назад
So basically you used frog DNA to fill in the dinosaur gene sequence gaps?
@MichaelDoornbos
@MichaelDoornbos 6 месяцев назад
This is the funniest thing I've read all day
@alandickey4480
@alandickey4480 6 месяцев назад
so preoccupied with whether or not they could, they didn't stop to think if they should. Life, uh, finds a way
@pepstein
@pepstein 6 месяцев назад
😂 this is gold!
@TheHighlander71
@TheHighlander71 6 месяцев назад
My hat is off to you sir Robin. Well done. Thanks for the all the work.
@quantisedspace7047
@quantisedspace7047 6 месяцев назад
It is because it is reading from the screen memory. You can see this if you tab past a Ready prompt: it will interpret it as 'READ Y' and report 'Out of Data'
@jack002tuber
@jack002tuber 6 месяцев назад
The BASIC ROM in a Commodore 64 is not custom made for it, they took the VIC20 ROM and just made it work, that's why the ROMs look so similar. The BASIC in there is wonderful for 1982 and kinda kludgy for 2024. So many constraints they had then.
@silkwesir1444
@silkwesir1444 6 месяцев назад
It was not wonderful for 1982 actually. It's a total mess. Doesn't hold a candle against the two versions of BASIC from the Apple II computers, and those came out several years before. Example: Think by using Integer arithmetic you can speed up your program? Think again! On C64 BASIC, it's even slower than just using the default floating point. How can that be, you ask? Well, because it doesn't do Integer arithmetic at all. It converts to float, then calculates, then converts back. This is really inexcusable, ESPECIALLY for the time, when computer resources were so limited that such techniques (using the much faster integer arithmetic for scenarios where it will suffice) actually would have made a noticable difference.
@jordanhazen7761
@jordanhazen7761 6 месяцев назад
@@silkwesir1444 Robin made another recent video about the missing native-integer math routines. I guess constraints on ROM space were the main reason those were left out. Did any subsequent Commodore BASICs ever fix this, maybe on the Plus/4 or 128?
@paulkoopmans4620
@paulkoopmans4620 6 месяцев назад
Absolutely amazing!
@barcoboy2
@barcoboy2 6 месяцев назад
Now you need to find a byte in the VIC20 KERNEL that could indicate the version number, and change it in your fixed version to 82 or $52, which is ASCII "R" for Robin!
@furrball
@furrball 6 месяцев назад
I'd have left the RTS in place for a potential use case by old code, you never know something jumped there on condition, to execute a RTS on condition. I mean, noneed for a NOP: an RTS after another RTS is unreachable, from above.
@terryraymond7984
@terryraymond7984 6 месяцев назад
awesome video robin
@SteveCirelli
@SteveCirelli 6 месяцев назад
I don't know why but I like the look of the bread bin the best.
@sandcat-maurice
@sandcat-maurice 6 месяцев назад
Great video, I learned quite a lot. Was checking the Kernal version on my MEGA65, and it shows version 3. I think that is as expected. Interesting video!
@8_Bit
@8_Bit 6 месяцев назад
Yes, version 3 is the final official KERNAL and as far as I know all the various remakes and modern updates of the C64 have used V3 as far as I'm aware.
@raythomas4812
@raythomas4812 6 месяцев назад
Great video. Sorry, but I have to say how lovely the keyboard sounds....remember it well
@rayf2145
@rayf2145 6 месяцев назад
I love how the C64c crackles and screeches when you insert the cartrdige. The breadbin doesn´t! While on a modern car these sounds would make me give it back to the dealer, on the old Commodore I find it very soothing and appropriate. So why is that not on the breadbin? Is the C64C one without case screws, but latches?!
@8_Bit
@8_Bit 6 месяцев назад
The breadbin does seem a little more sturdy. I might also have sprayed the breadbin cartridge port with "Canadian Deoxit" more recently, which has a bit of a lubricating effect. This 64C isn't one of those ultra-cheap no screw ones.
@muffenme
@muffenme 6 месяцев назад
I seen this error with the following: 10 print"choose a very very very large number "; 20 input a
@8_Bit
@8_Bit 6 месяцев назад
Aha, nice find! That makes sense that even a plain INPUT (without prompt) will cause the bug if the single-character ? prompt wraps around the screen. So if exactly 39 characters are printed first then it will trigger it seems. But this is also less of a problem because the ?REDO error will only happen once; when the ? is printed the next time it will be at the beginning of a new logical line and not trigger the bug.
@polluks2
@polluks2 6 месяцев назад
Well done!
@3vi1J
@3vi1J 6 месяцев назад
Wow, that's several things I never knew. In addition to the input bug, you showed that the early 64 kernels didn't already have the sparkle fix, and that later ones semi-undid it. Maybe later on they had less noise?
@dermito
@dermito 6 месяцев назад
Thanks, Robin! I very much enjoy your videos and thougjt I'd try a "Super Thanks" for the first time ever 😊.
@8_Bit
@8_Bit 6 месяцев назад
Thank you very much!
@TheGkrsoft
@TheGkrsoft 6 месяцев назад
Fantastic
@vanhetgoor
@vanhetgoor 6 месяцев назад
Well done, finding a very very stupid mistake that Commodore made in the past. I say very stupid because an input has to look at the keyboard-buffer not at logical lines. By the way, this version of BASIC, was that a BASIC that was around somewhere and adapted by Tramiel and partners or was this BASIC laying around somewhere and adapted by the Lord Voldemort of Redmond, Washington?
@tYNS
@tYNS 6 месяцев назад
Nice Fix!
@AureliusR
@AureliusR 6 месяцев назад
Yay! New 8BSAT!!! You rock Robin.
@AureliusR
@AureliusR 6 месяцев назад
Also, first time seeing my name in the credits! :D So freakin' cool. I love the VIC-20 but my brand-new C64 has had my attention since I got it a few days ago from a TPUG member for a very fair price. It's so cool seeing my program that I've been developing in VICE running on real hardware. It's funny that I never came across this bug: I just went back to a program I wrote ages ago in BASIC on the VIC, and it's actually 1 character short of filling the line width, so it worked and I never had any issues. Funny how one more character would have totally broken that program and confused the heck out of me.
@elfenmagix8173
@elfenmagix8173 6 месяцев назад
An excellent video. I wonder if this same error is on the PETs and C128; though perhaps not on the Plus4/C16...
@8_Bit
@8_Bit 6 месяцев назад
It seems the bug only started when the PET code was ported to the VIC-20, and then it was fixed on the later C64s before the C128 and maybe even before the Plus/4... but actually I haven't checked the Plus/4.
@8_Bit
@8_Bit 6 месяцев назад
I tried the Plus/4 just now, and there's no error. C16 should be exactly the same.
@katho8472
@katho8472 6 месяцев назад
That blue VIC20 mainboard is then a modern replacement? o.O Haven't seen a VIC20 variant of those, just the C64 thingies...
@8-bit-dust
@8-bit-dust 6 месяцев назад
Interesting and totally enjoyable, thank you Robin. On the topic of Kernel bugs and incompatibilities here is another (unsolved one): Power cartridge ( popular cart. In Europe) has a monitor that allows you to Walk through assembly code with W command. This works on a breadbin but does not on 64C (it does not execute next op code). It can be reproduced in emulator and real machines. Maybe kernal differences or perhaph there is some hardware incompatibility? Has been bugging me for a long time to know why and how they actually implemented the Walk command. Perhaps could be interesting topic?
@8_Bit
@8_Bit 6 месяцев назад
That is interesting! Since it can be reproduced in an emulator there's a good chance someone could figure out the cause. I'll put it on my list of things and hopefully I can find time to investigate. Thanks.
@larswadefalk6423
@larswadefalk6423 6 месяцев назад
Nicely worked Robin! You have to admit you tested the bug in an emulator with a patched rom file, before sending it? 🙂Did you not?
@8_Bit
@8_Bit 6 месяцев назад
Yes I did test with an emulator. In case anyone thinks otherwise, I'm not against emulators at all. They're a very useful tool. I just (generally) don't like making videos with emulators and especially modern computer desktops as the focus.
@larswadefalk6423
@larswadefalk6423 6 месяцев назад
@@8_Bit Yes, I agree completely. I was just messing with you 😜, because I know if I do have a way to test something before giving it away, I'd rather do that rather than being too self assure and failing. But yeah, emulators are useful. Tip: Turbo Rascal SE, looks like a pascal like language being way more efficient and optimized than anything else I've seen for the c64 and a bunch other 8 bits. Maybe you can do a video about it Robin.
@awilliams1701
@awilliams1701 6 месяцев назад
odd I always thought that input couldn't output anything other than a the question prompt. You had to use print to output a more proper prompt.
@FadkinsDiet
@FadkinsDiet 6 месяцев назад
I used print then input because I knew input with a prompt was flaky
@endymallorn
@endymallorn 6 месяцев назад
I don’t know if this really counts as a bug in my eyes, as it only occurs due to unexpected user behavior. It seems more like the real fix should have been making it impossible to modify the data in memory, and instead forcing it to be a new load each time a modification was desired. Annoying if you’re prone to typos, yes, but safer for the machine.
@megatech1966
@megatech1966 6 месяцев назад
Interesting. So neither of my C64c and C128 would have this bug.
@weedmanwestvancouverbc9266
@weedmanwestvancouverbc9266 6 месяцев назад
How is it that the older kernel and the newer ones still result in the same amount of bytes free?
@8_Bit
@8_Bit 6 месяцев назад
The same RAM range is still available for BASIC's use in all 3 revisions: 38K from $0800 - $9FFF.
@michaelm.7617
@michaelm.7617 6 месяцев назад
So The C64 has not the old kernal, because when you don't poke the colour in, the A apears?
@8_Bit
@8_Bit 6 месяцев назад
Yes, on TheC64 the "A" should appear in light blue after POKE 1024,1 and PRINT PEEK(65408) should display 3.
@be236
@be236 4 месяца назад
I assume this bug is fixed in Commodore 128 and Plus/4?
@Caffin8tor
@Caffin8tor 5 месяцев назад
I donated my Super Snapshot cart to LGR's channel, but I don't think Clint ever used it.
@8_Bit
@8_Bit 5 месяцев назад
It's a great cart! I only remember a couple LGR videos where he has covered the C64 so I guess he doesn't play around with it much.
@Caffin8tor
@Caffin8tor 5 месяцев назад
@8_Bit True. It would have been better to send to you or 8 bit guy but I think I didn't know about either channel at that time. I had also sent a cart with a SID that enables dual SIDs and Mountain King. Oh well, it just be like that sometimes.
@8_Bit
@8_Bit 5 месяцев назад
@@Caffin8tor Cool. I've got a few Snapshots already, though it's always interesting to find out what version each cartridge is as some ROMs probably haven't been archived. V5.22 is the final official ROM, but I've seen 5.20, 5.1 and I think one other. I still don't have a dual SID cart somehow after all these years. I should look around, someone has probably done a reproduction cartridge of one by now.
@AxelWerner
@AxelWerner 6 месяцев назад
debugging/analyzing 6502/6510 assembler is no fun without lables :(
@GreenAppelPie
@GreenAppelPie 6 месяцев назад
There’s nothing confusing about it. I can understand assuming staying on one line on a keyboard input at the time
@Mrshoujo
@Mrshoujo 6 месяцев назад
Atari BASIC & compatible dialects don't have this problem. It's also nice the Atari OS doesn't affect BASIC. It's really odd for the Commodore system OS aka 'kernel' would affect this behavior when it sounds like fixing some bytes in the BASIC ROM would suffice.
@8_Bit
@8_Bit 6 месяцев назад
The bug probably could have been fixed in either the KERNAL or BASIC ROM, but since they were already making other changes to the KERNAL, it's sensible to fix them there. They managed to leave the BASIC ROM unchanged throughout the entire run of the C64. Since Atari didn't include BASIC in the computer ROM and instead put it on a cartridge, it'd make more sense for them to fix bugs in the BASIC ROM... and they did. There's many bugs in ATARI's BASIC cartridge that they fixed over a few revisions.
@andyc8257
@andyc8257 6 месяцев назад
Coming from Sinclair and Amstrad machines, it's kind of bonkers to think INPUT actually reads values out of screen RAM rather than just buffering what is typed in. I guess because those machines have bitmapped displays (and thus reading characters back is more heavyweight) they did the more logically sensible thing.
@andyc8257
@andyc8257 6 месяцев назад
Coming from Sinclair and Amstrad machines, it's kind of bonkers to think INPUT actually reads values out of screen RAM rather than just buffering what is typed in. I guess because those machines have bitmapped displays (and thus reading characters back is more heavyweight) they did the more logically sensible thing.
@MarianoLu
@MarianoLu 6 месяцев назад
Yes is very interesting.The main difference is that the 64 has a full text editor as an input interface so right option was to look at what is in the screen
Далее
This Function Destroys Programs: MS-BASIC's VAL()
24:34
кажется, началось
00:45
Просмотров 1,3 млн
UNO!
00:18
Просмотров 1,8 млн
My New Game - Attack of the PETSCII Robots - Part 1
18:46
99.8% Compatible? The C64 Mode of the Commodore 128
1:02:11
The 6502 Rotate Right Myth
9:16
Просмотров 49 тыс.
How Wozniak’s code for the Apple 1 works
37:18
Просмотров 327 тыс.
I built my own 16-Bit CPU in Excel
16:28
Просмотров 1,4 млн