klokwrkblu #1 Posted October 29, 2008 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? Quote Share this post Link to post Share on other sites
SeaGtGruff #2 Posted October 29, 2008 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 Quote Share this post Link to post Share on other sites