Created
December 13, 2020 23:03
-
-
Save classilla/871b49c8029f8d090e02bc0d545cae6d to your computer and use it in GitHub Desktop.
Full anaglyph sprite demo for the C64 (assemble with xa65, LOAD and RUN). https://oldvcr.blogspot.com/2020/12/stereoscopic-computing-anaglyph-sprites.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; anaglyph sprite demo for the c64 | |
; cameron kaiser 2020 | |
; public domain | |
SPRITE = $0340 | |
VALUE = $14 | |
HVALUE = $fe | |
MODE = $15 | |
.word $0801 | |
* = $0801 | |
; basic loader | |
.word $080b | |
.word $fce2 | |
.byte $9e, $32, $30, $36, $31 | |
.byte $00, $00, $00 | |
; entry | |
; reset screen, draw crosshatch | |
lda #0 | |
sta VALUE | |
sta MODE | |
sta 53280 | |
sta 53281 | |
sta 53264 | |
sta 53269 | |
tax | |
lda #11 | |
lupc sta $d800,x | |
sta $d900,x | |
sta $da00,x | |
sta $db00,x | |
lda #91 | |
sta $0400,x | |
sta $0500,x | |
sta $0600,x | |
sta $0700,x | |
inx | |
bne lupc | |
; set sprite colours and enlargement | |
; sprite 0 is left (cyan) eye | |
; sprite 1 is right (red) eye | |
lda #6 | |
sta 53287 | |
lda #2 | |
sta 53288 | |
lda #3 | |
sta 53269 | |
sta 53271 | |
sta 53277 | |
lda #13 | |
sta 2040 | |
sta 2041 | |
; position sprites | |
mlup lda VALUE | |
clc | |
lsr | |
sta HVALUE | |
; using the red-rear-right rule, slide the sprite positions | |
; mostly done by eye | |
lda #150 | |
sec | |
sbc HVALUE | |
sta 53250 | |
lda #110 | |
sbc VALUE | |
sta 53251 | |
lda #108 | |
sbc VALUE | |
sta 53249 | |
clc | |
lda HVALUE | |
adc #140 | |
sta 53248 | |
; prepare to draw scaled interlaced sprite | |
lda #0 | |
sta SPRITE | |
sta SPRITE+1 | |
sta SPRITE+2 | |
; determine if sprites should be in front or behind crosshatch | |
lda VALUE | |
ldx #3 | |
cmp #10 | |
bcc *+4 | |
ldx #0 | |
stx 53275 | |
; use current value to draw scaled interlaced sprite | |
tax | |
beq lup3 ; value was 0, clear sprite | |
; turn x into x 1-bits | |
lup1 sec | |
ror SPRITE | |
ror SPRITE+1 | |
ror SPRITE+2 | |
dex | |
bne lup1 | |
; copy the right number of lines, skipping every other | |
; x register is conveniently already 0, accumulator has value of VALUE | |
; if 1x1, no copies (already handled). | |
; if 2x2, no copies. | |
; if 3x3, one copy. | |
; if 4x4, one copy. | |
; if 5x5, two copies. | |
; if 6x6, two copies. etc. | |
sbc #0 ; carry is already clear from the above, so -1 | |
lsr | |
beq clrs ; no copies, clear the remainder of the sprite | |
tay | |
clc | |
lup2 lda SPRITE | |
sta SPRITE+6,x | |
lda SPRITE+1 | |
sta SPRITE+7,x | |
lda SPRITE+2 | |
sta SPRITE+8,x | |
txa | |
adc #6 | |
tax | |
dey | |
bne lup2 | |
clrs lda #0 | |
lup3 sta SPRITE+6,x | |
inx | |
cpx #58 | |
bcc lup3 | |
; wait a couple jiffies between frames | |
lda #0 | |
sta $a2 | |
waitt lda $a2 | |
cmp #2 | |
bcc waitt | |
; stop if run/stop is pressed | |
lda 203 | |
cmp #63 | |
bne cycle | |
lda #0 | |
sta 53269 | |
lda #147 | |
jmp $ffd2 | |
; else cycle the position and loop | |
cycle lda MODE | |
bne decr | |
incr inc VALUE | |
lda VALUE | |
cmp #21 | |
beq *+5 | |
jmp mlup | |
sta MODE ; fall through | |
decr dec VALUE | |
lda VALUE | |
cmp #$ff | |
beq *+5 | |
jmp mlup | |
lda #0 | |
sta VALUE | |
sta MODE | |
jmp mlup | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment