Thovar Posted June 12, 2017 Share Posted June 12, 2017 I'm trying to change the player color with the background color everytime fire button for player 1 is fired (INPT4) but its just occours once. I tried to understando how constant works in dasm because constants appear that they aren't constants. The part of code that does it is in Joystick( part 3 of code). I used Joy of Sticks as base to my code. After i change the color with background ill try to change the color with any object in the screen. http://www.atariage.com/2600/programming/2600_101/05joy.html Heres the full code: PROCESSOR 6502 ; vcs.h para usar a TIA e os registradores include vcs.h ;=============================================================================== ; Início da RAM e separamos espaço pra possíveis variáveis - Cabeçalho ;=============================================================================== ;define um espaço para as variáveis SEG.U VARS ;RAM scomeça no endereço $80 ORG $80 ;=============================================================================== ; Início do Catucho - Cabeçalho ;=============================================================================== ; Cabeçalho SEG CODE ; Recomenda-se que rom até 2k comece em $F800 e 4K $F000 ORG $F000 ;Variáveis reservadas ;YBox = $82 COR_FUNDO = $99 COR_PLAYER = $83 YPos = $80; ; onde guardaremos a posição vertical do objeto Quadrado = $81; variável do quadrado ;BOX_COLOR = $84 ; blue ;=============================================================================== ; Inicio do Jogo ;=============================================================================== Inicio ;Limpa a RAM e os registradores da TIA e do processador ;recomendação para todos os jogos e limpar a RAM sei ;desativa qualquer interrupção cld ; limpa o bit de cáculo de BCD ldx #0 ; carrega x com 0 txa ; passa o valor de x para A tay ; || || de a para y free dex ; x = x -1 txs ; passa x para o Stack pointer pha ; da um push em A bne free ; enquanto não for zero(tiver algo) ontinua o loop ;escolhemos trabalhar com o míssel 0 lda #39 ; tamanho = 39 pg 40 manual stella sta NUSIZ0 ; quadrado = tamanho lda #99 ; posicão inicial 192/2 = 96 + 4 pixels = 100 -1 index (começa conta de 0) = 99 sta YPos ;Posição inicial no eixo y(vertical) ;mark lda #COR_PLAYER sta COLUP0 lda #COR_FUNDO sta COLUBK ; background = cor#39 marrom claro ; cpx #2 ; beq volta ;volta ; rts ;;set initial box position ;lda #120 ;sta YBox ;lda #(200 - BOX_HEIGHT)/2 ;lda #BOX_COLOR ;sta COLUP1 ;;;calcular a posiçao inicial no eixo x(horizontal) lda #79 ; posicão inicial 160/2 = 80 - 1 index = 79 sec ; limpa o carry sta WSYNC ; espera o inicio da linha ;;asl shiftleft bit, ajuda a "empurrar o quadrado para direita DivideLoop sbc #15 ;2 bcs DivideLoop ;4/5 4/ 9.../54 pg 8 manual 15 colour clock interval eor #7 ;+6/11... 01 10 asl ;8 asl ;10 asl ;12 asl ;14/19.../64 sta.wx HMM0,X ;19/24.../69 sta RESM0,X ;23 precisamos chegar no ciclo 23 ou + para podermos setar sta WSYNC ;necessário antes do HMOVE sta HMOVE ;movimentação horizontal tem q ter ciclo 24> aqui pg 9 manual stella ;Obs.: bug de 8 bits referente a este HMOVE ^^^^^^^^ que da o tracinho preto na tela superior esquerda ;=============================================================================== ; Estrutura do Programa Principal ;=============================================================================== Main ;1 - VerticalSync ;2 - VerticalBlank ;3 - Joystick ;4 - Núcleo ;5 - OverScan ;5.1 - voltemos ao Main ;6 - Fim do cartucho ;=============================================================================== ; 1 - Vertical Sync ; ------------- ; Aqui geramos o sinal que orienta a TV a mover o canhão para o topo da tela para ; podermos ir mandando os frames. O sinal VSync precisa ser de 3 linha como ; explicamos no trabalho ;=============================================================================== ;VerticalSync: lda #2 ; Carrega o acumulador com 2 para podermos setar D1 = 1 no sta da linha 86 sta VSYNC ; acumulador D1 = 1 e liga o sinal do vertical Sync sta WSYNC ; espera por SYNC para ir até o fim da 1ª linha sta WSYNC ; espera por SYNC para ir até o fim da 2ª linha sta WSYNC ; espera por SYNC para ir até o fim da 3ª linha lda #0 ; carrega o acumulador com 0 então poderemos setar D1 = 0 no sta da linha 91 ] ;sta GRP0 ;sta GRP1 sta VSYNC ; acumulador d1 = 0 e desliga o sinal vsync ;=============================================================================== ; 2 - Vertical Blank ; -------------- ; Pularemos 37 linhas do vblank ;=============================================================================== ldx #36 ; x = 36, já temos uma linha da nossa inicialição da Pos Horizontal vbLoop sta WSYNC ; espera ir até o fim da linha dex ; x = x -1 bne vbLoop ; volta a VbLoop se x > 0 ;=============================================================================== ; 3 - Joystick ; -------------- ; Aqui captaremos os comandos do Joystic para movimentar o quadrado ;=============================================================================== lda #16 ; a = 16 bit SWCHA ; faz um and lógico com o registrador A e SWCHA pega o bit de entrada bne testaBaixo ; se for diferente de zero inc YPos ; inc YPos ; 2 inc para regular a velocidade testaBaixo lda #32 ;a = 32 bit SWCHA ; faz um and lógico com o registrador A e SWCHA pega o bit de entrada bne testaEsquerda ; testa o próximo se >0 dec YPos ; dec YPos ; 2 dec para regular a velocidade testaEsquerda ;aqui usaremos reg X ldx #0 ; x = 0 lda #64 ; a = 64 bit SWCHA ;faz um and lógico com o registrador A e SWCHA pega o bit de entrada bne testaDireita ; testa o próximo se >0 ldx #%00011111 ;+1 nos 4 primeiros bits esquerda ; pg 41 manual do stella D7 D6 D5 D4 ;4 primeiros bits do registrador ;pg 41 manual do stella ;D7 D6 D5 D4 ;0 1 1 1 +7 ;0 1 1 0 +6 ;0 1 0 1 +5 Move left ;0 1 0 0 +4 indicated number +7 vmax -8 1 & -1 vmin ;0 0 1 1 +3 of clocks ;0 0 1 0 +2 ;0 0 0 1 +1 ;0 0 0 0 0 No Motion ;1 1 1 1 -1 ;1 1 1 0 -2 ;1 1 0 1 -3 ;1 1 0 0 -4 move right ;1 0 1 1 -5 indicated number ;1 0 1 0 -6 of clocks ;1 0 0 1 -7 ;1 0 0 0 -8 testaDireita lda #128 ;a = 128 bit SWCHA ;faz um and lógico com o registrador A e SWCHA pega o bit de entrada bne done ; vaa para done linha 198 se a flag de bit > 0 ldx #%11111111 ; -1 nos 4 primeiros bits direita done stx HMM0 ;Enfim, guarda o comando; ########################################################HERE THE INPT4 ########################################### LDA INPT4 ;read button input BMI ButtonNotPressed ;skip if button not pressed ldx COLUP0 cpx #COR_PLAYER bcs jumper ldx #COR_FUNDO ldy #COR_PLAYER stx COLUBK sty COLUP0 jumper ldx #COR_FUNDO ldy #COR_PLAYER stx COLUP0 sty COLUBK ButtonNotPressed ################################################## ;=============================================================================== ; 4 - Núcleo ; ------ ; Aqui é a parte onde desenhamos o nosso quadrado ;=============================================================================== ldy #190 ; y = 190 sta WSYNC ; espera fim da linha ;lda #%00000000 sta VBLANK ; desliga vblank sta WSYNC ; necessário antes de chamar HMOVE mover sta HMOVE ; executa comando se houver ; Desenhando a tela do jogo TelaPrincipal sta WSYNC QuadradoON cpy YPos ; verifica se quadrado ta ativo bne no ; pula pra linha 214 lda #8 ; a = 8 sta Quadrado ;atualiza quadrado no ;Ta fora da tela quadrado? lda #0 ; a =0 sta ENAM0 ; atualiza enam0 ;Voltou?Então pinta quadrado! lda Quadrado ; atualiza quadrado beq fim ; se flag =0 vai pra linha 227 ligado lda #2 ; a =2 sta ENAM0 ; atualiza enam0 dec Quadrado ; diminui o valor da variável quadrado fim dey ; y = y-1 bne TelaPrincipal ; se y> 0 continua o looping ;=============================================================================== ; 5 - Overscan ; -------------- ;Aqui contamos as 30 linhas finais da tela ;=============================================================================== ;lda #%01000010 lda #2 ; a = 2 pra fazer D1 = 1; sta WSYNC ; espera vsync para ir até o fim da linha, e garantir o fim da scanline sta VBLANK ; desliga a imagem e liga vblank ldx #30 ; x = 30 osLoop sta WSYNC ; espera vsync para ir até o fim da linha dex ; x = x -1 bne osLoop ; looping regressivo retornando para osLoop enquanto x != 0 ;=========================================================================== ; 5.1 - Retorna ao Main ;=========================================================================== ;lda #0 ;sta VBLANK jmp Main ; Volta para o label Main >> linha 93 << BoxGfx: .byte %11111111 .byte %11111111 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %10000001 .byte %11111111 .byte %00000000 ;=============================================================================== ; 6 - Fim do Cartucho ;=============================================================================== ORG $FFFC ; espaço para o endereço dos vetores de interrupçoes ( Reset o mais importante). .WORD Inicio ; NMI .WORD Inicio ; RESET .WORD Inicio ; IRQ T2f.asm T2f.bin Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted July 4, 2017 Share Posted July 4, 2017 (edited) You at using constants. The difference is this: Dasm sees COR_FUNDO and always replaces it with $99 when it assembles the code Its only there for your convenience as a label, the Atari never uses any RAM for it. To use RAM to make a variable, you would use: ORG $80 ;point DASM to the start of RAM CorFundo: ds 1 ;tell DASM you are using 1 byte of RAM and naming it CorFundo You have your color changes one right after the other here. If the button is pressed, it does the first color change, then changes it right back. You would need to place a jmp in front of "jumper" to prevent that: LDA INPT4 ;read button input BMI ButtonNotPressed ;skip if button not pressed ldx COLUP0 cpx #COR_PLAYER bcs jumper ldx #COR_FUNDO ldy #COR_PLAYER stx COLUBK sty COLUP0 jumper ldx #COR_FUNDO ldy #COR_PLAYER stx COLUP0 sty COLUBK Edited July 4, 2017 by BNE Jeff Quote Link to comment Share on other sites More sharing options...
bogax Posted July 8, 2017 Share Posted July 8, 2017 X ^ X = 0 Y ^ 0 = Y so (X ^ Y) ^ Y = X (X ^ Y) ^ X = Y or FLIP = X ^ Y X ^ FLIP = Y Y ^ FLIP = X CFLIP = COR_PLAYER ^ COR_FUNDO bit INPT4 BMI ButtonNotPressed ;skip if button not pressed LDA COLUP0 EOR #CFLIP STA COLUP0 LDA COLUBK EOR #CFLIP STA COLUBK ButtonNotPressed Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted September 3, 2017 Share Posted September 3, 2017 Better recheck the Stella programmer manual. Jeff's example would work, yours would not...the 2600 cannot read COLUxx registers (these point to the collision and INPT registers for read operations). Too bad, those would have been useful temp ram for offscreen routines! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.