Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Curses(3) inch(3) seems broken in NetBSD 5



Circa 1983 I wrote a game for the Commodore PET called Intruder.
Some time ago I ported it to Unix with curses(3). In order to try to
reproduce the PET graphic characters that I used, I use ACS characters
(Alternate Character Set) with curses.

One common thing to do with PET programs is to look at screen memory, to
see which character is present at some location. Fortunately, curses
offers the inch(3) family of functions for that.

Up to NetBSD 4.0, this worked fine. In 5.0.1, it seems that it has
broken. I put ACS_PLUS on the screen, and I get back a different value,
seemingly ACS_PLUS & 0xFF.

Here is some sample code, including some debugging which showed me the
problem. The full program can be found at
http://www.falu.nl/~rhialto/intruder/ . You can also get the original
PET Basic program which you can run directly on VICE; see the README
file.

screenpeek(b) == 110, mr == 65646

        acs_plus = ACS_PLUS;
    mr = acs_plus;      /* muur */


/*
 7500 a(0)=2:a(1)=-2*wd:a(2)=-2:a(3)=2*wd
 7520 a=xy-1:pokea,4:rem begin doolhof
 7550 j=int(rnd(1)*4):x=j
 7560 b=a+a(j):ifpeek(b)=mrthenpokeb,j:pokea+a(j)/2,pn:a=b:goto7550
 7570 j=(j+1)*-(j<3):ifj<>xthen7560
 7580 j=peek(a):pokea,pn:ifj<4thena=a-a(j):goto7550
 7590 return
 */
void
make_maze()
{
    struct xy a, b;
    int j, x;

    a = player_pos;
    a.x--;
    screenpoke(a, '@' + 4);
    for (;;) {
top:
        if (maze_delay_option > 0)
            usleep(maze_delay_option * 100);
        x = j = random() % 4;
        do {
            b = add_xy_twice(a, a_a[j]);
            if (screenpeek(b) == mr) {
                fprintf(stderr, "screenpeek(b) == mr\n");
                screenpoke(b, '@' + j);
                screenpoke(add_xy(a, a_a[j]), pn);
                a = b;
                goto top;
            }
            fprintf(stderr, "screenpeek(b) == %d, mr == %d\n", screenpeek(b), 
mr);
            j = (j + 1) % 4;
        } while (j != x);
        j = screenpeek(a) - '@';
        screenpoke(a, pn);
        if (j >= 4)
            break;
        a = subtract_xy_twice(a, a_a[j]);
    }
    fprintf(stderr, "make_maze finished\n");
}


void
screenpoke(struct xy pos, chtype ch)
{
    struct xy old_cursor_pos;

    getyx(stdscr, old_cursor_pos.y, old_cursor_pos.x);
    /*normalise_xy(&pos);*/
    mvaddch(pos.y, pos.x, ch);
    if (maze_delay_option >= 0)
        refresh();
    move(old_cursor_pos.y, old_cursor_pos.x);
}

chtype
screenpeek(struct xy pos)
{
    struct xy old_cursor_pos;
    chtype ch;

    getyx(stdscr, old_cursor_pos.y, old_cursor_pos.x);
    normalise_xy(&pos);
    move(pos.y, pos.x);
    ch = inch();
    move(old_cursor_pos.y, old_cursor_pos.x);

    return ch;
}

-Olaf.
-- 
___ Olaf 'Rhialto' Seibert    -- You author it, and I'll reader it.
\X/ rhialto/at/xs4all.nl      -- Cetero censeo "authored" delendum esse.


Home | Main Index | Thread Index | Old Index