-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine.6502
100 lines (82 loc) · 2.03 KB
/
Engine.6502
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
.inesprg 1 ; 1x 16KB bank of PRG code
.ineschr 1 ; 1x 8KB bank of CHR data
.inesmap 0 ; mapper 0 = NROM, no bank swapping
.inesmir 1 ; background mirroring (ignore for now)
;;;;;;; Vars
.rsset $0000
engine_input .rs 1 ; 01
engine_prev_input .rs 1 ; 02
temp_volatile .rs 1 ; 03
;;;;;;; Const
BUTTON_A = %10000000
BUTTON_B = %01000000
BUTTON_START = %00100000
BUTTON_SELECT = %00010000
BUTTON_UP = %00001000
BUTTON_DOWN = %00000100
BUTTON_LEFT = %00000010
BUTTON_RIGHT = %00000001
;;;;;;;
.bank 0
.org $C000
.include "Memory.6502"
.include "Macros.6502"
.include "PPU.6502"
.include "Game.6502"
engine_ReadInput:
LDA engine_input
STA engine_prev_input
LDA #$01
STA CONTROL_1_ACCESS_REG
LDA #$00
STA CONTROL_1_ACCESS_REG ; tell both the controllers to latch buttons
LDX #$08
READ_INPUT_LOOP:
LDA CONTROL_1_ACCESS_REG
LSR A
ROL engine_input
DEX
BNE READ_INPUT_LOOP
RTS
;;;;;;; Program Execution
engine_Reset:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX CONTROL_2_ACCESS_REG ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX PPU_CONTROL_REG_1 ; disable NMI
STX PPU_CONTROL_REG_2 ; disable rendering
STX $4010 ; disable DMC IRQs
JSR ppu_VBlankWait
CLR_MEM:
LDA #$00
STA $0000, X
STA $0100, X
STA $0300, X
STA $0400, X
STA $0500, X
STA $0600, X
STA $0700, X
LDA #$FE
STA $0200, X ;move all sprites off screen
INX
BNE CLR_MEM
JSR ppu_VBlankWait
JSR game_Init
JSR ppu_Init
GAME_LOOP:
JSR engine_ReadInput
JSR game_Tick
JMP GAME_LOOP
; Interupts
.org $FFFA ;first of the three vectors starts here
.dw NMI ;when an NMI happens (once per frame if enabled) the processor will jump to the label NMI:
.dw engine_Reset ;when the processor first turns on or is reset, it will jump to the label RESET:
.dw 0 ;external interrupt IRQ is not used in this tutorial
; Data
.bank 2
.org $0000
.incbin "NESGO.chr" ;includes 8KB graphics