Something went wrong. Try again.
This repo contains stub files for use in a talk on Atari 2600 development at the Buffalo Game Space.
Something went wrong. Try again.
6.3 kB 307 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Exercise 12; In this exercise you will add horizontal positioning;; Written for use with 8bitworkshop.com. ; Code included there and "Making Games For The Atari 2600"; by Steven Hugg;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Header;;;; Needed at top of all your source files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
processor 6502 include "vcs.h"
;;;;;;;;;;;;;;;;;; VARIABLE SEGMENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;
seg.u Variables org $80
;;; INSERT YOUR VARIABLES BELOW THIS PlayerYPos .bytePlayerXPos .byte ;;; AND ABOVE THIS
;;;;;;;;;;;;;;;;;; CODE SEGMENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
seg Code org $f000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; GENERAL INIT;;;; This code is necessary for initialization ;;;; but you can ignore it until you get curious;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Start sei cld ldx #$ff txs lda #0 ; ldx #$ffZeroZP sta $0,X dex bne ZeroZP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; INITIALIZE YOUR VARIABLES BELOW THIS lda #80 sta PlayerYPos lda #71 sta PlayerXPos ;;; AND ABOVE THIS
NextFrame ; next two lines turn off beam lda #2 sta VBLANK ; now three lines of vsync per spec sta VSYNC sta WSYNC sta WSYNC sta WSYNC ; turn off vsync lda #0 sta VSYNC ; now loop through 31 vertical blank lines ldx #31VBlankLoop sta WSYNC dex bne VBlankLoop
;;; REPLACE BETWEEN CODE HERE ldx #8HorizPositionLoop dex bne HorizPositionLoop sta RESP0
sta WSYNC ;;; AND HERE ; we will use our final two vblank line to setup ; any drawing lda #$ff sta PF0 sta PF1 sta PF2 lda #$80 sta COLUPF sta WSYNC
;;; now turn beam back on and draw 192 lines lda #0 sta VBLANK ;;; Draw 10 lines ldx #10ScanLoopTop sta WSYNC dex bne ScanLoopTop ;; Setup to draw the sidebar playfield (reflected) lda #$01 sta CTRLPF lda #$10 sta PF0 lda #0 sta PF1 sta PF2 ;; Skip until player top ldx PlayerYPosScanLoopMiddleTop sta WSYNC dex bne ScanLoopMiddleTop lda #$32 sta COLUP0
;;; Draw 8 lines ldx #8ScanLoopDrawSprite sta WSYNC lda ButtonsFrame0,x sta GRP0 lda ButtonsColorFrame0,x sta COLUP0 dex bne ScanLoopDrawSprite sta WSYNC lda #0 sta GRP0 ;;; Calculate and draw remaining lines lda #192 sbc #10 ; top sbc #10 ; bottom sbc #8 ; sprite sbc PlayerYPos taxScanLoopMiddleBottom sta WSYNC dex bne ScanLoopMiddleBottom ;; Now draw PF for the last 10 lines lda #$ff sta PF0 sta PF1 sta PF2 lda #$80 sta COLUPF ;;; Draw another 10 lines ldx #10ScanLoopBottom sta WSYNC dex bne ScanLoopBottom ; now draw 29 lines of overscan after ; turning beam off again lda #2 sta VBLANK ldx #29OverscanLoop sta WSYNC dex bne OverscanLoop
; Use a vblank line to check for bounds ;;; Up/down lda PlayerYPos cmp #2 bcs .TopBoundsCheck ldx #2 jmp .SkipMoveUp.TopBoundsCheck lda PlayerYPos cmp #162 bcc .JoystickCheck ldx #161 jmp .SkipMoveUp ;;; AND ABOVE HERE.JoystickCheck ldx PlayerYPos lda #$10 bit SWCHA bne .SkipMoveDown dex.SkipMoveDown lda #$20 bit SWCHA bne .SkipMoveUp inx.SkipMoveUp stx PlayerYPos sta WSYNC clc ;;; Left/right ;;; INSERT CODE BELOW HERE ;;; AND ABOVE HERE ;;; Sound check bit INPT4 bmi .ButtonNotPressed lda #5 sta AUDV0 lda #13 sta AUDC0 lda PlayerYPos lsr lsr lsr sta AUDF0 jmp .ButtonPressedDone.ButtonNotPressed lda #0 sta AUDV0.ButtonPressedDone sta WSYNC
;;; Now we've drawn our ;;; 3 VSYNC lines ;;; 37 VBLANK lines ;;; 192 scan lines ;;; 30 overscan lines
jmp NextFrame ;; Fine horizontal positioning;; From Making Games for the Atari 2600;; Note it will call WSYNC to start;; A should have desired X coord;; X is (0) player 0 (1) player 1 (2) missile 0;; (3) missile 1 (4) ballSetHorizPos subroutine sta WSYNC sec.DivideLoop sbc #15 bcs .DivideLoop ; loop until we go <0 eor #7 asl asl asl asl sta HMP0,x ; set fine offset sta RESP0,x ; set coarse rts ;---Graphics Data from PlayerPal 2600---
ButtonsFrame0 .byte #%00000000;$30 .byte #%00011000;$30 .byte #%00011000;$30 .byte #%00000000;$74 .byte #%01100110;$74 .byte #%01100110;$74 .byte #%00000000;$74 .byte #%00011000;$B4 .byte #%00011000;$B4;---End Graphics Data---
;---Color Data from PlayerPal 2600---
ButtonsColorFrame0 .byte #0 .byte #$30; .byte #$30; .byte #$74; .byte #$74; .byte #$74; .byte #$74; .byte #$B4; .byte #$B4;;---End Color Data---
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Footer;;;; Needed at bottom of all your source files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org $fffc .word Start .word Start