; Most programs include this file first ; Detect inclusion loops (otherwise ca65 goes crazy) .ifdef COMMON_A .error "common.a included twice" .end .endif COMMON_A = 1 .include "macros.a" SET_DEFAULT BUILD_NSF,0 SET_DEFAULT BUILD_MULTI,0 SET_DEFAULT BUILD_DEVCART,0 SET_DEFAULT CUSTOM_HEADER,0 SET_FLAG BUILD_ROM,(!BUILD_NSF) && (!BUILD_MULTI) .include "nes.a" ;**** Header and reset handler .if (!CUSTOM_HEADER) && (!BUILD_MULTI) ; iNES ROM .if BUILD_ROM .segment "HEADER" .byte "NES",26 .byte 2,1 ; 32K PRG, 8K CHR .byte 1 ; vertical mirroring .segment "VECTORS" .word 0,0,0,nmi,reset,irq .segment "CHARS" .incbin "ascii.chr" ; NSF .elseif BUILD_NSF .segment "HEADER" .byte "NESM",26,1,1,1 .word $E000,reset,nsf_play .segment "VECTORS" .word 0,0,0,0,0,irq .endif ; Reset handler .segment "CODE" ; At beginning so devcart program can patch this to ; re-run bootloader instead. nop forever: jmp forever reset: init_nes jmp startup .endif .if !CUSTOM_HEADER .define BEGIN_NMI nmi: .define BEGIN_IRQ irq: .endif ;**** Common modules .include "delay.a" ; keep first since it can't cross page .include "crc.a" .include "print.a" .include "shell.a" .if !BUILD_MULTI .include "serial.a" .endif .if !BUILD_NSF .include "ppu.a" .endif ;**** Building normal ROM or NSF .if BUILD_NSF || (BUILD_ROM && (!BUILD_DEVCART)) .if !BUILD_NSF .include "console.a" .else NO_CONSOLE = 1 wait_vbl: nsf_play: rts .endif startup: jsr console_init jsr serial_init jmp run_main print_char_: jsr console_print jmp serial_write exit_: tax ; Be sure output is visible print_str {newline,newline,newline} jsr console_show ; in case it was hidden ; Report audibly as well txa jsr beep_bits jmp forever ; Reports byte A to user by printing it in hex and ; reporting its bits via sound. ; Preserved: X, Y report_value: jsr print_a jmp beep_bits ;**** Building devcart .elseif BUILD_DEVCART NO_CONSOLE = 1 print_char_ = serial_write report_value = print_a startup: jsr serial_init delay_msec 45 jmp run_main exit_: ; Tell host to stop capturing serial lda #$1A jsr serial_write ; Run bootloader delay_msec 400 jsr wait_vbl jmp $FF04 ;**** Building multi ROM .elseif BUILD_MULTI .segment "VECTORS" .word 0,0,0,nmi,reset,irq .segment "HOOKS" SET_DEFAULT MULTI_TYPE,$56 .byte MULTI_TYPE,0 .word filename,run_main,0 reset: ; Reset MMC1, map shell to $8000, then run it ; write $80 to reset shift register, ; then write $08 to reg 0 lda #$90 : sta $8000 lsr a cmp #$02 bne :- jmp $8000 .code ; Entry points exit_ = $BFD2 print_char_ = $BFD5 .endif ;**** NO_CONSOLE .ifdef NO_CONSOLE console_init: console_hide: console_show: console_print: rts .endif ;**** print_filename .if .defined(FILENAME_KNOWN) && (!BUILD_DEVCART) print_filename: print_str {newline,"Test:"} lda #filename sta addr+1 jsr print_str_addr jsr print_newline rts filename: .incbin "ram:rom.nes" .byte 0 .else print_filename: rts filename: .byte 0 .endif