Wednesday, September 30, 2015

Day 2: A Primer on Debugging & Assembly

I'm going to separate my status from the notes and stuff learned, so I can pump these logs out in a more efficient matter.

Casey-isms

  • Everything in computers is just numbers.
  • As a general theme of Handmade Hero, we want to know what the machine is doing.
  • It gives us a connection to the computer and is not that much more slower or complicated.

OutputDebugStringA() vs OutputDebugStringW()

  • What does the A stand for?
    • Windows used to work only with standard ASCII strings (or ANSI?)
    • But the ASCII system didn't work for languages like Chinese, so Unicode became the standard, so Windows had to expand
    • So Windows started using wide character strings called UTF-16

Debugging & the Breakpoint

  • You set a "breakpoint" and run code, but when program reaches this point, it stops!
    • It will freeze everything, the memory, variables, etc so i can look at it
    • Press F9 in VS to set a breakpoint
  • Breakpoint freezes RIGHT before the line that executes
  • Step Into and Step Over
    • Step Over, F10, do whatever's on the current line
    • Step Into, not covered just yet
  • Useful Debug Windows
    • Watch: type in the name of something we want to see and show up corresponding value
    • Registers: to see the assembly language CPU operates on

Assembly

  • Appears to read right to left!
  • This is important, BECAUSE WE ALWAYS WANT TO KNOW WHAT IS HAPPENING ON THE MACHINE
    • In VS, Right click and select goto disassembly
    • For debugging, bring up registers. you can right click and display in hexadecimal
011A1BCE                    mov                                  byteptr [Test], 0FFh
(location in memory)    (register mnemonic)        (moves FF in code into byte pointer )

  • By watching the registers, we know this is a memory to memory move and does not reach the  registers)
  • Hexadecimal notations 
    • VS will translate it for you if you hover over hex
    • 0FFh : Assembly Notation
    • 0xFF (0xcc) : C notation

  • Even though EAX can hold 0000 0000, we can reference smaller parts of a register. we can pull out the bottom 8 bits...
    • This is what "al" (references to EAX to pull only a byte) does!


Monday, September 28, 2015

Day 1: Crash course in C/C++ & computer architecture

Step 2: Crash course in C/C++ & computer architecture (continued)

Comments: The amount of detail in this stream is amazing and quite honestly, overwhelming. I might have to work out some sort of system to absorb the sheer amount of information.
Progress: I grokked a large portion of it.  Will review before next video. Onwards!
Notes (This isn't a log of the entire video, rather, the parts that I felt were relevant to me):

What is Linking?

  • The back half of the compilation process.
  • Gathers all references to link together to make executable
  • What is the Unresolved external error?
    • External to the compilation unit where it was being used
    • unresolved means it couldn't find an actual definition!

How does windows, the linker, and your program know where to start?

  • The predefined name  WinMain
  • Use MSDN, don't bother with memorizing

WinMain() prototype

  • Lots of Windows only stuff here.
  • LPSTR(a pointer to string), HINSTANCE (a running program) 
  • hInstance
    • it refers to ourselves!
  • hPrevInstance
    • old, not important
  • LPSTR lpCmdLine
    • what got sent to us when we were run
    • arguments and stuff from the command line
  • int nCmdShow
    • Run in normal window or minimized windows

What is that letter before Instance / PrevInstance / etc

  • This comes from Hungarian Notation (an old standard where you prefix everything you type)
  • p for pointers, l for long, h for handle, etc

What's _In_ for?

  • Tells you what direction the data in flowing
  •  __In__ means it's passing information TO Windows.
  •  You typically want to remove this before compiling / running.

Function

  • Something that holds code for us that we can reuse
  • void: does not return anything when the function is called
  • <return value, aka what comes back from function> foo (<parameters>)

What's the ; (semi-colon) for?

  • End-of-line delimiter, it defines the end of a C++ statement

What is CALLBACK for?

  • A C Macro, it expands to some special decoration this is used from Windows
  • Decoration that tells compiler and linker that it's special
  • There are constraints that needs to be met!

When we removed foo() why was is a compile error and not a linker error?

  • This happens because C/C++ are languages that do NOT allow you to use thing that have not been defined yet
  • But if you can't actually call something unless it's defined, how are there ever unresolved external symbols at link time?
    • C allows forward declaration
    • Functions are divided into declaration and definition

Tidbits from Video 1 Q&A

  • Sysinternals, if you want a tool that grabs OutputDebugString into a log?
 

Welcome to the first post!

I decided I need to learn more about the technical aspects of game development.  I can probably make a game now, but I want to make gameplay experiences I think will be awesome.  To do that, I need to master my tools like any other artisan.  This blog will be an exercise in discipline as well as a log for myself.  I hope to reach milestones and learn a damn lot. There's probably no more excuses left with the materials available today.

I'll be following Handmade Hero and be making smaller projects as I learn the joyous in's and out's of C/C++. Maybe even slap together a Unity project in my off-time!

Step 1: Setup up Sublime 3 

Link used: Setting up Sublime with M VanDevander
Comments: Pretty straight forward.  I didn't want to use vim or emacs since I was already pretty comfortable with Sublime.
Status: COMPLETED


Step 2: Crash course in C/C++ & computer architecture

Comments: I'm familiar with C/C++ and some computer architecture.  However, I'm quite rusty since I've been using C#, Python, and other interpreted languages. Probably the roughest part will be thinking about memory, which modern languages handle for you.  
Status: IN PROGRESS

Sidestep 1: Unity!

I played a small, fun top-down shooter called Last Invader and really wanted to make one myself. Just good ol' fashioned, arcade fun.  As a side project, I think I'll whip together a a TDS for Kongregate/Newgrounds.