Skip to content

Commit e52ed4b

Browse files
committed
SDL TTF text example
1 parent f48340d commit e52ed4b

32 files changed

Lines changed: 452 additions & 18 deletions

‎c/operator.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,13 @@ int main() {
288288
}
289289
}
290290

291-
/* # Bitwise operators */
291+
/*
292+
# Bitwise operators
293+
294+
On signed integers: implementation defined or UB:
295+
http://stackoverflow.com/questions/11644362/bitwise-operation-on-signed-integer
296+
so just never do it.
297+
*/
292298
{
293299
/*
294300
# ~

‎gcc/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Cheat on the GNU Compile Collection (GCC) language extensions and command line u
66
1. [Compilation steps](compilation-steps.md)
77
1. [Invocation](invocation.md)
88
1. [Spec files](spec-files.md)
9+
1. [GCC as library](gcc-as-library.md)
910
1. Extensions
1011
1. Types
1112
1. [Empty struct](empty_struct.c)

‎gcc/asm.c‎

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
#include "common.h"
6262

63-
int main() {
63+
int main(void) {
6464
#if defined(__i386__) || defined(__x86_64__)
6565
puts("__i386__ || __x86_64__");
6666

@@ -169,7 +169,7 @@ int main() {
169169
gcc will automatically put the value of `in` from RAM into a register for us
170170
and `out` from a register into ram at the end
171171
172-
note how we can do an `inc` operation directly on `%1` and `%0`
172+
We can do an `inc` operation directly on both `%1` and `%0`,
173173
so they must both already be inside a registers as expected
174174
175175
GCC just makes sure they are written from/to memory before/after the operations.
@@ -185,6 +185,9 @@ int main() {
185185
: "=r" (out)
186186
: "r" (in)
187187
);
188+
/* in was not modified by inc. It had already been moved to a register. */
189+
assert(in == 0);
190+
/* Out was modified. But only after our custom assembly executed. */
188191
assert(out == 2);
189192
}
190193

@@ -201,7 +204,7 @@ int main() {
201204
and minimize the use of new registers.
202205
*/
203206
{
204-
volatile int x = 0;
207+
int x = 0;
205208
asm (
206209
"incl %0"
207210
: "=r" (x)
@@ -214,12 +217,14 @@ int main() {
214217
/*
215218
# Specific register constraints
216219
217-
`a` forces it to be put into eax.
220+
# a
221+
222+
Forces it to be put into eax.
218223
*/
219224
{
220-
volatile int x = 0;
221-
asm volatile (
222-
"incl %0"
225+
int x = 0;
226+
asm (
227+
"incl %%eax"
223228
: "=a" (x)
224229
: "0" (x)
225230
);
@@ -235,11 +240,43 @@ int main() {
235240
*/
236241
{
237242
register int eax asm ("eax");
238-
asm volatile ("mov $1, %%eax;" : : : "%eax");
243+
asm ("mov $1, %%eax;" : : : "%eax");
239244
assert(eax == 1);
240-
asm volatile ("mov $2, %%eax;" : : : "%eax");
245+
asm ("mov $2, %%eax;" : : : "%eax");
241246
assert(eax == 2);
242247
}
248+
249+
/*
250+
# modifiers
251+
252+
https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Modifiers.html#Modifiers
253+
254+
# =
255+
256+
Says that a value may have been modified by asm.
257+
258+
TODO: `=` vs indicating that it is an output? (before the second `:`?
259+
260+
# +
261+
262+
Both read from and written to.
263+
*/
264+
265+
/*
266+
# asm volatile
267+
268+
http://stackoverflow.com/questions/14449141/the-difference-between-asm-asm-volatile-and-clobbering-memory
269+
270+
TODO minimal example.
271+
*/
272+
273+
/*
274+
# volatile variable modified in asm
275+
276+
TODO do you need to mark variables modified in `asm` as volatile?
277+
278+
I think this is exactly what the `=` modifier does already, so maybe not.
279+
*/
243280
#endif
244281
return EXIT_SUCCESS;
245282
}

‎gcc/gcc-as-library.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# GCC as library
2+
3+
How to use GCC as a library, e.g. from another C program
4+
5+
- <http://programmers.stackexchange.com/questions/189949/is-there-a-way-to-use-gcc-as-a-library>
6+
- <http://stackoverflow.com/questions/1735360/compiling-program-within-another-program-using-gcc>
7+
- <http://stackoverflow.com/questions/8144793/gcc-for-parsing-code>
8+
9+
`libgccjit` from GCC 5 goes a long way.

‎opengl/alternatives.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,28 @@ Also by Khronos.
99
<http://gamedev.stackexchange.com/questions/96014/what-is-vulkan-and-how-does-it-differ-from-opengl>
1010

1111
Derived from <https://en.wikipedia.org/wiki/Mantle_%28API%29> by AMD, now abandoned in favor of Vulkan, and will somewhat be the new OpenGL.
12+
13+
There is no ES version like for OpenGL, <http://arstechnica.com/gadgets/2015/08/android-to-support-vulkan-graphics-api-the-open-answer-to-metal-and-dx12/> says ES and non-ES convergence has been going on for a while now.
14+
15+
### Samples
16+
17+
- <https://github.com/SaschaWillems/Vulkan>
18+
- <https://github.com/LunarG/VulkanSamples>
19+
20+
### Hardware support
21+
22+
Supported hardware:
23+
24+
- NVIDIA <https://developer.nvidia.com/vulkan-driver>: Kepler and Maxwell
25+
- Android
26+
- API 24?
27+
- Samsung Galaxy S7 was the first to support it.
28+
29+
Works on most GPUs that support OpenGL ES 3.1 <http://arstechnica.com/gadgets/2015/08/android-to-support-vulkan-graphics-api-the-open-answer-to-metal-and-dx12/>
30+
31+
### Ubuntu install
32+
33+
TODO. Already had an NVIDIA NVS 5400M driver 361.42 working for OpenGL.
34+
35+
- <http://askubuntu.com/questions/774131/installing-nvidia-vulkan-drivers-for-16-04>
36+
- <https://github.com/SaschaWillems/Vulkan/issues/188>

‎posix/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1. [getrusage](dlopen.c)
1616
1. [pthread](pthread.c)
1717
1. [pthread_mutex](pthread_mutex.c)
18+
1. [Regex](regex.c)
1819
1. Networking
1920
1. [socket](socket/)
2021
1. [netdb.h](netdb-h.md)

‎posix/bibliography.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
Very good intro do many of POSIX utilities with interesting examples and topics.
1616

1717
The problem is that each program requires you to pass several CLI arguments to them, and just print stuff to stdout, no assertions.
18+
19+
- <https://github.com/hailinzeng/Unix-Network-Programming>
20+
21+
- <http://www.apuebook.com/index.html> Advanced Programming in the UNIX® Environment, Third Edition by Richard Stevens

‎posix/common.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
/* POSIX only headers. */
4646
#include <arpa/inet.h>
47+
#include <curses.h>
4748
#include <dirent.h>
4849
#include <errno.h>
4950
#include <fcntl.h> /* creat, O_CREAT */
@@ -67,6 +68,7 @@
6768
#include <sys/utsname.h> /* uname, struct utsname */
6869
#include <sys/wait.h> /* wait, sleep */
6970
#include <syslog.h> /* syslog */
71+
#include <termios.h>
7072
#include <unistd.h> /* fork, ftruncate */
7173

7274
#define TMPFILE(x) __FILE__ "__" x ".tmp"

‎posix/curses/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile

‎posix/curses/Makefile_params‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBS := -lcurses

0 commit comments

Comments
 (0)