Coding Graphics in C: SetPixel, LineDraw, Moire and More!

  Рет қаралды 133,039

Dave's Garage

Dave's Garage

Жыл бұрын

Dave takes you on a tour of the C code used to write graphics primitives for the ancient Commodore KIM-1 computer. See how setpixel, linedraw, and more are implemented from first principles.

Пікірлер: 283
@licksorestockpile1190
@licksorestockpile1190 Жыл бұрын
You should definitely do more things like this with how programming works
@milk-it
@milk-it Жыл бұрын
Couldn’t agree more. I especially liked the other videos Dave had on C and Assembly. 10-20 mins like this on one relatively simple program gives me lots of practice material to learn from.
@licksorestockpile1190
@licksorestockpile1190 Жыл бұрын
@@milk-it no doubt. would also like to learn more about how the magic compiler turns if statements into actual bits that get fed into the cpu
@thisisreallyme3130
@thisisreallyme3130 Жыл бұрын
Agreed! So happy to see this type of low level coverage
@Railur
@Railur Жыл бұрын
@@milk-it This video is like "coding from the scratch". The times when developers had to code their graphics drivers on their own are gone. Nowadays, software engineering is not about the basics, but about much more abstract topics like portability, reliability, security and so on on that ground of primitive hardware based drivers.
@milk-it
@milk-it Жыл бұрын
@@Railur Good point. That's why so many apps look and feel the same nowadays.
@jamesclark2663
@jamesclark2663 Жыл бұрын
This brings back a lot of memories. It was like 2000 or 2001 and I was learning C using books and a compiler written in the 80s! (Borland Turbo C/C++ 1.1) I still have a great sense of nostalgia for that blue background with chunky yellow text and seeing functions written in that glorious font with pointers that poke and peek directly into memory and occasionally prodding hardware registers brings back some fond memories. Thanks , Dave!
@NeilRoy
@NeilRoy Жыл бұрын
Wow, that was really close to when I was doing the same thing, except I found DJGPP, the GNU 32bit DOS compiler, which was used to make Quake as well. Definitely brings back memories for me as well! Loved coding my own graphics like this, and the GNU compiler made it so much easier as you didn't have to worry about things like long jumps, memory boundaries etc... DJGPP handled all that for you.
@jamesclark2663
@jamesclark2663 Жыл бұрын
@@NeilRoy Ha, yeah! I discovered DJGPP a year or so later. It really opened up a lot of options since I was no longer limited to a measly 640k of RAM. Though I think it came at the cost of operating in protected mode which meant you couldn't quite access memory with the same directness as before.
@emmanuelbeaucage4461
@emmanuelbeaucage4461 Жыл бұрын
same but the 90s!
@emmanuelbeaucage4461
@emmanuelbeaucage4461 Жыл бұрын
TurboC! i remember using it from 1.0 up to a german 3.7 version!
@idjles
@idjles Жыл бұрын
Get off my lawn. This takes me back to 1981.
@drewlarson65
@drewlarson65 Жыл бұрын
Your fluency with bit-shifting and boolean is mesmerizing; a master-class video from you would be solid gold.
@Byynx
@Byynx 11 ай бұрын
That idea may be logic but i don't think he has the skills to be a good teacher. Just because we know something that doesn't makes us smart to teach it.
@scififan698
@scififan698 9 ай бұрын
That's really very basic stuff. Bit tricks go a lot further than this in the real world, it's a heap of fun! Just as an exercise for you: try to think of a way to swap two variables without using a temporary variable, but by just using bit operations. Or have a look at a fast bitcount, etc.
@greg4367
@greg4367 Жыл бұрын
Greetings from San Francisco. I thought there were no time machines, but you just brought me back to 1979. I loved it the first time around, and I'm (almost) ready to break out my Poly88 with a Cromemco Dazzler and write code along with you. Almost... but sanity prevailed. Dave, you are a BAD influence. I can't wait for your next stroll through my faded youth.
@mfkman
@mfkman Жыл бұрын
I remember implementing the Bresenham circle algorithm in assembly and also figuring out the math behind it when I was in 8th or 9th grade where I had just learnt the the Pythagorean theorem. It was so awesome :)
@rdwells
@rdwells Жыл бұрын
You can speed up that Bresenham's implementation considerably by avoiding calls to SETPIXEL. Instead, translate the x,y starting point to a byte address and a mask (as done within SETPIXEL), and within the loop, treat x moves as shifts of that mask (adding/subtracting one to the byte offset if the mask becomes 0), and treat y moves as adjustments (add/subtract BYTESPERROW) of the byte address. Back in the day (circa 1985 with an EGA/VGA adapter on a PC running MS-DOS) I had an assembly language Bresenham's that was nearly as fast as a NEC 7220 based board. Also, for a lot of applications (I was doing CAD work at the time), it is well worth the minimal effort to optimize horizontal and vertical lines.
@hrayz
@hrayz Жыл бұрын
Back on my CGA machine I was doing just that. I started with a setpixel (ASM inside of C code). That was about 200x faster than the built in command.. I started with this level of simple line command, setting every pixel of the line. Then improved it with a look at how many bits in a byte are set and did them all at once. Fun times!!
@greenaum
@greenaum Жыл бұрын
@@hrayz Yeah, BGI, Borland's graphics library, was useless. It was nice and compatible, but useless in terms of speed. And couldn't access MCGA / 256-colour mode. Better to just set a big pointer to graphics RAM and do it yourself.
@mp-kq3vc
@mp-kq3vc Жыл бұрын
More C programming please. Love it!
@NeilRoy
@NeilRoy Жыл бұрын
Loved this! Man, this takes me back. I still prefer to program in C (not C++) to this day, usually using a GNU compiler which supports the newer versions of C. I remember programming graphics in DOS on my old computer in the 1990s. I wrote my own graphics library much like you have here by accessing A000 etc... as I learned I added more functions to it for lines, some optimized functions for straight lines (I think that used memset commands to set larger amounts at once). I loved those days and the fact that it wasn't done for you. I created a free game called Deluxe Pacman 1 & 2 for DOS, older Windows and modern Windows (last tested on Windows 10) and it is coded entirely using C (no plusses), only it uses the Allegro library (I honestly wish I had done it entirely on my own and never used a library). Good times anyhow. Oh, and I used to use DJGPP for DOS back then, it handled the memory limitations for you, so no worries about things like long jumps and the like. I believe Quake was written with it. Very nice.
@koftabalady
@koftabalady 8 ай бұрын
This is so cool. I always wonder how did you guys learn these things, I really love low level programming but I don't understand it that much.
@TheRojo387
@TheRojo387 5 ай бұрын
I'm trying to learn what you did to write Pacman, but my graphics library will be entirely vector-based, so no more of those yucky antialiased jagged textures, and made especially for SVGA. I'm doing this for my own optical engine, then onto the FI and POST for my homemade operating system Chiplock, and then for what's known as a GCLI, which is just a regular CLI with graphical elements included to create a sense of immersion. It would have also been handy if CRT monitors were still common.
@jamesross1003
@jamesross1003 Жыл бұрын
This reminds me so much of when I was a kid programming different early machines that did not have any built in graphics like the early Atari and TRS80. I love it, please make more videos like this one. Thank you very much.
@ILostMyOreos
@ILostMyOreos Жыл бұрын
Great video!! I never have to touch low-level programming in my line of work but as time goes on in deepening my appreciation for this technology and the people who both understand it and are willing to share it. Everything is built on top of this! Incredible!
@jeffsimkowski4907
@jeffsimkowski4907 Жыл бұрын
That was awesome! I remember doing this in the early 80's. I have a lot of nostalgia for this and sometimes actually miss it, if you can believe that! More please!
@chrisdixon5241
@chrisdixon5241 Жыл бұрын
Hi Dave, thanks for the great video! This takes me back to my C64 days. You're absolutely right about the bit pattern for the characters being right to left on a left to right ordered screen memory. Though I never even gave it a second thought at the time, it just made sense since it was writing a byte to memory and that's the order of the bits for a 6502/6510
@DavidtheSwarfer
@DavidtheSwarfer Жыл бұрын
A few years ago I wrote a graphics primitive library for Arduino driving a 20*10RGB led array. This was used in a series of digital art workshops as part of our National Arts Festival. The best of the art was later displayed on our huge Rgb periodic table display. Each element was about 6x6” . Since the pixels were wired in an odd order I created a translation table to translate x/y to pixel number. Fun times.
@buttforce4208
@buttforce4208 11 ай бұрын
Really love this Dave! It's so great to draw some wisdom from the older generation of programmers. I'm continually amazed at the kind of fundamentals you develop if you don't spend all your day debugging yaml templating
@TheFuture36520
@TheFuture36520 5 ай бұрын
You're my hero 💙 and all I have been looking for. Finally now I have a tutorial guide for the idea behind how graphics were designed and implemented.
@IdleG00SE
@IdleG00SE Жыл бұрын
This is great. I recently wrote my own graphics API using similar algorithms. I will have to add Moire! Thank you for your channel.
@MattLozier314
@MattLozier314 Жыл бұрын
Dave, this was super-cool! Thank you so much for posting this video. Yes, would love to see more content like this. Cheers!
@airjuri
@airjuri Жыл бұрын
I'm glad that i took hard copy of my gfx library back in mid 90's. After HDD crash it would have been gone otherwise. "beautiful" C and assembler code in actual paper made by bit over twenty years old Airjuri. :D It has filled polygon, bresenham line, -circle and some screen fading effects. Off course all optimized for 320x200 screen. I should probably finish that game project i started back then ;)
@alphabasic1759
@alphabasic1759 2 күн бұрын
I remember doing this kind of programming for the PC before windows came out. Sound drivers too… fun times. Blew up a monitor or two.
@EndlessEnergy
@EndlessEnergy Жыл бұрын
Great video, it's always great to take a stroll through low level land and look under the hood. We take a lot of modern libraries for granted!
@JPEaglesandKatz
@JPEaglesandKatz Жыл бұрын
Ah brings back memories getting into assembly on my 6502 atari 800 xl back in 1981 or something... Still up till this day, 40 years later one of the most satisfying periods in my life :P
@lunam9172
@lunam9172 Жыл бұрын
This C stuff is so great to watch it was a simpler time, but at the same time more complicated (?)
@fburton8
@fburton8 Жыл бұрын
Happy memories of designing a tiny antialiased font to draw text in 256 color SuperVGA. It was for a simple GUI to acquire and show CCD camera data for use in an electrophysiology lab (looking at calcium transients in cells using calcium-sensitive fluorescent dye). Somehow there was enough room on the screen to display the image frame, a histogram and a control panel at the same time. The advantage of whatever mode I used was it had square pixels (so the image frame wasn't distorted) and there were enough colors to represent the range of intensity values coming in from the camera. If I remember right, it was a variable width font with maximum width 6 pixels and a height of 9 pixels. The manual 'antialiasing' was two-tone.
@flywittzbeats4008
@flywittzbeats4008 Жыл бұрын
I’m a beginner but still so interested in low level programming. This is amazing! I feel like C is such an awesome first language
@derekchristenson5711
@derekchristenson5711 9 ай бұрын
I'm surprised how simple this code looks, despite the fact that it's so low-level. Very interesting!
@ross825
@ross825 Жыл бұрын
That display is beautiful. I love old graphics
@StefanHolmes
@StefanHolmes Жыл бұрын
Really enjoyed this one. I am somewhat in the middle of working out how to render text to the C64 bitmap display, so this was a handy video.
@bitmanagent67
@bitmanagent67 2 ай бұрын
It brings me back to the good old days when the bar was low regarding customer expectations, and it was easy to impress people. Even yourself.
@sofiaknyazeva
@sofiaknyazeva Жыл бұрын
This is amazing! It also shows up how in previous a programmer have to think twice before using a single byte otherwise they may run out of volatile memory. The code was clean and explanation wad on point. Really great work!
@nicolaskeroack7860
@nicolaskeroack7860 Жыл бұрын
Why you don't say ram instead of volatile memory? Anyway agreed
@TheGoodChap
@TheGoodChap Жыл бұрын
It's cool because I always knew how font code in terminals technically works and probably could write it myself but its just cool to see it. I never really knew where that code actually exists in Linux whether it's a library function or something in BASH. It's such a basic thing to draw ascii it just feels like one of those things that's so rudimentary yet important that i don't even know where to find it
@_Stin_
@_Stin_ Жыл бұрын
Assembler gets my vote :) Thank you, Dave!
@christopherguy1217
@christopherguy1217 Жыл бұрын
That takes me back to programming on a VGA in assembler. I remember wishing I could do it in C.
@muddyexport5639
@muddyexport5639 Жыл бұрын
Excellent. Please continue professor...
@brianjuergensmeyer8809
@brianjuergensmeyer8809 Жыл бұрын
I love the fact that you are probably going to be the only human on this planet running this code, but you still have sanity checks to ensure that you're not going outside of screen memory. The force of habit from a person who has had to reflexively sanitize inputs his entire life.
@randallgreen4084
@randallgreen4084 Жыл бұрын
Love you explanations, so easy to understand.
@makethingsbetter
@makethingsbetter Жыл бұрын
Thanks Dave, it really is quite nice to receive a master lesson on such simple graphics outputs. Reminds me of learning Fortran over a night shift so that I could modify a shift trivia quiz to include a graphical image, using ascii characters. Amazing what you learn when you need it! Writing Trev wins with an image of a winners cup, no matter who wins, was the result I famously added to the code! Take that A-shift! Hahaha 🤣
@MePeterNicholls
@MePeterNicholls Жыл бұрын
I used to love creating my own character graphics on bbc basic. I’d have loads of 8x8 graph paper doodles then calculate the byte for each line. I was 8.
@SeriesTube01
@SeriesTube01 Жыл бұрын
I'm learning Spring Boot and Java, a real programming language as many people say, not like JavaScript. I found out Java was based on C. So many things worked thanks to C, it's incredible. I also just found out your channel, it looks very interesting. Keep it up. 👏👏👏
@jeffgrill4612
@jeffgrill4612 Жыл бұрын
Dave, enjoy your podcast. Would like to see you interview the folks who made up the team that created the 6502.
@MattLozier314
@MattLozier314 Жыл бұрын
I would be interested in this as well!
@ajisam61
@ajisam61 Жыл бұрын
excellent, expect more things like this, thank you
@vrmech
@vrmech Жыл бұрын
That reminds me of the first games I tried to make in high school. Going from amiga to a PC, playing with power basic and int 13h screen modes. How you could swap between 2 screen buffers to not see the screen flicker during updates. It was cool how drawing triangles, and fill routines worked. Reading code from dr.dobbs journal in asm.
@James-fo8rf
@James-fo8rf Жыл бұрын
As someone with little programming knowledge this video is really good.
@oliverw.douglas285
@oliverw.douglas285 Жыл бұрын
Nice tutorial short & to the point.
@tantumDicoQuodCogito
@tantumDicoQuodCogito Жыл бұрын
Yes, I remember my first challenger in programming when I was teenager and was to create a line function, no internet, no books. Then next challenger was a painting function, seriously very complex for me and more easy was to create a draw circle or ellipse function, only play with sines and cosines.
@d.h.y
@d.h.y Жыл бұрын
Thank you sir. You are a living library.
@Matthew_080
@Matthew_080 Жыл бұрын
You're very talented. This video is great
@GreenAppelPie
@GreenAppelPie Жыл бұрын
I’ll absolutely take more of this. I’d like to see code for capturing mouse and keyboard input.
@bobfarker4001
@bobfarker4001 Жыл бұрын
Idk how to do it from scratch but There are functions for that in the windows library. GetAsyncKeyState will capture keys(even when the program is minimized).
@puppergump4117
@puppergump4117 Жыл бұрын
@@bobfarker4001 Well it doesn't matter if the program is minimized unless you have focus checks or you wait event. Peek event or no window / draw loop at all will just make the program work in the background. I made a little keylogger like that, forgot about it for awhile and checked the file later only to see me trash talking people in tf2.
@bobfarker4001
@bobfarker4001 Жыл бұрын
@@puppergump4117 LOL. it is funny when you look at your own logs. I've made several keyloggers, some email some save locally. If you're email that is doing the logging gets hacked you're fucked.
@brocktechnology
@brocktechnology Жыл бұрын
Taking in stuff that's over your head is the first step to raising your head so time well spent.
@DL-mk4mz
@DL-mk4mz Жыл бұрын
Dave, would you be willing to do a programming series? I'm talking about all programming languages, from the ground up, at least the basics. I need that, and I'd bet others do too. You explain things better than most.
@andrewduncan1217
@andrewduncan1217 9 ай бұрын
I started using C for direct screen graphics in the DOS days using interrupt 10 to set VESA video modes. There day I still enjoy writing directly to the screen using C++ and the frame buffer and more recently drm/kms on Linux.
@franciscovarela7127
@franciscovarela7127 11 ай бұрын
Thanks for the memories.
@nils-kopal
@nils-kopal Жыл бұрын
Hey Dave, Very cool! Love the KIM-1 drawing some cool stuff. Some ideas for next videos: - Since you now have the Commodore start screen, implement BASIC 🙂 - Let it draw the Mandelbrot set 🙂 - Port a C64 game to the KIM-1. Probably an "easy" one, without sprites... OR, implement you own game... e.g. Tetris 🙂 Keep up the cool videos, especially about Commodore stuff and the KIM-1. Greetings from Germany, Nils
@technowey
@technowey Жыл бұрын
Hi. Great video. Every video I've ever seen you make is a great video. I wrote a line-draw algorithm using Bresnahan's algorithm, which is faster than the most modern line-drawing algorithm. I used system functions to draw text. I might rewrite that to make the text code more portable. At 3:22, you said the 127 was for the leftmost pixel and 1 was the rightmost pixel. I think you meant 128 and 1, unless the pixel is set to zero, in which case a mask of 127 is correct for the left-most pixel, and a mask of 254 is needed for the rightmost pixel. I'm sure you know what, and that most people realized what you meant.
@longjohn7992
@longjohn7992 Жыл бұрын
FINALLY someone who gets my goals c:
@nipupper6412
@nipupper6412 9 ай бұрын
Really great. thanks for the insight.
@paulmichaelfreedman8334
@paulmichaelfreedman8334 Жыл бұрын
Hi dave, I made my own petscii font (C64) in python with hex codes in a list. I used it for the LED Matrix TEXT scroller I built from a leftover 2812b strip. It was fun to do.
@farvardinmainyu1961
@farvardinmainyu1961 Жыл бұрын
This is so beautiful
@libb3n
@libb3n Жыл бұрын
Will we ever see a new Tempest bath robe record run again? Loved the last record video and the atmosphere where you had a casual morning with your coffee and setting a new record. Highly enjoyed watching it during my morning routine as well. :)
@CoreDreamStudios
@CoreDreamStudios Жыл бұрын
Nice idea of porting a C compiler, even if limited, to the KIM-1. Good stuff.
@CoreDreamStudios
@CoreDreamStudios Жыл бұрын
@@Dm_official_Daves_Garage BOT! All, do not reply to the fake Dave!
@SquallSf
@SquallSf Жыл бұрын
It is not porting. CC65 just generate 6502 code from C. You need to set a configuration to target KIM-1 - it is pretty much the extra stuff you need (beside the actual code) to make it easier/useable by the system.
@gianlucarenzi7706
@gianlucarenzi7706 Жыл бұрын
Awesome explained
@Robbinsffxi
@Robbinsffxi 4 ай бұрын
Would love to see you make a program or game for the Commander x16. I've programmed C for 3-4 years, and I struggled to grasp this from the first second. If that is basic, I bow to your skills.
@onogrirwin
@onogrirwin Жыл бұрын
Sounds like the beginning of a C only/CPU only 3d renderer from scratch series :)
@lexihaley2887
@lexihaley2887 Жыл бұрын
I gave this a thumbs up before I even skipped past the ad that preceded it Edit; And after watching, I wasn't wrong.
@crayzeape2230
@crayzeape2230 Жыл бұрын
It would be interesting to see how LLVM-MOS compares to CC65 these days. There are some rather large projects using LLVM-MOS now, including CP/M for the 6502.
@rickdearman9992
@rickdearman9992 Жыл бұрын
Very nice!
@vitorsantos6310
@vitorsantos6310 Жыл бұрын
I’ve always had this misunderstanding of how to use bit shifting and utilizing bitwise operands, a video on that would be very nice !
@guilherme5094
@guilherme5094 Жыл бұрын
Really nice👍
@ErazerPT
@ErazerPT Жыл бұрын
Loved it... Just the episode for "weirdos" like me that think doing stuff like a console graphics library, console raycasting renderers and the like is "fun". A graphics "first principles" of sorts. If i may suggest, add a text renderer that won't wrap and only draws whatever is within the valid screen area. Scrolling text, floating text, moving text in general. Guess FloodFill is next :P
@cougar-town
@cougar-town Жыл бұрын
Does the setpixel also has a starting point and ending point where the pixel draw is starting from and ending on? to make it possible to calculate from each side where to perform a future possible draw call within some future functionality. This could be useful for determining light sources on surfaces and what not for 2D or 3D games.
@honeymak
@honeymak 2 ай бұрын
Hi, Dave. nice c video. do you have some videos about your IDE and plugins/extensions you used in the video? nice piece eye catching is the mouse-over tooltip showing variables/functions call info. that's nice to have
@robbybobbyhobbies
@robbybobbyhobbies Жыл бұрын
Takes me wayyyy back to the 80s/90s when I was teaching myself graphics programming. Turned out it was a passing phase and sysadmin/programming then database work was where my future lay, but fun nonetheless.
@makethingsbetter
@makethingsbetter Жыл бұрын
Actually, adding another comment has become my trade mark. So I would add that we should explore the layers of programming onions to see if we can create a screen function, similar to screen 1,1; or screen 2 altering the mode to graphics mode, just like the PET. Be interested to see if you could add this to the simple graphics card in some fashion! 😊
@noelgomile3675
@noelgomile3675 Жыл бұрын
Dave you are a badass.
@foley2k2
@foley2k2 Жыл бұрын
Good stuff. There is a DirectBitmap class on stack overflow that'll give you C# for drawing pixels at speed in winforms using a pinned memory array. What graphics functions could leverage parallelized linq? That's probably an unexplored niche.
@anon_y_mousse
@anon_y_mousse Жыл бұрын
I'm wondering if you have enough memory on that thing to implement the full libc. If so I'd love to see it. As for the table, I'd use one regardless of how many or few edge cases there are because it'll always be faster and 256 bytes is really not too much to ask in this instance. If we were talking about upper and lower casing things, then it might be too much.
@michaelkaercher
@michaelkaercher Жыл бұрын
I think I would have needed 3x more lines. Great job.
@realnutteruk1
@realnutteruk1 Жыл бұрын
When a grid misaligns with one that's behind, that's a Moire!
@stevejohnson1685
@stevejohnson1685 Жыл бұрын
You forgot the "🎵"!
@alexandrohdez3982
@alexandrohdez3982 Жыл бұрын
Love it 👏👏👏
@pavelperina7629
@pavelperina7629 Жыл бұрын
This reminds me times when I was seven years old with zx spectrum at home, some programs in basic and one book to look at and to learn from. For some reason my mother which knew something about programming (algol, prolog ,fortran ... not sure) from university helped me with writing programs drawing doilies. I guess it was some cycloids with use of trigonometric functions. But I'm sure basic had sin, cos, putpixel or similar command. It was nice to watch cause it took some time. I'm surprised that computer from that era has C.
@bradnelson3595
@bradnelson3595 Жыл бұрын
That's a great memory, Pavel.
@stevetodd7383
@stevetodd7383 Жыл бұрын
It’s a modern C compiler that targets 6502 code. C was far from popular on that generation of hardware at the time.
@pavelperina7629
@pavelperina7629 Жыл бұрын
@@stevetodd7383ops. Yes. Editor in 80s didn't have syntax highlighter and I was not thinking about cross compiler. Which brings question how to transfer data. USB to serial? Old computer with floppy drive? Audio cable emulating tape?
@stevetodd7383
@stevetodd7383 Жыл бұрын
@@pavelperina7629 I think Dave mentioned connecting via serial. These machines did lack a lot of the oompf needed for a modern IDE, and even at the time a lot of commercial work was cross compiled on mini computers (MS BASIC started life on a PDP IIRC).
@EmbeddedEnigma
@EmbeddedEnigma Жыл бұрын
was always looking for something like this. I am learning to design graphic library for embedded displays. Do you know any books where I can learn more on this topic about ??
@stephenbradshaw6727
@stephenbradshaw6727 Жыл бұрын
Brings back happy memories of coding on a DOS box and having to implement all of that functionality myself. How quickly could it render to a screen buffer and then flip it to the display? Or is there not enough main memory for a buffer?
@kostis2849
@kostis2849 Жыл бұрын
nooo buffers there...
@stevetodd7383
@stevetodd7383 Жыл бұрын
If you were lucky then the video RAM didn’t suffer contention with the CPU (you’d see visible glitches on screen when both tried to access it at once. The PET tried to restrict it’s self to video updates during the blanking period because of this). RAM was far to expensive to waste for a double buffer.
@RamonChiNangWong078
@RamonChiNangWong078 Жыл бұрын
Mode 0x13 Oh this bring back the good ole tutorials
@GeoffSeeley
@GeoffSeeley Жыл бұрын
Man, it's been many decades since I've seen code this far down in the weeds, but I do remember the good old bit flipping days of C/ASM. Thanks for refreshing those brain (RAM) cells... should be good for another 30 years or I get unplugged.
@demonwaterdemonwater4993
@demonwaterdemonwater4993 Жыл бұрын
I think I need this
@mr.libluckiestinfinitebene2589
@mr.libluckiestinfinitebene2589 Жыл бұрын
Could you show how cpu instructions set implement to programing language and vice versa?
@lucasoorschot780
@lucasoorschot780 Жыл бұрын
I once had to do something similar in TRS-80 basic to render a working analog clock. The "pixel" drawing was quite interesting in that machine since the character set contained 64 characters consisting of 2x3 black&white (black&green) blocks (one character for each possible combination of those 6 "pixels"). The way of walking a line to draw each pixel was pretty much the same as in your case, Dave. The "mathematics" (missing most of the C bit manipulation options) of setting/clearing specific pixels was a bit of brain teaser though. And needles to say that it was slow enough to make a real-time seconds hand unthinkable. On the other hand, clearing/filling the screen (when done in machine code) was fast enough to create a stroboscope thanks to the mere 1K of video memory and the mighty handy LDIR or LDDR instructions (those of you with any Z80 experience can probably code that in under a minute). Anyway, thanks for an entertaining trip back in time to those early times where problems had to be solved by pure brain-power rather than processor-power. :)
@b43xoit
@b43xoit Жыл бұрын
Sixel graphics.
@MichaelPohoreski
@MichaelPohoreski Жыл бұрын
3:22 *Correction:* 128 is the first left pixel. 127 would be the right 7 pixels of the first 8 pixels. The Apple 2 reverses the bits for HGR. LSB is left-most bit, MSB is a palette bit, and bit 6 is the right-most pixel.
@DavesGarage
@DavesGarage Жыл бұрын
True, thanks!
@abo1428
@abo1428 Жыл бұрын
Hi Dave … would you consider to create an Assembler and C-Language Beginner tutorial series? I know there are a lot of tutorials here on YT, but not in that type of quality 👌🏻
@SquallSf
@SquallSf Жыл бұрын
If you think that in 8 min you will learn C/ASM ... then yes, there are no tutorials "in that type of quality" :D
@greatwolf.
@greatwolf. Жыл бұрын
This is definitely fascinating writing runnable programs for the PET in C. Some quick questions about it, is this being cross-compiled eg. like on x86-x64 platform with the toolchain targeting whatever instruction set the PET uses? Is there anything like a notion of an executable format on the PET? eg. PE32 on windows, ELF on Linux. How do you load the compiled executable onto the PET?
@HAGSLAB
@HAGSLAB Жыл бұрын
He mentioned CC65 which is a C cross compiler for the 6502 CPU. The CC65 compiler can generate multiple output formats, like raw images of machine code or even a PRG-file for the C64 etc. I have a few videos on my channel about the CC65 compiler. I'm not anywhere Daves level though. :)
@ucmRich
@ucmRich Жыл бұрын
Thank you Pal!!!! ESPECIALLY Thank you for Windows 95b OSR2 - my first "my" PC my dad bought me was a 133MHz Pentium w/MMX inside Packard Bell, i wish i still had it. I remember finding out that the Right-Mouse button did stuff 0.0 and then as i explore every little piece i could, i would check out the About... and find your name many times. before that my computers were the tandy color computer line, i remember creating my own operating system/client-user-interface/data-decoding-REencoder using an interfacer with my coco3 and two half height floppy drives. course at the time i didnt know any of those words, i was just trying to create a master program i could have perform multiple computation tasks while i was at school and then review the results on disk when i got home from time to time. but i was like 12 or something, soo... You though, you totally rock man!!! I love your videos and show them to people i know in my local area including a friend a few days about about your book, he told me he's going to check it out. and for the on-topic subject: yes i love your videos, every chance i get some free time, im checking them out. i especially love your style of C/C++ which is gnarly awesome!! I am in the process of working on my own (is it 'retro' the kids calling it these days??) anywho, my own 'computer' of sorts from scratch. I am hopeful i can get something that i can eventually mass produce and sell but we'll see
@ucmRich
@ucmRich Жыл бұрын
ohh i meant to say yes I would like to see more videos on programming graphics in C/C++ and on your computer research! +1
@WarrenGarabrandt
@WarrenGarabrandt Жыл бұрын
This is fascinating. How cool would it be if Dave were to design a full Commodore 64-esqe operating system for this that could emulate basic (or even JIT compile basic when it's run) and make this a fully usable computer like a commodore pet/64/whatever?
@GodSpeaksInMath
@GodSpeaksInMath Жыл бұрын
Hey Dave excellent show..long time listener first time caller...:-) I subbed after your addressable RGB LED series. Ive also had to work with these functions mostly in the last few years in writing graphics to OLED screens and I utilized these same functions you've described here but in my applications drawing graphics pixel by pixel while sending and receiving data takes up too many cpu cycles so i had to find another way... I can display an entire 30 second (10 frame/s) graphic animation to the screen using somewhat less cpu cycles by drawing the entire screen frame by frame( from const char pixel bitmap pixel arrays) but theres a shortcut because i just turn black and white images into frames and those can be sourced from anything. ..my knowledge has some gaps i need help with one main thing. How can i write the display using a changeable char array instead of constant char so i can rewrite each frame after compilation or how do i write the data directly to the memory location of the const char to change its contents in the loop? i tried a few pointer based methods before but i think it either didnt compile or kept crashing. i probably just needed to tighten up syntax somewhere...
@alexfrozen
@alexfrozen Жыл бұрын
You could save 256+ bytes from result just rearranging of font array. And even save some ticks of CPU. Precalculatable things should be precalculated.
@spacewolfjr
@spacewolfjr Жыл бұрын
Could you explain the algorithm behind "brasin' ham"? How often do I need to baste the ham? Kids in the Hall has alerted me to such ham-related issues like "Saltly Ham" and of course the "Ham of Truth"
@philippklostermann7768
@philippklostermann7768 Жыл бұрын
Why not reorder the ramfont instead of using translation tables for finding the right index?
@trapexit
@trapexit Жыл бұрын
Could also use xxd -i to generate the font array.
@TheRojo387
@TheRojo387 5 ай бұрын
With SVGA graphics, the SetPixel function must obviously be tweaked for what colour the pixel should be; obviously an int type will do, but care must be taken to ensure the proper ordering of alpha, blue, green, and red channels. And now I also know how my own homebrew library, for rendering NURBS contours, should be written.
@T3RRY_T3RR0R
@T3RRY_T3RR0R Жыл бұрын
Very nice. Always interesting to see how tasks like this get done with different languages. I'm currently working on a collaboration for a game engine written in Windows Batch. It's amazing what the language is capable of when you know how to use it to full effect.
@huangxf
@huangxf Жыл бұрын
I did almost the same thing about 20 years ago on an 80286 PC. As I remember very clear about the address 0xa000. It is the begining address of 13h VGA mode, which is a 320 x 200 screen. After Microsoft Windows 95, you can't draw graphics by writing data to screen memory.
@Cla0016
@Cla0016 Жыл бұрын
This is my morning drug
C++ Super Optimization: 1000X Faster
15:33
Dave's Garage
Рет қаралды 283 М.
100 Hours Of Graphics Programming
6:48
Tantan
Рет қаралды 143 М.
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
100❤️
00:20
Nonomen ノノメン
Рет қаралды 52 МЛН
I Designed My Own 16-bit CPU
15:46
AstroSam
Рет қаралды 1,9 МЛН
C vs ASM: Making the World's SMALLEST Windows App
20:15
Dave's Garage
Рет қаралды 140 М.
Understanding how a demo works on the Commodore 64 (English)
8:41
Commodore 64 & 6510 retro-programming
Рет қаралды 1,8 М.
Modern C++: Unique Ptrs and Vectors
16:25
Dave's Garage
Рет қаралды 132 М.
How do Video Game Graphics Work?
21:00
Branch Education
Рет қаралды 3,2 МЛН
Making Minecraft from scratch in 48 hours (NO GAME ENGINE)
16:38
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 909 М.
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 769 М.
E01: Stupid C++ Tricks with Dave
15:43
Dave's Garage
Рет қаралды 318 М.
Xiaomi Note 13 Pro по безумной цене в России
0:43
Простые Технологии
Рет қаралды 2 МЛН
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
Топ-3 суперкрутых ПК из CompShop
1:00
CompShop Shorts
Рет қаралды 460 М.
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 3,4 МЛН