I made a virtual dot matrix printer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
over the weekend I wrote a program I I think is kind of interesting uh it's a program that emulates a very simple dot matrix printer and emphasis here is on simple let me go ahead and show you what it looks like uh so here we've got the read me that describes a little bit about the program I'm just providing a bit of background here for that simplified uh virtual printer uh again it really is very simple but uh just kind of bit of a background here when I was growing up we had a nine pin Epson do Matrix printer and I I think everyone I knew had one too now in a dot matrix printer you've got a printer head that moves back and fourth across the page it's got nine pins arranged vertically that's why we call the nine pin printer although you could find higher resolution. Matrix printers with more pins but I I'm going to stick with nine pin here uh so as the head moves from left to right it strikes these pins through a ribbon onto paper makes a little dot for each pin and so if you arrange those dots you can make letters and 9 pin printers used up to five columns of dots so that they could actually hit between those five columns it really is more like nine pins across two you got one across between each one of those five uh but I'm going to use here the simplest uh case and so just a straight grid of 9 uh by five now for this printer I'm further simplifying it uh by using as you can see here uh just eight pins uh so here I've labeled them seven through zero uh uh to draw each letter and the last uh uh pin pin nine I've labeled it pin nine uh it's a little odd but you you'll understand why in a second it's dedicated uh just for printing an underline so if you have a a a one pin sort of gap between each line uh you can see that uh you actually have uh 10 pins dedicated for each line because that 10th one is really a gap and if you uh uh do the math here you can actually see all right so 66 lines on an 11inch page it's really 66 by 11 time 10 uh it's 60 dots per inch uh and if you use 60 DPI going you know horizontally as well but you've got 10 characters per inch a standard delete text uh you can work out the horizontal dimensions of an 8 and 1/2 by 11 in page and that's what we've got down here uh as well and so that that's what really walks us up to uh having a virtual do Matrix printer if we're assuming 60 DPI for this very simple case where everything's locked into a standard 5x8 uh grid uh then you've got a 510 by 660 pixel 8 1 12 by 11 uh sheet of paper so let me go and exit out of that and so let's look at the source code here real quick uh it um it's h so I just do a dur and you can see we just do V actually do a Fed on that first here on vp. C uh and so as I said it's very it's meant to be very very simple now it doesn't even do printer controls and it doesn't even do tabs uh and I didn't really spend any time building like a firmware with a different asy character so it really just prints an asky uh bit pattern for each letter instead but it it does show uh what a dot matrix printer was like and all that other stuff can be added later so here's just a quick walk through of what this code looks like uh so generally on this one I want you to read from the bottom up and so I'm going to jump all the way down to the bottom of the program and so here we've got uh the uh the main program uh and what it's doing is uh basically uh setting the video mode um there was a commented online there I was doing 640 by 480 but and I've now moved on to 24 by 768 uh assess the video mode it um uh you know does uh reads a list of files and uh for each file it prints it out on the uh on the virtual printer using the print file function uh it also has an initialization up there uh using a knit printer and if I jump up here a little bit you can see there's a nit printer and really all that's doing is defining a global structure called printer that's defining the size of the of the page and it's defining some other values as well U and uh it's allocating uh memory for firmware which as I said I didn't have time to implement firmware so all really does actually is it just fakes it as you can see here by uh by just loading a bit pattern uh for each uh asy character between 32 and 127 those are the printable uh lower asy and uh so really just getting a a a bit pattern instead of actually printing out a real letter uh but I am doing a a space for for asky 32 that's an actual space uh once we do that then it uh it uses the print file function me jump up here a little bit there's the uh print file and print files very short all it's really doing uh is reading the the file one character at a time I'm not worried about is this the fastest way to do it because that Mi printers are pretty SL slow anyway so uh if I slow it down accidentally by using just the very simple FG C uh method to read a file that's okay with me and then once it reads that character it just prints it on the virtual printer uh skipping up a little bit and so there's the print care function uh and all it really is doing is just taking that character uh looking up the value uh so you can see at the beginning here if it's a control code it tries to deal with that as I said earlier it doesn't even manage any control codes except car turn a new line um and uh it has uh if it's a printable asky then it just looks up the value in uh the firmware and then prints that uh 8x5 uh you know uh bit pattern uh onto the uh onto the printer so normally if it would actually loaded a real you know character set into the virtual firmware uh those five uh elements those five uh uh bytes would actually Define a real uh letter and so it's just using the print bite function uh to print each one of those uh five bytes and if I jump up a little bit further there's the beginning of print bite and all it's really doing is just doing a uh a bit of uh work to try and uh basically arrange a series of dots on the screen this part is a bit slow but again it doesn't really matter because uh do Matrix printers were also very slow if you want to artificially slow down the printer even further and adding a one millisecond delay between each character uh you can see I've commented out uh that line right here uh but it uh that makes it really unbearably slow to watch on a screen here uh but we can look at that in a little bit um and uh it it doesn't do underlining yet but it it does have the ability to support underlining so if underlining has been set uh it'll do that right here a little bit further up uh is actually where it uh prints out new lines and so it's just basically if it reaches the end of a line it pushes a new line and it does have the ability to set uh support for uh carriage return being added for Unix systems uh and if youve ever managed a a Unix system or try to connect a Linux system to a do metrix printer you get that staircase effect it's because it doesn't support or doesn't provide Unix doesn't provide a carriage return dos does Dos provides carriage return and new line and so this is providing a little bit of support uh if you uh want to feed it a Unix file uh and then um here's where it defines a new page really all it's doing is just putting a line down the right hand side of the screen uh and then waiting for me to uh press a key uh which happens up here with the pause function and then at the very top of the screen uh top of the file is that structure that I mentioned that's just defining a global structure uh for the uh for the printer all right so that's all background so let's actually uh quit this and let's look at a sample file so I've got a file here called read me um which we were looking at earlier and let's run that through the virtual printer VP read me uh oh and I need to compile it first so let's go ahead and compile it so I've got a a batch file here called build which will go ahead and compile that using the watcom compiler and Linker and now we've got a VP program and so we'll do VP on read me and there it is look at that I've got an8 and 1 half by 11 sheet of paper up on the screen uh and it's printing out uh text uh now again it doesn't do tabs and so the tabs are not going to show up but this file doesn't have tabs uh and uh and I didn't load the actual characters but it's it's right there I mean that's that's that's what a matrix printer uh is like now this doesn't fill up more than a page it's just filling up a uh uh it's just filling up part of a page now it just hit any key will actually move on to the next uh page or if that's the last page just hitting any key will exit the program uh I also have a couple other sample files in here I have a file called uh 67t XT which I was using as a sample file it's 67 charactera or 67 lines long and the first line is 85 characters wide which is why it wraps and uh that's because at 10 characters per inch and an 8 and 1 12 by 11 uh sheet of paper 8 and 1 half inches wide that means it can actually do 85 characters wide so uh let me break out of that and we'll do VP on 67. txt and look at that it's printed out uh 85 characters across the uh the top and uh it's filled uh it's just counting uh line numbers there on the left hand side all the way down to 66 and there is actually 67 lines in this file so if I hit any any uh key on the keyboard like I'll lose space we can now see the uh uh the 67 on page two and of course it's pause waiting for me to Exit the program so I just hit space and there it is now if you have a file that has tabs in it I said that it doesn't support tabs there is a program in here called untab doc um and it looks like this it's just a very simple uh program to convert uh tabs to spaces uh and um just uh the source code for that on tab. C doesn't have any tabs and so we can actually run uh VP on untab Doc and there's the source code to uh the untab program it's uh being printed using our virtual printer uh and and there it is now it's it takes up more than a page and so it's waiting for me to uh to hit a key so you can move on to page two there it is and there's page two and so that's the source code to untab now uh let's actually go in an edit uh the uh the VP uh do c program so we'll do fed on vp. C and I think it was around line 114 I think was where it actually uh I have a commented out uh line where you can add a delay and so right here yep on line 114 I've commented out a delay statement so using delay will add a millisecond delay but between printing each uh bite to the printer now that's is actually too long but it is kind of cool to watch a uh you know the dot maker printer actually draw it in uh you know live in front of you uh for a long file this will take forever uh but it's probably worth doing uh for a uh a small file like that 67 uh. txt file so we've uncommented delay and of course at the top of the file we need to make sure i86 has been uncommented and so right now that's been commented out so might as well just uncomment that and now we can do file and then save and then we'll go ahead and rebuild it it rebuilds everything but it's okay and now we'll run uh VP on 67. txt and remember this has that now it has a millisecond delay between printing uh each uh bite uh every basically as the printer head moved to the right it actually is going to have a little bit of a delay a millisecond delay between each uh bite that it prints to the screen and that means that every character is made up of five bytes uh plus a one B uh space uh it's going to be uh a little slow actually there's there's actually a little bug in there let me let me fix the bug here real quick so fed vp. C jump back down to line 114 um and so I mentioned this on my patreon those of you who are on patreon uh the the better way to do this so the what's getting passed into the function here is uh a bite value B and so it's actually better right here if rather than doing a delay for everything if it doesn't actually have anything to print probably no point in having a delay so we'll do an if B then we'll actually add a delay and if there isn't uh a value being passed to it if it's zero uh then we will um oh actually it's already been uh why am I doing that because it's actually already in there there's already an ifb up here uh so it actually uh doesn't have to add that and so we can actually undo that we'll just do uh quit and we'll abandon our change and that now let's go ahead and just run uh VP on 67. txt and we'll watch it draw to the screen so yeah this is a lot slower than an actual do Matrix print printer um but you know we'll just pretend it was a it was an old dot matrix printer maybe it's trying to print in really high resolution mode uh which would take a little while not quite this long uh but but uh this is what a dot matrix printer uh look like now uh while it's printing out the rest of this page I'll just mention I'm I'm planning to write an article about uh how uh you know different uh dot matrix printers worked uh and I needed something that that I could use as a demonstration ation for uh do Matrix printing output and so that's that was probably primary reason number one for writing this program uh another one was I had a conversation with somebody a while back uh and they said that at a conference they set up a do Matrix printer and uh let people print out uh things from uh you know a like a graphics program make a like a greeting card or something on a doet matrix printer and it was one of those things that you were meant to look at I finished the page and we'll hit space to go to the next one it was one of those things where you were meant to only you know start the print job and then come back later to actually pick it up when it was done but people wanted to hang around the booth and actually watch it draw and so um that was the other kind of reason I made this program is you can actually watch it draw uh if that's something you wanted to do and now you could do it without uh wasting printer or or rather wasting paper or wasting a a ribbon uh anyway so that is a virtual printer that simulates a a classic and very simplified 9pin printer uh what' you think about that uh uh program in the video let me know in the comments below I'll also uh add in the in the video description a link to my uh GitHub where I have the source code uh for the virtual printer thanks to everyone who supports me on patreon you really do make this channel happen I know I say that a lot but you really do give me the ability to take some time off from my Consulting to uh make videos and keep the website up to date and things like that uh some of you are sponsoring at a higher level and you uh I wanted to thank you especially uh here for that uh don't forget of course to uh like And subscribe that really does help the channel visit our website at fed.org join us on Facebook follow us on mastedon and consider supporting me on patreon thank you
Info
Channel: FreeDOS
Views: 3,702
Rating: undefined out of 5
Keywords: freedos, open source
Id: yj8R4UIqBrQ
Channel Id: undefined
Length: 17min 18sec (1038 seconds)
Published: Tue May 28 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.