Changeset 4ed9bfe in buchla-emu for emu


Ignore:
Timestamp:
09/04/2017 02:28:12 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
d021bbb
Parents:
4f967e8
Message:

Support data keys, X, E, and M.

Location:
emu
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • emu/all.h

    r4f967e8 r4ed9bfe  
    6666
    6767extern SDL_atomic_t run;
     68
     69extern uint32_t vid_win;
     70extern uint32_t ser_win;
    6871
    6972extern void sdl_init(void);
     
    158161extern uint32_t kbd_read(uint32_t off, int32_t sz);
    159162extern void kbd_write(uint32_t off, int32_t sz, uint32_t val);
     163
     164extern void kbd_text(SDL_TextInputEvent *ev);
     165extern void kbd_key(SDL_KeyboardEvent *ev);
  • emu/cpu.c

    r4f967e8 r4ed9bfe  
    8282        { 0x3b4001, 0x3b8001, 0, snd_init, snd_quit, snd_exec, snd_read, snd_write },
    8383        { 0x3b8001, 0x3bc001, 0, led_init, led_quit, led_exec, led_read, led_write },
    84         { 0x3bc001, 0x3c0001, 0, kbd_init, kbd_quit, kbd_exec, kbd_read, kbd_write }
     84        { 0x3bc001, 0x3c0001, 3, kbd_init, kbd_quit, kbd_exec, kbd_read, kbd_write }
    8585};
    8686
  • emu/kbd.c

    r4f967e8 r4ed9bfe  
    2424int32_t kbd_verbose = 0;
    2525
     26#define BUF_SZ 16
     27
     28static int32_t buf_hd = 0;
     29static int32_t buf_tl = 0;
     30static uint8_t buf[BUF_SZ];
     31
     32static uint8_t reg = 0;
     33static bool irq = false;
     34
     35static void xmit(void)
     36{
     37        ver2("kbd xmit %d %d", buf_tl, buf_hd);
     38
     39        if (buf_tl >= buf_hd) {
     40                return;
     41        }
     42
     43        reg = buf[buf_tl % BUF_SZ];
     44        irq = true;
     45        ver2("kbd xmit 0x%02x", reg);
     46
     47        ++buf_tl;
     48
     49        if (buf_tl >= BUF_SZ) {
     50                buf_hd -= BUF_SZ;
     51                buf_tl -= BUF_SZ;
     52                ver2("kbd adj %d %d", buf_tl, buf_hd);
     53        }
     54}
     55
     56static void out(uint8_t c)
     57{
     58        ver2("kbd out %d %d 0x%02x", buf_tl, buf_hd, c);
     59
     60        if (SDL_LockMutex(cpu_mutex) < 0) {
     61                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     62        }
     63
     64        if (buf_hd >= buf_tl + BUF_SZ) {
     65                err("keyboard port losing data");
     66        }
     67        else {
     68                buf[buf_hd % BUF_SZ] = c;
     69                ++buf_hd;
     70
     71                if (!irq) {
     72                        xmit();
     73                }
     74        }
     75
     76        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     77                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     78        }
     79}
     80
     81static void but_on(int32_t sig)
     82{
     83        out((uint8_t)(0x80 | sig));
     84        out(0x01);
     85}
     86
     87static void but_off(int32_t sig)
     88{
     89        out((uint8_t)(0x80 | sig));
     90        out(0x00);
     91}
     92
     93#if defined NOT_YET
     94static void key_touch(int32_t sig, int32_t val)
     95{
     96        out((uint8_t)(0x80 | sig));
     97        out(0x01);
     98        out((uint8_t)val);
     99}
     100
     101static void key_off(int32_t sig)
     102{
     103        out((uint8_t)(0x80 | sig));
     104        out(0x00);
     105}
     106
     107static void pot_128(int32_t sig, int32_t val)
     108{
     109        out((uint8_t)(0x80 | sig));
     110        out((uint8_t)val);
     111}
     112
     113static void pot_256(int32_t sig, int32_t val)
     114{
     115        out((uint8_t)(0x80 | sig));
     116        out((uint8_t)((val >> 7) & 0x01));
     117        out((uint8_t)(val & 0x7f));
     118}
     119#endif
     120
     121void kbd_key(SDL_KeyboardEvent *ev)
     122{
     123        (void)ev;
     124}
     125
     126void kbd_text(SDL_TextInputEvent *ev)
     127{
     128        for (int32_t i = 0; ev->text[i] != 0; ++i) {
     129                if (ev->text[i] >= '0' && ev->text[i] <= '9') {
     130                        int32_t sig = 60 + ev->text[i] - '0';
     131                        but_on(sig);
     132                        but_off(sig);
     133                        continue;
     134                }
     135
     136                switch (ev->text[i]) {
     137                case 'x':
     138                        but_on(70);
     139                        but_off(70);
     140                        break;
     141
     142                case 'e':
     143                        but_on(71);
     144                        but_off(71);
     145                        break;
     146
     147                case 'm':
     148                        but_on(72);
     149                        but_off(72);
     150                        break;
     151                }
     152        }
     153}
     154
    26155void kbd_init(void)
    27156{
     
    37166{
    38167        ver3("kbd exec");
    39         return false;
     168        return irq;
    40169}
    41170
     
    43172{
    44173        ver2("kbd rd %u:%d", off, sz * 8);
    45         return 0;
     174
     175        if (sz != 1 || off > 0) {
     176                fail("invalid kbd rd %u:%d", off, sz * 8);
     177        }
     178
     179        irq = false;
     180        uint32_t res = reg;
     181
     182        xmit();
     183
     184        return res;
    46185}
    47186
     
    49188{
    50189        ver2("kbd wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val);
     190        fail("invalid kbd wr %u:%d", off, sz * 8);
    51191}
  • emu/sdl.c

    r4f967e8 r4ed9bfe  
    6767
    6868        bool rel_mod = false;
     69        uint32_t win = 0;
    6970
    7071        while (SDL_AtomicGet(&run) != 0) {
     
    101102                                SDL_AtomicSet(&run, 0);
    102103                                continue;
     104                        }
     105
     106                        if (ev.type == SDL_WINDOWEVENT) {
     107                                if (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
     108                                        ver("sdl ev win %u", ev.window.windowID);
     109                                        win = ev.window.windowID;
     110                                }
    103111                        }
    104112
     
    138146                        if (ev.type == SDL_TEXTINPUT) {
    139147                                ver("sdl ev text input %d", ev.text.text[0]);
    140                                 ser_text(&ev.text);
     148
     149                                if (win == ser_win) {
     150                                        ser_text(&ev.text);
     151                                }
     152                                else if (win == vid_win) {
     153                                        kbd_text(&ev.text);
     154                                }
     155
    141156                                continue;
    142157                        }
     
    144159                        if (ev.type == SDL_KEYDOWN) {
    145160                                ver("sdl ev key down %d", (int32_t)ev.key.keysym.sym);
    146                                 ser_key(&ev.key);
     161
     162                                if (win == ser_win) {
     163                                        ser_key(&ev.key);
     164                                }
     165                                else if (win == vid_win) {
     166                                        kbd_key(&ev.key);
     167                                }
     168
    147169                                continue;
    148170                        }
  • emu/ser.c

    r4f967e8 r4ed9bfe  
    6363
    6464static SDL_Window *win;
     65uint32_t ser_win;
     66
    6567static SDL_Renderer *ren;
    6668static SDL_atomic_t frame;
     
    477479        }
    478480
     481        ser_win = SDL_GetWindowID(win);
     482
     483        if (ser_win == 0) {
     484                fail("SDL_GetWindowID() failed: %s", SDL_GetError());
     485        }
     486
    479487        ren = SDL_CreateRenderer(win, -1, 0);
    480488
  • emu/vid.c

    r4f967e8 r4ed9bfe  
    8080
    8181static SDL_Window *win;
     82uint32_t vid_win;
     83
    8284static SDL_Renderer *ren;
    8385static SDL_Texture *tex;
     
    225227        if (win == NULL) {
    226228                fail("SDL_CreateWindow() failed: %s", SDL_GetError());
     229        }
     230
     231        vid_win = SDL_GetWindowID(win);
     232
     233        if (vid_win == 0) {
     234                fail("SDL_GetWindowID() failed: %s", SDL_GetError());
    227235        }
    228236
Note: See TracChangeset for help on using the changeset viewer.