Changeset 3c30832 in buchla-emu for emu/ser.c


Ignore:
Timestamp:
07/23/2017 08:57:53 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
375f7fb
Parents:
8e1b163
Message:

Interrupt handling. Serial console shows ROMP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/ser.c

    r8e1b163 r3c30832  
    3131#define CON_FONT "ttf/vera-sans-mono.ttf"
    3232
     33#define REG_IER_ISR 0
     34#define REG_CFR_SR  1
     35#define REG_CDR_TBR 2
     36#define REG_TDR_RDR 3
     37
     38typedef struct {
     39        bool irq;
     40        uint8_t rdr;
     41} state_t;
     42
    3343int32_t ser_verbose = 0;
     44
     45static state_t state[] = {
     46        { .irq = false, .rdr = 0x00 },
     47        { .irq = false, .rdr = 0x00 }
     48};
    3449
    3550static uint8_t mem[CON_H][CON_W + 1];
     
    4257
    4358static int32_t cur_x = 0, cur_y = 0;
     59
     60static void out(int32_t un, uint8_t c)
     61{
     62        state[un].irq = true;
     63        state[un].rdr = c;
     64}
    4465
    4566static void update(void)
     
    173194        switch (ev->keysym.sym) {
    174195        case SDLK_BACKSPACE:
    175                 echo('\b');
     196                out(1, '\b');
    176197                break;
    177198
    178199        case SDLK_RETURN:
    179                 echo('\r');
    180                 echo('\n');
     200                out(1, '\r');
    181201                break;
    182202
     
    184204                if ((ev->keysym.mod & KMOD_CTRL) != 0 &&
    185205                                ev->keysym.sym >= SDLK_a && ev->keysym.sym <= SDLK_z) {
    186                         echo((uint8_t)(ev->keysym.sym - SDLK_a + 1));
     206                        out(1, (uint8_t)(ev->keysym.sym - SDLK_a + 1));
    187207                }
    188208
     
    194214{
    195215        for (int32_t i = 0; ev->text[i] != 0; ++i) {
    196                 echo((uint8_t)ev->text[i]);
     216                out(1, (uint8_t)ev->text[i]);
    197217        }
    198218}
     
    248268}
    249269
    250 void ser_exec(void)
     270bool ser_exec(void)
    251271{
    252272        ver3("ser exec");
     273        return state[0].irq || state[1].irq;
    253274}
    254275
     
    256277{
    257278        ver2("ser rd %u:%d", off, sz * 8);
    258         return 0;
     279
     280        if (sz != 1 || off > 7) {
     281                fail("invalid ser rd %u:%d", off, sz * 8);
     282        }
     283
     284        int32_t rg = (int32_t)(off % 4);
     285        int32_t un = (int32_t)(off / 4);
     286
     287        uint32_t rv;
     288
     289        switch (rg) {
     290        case REG_IER_ISR:
     291                rv = (uint32_t)(0xc0 | (state[un].irq ? 0x01 : 0x00));
     292                ver2("ISR[%d] 0x%02x", un, rv);
     293                break;
     294
     295        case REG_TDR_RDR:
     296                rv = state[un].rdr;
     297                state[un].irq = false;
     298                ver2("RDR[%d] 0x%02x", un, rv);
     299                break;
     300
     301        default:
     302                rv = 0x00;
     303                break;
     304        }
     305
     306        return rv;
    259307}
    260308
     
    262310{
    263311        ver2("ser wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val);
    264 }
     312
     313        if (sz != 1 || off > 7) {
     314                fail("invalid ser wr %u:%d", off, sz * 8);
     315        }
     316
     317        int32_t rg = (int32_t)(off % 4);
     318        int32_t un = (int32_t)(off / 4);
     319
     320        switch (rg) {
     321        case REG_TDR_RDR:
     322                ver2("TDR[%d] 0x%02x", un, val);
     323                echo((uint8_t)val);
     324                break;
     325
     326        default:
     327                break;
     328        }
     329}
Note: See TracChangeset for help on using the changeset viewer.