1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Fix bug with bgcolor and textcolor

This commit is contained in:
jede 2019-07-17 21:48:53 +02:00 committed by greg-king5
parent 6f7f6b5119
commit ede64f68a9
7 changed files with 59 additions and 89 deletions

View File

@ -3,23 +3,10 @@
.export _bgcolor .export _bgcolor
.import BGCOLOR .import BGCOLOR
.import BGCOLOR_CHANGE
.include "telestrat.inc" .include "telestrat.inc"
.proc _bgcolor .proc _bgcolor
cmp BGCOLOR ; Do we set the same color? If we don't detect it, we loose one char on the screen for each bgcolor call with the same color
bne out ; Yes
ldy #$00
sty BGCOLOR_CHANGE
rts
out:
ldx BGCOLOR ; Get last color in order to return it
sta BGCOLOR sta BGCOLOR
lda #$01 ; Notify the change color
sta BGCOLOR_CHANGE
txa ; Return previous color
rts rts
.endproc .endproc

View File

@ -3,9 +3,8 @@
; ;
.export _clrscr .export _clrscr
.import OLD_CHARCOLOR, OLD_BGCOLOR, CHARCOLOR, BGCOLOR
.import CHARCOLOR_CHANGE, CHARCOLOR, BGCOLOR, BGCOLOR_CHANGE
.include "telestrat.inc" .include "telestrat.inc"
.proc _clrscr .proc _clrscr
@ -35,12 +34,13 @@
dex dex
stx SCRX stx SCRX
stx CHARCOLOR_CHANGE ; X is equal to 0
stx BGCOLOR_CHANGE stx BGCOLOR
stx OLD_BGCOLOR
lda #$07 lda #$07
sta CHARCOLOR sta CHARCOLOR
sta BGCOLOR sta OLD_CHARCOLOR
rts rts
.endproc .endproc

View File

@ -4,34 +4,39 @@
; void cputc (char c); ; void cputc (char c);
; ;
.export _cputc, CHARCOLOR, CHARCOLOR_CHANGE, BGCOLOR, BGCOLOR_CHANGE .export _cputc, CHARCOLOR, OLD_CHARCOLOR, BGCOLOR, OLD_BGCOLOR
.include "telestrat.inc" .include "telestrat.inc"
.proc _cputc .proc _cputc
ldx CHARCOLOR_CHANGE ldx CHARCOLOR
cpx OLD_CHARCOLOR
beq do_not_change_color_foreground beq do_not_change_color_foreground
stx OLD_CHARCOLOR ; Store CHARCOLOR into OLD_CHARCOLOR
dec SCRX dec SCRX
dec SCRX dec SCRX
pha pha
lda CHARCOLOR txa ; Swap X to A because, X contains CHARCOLOR
BRK_TELEMON XFWR ; Change color on the screen (foreground) BRK_TELEMON XFWR ; Change color on the screen (foreground)
lda #$00
sta CHARCOLOR_CHANGE
inc SCRX inc SCRX
pla pla
do_not_change_color_foreground: do_not_change_color_foreground:
ldx BGCOLOR_CHANGE ldx BGCOLOR
cpx OLD_BGCOLOR
beq do_not_change_color beq do_not_change_color
stx OLD_BGCOLOR
dec SCRX ; Dec SCRX in order to place attribute before the right position dec SCRX ; Dec SCRX in order to place attribute before the right position
pha pha
lda BGCOLOR txa ; Swap X to A because, X contains CHARCOLOR
ORA #%00010000 ; Add 16 because background color is an attribute between 16 and 23. 17 is red background for example ORA #%00010000 ; Add 16 because background color is an attribute between 16 and 23. 17 is red background for example
BRK_TELEMON XFWR ; Change color on the screen (background) BRK_TELEMON XFWR ; Change color on the screen (background)
lda #$00
sta BGCOLOR_CHANGE
pla pla
do_not_change_color: do_not_change_color:
@ -41,9 +46,9 @@ do_not_change_color:
.bss .bss
CHARCOLOR: CHARCOLOR:
.res 1 .res 1
CHARCOLOR_CHANGE: OLD_CHARCOLOR:
.res 1 .res 1
BGCOLOR: BGCOLOR:
.res 1 .res 1
BGCOLOR_CHANGE: OLD_BGCOLOR:
.res 1 .res 1

View File

@ -3,13 +3,8 @@
; ;
.export _gotox .export _gotox
.import popa
.importzp sp
.include "telestrat.inc" .include "telestrat.inc"
.proc _gotox .proc _gotox
sta SCRX sta SCRX
rts rts

View File

@ -7,7 +7,7 @@
.export gotoxy, _gotoxy, update_adscr .export gotoxy, _gotoxy, update_adscr
.import popa, CHARCOLOR_CHANGE, BGCOLOR_CHANGE .import popa, OLD_CHARCOLOR, OLD_BGCOLOR
.include "telestrat.inc" .include "telestrat.inc"
@ -17,22 +17,24 @@ gotoxy: jsr popa ; Get Y
; This function moves only the display cursor; it does not move the prompt position. ; This function moves only the display cursor; it does not move the prompt position.
; In telemon, there is a position for the prompt, and another for the cursor. ; In telemon, there is a position for the prompt, and another for the cursor.
sta SCRY sta SCRY
jsr update_adscr ; Update adress video ram position when SCRY is modified
jsr popa jsr popa
sta SCRX sta SCRX
jsr update_adscr ; Update adress video ram position when SCRY et SCRX are modified
; Force to put again attribute when it moves on the screen
rts rts
.endproc .endproc
.proc update_adscr .proc update_adscr
; Force to set again color if cursor moves
lda #$01 ; $FF is used because we know that it's impossible to have this value with a color
sta CHARCOLOR_CHANGE ; It prevents a bug : If bgcolor or textcolor is set to black for example with no char displays,
sta BGCOLOR_CHANGE ; next cputsxy will not set the attribute if y coordinate changes
lda #$FF
sta OLD_CHARCOLOR
sta OLD_BGCOLOR
lda #<SCREEN lda #<SCREEN
sta ADSCRL sta ADSCRL

View File

@ -10,8 +10,5 @@
.proc _gotoy .proc _gotoy
sta SCRY sta SCRY
jsr update_adscr jsr update_adscr
; We change the current line, it means that we need to put color attributes again.
; That is not the case with _gotox because, it's on the same line attribute are already set
rts rts
.endproc .endproc

View File

@ -3,25 +3,9 @@
.export _textcolor .export _textcolor
.import CHARCOLOR .import CHARCOLOR
.import CHARCOLOR_CHANGE
.include "telestrat.inc" .include "telestrat.inc"
.proc _textcolor .proc _textcolor
cmp CHARCOLOR ; Do we set the same color? If we don't detect it, we loose one char on the screen for each textcolor call with the same color
bne out ; yes
ldy #$00
sty CHARCOLOR_CHANGE
; Return last color
rts
out:
ldx CHARCOLOR ; Get last color in order to return it
sta CHARCOLOR sta CHARCOLOR
lda #$01
sta CHARCOLOR_CHANGE
txa ; Return previous color
rts rts
.endproc .endproc