a bit faster, explicit memory init

This commit is contained in:
Peter Ferrie 2021-06-14 21:40:20 -07:00
parent 88a3baba1c
commit 63f9f2ce46

224
QR.6502
View File

@ -112,45 +112,33 @@ GETMESSAGE LDA MESSAGE,Y ; 0
STA $FC
JSR MULT45 ; RESULT IN FE,FD
CLC
INY ; 1
LDA MESSAGE,Y
LDA MESSAGE+1,Y
ADC $FD
STA $FD
BCC STOREPAIR
INC $FE ; RESULT IN FE,FD
STOREPAIR DEY ; 0
STA STORAGE+1,Y ; LO BYTE
LDA $FE
ADC #0 ; RESULT IN FE,FD
STA STORAGE,Y ; HI BYTE
INY ; 1
LDA $FD
STA STORAGE,Y ; LO BYTE
INY ; 2
CPY MESSAGELENGTH
BEQ BUILDQR
BCC GETMESSAGE
BCS BUILDQR
JMP GETMESSAGE
**************************************************
* Byte mode = ROR each byte in message 4x, append to mode/length bits.
**************************************************
BYTEMODE LDY #$00
FINDLENGTH LDX MESSAGE,Y
BEQ FOUNDLENGTH
INY
JMP FINDLENGTH
BYTEMODE LDY #$FF
FINDLENGTH INY
LDX MESSAGE,Y
BNE FINDLENGTH
FOUNDLENGTH STY MESSAGELENGTH
LDX MESSAGELENGTH
DEX
LDA MESSAGE,X ; LAST BYTE OF MESSAGE
AND #$0F ; LO 4 BITS
CLC
ROL
ROL
ROL
ROL
INX
STA STORAGE,X ; 4 BITS AT END OF CONVERTED MESSAGE
LDA MESSAGE-1,Y ; LAST BYTE OF MESSAGE
ASL ; LO 4 BITS
ASL
ASL
ASL
STA STORAGE,Y ; 4 BITS AT END OF CONVERTED MESSAGE
COPYMSG LDX #$0 ; COPY THE MESSAGE TO STORAGE
COPYBYTE LDA MESSAGE,X
@ -163,12 +151,10 @@ COPYBYTE LDA MESSAGE,X
LDY #$04
RORMSG LDX #$0
CLC
PHP
RORBYTE PLP
ROR STORAGE,X
RORBYTE ROR STORAGE,X
INX
PHP ; PRESERVES CARRY
CPX MESSAGELENGTH ; BECAUSE CPX CLOBBERS IT
TXA ; DON'T USE CPX, PRESERVES CARRY
EOR MESSAGELENGTH
BNE RORBYTE
DEY
BNE RORMSG
@ -183,7 +169,6 @@ BUILDQR
**************************************************
LDA MESSAGELENGTH ; NNNNXXXX
CLC
LDX MODE
CPX #$40
BEQ LSR4X
@ -203,32 +188,22 @@ LSR4X LSR
BNE DOALPHAMODE
JMP DOBYTEMODE
DOALPHAMODE AND #$1F ; 000NXXXX
DOALPHAMODE ; 000NXXXX
CLC
ROL ; <- 3X
ROL
ROL ; NXXXX 000
ASL
ASL ; <- 3X
ASL ; NXXXX 000
LDX #$0
ORA STORAGE,X ; 3 BITS OF FIRST HI BYTE
ORA STORAGE ; 3 BITS OF FIRST HI BYTE
INY
STA MPINTS,Y
INX
INY
LDA STORAGE,X ; FIRST LO BYTE
STA MPINTS,Y ; HOW CONVENIENT. FIRST PAIR OF BYTES ENDS ON AN 8X BOUNDARY.
INY ; SET UP NEXT BYTE OF QR
* FOR EACH REMAINING PAIR OF BYTES, GET 3 BITS FROM HI, 8 BITS FROM LO
LDA #$08
STA BITCOUNTER ; CURRENT BIT OF QR ENCODING CYCLE
LDA MPINTS,Y ; CURRENT BYTE OF QR DATA
LDA STORAGE+1 ; FIRST LO BYTE
JSR NEXTQRBYTE ; HOW CONVENIENT. FIRST PAIR OF BYTES ENDS ON AN 8X BOUNDARY.
; ALSO INITIALIZES BITCOUNTER
LDX #$02 ; WHICH BYTE OF MESSAGE
NEXTMBYTE ROL STORAGE,X ; HI BYTE - ROL 5X
NEXTMBYTE ASL STORAGE,X ; HI BYTE - ROL 5X
ROL STORAGE,X
ROL STORAGE,X
ROL STORAGE,X
@ -291,39 +266,31 @@ BIT10 ROL STORAGE,X
JSR NEXTQRBYTE
NEXTHIBYTE INX
CPX MESSAGELENGTH ; up to 114 BYTES OF MESSAGE
BEQ PADBYTES
BCS PADBYTES
JMP NEXTMBYTE ; 3 BITS OF HI BYTE AND 8 OF LO BYTE ROTATED INTO QR BYTESTREAM
DOBYTEMODE AND #$0F ; A=MESSAGELENGTH. 0000XXXX
CLC
ROL
ROL
ROL
ROL ; XXXX____
DOBYTEMODE ; A=MESSAGELENGTH. 0000XXXX
ASL
ASL
ASL
ASL ; XXXX____
ORA STORAGE,Y
INY
BYTEMODELOOP STA MPINTS,Y
CPY MESSAGELENGTH
BEQ LASTBYTE
LDA STORAGE,Y
INY
JMP BYTEMODELOOP
LASTBYTE LDA STORAGE,Y
INY
BYTEMODELOOP INY
STA MPINTS,Y
JMP PADLOOP
LDA STORAGE,Y
CPY MESSAGELENGTH
BCC BYTEMODELOOP
BEQ BYTEMODELOOP
BCS PADLOOP
* pad to 80 bytes with 0s and 11101100 00010001 (#$EC #$11)
PADBYTES LDX BITCOUNTER ; ALWAYS TERMINATE WITH 4 ZEROES
PADBYTES2 CLC
db $C9 ; MASK ASL
PADBYTES2 ASL
DEC BITCOUNTER
BMI PADBITS
ROL
JMP PADBYTES2
BPL PADBYTES2
PADBITS STA MPINTS,Y ; STORE INCOMPLETE BYTE WITH TRAILING ZEROS
CPX #$04 ; NEEDS TO BE AT LEAST 4 FOR TERMINATOR
BCS PADLOOP
@ -342,42 +309,42 @@ PADLOOP INY ; NEXT QR BYTE
DOECCBYTES LDX #$0 ; OH, THIS GON' BE FUN.
LDA #$50
STA BYTECOUNTER ; HOW MANY TIMES HAVE WE BEEN HERE BEFORE?
DOECCBYTES LDX #$50 ; OH, THIS GON' BE FUN.
STX BYTECOUNTER ; HOW MANY TIMES HAVE WE BEEN HERE BEFORE?
COPYBYTES LDA MPINTS,X ; COPY COMPLETE MESSAGE BYTES TO STORAGE SPACE AT $8000
STA STORAGE,X
INX
CPX #$51 ; DONE ALL 80 BYTES
BNE COPYBYTES
ECCSTEP1 LDX #$0 ; convert integers in message to exponents
MSGTOEXP LDY MPINTS,X ; convert integers in message to exponents
ECCSTEP1
MSGTOEXP TAY ; convert integers in message to exponents
LDA INTTOEXP,Y
STA MPEXP,X
INX
CPX #$51
BNE MSGTOEXP ; MSG EXPONENTS IN MPEXP
LDA #0
STA SCRATCH,X
DEX ; DONE ALL 80 BYTES
BPL COPYBYTES
STA XORRESULT+$50
STA XORRESULT+$51
STA XORRESULT+$52 ; SKIPZERO READS OOB
ECCSTEP2 LDX #$0 ; Multiply the Generator Polynomial by the Lead EXPONENT of the Message Polynomial
STEP2LOOP LDA MPEXP ; mp first exponent
CLC
ADC GENERATOR,X ; ADDED TO each gp exponent
ADC #0 ; MOD 255 ON ROLLOVER > FF ADDS CARRY
TAY
BCC SCRATCHINT ; MOD 255 ON ROLLOVER > FF ADDS CARRY
INY
SCRATCHINT LDA EXPTOINT,Y ; convert EXPONENTS in RESULT to INTEGERS
STA SCRATCH,X ; STORE IN WORK AREA 2
ECCSTEP3 EOR MPINTS,X ; INTEGER TERMS OF MESSAGE
STA XORRESULT,X ; RESULT FEEDS INTO STEP 1
INX
CPX #$15
BNE STEP2LOOP ; INTEGER RESULTS IN SCRATCH
ECCSTEP3 LDX #$0 ; XOR the result with the message polynomial (INTEGERS)
XORBYTE LDA SCRATCH,X ; INTEGER RESULT OF MULTIPLICATION
EOR MPINTS,X ; INTEGER TERMS OF MESSAGE
STOREXOR STA XORRESULT,X ; RESULT FEEDS INTO STEP 1
; XOR the result with the message polynomial (INTEGERS)
XORBYTE LDA MPINTS,X ; INTEGER TERMS OF MESSAGE
STA XORRESULT,X ; RESULT FEEDS INTO STEP 1
INX
CPX #$51
BNE XORBYTE
@ -410,23 +377,21 @@ XORTOEXP STA MPINTS,Y ; RESULT INTEGERS IN MPINTS
BNE XORTOEXP ; RESULT EXPONENTS IN MPEXP
DEC BYTECOUNTER ; DO ECC MATH UNTIL THERE'S 20 REMAINDERS
BEQ ECCDONE
JMP ECCSTEP2
BNE ECCSTEP2
ECCDONE ; XORRESULT CONTAINS 20 ECC BYTES
LDX #$1
LDY #$50
LDX #$15
LDY #$64
BUILDMSG LDA XORRESULT,X
STA STORAGE,Y
INX
INY
CPX #$16
DEY
DEX
BNE BUILDMSG ; STORAGE NOW HAS FULL 100 BYTES OF MESSAGE
RESETBYTE LDA #$0 ; SET UP FOR BYTE/BIT TRACKING
STA BYTECOUNTER
RESETBYTE ;;LDA #$0 ; SET UP FOR BYTE/BIT TRACKING
;;STA BYTECOUNTER
RESETBIT LDA #$8
STA BITCOUNTER
@ -434,9 +399,10 @@ RESETBIT LDA #$8
LDA #$20 ; ROW=33 (0-#$20)
STA ROW ; COLUMN=33 (0-#$20)
STA COLUMN
NEXTZIG CLC ; QRLINE=ROW/2
NEXTZIG ; QRLINE=ROW/2
LDA ROW
LSR
PHP
TAX ; LINE NUM OF BLANK QR = ROW/2
LDA QRLINESLO,X
STA LOBYTE
@ -456,8 +422,7 @@ LONIBBLE AND #$0F
BNE ZAG ; OCCUPIED?
JSR SETPIXEL ; GET A BIT FROM THE MESSAGE, AND DEPOSIT INTO THE PIXEL
ZAG DEY ; ZIG IS DONE/OCCUPIED, TIME TO ZAG - ONE COLUMN TO THE LEFT
LDA ROW ; LOST THE CARRY, SO CHECK THE ROW AGAIN
LSR
PLP ; RESTORE THE CARRY
LDA (LOBYTE),Y ; GET CURRENT QR PIXEL
BCC LONIBBLE2
AND #$F0
@ -482,14 +447,12 @@ DIVBY4 LSR ; DIVIDE STARTING COLUMN BY 2
GOINGUP LDA ROW
BEQ UTURN ; TURN THE CORNER AT ROW 0
DEC ROW
LDA COLUMN
JMP NEXTZIG ;
GOINGDOWN LDA ROW
CMP #$20 ; LAST ROW?
BEQ UTURN ; TURN THE CORNER, ROW 32
INC ROW ; OTHERWISE, NEXT ROW
LDA COLUMN
JMP NEXTZIG
UTURN LDA COLUMN
@ -500,7 +463,6 @@ CKCOLUMN CMP #$01 ; IS IT #$01? THEN WE'RE DONE HERE.
BEQ DODISPLAY
DEC COLUMN
DEC COLUMN ; TWO COLUMNS OVER FOR NEXT ZIG
LDA COLUMN
JMP NEXTZIG
@ -550,28 +512,20 @@ NEXTQRBYTE STA MPINTS,Y ; STORE COMPLETE BYTE
*** SETPIXEL
SETPIXEL CMP #$01 ; ACC IS GOING TO BE EITHER 01 OR 10
BEQ SETLONIBBLE
PHP
JSR GETNEXTBIT ; LOADS TEMP WITH PROPER F OR 0
; Y HAS COLUMN OFFSET
; (LOBYTE) HAS ROW
SETHINIBBLE LDA TEMP
AND #$F0
STA TEMP
EOR (LOBYTE),Y ; MIX BITS
PLP
BEQ SETLONIBBLE
LDA (LOBYTE),Y ; GET CURRENT QR PIXEL
AND #$0F ; CLEAR HI NIBBLE
SETHINIBBLE AND #$F0 ; SEPARATE BITS
JMP SETNIBBLE
SETLONIBBLE JSR GETNEXTBIT ; LOADS TEMP WITH PROPER F OR 0
LDA TEMP
AND #$0F
STA TEMP
SETLONIBBLE AND #$0F ; SEPARATE BITS
LDA (LOBYTE),Y ; GET CURRENT QR PIXEL
AND #$F0 ; CLEAR LO NIBBLE
SETNIBBLE EOR TEMP
SETNIBBLE EOR (LOBYTE),Y ; MERGE BITS
STA (LOBYTE),Y ; REPLACE QR PIXEL.
RTS
*** SETPIXEL
@ -583,32 +537,28 @@ GETNEXTBIT LDA BITCOUNTER ; WHERE WERE WE IN THE ROL SHENANIGANS?
LDA #$08 ; OR ARE WE?
STA BITCOUNTER ; IF SO...
INC BYTECOUNTER ; NEXT BYTE
NEXTBIT LDX BYTECOUNTER ; ARE WE DONE WITH ALL 100 BYTES?
NEXTBIT LDA TEMP
LDX BYTECOUNTER ; ARE WE DONE WITH ALL 100 BYTES?
CPX #$64
BEQ MASKDONE
BEQ MASKDONE1
DEC BITCOUNTER
CLC
ROL STORAGE,X
BCC WHITEPIXEL
BLACKPIXEL LDA #$00
BEQ COLORPIXEL ; BRANCH ALWAYS
ASL STORAGE,X
WHITEPIXEL LDA #$FF
COLORPIXEL STA TEMP
BLACKPIXEL ADC #$00
COLORPIXEL TAX
DOMASK ; JFC ON A POGO STICK! GOTTA MASK THE BITS!
; MASK PATTERN 1: IF (row) mod 2 == 0 THEN FLIP BIT.
LDA ROW
LSR
TXA
BCS MASKDONE ; ROW IS ODD, ALL DONE.
LDA TEMP ; ROW IS EVEN, FLIP THE BIT
BNE FLIPBIT
DEC TEMP ; TEMP IS ZERO, SET TO FF
RTS
FLIPBIT INC TEMP ; TEMP IS FF, SET TO ZERO
MASKDONE RTS
EOR #$FF ; ROW IS EVEN, FLIP THE BIT
MASKDONE STA TEMP
MASKDONE1 RTS
*** GETNEXTBIT