-
Notifications
You must be signed in to change notification settings - Fork 27
/
tms9918nes.asm
220 lines (182 loc) · 3.72 KB
/
tms9918nes.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
; Troy's HBC-56 - TMS9918/NES test
;
; Copyright (c) 2021 Troy Schrapel
;
; This code is licensed under the MIT license
;
; https://github.com/visrealm/hbc-56
;
!src "hbc56kernel.inc"
XPOS = $44
YPOS = $45
hbc56Meta:
+setHbcMetaTitle "TMS9918 NES TEST"
+setHbcMetaNES
rts
BUFFER_ADDR = $1000
sprite1:
!byte %00001000
!byte %00000100
!byte %00001111
!byte %00011011
!byte %00111111
!byte %00101111
!byte %00101000
!byte %00000110
sprite2:
!byte %00100000
!byte %01000000
!byte %11100000
!byte %10110000
!byte %11111000
!byte %11101000
!byte %00101000
!byte %11000000
XPOS = $44
YPOS = $45
XPOS1 = $46
YPOS1 = $47
hbc56Main:
lda #0
sei
jsr tmsModeGraphicsI
lda #TMS_R1_SPRITE_MAG2
jsr tmsReg1SetFields
jsr tmsInitTextTable ; clear the name table
+tmsEnableOutput
+tmsPrint "TROY'S HBC-56 BASIC READY", 1, 15
+tmsPrint ">10 PRINT \"HELLO WORLD!\"", 0, 17
+tmsPrint ">RUN", 0, 18
+tmsPrint "HELLO WORLD!", 1, 19
+tmsPrint "** DONE **", 1, 21
+tmsPrint ">", 0, 23
+tmsPrint 127, 1, 23
lda #40
sta XPOS
sta YPOS
lda #80
sta XPOS1
sta YPOS1
+tmsCreateSpritePattern 0, sprite1
+tmsCreateSpritePattern 1, sprite2
+tmsCreateSprite 0, 0, 40, 40, TMS_MAGENTA
+tmsCreateSprite 1, 1, 56, 40, TMS_MAGENTA
+tmsCreateSprite 2, 0, 80, 80, TMS_MED_RED
+tmsCreateSprite 3, 1, 96, 80, TMS_MED_RED
+tmsEnableInterrupts
cli
loop:
sei
jsr outputSeconds
ldx XPOS
ldy YPOS
+tmsSpritePosXYReg 0
txa
clc
adc #16
tax
+tmsSpritePosXYReg 1
ldx XPOS1
ldy YPOS1
+tmsSpritePosXYReg 2
txa
clc
adc #16
tax
+tmsSpritePosXYReg 3
cli
ldy #8
jsr customDelay
jmp loop
COLOR = $89
IMG = $8a
LAST_SECONDS_L = $8b
outputSeconds:
+tmsSetPosWrite 8, 1
+nes1BranchIfNotPressed NES_LEFT, +
+tmsPut 'L'
dec XPOS
+
+nes1BranchIfNotPressed NES_RIGHT, +
+tmsPut 'R'
inc XPOS
+
+nes1BranchIfNotPressed NES_UP, +
+tmsPut 'U'
dec YPOS
+
+nes1BranchIfNotPressed NES_DOWN, +
+tmsPut 'D'
inc YPOS
+
+nes1BranchIfNotPressed NES_SELECT, +
+tmsPut 'S'
+tmsPut 'e'
dec YPOS1
+
+nes1BranchIfNotPressed NES_START, +
+tmsPut 'S'
+tmsPut 't'
inc YPOS1
+
+nes1BranchIfNotPressed NES_B, +
+tmsPut 'B'
dec XPOS1
+
+nes1BranchIfNotPressed NES_A, +
+tmsPut 'A'
inc XPOS1
+
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
+tmsPut ' '
; flashing cursor
lda #(TMS_FPS / 2)
cmp HBC56_TICKS
bcc +
+tmsPrint ' ', 1, 23
jmp ++
+
+tmsPrint 127, 1, 23
++
lda HBC56_SECONDS_L
cmp LAST_SECONDS_L
beq .endOutput
sta LAST_SECONDS_L
; output seconds (as hex)
+tmsSetPosWrite 1, 1
lda HBC56_SECONDS_L
jsr tmsHex8 ; calls cli
.endOutput
rts
medDelay:
jsr delay
jsr delay
jsr delay
jsr delay
delay:
ldx #255
ldy #255
-
dex
bne -
ldx #255
dey
bne -
rts
customDelay:
ldx #255
-
dex
bne -
ldx #255
dey
bne -
rts