Skip to content

Commit e1113a4

Browse files
committed
snes controller example
1 parent cbc31bc commit e1113a4

3 files changed

Lines changed: 147 additions & 0 deletions

File tree

samples/snescontrollers/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export PROJECT=snescontrollers
2+
export PROJECTDIR=`pwd`
3+
export COMPILER=7800basic.sh
4+
5+
main: ${PROJECT}.bas.bin
6+
7+
${PROJECT}.bas.bin: ${PROJECT}.bas
8+
${COMPILER} ${PROJECT}.bas -O
9+
10+
clean:
11+
/bin/rm -f ${PROJECT}.bas.bin ${PROJECT}.bas.asm ${PROJECT}.bas.a78 ${PROJECT}.bas.list.txt ${PROJECT}.bas.symbol.txt
12+
/bin/rm -f a78info.cfg includes.7800 7800.asm 7800gfx.asm 7800basic_variable_redefs.h
13+
14+
run:
15+
a7800 a7800 -cart ${PROJECT}.bas.a78
1.06 KB
Loading
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
displaymode 320A
2+
3+
rem ** auto-detect if snes controllers are plugged-in.
4+
rem ** this can go anywhere, but there's a couple things to keep in mind:
5+
rem **
6+
rem ** 1. ports that didn't have snes controllers will be set to default
7+
rem ** controllers. (2 button joystick)
8+
rem ** 2. auto-detecting in a main game loop isn't recommended - there's
9+
rem ** a possibility some input may be missed, depending on the relative
10+
rem ** timing for the frame and when you check your controller state.
11+
12+
displaymode 320A
13+
BACKGRND=$0
14+
set zoneheight 8
15+
incgraphic ascii_full.png 320A 0 1
16+
characterset ascii_full
17+
alphachars ASCII
18+
P0C2=$0F
19+
P1C2=$1F
20+
P2C2=$9F
21+
22+
dim bitstring=d
23+
24+
clearscreen
25+
plotchars 'SNES2ATARI TEST' 0 0 0
26+
27+
plotchars 'snes_up' 0 0 6
28+
plotchars 'snes_down ' 0 0 7
29+
plotchars 'snes_left ' 0 0 8
30+
plotchars 'snes_right' 0 0 9
31+
plotchars 'snes_A' 0 60 6
32+
plotchars 'snes_B' 0 60 7
33+
plotchars 'snes_X' 0 60 8
34+
plotchars 'snes_Y' 0 60 9
35+
plotchars 'snes_lsh' 0 104 6
36+
plotchars 'snes_rsh' 0 104 7
37+
plotchars 'snes_select' 0 104 8
38+
plotchars 'snes_start' 0 104 9
39+
40+
plotchars 'Debug Info...' 0 0 12
41+
plotchars 'snesport' 0 0 13
42+
plotchars 'snesdetected0' 0 0 14
43+
plotchars 'snesdetected1' 0 0 15
44+
plotchars 'SWCHA' 0 0 16
45+
plotchars bitstring 0 0 17 16
46+
savescreen
47+
48+
main
49+
rem ** snes autoscan. It's recommended to only do this once, or duing a
50+
rem ** title screen loop, as the scan will temporarily disrupt the ports.
51+
temp1=framecounter&63
52+
if temp1>0 then skipsnesdetect
53+
rem ** only rescan if there are no snes controllers presently connected...
54+
if port0control = 11 && snesdetected0 <> 0 then skipsnesdetect
55+
if port1control = 11 && snesdetected1 <> 0 then skipsnesdetect
56+
snesdetect
57+
skipsnesdetect
58+
restorescreen
59+
60+
plotvalue ascii_full 0 snesport 2 80 13
61+
plotvalue ascii_full 0 snesdetected0 2 80 14
62+
plotvalue ascii_full 0 snesdetected1 2 80 15
63+
plotvalue ascii_full 0 SWCHA 2 80 16
64+
65+
if snesdetected0 then plotchars 'snes0 detected' 0 0 2 else plotchars 'snes0 not detected' 0 0 2
66+
if snesdetected1 then plotchars 'snes1 detected' 0 0 3 else plotchars 'snes1 not detected' 0 0 3
67+
68+
asm
69+
ldx snesport
70+
lda snes2atari0lo,x
71+
ora snes2atari0hi,x
72+
bne dosnestexts
73+
jmp .skipsnestext
74+
dosnestexts
75+
end
76+
if port0control <> 11 && port1control<>11 then goto skipsnestext
77+
78+
if snes#up then plotchars '*' 1 44 6
79+
if snes#down then plotchars '*' 1 44 7
80+
if snes#left then plotchars '*' 1 44 8
81+
if snes#right then plotchars '*' 1 44 9
82+
83+
if snes#A then plotchars '*' 1 88 6
84+
if snes#B then plotchars '*' 1 88 7
85+
if snes#X then plotchars '*' 1 88 8
86+
if snes#Y then plotchars '*' 1 88 9
87+
88+
if snes#lsh then plotchars '*' 1 154 6
89+
if snes#rsh then plotchars '*' 1 154 7
90+
if snes#select then plotchars '*' 1 154 8
91+
if snes#start then plotchars '*' 1 154 9
92+
93+
skipsnestext
94+
95+
asm
96+
; some code to covert the snes data to binary strings...
97+
lda snesport
98+
bne decodeport1
99+
ldy #15
100+
lda #0
101+
ClearBitsLoop
102+
sta bitstring,y
103+
dey
104+
bpl ClearBitsLoop
105+
ldx #7
106+
BitsReadLoop
107+
ror snes2atari0lo
108+
rol [bitstring+8],x
109+
ror snes2atari0hi
110+
rol bitstring,x
111+
dex
112+
bpl BitsReadLoop
113+
jmp .leavehere
114+
decodeport1
115+
ldy #15
116+
lda #0
117+
ClearBitsLoop2
118+
sta bitstring,y
119+
dey
120+
bpl ClearBitsLoop2
121+
ldx #7
122+
BitsReadLoop2
123+
ror snes2atari1lo
124+
rol [bitstring+8],x
125+
ror snes2atari1hi
126+
rol bitstring,x
127+
dex
128+
bpl BitsReadLoop2
129+
end
130+
leavehere
131+
drawscreen
132+
goto main

0 commit comments

Comments
 (0)