From e54ad81ce8f796f89ea72f029d2be4d82d6aad75 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 8 Oct 2015 20:43:25 +0200 Subject: [PATCH] some more rework, second attempt on fixing the color issues. added ifdefs to disable the color voodoo alltogether for debugging purposes. --- libsrc/c64/soft80.inc | 7 + libsrc/c64/soft80_cgetc.s | 71 +++----- libsrc/c64/soft80_color.s | 43 +++-- libsrc/c64/soft80_conio.s | 13 +- libsrc/c64/soft80_cputc.s | 344 ++++++++++++++++++++---------------- libsrc/c64/soft80_kclrscr.s | 12 +- 6 files changed, 256 insertions(+), 234 deletions(-) diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index d534cac69..f2058f91d 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -21,3 +21,10 @@ CH_BTEE = 177 CH_TTEE = 178 CH_RTEE = 179 CH_LRCORNER = 189 + +;------------------------------------------------------------------------------- +; set to 0 to disable the color-ram "voodoo" for debugging purposes +.define SOFT80COLORVOODOO 1 +; set to 0 to disable special case optimization for the "space" character +.define SOFT80FASTSPACE 1 + diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index a8c52c1a2..723c5ade8 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -4,87 +4,66 @@ .export soft80_cgetc .import cursor - .import soft80_putcolor .include "c64.inc" .include "soft80.inc" +.if SOFT80COLORVOODOO = 1 + .import soft80_putcolor +.endif + soft80_cgetc: lda KEY_COUNT ; Get number of characters bne L3 ; Jump if there are already chars waiting -; Switch on the cursor if needed - - lda cursor - jsr setcursor ; set cursor on or off accordingly + jsr invertcursor ; set cursor on or off accordingly L1: lda KEY_COUNT ; wait for key beq L1 - ldx #0 - lda CURS_FLAG - bne L2 - inx -L2: txa - jsr setcursor + jsr invertcursor ; set cursor on or off accordingly L3: jsr KBDREAD ; Read char and return in A ldx #0 rts -; Switch the cursor on or off - -; A= 0: cursor off -; 1: cursor on +; Switch the cursor on or off (invert) - .proc setcursor - - ; On or off? - cmp CURS_STATE - bne @set +invertcursor: + lda cursor + bne @invert rts -@set: - sta CURS_STATE +@invert: sei lda $01 pha - lda #$34 + lda #$34 ; enable RAM under I/O sta $01 - jsr soft80_putcolor - ldy #$00 +.if SOFT80COLORVOODOO = 1 + jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif lda CURS_X and #$01 - bne @l1 - - .repeat 8,line + tax +@lp1: lda (SCREEN_PTR),y - eor #$f0 + eor nibble,x sta (SCREEN_PTR),y - .if (line < 7) iny - .endif - .endrepeat + cpy #8 + bne @lp1 -@back: pla sta $01 cli rts -@l1: - .repeat 8,line - lda (SCREEN_PTR),y - eor #$0f - sta (SCREEN_PTR),y - .if line < 7 - iny - .endif - .endrepeat - - jmp @back - - .endproc + .rodata +nibble: .byte $f0, $0f diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index ee226633a..f537f8d84 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -30,57 +30,54 @@ soft80_bgcolor: jsr mkcharcolor +.if SOFT80COLORVOODOO = 1 ; if the old bg color is equal to color ram of that cell, then also ; update the color ram to the new value. ; FIXME: perhaps we must also check if the non visible character is not ; a space, and NOT update the color ram in that case. ldx #$00 lp1: - .repeat $3,page + .repeat $4,page .scope - lda soft80_colram+(page*$100),x + lda soft80_colram+(page*250),x and #$0f cmp tmp2 ; old bg color bne @sk1 - lda __bgcolor - sta soft80_colram+(page*$100),x + lda __bgcolor ; new bg color + sta soft80_colram+(page*250),x @sk1: .endscope .endrepeat - .scope - lda soft80_colram+$2e8,x - and #$0f - cmp tmp2 ; old bg color - bne @sk1 - lda __bgcolor - sta soft80_colram+$2e8,x -@sk1: - .endscope - inx bne lp1 +.endif sei ldy $01 lda #$34 ; disable I/O sta $01 + ; if the old bg color is equal to text color in this cell, then also + ; update the text color to the new value. + ; FIXME: perhaps we need to check for space, see note above ldx #$00 -@lp2: - .repeat $3,page - lda soft80_vram+(page*$100),x +lp2: + .repeat $4,page + .scope + lda soft80_vram+(page*250),x and #$0f + cmp tmp2 ; old bg color + bne @sk2 + lda __bgcolor ; new bg color +@sk2: ora tmp1 ; new bg color (high nibble) - sta soft80_vram+(page*$100),x + sta soft80_vram+(page*250),x + .endscope .endrepeat - lda soft80_vram+$2e8,x - and #$0f - ora tmp1 ; new bg color (high nibble) - sta soft80_vram+$2e8,x inx - bne @lp2 + bne lp2 sty $01 ; enable I/O cli diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 84e5157c8..5fbeaadc1 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -6,7 +6,7 @@ .destructor soft80_shutdown .import soft80_kclrscr - .import soft80_textcolor, soft80_bgcolor + .import __textcolor, __bgcolor .importzp ptr1, ptr2, ptr3 @@ -67,11 +67,18 @@ soft80_init: cli lda 646 ; use current textcolor - jsr soft80_textcolor + and #$0f + sta __textcolor lda VIC_BG_COLOR0 ; use current bgcolor and #$0f - jsr soft80_bgcolor + sta __bgcolor + asl a + asl a + asl a + asl a + ora __textcolor + sta CHARCOLOR jmp soft80_kclrscr diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 590e16740..41132a346 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -5,7 +5,6 @@ .export soft80_cputcxy, soft80_cputc .export soft80_cputdirect, soft80_putchar - .export soft80_putcolor .export soft80_newline, soft80_plot .import popa, _gotoxy @@ -20,6 +19,10 @@ .include "c64.inc" .include "soft80.inc" +.if SOFT80COLORVOODOO = 1 + .export soft80_putcolor +.endif + soft80_cputcxy: pha ; Save C jsr popa ; Get Y @@ -125,163 +128,17 @@ L5: ; returns: Y: cursor X position ; this function is going to be used a lot so we unroll it a bit for speed -;--- start color vodoo - -; remove color from cell -; y unmodified -remcolor: - - ;ldy #$00 ; is still $00 - - lda (CRAM_PTR),y ; vram - and #$0f - cmp __bgcolor - jeq @l2b ; vram==bgcolor - - inc $01 - lda (CRAM_PTR),y ; colram - stx $01 ;$34 - and #$0f - cmp __bgcolor - beq @l2s ; colram==bgcolor - - ; vram = colram - ;inc $01 - ;lda (CRAM_PTR),y ; colram - ;stx $01 ;$34 - ;and #$0f - - sta tmp3 - lda (CRAM_PTR),y ; vram - and #$f0 - ora tmp3 - sta (CRAM_PTR),y ; vram - - ; colram = bgcolor - lda __bgcolor - inc $01 - sta (CRAM_PTR),y ; colram - stx $01 ;$34 - - jmp @l2b - -@l2s: - ; colram is bgcolor - ; => only one char in cell used - - jsr soft80_checkchar - bcc @l2b ; space at current position - - ; vram = bgcolor - lda (CRAM_PTR),y ; vram - and #$f0 - ora __bgcolor - sta (CRAM_PTR),y ; vram -@l2b: - rts - -; put color to cell -; y unmodified -soft80_putcolor: - - ;ldy #$00 ; is still $00 - - lda (CRAM_PTR),y ; vram - and #$0f - cmp __bgcolor - beq @l2s ; vram==bgcolor => first char in cell - - ; vram!=bgcolor => second char in cell - - inc $01 ;$35 - lda (CRAM_PTR),y ; colram - stx $01 ;$34 - and #$0f - cmp __bgcolor - bne @l2s ; colram!=bgcolor - - ; colram==bgcolor => second char in cell or overwrite 1st char - - jsr soft80_checkchar - bcs @l2a ; char at current position => overwrite 1st - - ; colram=vram - lda (CRAM_PTR),y ; vram - inc $01 - sta (CRAM_PTR),y ; colram - stx $01 ;$34 - - ;jmp @l2a - -@l2s: - ; colram!=bgcolor => alread 2 chars in cell -@l2a: - - ; Set color - lda CHARCOLOR - sta (CRAM_PTR),y ; vram - - rts - - -;--- end color vodoo - - .export soft80_checkchar - -; test if there is a space or a character at current position -; CLC: space SEC: character -soft80_checkchar: - - ;ldy #$00 ; is still $00 - - lda CURS_X - and #$01 - jne @l1a - - .repeat 8,line - lda (SCREEN_PTR),y - and #$f0 - cmp #$f0 - bne @l2b - .if (line < 7) - iny - .endif - .endrepeat - - ldy #$00 - clc - rts -@l2b: - ldy #$00 - sec - rts -@l1a: - .repeat 8,line - lda (SCREEN_PTR),y - and #$0f - cmp #$0f - bne @l2bb - .if line < 7 - iny - .endif - .endrepeat - ldy #$00 - clc - rts -@l2bb: - ldy #$00 - sec - rts - +.if SOFT80FASTSPACE = 1 ; output space - +; in: y must be $00 _space: lda RVS jne _spaceinvers +.if SOFT80COLORVOODOO = 1 jsr remcolor - +.endif ;ldy #$00 ; is still $00 lda CURS_X @@ -310,10 +167,15 @@ _space: jmp _back ; output inverted space - +; in: y must be $00 _spaceinvers: +.if SOFT80COLORVOODOO = 1 jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif lda CURS_X and #$01 @@ -339,11 +201,12 @@ _spaceinvers: .endrepeat jmp _back +.endif ; output a character soft80_putchar: - sta tmp3 + sta tmp3 ; remember charcode sei ldx $01 @@ -353,14 +216,20 @@ soft80_putchar: stx $01 ; will stay $34 for space ldy #$00 ; will be $00 from now on +.if SOFT80FASTSPACE = 1 cmp #' ' ; space is a special (optimized) case jeq _space +.endif +.if SOFT80COLORVOODOO = 1 jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif + ; output character -; output character -char: - ldx tmp3 + ldx tmp3 ; get charcode lda RVS jne _invers @@ -429,3 +298,166 @@ _invers: .endif .endrepeat jmp _back + +;------------------------------------------------------------------------------- + +.if SOFT80COLORVOODOO = 1 +;--- start color vodoo + +; remove color from cell, called before putting a "space" character to the bitmap +; y unmodified +remcolor: + + ;ldy #$00 ; is still $00 + + ; if the textcolor in vram is equal to the background color, then + ; no (visible) character is in the current cell and we can exit + ; immediately. + lda (CRAM_PTR),y ; vram (textcolor) + and #$0f + cmp __bgcolor + jeq @l2b ; yes, vram==bgcolor + + ; now check if the textcolor in color ram is equal the background color, + ; if yes then there is only one (visible) character in the current cell + inc $01 + lda (CRAM_PTR),y ; colram (2nd textcolor) + stx $01 ;$34 + and #$0f + cmp __bgcolor + beq @l2s ; yes, colram==bgcolor + + ; two characters in the current cell, of which one will get removed + + ; vram = colram + ;inc $01 + ;lda (CRAM_PTR),y ; colram + ;stx $01 ;$34 + ;and #$0f + + ; move 2nd text color to vram + sta tmp3 + lda (CRAM_PTR),y ; vram + and #$f0 + ora tmp3 + sta (CRAM_PTR),y ; vram + + ; colram = bgcolor + lda __bgcolor + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + jmp @l2b + +@l2s: + ; colram is bgcolor + ; => only one char in cell used + + jsr soft80_checkchar + bcc @l2b ; space at current position + + ; vram (textcolor) = bgcolor + lda (CRAM_PTR),y ; vram + and #$f0 + ora __bgcolor + sta (CRAM_PTR),y ; vram +@l2b: + rts + +; put color to cell +; in: $01 is $34 (RAM under I/O) when entering +; y must be $00 +; out: y = $00 +soft80_putcolor: + + ;ldy #$00 ; is still $00 + + lda (CRAM_PTR),y ; vram + and #$0f + cmp __bgcolor + beq @l2s ; vram==bgcolor => first char in cell + + ; vram!=bgcolor => second char in cell + + inc $01 ;$35 + lda (CRAM_PTR),y ; colram + stx $01 ;$34 + and #$0f + cmp __bgcolor + bne @l2s ; colram!=bgcolor + + ; colram==bgcolor => second char in cell or overwrite 1st char + + jsr soft80_checkchar + bcs @l2a ; char at current position => overwrite 1st + + ; colram=vram + lda (CRAM_PTR),y ; vram + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + ;jmp @l2a + +@l2s: + ; colram!=bgcolor => alread 2 chars in cell +@l2a: + + ; Set color + lda CHARCOLOR + sta (CRAM_PTR),y ; vram + + rts + + ;.export soft80_checkchar + +; test if there is a space or a character at current position +; in: y must be $00 +; out: CLC: space SEC: character +; y = $00 +soft80_checkchar: + + ;ldy #$00 ; is still $00 + + lda CURS_X + and #$01 + jne @l1a + + .repeat 8,line + lda (SCREEN_PTR),y + and #$f0 + cmp #$f0 + bne @l2b + .if (line < 7) + iny + .endif + .endrepeat + + ldy #$00 + clc + rts +@l2b: + ldy #$00 + sec + rts +@l1a: + .repeat 8,line + lda (SCREEN_PTR),y + and #$0f + cmp #$0f + bne @l2bb + .if line < 7 + iny + .endif + .endrepeat + ldy #$00 + clc + rts +@l2bb: + ldy #$00 + sec + rts + +;--- end color vodoo +.endif diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 2e7457679..790aa2749 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -33,9 +33,14 @@ soft80_kclrscr: inx bne @lp3 +.if SOFT80COLORVOODOO = 1 + lda __bgcolor + jsr clear ; clear color ram +.endif + sei ldy $01 - lda #$34 + lda #$34 ; enable RAM under I/O sta $01 lda CHARCOLOR @@ -43,11 +48,6 @@ soft80_kclrscr: ora __bgcolor jsr clear ; clear vram - inc $01 ; -> $35 - - lda __bgcolor - jsr clear ; clear color ram - sty $01 cli -- 2.39.5