Skip to content

Game Generator Editor

Daniel Tremblay edited this page May 30, 2021 · 13 revisions

The Game Generator allows developers to write simple code in a text editor. The intent of the generator is to provide a decent assembly starter project. Once the assets are added and the registers for bitmaps, sprites and tilemaps are set, the assembly code can be refined to delivered the best results.

NOTE: the assembly files generated are compatible with 64tass assembler.

There is a limited set of functions implemented:

  • ASSET: includes a binary asset
  • COPY: copy byte arrays. Based on source and destination, the generator picks correct DMA functions
  • ASSIGNMENT: any kernel variable can be assigned a value
  • LABEL: define a label, useful for GOTO
  • GOTO: jump to a label
  • FILL: fill a byte array with a given byte
  • VGM_INIT: initialize the VGM player (to play VGM music files)
  • VGM_PLAY: plays one iteration of the VGM file
  • ENABLE_INTERRUPTS: enable interrupts based on the checked IRQs
  • // sprites
  • ENABLE_SPRITE: enable one of the 63 sprites
  • DISABLE_SPRITE: disable one of the 63 sprites
  • SET_SPRITE_POS: set the position of one the 63 sprites
  • // bitmaps
  • ENABLE_BITMAP: enabled one of the two bitmap layers
  • DISABLE_BITMAP: disable one of the two bitmap layers
  • // tilemaps
  • ENABLE_TILEMAP: enable one of the 4 tilemaps
  • DISABLE_TILEMAP: disable one of the 4 tilemaps
  • SET_TILEMAP_POS: set the position of one of the 4 tilemaps
  • IF: not yet implemented
  • VAR: not yet implemented

The template code is stored in the file "GameGeneratorTemplates.txt" in your Foenix IDE Resources folder. The template code is used to copy the code into your project assembly files "game_main.asm". The game_main.asm includes the base C256 Foenix definition files, a few basic handlers and helper functions. You can modify any of these files to generate a better experience for your own coding style.

The assembly code generated attempts to use Foenix Kernel sub-routines as much as possible.

ASSET Usage

Example: ASSET "foenix-96x96.bin" LOGO

The first parameter is a filename that the assembler will locate in the file system. The second parameter is a label for the asset.

Generated code:

LOGO
.binary "foenix-96x96.bin"

COPY Usage

Example: COPY LOGO $B0:0000 $7800

  • The first parameter is a source address, provided as an asset label or an hex value
  • The second parameter is a destination address, provided as an asset label or an hex value
  • The third parameter is the size of the array, maximum 0:0000 (the video RAM maximum)

NOTE: If the source is system RAM and the destination address is video RAM, then the helper function COPY_TO_VRAM is used.

Generated Code:

; Write the source and destination addresses
LDA #`LOGO
STA @l SDMA_SRC_ADDY_H
LDA #`$B0_0000-$B0_0000   ; offset by $B0 for video RAM
STA @l VDMA_DST_ADDY_H
LDA #`$7800
STA @l SDMA_SIZE_H
STA @l VDMA_SIZE_H
setal
LDA #<>LOGO
STA @l SDMA_SRC_ADDY_L
LDA #<>$B0_0000-$B0_0000   ; offset by $B0 for video RAM
STA @l VDMA_DST_ADDY_L
LDA #<>$7800
STA @l SDMA_SIZE_L
STA @l VDMA_SIZE_L
setas

; Write size of transfer to local register
JSL COPY_TO_VRAM

FILL Usage

Example: FILL $B0:0000 $1:2c00 0

  • The first parameter is the address to start filling memory with.
  • The second parameter is the number of bytes to fill.
  • The third parameter is the byte to fill with.

NOTE: This subroutine uses the DMA to fill the byte array. The CPU will stop executing whiles the operation is occuring.

Generated Code:

LDA #`$B0_0000-$B0_0000   ; offset by $B0 for video RAM
STA @l VDMA_DST_ADDY_H
LDA #`$1_2c00
STA @l VDMA_SIZE_H
LDA #0
STA VDMA_BYTE_2_WRITE

setal
LDA #<>$B0_0000-$B0_0000   ; offset by $B0 for video RAM
STA @l VDMA_DST_ADDY_L
LDA #<>$1_2c00
STA @l VDMA_SIZE_L
setas

; Write size of transfer to local register
JSL FILL_VRAM

VGM_INIT Usage

Example: VGM_INIT SONG

This simply set the VGM player initialized to play a VGM song.

  • The first parameter is the address of the SONG. This uses the vgm_player.asm code.

NOTE: The VGM player sets and uses Timer0 interrupts, to play song data at the correct rate. So, you need to enable Timer0 and add VGM_PLAY in the Timer0 handler.

Generated Code:

JSL VGM_INIT_TIMERS
; load the game over music
LDA #`SONG
STA CURRENT_POSITION + 2
STA SONG_START + 2
setal
LDA #<>SONG
STA SONG_START
setas
JSL VGM_SET_SONG_POINTERS
Clone this wiki locally