Changes in emu/ser.c [c5b6c90:0edef06] in buchla-emu
Legend:
- Unmodified
- Added
- Removed
-
emu/ser.c
rc5b6c90 r0edef06 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 41 39 #define REG_IER_ISR 0 42 40 #define REG_CFR_SR 1 … … 60 58 static SDL_Window *win; 61 59 static SDL_Renderer *ren; 60 static SDL_atomic_t frame; 62 61 63 62 static TTF_Font *fon; … … 70 69 static int32_t bel = 0; 71 70 72 static void update(void) 73 { 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 74 182 if (SDL_FillRect(sur, NULL, bel == 0 ? CON_BGR : CON_BEL) < 0) { 75 183 fail("SDL_FillRect() failed: %s", SDL_GetError()); … … 86 194 87 195 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); 89 209 90 210 if (lin == NULL) { … … 118 238 } 119 239 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 209 240 void ser_key(SDL_KeyboardEvent *ev) 210 241 { … … 252 283 } 253 284 254 SDL_RWops *ops = SDL_RWFromFile(CON_FONT, "rb"); 285 SDL_AtomicSet(&frame, 1); 286 287 SDL_RWops *ops = SDL_RWFromFile(font, "rb"); 255 288 256 289 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()); 258 291 } 259 292 … … 261 294 262 295 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()); 264 297 } 265 298 … … 286 319 mem[y][CON_W] = 0; 287 320 } 288 289 update();290 321 } 291 322 … … 309 340 310 341 if (bel == BEL_CYC - 1 || bel == 0) { 311 update();342 SDL_AtomicAdd(&frame, 1); 312 343 } 313 344 }
Note:
See TracChangeset
for help on using the changeset viewer.