2 ; Groepaz/Hitmen, 11.10.2015
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
8 .export soft80_cputcxy, soft80_cputc
9 .export soft80_cputdirect, soft80_putchar
10 .export soft80_newline, soft80_plot
11 .export soft80_checkchar
16 .import soft80_internal_bgcolor, soft80_internal_textcolor
17 .import soft80_internal_cursorxlsb
27 jsr _gotoxy ; Set cursor, drop x
30 ; Plot a character - also used as internal function
39 ; Set cursor position, calculate RAM pointers
44 jmp soft80_kplot ; Set the new cursor
47 beq soft80_newline ; Recalculate pointers
49 ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
50 ; codes $00-$1f are control codes which are not printable and thus may
51 ; give undefined result.
55 ; codes $80-$ff must get converted like this:
56 ; $80-$9f -> dont care (control codes)
67 ; entry point for direct output of a character. the value passed in
68 ; akku must match the offset in the charset.
69 ; - the following may not modify tmp1
71 jsr soft80_putchar ; Write the character to the screen
73 ; Advance cursor position
81 sta soft80_internal_cursorxlsb
102 ; - the following may not modify tmp1
124 ;-------------------------------------------------------------------------------
125 ; All following code belongs to the character output to bitmap
127 ; this stuff is going to be used a lot so we unroll it a bit for speed
128 ;-------------------------------------------------------------------------------
130 .if SOFT80FASTSPACE = 1
132 ; output inverted space (odd)
133 draw_spaceinvers_odd:
144 ; output inverted space (general entry point)
148 .if SOFT80COLORVOODOO = 1
152 sta (CRAM_PTR),y ; vram
155 lda soft80_internal_cursorxlsb
156 bne draw_spaceinvers_odd
158 ; output inverted space (even)
181 ; output space (general entry point)
188 .if SOFT80COLORVOODOO = 1
191 ;ldy #$00 ; is still $00
193 lda soft80_internal_cursorxlsb
196 ; output space (even)
208 ;-------------------------------------------------------------------------------
209 ; output one character in internal encoding without advancing cursor position
210 ; generic entry point
212 ; - the following may not modify tmp1
217 sta tmp3 ; remember charcode
224 stx $01 ; will stay $34 for space
225 ldy #$00 ; will be $00 from now on
227 .if SOFT80FASTSPACE = 1
228 cmp #' ' ; space is a special (optimized) case
232 .if SOFT80COLORVOODOO = 1
236 sta (CRAM_PTR),y ; vram
240 ldx tmp3 ; get charcode
246 lda soft80_internal_cursorxlsb
249 ; output character (odd)
253 ora soft80_hi_charset+(line*$80),x
261 ; output character (even)
266 ora soft80_lo_charset+(line*$80),x
281 ; output inverted character (odd)
286 eor soft80_lo_charset+(line*$80),x
294 ; output inverted character (generic)
296 lda soft80_internal_cursorxlsb
297 bne draw_charinvers_odd
302 eor soft80_hi_charset+(line*$80),x
310 ;-------------------------------------------------------------------------------
311 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
312 ; two colors, one of which is used for the background color, so two characters
313 ; have to share the same text color.
315 ; - in a cell that contains two spaces, both the color ram and the text color
316 ; in vram contain the background color
318 ; - in a cell that contains one character, its text color goes into vram. the
319 ; color ram contains the background color.
321 ; - in a cell that contains two characters, the color of the left character goes
322 ; to vram (and is shared by both for display). the "would be" color of the
323 ; right character goes to color ram as a reminder and can be restored when one
324 ; of the two characters is cleared by a space.
326 .if SOFT80COLORVOODOO = 1
328 ; remove color from cell, called before putting a "space" character to the bitmap
333 ; _A -> __ vram = bgcol
334 ; B_ -> __ vram = bgcol
335 ; BA -> _A vram = colram, colram = bgcol
336 ; BA -> B_ colram = bgcol
344 ;ldy #$00 ; is still $00
346 ; if the textcolor in vram is equal to the background color, then
347 ; no (visible) character is in the current cell and we can exit
349 lda (CRAM_PTR),y ; vram (textcolor)
351 cmp soft80_internal_bgcolor
352 beq @sk1 ; yes, vram==bgcolor
354 ; now check if the textcolor in color ram is equal the background color,
355 ; if yes then there is only one (visible) character in the current cell
357 lda (CRAM_PTR),y ; colram (2nd textcolor)
360 cmp soft80_internal_bgcolor
361 beq @sk2 ; yes, colram==bgcolor
362 sta tmp3 ; A contains colram
364 ; two characters in the current cell, of which one will get removed
366 lda soft80_internal_cursorxlsb
370 lda (CRAM_PTR),y ; vram
372 ora tmp3 ; colram value
373 sta (CRAM_PTR),y ; vram
376 lda soft80_internal_bgcolor
378 sta (CRAM_PTR),y ; colram
385 ; => only one char in cell used
388 bcs @sk1 ; space at current position
390 ; vram (textcolor) = bgcolor
391 lda (CRAM_PTR),y ; vram
393 ora soft80_internal_bgcolor
394 sta (CRAM_PTR),y ; vram
400 ; __ -> _A vram = textcol
401 ; __ -> B_ vram = textcol
402 ; _A -> BA colram = vram, vram = textcol
403 ; B_ -> BA colram = textcol
405 ; _A -> _C vram = textcol
406 ; B_ -> C_ vram = textcol
407 ; BA -> BC colram = textcol
408 ; BA -> CA vram = textcol
410 ; in: $01 is $34 (RAM under I/O) when entering
417 ;ldy #$00 ; is still $00
419 lda (CRAM_PTR),y ; vram
421 cmp soft80_internal_bgcolor
422 beq @sk1 ; vram==bgcolor => first char in cell
424 ; vram!=bgcolor => second char in cell
427 lda (CRAM_PTR),y ; colram
430 cmp soft80_internal_bgcolor
431 beq @l2s ; colram==bgcolor -> second char in cell
433 ; botch characters in the cell are used
435 lda soft80_internal_cursorxlsb
436 bne @sk2 ; jump if odd xpos
440 sta (CRAM_PTR),y ; vram
444 ; one character in cell is already used
446 bcc @sk1 ; char at current position => overwrite 1st
448 lda soft80_internal_cursorxlsb
449 beq @sk3 ; jump if even xpos
452 lda soft80_internal_textcolor
454 sta (CRAM_PTR),y ; colram
460 lda (CRAM_PTR),y ; vram
462 sta (CRAM_PTR),y ; colram
467 sta (CRAM_PTR),y ; vram
471 ; test if there is a space or a character at current position
482 lda soft80_internal_cursorxlsb
485 ; check charset data from bottom up, since a lot of eg lowercase chars
486 ; have no data in the top rows, but all of them DO have data in the
487 ; second to bottom row, this will likely be faster in average.