How Wozniak’s code for the Apple 1 works

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ค. 2024
  • More 6502 stuff: eater.net/6502
    Support these videos on Patreon: / beneater or eater.net/support for other ways to support.
    0:00 Variables
    2:16 Hardware initialization
    2:54 Reading input from the keyboard
    10:18 Parsing the command
    13:45 Parsing a hex value
    21:29 Examine mode
    28:28 Block examine mode
    31:16 Store mode
    34:28 Print routines
    ------------------
    Social media:
    Website: www.eater.net
    Twitter: / ben_eater
    Patreon: / beneater
    Reddit: / beneater
    Special thanks to these supporters for making this video possible:
    Adrien Friggeri, Aleksey Smolenchuk, An Dương, Anthony Weems, anula, Ben, Ben Cochran, Ben Williams, Bill Cooksey, Bill Watkins, Binh Tran, Богдан Федоров, Bradley Stach, Brian Haug, Burt Humburg, Carl Fooks, Carsten Schwender, Chai, Chaitanya Bhatt, Chris Anders, Chris Lajoie, Chris Sachs, criis, Cristi Cobzarenco, Daniel Pink, Daniel Tang, Daniel Zimmer, Dave Walter, David Clark, David Cox, David Dawkins, David House, David Klassen, David Sastre Medina, David Turner, Dean Bevan, Dean Winger, Deep Kalra, Dennis Henderson, Dennis Schubert, Dilip Gowda, Dirk Sperling, Dmitry Guyvoronsky, Dustin Campbell, Dzevad Trumic, Emilio Mendoza, Eric Dynowski, Erik Broeders, Erik Granlund, Ethan Sifferman, Eugene Bulkin, Evan Serrano, Evan Thayer, Eveli László, EvinSaysMarxWasRight!, Florian Bürgi, fxshlein, George Miroshnykov, ghostdunk, Gregory Burns, GusGold, Hailey, Hovis Biddle, Ingo Eble, Jacob Ford, James Beldock, James Capuder, Jared Dziedzic, Jason Bowen, Jason DeStefano, Jason Grim, Jason Thorpe, JavaXP, Jaxon Ketterman, jemmons, Jeremy Cole, Jesse Miller, Jim Kelly, Jim Knowler, Joe Beda, Joe Pregracke, Joe Rork, Joel, Joey Murphy, John Hamberger jn., John Henning, John Meade, Jon Dugan, Jonn Miller, Joseph Portaro, Justin Graziani, Kai Wells, Kefen, Ken Paul, Kennard Smith, Kenneth Christensen, Kyle Kellogg, Lambda GPU Workstations, László Bácsi, Lithou, Lukasz Pacholik, Marcos Fujisawa, Marcus Classon, Mariano Uvalle, Mark Day, Martin Noble, Mats Fredriksson, Matthew Clifford, melvin2001, Michael, Michael Cartwright, MICHAEL SLASS, Michael Tedder, Michael Timbrook, Michael Weitman, Miguel Ríos, mikebad, Miles Macchiaroli, Muqeet Mujahid, NacOJerk, Nate Welch, Nicholas Counts, Nicholas Moresco, Nick Chapman, Oli Homer, Olivier HUBER, Örn Arnarson, Paul Heller, Paul Pluzhnikov, Pete Dietl, Phil Dennis, Philip Hofstetter, ProgrammerDor, Ralph Irons, Randal Masutani, Randy True, raoulvp, real_huitz, ReJ aka Renaldas Zioma, Ric King, Richard Wagoner, Rick Hennigan, Rob Bruno, Robert Brown, Robert Diaz, Robert Keown, Robey Pointer, Roland Munsil, Sagnik Bhattacharya, Sam Sturgis, Scott Gorlick, Scott Holmes, Sean Bright, Sean Patrick O’Brien, Sergey Kruk, Shane Mulcahy, SonOfSofaman, sorek.uk, Spencer Ruport, Stefan Nesinger, Stephen Kovalcik, Stephen Riley, Steve Jones, TheWebMachine, Thomas Eriksen, Tim Oriol, Tim Sanders, Tim Walkowski, Tim Wheeler, Tom, Tom Smith, Tyler Latham, Usseod, Vincent Bernat, Warren Miller, Wim Coekaerts, Yee Lam Wan

