|
1 | 1 | !source "sys/acehead.asm" |
2 | 2 | !source "sys/acemacro.asm" |
| 3 | +!source "sys/toolhead.asm" |
3 | 4 |
|
4 | 5 | * = aceToolAddress |
5 | 6 |
|
6 | 7 | jmp main |
7 | 8 | !byte aceID1,aceID2,aceID3 |
8 | 9 | !byte 64,0 ;*stack,reserved |
9 | 10 |
|
10 | | -save = $02 ;(3) |
| 11 | +joys = $02 ;4 |
| 12 | +last = $06 ;4 |
| 13 | +cctr = $0a ;1 |
| 14 | +cptr = $0b ;1 |
| 15 | +cdata_ptr = $0c ;2 |
| 16 | +hptr = $0e ;1 |
11 | 17 |
|
12 | 18 | main = * |
13 | | - ; init zp |
14 | | - lda #<joyMsg |
15 | | - sta zp |
16 | | - lda #>joyMsg |
17 | | - sta zp+1 |
18 | | - jsr aceConStopkey |
19 | | - bcc + |
20 | | - jmp exit |
21 | | -+ jsr aceConJoystick |
22 | | - cmp save+0 ; check JOY1 changed? |
23 | | - bne joy1 |
24 | | - txa |
25 | | - cmp save+1 ; check JOY2 changed? |
26 | | - bne joy2 |
27 | | - jmp main |
28 | | - |
29 | | -joy1: |
30 | | - sta save+0 |
31 | | - +ldaSCII "1" |
32 | | - sta joyMsg+1 |
33 | | - lda save+0 |
34 | | - jmp message |
35 | | -joy2: |
36 | | - sta save+1 |
37 | | - +ldaSCII "2" |
38 | | - sta joyMsg+1 |
39 | | - lda save+1 |
40 | | -message: |
41 | | - sta save+2 |
42 | | - ldx #6 |
43 | | - +ldaSCII "-" |
44 | | -- sta joyMsg,x |
45 | | - inx |
46 | | - cpx #10 |
47 | | - bne - |
48 | | - clc |
49 | | - ldx #6 |
50 | | -- lsr save+2 |
51 | | - bcc + |
52 | | - inx |
53 | | - cpx #10 |
54 | | - bne - |
55 | | - beq ++ |
56 | | -+ +ldaSCII "*" |
57 | | - sta joyMsg,x |
58 | | - inx |
59 | | - cpx #10 |
60 | | - bne - |
61 | | -++lsr save+2 |
62 | | - bcc + |
63 | | - lda #11 |
64 | | - jmp ++ |
65 | | -+ lda #16 |
66 | | -++ldy #0 |
67 | | - ldx #0 |
68 | | - jsr aceConWrite |
69 | | - ;jsr $5ac1 |
70 | | - jmp main |
| 19 | + ; zp init |
| 20 | + lda #$ff |
| 21 | + sta last+0 |
| 22 | + sta last+1 |
| 23 | + sta last+2 |
| 24 | + sta last+3 |
| 25 | + ; screen setup |
| 26 | + jsr clearScr |
| 27 | + jsr draw |
| 28 | + ; read gamepads |
| 29 | + lda #0 |
| 30 | + sta cctr |
| 31 | + sta cptr |
| 32 | + lda #<highlight |
| 33 | + ldy #>highlight |
| 34 | + sta hptr+0 |
| 35 | + sty hptr+1 |
| 36 | + lda #<joys |
| 37 | + ldy #>joys |
| 38 | + clc |
| 39 | + jsr aceConGamepad |
| 40 | + ; check only 1 gamepad is connected |
| 41 | + lda joys+0 |
| 42 | + bne error |
| 43 | + lda joys+1 |
| 44 | + bne error |
| 45 | + lda #$ff |
| 46 | + cmp joys+2 |
| 47 | + bne error |
| 48 | + cmp joys+3 |
| 49 | + beq continue |
| 50 | +error: |
| 51 | + lda #<errorMsg |
| 52 | + ldy #>errorMsg |
| 53 | + jsr eputs |
| 54 | + jmp exit |
| 55 | +continue: |
| 56 | + ; put J: into configuration mode |
| 57 | + lda #<config |
| 58 | + ldy #>config |
| 59 | + sta cdata_ptr |
| 60 | + sty cdata_ptr+1 |
| 61 | + sec |
| 62 | + jsr aceConGamepad |
| 63 | + ; start config process |
| 64 | + lda #14 |
| 65 | + ldx #6 |
| 66 | + jsr aceConPos |
| 67 | + lda #<press |
| 68 | + ldy #>press |
| 69 | + sta zp |
| 70 | + sty zp+1 |
| 71 | + ldx #stdout |
| 72 | + lda #5 |
| 73 | + ldy #0 |
| 74 | + jsr write |
| 75 | +getbtns: |
| 76 | + lda cctr |
| 77 | + cmp #8 |
| 78 | + beq getdirs |
| 79 | + jsr nextbtn |
| 80 | + jmp getbtns |
| 81 | +getdirs: |
| 82 | + jsr nextbtn |
| 83 | + jsr nextbtn |
| 84 | + ; update the new configuration |
| 85 | + lda #<config |
| 86 | + ldy #>config |
| 87 | + sec |
| 88 | + jsr aceConGamepad |
| 89 | + jmp exit |
71 | 90 | exit: |
72 | | - rts |
| 91 | + rts |
| 92 | +errorMsg: |
| 93 | +!pet "Error: Check you have only one gamepad connected to USB, then press RESET.",13,0 |
| 94 | +config: |
| 95 | +!text "configmode" |
| 96 | +press: |
| 97 | +!pet "Press" |
| 98 | +labels: |
| 99 | +!pet "Btn A Btn B Btn X Btn Y L TrigR TrigSelectStart " |
| 100 | +!pet "Right Down " |
| 101 | +highlight: |
| 102 | +!byte 6,21,8,19,4,19,6,17,1,4,1,19,7,10,7,14,6,6,8,4 |
| 103 | +nextbtn = * |
| 104 | + ; instructions |
| 105 | + lda #14 |
| 106 | + ldx #12 |
| 107 | + jsr aceConPos |
| 108 | + lda #<labels |
| 109 | + ldy #>labels |
| 110 | + sta zp |
| 111 | + sty zp+1 |
| 112 | + clc |
| 113 | + adc cptr |
| 114 | + sta zp |
| 115 | + lda zp+1 |
| 116 | + adc #0 |
| 117 | + sta zp+1 |
| 118 | + ldx #stdout |
| 119 | + lda #6 |
| 120 | + ldy #0 |
| 121 | + jsr write |
| 122 | + ; button highlight |
| 123 | + ldy #1 |
| 124 | + lda (hptr),y |
| 125 | + tax |
| 126 | + dey |
| 127 | + lda (hptr),y |
| 128 | + jsr aceWinPos |
| 129 | + lda #1 |
| 130 | + sta syswork+5 |
| 131 | + lda #$40 |
| 132 | + ldx #0 |
| 133 | + ldy toolWinPalette+4 |
| 134 | + jsr aceWinPut |
| 135 | + ; get button id |
| 136 | + lda cctr |
| 137 | + cmp #8 |
| 138 | + bcc waitbtn |
| 139 | +- lda #<joys |
| 140 | + ldy #>joys |
| 141 | + clc |
| 142 | + jsr aceConGamepad |
| 143 | + dec joys+0 |
| 144 | + lda joys+0 |
| 145 | + cmp last+0 |
| 146 | + beq - |
| 147 | + ; store into config |
| 148 | + ldy cctr |
| 149 | + sta (cdata_ptr),y |
| 150 | + sta last+0 |
| 151 | + jmp setnext |
| 152 | +waitbtn: |
| 153 | + lda #<joys |
| 154 | + ldy #>joys |
| 155 | + clc |
| 156 | + jsr aceConGamepad |
| 157 | + dec joys+1 |
| 158 | + lda joys+1 |
| 159 | + cmp last+1 |
| 160 | + beq waitbtn |
| 161 | + ; store into config |
| 162 | + ldy cctr |
| 163 | + sta (cdata_ptr),y |
| 164 | + sta last+1 |
| 165 | +setnext: |
| 166 | + ; button un-highlight |
| 167 | + lda #$40 |
| 168 | + ldx #0 |
| 169 | + ldy toolWinPalette+0 |
| 170 | + jsr aceWinPut |
| 171 | + ; set to next |
| 172 | + inc cctr |
| 173 | + lda hptr |
| 174 | + clc |
| 175 | + adc #2 |
| 176 | + sta hptr |
| 177 | + lda hptr+1 |
| 178 | + adc #0 |
| 179 | + sta hptr+1 |
| 180 | + lda cptr |
| 181 | + clc |
| 182 | + adc #6 |
| 183 | + sta cptr |
| 184 | + lda cptr+1 |
| 185 | + adc #0 |
| 186 | + sta cptr+1 |
| 187 | + rts |
| 188 | + |
| 189 | +; reset the screen |
| 190 | +clearScr = * |
| 191 | + lda #$c0 |
| 192 | + ldx #$20 |
| 193 | + jsr aceWinCls |
| 194 | + lda #0 |
| 195 | + ldx #0 |
| 196 | + jmp aceConPos |
| 197 | + |
| 198 | +draw = * |
| 199 | + lda #<icon |
| 200 | + ldy #>icon |
| 201 | + sta cdata_ptr+0 |
| 202 | + sty cdata_ptr+1 |
| 203 | +-- ldy #0 |
| 204 | + sty cctr |
| 205 | +- ldy cctr |
| 206 | + cpy #24 |
| 207 | + beq + |
| 208 | + lda (cdata_ptr),y |
| 209 | + beq ++ |
| 210 | + jsr aceConPutlit |
| 211 | + inc cctr |
| 212 | + jmp - |
| 213 | ++ lda #$0d ;CR |
| 214 | + jsr aceConPutchar |
| 215 | + lda cdata_ptr+0 |
| 216 | + clc |
| 217 | + adc #24 |
| 218 | + sta cdata_ptr+0 |
| 219 | + lda cdata_ptr+1 |
| 220 | + adc #0 |
| 221 | + sta cdata_ptr+1 |
| 222 | + jmp -- |
| 223 | +++ rts |
| 224 | + |
| 225 | +;******** gamepad icon chars ******** |
| 226 | +icon = * |
| 227 | +; character codes (24x13 bytes) |
| 228 | +!byte 32, 32, 32,132,129,133, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,132,129,133, 32, 32, 32 |
| 229 | +!byte 32, 32, 32,130,204,130, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,130,210,130, 32, 32, 32 |
| 230 | +!byte 132,129,129,139,129,139,129,129,129,129,129,129,129,129,129,129,129,129,139,129,139,129,129,133 |
| 231 | +!byte 130, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,130 |
| 232 | +!byte 130, 32, 32, 32,156, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,216, 32, 32, 32,130 |
| 233 | +!byte 130, 32, 32, 32,130, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,130 |
| 234 | +!byte 130, 32,158,129,131,129,159, 32, 32, 83, 69, 76, 32, 83, 84, 65, 32,217, 32, 32, 32,193, 32,130 |
| 235 | +!byte 130, 32, 32, 32,130, 32, 32, 32, 32,144,144,144, 32,144,144,144, 32, 32, 32, 32, 32, 32, 32,130 |
| 236 | +!byte 130, 32, 32, 32,157, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,194, 32, 32, 32,130 |
| 237 | +!byte 130, 32, 32, 32, 32, 32, 32,132,129,129,129,129,129,129,129,129,133, 32, 32, 32, 32, 32, 32,130 |
| 238 | +!byte 130, 32, 32, 32, 32, 32, 32,130, 32, 32, 32, 32, 32, 32, 32, 32,130, 32, 32, 32, 32, 32, 32,130 |
| 239 | +!byte 130, 32, 32, 32, 32, 32, 32,130, 32, 32, 32, 32, 32, 32, 32, 32,130, 32, 32, 32, 32, 32, 32,130 |
| 240 | +!byte 134,129,129,129,129,129,129,135, 32, 32, 32, 32, 32, 32, 32, 32,134,129,129,129,129,129,129,135 |
| 241 | +!byte $00 ;termination |
73 | 242 |
|
74 | | -joyMsg = * |
75 | | -!pet chrCR |
76 | | -!pet "1: " |
77 | | -!pet "---- " |
78 | | -!pet "FIRE!" |
| 243 | +;******** standard library ******** |
| 244 | +eputs = * |
| 245 | + ldx #stderr |
| 246 | + jmp fputs |
| 247 | +puts = * |
| 248 | + ldx #stdout |
| 249 | +fputs = * |
| 250 | + sta zp |
| 251 | + sty zp+1 |
| 252 | + ldy #$ff |
| 253 | +- iny |
| 254 | + lda (zp),y |
| 255 | + bne - |
| 256 | + tya |
| 257 | + ldy #0 |
| 258 | + jmp write |
0 commit comments