I love this series/course! I live in Germany and bought the 6502 Kit + the Clock Kit, and I did pay the 50 bucks shipping extra to buy from your website, instead of just ordering each individual part elsewhere, because I wanted to support you. Keep up the great work, Ben, I'm looking forward to finally be able to build this computer myself!
Yeah…just bought the full 6502 kit and have been watching for a couple years…can’t wait to watch all of these again and follow along this time with my own kit.
In Commodore MS Basic, the output of the print command was controlled by a variable, the screen was device 3 but this could be changed to any device (0 Keyboard, 1 Tape, 2 Serial, 3 Screen, 4-7 Printer, 8-15 Disk). If you implement the LCD as a device then the system print/input/get commands can be redirected to any device.
That was something which came to my mind, too. Maybe Ben could set up the LCD as device #7. I'd think that it would also be possible to make the LCDPRINT command automatically set up the device to print to as #7 and then call the "PRINT" routine to handle the rest, which would save on RAM space since commands such as LCDPRINT condense to a single byte whereas "PRINT#7," would require at least 4 bytes. Ben would still need to set up some kind of subroutine to handle the nonprinting characters (perhaps making CHR$(26) which is the Form Feed character act like a LCDCMD 1 to clear the screen, for example), but I'm sure that MBASIC has the appropriate "hooks" already provided to allow that kind of control.
So that’s where the 8 in LOAD ‘*’,8 comes from! Used to play games on a C64 at my grandparents’ when I was growing up, and we just copied the loading instructions from a scrap of paper by the computer.
Zero page memory is absolutely critical for 6502. Not only is memory access faster in zero page, it's the only way to do indirect addressing. So if you want pointers, which you definitely do, you need 2 bytes in zero page to hold the address. When i was coding in machine code on the Apple ][, i never put simple variables in zero page, that was always just reserved for pointers. Mainly, because i was using basic for the majority of most programs, and only using machine code for the fast bits. So i could not use zero page that was used by basic. When i was writing my one and only 6502 "game," i could use the entire space, and that was amazing!
Co-Inventor with John G Kemeny who also passed away some year ago. But yes very sad, was one of my heroes who made computing accessible to so many more..
2:27 yes, PRINT in MS Basic supports a SPC(n) and TAB(n) pseudo-functions. SPC(n) outputs ‘n’ spaces (you can get the same result by outputting SPACE$(n) of course but that’s more verbose and allocates an additional string). TAB(n) outputs enough spaces to reach column ‘n’; if you’re past the ‘n-th’ column in the output already, it outputs a new line and then enough spaces to get to ‘n’ on the next line. These are not real functions but output-control/formatting operators; they only exist within PRINT.
I was shocked to find that there was a buffer in the zero page. I've always considered the zero page to be a kind of register. It's such a precious memory that I've always believed it should be used sparingly.
MS Basic even has a subroutine in zero page to pick up the next character from the prog - wild. And I've just realised I've picked that out of a more than 40 year old memory from when I was doing my own reverse engineering on it!
@@paulabraham2550 Not sure why you would put a subroutine in zero page on a 6502, there is no zero page JSR instruction. Are you thinking of the Z80? The Z80 doesn't have zero-page addressing modes, but it does have 8 special one-byte instructions that perform subroutine calls to locations in page zero. I think the Z80 version of MS Basic used them to save code space and speed up calls to very frequently used operations.
@@gcewing Ha! I guess you weren't about in the day if you think people would have got confused between the two ;-). No - definitely 6502, and definitely the "character get" routine was in zero page. I don't think I ever worked out why they did that myself - I was certainly confused about that myself when I found it. Perhaps the annotated source code explains it - I only had disassembled code, of course.
It brings back a lot of memories from working on Commodore BASIC mods. Your strings are stored in a string heap, it's similar to a stack only software generated and every time you manipulate a string it takes up space on the heap. Eventually heap grows to much and a garbage collection takes place to clean up the no longer needed strings or temporary strings. This would cause BASIC to periodically freeze up while this garbage collection is happening. Programmers would perform a command that checks available memory FRE(0) in Commodore BASIC and mem in some others, they would strategically put these commands in certain places to put the delay where it would have less noticeable impact on operation. BTW - We used add extra commands to Commodore basic without changing the ROM by intercepting the CHRGET subroutine, which is a piece of code in zero page.
Seconding (thirding? fourthing?) the floating point video. I think I've got a pretty good grasp of how floating point numbers are represented at a high level, but actually getting into the weeds on how the representation is generated would be really cool, especially in a pure-software environment like on the 6502.
It becomes quite easy after a bit as it has been structured for being semi-readable. 0 is 0x30, A is 0x41, a is 0x61. You just read digits as "whats after 0x3" and letters as "what's after 0x4, 0x5 or equivalently 0x6, 0x7". Space and the most common punctuation you easily pick up as "before the numbers or between numbers and letters" with space = 0x20.
This was jaw droppingly amazing 🤯 Mind that if you followed along since the beginning of the b breadboard computer series, We've watched Ben basically reinvent modern computing, from bits of wire and transistors, to evaluating formatted strings in software. We need an international holiday to celebrate this man!
Ben starts at a big step up though, with a 6502 processor. There are few people making videos chronicling creation of custom CPUs on breadboards out of simple logic chips. My current favorite is @fabianschuiki www.youtube.com/@fabianschuiki/videos he's now replacing components he's done on breadboards with custom circuit boards (with some tiny surface mounted components he solders himself), cleaning it up in preparation for some more fancy instruction decoding to come which I personally can't wait to see.
Please do a video on floating point numbers! Your videos and kits (I've built the 6502) have satisfied so many lifelong curiosities of mine. I have a working programmer's knowledge of floating point, NaNs, ULPs, etc. But I feel like I'm missing the intuitive/historical/fundamental picture-why they are the way they are, how they got that way, and why it makes sense-that your videos always satisfyingly provide. Please keep it up!
Hi, if you are looking for a really cheap soundcard, you can use a 555 timer with few resistors connected via their respective mosfets to pin 7 to control the PWM cycle time. Each resistor/mosfet pair gives us 2 new frequency combinations. With 4 resistors/mosfets pairs you will get 16 frequencies. That would sound like a buzzers from 80s :) If you wish, you can even use PCF8574 to control the cycle time via I2C. Good luck!
I think you're right about FRM standing for "formula". If I remember rightly, in Applesoft, if you wrote a deeply-nested expression that overflowed the evaluation stack, the error message you got was "FORMULA TOO COMPLEX".
I confirm the space before a positive number is for the sign, I think you passed on that code in the string construction. There was also a test for the comma that simulates a tab. However, later versions of basic also had a "print using" command (Amstrad) similar to C's "printf()" or "print@" (Oric) that included cursor positioning in the same command.
Agree. space vs minus sign was common in FORTRAN as well (another old language lol). FORTRAN had options where you could force a "+" sign instead of space.
That used to drive me nuts formatting the screen.. less so of course as the workarounds became habit. It always made for gaps next to numbers unless you went back over the screen with whatever got overwritten. Not really a thing in "productivity" but say in games or anything with graphics, you had to account for it being there haha
Hey Ben! I've been loving your content since your first releases of the 8-bit CPU you made. I'd love to see a dive into more RISC architectures, whenever you start to finish up the 6502 series. I've developed a few RISC CPUs myself, with some great help of your explanations, and would love to see my favorite Comp-Sci creator touch a few topics a bit closer to my knowledge!
Hmmm "82C00000" is NOT modern IEEE-754 flt point for 3.0. That would be 0x40400000 I remember using another system that also represented floating point in an odd way called "Excess-64". I suppose before floating point machine instructions were standardized, vendors were free to come up with each unique format.
That's exactly how the history of floating-point formats played out. Each vendor had their own format and conventions, some even had design bugs. Some engineers even went as far as saying "you don't need floating-point, any mathematician worth their salt will know where the point is supposed to be." Some threatened to boycott the standard unless it matched the hardware they themselves were already selling to clients (such as government, military, banks, etc.) It was one of the biggest dramas in the computer industry up to that point. Needless to say, IEEE-754 left a lot of vendors unhappy, we almost didn't get a floating-point standard at all.
Microsoft's floating point is actually really close to IEEE-754, especially for single-precision. Bias is 128 instead of 127, and the sign bit is moved from bit 31 to bit 23. Moving the sign bit means the 8-bit exponent is now aligned with the first byte. The IEEE-754 format would require some awkward bitshifting.
Note that MS Basic floating point numbers actually are 5 bytes long, first byte is biased exponent, next 4 bytes is mantissa in BIG endian format, leading 1 bit explicit. Also IEEE special formats like inf, nan and subnormals are not supported.
FAC is definitely standing for Floating point ACcumulator. If I remember correctly, the C64 has both FAC and FAC2, but I had no idea they were "repurposed" for printing strings! Excellent video!
I grew up on the 8088 which is different but close enough to this to call it... I remember thinking everything happening inside that box was just pure magic... and before it was over had basic and qbasic doing handstands lol... seeing the infrastructure under the hood and what made all of it tick is a wild blast from the past. I still have trouble following along with some of the assembly but still wild to watch as each block of this thing lays the foundation for the ones to follow. I'm strongly considering getting one of the kits just to play around with. Certainly *waaay* cheaper than the box I'd have otherwise needed to modify to really get my head around the hardware.
Brilliant! Takes me back to my early days on a 6502 machine. IIRC the comma and semicolon are used to modify formatting. Comma allows printing a separated list of things. Semicolon at the end prevents a newline. I think you can also use semicolon to suppress the space prepended to positive numbers.
Comma is used to say "advance to the next tab stop before printing the next thing" while semicolon is used to say "print the next thing immediately after the previous thing". Without either, it advances to the start of the next line before printing the next thing.
Semicolon did a few things in basic... I learned it as "(prepare to) append", preventing CRLF from running at the end of a print statement... similar to concatenate strings.. and in GW/Quick (at least) it would also dump the question mark at an input prompt, allowing you to change it to whatever you wanted within the prompt instead. Long time ago haha might be more uses but that's all that comes to mind at the moment. Edit: I've never heard of it dumping the leading space for a number, or I've forgotten lol, but that would have been nice to know many many years ago 🤣
8-bit show and tell has a lot of explanations how the C64, which uses a modified version of Microsoft Basic, works internally, especially with stuff like this. It is fascinating to see. It also applies very well if you want to modify Microsoft Basic on this project.
This is Microsoft Binary Format (MBF). Ask Mr. Google for more info. HEX 82 C0 00 00 00 = BIN 1000 0010 (exponent) 0 (sign) 110 0000 0000 0000 (mantissa) => BIN +0.11 * (10 pow (1000 0010 - 1000 0000)) = DEC 0.75 * (2 pow 2) = DEC 3
Any day with a Ben Eater video is a good day... Though it reminds me again that I haven't done anything on my Acorn Electron build for a lot of months now... life, man 🙄
Those edge cases of semicolon and comma are important for printing multiple variables and literals together, and whether or not to put a carriage return, nothing, or a tab at the end of the string.
It's easy 'reverse engineering' BASIC when you have the source code :) I had to first make my own source code for Nascom ROM BASIC by disassembling it in 1981! I can't remember finding any serious Microsoft bugs, except that they assembled it for 8080 and not Z80. There were some bugs in the routines that Nascom added, but nothing that broke it when using the T4 or NAS-SYS monitor ROMs. There was a bug in LIST where it would expand characters 80-FF to reserved words when they were string literals. This was funny when I let Computer & Video Games magazine include my Nimbot game as a type-in listing. I was using DATA and PRINT statements with block graphic characters in quotes. They didn't even contact me to fix it before publishing, they just printed the listing, which would have been a real pain for people to get working properly!
Another problem I found with Nascom BASIC was with strings. When a large number of strings was active, such as a string array with many elements, and many changes have been made to those strings, this would trigger a 'garbage collection' which shifted all the active string data down to leave a single region of free memory. The algorithm was very inefficient; It searched all string variables to find the string in the lowest address in memory that needed to be moved down to release the unused memory. For each of N strings, it would have to search through those N strings to find the lowest one to move. This would need N*N checks, which could stall your program for a very long time ... I managed to get > 1 hour!!!
The string format in MS BASIC is also continued in BASIC for the IBM PC. If you call varptr(s$), the returned pointer is that 3-byte structure with the length and the pointer to the string data. So apparently you can still learn a lot about older MS BASIC by looking at the appendix of the IBM BASIC manual from the PC/XT days.
Microsoft used a shared codebase for all versions of Microsoft BASIC. So the basic data structures are the same for all of them regardless of platform. The open sourced GW Basic source has extensive comments explaining how things work but other than the more detailed comments the x86 assembly of GW Basic wont really be any easier to understand than the 6502 code here.
@@MonochromeWench I was speaking of the IBM BASIC users manual though. The appendix has a lot of info about internals, such as memory organization and variable formats.
20:55 Isn't the range from $0100 to $01FF the stack area? This feels like a bug in the BASIC interpreter that could cause corruption if the stack is almost full, but probably rare to actually cause problems.
I looked into eval.s and there you can see that the intermediate steps of each numerical operation are stored onto the stack. It leaves the result there to get fetched for display or storing.
Q: FOUT calls a different string print routine that includes FREEFAC. You are always calling FREEFAC. FAC isn't loaded for strings, so won't calling FREEFAC unnecessarily result in bad things happening?
Thanks, Ben The 1st tome thru one of your assembly videos, my brain hurts. The 2nd time, a faint light begins to glimmer. Subsequent videos make that light just a little brighter each time. I think it's getting close to time to order a kit. Is Santa's address still "North Pole?"
There is a commented disassembly of the Applesoft BASIC available from the page at the third credit link in the Microsoft BASIC Github repo. (TH-cam keeps deleting my comment if I put a link here 😕). It confirms that FAC is the "MAIN FLT PT ACCUMULATOR" (S.DEFINITIONS) and it has commented PRINT (S.DACF) and FRMEVL (S.DD7B) routines. There is a comment at E102 (E103 jumps to FRMNUM, which calls FRMEVL and checks that the result is numeric) saying "EVALUATE NUMERIC FORMULA AT TXTPTR", so Formula Evaluate sounds right, too.
Minor bug in your print routine: you test the length after decrementing it, so a zero-length string wil print 256 bytes of garbage.
Sounds fun
Heartbleed 6502 edition
yes, tax, beq lcd_print_exit
but probably 0 byte strings will produce an error before ever getting there
@@EVPaddy How? That would require FRMEVL to abort the function that is calling it.
I love this series/course! I live in Germany and bought the 6502 Kit + the Clock Kit, and I did pay the 50 bucks shipping extra to buy from your website, instead of just ordering each individual part elsewhere, because I wanted to support you. Keep up the great work, Ben, I'm looking forward to finally be able to build this computer myself!
I need to buy it, too. It looks like a great way to learn.
Yeah…just bought the full 6502 kit and have been watching for a couple years…can’t wait to watch all of these again and follow along this time with my own kit.
In Commodore MS Basic, the output of the print command was controlled by a variable, the screen was device 3 but this could be changed to any device (0 Keyboard, 1 Tape, 2 Serial, 3 Screen, 4-7 Printer, 8-15 Disk). If you implement the LCD as a device then the system print/input/get commands can be redirected to any device.
That sounds like the best approach to do this
There are basic vectors to redirect for adding new i/o devices.
That was something which came to my mind, too. Maybe Ben could set up the LCD as device #7. I'd think that it would also be possible to make the LCDPRINT command automatically set up the device to print to as #7 and then call the "PRINT" routine to handle the rest, which would save on RAM space since commands such as LCDPRINT condense to a single byte whereas "PRINT#7," would require at least 4 bytes.
Ben would still need to set up some kind of subroutine to handle the nonprinting characters (perhaps making CHR$(26) which is the Form Feed character act like a LCDCMD 1 to clear the screen, for example), but I'm sure that MBASIC has the appropriate "hooks" already provided to allow that kind of control.
So that’s where the 8 in LOAD ‘*’,8 comes from! Used to play games on a C64 at my grandparents’ when I was growing up, and we just copied the loading instructions from a scrap of paper by the computer.
Zero page memory is absolutely critical for 6502. Not only is memory access faster in zero page, it's the only way to do indirect addressing. So if you want pointers, which you definitely do, you need 2 bytes in zero page to hold the address. When i was coding in machine code on the Apple ][, i never put simple variables in zero page, that was always just reserved for pointers.
Mainly, because i was using basic for the majority of most programs, and only using machine code for the fast bits. So i could not use zero page that was used by basic.
When i was writing my one and only 6502 "game," i could use the entire space, and that was amazing!
Yes, floating point video please
YES YES YES pretty please
+1. Not only the floating point as it was imlplemented in MS Basic, but also the standard IEEE format ;-)
@@PaulaBeanit's not that different, al FP numbers work largely the same.
In memory of Thomas Kurtz, inventor of BASIC
1928-2024
Oh. I didn't know Kurtz died.
10 PRINT ":( ";
20 GOTO 10
10 FOR I=1 TO 2
20 PRINT "The horror!"
30 NEXT I
...but seriously, RIP :(
Co-Inventor with John G Kemeny who also passed away some year ago. But yes very sad, was one of my heroes who made computing accessible to so many more..
@@RetroRyn I still program in BASIC on my ZX81 now and then.
@@frankowalker4662 Nice I started on a Sinclair ZX80, with 1K of ram, was fun..
2:27 yes, PRINT in MS Basic supports a SPC(n) and TAB(n) pseudo-functions. SPC(n) outputs ‘n’ spaces (you can get the same result by outputting SPACE$(n) of course but that’s more verbose and allocates an additional string). TAB(n) outputs enough spaces to reach column ‘n’; if you’re past the ‘n-th’ column in the output already, it outputs a new line and then enough spaces to get to ‘n’ on the next line. These are not real functions but output-control/formatting operators; they only exist within PRINT.
peek is one of them
Intel has been real quiet since this dropped
Bill Gates hates this one trick!
😂
MOS Technologies has been raking it in
0:33 I bought one of your breadboard CPU kits! It makes for a fantastic conversation starter. Maybe one day I'll even assemble it.
I was shocked to find that there was a buffer in the zero page. I've always considered the zero page to be a kind of register. It's such a precious memory that I've always believed it should be used sparingly.
this
MS Basic even has a subroutine in zero page to pick up the next character from the prog - wild. And I've just realised I've picked that out of a more than 40 year old memory from when I was doing my own reverse engineering on it!
Putting the buffer in zero page is probably so that the zero-page indexed addressing modes can be used to access it.
@@paulabraham2550 Not sure why you would put a subroutine in zero page on a 6502, there is no zero page JSR instruction. Are you thinking of the Z80? The Z80 doesn't have zero-page addressing modes, but it does have 8 special one-byte instructions that perform subroutine calls to locations in page zero. I think the Z80 version of MS Basic used them to save code space and speed up calls to very frequently used operations.
@@gcewing Ha! I guess you weren't about in the day if you think people would have got confused between the two ;-).
No - definitely 6502, and definitely the "character get" routine was in zero page. I don't think I ever worked out why they did that myself - I was certainly confused about that myself when I found it. Perhaps the annotated source code explains it - I only had disassembled code, of course.
It brings back a lot of memories from working on Commodore BASIC mods.
Your strings are stored in a string heap, it's similar to a stack only software generated and every time you manipulate a string it takes up space on the heap. Eventually heap grows to much and a garbage collection takes place to clean up the no longer needed strings or temporary strings. This would cause BASIC to periodically freeze up while this garbage collection is happening. Programmers would perform a command that checks available memory FRE(0) in Commodore BASIC and mem in some others, they would strategically put these commands in certain places to put the delay where it would have less noticeable impact on operation.
BTW - We used add extra commands to Commodore basic without changing the ROM by intercepting the CHRGET subroutine, which is a piece of code in zero page.
Seconding (thirding? fourthing?) the floating point video. I think I've got a pretty good grasp of how floating point numbers are represented at a high level, but actually getting into the weeds on how the representation is generated would be really cool, especially in a pure-software environment like on the 6502.
I don’t know why, but everything Ben does is always amazing, and I really like it.
That was interesting thank you! It's pretty crazy how you can read HEX like another language, pretty cool.
It becomes quite easy after a bit as it has been structured for being semi-readable. 0 is 0x30, A is 0x41, a is 0x61. You just read digits as "whats after 0x3" and letters as "what's after 0x4, 0x5 or equivalently 0x6, 0x7". Space and the most common punctuation you easily pick up as "before the numbers or between numbers and letters" with space = 0x20.
This is the content I need from TH-cam. Thanks so much for bringing us along.
it's a beautiful morning when you post Ben!
Ben u are my cyber motivator
This was jaw droppingly amazing 🤯
Mind that if you followed along since the beginning of the b breadboard computer series, We've watched Ben basically reinvent modern computing, from bits of wire and transistors, to evaluating formatted strings in software.
We need an international holiday to celebrate this man!
Ben starts at a big step up though, with a 6502 processor. There are few people making videos chronicling creation of custom CPUs on breadboards out of simple logic chips. My current favorite is @fabianschuiki www.youtube.com/@fabianschuiki/videos he's now replacing components he's done on breadboards with custom circuit boards (with some tiny surface mounted components he solders himself), cleaning it up in preparation for some more fancy instruction decoding to come which I personally can't wait to see.
@smallduck1001001 that's why I mentioned the breadboard computer series. The 6502 CPU only makes sense after you watch that.
What a nice day this is getting new Ben Eater video!
when bad times hit this guy posts a video and then the time is no longer bad you just amazing!!
A new Ben Eater video! What a wonderful day :D
Please do a video on floating point numbers! Your videos and kits (I've built the 6502) have satisfied so many lifelong curiosities of mine. I have a working programmer's knowledge of floating point, NaNs, ULPs, etc. But I feel like I'm missing the intuitive/historical/fundamental picture-why they are the way they are, how they got that way, and why it makes sense-that your videos always satisfyingly provide. Please keep it up!
Hi, if you are looking for a really cheap soundcard, you can use a 555 timer with few resistors connected via their respective mosfets to pin 7 to control the PWM cycle time. Each resistor/mosfet pair gives us 2 new frequency combinations. With 4 resistors/mosfets pairs you will get 16 frequencies. That would sound like a buzzers from 80s :) If you wish, you can even use PCF8574 to control the cycle time via I2C. Good luck!
Thank you for video Ben
I think you're right about FRM standing for "formula". If I remember rightly, in Applesoft, if you wrote a deeply-nested expression that overflowed the evaluation stack, the error message you got was "FORMULA TOO COMPLEX".
Mad respect, you are one of the best on youtube
I confirm the space before a positive number is for the sign, I think you passed on that code in the string construction. There was also a test for the comma that simulates a tab. However, later versions of basic also had a "print using" command (Amstrad) similar to C's "printf()" or "print@" (Oric) that included cursor positioning in the same command.
Agree. space vs minus sign was common in FORTRAN as well (another old language lol). FORTRAN had options where you could force a "+" sign instead of space.
That used to drive me nuts formatting the screen.. less so of course as the workarounds became habit. It always made for gaps next to numbers unless you went back over the screen with whatever got overwritten. Not really a thing in "productivity" but say in games or anything with graphics, you had to account for it being there haha
Yes, do a separate video about floating point numbers.
Hey Ben! I've been loving your content since your first releases of the 8-bit CPU you made. I'd love to see a dive into more RISC architectures, whenever you start to finish up the 6502 series. I've developed a few RISC CPUs myself, with some great help of your explanations, and would love to see my favorite Comp-Sci creator touch a few topics a bit closer to my knowledge!
Superb - really enjoyed watching that.
Ben eater’s original videos nerd sniped me so hard I got a masters in computer engineering.
I still love these videos and learn something every upload
Hmmm "82C00000" is NOT modern IEEE-754 flt point for 3.0. That would be 0x40400000 I remember using another system that also represented floating point in an odd way called "Excess-64". I suppose before floating point machine instructions were standardized, vendors were free to come up with each unique format.
Yeah, that confused me there. It is still the same basic (pun very much intended) idea, just done slightly differently.
That's exactly how the history of floating-point formats played out. Each vendor had their own format and conventions, some even had design bugs. Some engineers even went as far as saying "you don't need floating-point, any mathematician worth their salt will know where the point is supposed to be." Some threatened to boycott the standard unless it matched the hardware they themselves were already selling to clients (such as government, military, banks, etc.) It was one of the biggest dramas in the computer industry up to that point. Needless to say, IEEE-754 left a lot of vendors unhappy, we almost didn't get a floating-point standard at all.
Microsoft's floating point is actually really close to IEEE-754, especially for single-precision.
Bias is 128 instead of 127, and the sign bit is moved from bit 31 to bit 23. Moving the sign bit means the 8-bit exponent is now aligned with the first byte. The IEEE-754 format would require some awkward bitshifting.
Note that MS Basic floating point numbers actually are 5 bytes long, first byte is biased exponent, next 4 bytes is mantissa in BIG endian format, leading 1 bit explicit. Also IEEE special formats like inf, nan and subnormals are not supported.
MS Basic uses the MBF floating point system created by Monte Davidoff in 1975. It predates IEEE754 by 10 years
FAC is definitely standing for Floating point ACcumulator.
If I remember correctly, the C64 has both FAC and FAC2, but I had no idea they were "repurposed" for printing strings!
Excellent video!
I will never follow or understand any of this, but I am fascinated, how clever you are. Hats off.
I grew up on the 8088 which is different but close enough to this to call it... I remember thinking everything happening inside that box was just pure magic... and before it was over had basic and qbasic doing handstands lol... seeing the infrastructure under the hood and what made all of it tick is a wild blast from the past. I still have trouble following along with some of the assembly but still wild to watch as each block of this thing lays the foundation for the ones to follow. I'm strongly considering getting one of the kits just to play around with. Certainly *waaay* cheaper than the box I'd have otherwise needed to modify to really get my head around the hardware.
Brilliant! Takes me back to my early days on a 6502 machine. IIRC the comma and semicolon are used to modify formatting. Comma allows printing a separated list of things. Semicolon at the end prevents a newline. I think you can also use semicolon to suppress the space prepended to positive numbers.
Comma is used to say "advance to the next tab stop before printing the next thing" while semicolon is used to say "print the next thing immediately after the previous thing". Without either, it advances to the start of the next line before printing the next thing.
Semicolon did a few things in basic... I learned it as "(prepare to) append", preventing CRLF from running at the end of a print statement... similar to concatenate strings.. and in GW/Quick (at least) it would also dump the question mark at an input prompt, allowing you to change it to whatever you wanted within the prompt instead.
Long time ago haha might be more uses but that's all that comes to mind at the moment.
Edit: I've never heard of it dumping the leading space for a number, or I've forgotten lol, but that would have been nice to know many many years ago 🤣
8-bit show and tell has a lot of explanations how the C64, which uses a modified version of Microsoft Basic, works internally, especially with stuff like this. It is fascinating to see. It also applies very well if you want to modify Microsoft Basic on this project.
Fascinating stuff - many thanks for doing this!
❤
Yes Ben I found that interesting. As usual!
I am glade to see another video ! Sometimes I get worried that it may be the last time you upload .... 😅😂
Oh man. A video on floating point in 6502 would be awesome!
Wild. Fun stuff; thank you for sharing your explorations!
This is Microsoft Binary Format (MBF). Ask Mr. Google for more info. HEX 82 C0 00 00 00 = BIN 1000 0010 (exponent) 0 (sign) 110 0000 0000 0000 (mantissa) => BIN +0.11 * (10 pow (1000 0010 - 1000 0000)) = DEC 0.75 * (2 pow 2) = DEC 3
HES BACK 🎉🎉🎉
An I2C interface to a serial flash rom for storage would be an awesome next video.
Any day with a Ben Eater video is a good day... Though it reminds me again that I haven't done anything on my Acorn Electron build for a lot of months now... life, man 🙄
A big yes to floating point numbers video!
Fascinating as always. I would also be interested if you do a floating point video.
Very interesting, I very much like seeing how to work with assembly code. Your videos are Bothe entertaining and educational. Thank you very much.
Those edge cases of semicolon and comma are important for printing multiple variables and literals together, and whether or not to put a carriage return, nothing, or a tab at the end of the string.
Ben Eater videos are why i bought a clicky keyboard 😂
Babe, wake up, new Ben Eater's video just dropped
I think you should natively support keyboards and text to LCD to make the whole computer self contained!!
What a great Saturday! Great morning with my family. Now a Ben eater video?
Great thanks ❤❤❤
It's easy 'reverse engineering' BASIC when you have the source code :)
I had to first make my own source code for Nascom ROM BASIC by disassembling it in 1981!
I can't remember finding any serious Microsoft bugs, except that they assembled it for 8080 and not Z80.
There were some bugs in the routines that Nascom added, but nothing that broke it when using the T4 or NAS-SYS monitor ROMs.
There was a bug in LIST where it would expand characters 80-FF to reserved words when they were string literals.
This was funny when I let Computer & Video Games magazine include my Nimbot game as a type-in listing.
I was using DATA and PRINT statements with block graphic characters in quotes.
They didn't even contact me to fix it before publishing, they just printed the listing, which would have been a real pain for people to get working properly!
Another problem I found with Nascom BASIC was with strings.
When a large number of strings was active, such as a string array with many elements, and many changes have been made to those strings, this would trigger a 'garbage collection' which shifted all the active string data down to leave a single region of free memory.
The algorithm was very inefficient; It searched all string variables to find the string in the lowest address in memory that needed to be moved down to release the unused memory.
For each of N strings, it would have to search through those N strings to find the lowest one to move.
This would need N*N checks, which could stall your program for a very long time ... I managed to get > 1 hour!!!
wunderbar
„Hopefully you found that interesting“ - oh yes, most definitely.
Great content, thank you very much!!! Could you make a video on floating point, please?
Always a good day when Ben posts
The string format in MS BASIC is also continued in BASIC for the IBM PC. If you call varptr(s$), the returned pointer is that 3-byte structure with the length and the pointer to the string data. So apparently you can still learn a lot about older MS BASIC by looking at the appendix of the IBM BASIC manual from the PC/XT days.
Microsoft used a shared codebase for all versions of Microsoft BASIC. So the basic data structures are the same for all of them regardless of platform. The open sourced GW Basic source has extensive comments explaining how things work but other than the more detailed comments the x86 assembly of GW Basic wont really be any easier to understand than the 6502 code here.
@@MonochromeWench I was speaking of the IBM BASIC users manual though. The appendix has a lot of info about internals, such as memory organization and variable formats.
Ooo new video
If you're still doing videos on communication protocols, I'd love to see one on I2C
Please, do floating point numbers video: I think you would be able to explain it in a different (better) way compared to others on TH-cam
Benny is back❤
15:42 I can't speak for other people, but that'd be an awesome video!
I would LOVE a video on floating point. I never understood how they could get even basic floating point math to work in 8 bits.
Hot swapping ROMs, wild man 👍😎
Bro u made my life danke schön
Thank you Ben.
Good video, thank you again
BASIC mentioned! 🥳
Thank you!
Yes please do a video on floating point numbers
this is so cool
It would be cool to make a programming language that can run basic commands (or is built around basic) would be a good way to get into programming.
BASIC is a programming language that can run BASIC commands. I guess I'm missing your point.
20:55 Isn't the range from $0100 to $01FF the stack area? This feels like a bug in the BASIC interpreter that could cause corruption if the stack is almost full, but probably rare to actually cause problems.
Maybe those bytes got there by being pushed onto the stack?
I looked into eval.s and there you can see that the intermediate steps of each numerical operation are stored onto the stack. It leaves the result there to get fetched for display or storing.
OK, but you don't check for 0-length strings so what happens if you do LCDPRINT "" ?
Here's another vote for a video on floating point programming(?). Thumbs up!
A whole video on IEEE 754 would be cool. I think the FAC would be the F from FRMEVL, or Formula.
Love you sir ❤
Oh how I would love to see float (or maybe fixed?) point number video😊
I just love your videos
15:45 Looks much more like a fixed point number for me.
first time I see one of Ben's video with fewer than 1,000 views :O
Dear sir, take love from Bangladesh
I'd like both a floating point video, and maybe a transition into using the C functionality of cc65.
Lets vote for a Discord Server of Ben Eater 😂
Q: FOUT calls a different string print routine that includes FREEFAC. You are always calling FREEFAC. FAC isn't loaded for strings, so won't calling FREEFAC unnecessarily result in bad things happening?
Your guess is correct FAC is indeed the floatingpoint accumulator. Or at least it is on the C64
yes, C64 also uses Microsoft BASIC.
Very awesome
Thanks, Ben
The 1st tome thru one of your assembly videos, my brain hurts.
The 2nd time, a faint light begins to glimmer.
Subsequent videos make that light just a little brighter each time.
I think it's getting close to time to order a kit.
Is Santa's address still "North Pole?"
There is a commented disassembly of the Applesoft BASIC available from the page at the third credit link in the Microsoft BASIC Github repo. (TH-cam keeps deleting my comment if I put a link here 😕). It confirms that FAC is the "MAIN FLT PT ACCUMULATOR" (S.DEFINITIONS) and it has commented PRINT (S.DACF) and FRMEVL (S.DD7B) routines. There is a comment at E102 (E103 jumps to FRMNUM, which calls FRMEVL and checks that the result is numeric) saying "EVALUATE NUMERIC FORMULA AT TXTPTR", so Formula Evaluate sounds right, too.
I would love a video on floating point numbers
I would low to see a sound card built!!! Please do a video on that.
i would love to see a floating point video!
WOW... fantastic
dumping a bunch of print statements into a function in the hopes of finding something helpful. good to know I'm not alone.
“Hopefully you found that interesting”. You kidding, found it fascinating.
From memory, FAC is the floating point accumulator.
correct. a quick Google would've confirmed it for Ben. eg, the C64 Wiki has a short entry about it.