Jump to content
IGNORED

Stephen's A8 Blog - 30Hz VBI subroutine solved


RSS Bot

Recommended Posts

So I had my immediate mode VBI routine running. It is a very simple VBI, the first thing it does is synchronize my DLI code to the top of the screen (see DLI Blog). Then it reads a single joystick and moves the player horizontally. However, the VBI runs at 60Hz and my player position only needs updated at 30Hz. The solution is quite simple. The code is below, with some notes below that.

 

;12/29/09 - This is assembled to "VBI.OBJ";Assembled using MADS 1.8.8 build 2 (5 Jul 09);EQUATESSETVBV equ $E45C ;Immediate VBISTICK0 equ $D300 ;Joystick 0 hw regHPOSP0 equ $D000 ;Hardware Player 0 posXLOCP0 equ $00CC ;mem loc to hold HPOSP0 (cannot read it back)TIMR30 equ $00CD ;toggles between 0,1 to give a 30Hz interruptorg $0600 lda #$00 sta $200 ;Synchronize top DLI lda #$B2 ;with code at $B200 sta $201 ;The DLI will then walk itself down screen;The joystick read routine must only run at 30Hz but the VBI runs at 60Hz.;Declare a zero-page variable, set = 1 before starting the VBI!;Pseudo-code below;if (TIMR30 == 0); Readstick(); //this ends with a TIMR30--;;else; TIMR30 = 1; //Now jump to DLI exit code lda TIMR30 bne RdStk ;Read the joystick every other frame lda #1 sta TIMR30 ;Reset TIMR30 so we read it on the next frame jmp Exit ;Joystick read routine beginsRdStk lda STICK0 and #4 ;is Bit 3 set beq Left lda STICK0 and #8 ;is Bit 4 set beq Right bne DoneLeft lda XLOCP0 ;get the value cmp #$50 ;minimum HPOS bcc Done dec XLOCP0 ;move it left lda XLOCP0 sta HPOSP0 ;make the move jmp DoneRight lda XLOCP0 ;get the value cmp #$A2 ;maximum HPOS bcs Done inc XLOCP0 ;move it right lda XLOCP0 sta HPOSP0 ;make the moveDone dec TIMR30 ;set to zero so we skip it on the next frame;Joystick read routine endsExit jmp $E45F ;hit vector for deferred VBI ;run this code to set the Immediate VBI vector;AFTER the above code is loadedInit pla ;since calling from BASIC, clear stack ldy #$00 ;lo-byte ldx #$06 ;hi-byte lda #$06 ;Immediate VBI jsr SETVBV ;"inject" code into immediate VBI rts ;All done

 

Several things to note:

  • Certain memory locations will definitely change before code is finalized
  • Currently the game framework is being coded in Turbo BASIC XL 1.5 with lots of assembly routines
  • In order to setup and enable this immediate mode VBI, perform the following steps IN ORDER
    • Load the assembled code at $0600
    • ? USR($0647) will inject this code (see the "Init" section above )
    • Since I am leaving the OS enabled, the VBI will begin (or crash) immediately

    [*]Code to read / respond to the trigger is not currently in place[*]It is a bad idea to leave the "Init" routine dangling at the end of the VBI code block. Any changes to the VBI code cause its address to change which means I have to change the location I pass to the USR routine. This is just one of the many things that will be fixed during the development process.

 

Stephen Anderson

 

http://www.atariage.com/forums/index.php?app=blog&blogid=341&showentry=6700

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...