Skip to content

Commit 2308a96

Browse files
committed
add autoformat script
1 parent c34dc34 commit 2308a96

File tree

8 files changed

+113
-91
lines changed

8 files changed

+113
-91
lines changed

src/constants.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ MENU_TOP_MARGIN_SCROLL := 7 ; in blocks
111111

112112
; menuConfigSizeLookup
113113
; menu ram is defined at menuRAM in ./ram.asm
114-
.macro MENUSIZES
114+
.macro MENUSIZES
115115
.byte $0 ; MODE_TETRIS
116116
.byte $0 ; MODE_TSPINS
117117
.byte $0 ; MODE_SEED

src/nmi/pollkeyboard.asm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; |+--- Select column, row is incremented if this bit goes from high to low.
1111
; +---- Enable keyboard matrix (if 0, all voltages inside the keyboard will be 5V, reading back as logical 0 always)
1212

13-
; Incrementing the row from the (keyless) 10th row will cause it to wrap back to the first row.
13+
; Incrementing the row from the (keyless) 10th row will cause it to wrap back to the first row.
1414

1515
; Output ($4017 read)
1616

@@ -50,14 +50,14 @@ pollKeyboard:
5050
sta JOY1
5151
ldy #$0A
5252
@avoidParasiticCapacitance: ; wait approx 50 cycles after advancing rows
53-
dey
53+
dey
5454
bne @avoidParasiticCapacitance
5555
lda JOY2_APUFC
5656
and #KB_MASK
5757
sta generalCounter
5858
lda #KB_COL_1
5959
sta JOY1
60-
lda JOY2_APUFC
60+
lda JOY2_APUFC
6161
and #KB_MASK
6262
lsr
6363
sta keyboardInput,x
@@ -129,7 +129,7 @@ mapKeysToButtons:
129129
ora #BUTTON_RIGHT
130130
sta newlyPressedKeys
131131
@skipRightRead:
132-
@rightNotPressed:
132+
@rightNotPressed:
133133

134134
ldy #$07 ; grph -> B
135135
ldx #$06
@@ -168,7 +168,7 @@ mapKeysToButtons:
168168
@startNotPressed:
169169

170170

171-
; Separate Newly Pressed from Held
171+
; Separate Newly Pressed from Held
172172
lda newlyPressedKeys
173173
tay
174174
eor heldKeys
@@ -189,6 +189,6 @@ mapKeysToButtons:
189189
keyMask:
190190
.byte $80,$40,$20,$10,$08,$04,$02,$01
191191
readKey:
192-
lda keyboardInput,y
193-
and keyMask,x
194-
rts
192+
lda keyboardInput,y
193+
and keyMask,x
194+
rts

src/reset.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ reset: cld
1414
txs
1515
.if INES_MAPPER = 1
1616
inc reset
17-
.elseif INES_MAPPER = 4
17+
.elseif INES_MAPPER = 4
1818
jsr mmc3Init
1919
.elseif INES_MAPPER = 5
2020
jsr mmc5Init

src/sprites/piece.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ stageSpriteForCurrentPiece_actual:
8383
ldy oamStagingLength
8484
lda #$04
8585
sta generalCounter2
86-
@stageMino:
86+
@stageMino:
8787
lda orientationTable,x
8888
asl a
8989
asl a
@@ -116,7 +116,7 @@ stageSpriteForCurrentPiece_actual:
116116
sta oamStaging,y
117117
jmp @finishLoop
118118

119-
@validYCoordinate:
119+
@validYCoordinate:
120120
inc oamStagingLength
121121
iny
122122
lda orientationTable,x
@@ -126,7 +126,7 @@ stageSpriteForCurrentPiece_actual:
126126
clc
127127
adc generalCounter3
128128
sta oamStaging,y
129-
@finishLoop:
129+
@finishLoop:
130130
inc oamStagingLength
131131
iny
132132
inx

src/util/check_region.asm

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ checkRegion:
33

