2021-04-11 08:25:59 +00:00
|
|
|
|
; QR Code generator demo V0.3
|
|
|
|
|
; (C) 2021 Thomas Jentzsch
|
|
|
|
|
|
|
|
|
|
; TODOs
|
|
|
|
|
; + get it working!
|
|
|
|
|
; + reduce RAM usage
|
|
|
|
|
; + reverse data
|
|
|
|
|
; + overlap data with QR code
|
|
|
|
|
; + multiple pattern formats
|
|
|
|
|
; + apply pattern
|
|
|
|
|
; x evaluate pattern (very slow!)
|
2021-04-11 15:15:10 +00:00
|
|
|
|
; + optimize single pattern for space
|
2021-04-11 15:38:58 +00:00
|
|
|
|
; x support multiple QR code versions
|
2021-04-11 08:25:59 +00:00
|
|
|
|
; o support multiple QR code levels
|
2021-04-11 15:38:58 +00:00
|
|
|
|
; x try to optimize function pattern (SetPixel)
|
2021-04-11 08:25:59 +00:00
|
|
|
|
; x add logo (does NOT work for such small sizes)
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
; QR code data bytes (version 2):
|
|
|
|
|
; - 13 into right sprite column
|
|
|
|
|
; - 17 until horizontal timer line
|
|
|
|
|
; - 36 into right and middle sprite column
|
|
|
|
|
; - 8 in left sprite column
|
|
|
|
|
|
|
|
|
|
processor 6502
|
|
|
|
|
LIST OFF
|
|
|
|
|
include vcs.h
|
|
|
|
|
LIST ON
|
|
|
|
|
|
2021-04-11 15:15:10 +00:00
|
|
|
|
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;===============================================================================
|
|
|
|
|
; A S S E M B L E R - S W I T C H E S
|
|
|
|
|
;===============================================================================
|
|
|
|
|
|
|
|
|
|
BASE_ADR = $f000
|
|
|
|
|
|
2021-04-12 08:50:03 +00:00
|
|
|
|
NTSC = 1 ; 0 = PAL50
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ATARI_2600 = 1 ; enable for Atari 2600 specific code
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
2021-04-11 10:53:18 +00:00
|
|
|
|
; QR Code Generator Switches
|
2021-04-11 08:25:59 +00:00
|
|
|
|
QR_VERSION = 2 ; 1, 2 or 3 (TODO 1 and 3)
|
2021-04-11 19:07:28 +00:00
|
|
|
|
QR_LEVEL = 1 ; 0 (L), 1 (M), 2 (Q) and 3 (H))
|
2021-04-14 21:23:39 +00:00
|
|
|
|
QR_PADDING = 1 ; (+ 22 bytes) add padding bytes (optional)
|
|
|
|
|
QR_GENERATE = 0 ; (+~12 bytes) generates Reed-Solomon ECC generator polynomial on-the-fly
|
2021-04-12 14:33:25 +00:00
|
|
|
|
; else uses built-in table
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Atari 2600 specific QR settings (keep set to 0 for other platforms!)
|
|
|
|
|
IFCONST ATARI_2600
|
2021-04-12 08:50:03 +00:00
|
|
|
|
QR_OVERLAP = 1 ; overlaps input and output data to save RAM (defined for version 2 only!)
|
2021-04-12 14:33:25 +00:00
|
|
|
|
QR_SINGLE_MASK = 0 ; (-255 bytes) if 1 uses only 1 of the 8 mask pattern
|
2021-04-14 21:23:39 +00:00
|
|
|
|
QR_DIRECT_DRAW = 0 ; (+ 45 bytes) draw byte columns instead of individual pixel
|
|
|
|
|
ENDIF
|
|
|
|
|
|
|
|
|
|
IF QR_VERSION != 2
|
|
|
|
|
ECHO ""
|
|
|
|
|
ECHO "*** ERROR: Version", [QR_VERSION]d, "unsupported by demo code! ***"
|
|
|
|
|
ERR
|
|
|
|
|
ENDIF
|
2021-04-12 08:50:03 +00:00
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_SINGLE_MASK = 1 && QR_DIRECT_DRAW = 0
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ECHO ""
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ECHO "*** ERROR: Unsupported assembler switches combination! ***"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ERR
|
|
|
|
|
ENDIF
|
|
|
|
|
|
2021-04-11 15:15:10 +00:00
|
|
|
|
|
2021-04-11 10:53:18 +00:00
|
|
|
|
;===============================================================================
|
|
|
|
|
; C O N S T A N T S
|
|
|
|
|
;===============================================================================
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
NUM_FIRST = 1 ; left top 9 and bottom 8 bits are fixed!
|
|
|
|
|
RND_EOR_VAL = $b4
|
|
|
|
|
|
|
|
|
|
_QR_TOTAL SET 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;===============================================================================
|
|
|
|
|
; Z P - V A R I A B L E S
|
|
|
|
|
;===============================================================================
|
|
|
|
|
|
|
|
|
|
SEG.U variables
|
|
|
|
|
ORG $80
|
|
|
|
|
|
|
|
|
|
random .byte
|
|
|
|
|
|
|
|
|
|
;---------------------------------------
|
|
|
|
|
; QR code variables
|
|
|
|
|
; all byte counts based on version 2, level M QR code
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
tmpVars ds 6
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ELSE
|
|
|
|
|
tmpVars ds 9
|
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
msgIdx = tmpVars + 3
|
|
|
|
|
IF QR_SINGLE_MASK = 0
|
|
|
|
|
qrPattern .byte
|
|
|
|
|
ENDIF
|
|
|
|
|
;---------------------------------------
|
2021-04-11 10:53:18 +00:00
|
|
|
|
data ds QR_TOTAL ; 44 bytes
|
|
|
|
|
remainder = data ; (QR_DEGREE = 16 bytes)
|
|
|
|
|
msgData = data + QR_DEGREE ; (QR_MAX_DATA = 28 bytes)
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;- - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
; The QR code overlaps the data! It overwrites the data while being drawn.
|
|
|
|
|
IF QR_OVERLAP
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_DIRECT_DRAW
|
|
|
|
|
QR_NON_OVER = 6
|
|
|
|
|
ELSE
|
|
|
|
|
QR_NON_OVER = 8
|
|
|
|
|
ENDIF
|
|
|
|
|
qrCodeLst = data + QR_NON_OVER ; all but 6/8 bytes overlap (version 2 only!)
|
|
|
|
|
ds NUM_FIRST + QR_SIZE*3 - QR_TOTAL + QR_NON_OVER ; 38/40 bytes
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ELSE
|
2021-04-14 21:23:39 +00:00
|
|
|
|
qrCodeLst ds NUM_FIRST + QR_SIZE*3 ; 76 bytes
|
|
|
|
|
ENDIF ; /QR_OVERLAP
|
2021-04-11 08:25:59 +00:00
|
|
|
|
grp0LLst = qrCodeLst + QR_SIZE * 0
|
|
|
|
|
firstMsl = qrCodeLst + QR_SIZE * 1
|
|
|
|
|
grp1Lst = qrCodeLst + NUM_FIRST + QR_SIZE * 1
|
|
|
|
|
grp0RLst = qrCodeLst + NUM_FIRST + QR_SIZE * 2
|
2021-04-11 10:53:18 +00:00
|
|
|
|
CODE_LST_SIZE = . - qrCodeLst
|
2021-04-12 14:33:25 +00:00
|
|
|
|
IF QR_GENERATE
|
|
|
|
|
qrGenerator ds QR_DEGREE
|
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;---------------------------------------
|
|
|
|
|
; QR code total = 89/127 bytes
|
|
|
|
|
|
|
|
|
|
ECHO "RAM:", [$100 - .]d, "bytes free"
|
|
|
|
|
ECHO ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;===============================================================================
|
|
|
|
|
; M A C R O S
|
|
|
|
|
;===============================================================================
|
|
|
|
|
|
2021-04-11 09:50:25 +00:00
|
|
|
|
MAC BIT_B
|
|
|
|
|
.byte $24
|
|
|
|
|
ENDM
|
|
|
|
|
|
2021-04-11 08:25:59 +00:00
|
|
|
|
MAC BIT_W
|
|
|
|
|
.byte $2c
|
|
|
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
MAC SLEEP
|
|
|
|
|
IF {1} = 1
|
|
|
|
|
ECHO "ERROR: SLEEP 1 not allowed !"
|
|
|
|
|
END
|
|
|
|
|
ENDIF
|
|
|
|
|
IF {1} & 1
|
|
|
|
|
nop $00
|
|
|
|
|
REPEAT ({1}-3)/2
|
|
|
|
|
nop
|
|
|
|
|
REPEND
|
|
|
|
|
ELSE
|
|
|
|
|
REPEAT ({1})/2
|
|
|
|
|
nop
|
|
|
|
|
REPEND
|
|
|
|
|
ENDIF
|
|
|
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC NEXT_RANDOM
|
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
; update random value:
|
|
|
|
|
lda random ; 3
|
|
|
|
|
lsr ; 2
|
|
|
|
|
bcc .skipEOR ; 2/3
|
|
|
|
|
eor #RND_EOR_VAL ; 2
|
|
|
|
|
.skipEOR
|
|
|
|
|
sta random ; 3 = 14/19
|
|
|
|
|
ENDM
|
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Atari 2600 specific macros
|
2021-04-11 08:25:59 +00:00
|
|
|
|
IF QR_OVERLAP = 0
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC _BLACK_FUNC
|
|
|
|
|
;-----------------------------------------------------------
|
2021-04-12 08:50:03 +00:00
|
|
|
|
; blacks all function/alignment and timing pattern
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ldx #CODE_LST_SIZE
|
2021-04-11 08:25:59 +00:00
|
|
|
|
.loopBlack
|
2021-04-14 21:23:39 +00:00
|
|
|
|
lda BlackGfx-1,x
|
|
|
|
|
sta qrCodeLst-1,x
|
2021-04-11 08:25:59 +00:00
|
|
|
|
dex
|
2021-04-14 21:23:39 +00:00
|
|
|
|
bne .loopBlack
|
|
|
|
|
; X = 0!
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDM
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ELSE ; QR_OVERLAP
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC _BLACK_LEFT
|
|
|
|
|
;-----------------------------------------------------------
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Blacks all function/alignment and timing pattern areas of the left sprite column
|
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ldx #NUM_FIRST + QR_SIZE-1-8
|
|
|
|
|
.loopBlackLeft
|
|
|
|
|
lda LeftBlack+8,x
|
|
|
|
|
sta qrCodeLst+8,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlackLeft
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ELSE
|
|
|
|
|
; clear the bitmap column first...
|
|
|
|
|
ldx #NUM_FIRST + QR_SIZE-1-8
|
|
|
|
|
lda #0
|
|
|
|
|
.loopBlackLeft
|
|
|
|
|
sta qrCodeLst+8,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlackLeft
|
|
|
|
|
; ...then draw the pattern
|
|
|
|
|
IF QR_DIRECT_DRAW
|
|
|
|
|
ldy #1 ; left top pattern/vertical timing line
|
|
|
|
|
ELSE
|
|
|
|
|
ldy #2
|
|
|
|
|
ENDIF
|
|
|
|
|
.loopPattern
|
|
|
|
|
lda #$ff ; fill pattern
|
|
|
|
|
jsr DrawPattern
|
|
|
|
|
bpl .loopPattern
|
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC _BLACK_MIDDLE
|
|
|
|
|
;-----------------------------------------------------------
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Blacks all function/alignment and timing pattern areas of the middle sprite column
|
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ldx #QR_SIZE-1
|
|
|
|
|
.loopBlackMiddle
|
|
|
|
|
lda GRP1Black,x
|
|
|
|
|
sta grp1Lst,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlackMiddle
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ELSE
|
|
|
|
|
; clear the bitmap column first...
|
|
|
|
|
ldx #QR_SIZE-1
|
|
|
|
|
lda #0
|
|
|
|
|
.loopBlackMiddle
|
|
|
|
|
sta grp1Lst,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlackMiddle
|
|
|
|
|
; ...then draw the pattern
|
|
|
|
|
ldy #6 ; align pattern
|
|
|
|
|
.loopPattern
|
|
|
|
|
lda #$ff ; fill pattern
|
|
|
|
|
jsr DrawPattern
|
|
|
|
|
cpy #5
|
|
|
|
|
bcs .loopPattern
|
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC _BLACK_RIGHT
|
|
|
|
|
;-----------------------------------------------------------
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Blacks all function/alignment and timing pattern areas of the right sprite column
|
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ldx #QR_SIZE
|
|
|
|
|
.loopBlackRight
|
|
|
|
|
lda GRP0RBlack-1,x
|
|
|
|
|
sta grp0RLst-1,x
|
|
|
|
|
dex
|
|
|
|
|
bne .loopBlackRight
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ELSE
|
|
|
|
|
; clear the bitmap column first...
|
|
|
|
|
ldx #QR_SIZE-1
|
|
|
|
|
lda #$00
|
|
|
|
|
.loopBlackRight
|
|
|
|
|
sta grp0RLst,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlackRight
|
|
|
|
|
; ...then draw the pattern
|
|
|
|
|
ldy #4 ; right pattern
|
|
|
|
|
.loopPattern
|
|
|
|
|
lda #$ff ; fill pattern
|
|
|
|
|
jsr DrawPattern
|
|
|
|
|
cpy #3
|
|
|
|
|
bcs .loopPattern
|
|
|
|
|
ldx #0
|
|
|
|
|
ENDIF
|
|
|
|
|
; X = 0!
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDM
|
2021-04-14 21:23:39 +00:00
|
|
|
|
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDIF ; /QR_OVERLAP
|
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
|
MAC _DRAW_FUNC
|
|
|
|
|
;-----------------------------------------------------------
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; Draws all function/alignment and timing pattern over existing codewords
|
2021-04-11 10:53:18 +00:00
|
|
|
|
ldx #CODE_LST_SIZE-1
|
2021-04-11 08:25:59 +00:00
|
|
|
|
.loopBlack
|
|
|
|
|
lda qrCodeLst,x
|
|
|
|
|
ora BlackGfx,x
|
|
|
|
|
eor EorGfx,x
|
|
|
|
|
sta qrCodeLst,x
|
|
|
|
|
dex
|
|
|
|
|
bpl .loopBlack
|
2021-04-11 15:47:58 +00:00
|
|
|
|
|
|
|
|
|
IF QR_SINGLE_MASK && (QR_VERSION = 3 || QR_VERSION = 4)
|
|
|
|
|
; invert 1st pixel of 1st copy (bit 0 not set in formats Q and H)
|
|
|
|
|
ldy #0
|
|
|
|
|
ldx #QR_SIZE-9
|
|
|
|
|
jsr InvertPixel
|
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
ENDM
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;===============================================================================
|
|
|
|
|
; R O M - C O D E
|
|
|
|
|
;===============================================================================
|
|
|
|
|
SEG Bank0
|
|
|
|
|
ORG BASE_ADR
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
DrawScreen SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
ldx #227
|
|
|
|
|
.waitTim:
|
|
|
|
|
lda INTIM
|
|
|
|
|
bne .waitTim
|
|
|
|
|
sta WSYNC
|
|
|
|
|
sta VBLANK
|
|
|
|
|
stx TIM64T
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
ldx #3
|
|
|
|
|
bit SWCHB
|
|
|
|
|
bvs .skipCentering
|
|
|
|
|
; some vertical centering
|
|
|
|
|
ldx #(192-QR_SIZE*2)/2
|
|
|
|
|
.skipCentering
|
|
|
|
|
.waitTop
|
|
|
|
|
sta WSYNC
|
|
|
|
|
dex
|
|
|
|
|
bne .waitTop
|
|
|
|
|
|
|
|
|
|
ldx #QR_SIZE-1
|
|
|
|
|
lda #%1 ; 1st top left fixed pixel
|
|
|
|
|
bne .enterLoop
|
|
|
|
|
|
|
|
|
|
.tmpFirst = tmpVars
|
|
|
|
|
|
|
|
|
|
; the QR code kernel
|
2021-04-11 19:07:28 +00:00
|
|
|
|
.loopKernel ; @53
|
2021-04-11 08:25:59 +00:00
|
|
|
|
lda FirstIdxTbl,x ; 4*
|
2021-04-11 19:07:28 +00:00
|
|
|
|
cmp #1 ; 2
|
2021-04-11 15:38:58 +00:00
|
|
|
|
bcs .newFirst ; 2/3
|
2021-04-11 08:25:59 +00:00
|
|
|
|
lsr .tmpFirst ; 5
|
2021-04-11 19:07:28 +00:00
|
|
|
|
bpl .endFirst ; 3 = 16 unconditional
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
.newFirst ; @62
|
2021-04-11 15:38:58 +00:00
|
|
|
|
; $bf/$3f | $01 | $fe
|
|
|
|
|
bne .enterLoop ; 2/3
|
2021-04-11 08:25:59 +00:00
|
|
|
|
lda firstMsl ; 3
|
|
|
|
|
.enterLoop
|
2021-04-11 19:07:28 +00:00
|
|
|
|
sta .tmpFirst ; 3 = 8
|
|
|
|
|
.endFirst ; @70/69
|
2021-04-12 08:50:03 +00:00
|
|
|
|
ldy #-2 ; 2
|
2021-04-11 08:25:59 +00:00
|
|
|
|
.loopBlock
|
2021-04-11 19:07:28 +00:00
|
|
|
|
sta WSYNC ; 3 @75/74
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;---------------------------------------
|
|
|
|
|
;M1-P0-P1-P0
|
|
|
|
|
lda .tmpFirst ; 3
|
|
|
|
|
asl ; 2
|
|
|
|
|
sta ENAM1 ; 3 = 8
|
|
|
|
|
lda grp1Lst,x ; 4
|
|
|
|
|
sta GRP1 ; 3
|
|
|
|
|
lda grp0LLst,x ; 4
|
|
|
|
|
sta GRP0 ; 3
|
2021-04-12 08:50:03 +00:00
|
|
|
|
SLEEP 10 ;10 = 24
|
2021-04-11 08:25:59 +00:00
|
|
|
|
lda grp0RLst,x ; 4
|
2021-04-12 08:50:03 +00:00
|
|
|
|
iny ; 2
|
|
|
|
|
cpy #1 ; 2
|
|
|
|
|
bcc .isZero ; 2/3
|
2021-04-11 19:07:28 +00:00
|
|
|
|
BIT_B ; 1
|
2021-04-12 08:50:03 +00:00
|
|
|
|
.isZero
|
2021-04-11 08:25:59 +00:00
|
|
|
|
dex ; 2
|
2021-04-12 08:50:03 +00:00
|
|
|
|
sta GRP0 ; 3 = 16 @48
|
2021-04-11 19:07:28 +00:00
|
|
|
|
bcs .loopBlock ; 2/3
|
|
|
|
|
bpl .loopKernel ; 3/2=5/4
|
2021-04-11 08:25:59 +00:00
|
|
|
|
sta WSYNC
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
sty ENAM1
|
|
|
|
|
sty GRP1
|
|
|
|
|
sty GRP0
|
|
|
|
|
|
|
|
|
|
ldx #2
|
|
|
|
|
.waitScreen:
|
|
|
|
|
lda INTIM
|
|
|
|
|
bne .waitScreen
|
|
|
|
|
sta WSYNC
|
|
|
|
|
stx VBLANK
|
|
|
|
|
rts
|
|
|
|
|
; DrawScreen
|
|
|
|
|
|
2021-04-12 14:33:25 +00:00
|
|
|
|
include QRCodeGen.inc
|
|
|
|
|
|
2021-04-11 08:25:59 +00:00
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
Start SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
cld ; Clear BCD math bit.
|
|
|
|
|
lda #0
|
|
|
|
|
tax
|
|
|
|
|
dex
|
|
|
|
|
txs
|
|
|
|
|
.clearLoop:
|
|
|
|
|
tsx
|
|
|
|
|
pha
|
|
|
|
|
bne .clearLoop
|
|
|
|
|
|
|
|
|
|
lda INTIM
|
|
|
|
|
ora #$10
|
|
|
|
|
sta random
|
|
|
|
|
|
|
|
|
|
jsr InitDemo
|
|
|
|
|
|
|
|
|
|
.mainLoop:
|
|
|
|
|
jsr VerticalBlank
|
|
|
|
|
jsr DrawScreen
|
|
|
|
|
jsr OverScan
|
|
|
|
|
jmp .mainLoop
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
InitDemo SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
sta WSYNC
|
|
|
|
|
;---------------------------------------
|
|
|
|
|
lda #$0e
|
|
|
|
|
sta COLUBK
|
|
|
|
|
lda #$00
|
|
|
|
|
sta COLUP0
|
|
|
|
|
sta COLUP1
|
|
|
|
|
|
|
|
|
|
lda #%001
|
|
|
|
|
sta NUSIZ0
|
|
|
|
|
sta VDELP1
|
|
|
|
|
|
|
|
|
|
ldx #$3f
|
|
|
|
|
stx HMP0
|
|
|
|
|
inx
|
|
|
|
|
stx HMP1
|
|
|
|
|
lda #$a0
|
|
|
|
|
sta HMM1
|
|
|
|
|
|
|
|
|
|
SLEEP 3
|
|
|
|
|
|
|
|
|
|
sta RESM1
|
|
|
|
|
sta RESP0
|
|
|
|
|
sta RESP1
|
|
|
|
|
|
|
|
|
|
sta WSYNC
|
|
|
|
|
;---------------------------------------
|
|
|
|
|
sta HMOVE
|
|
|
|
|
|
|
|
|
|
jmp GenerateQR
|
|
|
|
|
; GameInit
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
VerticalBlank SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
lda #%00001110
|
|
|
|
|
.loopVSync:
|
|
|
|
|
sta WSYNC
|
|
|
|
|
sta VSYNC
|
|
|
|
|
lsr
|
|
|
|
|
bne .loopVSync
|
|
|
|
|
|
|
|
|
|
IF NTSC
|
|
|
|
|
lda #44
|
|
|
|
|
ELSE
|
|
|
|
|
lda #77
|
|
|
|
|
ENDIF
|
|
|
|
|
sta TIM64T
|
|
|
|
|
|
|
|
|
|
bit INPT4
|
|
|
|
|
bmi .skipRegen
|
|
|
|
|
|
|
|
|
|
jsr GenerateQR
|
|
|
|
|
.skipRegen
|
|
|
|
|
NEXT_RANDOM
|
|
|
|
|
rts
|
|
|
|
|
; VerticalBlank
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
OverScan SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
IF NTSC
|
|
|
|
|
lda #36
|
|
|
|
|
ELSE
|
|
|
|
|
lda #63
|
|
|
|
|
ENDIF
|
|
|
|
|
sta TIM64T
|
|
|
|
|
|
|
|
|
|
.waitTim:
|
|
|
|
|
lda INTIM
|
|
|
|
|
bne .waitTim
|
|
|
|
|
rts
|
|
|
|
|
; OverScan
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
GenerateQR SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
; *** Generate QR code from message ***
|
|
|
|
|
IF QR_SINGLE_MASK = 0
|
|
|
|
|
lda random
|
|
|
|
|
and #$07
|
|
|
|
|
; lda #0
|
|
|
|
|
sta qrPattern
|
|
|
|
|
ENDIF
|
|
|
|
|
|
|
|
|
|
MessageCode
|
|
|
|
|
; convert the message into a data stream
|
|
|
|
|
.msgLen = tmpVars
|
|
|
|
|
.msgPtr = tmpVars+1
|
|
|
|
|
lda random
|
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
and #$0f
|
|
|
|
|
tay
|
2021-04-14 21:23:39 +00:00
|
|
|
|
; ldy #3
|
2021-04-11 08:25:59 +00:00
|
|
|
|
lda MessagePtrLo,y
|
|
|
|
|
sta .msgPtr
|
|
|
|
|
lda MessagePtrHi,y
|
|
|
|
|
sta .msgPtr+1
|
|
|
|
|
lda MessagePtrLo+1,y
|
|
|
|
|
sec
|
|
|
|
|
sbc .msgPtr
|
|
|
|
|
sta .msgLen
|
|
|
|
|
START_MSG
|
|
|
|
|
ldy #0
|
|
|
|
|
.loopMsg
|
|
|
|
|
lda (.msgPtr),y
|
|
|
|
|
ADD_MSG_BYTE
|
|
|
|
|
iny
|
|
|
|
|
cpy .msgLen
|
|
|
|
|
bcc .loopMsg
|
|
|
|
|
STOP_MSG
|
|
|
|
|
|
|
|
|
|
ECHO "QR Code message code:", [. - MessageCode]d, "bytes"
|
|
|
|
|
_QR_TOTAL SET _QR_TOTAL + . - MessageCode
|
|
|
|
|
|
|
|
|
|
GEN_QR_CODE
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
BitMapCode
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
CheckPixel SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
2021-04-11 15:15:10 +00:00
|
|
|
|
; Platform and version specific code. Must NOT change X and Y registers!
|
2021-04-11 08:25:59 +00:00
|
|
|
|
; X = y; Y = x
|
|
|
|
|
; determine 8 bit column (0..2) or missile columns
|
|
|
|
|
tya
|
|
|
|
|
bne .notMissile
|
|
|
|
|
; check if single missile byte is affected
|
|
|
|
|
cpx #8
|
|
|
|
|
bcc .alwaysSet
|
|
|
|
|
cpx #8*2
|
|
|
|
|
bcs .alwaysSet
|
|
|
|
|
lda firstMsl
|
|
|
|
|
and BitMask-8,x
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.alwaysSet
|
|
|
|
|
lda #1
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notMissile
|
|
|
|
|
cpy #1+8
|
|
|
|
|
bcs .notGRP0L
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_OVERLAP & QR_DIRECT_DRAW
|
2021-04-11 08:25:59 +00:00
|
|
|
|
cpx #8 ; bottom left eye (partially) shared with data!
|
|
|
|
|
bcc .alwaysSet
|
|
|
|
|
ENDIF
|
|
|
|
|
lda grp0LLst,x
|
|
|
|
|
and BitMask-1,y
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notGRP0L
|
|
|
|
|
cpy #1+8*2
|
|
|
|
|
bcs .notGRP1
|
|
|
|
|
lda grp1Lst,x
|
|
|
|
|
and BitMask-1-8,y
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notGRP1
|
|
|
|
|
; must be GRP0R then
|
|
|
|
|
lda grp0RLst,x
|
|
|
|
|
and BitMask-1-8*2,y
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------
|
|
|
|
|
InvertPixel SUBROUTINE
|
|
|
|
|
;---------------------------------------------------------------
|
2021-04-11 15:15:10 +00:00
|
|
|
|
; Platform and version specific code. Must NOT change X and Y registers!
|
2021-04-11 08:25:59 +00:00
|
|
|
|
; X = y; Y = x
|
|
|
|
|
; determine 8 bit column (0..2) or missile column
|
|
|
|
|
tya
|
|
|
|
|
bne .notMissile
|
|
|
|
|
; check if single missile byte is affected
|
|
|
|
|
cpx #8
|
|
|
|
|
bcc .ignore
|
|
|
|
|
cpx #8*2
|
|
|
|
|
bcs .ignore
|
|
|
|
|
lda BitMask-8,x
|
|
|
|
|
eor firstMsl
|
|
|
|
|
sta firstMsl
|
|
|
|
|
.ignore
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notMissile
|
|
|
|
|
cpy #1+8
|
|
|
|
|
bcs .notGRP0L
|
|
|
|
|
lda grp0LLst,x
|
|
|
|
|
eor BitMask-1,y
|
|
|
|
|
sta grp0LLst,x
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notGRP0L
|
|
|
|
|
cpy #1+8*2
|
|
|
|
|
bcs .notGRP1
|
|
|
|
|
lda grp1Lst,x
|
|
|
|
|
eor BitMask-1-8,y
|
|
|
|
|
sta grp1Lst,x
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.notGRP1
|
|
|
|
|
; must be GRP0R then
|
|
|
|
|
lda grp0RLst,x
|
|
|
|
|
eor BitMask-1-8*2,y
|
|
|
|
|
sta grp0RLst,x
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
ECHO "QR Code bitmap code:", [. - BitMapCode]d, "bytes"
|
|
|
|
|
_QR_TOTAL SET _QR_TOTAL + . - BitMapCode
|
|
|
|
|
|
|
|
|
|
;===============================================================================
|
|
|
|
|
; R O M - T A B L E S (Bank 0)
|
|
|
|
|
;===============================================================================
|
|
|
|
|
org BASE_ADR + $600
|
|
|
|
|
|
|
|
|
|
FunctionModulesData
|
|
|
|
|
; Platform and version specific function module data definition
|
2021-04-11 15:15:10 +00:00
|
|
|
|
|
2021-04-14 21:23:39 +00:00
|
|
|
|
IF QR_DIRECT_DRAW
|
2021-04-11 15:15:10 +00:00
|
|
|
|
IF QR_VERSION = 1
|
|
|
|
|
ERR ; TODO
|
|
|
|
|
ENDIF
|
|
|
|
|
|
|
|
|
|
IF QR_VERSION = 2
|
|
|
|
|
IF QR_SINGLE_MASK
|
2021-04-14 21:23:39 +00:00
|
|
|
|
include FuncDataV2S.inc ; special pattern
|
2021-04-11 15:15:10 +00:00
|
|
|
|
ELSE
|
|
|
|
|
include FuncDataV2.inc
|
|
|
|
|
ENDIF
|
|
|
|
|
ENDIF
|
|
|
|
|
|
|
|
|
|
IF QR_VERSION = 3
|
|
|
|
|
ERR ; TODO
|
2021-04-14 21:23:39 +00:00
|
|
|
|
ENDIF
|
|
|
|
|
ENDIF
|
|
|
|
|
|
|
|
|
|
FirstIdxTbl ; for 25 pixel
|
|
|
|
|
ds 7, 0
|
|
|
|
|
.byte $fe
|
|
|
|
|
ds 7, 0
|
|
|
|
|
.byte $01
|
|
|
|
|
ds 7, 0
|
|
|
|
|
IF QR_LEVEL = 0 || QR_LEVEL = 1
|
|
|
|
|
.byte $bf ; 1st format bit is 1
|
|
|
|
|
ELSE
|
|
|
|
|
.byte $3f ; 1st format bit is 0
|
2021-04-11 15:15:10 +00:00
|
|
|
|
ENDIF
|
2021-04-11 08:25:59 +00:00
|
|
|
|
|
|
|
|
|
ECHO "QR Code function modules data:", [. - FunctionModulesData]d, "bytes"
|
|
|
|
|
_QR_TOTAL SET _QR_TOTAL + . - FunctionModulesData
|
|
|
|
|
|
|
|
|
|
QR_CODE_DATA
|
|
|
|
|
|
|
|
|
|
.byte " QR Code Generator Demo V0.3 - (C)2021 Thomas Jentzsch "
|
|
|
|
|
|
2021-04-12 08:50:03 +00:00
|
|
|
|
; messages MUST NOT be longer than 26 bytes for version 2, level M!
|
2021-04-11 08:25:59 +00:00
|
|
|
|
MessageTbl
|
|
|
|
|
Message0
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2002 - Thrust+ Platinum"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message1
|
2021-04-14 21:23:39 +00:00
|
|
|
|
.byte "2001 - Jammed"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message2
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2005 - SWOOPS!"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message3
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2017 - ZeroPage Homebrew"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message4
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2019 - Aardvark"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message5
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2012 - Boulder Dash"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message6
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2021 - VROOM!"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message7
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2020 - Robot City"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message8
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2015 - Star Castle Arcade"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message9
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2001 - AtariAge"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message10
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "1998 - Atari 2600 Nexus"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message11
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2009 - RAM Pong"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message12
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "1977 - Atari 2600"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message13
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "2014 - Three<65>s"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message14
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "1996 - Stella Mailing List"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
Message15
|
2021-04-11 15:15:10 +00:00
|
|
|
|
.byte "1996 - Stella Emulator"
|
2021-04-11 08:25:59 +00:00
|
|
|
|
MessageEnd
|
|
|
|
|
; .byte "..the single hardest thing"
|
|
|
|
|
|
|
|
|
|
MessagePtrLo
|
|
|
|
|
.byte <Message0, <Message1, <Message2, <Message3
|
|
|
|
|
.byte <Message4, <Message5, <Message6, <Message7
|
|
|
|
|
.byte <Message8, <Message9, <Message10, <Message11
|
|
|
|
|
.byte <Message12, <Message13, <Message14, <Message15
|
|
|
|
|
.byte <MessageEnd
|
|
|
|
|
MessagePtrHi
|
|
|
|
|
.byte >Message0, >Message1, >Message2, >Message3
|
|
|
|
|
.byte >Message4, >Message5, >Message6, >Message7
|
|
|
|
|
.byte >Message8, >Message9, >Message10, >Message11
|
|
|
|
|
.byte >Message12, >Message13, >Message14, >Message15
|
|
|
|
|
|
|
|
|
|
.byte "JTZ"
|
|
|
|
|
|
|
|
|
|
org BASE_ADR + $ffc
|
|
|
|
|
.word Start
|
|
|
|
|
.word Start
|
|
|
|
|
|
|
|
|
|
ECHO "----------------------------------------"
|
|
|
|
|
ECHO "QR Code total:", [_QR_TOTAL]d, "bytes"
|
|
|
|
|
ECHO ""
|
2021-04-12 08:50:03 +00:00
|
|
|
|
ECHO "QR Code Version", [QR_VERSION]d, ", Level (Degree)", [QR_LEVEL]d, "(", [QR_DEGREE]d, "), Capacity", [QR_CAPACITY]d, "bytes"
|
|
|
|
|
ECHO " -> Message Space", [QR_CAPACITY-QR_DEGREE-2]d, "bytes"
|