Jump to content

Recommended Posts

Posted (edited)

 

For about a month I have been studying a little bit of Assembly through the great material gathered on the Random Terrain website. (https://www.randomterrain.com/atari-2600-memories.html#assembly_language)

 

Although I managed to create my own kernel, several parts of it I still don't understand. And instead of spending effort with such deep learning, I researched if it was possible to simply create a kernel for batariBasic and continue programming in bB.

 

I found this post which presents a way to use a custom kernel.

 

With some modifications I got to this version below. It's a 2LK and I'm trying to use the same variables as bB to control the players, but this is the problem: I can't (I don't have enough knowledge) use the players pointer correctly. Could anyone clarify my ideas?

 

Player0Draw = $A4			; I'm not using the vars (0-47)
Player1Draw = $A5
BackgroundPtr = $A6 ; $A7


.customdrawscreen


custom_eat_overscan
	;bB code runs during overscan. We wait for overscan to finish so the
	;frame timing doesn't get screwed up.
	lda INTIM
	bmi custom_eat_overscan

custom_do_vertical_sync
	;just a standard vsync
        lda #2
        sta WSYNC ;one line with VSYNC
        sta VSYNC ;enable VSYNC
        sta WSYNC ;one line with VSYNC
        sta WSYNC ;one line with VSYNC
        lda #0
        sta WSYNC ;one line with VSYNC
        sta VSYNC ;turn off VSYNC

custom_setup_vblank_timing
	;use bB timing variables so it should work with both PAL and NTSC
        ifnconst vblank_time
        lda #42+128
        else
        lda #vblank_time+128
        endif
        sta TIM64T

	; feel free to throw useful pre-kernel code in here, so long as it 
	; completes before vblank is over.

custom_eat_vblank
	;wait for vblank to complete
	lda INTIM
	bmi custom_eat_vblank
	lda #0
	sta WSYNC
	sta VBLANK

custom_setup_visible_timing
	;my preference is to use TIM64T to ensure a full screen is drawn.
	lda #230
	sta TIM64T





;------------------------------------------------------------------------------

    ; Desenha a parte superior da tela
    ; 192 - 22 scanlines = 192 - (11*2) = 170
        lda #$02        ; Cor cinza no PF
        sta COLUPF      ; COR no PF 

        lda #1          ; 
        sta CTRLPF      ; Liga o REFLECT 

        ldx #11
UpperSection:
        sta WSYNC

        lda customPFPattern,x
        sta PF0 
        sta PF1
        sta PF2    

        lda customPFColor,x
        sta COLUBK          

        sta WSYNC
        dex
        bne UpperSection

        stx PF0
        stx PF1
        stx PF2


        ; y position
        lda #80
        adc player0height
        sbc player0y
        sta Player0Draw

        

;------------------------------------------------------------------------------
;-- AREA DE JOGO
;------------------------------------------------------------------------------
    ; Desenha a área de jogo
    ; 170 - 160 scanlines = 170 - (80*2) = 10 (base ... not implemented)

        ldy #80             ; Carrega o y com o tamanho da área de jogo

KernelLoop:                 ;   15 - todal de 15 ciclos, vindos do bne KernelLoop
    ; Continuação da segunda linha do 2LK
    ; precalcula os dados usados na primeiralinha do 2LK

        lda player0height   ; 2 17 - altura do Player0 - IMPORTANTE!! este valor deve ser altura-1
        dcp Player0Draw     ; 5 22 - Decrementa Player0Draw e compara com a altura
        bcs DoDrawGrp0      ; 2 24 - (3 25) se o Carry estiver setado, player0 está na scanline atual
        lda #0              ; 2 27 -    caso contrário, desliga o player0
        .byte $2C           ; 4 31 - $2C = BIT with absolute addressing, trick that
                            ;        causes the lda (HumanPtr),y to be skipped
DoDrawGrp0:                 ;   25 - 25 ciclos do pior caso na linha bcs DoDrawGrp0
        lda (player0pointer),y  ; 5 30 - carrega o formato do player0 <<----------------------------- It's not working

        sta WSYNC           ; 3 33 - Aguarda o fim da scanline


    ;-------------------------------------------------
    ; começo da primeira linha do 2LK

        sta GRP0                ; 3  3 - @ 0-22, desenha o player0 efetivamente (entre os ciclos 0 e 22)

        lda (BackgroundPtr),y   ; 5  8 - Atualizo a linha do BG
        sta COLUBK              ; 3 11 - guardo o valor do BG no resitrador COLUPF

        lda (player0color),y ; 5 16 - Pega a cor do Player0 
        sta COLUP0              ; 3 19 - seta a cor do Player0 

        ; todo esse código acima precisa estar entre o ciclo 0 e 22
        ; para adicionar mais alguma coisa neste scanline, é preciso liberar algo acima
        ; sobraram apenas 3 ciclos ... é possível ainda colocar algum padrão de PF em PF1 e PF2

    ;--------------------------------------------------
    ; pre calcula os dados necessáriso para a segunda linha do 2LK
  
      ;  lda player1height      ; 2 21 - altura do Player0 - IMPORTANTE!! este valor deve ser altura-1
      ;  dcp player1y         ; 5 26 - Decrementa Player1Draw e compara com a altura
      ;  bcs DoDrawGrp1          ; 2 28 - (3 18) se o Carry estiver setado, player1 está na scanline atual
      ;  lda #0                  ; 2 31 - caso contrário, use 0 para desligar o player1
      ;  .byte $2C               ; 4 35 - $2C = BIT with absolute addressing, trick that
                                ;        causes the lda (BoxPtr),y to be skipped
DoDrawGrp1:                     ;   28 - 28 ciclos vindo do bcs DoDrawGRP1
      ;  lda (player1pointer),y      ; 5 32 - Carrega a aparencia do player1
        sta WSYNC               ; 3 35 - Aguarda o inicio de uma nova scanline

    ;---------------------------------------
    ; inicio da segunda linha do 2LK
      ;  sta GRP1                ; 3  3 - @0-22, desenha o player1 efetivamente (entre os ciclos 0 e 22)

      ;  lda (player1color),y ; 5  8 - Pega a cor do Player1 
      ;  sta COLUP1              ; 3 11 - seta a cor do Player1 

        ; todo o codigo acima precisa estar entre os ciclos 0 e 22.
        ; ainda há 11 ciclos sobrando, talvez um playfield ou ball, ou missile
        ; possa entrar aqui neste ponto.

        dey                     ; 2 13 - decrementa o y
        bne KernelLoop          ; 2 15 - se não for igual a zero, pula plá pra cima


;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------


	sty COLUBK

custom_eat_visible
	;wait for the visible display to complete
	lda INTIM
	bne custom_eat_visible

custom_setup_overscan_timing
	        ifnconst overscan_time
        lda #35+128
        else
        lda #overscan_time+128-3-1
        endif
        sta TIM64T
        lda #%11000010
        sta WSYNC
        sta VBLANK

	;bB macro to return from a bank-switch gosub or from a regular gosub.
        RETURN


customPFPattern
    .byte %11011001
    .byte %11111111
    .byte %11011001
    .byte %11001001
    .byte %11011111
    .byte %11011001
    .byte %11011001
    .byte %11001001
    .byte %01001001
    .byte %01001001
    .byte %01001001
    .byte %01001001
    .byte %11001001
    .byte %00001000
    .byte %00001000
    .byte %11001001
    .byte %11011001

customPFColor:
    .byte $00, $AA, $00, $AA, $00, $AA, $00, $AA, $00, $AA, $00, $AA, $00

 

Thanks in advance.

 

 

Edited by Leonardo Santiago

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...