repo_id
stringlengths
5
115
size
int64
590
5.01M
file_path
stringlengths
4
212
content
stringlengths
590
5.01M
xboot/libxnes
1,593
documents/test-roms/cpu_flag_concurrency/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&$FFFF,-1&$FFFF,-1&$FFFF, 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_3.chr" ;.align $200 .incbin "ascii_2.chr" ;.align $200 .incbin "ascii_1.chr" .res $E00 .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 .align 256
xboot/libxnes
4,298
documents/test-roms/cpu_flag_concurrency/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 zp_byte text_color bss_res console_buf,console_buf_size ; Initializes console console_init: ; Flag that console hasn't been initialized setb console_scroll,-1&$FF lda #0 sta text_color jmp console_clear_line_ ; Hides console by blacking palette and disabling PPU. ; Preserved: A, X, Y console_hide: pha txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,0 lda #$0F tax tay jsr console_load_palette_ pla tay pla tax pla rts console_wait_vbl_: lda console_scroll cmp #-1&$FF 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 #$E0 ;sta text_color lda #0 : 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 txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ ; Shows console display ; Preserved: X, Y console_show_nowait: pha txa pha tay pha setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ console_load_palette_: pha setb PPUADDR,$3F setb PPUADDR,$00 setb PPUDATA,$0F ; black pla sta PPUDATA stx PPUDATA sty 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 clc adc text_color 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 #0 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
xboot/libxnes
1,096
documents/test-roms/cpu_flag_concurrency/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
xboot/libxnes
2,024
documents/test-roms/cpu_flag_concurrency/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
xboot/libxnes
4,660
documents/test-roms/cpu_flag_concurrency/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_nametable2 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
xboot/libxnes
5,124
documents/test-roms/cpu_flag_concurrency/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&$FF bne :- rts ; Delays A*256+X clocks (including JSR) + overhead of 26 cycles ; Minimum delay accepted: 0. ; Gobbles A,X,Y. Written by Joel Yliluoma delay_256a_x_26_clocks: ; JSR = 6 clocks ; RTS = 6 clocks tay ; OVERHEAD: 2 cycles beq @no_256s ; OVERHEAD: 5 cycles (3 for taken branch) @loop_256: ; ; TODO: waste exactly 256 cycles here lda #(256-25-7) ; 2 cycles jsr delay_a_25_clocks dey ; 2 cycles bne @loop_256 ; 3 cycles for taken branch ; ; non-taken branch: -1 cycles ; ; OVERHEAD: 4 cycle @no_256s: ; OVERHEAD: 4 cycles (either 5-1 or 2+2) ; ; TODO: Waste exactly X cycles. ; The overhead for delay_a_25_clocks is 25 clocks. ; Additionally, it has a minimum of .. 7? clocks. cpx #20 ; 2 cycles bcs @use_25 ; 3 cycles for taken branch ; ; OVERHEAD: 8 cycles (untaken branch was 2 cycles) ; Remaining delay: 0..20 ; ; address delay_unrolled_small_ - X ; = -X + delay_unrolled_small_ ; = (~X) + 1 + delay_unrolled_small_ ; RTS adds 1 to the address. ; Performs 2 extra cycles of delay ; lda #>(delay_unrolled_small_) ; 2 cycles pha ; 3 cycles txa ; 2 cycles eor #$FF ; 2 cycles clc ; 2 cycles adc #<(delay_unrolled_small_) ; 2 cycles pha ; 3 cycles rts ; 6 cycles + 2 cycles of extra ; ^FINAL OVERHEAD: 26 cycles @use_25: ; X is >= 21. ; OVERHEAD so far: 9 cycles txa ; 2 cycles sec ; 2 cycles sbc #12 ; 3 cycles jmp delay_a_25_clocks ; -3 cycles (because we don't use RTS) ; OVERHEAD so far: 9+2+ 2+3 -3+25 - 12 = 26 cycles ; 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&$FF bne :- rts max_short_delay = 41 ; delay_short_ macro jumps into these .res (max_short_delay-12)/2,$EA ; NOP delay_unrolled_: rts max_small_delay = 26 .align $40 .res (max_small_delay-2), $C9 ; cmp #imm - 2 cycles .byte $C5,$EA ; cmp zp - 3 cycles delay_unrolled_small_: 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
xboot/libxnes
1,638
documents/test-roms/cpu_flag_concurrency/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
xboot/libxnes
7,782
documents/test-roms/instr_timing/source/1-instr_timing.s
; Tests instruction timing for all except the 8 branches and 12 halts ; ; Times each instruction by putting it in a loop that counts iterations ; and waits for APU length counter to expire. CUSTOM_IRQ=1 .include "shell.inc" zp_byte nothing_failed zp_byte test_index zp_byte type_mask zp_byte saved_sp stack_copy = $600 ; stack is copied here during instruction test test_opcode = $705 ; test loop is copied here irq = test_opcode+2 main: print_str "Instruction timing test",{newline,newline} print_str "Takes about 25 seconds. " print_str "Doesn't time the 8 branches " print_str "and 12 illegal instructions.",{newline,newline} set_test 5,"Timing of APU length period, INC zp, LDA abs, AND #imm, or BNE (taken) is wrong." lda #$29 sta test_index jsr time_instr cmp #2 jne test_failed set_test 0 print_str "Official instructions...",newline lda #0 jsr test_instrs bne :+ set_test 2,"Official instruction timing is wrong" : print_str {newline,"NOPs and alternate SBC...",newline} lda #$80 jsr test_instrs bne :+ set_test 3,"NOPs and alternate SBC timing is wrong" : print_str {newline,"Unofficial instructions...",newline} lda #$40 jsr test_instrs bne :+ set_test 4,"Unofficial instruction timing is wrong" : jmp tests_done ; A -> Type to test test_instrs: sta type_mask setb nothing_failed,1 setb test_index,0 @loop: ldx test_index lda instr_types,x and #$F0 cmp type_mask bne :+ jsr avoid_silent_nsf jsr @test_instr : inc test_index bne @loop lda nothing_failed ora test_code rts ; Tests current instruction in normal and page cross cases @test_instr: ; No page crossing lda #2 jsr time_instr ldy test_index eor instr_times,y beq :+ jsr print_failed_instr jsr print_newline lda instr_times,y cmp instr_times_cross,y bne :+ ; test again only if page crossing time is different rts ; Page crossing : lda #3 jsr time_instr ldy test_index eor instr_times_cross,y beq :+ jsr print_failed_instr print_str " (cross)",newline : rts ; Prints failed instruction times ; A -> Actual XOR correct ; X -> Actual ; Preserved: Y print_failed_instr: pha lda test_index jsr print_hex jsr play_byte print_str " was " txa jsr print_dec pla print_str ", should be " stx temp eor temp jsr print_dec setb nothing_failed,0 rts ; Times a single instruction ; test_index -> Opcode of instruction ; A -> Byte to load into X and Y before running instruction ; X, A <- Cycles instruction took .align 256 time_instr: sta temp ldy test_index sty test_opcode ; Copy test_opcode to RAM lda instr_types,y and #$07 asl a tay lda test_addrs-2,y sta addr lda test_addrs-1,y sta addr+1 ldy #1 : lda (addr),y sta test_opcode,y iny cpy #16 bne :- ; Save copy of stack tsx stx saved_sp : lda $100,x sta stack_copy,x inx bne :- ; Set zero-page values so the addressing modes use the following ; when X and Y = $02/$03 ; zp $FD ; zp,x $FF/$00 ; abs $03FD ; abs,x/y $03FF/$0400 ; (ind,x) $02FD/$0302 ; (ind),y $02FF/$0300 ; JMP (ind) test_opcode+3 setb <$00,$02 setb <$01,$03 setb <$FD,$FD setb <$FE,$02 setb <$FF,$FD lda temp ; $A3 LAX (ab,X) will load X from these two sta $02FD sta $0302 setw $03FD,test_opcode+3 ; JMP ($03FD) will use this address ; Fill stack for RTS/RTI test ldx #$FF txs inx lda #>test_opcode : pha inx bne :- ; Setup registers lda temp tay tax setb temp,0 ; Synchronize with APU length counter setb SNDMODE,$40 setb SNDCHN,$01 setb $4000,$10 setb $4001,$7F setb $4002,$FF setb $4003,$18 lda #$01 : and SNDCHN bne :- ; Setup length counter setb $4003,$18 ; ~26323 delay, so length counter will be ~3500 cycles from expiring setb temp3,-13 setb temp2,-207 : inc temp2 bne :- inc temp3 bne :- ; Run instruction jmp test_opcode raw_to_cycles: ; entry i is lowest value that qualifies for i cycles .byte 241, 226, 212, 200, 189, 179, 171, 163, 156, 149, 0 ; Jumps here when instruction has been timed instr_done: ; Restore things in case instruction affected them sei cld ; Convert iteration count to cycle count lda temp ldy #-1 : iny cmp raw_to_cycles,y blt :- ; Convert 10+ to 0 cpy #10 blt :+ ldy #0 : ; Restore stack ldx saved_sp txs : lda stack_copy,x sta $100,x inx bne :- tya tax rts .macro instr_template instr : instr inc temp lda SNDCHN and #$01 bne :- jmp instr_done .endmacro test_1: instr_template nop test_2: instr_template sta <$FD test_3: instr_template sta $03FD test_4: instr_template jmp test_opcode+3 test_addrs: .word test_1, test_2, test_3, test_4 ; $8n = unofficial NOPs and $EB equivalent of SBC #imm ; $4n = all other unofficial opcodes ; $0n = official opcodes ; -1 = not tested ; n = instruction length instr_types: ; 0 1 2 3 4 5 6 7 8 9 A B C D E F .byte 2, 2, -1,$42,$82, 2, 2,$42, 1, 2, 1,$42,$83, 3, 3,$43 ; 0 .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; 1 .byte 4, 2, -1,$42, 2, 2, 2,$42, 1, 2, 1,$42, 3, 3, 3,$43 ; 2 .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; 3 .byte 2, 2, -1,$42,$82, 2, 2,$42, 1, 2, 1,$42, 4, 3, 3,$43 ; 4 .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; 5 .byte 3, 2, -1,$42,$82, 2, 2,$42, 1, 2, 1,$42, 3, 3, 3,$43 ; 6 .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; 7 .byte $82, 2,$82,$42, 2, 2, 2,$42, 1,$82, 1,$42, 3, 3, 3,$43 ; 8 .byte -1, 2, -1,$42, 2, 2, 2,$42, 1, 3, 1,$43,$43, 3,$43,$43 ; 9 .byte 2, 2, 2,$42, 2, 2, 2,$42, 1, 2, 1,$42, 3, 3, 3,$43 ; A .byte -1, 2, -1,$42, 2, 2, 2,$42, 1, 3, 1,$43, 3, 3, 3,$43 ; B .byte 2, 2,$82,$42, 2, 2, 2,$42, 1, 2, 1,$42, 3, 3, 3,$43 ; C .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; D .byte 2, 2,$82,$42, 2, 2, 2,$42, 1, 2, 1,$82, 3, 3, 3,$43 ; E .byte -1, 2, -1,$42,$82, 2, 2,$42, 1, 3,$81,$43,$83, 3, 3,$43 ; F ; Bxx HLT ; Clocks when no page crossing occurs instr_times: ; 0 1 2 3 4 5 6 7 8 9 A B C D E F .byte 7,6,0,8,3,3,5,5,3,2,2,2,4,4,6,6 ; 0 .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; 1 .byte 6,6,0,8,3,3,5,5,4,2,2,2,4,4,6,6 ; 2 .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; 3 .byte 6,6,0,8,3,3,5,5,3,2,2,2,3,4,6,6 ; 4 .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; 5 .byte 6,6,0,8,3,3,5,5,4,2,2,2,5,4,6,6 ; 6 .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; 7 .byte 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4 ; 8 .byte 0,6,0,6,4,4,4,4,2,5,2,5,5,5,5,5 ; 9 .byte 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4 ; A .byte 0,5,0,5,4,4,4,4,2,4,2,4,4,4,4,4 ; B .byte 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6 ; C .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; D .byte 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6 ; E .byte 0,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 ; F ; Clocks when page crossing occurs instr_times_cross: ; 0 1 2 3 4 5 6 7 8 9 A B C D E F .byte 7,6,0,8,3,3,5,5,3,2,2,2,4,4,6,6 ; 0 .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; 1 .byte 6,6,0,8,3,3,5,5,4,2,2,2,4,4,6,6 ; 2 .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; 3 .byte 6,6,0,8,3,3,5,5,3,2,2,2,3,4,6,6 ; 4 .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; 5 .byte 6,6,0,8,3,3,5,5,4,2,2,2,5,4,6,6 ; 6 .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; 7 .byte 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4 ; 8 .byte 0,6,0,6,4,4,4,4,2,5,2,5,5,5,5,5 ; 9 .byte 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4 ; A .byte 0,6,0,6,4,4,4,4,2,5,2,5,5,5,5,5 ; B .byte 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6 ; C .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; D .byte 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6 ; E .byte 0,6,0,8,4,4,6,6,2,5,2,7,5,5,7,7 ; F
xboot/libxnes
2,427
documents/test-roms/instr_timing/source/2-branch_timing.s
; Verifies timing of branch instructions ; ; Runs branch instruction in loop that counts iterations ; until APU length counter expires. Moves the loop around ; in memory to trigger page cross/no cross cases. .include "shell.inc" zp_byte opcode zp_byte flags zp_byte time_ptr bss_res times,8 main: set_test 0 for_loop test_opcode,$10,$F0,$20 jmp tests_done log_time: ldx time_ptr sta times,x inc time_ptr rts test_opcode: sta opcode ; Not taken ldx #$FF and #$20 beq :+ inx : stx flags setb time_ptr,0 jsr test_addrs ; Taken lda flags eor #$FF sta flags jsr test_addrs ; Verify times ldx #8 - 1 : lda times,x cmp @correct_times,x bne @error dex bpl :- rts @correct_times: .byte 2,2,2,2,3,3,4,4 @error: lda opcode jsr print_a jsr play_byte ldy #0 : lda times,y jsr print_dec jsr print_space iny cpy #8 bne :- jsr print_newline set_test 1 rts ; Tests instruction with page cross/no cross cases test_addrs: setw addr,$6EA jsr test_forward setw addr,$700 jsr test_reverse setw addr,$6EB jsr test_forward setw addr,$6FF jsr test_reverse rts ; Times code at addr time_code: pha ; Synchronize with APU length counter setb SNDMODE,$40 setb SNDCHN,$01 setb $4000,$10 setb $4001,$7F setb $4002,$FF setb $4003,$18 lda #$01 : and SNDCHN bne :- ; Setup length counter setb $4003,$18 delay 29830-7120 ; Run instruction setb temp,0 pla jmp (addr) raw_to_cycles: ; entry i is lowest value that qualifies for i cycles .byte 250, 241, 233, 226, 219, 213, 206, 201, 195, 190, 0 ; Jumps here when instruction has been timed instr_done: ; Convert iteration count to cycle count lda temp ldy #-1 : iny cmp raw_to_cycles,y blt :- ; Convert 10+ to 0 cpy #10 blt :+ ldy #0 : tya jsr log_time rts .macro test_dir ; Copy code ldy #40 : lda @code,y sta (addr),y dey bpl :- ; Patch branch opcode ldy #@branch - @code lda opcode sta (addr),y ; Calculate address of @loop lda addr clc adc #@loop - @code sta addr lda addr+1 adc #0 sta addr+1 jmp time_code @code: .endmacro .macro instr_loop inc temp lda SNDCHN and #$01 beq *+5 jmp (addr) jmp instr_done .endmacro test_reverse: test_dir : instr_loop @loop: lda flags pha plp @branch: bmi :- instr_loop test_forward: test_dir @loop: lda flags pha plp @branch: bmi :+ instr_loop : instr_loop
xboot/libxnes
1,856
documents/test-roms/instr_timing/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
xboot/libxnes
2,660
documents/test-roms/instr_timing/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
xboot/libxnes
1,506
documents/test-roms/instr_timing/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 ; Move code to $C000 .segment "CODE" .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 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
xboot/libxnes
5,523
documents/test-roms/instr_timing/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. .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: 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
xboot/libxnes
1,096
documents/test-roms/instr_timing/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
xboot/libxnes
2,024
documents/test-roms/instr_timing/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
xboot/libxnes
5,433
documents/test-roms/instr_timing/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 ; 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 to $E200 ($200 bytes for text output in devcarts ; where WRAM is mirrored to $E000) .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" .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_nametable2 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 ldx #0 stx SNDCHN .ifndef BUILD_NSF stx PPUCTRL .endif jsr report_result 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__ .macro fill_ram_ Begin, End .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 ; 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 ; 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 sta SNDCHN delay_msec 160 pla rts
xboot/libxnes
3,437
documents/test-roms/instr_timing/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
xboot/libxnes
1,632
documents/test-roms/instr_timing/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
xboot/libxnes
4,299
documents/test-roms/cpu_exec_space/source/test_cpu_exec_space_apu.s
; Expected output, and explanation: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TEST: test_cpu_exec_space_apu ; This program verifies that the ; CPU can execute code from any ; possible location that it can ; address, including I/O space. ; ; In this test, it is also ; verified that not only all ; write-only APU I/O ports ; return the open bus, but ; also the unallocated I/O ; space in $4018..$40FF. ; ; 40FF 40 ; Passed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Written by Joel Yliluoma - http://iki.fi/bisqwit/ .segment "LIB" .include "shell.inc" .include "colors.inc" .segment "CODE" zp_res nmi_count zp_res maybe_crashed zp_res temp_code,8 zp_res console_save,2 bss_res empty,$500 .macro print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 print_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 rts .endmacro .macro my_print_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 .local Addr jsr Addr seg_data "RODATA",{Addr: print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15} .endmacro set_vram_pos: ldy PPUSTATUS sta PPUADDR ; poke high 6 bits stx PPUADDR ; poke low 8 bits rts test_failed_finish: jsr crash_proof_end ; Re-enable screen jsr console_show text_white jmp test_failed open_bus_pathological_fail: jmp test_failed_finish main: jsr intro ; Disable all APU channels and frame IRQ (ensure that $4015 reads back as $00) lda #$00 sta $4015 lda #$40 sta $4017 ldx #>empty ldy #<empty lda #0 sta console_save @ram_clear_loop: stx console_save+1 : sta (console_save),y iny bne :- inx cpx #8 bne @ram_clear_loop text_color2 lda console_pos sta console_save+0 lda console_scroll sta console_save+1 lda #>temp_code jsr print_hex lda #<temp_code jsr print_hex lda #' ' jsr print_char jsr console_flush lda #$60 sta temp_code lda #$EA sta temp_code+1 jsr temp_code ldy #$40 ldx #0 @loop: lda console_save+0 sta console_pos lda console_save+1 sta console_scroll lda #13 jsr write_text_out ;CR cpx #$15 beq :+ tya jsr print_hex txa jsr print_hex lda #' ' jsr print_char lda $4000,x jsr print_hex lda #' ' jsr print_char jsr console_flush ; prepare for RTI lda #>(:+ ) pha lda #<(:+ ) pha php ; lda #$4C ; jmp abs sta temp_code+0 stx temp_code+1 sty temp_code+2 jmp temp_code : inx bne @loop text_white jsr console_show jsr wait_vbl jmp tests_passed .pushseg .segment "RODATA" intro: text_white print_str "TEST: test_cpu_exec_space_apu",newline text_color1 jsr print_str_ ; 0123456789ABCDEF0123456789ABCD .byte "This program verifies that the",newline .byte "CPU can execute code from any",newline .byte "possible location that it can",newline .byte "address, including I/O space.",newline .byte newline .byte "In this test, it is also",newline .byte "verified that not only all",newline .byte "write-only APU I/O ports",newline .byte "return the open bus, but",newline .byte "also the unallocated I/O",newline .byte "space in $4018..$40FF.",newline .byte newline,0 text_white rts .popseg nmi: pha lda maybe_crashed beq :+ inc nmi_count lda nmi_count cmp #4 bcc :+ jmp test_failed_finish : pla rti crash_proof_begin: lda #$FF sta nmi_count sta maybe_crashed ; Enable NMI lda #$80 sta $2000 rts crash_proof_end: ; Disable NMI lda #0 sta $2000 sta maybe_crashed rts irq: ; Presume we got here through a BRK opcode. ; Presumably, that opcode was placed in $8000..$E000 to trap wrong access. plp wrong_code_executed_somewhere: text_white print_str "ERROR",newline text_color1 ; 0123456789ABCDEF0123456789ABC| print_str "Mysteriously Landed at $" pla tax pla jsr print_hex txa jsr print_hex text_white jsr print_str_ .byte newline ; 0123456789ABCDEF0123456789ABCD .byte "Program flow did not follow",newline .byte "the planned path, for a number",newline .byte "of different possible reasons.",newline .byte 0 ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 2,"Failure To Obey Predetermined Execution Path" jmp test_failed_finish .pushseg .segment "WRONG_CODE_8000" .repeat $6200 brk .endrepeat ; zero-fill .popseg
xboot/libxnes
15,569
documents/test-roms/cpu_exec_space/source/test_cpu_exec_space_ppuio.s
; Expected output, and explanation: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TEST: test_cpu_exec_space ; This program verifies that the ; CPU can execute code from any ; possible location that it can ; address, including I/O space. ; ; In addition, it will be tested ; that an RTS instruction does a ; dummy read of the byte that ; immediately follows the ; instructions. ; ; JSR+RTS TEST OK ; JMP+RTS TEST OK ; RTS+RTS TEST OK ; JMP+RTI TEST OK ; JMP+BRK TEST OK ; ; Passed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Written by Joel Yliluoma - http://iki.fi/bisqwit/ .segment "LIB" .include "shell.inc" .include "colors.inc" .segment "CODE" zp_res nmi_count zp_res brk_issued zp_res maybe_crashed .macro print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 print_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 rts .endmacro .macro my_print_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 .local Addr jsr Addr seg_data "RODATA",{Addr: print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15} .endmacro set_vram_pos: ldy PPUSTATUS sta PPUADDR ; poke high 6 bits stx PPUADDR ; poke low 8 bits rts test_failed_finish: jsr crash_proof_end ; Re-enable screen jsr console_show text_white jmp test_failed open_bus_pathological_fail: jmp test_failed_finish main: lda #0 sta brk_issued ; Operations we will be doing are: ; jsr intro text_color2 ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 2,"PPU memory access through $2007 does not work properly. (Use other tests to determine the exact problem.)" jsr console_hide jsr crash_proof_begin ; Put byte $55 at $2400 and byte $AA at $2411. lda #$24 ldx #$00 jsr set_vram_pos ldy #$55 sty PPUDATA ldx #$11 jsr set_vram_pos ldy #$AA sty PPUDATA ; Read from $2400 and $2411. lda #$24 ldx #$00 jsr set_vram_pos ldy PPUDATA ; Discard the buffered byte; load $55 into buffer. ldx #$11 jsr set_vram_pos lda PPUDATA ; Load buffer ($55); place $AA in buffer. cmp #$55 bne test_failed_finish lda PPUDATA ; Load buffer ($AA); place unknown in buffer. cmp #$AA bne test_failed_finish jsr crash_proof_end jsr console_show ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 3,"PPU open bus implementation is missing or incomplete: A write to $2003, followed by a read from $2001 should return the same value as was written." jsr wait_vbl lda #$B2 ; sufficiently random byte. sta $2003 ; OAM index, but also populates open bus eor $2001 bne open_bus_pathological_fail ; Set VRAM address ($2411). This is the address we will be reading from, if the test worked properly. jsr console_hide jsr crash_proof_begin lda #$24 ldx #$00 jsr set_vram_pos ; Now, set HALF of the other address ($2400). If the test did NOT work properly, this address will be read from. lda #$24 sta PPUADDR ; Poke the open bus again; it was wasted earlier. lda #$60 ; rts sta $2003 ; OAM index, but also populates open bus set_test 4,"The RTS at $2001 was never executed." jsr $2001 ; should fetch opcode from $2001, and do a dummy read at $2002 ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 5,"An RTS opcode should still do a dummy fetch of the next opcode. (The same goes for all one-byte opcodes, really.)" ; Poke the OTHER HALF of the address ($2411). If the RTS did a dummy read at $2002, as it should, ; this ends up being a first HALF of a dummy address. lda #$11 sta PPUADDR ; Read from PPU. lda PPUDATA ; Discard the buffered byte; load something into buffer lda PPUDATA ; eject buffer. We should have $2400 contents ($55). pha jsr crash_proof_end jsr console_show pla cmp #$55 beq passed_1 cmp #$AA ; $AA is the expected result if the dummy read was not implemented properly. beq :+ ; ; If we got neither $55 nor $AA, there is something else wrong. ; jsr print_hex ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 6,"I have no idea what happened, but the test did not work as supposed to. In any case, the problem is in the PPU." : jmp test_failed_finish passed_1: ; ********* Do the test again, this time using JMP instead of JSR print_str "JSR+RTS TEST OK",newline jsr console_hide ; Set VRAM address ($2411). This is the address we will be reading from, if the test worked properly. jsr crash_proof_begin lda #$24 ldx #$00 jsr set_vram_pos ; Now, set HALF of the other address ($2400). If the test did NOT work properly, this address will be read from. lda #$24 sta PPUADDR ; Poke the open bus again; it was wasted earlier. lda #$60 ; rts sta $2003 ; OAM index, but also populates open bus jsr do_jmp_test ; should return here! ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 8,"Okay, the test passed when JSR was used, but NOT when the opcode was JMP. How can an emulator possibly get this result? You may congratulate yourself now, for finding something that is even more unconventional than this test." ; Poke the OTHER HALF of the address ($2411). If the RTS did a dummy read at $2002, as it should, ; this ends up being a first HALF of a dummy address. lda #$11 sta PPUADDR ; Read from PPU. lda PPUDATA ; Discard the buffered byte; load something into buffer lda PPUDATA ; eject buffer. We should have $2400 contents ($55). pha jsr crash_proof_end jsr console_show pla cmp #$55 beq passed_2 cmp #$AA ; $AA is the expected result if the dummy read was not implemented properly. beq :+ ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| ; ; If we got neither $55 nor $AA, there is something else wrong. ; jsr print_hex set_test 9,"Your PPU is broken in mind-defyingly random ways." : jmp test_failed_finish do_jmp_test: ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 4,"The RTS at $2001 was never executed." jmp $2001 ; should fetch opcode from $2001, and do a dummy read at $2002 passed_2: print_str "JMP+RTS TEST OK",newline ; ********* Do the test once more, this time using RTS instead of JSR jsr console_hide ; Set VRAM address ($2411). This is the address we will be reading from, if the test worked properly. jsr crash_proof_begin lda #$24 ldx #$00 jsr set_vram_pos ; Now, set HALF of the other address ($2400). If the test did NOT work properly, this address will be read from. lda #$24 sta PPUADDR ; Poke the open bus again; it was wasted earlier. lda #$60 ; rts sta $2003 ; OAM index, but also populates open bus jsr do_rts_test ; should return here! ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 11,"The test passed when JSR was used, and when JMP was used, but NOT when RTS was used. Caught ya! Paranoia wins." ; Poke the OTHER HALF of the address ($2411). If the RTS did a dummy read at $2002, as it should, ; this ends up being a first HALF of a dummy address. lda #$11 sta PPUADDR ; Read from PPU. lda PPUDATA ; Discard the buffered byte; load something into buffer lda PPUDATA ; eject buffer. We should have $2400 contents ($55). pha jsr crash_proof_end jsr console_show pla cmp #$55 beq passed_3 cmp #$AA ; $AA is the expected result if the dummy read was not implemented properly. beq :+ ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| ; ; If we got neither $55 nor $AA, there is something else wrong. ; jsr print_hex set_test 12,"Your PPU gave up reason at the last moment." : jmp test_failed_finish do_rts_test: set_test 10,"RTS to $2001 never returned." ; This message never gets displayed. lda #$20 pha lda #$00 pha rts passed_3: print_str "RTS+RTS TEST OK",newline ; Do the second test (JMP) once more. This time, use RTI rather than RTI. ; Set VRAM address ($2411). This is the address we will be reading from, if the test worked properly. jsr console_hide jsr crash_proof_begin lda #$24 ldx #$00 jsr set_vram_pos ; Now, set HALF of the other address ($2400). If the test did NOT work properly, this address will be read from. lda #$24 sta PPUADDR ; Poke the open bus again; it was wasted earlier. lda #$40 ; rti sta $2003 ; OAM index, but also populates open bus set_test 13,"JMP to $2001 never returned." ; This message never gets displayed, either. lda #>(:+ ) pha lda #<(:+ ) pha php jmp $2001 ; should fetch opcode from $2001, and do a dummy read at $2002 : ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 14,"An RTI opcode should still do a dummy fetch of the next opcode. (The same goes for all one-byte opcodes, really.)" ; Poke the OTHER HALF of the address ($2411). If the RTI did a dummy read at $2002, as it should, ; this ends up being a first HALF of a dummy address. lda #$11 sta PPUADDR ; Read from PPU. lda PPUDATA ; Discard the buffered byte; load something into buffer lda PPUDATA ; eject buffer. We should have $2400 contents ($55). pha jsr crash_proof_end jsr console_show pla cmp #$55 beq passed_4 cmp #$AA ; $AA is the expected result if the dummy read was not implemented properly. beq :+ ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| ; ; If we got neither $55 nor $AA, there is something else wrong. ; jsr print_hex set_test 15,"An RTI opcode should not destroy the PPU. Somehow that still appears to be the case here." : jmp test_failed_finish passed_4: print_str "JMP+RTI TEST OK",newline ; ********* Do the test again, this time using BRK instead of RTS/RTI jsr console_hide jsr crash_proof_begin ; Set VRAM address ($2411). This is the address we will be reading from, if the test worked properly. lda #$24 ldx #$00 jsr set_vram_pos ; Now, set HALF of the other address ($2400). If the test did NOT work properly, this address will be read from. lda #$24 sta PPUADDR ; Poke the open bus again; it was wasted earlier. lda #$00 ; brk sta $2003 ; OAM index, but also populates open bus lda #1 sta brk_issued set_test 17,"JSR to $2001 never returned." ; This message never gets displayed, either. jmp $2001 nop nop nop nop returned_from_brk: nop nop nop nop ; should return here! ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 18,"The BRK instruction should issue an automatic fetch of the byte that follows right after the BRK. (The same goes for all one-byte opcodes, but with BRK it should be a bit more obvious than with others.)" ; Poke the OTHER HALF of the address ($2411). If the BRK did a dummy read at $2002, as it should, ; this ends up being a first HALF of a dummy address. lda #$11 sta PPUADDR ; Read from PPU. lda PPUDATA ; Discard the buffered byte; load something into buffer lda PPUDATA ; eject buffer. We should have $2400 contents ($55). pha jsr crash_proof_end jsr console_show pla cmp #$55 beq passed_5 cmp #$AA ; $AA is the expected result if the dummy read was not implemented properly. beq :+ ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| ; ; If we got neither $55 nor $AA, there is something else wrong. ; jsr print_hex set_test 19,"A BRK opcode should not destroy the PPU. Somehow that still appears to be the case here." : jmp test_failed_finish passed_5: print_str "JMP+BRK TEST OK",newline text_white jsr console_show jsr wait_vbl jmp tests_passed .pushseg .segment "RODATA" intro: text_white print_str "TEST:test_cpu_exec_space_ppuio",newline text_color1 jsr print_str_ ; 0123456789ABCDEF0123456789ABCD .byte "This program verifies that the",newline .byte "CPU can execute code from any",newline .byte "possible location that it can",newline .byte "address, including I/O space.",newline .byte newline .byte "In addition, it will be tested",newline .byte "that an RTS instruction does a",newline .byte "dummy read of the byte that",newline .byte "immediately follows the",newline .byte "instructions.",newline .byte newline,0 text_white rts .popseg ; Prospects (bleak) of improving this test: ; ; $2000 is write only (writing updates open_bus, reading returns open_bus) ; $2001 is write only (writing updates open_bus, reading returns open_bus) ; $2002 is read only (writing updates open_bus, reading UPDATES open_bus (but only for low 5 bits)) ; $2003 is write only (writing updates open_bus, reading returns open_bus) ; $2004 is read-write (writing updates open_bus, however for %4==2, bitmask=11100011. Reading is UNRELIABLE.) ; $2005 is write only (writing updates open_bus, reading returns open_bus) ; $2006 is write only (writing updates open_bus, reading returns open_bus) ; $2007 is read-write (writing updates open_bus, reading UPDATES open_bus) irq: ; Presume we got here through a BRK opcode. lda brk_issued beq spurious_irq cmp #1 beq brk_successful ; If we got a spurious IRQ, and already warned of it once, do a regular RTI rti spurious_irq: lda #2 sta brk_issued set_test 16,"IRQ occurred uncalled" jmp test_failed_finish brk_successful: jmp returned_from_brk nmi: pha lda maybe_crashed beq :+ inc nmi_count lda nmi_count cmp #4 bcc :+ jmp test_failed_finish : pla rti crash_proof_begin: lda #$FF sta nmi_count sta maybe_crashed ; Enable NMI lda #$80 sta $2000 rts crash_proof_end: ; Disable NMI lda #0 sta $2000 sta maybe_crashed rts wrong_code_executed_somewhere: pha txa pha text_white print_str "ERROR",newline text_color1 print_str "Mysteriously Landed at $" pla jsr print_hex pla jsr print_hex jsr print_newline text_color1 ; 0123456789ABCDEF0123456789ABC| print_str "CPU thinks we are at: $" pla tax pla jsr print_hex txa jsr print_hex ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 7,"A jump to $2001 should never execute code from anywhere else than $2001" jmp test_failed_finish .pushseg .segment "WRONG_CODE_8000" .repeat $6200/8, I .byt $EA lda #<( $8001+ 8*I) ldx #>( $8001+ 8*I) jsr wrong_code_executed_somewhere .endrepeat ; CODE BEGINS AT E200 .popseg
xboot/libxnes
1,856
documents/test-roms/cpu_exec_space/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
xboot/libxnes
5,516
documents/test-roms/cpu_exec_space/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_hex_nibble pla pha and #$0F jsr print_hex_nibble pla rts print_hex_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,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15 jsr print_str_ .byte str .ifnblank str2 .byte str2 .endif .ifnblank str3 .byte str3 .endif .ifnblank str4 .byte str4 .endif .ifnblank str5 .byte str5 .endif .ifnblank str6 .byte str6 .endif .ifnblank str7 .byte str7 .endif .ifnblank str8 .byte str8 .endif .ifnblank str9 .byte str9 .endif .ifnblank str10 .byte str10 .endif .ifnblank str11 .byte str11 .endif .ifnblank str12 .byte str12 .endif .ifnblank str13 .byte str13 .endif .ifnblank str14 .byte str14 .endif .ifnblank str15 .byte str15 .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 .pushseg .segment "RODATA" ; >= 60000 ? (EA60) ; >= 50000 ? (C350) ; >= 40000 ? (9C40) ; >= 30000 ? (7530) ; >= 20000 ? (4E20) ; >= 10000 ? (2710) digit10000_hi: .byte $00,$27,$4E,$75,$9C,$C3,$EA digit10000_lo: .byte $00,$10,$20,$30,$40,$50,$60 ; >= 9000 ? (2328 (hex)) ; >= 8000 ? (1F40 (hex)) ; >= 7000 ? (1B58 (hex)) ; >= 6000 ? (1770 (hex)) ; >= 5000 ? (1388 (hex)) ; >= 4000 ? (FA0 (hex)) ; >= 3000 ? (BB8 (hex)) ; >= 2000 ? (7D0 (hex)) ; >= 1000 ? (3E8 (hex)) digit1000_hi: .byte $00,$03,$07,$0B,$0F,$13,$17,$1B,$1F,$23 digit1000_lo: .byte $00,$E8,$D0,$B8,$A0,$88,$70,$58,$40,$28 ; >= 900 ? (384 (hex)) ; >= 800 ? (320 (hex)) ; >= 700 ? (2BC (hex)) ; >= 600 ? (258 (hex)) ; >= 500 ? (1F4 (hex)) ; >= 400 ? (190 (hex)) ; >= 300 ? (12C (hex)) ; >= 200 ? (C8 (hex)) ; >= 100 ? (64 (hex)) digit100_hi: .byte $00,$00,$00,$01,$01,$01,$02,$02,$03,$03 digit100_lo: .byte $00,$64,$C8,$2C,$90,$F4,$58,$BC,$20,$84 .popseg .macro dec16_comparew table_hi, table_lo .local @lt cmp table_hi,y bcc @lt bne @lt ; only test the lo-part if hi-part is equal pha txa cmp table_lo,y pla @lt: .endmacro .macro do_digit table_hi, table_lo pha ; print Y as digit; put X in A and do SEC for subtraction jsr @print_dec16_helper sbc table_lo,y tax pla sbc table_hi,y .endmacro ; Prints A:X as 2-5 digit decimal value, NO space after. ; A = high 8 bits, X = low 8 bits. print_dec16: ora #0 beq @less_than_256 ldy #6 sty print_temp_ ; TODO: Use binary search? : dec16_comparew digit10000_hi,digit10000_lo bcs @got10000 dey bne :- ;cpy print_temp_ ;beq @got10000 @cont_1000: ldy #9 : dec16_comparew digit1000_hi,digit1000_lo bcs @got1000 dey bne :- ; Y = 0. cpy print_temp_ ; zero print_temp_ = print zero-digits beq @got1000 @cont_100: ldy #9 : dec16_comparew digit100_hi,digit100_lo bcs @got100 dey bne :- cpy print_temp_ beq @got100 @got10000: do_digit digit10000_hi,digit10000_lo ; value is now 0000..9999 ldy #0 sty print_temp_ beq @cont_1000 @got1000: do_digit digit1000_hi,digit1000_lo ; value is now 000..999 ldy #0 sty print_temp_ beq @cont_100 @got100: do_digit digit100_hi,digit100_lo ; value is now 00..99 txa jmp print_dec_00_99 @less_than_256: txa jmp print_dec @print_dec16_helper: tya jsr print_digit txa sec rts ; Prints A as 2-3 digit decimal value, NO space after. ; Preserved: Y print_dec: ; Hundreds cmp #10 blt print_digit cmp #100 blt print_dec_00_99 ldx #'0'-1 : inx sbc #100 bge :- adc #100 jsr print_char_x ; Tens print_dec_00_99: sec ldx #'0'-1 : inx sbc #10 bge :- adc #10 jsr print_char_x ; Ones print_digit: ora #'0' jmp print_char ; Print a single digit print_char_x: 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
xboot/libxnes
1,593
documents/test-roms/cpu_exec_space/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&$FFFF,-1&$FFFF,-1&$FFFF, 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_3.chr" ;.align $200 .incbin "ascii_2.chr" ;.align $200 .incbin "ascii_1.chr" .res $E00 .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 .align 256
xboot/libxnes
4,298
documents/test-roms/cpu_exec_space/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 zp_byte text_color bss_res console_buf,console_buf_size ; Initializes console console_init: ; Flag that console hasn't been initialized setb console_scroll,-1&$FF lda #0 sta text_color jmp console_clear_line_ ; Hides console by blacking palette and disabling PPU. ; Preserved: A, X, Y console_hide: pha txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,0 lda #$0F tax tay jsr console_load_palette_ pla tay pla tax pla rts console_wait_vbl_: lda console_scroll cmp #-1&$FF 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 #$E0 ;sta text_color lda #0 : 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 txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ ; Shows console display ; Preserved: X, Y console_show_nowait: pha txa pha tay pha setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ console_load_palette_: pha setb PPUADDR,$3F setb PPUADDR,$00 setb PPUDATA,$0F ; black pla sta PPUDATA stx PPUDATA sty 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 clc adc text_color 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 #0 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
xboot/libxnes
1,096
documents/test-roms/cpu_exec_space/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
xboot/libxnes
2,024
documents/test-roms/cpu_exec_space/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
xboot/libxnes
4,660
documents/test-roms/cpu_exec_space/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_nametable2 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
xboot/libxnes
3,445
documents/test-roms/cpu_exec_space/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&$FF 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&$FF 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
xboot/libxnes
1,632
documents/test-roms/cpu_exec_space/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
xboot/libxnes
1,881
documents/test-roms/cpu_interrupts_v2/source/3-nmi_and_irq.s
; NMI behavior when it interrupts IRQ vectoring. ; ; Result when run: ; NMI IRQ ; 23 00 NMI occurs before LDA #1 ; 21 00 NMI occurs after LDA #1 (Z flag clear) ; 21 00 ; 20 00 NMI occurs after CLC, interrupting IRQ ; 20 00 ; 20 00 ; 20 00 ; 20 00 ; 20 00 ; 20 00 Same result for 7 clocks before IRQ is vectored ; 25 20 IRQ occurs, then NMI occurs after SEC in IRQ handler ; 25 20 CUSTOM_IRQ=1 CUSTOM_NMI=1 .include "shell.inc" .include "sync_vbl.s" zp_byte irq_flag ; IRQ sets this to saved flags on stack zp_byte irq_temp zp_byte nmi_flag ; NMI sets this to saved flags on stack zp_byte nmi_temp nmi: ; 7 sta <nmi_temp ; 3 pla ; 4 pha ; 3 sta <nmi_flag ; 3 lda <nmi_temp ; 3 lda <nmi_temp ; 3 to keep clock count even bit SNDCHN ; 4 rti ; 6 irq: sec sta <irq_temp pla pha sta <irq_flag lda <irq_temp bit SNDCHN rti test: ; Run test code, with decreasing delay after ; after synchronizing with NMI, causing NMI ; to occur later each time. eor #$FF clc adc #1+12 jsr sync_vbl jsr delay_a_25_clocks delay 29678 ; Reset APU frame sequencer and enable IRQ lda #0 sta SNDMODE delay 29805 ; Enable NMI and IRQ lda #PPUCTRL_NMI sta PPUCTRL lda SNDCHN ; clear IRQ cli ; Clear interrupt flags lda #0 sta nmi_flag sta irq_flag clv sec ; Z and C set, others clear ; NMI occurs here first, lda #1 ; clear Z flag ; then here for two clocks, clc ; clear C flag ; then here. ; IRQ always occurs here. nop ; Read interrupt flags ldx nmi_flag ldy irq_flag ; Disable interrupts sei setb PPUCTRL,0 ; Print result jsr print_x jsr print_space jsr print_y jsr print_newline rts main: jsr console_hide print_str {"NMI BRK",newline} jsr reset_crc loop_n_times test,12 check_crc $B7B2ED22 jmp tests_passed
xboot/libxnes
1,373
documents/test-roms/cpu_interrupts_v2/source/4-irq_and_dma.s
; Has IRQ occur at various times around sprite DMA. ; First column refers to what instruction IRQ occurred ; after. Second column is time of IRQ, in CPU clocks relative ; to some arbitrary starting point. ; ; 0 +0 ; 1 +1 ; 1 +2 ; 2 +3 ; 2 +4 ; 4 +5 ; 4 +6 ; 7 +7 ; 7 +8 ; 7 +9 ; 7 +10 ; 8 +11 ; 8 +12 ; 8 +13 ; ... ; 8 +524 ; 8 +525 ; 8 +526 ; 9 +527 CUSTOM_IRQ=1 .include "shell.inc" .include "sync_apu.s" irq: bit SNDCHN rti begin: jsr sync_apu lda #0 sta SNDMODE cli delay 29273 lda #0 rts end: tsx dex lda #$80 sta $100,x landing: ; second column refers to these: nop ; 0 nop ; 1 lda #$07 ; 2 sta SPRDMA ; 4 nop ; 7 nop ; 8 nop ; 9 sei lda $100,x sec sbc #<landing jsr print_dec rts .macro test dly jsr begin delay 532-(dly) jsr end print_str {" +",.string(dly),newline} .endmacro main: test 0 test 1 test 2 test 3 test 4 test 5 test 6 test 7 test 8 test 9 test 10 test 11 test 12 test 13 print_str "...",newline test 512+12 test 512+13 test 512+14 test 512+15 check_crc $43571959 jmp tests_passed
xboot/libxnes
1,790
documents/test-roms/cpu_interrupts_v2/source/2-nmi_and_brk.s
; NMI behavior when it interrupts BRK. Occasionally fails on ; NES due to PPU-CPU synchronization. ; ; Result when run: ; NMI BRK -- ; 27 36 00 NMI before CLC ; 26 36 00 NMI after CLC ; 26 36 00 ; 36 00 00 NMI interrupting BRK, with B bit set on stack ; 36 00 00 ; 36 00 00 ; 36 00 00 ; 36 00 00 ; 27 36 00 NMI after SEC at beginning of IRQ handler ; 27 36 00 CUSTOM_IRQ=1 CUSTOM_NMI=1 .include "shell.inc" .include "sync_vbl.s" zp_byte irq_flag ; IRQ sets this to saved flags on stack zp_byte irq_temp zp_byte nmi_flag ; NMI sets this to saved flags on stack zp_byte nmi_temp nmi: ; 7 sta <nmi_temp ; 3 pla ; 4 pha ; 3 sta <nmi_flag ; 3 lda <nmi_temp ; 3 lda <nmi_temp ; 3 to keep clock count even bit SNDCHN ; 4 rti ; 6 irq: sec sta <irq_temp pla pha sta <irq_flag lda <irq_temp rti test: ; Run test with variable delay after NMI sync eor #$FF clc adc #1+10 pha jsr sync_vbl setb PPUCTRL,PPUCTRL_NMI pla jsr delay_a_25_clocks delay 29709 ; Clear flags clv sec ldx #0 stx nmi_flag stx irq_flag nop nop ; NMI occurs here on first clock, clc ; here for second two clocks, ; BRK that might get ignored brk inx ; BRK skips byte after it ; interrupts BRK for 5 clocks, ; and occurs after SEC in BRK handler for last 2 clocks. sec nop nop ; Get flags after test lda nmi_flag ldy irq_flag ; Disable NMI and IRQ pha sei lda #0 sta PPUCTRL pla ; Print result ora #$02 jsr print_a jsr print_space jsr print_y jsr print_space jsr print_x ; should be 0 jsr print_newline rts main: jsr console_hide print_str {"NMI BRK 00",newline} jsr reset_crc loop_n_times test,10 check_crc $B0D44BB7 jmp tests_passed
xboot/libxnes
2,787
documents/test-roms/cpu_interrupts_v2/source/5-branch_delays_irq.s
; A taken non-page-crossing branch ignores IRQ during ; its last clock, so that next instruction executes ; before the IRQ. Other instructions would execute the ; NMI before the next instruction. ; ; The same occurs for NMI, though that's not tested here. ; ; test_jmp ; T+ CK PC ; 00 02 04 NOP ; 01 01 04 ; 02 03 07 JMP ; 03 02 07 ; 04 01 07 ; 05 02 08 NOP ; 06 01 08 ; 07 03 08 JMP ; 08 02 08 ; 09 01 08 ; ; test_branch_not_taken ; T+ CK PC ; 00 02 04 CLC ; 01 01 04 ; 02 02 06 BCS ; 03 01 06 ; 04 02 07 NOP ; 05 01 07 ; 06 04 0A JMP ; 07 03 0A ; 08 02 0A ; 09 01 0A JMP ; ; test_branch_taken_pagecross ; T+ CK PC ; 00 02 0D CLC ; 01 01 0D ; 02 04 00 BCC ; 03 03 00 ; 04 02 00 ; 05 01 00 ; 06 04 03 LDA $100 ; 07 03 03 ; 08 02 03 ; 09 01 03 ; ; test_branch_taken ; T+ CK PC ; 00 02 04 CLC ; 01 01 04 ; 02 03 07 BCC ; 03 02 07 ; 04 05 0A LDA $100 *** This is the special case ; 05 04 0A ; 06 03 0A ; 07 02 0A ; 08 01 0A ; 09 03 0A JMP CUSTOM_IRQ = 1 .include "shell.inc" .include "sync_apu.s" .macro test routine,crc print_str .string( routine ),newline print_str "T+ CK PC",newline loop_n_times routine,10 jsr print_newline check_crc crc .endmacro main: test test_jmp,$2A43A4DA test test_branch_not_taken,$4D5A50A1 test test_branch_taken_pagecross,$DD60A954 test test_branch_taken,$B04DD9FC ;test test_branch_taken_to_jmp,$5E75AD67 ;test test_lda_abs,$48539E4E ;test test_lda_abs_ind_nocross,$96CF0268 ;test test_lda_abs_ind_cross,$A7C944D1 jmp tests_passed zp_byte saved_s begin: jsr print_a tsx stx saved_s pha jsr sync_apu setb $4017,$40 setb $4017,0 bit $4015 cli pla eor #$0F jsr delay_a_25_clocks delay 29788-15 rts .align 16 test_jmp: jsr begin nop ; 04 jmp :+ ; 07 : nop ; 08 : jmp :- .align 16 test_branch_not_taken: jsr begin clc ; 04 bcs :+ ; 06 nop ; 07 : lda $100 ; 0A : jmp :- .align 256 .res 256-7 test_branch_taken_pagecross: jsr begin clc ; 0D bcc :+ ; 0F nop ; 00 : lda $100 ; 03 : jmp :- .align 16 test_branch_taken: jsr begin clc ; 04 bcc :+ ; 06 nop ; 07 : lda $100 ; 0A : jmp :- ; Some other tests I also did .align 16 test_branch_taken_to_jmp: jsr begin clc ; 04 bcc :+ ; 06 nop ; 07 : jmp :- .align 16 test_lda_abs: jsr begin nop ; 04 lda $100 ; 07 nop ; 08 : jmp :- .align 16 test_lda_abs_ind_nocross: jsr begin ldx #0 ; 05 lda $100,x ; 08 nop ; 09 : jmp :- .align 16 test_lda_abs_ind_cross: jsr begin ldx #1 ; 05 lda $1FF,x ; 08 nop ; 09 : jmp :- .align 64 irq: delay 29830-9-6 + 2 ldx #7 : dex delay 29831 - 13 bit $4015 bit $4015 bvc :- jsr print_x pla pla and #$0F jsr print_a jsr print_newline ldx saved_s inx inx txs rts
xboot/libxnes
3,807
documents/test-roms/cpu_interrupts_v2/source/1-cli_latency.s
; Tests the delay in CLI taking effect, and some basic aspects of IRQ ; handling and the APU frame IRQ (needed by the tests). It uses the APU's ; frame IRQ and first verifies that it works well enough for the tests. ; ; The later tests execute CLI followed by SEI and equivalent pairs of ; instructions (CLI, PLP, where the PLP sets the I flag). These should ; only allow at most one invocation of the IRQ handler, even if it doesn't ; acknowledge the source of the IRQ. RTI is also tested, which behaves ; differently. These tests also *don't* disable interrupts after the first ; IRQ, in order to test whether a pair of instructions allows only one ; interrupt or causes continuous interrupts that block the main code from ; continuing. CUSTOM_IRQ=1 .include "shell.inc" zp_byte irq_count zp_byte irq_flags zp_res irq_addr,2 zp_byte irq_data begin_test: sei lda #0 sta irq_count sta irq_flags sta irq_addr sta irq_addr + 1 rts irq: sta irq_data pla ; save status flags and return addr from stack sta irq_flags pla sta irq_addr pla sta irq_addr + 1 pha ; restore return addr and status flags on stack lda irq_addr pha lda irq_flags pha inc irq_count bpl :+ pla ora #$04 ; set I flag in saved status to disable IRQ pha : lda irq_data rti ; Reports error if none or more than one interrupt occurred, ; or if return address within handler doesn't match YX. end_test: sei nop cmp irq_count jne test_failed cpx irq_addr jne test_failed cpy irq_addr + 1 jne test_failed rts .align 256 main: setb SNDMODE,0 delay_msec 40 ; APU frame IRQ should be active by now set_test 2,"RTI should not adjust return address (as RTS does)" lda #>addr2 pha lda #<addr2 pha php ldx #0 rti inx inx addr2: inx inx cpx #2 jne test_failed set_test 3,"APU should generate IRQ when $4017 = $00" jsr begin_test lda #$80 ; have IRQ handler set I flag after first invocation sta irq_count cli ldy #0 : dey bne :- sei nop lda irq_count cmp #$81 jne test_failed set_test 4,"Exactly one instruction after CLI should execute before IRQ is taken" jsr begin_test lda #$80 ; have IRQ handler set I flag after first invocation sta irq_count cli nop irq3: ldx #<irq3 ldy #>irq3 lda #$81 jsr end_test set_test 5,"CLI SEI should allow only one IRQ just after SEI" jsr begin_test lda #$80 ; have IRQ handler set I flag after first invocation sta irq_count cli sei irq4: ldx #<irq4 ldy #>irq4 lda #$81 jsr end_test set_test 6,"In IRQ allowed by CLI SEI, I flag should be set in saved status flags" jsr begin_test cli sei nop nop lda irq_flags and #$04 jeq test_failed set_test 7,"CLI PLP should allow only one IRQ just after PLP" jsr begin_test php cli plp irq5: ldx #<irq5 ldy #>irq5 lda #1 jsr end_test set_test 8,"PLP SEI should allow only one IRQ just after SEI" jsr begin_test lda #0 pha plp sei irq6: ldx #<irq6 ldy #>irq6 lda #1 jsr end_test set_test 9,"PLP PLP should allow only one IRQ just after PLP" jsr begin_test php lda #0 pha plp plp irq7: ldx #<irq7 ldy #>irq7 lda #1 jsr end_test set_test 10,"CLI RTI should not allow any IRQs" jsr begin_test lda #>rti1 pha lda #<rti1 pha php cli rti rti1: nop nop lda irq_count jne test_failed set_test 11,"Unacknowledged IRQ shouldn't let any mainline code run" jsr begin_test cli nop ; IRQ should keep firing here until counter reaches $80 nop lda irq_count cmp #$80 jne test_failed set_test 12,"RTI RTI shouldn't let any mainline code run" jsr begin_test lda #>rti3 pha lda #<rti3 pha php lda #>rti2 pha lda #<rti2 pha lda #0 pha rti rti2: rti rti3: nop lda irq_count cmp #$80 jne test_failed jmp tests_passed
xboot/libxnes
1,227
documents/test-roms/cpu_interrupts_v2/source/4-nmi_and_dma.s
; Has IRQ occur at various times around sprite DMA. ; First column refers to what instruction IRQ occurred ; after. Second column is time of IRQ, in CPU clocks relative ; to some arbitrary starting point. CUSTOM_IRQ=1 .include "shell.inc" .include "sync_apu.s" irq: bit SNDCHN rti begin: jsr sync_apu lda #0 sta SNDMODE cli delay 29273 lda #0 rts end: tsx dex lda #$80 sta $100,x landing: ; second column refers to these: nop ; 0 nop ; 1 lda #$07 ; 2 sta SPRDMA ; 4 nop ; 7 nop ; 8 nop ; 9 sei lda $100,x sec sbc #<landing jsr print_dec rts .macro test dly jsr begin delay 532-(dly) jsr end print_str {" +",.string(dly),newline} .endmacro main: test 0 test 1 test 2 test 3 test 4 test 5 test 6 test 7 test 8 test 9 test 10 test 11 test 12 test 13 print_str "...",newline test 512+12 test 512+13 test 512+14 test 512+15 check_crc $43571959 jmp tests_passed
xboot/libxnes
1,852
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
3,229
documents/test-roms/cpu_interrupts_v2/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 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
xboot/libxnes
3,104
documents/test-roms/cpu_interrupts_v2/source/common/shell_misc.s
; Reports internal error and exits program internal_error: init_cpu_regs 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
xboot/libxnes
1,483
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
5,404
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
1,096
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
3,060
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
2,729
documents/test-roms/cpu_interrupts_v2/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 .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
xboot/libxnes
3,713
documents/test-roms/cpu_interrupts_v2/source/common/sync_vbl.s
; Synchronizes EXACTLY to VBL, to accuracy of 1/3 CPU clock ; (1/2 CPU clock if PPU is enabled). Reading PPUSTATUS ; 29768 clocks or later after return will have bit 7 set. ; Reading PPUSTATUS immediately will have bit 7 clear. ; Preserved: A, X, Y ; Time: 120-330 msec .align 128 sync_vbl: pha ; Disable interrupts sei lda #0 sta PPUCTRL ; Coarse synchronize bit $2002 : bit $2002 bpl :- delay 29771 ; Divide possible cases into two groups, and optimize ; for each, halving time this routine takes. bit $2002 bmi :+ delay 4 ; max=4, lower=slower : delay 24 ; max=24, lower=slower ; Synchronize precisely to VBL. VBL occurs every 29780.67 ; CPU clocks. Loop takes 27 clocks. Every 1103 iterations, ; the second LDA $2002 will read exactly 29781 clocks ; after a previous read. Thus, the loop will effectively ; read $2002 one PPU clock later each frame. It starts out ; with VBL beginning sometime after this read, so that ; eventually VBL will begin just before the $2002 read, ; and thus leave CPU exactly synchronized to VBL. : delay 27 - 11 bit $2002 bit $2002 bpl :- pla rts ; Same as sync_vbl, but additionally ensures that next frame ; will skip PPU clock at end of VBL if rendering is enabled. ; Preserved: A, X, Y sync_vbl_odd: pha ; Rendering must be disabled jsr wait_vbl lda #0 sta PPUMASK jsr sync_vbl jsr @render_frame ; See whether frame was short ; If not, frames totaled 59561+1/3 CPU clocks delay 29781-17-1 lda PPUSTATUS bmi :+ jmp @end : ; If frame was short, first frame was ; one clock shorter. Wait another frame to ; toggle even/odd flag. Rendering enabled ; for frame so total of all three frames ; is 89341+1/3 CPU clocks, which has the ; same fraction as the other case, thus ; ensuring the same CPU-PPU synchronization. jsr @render_frame @end: ; Establish same timing as sync_vbl delay 29781-7 ; Be sure VBL flag is clear for this frame, as the ; other sync routines do. bit PPUSTATUS pla rts @render_frame: lda #PPUMASK_BG0 sta PPUMASK delay 29781-6-6-6-6+1 lda #0 sta PPUMASK rts ; Same as sync_vbl_odd, but next frame will NOT skip PPU clock ; Preserved: A, X, Y sync_vbl_even: jsr sync_vbl_odd delay 341*262*3 / 3 - 10; get to even frame without affecting sync ; Be sure VBL flag is clear for this frame, as the ; other sync routines do. bit PPUSTATUS rts ; Same as sync_vbl_even, but also writes A to SPRDMA without ; affecting timing (in particular, SPRDMA's optional extra clock ; is dealt with). ; Preserved: A, X, Y sync_vbl_even_dma: jsr sync_vbl_odd delay 341*262 - 534 sta SPRDMA bit PPUSTATUS ; Delay extra clock if ncessary. Unaffected by code ; alignment since it branches to next instr. bpl :+ : ; Be sure VBL flag is clear for this frame, as the ; other sync routines do. bit PPUSTATUS rts ; Same as sync_vbl, but then delays A additional PPU clocks. ; Preserved: X, Y .align 32 sync_vbl_delay: jsr sync_vbl ; VBL occurs every 29780.67 clocks, therefore ; each iteration of the loop is like delaying ; 1/3 CPU clock (1 PPU clock). : delay 29781-7 clc adc #-1 bcs :- delay 29781*2-10 ; Be sure VBL flag is clear for this frame, as the ; other sync routines do. bit PPUSTATUS rts ; Effectively delays n PPU clocks, while maintaing ; even/odd frame (i.e. never delays an odd number of ; frames). PPU rendering must be off. ; Preserved: A, X, Y .macro delay_ppu_even n .if (n) < 8 .error "time out of range" .endif .if (n) .MOD 3 = 1 .if (n) > 4 delay (n)/3-1 .endif delay 29781*4 .elseif (n) .MOD 3 = 2 delay (n)/3 delay 29781*2 .else delay (n)/3 .endif .endmacro
xboot/libxnes
3,437
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
1,632
documents/test-roms/cpu_interrupts_v2/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
xboot/libxnes
9,413
documents/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
xboot/libxnes
2,026
documents/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
xboot/libxnes
6,765
documents/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
xboot/libxnes
7,092
documents/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
xboot/libxnes
6,300
documents/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
xboot/libxnes
1,282
documents/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
xboot/libxnes
2,384
documents/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
xboot/libxnes
1,538
documents/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
xboot/libxnes
1,497
documents/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
xboot/libxnes
1,552
documents/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
xboot/libxnes
1,313
documents/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
xboot/libxnes
1,128
documents/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
xboot/libxnes
1,228
documents/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
xboot/libxnes
1,350
documents/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
xboot/libxnes
1,873
documents/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
xboot/libxnes
1,875
documents/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
xboot/libxnes
3,234
documents/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
xboot/libxnes
5,224
documents/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
xboot/libxnes
3,456
documents/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
xboot/libxnes
2,088
documents/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
xboot/libxnes
5,438
documents/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
xboot/libxnes
1,096
documents/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
xboot/libxnes
3,100
documents/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
xboot/libxnes
2,752
documents/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
xboot/libxnes
3,734
documents/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
xboot/libxnes
2,410
documents/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
xboot/libxnes
1,600
documents/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
xboot/libxnes
2,037
documents/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
xboot/libxnes
1,931
documents/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
xboot/libxnes
1,856
documents/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
xboot/libxnes
2,660
documents/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
xboot/libxnes
1,491
documents/test-roms/instr_misc/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 .align 256
xboot/libxnes
5,523
documents/test-roms/instr_misc/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. .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: 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
xboot/libxnes
1,096
documents/test-roms/instr_misc/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
xboot/libxnes
2,024
documents/test-roms/instr_misc/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
xboot/libxnes
4,658
documents/test-roms/instr_misc/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_nametable2 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
xboot/libxnes
3,437
documents/test-roms/instr_misc/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
xboot/libxnes
1,632
documents/test-roms/instr_misc/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
xboot/libxnes
16,115
documents/test-roms/cpu_dummy_writes/source/cpu_dummy_writes_oam.s
; All read-modify-write-instructions on 6502 have a particular glitch: ; They first write back the unmodified value; then, the modified value. ; This test uses the PPU OAM write ($2004) autoincrement feature to ; verify that the CPU does that. ; ; Expected output: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TEST: cpu_dummy_writes_oam ; This program verifies that the ; CPU does 2x writes properly. ; Any read-modify-write opcode ; should first write the origi- ; nal value; then the calculated ; value exactly 1 cycle later. ; ; Requirement: OAM memory reads ; MUST be reliable. This is ; often the case on emulators, ; but NOT on the real NES. ; Nevertheless, this test can be ; used to see if the CPU in the ; emulator is built properly. ; ; Testing OAM. The screen will go blank for a moment now. ; OK; Verifying opcodes... ; 0E2E4E6ECEEE 1E3E5E7EDEFE ; 0F2F4F6FCFEF 1F3F5F7FDFFF ; 03234363C3E3 13335373D3F3 ; 1B3B5B7BDBFB ; ; Passed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Written by Joel Yliluoma - http://iki.fi/bisqwit/ .segment "LIB" .include "shell.inc" .include "colors.inc" .include "crc_fast.s" .segment "CODE" ;OFFICIAL_ONLY = 0 zp_res testflag02 zp_res pointer, 2 zp_res num_failed_oam_reads, 2 zp_res oam_read_test_failed zp_res opcode_ptr, 2 zp_res opcode_buffer, 8 zp_res temp_x zp_res temp_oam_data, 3 zp_res temp_read_result zp_res x_position zp_res ptr_2004, 2 zp_res num_fails zp_res num_fails_2, 2 .macro test_at where, value setb SPRADDR,where lda SPRDATA cmp #value .endmacro test_failed_finish: ; Re-enable screen jsr console_show jmp test_failed main: jsr intro lda #0 sta oam_read_test_failed jsr oam_read_test text_white lda num_failed_oam_reads ora num_failed_oam_reads+1 bne @first_test_not_ok print_str "OK; " jmp @first_test_ok @first_test_not_ok: text_color1 print_str "FAIL. " ldx num_failed_oam_reads lda num_failed_oam_reads+1 jsr print_dec16 print_str " FAILED READS.",newline ; We will continue tests, but note for later use that ; this test failed. lda #1 sta oam_read_test_failed @first_test_ok: jsr test_rom_write jsr test_oam_access_functions ; Then do the actual test! ; jsr test_dummy_writes ; lda num_fails_2 ora num_fails_2+1 beq :+ jsr wait_vbl text_color1 ldx num_fails_2 lda num_fails_2+1 jsr print_dec16 print_str " OPCODES FAILED THE TEST",newline text_white lda oam_read_test_failed bne @opcode_test_failed_because_oam_problems jmp test_failed_finish @opcode_test_failed_because_oam_problems: print_str "Probably because" jmp test_2_failed : ; Now, when the dummy-write tests have been done (and passed), ; verify whether we failed the open bus test earlier. ; If it failed, do not give a clean exit status. lda oam_read_test_failed beq end_tests jsr wait_vbl print_str "Opcodes worked fine, but..." set_test 6,"OAM reads are unreliable." jmp test_failed_finish end_tests: jsr console_show jsr wait_vbl jmp tests_passed test_oam_access_functions: set_test 3,"Writes to OAM should automatically increment SPRADDR" jsr spr_reset ; Poke OAM in automatically increasing address delay 2 setb SPRADDR,$00 ; redundant delay 2 setb SPRDATA,$01 ; put $01 in OAM[0] setb SPRDATA,$02 ; put $02 in OAM[1] ; OAM[2] is kept as $E3 ; Verify that the second access was properly recorded ldx #$01 ldy #$02 ; read from OAM[0] and OAM[1] delay 2 setb SPRADDR,$00 delay 2 lda SPRDATA sta testflag02 cpx testflag02 bne test_3_failed delay 2 setb SPRADDR,$01 delay 2 lda SPRDATA sta testflag02 cpy testflag02 bne test_3_failed ; ; Verify that OAMaddr does not automatically increment delay 2 lda SPRDATA ; should read from OAM[1], not OAM[2] pha set_test 4,"Reads from OAM should not automatically increment SPRADDR" pla cmp #$02 ; expected result is $02 bne test_3_or_4_failed rts test_3_or_4_failed: jmp test_failed_finish test_3_failed: lda oam_read_test_failed beq test_3_or_4_failed ; 0123456789ABCDEF0123456789ABC| text_white print_str "A test for writes to OAM and",newline print_str "automatic SPRADDR increments",newline print_str "failed, but the test probably",newline print_str "was not meaningful in the",newline print_str "first place, because" test_2_failed: text_white set_test 2,"OAM reading is too unreliable." jmp test_failed spr_reset: ; Disable rendering jsr wait_vbl ; Poke OAM in explicitly set addresses setb SPRADDR,$00 ldx #$55 delay 2 stx SPRDATA delay 2 setb SPRADDR,$01 ldy #$B7 delay 2 sty SPRDATA delay 2 setb SPRADDR,$02 delay 2 setb SPRDATA,$E3 delay 2 setb SPRADDR,$00 delay 2 rts oam_read_test: text_white ; 0123456789ABCDEF0123456789ABC| print_str "Testing OAM. The screen will go blank for a moment now.",newline jsr init_crc_fast ; This test copied verbatim from oam_read ; ; Disable rendering jsr wait_vbl setb PPUCTRL,0 setb PPUMASK,0 ldx #0 ldy #15 stx num_failed_oam_reads @loop: ; Set address and read from OAM jsr next_random tax stx SPRADDR jsr next_random and #$E3 ; Set address and write complement stx SPRADDR sta SPRDATA pha ; Write 7 extra bytes, necessary ; to trigger failure in some cases. jsr next_random and #$E3 sta SPRDATA jsr next_random and #$E3 sta SPRDATA jsr next_random and #$E3 sta SPRDATA ; Write in some unrelated OAM index txa clc adc #$C7 sta SPRADDR jsr next_random and #$E3 sta SPRDATA jsr next_random and #$E3 sta SPRDATA jsr next_random and #$E3 sta SPRDATA jsr next_random and #$E3 sta SPRDATA ; Set address and log whether read ; back was correct stx SPRADDR ; Load something into open bus lda $2007 pla eor SPRDATA beq :+ inc num_failed_oam_reads bne :+ inc num_failed_oam_reads+1 : inx bne @loop dey bne @loop .pushseg .segment "RODATA" intro: text_white print_str "TEST: cpu_dummy_writes_oam",newline text_color1 jsr print_str_ ; 0123456789ABCDEF0123456789ABCD .byte "This program verifies that the",newline .byte "CPU does 2x writes properly.",newline .byte "Any read-modify-write opcode",newline .byte "should first write the origi-",newline .byte "nal value; then the calculated",newline .byte "value exactly 1 cycle later.",newline .byte newline .byte "Requirement: OAM memory reads",newline .byte "MUST be reliable. This is",newline .byte "often the case on emulators,",newline .byte "but NOT on the real NES.",newline .byte "Nevertheless, this test can be",newline .byte "used to see if the CPU in the",newline .byte "emulator is built properly.",newline .byte newline,0 text_white rts .popseg init_random: jsr init_crc_fast lda #1 jsr update_crc_fast rts next_random: lda #$55 jmp update_crc_fast .pushseg .segment "RODATA" Opcodes: ; Opcodes to test: ; * 0E (RMW) ASL abs U 0F (RMW) SLO abs (ASL+ORA) ; * 2E (RMW) ROL abs U 2F (RMW) RLA abs (ROL+AND) ; * 4E (RMW) LSR abs U 4F (RMW) SRE abs (LSR+EOR) ; * 6E (RMW) ROR abs U 6F (RMW) RRA abs (ROR+ADC) ; * CE (RMW) DEC abs U CF (RMW) DCP abs (DEC+CMP) ; * EE (RMW) INC abs U EF (RMW) ISB abs (INC+SBC) ; ; * 1E (RMW) ASL absx U 1F (RMW) SLO absx (ASL+ORA) U 1B (RMW) SLO absy (ASL+ORA) ; * 3E (RMW) ROL absx U 3F (RMW) RLA absx (ROL+AND) U 3B (RMW) RLA absy (ROL+AND) ; * 5E (RMW) LSR absx U 5F (RMW) SRE absx (LSR+EOR) U 5B (RMW) SRE absy (LSR+EOR) ; * 7E (RMW) ROR absx U 7F (RMW) RRA absx (ROR+ADC) U 7B (RMW) RRA absy (ROR+ADC) ; * DE (RMW) DEC absx U DF (RMW) DCP absx (DEC+CMP) U DB (RMW) DCP absy (DEC+CMP) ; * FE (RMW) INC absx U FF (RMW) ISB absx (INC+SBC) U FB (RMW) ISB absy (INC+SBC) ; ; K 12 (RMW) ASL ix U 03 (RMW) SLO ix (ASL+ORA) U 13 (RMW) SLO iy (ASL+ORA) ; K 32 (RMW) ROL ix U 23 (RMW) RLA ix (ROL+AND) U 33 (RMW) RLA iy (ROL+AND) ; K 52 (RMW) LSR ix U 43 (RMW) SRE ix (LSR+EOR) U 53 (RMW) SRE iy (LSR+EOR) ; K 72 (RMW) ROR ix U 63 (RMW) RRA ix (ROR+ADC) U 73 (RMW) RRA iy (ROR+ADC) ; K D2 (RMW) DEC ix U C3 (RMW) DCP ix (DEC+CMP) U D3 (RMW) DCP iy (DEC+CMP) ; K F2 (RMW) INC ix U E3 (RMW) ISB ix (INC+SBC) U F3 (RMW) ISB iy (INC+SBC) ; ; Format: Opcode number ($00 for end, $01 for newline, $02 for space) ; Value for absolute address (appended to opcode) (BIG-ENDIAN) ; Value for X ; Values for OAM[0],OAM[1],OAM[2] before test ; Expected OAM[1] after opcode; with Carry Set, Carry Clear (two bytes) ; OAM[0] and OAM[2] are expected to be unmodified (and thus tested). ; Each opcode will be tried twice. Once with carry clear, once with carry set ; opcode ABS X OAM0,1,2 READ1 READ2 ; OFFICIAL OPCODES .byte $0E, $20,$04, $00, $25,$B7,$E3, $4A, $4A ; ASL,254A .byte $2E, $20,$04, $00, $25,$B7,$E3, $4A, $4B ; ROL,254A or 254B .byte $4E, $20,$04, $00, $25,$B7,$E3, $12, $12 ; LSR,2512 .byte $6E, $20,$04, $00, $25,$B7,$E3, $12, $92 ; ROR,2512 or $2592 .byte $CE, $20,$04, $00, $25,$B7,$E3, $24, $24 ; DEC,2524 .byte $EE, $20,$04, $00, $25,$B7,$E3, $26, $26 ; INC,2526 .byte $02 ; .byte $1E, $20,$03, $01, $26,$B7,$E3, $4C, $4C ; ASL,$264C .byte $3E, $20,$00, $04, $26,$B7,$E3, $4C, $4D ; ROL,$264C or $264D .byte $5E, $20,$04, $00, $26,$B7,$E3, $13, $13 ; LSR,$2613 .byte $7E, $20,$02, $02, $26,$B7,$E3, $13, $93 ; ROR,$2613 or $2693 .byte $DE, $20,$04, $00, $26,$B7,$E3, $25, $25 ; DEC,$2625 .byte $FE, $20,$03, $01, $26,$B7,$E3, $27, $27 ; INC,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $0F, $20,$04, $00, $25,$B7,$E3, $4A, $4A ; SLO,254A .byte $2F, $20,$04, $00, $25,$B7,$E3, $4A, $4B ; RLA,254A or 254B .byte $4F, $20,$04, $00, $25,$B7,$E3, $12, $12 ; SRE,2512 .byte $6F, $20,$04, $00, $25,$B7,$E3, $12, $92 ; RRA,2512 or $2592 .byte $CF, $20,$04, $00, $25,$B7,$E3, $24, $24 ; DCP,2524 .byte $EF, $20,$04, $00, $25,$B7,$E3, $26, $26 ; ISB,2526 ; .byte $02 ; .byte $1F, $20,$03, $01, $26,$B7,$E3, $4C, $4C ; SLO,$264C .byte $3F, $20,$00, $04, $26,$B7,$E3, $4C, $4D ; RLA,$264C or $264D .byte $5F, $20,$04, $00, $26,$B7,$E3, $13, $13 ; SRE,$2613 .byte $7F, $20,$02, $02, $26,$B7,$E3, $13, $93 ; RRA,$2613 or $2693 .byte $DF, $20,$04, $00, $26,$B7,$E3, $25, $25 ; DCP,$2625 .byte $FF, $20,$03, $01, $26,$B7,$E3, $27, $27 ; ISB,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $03, $EA,<ptr_2004, $00, $25,$B7,$E3, $4A, $4A ; SLO,254A .byte $23, $EA,<ptr_2004, $00, $25,$B7,$E3, $4A, $4B ; RLA,254A or 254B .byte $43, $EA,<ptr_2004, $00, $25,$B7,$E3, $12, $12 ; SRE,2512 .byte $63, $EA,<ptr_2004, $00, $25,$B7,$E3, $12, $92 ; RRA,2512 or $2592 .byte $C3, $EA,<ptr_2004, $00, $25,$B7,$E3, $24, $24 ; DCP,2524 .byte $E3, $EA,<ptr_2004, $00, $25,$B7,$E3, $26, $26 ; ISB,2526 ; .byte $02 ; .byte $13, $EA,<ptr_2004, $00, $26,$B7,$E3, $4C, $4C ; SLO,$264C .byte $33, $EA,<ptr_2004, $00, $26,$B7,$E3, $4C, $4D ; RLA,$264C or $264D .byte $53, $EA,<ptr_2004, $00, $26,$B7,$E3, $13, $13 ; SRE,$2613 .byte $73, $EA,<ptr_2004, $00, $26,$B7,$E3, $13, $93 ; RRA,$2613 or $2693 .byte $D3, $EA,<ptr_2004, $00, $26,$B7,$E3, $25, $25 ; DCP,$2625 .byte $F3, $EA,<ptr_2004, $00, $26,$B7,$E3, $27, $27 ; ISB,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $1B, $20,$04, $00, $25,$B7,$E3, $4A, $4A ; SLO,254A .byte $3B, $20,$04, $00, $25,$B7,$E3, $4A, $4B ; RLA,254A or 254B .byte $5B, $20,$04, $00, $25,$B7,$E3, $12, $12 ; SRE,2512 .byte $7B, $20,$04, $00, $25,$B7,$E3, $12, $92 ; RRA,2512 or $2592 .byte $DB, $20,$04, $00, $25,$B7,$E3, $24, $24 ; DCP,2524 .byte $FB, $20,$04, $00, $25,$B7,$E3, $26, $26 ; ISB,2526 ; .byte $01 ; .byte $00 .popseg test_dummy_writes: jsr console_show set_test 5,"Some opcodes failed the test." ; 0123456789ABCDEF0123456789ABC| ; 0E2E4E6ECEEE 1E3E5E7EDEFE *00 ; 0F2F4F6FCFEF 1F3F5F7FDFFF *00 ; 03234363C3E3 13335373D3F3 *00 ; 1B3B5B7BDBFB *00 ; text_white print_str "Verifying opcodes...",newline setw opcode_ptr, Opcodes-1 lda #$60 ; "rts" sta opcode_buffer+3 sta opcode_buffer+7 lda #$F0 sta opcode_buffer+5 lda #$EA sta opcode_buffer+6 setw ptr_2004, $2004 ldx #0 ; X coordinate stx num_fails stx num_fails_2 stx num_fails_2+1 @opcode_loop: jsr next_opcode_byte beq @opcode_loop_end cmp #2 beq @make_space bcc @make_newline sta opcode_buffer+0 sta opcode_buffer+4 jsr next_opcode_byte ; absolute address, hi byte sta opcode_buffer+2 jsr next_opcode_byte ; absolute address, lo byte sta opcode_buffer+1 jsr next_opcode_byte ; X sta temp_x jsr next_opcode_byte ; OAM[0] sta temp_oam_data+0 jsr next_opcode_byte ; OAM[1] sta temp_oam_data+1 jsr next_opcode_byte ; OAM[2] sta temp_oam_data+2 stx x_position lda #0 sta temp_read_result clc jsr @opcode_test_once sec jsr @opcode_test_once lda temp_read_result beq @didnt_fail ; Did fail inc num_fails text_white lda opcode_buffer+0 jsr print_hex bne @opcode_next @opcode_loop_end: text_white rts @make_newline: jmp @make_newline_s @didnt_fail: text_color2 lda opcode_buffer+0 jsr print_hex @opcode_next: ldx x_position inx inx bne @opcode_loop @make_space: lda #' ' jsr print_char inx jmp @opcode_loop @make_newline_space_loop: lda #' ' jsr print_char inx @make_newline_s: cpx #26 bcc @make_newline_space_loop ; At end of line lda num_fails beq @no_fails_this_line clc adc num_fails_2 sta num_fails_2 lda #0 adc num_fails_2+1 sta num_fails_2+1 lda num_fails pha text_white lda #'*' jsr print_char pla jsr print_dec @no_fails_this_line: jsr print_newline ldx #0 stx num_fails jmp @opcode_loop @opcode_test_once: ; First, dry-execute the opcode just in case it crashes ; the emulator (so the screen is left readable) php ldy #0 jsr opcode_buffer+4 jsr console_hide plp ; Then execute the actual opcode ldx #0 stx SPRADDR lda temp_oam_data+0 sta SPRDATA lda temp_oam_data+1 sta SPRDATA lda temp_oam_data+2 sta SPRDATA ; Put something dummy at [3] stx SPRDATA ldx #0 stx SPRADDR ldx temp_x ldy #0 jsr opcode_buffer ; Execute opcode lda #3 sta SPRADDR lda SPRDATA ; Read OAM[3] (And ignore it) to clear any possible internal buffer ; Load first byte, and expect it to be unmodified lda #0 sta SPRADDR lda temp_oam_data+0 eor SPRDATA ora temp_read_result sta temp_read_result ; Load second byte, and expect it to be what the test dicatetes lda #1 sta SPRADDR ldy #0 jsr next_opcode_byte eor SPRDATA ora temp_read_result sta temp_read_result ; Load third byte, and expect it to be unmodified lda #2 sta SPRADDR lda temp_oam_data+2 eor SPRDATA ora temp_read_result sta temp_read_result jsr console_show_nowait jsr console_flush rts next_opcode_byte: incw opcode_ptr ldy #0 lda (opcode_ptr),y rts test_rom_write: set_test 7,"ROM should not be writable." lda #1 sta test_return_0+1 jsr test_return_0 cmp #0 bne :+ rts : jmp test_failed_finish test_return_0: lda #0 rts
xboot/libxnes
23,304
documents/test-roms/cpu_dummy_writes/source/cpu_dummy_writes_ppumem.s
; All read-modify-write-instructions on 6502 have a particular glitch: ; They first write back the unmodified value; then, the modified value. ; ; This test requires that the PPU open bus behavior is accurately emulated. ; Cycle accuracy will not be tested. ; ; ; Expected output: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TEST: cpu_dummy_writes_ppumem ; This program verifies that the ; CPU does 2x writes properly. ; Any read-modify-write opcode ; should first write the origi- ; nal value; then the calculated ; value exactly 1 cycle later. ; ; Verifying open bus behavior. ; W- W- WR W- W- W- W- WR ; 2000+ 0 1 2 3 4 5 6 7 ; R0: 0- 0- 00 0- 0- 0- 0- 00 ; R1: 0- 0- 00 0- 0- 0- 0- 00 ; R3: 0- 0- 00 0- 0- 0- 0- 00 ; R5: 0- 0- 00 0- 0- 0- 0- 00 ; R6: 0- 0- 00 0- 0- 0- 0- 00 ; OK; Verifying opcodes... ; 0E2E4E6ECEEE 1E3E5E7EDEFE ; 0F2F4F6FCFEF 1F3F5F7FDFFF ; 03234363C3E3 13335373D3F3 ; 1B3B5B7BDBFB ; ; Passed ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Written by Joel Yliluoma - http://iki.fi/bisqwit/ .segment "LIB" .include "shell.inc" .include "colors.inc" .include "crc_fast.s" .segment "CODE" ;OFFICIAL_ONLY = 0 zp_res num_fails zp_res num_fails_2, 2 zp_res open_bus_test_failed zp_res opcode_ptr, 2 zp_res opcode_buffer, 8 zp_res temp_read_result zp_res temp_ppu_ptr, 2 zp_res temp_open_bus zp_res temp_x zp_res x_position zp_res ptr_2006, 2 .macro fail_if_y_not n, fail_label cpy #n bne fail_label .endmacro ; Test open bus feature ; puts A into $2000+X ; reads from $2000+Y ; expects A open_bus_test: sta $2000,x cmp $2000,y bne test_failed_finish rts .macro do_open_bus_test test_no,name,poke_value,a_index,b_index set_test test_no,name lda #poke_value ldx #a_index ldy #b_index jsr open_bus_test .endmacro .macro do_open_bus_test1 poke_value,a_index,b_index lda #poke_value ldx #a_index ldy #b_index jsr open_bus_test .endmacro ; Set PPU addr to A*0x100+X ; Preserved: A,X; gobbled: Y set_vram_pos: ldy PPUSTATUS sta PPUADDR ; poke high 6 bits stx PPUADDR ; poke low 8 bits rts test_failed_finish: ; Re-enable screen jsr clear_vram_garbage jsr console_show jmp test_failed main: ; Operations we will be doing are: ; ; $2400->$27FF is nicely usable (secondary name table). ; ; INC ->$2526 ; DEC ->$2524 ; ; ASL ->$254A ; LSR ->$2512 ; ROR ->$2512 or $2592 ; ROL ->$254A or $254B ; ; SLO ->$252A ; SRE ->$2512 ; RRA ->$2512 or $2592 ; RLA ->$254A or $254B ; lda #0 sta open_bus_test_failed jsr intro jsr init_random jsr populate_vram_slow ; leaves display hidden ; First, verify that PPU memory I/O works as expected ; jsr test_one_byte_buffer jsr test_2005_writes jsr test_sequential_memory_read jsr test_sequential_memory_write jsr console_show jsr test_rom_write jsr test_open_bus_behavior ; Then do the actual test! ; jsr populate_vram_slow lda #$00 sta $2000 jsr test_dummy_writes ; lda num_fails_2 ora num_fails_2+1 beq :+ jsr wait_vbl text_color1 ldx num_fails_2 lda num_fails_2+1 jsr print_dec16 print_str " OPCODES FAILED THE TEST" text_white jmp test_failed_finish : ; Now, when the dummy-write tests have been done (and passed), ; verify whether we failed the open bus test earlier. ; If it failed, do not give a clean exit status. lda open_bus_test_failed beq end_tests jsr wait_vbl print_str "Opcodes worked fine, but..." set_test 10,"Open bus behavior is wrong." jmp test_failed_finish end_tests: jsr clear_vram_garbage jsr console_show jsr wait_vbl jmp tests_passed .pushseg .segment "RODATA" Opcodes: ; Opcodes to test: ; * 0E (RMW) ASL abs U 0F (RMW) SLO abs (ASL+ORA) ; * 2E (RMW) ROL abs U 2F (RMW) RLA abs (ROL+AND) ; * 4E (RMW) LSR abs U 4F (RMW) SRE abs (LSR+EOR) ; * 6E (RMW) ROR abs U 6F (RMW) RRA abs (ROR+ADC) ; * CE (RMW) DEC abs U CF (RMW) DCP abs (DEC+CMP) ; * EE (RMW) INC abs U EF (RMW) ISB abs (INC+SBC) ; ; * 1E (RMW) ASL absx U 1F (RMW) SLO absx (ASL+ORA) U 1B (RMW) SLO absy (ASL+ORA) ; * 3E (RMW) ROL absx U 3F (RMW) RLA absx (ROL+AND) U 3B (RMW) RLA absy (ROL+AND) ; * 5E (RMW) LSR absx U 5F (RMW) SRE absx (LSR+EOR) U 5B (RMW) SRE absy (LSR+EOR) ; * 7E (RMW) ROR absx U 7F (RMW) RRA absx (ROR+ADC) U 7B (RMW) RRA absy (ROR+ADC) ; * DE (RMW) DEC absx U DF (RMW) DCP absx (DEC+CMP) U DB (RMW) DCP absy (DEC+CMP) ; * FE (RMW) INC absx U FF (RMW) ISB absx (INC+SBC) U FB (RMW) ISB absy (INC+SBC) ; ; K 12 (RMW) ASL ix U 03 (RMW) SLO ix (ASL+ORA) U 13 (RMW) SLO iy (ASL+ORA) ; K 32 (RMW) ROL ix U 23 (RMW) RLA ix (ROL+AND) U 33 (RMW) RLA iy (ROL+AND) ; K 52 (RMW) LSR ix U 43 (RMW) SRE ix (LSR+EOR) U 53 (RMW) SRE iy (LSR+EOR) ; K 72 (RMW) ROR ix U 63 (RMW) RRA ix (ROR+ADC) U 73 (RMW) RRA iy (ROR+ADC) ; K D2 (RMW) DEC ix U C3 (RMW) DCP ix (DEC+CMP) U D3 (RMW) DCP iy (DEC+CMP) ; K F2 (RMW) INC ix U E3 (RMW) ISB ix (INC+SBC) U F3 (RMW) ISB iy (INC+SBC) ; ; Format: Opcode number ($00 for end, $01 for newline, $02 for space) ; Value for absolute address (appended to opcode) (BIG-ENDIAN) ; Value for X ; Value for PPU address (BIG_ENDIAN) -- this is used in order to avoid false positives. ; Value for open bus ($2005) -- this is the expected first byte ; Expected 2nd reads from $2007 with Carry Set, Carry Clear (two bytes) ; Each opcode will be tried twice. Once with carry clear, once with carry set ; opcode ABS X PPUADDR OpenBus READ1 READ2 ; OFFICIAL OPCODES .byte $0E, $20,$06, $00, $25,$FA, $25, $CA, $CA ; ASL,254A .byte $2E, $20,$06, $00, $25,$FA, $25, $CA, $CB ; ROL,254A or 254B .byte $4E, $20,$06, $00, $25,$FA, $25, $92, $92 ; LSR,2512 .byte $6E, $20,$06, $00, $25,$FA, $25, $92, $12 ; ROR,2512 or $2592 .byte $CE, $20,$06, $00, $25,$FA, $25, $A4, $A4 ; DEC,2524 .byte $EE, $20,$06, $00, $25,$FA, $25, $A6, $A6 ; INC,2526 ---Expect: reads open bus, gets $25 (Vaddr = $25FA) ; writes $2006 <- $25 (taddr = $2525) ; writes $2006 <- $26 (Vaddr = $2526) ; 2*read $2007 -> $A6 .byte $02 ; .byte $1E, $20,$05, $01, $25,$FA, $26, $0C, $0C ; ASL,$264C .byte $3E, $20,$01, $05, $25,$FA, $26, $0C, $0D ; ROL,$264C or $264D .byte $5E, $20,$04, $02, $25,$FA, $26, $D3, $D3 ; LSR,$2613 .byte $7E, $20,$02, $04, $25,$FA, $26, $D3, $53 ; ROR,$2613 or $2693 .byte $DE, $20,$04, $02, $25,$FA, $26, $E5, $E5 ; DEC,$2625 .byte $FE, $20,$03, $03, $25,$FA, $26, $E7, $E7 ; INC,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $0F, $20,$06, $00, $25,$FA, $25, $CA, $CA ; SLO,254A .byte $2F, $20,$06, $00, $25,$FA, $25, $CA, $CB ; RLA,254A or 254B .byte $4F, $20,$06, $00, $25,$FA, $25, $92, $92 ; SRE,2512 .byte $6F, $20,$06, $00, $25,$FA, $25, $92, $12 ; RRA,2512 or $2592 .byte $CF, $20,$06, $00, $25,$FA, $25, $A4, $A4 ; DCP,2524 .byte $EF, $20,$06, $00, $25,$FA, $25, $A6, $A6 ; ISB,2526 ; .byte $02 ; .byte $1F, $20,$05, $01, $25,$FA, $26, $0C, $0C ; SLO,$264C .byte $3F, $20,$01, $05, $25,$FA, $26, $0C, $0D ; RLA,$264C or $264D .byte $5F, $20,$04, $02, $25,$FA, $26, $D3, $D3 ; SRE,$2613 .byte $7F, $20,$02, $04, $25,$FA, $26, $D3, $53 ; RRA,$2613 or $2693 .byte $DF, $20,$04, $02, $25,$FA, $26, $E5, $E5 ; DCP,$2625 .byte $FF, $20,$03, $03, $25,$FA, $26, $E7, $E7 ; ISB,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $03, $EA,<ptr_2006, $00, $25,$FA, $25, $CA, $CA ; SLO,254A .byte $23, $EA,<ptr_2006, $00, $25,$FA, $25, $CA, $CB ; RLA,254A or 254B .byte $43, $EA,<ptr_2006, $00, $25,$FA, $25, $92, $92 ; SRE,2512 .byte $63, $EA,<ptr_2006, $00, $25,$FA, $25, $92, $12 ; RRA,2512 or $2592 .byte $C3, $EA,<ptr_2006, $00, $25,$FA, $25, $A4, $A4 ; DCP,2524 .byte $E3, $EA,<ptr_2006, $00, $25,$FA, $25, $A6, $A6 ; ISB,2526 ; .byte $02 ; .byte $13, $EA,<ptr_2006, $00, $25,$FA, $26, $0C, $0C ; SLO,$264C .byte $33, $EA,<ptr_2006, $00, $25,$FA, $26, $0C, $0D ; RLA,$264C or $264D .byte $53, $EA,<ptr_2006, $00, $25,$FA, $26, $D3, $D3 ; SRE,$2613 .byte $73, $EA,<ptr_2006, $00, $25,$FA, $26, $D3, $53 ; RRA,$2613 or $2693 .byte $D3, $EA,<ptr_2006, $00, $25,$FA, $26, $E5, $E5 ; DCP,$2625 .byte $F3, $EA,<ptr_2006, $00, $25,$FA, $26, $E7, $E7 ; ISB,$2627 ; .byte $01 ; ; UNOFFICIAL OPCODES ; .byte $1B, $20,$06, $00, $25,$FA, $25, $CA, $CA ; SLO,254A .byte $3B, $20,$06, $00, $25,$FA, $25, $CA, $CB ; RLA,254A or 254B .byte $5B, $20,$06, $00, $25,$FA, $25, $92, $92 ; SRE,2512 .byte $7B, $20,$06, $00, $25,$FA, $25, $92, $12 ; RRA,2512 or $2592 .byte $DB, $20,$06, $00, $25,$FA, $25, $A4, $A4 ; DCP,2524 .byte $FB, $20,$06, $00, $25,$FA, $25, $A6, $A6 ; ISB,2526 ; .byte $01 ; .byte $00 .popseg test_dummy_writes: jsr console_show set_test 9,"Some opcodes failed the test." ; 0123456789ABCDEF0123456789ABC| ; 0E2E4E6ECEEE 1E3E5E7EDEFE *00 ; 0F2F4F6FCFEF 1F3F5F7FDFFF *00 ; 03234363C3E3 13335373D3F3 *00 ; 1B3B5B7BDBFB *00 ; text_white print_ext_str "Verifying opcodes...",newline setw opcode_ptr, Opcodes-1 lda #$60 ; "rts" sta opcode_buffer+3 sta opcode_buffer+7 lda #$F0 sta opcode_buffer+5 lda #$EA sta opcode_buffer+6 setw ptr_2006, $2006 ldx #0 ; X coordinate stx num_fails stx num_fails_2 stx num_fails_2+1 @opcode_loop: jsr next_opcode_byte beq @opcode_loop_end cmp #2 beq @make_space bcc @make_newline sta opcode_buffer+0 sta opcode_buffer+4 jsr next_opcode_byte ; absolute address, hi byte sta opcode_buffer+2 jsr next_opcode_byte ; absolute address, lo byte sta opcode_buffer+1 jsr next_opcode_byte ; X sta temp_x jsr next_opcode_byte ; PPU address, hi sta temp_ppu_ptr+0 jsr next_opcode_byte ; PPU address; lo sta temp_ppu_ptr+1 jsr next_opcode_byte ; Value for open bus sta temp_open_bus stx x_position lda #0 sta temp_read_result clc jsr @opcode_test_once sec jsr @opcode_test_once lda temp_read_result beq @didnt_fail ; Did fail inc num_fails text_white lda opcode_buffer+0 jsr print_hex bne @opcode_next @opcode_loop_end: text_white rts @make_newline: jmp @make_newline_s @didnt_fail: text_color2 lda opcode_buffer+0 jsr print_hex @opcode_next: ldx x_position inx inx bne @opcode_loop @make_space: lda #' ' jsr print_char inx jmp @opcode_loop @make_newline_space_loop: lda #' ' jsr print_char inx @make_newline_s: cpx #26 bcc @make_newline_space_loop ; At end of line lda num_fails beq @no_fails_this_line clc adc num_fails_2 sta num_fails_2 lda #0 adc num_fails_2+1 sta num_fails_2+1 lda num_fails pha text_white lda #'*' jsr print_char pla jsr print_dec @no_fails_this_line: jsr print_newline ldx #0 stx num_fails jmp @opcode_loop @opcode_test_once: ; First, dry-execute the opcode just in case it crashes ; the emulator (so the screen is left readable) php ldy #0 jsr opcode_buffer+4 jsr console_hide plp ; Then execute the actual opcode lda PPUSTATUS ; reset low/high counter lda temp_ppu_ptr+0 sta PPUADDR lda temp_ppu_ptr+1 sta PPUADDR lda temp_open_bus sta $2005 ; writes to $2005 serve to put data into open bus sta $2005 ; writes twice, so the address toggle is not affected ldx temp_x ldy #0 jsr opcode_buffer ; Execute opcode lda PPUDATA ; ignore this byte jsr next_opcode_byte eor PPUDATA ora temp_read_result sta temp_read_result jsr console_show_nowait jsr console_flush rts next_opcode_byte: incw opcode_ptr ldy #0 lda (opcode_ptr),y rts test_one_byte_buffer: set_test 2,"Non-palette PPU memory reads should have one-byte buffer" lda #$25 ldx #$30 jsr set_vram_pos ldy PPUDATA ; $B0 should be placed in read-buffer ldx #$55 jsr set_vram_pos ldy PPUDATA ; $B0 should be produced; $D5 should be placed in read-buffer fail_if_y_not $B0, test_failed_finish2 ldy PPUDATA ; $D5 should be produced; $D6 should be placed in read-buffer fail_if_y_not $D5, test_failed_finish2 rts test_failed_finish2: ; Aux label to help overcome short branch length limitation. jmp test_failed_finish test_2005_writes: ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 3,"A single write to $2005 must not change the address used by $2007 when vblank is on." lda #$25 ldx #$4B jsr set_vram_pos lda #$55 sta $2005 ; set scrolling position ; read from PPU memory lda $2007 ; discard first read ldy $2007 ; should be x ^ $80 fail_if_y_not $CB, test_failed_finish2 set_test 4,"Even two writes to $2005 must not change the address used by $2007 when vblank is on." lda #$25 ldx #$6A jsr set_vram_pos lda #$55 sta $2005 ; set scrolling position lda #$8C sta $2005 ; ; read from PPU memory lda $2007 ; discard first read ldy $2007 ; should be x ^ $80 fail_if_y_not $EA, test_failed_finish2 ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 5,"A single write to $2006 must not change the address used by $2007 when vblank is on." lda #$25 ldx #$93 jsr set_vram_pos lda #$55 sta $2006 ; set half of the address ; read from PPU memory lda $2007 ; discard first read ldy $2007 ; should be x fail_if_y_not $13, test_failed_finish3 ; 0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC|0123456789ABCDEF0123456789ABC| set_test 6,"A single write to $2005 must change the address toggle for both $2005 and $2006." lda #$25 ldx #$93 jsr set_vram_pos ; taddr = $2593 (x fine = whatever) lda #$F0 sta $2005 ; set half of the address (should set the toggle) -- taddr = $25DE ; the next byte should set the toggle for also the VRAM lda #$DE ; alas, this completely overrides what was written to $2005. sta $2006 ; read from PPU memory lda $2007 ; discard first read ldy $2007 ; should be $DE ^ $80 fail_if_y_not $5E, test_failed_finish3 rts test_failed_finish3: ; Aux label to help overcome short branch length limitation. jmp test_failed_finish test_sequential_memory_read: set_test 7,"Sequential PPU memory read does not work" lda #$25 ldx #$55 jsr set_vram_pos ldy PPUDATA ; something should be produced; $D5 should be placed in read-buffer lda #$25 ldx #$C2 jsr set_vram_pos ldy PPUDATA ; should produce $D5 (from read buffer); $42 will be placed in read buffer fail_if_y_not $D5, test_failed_finish3 ldy PPUDATA fail_if_y_not $42, test_failed_finish3 ldy PPUDATA fail_if_y_not $43, test_failed_finish3 ldy PPUDATA fail_if_y_not $44, test_failed_finish3 ldy PPUDATA fail_if_y_not $45, test_failed_finish3 rts test_sequential_memory_write: set_test 8,"Sequential PPU memory write does not work" lda #$25 ldx #$33 jsr set_vram_pos lda #$40 sta PPUDATA lda #$41 sta PPUDATA lda #$42 sta PPUDATA lda #$43 sta PPUDATA lda #$44 sta PPUDATA lda #$25 ldx #$33 jsr set_vram_pos ldy PPUDATA ; discard ldy PPUDATA fail_if_y_not $40, test_failed_finish4 ldy PPUDATA fail_if_y_not $41, test_failed_finish4 ldy PPUDATA fail_if_y_not $42, test_failed_finish4 ldy PPUDATA fail_if_y_not $43, test_failed_finish4 ldy PPUDATA fail_if_y_not $44, test_failed_finish4 rts test_failed_finish4: ; Aux label to help overcome short branch length limitation. jmp test_failed_finish test_open_bus_behavior: ; Extensively test open bus. ; $2000 is write only (writing updates open_bus, reading returns open_bus) ; $2001 is write only (writing updates open_bus, reading returns open_bus) ; $2002 is read only (writing updates open_bus, reading UPDATES open_bus (but only for low 5 bits)) ; $2003 is write only (writing updates open_bus, reading returns open_bus) ; $2004 is read-write (writing updates open_bus, however for %4==2, bitmask=11100011. Reading is UNRELIABLE.) ; $2005 is write only (writing updates open_bus, reading returns open_bus) ; $2006 is write only (writing updates open_bus, reading returns open_bus) ; $2007 is read-write (writing updates open_bus, reading UPDATES open_bus) ; ; 0123456789ABCDEF0123456789ABC| ; W- W- WR W- W- W- W- WR ; 00 01 02 03 04 05 06 07 ; R 00 ; R 01 ; R 03 ; R 05 ; R 06 lda #0 sta num_fails_2 sta num_fails_2+1 jsr console_show print_ext_str "Verifying open bus behavior.",newline text_color1 print_ext_str " W- W- WR W- W- W- W- WR",newline print_ext_str "2000+ 0 1 2 3 4 5 6 7 ",newline jsr reset_crc ldx #0 jsr open_bus_test_line ldx #1 jsr open_bus_test_line ldx #3 jsr open_bus_test_line ldx #5 jsr open_bus_test_line ldx #6 jsr open_bus_test_line text_white is_crc $86FCF77E bne :+ ; 0123456789ABCDEF0123456789ABC| ;print_ext_str "Open bus behavior OK.",newline print_ext_str "OK; " rts : jsr crc_off print_ext_str "FAIL! " ldx num_fails_2 lda num_fails_2+1 jsr print_dec16 print_ext_str " ERRORS. CRC=" jsr print_crc print_ext_str ".",newline ; We will continue tests, but note for later use that ; this test failed. lda #1 sta open_bus_test_failed jmp crc_on .pushseg .segment "RODATA" ; When writing or reading $2000+x, which bits of the result are shown in open bus? open_bus_read_masks: .byte $FF,$FF,$1F,$FF, $FF,$FF,$FF,$FF ; When writing to this port, which bits can we modify? open_bus_write_and: .byte $FF&~$97,$FF&~$18,$FF,$FF, $7F,$7F,$FF,$FF ;.byte $00,$00,$00,$00, $00,$00,$00,$00 open_bus_write_or: .byte $00,$00,$00,$00, $00,$00,$00,$00 .popseg print_open_bus_fails: lda num_fails beq :+ text_white ; nonzero value = fail, color = white : jsr update_crc jsr print_hex_nibble text_color2 lda num_fails clc adc num_fails_2 sta num_fails_2 lda #0 adc num_fails_2+1 sta num_fails_2+1 rts .macro open_bus_write_test port_index .local loop ; Should write to $2000+port_index, ; and test whether $2000+X gives out the same value when read. ; Do several writes and count the number of failures. .if port_index = 7 lda #$24 ldx #$00 jsr set_vram_pos .endif lda #' ' jsr print_char lda #0 sta num_fails ldy #15 loop: jsr next_random and open_bus_write_and+port_index ora open_bus_write_and+port_index sta $2000+port_index eor $2000,x and open_bus_read_masks+port_index beq :+ inc num_fails : dey bne loop jsr print_open_bus_fails .endmacro .macro open_bus_read_test port_index .local loop ; Should read from $2000+port_index, ; and test whether $2000+X gives out the same value when read. lda #0 sta num_fails ldy #15 loop: lda $2000+port_index eor $2000,x and open_bus_read_masks+port_index beq :+ inc num_fails : dey bne loop jsr print_open_bus_fails .endmacro .macro open_bus_skip_test ; skipped in blue (default) lda #'-' jsr print_char .endmacro open_bus_test_line: ; Test writing into each of $2000..$2007, and read from $2000+X. text_color1 ldy #' ' tya jsr print_char jsr print_char lda #'R' jsr print_char txa jsr print_hex_nibble lda #':' jsr print_char text_color2 jsr console_hide ; Begin testing ; Write to $2000, read from $2000+X open_bus_write_test 0 open_bus_skip_test open_bus_write_test 1 open_bus_skip_test open_bus_write_test 2 open_bus_read_test 2 open_bus_write_test 3 open_bus_skip_test open_bus_write_test 4 open_bus_skip_test open_bus_write_test 5 open_bus_skip_test open_bus_write_test 6 open_bus_skip_test open_bus_write_test 7 open_bus_read_test 7 ; end test: clear garbage jsr console_show ; redisplay screen, and print the line of results jsr print_newline rts .pushseg .segment "RODATA" intro: text_white print_str "TEST: cpu_dummy_writes_ppumem",newline text_color1 jsr print_str_ ; 0123456789ABCDEF0123456789ABCD .byte "This program verifies that the",newline .byte "CPU does 2x writes properly.",newline .byte "Any read-modify-write opcode",newline .byte "should first write the origi-",newline .byte "nal value; then the calculated",newline .byte "value exactly 1 cycle later.",newline .byte newline,0 text_white rts .popseg init_random: jsr init_crc_fast lda #1 jsr update_crc_fast rts next_random: lda #$55 jmp update_crc_fast populate_vram_slow: ; Disable rendering jsr console_hide ; Populate the $2500..$25FF with bytes: $80..$7F ; These updates are done very slowly, in order to ; avoid bugs with those PPUs that do not automatically ; update the taddr when $2007 is written to. ldx #$00 : lda #$25 jsr set_vram_pos txa eor #$80 sta PPUDATA inx bne :- ; Then, populate $2400..$24FF with $40..$BF ; And the $2600..$26FF with $C0..$3F ; And the $2700..$2BFF with $00..$FF ; Since these will be used later in the tests, ; they can be overwritten quicker. ; 2400..24FF lda #$24 ldx #$00 jsr set_vram_pos : txa clc adc #$40 sta PPUDATA inx bne :- ; 2600..26FF lda #$26 jsr set_vram_pos : txa clc adc #$C0 sta PPUDATA inx bne :- ; 2700..27FF lda #$27 jsr set_vram_pos : stx PPUDATA inx bne :- rts clear_vram_garbage: ; Disable rendering jsr console_hide ;clear_vram_garbage_nohide: lda #0 sta $2000 sta $2001 ldy $2002 ldx #$00 lda #$24 jsr set_vram_pos ldy #$04 lda #0 : sta PPUDATA inx bne :- ; do 256 times dey bne :- ; do 1 times ; pass through to reset_scrolling ;reset_scrolling: ; reset scrolling position and vram write position ldy $2002 ;jsr console_show ; ldx #0 stx $2005 lda console_scroll sta $2005 txa jmp set_vram_pos rts test_rom_write: set_test 11,"ROM should not be writable." lda #1 sta test_return_0+1 jsr test_return_0 cmp #0 bne :+ rts : jmp test_failed_finish test_return_0: lda #0 rts
xboot/libxnes
1,856
documents/test-roms/cpu_dummy_writes/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
xboot/libxnes
5,870
documents/test-roms/cpu_dummy_writes/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_hex_nibble pla pha and #$0F jsr print_hex_nibble pla rts print_hex_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,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15 jsr print_str_ .byte str .ifnblank str2 .byte str2 .endif .ifnblank str3 .byte str3 .endif .ifnblank str4 .byte str4 .endif .ifnblank str5 .byte str5 .endif .ifnblank str6 .byte str6 .endif .ifnblank str7 .byte str7 .endif .ifnblank str8 .byte str8 .endif .ifnblank str9 .byte str9 .endif .ifnblank str10 .byte str10 .endif .ifnblank str11 .byte str11 .endif .ifnblank str12 .byte str12 .endif .ifnblank str13 .byte str13 .endif .ifnblank str14 .byte str14 .endif .ifnblank str15 .byte str15 .endif .byte 0 .endmacro .macro print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 print_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 rts .endmacro .macro print_ext_str s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15 .local @Addr jsr @Addr seg_data "RODATA",{@Addr: print_str_and_ret s,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15} .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 .pushseg .segment "RODATA" ; >= 60000 ? (EA60) ; >= 50000 ? (C350) ; >= 40000 ? (9C40) ; >= 30000 ? (7530) ; >= 20000 ? (4E20) ; >= 10000 ? (2710) digit10000_hi: .byte $00,$27,$4E,$75,$9C,$C3,$EA digit10000_lo: .byte $00,$10,$20,$30,$40,$50,$60 ; >= 9000 ? (2328 (hex)) ; >= 8000 ? (1F40 (hex)) ; >= 7000 ? (1B58 (hex)) ; >= 6000 ? (1770 (hex)) ; >= 5000 ? (1388 (hex)) ; >= 4000 ? (FA0 (hex)) ; >= 3000 ? (BB8 (hex)) ; >= 2000 ? (7D0 (hex)) ; >= 1000 ? (3E8 (hex)) digit1000_hi: .byte $00,$03,$07,$0B,$0F,$13,$17,$1B,$1F,$23 digit1000_lo: .byte $00,$E8,$D0,$B8,$A0,$88,$70,$58,$40,$28 ; >= 900 ? (384 (hex)) ; >= 800 ? (320 (hex)) ; >= 700 ? (2BC (hex)) ; >= 600 ? (258 (hex)) ; >= 500 ? (1F4 (hex)) ; >= 400 ? (190 (hex)) ; >= 300 ? (12C (hex)) ; >= 200 ? (C8 (hex)) ; >= 100 ? (64 (hex)) digit100_hi: .byte $00,$00,$00,$01,$01,$01,$02,$02,$03,$03 digit100_lo: .byte $00,$64,$C8,$2C,$90,$F4,$58,$BC,$20,$84 .popseg .macro dec16_comparew table_hi, table_lo .local @lt cmp table_hi,y bcc @lt bne @lt ; only test the lo-part if hi-part is equal pha txa cmp table_lo,y pla @lt: .endmacro .macro do_digit table_hi, table_lo pha ; print Y as digit; put X in A and do SEC for subtraction jsr @print_dec16_helper sbc table_lo,y tax pla sbc table_hi,y .endmacro ; Prints A:X as 2-5 digit decimal value, NO space after. ; A = high 8 bits, X = low 8 bits. print_dec16: ora #0 beq @less_than_256 ldy #6 sty print_temp_ ; TODO: Use binary search? : dec16_comparew digit10000_hi,digit10000_lo bcs @got10000 dey bne :- ;cpy print_temp_ ;beq @got10000 @cont_1000: ldy #9 : dec16_comparew digit1000_hi,digit1000_lo bcs @got1000 dey bne :- ; Y = 0. cpy print_temp_ ; zero print_temp_ = print zero-digits beq @got1000 @cont_100: ldy #9 : dec16_comparew digit100_hi,digit100_lo bcs @got100 dey bne :- cpy print_temp_ beq @got100 @got10000: do_digit digit10000_hi,digit10000_lo ; value is now 0000..9999 ldy #0 sty print_temp_ beq @cont_1000 @got1000: do_digit digit1000_hi,digit1000_lo ; value is now 000..999 ldy #0 sty print_temp_ beq @cont_100 @got100: do_digit digit100_hi,digit100_lo ; value is now 00..99 txa jmp print_dec_00_99 @less_than_256: txa jmp print_dec @print_dec16_helper: tya jsr print_digit txa sec rts ; Prints A as 2-3 digit decimal value, NO space after. ; Preserved: Y print_dec: ; Hundreds cmp #10 blt print_digit cmp #100 blt print_dec_00_99 ldx #'0'-1 : inx sbc #100 bge :- adc #100 jsr print_char_x ; Tens print_dec_00_99: sec ldx #'0'-1 : inx sbc #10 bge :- adc #10 jsr print_char_x ; Ones print_digit: ora #'0' jmp print_char ; Print a single digit print_char_x: 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
xboot/libxnes
1,591
documents/test-roms/cpu_dummy_writes/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&$FFFF,-1&$FFFF,-1&$FFFF, 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_3.chr" ;.align $200 .incbin "ascii_2.chr" ;.align $200 .incbin "ascii_1.chr" .res $E00 .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 .align 256
xboot/libxnes
4,296
documents/test-roms/cpu_dummy_writes/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 zp_byte text_color bss_res console_buf,console_buf_size ; Initializes console console_init: ; Flag that console hasn't been initialized setb console_scroll,-1&$FF lda #0 sta text_color jmp console_clear_line_ ; Hides console by blacking palette and disabling PPU. ; Preserved: A, X, Y console_hide: pha txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,0 lda #$0F tax tay jsr console_load_palette_ pla tay pla tax pla rts console_wait_vbl_: lda console_scroll cmp #-1&$FF 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 #$E0 ;sta text_color lda #0 : 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 txa pha tay pha jsr console_wait_vbl_ setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ ; Shows console display ; Preserved: X, Y console_show_nowait: pha txa pha tay pha setb PPUMASK,PPUMASK_BG0 lda #$22 ; red ldx #$27 ; green ldy #$30 ; white jsr console_load_palette_ pla tay pla tax jmp console_apply_scroll_ console_load_palette_: pha setb PPUADDR,$3F setb PPUADDR,$00 setb PPUDATA,$0F ; black pla sta PPUDATA stx PPUDATA sty 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 clc adc text_color 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 #0 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
xboot/libxnes
1,096
documents/test-roms/cpu_dummy_writes/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
xboot/libxnes
2,024
documents/test-roms/cpu_dummy_writes/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
xboot/libxnes
4,658
documents/test-roms/cpu_dummy_writes/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_nametable2 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
xboot/libxnes
4,822
documents/test-roms/cpu_dummy_writes/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 128 ;;;;;;;;;;;;;;;;;;;;;;;; ; Delays X:A clocks+overhead ; Time: 256*X+A+30 clocks (including JSR) ; Written by Joel Yliluoma. Clobbers A,X. Preserves Y. Has relocations. ;;;;;;;;;;;;;;;;;;;;;;;; delay_256x_a_30_clocks: cpx #0 ; +2 beq delay_a_25_clocks ; +3 (25+5 = 30 cycles overhead) ; do 256 cycles. ; 4 cycles so far. Loop is 1+1+ 2+3+ 1+3 = 11 bytes. dex ; 2 cycles pha ; 3 cycles lda #(256-25-9-2-7) ; +2 jsr delay_a_25_clocks pla ; 4 jmp delay_256x_a_30_clocks ; 3. ;;;;;;;;;;;;;;;;;;;;;;;; ; Delays A:X clocks+overhead ; Time: 256*A+X+31 clocks (including JSR) ; Written by Joel Yliluoma. Clobbers A. Preserves X,Y. Has relocations. ;;;;;;;;;;;;;;;;;;;;;;;; : ; do 256 cycles. ; 5 cycles done so far. Loop is 2+1+ 2+3+ 1 = 9 bytes. sbc #1 ; 2 cycles - Carry was set from cmp pha ; 3 cycles lda #(256-25-10-2-4) ; +2 jsr delay_a_25_clocks pla ; 4 cycles delay_256a_x_31_clocks: cmp #1 ; +2; 2 cycles overhead bcs :- ; +2; 4 cycles overhead ; 0-255 cycles remain, overhead = 4 txa ; +2; 6; +25 = 31 ;passthru ;;;;;;;;;;;;;;;;;;;;;;;; ; 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&$FF 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&$FF bne :- rts max_short_delay = 41 ; delay_short_ macro jumps into these .res (max_short_delay-12)/2,$EA ; NOP delay_unrolled_: rts ;max_small_delay = 10 ;.align $40 ; .res (max_small_delay-2), $C9 ; cmp #imm - 2 cycles ; .byte $C5,$EA ; cmp zp - 3 cycles ;delay_unrolled_small_: ; 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
xboot/libxnes
1,632
documents/test-roms/cpu_dummy_writes/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
XboxDev/cromwell
12,133
boot/BootStartup.S
/* * * BIOS ROM Startup Assembler */ /*************************************************************************** * * * 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "consts.h" #include "memory_layout.h" .code32 .section .text, "ax" .org 0x00 jmp start_linux .global Cromwellconfig Cromwellconfig: .org 0x0c // Space for the SHA1 checksum .org 0x20 // The Value positions are fixed, do not change them, used everywhere .long 0x0 // 0x20 if XBE, then this bit is 0, if Cromwell mode, the bit is set to 1 by the Startuploader .long 0x0 // 0x24 ImageRetryLoads .long 0x0 // 0x28 Bank, from where Loaded .long 0x0 // 0x2C 0 .. Bios = 256 k, 1 .. Bios = 1MB .long 0x0 // 0x30 free .long _end_complete_rom // 0x34 free .long 0x0 // 0x38 free .long 0x0 // free .align 16 tableGdt: .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 0x00 dummy .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00 // 0x08 code32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00 // 0x10 code32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00 // 0x18 data32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0x8f, 0x00 // 0x20 code16 (8f indicates 4K granularity, ie, huge limit) .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x8f, 0x00 // 0x28 data16 tableGdtDescriptor: // This is the GDT header having 8 bytes .word tableGdtDescriptor-tableGdt // 30 byte GDT .long GDT_LOC // GDT located at 0xA0000 .word 0 // Padding tableGdtEnd: .align 16 tableIdtDescriptor: .word 2048 .long IDT_LOC // IDT located at 0xB0000 .word 0 // fill Word, so we get aligned again // We are dword aligned now .align 16 .globl start_linux start_linux: //Make SURE the IRQs are turned off cli // kill the cache = Disable bit 30 + 29 = CD + NW // CD = Cache Disable (disable = 1) // NW Not write through (disable = 1) // mov %cr0, %eax //orl $0x60000000, %eax mov $0x60010033, %eax mov %eax, %cr0 wbinvd // Flush the TLB xor %eax, %eax mov %eax, %cr3 // We kill the Local Descriptor Table xor %eax, %eax lldt %ax // DR6/DR7: Clear the debug registers xor %eax, %eax mov %eax, %dr6 mov %eax, %dr7 mov %eax, %dr0 mov %eax, %dr1 mov %eax, %dr2 mov %eax, %dr3 // IMPORTANT! Linux expects the GDT located at a specific position, // 0xA0000, so we have to move it there. // Copy the GDT to its final location movl $GDT_LOC, %edi movl $tableGdt, %esi movl $(tableGdtEnd-tableGdt)/4, %ecx rep movsl // Load the new GDT lgdt GDT_LOC+(tableGdtDescriptor-tableGdt) // Kill the LDT, if any xor %eax, %eax lldt %ax // Reload CS as 0010 from the new GDT using a far jump .byte 0xEA // jmp far 0010:reload_cs .long reload_cs .word 0x0010 .align 16 reload_cs: // CS is now a valid entry in the GDT. Set SS, DS, and ES to valid // descriptors, but clear FS and GS as they are not necessary. // Set SS, DS, and ES to a data32 segment with maximum limit. movw $0x0018, %ax mov %eax, %ss mov %eax, %ds mov %eax, %es // Clear FS and GS xor %eax, %eax mov %eax, %fs mov %eax, %gs // Set the stack pointer to give us a valid stack movl $STACK_TOP, %esp // Clear out .bss xor %eax, %eax mov $BSS_SIZE_L, %ecx mov $BSS_BASE, %edi rep stosl // We clear the IDT in RAM (IDT located @ 0xb0000 ) xor %eax, %eax movl $0x5000/4, %ecx movl $IDT_LOC, %edi rep stosl wbinvd // We load the Interrupt Descriptor Table lidt tableIdtDescriptor // FPU SETUP xor %eax, %eax xor %edx, %edx xor %ecx, %ecx clts fninit xor %eax, %eax xor %edx, %edx xor %ecx, %ecx // We flush the TLB mov %cr3, %eax mov %eax, %cr3 // Clear Mmeory Type register movl $0x2ff, %ecx xor %eax, %eax xor %edx, %edx wrmsr // MTRR for RAM // from address 0, Writeback Caching, 128MB range movl $0x200, %ecx movl $0x00000000, %edx movl $0x00000006, %eax // == WB_CACHE == 6 //movl $0x00000004, %eax // Temporary, as USB development wrmsr // MASK0 set to 0xf8000[000] == 128M movl $0x201, %ecx movl $0x0000000f, %edx movl $0xf8000800, %eax wrmsr // MTRR for shadow RAM // from address 0xf0000000, Write-combining Caching, 128MB range movl $0x202, %ecx movl $0x00000000, %edx movl $0xf0000001, %eax // Write-Combining == 1 wrmsr // MASK0 set to 0xf8000[000] == 128M movl $0x203, %ecx movl $0x0000000f, %edx movl $0xf8000800, %eax wrmsr // MTRR for FLASH movl $0x204, %ecx movl $0x00000000, %edx movl $0xFff00000, %eax // We set to Uncacheable wrmsr movl $0x205, %ecx movl $0x0000000f, %edx movl $0xfff00800, %eax wrmsr xor %eax, %eax xor %edx, %edx movl $0x206, %ecx // IA32_MTRR_PHYS Base 3 wrmsr movl $0x207, %ecx // IA32_MTRR_PHYS_MASK 3 wrmsr movl $0x208, %ecx // IA32_MTRR_PHYS Base 4 wrmsr movl $0x209, %ecx // IA32_MTRR_PHYS_MASK 4 wrmsr movl $0x20a, %ecx // IA32_MTRR_PHYS Base 5 wrmsr movl $0x20b, %ecx // IA32_MTRR_PHYS_MASK 5 wrmsr movl $0x20c, %ecx // IA32_MTRR_PHYS Base 6 wrmsr movl $0x20d, %ecx // IA32_MTRR_PHYS_MASK 6 wrmsr movl $0x20e, %ecx // IA32_MTRR_PHYS Base 7 wrmsr movl $0x20f, %ecx // IA32_MTRR_PHYS_MASK 7 wrmsr // Ok, we tell now the processor, we finished Memory Type definitions // We set the Default Memory Type in the Box now to Type == 0 .. Means UC .. Uncacheable movl $0x2ff, %ecx xor %edx, %edx movl $0x800, %eax //Enable MTRRs wrmsr // movl $0x600, %eax // mov %eax, %cr4 mov %eax, %eax // Flush the TLB and resets it mov %eax, %cr3 wbinvd /* turn on normal cache */ // bit 30 + 29 = CD + NW // CD = Cache Disable (disable = 1) // NW Not write through (disable = 1) // movl %cr0, %eax // mov %eax, %ebx // andl $0x9fFFffFF,%eax // movl %eax, %cr0 // wbinvd jmp BootResetAction /////////////////////////////////////////// // // Interrupt Service Routines // .global IntHandlerTimer0 IntHandlerTimer0: cli pusha pushf call IntHandlerCTimer0 mov $0x20, %al outb %al, $0x20 popf // sti popa iret .global IntHandler1 IntHandler1: pusha pushf cli call IntHandler1C mov $0x21, %al outb %al, $0x20 popf // sti popa iret .global IntHandler2 IntHandler2: cli pusha pushf call IntHandler2C mov $0x22, %al outb %al, $0x20 popf popa // sti iret .global IntHandler3 IntHandler3: cli pusha pushf call IntHandler3VsyncC mov $0x23, %al outb %al, $0x20 popf popa // sti iret .global IntHandler4 IntHandler4: cli pusha pushf call IntHandler4C mov $0x24, %al outb %al, $0x20 popf popa // sti iret .global IntHandler5 IntHandler5: cli pusha pushf call IntHandler5C mov $0x25, %al outb %al, $0x20 popf popa // sti iret .global IntHandler6 IntHandler6: cli pusha pushf call IntHandler6C mov $0x26, %al outb %al, $0x20 popf popa sti iret .global IntHandler7 IntHandler7: cli pusha pushf call IntHandler7C mov $0x27, %al outb %al, $0x20 popf popa sti iret .global IntHandler8 IntHandler8: cli pusha pushf call IntHandler8C // EOI on master and slave needed mov $0x60, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret .global IntHandler9 IntHandler9: pusha pushf cli call IntHandler9C // EOI on master and slave needed mov $0x61, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // Int 10 interrupts .global IntHandler10 IntHandler10: pusha pushf cli call IntHandler10C // EOI on master and slave needed mov $0x62, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // Int 11 interrupts .global IntHandlerI2C IntHandlerI2C: pusha pushf cli call IntHandlerCI2C // EOI on master and slave needed mov $0x63, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // Int 12 interrupts .global IntHandlerSmc IntHandlerSmc: cli pusha pushf call IntHandlerCSmc // acknowledge EXTSMI# action (from PIC p6) mov $0x8020, %dx inw %dx, %ax or $0x0200, %ax outw %ax, %dx // EOI on master and slave needed mov $0x64, %al // is int12 out %al, $0xa0 mov $0x62, %al // do cascaded master out %al, $0x20 popf popa iret // Int 13 interrupts .global IntHandler13 IntHandler13: cli pusha pushf call IntHandler13C // EOI on master and slave needed mov $0x65, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // Int 14 interrupts .global IntHandlerIde IntHandlerIde: cli pusha pushf call IntHandlerCIde // EOI on master and slave needed mov $0x66, %al // was $0x20 out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // Int 15 interrupts .global IntHandler15 IntHandler15: cli pusha pushf call IntHandler15C // EOI on master and slave needed mov $0x67, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret // unused interrupts on master PIC .global IntHandlerUnused IntHandlerUnused: cli pusha pushf call IntHandlerUnusedC mov $0x20, %al out %al, $0x20 popf popa iret // unused interrupts on slave PIC .global IntHandlerUnusedPic2 IntHandlerUnusedPic2: cli pusha pushf call IntHandlerUnusedC2 mov $0xffff, %ax mov $0x8028, %dx outw %ax, %dx mov $0x80cc, %dx mov $0x40, %al outb %al, %dx mov $0x20, %al out %al, $0xa0 mov $0x62, %al out %al, $0x20 popf popa iret .global SpareIntNop SpareIntNop: iret // CPU Exception Interrupts .global IntHandlerException0 IntHandlerException0: pusha pushf cli call IntHandlerException0C popf popa iret .global IntHandlerException1 IntHandlerException1: pusha pushf cli call IntHandlerException1C popf popa iret .global IntHandlerException2 IntHandlerException2: pusha pushf cli call IntHandlerException2C popf popa iret .global IntHandlerException3 IntHandlerException3: pusha pushf cli call IntHandlerException3C popf popa iret .global IntHandlerException4 IntHandlerException4: pusha pushf cli call IntHandlerException4C popf popa iret .global IntHandlerException5 IntHandlerException5: pusha pushf cli call IntHandlerException5C popf popa iret .global IntHandlerException6 IntHandlerException6: pusha pushf cli call IntHandlerException6C popf popa iret .global IntHandlerException7 IntHandlerException7: pusha pushf cli call IntHandlerException7C popf popa iret .global IntHandlerException8 IntHandlerException8: pusha pushf cli call IntHandlerException8C popf popa iret .global IntHandlerException9 IntHandlerException9: pusha pushf cli call IntHandlerException9C popf popa iret .global IntHandlerExceptionA IntHandlerExceptionA: pusha pushf cli call IntHandlerExceptionAC popf popa iret .global IntHandlerExceptionB IntHandlerExceptionB: pusha pushf cli call IntHandlerExceptionBC popf popa iret .global IntHandlerExceptionC IntHandlerExceptionC: pusha pushf cli call IntHandlerExceptionCC popf popa iret .global IntHandlerExceptionD IntHandlerExceptionD: pusha pushf cli call IntHandlerExceptionDC popf popa iret .global IntHandlerExceptionE IntHandlerExceptionE: pusha pushf cli call IntHandlerExceptionEC popf popa iret .global IntHandlerExceptionF IntHandlerExceptionF: pusha pushf cli call IntHandlerExceptionFC popf popa iret .global IntHandlerException10 IntHandlerException10: pusha pushf cli call IntHandlerException10C popf popa iret
XboxDev/cromwell
9,409
boot_rom/2bBootStartup.S
/* * * BIOS ROM Startup Assembler * (C)2002 Andy, Michael, Paul, Steve * Original top and bottom ROM code by Steve from an idea by Michael * -- NOTE: Comment removed, the top / bottom Code changed to turnaround code. */ /*************************************************************************** * * * 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* Rewritten from Original .bin linking to compiler system by Lehner Franz (franz@caos.at) Rewritten to Dual Boot concept for 2BL loading New written CPU Inits by Lehner Franz (franz@caos.at) Written New Working Xcodes + Xcode compiler by Lehner Franz (franz@caos.at) Focus support by Lehner Franz (franz@caos.at) Xcalibur support by Lehner Franz (franz@caos.at) */ #include "2bconsts.h" #define xcode_peek(val1) .byte 0x2; .long val1 ; .long 0x0 ; #define xcode_poke(val1,val2) .byte 0x3; .long val1 ; .long val2 ; #define xcode_pciout(val1,val2) .byte 0x4; .long val1 ; .long val2 ; #define xcode_pciin_a(val1) .byte 0x5; .long val1 ; .long 0x0 ; #define xcode_bittoggle(val1,val2) .byte 0x6; .long val1 ; .long val2 ; #define xcode_ifgoto(val1,val2) .byte 0x8; .long val1 ; .long (9*(val2-1)) ; #define xcode_outb(val1,val2) .byte 0x11; .long val1 ; .long val2 ; #define xcode_inb(val1) .byte 0x12; .long val1 ; .long 0x0 ; #define xcode_poke_a(val1) .byte 0x7; .long 0x3; .long val1 ; #define xcode_pciout_a(val1) .byte 0x7; .long 0x4; .long val1 ; #define xcode_outb_a(val1) .byte 0x7; .long 0x11; .long val1 ; #define xcode_goto(val1) .byte 0x9; .long 0x0; .long (9*(val1-1)); #define xcode_END(val1) .byte 0xEE; .long val1 ; .long 0x0; #define SMBUS 0x0000c000 #define SMB_xcode_Write(val1,val2); xcode_outb(SMBUS+8, val1); \ xcode_outb(SMBUS+6, val2); \ xcode_outb(SMBUS+2, 0x0000000a); \ xcode_inb(SMBUS); \ xcode_ifgoto(0x00000010,-1); \ xcode_outb(SMBUS, 0x00000010); .code32 .section .low_rom, "ax" .org 0x0 /* MCPX Magic Values - clock timings*/ .long 0xff000009 .long 0xff000008 .long 0x2b16d065 .long 0x3346322d .long 0x01010101 .long 0x08080808 .long 0x00000801 #ifndef MCPXREVD5 .long 0xc8fc7c8a // MCPX =< D5 .long 0x44290213 .long 0x90004998 .long 0x00000000 #else .long 0xc8b4588a // MCPX 1.6 > D5 .long 0x00100000 .long 0x00050aa7 .long 0xf0000000 #endif .long 0xffffffff .long 0xffffffff .org 0x40 .long _start_checksum // This number will be overwritten // With imagebld, but we need a temp value .org 0x6c .long 0x00000107 .org 0x70 // MCPX Config Area .long 0x0000000f .long 0x40004400 #ifndef MCPXREVD5 .long 0x12d10070 .long 0x00000c90 #else .long 0x16ce0090 .long 0x00000dc0 #endif //The bytecode interpreter begins here .org 0x80 #include "Xcodes.h" // Note: never change this from offset 0x1000 .... // This is the Main Entry point .... .org 0x1000 // Good Morning CPU // NOTE: /* We come here form the high rom section Jump */ // Clear Intel Interrupts in Processor Register // Everytime very good, specially when comming out of a running envoronment movl $0x1b, %ecx xor %eax, %eax xor %edx, %edx wrmsr // Interrupts now Dead xor %eax, %eax xor %edx, %edx xor %ecx, %ecx // kill the cache = Disable bit 30 + 29 = CD + NW // CD = Cache Disable (disable = 1) // NW Not write through (disable = 1) mov %cr0, %eax orl $0x60000000, %eax mov %eax, %cr0 wbinvd // We clear the cr3 register mov %eax, %eax mov %eax, %cr3 // Clear Memory Type register movl $0x2ff, %ecx xor %eax, %eax xor %edx, %edx wrmsr /* We are setting the Ram Init's now to set up the Regions in the Ram */ // MTRR for RAM // from address 0, Writeback Caching, 128MB range movl $0x200, %ecx movl $0x00000000, %edx movl $0x00000006, %eax // == WB_CACHE == 6 //movl $0x00000004, %eax // Temporary, as USB development wrmsr // MASK0 set to 0xf8000[000] == 128M movl $0x201, %ecx movl $0x0000000f, %edx movl $0xf8000800, %eax wrmsr // MTRR for shadow RAM // from address 0xf0000000, Write-combining Caching, 128MB range movl $0x202, %ecx movl $0x00000000, %edx movl $0xf0000001, %eax // Write-Combining == 1 wrmsr // MASK0 set to 0xf8000[000] == 128M movl $0x203, %ecx movl $0x0000000f, %edx movl $0xf8000800, %eax wrmsr // MTRR for FLASH movl $0x204, %ecx movl $0x00000000, %edx movl $0xFff00000, %eax // We set to Uncacheable wrmsr movl $0x205, %ecx movl $0x0000000f, %edx movl $0xfff00800, %eax wrmsr xor %eax, %eax xor %edx, %edx movl $0x206, %ecx // IA32_MTRR_PHYS Base 3 wrmsr movl $0x207, %ecx // IA32_MTRR_PHYS_MASK 3 wrmsr movl $0x208, %ecx // IA32_MTRR_PHYS Base 4 wrmsr movl $0x209, %ecx // IA32_MTRR_PHYS_MASK 4 wrmsr movl $0x20a, %ecx // IA32_MTRR_PHYS Base 5 wrmsr movl $0x20b, %ecx // IA32_MTRR_PHYS_MASK 5 wrmsr movl $0x20c, %ecx // IA32_MTRR_PHYS Base 6 wrmsr movl $0x20d, %ecx // IA32_MTRR_PHYS_MASK 6 wrmsr movl $0x20e, %ecx // IA32_MTRR_PHYS Base 7 wrmsr movl $0x20f, %ecx // IA32_MTRR_PHYS_MASK 7 wrmsr // Define Memory in IA32_MTRR_DEF_TYPE movl $0x2ff, %ecx xor %edx, %edx movl $0x800, %eax //Enable MTRRs wrmsr /* turn on normal cache */ // bit 30 + 29 = CD + NW // CD = Cache Disable (disable = 1) // NW Not write through (disable = 1) movl %cr0, %eax mov %eax, %ebx andl $0x9FFFFFFF,%eax movl %eax, %cr0 cld // copy everything into RAM mov $_ram_location, %edi mov $_start_ramcopy, %esi mov $(_size_ramcopy + 100), %ecx shr $2,%ecx // We dividy / 4, as we copy Dword oriented rep movsl jmp initaftermemcpy /* We leave Flash at this point, we never come back to it anymore. the following ASM instructions below, already are linked to memory (look to the ldscript in this case) */ .section .text, "ax" // Note: We are in Memory here, not in Flash anylonger, // we have been copy'd here and linked for memory, as we reside in section .text // Look to LDscript .global MemoryChecksum MemoryChecksum: // The SHA-1 Hashsum is dumped here after with ImageBLD .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00 .long _size_sha1hash .long 0x00 // Will be dumped in by imagebld ->compressed_image_start; .long 0x00 // Will be dumped in by imagebld ->compressed_image_size; .long 0x00 // Will be dumped in by imagebld ->0 .. 256kb image, 1 .. 1MB image .org 0x40 // We have linkbase for this programm = 0x100000 + 0x40 = divisable /4 .. so CPU likes it tableGdt: .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 0x00 dummy .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9b, 0xcf, 0x00 // 0x08 code32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9b, 0xcf, 0x00 // 0x10 code32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x93, 0xcf, 0x00 // 0x18 data32 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9b, 0x8f, 0x00 // 0x20 code16 (8f indicates 4K granularity, ie, huge limit) .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x93, 0x8f, 0x00 // 0x28 data16 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Dummy tableGdtDescriptor: .word 0x30 .long tableGdt .word 0x0 // fill Word, so we get alliged again tableIdtDescriptor: .word 2048 .long 0x400000 .word 0x0 // fill Word, so we get alliged again initaftermemcpy: /* These Init Codes Can be found in the 2'nd Bootloader */ // We set up a GDT now, this is not necessary needed, // but it is preferred, as we have more ability with commands // We clear the IDT in RAM xor %eax,%eax mov $0x5000,%ecx mov $0x400000,%edi rep stosb lidt tableIdtDescriptor lgdt tableGdtDescriptor // set up selectors for everything xor %eax, %eax lldt %ax // Reload CS as 0010 from the new GDT using a far jump .byte 0xEA // jmp far 0010:reload_cs .long reload_cs .word 0x0010 .align 16 reload_cs: // CS is now a valid entry in the GDT. Set SS, DS, and ES to valid // descriptors, but clear FS and GS as they are not necessary. // Set SS, DS, and ES to a data32 segment with maximum limit. movw $0x0018, %ax mov %eax, %ss mov %eax, %ds mov %eax, %es // Clear FS and GS xor %eax, %eax mov %eax, %fs mov %eax, %gs // Set the stack pointer to give us a valid stack movl $0x1ffff0, %esp // Clear out .bss xor %eax, %eax mov $BSS_SIZE_L, %ecx mov $BSS_BASE, %edi rep stosl mov $0x8, %al mov $0x61, %dx out %al, %dx // Enable IDE and NIC mov $0x8000088C, %eax movw $0xcf8, %dx outl %eax, %dx movw $0xcfc, %dx movl $0x40000000, %eax outl %eax, %dx // CPU Whoami ? sesless ? mov $0x80000080, %eax movw $0xcf8, %dx outl %eax, %dx movw $0xcfc, %dx movl $0x100, %eax outl %eax, %dx // this can be found in BootResetAction.c jmp BootStartBiosLoader
XboxDev/cromwell
10,561
boot_xbe/xbe.S
#define BASE_ADDRESS 0x10000 #define FILE_SIZE (0x4000+0x40000) header_start: .ascii "XBEH" // digital signature .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long BASE_ADDRESS // base address .long headers_end - header_start // size of headers .long FILE_SIZE+1024 // size of image .long header_end - header_start // size of image header .long 0 // time date stamp *unimportant* .long certificate // certificate address .long 1 // number of section headers .long section_headers // section headers address .long 0 // initialization flags .long 0x11100 ^ 0xA8FC57AB // entry point address XOR key **GAS ISSUE: "entry" won't work** .long 0x18000 // thread local storage address .long 0 // size of stack commit (PE copy) *unimportant* .long 0 // size of heap reserve (PE copy) *unimportant* .long 0 // size of heap commit (PE copy) *unimportant* .long 0 // original base address (PE copy) *unimportant* .long 0 // original size of image (PE copy)*unimportant* .long 0 // original checksum (PE copy) *unimportant* .long 0 // original time stamp (PE copy) *unimportant* .long normalname // debug path name address *unimportant* .long normalname // debug file name address *unimportant* .long unicodename // debug unicode file name address *unimportant* .long 0x11000 ^ 0x5B6D40B6 // kernel image thunk address XOR key **GAS ISSUE: see above** .long 0 // non-kernel import directory address .long 0 // number of library versions *unimportant* .long 0 // library versions address *unimportant* .long 0 // kernel library version address *unimportant* .long 0 // XAPI library address *unimportant* .long logo // logo bitmap address *unimportant* .long logo_end-logo // logo bitmap size *unimportant* header_end: certificate: .long certificate_end - certificate // size of certificate .long 0 // time date stamp *unimportant* .long 0 // title id *unimportant?* // title name (unicode string, 40 chars) *unimportant, but beautiful* unicodename: .word 'X','r','o','m','w','e','l','l',0,0,0 normalname: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0 // alternate title ids .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0xC0000005 .long 0x80000007 // game regions: all; don't delete eepromkey .long -1 // game ratings .long 0 // disk number .long 0 // version // LAN key .long 0,0,0,0 // signature key .long 0,0,0,0 // 16 title alternate signature keys .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 certificate_end: section_headers: // .long 0x16 // flags: RO_HEAD_PAGE, EXECUTABLE, PRELOAD .long 0x07 // flags: WRITABLE, EXECUTABLE, PRELOAD .long section_1_start // virtual address .long FILE_SIZE // virtual size .long 0x1000 // file pointer to raw data .long FILE_SIZE // size of raw data .long section_name // address of section name .long 0 // unknown .long rc1 // head shared page reference count address *not NULL important* .long rc2 // tail shared page reference count address *not NULL important* // unknown .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0 section_headers_end: rc1: .word 0 rc2: .word 0 section_name: .byte '.','t','e','x','t',0 .align 4 logo: // "Linux" .byte 0x52, 0x00, 0x13, 0x73, 0xB3, 0xF3, 0xF5, 0xE3 .byte 0xD3, 0xE3, 0x63, 0x03, 0x03, 0x03, 0x03, 0x07 .byte 0x03, 0x03, 0x13, 0x43, 0x33, 0x13, 0x03, 0x96 .byte 0x00, 0x9A, 0x00, 0x03, 0x03, 0x13, 0x33, 0xB3 .byte 0xF3, 0xF3, 0xF3, 0x93, 0x43, 0x23, 0x13, 0x03 .byte 0x03, 0x09, 0x03, 0x03, 0x73, 0x93, 0x83, 0x33 .byte 0x13, 0x03, 0x92, 0x00, 0x9A, 0x00, 0x03, 0x03 .byte 0x03, 0x23, 0x63, 0xF5, 0xE3, 0x73, 0x43, 0x23 .byte 0x13, 0x03, 0x03, 0x09, 0x03, 0x03, 0x73, 0x93 .byte 0x83, 0x33, 0x13, 0x03, 0x03, 0x09, 0x03, 0x05 .byte 0x09, 0x0B, 0x05, 0x03, 0x03, 0x05, 0x05, 0x07 .byte 0x03, 0x0B, 0x05, 0x9A, 0x00, 0x03, 0x03, 0x03 .byte 0x13, 0x63, 0xF5, 0xE3, 0x73, 0x43, 0x23, 0x03 .byte 0x03, 0x0B, 0x03, 0x13, 0x33, 0x53, 0x53, 0x33 .byte 0x13, 0x03, 0x03, 0x05, 0x03, 0x03, 0x05, 0x03 .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x05, 0x03, 0x03 .byte 0x03, 0x03, 0x05, 0x03, 0x03, 0x05, 0x03, 0x03 .byte 0x03, 0x9A, 0x00, 0x03, 0x03, 0x03, 0x13, 0x53 .byte 0xF5, 0xD3, 0x73, 0x33, 0x13, 0x03, 0x05, 0x03 .byte 0x05, 0x03, 0x03, 0x23, 0x33, 0x33, 0x33, 0x23 .byte 0x23, 0x23, 0x23, 0x35, 0x23, 0x33, 0x33, 0x33 .byte 0x23, 0x05, 0x03, 0x13, 0x35, 0x33, 0x23, 0x13 .byte 0x25, 0x23, 0x33, 0x23, 0x13, 0x13, 0x33, 0x33 .byte 0x35, 0x33, 0x23, 0x23, 0x33, 0x33, 0x13, 0x03 .byte 0x03, 0x9A, 0x00, 0x03, 0x03, 0x03, 0x03, 0x53 .byte 0xF5, 0xD3, 0x73, 0x33, 0x13, 0x03, 0x03, 0x03 .byte 0x05, 0x03, 0x03, 0x53, 0x83, 0x73, 0x43, 0x23 .byte 0x13, 0x63, 0x93, 0xD3, 0xF3, 0xE3, 0xB3, 0xB3 .byte 0xA3, 0xE3, 0xA3, 0x43, 0x13, 0x23, 0x93, 0xF3 .byte 0xE3, 0xF3, 0x83, 0x43, 0x83, 0x93, 0xD3, 0xF3 .byte 0x93, 0x13, 0x33, 0xB3, 0xF7, 0xB3, 0x43, 0xA3 .byte 0xF3, 0xE3, 0x53, 0x13, 0x03, 0x9A, 0x00, 0x03 .byte 0x03, 0x03, 0x03, 0x53, 0xF5, 0xD3, 0x63, 0x33 .byte 0x13, 0x03, 0x05, 0x03, 0x03, 0x03, 0x63, 0x83 .byte 0x53, 0x93, 0x83, 0x33, 0x23, 0x13, 0x23, 0xD3 .byte 0xF3, 0xF3, 0xD3, 0x53, 0x33, 0xC3, 0xF3, 0xD3 .byte 0x43, 0x33, 0x53, 0x93, 0xF3, 0xF3, 0xA3, 0x43 .byte 0x23, 0x73, 0xF5, 0xC3, 0x33, 0x23, 0x23, 0xA3 .byte 0xF5, 0x83, 0x43, 0x73, 0xD3, 0x63, 0x23, 0x13 .byte 0x03, 0x9A, 0x00, 0x03, 0x03, 0x03, 0x03, 0x53 .byte 0xF5, 0xD3, 0x63, 0x33, 0x13, 0x03, 0x03, 0x03 .byte 0x05, 0x13, 0x83, 0x43, 0x63, 0x93, 0x83, 0x53 .byte 0x33, 0x13, 0x33, 0xC3, 0xF3, 0xF3, 0x83, 0x53 .byte 0x33, 0xA3, 0xF3, 0xF3, 0x73, 0x33, 0x23, 0x43 .byte 0xE3, 0xF3, 0xB3, 0x53, 0x33, 0x83, 0xF5, 0xC3 .byte 0x53, 0x33, 0x23, 0x43, 0xD3, 0xF3, 0xE3, 0x83 .byte 0xD3, 0x83, 0x33, 0x23, 0x13, 0x03, 0x9A, 0x00 .byte 0x03, 0x03, 0x03, 0x03, 0x53, 0xF5, 0xD3, 0x63 .byte 0x33, 0x13, 0x03, 0x05, 0x03, 0x73, 0x33, 0x43 .byte 0x33, 0x73, 0x93, 0x83, 0x53, 0x33, 0x13, 0x23 .byte 0xB3, 0xF3, 0xF3, 0x83, 0x53, 0x33, 0x93, 0xF3 .byte 0xF3, 0x83, 0x33, 0x23, 0x43, 0xF3, 0xF3, 0xB3 .byte 0x53, 0x33, 0x93, 0xF5, 0xC3, 0x53, 0x33, 0x13 .byte 0x23, 0x73, 0xF5, 0xE3, 0xC3, 0x53, 0x33, 0x23 .byte 0x03, 0x03, 0x9A, 0x00, 0x03, 0x03, 0x03, 0x13 .byte 0x53, 0xF5, 0xD3, 0x63, 0x33, 0x13, 0x03, 0x03 .byte 0x03, 0x03, 0xA3, 0x53, 0x23, 0x53, 0x93, 0x93 .byte 0x83, 0x53, 0x33, 0x13, 0x23, 0xC3, 0xF3, 0xE3 .byte 0x83, 0x43, 0x23, 0x93, 0xF3, 0xF3, 0x83, 0x43 .byte 0x23, 0x43, 0xF5, 0xA3, 0x53, 0x33, 0x73, 0xF5 .byte 0xC3, 0x53, 0x33, 0x13, 0x13, 0x23, 0xB3, 0xF3 .byte 0xF3, 0xA3, 0x53, 0x33, 0x13, 0x03, 0x03, 0x9A .byte 0x00, 0x03, 0x03, 0x03, 0x03, 0x53, 0xF5, 0xD3 .byte 0x73, 0x33, 0x13, 0x03, 0x03, 0x03, 0x03, 0xB3 .byte 0x63, 0x33, 0x63, 0x93, 0x93, 0x73, 0x53, 0x33 .byte 0x13, 0x23, 0xC3, 0xF3, 0xE3, 0x73, 0x43, 0x23 .byte 0x93, 0xF3, 0xF3, 0x83, 0x43, 0x23, 0x43, 0xF5 .byte 0xA3, 0x53, 0x33, 0x73, 0xF3, 0xF3, 0xC3, 0x53 .byte 0x33, 0x13, 0x13, 0x13, 0x73, 0xF3, 0xF3, 0xE3 .byte 0x73, 0x33, 0x13, 0x03, 0x03, 0x9A, 0x00, 0x03 .byte 0x03, 0x03, 0x03, 0x53, 0xF5, 0xD3, 0x63, 0x33 .byte 0x13, 0x03, 0x03, 0x03, 0x33, 0xE3, 0x63, 0x43 .byte 0x83, 0x93, 0x83, 0x73, 0x73, 0x53, 0x13, 0x23 .byte 0xC3, 0xF3, 0xD3, 0x73, 0x33, 0x13, 0x93, 0xF3 .byte 0xF3, 0x73, 0x43, 0x23, 0x43, 0xF5, 0xA3, 0x53 .byte 0x23, 0x73, 0xF5, 0xC3, 0x53, 0x33, 0x13, 0x03 .byte 0x03, 0x83, 0xC3, 0xF3, 0xF3, 0xC3, 0x43, 0x23 .byte 0x03, 0x03, 0x9A, 0x00, 0x05, 0x03, 0x03, 0x53 .byte 0xF5, 0xE3, 0x73, 0x33, 0x13, 0x03, 0x05, 0x83 .byte 0xF3, 0x73, 0x53, 0x93, 0x93, 0x83, 0x73, 0x83 .byte 0x43, 0x23, 0x33, 0xC3, 0xF3, 0xD3, 0x73, 0x43 .byte 0x23, 0x93, 0xF3, 0xF3, 0x73, 0x43, 0x23, 0x43 .byte 0xF5, 0xA3, 0x53, 0x33, 0x83, 0xF5, 0xC3, 0x53 .byte 0x33, 0x13, 0x03, 0x63, 0xE3, 0x73, 0xB3, 0xF5 .byte 0x83, 0x33, 0x13, 0x03, 0x9A, 0x00, 0x05, 0x03 .byte 0x03, 0x63, 0xF5, 0xF3, 0x73, 0x33, 0x13, 0x03 .byte 0x23, 0x73, 0xF3, 0xF3, 0x73, 0x63, 0x93, 0x93 .byte 0x83, 0x83, 0x73, 0x33, 0x23, 0x23, 0xD3, 0xF3 .byte 0xD3, 0x63, 0x33, 0x13, 0x93, 0xF3, 0xF3, 0x63 .byte 0x33, 0x23, 0x43, 0xF3, 0xF3, 0xB3, 0x53, 0x43 .byte 0xA3, 0xF5, 0xC3, 0x53, 0x33, 0x03, 0x23, 0xB3 .byte 0x83, 0x43, 0x63, 0xD3, 0xF3, 0xE3, 0x53, 0x23 .byte 0x13, 0x9E, 0x00, 0x13, 0x63, 0x83, 0xC3, 0xF3 .byte 0xF5, 0xA3, 0x83, 0x73, 0x73, 0xC3, 0xF7, 0x83 .byte 0x53, 0x83, 0x93, 0x93, 0x83, 0x53, 0x33, 0x53 .byte 0x83, 0xF5, 0xE3, 0xA3, 0x53, 0x63, 0xD3, 0xF3 .byte 0xF3, 0xA3, 0x63, 0x23, 0x23, 0x93, 0xF3, 0xF3 .byte 0xB3, 0x93, 0xB3, 0xF3, 0xF3, 0xE3, 0x83, 0x53 .byte 0x73, 0xA3, 0xF3, 0xC3, 0x63, 0x73, 0xB3, 0xF5 .byte 0xC3, 0x63, 0x23, 0x9E, 0x00, 0x13, 0x63, 0x75 .byte 0x83, 0x93, 0x83, 0x83, 0x73, 0x63, 0x73, 0x73 .byte 0x83, 0x83, 0x93, 0x63, 0x43, 0x43, 0x63, 0x63 .byte 0x53, 0x33, 0x23, 0x43, 0x63, 0x73, 0x83, 0x93 .byte 0x83, 0x53, 0x63, 0x83, 0x83, 0x93, 0x93, 0x53 .byte 0x23, 0x13, 0x33, 0x73, 0xA3, 0xA3, 0x73, 0x43 .byte 0x83, 0xA3, 0x93, 0x73, 0x43, 0x73, 0x73, 0x73 .byte 0x93, 0x53, 0x53, 0x73, 0x83, 0x93, 0x93, 0x63 .byte 0x23, 0x9A, 0x00, 0x03, 0x03, 0x03, 0x13, 0x23 .byte 0x33, 0x43, 0x43, 0x33, 0x23, 0x13, 0x13, 0x23 .byte 0x23, 0x35, 0x33, 0x23, 0x23, 0x23, 0x33, 0x33 .byte 0x23, 0x13, 0x13, 0x13, 0x23, 0x33, 0x33, 0x33 .byte 0x23, 0x13, 0x23, 0x33, 0x33, 0x33, 0x23, 0x13 .byte 0x13, 0x13, 0x23, 0x33, 0x33, 0x33, 0x35, 0x45 .byte 0x33, 0x23, 0x13, 0x13, 0x23, 0x23, 0x23, 0x23 .byte 0x23, 0x33, 0x33, 0x33, 0x23, 0x13, 0x4E, 0x00 logo_end: .align 4 headers_end:
XboxDev/cromwell
26,002
boot_xbe/font.S
// This 256 character 8x16 VGA font (IBM codepage 437) was taken from // /usr/lib/kbd/consolefonts/default8x16.psf.gz in Linux Mandrake 8.2 font: .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7E, 0x81, 0xA5, 0x81, 0x81, 0xBD, 0x99, 0x81, 0x81, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7E, 0xFF, 0xDB, 0xFF, 0xFF, 0xC3, 0xE7, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x6C, 0xFE, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0xE7, 0xE7, 0xE7, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF .byte 0x00, 0x00, 0x1E, 0x0E, 0x1A, 0x32, 0x78, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x30, 0x30, 0x70, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x63, 0x63, 0x67, 0xE7, 0xE6, 0xC0, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x18, 0x18, 0xDB, 0x3C, 0xE7, 0x3C, 0xDB, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFE, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x02, 0x06, 0x0E, 0x1E, 0x3E, 0xFE, 0x3E, 0x1E, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7F, 0xDB, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x7C, 0xC6, 0x60, 0x38, 0x6C, 0xC6, 0xC6, 0x6C, 0x38, 0x0C, 0xC6, 0x7C, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x6C, 0x6C, 0xFE, 0x6C, 0x6C, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x18, 0x7C, 0xC6, 0xC2, 0xC0, 0x7C, 0x06, 0x06, 0x86, 0xC6, 0x7C, 0x18, 0x18, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0xC2, 0xC6, 0x0C, 0x18, 0x30, 0x60, 0xC6, 0x86, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0x06, 0x06, 0x3C, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x0C, 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x0C, 0x0C, 0x1E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFE, 0xC0, 0xC0, 0xC0, 0xFC, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x38, 0x60, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFE, 0xC6, 0x06, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x06, 0x06, 0x0C, 0x78, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x0C, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xDE, 0xDE, 0xDE, 0xDC, 0xC0, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x66, 0x66, 0xFC, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC0, 0xC0, 0xC2, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFE, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xDE, 0xC6, 0xC6, 0x66, 0x3A, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0xCC, 0x78, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xE6, 0x66, 0x66, 0x6C, 0x78, 0x78, 0x6C, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xF0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0xE7, 0xFF, 0xFF, 0xDB, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, 0xCE, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xDE, 0x7C, 0x0C, 0x0E, 0x00, 0x00 .byte 0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0x60, 0x38, 0x0C, 0x06, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFF, 0xDB, 0x99, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xDB, 0xDB, 0xFF, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0xC3, 0x66, 0x3C, 0x18, 0x18, 0x3C, 0x66, 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0xC3, 0xC3, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFF, 0xC3, 0x86, 0x0C, 0x18, 0x30, 0x60, 0xC1, 0xC3, 0xFF, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0x0E, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00 .byte 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xE0, 0x60, 0x60, 0x78, 0x6C, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x1C, 0x0C, 0x0C, 0x3C, 0x6C, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xCC, 0x78, 0x00 .byte 0x00, 0x00, 0xE0, 0x60, 0x60, 0x6C, 0x76, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x06, 0x06, 0x00, 0x0E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00 .byte 0x00, 0x00, 0xE0, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x78, 0x6C, 0x66, 0xE6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0xFF, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0x0C, 0x1E, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0x60, 0x60, 0xF0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xC6, 0x60, 0x38, 0x0C, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x10, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xC3, 0x66, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3, 0xC3, 0xDB, 0xDB, 0xFF, 0x66, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0xC3, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0xF8, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xCC, 0x18, 0x30, 0x60, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x0E, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3C, 0x66, 0xC2, 0xC0, 0xC0, 0xC0, 0xC2, 0x66, 0x3C, 0x0C, 0x06, 0x7C, 0x00, 0x00 .byte 0x00, 0x00, 0xCC, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x0C, 0x18, 0x30, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x10, 0x38, 0x6C, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xCC, 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x38, 0x6C, 0x38, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x60, 0x66, 0x3C, 0x0C, 0x06, 0x3C, 0x00, 0x00, 0x00 .byte 0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0x00, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x18, 0x3C, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0xC6, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x38, 0x6C, 0x38, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x30, 0x60, 0x00, 0xFE, 0x66, 0x60, 0x7C, 0x60, 0x60, 0x66, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x3B, 0x1B, 0x7E, 0xD8, 0xDC, 0x77, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x3E, 0x6C, 0xCC, 0xCC, 0xFE, 0xCC, 0xCC, 0xCC, 0xCC, 0xCE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x10, 0x38, 0x6C, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x60, 0x30, 0x18, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x30, 0x78, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x60, 0x30, 0x18, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC6, 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0x0C, 0x78, 0x00 .byte 0x00, 0xC6, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x18, 0x18, 0x7E, 0xC3, 0xC0, 0xC0, 0xC0, 0xC3, 0x7E, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x38, 0x6C, 0x64, 0x60, 0xF0, 0x60, 0x60, 0x60, 0x60, 0xE6, 0xFC, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xC3, 0x66, 0x3C, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0xFC, 0x66, 0x66, 0x7C, 0x62, 0x66, 0x6F, 0x66, 0x66, 0x66, 0xF3, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x0E, 0x1B, 0x18, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0x70, 0x00, 0x00 .byte 0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x0C, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x18, 0x30, 0x60, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x18, 0x30, 0x60, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x76, 0xDC, 0x00, 0xDC, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00 .byte 0x76, 0xDC, 0x00, 0xC6, 0xE6, 0xF6, 0xFE, 0xDE, 0xCE, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xC0, 0xC6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0xC0, 0xC0, 0xC2, 0xC6, 0xCC, 0x18, 0x30, 0x60, 0xCE, 0x9B, 0x06, 0x0C, 0x1F, 0x00, 0x00 .byte 0x00, 0xC0, 0xC0, 0xC2, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xCE, 0x96, 0x3E, 0x06, 0x06, 0x00, 0x00 .byte 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C, 0x3C, 0x3C, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6C, 0xD8, 0x6C, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x6C, 0x36, 0x6C, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44 .byte 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA .byte 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF .byte 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0 .byte 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F .byte 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0xD8, 0xD8, 0xD8, 0xDC, 0x76, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0xD8, 0xCC, 0xC6, 0xC6, 0xC6, 0xCC, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xFE, 0xC6, 0xC6, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0xFE, 0xC6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xC6, 0xFE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0xD8, 0xD8, 0x70, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xC0, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x7E, 0x18, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x6C, 0x6C, 0x6C, 0xEE, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x1E, 0x30, 0x18, 0x0C, 0x3E, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0xDB, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x03, 0x06, 0x7E, 0xDB, 0xDB, 0xF3, 0x7E, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x1C, 0x30, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x30, 0x1C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x0E, 0x1B, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 .byte 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0xD8, 0x70, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x6C, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0xD8, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x70, 0xD8, 0x30, 0x60, 0xC8, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
XboxDev/cromwell
13,330
boot_xbe/xbeboot.S
// Xbox Linux XBE Bootloader // // Copyright (C) 2002 Michael Steil & anonymous // // 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 2 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. // // The latest version of the GPL can be retrieved at: // http://www.gnu.org/licenses/gpl.html . // // Xbox is a trademark or registered trademark of Microsoft Corporation. // No relationship between the author(s) and Microsoft Corporation exists or is // implied. // Constants // Size of a page on x86 #define PAGE_SIZE 4096 // Win32 read/write protection mode. x86 has no flag for executability. #define PAGE_READWRITE 4 // Final address of Linux kernel in RAM #define KERNEL_ADDRESS 0x00100000 // Minimum physical address at which the kernel can reside temporarily #define MIN_KERNEL_ADDRESS KERNEL_ADDRESS // Memory reserved to the kernel (1 MB at the moment) #define KERNEL_MAX_SIZE 0x00100000 // 1MB maximum Kernel for Cromwell // Location of kernel in RAM #define KERNEL_RAM_ADDRESS 0x03A00000 // Size of memory on a retail XBOX unit #define RETAIL_RAM_SIZE 0x04000000 // Reserve pages in address space #define MEM_RESERVE 0x00002000 // Commit physical memory to pages #define MEM_COMMIT 0x00001000 // CR0 bit to block write-through #define CR0_DISABLE_WRITE_THROUGH 0x20000000 // CR0 bit to disable caching #define CR0_DISABLE_CACHE 0x40000000 // CR0 bit to enable paging #define CR0_ENABLE_PAGING 0x80000000 #define FRAMEBUFFER 0xF0040240 #define TEXTBUFFER (FRAMEBUFFER + 80 * 640 * 4) //#define DebugOut /* located within bootsect space (copied from arch/i386/setup.c) */ /* originally defined mostly in arch/i386/kernel/setup.c and head.S */ PARAM = 0 SCREEN_INFO = PARAM+0 EXT_MEM_K = PARAM+2 CL_MAGIC = PARAM+0x20 CL_OFFSET = PARAM+0x22 ALT_MEM_K = PARAM+0x01e0 APM_BIOS_INFO = PARAM+0x0040 DRIVE_INFO = PARAM+0x0080 SYS_DESC_TABLE = PARAM+0x00A0 SETUP_SECTS = PARAM+0x01F1 MOUNT_ROOT_RDO = PARAM+0x01F2 SYSSIZE = PARAM+0x01F4 RAMDISK_FLAGS = PARAM+0x01F8 ORIG_ROOT_DEV = PARAM+0x01FC AUX_DEVICE_INFO = PARAM+0x01FF /* located within and following the setup space: */ LOADER_TYPE = PARAM+0x0210 LOAD_FLAGS = PARAM+0x0211 KERNEL_START = PARAM+0x0214 INITRD_START = PARAM+0x0218 INITRD_SIZE = PARAM+0x021C COMMAND_LINE = PARAM+0x0800 REL_COMMAND_LINE = 0x0800 PARAM_CURSOR_POS = PARAM+0x00 PARAM_VIDEO_PAGE = PARAM+0x04 PARAM_VIDEO_MODE = PARAM+0x06 PARAM_VIDEO_COLS = PARAM+0x07 PARAM_VIDEO_EGA_BX = PARAM+0x0a PARAM_VIDEO_LINES = PARAM+0x0e PARAM_HAVE_VGA = PARAM+0x0f PARAM_FONT_POINTS = PARAM+0x10 PARAM_LFB_WIDTH = PARAM+0x12 PARAM_LFB_HEIGHT = PARAM+0x14 PARAM_LFB_DEPTH = PARAM+0x16 PARAM_LFB_BASE = PARAM+0x18 PARAM_LFB_SIZE = PARAM+0x1c PARAM_LFB_LINELENGTH = PARAM+0x24 PARAM_LFB_COLORS = PARAM+0x26 PARAM_VESAPM_SEG = PARAM+0x2e PARAM_VESAPM_OFF = PARAM+0x30 PARAM_LFB_PAGES = PARAM+0x32 .code32 .text // This includes a minimal XBE header. It's not complete, i.e. software that wants // to decode the header, such as "xbedump" (or probably Microsoft's certification // tools) are likely to fail, but it is a valid header for the Xbox kernel. #include "xbe.S" .org 0x1000 section_1_start: // this should be 0x11000 // kernel thunk table MmAllocateContiguousMemoryEx: .long 0x80000000 + 166 MmGetPhysicalAddress: .long 0x80000000 + 173 NtAllocateVirtualMemory: .long 0x80000000 + 184 .long 0 // end of table .org 0x1080 cromwellstart: .long 0x3000 // Start of the ROM image cromwellsize: .long 0x00060000 // Size of the ROM image (this Value will be overwritten by Imagebld) .org 0x1100 entry: // this should be 0x11100 .globl _start .intel_syntax noprefix _start: #ifdef DebugOut mov ebx, 0 // x position mov ecx, 0 // y position lea esi, text1 mov eax, MmAllocateContiguousMemoryEx call strhexout lea esi, text2 mov eax, MmGetPhysicalAddress call strhexout lea esi, text3 mov eax, NtAllocateVirtualMemory call strhexout lea esi, text_kernel mov eax, offset kernel call strhexout #endif // 1. use MmAllocateContiguousMemoryEx to allocate physical memory // somewhere between 1 and 32 MB for the kernel push ebx push ecx push PAGE_READWRITE push 0 push RETAIL_RAM_SIZE / 2 - 1 push MIN_KERNEL_ADDRESS + (KERNEL_MAX_SIZE) push (KERNEL_MAX_SIZE) call dword ptr [MmAllocateContiguousMemoryEx] mov [kernelram], eax pop ecx pop ebx #ifdef DebugOut push eax lea esi, text_kernelram call strhexout pop eax // kernelram #endif // 3. MmGetPhysicalAddress that memory push ebx push ecx push dword ptr [kernelram] call dword ptr [MmGetPhysicalAddress] mov [phys_kernelram], eax pop ecx pop ebx #ifdef DebugOut lea esi, text_phys_kernelram call strhexout #endif // 2. put kernel there // UWEI push ecx mov esi, offset kernel mov edi, dword ptr [kernelram] mov ecx, [cromwellsize] rep movsb pop ecx // 4. use MmAllocateContiguousMemoryEx to allocate 4096 bytes of memory // for the boot loader between 16 MB and 32 MB (virtual memory should // be unallocated there) push ebx push ecx push PAGE_READWRITE push 16 push RETAIL_RAM_SIZE / 2 push RETAIL_RAM_SIZE / 4 push PAGE_SIZE call dword ptr [MmAllocateContiguousMemoryEx] mov [bootloaderram], eax pop ecx pop ebx #ifdef DebugOut lea esi, text_bootloaderram call strhexout #endif // 5. use MmGetPhysicalAddress on that push ebx push ecx push dword ptr [bootloaderram] call dword ptr [MmGetPhysicalAddress] mov [phys_bootloaderram], eax pop ecx pop ebx #ifdef DebugOut lea esi, text_phys_bootloaderram call strhexout #endif // 6. use NtAllocateVirtualMemory to allocate virtual memory at that virtual address // NtAllocateVirtualMemory( // (PVOID*) &phys_bootloaderram, // (ULONG) 0, // (PULONG) PAGE_SIZE, *****BUG***** POINTER!! // (ULONG) MEM_RESERVE | MEM_COMMIT, // (ULONG) PAGE_READWRITE); push ebx push ecx push PAGE_READWRITE push MEM_RESERVE + MEM_COMMIT // sum = 3000 push offset ptr_PAGE_SIZE push 0 // 0 is used when the caller determines address push offset phys_bootloaderram call dword ptr [NtAllocateVirtualMemory] pop ecx pop ebx #ifdef DebugOut lea esi, text_allocvirt call strhexout #endif // 7. put a copy of the boot loader at both #4 and #6's memory // Copy to #4 cld mov esi, offset blentry mov edi, [bootloaderram] mov ecx, PAGE_SIZE / 4 rep movsb // Copy to #6 // The phys_bootloaderram looks strange, but it's correct. It was made into // a virtual address by NtAllocateVirtualMemory. mov esi, offset blentry mov edi, [phys_bootloaderram] mov ecx, PAGE_SIZE / 4 rep movsb // mov ebp, dword ptr [phys_pm_kernelram] // kernel mov esi, dword ptr [phys_kernelram] // kernel information structure mov edx, [phys_bootloaderram]; // we'll need it again later mov ecx, edx; sub ecx, offset blentry; // construct jmp to new CS mov eax, ecx add eax, offset newloc mov ebx, ecx add ebx, offset ptr_newloc mov [ebx], eax add ebx, 0x80000000 // change physical page, too mov [ebx], eax jmp edx; // this is the bootloader code // ecx = ("blentry" in real memory) - (blentry in original memory) // ebp = phys_pm_kernelram // esi = phys_kernelram blentry: cli; // turn off paging mov eax, cr0 and eax, 0xFFFFFFFF - CR0_ENABLE_PAGING mov cr0, eax xor eax, eax // flush the TLB mov cr3, eax // setup // put position if gdt into gdt_48_base mov eax, ecx add eax, offset bootloader_gdt mov ebx, ecx add ebx, offset gdt_48_base mov [ebx], eax // load new gdt/ldt/idt mov eax, ecx add eax, offset idt_48 lidt [eax] mov eax, ecx add eax, offset gdt_48 lgdt [eax] xor eax, eax lldt ax // initialize segment registers mov ax, 0x0010 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax // jmp to new location .byte 0xea // = ljmp ptr_newloc: .long 0 .word 0x0008 newloc: // copy the Cromwell to it's new position mov edi, KERNEL_RAM_ADDRESS mov ecx, KERNEL_MAX_SIZE rep movsb // Kill Interrupt Handler cli // Interrupt Handler Now Dead //jmp newflash // Jump into Cromwell & start Kernel .byte 0xea // = ljmp .long KERNEL_RAM_ADDRESS // Basically, jump to the first Byte in the Cromwell image... .word 0x0008 newflash: // flash the LEDs // use this as debug code to check whether control reaches a certain point #define LED_RED_C0 0x80 #define LED_RED_C1 0x40 #define LED_RED_C2 0x20 #define LED_RED_C3 0x10 #define LED_GREEN_C0 0x08 #define LED_GREEN_C1 0x04 #define LED_GREEN_C2 0x02 #define LED_GREEN_C3 0x01 mov dx, 0xc004 mov al, 0x20 out dx, al mov dx, 0xc008 mov al, 8 out dx, al mov dx, 0xc006 mov al, LED_RED_C0+LED_GREEN_C1+LED_RED_C2+LED_GREEN_C2 out dx, al mov dx, 0xc000 in ax, dx out dx, al mov dx, 0xc002 mov al, 0x1a out dx, al mov eax, 1000000 l2: dec eax jne l2 mov dx, 0xc004 mov al, 0x20 out dx, al mov dx, 0xc008 mov al, 7 out dx, al mov dx, 0xc006 mov al, 1 out dx, al mov dx, 0xc000 in ax, dx out dx, al mov dx, 0xc002 mov al, 0x1a out dx, al lx: jmp lx // taken from linux/arch/i386/boot/boot.S // SS entry was added .align 16 bootloader_gdt: // 0000 (dummy) .word 0, 0, 0, 0 // dummy // // 0008 (TSS?) // .word 0, 0, 0, 0 // unused // 0008 (code segment) .word 0xFFFF // 4Gb - (0x100000*0x1000 = 4Gb) .word 0 // base address = 0 .word 0x9A00 // code read/exec .word 0x00CF // granularity = 4096, 386 // (+5th nibble of limit) // 0010 (data segment) .word 0xFFFF // 4Gb - (0x100000*0x1000 = 4Gb) .word 0 // base address = 0 .word 0x9200 // data read/write .word 0x00CF // granularity = 4096, 386 // (+5th nibble of limit) .align 8 idt_48: .word 0 // idt limit = 0 .word 0, 0 // idt base = 0L .align 8 gdt_48: .word 0x8000 // GDT limit=2048, 256 entries gdt_48_base: .long 0 // GDT base // call flash //infinite: // jmp infinite strhexout: push eax call strout pop eax call hexout32 cr: mov al, 0xa jmp chrout strout: // esi: text // ebx: x position (will be updated) // ecx: y position (will be updated) mov eax, 0 lodsb // char test al,al je charend call chrout jmp strout charend: ret hexout32: push eax shr eax, 16 call hexout16 pop eax and eax, 0xFFFF hexout16: push eax mov al, ah call hexout8 pop eax hexout8: push eax shr al, 4 call hexout4 pop eax and al, 0xF hexout4: cmp al, 10 jb hexoutd add al, 'A' - 10 jmp chrout hexoutd: add al, '0' chrout: // eax: character // ebx: x position (will be updated) // ecx: y position (will be updated) cmp al, 0x0a // lf? jne nlf mov ebx, 0 inc ecx ret nlf: pusha and eax, 0xff // avoid font overflow shl eax, 4 // index to character lea esi, font[eax] mov eax, ebx // x position shl eax, 5 // index to screen line lea edi, TEXTBUFFER[eax] mov eax, ecx // y position mov ebx, 0xA000 mul ebx add edi, eax mov ecx, 16 fl1: lodsb push ecx mov ecx, 8 fl2: shl al, 1 push eax mov eax, 0 jnc f2 dec eax f2: stosd pop eax loop fl2 add edi, 640*4 - 8*4 pop ecx loop fl1 popa // update cursor position inc ebx cmp ebx, 80 jb no1 mov bx, 0 inc cx no1: ret text1: .ascii "MmAllocateContiguousMemoryEx: 0x" .byte 0 text2: .ascii "MmGetPhysicalAddress: 0x" .byte 0 text3: .ascii "NtAllocateVirtualMemory: 0x" .byte 0 text_kernel: .ascii "kernel: 0x" .byte 0 text_kernelram: .ascii "kernelram: 0x" .byte 0 text_phys_kernelram: .ascii "phys_kernelram: 0x" .byte 0 text_bootloaderram: .ascii "bootloaderram: 0x" .byte 0 text_phys_bootloaderram: .ascii "phys_bootloaderram: 0x" .byte 0 text_allocvirt: .ascii "NtAllocateVirtualMemory(...) = 0x" .byte 0 text_setup_sects: .ascii "setup_sects: 0x" .byte 0 //text_phys_pm_kernelram: //.ascii "phys_pm_kernelram: 0x" //.byte 0 ptr_PAGE_SIZE: .long PAGE_SIZE my_command_line: .ascii "devfs=mount" .byte 0 // Variables .align 4 // Virtual address of the kernel's allocated physical memory kernelram: .long 0 // Physical address of kernelram phys_kernelram: .long 0 // Virtual address of the bootloaders's allocated physical memory bootloaderram: .long 0 // Physical address of bootloader _and_ virtual address of a second copy phys_bootloaderram: .long 0 //phys_pm_kernelram: // .long 0 #include "font.S" //.align 4096. .org 0x3000 kernel: