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
25 .if SOFT80COLORVOODOO = 1
26 .export soft80_putcolor
32 jsr _gotoxy ; Set cursor, drop x
35 ; Plot a character - also used as internal function
44 ; Set cursor position, calculate RAM pointers
49 jmp soft80_kplot ; Set the new cursor
52 beq soft80_newline ; Recalculate pointers
54 ; Printable char of some sort
58 ; extra check for petscii codes 160-191, these have been moved to
66 bpl L10 ; branch always
74 ; entry point for direct output of a character. the value passed in
75 ; akku must match the offset in the charset.
76 ; - the following may not modify tmp1
78 jsr soft80_putchar ; Write the character to the screen
80 ; Advance cursor position
90 sta soft80_internal_cursorxlsb
106 inc CURS_Y ; new line
111 ; - the following may not modify tmp1
133 ; Write one character to the screen without doing anything else
135 ; returns: Y: cursor X position
136 ; this function is going to be used a lot so we unroll it a bit for speed
138 .if SOFT80FASTSPACE = 1
146 .if SOFT80COLORVOODOO = 1
149 ;ldy #$00 ; is still $00
153 lda soft80_internal_cursorxlsb
177 ; output inverted space
181 .if SOFT80COLORVOODOO = 1
185 sta (CRAM_PTR),y ; vram
190 lda soft80_internal_cursorxlsb
215 ; entry point for outputting one character in internal encoding
216 ; without advancing cursor position
217 ; - 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
238 sta (CRAM_PTR),y ; vram
242 ldx tmp3 ; get charcode
249 lda soft80_internal_cursorxlsb
255 ora soft80_hi_charset+(line*$80),x
267 ora soft80_lo_charset+(line*$80),x
284 ; output inverted character
289 lda soft80_internal_cursorxlsb
295 eor soft80_hi_charset+(line*$80),x
306 eor soft80_lo_charset+(line*$80),x
314 ;-------------------------------------------------------------------------------
315 ; optional "color voodoo". the problem is that each 8x8 cell can only contain
316 ; two colors, one of which is used for the background color, so two characters
317 ; have to share the same text color.
319 ; - in a cell that contains two spaces, both the color ram and the text color
320 ; in vram contain the background color
322 ; - in a cell that contains one character, its text color goes into vram. the
323 ; color ram contains the background color.
325 ; - in a cell that contains two characters, the color of the left character goes
326 ; to vram (and is shared by both for display). the "would be" color of the
327 ; right character goes to color ram as a reminder and can be restored when one
328 ; of the two characters is cleared by a space.
330 .if SOFT80COLORVOODOO = 1
332 ; remove color from cell, called before putting a "space" character to the bitmap
337 ; _A -> __ vram = bgcol
338 ; B_ -> __ vram = bgcol
339 ; BA -> _A vram = colram, colram = bgcol
340 ; BA -> B_ colram = bgcol
347 ;ldy #$00 ; is still $00
349 ; if the textcolor in vram is equal to the background color, then
350 ; no (visible) character is in the current cell and we can exit
352 lda (CRAM_PTR),y ; vram (textcolor)
354 cmp soft80_internal_bgcolor
355 beq @sk1 ; yes, vram==bgcolor
357 ; now check if the textcolor in color ram is equal the background color,
358 ; if yes then there is only one (visible) character in the current cell
360 lda (CRAM_PTR),y ; colram (2nd textcolor)
363 cmp soft80_internal_bgcolor
364 beq @sk2 ; yes, colram==bgcolor
366 ; two characters in the current cell, of which one will get removed
370 ;lda (CRAM_PTR),y ; colram
373 sta tmp3 ; A contains colram
377 lda soft80_internal_cursorxlsb
381 lda (CRAM_PTR),y ; vram
384 sta (CRAM_PTR),y ; vram
387 lda soft80_internal_bgcolor
389 sta (CRAM_PTR),y ; colram
396 ; => only one char in cell used
399 bcc @sk1 ; space at current position
401 ; vram (textcolor) = bgcolor
402 lda (CRAM_PTR),y ; vram
404 ora soft80_internal_bgcolor
405 sta (CRAM_PTR),y ; vram
411 ; __ -> _A vram = textcol
412 ; __ -> B_ vram = textcol
413 ; _A -> BA colram = vram, vram = textcol
414 ; B_ -> BA colram = textcol
416 ; _A -> _C vram = textcol
417 ; B_ -> C_ vram = textcol
418 ; BA -> BC colram = textcol
419 ; BA -> CA vram = textcol
421 ; in: $01 is $34 (RAM under I/O) when entering
428 ;ldy #$00 ; is still $00
430 lda (CRAM_PTR),y ; vram
432 cmp soft80_internal_bgcolor
433 beq @sk1 ; vram==bgcolor => first char in cell
435 ; vram!=bgcolor => second char in cell
438 lda (CRAM_PTR),y ; colram
441 cmp soft80_internal_bgcolor
442 beq @l2s ; colram==bgcolor -> second char in cell
444 ; botch characters in the cell are used
448 lda soft80_internal_cursorxlsb
449 bne @sk2 ; jump if odd xpos
453 sta (CRAM_PTR),y ; vram
457 ; one character in cell is already used
459 bcs @sk1 ; char at current position => overwrite 1st
463 lda soft80_internal_cursorxlsb
464 beq @sk3 ; jump if even xpos
467 lda soft80_internal_textcolor
469 sta (CRAM_PTR),y ; colram
475 lda (CRAM_PTR),y ; vram
477 sta (CRAM_PTR),y ; colram
482 sta (CRAM_PTR),y ; vram
485 ; test if there is a space or a character at current position
487 ; out: CLC: space SEC: character
491 ;ldy #$00 ; is still $00
495 lda soft80_internal_cursorxlsb