2 ; Groepaz/Hitmen, 11.10.2015
4 ; high level implementation for the soft80 implementation
6 ; void cputcxy (unsigned char x, unsigned char y, char c);
10 .export soft80_cputcxy, soft80_cputc
11 .export soft80_cputdirect, soft80_putchar
12 .export soft80_newline, soft80_plot
13 .export soft80_checkchar
18 .import soft80_internal_bgcolor, soft80_internal_cellcolor
19 .import soft80_internal_cursorxlsb
28 jsr gotoxy ; Set cursor, drop x and y
31 ; Plot a character - also used as internal function
40 ; Set cursor position, calculate RAM pointers
45 jmp soft80_kplot ; Set the new cursor
48 beq soft80_newline ; Recalculate pointers
50 ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
51 ; codes $00-$1f are control codes which are not printable and thus may
52 ; give undefined result.
56 ; codes $80-$ff must get converted like this:
57 ; $80-$9f -> dont care (control codes)
68 ; entry point for direct output of a character. the value passed in
69 ; akku must match the offset in the charset.
70 ; - the following may not modify tmp1
72 jsr soft80_putchar ; Write the character to the screen
74 ; Advance cursor position
82 sta soft80_internal_cursorxlsb
103 ; - the following may not modify tmp1
125 ;-------------------------------------------------------------------------------
126 ; All following code belongs to the character output to bitmap
128 ; this stuff is going to be used a lot so we unroll it a bit for speed
129 ;-------------------------------------------------------------------------------
131 .if SOFT80FASTSPACE = 1
133 ; output inverted space (odd)
134 draw_spaceinvers_odd:
145 ; output inverted space (general entry point)
149 .if SOFT80COLORVOODOO = 1
152 lda soft80_internal_cellcolor
153 sta (CRAM_PTR),y ; vram
156 lda soft80_internal_cursorxlsb
157 bne draw_spaceinvers_odd
159 ; output inverted space (even)
182 ; output space (general entry point)
189 .if SOFT80COLORVOODOO = 1
192 ;ldy #$00 ; is still $00
194 lda soft80_internal_cursorxlsb
197 ; output space (even)
209 ;-------------------------------------------------------------------------------
210 ; output one character in internal encoding without advancing cursor position
211 ; generic entry point
213 ; - the following may not modify tmp1
218 sta tmp3 ; remember charcode
225 stx $01 ; will stay $34 for space
226 ldy #$00 ; will be $00 from now on
228 .if SOFT80FASTSPACE = 1
229 cmp #' ' ; space is a special (optimized) case
233 .if SOFT80COLORVOODOO = 1
236 lda soft80_internal_cellcolor
237 sta (CRAM_PTR),y ; vram
241 ldx tmp3 ; get charcode
247 lda soft80_internal_cursorxlsb
250 ; output character (odd)
254 ora soft80_hi_charset+(line*$80),x
262 ; output character (even)
267 ora soft80_lo_charset+(line*$80),x
282 ; output inverted character (odd)
287 eor soft80_lo_charset+(line*$80),x
295 ; output inverted character (generic)
297 lda soft80_internal_cursorxlsb
298 bne draw_charinvers_odd
303 eor soft80_hi_charset+(line*$80),x
311 ;-------------------------------------------------------------------------------
312 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
313 ; two colors, one of which is used for the background color, so two characters
314 ; have to share the same text color.
316 ; - in a cell that contains two spaces, both the color ram and the text color
317 ; in vram contain the background color
319 ; - in a cell that contains one character, its text color goes into vram. the
320 ; color ram contains the background color.
322 ; - in a cell that contains two characters, the color of the left character goes
323 ; to vram (and is shared by both for display). the "would be" color of the
324 ; right character goes to color ram as a reminder and can be restored when one
325 ; of the two characters is cleared by a space.
327 .if SOFT80COLORVOODOO = 1
329 ; remove color from cell, called before putting a "space" character to the bitmap
334 ; _A -> __ vram = bgcol
335 ; B_ -> __ vram = bgcol
336 ; BA -> _A vram = colram, colram = bgcol
337 ; BA -> B_ colram = bgcol
345 ;ldy #$00 ; is still $00
347 ; if the textcolor in vram is equal to the background color, then
348 ; no (visible) character is in the current cell and we can exit
350 lda (CRAM_PTR),y ; vram (textcolor)
352 cmp soft80_internal_bgcolor
353 beq @sk1 ; yes, vram==bgcolor
355 ; now check if the textcolor in color ram is equal the background color,
356 ; if yes then there is only one (visible) character in the current cell
358 lda (CRAM_PTR),y ; colram (2nd textcolor)
361 cmp soft80_internal_bgcolor
362 beq @sk2 ; yes, colram==bgcolor
363 sta tmp3 ; A contains colram
365 ; two characters in the current cell, of which one will get removed
367 lda soft80_internal_cursorxlsb
371 lda (CRAM_PTR),y ; vram
373 ora tmp3 ; colram value
374 sta (CRAM_PTR),y ; vram
377 lda soft80_internal_bgcolor
379 sta (CRAM_PTR),y ; colram
386 ; => only one char in cell used
389 bcs @sk1 ; space at current position
391 ; vram (textcolor) = bgcolor
392 lda (CRAM_PTR),y ; vram
394 ora soft80_internal_bgcolor
395 sta (CRAM_PTR),y ; vram
401 ; __ -> _A vram = textcol
402 ; __ -> B_ vram = textcol
403 ; _A -> BA colram = vram, vram = textcol
404 ; B_ -> BA colram = textcol
406 ; _A -> _C vram = textcol
407 ; B_ -> C_ vram = textcol
408 ; BA -> BC colram = textcol
409 ; BA -> CA vram = textcol
411 ; in: $01 is $34 (RAM under I/O) when entering
418 ;ldy #$00 ; is still $00
420 lda (CRAM_PTR),y ; vram
422 cmp soft80_internal_bgcolor
423 beq @sk1 ; vram==bgcolor => first char in cell
425 ; vram!=bgcolor => second char in cell
428 lda (CRAM_PTR),y ; colram
431 cmp soft80_internal_bgcolor
432 beq @l2s ; colram==bgcolor -> second char in cell
434 ; botch characters in the cell are used
436 lda soft80_internal_cursorxlsb
437 bne @sk2 ; jump if odd xpos
440 lda soft80_internal_cellcolor
441 sta (CRAM_PTR),y ; vram
445 ; one character in cell is already used
447 bcc @sk1 ; char at current position => overwrite 1st
449 lda soft80_internal_cursorxlsb
450 beq @sk3 ; jump if even xpos
455 sta (CRAM_PTR),y ; colram
461 lda (CRAM_PTR),y ; vram
463 sta (CRAM_PTR),y ; colram
467 lda soft80_internal_cellcolor
468 sta (CRAM_PTR),y ; vram
472 ; test if there is a space or a character at current position
483 lda soft80_internal_cursorxlsb
486 ; check charset data from bottom up, since a lot of eg lowercase chars
487 ; have no data in the top rows, but all of them DO have data in the
488 ; second to bottom row, this will likely be faster in average.