; 'NES-test example'
;---------------------------------------------------------------------
; Implemented in ATALAN Programming language
; generated by Scratchalan
; [GENERATE_DATE]
;---------------------------------------------------------------------
; NROM rom layout:
; Max codesize : 32Kib
; Max gfxsize  : 128Kib (MMC1 Mapper)
;---------------------------------------------------------------------


use nes

use nes_sprite

use nes_input

use nes_bg

use nes_mmc1

; global var's
game_screen:0..[STAGE_COUNT]
screen_state:0..1
keysPressed1:0..255
keysPressed2:0..255
out ppuState@15:0..255
[STAGE_USE]


start@

waitvbl

waitvbl
waitvbl


; Init MMC1 Mapper
setMMC1Ctrl 24
setMMC1Prog 0
setMMC1Chr0 0
setMMC1Chr1 0

; set Display Mode
;setDisplayMode %00000000 %00000000
setDisplayMode %00001000 %00010100


game_screen  = 0
screen_state = 0

_LAST_FRAME_OAM_INDEX = 0
_OAM_INDEX = 0


main@


ppuState = PPU_STAT_REG
;wait for vblank


waitvbl

CPU_PROF_START = 1 ; Profiling start
;copy sprite data to PPU

PPU_DMA_ADR= 3

_LAST_FRAME_OAM_INDEX =_OAM_INDEX
_OAM_INDEX = 0
; read out the Buttonstate of Joypad 1

keysPressed1= getJoyPad1State

keysPressed2= getJoyPad2State



[SCREEN_UPDATE]
if _LAST_FRAME_OAM_INDEX >_OAM_INDEX
   resetUnusedSprites
CPU_PROF_END = 1 ; Profiling end
goto main

