Changes in emu/ser.c [0edef06:c5b6c90] in buchla-emu
Legend:
- Unmodified
- Added
- Removed
-
emu/ser.c
r0edef06 rc5b6c90 37 37 #define CON_FGR ((SDL_Color){ .r = 255, .b = 255, .g = 255, .a = 255 }) 38 38 39 #define CON_FONT "ttf/vera-sans-mono.ttf" 40 39 41 #define REG_IER_ISR 0 40 42 #define REG_CFR_SR 1 … … 58 60 static SDL_Window *win; 59 61 static SDL_Renderer *ren; 60 static SDL_atomic_t frame;61 62 62 63 static TTF_Font *fon; … … 69 70 static int32_t bel = 0; 70 71 71 static 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 77 static 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 94 static 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 109 static void down(void) 110 { 111 if (cur_y < CON_H - 1) { 112 ++cur_y; 113 return; 114 } 115 116 scroll(); 117 } 118 119 static 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 153 static 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 168 void 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 72 static void update(void) 73 { 182 74 if (SDL_FillRect(sur, NULL, bel == 0 ? CON_BGR : CON_BEL) < 0) { 183 75 fail("SDL_FillRect() failed: %s", SDL_GetError()); … … 194 86 195 87 for (int32_t y = 0; y < CON_H; ++y) { 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); 88 SDL_Surface *lin = TTF_RenderText_Blended(fon, (char *)mem[y], CON_FGR); 209 89 210 90 if (lin == NULL) { … … 238 118 } 239 119 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 240 209 void ser_key(SDL_KeyboardEvent *ev) 241 210 { … … 283 252 } 284 253 285 SDL_AtomicSet(&frame, 1); 286 287 SDL_RWops *ops = SDL_RWFromFile(font, "rb"); 254 SDL_RWops *ops = SDL_RWFromFile(CON_FONT, "rb"); 288 255 289 256 if (ops == NULL) { 290 fail("error while opening font file %s: %s", font, SDL_GetError());257 fail("error while opening font file " CON_FONT ": %s", SDL_GetError()); 291 258 } 292 259 … … 294 261 295 262 if (fon == NULL) { 296 fail("error while loading font file %s: %s", font, TTF_GetError());263 fail("error while loading font file " CON_FONT ": %s", TTF_GetError()); 297 264 } 298 265 … … 319 286 mem[y][CON_W] = 0; 320 287 } 288 289 update(); 321 290 } 322 291 … … 340 309 341 310 if (bel == BEL_CYC - 1 || bel == 0) { 342 SDL_AtomicAdd(&frame, 1);311 update(); 343 312 } 344 313 }
Note:
See TracChangeset
for help on using the changeset viewer.