44
; region detection via http://forums.nesdev.com/viewtopic.php?p=163258#p163258
55
;;; use the power-on wait to detect video system-
6-
ldx #0
6+
ldx #0
77
stx palFlag ; extra zeroing
8-
ldy #0
8+
ldy #0
99
@vwait1:
10-
bit $2002
11-
bpl @vwait1 ; at this point, about 27384 cycles have passed
10+
bit $2002
11+
bpl @vwait1 ; at this point, about 27384 cycles have passed
1212
@vwait2:
13-
inx
14-
bne @noincy
15-
iny
13+
inx
14+
bne @noincy
15+
iny
1616
@noincy:
17-
bit $2002
18-
bpl @vwait2 ; at this point, about 57165 cycles have passed
17+
bit $2002
18+
bpl @vwait2 ; at this point, about 57165 cycles have passed
1919
@endVWait:
2020

2121
;;; BUT because of a hardware oversight, we might have missed a vblank flag.
@@ -24,16 +24,16 @@ checkRegion:
2424
;;; PAL NES: 33247 cycles / 12.005 -> $AD1 or $15A2
2525
;;; Dendy: 35464 cycles / 12.005 -> $B8A or $1714
2626

27-
tya
28-
cmp #16
29-
bcc @nodiv2
30-
lsr
27+
tya
28+
cmp #16
29+
bcc @nodiv2
30+
lsr
3131
@nodiv2:
32-
clc
33-
adc #<-9
34-
cmp #3
35-
bcc @noclip3
36-
lda #3
32+
clc
33+
adc #<-9
34+
cmp #3
35+
bcc @noclip3
36+
lda #3
3737
@noclip3:
3838
;;; Right now, A contains 0,1,2,3 for NTSC,PAL,Dendy,Bad
3939
cmp #0

src/util/core.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ updateAudioWaitForNmiAndResetOamStaging:
6161
beq @checkForNmi
6262

6363
resetOAMStaging:
64-
; Hide a sprite by moving it down offscreen, by writing any values between #$EF-#$FF here.
65-
; Sprites are never displayed on the first line of the picture, and it is impossible to place
66-
; a sprite partially off the top of the screen.
64+
; Hide a sprite by moving it down offscreen, by writing any values between #$EF-#$FF here.
65+
; Sprites are never displayed on the first line of the picture, and it is impossible to place
66+
; a sprite partially off the top of the screen.
6767
; https://www.nesdev.org/wiki/PPU_OAM
6868
ldx #$00
6969
lda #$FF

src/util/math.asm

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -177,82 +177,82 @@ SUBTBL:
177177

178178
; source: https://codebase64.org/doku.php?id=base:24bit_multiplication_24bit_product
179179
unsigned_mul24:
180-
lda #$00 ; set product to zero
181-
sta product24
182-
sta product24+1
183-
sta product24+2
180+
lda #$00 ; set product to zero
181+
sta product24
182+
sta product24+1
183+
sta product24+2
184184

185185
@loop:
186-
lda factorB24 ; while factorB24 !=0
187-
bne @nz
188-
lda factorB24+1
189-
bne @nz
190-
lda factorB24+2
191-
bne @nz
192-
rts
186+
lda factorB24 ; while factorB24 !=0
187+
bne @nz
188+
lda factorB24+1
189+
bne @nz
190+
lda factorB24+2
191+
bne @nz
192+
rts
193193
@nz:
194-
lda factorB24; if factorB24 isodd
195-
and #$01
196-
beq @skip
194+
lda factorB24; if factorB24 isodd
195+
and #$01
196+
beq @skip
197197

198-
lda factorA24 ; product24 += factorA24
199-
clc
200-
adc product24
201-
sta product24
198+
lda factorA24 ; product24 += factorA24
199+
clc
200+
adc product24
201+
sta product24
202202