ความคิดเห็น • 449

  • @DefaultFlame
    @DefaultFlame 6 หลายเดือนก่อน +26

    Did I understand everything? No.
    Do I feel an enormous amount of respect and admiration for the people/person who came up this? Yes.
    As well as for you who walked us through it? Yes.

    • @DefaultFlame
      @DefaultFlame 6 หลายเดือนก่อน +1

      My apologise for anything I misinterpreted or misunderstood, English is my second language and I am very drunk currently.

  • @rymaples
    @rymaples 11 หลายเดือนก่อน +1027

    It takes a special kind of person that is both intelligent and has the ability to explain what is happening in a way anyone can understand. If I had Ben as a professor I would go back to school just to go back to school.

    • @wherami
      @wherami 10 หลายเดือนก่อน +7

      Same

    • @mb106429
      @mb106429 10 หลายเดือนก่อน +15

      Sadly, teacher's skills in say UK, are not teaching.
      Primarily it is the teacher's ability in crowd control over a group of kids that don't want to be there partly because of the previous lessons's crowd control emphasis.
      The teacher spends most of their efforts on crowd control and this crowd control emphasis is guaranteed by the imbalance of 33 pupils to 1 teacher. Or worse.
      If the teacher has any spare energy, some teaching can occur
      They don't have the latest most intresting subjects in schools, only the bread n butter basics, the ones that don't need much practical work

    • @lightning_11
      @lightning_11 10 หลายเดือนก่อน +9

      @@mb106429 It seems to get better in College, since most teachers don't care if you come to class or not as long as you pay your tuition. Although a lot of college professors are so into their field that they have a hard time giving the context required for a normal person to understand what they're saying.

    • @timsmith2525
      @timsmith2525 10 หลายเดือนก่อน +5

      Ben is an excellent teacher.

    • @timsmith2525
      @timsmith2525 10 หลายเดือนก่อน +2

      @@mb106429 True in the US, which is why I left teaching to go back to programming computers.

  • @devttyUSB0
    @devttyUSB0 10 หลายเดือนก่อน +36

    This makes you appreciate how clean 'GOTO' usage actually is. :-)

    • @rabidbigdog
      @rabidbigdog 10 หลายเดือนก่อน

      Hahaha, exactly.

  • @0LoneTech
    @0LoneTech 10 หลายเดือนก่อน +231

    35:42 I believe it actually adds 7, because the carry bit is set. This skips the 6 non-digit symbols after the digits, and the @ before the letters.

    • @Beus38
      @Beus38 10 หลายเดือนก่อน +24

      Exactly, adding 6 would make it a C0, while it needs to be C1 to display an "A", so you're totally right.

    • @viktorhugo8252
      @viktorhugo8252 10 หลายเดือนก่อน +1

      @@Beus38. ,ADC add always with carry-flag

  • @kylestubblefield3404
    @kylestubblefield3404 10 หลายเดือนก่อน +10

    The elegance of falling through the conditions so you can setup the machine, while eliminating branch instructions to reduce both size of the binary, and clock cycles is brilliant.

  • @MichaelDoornbos
    @MichaelDoornbos 11 หลายเดือนก่อน +189

    I’ve run Wozmon on my KIM-1 for years but never thought to do a deep dive to think about how it works. Excellent deep dive Ben!

    • @alexstrasheim5451
      @alexstrasheim5451 11 หลายเดือนก่อน +6

      My high school's electronics lab had a KIM-1 back in the 70s, along with a Heathkit H8. But I don't think I understood any of it very well until I bought Ben's 6502 kit and watched the videos.

    • @MichaelDoornbos
      @MichaelDoornbos 11 หลายเดือนก่อน +7

      @@alexstrasheim5451 yeah, Ben's many series are the best resource I've ever seen for first principles computing learning

  • @frixyg2050
    @frixyg2050 10 หลายเดือนก่อน +10

    That is a much more elegant ASCII > HEX conversion than I have been using in my 6502 assembly! Now I'm going to go update my code...

    • @viktorhugo8252
      @viktorhugo8252 10 หลายเดือนก่อน +1

      Hihi…-Update this

  • @3vi1J
    @3vi1J 10 หลายเดือนก่อน +57

    Woz's software is as ingeniously optimized as his hardware designs. What a talented guy.

    • @ducksonplays4190
      @ducksonplays4190 9 หลายเดือนก่อน +11

      @@OskarHersch Evidently, you dislike Wozniak

    • @Vilakazi
      @Vilakazi 8 หลายเดือนก่อน +7

      Which is why i hate the media because they always talked about Steve Jobs being the genius and not woz. Kind of makes me wonder who is the real genius behind tesla and spaceX when the media is pumping the facade of Elon Musk being the genius down our throats.

    • @Vilakazi
      @Vilakazi 8 หลายเดือนก่อน

      @@ducksonplays4190 he's an Elon Musk fan. They hate actual geniuses because the fake one's reminds them of themselves.

    • @adammontgomery7980
      @adammontgomery7980 5 หลายเดือนก่อน +4

      @@Vilakazi I think Elon has said before that his success is due to hiring the best people. Jobs was definitely a visionary person, and so is Elon. You need big picture people, and people who are all about the details. Woz is a detail oriented person, Jobs was the big picture guy; you wouldn't have Apple without either.

    • @rennleitung_7
      @rennleitung_7 5 หลายเดือนก่อน

      If the 5000$ story about BREAKOUT is true, Steve Jobs is definitely the greater genius for talking Wozniak into apple.

  • @davidgari3240
    @davidgari3240 10 หลายเดือนก่อน +13

    Thanks Ben, for flashing me back to the late '70s when I learned all this stuff (on an 8080 but that's not important right now).
    The pure joy of 'touching the metal' with your mind is something any young person should experience.
    Woz was like a Kung Fu master.

  • @mashrien
    @mashrien 10 หลายเดือนก่อน +154

    "fall-through" code has always been a bit of a brain-breaker for me.. I have an incredible amount of respect for Woz for his talent in code alone, to say nothing of his other achievements in life. Guy's a genuine genius when it comes to computers and code.
    Then you get to modern ASM and there's SO MANY symbols/ops to remember.. I'll stick to modern typed languages of the C-variety lol

    • @jefffrasca4054
      @jefffrasca4054 10 หลายเดือนก่อน +23

      Try looking at RISC-V. MIPS is my other favorite streamlined, modern-ish ISA. ARM8 is simpler than x86 by a wide margin, but more complicated than RISC-V by quite a bit. All risc ISAs have some quirks that are meant to make things easier for chip designers and compiler writers that make stuff weird for hand ASM (for RISC-V: setting a register to a specific value can take multiple instructions), but you should be able to rely on your assembler to handle that in nearly all cases.
      The other joy of RISC-V is the ISA specification was written by professors as a teaching tool, so they are extremely readable and include notes on why it's setup the way it is.
      ARM docs read like they were written by a committee of patent lawyers and engineers (because...well).
      The AMD64 docs are similar in form to ARM8 docs but more so and they've clearly evolved over time and accrued bugs and omissions as things changed subtly over many generations of updates and edits.

    • @edgeeffect
      @edgeeffect 10 หลายเดือนก่อน +6

      ​​​@@jefffrasca4054easyest assembler I've done in years is AVR... some IO modes on the bigger microcontrollers is a bit quirky... but it's still really nice.
      Looking forward to getting into MIPS sometime soon.

    • @gambistics
      @gambistics 10 หลายเดือนก่อน +3

      One option would be to programm the lower tier ARMs because they come with quite condensed instruction set. E.g. RPi Pico uses the M0+ variety which I found somewhat accessible to learn basic assembly on a modern platform.

    • @renakunisaki
      @renakunisaki 10 หลายเดือนก่อน +4

      If you want to learn assembly, the Game Boy is a great place to start. It's (mostly) Z80, but the concepts are the same.

    • @ChrisM541
      @ChrisM541 8 หลายเดือนก่อน +1

      @@jefffrasca4054 Interesting thought: since all CPU's execute software via machine code...
      - How important is is for a country/countries/The West etc safety to have experts in assembly?
      - If no one understands what an .exe (or equivalent) does then that might(!) be problematic for national/international security?

  • @felixmerz6229
    @felixmerz6229 10 หลายเดือนก่อน +100

    Super interesting, yes. Genius program. Great example of something that needs to live in the creator's mind in its entirety all at once, that's my favorite special case of programming.

    • @nollix
      @nollix 10 หลายเดือนก่อน +2

      That property is what makes programming hard. Most humans are too limited in 'brain ram' to do that, so we should get mind chips already (unironically)

    • @bryede
      @bryede 10 หลายเดือนก่อน +8

      This is the kind of stuff you see in Atari 2600 cartridges, crazy compact code.

  • @nrnoble
    @nrnoble 3 หลายเดือนก่อน +1

    My computing days go back the late 70s so this video was fascinating to watch. I bought an Apple II+ in 1980 and used Wozmon a lot to learn how to program the 6502. Considering the lack of development tools at the time and how crude they were, imagine the amount of effort it took for Steve Wozniak to create Wozmon. Today I could write Wozmon using modern development tools, but even with such tools, I doubt I could code something that was as small as 256 bytes. In one of Wozniak's books, he wrote that he literally would hand-write code on paper in the form of Ones and Zeros. Hell, that is like The Matrix in terms of his mind works. :)

  • @gnpar
    @gnpar 10 หลายเดือนก่อน +29

    9:36 does anyone else love when Ben goes down the philosophical rabbit hole?

    • @mychemicaljojo
      @mychemicaljojo 10 หลายเดือนก่อน

      I’m glad this has been highlighted. After seeing the advancements that AlphaGo had on optimizing assembly for sorting functions, I’m glad Ben commented on it and drew the beautiful parallel to biological systems and their inherent coupling.

  • @HalfInt
    @HalfInt 10 หลายเดือนก่อน +7

    Not the content that wins TH-cam, but the content that feeds my brain, thus winning me. Thanks Ben!

  • @piyush9555
    @piyush9555 10 หลายเดือนก่อน +80

    Just made my own 8 bit computer (in Logisim) from your videos, I have no words how high quality your videos are, thank you Ben. Keep making quality videos 🎉, I love your channel ❤

    • @mashrien
      @mashrien 10 หลายเดือนก่อน +11

      Thank you for name dropping "logisim"- I had been wondering if there was such a program, and now that I have it, there's a whole world of circuit designs I can try before I actually build them out with physical circuits.
      Thank you so very much for your comment kind internet stranger ❤️

    • @piyush9555
      @piyush9555 10 หลายเดือนก่อน +4

      @@mashrien I kinda knew someone would find it really useful, I was thinking the same until I discovered it in another course about designing a cpu on udemy where he used that but I didn't take that course because Ben's is the best.

    • @mashrien
      @mashrien 10 หลายเดือนก่อน +2

      @@piyush9555 I didn't really realize Ben had a course anywhere but here on TH-cam

    • @portalwalker_
      @portalwalker_ 10 หลายเดือนก่อน +4

      I build one in Minecraft because of his videos

    • @piyush9555
      @piyush9555 10 หลายเดือนก่อน

      @@mashrien nope, it was some other guy

  • @BFLmouse
    @BFLmouse 10 หลายเดือนก่อน +23

    There's another nifty bit of optimization in there that had me confused for a bit.
    Just after XAMNEXT the code loads A from XAML and then compares it with L but the next two instructions load A from XAMH and subtracts H.
    The compare sets the flags as if a subtraction had been done, but then the SBC instruction overwrites those flag settings.
    I was confused as to why there was no branch instruction after the compare.
    Then I realized that the CMP instruction sets the carry flag if A >= L, and then the SBC instruction includes the carry in the subraction.
    It could have been done with two SBC instructions, but then the carry flag would have to be cleared before doing the first subtraction.
    Doing it this way saves an extra byte of code.

  • @Barquevious_Jackson
    @Barquevious_Jackson 10 หลายเดือนก่อน +6

    I was just randomly checking in on this channel and caught a video less then 30 minutes after dropping from someone who rarely uploads, absolutely insane! I've never had that happen!

  • @stompreaper
    @stompreaper 10 หลายเดือนก่อน +23

    Thanks for the walkthrough Ben. Extremely well executed and demonstrates how elegant this software is, the depth of talent that Woz has and how great an educator you are.
    I would love to see more of this kind of content. There is something about seeing elegant/efficient algorithms in assembly that really gets you thinking.
    In todays high level programming world you don’t see this a lot but it’s so valuable to look back and understand in order to look forward and design.

  • @chrisg6597
    @chrisg6597 10 หลายเดือนก่อน +36

    I started programming in assembler in the 1980's. Most of the code I wrote was space limited and like the code demonstrated here was written in a way with byte pinching (like using branch instead of jump instructions) stacked subroutines (Multiple entry but only one exit point) etc. When other programmers who have never had to write code with space restraints, looked at my code, I wasn't called a genius.... I was actually told that I program like a moron!

    • @johnm2012
      @johnm2012 10 หลายเดือนก่อน +3

      It's a fine line. I think a subroutine with three entry points and one RTS is fine, as is omitting the CLC before doing an ADC, as long as you add a comment that the carry flag is known at this point in the code. Some of the tricks seem a bit janky though - I particularly dislike the method of selecting the mode and would try to avoid it if at all possible.

    • @0LoneTech
      @0LoneTech 10 หลายเดือนก่อน +6

      Just call it tail call optimization.

    • @timsmith2525
      @timsmith2525 10 หลายเดือนก่อน +1

      @@0LoneTech Yes, pretentious terminology covers a multitude of sins.

    • @0LoneTech
      @0LoneTech 10 หลายเดือนก่อน +5

      @@timsmith2525 What sins? The terminology is there to mean something, in this case that we know the adjacent code chunks have distinct roles but connected program flow. A typical use might e.g. be if the ABI requires a large epilogue, factoring it out of your subroutines. It's a well known problem, to the degree that Intel added new instructions for it in the 80186. That the branching itself became as costly was a far later development, with deep pipelines and instruction caches.
      An example of such a common epilogue on 6502 is pushya in durexforth.asm.

    • @timsmith2525
      @timsmith2525 10 หลายเดือนก่อน +1

      @@0LoneTech "I was actually told that I program like a moron!" "Just call it tail call optimization." My point is that many people will judge things based on what they're called.
      Without a pretentious name, "three entry points and one RTS" is a bad practice; however, if you call it "tall call optimization", those same people will suddenly nod, and go, "Hmm…, Yes, tall call optimization."
      "The terminology is there to mean something." Not always: Sometimes it's there so people can sound important. Which is what I thought you meant when you implied that giving it a pretentious name will avoid the "moron" comments.

  • @CapteinObvious
    @CapteinObvious 10 หลายเดือนก่อน +1

    Brilliant work by both Wozniak and you, Ben. Your videos are always a treat.

  • @ast_rsk
    @ast_rsk 11 หลายเดือนก่อน +26

    This was an incredible deep dive! Thank you so much for this effort. I am learning so much and am finding a much deeper appreciation for what we have today and the people who helped get us there.

  • @DeepRockLabs
    @DeepRockLabs 9 หลายเดือนก่อน

    Love the way you break these things down and go through it all fully

  • @maixicek
    @maixicek 10 หลายเดือนก่อน +1

    Awesome code explanation Ben, thank you 🥰

  • @AuctorisVideo
    @AuctorisVideo 10 หลายเดือนก่อน

    This is an *excellent* video Ben. One of the best things that I've seen in a long time. Thankyou!

  • @peteregan9750
    @peteregan9750 10 หลายเดือนก่อน

    Keep it up BEN ! love your videos much more interesting and informative than most.

  • @jimcameron6803
    @jimcameron6803 10 หลายเดือนก่อน +24

    I was momentarily confused by the ADC #6 at the end, since the actual offset you need to add to print hex digits A-F as letters is 7, not 6. But then I realised that the carry flag would always be set at that point from the previous compare instruction. Just another memory-saving 6502 trick: why waste a whole byte clearing the carry flag when you can just add one less?

  • @ihuitson
    @ihuitson 10 หลายเดือนก่อน +6

    I hope Woz gets to watch this and would love to hear his take on the breakdown.

    • @rabidbigdog
      @rabidbigdog 10 หลายเดือนก่อน +1

      Please make it happen. A vid of Woz assembling the bread-board 6502?

  • @w2tty
    @w2tty 4 หลายเดือนก่อน +1

    Pure genius. Your explanation is amazing.

  • @m1geo
    @m1geo 10 หลายเดือนก่อน +1

    Nice one, Ben! Enjoyed that!

  • @MrFantom_
    @MrFantom_ 10 หลายเดือนก่อน +3

    I know it's gonna be a good day when Ben uploads, great video as always!

  • @tadeuszmic8338
    @tadeuszmic8338 10 หลายเดือนก่อน +1

    Sorry for my English.
    Interesting and simply explained monitor prog. Apple 1.
    I like Motorola's concept of microprocessors and especially the 6502. In 1988 I had a Commodore VIC-20 and did some assembly language programming.
    I like assembly language (6502 has a simple way) and I'm looking for solutions for 8-bit microcontrollers similar in programming, stm8s103f series....
    I also like the successors of the 8051, stc15fxxx.
    Steve Wozniak is of Polish origin and I am Polish.

  • @theobgshow
    @theobgshow 10 หลายเดือนก่อน

    Thank you. This is an amazing breakdown.

  • @BICIeCOMPUTERconGabriele
    @BICIeCOMPUTERconGabriele 10 หลายเดือนก่อน +6

    Very interesting as always, Ben! It will be funny if you contacte Apple customer support to ask for the wrong comment on the mode decoding, and then share their reaction!

    • @renakunisaki
      @renakunisaki 10 หลายเดือนก่อน +1

      Probably something like "support for this model is discontinued, please upgrade to the latest iMac for only $9999..."

    • @Ignisami
      @Ignisami 10 หลายเดือนก่อน

      As a former Advisor, you’d get an answer along the lines of ‘sorry but I can’t help you’. Advisors are barely informed that the terminal exists, something like this is essentially magic

  • @JoseSilveira-newhandleforYT
    @JoseSilveira-newhandleforYT 10 หลายเดือนก่อน +1

    Great code and great explanation! I had to pull my head a few decades back :-)

  • @PeteBagheera
    @PeteBagheera 10 หลายเดือนก่อน

    Most fascinating piece of code ever explained to me!

  • @mduvigneaud
    @mduvigneaud 10 หลายเดือนก่อน

    Ben, this was a really fantastic video. I really appreciate it. I've been early watching all of your videos for a while! :)

  • @corbin_zip
    @corbin_zip 10 หลายเดือนก่อน +2

    I really love this video. I've been looking for this sort of content for something like, let's say the early Pokemon games or Windows source code leaks and that sort of thing -- someone who knows what they're doing and has a knack for explaining these sorts of things. Thank you for all of your hard work and the phenomenal video!

    • @1Pandemoonium
      @1Pandemoonium 10 หลายเดือนก่อน +2

      pannenkoek2012 is pretty great, focused quite a bit around Super Mario 64.
      Recently discovered his video on crashing the game using the pendulum, super cool and nicely presented.

  • @amcluesent
    @amcluesent 10 หลายเดือนก่อน +2

    40 years ago I was quite happy coding in assembler!

    • @jdrukman
      @jdrukman 10 หลายเดือนก่อน

      I always say that assembly programming was like making a fully functional car out of only legos. The feeling when something finally worked was amazing. I don’t get that rush from modern programming.

  • @mpesava
    @mpesava 10 หลายเดือนก่อน +1

    I loved to code x86 asm back when I was young and I think I was quite good at it ... but this is brilliant! I can't imagine coding like this. Just WOW, Woz! ... a thanks for nice explanation @Ben

  • @anschelsc
    @anschelsc 10 หลายเดือนก่อน +12

    I always knew Steve Wozniak was a genius but it's fascinating to see it laid out like this. For a future video, have you considered trying to explain his famous hardware Breakout implementation?

  • @ferrreira
    @ferrreira 10 หลายเดือนก่อน +2

    I thought Rocco from Udemy was an amazing coding teacher, but you are just insane. Wow. I'd absolutely pay for your courses.

  • @scottlarson1548
    @scottlarson1548 10 หลายเดือนก่อน +5

    This takes me back to the days when I used a terrible 6502 disassembler that would always do _something_ no matter what you entered. Error checking would have required code, code would have required precious bytes, so it just didn't do that. Every character was a command and every command had at least one synonym because apparently it did bit operations and branched (or was it jump indirect?) on the bits. Since the character to store characters had synonyms, you had to be careful not to accidentally type one of them and unintentionally store a byte: for example instead of printing _x_ bytes starting at a location, accidentally typing a store command would store _x_ at that location. UGH.

    • @toby9999
      @toby9999 10 หลายเดือนก่อน +2

      I couldn't find anything decent at the time so I wrote my own machine code monitor for the 6502. I didn't have an assembler. Everything was in hex.

  • @jenselstner5527
    @jenselstner5527 10 หลายเดือนก่อน

    What a joy-ride. thanks a lot.

  • @Pythoman
    @Pythoman 10 หลายเดือนก่อน

    Thank you for the great contents. I learnt alot from your channel

  • @johnathanasiou9284
    @johnathanasiou9284 10 หลายเดือนก่อน

    Appreciate the walkthrough Ben & have forgotten a lot of the machine code concepts I studied as a kid & in early college.
    You're an amazing explainer & although I worked more on Z80 assembly the dependencies many of us did way back when were more or less the norm as memory was super expensive (even > 64kB was thought of as "page memory" for those rich enough to afford it) so saving storage was key, especially when coding assembly code on paper via hexadecimal.
    Had coded a rudimentary version of Frogger on the Z80 based Exidy Sorcerer at school with a buddy & it took us ages to create it, but we wanted a solution as spending a fortune on 20c coins was expensive (one could get a pie or bag of lollies with 20c).
    Never got to code in Wozmon but remember the Sorcerer had a similar hex monitor when you removed the BASIC ROM pack cartridge.
    When I got to college & worked with MASM & the MPF-1 Micro-Professor & saw how much easier it was to have a proper assembler it was far easier to create cleaner code with far less stress.
    It is amazing what Wozniak was able to create as a young engineer.
    Appreciate your efforts on everything you've been showcasing & God bless

  • @ecosta
    @ecosta 9 หลายเดือนก่อน

    I love the simplicity of Ben's explaining such an elegant design from old times. Really makes me think if we actually need all of those abstractions we forced ourselves into nowadays.

  • @spit75d
    @spit75d 10 หลายเดือนก่อน +1

    Incredibly elegant code. Woz is the man!

  • @etmax1
    @etmax1 หลายเดือนก่อน

    Very well explained, Woz was very skilled 🙂

  • @fortytwo8388
    @fortytwo8388 10 หลายเดือนก่อน

    thanks for the video. It brings me back to high school when we did learn to code on the Apple II

  • @PixelBrushArt
    @PixelBrushArt 10 หลายเดือนก่อน

    Amazing stuff!

  • @skatcat743
    @skatcat743 9 หลายเดือนก่อน

    absolutely fascinating.

  • @PeranMe
    @PeranMe 10 หลายเดือนก่อน +5

    Thanks so much, a video on wozmon has been at the top of my wishlist for SOO long, both because so many old toads like myself rave about it, but also because Woz himself seems an interesting guy! Frankly, the only reason I haven’t pestered you about it before was because of a dream of finding the free time to make a video like this myself! But it would never have been as good as your work, so luckily for everyone you beat me to it! :-) Again thanks, you’re a star!!

  • @lightdark00
    @lightdark00 10 หลายเดือนก่อน +1

    Thank you for trying to win youtube like this.

  • @bytesandbikes
    @bytesandbikes 10 หลายเดือนก่อน +1

    Thank you for this walk through this maze. Can't decide if it's mad or genius. Probably both!

  • @n2n8sda
    @n2n8sda 4 หลายเดือนก่อน

    Great video, never really looked at the wozmon code before.. That initial setup so that after initialization of the hardware after a reset the register value is negative so triggers an escape character sequence and a further initialization to 0 is just so efficiently sublime.
    It's been 30 years or more since I wrote assembly somewhat full time, I like to think assembly by default is more refined than most high level languages but I'll admit that I never got close to that refined.

  • @jeromethiel4323
    @jeromethiel4323 10 หลายเดือนก่อน +14

    Wozniac was extremely good at machine programming. That's the only reason the Apple ][ was able to do so much with so little. Extremely efficient code. Same thing with the Apple disk drives. Extremely simple, and yet it all works, thanks to extremely tight machine code. The Woz could program the metal so extremely well, it isn't funny.
    As someone who had (in my early days) to hand assemble 6502 code for the Apple ][+, i appreciate tight coding. I was watching to see if there was anything that i could improve in that code, and am happy to say i can't see a single instance where i could shave even a byte off of that code. 248 bytes is crazy small for as much as the Wozmon does.
    Heck, the mini assembler from the integer basic was also amazing.

    • @mojoblues66
      @mojoblues66 10 หลายเดือนก่อน

      Back in the early 80s I always wondered how that mini disassembler worked, perhaps Ben can make a deep dive into that as well!

  • @stephendanieldrums
    @stephendanieldrums 10 หลายเดือนก่อน

    A lot "clicked" for me on the last 2 videos. Been working on compiling some NES roms with 6502 assembly, and this really is similar to the how the APU and PPU registers work. This is just a little bit less abstract, as WOZMON is, in itself, a controller. The optimizations and dependencies really highlight some logic ideas that were still foreign to my brain. Thanks for the great content!

  • @blackpanda3771
    @blackpanda3771 10 หลายเดือนก่อน

    Like Always Great Video ive never learned AS much from TH-cam then in your vids

  • @Fifty1Ford
    @Fifty1Ford 11 หลายเดือนก่อน +10

    This is Great! Thanks for the deep dive! I feel smarter already. But also somehow dumber... Woz really produced with the APPLE 1 and 2.

  • @TheZ0dMan
    @TheZ0dMan 10 หลายเดือนก่อน

    Ahh the finer details of assembly programming, a lost art in my onion. Watching this video reminds me of when I was doing embedded programming with the HD64180 in the late 80's. Thanks for a trip down memory late and a great video!

    • @davidmartensson273
      @davidmartensson273 10 หลายเดือนก่อน

      Lost, but also obsolete since as they said, modern programs have so much features that you would not be able to optimize this way without making it impossible to change and you would likely end up with many edge case bugs, and of cause, you would never ever finish a program.
      Offloading the assembly level to the compiler for all but maybe some tiny, super optimized, parts allows for bigger programs.
      While I never did much assembly programming I did a lot of turbo pascal where I also used a lot of "clever" solutions to speed up screen handling and not only did it make the program some 2000 times faster than relying on the normal IO libraries, it also made the resulting program much smaller since turbo pascal used a compiler that removed unused parts of any module you included.
      It was never even close to this amazing but still, I would never try to do anything similar again, maintaining and extending that code was a beast.

  • @OscarSommerbo
    @OscarSommerbo 10 หลายเดือนก่อน +7

    There are some clever bits in it to save on bytes, but it is rather straight forward 6502 assembly with some fairly standard tricks. BUT I assume Woz probably had to invent a lot of it to fit the monitor into 256 bytes.

    • @TonyHammitt
      @TonyHammitt 10 หลายเดือนก่อน +12

      Yeah, they're standard tricks NOW :) Coming up with what will become the future's standard tricks is indeed the tricky part!

    • @johnm2012
      @johnm2012 10 หลายเดือนก่อน +4

      While watching the video I wondered how much experience Woz had had with the 6502 at the time he wrote this and how long it took him to write, debug and shoehorn into a single page.

  • @pmanolak
    @pmanolak 10 หลายเดือนก่อน +1

    Ben without doubt, you deserve to teach on MIT!!!

  • @viniciusfriasaleite8016
    @viniciusfriasaleite8016 10 หลายเดือนก่อน

    Really impressive!!

  • @jrioublanc
    @jrioublanc 10 หลายเดือนก่อน

    Very interesting, thank you.

  • @wherami
    @wherami 10 หลายเดือนก่อน +1

    Your channel made me try to learn assembly

  • @Artixou
    @Artixou 10 หลายเดือนก่อน +1

    Rewriting this for my own CPU I made in verilog, so this is useful ;)

  • @johnbrooks2564
    @johnbrooks2564 10 หลายเดือนก่อน +5

    There are other incorrect comments in Woz's code. ASL cannot generate an odd number, so the comment of $7B for STOR is incorrect. My guess is that Woz's comments are from an earlier version of WozMon which used the '=' character for STOR mode. If Woz's earlier version used ROR of '=' with carry set (instead of ASL ':') it would result in a $7B mode as described by the comment.

  • @BryantBrothers-gm1qx
    @BryantBrothers-gm1qx 10 หลายเดือนก่อน

    I have absolutely no idea what you are talking about or most of the comments but it sounds VERY interesting and ive always been amazed about how computers actually WORK so thanks for the upload!!!

  • @alanmartin9207
    @alanmartin9207 10 หลายเดือนก่อน

    Back in the early 80s when I was learning 6502 on an ITT 2020 and then an Apple II, as a total beginner I found Wozniak's Sweet16 extremely useful. Another one of his little coding miracles, using only a few hundred bytes.

  • @Rx7man
    @Rx7man 10 หลายเดือนก่อน +2

    Some great ideas put to practice here for code optimization, like the "falling through" of the functions into the next and only one return especially. A lot of these aren't good for code readability and you wouldn't want megabytes of program written this way, but for 248 bytes it works just fine
    Look up the speech "Art of code" by Dylan Beattie, He talks about some amazing code and is very easy to listen to

  • @suncrafterspielt9479
    @suncrafterspielt9479 10 หลายเดือนก่อน

    great deep dive

  • @StefanoBorini
    @StefanoBorini 10 หลายเดือนก่อน +39

    This is were the good old times when you did not need no stinking structured programming. You squeezed every byte of machine memory and every CPU cycle and it was glorious.

  • @willynebula6193
    @willynebula6193 10 หลายเดือนก่อน

    Simply awesome

  • @davidjbergman
    @davidjbergman 10 หลายเดือนก่อน +1

    Thanks!

  • @johnnycrash1624
    @johnnycrash1624 10 หลายเดือนก่อน +9

    Wait... the value for store mode comes from a left shift on BA, the colon character. But that results in 74, not 7B. Am I missing something or is that another mistake? Doesn't matter cause it only checks the top two bits, but that had me confused.

    • @0LoneTech
      @0LoneTech 10 หลายเดือนก่อน +1

      I think you're right. Interestingly, 7b would be correct if we were rotating in a 1 and the character was = (equals) instead of : (colon); my guess is the command was changed at some point, probably to match the printout. I don't think it's a simple typo because it is repeated.

    • @BenEater
      @BenEater  10 หลายเดือนก่อน +6

      Yeah, it looks like another typo in the comments. It's actually 74 and you're right that it doesn't matter.

    • @johnm2012
      @johnm2012 10 หลายเดือนก่อน

      I've always been puzzled by the mnemonic used for the 6502's shift left operation. Surely LSL would make much more sense.

    • @0LoneTech
      @0LoneTech 10 หลายเดือนก่อน +1

      @@johnm2012 It's likely inherited from some other processor, e.g. 6800 which is slightly older and has ASL/ASR/LSR/ROL/ROR.

    • @johnm2012
      @johnm2012 10 หลายเดือนก่อน

      @@0LoneTech That would make some sense, though I would still wonder why ASL was chosen as the mnemonic for the 6800 instead of LSL.

  • @KindStarWonder
    @KindStarWonder 10 หลายเดือนก่อน

    Thank you!

  • @michaelkaercher
    @michaelkaercher 10 หลายเดือนก่อน

    I worked through the code a couple of month ago but I max understood 60%. Cool explaination.

  • @rulojuka
    @rulojuka 10 หลายเดือนก่อน +2

    24:33 I am pretty sure you can send him an errata and we will post you a check for 2.56 dollars! Oops, maybe this is another programmer!
    Wonderful video, as always!

    • @kellyfrench
      @kellyfrench 10 หลายเดือนก่อน

      You are thinking of Donald Knuth and The Art of Computer Programming.

  • @flethe1555
    @flethe1555 10 หลายเดือนก่อน

    we love you Ben Eater

  • @davidhand9721
    @davidhand9721 5 หลายเดือนก่อน

    So many brilliant tricks that rely on a total understanding of the instruction set. If you don't keep track of how each instruction affects the flags, you can forget about making sense of this code. This is the kind of elegance that, thankfully, programmers don't need anymore. In fact, it's very much frowned upon to write code that relies on a reader knowing _any_ context.

  • @StevenHokins
    @StevenHokins 10 หลายเดือนก่อน

    Good in depth walkthrought

  • @eternaldoorman5228
    @eternaldoorman5228 10 หลายเดือนก่อน +2

    That was really interesting, thanks! That last print routine reminds me of an interview question I got asked at a company (now defunct) called Harlequin who had a PostScript(TM) compatible interpreter that they sold to various people. They used a lot of optimizations using something called "Duff's device" which I'd never heard of before. The idea is just that you can often unroll loops (in C code) and it makes them a little faster because you can have, say four iterations sequentially and you avoid having to do the comparison and branch for the first three. Of course that only works for loops which are a multiple of four, but you can get around that by wrapping the body in a case statement and the first time you enter the loop you check the number of iterations mod 4 and branch into the body of the loop to do n+4m iterations. The thing I learned at that interview was that C case statement is effectively just a bunch of labelled gotos and that you can write C code that looks like it should be a syntax error but it works!!!

    • @anon_y_mousse
      @anon_y_mousse 10 หลายเดือนก่อน +1

      C compilers generate jump tables for switch statements. So the whole point of Duff's device was to jump into an offset that allowed it to do the last few operations which weren't an exact match to the number of operations done per loop because branching has always been really costly, so instead of copying one element at a time, they would count down N at a time, usually 8 but not always, and the tail would be accounted for by jumping to the point where only that amount of operations would be done to finish the last loop.

  • @prestonzaras6175
    @prestonzaras6175 10 หลายเดือนก่อน

    Hey Ben Eater! I’ve recently gotten a FLIR one thermal imaging camera for my phone and I’m trying to figure out how to interface it with a raspberry pi! Im pretty new to electronics but I love your videos and would love to get my hands dirty and learn a bunch new info along the way! Much thanks and keep up the good work!

  • @joebates93
    @joebates93 10 หลายเดือนก่อน

    I'm so glad you exist

  • @soranuareane
    @soranuareane 10 หลายเดือนก่อน +6

    Regarding your critique from the guise of a 21st century programmer at around 8:45, I'll add my own two cents: the abstraction flood seems standard (to me) for heavily-optimized code. If you look at the output of any modern compiler with optimization enabled, the resulting assembly is full of these strange "huh... that's... one way to do it" constructs.
    I'm willing to bet this code went through several dozen (if not more) revisions to get it to fit in a single page of memory.

  • @Tinker001
    @Tinker001 10 หลายเดือนก่อน

    Dangit Ben!
    Thanks for half an hour of pure nostalgia.
    & reminding me how old I am. :P

  • @cheeseparis1
    @cheeseparis1 10 หลายเดือนก่อน

    09:46 I was so looking forward to seeing you inspect 0200-027F !

  • @AzureLazuline
    @AzureLazuline 10 หลายเดือนก่อน

    this code is arcane! I understood all the hacks as you explained them, but i still can't believe it. I did SNES assembly as a kid, and i definitely don't miss having to debug crap like this.
    this reminds me of Exapunks, a game where you program in assembly code too. All the top scores on the leaderboard (for execution time and for number of bytes) are all like this, it's nuts! Anyone who's watching videos like this, you'd probably like Exapunks, go check it out 😄

  • @anon_y_mousse
    @anon_y_mousse 10 หลายเดือนก่อน +1

    Next thing you know, you'll be incorporating a disk drive to store programs and writing an operating system. Maybe you could even network multiple 6502 breadboard computers and make a super computer. Then you could write a program to compute pi in parallel and see if you could beat some old 80's era records for generating digits of pi. That would be fun.

  • @jan_phd
    @jan_phd 10 หลายเดือนก่อน

    The 6502 was my favorite processor. My first A.I. was written by me, in this nomenclature.

  • @der.Schtefan
    @der.Schtefan 10 หลายเดือนก่อน

    Oh, I am pretty sure THIS is the kind of content that wins 8-bit TH-cam :) Btw, if you get another 256 bytes, I am sure you can add a lot of more features, for instance checking if a pin (button) is pushed during NMI, and break into WozMon, great for debugging. The C64 did allow similar things, where RUN/STOP being pushed while RESTORE button (mapped to NMI) was hit, would break you into BASIC, or any machine monitor if you set up your assember right (eg. TMP, or TMP+REU). You could go even so far to allow reprogramming or flashing via RS-232

  • @willofirony
    @willofirony 10 หลายเดือนก่อน +1

    Code like this was meat and veg to a programmer back in the late seventies. The carefree treatment of dependencies was due to the fact that literality nothing else was happening in this computer. The various state indicators will have been put into a known state by the first piece of code, the reset. Even in a monitor that enabled the developer to run code outside the monitor, the break routine would save all the registers and flags in a buffer (which usually would be echoed to the display). When the developer had finished examining that data, a key press would just restore the registers and using a copy of the PC on the stack, the monitor would "return" to the program being examined. In the days of single thread, cacheless CPUs with very little RAM, the Monitor/system developer owned every byte of the computer. BTW, the tricky coding, especially on Z80 (which had more bytes to many ops) it was not unknown to JSR INTO the bytes of an op code to "overload" a routine!

  • @donnyofdoom1873
    @donnyofdoom1873 10 หลายเดือนก่อน +1

    This really makes me want to go back and play Exapunks again

  • @KingDuken
    @KingDuken 10 หลายเดือนก่อน +1

    Triggering some memories from college on Assembly. As a computer engineer myself, I say that I probably take C++ for granted. I almost forgot how holistic Assembly is with hardware.

  • @roelandriemens
    @roelandriemens 10 หลายเดือนก่อน +3

    Thanks Ben for the deep dive into Wozmon. I have a problem with my contentration due to Long Covid, but this I can understand completely. Inspired by your clear tutorials I hope to build a 6502 board myself somewhere in near the future when my energy comes back.

    • @OurSpaceshipEarth
      @OurSpaceshipEarth 3 หลายเดือนก่อน +1

      Inspiring, don't ever give up on yourr drreams, even if you have to reschedule them, again.. ;]

    • @roelandriemens
      @roelandriemens 3 หลายเดือนก่อน

      @@OurSpaceshipEarth Thanks.

  • @badcat4502
    @badcat4502 10 หลายเดือนก่อน

    Ouu yeah, a new video I wont understand but I will love to investigate

  • @pwlegolas3
    @pwlegolas3 2 หลายเดือนก่อน +1

    Thanks Ben ! This is so awesome and bare metal. I feel the old ways of coding were so neat and direct . If one understands such implementation details while programming , it really feels like you're programming . These days there are so many abstraction levels (interpreting scripts/codes) between the user and the machine , it doesn't even feel like you're programming any more . 90% of your job is done by libraries when you write a code.

  • @CosmicAerospace
    @CosmicAerospace 10 หลายเดือนก่อน +1

    "Babe, wake up, Ben just uploaded a new video"

  • @kaizen9451
    @kaizen9451 10 หลายเดือนก่อน +3

    Rumours are if you create a recursive infinite loop with wozcode, woz himself appears and bonks you on the head with an original apple II for not having better exit conditions.

  • @EsmaelM-ze8nk
    @EsmaelM-ze8nk 8 หลายเดือนก่อน

    I never attend such kind of tutor in my life. ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