FreeCalypso > hg > freecalypso-tools
view target-utils/c139explore/lcd.c @ 465:003e48f8ebe1
rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel
I generally don't use NULL and use plain 0 instead, based on a "NULL
considered harmful" discussion on the classiccmp mailing list many aeons
ago (I couldn't find it, and I reason that it must have been 2005 or
earlier), but a recent complaint by a packager sent me searching, and I
found this:
https://ewontfix.com/11/
While I don't give a @#$% about "modern" systems and code-nazi tools,
I realized that passing a plain 0 as a pointer sentinel in execl is wrong
because it will break on systems where pointers are longer than the plain
int type. Again, I don't give a @#$% about the abomination of x86_64 and
the like, but if anyone ever manages to port my code to something like a
PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0
as a function argument where a pointer is expected most definitely won't
work: if the most natural stack slot and SP alignment unit is 16 bits,
fitting an int, with longs and pointers taking up two such slots, then
the call stack will be totally wrong with a plain 0 passed for a pointer.
Casting the 0 to (char *) ought to be the most kosher solution for the
most retro systems possible.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Feb 2019 00:00:19 +0000 |
parents | e7502631a0f9 |
children |
line wrap: on
line source
#include <sys/types.h> #include "types.h" static void send_cmd_data(cmdbyte, databyte) { send_via_uwire(cmdbyte); send_via_uwire(databyte | 0x100); } void cmd_lcdcmd(argbulk) char *argbulk; { char *argv[3]; u_long cmd, data; if (parse_args(argbulk, 2, 2, argv, 0) < 0) return; if (parse_hexarg(argv[0], 2, &cmd) < 0) { printf("ERROR: arg1 must be a valid 8-bit hex value\n"); return; } if (parse_hexarg(argv[1], 2, &data) < 0) { printf("ERROR: arg2 must be a valid 8-bit hex value\n"); return; } send_cmd_data(cmd, data); } static void send_pixel_value(pix) { send_via_uwire((pix >> 8) | 0x100); send_via_uwire((pix & 0xFF) | 0x100); } void cmd_lcdpix(argbulk) char *argbulk; { char *argv[2]; u_long pixval; if (parse_args(argbulk, 1, 1, argv, 0) < 0) return; if (parse_hexarg(argv[0], 4, &pixval) < 0) { printf("ERROR: arg1 must be a valid 16-bit hex value\n"); return; } send_pixel_value(pixval); } void cmd_lcdinit() { /* from OsmocomBB */ send_cmd_data(0x3F, 0x01); send_cmd_data(0x20, 0x03); send_cmd_data(0x31, 0x03); } static void set_lcd_addr_region(xstart, xend, ystart, yend) { send_cmd_data(0x10, xstart); send_cmd_data(0x11, ystart); send_cmd_data(0x12, xend); send_cmd_data(0x13, yend); send_cmd_data(0x14, xstart); send_cmd_data(0x15, ystart); } void cmd_lcdfill(argbulk) char *argbulk; { int argc; char *argv[6]; u_long pixval; int xstart, xend, ystart, yend; int npix; if (parse_args(argbulk, 1, 5, argv, &argc) < 0) return; if (parse_hexarg(argv[0], 4, &pixval) < 0) { printf("ERROR: arg1 must be a valid 16-bit hex value\n"); return; } switch (argc) { case 1: xstart = ystart = 0; xend = 95; yend = 63; break; case 5: xstart = atoi(argv[1]); if (xstart < 0 || xstart > 95) { range_err: printf("ERROR: coordinate arg out of range\n"); return; } xend = atoi(argv[2]); if (xend < 0 || xend > 95) goto range_err; ystart = atoi(argv[3]); if (ystart < 0 || ystart > 63) goto range_err; yend = atoi(argv[4]); if (yend < 0 || yend > 63) goto range_err; if (xend < xstart || yend < ystart) { printf("ERROR: negative range\n"); return; } break; default: printf("ERROR: wrong number of arguments\n"); return; } set_lcd_addr_region(xstart, xend, ystart, yend); npix = (xend + 1 - xstart) * (yend + 1 - ystart); while (npix--) send_pixel_value(pixval); } void cmd_hbars() { int i, j, k, p; /* * The result of this command should be 8 horizontal bars * in the natural RGB order. */ set_lcd_addr_region(16, 79, 0, 63); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { p = 0; if (i & 4) p |= 0xF800; if (i & 2) p |= 0x07E0; if (i & 1) p |= 0x001F; for (k = 0; k < 64; k++) send_pixel_value(p); } } } void cmd_vbars() { int i, j, k, p; /* * The result of this command should be 8 vertical bars * in the natural RGB order. */ set_lcd_addr_region(16, 79, 0, 63); for (i = 0; i < 64; i++) { for (j = 0; j < 8; j++) { p = 0; if (j & 4) p |= 0xF800; if (j & 2) p |= 0x07E0; if (j & 1) p |= 0x001F; for (k = 0; k < 8; k++) send_pixel_value(p); } } }