1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-22 00:17:03 +00:00

Allow initializing writable variables on cartridge targets

This commit is contained in:
Karol Stasiak
2019-06-28 16:28:49 +02:00
parent 7f28a6b10f
commit 674f8d1983
22 changed files with 436 additions and 107 deletions
+11 -4
View File
@@ -3,16 +3,20 @@
import nes_joy1_default
volatile byte initialized
void main() {
init_graphics()
init_input()
init_sound()
ppu_ctrl = %10001000
ppu_mask = %00011110
initialized = 1
while(true){}
}
void nmi() {
if initialized != 1 { return }
scroll_screen()
update_sprite()
react_to_input()
@@ -24,7 +28,7 @@ void irq() {
array oam_buffer [256] @$200
byte scroll
byte a
byte a // debouncing
sbyte dx
void init_graphics() {
@@ -72,13 +76,13 @@ void load_name_tables() {
p = bg.addr
ppu_set_addr($2400)
for page_count,0,until,4 {
for b,0,until,255 {
for b,0,to,255 {
ppu_write_data(p[b])
}
p.hi += 1
}
for page_count,0,until,4 {
for b,0,until,255 {
for b,0,to,255 {
ppu_write_data(0)
}
}
@@ -103,8 +107,11 @@ void update_sprite() {
void react_to_input() {
read_joy()
if input_a != 0 { // A button
reverse_dx()
if a == 0 {
reverse_dx()
}
}
a = input_a
if input_dy < 0 { // Up button
if oam_buffer[0] > 7 { oam_buffer[0] -= 1}
}
+22 -22
View File
@@ -1,16 +1,24 @@
// Based upon the example code from NES 101 tutorial by Michael Martin
// compile with -t nes_mmc4
import nes_joy
volatile byte initialized
void main() {
initialized = 0
set_prg_bank(0)
init_rw_memory()
init_graphics()
init_input()
init_sound()
ppu_ctrl = %10001000
ppu_mask = %00011110
initialized = 1
while(true){}
}
void nmi() {
if initialized != 1 { return }
set_prg_bank(1)
scroll_screen()
set_prg_bank(2)
@@ -24,22 +32,18 @@ void irq() {
}
array oam_buffer [256] @$200
byte scroll
byte a
byte scroll = 240
byte a = 0 // debouncing
segment(ram) sbyte dx
void init_graphics() {
set_horizontal_mirroring()
set_chr_bank0($06)
set_chr_bank1($1A)
init_sprites()
set_prg_bank(6)
load_palette()
load_name_tables()
init_scrolling()
}
void init_input() {
a = 0
}
void init_sound() {
@@ -78,22 +82,18 @@ noinline void load_name_tables() {
p = bg.addr
ppu_set_addr($2400)
for page_count,0,until,4 {
for b,0,until,255 {
for b,0,to,255 {
ppu_write_data(p[b])
}
p.hi += 1
}
for page_count,0,until,4 {
for b,0,until,255 {
for b,0,to,255 {
ppu_write_data(0)
}
}
}
void init_scrolling() {
scroll = 240
}
segment(prgrom2)
noinline void update_sprite() {
ppu_oam_dma_write(oam_buffer.addr.hi)
@@ -109,17 +109,17 @@ noinline void update_sprite() {
segment(prgrom3)
noinline void react_to_input() {
strobe_joypad()
if read_joypad1() & 1 != 0 { // A button
reverse_dx()
read_joy1()
if input_a != 0 { // A button
if a == 0 {
reverse_dx()
}
}
read_joypad1() // B button
read_joypad1() // Select button
read_joypad1() // Start button
if read_joypad1() & 1 != 0 { // Up button
a = input_a
if input_dy < 0 { // Up button
if oam_buffer[0] > 7 { oam_buffer[0] -= 1}
}
if read_joypad1() & 1 != 0 { // Down button
if input_dy > 0 { // Down button
if oam_buffer[0] < 223 { oam_buffer[0] += 1}
}
}