Changes in emu/ser.c [c5b6c90:0edef06] in buchla-emu


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/ser.c

    rc5b6c90 r0edef06  
    3737#define CON_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 })
    3838
    39 #define CON_FONT "ttf/vera-sans-mono.ttf"
    40 
    4139#define REG_IER_ISR 0
    4240#define REG_CFR_SR  1
     
    6058static SDL_Window *win;
    6159static SDL_Renderer *ren;
     60static SDL_atomic_t frame;
    6261
    6362static TTF_Font *fon;
     
    7069static int32_t bel = 0;
    7170
    72 static void update(void)
    73 {
     71static void scroll(void)
     72{
     73        memmove(mem, mem + 1, (CON_H - 1) * (CON_W + 1));
     74        memset(mem + (CON_H - 1), ' ', CON_W);
     75}
     76
     77static void forw(void)
     78{
     79        if (cur_x < CON_W - 1) {
     80                ++cur_x;
     81                return;
     82        }
     83
     84        if (cur_y == CON_H - 1) {
     85                cur_x = 0;
     86                scroll();
     87                return;
     88        }
     89
     90        cur_x = 0;
     91        ++cur_y;
     92}
     93
     94static void back(void)
     95{
     96        if (cur_x > 0) {
     97                --cur_x;
     98                return;
     99        }
     100
     101        if (cur_y == 0) {
     102                return;
     103        }
     104
     105        cur_x = CON_W - 1;
     106        --cur_y;
     107}
     108
     109static void down(void)
     110{
     111        if (cur_y < CON_H - 1) {
     112                ++cur_y;
     113                return;
     114        }
     115
     116        scroll();
     117}
     118
     119static void echo(uint8_t c)
     120{
     121        if (c < 32) {
     122                switch (c) {
     123                case '\r':
     124                        cur_x = 0;
     125                        break;
     126
     127                case '\n':
     128                        down();
     129                        break;
     130
     131                case '\b':
     132                        back();
     133                        break;
     134
     135                case '\a':
     136                        bel = BEL_CYC;
     137                        break;
     138
     139                default:
     140                        echo('^');
     141                        echo((uint8_t)(c + '@'));
     142                        return;
     143                }
     144        }
     145        else {
     146                mem[cur_y][cur_x] = c;
     147                forw();
     148        }
     149
     150        SDL_AtomicAdd(&frame, 1);
     151}
     152
     153static void out(int32_t un, uint8_t c)
     154{
     155        if (SDL_LockMutex(cpu_mutex) < 0) {
     156                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     157        }
     158
     159        state[un].rdr = c;
     160        state[un].rdr_ok = true;
     161        state[un].irq_r = true;
     162
     163        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     164                fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     165        }
     166}
     167
     168void ser_sdl(void)
     169{
     170        ver3("ser_sdl()");
     171
     172        static int32_t last = 0;
     173        int32_t now = SDL_AtomicGet(&frame);
     174
     175        if (last == now) {
     176                ver3("no update");
     177                return;
     178        }
     179
     180        last = now;
     181
    74182        if (SDL_FillRect(sur, NULL, bel == 0 ? CON_BGR : CON_BEL) < 0) {
    75183                fail("SDL_FillRect() failed: %s", SDL_GetError());
     
    86194
    87195        for (int32_t y = 0; y < CON_H; ++y) {
    88                 SDL_Surface *lin = TTF_RenderText_Blended(fon, (char *)mem[y], CON_FGR);
     196                char line[CON_W + 1];
     197
     198                if (SDL_LockMutex(cpu_mutex) < 0) {
     199                        fail("SDL_LockMutex() failed: %s", SDL_GetError());
     200                }
     201
     202                memcpy(line, mem[y], CON_W + 1);
     203
     204                if (SDL_UnlockMutex(cpu_mutex) < 0) {
     205                        fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
     206                }
     207
     208                SDL_Surface *lin = TTF_RenderText_Blended(fon, line, CON_FGR);
    89209
    90210                if (lin == NULL) {
     
    118238}
    119239
    120 static void scroll(void)
    121 {
    122         memmove(mem, mem + 1, (CON_H - 1) * (CON_W + 1));
    123         memset(mem + (CON_H - 1), ' ', CON_W);
    124 }
    125 
    126 static void forw(void)
    127 {
    128         if (cur_x < CON_W - 1) {
    129                 ++cur_x;
    130                 return;
    131         }
    132 
    133         if (cur_y == CON_H - 1) {
    134                 cur_x = 0;
    135                 scroll();
    136                 return;
    137         }
    138 
    139         cur_x = 0;
    140         ++cur_y;
    141 }
    142 
    143 static void back(void)
    144 {
    145         if (cur_x > 0) {
    146                 --cur_x;
    147                 return;
    148         }
    149 
    150         if (cur_y == 0) {
    151                 return;
    152         }
    153 
    154         cur_x = CON_W - 1;
    155         --cur_y;
    156 }
    157 
    158 static void down(void)
    159 {
    160         if (cur_y < CON_H - 1) {
    161                 ++cur_y;
    162                 return;
    163         }
    164 
    165         scroll();
    166 }
    167 
    168 static void echo(uint8_t c)
    169 {
    170         if (c < 32) {
    171                 switch (c) {
    172                 case '\r':
    173                         cur_x = 0;
    174                         break;
    175 
    176                 case '\n':
    177                         down();
    178                         break;
    179 
    180                 case '\b':
    181                         back();
    182                         break;
    183 
    184                 case '\a':
    185                         bel = BEL_CYC;
    186                         break;
    187 
    188                 default:
    189                         echo('^');
    190                         echo((uint8_t)(c + '@'));
    191                         return;
    192                 }
    193         }
    194         else {
    195                 mem[cur_y][cur_x] = c;
    196                 forw();
    197         }
    198 
    199         update();
    200 }
    201 
    202 static void out(int32_t un, uint8_t c)
    203 {
    204         state[un].rdr = c;
    205         state[un].rdr_ok = true;
    206         state[un].irq_r = true;
    207 }
    208 
    209240void ser_key(SDL_KeyboardEvent *ev)
    210241{
     
    252283        }
    253284
    254         SDL_RWops *ops = SDL_RWFromFile(CON_FONT, "rb");
     285        SDL_AtomicSet(&frame, 1);
     286
     287        SDL_RWops *ops = SDL_RWFromFile(font, "rb");
    255288
    256289        if (ops == NULL) {
    257                 fail("error while opening font file " CON_FONT ": %s", SDL_GetError());
     290                fail("error while opening font file %s: %s", font, SDL_GetError());
    258291        }
    259292
     
    261294
    262295        if (fon == NULL) {
    263                 fail("error while loading font file " CON_FONT ": %s", TTF_GetError());
     296                fail("error while loading font file %s: %s", font, TTF_GetError());
    264297        }
    265298
     
    286319                mem[y][CON_W] = 0;
    287320        }
    288 
    289         update();
    290321}
    291322
     
    309340
    310341                if (bel == BEL_CYC - 1 || bel == 0) {
    311                         update();
     342                        SDL_AtomicAdd(&frame, 1);
    312343                }
    313344        }
Note: See TracChangeset for help on using the changeset viewer.