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
29 jsr _gotoxy ; Set cursor, drop x
32 ; Plot a character - also used as internal function
41 ; Set cursor position, calculate RAM pointers
46 jmp soft80_kplot ; Set the new cursor
49 beq soft80_newline ; Recalculate pointers
51 ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
52 ; codes $00-$1f are control codes which are not printable and thus may
53 ; give undefined result.
57 ; codes $80-$ff must get converted like this:
58 ; $80-$9f -> dont care (control codes)
69 ; entry point for direct output of a character. the value passed in
70 ; akku must match the offset in the charset.
71 ; - the following may not modify tmp1
73 jsr soft80_putchar ; Write the character to the screen
75 ; Advance cursor position
83 sta soft80_internal_cursorxlsb
104 ; - the following may not modify tmp1
126 ;-------------------------------------------------------------------------------
127 ; All following code belongs to the character output to bitmap
129 ; this stuff is going to be used a lot so we unroll it a bit for speed
130 ;-------------------------------------------------------------------------------
132 .if SOFT80FASTSPACE = 1
134 ; output inverted space (odd)
135 draw_spaceinvers_odd:
146 ; output inverted space (general entry point)
150 .if SOFT80COLORVOODOO = 1
153 lda soft80_internal_cellcolor
154 sta (CRAM_PTR),y ; vram
157 lda soft80_internal_cursorxlsb
158 bne draw_spaceinvers_odd
160 ; output inverted space (even)
183 ; output space (general entry point)
190 .if SOFT80COLORVOODOO = 1
193 ;ldy #$00 ; is still $00
195 lda soft80_internal_cursorxlsb
198 ; output space (even)
210 ;-------------------------------------------------------------------------------
211 ; output one character in internal encoding without advancing cursor position
212 ; generic entry point
214 ; - the following may not modify tmp1
219 sta tmp3 ; remember charcode
226 stx $01 ; will stay $34 for space
227 ldy #$00 ; will be $00 from now on
229 .if SOFT80FASTSPACE = 1
230 cmp #' ' ; space is a special (optimized) case
234 .if SOFT80COLORVOODOO = 1
237 lda soft80_internal_cellcolor
238 sta (CRAM_PTR),y ; vram
242 ldx tmp3 ; get charcode
248 lda soft80_internal_cursorxlsb
251 ; output character (odd)
255 ora soft80_hi_charset+(line*$80),x
263 ; output character (even)
268 ora soft80_lo_charset+(line*$80),x
283 ; output inverted character (odd)
288 eor soft80_lo_charset+(line*$80),x
296 ; output inverted character (generic)
298 lda soft80_internal_cursorxlsb
299 bne draw_charinvers_odd
304 eor soft80_hi_charset+(line*$80),x
312 ;-------------------------------------------------------------------------------
313 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
314 ; two colors, one of which is used for the background color, so two characters
315 ; have to share the same text color.
317 ; - in a cell that contains two spaces, both the color ram and the text color
318 ; in vram contain the background color
320 ; - in a cell that contains one character, its text color goes into vram. the
321 ; color ram contains the background color.
323 ; - in a cell that contains two characters, the color of the left character goes
324 ; to vram (and is shared by both for display). the "would be" color of the
325 ; right character goes to color ram as a reminder and can be restored when one
326 ; of the two characters is cleared by a space.
328 .if SOFT80COLORVOODOO = 1
330 ; remove color from cell, called before putting a "space" character to the bitmap
335 ; _A -> __ vram = bgcol
336 ; B_ -> __ vram = bgcol
337 ; BA -> _A vram = colram, colram = bgcol
338 ; BA -> B_ colram = bgcol
346 ;ldy #$00 ; is still $00
348 ; if the textcolor in vram is equal to the background color, then
349 ; no (visible) character is in the current cell and we can exit
351 lda (CRAM_PTR),y ; vram (textcolor)
353 cmp soft80_internal_bgcolor
354 beq @sk1 ; yes, vram==bgcolor
356 ; now check if the textcolor in color ram is equal the background color,
357 ; if yes then there is only one (visible) character in the current cell
359 lda (CRAM_PTR),y ; colram (2nd textcolor)
362 cmp soft80_internal_bgcolor
363 beq @sk2 ; yes, colram==bgcolor
364 sta tmp3 ; A contains colram
366 ; two characters in the current cell, of which one will get removed
368 lda soft80_internal_cursorxlsb
372 lda (CRAM_PTR),y ; vram
374 ora tmp3 ; colram value
375 sta (CRAM_PTR),y ; vram
378 lda soft80_internal_bgcolor
380 sta (CRAM_PTR),y ; colram
387 ; => only one char in cell used
390 bcs @sk1 ; space at current position
392 ; vram (textcolor) = bgcolor
393 lda (CRAM_PTR),y ; vram
395 ora soft80_internal_bgcolor
396 sta (CRAM_PTR),y ; vram
402 ; __ -> _A vram = textcol
403 ; __ -> B_ vram = textcol
404 ; _A -> BA colram = vram, vram = textcol
405 ; B_ -> BA colram = textcol
407 ; _A -> _C vram = textcol
408 ; B_ -> C_ vram = textcol
409 ; BA -> BC colram = textcol
410 ; BA -> CA vram = textcol
412 ; in: $01 is $34 (RAM under I/O) when entering
419 ;ldy #$00 ; is still $00
421 lda (CRAM_PTR),y ; vram
423 cmp soft80_internal_bgcolor
424 beq @sk1 ; vram==bgcolor => first char in cell
426 ; vram!=bgcolor => second char in cell
429 lda (CRAM_PTR),y ; colram
432 cmp soft80_internal_bgcolor
433 beq @l2s ; colram==bgcolor -> second char in cell
435 ; botch characters in the cell are used
437 lda soft80_internal_cursorxlsb
438 bne @sk2 ; jump if odd xpos
441 lda soft80_internal_cellcolor
442 sta (CRAM_PTR),y ; vram
446 ; one character in cell is already used
448 bcc @sk1 ; char at current position => overwrite 1st
450 lda soft80_internal_cursorxlsb
451 beq @sk3 ; jump if even xpos
456 sta (CRAM_PTR),y ; colram
462 lda (CRAM_PTR),y ; vram
464 sta (CRAM_PTR),y ; colram
468 lda soft80_internal_cellcolor
469 sta (CRAM_PTR),y ; vram
473 ; test if there is a space or a character at current position
484 lda soft80_internal_cursorxlsb
487 ; check charset data from bottom up, since a lot of eg lowercase chars
488 ; have no data in the top rows, but all of them DO have data in the
489 ; second to bottom row, this will likely be faster in average.