Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p3_wordprocessor.c @ 82:bc3092c41335
Cleaning up old wordprocessor to make it OLEDSim compatible.
author | JeanDo |
---|---|
date | Tue, 07 Dec 2010 13:22:17 +0100 |
parents | 77f1556457b1 |
children |
comparison
equal
deleted
inserted
replaced
81:31fa973a70fd | 82:bc3092c41335 |
---|---|
55 // #include "ostc90.tbl.txt" | 55 // #include "ostc90.tbl.txt" |
56 // assembler code (PART 1) for working OSTC experimental plattform | 56 // assembler code (PART 1) for working OSTC experimental plattform |
57 // C code (PART 2) for working OSTC experimental plattform | 57 // C code (PART 2) for working OSTC experimental plattform |
58 // | 58 // |
59 // history: | 59 // history: |
60 // | 60 // 2010-12-1 : jDG Cleanups to a tighter code. |
61 | 61 |
62 | 62 |
63 // ********************* | 63 // ********************* |
64 // ** I N C L U D E S ** | 64 // ** I N C L U D E S ** |
65 // ********************* | 65 // ********************* |
100 // *********************** | 100 // *********************** |
101 | 101 |
102 #pragma udata bank0a=0x060 | 102 #pragma udata bank0a=0x060 |
103 // input | 103 // input |
104 volatile unsigned char wp_stringstore[26]; | 104 volatile unsigned char wp_stringstore[26]; |
105 volatile unsigned char wp_color1; | 105 volatile unsigned int wp_color; |
106 volatile unsigned char wp_color2; | |
107 volatile unsigned char wp_top; | 106 volatile unsigned char wp_top; |
108 volatile unsigned char wp_leftx2; | 107 volatile unsigned char wp_leftx2; |
109 volatile unsigned char wp_font; | 108 volatile unsigned char wp_font; |
110 volatile unsigned char wp_invert; | 109 volatile unsigned char wp_invert; |
111 // internal | 110 // internal |
112 volatile unsigned char wp_temp_U8; | 111 volatile unsigned char wp_temp_U8; |
113 volatile unsigned char wp_txtptr; | 112 volatile unsigned char wp_txtptr; |
114 volatile unsigned char wp_char; | 113 volatile unsigned char wp_char; |
115 volatile unsigned char wp_command; | 114 volatile unsigned char wp_command; |
116 volatile unsigned int wp_data_16bit; | 115 volatile unsigned int wp_data_16bit; |
117 volatile unsigned char wp_data_8bit_one; | |
118 volatile unsigned char wp_data_8bit_two; | |
119 volatile unsigned int wp_start; | 116 volatile unsigned int wp_start; |
120 volatile unsigned int wp_end; | 117 volatile unsigned int wp_end; |
121 volatile unsigned int wp_i; | 118 volatile unsigned int wp_i; |
122 volatile unsigned char wp_black; | |
123 volatile unsigned char wp_debug_U8; | 119 volatile unsigned char wp_debug_U8; |
120 | |
121 // Temporary used only inside the wordprocessor.c module | |
122 static unsigned int wp_string_width = 0; | |
124 | 123 |
125 | 124 |
126 // ************************* | 125 // ************************* |
127 // ** P R O T O T Y P E S ** | 126 // ** P R O T O T Y P E S ** |
128 // ************************* | 127 // ************************* |
130 | 129 |
131 void main_calc_wordprocessor(void); | 130 void main_calc_wordprocessor(void); |
132 | 131 |
133 void wp_write_command(void); | 132 void wp_write_command(void); |
134 void wp_write_data(void); | 133 void wp_write_data(void); |
135 void wp_write_black(void); | |
136 void wp_write_color(void); | |
137 void wp_set_window(void); | 134 void wp_set_window(void); |
138 void wp_set_char_font_small(void); | 135 void wp_set_char_font_small(void); |
139 void wp_set_char_font_medium(void); | 136 void wp_set_char_font_medium(void); |
140 void wp_set_char_font_large(void); | 137 void wp_set_char_font_large(void); |
141 void wordprocessor(void); | 138 void wordprocessor(void); |
161 #pragma code main = 0x9000 | 158 #pragma code main = 0x9000 |
162 void main(void) | 159 void main(void) |
163 { | 160 { |
164 wp_top = 10; | 161 wp_top = 10; |
165 wp_leftx2 = 10; | 162 wp_leftx2 = 10; |
166 wp_color1 = 255; | 163 wp_color = 0xFFFF; |
167 wp_color2 = 255; | |
168 wp_font = 0; | 164 wp_font = 0; |
169 wp_invert = 0; | 165 wp_invert = 0; |
170 wp_stringstore[0] = ' '; | 166 wp_stringstore[0] = ' '; |
171 wp_stringstore[1] = '!'; | 167 wp_stringstore[1] = '!'; |
172 wp_stringstore[2] = '"'; | 168 wp_stringstore[2] = '"'; |
224 // ********************** | 220 // ********************** |
225 // ********************** | 221 // ********************** |
226 #pragma code main_wordprocessor = 0x0B468 | 222 #pragma code main_wordprocessor = 0x0B468 |
227 void main_wordprocessor(void) | 223 void main_wordprocessor(void) |
228 { | 224 { |
229 wordprocessor(); | 225 _asm |
226 goto wordprocessor | |
227 _endasm | |
230 } | 228 } |
231 | 229 |
232 // ********************* | 230 // ********************* |
233 // ********************* | 231 // ********************* |
234 // ** THE SUBROUTINES ** | 232 // ** THE SUBROUTINES ** |
251 _endasm | 249 _endasm |
252 } | 250 } |
253 | 251 |
254 void wp_write_data(void) | 252 void wp_write_data(void) |
255 { | 253 { |
256 wp_data_8bit_one = wp_data_16bit >> 8; | |
257 wp_data_8bit_two = wp_data_16bit; | |
258 _asm | 254 _asm |
259 bsf oled_rs | 255 bsf oled_rs |
260 movff wp_data_8bit_one,PORTD | 256 movff wp_data_16bit+1,PORTD // OLED commands are big endian... |
261 bcf oled_rw | 257 bcf oled_rw |
262 bsf oled_rw | 258 bsf oled_rw |
263 movff wp_data_8bit_two,PORTD | 259 movff wp_data_16bit+0,PORTD |
264 bcf oled_rw | 260 bcf oled_rw |
265 bsf oled_rw | 261 bsf oled_rw |
266 _endasm | 262 _endasm |
267 } | 263 } |
268 | 264 |
269 void wp_write_black(void) | 265 ////////////////////////////////////////////////////////////////////////////// |
270 { | 266 |
271 _asm | 267 void wp_char_width(void) |
272 movff wp_black,PORTD | 268 { |
273 bcf oled_rw | 269 wp_string_width = 0; |
274 bsf oled_rw | 270 for(wp_txtptr = 0; wp_txtptr < 26; wp_txtptr++) |
275 bcf oled_rw | 271 { |
276 bsf oled_rw | 272 wp_char = wp_stringstore[wp_txtptr]; |
277 _endasm | 273 if( wp_char == 0 ) break; |
278 } | 274 |
279 | 275 if(wp_font == 2) |
280 void wp_write_color(void) | 276 wp_set_char_font_large(); |
281 { | 277 else if(wp_font == 1) |
282 _asm | 278 wp_set_char_font_medium(); |
283 movff wp_color1,PORTD | 279 else |
284 bcf oled_rw | 280 wp_set_char_font_small(); |
285 bsf oled_rw | 281 |
286 movff wp_color2,PORTD | 282 for(wp_i = wp_start; wp_i<wp_end;wp_i++) |
287 bcf oled_rw | 283 { |
288 bsf oled_rw | 284 wp_data_16bit = wp_i ^ 1; |
289 _endasm | 285 if(wp_font == 2) |
290 } | 286 wp_temp_U8 = ((rom unsigned char*)wp_large_data)[wp_data_16bit]; |
287 else if(wp_font == 1) | |
288 wp_temp_U8 = ((rom unsigned char*)wp_medium_data)[wp_data_16bit]; | |
289 else | |
290 wp_temp_U8 = ((rom unsigned char*)wp_small_data)[wp_data_16bit]; | |
291 | |
292 wp_temp_U8 = 1 + (wp_temp_U8 & 127); | |
293 wp_string_width += wp_temp_U8; | |
294 } | |
295 } | |
296 | |
297 if(wp_font == 2) | |
298 wp_string_width /= WP_FONT_LARGE_HEIGHT; | |
299 else if(wp_font == 1) | |
300 wp_string_width /= WP_FONT_MEDIUM_HEIGHT; | |
301 else | |
302 wp_string_width /= WP_FONT_SMALL_HEIGHT; | |
303 } | |
304 | |
305 ////////////////////////////////////////////////////////////////////////////// | |
291 | 306 |
292 void wp_set_window(void) | 307 void wp_set_window(void) |
293 { | 308 { |
309 // Compute string width (in pixels) | |
310 wp_char_width(); | |
311 | |
294 // x axis start ( 0 - 319) | 312 // x axis start ( 0 - 319) |
295 wp_command = 0x35; | 313 wp_command = 0x35; |
296 wp_write_command(); | 314 wp_write_command(); |
297 wp_data_16bit = ((unsigned int)wp_leftx2) << 1; | 315 wp_data_16bit = ((unsigned int)wp_leftx2) << 1; |
298 wp_write_data(); | 316 wp_write_data(); |
299 // x axis end ( 0 - 319) | 317 // x axis end ( 0 - 319) |
300 wp_command = 0x36; | 318 wp_command = 0x36; |
301 wp_write_command(); | 319 wp_write_command(); |
302 wp_data_16bit = 319; | 320 wp_data_16bit = wp_data_16bit + wp_string_width -1; |
303 wp_write_data(); | 321 wp_write_data(); |
304 // y axis start + end ( 0 - 239 ) | 322 // y axis start + end ( 0 - 239 ) |
305 wp_command = 0x37; | 323 wp_command = 0x37; |
306 wp_write_command(); | 324 wp_write_command(); |
307 // the bottom part | 325 // the bottom part |
366 if((wp_char < '.') || (wp_char > '9')) | 384 if((wp_char < '.') || (wp_char > '9')) |
367 wp_char = 0x2F; | 385 wp_char = 0x2F; |
368 wp_start = wp_large_table[wp_char - '.']; | 386 wp_start = wp_large_table[wp_char - '.']; |
369 wp_end = wp_large_table[1 + wp_char - '.']; | 387 wp_end = wp_large_table[1 + wp_char - '.']; |
370 } | 388 } |
389 | |
371 void wordprocessor(void) | 390 void wordprocessor(void) |
372 { | 391 { |
373 #define TOPLIMIT 230 | 392 #define TOPLIMIT 230 |
374 #define LEFTLIMIT 155 | 393 #define LEFTLIMIT 155 |
375 | 394 |
376 if(wp_top > TOPLIMIT) | 395 if(wp_top > TOPLIMIT) |
377 wp_top = TOPLIMIT; | 396 wp_top = TOPLIMIT; |
378 if(wp_leftx2 > LEFTLIMIT) | 397 if(wp_leftx2 > LEFTLIMIT) |
379 wp_leftx2 = LEFTLIMIT; | 398 wp_leftx2 = LEFTLIMIT; |
380 | 399 |
400 // FIX C18 Bug: avoid crash if TBLPTRU was set somewhere... | |
401 // Should be called once before first PROM read, ie. font | |
402 // definition access... | |
403 _asm | |
404 clrf TBLPTRU, ACCESS | |
405 _endasm | |
406 | |
381 wp_set_window(); | 407 wp_set_window(); |
408 | |
382 // access to GRAM | 409 // access to GRAM |
383 wp_command = 0x22; | 410 wp_command = 0x22; |
384 wp_write_command(); | 411 wp_write_command(); |
385 _asm | 412 _asm |
386 bsf oled_rs | 413 bsf oled_rs |
387 _endasm | 414 _endasm |
415 | |
388 wp_txtptr = 0; | 416 wp_txtptr = 0; |
389 wp_char = wp_stringstore[wp_txtptr]; | 417 wp_char = wp_stringstore[wp_txtptr]; |
390 /* | 418 |
391 _asm | 419 while( wp_char && (wp_txtptr < 26) ) |
392 lfsr 0x2,0x60 | |
393 movff 0xfde,wp_char | |
394 _endasm | |
395 */ | |
396 if(!wp_char) | |
397 { | |
398 wp_char = ':'; | |
399 wp_txtptr = 25; | |
400 } | |
401 _asm | |
402 clrf TBLPTRU, ACCESS | |
403 _endasm | |
404 while((wp_char) && (wp_txtptr < 26)) | |
405 { | 420 { |
406 if(wp_font == 2) | 421 if(wp_font == 2) |
407 wp_set_char_font_large(); | 422 wp_set_char_font_large(); |
408 else if(wp_font == 1) | 423 else if(wp_font == 1) |
409 wp_set_char_font_medium(); | 424 wp_set_char_font_medium(); |
410 else | 425 else |
411 wp_set_char_font_small(); | 426 wp_set_char_font_small(); |
412 wp_black = 0; | 427 |
413 for(wp_i = wp_start; wp_i<wp_end;wp_i++) | 428 for(wp_i = wp_start; wp_i<wp_end;wp_i++) |
414 { | 429 { |
430 wp_data_16bit = wp_i ^ 1; | |
415 if(wp_font == 2) | 431 if(wp_font == 2) |
416 wp_data_16bit = wp_large_data[wp_i / 2]; | 432 wp_temp_U8 = ((rom unsigned char*)wp_large_data)[wp_data_16bit]; |
417 else if(wp_font == 1) | 433 else if(wp_font == 1) |
418 wp_data_16bit = wp_medium_data[wp_i / 2]; | 434 wp_temp_U8 = ((rom unsigned char*)wp_medium_data)[wp_data_16bit]; |
419 else | 435 else |
420 wp_data_16bit = wp_small_data[wp_i / 2]; | 436 wp_temp_U8 = ((rom unsigned char*)wp_small_data)[wp_data_16bit]; |
421 if(wp_i & 1) | 437 |
422 wp_temp_U8 = wp_data_16bit & 0xFF; | 438 // Manage to get color (or black) into data_16: |
439 if( wp_invert ) wp_temp_U8 ^= 128; | |
440 if( wp_temp_U8 & 128 ) | |
441 wp_data_16bit = 0; | |
423 else | 442 else |
424 wp_temp_U8 = wp_data_16bit >> 8; | 443 wp_data_16bit = wp_color; |
425 if((wp_temp_U8 & 128)) | 444 |
426 { | 445 // Then send that to screen |
427 wp_temp_U8 -= 127; | 446 wp_temp_U8 = 1 + (wp_temp_U8 & 127); |
428 if(wp_invert) | 447 while(wp_temp_U8-- > 0) |
429 { | |
430 while(wp_temp_U8 > 0) | |
431 { | |
432 wp_temp_U8--; | |
433 wp_write_color(); | |
434 } | |
435 } | |
436 else | |
437 { | 448 { |
438 _asm | 449 _asm |
439 movff wp_black,PORTD | 450 // wp selected color |
440 _endasm | 451 movff wp_data_16bit+1,PORTD // OLED is big endian. PIC is not. |
441 while(wp_temp_U8 > 0) | |
442 { | |
443 wp_temp_U8--; | |
444 _asm | |
445 bcf oled_rw | 452 bcf oled_rw |
446 bsf oled_rw | 453 bsf oled_rw |
454 movff wp_data_16bit+0,PORTD | |
447 bcf oled_rw | 455 bcf oled_rw |
448 bsf oled_rw | 456 bsf oled_rw |
449 _endasm | 457 _endasm |
450 } | 458 } |
451 } | 459 } |
452 } | 460 |
453 else | |
454 { | |
455 wp_temp_U8++; | |
456 if(wp_invert) | |
457 { | |
458 _asm | |
459 movff wp_black,PORTD | |
460 _endasm | |
461 while(wp_temp_U8 > 0) | |
462 { | |
463 wp_temp_U8--; | |
464 _asm | |
465 bcf oled_rw | |
466 bsf oled_rw | |
467 bcf oled_rw | |
468 bsf oled_rw | |
469 _endasm | |
470 } | |
471 } | |
472 else | |
473 { | |
474 while(wp_temp_U8 > 0) | |
475 { | |
476 wp_temp_U8--; | |
477 wp_write_color(); | |
478 } | |
479 } | |
480 } | |
481 } | |
482 /* | |
483 _asm | |
484 movff 0xfde,wp_char | |
485 _endasm | |
486 */ | |
487 wp_txtptr++; | 461 wp_txtptr++; |
488 wp_char = wp_stringstore[wp_txtptr]; | 462 wp_char = wp_stringstore[wp_txtptr]; |
489 } | 463 } |
490 wp_command = 0x00; | 464 wp_command = 0x00; |
491 wp_write_command(); | 465 wp_write_command(); |