Changeset 657abdf in buchla-emu for emu


Ignore:
Timestamp:
08/20/2017 09:47:23 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
7ba68aa, c1c1ca5
Parents:
a9861f3
Message:

Serial FIFO. Mouse support.

Location:
emu
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • emu/all.h

    ra9861f3 r657abdf  
    121121extern void ser_key(SDL_KeyboardEvent *ev);
    122122
     123extern void ser_mou_res(void);
     124extern void ser_mou_mov(SDL_MouseMotionEvent *ev);
     125extern void ser_mou_dn(SDL_MouseButtonEvent *ev);
     126extern void ser_mou_up(SDL_MouseButtonEvent *ev);
     127
    123128extern void mid_init(void);
    124129extern void mid_quit(void);
  • emu/sdl.c

    ra9861f3 r657abdf  
    106106                                ver("sdl ev down-arrow");
    107107                                rel_mod = true;
     108                                ser_mou_res();
    108109                                continue;
    109110                        }
     
    113114                                rel_mod = false;
    114115                                continue;
     116                        }
     117
     118                        if (rel_mod) {
     119                                if (ev.type == SDL_MOUSEMOTION) {
     120                                        ver("sdl ev mousemotion (%d, %d)", ev.motion.xrel, ev.motion.yrel);
     121                                        ser_mou_mov(&ev.motion);
     122                                        continue;
     123                                }
     124
     125                                if (ev.type == SDL_MOUSEBUTTONDOWN) {
     126                                        ver("sdl ev mousebuttondown %d", ev.button.button);
     127                                        ser_mou_dn(&ev.button);
     128                                        continue;
     129                                }
     130
     131                                if (ev.type == SDL_MOUSEBUTTONUP) {
     132                                        ver("sdl ev mousebuttonup %d", ev.button.button);
     133                                        ser_mou_up(&ev.button);
     134                                        continue;
     135                                }
    115136                        }
    116137
  • emu/ser.c

    ra9861f3 r657abdf  
    2828
    2929#define BEL_CYC 10000
     30#define MOU_CYC 10000
    3031
    3132#define CON_W 80
     
    3738#define CON_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 })
    3839
     40#define BUF_SZ 16
     41
    3942#define REG_IER_ISR 0
    4043#define REG_CFR_SR  1
     
    4346
    4447typedef struct {
     48        int32_t buf_hd;
     49        int32_t buf_tl;
     50        uint8_t buf[BUF_SZ];
    4551        bool irq_r;
    4652        bool irq_t;
     
    5056
    5157static state_t state[] = {
    52         { .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 },
    53         { .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 }
     58        { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 },
     59        { .buf_hd = 0, .buf_tl = 0, .irq_r = false, .irq_t = false, .rdr_ok = false, .rdr = 0x00 }
    5460};
    5561
     
    6874static int32_t cur_x = 0, cur_y = 0;
    6975static int32_t bel = 0;
     76
     77static int32_t mou;
     78static int32_t mou_dx, mou_dy;
     79static bool mou_l, mou_r;
    7080
    7181static void scroll(void)
     
    151161}
    152162
     163static void xmit(int32_t un)
     164{
     165        int32_t i = state[un].buf_tl;
     166        ver2("ser xmit %d %d", i, state[un].buf_hd);
     167
     168        if (i >= state[un].buf_hd) {
     169                return;
     170        }
     171
     172        uint8_t byte = state[un].buf[i % BUF_SZ];
     173        ver2("ser xmit 0x%02x", byte);
     174
     175        state[un].rdr = byte;
     176        state[un].rdr_ok = true;
     177        state[un].irq_r = true;
     178
     179        state[un].buf_tl = i + 1;
     180
     181        if (state[un].buf_tl >= BUF_SZ) {
     182                state[un].buf_hd -= BUF_SZ;
     183                state[un].buf_tl -= BUF_SZ;
     184                ver2("ser adj %d %d", state[un].buf_tl, state[un].buf_hd);
     185        }
     186}
     187
     188static void out_lk(int32_t un, uint8_t c)
     189{
     190        int32_t i = state[un].buf_hd;
     191        ver2("ser out %d %d 0x%02x", state[un].buf_tl, i, c);
     192
     193        if (i >= state[un].buf_tl + BUF_SZ) {
     194                err("serial port %d losing data", un);
     195                return;
     196        }
     197
     198        state[un].buf[i % BUF_SZ] = c;
     199        state[un].buf_hd = i + 1;
     200
     201        if (!state[un].irq_r && !state[un].rdr_ok) {
     202                xmit(un);
     203        }
     204}
     205
    153206static void out(int32_t un, uint8_t c)
    154207{
     
    157210        }
    158211
    159         state[un].rdr = c;
    160         state[un].rdr_ok = true;
    161         state[un].irq_r = true;
     212        out_lk(un, c);
    162213
    163214        if (SDL_UnlockMutex(cpu_mutex) < 0) {
    164215                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
    165216        }
     217}
     218
     219static void mouse(uint8_t c)
     220{
     221        if (c == 't') {
     222                ver2("ser mou init");
     223        }
     224
     225        out_lk(0, 'V');
     226        out_lk(0, 'O');
    166227}
    167228
     
    266327}
    267328
     329static void mou_ev(void)
     330{
     331        ver2("ser mou ev (%d, %d) %c %c",
     332                mou_dx, mou_dy, mou_l ? 'l' : '-', mou_r ? 'r' : '-');
     333
     334        int32_t dx = mou_dx;
     335        int32_t dy = mou_dy;
     336
     337        if (dx < -128) {
     338                dx = -128;
     339        }
     340        else if (dx > 127) {
     341                dx = 127;
     342        }
     343
     344        if (dy < -128) {
     345                dy = -128;
     346        }
     347        else if (dy > 127) {
     348                dy = 127;
     349        }
     350
     351        dx = dx & 0xff;
     352        dy = dy & 0xff;
     353
     354        int32_t b1 = 0x40;
     355
     356        if (mou_l) {
     357                b1 |= 0x20;
     358        }
     359
     360        if (mou_r) {
     361                b1 |= 0x10;
     362        }
     363
     364        b1 |= (dy & 0xc0) >> 4;
     365        b1 |= (dx & 0xc0) >> 6;
     366
     367        int32_t b2 = dx & 0x3f;
     368        int32_t b3 = dy & 0x3f;
     369
     370        out_lk(0, (uint8_t)b1);
     371        out_lk(0, (uint8_t)b2);
     372        out_lk(0, (uint8_t)b3);
     373
     374        mou_dx = mou_dy = 0;
     375}
     376
     377static void mou_ev_chk(void)
     378{
     379        if (--mou > 0) {
     380                return;
     381        }
     382
     383        mou = MOU_CYC;
     384
     385        if (mou_dx == 0 && mou_dy == 0) {
     386                return;
     387        }
     388
     389        mou_ev();
     390}
     391
     392void ser_mou_res(void)
     393{
     394        if (SDL_LockMutex(cpu_mutex) < 0) {
     395                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     396        }
     397
     398        mou = MOU_CYC;
     399        mou_dx = mou_dy = 0;
     400        mou_l = mou_r = false;
     401
     402        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     403                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     404        }
     405}
     406
     407void ser_mou_mov(SDL_MouseMotionEvent *ev)
     408{
     409        if (SDL_LockMutex(cpu_mutex) < 0) {
     410                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     411        }
     412
     413        mou_dx += ev->xrel;
     414        mou_dy += ev->yrel;
     415
     416        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     417                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     418        }
     419}
     420
     421void ser_mou_dn(SDL_MouseButtonEvent *ev)
     422{
     423        if (SDL_LockMutex(cpu_mutex) < 0) {
     424                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     425        }
     426
     427        if (ev->button == SDL_BUTTON_LEFT) {
     428                mou_l = true;
     429        }
     430        else if (ev->button == SDL_BUTTON_RIGHT) {
     431                mou_r = true;
     432        }
     433        else {
     434                return;
     435        }
     436
     437        mou_ev();
     438
     439        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     440                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     441        }
     442}
     443
     444void ser_mou_up(SDL_MouseButtonEvent *ev)
     445{
     446        if (SDL_LockMutex(cpu_mutex) < 0) {
     447                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     448        }
     449
     450        if (ev->button == SDL_BUTTON_LEFT) {
     451                mou_l = false;
     452        }
     453        else if (ev->button == SDL_BUTTON_RIGHT) {
     454                mou_r = false;
     455        }
     456        else {
     457                return;
     458        }
     459
     460        mou_ev();
     461
     462        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     463                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     464        }
     465}
     466
    268467void ser_init(void)
    269468{
     
    343542                }
    344543        }
     544
     545        mou_ev_chk();
    345546
    346547        return state[0].irq_r || state[0].irq_t || state[1].irq_r || state[1].irq_t;
     
    379580        }
    380581
     582        if (!state[un].irq_r && !state[un].rdr_ok) {
     583                xmit(un);
     584        }
     585
    381586        return rv;
    382587}
     
    396601        case REG_TDR_RDR:
    397602                ver2("TDR[%d] 0x%02x", un, val);
    398                 echo((uint8_t)val);
     603
     604                if (un == 1) {
     605                        echo((uint8_t)val);
     606                }
     607                else {
     608                        mouse((uint8_t)val);
     609                }
     610
    399611                state[un].irq_t = true;
    400612                break;
Note: See TracChangeset for help on using the changeset viewer.