-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.asm
76 lines (61 loc) · 1.57 KB
/
hello.asm
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
PROCESSOR 6502
INCLUDE "vcs.h"
INCLUDE "macro.h"
NUM_SCANLINES = 242 ; 242 scanlines for PAL, 192 for NTSC
ORG $F000 ; Start of "cart area" (see Atari memory map)
; Vertical sync
StartFrame:
lda #%00000010 ; D1 = 1: Vertical sync
sta VSYNC
sta WSYNC
sta WSYNC
sta WSYNC
lda #0
sta VSYNC ; End of vertical sync, "turn on
; Vertical blank, where game logic would go
Vblank:
REPEAT 37 ; Wait until this (and the other 36) vertical blank
sta WSYNC ; scanlines are finished
REPEND
lda #0
sta VBLANK ; Vertical blank is done, "turn on" the beam
ldx #0 ; Counter for visible frames
; The kernel, where drawing occurs
Scanline:
lda #$00 ; Black background
sta COLUBK
stx COLUP0 ; Player color equals scanline count
lda #%01010101 ; Bit pattern to display as player, usually a sprite
sta GRP0
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
sta RESP0
inx ; Increase scan line counter
ScanlineEnd:
sta WSYNC ; Wait for scanline end
cpx #(NUM_SCANLINES - 1)
bne Scanline ; x != NUM_SCANLINES - 1, go to next scanline
; Overscan, where more game logic could go
Overscan:
lda #%01000010 ; "turn off" the beam again...
sta VBLANK ;
REPEAT 30 ; ...for 30 overscan scanlines...
sta WSYNC
REPEND
jmp StartFrame ; ...and start it over!
; Cart configuration area, required for the 6502 can start our game
ORG $FFFA
.WORD StartFrame ; 0xFFFA: NMI
.WORD StartFrame ; 0xFFFC: RESET
.WORD StartFrame ; 0xFFFE: IRQ
END