203-
lda factorA24+1
204-
adc product24+1
205-
sta product24+1
203+
lda factorA24+1
204+
adc product24+1
205+
sta product24+1
206206

207-
lda factorA24+2
208-
adc product24+2
209-
sta product24+2 ; end if
207+
lda factorA24+2
208+
adc product24+2
209+
sta product24+2 ; end if
210210

211211
@skip:
212-
asl factorA24 ; << factorA24
213-
rol factorA24+1
214-
rol factorA24+2
215-
lsr factorB24+2 ; >> factorB24
216-
ror factorB24+1
217-
ror factorB24
212+
asl factorA24 ; << factorA24
213+
rol factorA24+1
214+
rol factorA24+2
215+
lsr factorB24+2 ; >> factorB24
216+
ror factorB24+1
217+
ror factorB24
218218

219-
jmp @loop ; end while
219+
jmp @loop ; end while
220220

221221
unsigned_div24:
222222
lda #0 ;preset remainder to 0
223-
sta remainder
224-
sta remainder+1
225-
sta remainder+2
226-
ldx #24 ;repeat for each bit: ...
223+
sta remainder
224+
sta remainder+1
225+
sta remainder+2
226+
ldx #24 ;repeat for each bit: ...
227227

228228
@divloop:
229229
asl dividend ;dividend lb & hb*2, msb -> Carry
230-
rol dividend+1
231-
rol dividend+2
232-
rol remainder ;remainder lb & hb * 2 + msb from carry
233-
rol remainder+1
234-
rol remainder+2
235-
lda remainder
236-
sec
237-
sbc divisor ;substract divisor to see if it fits in
238-
tay ;lb result -> Y, for we may need it later
239-
lda remainder+1
240-
sbc divisor+1
241-
sta pztemp
242-
lda remainder+2
243-
sbc divisor+2
244-
bcc @skip ;if carry=0 then divisor didn't fit in yet
230+
rol dividend+1
231+
rol dividend+2
232+
rol remainder ;remainder lb & hb * 2 + msb from carry
233+
rol remainder+1
234+
rol remainder+2
235+
lda remainder
236+
sec
237+
sbc divisor ;substract divisor to see if it fits in
238+
tay ;lb result -> Y, for we may need it later
239+
lda remainder+1
240+
sbc divisor+1
241+
sta pztemp
242+
lda remainder+2
243+
sbc divisor+2
244+
bcc @skip ;if carry=0 then divisor didn't fit in yet
245245

246-
sta remainder+2 ;else save substraction result as new remainder,
247-
lda pztemp
248-
sta remainder+1
249-
sty remainder
250-
inc dividend ;and INCrement result cause divisor fit in 1 times
246+
sta remainder+2 ;else save substraction result as new remainder,
247+
lda pztemp
248+
sta remainder+1
249+
sty remainder
250+
inc dividend ;and INCrement result cause divisor fit in 1 times
251251

252252
@skip:
253253
dex
254-
bne @divloop
255-
rts
254+
bne @divloop
255+
rts
256256

257257
; from http://forum.6502.org/viewtopic.php?p=5789&sid=46a88a49579252ae3edcf53c0cd54f68#p5789
258258
;----------------------------------------------------------------

tools/format.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function format(line) {
5+
return line.trimEnd().replace(/^\t+/, (_) => ' '.repeat(4 * _.length));
6+
}
7+
8+
(function processFiles(directory) {
9+
const files = fs.readdirSync(directory);
10+
11+
files.forEach(file => {
12+
const filePath = path.join(directory, file);
13+
const stat = fs.statSync(filePath);
14+
15+
if (stat.isDirectory()) {
16+
processFiles(filePath);
17+
} else if (file.endsWith('.asm')) {
18+
const content = fs.readFileSync(filePath, 'utf8');
19+
fs.writeFileSync(filePath, content.split('\n').map(format).join('\n'));
20+
}
21+
});
22+
})(process.cwd());

0 commit comments

Comments
 (0)