Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/nes-warface.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-11-04 20:45:48 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-11-04 20:45:48 +0300
commitd88fab7c179ed838ac2fb7475ee3f1766e657d98 (patch)
tree18c37212bf0c7279f28c8bc06db26080a149a24a
Interrupts added to mapper
-rw-r--r--.gitmodules3
-rw-r--r--Makefile25
-rw-r--r--Mapper/WarfaceMapper.qpf30
-rw-r--r--Mapper/WarfaceMapper.qsf51
-rw-r--r--Mapper/WarfaceMapper.qwsbin0 -> 1335 bytes
-rw-r--r--Mapper/WarfaceMapper.v129
-rw-r--r--Warface-11.ftmbin0 -> 39094 bytes
-rw-r--r--Warface-11.nsfbin0 -> 27245 bytes
-rw-r--r--bank0_subroutines.asm188
-rw-r--r--images/belaya_akula.jpgbin0 -> 35833 bytes
-rw-r--r--images/buhanka.jpgbin0 -> 28800 bytes
-rw-r--r--images/chernobyl.jpgbin0 -> 25501 bytes
-rw-r--r--images/dira.jpgbin0 -> 41352 bytes
-rw-r--r--images/glaza.jpgbin0 -> 14457 bytes
-rw-r--r--images/gorgona.jpgbin0 -> 21931 bytes
-rw-r--r--images/logo_warface.jpgbin0 -> 6874 bytes
-rw-r--r--images/myatej.jpgbin0 -> 25683 bytes
-rw-r--r--images/pagoda.jpgbin0 -> 35043 bytes
-rw-r--r--images/rayon4.jpgbin0 -> 33780 bytes
-rw-r--r--images/shkola.jpgbin0 -> 25573 bytes
-rw-r--r--images/sindikat.jpgbin0 -> 32144 bytes
-rw-r--r--images/sputnik.jpgbin0 -> 26779 bytes
-rw-r--r--images/sworm.jpgbin0 -> 21237 bytes
-rw-r--r--images/trailer-park.jpgbin0 -> 25432 bytes
-rw-r--r--images/zapravka.jpgbin0 -> 25296 bytes
-rw-r--r--nametables.asm27
-rw-r--r--symbols.pngbin0 -> 3351 bytes
m---------tools_sources/NesTiler0
-rw-r--r--warface.asm255
29 files changed, 708 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..f6f8dd0
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "tools_sources/NesTiler"]
+ path = tools_sources/NesTiler
+ url = https://github.com/ClusterM/NesTiler.git
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..79427f5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+NESASM=tools/NESASM.EXE
+EMU=fceux
+SOURCES=music.asm
+EXECUTABLE=warface.nes
+MUSIC=Warface-11.nsf
+MUSIC_BIN=music.bin
+
+all: $(SOURCES) $(EXECUTABLE)
+
+$(EXECUTABLE): $(SOURCES) $(BIN_FILES) $(MUSIC_BIN)
+ rm -f $(EXECUTABLE)
+ $(NESASM) $(SOURCES) -o $(EXECUTABLE) --symbols=$(EXECUTABLE) -iWss
+
+$(BIN_FILES): %:
+ $(CONVERTER)
+$(MUSIC_BIN):
+ dd if=$(MUSIC) of=music.bin bs=1 skip=128
+
+build: $(EXECUTABLE)
+
+clean:
+ rm -f $(EXECUTABLE) $(MUSIC_BIN) *.lst *.nl
+
+run: $(EXECUTABLE)
+ $(EMU) $(EXECUTABLE)
diff --git a/Mapper/WarfaceMapper.qpf b/Mapper/WarfaceMapper.qpf
new file mode 100644
index 0000000..9efb2e2
--- /dev/null
+++ b/Mapper/WarfaceMapper.qpf
@@ -0,0 +1,30 @@
+# -------------------------------------------------------------------------- #
+#
+# Copyright (C) 1991-2013 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions
+# and other software and tools, and its AMPP partner logic
+# functions, and any output files from any of the foregoing
+# (including device programming or simulation files), and any
+# associated documentation or information are expressly subject
+# to the terms and conditions of the Altera Program License
+# Subscription Agreement, Altera MegaCore Function License
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of
+# programming logic devices manufactured by Altera and sold by
+# Altera or its authorized distributors. Please refer to the
+# applicable agreement for further details.
+#
+# -------------------------------------------------------------------------- #
+#
+# Quartus II 64-Bit
+# Version 13.0.1 Build 232 06/12/2013 Service Pack 1 SJ Web Edition
+# Date created = 09:20:39 November 02, 2020
+#
+# -------------------------------------------------------------------------- #
+
+QUARTUS_VERSION = "13.0"
+DATE = "09:20:39 November 02, 2020"
+
+# Revisions
+
+PROJECT_REVISION = "WarfaceMapper"
diff --git a/Mapper/WarfaceMapper.qsf b/Mapper/WarfaceMapper.qsf
new file mode 100644
index 0000000..1c7c2dc
--- /dev/null
+++ b/Mapper/WarfaceMapper.qsf
@@ -0,0 +1,51 @@
+# -------------------------------------------------------------------------- #
+#
+# Copyright (C) 1991-2013 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions
+# and other software and tools, and its AMPP partner logic
+# functions, and any output files from any of the foregoing
+# (including device programming or simulation files), and any
+# associated documentation or information are expressly subject
+# to the terms and conditions of the Altera Program License
+# Subscription Agreement, Altera MegaCore Function License
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of
+# programming logic devices manufactured by Altera and sold by
+# Altera or its authorized distributors. Please refer to the
+# applicable agreement for further details.
+#
+# -------------------------------------------------------------------------- #
+#
+# Quartus II 64-Bit
+# Version 13.0.1 Build 232 06/12/2013 Service Pack 1 SJ Web Edition
+# Date created = 09:20:39 November 02, 2020
+#
+# -------------------------------------------------------------------------- #
+#
+# Notes:
+#
+# 1) The default values for assignments are stored in the file:
+# WarfaceMapper_assignment_defaults.qdf
+# If this file doesn't exist, see file:
+# assignment_defaults.qdf
+#
+# 2) Altera recommends that you do not modify this file. This
+# file is updated automatically by the Quartus II software
+# and any changes you make may be lost or overwritten.
+#
+# -------------------------------------------------------------------------- #
+
+
+set_global_assignment -name FAMILY MAX3000A
+set_global_assignment -name DEVICE "EPM3064ATC100-7"
+set_global_assignment -name TOP_LEVEL_ENTITY WarfaceMapper
+set_global_assignment -name ORIGINAL_QUARTUS_VERSION "13.0 SP1"
+set_global_assignment -name PROJECT_CREATION_TIME_DATE "09:20:39 NOVEMBER 02, 2020"
+set_global_assignment -name LAST_QUARTUS_VERSION "13.0 SP1"
+set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
+set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR "-1"
+set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
+set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
+set_global_assignment -name EDA_DESIGN_ENTRY_SYNTHESIS_TOOL Custom
+set_global_assignment -name EDA_INPUT_DATA_FORMAT "VERILOG HDL" -section_id eda_design_synthesis
+set_global_assignment -name VERILOG_FILE WarfaceMapper.v \ No newline at end of file
diff --git a/Mapper/WarfaceMapper.qws b/Mapper/WarfaceMapper.qws
new file mode 100644
index 0000000..6fb6486
--- /dev/null
+++ b/Mapper/WarfaceMapper.qws
Binary files differ
diff --git a/Mapper/WarfaceMapper.v b/Mapper/WarfaceMapper.v
new file mode 100644
index 0000000..4a71b05
--- /dev/null
+++ b/Mapper/WarfaceMapper.v
@@ -0,0 +1,129 @@
+module WarfaceMapper
+(
+ input m2,
+ input romsel,
+ input cpu_rw,
+ input ppu_rd,
+ input ppu_wr,
+
+ input cpu_a0,
+ input cpu_a13,
+ input cpu_a14,
+ input [7:0] cpu_data,
+ output [16:13] prg_addr,
+ output prg_ce,
+ output prg_oe,
+ output prg_prog,
+
+ input [13:10] ppu_addr,
+ output [16:10] chr_addr,
+ output chr_ce,
+ output chr_oe,
+ output chr_prog,
+
+ output ciram_a10,
+ output irq
+);
+
+// scanline counter, counts dummy PPU reads, detects v-blank automatically
+reg [3:0] ppu_rd_hi_time = 0; // counts how long there is no reads from PPU to detect v-blank
+reg [1:0] ppu_nt_read_count; // nametable read counter
+reg [7:0] scanline = 0; // current scanline
+reg new_screen = 0; // stores 1 when v-blank detected ("in frame" flag)
+reg new_screen_clear = 0; // flag to clear new_screen flag
+
+assign prg_ce = romsel;
+assign prg_oe = romsel | !cpu_rw;
+assign prg_prog = romsel | cpu_rw;
+
+reg [2:0] prg_bank;
+assign prg_addr = cpu_a14
+ ? {3'b111, cpu_a13} // fixed last bank @ $C000-$FFFF
+ : {prg_bank, cpu_a13}; // selectable @ $8000-$BFFF
+
+assign chr_ce = ppu_addr[13];
+assign chr_oe = ppu_addr[13] | ppu_rd;
+assign chr_prog = ppu_addr[13] | ppu_wr;
+
+reg prg_auto_switch = 0;
+reg [4:0] chr_bank;
+reg [1:0] chr_latch;
+assign chr_addr[16:10] = !ppu_addr[12]
+ ? (
+ prg_auto_switch
+ ? {chr_bank[4:2], chr_latch[1:0], ppu_addr[11:10]} // $0000-$0FFF is autoswitchable
+ : {chr_bank[4:0], ppu_addr[11:10]} // $0000-$0FFF is switchable manually
+ )
+ : {5'b11111, ppu_addr[11:10]}; // $1000-$1FFF is fixed to last
+
+assign ciram_a10 = ppu_addr[10]; // horizontal mirroring
+
+reg [11:0] timer = 0;
+reg timer_elapsed = 0;
+assign irq = timer_elapsed ? 1'b0 : 1'bZ;
+
+always @ (negedge m2)
+begin
+ if (timer > 0)
+ begin
+ timer = timer - 1;
+ if (timer == 0) timer_elapsed = 1;
+ end
+ if (!romsel && !cpu_rw && cpu_a13 && cpu_a14) // write to $6000-$7FFF
+ begin
+ if (!cpu_a0)
+ begin // even
+ prg_bank[2:0] = cpu_data[2:0];
+ if (cpu_data[7]) timer = 4095;
+ timer_elapsed = 0;
+ end else begin // odd
+ prg_auto_switch = cpu_data[7];
+ chr_bank[4:0] = cpu_data[4:0];
+ end
+ end
+end
+
+// V-blank detector
+always @ (negedge m2, negedge ppu_rd)
+begin
+ if (~ppu_rd)
+ begin
+ ppu_rd_hi_time = 0;
+ if (new_screen_clear) new_screen = 0;
+ end else if (ppu_rd_hi_time < 4'b1111)
+ begin
+ // Counting how long there is no PPU reads
+ ppu_rd_hi_time = ppu_rd_hi_time + 1'b1;
+ end else begin
+ // Too long, v-blank detected
+ new_screen = 1;
+ end
+end
+
+// Scanline counter
+always @ (negedge ppu_rd)
+begin
+ if (!new_screen && new_screen_clear) new_screen_clear = 0;
+ if (new_screen & !new_screen_clear)
+ begin
+ scanline = 0;
+ new_screen_clear = 1;
+ chr_latch = 0;
+ end else
+ if (ppu_addr[13:12] == 2'b10)
+ begin
+ if (ppu_nt_read_count < 3)
+ begin
+ ppu_nt_read_count = ppu_nt_read_count + 1'b1;
+ end else begin
+ scanline = scanline + 1'b1;
+ if (scanline == 64) chr_latch = 1;
+ if (scanline == 128) chr_latch = 2;
+ if (scanline == 192) chr_latch = 3;
+ end
+ end else begin
+ ppu_nt_read_count = 0;
+ end
+end
+
+endmodule \ No newline at end of file
diff --git a/Warface-11.ftm b/Warface-11.ftm
new file mode 100644
index 0000000..6aa6f67
--- /dev/null
+++ b/Warface-11.ftm
Binary files differ
diff --git a/Warface-11.nsf b/Warface-11.nsf
new file mode 100644
index 0000000..89174d6
--- /dev/null
+++ b/Warface-11.nsf
Binary files differ
diff --git a/bank0_subroutines.asm b/bank0_subroutines.asm
new file mode 100644
index 0000000..7dbb4c1
--- /dev/null
+++ b/bank0_subroutines.asm
@@ -0,0 +1,188 @@
+ ; далее методы в нулевом банке
+ .bank 0
+ .org $8000
+
+init:
+ lda #%00000000 ; Выключаем пока что PPU
+ sta PPUSTATUS
+ sta PPUMASK
+ jsr wait_blank_simple
+ jsr load_black ; Делаем экран чёрным
+
+ ; Определяем тип консоли
+ jsr wait_blank_simple
+console_detect:
+ inx
+ bne console_detect_s
+ iny
+console_detect_s:
+ lda PPUSTATUS
+ bpl console_detect
+ lda #$00
+ cpy #$09
+ bne console_detect_not_ntsc
+console_detect_not_ntsc:
+ cpy #$0A
+ bne console_detect_not_pal
+ ora #$01
+console_detect_not_pal:
+ cpy #$0B
+ bne console_detect_not_dendy
+ ora #$01
+console_detect_not_dendy:
+ sta <CONSOLE_TYPE
+
+ ; Обнуляем звуковые регистры
+ lda #0
+ sta $4000
+ sta $4001
+ sta $4002
+ sta $4003
+ sta $4004
+ sta $4005
+ sta $4006
+ sta $4007
+ sta $4009
+ sta $400A
+ sta $400C
+ sta $400D
+ sta $400E
+ sta $400F
+ sta $4010
+ sta $4011
+ sta $4012
+ sta $4013
+ lda #$0F
+ sta $4015
+ lda #$40
+ sta $4017
+ lda #0
+
+ rts
+
+ ; очищаем nametable
+clear_screen:
+ lda #$20
+ sta PPUADDR
+ lda #$00
+ sta PPUADDR
+ lda #$00
+ ldx #0
+ ldy #$10
+.loop:
+ sta PPUDATA
+ inx
+ bne .loop
+ dey
+ bne .loop
+ rts
+
+load_black:
+ ; загружаем пустую палитру по адресу $3F00 в PPU
+ lda #$3F
+ sta PPUADDR
+ lda #$00
+ sta PPUADDR
+ ldx #$00
+ lda #$1D ; чёрный цвет
+.loop:
+ sta PPUDATA
+ inx
+ cpx #32
+ bne .loop
+ rts
+
+ ; загружаем 16 байт палитры во временную память
+preload_palette:
+ ldy #$00
+ ldx #16
+.loop:
+ lda [PAL_SOURCE_ADDR], y
+ sta PALETTE_CACHE, y
+ iny
+ dex
+ bne .loop
+ rts
+
+ ; загружаем 16 байт палитры в $3F00
+load_palette:
+ lda #LOW(PALETTE_CACHE)
+ sta COPY_SOURCE_ADDR
+ lda #HIGH(PALETTE_CACHE)
+ sta COPY_SOURCE_ADDR+1
+ lda #$3F
+ sta $2006
+ lda #$00
+ sta $2006
+ ldy #$00
+ ldx #16
+.loop:
+ lda [COPY_SOURCE_ADDR], y
+ sta $2007
+ iny
+ dex
+ bne .loop
+ bit PPUSTATUS
+ rts
+
+ ; затемняет загруженную палитру
+dim:
+ ldx #0
+.loop:
+ lda PALETTE_CACHE, x
+ sec
+ sbc #$10
+ bpl .not_minus
+ lda #$1D
+.not_minus:
+ cmp #$0D
+ bne .not_very_black
+ lda #$1D
+.not_very_black:
+ sta PALETTE_CACHE, x
+ inx
+ cpx #16
+ bne .loop
+ rts
+
+dim_in_s:
+ jsr preload_palette
+ jsr dim
+ jsr dim
+ jsr load_palette
+ jsr wait_blank5
+ jsr preload_palette
+ jsr dim
+ jsr load_palette
+ jsr wait_blank5
+ jsr preload_palette
+ jsr load_palette
+ jsr wait_blank
+ rts
+
+dim_out_s:
+ jsr preload_palette
+ jsr dim
+ jsr load_palette
+ jsr wait_blank5
+ jsr preload_palette
+ jsr dim
+ jsr dim
+ jsr load_palette
+ jsr wait_blank5
+ jsr preload_palette
+ jsr dim
+ jsr dim
+ jsr dim
+ jsr load_palette
+ jsr wait_blank5
+ jsr load_black
+ jsr wait_blank
+ rts
+
+title_palette:
+ .incbin "title_palette_0.bin"
+ .incbin "title_palette_1.bin"
+ .incbin "title_palette_2.bin"
+ .incbin "title_palette_3.bin"
+
diff --git a/images/belaya_akula.jpg b/images/belaya_akula.jpg
new file mode 100644
index 0000000..f8d8173
--- /dev/null
+++ b/images/belaya_akula.jpg
Binary files differ
diff --git a/images/buhanka.jpg b/images/buhanka.jpg
new file mode 100644
index 0000000..be69d4f
--- /dev/null
+++ b/images/buhanka.jpg
Binary files differ
diff --git a/images/chernobyl.jpg b/images/chernobyl.jpg
new file mode 100644
index 0000000..5566ff9
--- /dev/null
+++ b/images/chernobyl.jpg
Binary files differ
diff --git a/images/dira.jpg b/images/dira.jpg
new file mode 100644
index 0000000..ad7f976
--- /dev/null
+++ b/images/dira.jpg
Binary files differ
diff --git a/images/glaza.jpg b/images/glaza.jpg
new file mode 100644
index 0000000..f00b82d
--- /dev/null
+++ b/images/glaza.jpg
Binary files differ
diff --git a/images/gorgona.jpg b/images/gorgona.jpg
new file mode 100644
index 0000000..a0ad81b
--- /dev/null
+++ b/images/gorgona.jpg
Binary files differ
diff --git a/images/logo_warface.jpg b/images/logo_warface.jpg
new file mode 100644
index 0000000..80dc597
--- /dev/null
+++ b/images/logo_warface.jpg
Binary files differ
diff --git a/images/myatej.jpg b/images/myatej.jpg
new file mode 100644
index 0000000..f5236da
--- /dev/null
+++ b/images/myatej.jpg
Binary files differ
diff --git a/images/pagoda.jpg b/images/pagoda.jpg
new file mode 100644
index 0000000..bd4601f
--- /dev/null
+++ b/images/pagoda.jpg
Binary files differ
diff --git a/images/rayon4.jpg b/images/rayon4.jpg
new file mode 100644
index 0000000..b125dfd
--- /dev/null
+++ b/images/rayon4.jpg
Binary files differ
diff --git a/images/shkola.jpg b/images/shkola.jpg
new file mode 100644
index 0000000..d53d045
--- /dev/null
+++ b/images/shkola.jpg
Binary files differ
diff --git a/images/sindikat.jpg b/images/sindikat.jpg
new file mode 100644
index 0000000..606868f
--- /dev/null
+++ b/images/sindikat.jpg
Binary files differ
diff --git a/images/sputnik.jpg b/images/sputnik.jpg
new file mode 100644
index 0000000..9558605
--- /dev/null
+++ b/images/sputnik.jpg
Binary files differ
diff --git a/images/sworm.jpg b/images/sworm.jpg
new file mode 100644
index 0000000..3c5969d
--- /dev/null
+++ b/images/sworm.jpg
Binary files differ
diff --git a/images/trailer-park.jpg b/images/trailer-park.jpg
new file mode 100644
index 0000000..a789442
--- /dev/null
+++ b/images/trailer-park.jpg
Binary files differ
diff --git a/images/zapravka.jpg b/images/zapravka.jpg
new file mode 100644
index 0000000..820ad1e
--- /dev/null
+++ b/images/zapravka.jpg
Binary files differ
diff --git a/nametables.asm b/nametables.asm
new file mode 100644
index 0000000..086d8f4
--- /dev/null
+++ b/nametables.asm
@@ -0,0 +1,27 @@
+ .bank 2
+ .org $8000
+
+title_name_table:
+ .incbin "title_name_table_0.bin"
+ .incbin "title_name_table_1.bin"
+ .incbin "title_name_table_2.bin"
+ .incbin "title_name_table_3.bin"
+ .incbin "title_attr_table_0.bin"
+ .incbin "title_attr_table_1.bin"
+ .incbin "title_attr_table_2.bin"
+ .incbin "title_attr_table_3.bin"
+
+ .bank 16
+ .org $0000
+ .incbin "title_pattern_0.bin"
+ .org $1000
+ .incbin "title_pattern_1.bin"
+ .bank 17
+ .org $0000
+ .incbin "title_pattern_2.bin"
+ .org $1000
+ .incbin "title_pattern_3.bin"
+
+
+ .bank 31
+ .db 0
diff --git a/symbols.png b/symbols.png
new file mode 100644
index 0000000..e0e595f
--- /dev/null
+++ b/symbols.png
Binary files differ
diff --git a/tools_sources/NesTiler b/tools_sources/NesTiler
new file mode 160000
+Subproject 96369101aa743580b01f2cf33d6d6c1dffe58b6
diff --git a/warface.asm b/warface.asm
new file mode 100644
index 0000000..0b124f5
--- /dev/null
+++ b/warface.asm
@@ -0,0 +1,255 @@
+;
+; Автор: Авдюхин Алексей / clusterrr@clusterrr.com / http://clusterrr.com
+; Специально Mail.ru Group
+;
+
+; INES header
+ .inesprg 128 * 1024 ; 16 банков PRG
+ .ineschr 128 * 1024 ; 16 банков CHR
+ .inesmir 0 ; горизонтальный мирроринг
+ .inesmap 3914 ; маппер #3914 (кастомный)
+
+PPUCTRL .equ $2000
+PPUMASK .equ $2001
+PPUSTATUS .equ $2002
+OAMADDR .equ $2003
+OAMDATA .equ $2004
+PPUSCROLL .equ $2005
+PPUADDR .equ $2006
+PPUDATA .equ $2007
+OAMDMA .equ $4014
+
+ .rsset $0020 ; адрес для переменных
+ACTIVE_BANK .rs 1 ; текущий PRG банк
+CONSOLE_TYPE .rs 1 ; тип консоли
+COPY_SOURCE_ADDR .rs 2
+PAL_SOURCE_ADDR .rs 2
+PALETTE_CACHE .rs 16
+
+ .bank 12 ; PRG банк #12, середина PRG
+ .org $9213
+ .incbin "music.bin" ; Музыка
+
+ .bank 15 ; PRG банк #15, конец PRG
+
+ .org $FFFA ; Векторы прерываний
+ .dw NMI ; NMI вектор
+ .dw Start ; Ресет вектор $FFFA
+ .dw IRQ ; IRQ
+
+ .bank 15 ; Тут начинается наш код
+ .org $FD00 ; В памяти NES это будет адрес $8000
+
+Start:
+ sei ; сразу же отключаем любые прерывания
+ ; обнуляем стек
+ ldx #$ff
+ txs
+ ; вызываем функцию инициализации из нулевого банка
+ lda #BANK(init)/2
+ jsr select_prg_bank
+ jsr init
+ ; предпоследний банк
+ lda #6
+ jsr select_prg_bank
+ lda #0 ; номер трека
+ ; в регистре X задаётся регион: PAL или NTSC
+ ldx CONSOLE_TYPE
+ jsr $A999 ; Инициализируем музыкальный проигрыватель
+
+ cli
+ jsr disable_ppu
+ jsr wait_blank_simple
+ ; загружаем nametable
+ lda #BANK(title_name_table)/2
+ jsr select_prg_bank
+ lda #LOW(title_name_table)
+ sta COPY_SOURCE_ADDR
+ lda #HIGH(title_name_table)
+ sta COPY_SOURCE_ADDR+1
+ jsr load_name_table
+ ; выбираем CHR банк с автопереключением
+ jsr wait_blank_simple
+ lda #0
+ jsr select_chr_bank
+ jsr enable_ppu
+ ; загружаем палитру
+ lda #BANK(title_palette)/2
+ jsr select_prg_bank
+ lda #LOW(title_palette)
+ sta PAL_SOURCE_ADDR
+ lda #HIGH(title_palette)
+ sta PAL_SOURCE_ADDR+1
+
+ ; бесконечный цикл
+main_loop:
+ jsr dim_in
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+
+ jsr dim_out
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+ jsr wait_blank
+
+ jmp main_loop
+
+IRQ:
+ php
+ pha
+ tya
+ pha
+ txa
+ pha
+
+ ; вызываем код музыки из предпоследнего банка
+ ; заодно это делает ack прерыванию
+ lda #6
+ sta $6000
+ jsr $A99C ; играем музыку
+ ; возвращаем назад активный банк
+ lda ACTIVE_BANK
+ sta $6000
+
+ pla
+ tax
+ pla
+ tay
+ pla
+ plp
+ rti
+
+NMI:
+ php
+ pha
+ tya
+ pha
+ txa
+ pha
+
+ ; запускаем таймер, чтобы потом играть музыку
+ lda ACTIVE_BANK
+ ora #%10000000
+ sta $6000
+
+ pla
+ tax
+ pla
+ tay
+ pla
+ plp
+ rti
+
+ ; субрутина выбора PRG банка
+select_prg_bank:
+ sta ACTIVE_BANK
+ sta $6000
+ rts
+
+ ; субрутина для выбора CHR банка
+select_chr_bank:
+ asl A
+ asl A
+ ora #%10000000
+ sta $6001
+
+enable_ppu:
+ bit PPUSTATUS
+ lda #0
+ sta PPUSCROLL
+ sta PPUSCROLL
+ lda #%10000000
+ sta PPUCTRL
+ lda #%00001010
+ sta PPUMASK
+ jsr wait_blank_simple
+ rts
+
+disable_ppu:
+ lda #%10000000
+ sta PPUCTRL
+ lda #%00000000
+ sta PPUMASK
+ jsr wait_blank_simple
+ rts
+
+ ; субрутина простого ожидания vblank
+wait_blank_simple:
+ pha
+ bit PPUSTATUS
+.loop:
+ lda PPUSTATUS ; load A with value at location $2002
+ bpl .loop ; if bit 7 is not set (not VBlank) keep checking
+ pla
+ rts
+
+ ; субрутина ожидания vblank
+wait_blank:
+ pha
+ tya
+ pha
+ txa
+ pha
+
+ jsr enable_ppu
+
+ pla
+ tax
+ pla
+ tay
+ pla
+ rts
+
+wait_blank5:
+ ldx #5
+.loop:
+ jsr wait_blank
+ dex
+ bne .loop
+ rts
+
+ ; загружаем nametable в $1000
+load_name_table:
+ lda #$20
+ sta $2006
+ lda #$00
+ sta $2006
+ ldy #$00
+ ldx #$04
+.loop:
+ lda [COPY_SOURCE_ADDR], y
+ sta $2007
+ iny
+ bne .loop
+ inc <COPY_SOURCE_ADDR+1
+ dex
+ bne .loop
+ rts
+
+dim_in:
+ lda #0
+ jsr select_prg_bank
+ jsr dim_in_s
+ rts
+
+dim_out:
+ lda #0
+ jsr select_prg_bank
+ jsr dim_out_s
+ rts
+
+ .include "bank0_subroutines.asm"
+ .include "nametables.asm"