Jump to content
klokwrkblu

Switching playfields

Recommended Posts

How do you write a code that allows multiple play fields?

 

That is, when you flip the game select switch, it will change to a different play field? :|

Share this post


Link to post
Share on other sites
How do you write a code that allows multiple play fields?

 

That is, when you flip the game select switch, it will change to a different play field? :|

If you're coding in batari Basic, it's as simple as gosubbing or on gotoing to a particular playfield: statement based on some variable that gets incremented as the player presses the select switch. That's because batari Basic copies the playfield data into RAM, so the kernel can always read it from the same RAM locations.

 

If you're coding in straight assembly, and want to have just one kernel, then you'll probably want to read the playfield data using an addressing mode that allows the data to be pulled from anywhere with the same code-- most likely the Indirect,Y mode, which is very handy for reading player data or playfield data from different locations. What you would do is store the lo byte and high byte of the target address in two bytes of zero-page RAM, then you can use the Indirect,Y mode to read the data from that address-- maybe something like the following:

 

Playfield_ = $80
Playfield_Lo = $80
Playfield_Hi = $81

  LDA #<Level_1_Playfield
  STA Playfield_Lo
  LDA #>Level_1_Playfield
  STA Playfield_Hi

Kernel_Loop

 ; do vertical sync, vertical blank, etc., then display the playfield

  LDY #192

Playfield_Loop

  DEY
  LDA (Playfield),Y
  STA PF0
  DEY
  LDA (Playfield),Y
  STA PF1
  DEY
  LDA (Playfield),Y
  STA PF2
  STA WSYNC; draw each playfield row
  STA WSYNC; three times
  STA WSYNC
  CPY #0
  BNE Playfield_Loop

 ; then do the overscan and

  JMP Kernel_Loop

Level_1_Playfield

  BYTE %11110000,%11111111,%11111111; Rows 1-3
  BYTE %00010000,%00000000,%00000000; Rows 4-6
  BYTE %00010000,%00000000,%00000000; Rows 7-9

 ; etc.

Obviously, the above example is incomplete code, and it isn't the only way to do it, but hopefully it will give you the basic idea of how you could do it. The code snippet shown above draws the playfield upside down (because Y is decremented), so you would store the playfield data upside down. And you would load the lo byte and hi byte of the address for whichever playfield you want to draw, then store them in the zero-page RAM locations, so the kernel can draw whichever playfield the zero-page vector is pointing to. You'd most likely store the actual addresses of the playfields in two tables-- one table for the lo byte, and another table for the hi byte-- so you can pull the desired address from the tables based on an index (i.e., based on the level number):

 

   LDX Level_Number
  LDA Playfield_Lo_Byte_Table,X
  STA Playfield_Lo
  LDA Playfield_Hi_Byte_Table,X
  STA Playfield_Hi

 ; etc.

Playfield_Lo_Byte_Table

  BYTE #<Level_1_Playfield
  BYTE #<Level_2_Playfield
  BYTE #<Level_3_Playfield

 ; etc.

Playfield_Hi_Byte_Table

  BYTE #>Level_1_Playfield
  BYTE #>Level_2_Playfield
  BYTE #>Level_3_Playfield

 ; etc.

Level_1_Playfield

 ; data for 1st playfield

Level_2_Playfield

 ; data for 2nd playfield

Level_3_Playfield

 ; data for 3rd playfield

 ; etc.

What you might want to do is disassemble the ROM for some existing game that draws different playfields, and see how it's done in that game.

 

Michael

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.

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...