Advertisement
peterberendi

C64 christmas star 33 lines

Dec 25th, 2022
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :BasicUpstart2(start)
  2. .const  column    = $a4
  3. .const  diagonal  = $a5
  4. .const  toprow    = $a6
  5. .const  bottomrow = $a8
  6. start:
  7.     jsr $e544    // clear screen
  8.     sei          // before messing up the keyboard buffer
  9.     ldx #(init_end-init_a5)
  10. D7:              // initialize zeropage pointers
  11.     lda init_a5-1,x
  12.     sta diagonal-1,x
  13.     dex
  14.     bne D7
  15. D8:              // loop over rows
  16.     lda #0
  17.     sta column
  18. D0:              // loop over columns
  19.     ldy column
  20.     ldx #$20     // space
  21.     cpy #8
  22.     bcc D1
  23.     cpy diagonal
  24.     bcs D1
  25.     ldx #$2a
  26. D1:
  27.     lda diagonal
  28.     cmp #17
  29.     bcc D2
  30.     tya
  31.     adc #16      // carry == 1 bc bcc above
  32.     cmp diagonal
  33.     bcc D2
  34.     ldx #$2a     // '*'
  35. D2:
  36.     txa
  37.     sta (toprow),y
  38.     sta (bottomrow),y
  39.     lda #32
  40.     sec
  41.     sbc column   // mirroring, a = 32 - column
  42.     tay
  43.     txa
  44.     sta (toprow),y
  45.     sta (bottomrow),y
  46.     inc column
  47.     cpy #16
  48.     bne D0
  49.     lda toprow   // top row pointer += 40
  50.     adc #39      // c == 1 bc y>=$10 in cpy above
  51.     sta toprow
  52.     lda toprow+1
  53.     adc #0       // carry from low byte adc
  54.     sta toprow+1
  55.     lda bottomrow      // bottom row pointer -= 40
  56.     sbc #39      // c == 0 bc adc above never overflows
  57.     sta bottomrow
  58.     lda bottomrow+1
  59.     sbc #0       // carry from low byte sbc
  60.     sta bottomrow+1
  61.     inc diagonal
  62.     lda diagonal
  63.     cmp #26      // diagonal reached the center
  64.     bne D8
  65.  
  66.     ldy #0
  67.     tya
  68. C0:              // clear sprites
  69.     sta spr0bmp,y
  70.     sta spr0bmp+$100,y
  71.     iny
  72.     bne C0
  73.  
  74.     //ldy #0 unnecessary
  75. C1:              // loop over character shape
  76.     lda asterisk,y
  77.     ldx #(init_end-init_spriteptr)
  78. C2:              // loop over pointers into sprites
  79.     sta ($a8,x)  // copy to sprites
  80.     inc $a8,x    // add 3 for next sprite row
  81.     inc $a8,x
  82.     inc $a8,x
  83.     dex          // next pointer
  84.     dex
  85.     bne C2
  86.     iny
  87.     cpy #5
  88.     bne C1
  89.  
  90.     lda #spr0bmp>>6     // sprites 1 and 6 are always at $2c00
  91.     sta $07f9
  92.     sta $07fe
  93.  
  94.     lda #14      // sprite color
  95.     ldx #8
  96. C8:
  97.     sta $d026,x
  98.     dex
  99.     bne C8
  100.     lda #$7e     // enable sprites 1 through 6
  101.     sta $d015
  102.  
  103. M0:
  104.     lda #240
  105. M1:              // wait for scanline
  106.     cmp $d012
  107.     bne M1
  108.  
  109.     ldx #spr3bmp>>6     // bottom left, sprites 2 and 3 at $2cc0
  110.     ldy #0
  111.     jsr setsprites
  112.     lda #249
  113. L2:              // wait for scanline
  114.     cmp $d012
  115.     bne L2
  116.     lda #$13     // clear RSEL
  117.     sta $d011
  118.  
  119.     //lda #24    // we want scanline 280 (below the sprites), just ignoring the high bit
  120.     lda #$1B     // 283 will do, and it can be reused to set RSEL
  121. K0:              // wait for scanline
  122.     cmp $d012
  123.     bne K0
  124.  
  125.     sta $d011    // set RSEL
  126.  
  127.     ldx #spr1bmp>>6     // top left, sprites 2 and 3 at $2c40
  128.     ldy #8
  129.     jsr setsprites
  130.     beq M0       // z == 1 bc bne before rts in setsprites:
  131.  
  132. setsprites:
  133.     stx $07fa    // pointers for sprites 2 and 3
  134.     stx $07fb
  135.     inx          // pointers for sprites 4 and 5 follow
  136.     stx $07fc
  137.     stx $07fd
  138.     ldx #pos_top-pos_bottom
  139. S1:
  140.     txa
  141.     and #1       // attempt to exclude x coordinates from the addition
  142.     bne S2       // a == 1, x gets incremented by 1 when branch is taken
  143.     tya          // otherwise by y
  144. S2:
  145.     clc
  146.     adc pos_bottom-1,x
  147.     bcc S3
  148.     adc #31      // c == 1, increment by 32 when overflowed
  149. S3:
  150.     sta $d001,x
  151.     dex
  152.     bne S1
  153.     rts
  154. pos_bottom:
  155.     .byte 111,251, 127,251, 111,11, 231,11, 215,251, 231,251
  156.     //.byte 112,250, 128,250, 112,10, 232,10, 216,250, 232,250
  157. pos_top:
  158.     //.byte 112,34,  128,34,  112,18, 232,18, 216,34,  232,34
  159. init_a5:
  160.     .byte 13     // diagonal
  161.     .word $0403  // top row start
  162.     .word $07c3  // bottom row start
  163. init_spriteptr:
  164. .label  spr0bmp = $2c00
  165. .label  spr1bmp = spr0bmp+$40
  166. .label  spr2bmp = spr1bmp+$40
  167. .label  spr3bmp = spr2bmp+$40
  168. .label  spr4bmp = spr3bmp+$40
  169.  
  170.     .word $2c00,$2c01,$2c18,$2c19
  171.     .word $2c40,$2c58,$2c59
  172.     .word $2c81,$2c98,$2c99
  173.     .word $2cc0,$2cc1,$2cd8
  174.     .word $2d00,$2d01,$2d19
  175. init_end:
  176. asterisk:
  177.     .byte $66, $3c, $ff, $3c, $66
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement