repo_id stringlengths 5 115 | size int64 590 5.01M | file_path stringlengths 4 212 | content stringlengths 590 5.01M |
|---|---|---|---|
xem/nes | 2,397 | nes-test-roms/nes_instr_test/source/06-abs_xy.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $BD,"LDA a,X" ; AXY = a,XY
entry $B9,"LDA a,Y"
entry $BC,"LDY a,X"
entry $BE,"LDX a,Y"
entry $9D,"STA a,X" ; a,XY = A
entry $99,"STA a,Y"
entry $FE,"INC a,X" ; a,XY = op a,XY
entry $DE,"DEC a,X"
entry $1E,"ASL a,X"
entry $5E,"LSR a,X"
entry $3E,"ROL a,X"
entry $7E,"ROR a,X"
entry $7D,"ADC a,X" ; A = A op a,XY
entry $79,"ADC a,Y"
entry $FD,"SBC a,X"
entry $F9,"SBC a,Y"
entry $1D,"ORA a,X"
entry $19,"ORA a,Y"
entry $3D,"AND a,X"
entry $39,"AND a,Y"
entry $5D,"EOR a,X"
entry $59,"EOR a,Y"
entry $DD,"CMP a,X" ; A op a,XY
entry $D9,"CMP a,Y"
.ifndef OFFICIAL_ONLY
entry $1C,"TOP abs,X"
entry $3C,"TOP abs,X"
entry $5C,"TOP abs,X"
entry $7C,"TOP abs,X"
entry $DC,"TOP abs,X"
entry $FC,"TOP abs,X"
entry $1F,"SLO abs,X"
entry $3F,"RLA abs,X"
entry $5F,"SRE abs,X"
entry $7F,"RRA abs,X"
entry $9C,"SYA abs,X"
entry $DF,"DCP abs,X"
entry $FF,"ISC abs,X"
entry $1B,"SLO abs,Y"
entry $3B,"RLA abs,Y"
entry $5B,"SRE abs,Y"
entry $7B,"RRA abs,Y"
entry $9E,"SXA abs,Y"
entry $BF,"LAX abs,Y"
entry $DB,"DCP abs,Y"
entry $FB,"ISC abs,Y"
.endif
instrs_size = * - instrs
operand = $2FE
instr_template:
lda operand
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #1
jsr :+
lda #2
: sta in_x
eor #3
sta in_y
test_normal
rts
correct_checksums:
.dword $E9468A6E
.dword $7EE7005C
.dword $4FA75F54
.dword $19F17935
.dword $D7775153
.dword $A7756BFC
.dword $1DD34BF8
.dword $4CF654EB
.dword $167DC608
.dword $7989FBE2
.dword $70451E61
.dword $ED3AA6EF
.dword $E5328CF1
.dword $D287638B
.dword $6FC54B7A
.dword $8774BACC
.dword $05331E96
.dword $8DF442A1
.dword $71FB6ACE
.dword $5396E16A
.dword $0CA28045
.dword $C1F44777
.dword $A8D5E376
.dword $C32624B7
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $E893AB95
.dword $8946938D
.dword $5C5BC0E7
.dword $2B4CFDCF
.dword $973A2CEA
.dword $3203662F
.dword $92BD9042
.dword $BE321B27
.dword $72EDF2C3
.dword $98728C4F
.dword $0BD391C9
.dword $CAA64F06
.dword $F6E1B339
.dword $577C9968
.dword $980F0B56
|
xem/nes | 1,442 | nes-test-roms/nes_instr_test/source/07-ind_x.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $A1,"LDA (z,X)" ; A = (z,X)
entry $81,"STA (z,X)" ; (z,X) = A
entry $C1,"CMP (z,X)" ; A op (z,X)
entry $61,"ADC (z,X)" ; A = A op (z,X)
entry $E1,"SBC (z,X)"
entry $01,"ORA (z,X)"
entry $21,"AND (z,X)"
entry $41,"EOR (z,X)"
.ifndef OFFICIAL_ONLY
entry $03,"SLO (z,X)"
entry $23,"RLA (z,X)"
entry $43,"SRE (z,X)"
entry $63,"RRA (z,X)"
entry $83,"AAX (z,X)"
entry $A3,"LAX (z,X)"
entry $C3,"DCP (z,X)"
entry $E3,"ISC (z,X)"
.endif
instrs_size = * - instrs
address = <$FF
operand = $2FF
instr_template:
lda (address,x)
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
lda address
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #<operand
sta address
lda #>operand
sta <(address+1)
lda #<(operand+1)
sta <(address+2)
lda #>(operand+1)
sta <(address+3)
lda #0
jsr :+
lda #2
: sta in_x
test_normal
rts
correct_checksums:
.dword $B9D16BC6
.dword $DBC21F73
.dword $84827E50
.dword $FE9A8B04
.dword $9EEFAAD8
.dword $65F6C5BB
.dword $82C41B16
.dword $DC68A9E8
.dword $04A09668
.dword $417BDD05
.dword $9A40C4E4
.dword $0CB8C16E
.dword $EC8492F8
.dword $AFC77201
.dword $5BFDAB74
.dword $C62D3147
|
xem/nes | 1,510 | nes-test-roms/nes_instr_test/source/05-absolute.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $AD,"LDA a" ; AXY = a
entry $AE,"LDX a"
entry $AC,"LDY a"
entry $8D,"STA a" ; a = AXY
entry $8E,"STX a"
entry $8C,"STY a"
entry $EE,"INC a" ; a = op a
entry $CE,"DEC a"
entry $0E,"ASL a"
entry $4E,"LSR a"
entry $2E,"ROL a"
entry $6E,"ROR a"
entry $6D,"ADC a" ; A = A op a
entry $ED,"SBC a"
entry $0D,"ORA a"
entry $2D,"AND a"
entry $4D,"EOR a"
entry $CD,"CMP a" ; AXY op a
entry $2C,"BIT a"
entry $EC,"CPX a"
entry $CC,"CPY a"
.ifndef OFFICIAL_ONLY
entry $0C,"TOP abs"
entry $0F,"SLO abs"
entry $2F,"RLA abs"
entry $4F,"SRE abs"
entry $6F,"RRA abs"
entry $8F,"AAX abs"
entry $AF,"LAX abs"
entry $CF,"DCP abs"
entry $EF,"ISC abs"
.endif
instrs_size = * - instrs
operand = $2FE
instr_template:
lda operand
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $AB3E4F82
.dword $7B121231
.dword $E544DF3D
.dword $6C920797
.dword $D813DA7E
.dword $B656C54F
.dword $E6708F26
.dword $E7A8F852
.dword $2980FD5C
.dword $5CA561A6
.dword $354CDEB5
.dword $6C7D266C
.dword $86046BF5
.dword $999E9E48
.dword $DC562F7E
.dword $6BF08A00
.dword $D2A32FD6
.dword $7DF1D50B
.dword $C0066908
.dword $751D8339
.dword $A451BD7A
.dword $ACE6BAE4
.dword $7CA30777
.dword $8254F5DE
.dword $A75B33F1
.dword $6DB4854B
.dword $466B9DCC
.dword $1D8ACEF5
.dword $E44BA262
.dword $BD2619BF
|
xem/nes | 1,128 | nes-test-roms/nes_instr_test/source/11-special.s | CUSTOM_IRQ=1
.include "shell.inc"
irq: pla
pha
rti
jmp_6ff:
.byte $6C ; JMP ($6FF) (to avoid warning)
.word $6FF
main:
setb SNDMODE,$40 ; disable frame IRQ
set_test 3,"JMP ($6FF) should get high byte from $600"
setb $6FF,$F0
setb $600,$07
setb $700,$06
setb $7F0,$E8 ; INX
setb $7F1,$60 ; RTS
setb $6F0,$60 ; RTS
ldx #0
jsr jmp_6ff
cpx #1
jne test_failed
set_test 4,"RTS should return to addr+1"
lda #>:+
pha
lda #<:+
pha
ldx #0
rts
inx
: inx
inx
cpx #1
jne test_failed
set_test 5,"RTI should return to addr"
lda #>:+
pha
lda #<:+
pha
ldx #0
php
rti
inx
: inx
inx
cpx #2
jne test_failed
set_test 6,"JSR should push addr of next instr - 1"
setb $6FE,$20 ; JSR
setb $6FF,<:+
setb $700,>:+
jmp $6FE
: pla
cmp #$00
jne test_failed
pla
cmp #$07
jne test_failed
set_test 7,"BRK should push status with bits 4 and 5 set"
lda #$00
pha
plp
brk
nop
cmp #$30
jne test_failed
lda #$FF
pha
plp
brk
nop
cmp #$FF
jne test_failed
set_test 8,"BRK should push address BRK + 2"
ldx #1
brk
inx
inx
cpx #2
jne test_failed
jmp tests_passed
|
xem/nes | 1,565 | nes-test-roms/nes_instr_test/source/03-zero_page.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $A5,"LDA z" ; AXY = z
entry $A6,"LDX z"
entry $A4,"LDY z"
entry $85,"STA z" ; z = AXY
entry $86,"STX z"
entry $84,"STY z"
entry $E6,"INC z" ; z = op z
entry $C6,"DEC z"
entry $06,"ASL z"
entry $46,"LSR z"
entry $26,"ROL z"
entry $66,"ROR z"
entry $65,"ADC z" ; A = A op z
entry $E5,"SBC z"
entry $05,"ORA z"
entry $25,"AND z"
entry $45,"EOR z"
entry $24,"BIT z" ; AXY op z
entry $C5,"CMP z"
entry $E4,"CPX z"
entry $C4,"CPY z"
.ifndef OFFICIAL_ONLY
entry $04,"DOP z"
entry $44,"DOP z"
entry $64,"DOP z"
entry $07,"SLO z"
entry $27,"RLA z"
entry $47,"SRE z"
entry $67,"RRA z"
entry $87,"AAX z"
entry $A7,"LAX z"
entry $C7,"DCP z"
entry $E7,"ISC z"
.endif
instrs_size = * - instrs
operand = <$FE
instr_template:
lda <operand
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $AB3E4F82
.dword $7B121231
.dword $E544DF3D
.dword $6C920797
.dword $D813DA7E
.dword $B656C54F
.dword $E6708F26
.dword $E7A8F852
.dword $2980FD5C
.dword $5CA561A6
.dword $354CDEB5
.dword $6C7D266C
.dword $86046BF5
.dword $999E9E48
.dword $DC562F7E
.dword $6BF08A00
.dword $D2A32FD6
.dword $C0066908
.dword $7DF1D50B
.dword $751D8339
.dword $A451BD7A
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $7CA30777
.dword $8254F5DE
.dword $A75B33F1
.dword $6DB4854B
.dword $466B9DCC
.dword $1D8ACEF5
.dword $E44BA262
.dword $BD2619BF
|
xem/nes | 1,326 | nes-test-roms/nes_instr_test/source/08-ind_y.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $B1,"LDA (z),Y" ; A = (z),Y
entry $91,"STA (z),Y" ; (z),Y = A
entry $D1,"CMP (z),Y" ; A op (z),Y
entry $11,"ORA (z),Y" ; A = A op (z),Y
entry $F1,"SBC (z),Y"
entry $71,"ADC (z),Y"
entry $31,"AND (z),Y"
entry $51,"EOR (z),Y"
.ifndef OFFICIAL_ONLY
entry $13,"SLO (z),Y"
entry $33,"RLA (z),Y"
entry $53,"SRE (z),Y"
entry $73,"RRA (z),Y"
entry $B3,"LAX (z),Y"
entry $D3,"DCP (z),Y"
entry $F3,"ISC (z),Y"
.endif
instrs_size = * - instrs
address = <$FF
operand = $2FF
instr_template:
lda (address),y
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
lda address
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #<operand
sta address
lda #>operand
sta <(address+1)
lda #0
jsr :+
lda #1
: sta in_y
test_normal
rts
correct_checksums:
.dword $A70CC617
.dword $C51FB2A2
.dword $9A5FD381
.dword $7B2B686A
.dword $80320709
.dword $E04726D5
.dword $9C19B6C7
.dword $C2B50439
.dword $1A7D3BB9
.dword $5FA670D4
.dword $849D6935
.dword $12656CBF
.dword $964F3A4A
.dword $452006A5
.dword $D8F09C96
|
xem/nes | 1,241 | nes-test-roms/nes_instr_test/source/02-immediate.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $A9,"LDA #n" ; AXY = #n
entry $A2,"LDX #n"
entry $A0,"LDY #n"
entry $69,"ADC #n" ; A = A op #n
entry $E9,"SBC #n"
entry $09,"ORA #n"
entry $29,"AND #n"
entry $49,"EOR #n"
entry $C9,"CMP #n" ; AXY op #n
entry $E0,"CPX #n"
entry $C0,"CPY #n"
.ifndef OFFICIAL_ONLY
entry $EB,"SBC #n"
entry $80,"DOP #n"
entry $82,"DOP #n"
entry $89,"DOP #n"
entry $C2,"DOP #n"
entry $E2,"DOP #n"
entry $0B,"AAC #n"
entry $2B,"AAC #n"
entry $4B,"ASR #n"
entry $6B,"ARR #n"
entry $AB,"ATX #n"
entry $CB,"AXS #n"
.endif
instrs_size = * - instrs
operand = instr+1
instr_template:
lda #0
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $AB3E4F82
.dword $7B121231
.dword $E544DF3D
.dword $86046BF5
.dword $999E9E48
.dword $DC562F7E
.dword $6BF08A00
.dword $D2A32FD6
.dword $7DF1D50B
.dword $751D8339
.dword $A451BD7A
.dword $999E9E48
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $ACE6BAE4
.dword $DC37BE89
.dword $DC37BE89
.dword $C07C3593
.dword $49618FA8
.dword $1D8ACEF5
.dword $1240499F
|
xem/nes | 1,363 | nes-test-roms/nes_instr_test/source/10-stack.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $48,"PHA"
entry $08,"PHP"
entry $68,"PLA"
entry $28,"PLP"
entry $9A,"TXS"
entry $BA,"TSX"
instrs_size = * - instrs
instr_template:
pha
jmp instr_done
instr_template_size = * - instr_template
values2:
.byte 0,$FF,$01,$02,$04,$08,$10,$20,$40,$80
values2_size = * - values2
zp_byte operand
.macro set_in
sta in_p
set_paxyso
; Clear bytes on stack
stx $17F
sty $180
stx $181
sty $1FE
stx $1FF
sty $100
stx $101
sty $102
.endmacro
zp_byte save
zp_byte save2
zp_byte save3
zp_byte save4
zp_byte save5
.macro check_out
php
sta save ; A
pla
sta save2 ; P
pla
sta save3 ; PLA
stx save4 ; X
tsx
stx save5 ; S
ldx saved_s
txs
; Output
tya
jsr update_crc_fast
lda save
jsr update_crc_fast
lda save2
jsr update_crc_fast
lda save3
jsr update_crc_fast
lda save4
jsr update_crc_fast
lda save5
jsr update_crc_fast
ldx in_s
dex
lda $100,x
jsr update_crc_fast
inx
lda $100,x
jsr update_crc_fast
inx
lda $100,x
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
; Values for SP
lda #$80
jsr :+
lda #$00
jsr :+
lda #$01
jsr :+
lda #$FF
jsr :+
lda #$FE
: sta in_s
test_normal
rts
correct_checksums:
.dword $AA53E72F
.dword $F46D6C3F
.dword $4B0D5E27
.dword $A1AB7B53
.dword $8A5B86A7
.dword $6157E3AF
|
xem/nes | 1,886 | nes-test-roms/nes_instr_test/source/04-zp_xy.s | ;CALIBRATE=1
.include "instr_test.inc"
instrs:
entry $B5,"LDA z,X" ; AXY = z,XY
entry $B4,"LDY z,X"
entry $B6,"LDX z,Y"
entry $95,"STA z,X" ; z,XY = AXY
entry $94,"STY z,X"
entry $96,"STX z,Y"
entry $F6,"INC z,X" ; z,XY = op z,XY
entry $D6,"DEC z,X"
entry $16,"ASL z,X"
entry $56,"LSR z,X"
entry $36,"ROL z,X"
entry $76,"ROR z,X"
entry $75,"ADC z,X" ; A = A op z,XY
entry $F5,"SBC z,X"
entry $15,"ORA z,X"
entry $35,"AND z,X"
entry $55,"EOR z,X"
entry $D5,"CMP z,X" ; A op z,XY
.ifndef OFFICIAL_ONLY
entry $14,"DOP z,X"
entry $34,"DOP z,X"
entry $54,"DOP z,X"
entry $74,"DOP z,X"
entry $D4,"DOP z,X"
entry $F4,"DOP z,X"
entry $17,"SLO z,X"
entry $37,"RLA z,X"
entry $57,"SRE z,X"
entry $77,"RRA z,X"
entry $D7,"DCP z,X"
entry $F7,"ISC z,X"
entry $97,"AAX z,Y"
entry $B7,"LAX z,Y"
.endif
instrs_size = * - instrs
operand = <$FE
instr_template:
lda <operand
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta <(operand+1)
lda values+2,y
sta <(operand+2)
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda <(operand+1)
jsr update_crc_fast
lda <((operand+2)&$FF)
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #1
jsr :+
lda #2
: sta in_x
eor #3
sta in_y
test_normal
rts
correct_checksums:
.dword $E9468A6E
.dword $4FA75F54
.dword $19F17935
.dword $D7775153
.dword $5054FA78
.dword $026E0DE7
.dword $1DD34BF8
.dword $4CF654EB
.dword $167DC608
.dword $7989FBE2
.dword $70451E61
.dword $ED3AA6EF
.dword $E5328CF1
.dword $6FC54B7A
.dword $05331E96
.dword $71FB6ACE
.dword $0CA28045
.dword $A8D5E376
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $EE62210F
.dword $E893AB95
.dword $8946938D
.dword $5C5BC0E7
.dword $2B4CFDCF
.dword $3203662F
.dword $92BD9042
.dword $27A8A6AF
.dword $F6E1B339
|
xem/nes | 2,073 | nes-test-roms/nes_instr_test/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data "STRINGS",{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing:
jmp init_crc
; Reports that all tests passed
tests_passed:
.ifndef BUILD_MULTI
jsr print_filename
print_str newline,"Passed"
.endif
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
.ifndef BUILD_MULTI
jsr print_filename
print_str newline,"Done"
.endif
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF as 1, in case it wasn't ever set
inx
bne :+
inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
.ifndef BUILD_MULTI
jsr print_filename
.endif
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
tya
pha
; Compare with complemented checksum
ldy #3
: lda (addr),y
sec
adc checksum,y
bne @wrong
dey
bpl :-
jsr reset_crc
pla
tay
pla
rts
@wrong: jsr print_newline
jsr print_crc
jsr print_newline
jmp test_failed
|
xem/nes | 2,481 | nes-test-roms/nes_instr_test/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr @nibble
pla
pha
and #$0F
jsr @nibble
pla
rts
@nibble:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
.ifnblank str2
jsr_with_addr print_str_addr,{.byte str,str2,0}
.else
jsr_with_addr print_str_addr,{.byte str,0}
.endif
.endmacro
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: Y
print_dec:
; Hundreds
cmp #10
blt @ones
cmp #100
blt @tens
ldx #'0'-1
: inx
sbc #100
bge :-
adc #100
jsr @digit
; Tens
@tens: sec
ldx #'0'-1
: inx
sbc #10
bge :-
adc #10
jsr @digit
; Ones
@ones: ora #'0'
jmp print_char
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
xem/nes | 1,322 | nes-test-roms/nes_instr_test/source/common/build_rom.s | ; Builds program as iNES ROM
.if 0 ; Options to set before .include "shell.inc":
CHR_RAM=1 ; Use CHR-RAM instead of CHR-ROM
CART_WRAM=1 ; Use mapper that supports 8K WRAM in cart
CUSTOM_MAPPER=n ; Specify mapper number
.endif
.ifndef CUSTOM_MAPPER
.ifdef CART_WRAM
CUSTOM_MAPPER = 2 ; UNROM
.else
CUSTOM_MAPPER = 0 ; NROM
.endif
.endif
;;;; iNES header
.ifndef CUSTOM_HEADER
.segment "HEADER"
.byte "NES",26
.ifdef CHR_RAM
.byte 2,0 ; 32K PRG, CHR RAM
.else
.byte 2,1 ; 32K PRG, 8K CHR
.endif
.byte CUSTOM_MAPPER*$10+$01 ; vertical mirroring
.endif
.ifndef CUSTOM_VECTORS
.segment "VECTORS"
.word 0,0,0, nmi, reset, irq
.endif
;;;; CHR-RAM/ROM
.ifdef CHR_RAM
.rodata
ascii_chr:
.incbin "ascii.chr"
ascii_chr_end:
.else
.segment "CHARS"
.incbin "ascii.chr"
.align $2000
.endif
;;;; Shell
.ifndef NEED_CONSOLE
NEED_CONSOLE=1
.endif
.include "shell.s"
std_reset:
lda #0
sta PPUCTRL
sta PPUMASK
jmp run_shell
init_runtime:
.ifdef CHR_RAM
; Load ASCII font into CHR RAM
ldy #0
sty PPUADDR
sty PPUADDR
ldx #<ascii_chr
stx addr
ldx #>ascii_chr
@page:
stx addr+1
: lda (addr),y
sta PPUDATA
iny
bne :-
inx
cpx #>ascii_chr_end
bne @page
.endif
rts
post_exit:
jsr clear_nvram
jmp forever
; User code goes in main code segment
.code
|
xem/nes | 3,669 | nes-test-roms/nes_instr_test/source/common/console.s | ; Scrolling text console with line wrapping, 30x29 characters.
; Buffers lines for speed. Will work even if PPU doesn't
; support scrolling (until text reaches bottom). Keeps border
; along bottom in case TV cuts it off.
;
; Defers most initialization until first newline, at which
; point it clears nametable and makes palette non-black.
;
; ** ASCII font must already be in CHR, and mirroring
; must be vertical or single-screen.
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs
console_margin = 1
console_buf_size = 32
console_width = console_buf_size - (console_margin*2)
zp_byte console_pos
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_buf_size
; Initializes console
console_init:
; Flag that console hasn't been initialized
setb console_scroll,-1
jmp console_clear_line_
; Hides console by blacking palette and disabling PPU.
; Preserved: A, X, Y
console_hide:
pha
jsr console_wait_vbl_
setb PPUMASK,0
lda #$0F
jsr console_load_palette_
pla
rts
console_wait_vbl_:
lda console_scroll
cmp #-1
jne wait_vbl_optional
; In case PPU doesn't support scrolling, start a
; couple of lines down
setb console_scroll,16
jsr console_hide
txa
pha
; Fill nametable with spaces
setb PPUADDR,$20
setb PPUADDR,$00
ldx #240
lda #' '
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
; Clear attributes
lda #0
ldx #$40
: sta PPUDATA
dex
bne :-
pla
tax
jmp console_show
; Shows console display
; Preserved: X, Y
console_show:
pha
jsr console_wait_vbl_
setb PPUMASK,PPUMASK_BG0
lda #$30 ; white
jsr console_load_palette_
jmp console_apply_scroll_
console_load_palette_:
pha
setb PPUADDR,$3F
setb PPUADDR,$00
setb PPUDATA,$0F ; black
pla
sta PPUDATA
sta PPUDATA
sta PPUDATA
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
stx console_temp
; Newline if buf full and next char isn't space
ldx console_pos
bpl :+
cmp #' '
beq @ignore_space
ldx console_temp
jsr console_newline
stx console_temp
ldx console_pos
:
; Write to buffer
sta console_buf+console_margin,x
dex
stx console_pos
@ignore_space:
ldx console_temp
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_clear_line_
; Scroll up 8 pixels and clear one line AHEAD
lda console_scroll
jsr console_add_8_to_scroll_
sta console_scroll
jsr console_add_8_to_scroll_
jsr console_flush_a
jmp console_apply_scroll_
; A = (A + 8) % 240
console_add_8_to_scroll_:
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_clear_line_:
stx console_temp
; Start new clear line
lda #' '
ldx #console_buf_size-1
: sta console_buf,x
dex
bpl :-
ldx #console_width-1
stx console_pos
ldx console_temp
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl_
jsr console_flush_
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
lda console_scroll
jsr console_add_8_to_scroll_
jsr console_add_8_to_scroll_
sta PPUSCROLL
pla
rts
console_flush_:
lda console_scroll
console_flush_a:
; Address line in nametable
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
sta PPUADDR
; Copy line
stx console_temp
ldx #console_buf_size-1
: lda console_buf,x
sta PPUDATA
dex
bpl :-
ldx console_temp
rts
|
xem/nes | 1,930 | nes-test-roms/nes_instr_test/source/common/build_nsf.s | ; Builds program as NSF music file
.ifndef NSF_SONG_COUNT
NSF_SONG_COUNT = 1
.endif
.ifndef CUSTOM_NSF_HEADER
.segment "HEADER"
.byte "NESM",26,1
.byte NSF_SONG_COUNT
.byte 1 ; start with first song
.word load_addr,reset,nsf_play
.endif
.segment "DMC"
load_addr:
.ifndef CUSTOM_NSF_VECTORS
.segment "VECTORS"
.word 0,0,0,nmi,internal_error,irq
.endif
.include "shell.s"
nv_res nsf_track,1
nv_res nsf_running,1
.ifdef EMPTY_NSF_PLAY
CUSTOM_NSF_PLAY = 1
nsf_play:
rts
.endif
std_reset:
sta nsf_track
; In case NSF player interrupts init with play,
; wait a while in init. If play interrupts, then
; we just use that play call to run program, and
; this is never resumed.
setb nsf_running,1
delay_msec 500
.ifndef CUSTOM_NSF_PLAY
nsf_play:
.endif
std_nsf_play:
php
bit nsf_running
bpl :+
plp
rts
: lda nsf_running
beq :+
; First call
setb nsf_running,0
delay_msec 20
jmp run_shell
; Player let init run too long before interrupting
; with play, or play call interrupted itself.
: setb nsf_running,$80
jsr clear_ram
jsr init_shell
print_str "NSF player called play recursively"
jmp internal_error
init_runtime:
rts
post_exit:
forever:
jmp forever
; Reports A in binary as high and low tones, with
; leading low tone for reference. Omits leading
; zeroes.
; Preserved: A, X, Y
play_byte:
pha
; Make low reference beep
clc
jsr @beep
; Remove high zero bits
sec
: rol a
bcc :-
; Play remaining bits
beq @zero
: jsr @beep
asl a
bne :-
@zero:
delay_msec 300
pla
rts
; Plays low/high beep based on carry
; Preserved: A, X, Y
@beep:
pha
; Set up square
lda #1
sta SNDCHN
sta $4001
sta $4003
adc #$FE ; period=$100 if carry, $1FF if none
sta $4002
; Fade volume
lda #$0F
: ora #$30
sta $4000
delay_msec 8
sec
sbc #$31
bpl :-
; Silence
sta SNDCHN
delay_msec 160
pla
rts
; User code goes in main code segment
.code
|
xem/nes | 1,451 | nes-test-roms/nes_instr_test/source/common/text_out.s | ; Text output as expanding zero-terminated string at text_out_base
; The final exit result byte is written here
final_result = $6000
; Text output is written here as an expanding
; zero-terminated string
text_out_base = $6004
bss_res text_out_temp
zp_res text_out_addr,2
init_text_out:
ldx #0
; Executing from $6000 already
lda #>init_text_out
bpl :+
; Disable if there's no RAM there
lda $6000
eor #$FF
sta $6000
cmp $6000
bne :+
; Disable if changes to $6000 affect $E000,
; as on my devcart
ldy $E000
eor #$FF
sta $6000 ; restore original data in RAM
cpy $E000 ; see if $E000 changed as well
bne :+
; Terminate output string
setb text_out_base,0
setb final_result,$80
; Signature that tells emulator data is valid
setb text_out_base-3,$DE
setb text_out_base-2,$B0
setb text_out_base-1,$61
ldx #>text_out_base
: stx text_out_addr+1
setb text_out_addr,<text_out_base
rts
; Sets final result byte in memory
set_final_result:
sta final_result
rts
; Writes character to text output
; A -> Character to write
; Preserved: A, X, Y
write_text_out:
sty text_out_temp
ldy text_out_addr+1
beq @off
; Write new terminator FIRST, then new char before it,
; in case emulator looks at string in middle of this routine.
ldy #1
pha
lda #0
sta (text_out_addr),y
dey
pla
sta (text_out_addr),y
inc text_out_addr
bne :+
inc text_out_addr+1
:
@off:
ldy text_out_temp
rts
|
xem/nes | 2,104 | nes-test-roms/nes_instr_test/source/common/ppu.s | ; PPU utilities
; Special tile images
tile_blank = 0
tile_color1 = 1
tile_color2 = 2
tile_solid = 3
tile_upper_left = 4
tile_upper_right = 5
tile_lower_left = 6
tile_lower_right = 7
tile_upper_left_lower_right = 8
bss_res ppu_not_present
; Sets PPUADDR to w
; Preserved: X, Y
.macro set_ppuaddr w
bit PPUSTATUS
setb PPUADDR,>w
setb PPUADDR,<w
.endmacro
; Delays by no more than n scanlines
.macro delay_scanlines n
.if CLOCK_RATE <> 1789773
.error "Currently only supports NTSC"
.endif
delay ((n)*341)/3
.endmacro
; Waits for VBL then disables PPU rendering.
; Preserved: A, X, Y
disable_rendering:
pha
jsr wait_vbl_optional
setb PPUMASK,0
pla
rts
; Fills first nametable with $00
; Preserved: Y
clear_nametable:
lda #0
jsr fill_screen
; Clear pattern table
ldx #64
: sta PPUDATA
dex
bne :-
rts
; Fills screen with tile A
; Preserved: A, Y
fill_screen:
ldx #$20
stx PPUADDR
ldx #$00
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
rts
; Fills palette with $0F
; Preserved: Y
clear_palette:
set_ppuaddr $3F00
ldx #$20
lda #$0F
: sta PPUDATA
dex
bne :-
; Fills OAM with $FF
; Preserved: Y
clear_oam:
lda #$FF
; Fills OAM with A
; Preserved: A, Y
fill_oam:
ldx #0
: sta SPRDATA
dex
bne :-
rts
; Initializes wait_vbl_optional. Must be called before
; using it.
.align 32
init_wait_vbl:
; Wait for VBL flag to be set, or ~60000
; clocks (2 frames) to pass
ldy #24
ldx #1
bit PPUSTATUS
: bit PPUSTATUS
bmi @set
dex
bne :-
dey
bpl :-
@set:
; Be sure flag didn't stay set (in case
; PPUSTATUS always has high bit set)
tya
ora PPUSTATUS
sta ppu_not_present
rts
; Same as wait_vbl, but returns immediately if PPU
; isn't working or doesn't support VBL flag
; Preserved: A, X, Y
.align 16
wait_vbl_optional:
bit ppu_not_present
bmi :++
; FALL THROUGH
; Clears VBL flag then waits for it to be set.
; Preserved: A, X, Y
wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
: rts
|
xem/nes | 5,082 | nes-test-roms/nes_instr_test/source/common/shell.s | ; Common routines and runtime
; Detect inclusion loops (otherwise ca65 goes crazy)
.ifdef SHELL_INCLUDED
.error "shell.s included twice"
.end
.endif
SHELL_INCLUDED = 1
; Number of clocks delay before reset is jumped to
.ifndef DEVCART_DELAY
DEVCART_DELAY = 0
.endif
;**** Special globals ****
; Temporary variables that ANY routine might modify, so
; only use them between routine calls.
temp = <$A
temp2 = <$B
temp3 = <$C
addr = <$E
.segment "NVRAM"
; Beginning of variables not cleared at startup
nvram_begin:
;**** Code segment setup ****
.ifndef NOT_FOR_DEVCART
; Move code to $E000
.segment "DMC"
.res $6000
.endif
; Devcart corrupts byte at $E000 when powering off
.code
nop
; Goes after all other read-only data, to avoid trailing zeroes
; from getting stripped off by devcart loader.
.segment "ROEND"
.byte $FF
; Cause support code to go AFTER user code, so that
; changes to support code don't move user code around.
.segment "CODE2"
; Any user code which runs off end might end up here,
; so catch that mistake.
nop ; in case there was three-byte opcode before this
nop
jmp internal_error
;**** Common routines ****
.include "macros.inc"
.include "neshw.inc"
.include "print.s"
.include "delay.s"
.include "crc.s"
.include "testing.s"
.ifdef NEED_CONSOLE
.include "console.s"
.else
; Stubs so code doesn't have to care whether
; console exists
console_init:
console_show:
console_hide:
console_print:
console_flush:
rts
.endif
.ifndef CUSTOM_PRINT
.include "text_out.s"
print_char_:
jsr write_text_out
jmp console_print
.endif
;**** Shell core ****
.ifndef CUSTOM_RESET
reset:
sei
jmp std_reset
.endif
; Sets up hardware then runs main
run_shell:
sei
cld ; unnecessary on NES, but might help on clone
ldx #$FF
txs
jsr init_shell
set_test $FF
jmp run_main
; Initializes shell
init_shell:
jsr clear_ram
jsr init_wait_vbl ; waits for VBL once here,
jsr wait_vbl_optional ; so only need to wait once more
jsr init_text_out
jsr init_testing
jsr init_runtime
jsr console_init
rts
; Runs main in consistent PPU/APU environment, then exits
; with code 0
run_main:
jsr pre_main
jsr main
lda #0
jmp exit
; Sets up environment for main to run in
pre_main:
.ifndef BUILD_NSF
jsr disable_rendering
setb PPUCTRL,0
jsr clear_palette
jsr clear_nametable
jsr clear_oam
.endif
lda #$34
pha
lda #0
tax
tay
jsr wait_vbl_optional
plp
sta SNDMODE
rts
.ifndef CUSTOM_EXIT
exit:
.endif
; Reports result and ends program
std_exit:
sei
cld
ldx #$FF
txs
.ifndef BUILD_NSF
ldx #0
stx PPUCTRL
.endif
jsr report_result
jmp post_exit
; Reports final result code in A
; Preserved: A
report_result:
pha
jsr :+
jsr play_byte
pla
jmp set_final_result
: jsr print_newline
jsr console_show
; 0: ""
cmp #1
bge :+
rts
:
; 1: "Failed"
bne :+
print_str {"Failed",newline}
rts
; n: "Failed #n"
: print_str "Failed #"
jsr print_dec
jsr print_newline
rts
;**** Other routines ****
; Reports internal error and exits program
internal_error:
print_str newline,"Internal error"
lda #255
jmp exit
.import __NVRAM_LOAD__, __NVRAM_SIZE__
; Clears $0-($100+S) and nv_ram_end-$7FF
clear_ram:
lda #0
; Main pages
tax
: sta 0,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x
inx
bne :-
; Stack except that above stack pointer
tsx
inx
: dex
sta $100,x
bne :-
; BSS except nvram
ldx #<__NVRAM_SIZE__
: sta __NVRAM_LOAD__,x
inx
bne :-
rts
; Clears nvram
clear_nvram:
ldx #<__NVRAM_SIZE__
beq @empty
lda #0
: dex
sta __NVRAM_LOAD__,x
bne :-
@empty:
rts
; Prints filename and newline, if available, otherwise nothing.
; Preserved: A, X, Y
print_filename:
.ifdef FILENAME_KNOWN
pha
jsr print_newline
setw addr,filename
jsr print_str_addr
jsr print_newline
pla
.endif
rts
.pushseg
.segment "STRINGS"
; Filename terminated with zero byte.
filename:
.ifdef FILENAME_KNOWN
.incbin "ram:rom.nes"
.endif
.byte 0
.popseg
;**** NSF-specific ****
.ifdef BUILD_NSF
bss_res nsf_activity,1
; Call periodically where there would otherwise be silence,
; so that NSF build won't be cut short in NSF player that
; detects silence.
; Preserved: A, X, Y
avoid_silent_nsf:
pha
lda nsf_activity
clc
adc #4
sta nsf_activity
sta $4011
pla
rts
init_wait_vbl:
wait_vbl_optional:
;wait_vbl: ; undefined so assembler error results if called
rts
.ifndef CUSTOM_IRQ
irq:
.endif
nmi:
jmp internal_error
;**** ROM-specific ****
.else ; .ifndef BUILD_NSF
.include "ppu.s"
avoid_silent_nsf:
play_byte:
rts
; Disables interrupts and loops forever
.ifndef CUSTOM_FOREVER
forever:
sei
lda #0
sta PPUCTRL
: beq :-
.endif
; Default NMI
.ifndef CUSTOM_NMI
zp_byte nmi_count
nmi:
inc nmi_count
rti
; Waits for NMI. Must be using NMI handler that increments
; nmi_count, with NMI enabled.
; Preserved: X, Y
wait_nmi:
lda nmi_count
: cmp nmi_count
beq :-
rts
.endif
; Default IRQ
.ifndef CUSTOM_IRQ
irq:
bit SNDCHN ; clear APU IRQ flag
rti
.endif
.endif
|
xem/nes | 3,443 | nes-test-roms/nes_instr_test/source/common/delay.s | ; Delays in CPU clocks, milliseconds, etc. All routines are re-entrant
; (no global data). No routines touch X or Y during execution.
; Code generated by macros is relocatable; it contains no JMPs to itself.
zp_byte delay_temp_ ; only written to
; Delays n clocks, from 2 to 16777215
; Preserved: A, X, Y, flags
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
delay_ (n)
.endmacro
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100 usec.
; Preserved: A, X, Y, flags
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: A, X, Y, flags
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
.align 64
; Delays A clocks + overhead
; Preserved: X, Y
; Time: A+25 clocks (including JSR)
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256 clocks + overhead
; Preserved: X, Y
; Time: A*256+16 clocks (including JSR)
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_11_clocks_:
: pha
lda #256-19-22
jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536 clocks + overhead
; Preserved: X, Y
; Time: A*65536+16 clocks (including JSR)
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_11_clocks_:
: pha
lda #256-19-22-13
jsr delay_a_25_clocks
lda #255
jsr delay_256a_11_clocks_
pla
clc
adc #-1
bne :-
rts
max_short_delay = 41
; delay_short_ macro jumps into these
.res (max_short_delay-12)/2,$EA ; NOP
delay_unrolled_:
rts
.macro delay_short_ n
.if n < 0 .or n = 1 .or n > max_short_delay
.error "Internal delay error"
.endif
.if n = 0
; nothing
.elseif n = 2
nop
.elseif n = 3
sta <delay_temp_
.elseif n = 4
nop
nop
.elseif n = 5
sta <delay_temp_
nop
.elseif n = 6
nop
nop
nop
.elseif n = 7
php
plp
.elseif n = 8
nop
nop
nop
nop
.elseif n = 9
php
plp
nop
.elseif n = 10
sta <delay_temp_
php
plp
.elseif n = 11
php
plp
nop
nop
.elseif n = 13
php
plp
nop
nop
nop
.elseif n & 1
sta <delay_temp_
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.macro delay_nosave_ n
; 65536+17 = maximum delay using delay_256a_11_clocks_
; 255+27 = maximum delay using delay_a_25_clocks
; 27 = minimum delay using delay_a_25_clocks
.if n > 65536+17
lda #^(n - 15)
jsr delay_65536a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (((n - 15) & $FFFF) + 2)
.elseif n > 255+27
lda #>(n - 15)
jsr delay_256a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (<(n - 15) + 2)
.elseif n >= 27
lda #<(n - 27)
jsr delay_a_25_clocks
.else
delay_short_ n
.endif
.endmacro
.macro delay_ n
.if n > max_short_delay
php
pha
delay_nosave_ (n - 14)
pla
plp
.else
delay_short_ n
.endif
.endmacro
|
xem/nes | 2,121 | nes-test-roms/nes_instr_test/source/common/instr_test_end.s | zp_byte instrs_idx
zp_byte failed_count
main: ldx #$A2
txs
jsr init_crc_fast
; Test each instruction
lda #0
@loop: sta instrs_idx
tay
jsr reset_crc
lda instrs,y
jsr test_instr
jsr check_result
lda instrs_idx
clc
adc #4
cmp #instrs_size
bne @loop
lda failed_count
jne test_failed
jmp tests_passed
; Check result of test
check_result:
.ifdef CALIBRATE
; Print correct CRC
jsr crc_off
print_str ".dword $"
ldx #0
: lda checksum,x
jsr print_hex
inx
cpx #4
bne :-
jsr print_newline
jsr crc_on
.else
; Verify CRC
ldx #3
ldy instrs_idx
: lda checksum,x
cmp correct_checksums,y
bne @wrong
iny
dex
bpl :-
.endif
rts
; Print failed opcode and name
@wrong:
ldy instrs_idx
lda instrs,y
jsr print_a
jsr play_byte
lda instrs+2,y
sta addr
lda instrs+3,y
sta addr+1
jsr print_str_addr
jsr print_newline
inc failed_count
rts
bss_res instr,instr_template_size
; Tests instr A
test_instr:
sta instr
jsr avoid_silent_nsf
; Copy rest of template
ldx #instr_template_size - 1
: lda instr_template,x
sta instr,x
dex
bne :-
; Disable and clear frame IRQ
lda #$40
sta SNDMODE
; Default stack
lda #$90
sta in_s
; Test with different flags
lda #$00
jsr test_flags
lda #$FF
jsr test_flags
rts
zp_byte operand_idx
test_flags:
sta in_p
ldy #values_size-1
: sty operand_idx
lda values,y
sta in_a
lda values+1,y
sta in_x
lda values+2,y
sta in_y
jsr test_values
ldy operand_idx
dey
bpl :-
rts
.ifndef values2
values2 = values
values2_size = values_size
.endif
.macro test_normal
zp_byte a_idx
zp_byte saved_s
tsx
stx saved_s
ldy #values2_size-1
inner: sty a_idx
lda values2,y
sta operand
set_in
.if 0
; P A X Y S O (z,x) (z),y
jsr print_p
jsr print_a
jsr print_x
jsr print_y
jsr print_s
lda operand
jsr print_a
.ifdef address
lda (address,x)
jsr print_a
lda (address),y
jsr print_a
.else
lda operand,x
jsr print_a
lda operand,y
jsr print_a
.endif
jsr print_newline
.endif
jmp instr
instr_done:
check_out
ldy a_idx
dey
bpl inner
ldx saved_s
txs
.endmacro
|
xem/nes | 1,277 | nes-test-roms/nes_instr_test/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: A, X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
jmp reset_crc
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
lda #$FF
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: A, X, Y
; Time: 357 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
pha
stx checksum_temp
eor checksum
ldx #8
@bit: lsr checksum+3
ror checksum+2
ror checksum+1
ror a
bcc :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
: dex
bne @bit
sta checksum
ldx checksum_temp
pla
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
; Print complement
ldx #3
: lda checksum,x
eor #$FF
jsr print_hex
dex
bpl :-
jmp crc_on
|
xem/nes | 1,835 | nes-test-roms/volume_tests/src/pads.s | ; Copyright (c) 2009 Damian Yerrick
;
; This work is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any
; damages arising from the use of this work.
;
; Permission is granted to anyone to use this work for any
; purpose, including commercial applications, and to alter it and
; redistribute it freely, subject to the following restrictions:
;
; 1. The origin of this work must not be misrepresented; you
; must not claim that you wrote the original work. If you use
; this work in a product, an acknowledgment in the product
; documentation would be appreciated but is not required.
; 2. Altered source versions must be plainly marked as such,
; and must not be misrepresented as being the original work.
; 3. This notice may not be removed or altered from any
; source distribution.
;
; The term "source" refers to the preferred form of a work for making
; changes to it.
JOY1 = $4016
JOY2 = $4017
.export read_pads
.importzp cur_keys, new_keys
read_pads:
; store the current keypress state to detect key-down later
lda cur_keys
sta 4
lda cur_keys+1
sta 5
; read the joypads twice
jsr read_pads_once
lda 0
sta 2
lda 1
sta 3
jsr read_pads_once
ldx #1
@fixupKeys:
; if the player's keys read out the same ways both times, update
lda 0,x
cmp 2,x
bne @dontUpdateGlitch
sta cur_keys,x
@dontUpdateGlitch:
lda 4,x ; A = keys that were down last frame
eor #$FF ; A = keys that were up last frame
and cur_keys,x ; A = keys down now and up last frame
sta new_keys,x
dex
bpl @fixupKeys
rts
read_pads_once:
lda #1
sta 0
sta 1
sta JOY1
lda #0
sta JOY1
loop:
lda JOY1
and #$03
cmp #1
rol 0
lda JOY2
and #$03
cmp #1
rol 1
bcc loop
rts
|
xem/nes | 4,397 | nes-test-roms/volume_tests/src/sound.s | ; Copyright (c) 2009 Damian Yerrick
;
; This work is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any
; damages arising from the use of this work.
;
; Permission is granted to anyone to use this work for any
; purpose, including commercial applications, and to alter it and
; redistribute it freely, subject to the following restrictions:
;
; 1. The origin of this work must not be misrepresented; you
; must not claim that you wrote the original work. If you use
; this work in a product, an acknowledgment in the product
; documentation would be appreciated but is not required.
; 2. Altered source versions must be plainly marked as such,
; and must not be misrepresented as being the original work.
; 3. This notice may not be removed or altered from any
; source distribution.
;
; The term "source" refers to the preferred form of a work for making
; changes to it.
.export init_sound, volume_test
.importzp retraces
SNDCHN = $4015
.segment "ZEROPAGE"
level4011: .res 1
.segment "CODE"
;;
; Initializes all sound channels.
;
.proc init_sound
ldx #$00
stx SNDCHN
lda #$0F
sta SNDCHN
lda #$30
sta $4000
sta $4004
sta $400C
lda #8
sta $4001
sta $4005
stx $4003
stx $4007
stx $400F
stx $4011
rts
.endproc
;;
.proc volume_test
; 1. square wave 1
; 2. square wave 1 + 2
; 3. triangle
; 4. noise
; 5. raw dac
lda #0
sta level4011
sta $4011
ldy #4
jsr wait_frames
loop4011:
lda level4011
sta $4011
ldy #0
jsr test_square_waves
ldy #1
jsr test_square_waves
jsr test_triangle_wave
ldy #2
jsr test_square_waves
jsr test_raw_4011
lda level4011
clc
adc #$30
bmi done
tax
jsr ramp_4011_to_x
jmp loop4011
done:
rts
.endproc
.proc ramp_4011_to_x
cpx level4011
beq done
bcc done
inc level4011
lda level4011
sta $4011
ldy #200
:
dey
bne :-
jmp ramp_4011_to_x
done:
rts
.endproc
;;
; y: nonzero if using $4004; zero if only using $4000
.proc test_square_waves
mask4000 = 0
mask4004 = 1
mask400C = 2
volumeCountdown = 3
duty = 4
cpy #1
beq mode1
cpy #2
beq mode2
; mode 0: one square wave, four duty cycles
ldy #$FF
sty mask4000
iny
sty mask4004
sty mask400C
jmp begin_test
mode1:
; two unison square waves, four duty cycles
ldy #$FF
sty mask4000
sty mask4004
iny
sty mask400C
jmp begin_test
mode2:
; one noise wave, two duty cycles
ldy #$FF
sty mask400C
iny
sty mask4000
sty mask4004
begin_test:
lda #$30
sta duty
doOneDuty:
lda #15
sta volumeCountdown
lda #$30
sta $4000
sta $4004
sta $400C
lda #111
sta $4002
sta $4006
lda duty
ora #$02
sta $400E
lda #0
sta $4003
sta $4007
sta $400F
ldy #8
jsr wait_frames
doOneVolume:
lda volumeCountdown
ora duty
and mask4000
sta $4000
lda volumeCountdown
ora duty
and mask4004
sta $4004
lda volumeCountdown
ora #$30
and mask400C
sta $400C
ldy #4
jsr wait_frames
dec volumeCountdown
bpl doOneVolume
; go to next duty
; in mode 0, 1: $30, $70, $B0, $F0
; in mode 2: $30, $F0
lda mask400C
and #$80
ora duty
clc
adc #$40
sta duty
bcc doOneDuty
rts
.endproc
.proc test_triangle_wave
lda #$00
sta $4008
ldy #8
jsr wait_frames
lda #$81
sta $4008
lda #55
sta $400A
lda #0
sta $400B
ldy #60
jsr wait_frames
lda #0
sta $4008
ldy #4
jsr wait_frames
rts
.endproc
.proc test_raw_4011
lda #<(65536-997)
sta 0
lda #>(65536-997)
sta 1
lda level4011
sta $4011
clc
adc #30
sta 2
ldy #8
jsr wait_frames
loop:
; The top and bottom halves of this wave are 896 cycles each.
; TOP HALF: 7 to move speaker, 889 to waste
ldx 2
stx $4011
ldy #890/5
:
dey
bne :-
; BOTTOM HALF: 7 to move speaker, 868 to waste, 21 to loop
lda level4011
sta $4011
ldy #865/5
:
dey
bne :-
lsr a
lsr a
sec
lda #0
adc 0
sta 0
lda #0
adc 1
sta 1
bcc loop
ldy #20
jsr wait_frames
waste12:
rts
.endproc
.proc wait_frames
lda retraces
:
cmp retraces
beq :-
dey
bne wait_frames
rts
.endproc
|
xem/nes | 2,196 | nes-test-roms/volume_tests/src/hello.s | ; Copyright (c) 2009 Damian Yerrick
;
; This work is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any
; damages arising from the use of this work.
;
; Permission is granted to anyone to use this work for any
; purpose, including commercial applications, and to alter it and
; redistribute it freely, subject to the following restrictions:
;
; 1. The origin of this work must not be misrepresented; you
; must not claim that you wrote the original work. If you use
; this work in a product, an acknowledgment in the product
; documentation would be appreciated but is not required.
; 2. Altered source versions must be plainly marked as such,
; and must not be misrepresented as being the original work.
; 3. This notice may not be removed or altered from any
; source distribution.
;
; The term "source" refers to the preferred form of a work for making
; changes to it.
.p02
PPUCTRL = $2000
PPUMASK = $2001
PPUSTATUS = $2002
PPUADDR = $2006
PPUDATA = $2007
OAM_DMA = $4014
P1 = $4016
P2 = $4017
.exportzp cur_keys, new_keys, retraces
.import read_pads
.import init_sound, volume_test
.segment "INESHDR"
.byt "NES", $1a
.byt 1, 1, 0, 0
.res 8
.segment "ZEROPAGE"
cur_keys: .res 2
new_keys: .res 2
retraces: .res 1
psg_sfx_state: .res 16
.segment "CODE"
nmi:
inc retraces
irq:
rti
reset:
sei
ldx #0
stx PPUCTRL
stx PPUMASK
dex
txs
lda #$40
sta P2
bit PPUSTATUS
cld ; no effect on NES; helps in generic 6502 debuggers
jsr init_sound
@waitvbl1:
bit PPUSTATUS
bpl @waitvbl1
lda #0
tax
@clrram:
sta 0,x
sta $100,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x
inx
bne @clrram
@waitvbl2:
bit PPUSTATUS
bpl @waitvbl2
; write palette
lda #$3F
sta PPUADDR
ldx #$00
stx PPUADDR
lda #$0D
sta PPUDATA
lda #$1A
sta PPUDATA
lda #$2A
sta PPUDATA
lda #$3A
sta PPUDATA
stx PPUADDR
stx PPUADDR
lda #%10000000
sta PPUCTRL
forever:
lda retraces
:
cmp retraces
beq :-
jsr read_pads
lda new_keys
bpl @not_p1A
jsr volume_test
@not_p1A:
jmp forever
.segment "VECTORS"
.addr nmi, reset, irq |
xem/nes | 4,339 | nes-test-roms/apu_test/source/7-dmc_basics.s | ; Verifies basic DMC operation
.include "apu_shell.inc"
; Delays n DMC sample bytes, assuming DMC is running at maximum rate
.macro delay_dmc n
delay 54*8 * (n)
.endmacro
main:
; Setup
setb chan_bit,$10 ; so should_be_* will work
setb $4012,<((dmc_sample-$C000)/$40)
setb $4010,$0F
delay 428*9
set_test 2,"DMC isn't working well enough to test further"
setb SNDCHN,$00
setb $4013,1 ; length = 17 bytes
setb SNDCHN,$10 ; start DMC
delay_dmc 10
jsr should_be_playing
delay_dmc 10
jsr should_be_silent
set_test 3,"Starting DMC should reload length from $4013"
setb SNDCHN,$00
setb $4013,1
setb SNDCHN,$10
delay_dmc 20
setb SNDCHN,$00
setb SNDCHN,$10 ; length should be 17 again
delay_dmc 10
jsr should_be_playing
delay_dmc 10
jsr should_be_silent
set_test 4,"Writing $10 to $4015 should restart DMC if previous sample finished"
setb SNDCHN,$10
delay_dmc 20 ; allow sample to finish
setb SNDCHN,$10 ; start another
jsr should_be_playing
set_test 5,"Writing $10 to $4015 should not affect DMC if previous sample is still playing"
setb SNDCHN,$10
delay_dmc 10
setb SNDCHN,$10 ; previous sample still playing, so this is ignored
jsr should_be_playing
delay_dmc 10
jsr should_be_silent
set_test 6,"Writing $00 to $4015 should stop current sample"
setb SNDCHN,$10
delay_dmc 10
setb SNDCHN,$00 ; stops sample immediately
jsr should_be_silent
set_test 7,"Changing $4013 shouldn't affect current sample length"
setb SNDCHN,$10 ; start 17-byte sample
setb $4013,2 ; length of next sample = 33 bytes
delay_dmc 20
setb SNDCHN,$10 ; start 33-byte sample
setb $4013,1 ; length of next sample = 17 bytes
delay_dmc 30
jsr should_be_playing
delay_dmc 6
jsr should_be_silent
set_test 8,"Shouldn't set DMC IRQ flag when flag is disabled"
setb $4010,$0F
setb SNDCHN,$10 ; start 17-byte sample
delay_dmc 20
lda $4015
jmi test_failed
set_test 9,"Should set IRQ flag when enabled and sample ends"
setb $4010,$8F
setb SNDCHN,$10 ; start 17-byte sample
lda $4015
jmi test_failed
delay_dmc 20
lda $4015
jpl test_failed
set_test 10,"Reading IRQ flag shouldn't clear it"
lda $4015
jpl test_failed
set_test 11,"Writing to $4015 should clear IRQ flag"
setb SNDCHN,$10
lda $4015
jmi test_failed
setb SNDCHN,0
set_test 12,"Disabling IRQ flag should clear it"
setb SNDCHN,$10
delay_dmc 20
lda $4015
jpl test_failed
setb $4010,$0F ; should clear IRQ flag
setb $4010,$8F ; shouldn't change it
lda $4015
jmi test_failed
set_test 13,"Looped sample shouldn't end until $00 is written to $4015"
setb $4010,$4F
setb SNDCHN,$10
delay_dmc 100
jsr should_be_playing
setb SNDCHN,$00
jsr should_be_silent
set_test 14,"Looped sample shouldn't ever set IRQ flag"
setb $4010,$CF
setb SNDCHN,$10
delay_dmc 100
lda $4015
jmi test_failed
setb SNDCHN,$00
lda $4015
jmi test_failed
set_test 15,"Clearing loop flag and then setting again shouldn't stop loop"
setb $4010,$CF
setb SNDCHN,$10
delay_dmc 17*3 + 10
setb $4010,$8F
setb $4010,$CF
delay_dmc 100
jsr should_be_playing
setb SNDCHN,$00
set_test 16,"Clearing loop flag should end sample once it reaches end"
setb $4010,$CF
setb SNDCHN,$10
delay_dmc 17*3 + 10
setb $4010,$8F
lda $4015
jmi test_failed
jsr should_be_playing
delay_dmc 10
lda $4015
jpl test_failed
jsr should_be_silent
set_test 17,"Looped sample should reload length from $4013 each time it reaches end"
setb $4010,$CF
setb SNDCHN,$10
delay_dmc 17*3 + 10
setb $4013,2
delay_dmc 10
setb $4010,$8F
delay_dmc 23
lda $4015
jmi test_failed
jsr should_be_playing
delay_dmc 10
lda $4015
jpl test_failed
jsr should_be_silent
set_test 18,"$4013=0 should give 1-byte sample"
setb $4010,$8F
setb $4013,0
setb SNDCHN,$10
delay_dmc 4
jsr should_be_silent
set_test 19,"There should be a one-byte buffer that's filled immediately if empty"
setb $4013,1
setb SNDCHN,$10
lda #$10
: and $4015
bne :-
delay_dmc 4
delay 30
setb $4013,0
setb SNDCHN,$10
lda $4015
and #$90
cmp #$80
jne test_failed
setb SNDCHN,$10
jsr should_be_playing
delay_dmc 4
jsr should_be_silent
jmp tests_passed
; Silent DMC sample so tests won't make any noise
.align $40
dmc_sample:
.res 33,$00
|
xem/nes | 1,207 | nes-test-roms/apu_test/source/4-jitter.s | ; Tests for APU clock jitter. Also tests basic timing of frame irq flag
; since it's needed to determine jitter.
.include "shell.inc"
; Returns current jitter in A. Takes an even number of clocks.
get_jitter:
delay 3 ; make routine an even number of clocks
setb SNDMODE,$40 ; clear frame irq flag
setb SNDMODE,$00 ; begin mode 0, frame irq enabled
delay 29827
lda SNDCHN ; read at 29831
and #$40
rts
main: set_test 2,"Frame irq is set too soon"
setb SNDMODE,$40 ; clear frame irq flag
setb SNDMODE,$00 ; begin mode 0, frame irq enabled
delay 29826
lda SNDCHN ; read at 29830
and #$40
jne test_failed
set_test 3,"Frame irq is set too late"
setb SNDMODE,$40 ; clear frame irq flag
setb SNDMODE,$00 ; begin mode 0, frame irq enabled
delay 29828
lda SNDCHN ; read at 29832
and #$40
jeq test_failed
set_test 4,"Even jitter not handled properly"
jsr get_jitter
sta <temp
delay 3 ; keep on even clocks
jsr get_jitter
cmp <temp
jne test_failed
set_test 5,"Odd jitter not handled properly"
jsr get_jitter
sta <temp
jsr get_jitter ; occurs on odd clock
cmp <temp
jeq test_failed
jmp tests_passed
|
xem/nes | 1,599 | nes-test-roms/apu_test/source/1-len_ctr.s | ; Tests length counter operation for the four main channels
.include "apu_shell.inc"
main: test_main_chans test
jmp tests_passed
test:
set_test 2,"Problem with length counter load or $4015"
mov $4015,chan_bit ; enable channel
setb {$4003,x},len_2 ; load length
jsr should_be_playing
set_test 3,"Problem with length table, timing, or $4015"
delay_msec 30
jsr should_be_silent ; length should have reached 0 by now
set_test 4,"Writing $80 to $4017 should clock length immediately"
setb $4017,0
setb {$4003,x},len_2
setb $4017,$80 ; should clock length immediately
setb $4017,$80 ; should clock length immediately
jsr should_be_silent
set_test 5,"Writing 0 to $4017 shouldn't clock length immediately"
setb {$4003,x},len_2
setb $4017,0 ; shouldn't clock length
setb $4017,0 ; shouldn't clock length
jsr should_be_playing
set_test 6,"Disabling via $4015 should clear length counter"
setb {$4003,x},len_2
setb $4015,0 ; should clear length immediately
jsr should_be_silent
mov $4015,chan_bit
jsr should_be_silent ; length should still be clear
set_test 7,"When disabled via $4015, length shouldn't allow reloading"
setb $4015,0
setb {$4003,x},len_2 ; shouldn't reload length
jsr should_be_silent
mov $4015,chan_bit
jsr should_be_silent ; length should still be clear
set_test 8,"Halt bit should suspend length clocking"
setb {$4000,x},halt ; halt length
setb {$4003,x},len_2
setb $4017,$80 ; attempt to clock length twice
setb $4017,$80
jsr should_be_playing
rts
|
xem/nes | 1,491 | nes-test-roms/apu_test/source/5-len_timing.s | ; Verifies timing of length counter clocks in both modes
.include "apu_shell.inc"
main: test_main_chans test_chan
jmp tests_passed
.macro test len,clk,mode,time
jsr sync_apu
delay 3
setb {$4003,x},len
setb SNDMODE,clk*$C0 ; optionally clock length
lda #mode
sta SNDMODE ; begin mode
delay time-4
lda SNDCHN ; read at time
and chan_bit
.endmacro
test_chan:
set_test 2,"First length of mode 0 is too soon"
test len_2,1,0,14915
jeq chan_failed
set_test 3,"First length of mode 0 is too late"
test len_2,1,0,14916
jne chan_failed
set_test 4,"Second length of mode 0 is too soon"
test len_2,0,0,29831
jeq chan_failed
set_test 5,"Second length of mode 0 is too late"
test len_2,0,0,29832
jne chan_failed
set_test 6,"Third length of mode 0 is too soon"
test len_4,1,0,44745
jeq chan_failed
set_test 7,"Third length of mode 0 is too late"
test len_4,1,0,44746
jne chan_failed
set_test 8,"First length of mode 1 is too soon"
test len_2,0,$80,14915
jeq chan_failed
set_test 9,"First length of mode 1 is too late"
test len_2,0,$80,14916
jne chan_failed
set_test 10,"Second length of mode 1 is too soon"
test len_4,1,$80,37283
jeq chan_failed
set_test 11,"Second length of mode 1 is too late"
test len_4,1,$80,37284
jne chan_failed
set_test 12,"Third length of mode 1 is too soon"
test len_4,0,$80,52197
jeq chan_failed
set_test 13,"Third length of mode 1 is too late"
test len_4,0,$80,52198
jne chan_failed
rts
|
xem/nes | 1,852 | nes-test-roms/apu_test/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data "RODATA",{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing = init_crc
; Reports that all tests passed
tests_passed:
jsr print_filename
print_str newline,"Passed"
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
jsr print_filename
print_str newline,"Done"
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF as 1, in case it wasn't ever set
inx
bne :+
inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
jsr print_filename
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
jsr is_crc_
bne :+
jsr reset_crc
pla
rts
: jsr print_newline
jsr print_crc
jmp test_failed
|
xem/nes | 2,841 | nes-test-roms/apu_test/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
zp_byte print_temp_
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr print_nibble_
pla
pha
and #$0F
jsr print_nibble_
pla
rts
print_nibble_:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints low 4 bits of A as single hex character
; Preserved: A, X, Y
print_nibble:
pha
and #$0F
jsr update_crc
jsr print_nibble_
pla
rts
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
jsr print_str_
.byte str
.ifnblank str2
.byte str2
.endif
.byte 0
.endmacro
print_str_:
sta print_temp_
pla
sta addr
pla
sta addr+1
jsr inc_addr
jsr print_str_addr
lda print_temp_
jmp (addr)
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: A, X, Y
print_dec:
pha
sta print_temp_
jsr update_crc
txa
pha
lda print_temp_
; Hundreds
cmp #10
blt @ones
cmp #100
blt @tens
ldx #'0'-1
: inx
sbc #100
bge :-
adc #100
jsr @digit
; Tens
@tens: sec
ldx #'0'-1
: inx
sbc #10
bge :-
adc #10
jsr @digit
; Ones
@ones: ora #'0'
jsr print_char
pla
tax
pla
rts
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
xem/nes | 3,089 | nes-test-roms/apu_test/source/common/shell_misc.s | ; Reports internal error and exits program
internal_error:
print_str newline,"Internal error"
lda #255
jmp exit
.import __NVRAM_LOAD__, __NVRAM_SIZE__
.macro fill_ram_ Begin, End
; Simpler to count from negative size up to 0,
; and adjust address downward to compensate
; for initial low byte in Y index
.local Neg_size
Neg_size = (Begin) - (End)
ldxy #(Begin) - <Neg_size
sty addr
stx addr+1
ldxy #Neg_size
: sta (addr),y
iny
bne :-
inc addr+1
inx
bne :-
.endmacro
; Clears 0 through ($100+S), $200 through __NVRAM_LOAD__-1, and
; __NVRAM_LOAD__+__NVRAM_SIZE__ through $7FF
clear_ram:
lda #0
bss_begin = $200
fill_ram_ bss_begin,__NVRAM_LOAD__
fill_ram_ __NVRAM_LOAD__+__NVRAM_SIZE__,$800
; Zero-page
tax
: sta 0,x
inx
bne :-
; Stack below S
tsx
inx
: dex
sta $100,x
bne :-
rts
nv_res unused_nv_var ; to avoid size=0
; Clears nvram
clear_nvram:
lda #0
fill_ram_ __NVRAM_LOAD__,__NVRAM_LOAD__+__NVRAM_SIZE__
rts
; Prints filename and newline, if available, otherwise nothing.
; Preserved: A, X, Y
print_filename:
.ifdef FILENAME_KNOWN
pha
jsr print_newline
setw addr,filename
jsr print_str_addr
jsr print_newline
pla
.endif
rts
.pushseg
.segment "RODATA"
; Filename terminated with zero byte.
filename:
.ifdef FILENAME_KNOWN
.incbin "ram:nes_temp"
.endif
.byte 0
.popseg
;**** ROM-specific ****
.ifndef BUILD_NSF
.include "ppu.s"
avoid_silent_nsf:
play_byte:
rts
; Disables interrupts and loops forever
.ifndef CUSTOM_FOREVER
forever:
sei
lda #0
sta PPUCTRL
: beq :-
.res $10,$EA ; room for code to run loader
.endif
; Default NMI
.ifndef CUSTOM_NMI
zp_byte nmi_count
zp_byte flags_from_nmi
zp_byte pclo_from_nmi
nmi: ; Record flags and PC low byte from stack
pla
sta flags_from_nmi
pla
sta pclo_from_nmi
pha
lda flags_from_nmi
pha
inc nmi_count
rti
; Waits for NMI. Must be using NMI handler that increments
; nmi_count, with NMI enabled.
; Preserved: X, Y
wait_nmi:
lda nmi_count
: cmp nmi_count
beq :-
rts
.endif
; Default IRQ
.ifndef CUSTOM_IRQ
zp_byte flags_from_irq
zp_byte pclo_from_irq
zp_byte irq_count
irq: ; Record flags and PC low byte from stack
pla
sta flags_from_irq
pla
sta pclo_from_irq
pha
lda flags_from_irq
pha
inc irq_count
bit SNDCHN ; clear frame IRQ flag
rti
.endif
.endif
; Reports A in binary as high and low tones, with
; leading low tone for reference. Omits leading
; zeroes. Doesn't hang if no APU is present.
; Preserved: A, X, Y
play_hex:
pha
; Make low reference beep
clc
jsr @beep
; Remove high zero bits
sec
: rol a
bcc :-
; Play remaining bits
beq @zero
: jsr @beep
asl a
bne :-
@zero:
delay_msec 300
pla
rts
; Plays low/high beep based on carry
; Preserved: A, X, Y
@beep:
pha
; Set up square
lda #1
sta SNDCHN
sta $4001
sta $4003
adc #$FE ; period=$100 if carry, $1FF if none
sta $4002
; Fade volume
lda #$0F
: ora #$30
sta $4000
delay_msec 8
sec
sbc #$31
bpl :-
; Silence
setb SNDCHN,0
delay_msec 160
pla
rts
|
xem/nes | 1,483 | nes-test-roms/apu_test/source/common/build_rom.s | ; Builds program as iNES ROM
; Default is 32K PRG and 8K CHR ROM, NROM (0)
.if 0 ; Options to set before .include "shell.inc":
CHR_RAM=1 ; Use CHR-RAM instead of CHR-ROM
CART_WRAM=1 ; Use mapper that supports 8K WRAM in cart
CUSTOM_MAPPER=n ; Specify mapper number
.endif
.ifndef CUSTOM_MAPPER
.ifdef CART_WRAM
CUSTOM_MAPPER = 2 ; UNROM
.else
CUSTOM_MAPPER = 0 ; NROM
.endif
.endif
;;;; iNES header
.ifndef CUSTOM_HEADER
.segment "HEADER"
.byte $4E,$45,$53,26 ; "NES" EOF
.ifdef CHR_RAM
.byte 2,0 ; 32K PRG, CHR RAM
.else
.byte 2,1 ; 32K PRG, 8K CHR
.endif
.byte CUSTOM_MAPPER*$10+$01 ; vertical mirroring
.endif
.ifndef CUSTOM_VECTORS
.segment "VECTORS"
.word -1,-1,-1, nmi, reset, irq
.endif
;;;; CHR-RAM/ROM
.ifdef CHR_RAM
.define CHARS "CHARS_PRG"
.segment CHARS
ascii_chr:
.segment "CHARS_PRG_ASCII"
.align $200
.incbin "ascii.chr"
ascii_chr_end:
.else
.define CHARS "CHARS"
.segment "CHARS_ASCII"
.align $200
.incbin "ascii.chr"
.res $1800
.endif
.segment CHARS
.res $10,0
;;;; Shell
.ifndef NEED_CONSOLE
NEED_CONSOLE=1
.endif
.segment "CODE"
.res $4000
.include "shell.s"
std_reset:
lda #0
sta PPUCTRL
sta PPUMASK
jmp run_shell
init_runtime:
.ifdef CHR_RAM
load_chr_ram
.endif
rts
post_exit:
jsr set_final_result
jsr play_hex
jmp forever
; This helps devcart recover after running test.
; It is never executed by test ROM.
.segment "LOADER"
.incbin "devcart.bin"
.code
.align 256
|
xem/nes | 5,404 | nes-test-roms/apu_test/source/common/console.s | ; Scrolling text console with word wrapping, 30x29 characters.
;
; * Defers PPU initialization until first flush/ newline.
; * Works even if PPU doesn't support scrolling.
; * Keeps border around edge of screen for TV overscan.
; * Requires vertical or single-screen mirroring.
; * Requires ASCII font in CHR.
.ifndef CONSOLE_COLOR
CONSOLE_COLOR = $30 ; white
.endif
console_screen_width = 32 ; if lower than 32, left-justifies
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs. OK if either/both are 0.
console_left_margin = 1
console_right_margin = 1
console_width = console_screen_width - console_left_margin - console_right_margin
zp_byte console_pos ; 0 to console_width
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_width
; Initializes console
console_init:
; Flag that console hasn't been initialized
setb console_scroll,-1
setb console_pos,0
rts
; Hides console by disabling PPU rendering and blacking out
; first four entries of palette.
; Preserved: A, X, Y
console_hide:
pha
jsr console_wait_vbl_
setb PPUMASK,0
lda #$0F
jsr console_load_palette_
pla
rts
; Shows console display
; Preserved: A, X, Y
console_show:
pha
lda #CONSOLE_COLOR
jsr console_show_custom_color_
pla
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
sty console_temp
ldy console_pos
cpy #console_width
beq console_full_
sta console_buf,y
iny
sty console_pos
ldy console_temp
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_scroll_up_
setb console_pos,0
pla
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_apply_scroll_
pla
rts
;**** Internal routines ****
console_full_:
ldy console_temp
; Line is full
; If space, treat as newline
cmp #' '
beq console_newline
; Wrap current line at appropriate point
pha
tya
pha
jsr console_wrap_
pla
tay
pla
jmp console_print
; Inserts newline into buffer at appropriate position, leaving
; next line ready in buffer
; Preserved: X, console_temp
console_wrap_:
; Find beginning of last word
ldy #console_width
lda #' '
: dey
bmi console_newline
cmp console_buf,y
bne :-
; y = 0 to console_width-1
; Flush through current word and put remaining
; in buffer for next line
jsr console_wait_vbl_
; Time to last PPU write: 207 + 32*(26 + 10)
lda console_scroll
jsr console_set_ppuaddr_
stx console_pos ; save X
ldx #0
; Print everything before last word
: lda console_buf,x
sta PPUDATA
inx
dey
bpl :-
; x = 1 to console_width
; Move last word to beginning of buffer, and
; print spaces for rest of line
ldy #0
beq :++
: lda #' '
sta PPUDATA
lda console_buf,x
inx
sta console_buf,y
iny
: cpx #console_width
bne :--
ldx console_pos ; restore X
; Append new text after that
sty console_pos
; FALL THROUGH
; Scrolls up 8 pixels and clears one line BELOW new line
; Preserved: X, console_temp
console_scroll_up_:
; Scroll up 8 pixels
lda console_scroll
jsr console_add_8_to_scroll_
sta console_scroll
; Clear line AFTER that on screen
jsr console_add_8_to_scroll_
jsr console_set_ppuaddr_
ldy #console_width
lda #' '
: sta PPUDATA
dey
bne :-
; FALL THROUGH
; Applies current scrolling position to PPU
; Preserved: X, Y, console_temp
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
lda console_scroll
jsr console_add_8_to_scroll_
jsr console_add_8_to_scroll_
sta PPUSCROLL
rts
; Sets PPU address for row
; In: A = scroll position
; Preserved: X, Y
console_set_ppuaddr_:
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
ora #console_left_margin
sta PPUADDR
rts
; A = (A + 8) % 240
; Preserved: X, Y
console_add_8_to_scroll_:
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_show_custom_color_:
pha
jsr console_wait_vbl_
setb PPUMASK,PPUMASK_BG0
pla
jsr console_load_palette_
jmp console_apply_scroll_
console_load_palette_:
pha
setb PPUADDR,$3F
setb PPUADDR,$00
setb PPUDATA,$0F ; black
pla
sta PPUDATA
sta PPUDATA
sta PPUDATA
rts
; Initializes PPU if necessary, then waits for VBL
; Preserved: A, X, Y, console_temp
console_wait_vbl_:
lda console_scroll
cmp #-1
bne @already_initialized
; Deferred initialization of PPU until first use of console
; In case PPU doesn't support scrolling, start a
; couple of lines down
setb console_scroll,16
jsr console_hide
tya
pha
; Fill nametable with spaces
setb PPUADDR,$20
setb PPUADDR,$00
ldy #240
lda #' '
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dey
bne :-
; Clear attributes
lda #0
ldy #$40
: sta PPUDATA
dey
bne :-
pla
tay
jsr console_show
@already_initialized:
jmp wait_vbl_optional
; Flushes current line
; Preserved: X, Y
console_flush_:
lda console_scroll
jsr console_set_ppuaddr_
sty console_temp
; Copy line
ldy #0
beq :++
: lda console_buf,y
sta PPUDATA
iny
: cpy console_pos
bne :--
ldy console_temp
rts
|
xem/nes | 1,096 | nes-test-roms/apu_test/source/common/text_out.s | ; Text output as expanding zero-terminated string at text_out_base
; The final exit result byte is written here
final_result = $6000
; Text output is written here as an expanding
; zero-terminated string
text_out_base = $6004
bss_res text_out_temp
zp_res text_out_addr,2
init_text_out:
ldx #0
; Put valid data first
setb text_out_base,0
lda #$80
jsr set_final_result
; Now fill in signature that tells emulator there's
; useful data there
setb text_out_base-3,$DE
setb text_out_base-2,$B0
setb text_out_base-1,$61
ldx #>text_out_base
stx text_out_addr+1
setb text_out_addr,<text_out_base
rts
; Sets final result byte in memory
set_final_result:
sta final_result
rts
; Writes character to text output
; In: A=Character to write
; Preserved: A, X, Y
write_text_out:
sty text_out_temp
; Write new terminator FIRST, then new char before it,
; in case emulator looks at string in middle of this routine.
ldy #1
pha
lda #0
sta (text_out_addr),y
dey
pla
sta (text_out_addr),y
inc text_out_addr
bne :+
inc text_out_addr+1
:
ldy text_out_temp
rts
|
xem/nes | 3,060 | nes-test-roms/apu_test/source/common/ppu.s | ; PPU utilities
bss_res ppu_not_present
; Sets PPUADDR to w
; Preserved: X, Y
.macro set_ppuaddr w
bit PPUSTATUS
setb PPUADDR,>w
setb PPUADDR,<w
.endmacro
; Delays by no more than n scanlines
.macro delay_scanlines n
.if CLOCK_RATE <> 1789773
.error "Currently only supports NTSC"
.endif
delay ((n)*341)/3
.endmacro
; Waits for VBL then disables PPU rendering.
; Preserved: A, X, Y
disable_rendering:
pha
jsr wait_vbl_optional
setb PPUMASK,0
pla
rts
; Fills first nametable with $00
; Preserved: Y
clear_nametable:
ldx #$20
bne clear_nametable_
clear_nametable2:
ldx #$24
clear_nametable_:
lda #0
jsr fill_screen_
; Clear pattern table
ldx #64
: sta PPUDATA
dex
bne :-
rts
; Fills screen with tile A
; Preserved: A, Y
fill_screen:
ldx #$20
bne fill_screen_
; Same as fill_screen, but fills other nametable
fill_screen2:
ldx #$24
fill_screen_:
stx PPUADDR
ldx #$00
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
rts
; Fills palette with $0F
; Preserved: Y
clear_palette:
set_ppuaddr $3F00
ldx #$20
lda #$0F
: sta PPUDATA
dex
bne :-
; Fills OAM with $FF
; Preserved: Y
clear_oam:
lda #$FF
; Fills OAM with A
; Preserved: A, Y
fill_oam:
ldx #0
stx SPRADDR
: sta SPRDATA
dex
bne :-
rts
; Initializes wait_vbl_optional. Must be called before
; using it.
.align 32
init_wait_vbl:
; Wait for VBL flag to be set, or ~60000
; clocks (2 frames) to pass
ldy #24
ldx #1
bit PPUSTATUS
: bit PPUSTATUS
bmi @set
dex
bne :-
dey
bpl :-
@set:
; Be sure flag didn't stay set (in case
; PPUSTATUS always has high bit set)
tya
ora PPUSTATUS
sta ppu_not_present
rts
; Same as wait_vbl, but returns immediately if PPU
; isn't working or doesn't support VBL flag
; Preserved: A, X, Y
.align 16
wait_vbl_optional:
bit ppu_not_present
bmi :++
; FALL THROUGH
; Clears VBL flag then waits for it to be set.
; Preserved: A, X, Y
wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
: rts
.macro check_ppu_region_ Len
; Delays since VBL began
jsr wait_vbl_optional ; 10 average
delay Len - 18 - 200
lda PPUSTATUS ; 4
bmi @ok ; 2
delay 200
; Next VBL should roughly begin here if it's the
; one we are detecting
delay 200
lda PPUSTATUS ; 2
bpl @ok
.endmacro
check_ppu_region:
.ifndef REGION_FREE
.ifdef PAL_ONLY
check_ppu_region_ 29781
print_str {newline,"Note: This test is meant for PAL NES only.",newline,newline}
.endif
.ifdef NTSC_ONLY
check_ppu_region_ 33248
print_str {newline,"Note: This test is meant for NTSC NES only.",newline,newline}
.endif
.endif
@ok: rts
; Loads ASCII font into CHR RAM and fills rest with $FF
.macro load_chr_ram
bit PPUSTATUS
setb PPUADDR,0
setb PPUADDR,0
; Copy ascii_chr to 0
setb addr,<ascii_chr
ldx #>ascii_chr
ldy #0
@page:
stx addr+1
: lda (addr),y
sta PPUDATA
iny
bne :-
inx
cpx #>ascii_chr_end
bne @page
; Fill rest
lda #$FF
: sta PPUDATA
iny
bne :-
inx
cpx #$20
bne :-
.endmacro
|
xem/nes | 2,698 | nes-test-roms/apu_test/source/common/shell.s | ; Shell that sets up testing framework and calls main
; Detect inclusion loops (otherwise ca65 goes crazy)
.ifdef SHELL_INCLUDED
.error "shell.s included twice"
.end
.endif
SHELL_INCLUDED = 1
; Temporary variables that ANY routine might modify, so
; only use them between routine calls.
temp = <$A
temp2 = <$B
temp3 = <$C
addr = <$E
ptr = addr
; Move code from $C000 to $E200, to accommodate my devcarts
.segment "CODE"
.res $2200
; Put shell code after user code, so user code is in more
; consistent environment
.segment "CODE2"
; Any user code which runs off end might end up here,
; so catch that mistake.
nop ; in case there was three-byte opcode before this
nop
jmp internal_error
;**** Common routines ****
.include "macros.inc"
.include "neshw.inc"
.include "delay.s"
.include "print.s"
.include "crc.s"
.include "testing.s"
;**** Shell core ****
.ifndef CUSTOM_RESET
reset:
sei
jmp std_reset
.endif
; Sets up hardware then runs main
run_shell:
init_cpu_regs
jsr init_shell
set_test $FF
jmp run_main
; Initializes shell without affecting current set_test values
init_shell:
jsr clear_ram
jsr init_wait_vbl ; waits for VBL once here,
jsr wait_vbl_optional ; so only need to wait once more
jsr init_text_out
jsr init_testing
jsr init_runtime
jsr console_init
rts
; Runs main in consistent PPU/APU environment, then exits
; with code 0
run_main:
jsr pre_main
jsr main
lda #0
jmp exit
; Sets up environment for main to run in
pre_main:
.ifndef BUILD_NSF
jsr disable_rendering
setb PPUCTRL,0
jsr clear_palette
jsr clear_nametable
jsr clear_nametable2
jsr clear_oam
.endif
; Clear APU registers
lda #0
sta $4015
ldx #$13
: sta $4000,x
dex
bpl :-
; CPU registers
lda #$34
pha
lda #0
tax
tay
jsr wait_vbl_optional
plp
sta SNDMODE
rts
.ifndef CUSTOM_EXIT
exit:
.endif
; Reports result and ends program
std_exit:
sta temp
init_cpu_regs
setb SNDCHN,0
lda temp
jsr report_result
pha
jsr check_ppu_region
pla
jmp post_exit
; Reports final result code in A
report_result:
jsr :+
jmp play_byte
: jsr print_newline
jsr console_show
; 0: ""
cmp #1
bge :+
rts
:
; 1: "Failed"
bne :+
print_str {"Failed",newline}
rts
; n: "Failed #n"
: print_str "Failed #"
jsr print_dec
jsr print_newline
rts
;**** Other routines ****
.include "shell_misc.s"
.ifdef NEED_CONSOLE
.include "console.s"
.else
; Stubs so code doesn't have to care whether
; console exists
console_init:
console_show:
console_hide:
console_print:
console_flush:
rts
.endif
.ifndef CUSTOM_PRINT
.include "text_out.s"
print_char_:
jsr write_text_out
jmp console_print
stop_capture:
rts
.endif
|
xem/nes | 3,437 | nes-test-roms/apu_test/source/common/delay.s | ; Delays in CPU clocks, milliseconds, etc. All routines are re-entrant
; (no global data). No routines touch X or Y during execution.
; Code generated by macros is relocatable; it contains no JMPs to itself.
zp_byte delay_temp_ ; only written to
; Delays n clocks, from 2 to 16777215
; Preserved: A, X, Y, flags
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
delay_ (n)
.endmacro
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100.
; Preserved: A, X, Y, flags
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: A, X, Y, flags
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
.align 64
; Delays A clocks + overhead
; Preserved: X, Y
; Time: A+25 clocks (including JSR)
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256 clocks + overhead
; Preserved: X, Y
; Time: A*256+16 clocks (including JSR)
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_11_clocks_:
: pha
lda #256-19-22
jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536 clocks + overhead
; Preserved: X, Y
; Time: A*65536+16 clocks (including JSR)
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_11_clocks_:
: pha
lda #256-19-22-13
jsr delay_a_25_clocks
lda #255
jsr delay_256a_11_clocks_
pla
clc
adc #-1
bne :-
rts
max_short_delay = 41
; delay_short_ macro jumps into these
.res (max_short_delay-12)/2,$EA ; NOP
delay_unrolled_:
rts
.macro delay_short_ n
.if n < 0 .or n = 1 .or n > max_short_delay
.error "Internal delay error"
.endif
.if n = 0
; nothing
.elseif n = 2
nop
.elseif n = 3
sta <delay_temp_
.elseif n = 4
nop
nop
.elseif n = 5
sta <delay_temp_
nop
.elseif n = 6
nop
nop
nop
.elseif n = 7
php
plp
.elseif n = 8
nop
nop
nop
nop
.elseif n = 9
php
plp
nop
.elseif n = 10
sta <delay_temp_
php
plp
.elseif n = 11
php
plp
nop
nop
.elseif n = 13
php
plp
nop
nop
nop
.elseif n & 1
sta <delay_temp_
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.macro delay_nosave_ n
; 65536+17 = maximum delay using delay_256a_11_clocks_
; 255+27 = maximum delay using delay_a_25_clocks
; 27 = minimum delay using delay_a_25_clocks
.if n > 65536+17
lda #^(n - 15)
jsr delay_65536a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (((n - 15) & $FFFF) + 2)
.elseif n > 255+27
lda #>(n - 15)
jsr delay_256a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (<(n - 15) + 2)
.elseif n >= 27
lda #<(n - 27)
jsr delay_a_25_clocks
.else
delay_short_ n
.endif
.endmacro
.macro delay_ n
.if n > max_short_delay
php
pha
delay_nosave_ (n - 14)
pla
plp
.else
delay_short_ n
.endif
.endmacro
|
xem/nes | 1,632 | nes-test-roms/apu_test/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: A, X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
jmp reset_crc
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
lda #$FF
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: A, X, Y
; Time: 357 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
pha
stx checksum_temp
eor checksum
ldx #8
@bit: lsr checksum+3
ror checksum+2
ror checksum+1
ror a
bcc :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
: dex
bne @bit
sta checksum
ldx checksum_temp
pla
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
; Print complement
ldx #3
: lda checksum,x
eor #$FF
jsr print_hex
dex
bpl :-
jmp crc_on
; EQ if checksum matches CRC
; Out: A=0 and EQ if match, A>0 and NE if different
; Preserved: X, Y
.macro is_crc crc
jsr_with_addr is_crc_,{.dword crc}
.endmacro
is_crc_:
tya
pha
; Compare with complemented checksum
ldy #3
: lda (ptr),y
sec
adc checksum,y
bne @wrong
dey
bpl :-
pla
tay
lda #0
rts
@wrong:
pla
tay
lda #1
rts
|
xem/nes | 1,061 | nes-test-roms/apu_reset/source/4017_written.s | ; At power, $4017 = $00.
; At reset, $4017 mode is unchanged, but IRQ inhibit
; flag is sometimes cleared.
CUSTOM_RESET=1
.include "shell.inc"
.include "run_at_reset.s"
nv_res log,4
reset:
setb $4015,$01
setb $4000,0
setb $4001,$7F
setb $4002,$FF
setb $4003,$28
delay 29831*2-5*6-9-7
lda $4015
sta log+0
lda $4015
sta log+1
delay 14887
lda $4015
sta log+2
lda $4015
sta log+3
jmp std_reset
main: jsr num_resets
bne first_reset
power:
set_test 2,"At power, $4017 should be written with $00"
lda log+0
and #$41
cmp #$41
jne test_failed
lda log+1
and #$01
jne test_failed
jsr prompt_to_reset
setb $4017,$40
jmp wait_reset
first_reset:
set_test 3,"At reset, $4017 should should be rewritten with last value written"
cmp #2
beq second_reset
lda log+0
and #$01
jeq test_failed
lda log+1
and #$01
jne test_failed
jsr prompt_to_reset
setb $4017,$80 ; put in other mode this time
jmp wait_reset
second_reset:
lda log+2
and #$01
jeq test_failed
lda log+3
and #$01
jne test_failed
jmp tests_passed
|
xem/nes | 1,218 | nes-test-roms/apu_reset/source/works_immediately.s | ; At power and reset, $4017, $4015, and length counters work
; immediately.
CUSTOM_RESET=1
.include "shell.inc"
.include "run_at_reset.s"
nv_res log,4
reset:
; Triangle linear counter
setb $4008,$FF
setb $4017,$80
setb $4015,$0F
; Setup channels
setb $4000,$00
setb $4001,$7F
setb $4002,$FF
setb $4003,$28
setb $4004,$00
setb $4005,$7F
setb $4006,$FF
setb $4007,$28
setb $4008,$7F
setb $400A,$FF
setb $400B,$28
setb $400C,$00
setb $400E,$00
setb $400F,$28
setb $4010,$8F
setb $4013,1
setb $4015,$1F
delay 6000
lda $4015
sta log+0
delay 2000
lda $4015
sta log+1
delay 29831*2 - 18*6 - 8016 + 14907 - 180
lda $4015
sta log+2
delay 200
lda $4015
sta log+3
jmp std_reset
main: jsr num_resets
bne first_reset
power: set_test 2,"At power, writes should work immediately"
jsr test
jsr prompt_to_reset
setb $4013,2
setb $4015,$00
setb $4017,$00
jmp wait_reset
first_reset:
set_test 3,"At reset, writes should work immediately"
jsr test
jmp tests_passed
test:
lda log+0
and #$DF
cmp #$1F
jne test_failed
lda log+1
and #$DF
cmp #$8F
jne test_failed
lda log+2
and #$4F
cmp #$0F
jne test_failed
lda log+3
and #$0F
jne test_failed
rts
|
xem/nes | 1,852 | nes-test-roms/apu_reset/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data "RODATA",{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing = init_crc
; Reports that all tests passed
tests_passed:
jsr print_filename
print_str newline,"Passed"
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
jsr print_filename
print_str newline,"Done"
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF as 1, in case it wasn't ever set
inx
bne :+
inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
jsr print_filename
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
jsr is_crc_
bne :+
jsr reset_crc
pla
rts
: jsr print_newline
jsr print_crc
jmp test_failed
|
xem/nes | 2,841 | nes-test-roms/apu_reset/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
zp_byte print_temp_
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr print_nibble_
pla
pha
and #$0F
jsr print_nibble_
pla
rts
print_nibble_:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints low 4 bits of A as single hex character
; Preserved: A, X, Y
print_nibble:
pha
and #$0F
jsr update_crc
jsr print_nibble_
pla
rts
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
jsr print_str_
.byte str
.ifnblank str2
.byte str2
.endif
.byte 0
.endmacro
print_str_:
sta print_temp_
pla
sta addr
pla
sta addr+1
jsr inc_addr
jsr print_str_addr
lda print_temp_
jmp (addr)
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: A, X, Y
print_dec:
pha
sta print_temp_
jsr update_crc
txa
pha
lda print_temp_
; Hundreds
cmp #10
blt @ones
cmp #100
blt @tens
ldx #'0'-1
: inx
sbc #100
bge :-
adc #100
jsr @digit
; Tens
@tens: sec
ldx #'0'-1
: inx
sbc #10
bge :-
adc #10
jsr @digit
; Ones
@ones: ora #'0'
jsr print_char
pla
tax
pla
rts
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
xem/nes | 3,089 | nes-test-roms/apu_reset/source/common/shell_misc.s | ; Reports internal error and exits program
internal_error:
print_str newline,"Internal error"
lda #255
jmp exit
.import __NVRAM_LOAD__, __NVRAM_SIZE__
.macro fill_ram_ Begin, End
; Simpler to count from negative size up to 0,
; and adjust address downward to compensate
; for initial low byte in Y index
.local Neg_size
Neg_size = (Begin) - (End)
ldxy #(Begin) - <Neg_size
sty addr
stx addr+1
ldxy #Neg_size
: sta (addr),y
iny
bne :-
inc addr+1
inx
bne :-
.endmacro
; Clears 0 through ($100+S), $200 through __NVRAM_LOAD__-1, and
; __NVRAM_LOAD__+__NVRAM_SIZE__ through $7FF
clear_ram:
lda #0
bss_begin = $200
fill_ram_ bss_begin,__NVRAM_LOAD__
fill_ram_ __NVRAM_LOAD__+__NVRAM_SIZE__,$800
; Zero-page
tax
: sta 0,x
inx
bne :-
; Stack below S
tsx
inx
: dex
sta $100,x
bne :-
rts
nv_res unused_nv_var ; to avoid size=0
; Clears nvram
clear_nvram:
lda #0
fill_ram_ __NVRAM_LOAD__,__NVRAM_LOAD__+__NVRAM_SIZE__
rts
; Prints filename and newline, if available, otherwise nothing.
; Preserved: A, X, Y
print_filename:
.ifdef FILENAME_KNOWN
pha
jsr print_newline
setw addr,filename
jsr print_str_addr
jsr print_newline
pla
.endif
rts
.pushseg
.segment "RODATA"
; Filename terminated with zero byte.
filename:
.ifdef FILENAME_KNOWN
.incbin "ram:nes_temp"
.endif
.byte 0
.popseg
;**** ROM-specific ****
.ifndef BUILD_NSF
.include "ppu.s"
avoid_silent_nsf:
play_byte:
rts
; Disables interrupts and loops forever
.ifndef CUSTOM_FOREVER
forever:
sei
lda #0
sta PPUCTRL
: beq :-
.res $10,$EA ; room for code to run loader
.endif
; Default NMI
.ifndef CUSTOM_NMI
zp_byte nmi_count
zp_byte flags_from_nmi
zp_byte pclo_from_nmi
nmi: ; Record flags and PC low byte from stack
pla
sta flags_from_nmi
pla
sta pclo_from_nmi
pha
lda flags_from_nmi
pha
inc nmi_count
rti
; Waits for NMI. Must be using NMI handler that increments
; nmi_count, with NMI enabled.
; Preserved: X, Y
wait_nmi:
lda nmi_count
: cmp nmi_count
beq :-
rts
.endif
; Default IRQ
.ifndef CUSTOM_IRQ
zp_byte flags_from_irq
zp_byte pclo_from_irq
zp_byte irq_count
irq: ; Record flags and PC low byte from stack
pla
sta flags_from_irq
pla
sta pclo_from_irq
pha
lda flags_from_irq
pha
inc irq_count
bit SNDCHN ; clear frame IRQ flag
rti
.endif
.endif
; Reports A in binary as high and low tones, with
; leading low tone for reference. Omits leading
; zeroes. Doesn't hang if no APU is present.
; Preserved: A, X, Y
play_hex:
pha
; Make low reference beep
clc
jsr @beep
; Remove high zero bits
sec
: rol a
bcc :-
; Play remaining bits
beq @zero
: jsr @beep
asl a
bne :-
@zero:
delay_msec 300
pla
rts
; Plays low/high beep based on carry
; Preserved: A, X, Y
@beep:
pha
; Set up square
lda #1
sta SNDCHN
sta $4001
sta $4003
adc #$FE ; period=$100 if carry, $1FF if none
sta $4002
; Fade volume
lda #$0F
: ora #$30
sta $4000
delay_msec 8
sec
sbc #$31
bpl :-
; Silence
setb SNDCHN,0
delay_msec 160
pla
rts
|
xem/nes | 1,483 | nes-test-roms/apu_reset/source/common/build_rom.s | ; Builds program as iNES ROM
; Default is 32K PRG and 8K CHR ROM, NROM (0)
.if 0 ; Options to set before .include "shell.inc":
CHR_RAM=1 ; Use CHR-RAM instead of CHR-ROM
CART_WRAM=1 ; Use mapper that supports 8K WRAM in cart
CUSTOM_MAPPER=n ; Specify mapper number
.endif
.ifndef CUSTOM_MAPPER
.ifdef CART_WRAM
CUSTOM_MAPPER = 2 ; UNROM
.else
CUSTOM_MAPPER = 0 ; NROM
.endif
.endif
;;;; iNES header
.ifndef CUSTOM_HEADER
.segment "HEADER"
.byte $4E,$45,$53,26 ; "NES" EOF
.ifdef CHR_RAM
.byte 2,0 ; 32K PRG, CHR RAM
.else
.byte 2,1 ; 32K PRG, 8K CHR
.endif
.byte CUSTOM_MAPPER*$10+$01 ; vertical mirroring
.endif
.ifndef CUSTOM_VECTORS
.segment "VECTORS"
.word -1,-1,-1, nmi, reset, irq
.endif
;;;; CHR-RAM/ROM
.ifdef CHR_RAM
.define CHARS "CHARS_PRG"
.segment CHARS
ascii_chr:
.segment "CHARS_PRG_ASCII"
.align $200
.incbin "ascii.chr"
ascii_chr_end:
.else
.define CHARS "CHARS"
.segment "CHARS_ASCII"
.align $200
.incbin "ascii.chr"
.res $1800
.endif
.segment CHARS
.res $10,0
;;;; Shell
.ifndef NEED_CONSOLE
NEED_CONSOLE=1
.endif
.segment "CODE"
.res $4000
.include "shell.s"
std_reset:
lda #0
sta PPUCTRL
sta PPUMASK
jmp run_shell
init_runtime:
.ifdef CHR_RAM
load_chr_ram
.endif
rts
post_exit:
jsr set_final_result
jsr play_hex
jmp forever
; This helps devcart recover after running test.
; It is never executed by test ROM.
.segment "LOADER"
.incbin "devcart.bin"
.code
.align 256
|
xem/nes | 1,118 | nes-test-roms/apu_reset/source/common/run_at_reset.s | ; Keeps track of number of times reset, and prompts user.
power_flag_value = $42
nv_res power_flag_
nv_res num_resets_
; Out: A = number of times NES has been reset since turned on
; Preserved: X, Y
num_resets:
lda power_flag_
cmp #power_flag_value
bne :+
lda num_resets_
rts
: lda #0
rts
; Prompts user to press reset after message disappears,
; then hides message, increments reset count, and asks
; emulator to reset NES.
; Preserved: X, Y
prompt_to_reset:
print_str {newline,newline,"Press RESET"}
; Add "again" if this isn't first requested reset
jsr num_resets
beq :+
print_str " again"
:
print_str newline,newline
jsr inc_reset_count
; Show message
jsr console_show
rts
; Increments reset count and marks it as valid
; Preserved: X, Y
inc_reset_count:
jsr num_resets
clc
adc #1
bcc :+
lda #$FF ; don't wrap around
: sta num_resets_
setb power_flag_,power_flag_value
; Tell emulator that NES should be reset now
lda #$81
jsr set_final_result
rts
; Waits in infinite loop for reset
; Preserved: A, X, Y, flags
wait_reset:
jmp wait_reset
|
xem/nes | 5,404 | nes-test-roms/apu_reset/source/common/console.s | ; Scrolling text console with word wrapping, 30x29 characters.
;
; * Defers PPU initialization until first flush/ newline.
; * Works even if PPU doesn't support scrolling.
; * Keeps border around edge of screen for TV overscan.
; * Requires vertical or single-screen mirroring.
; * Requires ASCII font in CHR.
.ifndef CONSOLE_COLOR
CONSOLE_COLOR = $30 ; white
.endif
console_screen_width = 32 ; if lower than 32, left-justifies
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs. OK if either/both are 0.
console_left_margin = 1
console_right_margin = 1
console_width = console_screen_width - console_left_margin - console_right_margin
zp_byte console_pos ; 0 to console_width
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_width
; Initializes console
console_init:
; Flag that console hasn't been initialized
setb console_scroll,-1
setb console_pos,0
rts
; Hides console by disabling PPU rendering and blacking out
; first four entries of palette.
; Preserved: A, X, Y
console_hide:
pha
jsr console_wait_vbl_
setb PPUMASK,0
lda #$0F
jsr console_load_palette_
pla
rts
; Shows console display
; Preserved: A, X, Y
console_show:
pha
lda #CONSOLE_COLOR
jsr console_show_custom_color_
pla
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
sty console_temp
ldy console_pos
cpy #console_width
beq console_full_
sta console_buf,y
iny
sty console_pos
ldy console_temp
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_scroll_up_
setb console_pos,0
pla
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_apply_scroll_
pla
rts
;**** Internal routines ****
console_full_:
ldy console_temp
; Line is full
; If space, treat as newline
cmp #' '
beq console_newline
; Wrap current line at appropriate point
pha
tya
pha
jsr console_wrap_
pla
tay
pla
jmp console_print
; Inserts newline into buffer at appropriate position, leaving
; next line ready in buffer
; Preserved: X, console_temp
console_wrap_:
; Find beginning of last word
ldy #console_width
lda #' '
: dey
bmi console_newline
cmp console_buf,y
bne :-
; y = 0 to console_width-1
; Flush through current word and put remaining
; in buffer for next line
jsr console_wait_vbl_
; Time to last PPU write: 207 + 32*(26 + 10)
lda console_scroll
jsr console_set_ppuaddr_
stx console_pos ; save X
ldx #0
; Print everything before last word
: lda console_buf,x
sta PPUDATA
inx
dey
bpl :-
; x = 1 to console_width
; Move last word to beginning of buffer, and
; print spaces for rest of line
ldy #0
beq :++
: lda #' '
sta PPUDATA
lda console_buf,x
inx
sta console_buf,y
iny
: cpx #console_width
bne :--
ldx console_pos ; restore X
; Append new text after that
sty console_pos
; FALL THROUGH
; Scrolls up 8 pixels and clears one line BELOW new line
; Preserved: X, console_temp
console_scroll_up_:
; Scroll up 8 pixels
lda console_scroll
jsr console_add_8_to_scroll_
sta console_scroll
; Clear line AFTER that on screen
jsr console_add_8_to_scroll_
jsr console_set_ppuaddr_
ldy #console_width
lda #' '
: sta PPUDATA
dey
bne :-
; FALL THROUGH
; Applies current scrolling position to PPU
; Preserved: X, Y, console_temp
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
lda console_scroll
jsr console_add_8_to_scroll_
jsr console_add_8_to_scroll_
sta PPUSCROLL
rts
; Sets PPU address for row
; In: A = scroll position
; Preserved: X, Y
console_set_ppuaddr_:
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
ora #console_left_margin
sta PPUADDR
rts
; A = (A + 8) % 240
; Preserved: X, Y
console_add_8_to_scroll_:
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_show_custom_color_:
pha
jsr console_wait_vbl_
setb PPUMASK,PPUMASK_BG0
pla
jsr console_load_palette_
jmp console_apply_scroll_
console_load_palette_:
pha
setb PPUADDR,$3F
setb PPUADDR,$00
setb PPUDATA,$0F ; black
pla
sta PPUDATA
sta PPUDATA
sta PPUDATA
rts
; Initializes PPU if necessary, then waits for VBL
; Preserved: A, X, Y, console_temp
console_wait_vbl_:
lda console_scroll
cmp #-1
bne @already_initialized
; Deferred initialization of PPU until first use of console
; In case PPU doesn't support scrolling, start a
; couple of lines down
setb console_scroll,16
jsr console_hide
tya
pha
; Fill nametable with spaces
setb PPUADDR,$20
setb PPUADDR,$00
ldy #240
lda #' '
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dey
bne :-
; Clear attributes
lda #0
ldy #$40
: sta PPUDATA
dey
bne :-
pla
tay
jsr console_show
@already_initialized:
jmp wait_vbl_optional
; Flushes current line
; Preserved: X, Y
console_flush_:
lda console_scroll
jsr console_set_ppuaddr_
sty console_temp
; Copy line
ldy #0
beq :++
: lda console_buf,y
sta PPUDATA
iny
: cpy console_pos
bne :--
ldy console_temp
rts
|
xem/nes | 1,096 | nes-test-roms/apu_reset/source/common/text_out.s | ; Text output as expanding zero-terminated string at text_out_base
; The final exit result byte is written here
final_result = $6000
; Text output is written here as an expanding
; zero-terminated string
text_out_base = $6004
bss_res text_out_temp
zp_res text_out_addr,2
init_text_out:
ldx #0
; Put valid data first
setb text_out_base,0
lda #$80
jsr set_final_result
; Now fill in signature that tells emulator there's
; useful data there
setb text_out_base-3,$DE
setb text_out_base-2,$B0
setb text_out_base-1,$61
ldx #>text_out_base
stx text_out_addr+1
setb text_out_addr,<text_out_base
rts
; Sets final result byte in memory
set_final_result:
sta final_result
rts
; Writes character to text output
; In: A=Character to write
; Preserved: A, X, Y
write_text_out:
sty text_out_temp
; Write new terminator FIRST, then new char before it,
; in case emulator looks at string in middle of this routine.
ldy #1
pha
lda #0
sta (text_out_addr),y
dey
pla
sta (text_out_addr),y
inc text_out_addr
bne :+
inc text_out_addr+1
:
ldy text_out_temp
rts
|
xem/nes | 3,060 | nes-test-roms/apu_reset/source/common/ppu.s | ; PPU utilities
bss_res ppu_not_present
; Sets PPUADDR to w
; Preserved: X, Y
.macro set_ppuaddr w
bit PPUSTATUS
setb PPUADDR,>w
setb PPUADDR,<w
.endmacro
; Delays by no more than n scanlines
.macro delay_scanlines n
.if CLOCK_RATE <> 1789773
.error "Currently only supports NTSC"
.endif
delay ((n)*341)/3
.endmacro
; Waits for VBL then disables PPU rendering.
; Preserved: A, X, Y
disable_rendering:
pha
jsr wait_vbl_optional
setb PPUMASK,0
pla
rts
; Fills first nametable with $00
; Preserved: Y
clear_nametable:
ldx #$20
bne clear_nametable_
clear_nametable2:
ldx #$24
clear_nametable_:
lda #0
jsr fill_screen_
; Clear pattern table
ldx #64
: sta PPUDATA
dex
bne :-
rts
; Fills screen with tile A
; Preserved: A, Y
fill_screen:
ldx #$20
bne fill_screen_
; Same as fill_screen, but fills other nametable
fill_screen2:
ldx #$24
fill_screen_:
stx PPUADDR
ldx #$00
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
rts
; Fills palette with $0F
; Preserved: Y
clear_palette:
set_ppuaddr $3F00
ldx #$20
lda #$0F
: sta PPUDATA
dex
bne :-
; Fills OAM with $FF
; Preserved: Y
clear_oam:
lda #$FF
; Fills OAM with A
; Preserved: A, Y
fill_oam:
ldx #0
stx SPRADDR
: sta SPRDATA
dex
bne :-
rts
; Initializes wait_vbl_optional. Must be called before
; using it.
.align 32
init_wait_vbl:
; Wait for VBL flag to be set, or ~60000
; clocks (2 frames) to pass
ldy #24
ldx #1
bit PPUSTATUS
: bit PPUSTATUS
bmi @set
dex
bne :-
dey
bpl :-
@set:
; Be sure flag didn't stay set (in case
; PPUSTATUS always has high bit set)
tya
ora PPUSTATUS
sta ppu_not_present
rts
; Same as wait_vbl, but returns immediately if PPU
; isn't working or doesn't support VBL flag
; Preserved: A, X, Y
.align 16
wait_vbl_optional:
bit ppu_not_present
bmi :++
; FALL THROUGH
; Clears VBL flag then waits for it to be set.
; Preserved: A, X, Y
wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
: rts
.macro check_ppu_region_ Len
; Delays since VBL began
jsr wait_vbl_optional ; 10 average
delay Len - 18 - 200
lda PPUSTATUS ; 4
bmi @ok ; 2
delay 200
; Next VBL should roughly begin here if it's the
; one we are detecting
delay 200
lda PPUSTATUS ; 2
bpl @ok
.endmacro
check_ppu_region:
.ifndef REGION_FREE
.ifdef PAL_ONLY
check_ppu_region_ 29781
print_str {newline,"Note: This test is meant for PAL NES only.",newline,newline}
.endif
.ifdef NTSC_ONLY
check_ppu_region_ 33248
print_str {newline,"Note: This test is meant for NTSC NES only.",newline,newline}
.endif
.endif
@ok: rts
; Loads ASCII font into CHR RAM and fills rest with $FF
.macro load_chr_ram
bit PPUSTATUS
setb PPUADDR,0
setb PPUADDR,0
; Copy ascii_chr to 0
setb addr,<ascii_chr
ldx #>ascii_chr
ldy #0
@page:
stx addr+1
: lda (addr),y
sta PPUDATA
iny
bne :-
inx
cpx #>ascii_chr_end
bne @page
; Fill rest
lda #$FF
: sta PPUDATA
iny
bne :-
inx
cpx #$20
bne :-
.endmacro
|
xem/nes | 2,698 | nes-test-roms/apu_reset/source/common/shell.s | ; Shell that sets up testing framework and calls main
; Detect inclusion loops (otherwise ca65 goes crazy)
.ifdef SHELL_INCLUDED
.error "shell.s included twice"
.end
.endif
SHELL_INCLUDED = 1
; Temporary variables that ANY routine might modify, so
; only use them between routine calls.
temp = <$A
temp2 = <$B
temp3 = <$C
addr = <$E
ptr = addr
; Move code from $C000 to $E200, to accommodate my devcarts
.segment "CODE"
.res $2200
; Put shell code after user code, so user code is in more
; consistent environment
.segment "CODE2"
; Any user code which runs off end might end up here,
; so catch that mistake.
nop ; in case there was three-byte opcode before this
nop
jmp internal_error
;**** Common routines ****
.include "macros.inc"
.include "neshw.inc"
.include "delay.s"
.include "print.s"
.include "crc.s"
.include "testing.s"
;**** Shell core ****
.ifndef CUSTOM_RESET
reset:
sei
jmp std_reset
.endif
; Sets up hardware then runs main
run_shell:
init_cpu_regs
jsr init_shell
set_test $FF
jmp run_main
; Initializes shell without affecting current set_test values
init_shell:
jsr clear_ram
jsr init_wait_vbl ; waits for VBL once here,
jsr wait_vbl_optional ; so only need to wait once more
jsr init_text_out
jsr init_testing
jsr init_runtime
jsr console_init
rts
; Runs main in consistent PPU/APU environment, then exits
; with code 0
run_main:
jsr pre_main
jsr main
lda #0
jmp exit
; Sets up environment for main to run in
pre_main:
.ifndef BUILD_NSF
jsr disable_rendering
setb PPUCTRL,0
jsr clear_palette
jsr clear_nametable
jsr clear_nametable2
jsr clear_oam
.endif
; Clear APU registers
lda #0
sta $4015
ldx #$13
: sta $4000,x
dex
bpl :-
; CPU registers
lda #$34
pha
lda #0
tax
tay
jsr wait_vbl_optional
plp
sta SNDMODE
rts
.ifndef CUSTOM_EXIT
exit:
.endif
; Reports result and ends program
std_exit:
sta temp
init_cpu_regs
setb SNDCHN,0
lda temp
jsr report_result
pha
jsr check_ppu_region
pla
jmp post_exit
; Reports final result code in A
report_result:
jsr :+
jmp play_byte
: jsr print_newline
jsr console_show
; 0: ""
cmp #1
bge :+
rts
:
; 1: "Failed"
bne :+
print_str {"Failed",newline}
rts
; n: "Failed #n"
: print_str "Failed #"
jsr print_dec
jsr print_newline
rts
;**** Other routines ****
.include "shell_misc.s"
.ifdef NEED_CONSOLE
.include "console.s"
.else
; Stubs so code doesn't have to care whether
; console exists
console_init:
console_show:
console_hide:
console_print:
console_flush:
rts
.endif
.ifndef CUSTOM_PRINT
.include "text_out.s"
print_char_:
jsr write_text_out
jmp console_print
stop_capture:
rts
.endif
|
xem/nes | 3,437 | nes-test-roms/apu_reset/source/common/delay.s | ; Delays in CPU clocks, milliseconds, etc. All routines are re-entrant
; (no global data). No routines touch X or Y during execution.
; Code generated by macros is relocatable; it contains no JMPs to itself.
zp_byte delay_temp_ ; only written to
; Delays n clocks, from 2 to 16777215
; Preserved: A, X, Y, flags
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
delay_ (n)
.endmacro
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100.
; Preserved: A, X, Y, flags
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: A, X, Y, flags
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
.align 64
; Delays A clocks + overhead
; Preserved: X, Y
; Time: A+25 clocks (including JSR)
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256 clocks + overhead
; Preserved: X, Y
; Time: A*256+16 clocks (including JSR)
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_11_clocks_:
: pha
lda #256-19-22
jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536 clocks + overhead
; Preserved: X, Y
; Time: A*65536+16 clocks (including JSR)
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_11_clocks_:
: pha
lda #256-19-22-13
jsr delay_a_25_clocks
lda #255
jsr delay_256a_11_clocks_
pla
clc
adc #-1
bne :-
rts
max_short_delay = 41
; delay_short_ macro jumps into these
.res (max_short_delay-12)/2,$EA ; NOP
delay_unrolled_:
rts
.macro delay_short_ n
.if n < 0 .or n = 1 .or n > max_short_delay
.error "Internal delay error"
.endif
.if n = 0
; nothing
.elseif n = 2
nop
.elseif n = 3
sta <delay_temp_
.elseif n = 4
nop
nop
.elseif n = 5
sta <delay_temp_
nop
.elseif n = 6
nop
nop
nop
.elseif n = 7
php
plp
.elseif n = 8
nop
nop
nop
nop
.elseif n = 9
php
plp
nop
.elseif n = 10
sta <delay_temp_
php
plp
.elseif n = 11
php
plp
nop
nop
.elseif n = 13
php
plp
nop
nop
nop
.elseif n & 1
sta <delay_temp_
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.macro delay_nosave_ n
; 65536+17 = maximum delay using delay_256a_11_clocks_
; 255+27 = maximum delay using delay_a_25_clocks
; 27 = minimum delay using delay_a_25_clocks
.if n > 65536+17
lda #^(n - 15)
jsr delay_65536a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (((n - 15) & $FFFF) + 2)
.elseif n > 255+27
lda #>(n - 15)
jsr delay_256a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (<(n - 15) + 2)
.elseif n >= 27
lda #<(n - 27)
jsr delay_a_25_clocks
.else
delay_short_ n
.endif
.endmacro
.macro delay_ n
.if n > max_short_delay
php
pha
delay_nosave_ (n - 14)
pla
plp
.else
delay_short_ n
.endif
.endmacro
|
xem/nes | 1,632 | nes-test-roms/apu_reset/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: A, X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
jmp reset_crc
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
lda #$FF
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: A, X, Y
; Time: 357 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
pha
stx checksum_temp
eor checksum
ldx #8
@bit: lsr checksum+3
ror checksum+2
ror checksum+1
ror a
bcc :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
: dex
bne @bit
sta checksum
ldx checksum_temp
pla
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
; Print complement
ldx #3
: lda checksum,x
eor #$FF
jsr print_hex
dex
bpl :-
jmp crc_on
; EQ if checksum matches CRC
; Out: A=0 and EQ if match, A>0 and NE if different
; Preserved: X, Y
.macro is_crc crc
jsr_with_addr is_crc_,{.dword crc}
.endmacro
is_crc_:
tya
pha
; Compare with complemented checksum
ldy #3
: lda (ptr),y
sec
adc checksum,y
bne @wrong
dey
bpl :-
pla
tay
lda #0
rts
@wrong:
pla
tay
lda #1
rts
|
xem/nes | 9,413 | nes-test-roms/spritecans-2011/src/sprite.s | ;
; sprite.asm
; 64 Sprite Cans intro for NES
; Copyright 2000-2011 Damian Yerrick
;;; Copyright (C) 2000-2011 Damian Yerrick
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 3
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to
; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.
;
.include "src/nes.h"
.p02
.import getTVSystem, init_music, init_sound, update_sound
.exportzp nmis, psg_sfx_state, tvSystem
NTSC_INCREASE_TIME = 98 ; 3606*3/110
PAL_INCREASE_TIME = 82 ; 3000*3/110
; This program runs on NROM-128 (mapper 0), with only 4 KiB of PRG
; and 2.5 KiB of CHR actually used.
.segment "INESHDR"
.byt "NES",$1A
.byt $01 ; one PRG bank
.byt $01 ; one CHR bank
.byt $00 ; mapper bits 3-0; no battery
.byt $00 ; mapper bits 7-4
.segment "ZEROPAGE"
; Work around the 8 sprites per scanline limitation by constantly
; shuffling priorities. Konami games use this algorithm.
firstsproffset: .res 1 ; offset to start writing sprites to
; each frame, firstsproffset += 60
cursproffset: .res 1 ; offset to write next sprite to
; for each sprite written, cursproffset += 68
tvSystem: .res 1 ; 0: ntsc; 1: pal; 2: dendy
nmis: .res 2 ; 16-bit number of elapsed vblanks
psg_sfx_state: .res 32 ; used by music engine
last_active_can: .res 1 ; (this + 1) cans are drawn
till_increase: .res 1 ; increase cans once per measure
OAM = $200 ; sprite dma communication area
.segment "BSS"
NUM_CANS = 64
canXLo: .res NUM_CANS
canXHi: .res NUM_CANS
canYLo: .res NUM_CANS
canYHi: .res NUM_CANS
canDXLo: .res NUM_CANS
canDYLo: .res NUM_CANS
canTheta: .res NUM_CANS
canDTheta: .res NUM_CANS
.segment "CODE"
.proc resetpoint
cld
sei
ldx #$FF
txs
inx ; turn off nmis and rendering
stx PPUCTRL
stx PPUMASK
bit PPUSTATUS
vwait1:
bit PPUSTATUS
bpl vwait1
txa
ramclrloop:
sta $00,x
sta $100,x
sta $600,x
sta $700,x
sta $300,x
sta $400,x
sta $500,x
inx
bne ramclrloop
;clear OAM
oamclrloop:
lda #$FF ; y offscreen
sta OAM,x
inx
inx
inx
inx
bne oamclrloop
vwait2:
bit PPUSTATUS
bpl vwait2
; initialize palette
lda #$3F
sta PPUADDR
stx PPUADDR
copypalloop:
lda titlepal,x
sta PPUDATA
inx
cpx #32
bne copypalloop
; copy nametable
lda #<obeydata
sta 0
lda #>obeydata
sta 1
jsr copynametable
; initialize sprite cans
ldx #NUM_CANS - 1
setupCanPos:
lda #0
sta canXLo,x
sta canYLo,x
; can't have 128 as the velocity because the bounce code fails if
; x == -x. The value 128 is in 0-63, so use 0-127 for positions
; and 128-255 for velocities.
lda randnos+128,x
sta canDXLo,x
lda randnos+192,x
sta canDYLo,x
txa
sta canTheta,x
lda randnos+0,x
cmp #224
bcc @canNotPastBottom
eor #%10000000
@canNotPastBottom:
sta canYHi,x
lda randnos+64,x
cmp #248
bcc @canNotPastRight
eor #%10000000
@canNotPastRight:
sta canXHi,x
txa
lsr a
lsr a
lsr a
sec
sbc #4
sta canDTheta,x
dex
bpl setupCanPos
jsr getTVSystem
sta tvSystem
lda #NUM_CANS-1
sta last_active_can
jsr sortCans
lda #0
sta last_active_can
lda #NTSC_INCREASE_TIME
ldy tvSystem
beq @initialNotPAL
lda #PAL_INCREASE_TIME
@initialNotPAL:
sta till_increase
jsr init_sound
lda #0 ; start "Celestial Soda Pop"
jsr init_music
lda #VBLANK_NMI
sta PPUCTRL
mainloop:
jsr update_sound
; In the early warmup of the intro, increase the number of
; sprites until all 64 are on screen.
dec till_increase
bne no_increase_yet
lda last_active_can
cmp #NUM_CANS - 1
bcs no_increase_yet
sec
rol last_active_can
lda #NTSC_INCREASE_TIME
ldy tvSystem
beq @increaseNotPAL
lda #PAL_INCREASE_TIME
@increaseNotPAL:
sta till_increase
no_increase_yet:
ldy firstsproffset
tya
clc
adc #60
sta firstsproffset
ldx last_active_can
moveCanLoop:
; move can horizontally
lda canDXLo,x
bpl :+
dec canXHi,x
:
clc
adc canXLo,x
sta canXLo,x
bcc :+
inc canXHi,x
:
; does it need to bounce off the left/right wall?
lda canXHi,x
cmp #248
bcc :+
lda #0
sbc canDXLo,x
sta canDXLo,x
:
; move can vertically
lda canDYLo,x
bpl :+
dec canYHi,x
:
clc
adc canYLo,x
sta canYLo,x
bcc :+
inc canYHi,x
:
lda canYHi,x
; does it need to bounce off the bottom/top wall?
cmp #224
bcc :+
lda #0
sbc canDYLo,x
sta canDYLo,x
:
; rotate the can
lda canTheta,x
clc
adc canDTheta,x
sta canTheta,x
and #%11110000
lsr a
lsr a
lsr a
ora #%10000000
; now actually draw the can
sta OAM+1,y
lda #%00100001 ; behind bg, basecolor=$3F14
sta OAM+2,y
lda canXHi,x
cmp #252
bcc :+
lda #0
:
sta OAM+3,y
lda canYHi,x
cmp #248
bcc :+
lda #0
:
sta OAM,y
tya
clc
adc #68
tay
dex
bpl moveCanLoop
; clear out sprite space used for inactive cans
lda last_active_can
eor #$3F
beq allCansActive
tax
eraseInactiveCanLoop:
lda #$FF
sta OAM,y
tya
clc
adc #68
tay
dex
bne eraseInactiveCanLoop
lda last_active_can
beq noSortNeeded
allCansActive:
jsr sortCans
noSortNeeded:
jsr wait4vbl
; If the time since power on is correct,
; erase the boot message.
lda nmis ;erase
bne @noerasemsg
lda nmis+1
cmp #2
bne @noerasemsg
lda #$21
sta PPUADDR
lda #$c0
sta PPUADDR
ldx #32
lda #0
@eraseloop:
.repeat 4
sta PPUDATA
.endrepeat
dex
bne @eraseloop
@noerasemsg:
; Copy sprite display list to the PPU
lda #0
sta PPUSCROLL
sta PPUSCROLL
sta OAMADDR
lda #>OAM
sta OAM_DMA
lda #VBLANK_NMI|OBJ_8X16
sta PPUCTRL
lda #BG_ON|OBJ_ON
sta PPUMASK
jmp mainloop
.endproc
;;
; Does one pass of bubble sort on the sprites by their X coordinates.
.proc sortCans
ldx #0
sortloop:
lda canXHi,x ; compare the sprites' X coordinates
cmp canXHi+1,x
bcs noSwap
jsr swapCans
noSwap:
inx
cpx last_active_can
bcc sortloop
rts
.endproc
;;
; Swaps a pair of sprites x and x+1.
.proc swapCans
ldy canXHi,x
lda canXHi+1,x
sta canXHi,x
tya
sta canXHi+1,x
ldy canXLo,x
lda canXLo+1,x
sta canXLo,x
tya
sta canXLo+1,x
ldy canDXLo,x
lda canDXLo+1,x
sta canDXLo,x
tya
sta canDXLo+1,x
ldy canYHi,x
lda canYHi+1,x
sta canYHi,x
tya
sta canYHi+1,x
ldy canYLo,x
lda canYLo+1,x
sta canYLo,x
tya
sta canYLo+1,x
ldy canDYLo,x
lda canDYLo+1,x
sta canDYLo,x
tya
sta canDYLo+1,x
ldy canTheta,x
lda canTheta+1,x
sta canTheta,x
tya
sta canTheta+1,x
ldy canDTheta,x
lda canDTheta+1,x
sta canDTheta,x
tya
sta canDTheta+1,x
rts
.endproc
;;
; Copies a name table from address in 0 to CIRAM $2000.
.proc copynametable
src = 0
ldy #VBLANK_NMI
sty PPUCTRL
lda #$20
sta PPUADDR
ldy #$00
sty PPUADDR
ldx #4
copyloop:
.repeat 2
lda (src),y
sta PPUDATA
iny
.endrepeat
bne copyloop
inc src+1
dex
bne copyloop
rts
.endproc
;;
; Waits for vertical blanking.
.proc wait4vbl
lda nmis
notyet:
cmp nmis
beq notyet
rts
.endproc
;;
; Increments retrace count for wait4vbl and other logic.
.proc nmipoint
inc nmis
bne nohi
inc nmis+1
nohi:
rti
.endproc
;;
; IRQ handler that does nothing because doesn't use
; mapper IRQs, APU frame IRQs, or DPCM IRQs.
.proc irqpoint
rti
.endproc
;
; DATA TABLES
;
.segment "RODATA"
obeydata: .incbin "src/sprite.nam" ; made with 8name II
randnos: ; per http://en.wikipedia.org/wiki/Rijndael_S-box
.byt 99,124,119,123,242,107,111,197, 48, 1,103, 43,254,215,171,118
.byt 202,130,201,125,250, 89, 71,240,173,212,162,175,156,164,114,192
.byt 183,253,147, 38, 54, 63,247,204, 52,165,229,241,113,216, 49, 21
.byt 4,199, 35,195, 24,150, 5,154, 7, 18,128,226,235, 39,178,117
.byt 9,131, 44, 26, 27,110, 90,160, 82, 59,214,179, 41,227, 47,132
.byt 83,209, 0,237, 32,252,177, 91,106,203,190, 57, 74, 76, 88,207
.byt 208,239,170,251, 67, 77, 51,133, 69,249, 2,127, 80, 60,159,168
.byt 81,163, 64,143,146,157, 56,245,188,182,218, 33, 16,255,243,210
.byt 205, 12, 19,236, 95,151, 68, 23,196,167,126, 61,100, 93, 25,115
.byt 96,129, 79,220, 34, 42,144,136, 70,238,184, 20,222, 94, 11,219
.byt 224, 50, 58, 10, 73, 6, 36, 92,194,211,172, 98,145,149,228,121
.byt 231,200, 55,109,141,213, 78,169,108, 86,244,234,101,122,174, 8
.byt 186,120, 37, 46, 28,166,180,198,232,221,116, 31, 75,189,139,138
.byt 112, 62,181,102, 72, 3,246, 14, 97, 53, 87,185,134,193, 29,158
.byt 225,248,152, 17,105,217,142,148,155, 30,135,233,206, 85, 40,223
.byt 140,161,137, 13,191,230, 66,104, 65,153, 45, 15,176, 84,187, 22
; palette
titlepal:
.byt $0f,$00,$10,$30,$0f,$12,$1a,$30,$0f,$1a,$2c,$30,$0f,$12,$14,$30
.byt $0f,$00,$10,$30,$0f,$12,$1a,$30,$0f,$1a,$2c,$30,$0f,$12,$14,$30
.segment "VECTORS"
.addr nmipoint, resetpoint, irqpoint
|
xem/nes | 2,026 | nes-test-roms/spritecans-2011/src/paldetect.s | ;
; NES TV system detection code
; Copyright 2011 Damian Yerrick
;
; Copying and distribution of this file, with or without
; modification, are permitted in any medium without royalty
; provided the copyright notice and this notice are preserved.
; This file is offered as-is, without any warranty.
;
.export getTVSystem
.importzp nmis
.align 32 ; ensure that branches do not cross a page boundary
;;
; Detects which of NTSC, PAL, or Dendy is in use by counting cycles
; between NMIs.
;
; NTSC NES produces 262 scanlines, with 341/3 CPU cycles per line.
; PAL NES produces 312 scanlines, with 341/3.2 CPU cycles per line.
; Its vblank is longer than NTSC, and its CPU is slower.
; Dendy is a Russian famiclone distributed by Steepler that uses the
; PAL signal with a CPU as fast as the NTSC CPU. Its vblank is as
; long as PAL's, but its NMI occurs toward the end of vblank (line
; 291 instead of 241) so that cycle offsets from NMI remain the same
; as NTSC, keeping Balloon Fight and any game using a CPU cycle-
; counting mapper (e.g. FDS, Konami VRC) working.
;
; nmis is a variable that the NMI handler modifies every frame.
; Make sure your NMI handler finishes within 1500 or so cycles (not
; taking the whole NMI or waiting for sprite 0) while calling this,
; or the result in A will be wrong.
;
; @return A: TV system (0: NTSC, 1: PAL, 2: Dendy; 3: unknown
; Y: high byte of iterations used (1 iteration = 11 cycles)
; X: low byte of iterations used
.proc getTVSystem
ldx #0
ldy #0
lda nmis
nmiwait1:
cmp nmis
beq nmiwait1
lda nmis
nmiwait2:
; Each iteration takes 11 cycles.
; NTSC NES: 29780 cycles or 2707 = $A93 iterations
; PAL NES: 33247 cycles or 3022 = $BCE iterations
; Dendy: 35464 cycles or 3224 = $C98 iterations
; so we can divide by $100 (rounding down), subtract ten,
; and end up with 0=ntsc, 1=pal, 2=dendy, 3=unknown
inx
bne :+
iny
:
cmp nmis
beq nmiwait2
tya
sec
sbc #10
cmp #3
bcc notAbove3
lda #3
notAbove3:
rts
.endproc
|
xem/nes | 6,765 | nes-test-roms/spritecans-2011/src/music.s | ; music.s
; part of sound engine for LJ65
;;; Copyright (C) 2009-2011 Damian Yerrick
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 3
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to
; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.
;
; Visit http://www.pineight.com/ for more information.
.importzp psg_sfx_state
.import soundBSS
.import start_sound
.importzp tvSystem
.export music_playing
.export init_music, stop_music, update_music, update_music_ch
.include "src/musicseq.h"
musicPatternPos = psg_sfx_state + 2
conductorPos = psg_sfx_state + 16
noteEnvVol = soundBSS + 0
notePitch = soundBSS + 1
noteRowsLeft = soundBSS + 2
; 3 is in sound.s
musicPattern = soundBSS + 16
patternTranspose = soundBSS + 17
noteInstrument = soundBSS + 18
; 19 is in sound.s
tempoCounterLo = soundBSS + 48
tempoCounterHi = soundBSS + 49
music_tempoLo = soundBSS + 50
music_tempoHi = soundBSS + 51
conductorSegno = soundBSS + 52
conductorWaitRows = soundBSS + 62
music_playing = soundBSS + 63
FRAMES_PER_MINUTE_PAL = 3000
FRAMES_PER_MINUTE_NTSC = 3606
.segment "RODATA"
fpmLo:
.byt <FRAMES_PER_MINUTE_NTSC, <FRAMES_PER_MINUTE_PAL
fpmHi:
.byt >FRAMES_PER_MINUTE_NTSC, >FRAMES_PER_MINUTE_PAL
silentPattern:
.byt 26*8+7, 255
durations:
.byt 1, 2, 3, 4, 6, 8, 12, 16
.segment "CODE"
.proc init_music
asl a
tax
lda songTable,x
sta conductorPos
sta conductorSegno
lda songTable+1,x
sta conductorPos+1
sta conductorSegno+1
ldx #12
stx music_playing
channelLoop:
lda #$FF
sta musicPattern,x
lda #<silentPattern
sta musicPatternPos,x
lda #>silentPattern
sta musicPatternPos+1,x
lda #0
sta patternTranspose,x
sta noteInstrument,x
sta noteEnvVol,x
sta noteRowsLeft,x
dex
dex
dex
dex
bpl channelLoop
lda #0
sta conductorWaitRows
lda #$FF
sta tempoCounterLo
sta tempoCounterHi
lda #<300
sta music_tempoLo
lda #>300
sta music_tempoHi
rts
.endproc
.proc stop_music
lda #0
sta music_playing
rts
.endproc
.proc update_music
lda music_playing
beq music_not_playing
lda music_tempoLo
clc
adc tempoCounterLo
sta tempoCounterLo
lda music_tempoHi
adc tempoCounterHi
sta tempoCounterHi
bcs new_tick
music_not_playing:
rts
new_tick:
ldy tvSystem
beq is_ntsc_1
ldy #1
is_ntsc_1:
; Subtract tempo
lda tempoCounterLo
sbc fpmLo,y
sta tempoCounterLo
lda tempoCounterHi
sbc fpmHi,y
sta tempoCounterHi
;jmp skipConductor
lda conductorWaitRows
beq doConductor
dec conductorWaitRows
jmp skipConductor
doConductor:
ldy #0
lda (conductorPos),y
inc conductorPos
bne :+
inc conductorPos+1
:
sta 0
cmp #CON_SETTEMPO
bcc @notTempoChange
and #%00000011
sta music_tempoHi
lda (conductorPos),y
inc conductorPos
bne :+
inc conductorPos+1
:
sta music_tempoLo
jmp doConductor
@notTempoChange:
cmp #CON_WAITROWS
bcc conductorPlayPattern
beq conductorDoWaitRows
cmp #CON_FINE
bne @notFine
lda #0
sta music_playing
sta music_tempoHi
sta music_tempoLo
rts
@notFine:
cmp #CON_SEGNO
bne @notSegno
lda conductorPos
sta conductorSegno
lda conductorPos+1
sta conductorSegno+1
jmp doConductor
@notSegno:
cmp #CON_DALSEGNO
bne @notDalSegno
lda conductorSegno
sta conductorPos
lda conductorSegno+1
sta conductorPos+1
jmp doConductor
@notDalSegno:
jmp skipConductor
conductorPlayPattern:
and #$03
asl a
asl a
tax
lda #0
sta noteRowsLeft,x
lda (conductorPos),y
sta musicPattern,x
iny
lda (conductorPos),y
sta patternTranspose,x
iny
lda (conductorPos),y
sta noteInstrument,x
tya
sec
adc conductorPos
sta conductorPos
bcc :+
inc conductorPos+1
:
jsr startPattern
jmp doConductor
; this should be last so it can fall into skipConductor
conductorDoWaitRows:
lda (conductorPos),y
inc conductorPos
bne :+
inc conductorPos+1
:
sta conductorWaitRows
skipConductor:
ldx #12
channelLoop:
lda noteRowsLeft,x
bne skipNote
lda (musicPatternPos,x)
cmp #255
bne notStartPatternOver
jsr startPattern
lda (musicPatternPos,x)
notStartPatternOver:
inc musicPatternPos,x
bne patternNotNewPage
inc musicPatternPos+1,x
patternNotNewPage:
; set the note's duration
pha
and #$07
tay
lda durations,y
sta noteRowsLeft,x
pla
lsr a
lsr a
lsr a
cmp #25
bcc isTransposedNote
beq notKeyOff
lda #0
sta noteEnvVol,x
notKeyOff:
jmp skipNote
isTransposedNote:
cpx #12
beq isDrumNote
adc patternTranspose,x
sta notePitch,x
lda noteInstrument,x
asl a
asl a
tay
lda instrumentTable,y
asl a
asl a
asl a
asl a
ora #$0C
sta noteEnvVol,x
skipNote:
dec noteRowsLeft,x
dex
dex
dex
dex
bpl channelLoop
rts
isDrumNote:
stx 5
tax
lda drumSFX,x
jsr start_sound
ldx 5
jmp skipNote
startPattern:
lda musicPattern,x
asl a
bcc @notSilentPattern
lda #<silentPattern
sta musicPatternPos,x
lda #>silentPattern
sta musicPatternPos+1,x
rts
@notSilentPattern:
tay
lda musicPatternTable,y
sta musicPatternPos,x
lda musicPatternTable+1,y
sta musicPatternPos+1,x
rts
.endproc
.proc update_music_ch
ch_number = 0
out_volume = 2
out_pitch = 3
lda music_playing
beq silenced
lda noteEnvVol,x
lsr a
lsr a
lsr a
lsr a
bne notSilenced
silenced:
lda #0
sta 2
rts
notSilenced:
sta 2
lda noteInstrument,x
asl a
asl a
tay
lda 2
eor instrumentTable,y
and #$0F
eor instrumentTable,y
sta 2
lda noteEnvVol,x
sec
sbc instrumentTable+1,y
bcc silenced
sta noteEnvVol,x
lda notePitch,x
sta 3
; bit 7 of attribute 2: cut note when half a row remains
lda instrumentTable+2,y
bpl notCutNote
lda noteRowsLeft,x
bne notCutNote
clc
lda tempoCounterLo
adc #<(FRAMES_PER_MINUTE_NTSC/2)
lda tempoCounterHi
adc #>(FRAMES_PER_MINUTE_NTSC/2)
bcc notCutNote
lda #0
sta noteEnvVol,x
notCutNote:
rts
.endproc
|
xem/nes | 7,092 | nes-test-roms/spritecans-2011/src/sound.s | ; sound.s
; part of sound engine for LJ65
;;; Copyright (C) 2009-2011 Damian Yerrick
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 3
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to
; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.
;
; Visit http://www.pineight.com/ for more information.
.import periodTableLo, periodTableHi
.importzp psg_sfx_state ; a 32 byte buffer in zp?
.importzp tvSystem
.import update_music, update_music_ch, music_playing
.export init_sound, start_sound, update_sound, soundBSS
; Ordinarily, the effect engine will move a pulse sound effect from
; $4000 to $4004 if $4004 is idle and $4000 is not, or if $4004 has
; less sfx data left to play than $4000. Turn this off to force all
; pulse sfx to be played on $4000.
SQUARE_POOLING = 1
; As of 2011-03-10, a sound effect interrupts a musical instrument on
; the same channel only if the volume of the sfx is greater than that
; of the instrument. Turn this off to force sound fx to interrupt
; the music whenever sfx data remains on that channel, even if the
; music is louder.
KEEP_MUSIC_IF_LOUDER = 1
SNDCHN = $4015
.segment "BSS"
soundBSS: .res 64
psg_sfx_datalo = psg_sfx_state + 0
psg_sfx_datahi = psg_sfx_state + 1
psg_sfx_lastfreqhi = psg_sfx_state + 18
psg_sfx_remainlen = psg_sfx_state + 19
psg_sfx_rate = soundBSS + 3
psg_sfx_ratecd = soundBSS + 19
.segment "CODE"
;;
; Initializes all sound channels.
;
.proc init_sound
lda #$0F
sta SNDCHN
lda #$30
sta $4000
sta $4004
sta $400C
sta psg_sfx_lastfreqhi+0
sta psg_sfx_lastfreqhi+8
sta psg_sfx_lastfreqhi+4
lda #8
sta $4001
sta $4005
lda #0
sta $4003
sta $4007
sta $400F
sta psg_sfx_remainlen+0
sta psg_sfx_remainlen+4
sta psg_sfx_remainlen+8
sta psg_sfx_remainlen+12
sta music_playing
lda #0
sta $4011
rts
.endproc
;;
; Starts a sound effect.
; (Trashes $0000-$0004 and X.)
;
; @param A sound effect number (0-63)
;
.proc start_sound
snddatalo = 0
snddatahi = 1
sndchno = 2
sndlen = 3
sndrate = 4
asl a
asl a
tax
lda psg_sound_table,x
sta snddatalo
lda psg_sound_table+1,x
sta snddatahi
lda psg_sound_table+2,x
and #$0C
sta sndchno
lda psg_sound_table+2,x
lsr a
lsr a
lsr a
lsr a
sta sndrate
lda psg_sound_table+3,x
sta sndlen
; split up square wave sounds between $4000 and $4004
.if ::SQUARE_POOLING
lda sndchno
bne not_ch0to4 ; if not ch 0, don't try moving it
lda psg_sfx_remainlen+4
cmp psg_sfx_remainlen
bcs not_ch0to4
lda #4
sta sndchno
not_ch0to4:
.endif
ldx sndchno
lda sndlen
cmp psg_sfx_remainlen,x
bcs ch_not_full
rts
ch_not_full:
lda snddatalo
sta psg_sfx_datalo,x
lda snddatahi
sta psg_sfx_datahi,x
lda sndlen
sta psg_sfx_remainlen,x
lda sndrate
sta psg_sfx_rate,x
lda #0
sta psg_sfx_ratecd,x
rts
.endproc
;;
; Updates sound effect channels.
;
.proc update_sound
jsr update_music
ldx #12
loop:
jsr update_music_ch
jsr update_one_ch
dex
dex
dex
dex
bpl loop
rts
.endproc
.proc update_one_ch
; At this point, the music engine should have left duty and volume
; in 2 and pitch in 3.
lda psg_sfx_remainlen,x
bne ch_not_done
lda 2
bne update_channel_hw
; Turn off the channel and force a reinit of the length counter.
cpx #8
beq not_triangle_kill
lda #$30
not_triangle_kill:
sta $4000,x
lda #$FF
sta psg_sfx_lastfreqhi,x
rts
ch_not_done:
; playback rate divider
dec psg_sfx_ratecd,x
bpl rate_divider_cancel
lda psg_sfx_rate,x
sta psg_sfx_ratecd,x
; fetch the instruction
lda psg_sfx_datalo+1,x
sta 1
lda psg_sfx_datalo,x
sta 0
clc
adc #2
sta psg_sfx_datalo,x
bcc :+
inc psg_sfx_datahi,x
:
ldy #0
.if ::KEEP_MUSIC_IF_LOUDER
lda 2
and #$0F
sta 4
lda (0),y
and #$0F
; At this point: A = sfx volume; 4 = musc volume
cmp 4
bcc music_was_louder
.endif
lda (0),y
sta 2
iny
lda (0),y
sta 3
music_was_louder:
dec psg_sfx_remainlen,x
update_channel_hw:
lda 2
ora #$30
cpx #12
bne notnoise
sta $400C
lda 3
sta $400E
rate_divider_cancel:
rts
notnoise:
sta $4000,x
ldy 3
lda tvSystem
beq :+
iny
:
lda periodTableLo,y
sta $4002,x
lda periodTableHi,y
cmp psg_sfx_lastfreqhi,x
beq no_change_to_hi_period
sta psg_sfx_lastfreqhi,x
sta $4003,x
no_change_to_hi_period:
rts
.endproc
.segment "RODATA"
psg_sound_table:
.addr turn_snd
.byt 0, 18
.addr shift_snd
.byt 0, 2
.addr land_snd
.byt 16+0, 15
.addr lock_snd
.byt 12, 2
.addr threat1_snd
.byt 0, 21
.addr threat2_snd
.byt 16+0, 10
.addr shoot_snd
.byt 64+12, 7
.addr die1_snd
.byt 48+0, 17
.addr die2_snd
.byt 48+12, 16
.addr snare_snd
.byt 12, 7
.addr kick_snd
.byt 12, 3
; alternating duty/volume and pitch bytes
turn_snd:
.byt $4F, $24, $44, $24
.byt $4F, $29, $44, $29
.byt $4F, $2E, $44, $2E
.byt $44, $24, $42, $24
.byt $44, $29, $42, $29
.byt $44, $2E, $42, $2E
.byt $42, $24, $41, $24
.byt $42, $29, $41, $29
.byt $42, $2E, $41, $2E
shift_snd:
.byt $4F, $30, $44, $30
land_snd:
.byt $8F, $12, $4F, $0F, $8E, $0C
.byt $0E, $0E, $8D, $0C, $4C, $0A
.byt $8B, $0B, $0A, $09, $89, $06
.byt $48, $08, $87, $07, $06, $05
.byt $84, $06, $42, $04, $81, $03
lock_snd:
.byt $06, $03, $03, $03
threat1_snd:
.byt $46, $1F
.byt $4C, $1F, $4C, $1F, $4C, $25, $4C, $25
.byt $4C, $2B, $4C, $2B, $4C, $31, $4C, $31
.byt $4C, $31, $4C, $31, $4C, $31, $4C, $31, $4C, $31, $4C, $31
.byt $4C, $31, $4B, $31, $4A, $31, $49, $31, $47, $31, $45, $31
threat2_snd:
.byt $4C, $1C, $4C, $22
.byt $4C, $28, $4C, $2E
.byt $4C, $2E, $4C, $2E, $4C, $2E, $4B, $2E, $49, $2E, $46, $2E
shoot_snd:
.byt $0A, $03, $08, $04, $07, $04, $06, $05
.byt $04, $06, $03, $06, $02, $06
die1_snd:
.byt $0F, $07
.byt $0F, $07
.byt $0E, $07
.byt $0D, $07
.byt $0C, $07
.byt $0B, $07
.byt $0A, $07
.byt $09, $07
.byt $08, $07
.byt $07, $07
.byt $06, $07
.byt $05, $07
.byt $04, $07
.byt $03, $07
.byt $02, $07, $01, $07, $01, $07
die2_snd:
.byt $0F, $0E
.byt $0E, $0D
.byt $0D, $0E
.byt $0C, $0E
.byt $0B, $0E
.byt $0A, $0F
.byt $09, $0E
.byt $08, $0E
.byt $07, $0F
.byt $06, $0E
.byt $05, $0F
.byt $04, $0E
.byt $03, $0F
.byt $02, $0E, $01, $0F, $01, $0F
snare_snd:
.byt $0A, $05, $08, $04, $06, $04
.byt $04, $04, $03, $04, $02, $04, $01, $04
kick_snd:
.byt $08,$04,$08,$0E,$04,$0E
.byt $05,$0E,$04,$0E,$03,$0E,$02,$0E,$01,$0E
|
xem/nes | 6,300 | nes-test-roms/spritecans-2011/src/musicseq.s | ;
; Music sequence data for Sprite Cans Demo
; Copyright 2010 Damian Yerrick
; Copyright 1984 Ray Lynch
;
; To the extent permitted by law, copying and distribution of this
; file, with or without modification, are permitted in any medium
; without royalty provided the copyright notice and this notice are
; preserved in all copies of the source code.
; This file is offered as-is, without any warranty.
;
.include "src/musicseq.h"
.segment "RODATA"
musicPatternTable:
.addr csp_pat_warmup
.addr csp_pat_melody_warmup
.addr csp_pat_backing_loop
.addr csp_pat_melody_loop
.addr csp_pat_bass_loop
.addr csp_pat_bass_end
drumSFX:
.byt 10, 9, 3
KICK = 0*8
SNARE = 1*8
CLHAT = 2*8
instrumentTable:
; first byte: initial duty (0/4/8/c) and volume (1-F)
; second byte: volume decrease every 16 frames
; third byte:
; bit 7: cut note if half a row remains
.byt $88, 8, $00, 0 ; bass
.byt $48, 4, $00, 0 ; song start bass
.byt $87, 3, $00, 0 ; bell between rounds
.byt $87, 2, $00, 0 ; xylo
songTable:
.addr csp_conductor
;____________________________________________________________________
csp_conductor:
setTempo 440
playPatSq2 0, 3, 1
waitRows 12*6
playPatSq1 1, 15, 2
waitRows 12*18
segno
playPatSq2 2, 7, 1
waitRows 12*2
playPatSq1 3, 27, 2
playPatTri 4, 14, 0
waitRows 12*18
playPatTri 5, 16, 0
waitRows 12*2
dalSegno
csp_pat_warmup:
.byt N_CSH|D_D2
.byt N_CSH|D_D2
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
; melody cuts in
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_B|D_D8, N_B|D_D8, N_B|D_D8, N_B|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_GS|D_D8, N_GS|D_D8, N_GS|D_D8, N_GS|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_EH|D_D8, N_EH|D_D8, N_EH|D_D8, N_EH|D_D8
.byt N_B|D_D8, N_B|D_D8, N_B|D_D8, N_B|D_D8
.byt N_EH|D_D8, N_EH|D_D8, N_EH|D_D8, N_EH|D_D8
.byt N_B|D_D8, N_B|D_D8, N_B|D_D8, N_B|D_D8
.byt N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8, N_CSH|D_D8
.byt N_GS|D_D8, N_GS|D_D8, N_GS|D_D8, N_GS|D_D8
.byt N_A|D_D8, N_A|D_D8, N_A|D_D8, N_A|D_D8
.byt N_A|D_D8, N_A|D_D8, N_A|D_D8, N_B|D_D8
.byt 255
csp_pat_melody_warmup:
.byt N_CSH|D_8, N_DSH|D_D8, N_EH|D_D8, N_FSH|D_D8, N_GSH|D_D8
.byt N_FSH|D_D8, N_EH|D_D8, N_DSH, N_CSH|D_8, N_DSH|D_2
.byt N_TIE, N_EH, N_DSH|D_8, N_CSH|D_2
.byt N_TIE, N_CSH, N_B|D_8, N_CSH|D_D2
.byt N_B
.byt N_CSH|D_8, N_DSH|D_D8, N_EH|D_D8, N_FSH|D_D8, N_GSH|D_D8
.byt N_FSH|D_D8, N_EH|D_D8, N_DSH, N_CSH|D_8, N_DSH|D_2
.byt N_TIE, N_B, N_DSH|D_8, N_CSH|D_2
.byt N_TIE, N_GS, N_B|D_8, N_CSH|D_2
.byt N_TIE, N_EH, N_FSH|D_8, N_GSH|D_D8
.byt N_GSH|D_D8, N_BH|D_4, N_EH|D_8, N_FSH|D_2
.byt N_TIE, N_EH, N_FSH|D_8, N_GSH|D_D4
.byt N_BH|D_4, N_GSH|D_8, N_FSH|D_2
.byt N_TIE, N_EH, N_DSH|D_8, N_EH|D_D4
.byt N_EH, N_DSH|D_8, N_CSH|D_4
.byt N_DSH|D_4, N_TIE, N_DSH, N_CSH|D_D8, N_B|D_8, N_CSH|D_2
.byt N_TIE, N_CSH|D_4
.byt N_CSH|D_4, N_TIE, N_CSH, N_EH|D_8, N_DSH|D_4
.byt N_CSH|D_D2
.byt REST|D_D2
.byt 255
csp_pat_backing_loop:
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
; melody cuts in
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_G|D_D8, N_GH|D_D8, N_G|D_D8, N_GH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_E|D_D8, N_EH|D_D8, N_E|D_D8, N_EH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_CH|D_D8, N_CHH|D_D8, N_CH|D_D8, N_CHH|D_D8
.byt N_G|D_D8, N_GH|D_D8, N_G|D_D8, N_GH|D_D8
.byt N_CH|D_D8, N_CHH|D_D8, N_CH|D_D8, N_CHH|D_D8
.byt N_G|D_D8, N_GH|D_D8, N_G|D_D8, N_GH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_E|D_D8, N_EH|D_D8, N_E|D_D8, N_EH|D_D8
.byt N_F|D_D8, N_FH|D_D8, N_F|D_D8, N_FH|D_D8
.byt N_F|D_D8, N_FH|D_D8, N_G|D_D8, N_GH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt N_A|D_D8, N_AH|D_D8, N_A|D_D8, N_AH|D_D8
.byt 255
csp_pat_melody_loop:
.byt N_CSH|D_8, N_DSH|D_D8, N_EH|D_D8, N_FSH|D_D8, N_GSH|D_D8
.byt N_FSH|D_D8, N_EH|D_D8, N_DSH, N_CSH|D_8, N_DSH|D_2
.byt N_TIE, N_EH, N_DSH|D_8, N_CSH|D_2
.byt N_TIE, N_B, N_GS|D_8, N_CSH|D_D2
.byt N_B
.byt N_CSH|D_8, N_DSH|D_D8, N_EH|D_D8, N_FSH|D_D8, N_GSH|D_4
.byt N_FSH|D_D8, N_EH|D_8, N_DSH, N_CSH|D_8, N_DSH|D_D4
.byt N_TIE, N_GS, N_B, N_CSH, N_DSH, N_EH, N_DSH
.byt N_CSH|D_4, N_TIE, N_CSH|D_D8, N_B, N_GS|D_8, N_CSH|D_2
.byt N_TIE, N_EH, N_FSH|D_8, N_GSH|D_D8
.byt N_GSH|D_D8, N_BH|D_4, N_EH|D_8, N_FSH|D_2
.byt N_TIE, N_EH, N_FSH|D_8, N_GSH|D_D4
.byt N_BH|D_4, N_GSH|D_8, N_FSH|D_2
.byt N_TIE, N_EH, N_DSH|D_8, N_EH|D_D4
.byt N_EH, N_DSH|D_8, N_CSH|D_4
.byt N_DSH|D_4, N_TIE, N_DSH, N_CSH|D_D8, N_B|D_8, N_CSH|D_D4
.byt N_CSH|D_D4, N_CSH|D_D4
.byt N_CSH, N_EH|D_8, N_DSH|D_4
.byt N_CSH|D_D2
.byt REST|D_D2
.byt REST|D_D2
.byt REST|D_D2
.byt 255
csp_pat_bass_loop:
.byt N_DH|D_2, N_A|D_4
.byt N_D|D_2, N_D, N_A|D_D8
.byt N_G|D_D4, N_C|D_D4
.byt N_D|D_2, N_A|D_4
.byt N_DH|D_D2
.byt N_DH|D_2, N_A|D_4
.byt N_D|D_2, N_D, N_A|D_D8
.byt N_E|D_2, N_TIE, N_A|D_D8
.byt N_D|D_2, N_TIE, N_A|D_D8
.byt N_DH|D_D2
.byt REST|D_4, REST, N_CHH|D_D8, N_FH, N_CH|D_8, N_F
.byt N_C|D_D8, N_C|D_D8, N_C|D_D4
.byt REST|D_4, REST, N_CHH|D_D8, N_FH, N_CH|D_8, N_F
.byt N_C|D_D8, N_C|D_D8, N_C|D_D4
.byt REST|D_4, REST, N_A, N_DH|D_8, N_AH|D_4
.byt REST|D_4, REST, N_A, N_EH|D_8, N_AH|D_4
.byt REST|D_2, N_AS, N_FH|D_8, N_ASH|D_D4
.byt N_FH, N_BB|D_8, N_CH|D_4
.byt 255
csp_pat_bass_end:
.byt N_CH|D_2, N_G|D_4
.byt N_C|D_2, N_G|D_4
.byt N_CH|D_2, N_GH|D_4
.byt N_CHH|D_2, N_CHH, N_GH|D_D8
.byt 255
|
xem/nes | 1,282 | nes-test-roms/instr_test-v3/source/01-implied.s | .include "instr_test.inc"
instrs:
entry $2A,"ROL A" ; A = op A
entry $0A,"ASL A"
entry $6A,"ROR A"
entry $4A,"LSR A"
entry $8A,"TXA" ; AXY = AXY
entry $98,"TYA"
entry $AA,"TAX"
entry $A8,"TAY"
entry $E8,"INX" ; XY = op XY
entry $C8,"INY"
entry $CA,"DEX"
entry $88,"DEY"
entry $38,"SEC" ; flags = op flags
entry $18,"CLC"
entry $F8,"SED"
entry $D8,"CLD"
entry $78,"SEI"
entry $58,"CLI"
entry $B8,"CLV"
entry $EA,"NOP"
.ifndef OFFICIAL_ONLY
entry $1A,"NOP"
entry $3A,"NOP"
entry $5A,"NOP"
entry $7A,"NOP"
entry $DA,"NOP"
entry $FA,"NOP"
.endif
instrs_size = * - instrs
instr_template:
nop
jmp instr_done
instr_template_size = * - instr_template
operand = in_a
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $B129E6BE
.dword $965A320E
.dword $905D41EE
.dword $51FA7AD7
.dword $A60AE5B1
.dword $8FA16B44
.dword $D311C870
.dword $453F27CD
.dword $4F91B466
.dword $604DB29C
.dword $4BCFE982
.dword $8E0D1602
.dword $26DBEBEC
.dword $49214BA2
.dword $8C4FB749
.dword $37962351
.dword $99E7216C
.dword $6408D38D
.dword $C334A2A7
.dword $55827CC6
.dword $55827CC6
.dword $55827CC6
.dword $55827CC6
.dword $55827CC6
.dword $55827CC6
.dword $55827CC6
|
xem/nes | 2,384 | nes-test-roms/instr_test-v3/source/06-abs_xy.s | .include "instr_test.inc"
instrs:
entry $BD,"LDA a,X" ; AXY = a,XY
entry $B9,"LDA a,Y"
entry $BC,"LDY a,X"
entry $BE,"LDX a,Y"
entry $9D,"STA a,X" ; a,XY = A
entry $99,"STA a,Y"
entry $FE,"INC a,X" ; a,XY = op a,XY
entry $DE,"DEC a,X"
entry $1E,"ASL a,X"
entry $5E,"LSR a,X"
entry $3E,"ROL a,X"
entry $7E,"ROR a,X"
entry $7D,"ADC a,X" ; A = A op a,XY
entry $79,"ADC a,Y"
entry $FD,"SBC a,X"
entry $F9,"SBC a,Y"
entry $1D,"ORA a,X"
entry $19,"ORA a,Y"
entry $3D,"AND a,X"
entry $39,"AND a,Y"
entry $5D,"EOR a,X"
entry $59,"EOR a,Y"
entry $DD,"CMP a,X" ; A op a,XY
entry $D9,"CMP a,Y"
.ifndef OFFICIAL_ONLY
entry $1C,"TOP abs,X"
entry $3C,"TOP abs,X"
entry $5C,"TOP abs,X"
entry $7C,"TOP abs,X"
entry $DC,"TOP abs,X"
entry $FC,"TOP abs,X"
entry $1F,"SLO abs,X"
entry $3F,"RLA abs,X"
entry $5F,"SRE abs,X"
entry $7F,"RRA abs,X"
entry $9C,"SYA abs,X"
entry $DF,"DCP abs,X"
entry $FF,"ISC abs,X"
entry $1B,"SLO abs,Y"
entry $3B,"RLA abs,Y"
entry $5B,"SRE abs,Y"
entry $7B,"RRA abs,Y"
entry $9E,"SXA abs,Y"
entry $BF,"LAX abs,Y"
entry $DB,"DCP abs,Y"
entry $FB,"ISC abs,Y"
.endif
instrs_size = * - instrs
operand = $2FE
instr_template:
lda operand
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #1
jsr :+
lda #2
: sta in_x
eor #3
sta in_y
test_normal
rts
correct_checksums:
.dword $8B53FA6E
.dword $ED606C6A
.dword $63FE045F
.dword $B6C7BA63
.dword $B374C422
.dword $CE7ABA24
.dword $771C915B
.dword $71675CF6
.dword $DD12400E
.dword $808A4BF5
.dword $54FC683C
.dword $46392060
.dword $6C804870
.dword $CD587E36
.dword $EF2A694B
.dword $E0D6DFA5
.dword $BFA7B86E
.dword $D37908FE
.dword $AAE1A597
.dword $7F54BFF0
.dword $D37CC347
.dword $94C851D4
.dword $539CBA74
.dword $56D05064
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $14AA08E6
.dword $BF4BF92E
.dword $C2207461
.dword $F34758B1
.dword $7DA6ABE2
.dword $E62C1F92
.dword $A3FD5073
.dword $234A2B6E
.dword $84467B6B
.dword $CED1ADC0
.dword $6655FFC6
.dword $9E821698
.dword $47579BB5
.dword $49B176EB
.dword $A72DC04B
|
xem/nes | 1,538 | nes-test-roms/instr_test-v3/source/07-ind_x.s | .include "instr_test.inc"
instrs:
entry $A1,"LDA (z,X)" ; A = (z,X)
entry $81,"STA (z,X)" ; (z,X) = A
entry $C1,"CMP (z,X)" ; A op (z,X)
entry $61,"ADC (z,X)" ; A = A op (z,X)
entry $E1,"SBC (z,X)"
entry $01,"ORA (z,X)"
entry $21,"AND (z,X)"
entry $41,"EOR (z,X)"
.ifndef OFFICIAL_ONLY
entry $03,"SLO (z,X)"
entry $23,"RLA (z,X)"
entry $43,"SRE (z,X)"
entry $63,"RRA (z,X)"
entry $83,"AAX (z,X)"
entry $A3,"LAX (z,X)"
entry $C3,"DCP (z,X)"
entry $E3,"ISC (z,X)"
.endif
instrs_size = * - instrs
address = <$FF
operand = $2FF
instr_template:
lda (address,x)
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
lda address
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #<operand
sta address
lda #>operand
sta <(address+1)
lda #<(operand+1)
sta <(address+2)
lda #>(operand+1)
sta <(address+3)
; Be sure X doesn't have values other than
; 0 or 2
lda #0
jsr :+
lda #2
: sta in_x
lda #$A5
sta address+1
sta address+2
sta address+3
test_normal
rts
correct_checksums:
.dword $C7123EFB
.dword $A914111E
.dword $78FDC202
.dword $727A1EC0
.dword $0CCBE904
.dword $918A9806
.dword $47A2405D
.dword $9D5AE8F0
.dword $57CC5810
.dword $686F6585
.dword $41CCD775
.dword $1CCC0373
.dword $54931D9E
.dword $D221ACE3
.dword $2F5C514E
.dword $47A96694
|
xem/nes | 1,497 | nes-test-roms/instr_test-v3/source/05-absolute.s | .include "instr_test.inc"
instrs:
entry $AD,"LDA a" ; AXY = a
entry $AE,"LDX a"
entry $AC,"LDY a"
entry $8D,"STA a" ; a = AXY
entry $8E,"STX a"
entry $8C,"STY a"
entry $EE,"INC a" ; a = op a
entry $CE,"DEC a"
entry $0E,"ASL a"
entry $4E,"LSR a"
entry $2E,"ROL a"
entry $6E,"ROR a"
entry $6D,"ADC a" ; A = A op a
entry $ED,"SBC a"
entry $0D,"ORA a"
entry $2D,"AND a"
entry $4D,"EOR a"
entry $CD,"CMP a" ; AXY op a
entry $2C,"BIT a"
entry $EC,"CPX a"
entry $CC,"CPY a"
.ifndef OFFICIAL_ONLY
entry $0C,"TOP abs"
entry $0F,"SLO abs"
entry $2F,"RLA abs"
entry $4F,"SRE abs"
entry $6F,"RRA abs"
entry $8F,"AAX abs"
entry $AF,"LAX abs"
entry $CF,"DCP abs"
entry $EF,"ISC abs"
.endif
instrs_size = * - instrs
operand = $2FE
instr_template:
lda operand
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $5D5728B8
.dword $EA228F76
.dword $7C0C60CB
.dword $47422599
.dword $5AC36C4F
.dword $34B566BB
.dword $2FEC251E
.dword $2D40B32D
.dword $13852B6A
.dword $53AEB6C8
.dword $5F3FDB23
.dword $DC0B06BF
.dword $49288BFC
.dword $14C7EA46
.dword $42684E66
.dword $EA1D7F06
.dword $512F9D2A
.dword $70AA1B34
.dword $59C741E9
.dword $D3DC4002
.dword $6675067C
.dword $6CB13BC0
.dword $E8A350DF
.dword $BB4C5C90
.dword $02F88F3F
.dword $9749194D
.dword $15C5F146
.dword $D311C870
.dword $F0A1F923
.dword $46252975
|
xem/nes | 1,552 | nes-test-roms/instr_test-v3/source/03-zero_page.s | .include "instr_test.inc"
instrs:
entry $A5,"LDA z" ; AXY = z
entry $A6,"LDX z"
entry $A4,"LDY z"
entry $85,"STA z" ; z = AXY
entry $86,"STX z"
entry $84,"STY z"
entry $E6,"INC z" ; z = op z
entry $C6,"DEC z"
entry $06,"ASL z"
entry $46,"LSR z"
entry $26,"ROL z"
entry $66,"ROR z"
entry $65,"ADC z" ; A = A op z
entry $E5,"SBC z"
entry $05,"ORA z"
entry $25,"AND z"
entry $45,"EOR z"
entry $24,"BIT z" ; AXY op z
entry $C5,"CMP z"
entry $E4,"CPX z"
entry $C4,"CPY z"
.ifndef OFFICIAL_ONLY
entry $04,"DOP z"
entry $44,"DOP z"
entry $64,"DOP z"
entry $07,"SLO z"
entry $27,"RLA z"
entry $47,"SRE z"
entry $67,"RRA z"
entry $87,"AAX z"
entry $A7,"LAX z"
entry $C7,"DCP z"
entry $E7,"ISC z"
.endif
instrs_size = * - instrs
operand = <$FE
instr_template:
lda <operand
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $5D5728B8
.dword $EA228F76
.dword $7C0C60CB
.dword $47422599
.dword $5AC36C4F
.dword $34B566BB
.dword $2FEC251E
.dword $2D40B32D
.dword $13852B6A
.dword $53AEB6C8
.dword $5F3FDB23
.dword $DC0B06BF
.dword $49288BFC
.dword $14C7EA46
.dword $42684E66
.dword $EA1D7F06
.dword $512F9D2A
.dword $59C741E9
.dword $70AA1B34
.dword $D3DC4002
.dword $6675067C
.dword $6CB13BC0
.dword $6CB13BC0
.dword $6CB13BC0
.dword $E8A350DF
.dword $BB4C5C90
.dword $02F88F3F
.dword $9749194D
.dword $15C5F146
.dword $D311C870
.dword $F0A1F923
.dword $46252975
|
xem/nes | 1,313 | nes-test-roms/instr_test-v3/source/08-ind_y.s | .include "instr_test.inc"
instrs:
entry $B1,"LDA (z),Y" ; A = (z),Y
entry $91,"STA (z),Y" ; (z),Y = A
entry $D1,"CMP (z),Y" ; A op (z),Y
entry $11,"ORA (z),Y" ; A = A op (z),Y
entry $F1,"SBC (z),Y"
entry $71,"ADC (z),Y"
entry $31,"AND (z),Y"
entry $51,"EOR (z),Y"
.ifndef OFFICIAL_ONLY
entry $13,"SLO (z),Y"
entry $33,"RLA (z),Y"
entry $53,"SRE (z),Y"
entry $73,"RRA (z),Y"
entry $B3,"LAX (z),Y"
entry $D3,"DCP (z),Y"
entry $F3,"ISC (z),Y"
.endif
instrs_size = * - instrs
address = <$FF
operand = $2FF
instr_template:
lda (address),y
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta operand+1
lda values+2,y
sta operand+2
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda operand+1
jsr update_crc_fast
lda operand+2
jsr update_crc_fast
lda address
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #<operand
sta address
lda #>operand
sta <(address+1)
lda #0
jsr :+
lda #1
: sta in_y
test_normal
rts
correct_checksums:
.dword $C34014B1
.dword $AD463B54
.dword $7CAFE848
.dword $95D8B24C
.dword $0899C34E
.dword $7628348A
.dword $43F06A17
.dword $9908C2BA
.dword $539E725A
.dword $6C3D4FCF
.dword $459EFD3F
.dword $189E2939
.dword $B1EC2D77
.dword $2B0E7B04
.dword $43FB4CDE
|
xem/nes | 1,128 | nes-test-roms/instr_test-v3/source/15-special.s | CUSTOM_IRQ=1
.include "shell.inc"
irq: pla
pha
rti
jmp_6ff:
.byte $6C ; JMP ($6FF) (to avoid warning)
.word $6FF
main:
setb SNDMODE,$40 ; disable frame IRQ
set_test 3,"JMP ($6FF) should get high byte from $600"
setb $6FF,$F0
setb $600,$07
setb $700,$06
setb $7F0,$E8 ; INX
setb $7F1,$60 ; RTS
setb $6F0,$60 ; RTS
ldx #0
jsr jmp_6ff
cpx #1
jne test_failed
set_test 4,"RTS should return to addr+1"
lda #>:+
pha
lda #<:+
pha
ldx #0
rts
inx
: inx
inx
cpx #1
jne test_failed
set_test 5,"RTI should return to addr"
lda #>:+
pha
lda #<:+
pha
ldx #0
php
rti
inx
: inx
inx
cpx #2
jne test_failed
set_test 6,"JSR should push addr of next instr - 1"
setb $6FE,$20 ; JSR
setb $6FF,<:+
setb $700,>:+
jmp $6FE
: pla
cmp #$00
jne test_failed
pla
cmp #$07
jne test_failed
set_test 7,"BRK should push status with bits 4 and 5 set"
lda #$00
pha
plp
brk
nop
cmp #$30
jne test_failed
lda #$FF
pha
plp
brk
nop
cmp #$FF
jne test_failed
set_test 8,"BRK should push address BRK + 2"
ldx #1
brk
inx
inx
cpx #2
jne test_failed
jmp tests_passed
|
xem/nes | 1,228 | nes-test-roms/instr_test-v3/source/02-immediate.s | .include "instr_test.inc"
instrs:
entry $A9,"LDA #n" ; AXY = #n
entry $A2,"LDX #n"
entry $A0,"LDY #n"
entry $69,"ADC #n" ; A = A op #n
entry $E9,"SBC #n"
entry $09,"ORA #n"
entry $29,"AND #n"
entry $49,"EOR #n"
entry $C9,"CMP #n" ; AXY op #n
entry $E0,"CPX #n"
entry $C0,"CPY #n"
.ifndef OFFICIAL_ONLY
entry $EB,"SBC #n"
entry $80,"DOP #n"
entry $82,"DOP #n"
entry $89,"DOP #n"
entry $C2,"DOP #n"
entry $E2,"DOP #n"
entry $0B,"AAC #n"
entry $2B,"AAC #n"
entry $4B,"ASR #n"
entry $6B,"ARR #n"
entry $AB,"ATX #n"
entry $CB,"AXS #n"
.endif
instrs_size = * - instrs
operand = instr+1
instr_template:
lda #0
jmp instr_done
instr_template_size = * - instr_template
.define set_in set_paxyso
.define check_out check_paxyso
.include "instr_test_end.s"
test_values:
test_normal
rts
correct_checksums:
.dword $5D5728B8
.dword $EA228F76
.dword $7C0C60CB
.dword $49288BFC
.dword $14C7EA46
.dword $42684E66
.dword $EA1D7F06
.dword $512F9D2A
.dword $70AA1B34
.dword $D3DC4002
.dword $6675067C
.dword $14C7EA46
.dword $6CB13BC0
.dword $6CB13BC0
.dword $6CB13BC0
.dword $6CB13BC0
.dword $6CB13BC0
.dword $FE191060
.dword $FE191060
.dword $27355577
.dword $C6B8642B
.dword $D311C870
.dword $EE21BFAD
|
xem/nes | 1,350 | nes-test-roms/instr_test-v3/source/10-stack.s | .include "instr_test.inc"
instrs:
entry $48,"PHA"
entry $08,"PHP"
entry $68,"PLA"
entry $28,"PLP"
entry $9A,"TXS"
entry $BA,"TSX"
instrs_size = * - instrs
instr_template:
pha
jmp instr_done
instr_template_size = * - instr_template
values2:
.byte 0,$FF,$01,$02,$04,$08,$10,$20,$40,$80
values2_size = * - values2
zp_byte operand
.macro set_in
sta in_p
set_paxyso
; Clear bytes on stack
stx $17F
sty $180
stx $181
sty $1FE
stx $1FF
sty $100
stx $101
sty $102
.endmacro
zp_byte save
zp_byte save2
zp_byte save3
zp_byte save4
zp_byte save5
.macro check_out
php
sta save ; A
pla
sta save2 ; P
pla
sta save3 ; PLA
stx save4 ; X
tsx
stx save5 ; S
ldx saved_s
txs
; Output
tya
jsr update_crc_fast
lda save
jsr update_crc_fast
lda save2
jsr update_crc_fast
lda save3
jsr update_crc_fast
lda save4
jsr update_crc_fast
lda save5
jsr update_crc_fast
ldx in_s
dex
lda $100,x
jsr update_crc_fast
inx
lda $100,x
jsr update_crc_fast
inx
lda $100,x
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
; Values for SP
lda #$80
jsr :+
lda #$00
jsr :+
lda #$01
jsr :+
lda #$FF
jsr :+
lda #$FE
: sta in_s
test_normal
rts
correct_checksums:
.dword $798D2DB5
.dword $0CA6FC29
.dword $68C636F1
.dword $D35DB3D5
.dword $F1159742
.dword $A3EBB2D7
|
xem/nes | 1,873 | nes-test-roms/instr_test-v3/source/04-zp_xy.s | .include "instr_test.inc"
instrs:
entry $B5,"LDA z,X" ; AXY = z,XY
entry $B4,"LDY z,X"
entry $B6,"LDX z,Y"
entry $95,"STA z,X" ; z,XY = AXY
entry $94,"STY z,X"
entry $96,"STX z,Y"
entry $F6,"INC z,X" ; z,XY = op z,XY
entry $D6,"DEC z,X"
entry $16,"ASL z,X"
entry $56,"LSR z,X"
entry $36,"ROL z,X"
entry $76,"ROR z,X"
entry $75,"ADC z,X" ; A = A op z,XY
entry $F5,"SBC z,X"
entry $15,"ORA z,X"
entry $35,"AND z,X"
entry $55,"EOR z,X"
entry $D5,"CMP z,X" ; A op z,XY
.ifndef OFFICIAL_ONLY
entry $14,"DOP z,X"
entry $34,"DOP z,X"
entry $54,"DOP z,X"
entry $74,"DOP z,X"
entry $D4,"DOP z,X"
entry $F4,"DOP z,X"
entry $17,"SLO z,X"
entry $37,"RLA z,X"
entry $57,"SRE z,X"
entry $77,"RRA z,X"
entry $D7,"DCP z,X"
entry $F7,"ISC z,X"
entry $97,"AAX z,Y"
entry $B7,"LAX z,Y"
.endif
instrs_size = * - instrs
operand = <$FE
instr_template:
lda <operand
jmp instr_done
instr_template_size = * - instr_template
.macro set_in
lda values+1,y
sta <(operand+1)
lda values+2,y
sta <(operand+2)
set_paxyso
.endmacro
.macro check_out
check_paxyso
lda <(operand+1)
jsr update_crc_fast
lda <((operand+2)&$FF)
jsr update_crc_fast
.endmacro
.include "instr_test_end.s"
test_values:
lda #1
jsr :+
lda #2
: sta in_x
eor #3
sta in_y
test_normal
rts
correct_checksums:
.dword $8B53FA6E
.dword $63FE045F
.dword $B6C7BA63
.dword $B374C422
.dword $A0C0220A
.dword $FB4F13E9
.dword $771C915B
.dword $71675CF6
.dword $DD12400E
.dword $808A4BF5
.dword $54FC683C
.dword $46392060
.dword $6C804870
.dword $EF2A694B
.dword $BFA7B86E
.dword $AAE1A597
.dword $D37CC347
.dword $539CBA74
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $FEBE0BFF
.dword $14AA08E6
.dword $BF4BF92E
.dword $C2207461
.dword $F34758B1
.dword $E62C1F92
.dword $A3FD5073
.dword $68875F5F
.dword $47579BB5
|
xem/nes | 1,875 | nes-test-roms/instr_test-v3/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data RODATA,{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing = init_crc
; Reports that all tests passed
tests_passed:
jsr print_filename
print_str newline,"Passed"
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
jsr print_filename
print_str newline,"Done"
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF and 0 as 1, in case it wasn't ever set
beq @unset
inx
bne :+
@unset: inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
jsr print_filename
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
jsr is_crc_
bne :+
jsr reset_crc
pla
rts
: jsr print_newline
jsr print_crc
jmp test_failed
|
xem/nes | 3,234 | nes-test-roms/instr_test-v3/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
zp_byte print_temp_
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr print_nibble_
pla
pha
and #$0F
jsr print_nibble_
pla
rts
print_nibble_:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints low 4 bits of A as single hex character
; Preserved: A, X, Y
print_nibble:
pha
and #$0F
jsr update_crc
jsr print_nibble_
pla
rts
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
jsr print_str_
.byte str
.ifnblank str2
.byte str2
.endif
.byte 0
.endmacro
print_str_:
sta print_temp_
pla
sta addr
pla
sta addr+1
jsr inc_addr
jsr print_str_addr
lda print_temp_
jmp (addr)
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
bne :+
inc addr+1
: rts
; Prints A as 1-3 digit decimal.
; In: A = MSB
; Preserved: A, X, Y
print_dec:
sta print_temp_
pha
txa
pha
tya
pha
ldy print_temp_
lda #0
sta print_temp_
tya
jmp :+
; Prints 16-bit AY as 1-5 digit decimal.
; Preserved: A, X, Y
print_ay_dec:
jsr update_crc
sta print_temp_
pha
txa
pha
tya
pha
: jsr update_crc
; Strip leading zeroes
ldx #6
: dex
cmp @lsb-1,x
lda print_temp_
sbc @msb-1,x
tya
bcc :-
bcs @non_zero
; Print remaining digits
@more: ; Commit subtraction
iny
sta print_temp_
pla
; Subtract
@digit: sbc @lsb,x
pha
lda print_temp_
sbc @msb,x
bcs @more
; Print digit and undo subtraction
tya
jsr print_char_
pla
clc
adc @lsb,x
@non_zero:
sec
ldy #'0'
dex
bne @digit
ora #'0'
jsr print_char_
pla
tay
pla
tax
pla
rts
@lsb: .byte 0,<10,<100,<1000,<10000
@msb: .byte 0,>10,>100,>1000,>10000
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
xem/nes | 5,224 | nes-test-roms/instr_test-v3/source/common/crc_fast.s | ; Fast table-based CRC-32
; Initializes fast CRC tables and resets checksum.
; Preserved: Y
init_crc_fast = reset_crc
; Updates checksum with byte from A
; Preserved: X, Y
; Time: 54 clocks
update_crc_fast:
stx checksum_temp
; Updates checksum with byte from A
; Preserved: Y
; Time: 42 clocks
.macro update_crc_fast
eor checksum
tax
lda checksum+1
eor checksum_t0,x
sta checksum
lda checksum+2
eor checksum_t1,x
sta checksum+1
lda checksum+3
eor checksum_t2,x
sta checksum+2
lda checksum_t3,x
sta checksum+3
.endmacro
update_crc_fast
ldx checksum_temp
rts
.pushseg
.segment "RODATA"
.align 256
checksum_t0:
.byte $8D,$1B,$A1,$37,$94,$02,$B8,$2E,$BF,$29,$93,$05,$A6,$30,$8A,$1C
.byte $E9,$7F,$C5,$53,$F0,$66,$DC,$4A,$DB,$4D,$F7,$61,$C2,$54,$EE,$78
.byte $45,$D3,$69,$FF,$5C,$CA,$70,$E6,$77,$E1,$5B,$CD,$6E,$F8,$42,$D4
.byte $21,$B7,$0D,$9B,$38,$AE,$14,$82,$13,$85,$3F,$A9,$0A,$9C,$26,$B0
.byte $1D,$8B,$31,$A7,$04,$92,$28,$BE,$2F,$B9,$03,$95,$36,$A0,$1A,$8C
.byte $79,$EF,$55,$C3,$60,$F6,$4C,$DA,$4B,$DD,$67,$F1,$52,$C4,$7E,$E8
.byte $D5,$43,$F9,$6F,$CC,$5A,$E0,$76,$E7,$71,$CB,$5D,$FE,$68,$D2,$44
.byte $B1,$27,$9D,$0B,$A8,$3E,$84,$12,$83,$15,$AF,$39,$9A,$0C,$B6,$20
.byte $AD,$3B,$81,$17,$B4,$22,$98,$0E,$9F,$09,$B3,$25,$86,$10,$AA,$3C
.byte $C9,$5F,$E5,$73,$D0,$46,$FC,$6A,$FB,$6D,$D7,$41,$E2,$74,$CE,$58
.byte $65,$F3,$49,$DF,$7C,$EA,$50,$C6,$57,$C1,$7B,$ED,$4E,$D8,$62,$F4
.byte $01,$97,$2D,$BB,$18,$8E,$34,$A2,$33,$A5,$1F,$89,$2A,$BC,$06,$90
.byte $3D,$AB,$11,$87,$24,$B2,$08,$9E,$0F,$99,$23,$B5,$16,$80,$3A,$AC
.byte $59,$CF,$75,$E3,$40,$D6,$6C,$FA,$6B,$FD,$47,$D1,$72,$E4,$5E,$C8
.byte $F5,$63,$D9,$4F,$EC,$7A,$C0,$56,$C7,$51,$EB,$7D,$DE,$48,$F2,$64
.byte $91,$07,$BD,$2B,$88,$1E,$A4,$32,$A3,$35,$8F,$19,$BA,$2C,$96,$00
checksum_t1:
.byte $EF,$DF,$8E,$BE,$2B,$1B,$4A,$7A,$67,$57,$06,$36,$A3,$93,$C2,$F2
.byte $FF,$CF,$9E,$AE,$3B,$0B,$5A,$6A,$77,$47,$16,$26,$B3,$83,$D2,$E2
.byte $CF,$FF,$AE,$9E,$0B,$3B,$6A,$5A,$47,$77,$26,$16,$83,$B3,$E2,$D2
.byte $DF,$EF,$BE,$8E,$1B,$2B,$7A,$4A,$57,$67,$36,$06,$93,$A3,$F2,$C2
.byte $AE,$9E,$CF,$FF,$6A,$5A,$0B,$3B,$26,$16,$47,$77,$E2,$D2,$83,$B3
.byte $BE,$8E,$DF,$EF,$7A,$4A,$1B,$2B,$36,$06,$57,$67,$F2,$C2,$93,$A3
.byte $8E,$BE,$EF,$DF,$4A,$7A,$2B,$1B,$06,$36,$67,$57,$C2,$F2,$A3,$93
.byte $9E,$AE,$FF,$CF,$5A,$6A,$3B,$0B,$16,$26,$77,$47,$D2,$E2,$B3,$83
.byte $6C,$5C,$0D,$3D,$A8,$98,$C9,$F9,$E4,$D4,$85,$B5,$20,$10,$41,$71
.byte $7C,$4C,$1D,$2D,$B8,$88,$D9,$E9,$F4,$C4,$95,$A5,$30,$00,$51,$61
.byte $4C,$7C,$2D,$1D,$88,$B8,$E9,$D9,$C4,$F4,$A5,$95,$00,$30,$61,$51
.byte $5C,$6C,$3D,$0D,$98,$A8,$F9,$C9,$D4,$E4,$B5,$85,$10,$20,$71,$41
.byte $2D,$1D,$4C,$7C,$E9,$D9,$88,$B8,$A5,$95,$C4,$F4,$61,$51,$00,$30
.byte $3D,$0D,$5C,$6C,$F9,$C9,$98,$A8,$B5,$85,$D4,$E4,$71,$41,$10,$20
.byte $0D,$3D,$6C,$5C,$C9,$F9,$A8,$98,$85,$B5,$E4,$D4,$41,$71,$20,$10
.byte $1D,$2D,$7C,$4C,$D9,$E9,$B8,$88,$95,$A5,$F4,$C4,$51,$61,$30,$00
checksum_t2:
.byte $02,$05,$0C,$0B,$6F,$68,$61,$66,$D9,$DE,$D7,$D0,$B4,$B3,$BA,$BD
.byte $B5,$B2,$BB,$BC,$D8,$DF,$D6,$D1,$6E,$69,$60,$67,$03,$04,$0D,$0A
.byte $6C,$6B,$62,$65,$01,$06,$0F,$08,$B7,$B0,$B9,$BE,$DA,$DD,$D4,$D3
.byte $DB,$DC,$D5,$D2,$B6,$B1,$B8,$BF,$00,$07,$0E,$09,$6D,$6A,$63,$64
.byte $DE,$D9,$D0,$D7,$B3,$B4,$BD,$BA,$05,$02,$0B,$0C,$68,$6F,$66,$61
.byte $69,$6E,$67,$60,$04,$03,$0A,$0D,$B2,$B5,$BC,$BB,$DF,$D8,$D1,$D6
.byte $B0,$B7,$BE,$B9,$DD,$DA,$D3,$D4,$6B,$6C,$65,$62,$06,$01,$08,$0F
.byte $07,$00,$09,$0E,$6A,$6D,$64,$63,$DC,$DB,$D2,$D5,$B1,$B6,$BF,$B8
.byte $BA,$BD,$B4,$B3,$D7,$D0,$D9,$DE,$61,$66,$6F,$68,$0C,$0B,$02,$05
.byte $0D,$0A,$03,$04,$60,$67,$6E,$69,$D6,$D1,$D8,$DF,$BB,$BC,$B5,$B2
.byte $D4,$D3,$DA,$DD,$B9,$BE,$B7,$B0,$0F,$08,$01,$06,$62,$65,$6C,$6B
.byte $63,$64,$6D,$6A,$0E,$09,$00,$07,$B8,$BF,$B6,$B1,$D5,$D2,$DB,$DC
.byte $66,$61,$68,$6F,$0B,$0C,$05,$02,$BD,$BA,$B3,$B4,$D0,$D7,$DE,$D9
.byte $D1,$D6,$DF,$D8,$BC,$BB,$B2,$B5,$0A,$0D,$04,$03,$67,$60,$69,$6E
.byte $08,$0F,$06,$01,$65,$62,$6B,$6C,$D3,$D4,$DD,$DA,$BE,$B9,$B0,$B7
.byte $BF,$B8,$B1,$B6,$D2,$D5,$DC,$DB,$64,$63,$6A,$6D,$09,$0E,$07,$00
checksum_t3:
.byte $D2,$A5,$3C,$4B,$D5,$A2,$3B,$4C,$DC,$AB,$32,$45,$DB,$AC,$35,$42
.byte $CF,$B8,$21,$56,$C8,$BF,$26,$51,$C1,$B6,$2F,$58,$C6,$B1,$28,$5F
.byte $E9,$9E,$07,$70,$EE,$99,$00,$77,$E7,$90,$09,$7E,$E0,$97,$0E,$79
.byte $F4,$83,$1A,$6D,$F3,$84,$1D,$6A,$FA,$8D,$14,$63,$FD,$8A,$13,$64
.byte $A4,$D3,$4A,$3D,$A3,$D4,$4D,$3A,$AA,$DD,$44,$33,$AD,$DA,$43,$34
.byte $B9,$CE,$57,$20,$BE,$C9,$50,$27,$B7,$C0,$59,$2E,$B0,$C7,$5E,$29
.byte $9F,$E8,$71,$06,$98,$EF,$76,$01,$91,$E6,$7F,$08,$96,$E1,$78,$0F
.byte $82,$F5,$6C,$1B,$85,$F2,$6B,$1C,$8C,$FB,$62,$15,$8B,$FC,$65,$12
.byte $3F,$48,$D1,$A6,$38,$4F,$D6,$A1,$31,$46,$DF,$A8,$36,$41,$D8,$AF
.byte $22,$55,$CC,$BB,$25,$52,$CB,$BC,$2C,$5B,$C2,$B5,$2B,$5C,$C5,$B2
.byte $04,$73,$EA,$9D,$03,$74,$ED,$9A,$0A,$7D,$E4,$93,$0D,$7A,$E3,$94
.byte $19,$6E,$F7,$80,$1E,$69,$F0,$87,$17,$60,$F9,$8E,$10,$67,$FE,$89
.byte $49,$3E,$A7,$D0,$4E,$39,$A0,$D7,$47,$30,$A9,$DE,$40,$37,$AE,$D9
.byte $54,$23,$BA,$CD,$53,$24,$BD,$CA,$5A,$2D,$B4,$C3,$5D,$2A,$B3,$C4
.byte $72,$05,$9C,$EB,$75,$02,$9B,$EC,$7C,$0B,$92,$E5,$7B,$0C,$95,$E2
.byte $6F,$18,$81,$F6,$68,$1F,$86,$F1,$61,$16,$8F,$F8,$66,$11,$88,$FF
.popseg
|
xem/nes | 3,456 | nes-test-roms/instr_test-v3/source/common/shell_misc.s | ; Reports internal error and exits program
internal_error:
assert_failed:
pla
tay
pla
init_cpu_regs
print_str newline,"internal error, PC="
jsr print_hex
jsr print_y
lda #255
jmp exit
.import __NVRAM_LOAD__, __NVRAM_SIZE__
.macro fill_ram_ Begin, End
; Simpler to count from negative size up to 0,
; and adjust address downward to compensate
; for initial low byte in Y index
.local Neg_size
Neg_size = (Begin) - (End)
ldxy #(Begin) - <Neg_size
sty addr
stx addr+1
ldxy #Neg_size
: sta (addr),y
iny
bne :-
inc addr+1
inx
bne :-
.endmacro
; Clears 0 through ($100+S), $200 through __NVRAM_LOAD__-1, and
; __NVRAM_LOAD__+__NVRAM_SIZE__ through $7FF
clear_ram:
lda #0
bss_begin = $200
fill_ram_ bss_begin,__NVRAM_LOAD__
fill_ram_ __NVRAM_LOAD__+__NVRAM_SIZE__,$800
; Zero-page
tax
: sta 0,x
inx
bne :-
; Stack below S
tsx
inx
: dex
sta $100,x
bne :-
rts
nv_res unused_nv_var ; to avoid size=0
; Clears nvram
clear_nvram:
lda #0
fill_ram_ __NVRAM_LOAD__,__NVRAM_LOAD__+__NVRAM_SIZE__
rts
; Prints filename and newline, if available, otherwise nothing.
; Preserved: A, X, Y
print_filename:
.ifdef FILENAME_KNOWN
; avoid cluttering output with filename on devcart
.ifndef BUILD_DEVCART
pha
jsr print_newline
setw addr,filename
jsr print_str_addr
jsr print_newline
pla
.endif
.endif
rts
.pushseg
.segment "RODATA"
; TODO: use approach from SNES, where length doesn't affect data
; Filename terminated with zero byte.
filename:
.ifdef FILENAME_KNOWN
.incbin "ram:nes_temp"
.endif
.byte 0
.popseg
;**** ROM-specific ****
.ifndef BUILD_NSF
.include "ppu.s"
avoid_silent_nsf:
play_byte:
rts
; Disables interrupts and loops forever. When running on
; devcart, this is patched to re-run loader.
.ifndef CUSTOM_FOREVER
forever:
sei
lda #0
sta PPUCTRL
: beq :-
.res $10,$EA ; room for code to run loader
.endif
; Default NMI
.ifndef CUSTOM_NMI
zp_byte nmi_count
zp_byte flags_from_nmi
zp_byte pclo_from_nmi
zp_byte nmi_temp
nmi: ; Record flags and PC low byte from stack
sta nmi_temp
pla
sta flags_from_nmi
pla
sta pclo_from_nmi
pha
lda flags_from_nmi
pha
lda nmi_temp
inc nmi_count
rti
; Waits for NMI. Must be using NMI handler that increments
; nmi_count, with NMI enabled.
; Preserved: X, Y
wait_nmi:
lda nmi_count
: cmp nmi_count
beq :-
rts
.endif
; Default IRQ
.ifndef CUSTOM_IRQ
zp_byte flags_from_irq
zp_byte pclo_from_irq
zp_byte irq_count
irq: ; Record flags and PC low byte from stack
pla
sta flags_from_irq
pla
sta pclo_from_irq
pha
lda flags_from_irq
pha
inc irq_count
bit SNDCHN ; clear frame IRQ flag
rti
.endif
.endif
; Reports A in binary as high and low tones, with
; leading low tone for reference. Omits leading
; zeroes. Doesn't hang if no APU is present.
; Preserved: A, X, Y
play_hex:
pha
; Make low reference beep
clc
jsr @beep
; Remove high zero bits
sec
: rol a
bcc :-
; Play remaining bits
beq @zero
: jsr @beep
asl a
bne :-
@zero:
delay_msec_approx 300
pla
rts
; Plays low/high beep based on carry
; Preserved: A, X, Y
@beep:
pha
; Set up square
lda #1
sta SNDCHN
sta $4001
sta $4003
adc #$FE ; period=$100 if carry, $1FF if none
sta $4002
; Fade volume
lda #$0F
: ora #$30
sta $4000
delay_msec_approx 8
sec
sbc #$31
bpl :-
; Silence
setb SNDCHN,0
delay_msec_approx 160
pla
rts
|
xem/nes | 2,088 | nes-test-roms/instr_test-v3/source/common/build_rom.s | ; Builds program as iNES ROM
; Default is 32K PRG and 8K CHR ROM, NROM (0)
; CHR_RAM selects UNROM (2)
; CART_WRAM selects MMC1 (1)
.if 0 ; Options to set before .include "shell.inc":
CHR_RAM = 1 ; Use CHR-RAM instead of CHR-ROM
CART_WRAM = 1 ; Use mapper that supports 8K WRAM in cart
MAPPER = n ; Specify mapper number
.endif
.ifndef MAPPER
.ifdef CART_WRAM
MAPPER = 1 ; MMC1
.elseif .defined(CHR_RAM)
MAPPER = 2 ; UNROM
.else
MAPPER = 0 ; NROM
.endif
.endif
.ifndef V_MIRRORING
V_MIRRORING = 1 ; since text console needs it
.endif
;;;; iNES header
.ifndef CUSTOM_HEADER
.segment "HEADER"
.byte "NES",$1A
.ifdef CHR_RAM
.byte 2,0 ; 32K PRG, CHR RAM
.else
.byte 2,1 ; 32K PRG, 8K CHR
.endif
.byte MAPPER*$10 + V_MIRRORING
.endif
.ifndef CUSTOM_VECTORS
.segment "VECTORS"
.word -1,-1,-1, nmi, reset, irq
.endif
;;;; CHR-RAM/ROM
.ifdef CHR_RAM
.define CHARS "CHARS_PRG"
.segment CHARS
ascii_chr:
.segment "CHARS_PRG_ASCII"
.align $200
.incbin "ascii.chr"
ascii_chr_end:
.else
.define CHARS "CHARS"
.segment "CHARS_ASCII"
.align $200
.incbin "ascii.chr"
.res $1800
.endif
.segment CHARS
.res $10,0
;;;; Shell
.ifndef NEED_CONSOLE
NEED_CONSOLE=1
.endif
.ifndef LARGER_ROM_HACK
.segment "CODE"
.res $4000
.endif
.include "shell.s"
std_reset:
.if MAPPER = 1
; Some writes to odd addresses to work
; with my Ultima devcart
lda #$80
sta $8001
; Vertical mirroring, 8K CHR, WRAM enabled, all 32K mapped
lda #$0E<<1 ; $0E
: lsr a
sta $8000 ; 0E 07 03 01 00
bne :-
lda #04 ; $00
: sta $A001 ; 04 08 10 20 40
asl a
bpl :-
lda #$05 ; $01
: sta $C001 ; 05 0A 14 28 50
asl a
bpl :-
lda #04 ; $00
: sta $E000 ; 04 08 10 20 40
asl a
bpl :-
.endif
lda #0
sta PPUCTRL
sta PPUMASK
jmp run_shell
init_runtime:
.ifdef CHR_RAM
load_chr_ram
.endif
rts
post_exit:
jsr set_final_result
jsr play_hex
jmp forever
; Standard NES bootloader to help with devcart.
; It is never executed by test ROM.
.segment "LOADER"
.incbin "bootloader.bin"
.code
.align 256
|
xem/nes | 5,438 | nes-test-roms/instr_test-v3/source/common/console.s | ; Scrolling text console with word wrapping, 30x29 characters.
;
; * Defers PPU initialization until first flush/ newline.
; * Works even if PPU doesn't support scrolling.
; * Keeps border around edge of screen for TV overscan.
; * Requires vertical or single-screen mirroring.
; * Requires ASCII font in CHR.
.ifndef CONSOLE_COLOR
CONSOLE_COLOR = $30 ; white
.endif
console_screen_width = 32 ; if lower than 32, left-justifies
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs. OK if either/both are 0.
console_left_margin = 1
console_right_margin = 1
console_width = console_screen_width - console_left_margin - console_right_margin
zp_byte console_pos ; 0 to console_width
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_width
; Initializes console
console_init:
; Flag that console hasn't been initialized
setb console_scroll,-1
setb console_pos,0
rts
; Hides console by disabling PPU rendering and blacking out
; first four entries of palette.
; Preserved: A, X, Y
console_hide:
pha
jsr console_wait_vbl_
setb PPUMASK,0
lda #$0F
jsr console_load_palette_
pla
rts
; Shows console display
; Preserved: A, X, Y
console_show:
pha
lda #CONSOLE_COLOR
jsr console_show_custom_color_
pla
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
sty console_temp
ldy console_pos
cpy #console_width
beq console_full_
sta console_buf,y
iny
sty console_pos
ldy console_temp
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_scroll_up_
setb console_pos,0
pla
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_apply_scroll_
pla
rts
;**** Internal routines ****
console_full_:
ldy console_temp
; Line is full
; If space, treat as newline
cmp #' '
beq console_newline
; Wrap current line at appropriate point
pha
tya
pha
jsr console_wrap_
pla
tay
pla
jmp console_print
; Inserts newline into buffer at appropriate position, leaving
; next line ready in buffer
; Preserved: X, console_temp
console_wrap_:
; Find beginning of last word
ldy #console_width
lda #' '
: dey
bmi console_newline
cmp console_buf,y
bne :-
; y = 0 to console_width-1
; Flush through current word and put remaining
; in buffer for next line
jsr console_wait_vbl_
; Time to last PPU write: 207 + 32*(26 + 10)
lda console_scroll
jsr console_set_ppuaddr_
stx console_pos ; save X
ldx #0
; Print everything before last word
: lda console_buf,x
sta PPUDATA
inx
dey
bpl :-
; x = 1 to console_width
; Move last word to beginning of buffer, and
; print spaces for rest of line
ldy #0
beq :++
: lda #' '
sta PPUDATA
lda console_buf,x
inx
sta console_buf,y
iny
: cpx #console_width
bne :--
ldx console_pos ; restore X
; Append new text after that
sty console_pos
; FALL THROUGH
; Scrolls up 8 pixels and clears one line BELOW new line
; Preserved: X, console_temp
console_scroll_up_:
; Scroll up 8 pixels
lda console_scroll
jsr console_add_8_to_scroll_
sta console_scroll
; Clear line AFTER that on screen
jsr console_add_8_to_scroll_
jsr console_set_ppuaddr_
ldy #console_width
lda #' '
: sta PPUDATA
dey
bne :-
; FALL THROUGH
; Applies current scrolling position to PPU
; Preserved: X, Y, console_temp
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
lda console_scroll
jsr console_add_8_to_scroll_
jsr console_add_8_to_scroll_
sta PPUSCROLL
rts
; Sets PPU address for row
; In: A = scroll position
; Preserved: X, Y
console_set_ppuaddr_:
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
ora #console_left_margin
sta PPUADDR
rts
; A = (A + 8) % 240
; Preserved: X, Y
console_add_8_to_scroll_:
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_show_custom_color_:
pha
jsr console_wait_vbl_
setb PPUMASK,PPUMASK_BG0
pla
jsr console_load_palette_
jmp console_apply_scroll_
console_load_palette_:
pha
setb PPUADDR,$3F
setb PPUADDR,$00
setb PPUDATA,$0F ; black
pla
sta PPUDATA
sta PPUDATA
sta PPUDATA
lda #0
sta PPUADDR
sta PPUADDR
rts
; Initializes PPU if necessary, then waits for VBL
; Preserved: A, X, Y, console_temp
console_wait_vbl_:
lda console_scroll
cmp #-1
bne @already_initialized
; Deferred initialization of PPU until first use of console
; In case PPU doesn't support scrolling, start a
; couple of lines down
setb console_scroll,16
jsr console_hide
tya
pha
; Fill nametable with spaces
setb PPUADDR,$20
setb PPUADDR,$00
ldy #240
lda #' '
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dey
bne :-
; Clear attributes
lda #0
ldy #$40
: sta PPUDATA
dey
bne :-
pla
tay
jsr console_show
@already_initialized:
jmp wait_vbl_optional
; Flushes current line
; Preserved: X, Y
console_flush_:
lda console_scroll
jsr console_set_ppuaddr_
sty console_temp
; Copy line
ldy #0
beq :++
: lda console_buf,y
sta PPUDATA
iny
: cpy console_pos
bne :--
ldy console_temp
rts
|
xem/nes | 1,096 | nes-test-roms/instr_test-v3/source/common/text_out.s | ; Text output as expanding zero-terminated string at text_out_base
; The final exit result byte is written here
final_result = $6000
; Text output is written here as an expanding
; zero-terminated string
text_out_base = $6004
bss_res text_out_temp
zp_res text_out_addr,2
init_text_out:
ldx #0
; Put valid data first
setb text_out_base,0
lda #$80
jsr set_final_result
; Now fill in signature that tells emulator there's
; useful data there
setb text_out_base-3,$DE
setb text_out_base-2,$B0
setb text_out_base-1,$61
ldx #>text_out_base
stx text_out_addr+1
setb text_out_addr,<text_out_base
rts
; Sets final result byte in memory
set_final_result:
sta final_result
rts
; Writes character to text output
; In: A=Character to write
; Preserved: A, X, Y
write_text_out:
sty text_out_temp
; Write new terminator FIRST, then new char before it,
; in case emulator looks at string in middle of this routine.
ldy #1
pha
lda #0
sta (text_out_addr),y
dey
pla
sta (text_out_addr),y
inc text_out_addr
bne :+
inc text_out_addr+1
:
ldy text_out_temp
rts
|
xem/nes | 3,100 | nes-test-roms/instr_test-v3/source/common/ppu.s | ; PPU utilities
bss_res ppu_not_present
; Sets PPUADDR to w
; Preserved: X, Y
.macro set_ppuaddr w
bit PPUSTATUS
setb PPUADDR,>w
setb PPUADDR,<w
.endmacro
; Delays by no more than n scanlines
.macro delay_scanlines n
.if CLOCK_RATE <> 1789773
.error "Currently only supports NTSC"
.endif
delay ((n)*341)/3
.endmacro
; Waits for VBL then disables PPU rendering.
; Preserved: A, X, Y
disable_rendering:
pha
jsr wait_vbl_optional
setb PPUMASK,0
pla
rts
; Fills first nametable with $00
; Preserved: Y
clear_nametable:
ldx #$20
bne clear_nametable_
clear_nametable2:
ldx #$24
clear_nametable_:
lda #0
jsr fill_screen_
; Clear pattern table
ldx #64
: sta PPUDATA
dex
bne :-
rts
; Fills screen with tile A
; Preserved: A, Y
fill_screen:
ldx #$20
bne fill_screen_
; Same as fill_screen, but fills other nametable
fill_screen2:
ldx #$24
fill_screen_:
stx PPUADDR
ldx #$00
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
rts
; Fills palette with $0F
; Preserved: Y
clear_palette:
set_ppuaddr $3F00
ldx #$20
lda #$0F
: sta PPUDATA
dex
bne :-
; Fills OAM with $FF
; Preserved: Y
clear_oam:
lda #$FF
; Fills OAM with A
; Preserved: A, Y
fill_oam:
ldx #0
stx SPRADDR
: sta SPRDATA
dex
bne :-
rts
; Initializes wait_vbl_optional. Must be called before
; using it.
.align 32
init_wait_vbl:
; Wait for VBL flag to be set, or ~60000
; clocks (2 frames) to pass
ldy #24
ldx #1
bit PPUSTATUS
: bit PPUSTATUS
bmi @set
dex
bne :-
dey
bpl :-
@set:
; Be sure flag didn't stay set (in case
; PPUSTATUS always has high bit set)
tya
ora PPUSTATUS
sta ppu_not_present
rts
; Same as wait_vbl, but returns immediately if PPU
; isn't working or doesn't support VBL flag
; Preserved: A, X, Y
.align 16
wait_vbl_optional:
bit ppu_not_present
bmi :++
; FALL THROUGH
; Clears VBL flag then waits for it to be set.
; Preserved: A, X, Y
wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
: rts
.macro check_ppu_region_ Len
; Delays since VBL began
jsr wait_vbl_optional ; 10 average
delay Len - 18 - 200
lda PPUSTATUS ; 4
bmi @ok ; 2
delay 200
; Next VBL should roughly begin here if it's the
; one we are detecting
delay 200
lda PPUSTATUS ; 2
bpl @ok
.endmacro
check_ppu_region:
.ifndef REGION_FREE
.ifdef PAL_ONLY
check_ppu_region_ 29781
print_str {newline,"Note: This test is meant for PAL NES only.",newline,newline}
.endif
.ifdef NTSC_ONLY
check_ppu_region_ 33248
print_str {newline,"Note: This test is meant for NTSC NES only.",newline,newline}
.endif
.endif
@ok: rts
; Loads ASCII font into CHR RAM and fills rest with $FF
.macro load_chr_ram
jsr wait_vbl_optional
mov PPUCTRL,#0
mov PPUMASK,#0
mov PPUADDR,#0
mov PPUADDR,#0
; Copy ascii_chr to 0
setb addr,<ascii_chr
ldx #>ascii_chr
ldy #0
@page:
stx addr+1
: lda (addr),y
sta PPUDATA
iny
bne :-
inx
cpx #>ascii_chr_end
bne @page
; Fill rest
lda #$FF
: sta PPUDATA
iny
bne :-
inx
cpx #$20
bne :-
.endmacro
|
xem/nes | 2,752 | nes-test-roms/instr_test-v3/source/common/shell.s | ; Shell that sets up testing framework and calls main
; Detect inclusion loops (otherwise ca65 goes crazy)
.ifdef SHELL_INCLUDED
.error "shell.s included twice"
.end
.endif
SHELL_INCLUDED = 1
; Temporary variables that ANY routine might modify, so
; only use them between routine calls.
temp = <$A
temp2 = <$B
temp3 = <$C
addr = <$E
ptr = addr
; Move code from $C000 to $E200, to accommodate my devcarts
.ifndef LARGER_ROM_HACK
.segment "CODE"
.res $2200
.endif
; Put shell code after user code, so user code is in more
; consistent environment
.ifndef NO_CODE2
.segment "CODE2"
.endif
; Any user code which runs off end might end up here,
; so catch that mistake.
nop ; in case there was three-byte opcode before this
nop
jmp internal_error
;**** Common routines ****
.include "macros.inc"
.include "neshw.inc"
.include "delay.s"
.include "print.s"
.include "crc.s"
.include "testing.s"
;**** Shell core ****
.ifndef CUSTOM_RESET
reset:
sei
jmp std_reset
.endif
; Sets up hardware then runs main
run_shell:
init_cpu_regs
jsr init_shell
set_test $FF
jmp run_main
; Initializes shell without affecting current set_test values
init_shell:
jsr clear_ram
jsr init_wait_vbl ; waits for VBL once here,
jsr wait_vbl_optional ; so only need to wait once more
jsr init_text_out
jsr init_testing
jsr init_runtime
jsr console_init
rts
; Runs main in consistent PPU/APU environment, then exits
; with code 0
run_main:
jsr pre_main
jsr main
lda #0
jmp exit
; Sets up environment for main to run in
pre_main:
.ifndef BUILD_NSF
jsr disable_rendering
setb PPUCTRL,0
jsr clear_palette
jsr clear_nametable
jsr clear_nametable2
jsr clear_oam
.endif
; Clear APU registers
lda #0
sta $4015
ldx #$13
: sta $4000,x
dex
bpl :-
; CPU registers
lda #$34
pha
lda #0
tax
tay
jsr wait_vbl_optional
plp
sta SNDMODE
rts
.ifndef CUSTOM_EXIT
exit:
.endif
; Reports result and ends program
std_exit:
sta temp
init_cpu_regs
setb SNDCHN,0
lda temp
jsr report_result
pha
jsr check_ppu_region
pla
jmp post_exit
; Reports final result code in A
report_result:
jsr :+
jmp play_byte
: jsr print_newline
jsr console_show
; 0: ""
cmp #1
bge :+
rts
:
; 1: "Failed"
bne :+
print_str {"Failed",newline}
rts
; n: "Failed #n"
: print_str "Failed #"
jsr print_dec
jsr print_newline
rts
;**** Other routines ****
.include "shell_misc.s"
.ifdef NEED_CONSOLE
.include "console.s"
.else
; Stubs so code doesn't have to care whether
; console exists
console_init:
console_show:
console_hide:
console_print:
console_flush:
rts
.endif
.ifndef CUSTOM_PRINT
.include "text_out.s"
print_char_:
jsr write_text_out
jmp console_print
stop_capture:
rts
.endif
|
xem/nes | 3,734 | nes-test-roms/instr_test-v3/source/common/delay.s | ; Delays in CPU clocks, milliseconds, etc. All routines are re-entrant
; (no global data). No routines touch X or Y during execution.
; Code generated by macros is relocatable; it contains no JMPs to itself.
zp_res delay_temp_ ; only written to
; Delays n clocks, from 2 to 16777215
; Preserved: A, X, Y, flags
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
delay_ (n)
.endmacro
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100.
; Preserved: A, X, Y, flags
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: A, X, Y, flags
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
; Delays approximately n milliseconds (1/1000 second),
; without caring whether it's NTSC or PAL.
; n can range from 0 to 1100.
; Preserved: A, X, Y, flags
.macro delay_msec_approx n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*1726190+500)/1000
.endmacro
.align 64
; Delays A clocks + overhead
; Preserved: X, Y
; Time: A+25 clocks (including JSR)
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256 clocks + overhead
; Preserved: X, Y
; Time: A*256+16 clocks (including JSR)
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_11_clocks_:
: pha
lda #256-19-22
jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536 clocks + overhead
; Preserved: X, Y
; Time: A*65536+16 clocks (including JSR)
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_11_clocks_:
: pha
lda #256-19-22-13
jsr delay_a_25_clocks
lda #255
jsr delay_256a_11_clocks_
pla
clc
adc #-1
bne :-
rts
max_short_delay = 41
; delay_short_ macro jumps into these
.res (max_short_delay-12)/2,$EA ; NOP
delay_unrolled_:
rts
.macro delay_short_ n
.if n < 0 .or n = 1 .or n > max_short_delay
.error "Internal delay error"
.endif
.if n = 0
; nothing
.elseif n = 2
nop
.elseif n = 3
sta <delay_temp_
.elseif n = 4
nop
nop
.elseif n = 5
sta <delay_temp_
nop
.elseif n = 6
nop
nop
nop
.elseif n = 7
php
plp
.elseif n = 8
nop
nop
nop
nop
.elseif n = 9
php
plp
nop
.elseif n = 10
sta <delay_temp_
php
plp
.elseif n = 11
php
plp
nop
nop
.elseif n = 13
php
plp
nop
nop
nop
.elseif n & 1
sta <delay_temp_
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.macro delay_nosave_ n
; 65536+17 = maximum delay using delay_256a_11_clocks_
; 255+27 = maximum delay using delay_a_25_clocks
; 27 = minimum delay using delay_a_25_clocks
.if n > 65536+17
lda #^(n - 15)
jsr delay_65536a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (((n - 15) & $FFFF) + 2)
.elseif n > 255+27
lda #>(n - 15)
jsr delay_256a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (<(n - 15) + 2)
.elseif n >= 27
lda #<(n - 27)
jsr delay_a_25_clocks
.else
delay_short_ n
.endif
.endmacro
.macro delay_ n
.if n > max_short_delay
php
pha
delay_nosave_ (n - 14)
pla
plp
.else
delay_short_ n
.endif
.endmacro
|
xem/nes | 2,410 | nes-test-roms/instr_test-v3/source/common/instr_test_end.s | ; Offset of current instruction
zp_byte instrs_idx
zp_byte failed_count
main:
; Stack slightly lower than top
ldx #$A2
txs
jsr init_crc_fast
; Test each instruction
lda #0
@loop: sta instrs_idx
tay
jsr reset_crc
lda instrs,y
jsr test_instr
jsr check_result
lda instrs_idx
clc
adc #4
cmp #instrs_size
bne @loop
.ifdef BUILD_DEVCART
lda #0
jmp exit
.endif
lda failed_count
jne test_failed
jmp tests_passed
; Check result of test
check_result:
.ifdef BUILD_DEVCART
; Print correct CRC
jsr crc_off
print_str ".dword $"
ldx #0
: lda checksum,x
jsr print_hex
inx
cpx #4
bne :-
jsr print_newline
jsr crc_on
.else
; Verify CRC
ldx #3
ldy instrs_idx
: lda checksum,x
cmp correct_checksums,y
bne @wrong
iny
dex
bpl :-
.endif
rts
; Print failed opcode and name
@wrong:
ldy instrs_idx
lda instrs,y
jsr print_a
jsr play_byte
lda instrs+2,y
sta addr
lda instrs+3,y
sta addr+1
jsr print_str_addr
jsr print_newline
inc failed_count
rts
; Place where instruction is executed
instr = $3A0
; Tests instr A
test_instr:
sta instr
jsr avoid_silent_nsf
; Copy rest of template
ldx #instr_template_size - 1
: lda instr_template,x
sta instr,x
dex
bne :-
; Disable and be sure APU IRQs are clear, since
; I flag gets cleared during testing.
setb SNDMODE,$C0
setb $4010,0
nop
lda SNDCHN
; Default stack
lda #$90
sta in_s
; Test with different flags
lda #$00
jsr test_flags
lda #$FF
jsr test_flags
rts
; Position in operand table
zp_byte operand_idx
test_flags:
sta in_p
ldy #values_size-1
: sty operand_idx
lda values,y
sta in_a
lda values+1,y
sta in_x
lda values+2,y
sta in_y
jsr test_values
ldy operand_idx
dey
bpl :-
rts
.ifndef values2
values2 = values
values2_size = values_size
.endif
.macro test_normal
zp_byte a_idx
zp_byte saved_s
tsx
stx saved_s
set_stack
ldy #values2_size-1
inner: sty a_idx
lda values2,y
sta operand
set_in
; For debugging
.if 0
; P A X Y S O (z,x) (z),y
jsr print_p
jsr print_a
jsr print_x
jsr print_y
jsr print_s
lda operand
jsr print_a
.ifdef address
lda (address,x)
jsr print_a
lda (address),y
jsr print_a
.else
lda operand,x
jsr print_a
lda operand,y
jsr print_a
.endif
jsr print_newline
.endif
jmp instr
instr_done:
check_out
ldy a_idx
dey
bpl inner
check_stack
ldx saved_s
txs
.endmacro
|
xem/nes | 1,600 | nes-test-roms/instr_test-v3/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4 ; Current CRC-32; no need to invert
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: A, X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
jmp reset_crc
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: A, X, Y
; Time: 360 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
pha
stx checksum_temp
eor checksum
ldx #8
sec
@bit: ror checksum+3
ror checksum+2
ror checksum+1
ror a
bcs :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
sec
: dex
bne @bit
sta checksum
ldx checksum_temp
pla
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
ldx #3
: lda checksum,x
jsr print_hex
dex
bpl :-
jmp crc_on
; EQ if checksum matches CRC
; Out: A=0 and EQ if match, A>0 and NE if different
; Preserved: X, Y
.macro is_crc crc
jsr_with_addr is_crc_,{.dword crc}
.endmacro
is_crc_:
tya
pha
ldy #3
: lda (ptr),y
cmp checksum,y
bne @wrong
dey
bpl :-
pla
tay
lda #0
rts
@wrong:
pla
tay
lda #1
rts
|
xem/nes | 1,111 | nes-test-roms/dmc_dma_during_read4/source/double_2007_read.s | ; Double read of $2007 sometimes ignores extra
; read, and puts odd things into buffer.
;
; Output (depends on CPU-PPU synchronization):
;22 33 44 55 66
;22 44 55 66 77 or
;22 33 44 55 66 or
;02 44 55 66 77 or
;32 44 55 66 77 or
;85CFD627 or F018C287 or 440EF923 or E52F41A5
CHR_RAM=1
.include "shell.inc"
begin:
; Disable PPU
jsr wait_vbl
lda #0
sta PPUMASK
; Fill VRAM with $11 22 33 44 55 66 77
lda #0
sta PPUADDR
sta PPUADDR
ldx #7
lda #$11
: sta PPUDATA
clc
adc #$11
dex
bne :-
; PPUADDR=1, and fill buffer
lda #$00
sta PPUADDR
lda #$01
sta PPUADDR
lda PPUDATA
rts
end:
jsr print_a
; Read several bytes
ldx #4
: lda PPUDATA
jsr print_a
dex
bne :-
jsr print_newline
rts
main: jsr begin
ldx #$00
lda $20F7,x ; reads $2007 once
jsr end
jsr begin
ldx #$10
lda $20F7,x ; reads $2007 twice in succession
jsr end
jsr print_crc
rts
|
xem/nes | 1,059 | nes-test-roms/dmc_dma_during_read4/source/read_write_2007.s | ; Read of $2007 just before write behaves normally.
;
; Output:
;33 11 22 33 09 55 66 77
;33 11 22 33 09 55 66 77
CHR_RAM=1
.include "shell.inc"
begin:
; Disable PPU
jsr wait_vbl
lda #0
sta PPUMASK
; Fill VRAM with $11 22 33 44 55 66 77
lda #0
sta PPUADDR
sta PPUADDR
ldx #7
lda #$11
: sta PPUDATA
clc
adc #$11
dex
bne :-
; PPUADDR=1, and fill buffer
lda #$00
sta PPUADDR
lda #$01
sta PPUADDR
lda PPUDATA
rts
end:
; Dump VRAM
lda #0
sta PPUADDR
sta PPUADDR
ldx #8
: lda PPUDATA
jsr print_a
dex
bne :-
jsr print_newline
rts
main: ; Manually read before write
jsr begin
ldx #0
lda #9
ldx $2007
sta $2007
jsr end
; Read one clock before write
jsr begin
ldx #0
lda #9
sta $2007,x ; reads then writes $2007
jsr end
check_crc $0F877C4B
jmp tests_passed
|
xem/nes | 1,157 | nes-test-roms/dmc_dma_during_read4/source/dma_2007_read.s | ; DMC DMA during $2007 read causes 2-3 extra $2007
; reads before real read.
;
; Number of extra reads depends in CPU-PPU
; synchronization at reset.
;
; Output:
;11 22
;11 22
;33 44 or 44 55
;11 22
;11 22
;159A7A8F or 5E3DF9C4
iter = 5 ; how many times the test is run
time = 14 ; adjusts time of first DMA
dma = 1 ; set to 0 to disable DMA
.include "common.inc"
; Setup things before time-critical part of test
begin:
; Disable PPU
jsr wait_vbl
lda #0
sta PPUMASK
; Fill VRAM with $11 22 33 44 55 66 77
lda #0
sta PPUADDR
sta PPUADDR
ldx #7
lda #$11
: sta PPUDATA
clc
adc #$11
dex
bne :-
; PPUADDR=0, and read once to fill buffer
lda #0
sta PPUADDR
sta PPUADDR
lda PPUDATA
rts
; DMC DMA occurs during this code
test: nop
nop
ldx $2007
nop
nop
rts
; Dump results
end: lda $2007
jsr print_x
jsr print_a
jsr print_newline
rts
main: ; Run above routines with synchronized DMC DMA
jsr run_tests
jsr print_crc
rts
|
xem/nes | 1,221 | nes-test-roms/dmc_dma_during_read4/source/dma_2007_write.s | ; DMC DMA during $2007 write has no effect.
;
; Output:
;22 11 22 AA 44 55 66 77
;22 11 22 AA 44 55 66 77
;22 11 22 AA 44 55 66 77
;22 11 22 AA 44 55 66 77
;22 11 22 AA 44 55 66 77
iter = 5 ; how many times the test is run
time = 11 ; adjusts time of first DMA
dma = 1 ; set to 0 to disable DMA
.include "common.inc"
; Setup things before time-critical part of test
begin:
; Disable PPU
jsr wait_vbl
lda #0
sta PPUMASK
; Fill VRAM with $11 22 33 44 55 66 77
lda #0
sta PPUADDR
sta PPUADDR
ldx #7
lda #$11
: sta PPUDATA
clc
adc #$11
dex
bne :-
; PPUADDR=0, and read once to fill buffer
lda #0
sta PPUADDR
sta PPUADDR
lda PPUDATA
rts
; DMC DMA occurs during this code
test: nop
nop
lda #$AA
sta $2007
nop
nop
rts
; Dump results
end: lda #0
sta PPUADDR
sta PPUADDR
ldx #8
: lda PPUDATA
jsr print_a
dex
bne :-
jsr print_newline
rts
main: ; Run above routines with synchronized DMC DMA
jsr run_tests
check_crc $28F53CA4
jmp tests_passed
|
xem/nes | 2,223 | nes-test-roms/dmc_dma_during_read4/source/common/testing.s | ; Utilities for writing test ROMs
zp_res test_code,1 ; code of current test
zp_res test_name,2 ; address of name of current test, or 0 of none
; Reports that all tests passed
tests_passed:
.if !BUILD_MULTI
jsr print_filename
print_str "Passed"
.endif
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
lda test_code
; Treat 0 as 1, in case it wasn't ever set
bne :+
lda #1
sta test_code
:
; If code >= 2, print name
cmp #2
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
.if !BUILD_MULTI
jsr print_filename
.endif
; End program
lda test_code
jmp exit
; Sets current test code and optional name. Also resets
; checksum.
.macro set_test code,name
pha
lda #code
jsr set_test_
.local Addr
lda #<Addr
sta <test_name
lda #>Addr
sta <test_name+1
seg_data "STRINGS",{Addr: .byte name,0}
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; If checksum doesn't match expected, reports failed test.
; Passing 0 just prints checksum.
; Preserved: A, X, Y
.macro check_crc expected
.if expected
jsr_with_addr check_crc_,{.dword expected}
.else
; print checksum if 0 is passed
jsr print_newline
jsr print_crc
jsr print_newline
.endif
.endmacro
check_crc_:
pha
tya
pha
; Compare with complemented checksum
ldy #3
: lda (addr),y
sec
adc checksum,y
bne @wrong
dey
bpl :-
pla
tay
pla
rts
@wrong: jsr print_newline
jsr print_crc
jsr print_newline
jmp test_failed
; Reports value of A via low/high beeps.
; Preserved: A, X, Y
beep_bits:
pha
; Make reference low beep
clc
jsr @beep
; End marker
sec
; Remove high zero bits
: rol a
beq @zero
bcc :-
; Play remaining bits
: php
jsr @beep
plp
asl a
bne :-
@zero: pla
rts
@beep: pha
; Set LSB of pitch based on carry
lda #0
adc #$FF
sta $4002
; Set up square
lda #1
sta SNDCHN
sta $4003
sta $4001
; Fade volume
lda #15
: pha
eor #$30
sta $4000
delay_msec 8
pla
clc
adc #-1
bne :-
; Silence
sta SNDCHN
delay_msec 120
pla
rts
|
xem/nes | 2,326 | nes-test-roms/dmc_dma_during_read4/source/common/print.s | ; Prints values in various ways to output, including numbers and strings.
newline = 10
; Prints indicated register to console as two hex chars and space
; Preserved: A, X, Y, P
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: X, Y
print_hex:
; Update checksum
pha
jsr update_crc
pla
; Print high nibble
pha
lsr a
lsr a
lsr a
lsr a
jsr @nibble
pla
; Print low nibble
and #$0F
@nibble:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints character and updates checksum UNLESS it's a newline.
; Preserved: X, Y
print_char:
cmp #newline
beq :+
pha
jsr update_crc
pla
: jmp print_char_
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str
jsr_with_addr print_str_addr,{.byte str,0}
.endmacro
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: Y
print_dec:
; Hundreds
cmp #100
blt @tens
ldx #'0'
: sbc #100
inx
cmp #100
bge :-
jsr @digit
; Tens
@tens: cmp #10
blt @ones
ldx #'0'
: sbc #10
inx
cmp #10
bge :-
jsr @digit
; Ones
@ones: ora #'0'
jmp print_char
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y
.macro print_cc cond,yes,no
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
.endmacro
|
xem/nes | 3,161 | nes-test-roms/dmc_dma_during_read4/source/common/console.s | ; Scrolling text console with line wrapping, 30x30 characters.
; Buffers lines for speed. Will work even if PPU doesn't
; support scrolling (until text reaches bottom).
; ** ASCII font must already be in CHR, and mirroring
; must be vertical or single-screen.
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs
console_margin = 1
console_buf_size = 32
console_width = console_buf_size - (console_margin*2)
zp_byte console_pos
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_buf_size
; Waits for beginning of VBL
; Preserved: A, X, Y
console_wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
rts
; Initializes console
console_init:
jsr console_hide
lda #0
sta PPUCTRL
; Load palette
lda #$3F
sta PPUADDR
lda #0
sta PPUADDR
lda #$0F ; black background
sta PPUDATA
lda #$30 ; white text
sta PPUDATA
sta PPUDATA
sta PPUDATA
; Fill nametable with spaces
lda #$20
sta PPUADDR
ldx #0
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
; Clear attributes
lda #0
ldx #$40
: sta PPUDATA
dex
bne :-
; In case PPU doesn't support scrolling, start a
; couple of lines down
lda #8
sta console_scroll
jsr console_scroll_up_
jmp console_show
; Shows console display
; Preserved: X, Y
console_show:
pha
jsr console_wait_vbl
lda #PPUMASK_BG0
sta PPUMASK
jmp console_apply_scroll_
; Hides console display and makes screen black
; Preserved: X, Y
console_hide:
jsr console_wait_vbl
lda #0
sta PPUMASK
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
; Write to buffer
stx console_temp
ldx console_pos
sta console_buf+console_margin,x
ldx console_temp
; Update pos and print newline if buf full
dec console_pos
bmi console_newline ; reached end of line
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl
jsr console_flush_
jsr console_scroll_up_
jsr console_flush_
jmp console_apply_scroll_
console_get_scroll_:
; A = (console_scroll+8)%240
lda console_scroll
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_scroll_up_:
; Scroll up 8 pixels
jsr console_get_scroll_
sta console_scroll
stx console_temp
; Start new clear line
lda #' '
ldx #console_buf_size-1
: sta console_buf,x
dex
bpl :-
ldx #console_width-1
stx console_pos
ldx console_temp
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl
jsr console_flush_
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
jsr console_get_scroll_
sta PPUSCROLL
pla
rts
console_flush_:
; Address line in nametable
lda console_scroll
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
sta PPUADDR
; Copy line
stx console_temp
ldx #console_buf_size-1
: lda console_buf,x
sta PPUDATA
dex
bpl :-
ldx console_temp
rts
|
xem/nes | 2,604 | nes-test-roms/dmc_dma_during_read4/source/common/sync_dmc.s | ; Synchronizes to DMC and times a piece of code
; Synchronizes precisely with DMC timer
; Preserved: X, Y
; Time: 8 msec avg, 17 msec max
.align 64
sync_dmc:
; Setup
lda #$80
sta $4010
lda #0
sta $4013
sta SNDCHN
; Start twice (first will clear immediately)
lda #$10
sta SNDCHN
nop
sta SNDCHN
; Coarse synchronize
: bit SNDCHN
bne :-
; DO NOT write to memory. It affects timing.
nop ; 2 fine-tune: 2=OK 3=OK 4=fail
; Fine synchronize. 3421+4 clocks per iter
nop ; 2
nop ; 2
lda #226 ; 3391 delay
bne @first ; 3
@wait:
lda #227 ; 3406 delay
@first:
: nop
nop
nop
nop
sec
sbc #1
bne :-
; 4 DMC wait-states
lda #$10 ; 2
sta SNDCHN ; 4
nop ; 2
bit SNDCHN ; 4
bne @wait ; 3
rts
; Returns in XA number of clocks elapsed since call to
; time_code_begin, MOD 3424. Unreliable if result is
; 3387 or greater.
; Time: 33 msec max
.align 64
time_code_end:
; Restart
lda #$10
sta SNDCHN
nop
sta SNDCHN
; Rough sync
ldy #-$2C
@coarse:
nop
nop
bne :+
: dey
bit SNDCHN
bne @coarse
; DO NOT write to memory. It affects timing.
; Fine sync
ldx #-$2
@wait:
lda #$10 ; 2
sta SNDCHN ; 4
lda #179 ; delay 3402
: nop
nop
nop
nop
nop
nop
sec
sbc #1
bne :-
inx ; 2
lda #$10 ; 2
bit SNDCHN ; 4
beq @wait ; 3
;jsr print_y
;jsr print_x
; Calculate result
; XA = Y << 4 | X
stx <0
tya
lsr a
lsr a
lsr a
lsr a
tax
tya
asl a
asl a
asl a
asl a
clc
adc <0
bcc :+
inx
:
rts
; Begins timing section of code
; Preserved: A, X, Y, flags
; Time: 9 msec avg, 17 msec max
.align 32
time_code_begin:
php
pha
txa
pha
tya
pha
jsr sync_dmc
nop
ldx #163 ; 3396 delay
lda #3
: dex
bne :-
sec
sbc #1
bne :-
pla
tay
pla
tax
pla
plp
rts
|
xem/nes | 2,505 | nes-test-roms/dmc_dma_during_read4/source/common/delay.s | ; Delays in clocks and milliseconds. All routines re-entrant
; (no global data).
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100.
; Preserved: X, Y
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: X, Y
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
; Delays n clocks, from 2 to 16777215
; Preserved: X, Y
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
.if (n) < 14 .and (n) <> 12
delay_inline (n)
.elseif (n) < 27
delay_unrolled (n)
.elseif <(n) = 0
delay_256 (n)
.else
lda #<((n)-27)
jsr delay_a_25_clocks
delay_256 ((n)-27)
.endif
.endmacro
; Delays A+25 clocks (including JSR)
; Preserved: X, Y
.align 64
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256+16 clocks (including JSR)
; Preserved: X, Y
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_clocks_:
pha
lda #256-19-22-16
bne @first ; always branches
: pha
lda #256-19-22
@first: jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536+16 clocks (including JSR)
; Preserved: X, Y
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_clocks_:
pha
lda #256-19-22-16
bne @first
: pha
lda #256-19-22
@first: jsr delay_a_25_clocks
lda #255
jsr delay_256a_clocks_
pla
clc
adc #-1
bne :-
rts
.macro delay_inline n
.if n = 7 .or n >= 9
pha
pla
delay_inline (n-7)
.elseif n >= 3 .and n & 1
lda <0
delay_inline (n-3)
.elseif n >= 2
nop
delay_inline (n-2)
.elseif n > 0
.error "delay_short internal error"
.endif
.endmacro
.macro delay_unrolled n
.if n & 1
lda <0
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.res 7,$EA ; NOP
delay_unrolled_:
rts
.macro delay_256 n
.if >n
lda #>n
jsr delay_256a_clocks_
.endif
.if ^n
lda #^n
jsr delay_65536a_clocks_
.endif
.endmacro
|
xem/nes | 1,260 | nes-test-roms/dmc_dma_during_read4/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
; FALL THROUGH
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
lda #$FF
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: X, Y
; Time: 350 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
stx checksum_temp
eor checksum
ldx #8
@bit: lsr checksum+3
ror checksum+2
ror checksum+1
ror a
bcc :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
: dex
bne @bit
sta checksum
ldx checksum_temp
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
; Print complement
ldx #3
: lda checksum,x
eor #$FF
jsr print_hex
dex
bpl :-
jmp crc_on
|
xem/nes | 1,856 | nes-test-roms/oam_read/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data "RODATA",{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing:
jmp init_crc
; Reports that all tests passed
tests_passed:
jsr print_filename
print_str newline,"Passed"
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
jsr print_filename
print_str newline,"Done"
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF as 1, in case it wasn't ever set
inx
bne :+
inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
jsr print_filename
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
jsr is_crc_
bne :+
jsr reset_crc
pla
rts
: jsr print_newline
jsr print_crc
jmp test_failed
|
xem/nes | 2,583 | nes-test-roms/oam_read/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
zp_byte print_temp_
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr @nibble
pla
pha
and #$0F
jsr @nibble
pla
rts
@nibble:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
jsr print_str_
.byte str
.ifnblank str2
.byte str2
.endif
.byte 0
.endmacro
print_str_:
sta print_temp_
pla
sta addr
pla
sta addr+1
jsr inc_addr
jsr print_str_addr
lda print_temp_
jmp (addr)
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: Y
print_dec:
; Hundreds
cmp #10
blt @ones
cmp #100
blt @tens
ldx #'0'-1
: inx
sbc #100
bge :-
adc #100
jsr @digit
; Tens
@tens: sec
ldx #'0'-1
: inx
sbc #10
bge :-
adc #10
jsr @digit
; Ones
@ones: ora #'0'
jmp print_char
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
xem/nes | 1,480 | nes-test-roms/oam_read/source/common/build_rom.s | ; Builds program as iNES ROM
; Default is 16K PRG and 8K CHR ROM, NROM (0)
.if 0 ; Options to set before .include "shell.inc":
CHR_RAM=1 ; Use CHR-RAM instead of CHR-ROM
CART_WRAM=1 ; Use mapper that supports 8K WRAM in cart
CUSTOM_MAPPER=n ; Specify mapper number
.endif
.ifndef CUSTOM_MAPPER
.ifdef CART_WRAM
CUSTOM_MAPPER = 2 ; UNROM
.else
CUSTOM_MAPPER = 0 ; NROM
.endif
.endif
;;;; iNES header
.ifndef CUSTOM_HEADER
.segment "HEADER"
.byte $4E,$45,$53,26 ; "NES" EOF
.ifdef CHR_RAM
.byte 2,0 ; 32K PRG, CHR RAM
.else
.byte 2,1 ; 32K PRG, 8K CHR
.endif
.byte CUSTOM_MAPPER*$10+$01 ; vertical mirroring
.endif
.ifndef CUSTOM_VECTORS
.segment "VECTORS"
.word -1,-1,-1, nmi, reset, irq
.endif
;;;; CHR-RAM/ROM
.ifdef CHR_RAM
.define CHARS "CHARS_PRG"
.segment CHARS
ascii_chr:
.segment "CHARS_PRG_ASCII"
.align $200
.incbin "ascii.chr"
ascii_chr_end:
.else
.define CHARS "CHARS"
.segment "CHARS_ASCII"
.align $200
.incbin "ascii.chr"
.res $1800
.endif
.segment CHARS
.res $10,0
;;;; Shell
.ifndef NEED_CONSOLE
NEED_CONSOLE=1
.endif
; Move code to $C000
.segment "DMC"
.res $4000
.include "shell.s"
std_reset:
lda #0
sta PPUCTRL
sta PPUMASK
jmp run_shell
init_runtime:
.ifdef CHR_RAM
load_ascii_chr
.endif
rts
post_exit:
jsr set_final_result
jmp forever
; This helps devcart recover after running test.
; It is never executed by test ROM.
.segment "LOADER"
.incbin "devcart.bin"
.code
|
xem/nes | 3,732 | nes-test-roms/oam_read/source/common/console.s | ; Scrolling text console with line wrapping, 30x29 characters.
; Buffers lines for speed. Will work even if PPU doesn't
; support scrolling (until text reaches bottom). Keeps border
; along bottom in case TV cuts it off.
;
; Defers most initialization until first newline, at which
; point it clears nametable and makes palette non-black.
;
; ** ASCII font must already be in CHR, and mirroring
; must be vertical or single-screen.
; Number of characters of margin on left and right, to avoid
; text getting cut off by common TVs
console_margin = 1
console_buf_size = 32
console_width = console_buf_size - (console_margin*2)
zp_byte console_pos
zp_byte console_scroll
zp_byte console_temp
bss_res console_buf,console_buf_size
; Initializes console
console_init:
; Flag that console hasn't been initialized
setb console_scroll,-1
jmp console_clear_line_
; Hides console by blacking palette and disabling PPU.
; Preserved: A, X, Y
console_hide:
pha
jsr console_wait_vbl_
setb PPUMASK,0
lda #$0F
jsr console_load_palette_
pla
rts
console_wait_vbl_:
lda console_scroll
cmp #-1
jne wait_vbl_optional
; Deferred initialization of PPU until first use of console
; In case PPU doesn't support scrolling, start a
; couple of lines down
setb console_scroll,16
jsr console_hide
txa
pha
; Fill nametable with spaces
setb PPUADDR,$20
setb PPUADDR,$00
ldx #240
lda #' '
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
; Clear attributes
lda #0
ldx #$40
: sta PPUDATA
dex
bne :-
pla
tax
jmp console_show
; Shows console display
; Preserved: X, Y
console_show:
pha
jsr console_wait_vbl_
setb PPUMASK,PPUMASK_BG0
lda #$30 ; white
jsr console_load_palette_
jmp console_apply_scroll_
console_load_palette_:
pha
setb PPUADDR,$3F
setb PPUADDR,$00
setb PPUDATA,$0F ; black
pla
sta PPUDATA
sta PPUDATA
sta PPUDATA
rts
; Prints char A to console. Will not appear until
; a newline or flush occurs.
; Preserved: A, X, Y
console_print:
cmp #10
beq console_newline
stx console_temp
; Newline if buf full and next char isn't space
ldx console_pos
bpl :+
cmp #' '
beq @ignore_space
ldx console_temp
jsr console_newline
stx console_temp
ldx console_pos
:
; Write to buffer
sta console_buf+console_margin,x
dex
stx console_pos
@ignore_space:
ldx console_temp
rts
; Displays current line and starts new one
; Preserved: A, X, Y
console_newline:
pha
jsr console_wait_vbl_
jsr console_flush_
jsr console_clear_line_
; Scroll up 8 pixels and clear one line AHEAD
lda console_scroll
jsr console_add_8_to_scroll_
sta console_scroll
jsr console_add_8_to_scroll_
jsr console_flush_a
jmp console_apply_scroll_
; A = (A + 8) % 240
console_add_8_to_scroll_:
cmp #240-8
bcc :+
adc #16-1;+1 for set carry
: adc #8
rts
console_clear_line_:
stx console_temp
; Start new clear line
lda #' '
ldx #console_buf_size-1
: sta console_buf,x
dex
bpl :-
ldx #console_width-1
stx console_pos
ldx console_temp
rts
; Displays current line's contents without scrolling.
; Preserved: A, X, Y
console_flush:
pha
jsr console_wait_vbl_
jsr console_flush_
console_apply_scroll_:
lda #0
sta PPUADDR
sta PPUADDR
sta PPUSCROLL
lda console_scroll
jsr console_add_8_to_scroll_
jsr console_add_8_to_scroll_
sta PPUSCROLL
pla
rts
console_flush_:
lda console_scroll
console_flush_a:
; Address line in nametable
sta console_temp
lda #$08
asl console_temp
rol a
asl console_temp
rol a
sta PPUADDR
lda console_temp
sta PPUADDR
; Copy line
stx console_temp
ldx #console_buf_size-1
: lda console_buf,x
sta PPUDATA
dex
bpl :-
ldx console_temp
rts
|
xem/nes | 1,096 | nes-test-roms/oam_read/source/common/text_out.s | ; Text output as expanding zero-terminated string at text_out_base
; The final exit result byte is written here
final_result = $6000
; Text output is written here as an expanding
; zero-terminated string
text_out_base = $6004
bss_res text_out_temp
zp_res text_out_addr,2
init_text_out:
ldx #0
; Put valid data first
setb text_out_base,0
lda #$80
jsr set_final_result
; Now fill in signature that tells emulator there's
; useful data there
setb text_out_base-3,$DE
setb text_out_base-2,$B0
setb text_out_base-1,$61
ldx #>text_out_base
stx text_out_addr+1
setb text_out_addr,<text_out_base
rts
; Sets final result byte in memory
set_final_result:
sta final_result
rts
; Writes character to text output
; In: A=Character to write
; Preserved: A, X, Y
write_text_out:
sty text_out_temp
; Write new terminator FIRST, then new char before it,
; in case emulator looks at string in middle of this routine.
ldy #1
pha
lda #0
sta (text_out_addr),y
dey
pla
sta (text_out_addr),y
inc text_out_addr
bne :+
inc text_out_addr+1
:
ldy text_out_temp
rts
|
xem/nes | 1,824 | nes-test-roms/oam_read/source/common/ppu.s | ; PPU utilities
bss_res ppu_not_present
; Sets PPUADDR to w
; Preserved: X, Y
.macro set_ppuaddr w
bit PPUSTATUS
setb PPUADDR,>w
setb PPUADDR,<w
.endmacro
; Delays by no more than n scanlines
.macro delay_scanlines n
.if CLOCK_RATE <> 1789773
.error "Currently only supports NTSC"
.endif
delay ((n)*341)/3
.endmacro
; Waits for VBL then disables PPU rendering.
; Preserved: A, X, Y
disable_rendering:
pha
jsr wait_vbl_optional
setb PPUMASK,0
pla
rts
; Fills first nametable with $00
; Preserved: Y
clear_nametable:
lda #0
jsr fill_screen
; Clear pattern table
ldx #64
: sta PPUDATA
dex
bne :-
rts
; Fills screen with tile A
; Preserved: A, Y
fill_screen:
ldx #$20
stx PPUADDR
ldx #$00
stx PPUADDR
ldx #240
: sta PPUDATA
sta PPUDATA
sta PPUDATA
sta PPUDATA
dex
bne :-
rts
; Fills palette with $0F
; Preserved: Y
clear_palette:
set_ppuaddr $3F00
ldx #$20
lda #$0F
: sta PPUDATA
dex
bne :-
; Fills OAM with $FF
; Preserved: Y
clear_oam:
lda #$FF
; Fills OAM with A
; Preserved: A, Y
fill_oam:
ldx #0
: sta SPRDATA
dex
bne :-
rts
; Initializes wait_vbl_optional. Must be called before
; using it.
.align 32
init_wait_vbl:
; Wait for VBL flag to be set, or ~60000
; clocks (2 frames) to pass
ldy #24
ldx #1
bit PPUSTATUS
: bit PPUSTATUS
bmi @set
dex
bne :-
dey
bpl :-
@set:
; Be sure flag didn't stay set (in case
; PPUSTATUS always has high bit set)
tya
ora PPUSTATUS
sta ppu_not_present
rts
; Same as wait_vbl, but returns immediately if PPU
; isn't working or doesn't support VBL flag
; Preserved: A, X, Y
.align 16
wait_vbl_optional:
bit ppu_not_present
bmi :++
; FALL THROUGH
; Clears VBL flag then waits for it to be set.
; Preserved: A, X, Y
wait_vbl:
bit PPUSTATUS
: bit PPUSTATUS
bpl :-
: rts
|
xem/nes | 4,636 | nes-test-roms/oam_read/source/common/shell.s | ; Common routines and runtime
; Detect inclusion loops (otherwise ca65 goes crazy)
.ifdef SHELL_INCLUDED
.error "shell.s included twice"
.end
.endif
SHELL_INCLUDED = 1
;**** Special globals ****
; Temporary variables that ANY routine might modify, so
; only use them between routine calls.
temp = <$A
temp2 = <$B
temp3 = <$C
addr = <$E
ptr = addr
.segment "NVRAM"
; Beginning of variables not cleared at startup
nvram_begin:
;**** Code segment setup ****
.segment "RODATA"
; Any user code which runs off end might end up here,
; so catch that mistake.
nop ; in case there was three-byte opcode before this
nop
jmp internal_error
; Move code to $E200 ($200 bytes for text output)
.segment "DMC"
.res $2200
; Devcart corrupts byte at $E000 when powering off
.segment "CODE"
nop
;**** Common routines ****
.include "macros.inc"
.include "neshw.inc"
.include "print.s"
.include "delay.s"
.include "crc.s"
.include "testing.s"
.ifdef NEED_CONSOLE
.include "console.s"
.else
; Stubs so code doesn't have to care whether
; console exists
console_init:
console_show:
console_hide:
console_print:
console_flush:
rts
.endif
.ifndef CUSTOM_PRINT
.include "text_out.s"
print_char_:
jsr write_text_out
jmp console_print
stop_capture:
rts
.endif
;**** Shell core ****
.ifndef CUSTOM_RESET
reset:
sei
jmp std_reset
.endif
; Sets up hardware then runs main
run_shell:
sei
cld ; unnecessary on NES, but might help on clone
ldx #$FF
txs
jsr init_shell
set_test $FF
jmp run_main
; Initializes shell
init_shell:
jsr clear_ram
jsr init_wait_vbl ; waits for VBL once here,
jsr wait_vbl_optional ; so only need to wait once more
jsr init_text_out
jsr init_testing
jsr init_runtime
jsr console_init
rts
; Runs main in consistent PPU/APU environment, then exits
; with code 0
run_main:
jsr pre_main
jsr main
lda #0
jmp exit
; Sets up environment for main to run in
pre_main:
.ifndef BUILD_NSF
jsr disable_rendering
setb PPUCTRL,0
jsr clear_palette
jsr clear_nametable
jsr clear_oam
.endif
lda #$34
pha
lda #0
tax
tay
jsr wait_vbl_optional
plp
sta SNDMODE
rts
.ifndef CUSTOM_EXIT
exit:
.endif
; Reports result and ends program
std_exit:
sei
cld
ldx #$FF
txs
pha
setb SNDCHN,0
.ifndef BUILD_NSF
setb PPUCTRL,0
.endif
pla
pha
jsr report_result
;jsr clear_nvram ; TODO: was this needed for anything?
pla
jmp post_exit
; Reports final result code in A
report_result:
jsr :+
jmp play_byte
: jsr print_newline
jsr console_show
; 0: ""
cmp #1
bge :+
rts
:
; 1: "Failed"
bne :+
print_str {"Failed",newline}
rts
; n: "Failed #n"
: print_str "Failed #"
jsr print_dec
jsr print_newline
rts
;**** Other routines ****
; Reports internal error and exits program
internal_error:
print_str newline,"Internal error"
lda #255
jmp exit
.import __NVRAM_LOAD__, __NVRAM_SIZE__
; Clears $0-($100+S) and nv_ram_end-$7FF
clear_ram:
lda #0
; Main pages
tax
: sta 0,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x
inx
bne :-
; Stack except that above stack pointer
tsx
inx
: dex
sta $100,x
bne :-
; BSS except nvram
ldx #<__NVRAM_SIZE__
: sta __NVRAM_LOAD__,x
inx
bne :-
rts
; Clears nvram
clear_nvram:
ldx #<__NVRAM_SIZE__
beq @empty
lda #0
: dex
sta __NVRAM_LOAD__,x
bne :-
@empty:
rts
; Prints filename and newline, if available, otherwise nothing.
; Preserved: A, X, Y
print_filename:
.ifdef FILENAME_KNOWN
pha
jsr print_newline
setw addr,filename
jsr print_str_addr
jsr print_newline
pla
.endif
rts
.pushseg
.segment "RODATA"
; Filename terminated with zero byte.
filename:
.ifdef FILENAME_KNOWN
.incbin "ram:nes_temp"
.endif
.byte 0
.popseg
;**** ROM-specific ****
.ifndef BUILD_NSF
.include "ppu.s"
avoid_silent_nsf:
play_byte:
rts
; Loads ASCII font into CHR RAM
.macro load_ascii_chr
bit PPUSTATUS
setb PPUADDR,$00
setb PPUADDR,$00
setb addr,<ascii_chr
ldx #>ascii_chr
ldy #0
@page:
stx addr+1
: lda (addr),y
sta PPUDATA
iny
bne :-
inx
cpx #>ascii_chr_end
bne @page
.endmacro
; Disables interrupts and loops forever
.ifndef CUSTOM_FOREVER
forever:
sei
lda #0
sta PPUCTRL
: beq :-
.res $10,$EA ; room for code to run loader
.endif
; Default NMI
.ifndef CUSTOM_NMI
zp_byte nmi_count
nmi:
inc nmi_count
rti
; Waits for NMI. Must be using NMI handler that increments
; nmi_count, with NMI enabled.
; Preserved: X, Y
wait_nmi:
lda nmi_count
: cmp nmi_count
beq :-
rts
.endif
; Default IRQ
.ifndef CUSTOM_IRQ
irq:
bit SNDCHN ; clear APU IRQ flag
rti
.endif
.endif
|
xem/nes | 3,437 | nes-test-roms/oam_read/source/common/delay.s | ; Delays in CPU clocks, milliseconds, etc. All routines are re-entrant
; (no global data). No routines touch X or Y during execution.
; Code generated by macros is relocatable; it contains no JMPs to itself.
zp_byte delay_temp_ ; only written to
; Delays n clocks, from 2 to 16777215
; Preserved: A, X, Y, flags
.macro delay n
.if (n) < 0 .or (n) = 1 .or (n) > 16777215
.error "Delay out of range"
.endif
delay_ (n)
.endmacro
; Delays n milliseconds (1/1000 second)
; n can range from 0 to 1100.
; Preserved: A, X, Y, flags
.macro delay_msec n
.if (n) < 0 .or (n) > 1100
.error "time out of range"
.endif
delay ((n)*CLOCK_RATE+500)/1000
.endmacro
; Delays n microseconds (1/1000000 second).
; n can range from 0 to 100000.
; Preserved: A, X, Y, flags
.macro delay_usec n
.if (n) < 0 .or (n) > 100000
.error "time out of range"
.endif
delay ((n)*((CLOCK_RATE+50)/100)+5000)/10000
.endmacro
.align 64
; Delays A clocks + overhead
; Preserved: X, Y
; Time: A+25 clocks (including JSR)
: sbc #7 ; carry set by CMP
delay_a_25_clocks:
cmp #7
bcs :- ; do multiples of 7
lsr a ; bit 0
bcs :+
: ; A=clocks/2, either 0,1,2,3
beq @zero ; 0: 5
lsr a
beq :+ ; 1: 7
bcc :+ ; 2: 9
@zero: bne :+ ; 3: 11
: rts ; (thanks to dclxvi for the algorithm)
; Delays A*256 clocks + overhead
; Preserved: X, Y
; Time: A*256+16 clocks (including JSR)
delay_256a_16_clocks:
cmp #0
bne :+
rts
delay_256a_11_clocks_:
: pha
lda #256-19-22
jsr delay_a_25_clocks
pla
clc
adc #-1
bne :-
rts
; Delays A*65536 clocks + overhead
; Preserved: X, Y
; Time: A*65536+16 clocks (including JSR)
delay_65536a_16_clocks:
cmp #0
bne :+
rts
delay_65536a_11_clocks_:
: pha
lda #256-19-22-13
jsr delay_a_25_clocks
lda #255
jsr delay_256a_11_clocks_
pla
clc
adc #-1
bne :-
rts
max_short_delay = 41
; delay_short_ macro jumps into these
.res (max_short_delay-12)/2,$EA ; NOP
delay_unrolled_:
rts
.macro delay_short_ n
.if n < 0 .or n = 1 .or n > max_short_delay
.error "Internal delay error"
.endif
.if n = 0
; nothing
.elseif n = 2
nop
.elseif n = 3
sta <delay_temp_
.elseif n = 4
nop
nop
.elseif n = 5
sta <delay_temp_
nop
.elseif n = 6
nop
nop
nop
.elseif n = 7
php
plp
.elseif n = 8
nop
nop
nop
nop
.elseif n = 9
php
plp
nop
.elseif n = 10
sta <delay_temp_
php
plp
.elseif n = 11
php
plp
nop
nop
.elseif n = 13
php
plp
nop
nop
nop
.elseif n & 1
sta <delay_temp_
jsr delay_unrolled_-((n-15)/2)
.else
jsr delay_unrolled_-((n-12)/2)
.endif
.endmacro
.macro delay_nosave_ n
; 65536+17 = maximum delay using delay_256a_11_clocks_
; 255+27 = maximum delay using delay_a_25_clocks
; 27 = minimum delay using delay_a_25_clocks
.if n > 65536+17
lda #^(n - 15)
jsr delay_65536a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (((n - 15) & $FFFF) + 2)
.elseif n > 255+27
lda #>(n - 15)
jsr delay_256a_11_clocks_
; +2 ensures remaining clocks is never 1
delay_nosave_ (<(n - 15) + 2)
.elseif n >= 27
lda #<(n - 27)
jsr delay_a_25_clocks
.else
delay_short_ n
.endif
.endmacro
.macro delay_ n
.if n > max_short_delay
php
pha
delay_nosave_ (n - 14)
pla
plp
.else
delay_short_ n
.endif
.endmacro
|
xem/nes | 1,632 | nes-test-roms/oam_read/source/common/crc.s | ; CRC-32 checksum calculation
zp_res checksum,4
zp_byte checksum_temp
zp_byte checksum_off_
; Turns CRC updating on/off. Allows nesting.
; Preserved: A, X, Y
crc_off:
dec checksum_off_
rts
crc_on: inc checksum_off_
beq :+
jpl internal_error ; catch unbalanced crc calls
: rts
; Initializes checksum module. Might initialize tables
; in the future.
init_crc:
jmp reset_crc
; Clears checksum and turns it on
; Preserved: X, Y
reset_crc:
lda #0
sta checksum_off_
lda #$FF
sta checksum
sta checksum + 1
sta checksum + 2
sta checksum + 3
rts
; Updates checksum with byte in A (unless disabled via crc_off)
; Preserved: A, X, Y
; Time: 357 clocks average
update_crc:
bit checksum_off_
bmi update_crc_off
update_crc_:
pha
stx checksum_temp
eor checksum
ldx #8
@bit: lsr checksum+3
ror checksum+2
ror checksum+1
ror a
bcc :+
sta checksum
lda checksum+3
eor #$ED
sta checksum+3
lda checksum+2
eor #$B8
sta checksum+2
lda checksum+1
eor #$83
sta checksum+1
lda checksum
eor #$20
: dex
bne @bit
sta checksum
ldx checksum_temp
pla
update_crc_off:
rts
; Prints checksum as 8-character hex value
print_crc:
jsr crc_off
; Print complement
ldx #3
: lda checksum,x
eor #$FF
jsr print_hex
dex
bpl :-
jmp crc_on
; EQ if checksum matches CRC
; Out: A=0 and EQ if match, A>0 and NE if different
; Preserved: X, Y
.macro is_crc crc
jsr_with_addr is_crc_,{.dword crc}
.endmacro
is_crc_:
tya
pha
; Compare with complemented checksum
ldy #3
: lda (ptr),y
sec
adc checksum,y
bne @wrong
dey
bpl :-
pla
tay
lda #0
rts
@wrong:
pla
tay
lda #1
rts
|
xem/nes | 2,037 | nes-test-roms/instr_misc/source/03-dummy_reads.s | ; Tests some instructions that do dummy reads before the real read/write.
; Doesn't test all instructions.
;
; Tests LDA and STA with modes (ZP,X), (ZP),Y and ABS,X
; Dummy reads for the following cases are tested:
;
; LDA ABS,X or (ZP),Y when carry is generated from low byte
; STA ABS,X or (ZP),Y
; ROL ABS,X always
.include "shell.inc"
no_read:
lda PPUSTATUS
single_read:
jpl test_failed
dummy_read:
lda PPUSTATUS
double_read:
jmi test_failed
lda PPUSTATUS
jmi test_failed
begin: jsr wait_vbl
delay PPU_FRAMELEN + 20
ldx #$22
ldy #$22
rts
main: jsr begin
set_test 2,"Test requires $2002 mirroring every 8 bytes to $3FFA"
lda $3FFA
jsr single_read
set_test 3,"LDA abs,x"
lda $2000,x ; $2022
jsr single_read
lda $20E0,x ; $2002, $2102
jsr double_read
lda $20E2,x ; $2004, $2104
jsr no_read
lda $3FE0,x ; $3F02, $4002
jsr dummy_read
set_test 4,"STA abs,x"
sta $2002
jsr no_read
sta $20E0,x ; $2002, $2102 (write)
jsr dummy_read
sta $20E2,x ; $2004, $2104 (write)
jsr no_read
sta $3FE0,x ; $3F02, $4002 (write)
jsr dummy_read
set_test 5,"LDA (z),y"
setw addr,$2000
lda (addr),y ; $2022
jsr single_read
setw addr,$20E0
lda (addr),y ; $2002, $2102
jsr double_read
setw addr,$20E2
lda (addr),y ; $2004, $2104
jsr no_read
setw addr,$3FE0
lda (addr),y ; $3F02, $4002
jsr dummy_read
set_test 6,"STA (z),y"
setw addr,$20E0
sta (addr),y ; $2002, $2102 (write)
jsr dummy_read
setw addr,$20E2
sta (addr),y ; $2004, $2104 (write)
jsr no_read
setw addr,$3FE0
sta (addr),y ; $3F02, $4002 (write)
jsr dummy_read
set_test 7,"LDA (z,x)"
ldx #0
setw addr,$2002
lda (addr,x) ; no dummy read
jsr single_read
set_test 8,"STA (z,x)"
ldx #0
setw addr,$2002
sta (addr,x) ; no dummy read
jsr no_read
set_test 9,"ROL abs"
rol $2022 ; $2022
ror a
jsr single_read
set_test 10,"ROL abs,x"
rol $2000,x ; $2022, $2022
ror a
jsr double_read
rol $3FE0,x ; $3F02, $4002
jsr dummy_read
jmp tests_passed
|
xem/nes | 1,931 | nes-test-roms/instr_misc/source/04-dummy_reads_apu.s | ; Tests dummy reads for (hopefully) ALL instructions which do them,
; including unofficial ones. Prints opcode(s) of failed
; instructions. Requires that APU implement $4015 IRQ flag reading.
.include "shell.inc"
zp_byte opcode
zp_byte errors
begin: setb SNDMODE,0
lda SNDCHN
delay 30000
setw addr,SNDCHN+3
rts
failed:
inc errors
lda opcode
jsr print_a
jsr play_byte
rts
.macro test_ x_, y_, instr
.local instr_
lda instr_
sta opcode
jsr begin
ldx #x_
ldy #y_
instr_: instr
lda SNDCHN
and #$40
.endmacro
.macro test_x opcode
test_ 0,-3,{.byte opcode,<SNDCHN+3,>SNDCHN}
beq :+
test_ -3,0,{.byte opcode,<SNDCHN+3,>SNDCHN}
beq :++
: jsr failed
:
.endmacro
.macro test_y opcode
test_ -3,0,{.byte opcode,<SNDCHN+3,>SNDCHN}
beq :+
test_ 0,-3,{.byte opcode,<SNDCHN+3,>SNDCHN}
beq :++
: jsr failed
:
.endmacro
.macro test_i opcode
test_ -3,0,{.byte opcode,addr}
beq :+
test_ 0,-3,{.byte opcode,addr}
beq :++
: jsr failed
:
.endmacro
.macro test_xyi opcode
test_x opcode
test_y opcode-4
test_i opcode-12
.endmacro
main:
set_test 2,"Official opcodes failed"
test_xyi $1D ; ORA
test_xyi $3D ; AND
test_xyi $5D ; EOR
test_xyi $7D ; ADC
test_xyi $9D ; STA
test_xyi $BD ; LDA
test_xyi $DD ; CMP
test_xyi $FD ; SBC
test_x $1E ; ASL
test_x $3E ; ROL
test_x $5E ; LSR
test_x $7E ; ROR
test_x $DE ; DEC
test_x $FE ; INC
test_x $BC ; LDY
test_y $BE ; LDX
lda errors
jne test_failed
set_test 2,"Unofficial opcodes failed"
test_x $1C ; SKW
test_x $3C ; SKW
test_x $5C ; SKW
test_x $7C ; SKW
test_x $DC ; SKW
test_x $FC ; SKW
test_xyi $1F ; ASO
test_xyi $3F ; RLA
test_xyi $5F ; LSE
test_xyi $7F ; RRA
test_xyi $DF ; DCM
test_xyi $FF ; INS
test_x $9C ; SAY
test_y $BF ; LAX
test_y $9B ; TAS
test_y $9E ; XAS
test_y $9F ; AXA
test_y $BB ; LAS
test_i $93 ; AXA
test_i $B3 ; LAX
lda errors
jne test_failed
jmp tests_passed
|
xem/nes | 1,856 | nes-test-roms/instr_misc/source/common/testing.s | ; Utilities for writing test ROMs
; In NVRAM so these can be used before initializing runtime,
; then runtime initialized without clearing them
nv_res test_code ; code of current test
nv_res test_name,2 ; address of name of current test, or 0 of none
; Sets current test code and optional name. Also resets
; checksum.
; Preserved: A, X, Y
.macro set_test code,name
pha
lda #code
jsr set_test_
.ifblank name
setb test_name+1,0
.else
.local Addr
setw test_name,Addr
seg_data "RODATA",{Addr: .byte name,0}
.endif
pla
.endmacro
set_test_:
sta test_code
jmp reset_crc
; Initializes testing module
init_testing:
jmp init_crc
; Reports that all tests passed
tests_passed:
jsr print_filename
print_str newline,"Passed"
lda #0
jmp exit
; Reports "Done" if set_test has never been used,
; "Passed" if set_test 0 was last used, or
; failure if set_test n was last used.
tests_done:
ldx test_code
jeq tests_passed
inx
bne test_failed
jsr print_filename
print_str newline,"Done"
lda #0
jmp exit
; Reports that the current test failed. Prints code and
; name last set with set_test, or just "Failed" if none
; have been set yet.
test_failed:
ldx test_code
; Treat $FF as 1, in case it wasn't ever set
inx
bne :+
inx
stx test_code
:
; If code >= 2, print name
cpx #2-1 ; -1 due to inx above
blt :+
lda test_name+1
beq :+
jsr print_newline
sta addr+1
lda test_name
sta addr
jsr print_str_addr
jsr print_newline
:
jsr print_filename
; End program
lda test_code
jmp exit
; If checksum doesn't match expected, reports failed test.
; Clears checksum afterwards.
; Preserved: A, X, Y
.macro check_crc expected
jsr_with_addr check_crc_,{.dword expected}
.endmacro
check_crc_:
pha
jsr is_crc_
bne :+
jsr reset_crc
pla
rts
: jsr print_newline
jsr print_crc
jmp test_failed
|
xem/nes | 2,660 | nes-test-roms/instr_misc/source/common/print.s | ; Prints values in various ways to output,
; including numbers and strings.
newline = 10
zp_byte print_temp_
; Prints indicated register to console as two hex
; chars and space
; Preserved: A, X, Y, flags
print_a:
php
pha
print_reg_:
jsr print_hex
lda #' '
jsr print_char_
pla
plp
rts
print_x:
php
pha
txa
jmp print_reg_
print_y:
php
pha
tya
jmp print_reg_
print_p:
php
pha
php
pla
jmp print_reg_
print_s:
php
pha
txa
tsx
inx
inx
inx
inx
jsr print_x
tax
pla
plp
rts
; Prints A as two hex characters, NO space after
; Preserved: A, X, Y
print_hex:
jsr update_crc
pha
lsr a
lsr a
lsr a
lsr a
jsr @nibble
pla
pha
and #$0F
jsr @nibble
pla
rts
@nibble:
cmp #10
blt @digit
adc #6;+1 since carry is set
@digit: adc #'0'
jmp print_char_
; Prints character and updates checksum UNLESS
; it's a newline.
; Preserved: A, X, Y
print_char:
cmp #newline
beq :+
jsr update_crc
: pha
jsr print_char_
pla
rts
; Prints space. Does NOT update checksum.
; Preserved: A, X, Y
print_space:
pha
lda #' '
jsr print_char_
pla
rts
; Advances to next line. Does NOT update checksum.
; Preserved: A, X, Y
print_newline:
pha
lda #newline
jsr print_char_
pla
rts
; Prints string
; Preserved: A, X, Y
.macro print_str str,str2
jsr print_str_
.byte str
.ifnblank str2
.byte str2
.endif
.byte 0
.endmacro
print_str_:
sta print_temp_
pla
sta addr
pla
sta addr+1
jsr inc_addr
jsr print_str_addr
lda print_temp_
jmp (addr)
; Prints string at addr and leaves addr pointing to
; byte AFTER zero terminator.
; Preserved: A, X, Y
print_str_addr:
pha
tya
pha
ldy #0
beq :+ ; always taken
@loop: jsr print_char
jsr inc_addr
: lda (addr),y
bne @loop
pla
tay
pla
; FALL THROUGH
; Increments 16-bit value in addr.
; Preserved: A, X, Y
inc_addr:
inc addr
beq :+
rts
: inc addr+1
rts
; Prints A as 1-3 digit decimal value, NO space after.
; Preserved: A, X, Y
print_dec:
pha
sta print_temp_
txa
pha
lda print_temp_
; Hundreds
cmp #10
blt @ones
cmp #100
blt @tens
ldx #'0'-1
: inx
sbc #100
bge :-
adc #100
jsr @digit
; Tens
@tens: sec
ldx #'0'-1
: inx
sbc #10
bge :-
adc #10
jsr @digit
; Ones
@ones: ora #'0'
jsr print_char
pla
tax
pla
rts
; Print a single digit
@digit: pha
txa
jsr print_char
pla
rts
; Prints one of two characters based on condition.
; SEC; print_cc bcs,'C','-' prints 'C'.
; Preserved: A, X, Y, flags
.macro print_cc cond,yes,no
; Avoids labels since they're not local
; to macros in ca65.
php
pha
cond *+6
lda #no
bne *+4
lda #yes
jsr print_char
pla
plp
.endmacro
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.