|
| 1 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 | +; Exercise 4 |
| 3 | +; In this exercise you will cycle the background color more slowly |
| 4 | +; and learn about variables |
| 5 | +; |
| 6 | +; Written for use with 8bitworkshop.com. |
| 7 | +; Code included there and "Making Games For The Atari 2600" |
| 8 | +; by Steven Hugg |
| 9 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 10 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 11 | +;;;; Header |
| 12 | +;;;; Needed at top of all your source files |
| 13 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 14 | + |
| 15 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 16 | + |
| 17 | + processor 6502 |
| 18 | + include "vcs.h" |
| 19 | + |
| 20 | +;;;;;;;;;;;;;;;;;; VARIABLE SEGMENT ;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 21 | + |
| 22 | + seg.u Variables |
| 23 | + org $80 |
| 24 | + |
| 25 | + ;;; INSERT YOUR VARIABLES BELOW THIS |
| 26 | +BackgroundColor .byte |
| 27 | +CycleSpeed .byte |
| 28 | + ;;; AND ABOVE THIS |
| 29 | + |
| 30 | +;;;;;;;;;;;;;;;;;; CODE SEGMENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 31 | + |
| 32 | + seg Code |
| 33 | + org $f000 |
| 34 | + |
| 35 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 36 | +;;;; GENERAL INIT |
| 37 | +;;;; This code is necessary for initialization |
| 38 | +;;;; but you can ignore it until you get curious |
| 39 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 40 | + |
| 41 | +Start sei |
| 42 | + cld |
| 43 | + ldx #$ff |
| 44 | + txs |
| 45 | + lda #0 ; |
| 46 | + ldx #$ff |
| 47 | +ZeroZP sta $0,X |
| 48 | + dex |
| 49 | + bne ZeroZP |
| 50 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 51 | + |
| 52 | + ;;; INITIALIZE YOUR VARIABLES BELOW THIS |
| 53 | + LDA #10 |
| 54 | + STA CycleSpeed |
| 55 | + TAY |
| 56 | + LDA #40 |
| 57 | + STA BackgroundColor |
| 58 | + ;;; AND ABOVE THIS |
| 59 | + |
| 60 | + |
| 61 | +NextFrame |
| 62 | + ; next two lines turn off beam |
| 63 | + lda #2 |
| 64 | + sta VBLANK |
| 65 | + ; now three lines of vsync per spec |
| 66 | + sta VSYNC |
| 67 | + sta WSYNC |
| 68 | + sta WSYNC |
| 69 | + sta WSYNC |
| 70 | + |
| 71 | + ; turn off vsync |
| 72 | + lda #0 |
| 73 | + sta VSYNC |
| 74 | + |
| 75 | + ; now loop through 36 vertical blank lines |
| 76 | + ldx #36 |
| 77 | +VBlankLoop |
| 78 | + sta WSYNC |
| 79 | + dex |
| 80 | + bne VBlankLoop |
| 81 | + |
| 82 | + ; we will use our final vblank line to setup |
| 83 | + ; any drawing |
| 84 | + ;;; INSERT YOUR CODE BELOW THIS |
| 85 | + DEY |
| 86 | + BNE SkipDecrementColor |
| 87 | + LDY BackgroundColor |
| 88 | + DEY |
| 89 | + STY BackgroundColor |
| 90 | + LDY CycleSpeed |
| 91 | +SkipDecrementColor |
| 92 | + LDA BackgroundColor |
| 93 | + STA COLUBK |
| 94 | + ;;; AND ABOVE THIS |
| 95 | + sta WSYNC |
| 96 | + |
| 97 | + ; now turn beam back on and draw 192 lines |
| 98 | + lda #0 |
| 99 | + sta VBLANK |
| 100 | + ldx #192 |
| 101 | +ScanLoop |
| 102 | + sta WSYNC |
| 103 | + dex |
| 104 | + bne ScanLoop |
| 105 | + |
| 106 | + ; now draw 30 lines of overscan after |
| 107 | + ; turning beam off again |
| 108 | + lda #2 |
| 109 | + sta VBLANK |
| 110 | + ldx #30 |
| 111 | +OverscanLoop |
| 112 | + sta WSYNC |
| 113 | + dex |
| 114 | + bne OverscanLoop |
| 115 | + |
| 116 | + ;;; Now we've drawn our |
| 117 | + ;;; 3 VSYNC lines |
| 118 | + ;;; 37 VBLANK lines |
| 119 | + ;;; 192 scan lines |
| 120 | + ;;; 30 overscan lines |
| 121 | + |
| 122 | + jmp NextFrame |
| 123 | + |
| 124 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 125 | +;;;; Footer |
| 126 | +;;;; Needed at bottom of all your source files |
| 127 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 128 | + org $fffc |
| 129 | + .word Start |
| 130 | + .word Start |
0 commit comments