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
15 .import soft80_internal_bgcolor, soft80_internal_textcolor
16 .import soft80_internal_cursorxlsb
26 jsr _gotoxy ; Set cursor, drop x
29 ; Plot a character - also used as internal function
38 ; Set cursor position, calculate RAM pointers
43 jmp soft80_kplot ; Set the new cursor
46 beq soft80_newline ; Recalculate pointers
48 ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
49 ; codes $00-$1f are control codes which are not printable and thus may
50 ; give undefined result.
54 ; codes $80-$ff must get converted like this:
55 ; $80-$9f -> dont care (control codes)
66 ; entry point for direct output of a character. the value passed in
67 ; akku must match the offset in the charset.
68 ; - the following may not modify tmp1
70 jsr soft80_putchar ; Write the character to the screen
72 ; Advance cursor position
80 sta soft80_internal_cursorxlsb
101 ; - the following may not modify tmp1
123 ;-------------------------------------------------------------------------------
124 ; All following code belongs to the character output to bitmap
126 ; this stuff is going to be used a lot so we unroll it a bit for speed
127 ;-------------------------------------------------------------------------------
129 .if SOFT80FASTSPACE = 1
131 ; output inverted space (odd)
132 draw_spaceinvers_odd:
143 ; output inverted space (general entry point)
147 .if SOFT80COLORVOODOO = 1
151 sta (CRAM_PTR),y ; vram
154 lda soft80_internal_cursorxlsb
155 bne draw_spaceinvers_odd
157 ; output inverted space (even)
180 ; output space (general entry point)
187 .if SOFT80COLORVOODOO = 1
190 ;ldy #$00 ; is still $00
192 lda soft80_internal_cursorxlsb
195 ; output space (even)
207 ;-------------------------------------------------------------------------------
208 ; output one character in internal encoding without advancing cursor position
209 ; generic entry point
211 ; - the following may not modify tmp1
216 sta tmp3 ; remember charcode
223 stx $01 ; will stay $34 for space
224 ldy #$00 ; will be $00 from now on
226 .if SOFT80FASTSPACE = 1
227 cmp #' ' ; space is a special (optimized) case
231 .if SOFT80COLORVOODOO = 1
235 sta (CRAM_PTR),y ; vram
239 ldx tmp3 ; get charcode
245 lda soft80_internal_cursorxlsb
248 ; output character (odd)
252 ora soft80_hi_charset+(line*$80),x
260 ; output character (even)
265 ora soft80_lo_charset+(line*$80),x
280 ; output inverted character (odd)
285 eor soft80_lo_charset+(line*$80),x
293 ; output inverted character (generic)
295 lda soft80_internal_cursorxlsb
296 bne draw_charinvers_odd
301 eor soft80_hi_charset+(line*$80),x
309 ;-------------------------------------------------------------------------------
310 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
311 ; two colors, one of which is used for the background color, so two characters
312 ; have to share the same text color.
314 ; - in a cell that contains two spaces, both the color ram and the text color
315 ; in vram contain the background color
317 ; - in a cell that contains one character, its text color goes into vram. the
318 ; color ram contains the background color.
320 ; - in a cell that contains two characters, the color of the left character goes
321 ; to vram (and is shared by both for display). the "would be" color of the
322 ; right character goes to color ram as a reminder and can be restored when one
323 ; of the two characters is cleared by a space.
325 .if SOFT80COLORVOODOO = 1
327 ; remove color from cell, called before putting a "space" character to the bitmap
332 ; _A -> __ vram = bgcol
333 ; B_ -> __ vram = bgcol
334 ; BA -> _A vram = colram, colram = bgcol
335 ; BA -> B_ colram = bgcol
342 ;ldy #$00 ; is still $00
344 ; if the textcolor in vram is equal to the background color, then
345 ; no (visible) character is in the current cell and we can exit
347 lda (CRAM_PTR),y ; vram (textcolor)
349 cmp soft80_internal_bgcolor
350 beq @sk1 ; yes, vram==bgcolor
352 ; now check if the textcolor in color ram is equal the background color,
353 ; if yes then there is only one (visible) character in the current cell
355 lda (CRAM_PTR),y ; colram (2nd textcolor)
358 cmp soft80_internal_bgcolor
359 beq @sk2 ; yes, colram==bgcolor
361 ; two characters in the current cell, of which one will get removed
365 ;lda (CRAM_PTR),y ; colram
368 sta tmp3 ; A contains colram
370 lda soft80_internal_cursorxlsb
374 lda (CRAM_PTR),y ; vram
377 sta (CRAM_PTR),y ; vram
380 lda soft80_internal_bgcolor
382 sta (CRAM_PTR),y ; colram
389 ; => only one char in cell used
392 bcc @sk1 ; space at current position
394 ; vram (textcolor) = bgcolor
395 lda (CRAM_PTR),y ; vram
397 ora soft80_internal_bgcolor
398 sta (CRAM_PTR),y ; vram
404 ; __ -> _A vram = textcol
405 ; __ -> B_ vram = textcol
406 ; _A -> BA colram = vram, vram = textcol
407 ; B_ -> BA colram = textcol
409 ; _A -> _C vram = textcol
410 ; B_ -> C_ vram = textcol
411 ; BA -> BC colram = textcol
412 ; BA -> CA vram = textcol
414 ; in: $01 is $34 (RAM under I/O) when entering
421 ;ldy #$00 ; is still $00
423 lda (CRAM_PTR),y ; vram
425 cmp soft80_internal_bgcolor
426 beq @sk1 ; vram==bgcolor => first char in cell
428 ; vram!=bgcolor => second char in cell
431 lda (CRAM_PTR),y ; colram
434 cmp soft80_internal_bgcolor
435 beq @l2s ; colram==bgcolor -> second char in cell
437 ; botch characters in the cell are used
439 lda soft80_internal_cursorxlsb
440 bne @sk2 ; jump if odd xpos
444 sta (CRAM_PTR),y ; vram
448 ; one character in cell is already used
450 bcs @sk1 ; char at current position => overwrite 1st
452 lda soft80_internal_cursorxlsb
453 beq @sk3 ; jump if even xpos
456 lda soft80_internal_textcolor
458 sta (CRAM_PTR),y ; colram
464 lda (CRAM_PTR),y ; vram
466 sta (CRAM_PTR),y ; colram
471 sta (CRAM_PTR),y ; vram
475 ; test if there is a space or a character at current position
479 ; out: CLC: space SEC: character
484 ;ldy #$00 ; is still $00
486 lda soft80_internal_cursorxlsb
489 ; check charset data from bottom up, since a lot of eg lowercase chars
490 ; have no data in the top rows, but all of them DO have data in the
491 ; second to bottom row, this will likely be faster in average.