a little optimization for space

This commit is contained in:
thrust26 2021-04-11 11:50:25 +02:00
parent b79d4a29b5
commit 247629475b
2 changed files with 36 additions and 33 deletions

View File

@ -83,7 +83,7 @@
MAC _DRAW_CODEWORDS MAC _DRAW_CODEWORDS
;----------------------------------------------------------- ;-----------------------------------------------------------
; Note: This part has the maximum RAM usage ; Note: This part has the maximum RAM usage
.right = tmpVars+0 .right1 = tmpVars+0
.vert = tmpVars+1 .vert = tmpVars+1
.j = tmpVars+2 .j = tmpVars+2
.y = tmpVars+3 .y = tmpVars+3
@ -97,29 +97,31 @@
_BLACK_FUNC ; returns with X = 0 _BLACK_FUNC ; returns with X = 0
ENDIF ENDIF
; int i = 0; // Bit index into the data ; int i = 0; // Bit index into the data
; ldx #0
; 2600 code has data in reversed order ; 2600 code has data in reversed order
stx .iBit stx .iBit
lda #TOTAL_LEN-1 lda #TOTAL_LEN-1
sta .iByte sta .iByte
; // Do the funny zigzag scan ; // Do the funny zigzag scan
; Note: 2600 code has .right1 increased by 1
; for (int right = qrsize - 1; right >= 1; right -= 2) { // Index of right column in each column pair ; for (int right = qrsize - 1; right >= 1; right -= 2) { // Index of right column in each column pair
ldy #QR_SIZE - 1 ldy #QR_SIZE-1+1
.loopRight .loopRight
; if (right == 6) ; if (right == 6)
cpy #6 cpy #6+1
bne .not6 bne .not6
; right = 5; ; right = 5;
dey ; skip the timing column dey ; skip the timing column
.not6 .not6
sty .right sty .right1
IF QR_OVERLAP IF QR_OVERLAP
; overwrite shared data ; overwrite shared data
cpy #16 cpy #16+1
bne .skipBlackMiddle bne .skipBlackMiddle
; blacken the middle function modules in the bitmap ; blacken the middle function modules in the bitmap
_BLACK_MIDDLE _BLACK_MIDDLE
.skipBlackMiddle .skipBlackMiddle
cpy #8 cpy #8+1
bne .skipBlackLeft bne .skipBlackLeft
; blacken the left function modules in the bitmap ; blacken the left function modules in the bitmap
_BLACK_LEFT _BLACK_LEFT
@ -129,39 +131,33 @@
ldy #QR_SIZE-1 ldy #QR_SIZE-1
.loopVert .loopVert
sty .vert sty .vert
; for (int j = 0; j < 2; j++) {
ldy #-1
.loopJ
iny
sty .j
; bool upward = ((right + 1) & 2) != 0; // 2600 code works in reverse ; bool upward = ((right + 1) & 2) != 0; // 2600 code works in reverse
ldx .vert lda .right1
lda .right and #$02
clc
adc #1
and #$2
bne .notUp bne .notUp
; int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate ; int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate
lda #QR_SIZE-1 lda #QR_SIZE-1;+1
sec sec
sbc .vert sbc .vert
tax
.notUp
stx .y
; int x = right - j; // Actual x coordinate
lda .right
sec
sbc .j
; sta .x
tay tay
.notUp
sty .y
; for (int j = 0; j < 2; j++) {
; some tricky code with .j here
ldy .right1
BIT_B
.loopJ
dey
sty .j
; int x = right - j; // Actual x coordinate
dey
; if (!getModule(qrcode, x, y) && i < dataLen * 8) { ; if (!getModule(qrcode, x, y) && i < dataLen * 8) {
; ldy .x ; ldy .x
; ldx .y ldx .y
jsr CheckPixel jsr CheckPixel
bne .skipPixel bne .skipPixel
ldx .iByte
bmi .skipPixel
; bool black = getBit(data[i >> 3], 7 - (i & 7)); ; bool black = getBit(data[i >> 3], 7 - (i & 7));
ldx .iByte
lda data,x lda data,x
ldx .iBit ldx .iBit
and BitMask,x and BitMask,x
@ -170,30 +166,33 @@
; ldy .x ; ldy .x
ldx .y ldx .y
jsr InvertPixel jsr InvertPixel
ldx .iBit
.skipInv .skipInv
; i++; ; i++;
ldy .iBit inx
iny txa
tya
and #$07 and #$07
sta .iBit sta .iBit
bne .skipByte bne .skipByte
dec .iByte dec .iByte
bmi .exitDraw ; 2600 code exits here!
.skipByte .skipByte
; } ; }
.skipPixel .skipPixel
ldy .j ldy .j
cpy .right1
beq .loopJ beq .loopJ
; } // for j ; } // for j
ldy .vert ldy .vert
dey dey
bpl .loopVert bpl .loopVert
; } // for vert ; } // for vert
ldy .right ldy .right1
dey dey
dey dey
bpl .loopRight bpl .loopRight ; unconditional!
; } // for right ; } // for right
.exitDraw
ENDM ENDM
;----------------------------------------------------------- ;-----------------------------------------------------------

View File

@ -146,6 +146,10 @@ QR_LST_SIZE = . - qrCodeLst
; M A C R O S ; M A C R O S
;=============================================================================== ;===============================================================================
MAC BIT_B
.byte $24
ENDM
MAC BIT_W MAC BIT_W
.byte $2c .byte $2c
ENDM ENDM