;Assemble It - Tutorial ;Goldfish Demo ;---------------------- ;Producing a demo which uses a 1x2 ;scrolltext using sources like a ;split up bitmap picture, colour ;rolling and also play music message = $5000 ;Position of scroll text message xpos = $05 ;Smooth scroll timer fishpos = $0370 ;Position of where to place the sprites !to "goldfishdemo.prg",cbm *=$0800 ;Import charset data here !bin "bin\1x2charset.prg",,2 ;Insert music data file. *=$1000 ;Import music !binary "bin\music.prg",,2 *=$1f80 ;Import sprites !binary "bin\sprites.prg",,2 ;Insert picture (colour RAM, video RAM and Bitmap) ;Picture is split up into separate parts (You can easily ;grab a KOALAPAINT picture and split each data separately :) ;if you need to. ;$2000-$3f40 - Bitmap ;$4000-$43e8 - Colour RAM ;$4400-$47e8 - Video RAM *=$2000 !binary "bin\pic.goldfish.prg",,2 ;The main code for the demo. *= $4800 start sei lda #$00 sta $d020 lda #$07 sta $d021 ;Prepare sprites lda #$ff ;turn 'em on sta $d015 ;no. of sprites = 8 sta $d01c ;multicolour lda #$00 ;disable expanded sta $d017 ;sprites sta $d01d ; lda #$fe ; sta $07f8 ; sta $07fa ; sta $07fc ; sta $07fe ; lda #$ff ; sta $07f9 ; sta $07fb ; sta $07fd ; sta $07ff ; lda #$0d sta $d025 ;multicolour mode1 lda #$0b sta $d026 ;multicolour mode2 lda #$05 sta $d027 ;the main colour for sta $d028 ;the sprites. sta $d029 ; sta $d02a ; sta $d02b ; sta $d02c ; sta $d02d ; sta $d02e ; ;Call a loop to set start position for ;all fish accordingly to the table ldx #$00 posloop lda pos+$00,x sta fishpos+$00,x inx cpx #$10 bne posloop ;The first thing which we are going ;to do is fill the screen with the ;data for the video RAM and the ;colour RAM of the bitmap picture ldx #$00 copydat lda $4000,x ;This part here sta $0400,x ;reads all data lda $4100,x ;from $4000 and sta $0500,x ;pastes all the lda $4200,x ;data to the sta $0600,x ;SCREEN in bank lda $42e8,x ;3 sta $06e8,x lda $4400,x ;This part reads sta $d800,x ;all the data lda $4500,x ;from $4400 and sta $d900,x ;then pastes all lda $4600,x ;data into the sta $da00,x ;COLOUR RAM lda $46e8,x sta $dae8,x inx ;Count 256 times bne copydat ;else loop ;Clear bottom bit so you get no mess ;when you start a scrolltext ldx #$00 blank lda #$20 sta $0798,x inx cpx #$50 bne blank ;Initialise the scrolltext lda #message sta read+2 ;Prepare and initialise the IRQ raster ;interrupt lda #int sta $0315 lda #$00 sta $d012 ;init rasterline lda #$7f sta $dc0d lda #$01 sta $d019 sta $d01a ;Initialise the music at $1000 lda #$00 tax tay jsr $1000 cli ;clear irq flag hold jmp hold ;Now play and run the IRQ raster ;interrupt to get some effects. int lda $d019 and #$01 sta $d019 bne irq jmp $ea81 ;The main IRQ loops to call our ;routines to slide the scroll, display ;the bitmap, move sprites and also ;properly play the music. irq lda #$00 sta $d012 jsr movefish jsr scrolltext jsr splits jsr $1003 jmp $ea7e ;The usual routine for calling a ;scrolltext. ;You should already know this bit from ;the intro coding chapter scrolltext lda xpos sec sbc #$02 ;Scroll speed and #$07 sta xpos bcs endscr ldx #$00 wrap lda $0799,x sta $0798,x lda $07c1,x sta $07c0,x inx cpx #$28 bne wrap read lda $07bf cmp #$00 bne setpt lda #message sta read+2 jmp read setpt sta $07bf clc adc #$80 sta $07e7 inc read+1 lda read+1 cmp #$00 bne endscr inc read+2 endscr rts ;Now we do the raster splits for the ;demo. splits lda #$e6 ;bottom of screen cmp $d012 ;raster split for bne *-5 ;the colour rolling ldy #$0c ;scrolltext. dey bne *-4 lda #$1b ;char mode sta $d011 ; lda #$12 ; sta $d018 ;char at $0800-$1000 lda xpos ;smooth scroll sta $d016 ;is set ldx #$00 loop1 ldy timing,x ;a special loop2 dey ;routine that bne loop2 ;makes those nice lda colours,x ;multicolour bars sta $d021 inx cpx #$10 bne loop1 lda #$fd ;our second split cmp $d012 ; bne *-5 lda #$3b ;bitmap mode sta $d011 lda #$18 ;charset for the sta $d018 ;bitmap and turn sta $d016 ;on screen multic lda #$07 ;yellow bckground sta $d021 ;(fish pic's eye) ;roll those colourdatas so we can have a ;cool colour scroll. colroll lda colours+$00 ;you should sta colours+$0f ;already know ldx #$00 ;this section. rolloop lda colours+$01,x;its a loop sta colours+$00,x;that will inx ;scroll data cpx #$0f ;tables. bne rolloop ; rts ; ;move those sprites and expand the ;sprite position movefish lda fishpos+$00 ;you should be clc ;familiar with adc #$01 ;this thing sta fishpos+$00 ;hopefully lda fishpos+$02 ; sec ;subtract 1 sbc #$01 ;to speed sta fishpos+$02 lda fishpos+$04 clc ;add 2 adc #$02 ;to speed sta fishpos+$04 lda fishpos+$06 sec sbc #$02 ;subtract 2 sta fishpos+$06 ;to speed lda fishpos+$08 clc adc #$03 ;add 3 to speed sta fishpos+$08 lda fishpos+$0a sec ;subtract 3 to sbc #$03 ;speed sta fishpos+$0a lda fishpos+$0c clc adc #$02 sta fishpos+$0c lda fishpos+$0e sec sbc #$02 sta fishpos+$0e ;expand the positioning of the sprites ;so that they can move more than 256 ;pixels. ldx #$00 ; take a look exppos lda fishpos+$01,x ; at the sta $d001,x ; missile lda fishpos+$00,x ; blasta code asl a ; to really ror $d010 ; understand sta $d000,x ; what this inx ; routine inx ; does cpx #$10 ; bne exppos ; rts ; ;data tables for the colour scroll and ;timing of the colourscroll ;DASM users, use dc.b, ACME use !BYTE colours !byte $06,$0e,$03,$01 !byte $03,$0e,$06,$00 !byte $02,$0a,$07,$01 !byte $07,$0a,$02,$00 timing !byte $0c,$0c,$0c,$0c !byte $0c,$0c,$0c,$0c !byte $0c,$0c,$0c,$0c !byte $0c,$0c,$0c,$0c fishpd !byte $01,$02,$03,$02 !byte $ff,$fe,$ff,$fd pos !byte $00,$40,$00,$50 !byte $00,$60,$00,$70 !byte $00,$80,$00,$90 !byte $00,$a0,$00,$b0 ;Now insert the scroll text *=$5000 !binary "bin\scrolltext.prg",,2 ;Alternatively - if you want to write your message, ;remove !binary "bin\scrolltext.prg "and then add ;!ct scr ;!text " ... message ... " ;!byte 0 ;END!