Printf & Terminal Control Codes | 32 bit OS Dev (in C)
Making a starter 32 bit printf() to simplify printing with no cursor X/Y parameters, control/escape codes to change terminal variables like colors & cursor position, and abstracting fd 1 through a write() syscall.
Trying out normalized audio to -18 LUFS this video, to be closer to youtube (-14 LUFS) and have more consistent levels. Let me know if this is too loud/quiet/harsh, or you can hear too many mouth sounds. I think I was too close to the mic on these next few videos.
64 bit printf without stdarg.h example: https://git.sr.ht/~queso_fuego/printf_no_varargs/tree
OS Dev playlist:
https://www.youtube.com/playlist?list=PLT7NbkyNWaqajsw8Xh7SP9KJwjfpP8TNX
Source code for this video (includes upcoming changes/additions for printf with malloc and argc/argv):
https://git.sr.ht/~queso_fuego/amateur_os_video_sources/tree/master/item/43_printf_terminal_argc_argv
Git Repos:
Sourcehut: https://git.sr.ht/~queso_fuego/quesos
Github mirror: https://github.com/queso-fuego/amateuros
Other links:
https://wiki.bash-hackers.org/scripting/terminalcodes
https://en.wikipedia.org/wiki/ASCII#Control_code_chart
Join the Community Discord: https://discord.gg/yKm4T89QFn
Contact:
email: fuegoqueso@gmail.com
twitter: @Queso_Fuego
twitch: https://www.twitch.tv/queso_fuego
Notes:
- The fancy one-liners don't quite work for setting fg/bg colors in a control code. Hex char to number should be str[i] - ('A' - 10), not just 'A', to subtract 55. The range ['A'-'F'/65-70] - 55 = 65-55 to 70-55 = 10-15.
Next video ideas:
- Change printf to send a full string to write(), to use control codes within printf; Replace print_ functions with printf functions & use control codes to replace other things
- Passing argc & argv to called programs, example would be loading a file in the editor by passing it on command line, otherwise edit new file by default
- A better filesystem incl. LBA & directories, similar-ish to MINIX or ext2
- Let me know if there's anything specific you'd like to see!
Outline:
0:00 Intro & printf example
7:44 syscall_numbers.h & syscall_wrappers.h
21:45 syscall_write() skeleton
29:54 terminal.h, for printing & control codes
1:15:11 stdio.h, printf()
1:46:21 fail at debugging printf calls
1:57:44 Fixed printf calls
2:07:44 Use printf in calculator, fix cursor drawing
2:19:35 Use printf for initial boot message, Outro/Coming up
Software:
VMware Workstation Player: https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html
freeBSD: https://www.freebsd.org/
qemu: https://www.qemu.org/
vim: https://www.vim.org/ (theme = gruvbox)
clang: https://clang.llvm.org/
davinci resolve: https://www.blackmagicdesign.com/products/davinciresolve/
OBS Studio: https://obsproject.com/
Peripherals:
Camera: Sony ZV-1, Elgato Camlink 4k
Microphone: Shure SM7B, Cloudlifter CL-1, Focusrite Scarlett Solo
Keyboard: HHKB Pro Hybrid Type S, white/blank keycaps
Mouse: Logitech M590
Updates may be on twitter, YouTube channel community tab, or the community discord, if I remember to update anything.
Music credits:
"Acid Trumpet" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/
"Night in Venice" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/
#osdev #printf #programming