some code shuffling to get rid of long branches

This commit is contained in:
mrdudz 2015-10-12 18:01:48 +02:00
parent cf8b21b27e
commit ead9950044
2 changed files with 102 additions and 90 deletions

View file

@ -70,6 +70,10 @@ soft80_init:
sta $01 sta $01
cli cli
; the "color voodoo" in other parts of the code relies on the vram and
; colorram being set up as expected, which is why we cant use the
; _bgcolor and _textcolor functions here.
lda 646 ; use current textcolor lda 646 ; use current textcolor
and #$0f and #$0f
sta soft80_internal_textcolor sta soft80_internal_textcolor

View file

@ -10,22 +10,16 @@
.export soft80_newline, soft80_plot .export soft80_newline, soft80_plot
.import popa, _gotoxy .import popa, _gotoxy
.import xsize
.import soft80_kplot .import soft80_kplot
.import soft80_internal_bgcolor, soft80_internal_textcolor .import soft80_internal_bgcolor, soft80_internal_textcolor
.import soft80_internal_cursorxlsb .import soft80_internal_cursorxlsb
.importzp tmp4,tmp3 .importzp tmp4,tmp3
.macpack longbranch
.include "c64.inc" .include "c64.inc"
.include "soft80.inc" .include "soft80.inc"
.if SOFT80COLORVOODOO = 1
.export soft80_putcolor
.endif
soft80_cputcxy: soft80_cputcxy:
pha ; Save C pha ; Save C
jsr popa ; Get Y jsr popa ; Get Y
@ -51,10 +45,18 @@ soft80_plot:
L1: cmp #$0D ; LF? L1: cmp #$0D ; LF?
beq soft80_newline ; Recalculate pointers beq soft80_newline ; Recalculate pointers
; Printable char of some sort ; shortcut for codes < $80 ... codes $20-$7f can be printed directly,
; codes $00-$1f are control codes which are not printable and thus may
; give undefined result.
tay tay
bpl L10 bpl L10
; codes $80-$ff must get converted like this:
; $80-$9f -> dont care (control codes)
; $a0-$bf -> $00-$1f
; $c0-$df -> $60-$7f
; $e0-$ff -> $00-$1f
; extra check for petscii codes 160-191, these have been moved to ; extra check for petscii codes 160-191, these have been moved to
; 0-31 in the charset ; 0-31 in the charset
and #%11100000 and #%11100000
@ -77,9 +79,7 @@ L10:
soft80_cputdirect: soft80_cputdirect:
jsr soft80_putchar ; Write the character to the screen jsr soft80_putchar ; Write the character to the screen
; Advance cursor position ; Advance cursor position
advance:
iny ; contains CURS_X iny ; contains CURS_X
cpy #charsperline cpy #charsperline
beq L3 beq L3
@ -130,53 +130,29 @@ L5:
inc CURS_Y inc CURS_Y
rts rts
; Write one character to the screen without doing anything else ;-------------------------------------------------------------------------------
; in: A: character ; All following code belongs to the character output to bitmap
; returns: Y: cursor X position ;
; this function is going to be used a lot so we unroll it a bit for speed ; this stuff is going to be used a lot so we unroll it a bit for speed
;-------------------------------------------------------------------------------
.if SOFT80FASTSPACE = 1 .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
;and #$01
lda soft80_internal_cursorxlsb
bne @l1
; output inverted space (odd)
draw_spaceinvers_odd:
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
ora #$f0 and #$f0
sta (SCREEN_PTR),y
.if (line < 7)
iny
.endif
.endrepeat
jmp _back
@l1:
.repeat 8,line
lda (SCREEN_PTR),y
ora #$0f
sta (SCREEN_PTR),y sta (SCREEN_PTR),y
.if line < 7 .if line < 7
iny iny
.endif .endif
.endrepeat .endrepeat
@l2: jmp draw_back
jmp _back
; output inverted space ; output inverted space (general entry point)
; in: y must be $00 ; in: y must be $00
_spaceinvers: draw_spaceinvers:
.if SOFT80COLORVOODOO = 1 .if SOFT80COLORVOODOO = 1
jsr soft80_putcolor jsr soft80_putcolor
@ -188,8 +164,9 @@ _spaceinvers:
;lda CURS_X ;lda CURS_X
;and #$01 ;and #$01
lda soft80_internal_cursorxlsb lda soft80_internal_cursorxlsb
bne @l1 bne draw_spaceinvers_odd
; output inverted space (even)
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
and #$0f and #$0f
@ -198,23 +175,57 @@ _spaceinvers:
iny iny
.endif .endif
.endrepeat .endrepeat
jmp _back jmp draw_back
@l1:
; output space (odd)
draw_space_odd:
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
and #$f0 ora #$0f
sta (SCREEN_PTR),y sta (SCREEN_PTR),y
.if line < 7 .if line < 7
iny iny
.endif .endif
.endrepeat .endrepeat
jmp draw_back
jmp _back ; output space (general entry point)
; in: y must be $00
draw_space:
lda RVS
bne draw_spaceinvers
.if SOFT80COLORVOODOO = 1
jsr remcolor
.endif
;ldy #$00 ; is still $00
;lda CURS_X
;and #$01
lda soft80_internal_cursorxlsb
bne draw_space_odd
; output space (even)
.repeat 8,line
lda (SCREEN_PTR),y
ora #$f0
sta (SCREEN_PTR),y
.if (line < 7)
iny
.endif
.endrepeat
jmp draw_back
.endif .endif
; entry point for outputting one character in internal encoding ;-------------------------------------------------------------------------------
; without advancing cursor position ; output one character in internal encoding without advancing cursor position
; - the following may not modify tmp1 ; generic entry point
;
; - the following may not modify tmp1
; in: A: charcode
; out: Y: CURS_X
;
soft80_putchar: soft80_putchar:
sta tmp3 ; remember charcode sta tmp3 ; remember charcode
@ -228,7 +239,7 @@ soft80_putchar:
.if SOFT80FASTSPACE = 1 .if SOFT80FASTSPACE = 1
cmp #' ' ; space is a special (optimized) case cmp #' ' ; space is a special (optimized) case
jeq _space beq draw_space
.endif .endif
.if SOFT80COLORVOODOO = 1 .if SOFT80COLORVOODOO = 1
@ -237,18 +248,18 @@ soft80_putchar:
lda CHARCOLOR lda CHARCOLOR
sta (CRAM_PTR),y ; vram sta (CRAM_PTR),y ; vram
.endif .endif
; output character
; output character
ldx tmp3 ; get charcode ldx tmp3 ; get charcode
lda RVS lda RVS
jne _invers beq @skp
jmp draw_charinvers
;lda CURS_X @skp:
;and #$01
lda soft80_internal_cursorxlsb lda soft80_internal_cursorxlsb
bne @l1 bne draw_char_even
; output character (odd)
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
and #$0f and #$0f
@ -258,9 +269,10 @@ soft80_putchar:
iny iny
.endif .endif
.endrepeat .endrepeat
jmp @l2 jmp draw_back
@l1:
; output character (even)
draw_char_even:
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
and #$f0 and #$f0
@ -271,9 +283,7 @@ soft80_putchar:
.endif .endif
.endrepeat .endrepeat
@l2: draw_back:
_back:
lda tmp4 lda tmp4
sta $01 sta $01
cli cli
@ -281,13 +291,23 @@ _back:
ldy CURS_X ldy CURS_X
rts rts
; output inverted character ; output inverted character (odd)
_invers: draw_charinvers_odd:
.repeat 8,line
lda (SCREEN_PTR),y
ora #$0f
eor soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
jmp draw_back
;lda CURS_X ; output inverted character (generic)
;and #$01 draw_charinvers:
lda soft80_internal_cursorxlsb lda soft80_internal_cursorxlsb
bne @l1 bne draw_charinvers_odd
.repeat 8,line .repeat 8,line
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
@ -298,18 +318,7 @@ _invers:
iny iny
.endif .endif
.endrepeat .endrepeat
jmp _back jmp draw_back
@l1:
.repeat 8,line
lda (SCREEN_PTR),y
ora #$0f
eor soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
jmp _back
;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
; optional "color voodoo". the problem is that each 8x8 cell can only contain ; optional "color voodoo". the problem is that each 8x8 cell can only contain
@ -500,7 +509,7 @@ soft80_checkchar:
bne @l1a bne @l1a
; check charset data from bottom up, since a lot of eg lowercase chars ; check charset data from bottom up, since a lot of eg lowercase chars
; have no data in the top rows, but all of the DO have data in the ; have no data in the top rows, but all of them DO have data in the
; second to bottom row, this will likely be faster in average. ; second to bottom row, this will likely be faster in average.
ldy #7 ldy #7
@ -513,7 +522,6 @@ soft80_checkchar:
dey dey
.endif .endif
.endrepeat .endrepeat
;ldy #$00 ; is 0 ;ldy #$00 ; is 0
clc clc
rts rts
@ -527,7 +535,7 @@ soft80_checkchar:
lda (SCREEN_PTR),y lda (SCREEN_PTR),y
and #$0f and #$0f
cmp #$0f cmp #$0f
bne @l2bb bne @l2b
.if line < 7 .if line < 7
dey dey
.endif .endif
@ -535,9 +543,9 @@ soft80_checkchar:
;ldy #$00 ; is 0 ;ldy #$00 ; is 0
clc clc
rts rts
@l2bb: ;@l2bb:
ldy #$00 ; ldy #$00
sec ; sec
rts ; rts
.endif .endif