Advertisement
chesterbr

hello.asm

Aug 24th, 2011
1,435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; hello.asm
  3. ;
  4. ; Um "Hello, World!" feito para ilustrar a minha palestra sobre programação
  5. ; para Atari 2600 (slides em http://slideshare.net/chesterbr).
  6. ;
  7. ; O código é livre (vide final do arquivo). Para compilar use o DASM
  8. ; (http://dasm-dillon.sourceforge.net/), através do comando:
  9. ;
  10. ;   dasm hello.asm -ohello.bin -f3
  11. ;
  12.  
  13.     PROCESSOR 6502
  14.     INCLUDE "vcs.h"
  15.  
  16.     ORG $F000       ; Início do cartucho (vide Mapa de Memória do Atari)
  17.  
  18. InicioFrame:
  19.     lda #%00000010  ; VSYNC inicia setando o bit 1 deste endereço
  20.     sta VSYNC
  21.     REPEAT 3        ; ...e dura 3 scanlines (WSYNC=fim da scanline)
  22.         sta WSYNC
  23.     REPEND
  24.     lda #0
  25.     sta VSYNC       ; VSYNC finaliza limpando o bit 1      
  26.  
  27. PreparaPlayfield:   ; Vamos usar o início do VBLANK para ajustar cores
  28.     lda #$00
  29.     sta ENABL       ; Desliga a ball, os missiles e os players
  30.     sta ENAM0
  31.     sta ENAM1
  32.     sta GRP0
  33.     sta GRP1
  34.     sta COLUBK      ; Cor de fundo (preto)
  35.     sta PF0         ; PF0 e PF2 ficam apagados (so usaremos o PF1)...
  36.     sta PF2
  37.     lda #$FF        ; Cor do playfield (possivelmente amarelo)
  38.     sta COLUPF
  39.     lda #$00        ; Reset no bit 0 do CTRLPF (para duplicar e nao repetir)
  40.     sta CTRLPF
  41.     ldx #0          ; X é o nosso contador de scanlines (0-191)
  42.     REPEAT 37       ; Aguarda o final da primeira linha, e das outras 36
  43.         sta WSYNC   ;
  44.     REPEND
  45.     lda #0          ; Finaliza o VBLANK, "ligando o canhão"
  46.     sta VBLANK
  47.    
  48. Scanline:
  49.     cpx #174        ; "HELLO WORLD" = (11 chars x 8 linhas - 1) x 2 scanlines =
  50.     bcs FimScanline ;   174 (0 a 173). Passou disso, pula o desenho
  51.     txa             ; Queremos 2 scanlines para cada linha da frase, então
  52.     lsr             ;   vamos fazer Y = X / 2. Para dividir por 2 usamos o
  53.     tay             ;   shift lógico (que só opera no A)
  54.     lda Frase,y     ; "Frase,Y" = "Frase+Y" (Y-ésima linha da frase)
  55.     sta PF1         ; Coloca ela nos bits 5 a 11 do playfield
  56. FimScanline:
  57.     sta WSYNC       ; Aguarda o final do scanline
  58.     inx             ; Incrementa o contador e repete até completar a tela
  59.     cpx #191
  60.     bne Scanline
  61.  
  62. Overscan:
  63.     lda #%01000010  ; "Desliga o canhão:"
  64.     sta VBLANK      ;
  65.     REPEAT 30       ; 30 scanlines de overscan...
  66.         sta WSYNC
  67.     REPEND
  68.     jmp InicioFrame ; ...e começamos tudo de novo!
  69.  
  70. Frase:
  71.     .BYTE %00000000 ; H
  72.     .BYTE %01000010
  73.     .BYTE %01111110
  74.     .BYTE %01000010
  75.     .BYTE %01000010
  76.     .BYTE %01000010
  77.     .BYTE %00000000
  78.     .BYTE %00000000 ; E
  79.     .BYTE %01111110
  80.     .BYTE %01000000
  81.     .BYTE %01111100
  82.     .BYTE %01000000
  83.     .BYTE %01000000
  84.     .BYTE %01111110
  85.     .BYTE %00000000
  86.     .BYTE %00000000 ; L
  87.     .BYTE %01000000
  88.     .BYTE %01000000
  89.     .BYTE %01000000
  90.     .BYTE %01000000
  91.     .BYTE %01000000
  92.     .BYTE %01111110
  93.     .BYTE %00000000
  94.     .BYTE %00000000 ; L
  95.     .BYTE %01000000
  96.     .BYTE %01000000
  97.     .BYTE %01000000
  98.     .BYTE %01000000
  99.     .BYTE %01000000
  100.     .BYTE %01111110
  101.     .BYTE %00000000 ; O
  102.     .BYTE %00000000
  103.     .BYTE %00111100
  104.     .BYTE %01000010
  105.     .BYTE %01000010
  106.     .BYTE %01000010
  107.     .BYTE %01000010
  108.     .BYTE %00111100
  109.     .BYTE %00000000
  110.     .BYTE %00000000 ; espaço em branco
  111.     .BYTE %00000000
  112.     .BYTE %00000000
  113.     .BYTE %00000000
  114.     .BYTE %00000000
  115.     .BYTE %00000000
  116.     .BYTE %00000000
  117.     .BYTE %00000000
  118.     .BYTE %00000000 ; W
  119.     .BYTE %01000010
  120.     .BYTE %01000010
  121.     .BYTE %01000010
  122.     .BYTE %01000010
  123.     .BYTE %01011010
  124.     .BYTE %00100100
  125.     .BYTE %00000000
  126.     .BYTE %00000000 ; O
  127.     .BYTE %00111100
  128.     .BYTE %01000010
  129.     .BYTE %01000010
  130.     .BYTE %01000010
  131.     .BYTE %01000010
  132.     .BYTE %00111100
  133.     .BYTE %00000000
  134.     .BYTE %00000000 ; R
  135.     .BYTE %01111100
  136.     .BYTE %01000010
  137.     .BYTE %01000010
  138.     .BYTE %01111100
  139.     .BYTE %01000100
  140.     .BYTE %01000010
  141.     .BYTE %00000000
  142.     .BYTE %00000000 ; L
  143.     .BYTE %01000000
  144.     .BYTE %01000000
  145.     .BYTE %01000000
  146.     .BYTE %01000000
  147.     .BYTE %01000000
  148.     .BYTE %01111110
  149.     .BYTE %00000000
  150.     .BYTE %00000000 ; D
  151.     .BYTE %01111000
  152.     .BYTE %01000100
  153.     .BYTE %01000010
  154.     .BYTE %01000010
  155.     .BYTE %01000100
  156.     .BYTE %01111000
  157.     .BYTE %00000000 ; Último byte escrito no PF1 (importante, mantém o resto da tela "limpa")
  158.    
  159.     ORG $FFFA             ; Configurações que ficam no finalzinho do cartucho:
  160.     .WORD InicioFrame     ;     NMI
  161.     .WORD InicioFrame     ;     RESET
  162.     .WORD InicioFrame     ;     IRQ
  163.    
  164.     END
  165.  
  166. ;
  167. ; Copyright 2011 Carlos Duarte do Nascimento (Chester). All rights reserved.
  168. ;
  169. ; Redistribution and use in source and binary forms, with or without modification, are
  170. ; permitted provided that the following conditions are met:
  171. ;
  172. ;    1. Redistributions of source code must retain the above copyright notice, this list of
  173. ;       conditions and the following disclaimer.
  174. ;
  175. ;    2. Redistributions in binary form must reproduce the above copyright notice, this list
  176. ;       of conditions and the following disclaimer in the documentation and/or other materials
  177. ;       provided with the distribution.
  178. ;
  179. ; THIS SOFTWARE IS PROVIDED BY CHESTER ''AS IS'' AND ANY EXPRESS OR IMPLIED
  180. ; WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  181. ; FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
  182. ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  183. ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  184. ; SERVICES;  LOSS OF USE, DATA, OR PROFITS;  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  185. ; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  186. ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  187. ; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  188. ;
  189. ; The views and conclusions contained in the software and documentation are those of the
  190. ; authors and should not be interpreted as representing official policies, either expressed
  191. ; or implied, of Chester.
  192. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement