]> git.sur5r.net Git - cc65/blobdiff - libsrc/c64/soft80_cputc.s
Merge pull request #431 from polluks/patch-2
[cc65] / libsrc / c64 / soft80_cputc.s
index 0d450d27bbc6f63ca3bf7824218384b57e481d7f..f00f7792f0684171e14d45bb310dc0f7e94447f1 100644 (file)
@@ -1,6 +1,8 @@
 ;
 ; Groepaz/Hitmen, 11.10.2015
 ;
+; high level implementation for the soft80 implementation
+;
 ; void cputcxy (unsigned char x, unsigned char y, char c);
 ; void cputc (char c);
 ;
         .export         soft80_cputcxy, soft80_cputc
         .export         soft80_cputdirect, soft80_putchar
         .export         soft80_newline, soft80_plot
+        .export         soft80_checkchar
 
-        .import         popa, _gotoxy
+        .import         gotoxy
 
         .import         soft80_kplot
-        .import         soft80_internal_bgcolor, soft80_internal_textcolor
+        .import         soft80_internal_bgcolor, soft80_internal_cellcolor
         .import         soft80_internal_cursorxlsb
 
         .importzp       tmp4,tmp3
@@ -22,8 +25,7 @@
 
 soft80_cputcxy:
         pha                     ; Save C
-        jsr     popa            ; Get Y
-        jsr     _gotoxy         ; Set cursor, drop x
+        jsr     gotoxy          ; Set cursor, drop x and y
         pla                     ; Restore C
 
 ; Plot a character - also used as internal function
@@ -49,7 +51,7 @@ L1:     cmp     #$0D            ; LF?
         ; codes $00-$1f are control codes which are not printable and thus may
         ; give undefined result.
         tay
-        bpl     L10
+        bpl     @L10
 
         ; codes $80-$ff must get converted like this:
         ; $80-$9f  ->   dont care (control codes)
@@ -57,21 +59,11 @@ L1:     cmp     #$0D            ; LF?
         ; $c0-$df  ->   $60-$7f
         ; $e0-$ff  ->   $00-$1f
 
-        ; extra check for petscii codes 160-191, these have been moved to
-        ; 0-31 in the charset
-        and     #%11100000
-        cmp     #%10100000
-        bne     @sk
-
-        tya
-        and     #%00011111
-        bpl     L10             ; branch always
-@sk:
-        tya
+        ora     #%01000000      ; $40
         clc
-        adc     #$20
-        and     #$7F
-L10:
+        adc     #%00100000      ; $20
+        and     #%01111111      ; $7f
+@L10:
 
         ; entry point for direct output of a character. the value passed in
         ; akku must match the offset in the charset.
@@ -82,7 +74,7 @@ soft80_cputdirect:
         ; Advance cursor position
         iny                     ; contains CURS_X
         cpy     #charsperline
-        beq     L3
+        beq     @L3
 
         sty     CURS_X
         tya
@@ -102,7 +94,7 @@ soft80_cputdirect:
         inc     CRAM_PTR+1
 @L5:
         rts
-L3:
+@L3:
         inc     CURS_Y          ; new line
         ldy     #0              ; + cr
         sty     CURS_X
@@ -124,9 +116,9 @@ soft80_newline:
         clc
         adc     #40
         sta     CRAM_PTR
-        bcc     L5
+        bcc     @L5
         inc     CRAM_PTR+1
-L5:
+@L5:
         inc     CURS_Y
         rts
 
@@ -157,7 +149,7 @@ draw_spaceinvers:
 .if SOFT80COLORVOODOO = 1
         jsr     soft80_putcolor
 .else
-        lda     CHARCOLOR
+        lda     soft80_internal_cellcolor
         sta     (CRAM_PTR),y    ; vram
 .endif
 
@@ -241,7 +233,7 @@ soft80_putchar:
 .if SOFT80COLORVOODOO = 1
         jsr     soft80_putcolor
 .else
-        lda     CHARCOLOR
+        lda     soft80_internal_cellcolor
         sta     (CRAM_PTR),y    ; vram
 .endif
 
@@ -346,7 +338,8 @@ draw_charinvers:
 ;
 ; in:  x must be $34
 ;      y must be $00
-; out: y = $00
+; out: x = $34
+;      y = $00
 remcolor:
 
         ;ldy     #$00            ; is still $00
@@ -367,23 +360,17 @@ remcolor:
         and     #$0f
         cmp     soft80_internal_bgcolor
         beq     @sk2            ; yes, colram==bgcolor
+        sta     tmp3            ; A contains colram
 
         ; 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
-        sta     tmp3            ; A contains colram
-
         lda     soft80_internal_cursorxlsb
         bne     @sk3
 
         ; vram = colram
         lda     (CRAM_PTR),y    ; vram
         and     #$f0
-        ora     tmp3
+        ora     tmp3            ; colram value
         sta     (CRAM_PTR),y    ; vram
 @sk3:
         ; colram = bgcolor
@@ -399,7 +386,7 @@ remcolor:
         ; => only one char in cell used
 
         jsr     soft80_checkchar
-        bcc     @sk1            ; space at current position
+        bcs     @sk1            ; space at current position
 
         ; vram (textcolor) = bgcolor
         lda     (CRAM_PTR),y    ; vram
@@ -450,20 +437,20 @@ soft80_putcolor:
         bne     @sk2            ; jump if odd xpos
 
         ; vram = textcol
-        lda     CHARCOLOR
+        lda     soft80_internal_cellcolor
         sta     (CRAM_PTR),y    ; vram
         rts
 
 @l2s:
         ; one character in cell is already used
         jsr     soft80_checkchar
-        bcs     @sk1            ; char at current position => overwrite 1st
+        bcc     @sk1            ; char at current position => overwrite 1st
 
         lda     soft80_internal_cursorxlsb
         beq     @sk3            ; jump if even xpos
 @sk2:
         ; colram = textcol
-        lda     soft80_internal_textcolor
+        lda     CHARCOLOR
         inc     $01             ; $35
         sta     (CRAM_PTR),y    ; colram
         stx     $01             ; $34
@@ -477,7 +464,7 @@ soft80_putcolor:
         stx     $01             ; $34
 @sk1:
         ; vram = textcol
-        lda     CHARCOLOR
+        lda     soft80_internal_cellcolor
         sta     (CRAM_PTR),y    ; vram
         rts
 
@@ -485,14 +472,14 @@ soft80_putcolor:
 ; test if there is a space or a character at current position
 ;
 ; in:  x = $34
-;      y must be $00
-; out: CLC: space        SEC: character
+;      $01 must be $34
+;
+; out: SEC: space
+;      CLC: character
 ;      x = $34
 ;      y = $00
 soft80_checkchar:
 
-        ;ldy     #$00                            ; is still $00
-
         lda     soft80_internal_cursorxlsb
         bne     @l1a
 
@@ -511,11 +498,11 @@ soft80_checkchar:
         .endif
         .endrepeat
         ;ldy     #$00                            ; is 0
-        clc
+        ;sec                                     ; is set
         rts
 @ischar:
         ldy     #$00
-        sec
+        ;clc                                     ; is cleared
         rts
 @l1a:
         ldy     #$07
@@ -529,6 +516,6 @@ soft80_checkchar:
         .endif
         .endrepeat
         ;ldy     #$00                            ; is 0
-        clc
+        ;sec                                     ; is set
         rts
 .endif