This page was last updated on March 13th, 2020(UTC) and it is currently October 25th, 2020(UTC).
That means this page is 225 days, 10 hours, 34 minutes and 54 seconds old. Please keep that in mind.

42 - Really Getting Ahead I made some changes to SETTINGS.H, which you will find interesting.

#ifndef _SETTINGS_H //Defines are compiletime only variables. #define xsize 320 #define ysize 200 #define starnum 200 //------------------------------------------------------------------------- extern "C" void srand(int seed); extern "C" int rand(); extern "C" int time(int ptr); //------------------------------------------------------------------------- #define defkey(x, y) const int KEY_##x = y; defkey(esc, 0x01) defkey(til, 0x29) defkey(min, 0x0c) defkey(equ, 0x0d) defkey(bspace, 0x0e) defkey(tab, 0x0f) defkey(q, 0x10) defkey(w, 0x11) defkey(e, 0x12) defkey(r, 0x13) defkey(t, 0x14) defkey(y, 0x15) defkey(u, 0x16) defkey(i, 0x17) defkey(o, 0x18) defkey(p, 0x19) defkey(lsqrbrkt, 0x1a) defkey(rsqrbrkt, 0x1b) defkey(bslash, 0x2b) defkey(caps, 0x3a) defkey(a, 0x1e) defkey(s, 0x1f) defkey(d, 0x20) defkey(f, 0x21) defkey(g, 0x22) defkey(h, 0x23) defkey(j, 0x24) defkey(k, 0x25) defkey(l, 0x26) defkey(scln, 0x27) defkey(quot, 0x28) defkey(enter, 0x1c) defkey(lshift, 0x2a) defkey(z, 0x2c) defkey(x, 0x2d) defkey(c, 0x2e) defkey(v, 0x2f) defkey(b, 0x30) defkey(n, 0x31) defkey(m, 0x32) defkey(comma, 0x33) defkey(period, 0x34) defkey(fslash, 0x35) defkey(rshift, 0x36) defkey(ctrl, 0x1d) defkey(alt, 0x38) defkey(space, 0x39) defkey(up, 0x48) defkey(down, 0x50) defkey(left, 0x4b) defkey(right, 0x4d) //The following keys can't use the macro. #define KEY_1 0x02 #define KEY_2 0x03 #define KEY_3 0x04 #define KEY_4 0x05 #define KEY_5 0x06 #define KEY_6 0x07 #define KEY_7 0x08 #define KEY_8 0x09 #define KEY_9 0x0a #define KEY_0 0x0b //------------------------------------------------------------------------- extern "C" int easymode(); extern "C" char buffer[0xfa00]; extern "C" char keymap[0x80]; #endif #define _SETTINGS_H true

"#ifndef" is "if not #defined", which is a nifty little trick that we can use to ensure code is not "redefined" when included more than once by a single file. Next, we have macros (compile-time-only functions created with #define statements), which the syntax explains itself (outside of "##" which allowsed us to turn KEY_X into whatever we wanted it to be through "concatination after evaluateion"). I didn't test all these keys, but you'll find it fairly useful in the next lesson. Beware, macros and some of their functions cannot be relied on from compiler to compiler, and I also expect this behavior to change over time. However, they're very useful for making some repetitive tasks like this easier.

Get your own web kitty here!
┬ęCopyright 2010-2020. All rights reserved.