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)
60 ; extra check for petscii codes 160-191, these have been moved to
68 bpl L10 ; branch always
76 ; entry point for direct output of a character. the value passed in
77 ; akku must match the offset in the charset.
78 ; - the following may not modify tmp1
80 jsr soft80_putchar ; Write the character to the screen
82 ; Advance cursor position
90 sta soft80_internal_cursorxlsb
106 inc CURS_Y ; new line
111 ; - the following may not modify tmp1
133 ;-------------------------------------------------------------------------------
134 ; All following code belongs to the character output to bitmap
136 ; this stuff is going to be used a lot so we unroll it a bit for speed
137 ;-------------------------------------------------------------------------------
139 .if SOFT80FASTSPACE = 1
141 ; output inverted space (odd)
142 draw_spaceinvers_odd:
153 ; output inverted space (general entry point)
157 .if SOFT80COLORVOODOO = 1
161 sta (CRAM_PTR),y ; vram
164 lda soft80_internal_cursorxlsb
165 bne draw_spaceinvers_odd
167 ; output inverted space (even)
190 ; output space (general entry point)
197 .if SOFT80COLORVOODOO = 1
200 ;ldy #$00 ; is still $00
202 lda soft80_internal_cursorxlsb
205 ; output space (even)
217 ;-------------------------------------------------------------------------------
218 ; output one character in internal encoding without advancing cursor position
219 ; generic entry point
221 ; - the following may not modify tmp1
226 sta tmp3 ; remember charcode
233 stx $01 ; will stay $34 for space
234 ldy #$00 ; will be $00 from now on
236 .if SOFT80FASTSPACE = 1
237 cmp #' ' ; space is a special (optimized) case
241 .if SOFT80COLORVOODOO = 1
245 sta (CRAM_PTR),y ; vram
249 ldx tmp3 ; get charcode
255 lda soft80_internal_cursorxlsb
258 ; output character (odd)
262 ora soft80_hi_charset+(line*$80),x
270 ; output character (even)
275 ora soft80_lo_charset+(line*$80),x
290 ; output inverted character (odd)
295 eor soft80_lo_charset+(line*$80),x
303 ; output inverted character (generic)
305 lda soft80_internal_cursorxlsb
306 bne draw_charinvers_odd
311 eor soft80_hi_charset+(line*$80),x
319 ;-------------------------------------------------------------------------------
320 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
321 ; two colors, one of which is used for the background color, so two characters
322 ; have to share the same text color.
324 ; - in a cell that contains two spaces, both the color ram and the text color
325 ; in vram contain the background color
327 ; - in a cell that contains one character, its text color goes into vram. the
328 ; color ram contains the background color.
330 ; - in a cell that contains two characters, the color of the left character goes
331 ; to vram (and is shared by both for display). the "would be" color of the
332 ; right character goes to color ram as a reminder and can be restored when one
333 ; of the two characters is cleared by a space.
335 .if SOFT80COLORVOODOO = 1
337 ; remove color from cell, called before putting a "space" character to the bitmap
342 ; _A -> __ vram = bgcol
343 ; B_ -> __ vram = bgcol
344 ; BA -> _A vram = colram, colram = bgcol
345 ; BA -> B_ colram = bgcol
352 ;ldy #$00 ; is still $00
354 ; if the textcolor in vram is equal to the background color, then
355 ; no (visible) character is in the current cell and we can exit
357 lda (CRAM_PTR),y ; vram (textcolor)
359 cmp soft80_internal_bgcolor
360 beq @sk1 ; yes, vram==bgcolor
362 ; now check if the textcolor in color ram is equal the background color,
363 ; if yes then there is only one (visible) character in the current cell
365 lda (CRAM_PTR),y ; colram (2nd textcolor)
368 cmp soft80_internal_bgcolor
369 beq @sk2 ; yes, colram==bgcolor
371 ; two characters in the current cell, of which one will get removed
375 ;lda (CRAM_PTR),y ; colram
378 sta tmp3 ; A contains colram
380 lda soft80_internal_cursorxlsb
384 lda (CRAM_PTR),y ; vram
387 sta (CRAM_PTR),y ; vram
390 lda soft80_internal_bgcolor
392 sta (CRAM_PTR),y ; colram
399 ; => only one char in cell used
402 bcc @sk1 ; space at current position
404 ; vram (textcolor) = bgcolor
405 lda (CRAM_PTR),y ; vram
407 ora soft80_internal_bgcolor
408 sta (CRAM_PTR),y ; vram
414 ; __ -> _A vram = textcol
415 ; __ -> B_ vram = textcol
416 ; _A -> BA colram = vram, vram = textcol
417 ; B_ -> BA colram = textcol
419 ; _A -> _C vram = textcol
420 ; B_ -> C_ vram = textcol
421 ; BA -> BC colram = textcol
422 ; BA -> CA vram = textcol
424 ; in: $01 is $34 (RAM under I/O) when entering
431 ;ldy #$00 ; is still $00
433 lda (CRAM_PTR),y ; vram
435 cmp soft80_internal_bgcolor
436 beq @sk1 ; vram==bgcolor => first char in cell
438 ; vram!=bgcolor => second char in cell
441 lda (CRAM_PTR),y ; colram
444 cmp soft80_internal_bgcolor
445 beq @l2s ; colram==bgcolor -> second char in cell
447 ; botch characters in the cell are used
449 lda soft80_internal_cursorxlsb
450 bne @sk2 ; jump if odd xpos
454 sta (CRAM_PTR),y ; vram
458 ; one character in cell is already used
460 bcs @sk1 ; char at current position => overwrite 1st
462 lda soft80_internal_cursorxlsb
463 beq @sk3 ; jump if even xpos
466 lda soft80_internal_textcolor
468 sta (CRAM_PTR),y ; colram
474 lda (CRAM_PTR),y ; vram
476 sta (CRAM_PTR),y ; colram
481 sta (CRAM_PTR),y ; vram
485 ; test if there is a space or a character at current position
489 ; out: CLC: space SEC: character
494 ;ldy #$00 ; is still $00
496 lda soft80_internal_cursorxlsb
499 ; check charset data from bottom up, since a lot of eg lowercase chars
500 ; have no data in the top rows, but all of them DO have data in the
501 ; second to bottom row, this will likely be faster in average.