Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; hello.asm
- ;
- ; Um "Hello, World!" feito para ilustrar a minha palestra sobre programação
- ; para Atari 2600 (slides em http://slideshare.net/chesterbr).
- ;
- ; O código é livre (vide final do arquivo). Para compilar use o DASM
- ; (http://dasm-dillon.sourceforge.net/), através do comando:
- ;
- ; dasm hello.asm -ohello.bin -f3
- ;
- PROCESSOR 6502
- INCLUDE "vcs.h"
- ORG $F000 ; Início do cartucho (vide Mapa de Memória do Atari)
- InicioFrame:
- lda #%00000010 ; VSYNC inicia setando o bit 1 deste endereço
- sta VSYNC
- REPEAT 3 ; ...e dura 3 scanlines (WSYNC=fim da scanline)
- sta WSYNC
- REPEND
- lda #0
- sta VSYNC ; VSYNC finaliza limpando o bit 1
- PreparaPlayfield: ; Vamos usar o início do VBLANK para ajustar cores
- lda #$00
- sta ENABL ; Desliga a ball, os missiles e os players
- sta ENAM0
- sta ENAM1
- sta GRP0
- sta GRP1
- sta COLUBK ; Cor de fundo (preto)
- sta PF0 ; PF0 e PF2 ficam apagados (so usaremos o PF1)...
- sta PF2
- lda #$FF ; Cor do playfield (possivelmente amarelo)
- sta COLUPF
- lda #$00 ; Reset no bit 0 do CTRLPF (para duplicar e nao repetir)
- sta CTRLPF
- ldx #0 ; X é o nosso contador de scanlines (0-191)
- REPEAT 37 ; Aguarda o final da primeira linha, e das outras 36
- sta WSYNC ;
- REPEND
- lda #0 ; Finaliza o VBLANK, "ligando o canhão"
- sta VBLANK
- Scanline:
- cpx #174 ; "HELLO WORLD" = (11 chars x 8 linhas - 1) x 2 scanlines =
- bcs FimScanline ; 174 (0 a 173). Passou disso, pula o desenho
- txa ; Queremos 2 scanlines para cada linha da frase, então
- lsr ; vamos fazer Y = X / 2. Para dividir por 2 usamos o
- tay ; shift lógico (que só opera no A)
- lda Frase,y ; "Frase,Y" = "Frase+Y" (Y-ésima linha da frase)
- sta PF1 ; Coloca ela nos bits 5 a 11 do playfield
- FimScanline:
- sta WSYNC ; Aguarda o final do scanline
- inx ; Incrementa o contador e repete até completar a tela
- cpx #191
- bne Scanline
- Overscan:
- lda #%01000010 ; "Desliga o canhão:"
- sta VBLANK ;
- REPEAT 30 ; 30 scanlines de overscan...
- sta WSYNC
- REPEND
- jmp InicioFrame ; ...e começamos tudo de novo!
- Frase:
- .BYTE %00000000 ; H
- .BYTE %01000010
- .BYTE %01111110
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %00000000
- .BYTE %00000000 ; E
- .BYTE %01111110
- .BYTE %01000000
- .BYTE %01111100
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01111110
- .BYTE %00000000
- .BYTE %00000000 ; L
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01111110
- .BYTE %00000000
- .BYTE %00000000 ; L
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01111110
- .BYTE %00000000 ; O
- .BYTE %00000000
- .BYTE %00111100
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %00111100
- .BYTE %00000000
- .BYTE %00000000 ; espaço em branco
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000
- .BYTE %00000000 ; W
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01011010
- .BYTE %00100100
- .BYTE %00000000
- .BYTE %00000000 ; O
- .BYTE %00111100
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %00111100
- .BYTE %00000000
- .BYTE %00000000 ; R
- .BYTE %01111100
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01111100
- .BYTE %01000100
- .BYTE %01000010
- .BYTE %00000000
- .BYTE %00000000 ; L
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01000000
- .BYTE %01111110
- .BYTE %00000000
- .BYTE %00000000 ; D
- .BYTE %01111000
- .BYTE %01000100
- .BYTE %01000010
- .BYTE %01000010
- .BYTE %01000100
- .BYTE %01111000
- .BYTE %00000000 ; Último byte escrito no PF1 (importante, mantém o resto da tela "limpa")
- ORG $FFFA ; Configurações que ficam no finalzinho do cartucho:
- .WORD InicioFrame ; NMI
- .WORD InicioFrame ; RESET
- .WORD InicioFrame ; IRQ
- END
- ;
- ; Copyright 2011 Carlos Duarte do Nascimento (Chester). All rights reserved.
- ;
- ; Redistribution and use in source and binary forms, with or without modification, are
- ; permitted provided that the following conditions are met:
- ;
- ; 1. Redistributions of source code must retain the above copyright notice, this list of
- ; conditions and the following disclaimer.
- ;
- ; 2. Redistributions in binary form must reproduce the above copyright notice, this list
- ; of conditions and the following disclaimer in the documentation and/or other materials
- ; provided with the distribution.
- ;
- ; THIS SOFTWARE IS PROVIDED BY CHESTER ''AS IS'' AND ANY EXPRESS OR IMPLIED
- ; WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- ; FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
- ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- ; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ;
- ; The views and conclusions contained in the software and documentation are those of the
- ; authors and should not be interpreted as representing official policies, either expressed
- ; or implied, of Chester.
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement