- Timestamp:
- 07/23/2017 08:57:53 PM (7 years ago)
- Branches:
- master
- Children:
- 375f7fb
- Parents:
- 8e1b163
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/ser.c
r8e1b163 r3c30832 31 31 #define CON_FONT "ttf/vera-sans-mono.ttf" 32 32 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 38 typedef struct { 39 bool irq; 40 uint8_t rdr; 41 } state_t; 42 33 43 int32_t ser_verbose = 0; 44 45 static state_t state[] = { 46 { .irq = false, .rdr = 0x00 }, 47 { .irq = false, .rdr = 0x00 } 48 }; 34 49 35 50 static uint8_t mem[CON_H][CON_W + 1]; … … 42 57 43 58 static int32_t cur_x = 0, cur_y = 0; 59 60 static void out(int32_t un, uint8_t c) 61 { 62 state[un].irq = true; 63 state[un].rdr = c; 64 } 44 65 45 66 static void update(void) … … 173 194 switch (ev->keysym.sym) { 174 195 case SDLK_BACKSPACE: 175 echo('\b');196 out(1, '\b'); 176 197 break; 177 198 178 199 case SDLK_RETURN: 179 echo('\r'); 180 echo('\n'); 200 out(1, '\r'); 181 201 break; 182 202 … … 184 204 if ((ev->keysym.mod & KMOD_CTRL) != 0 && 185 205 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)); 187 207 } 188 208 … … 194 214 { 195 215 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]); 197 217 } 198 218 } … … 248 268 } 249 269 250 voidser_exec(void)270 bool ser_exec(void) 251 271 { 252 272 ver3("ser exec"); 273 return state[0].irq || state[1].irq; 253 274 } 254 275 … … 256 277 { 257 278 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; 259 307 } 260 308 … … 262 310 { 263 311 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.