Skip to content

Commit

Permalink
Make the banked call routine an ASM callback leaf.
Browse files Browse the repository at this point in the history
This allows the norecurse pass to effectively see through it.
  • Loading branch information
mysterymath committed Oct 8, 2022
1 parent 4d03950 commit 79f20a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 0 additions & 8 deletions mos-platform/nes-mmc1/bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ mmc1_register_write_retry(unsigned addr, char val) {
_IN_PROGRESS = 0;
}

__attribute__((noinline, weak)) void banked_call(char bank_id,
void (*method)(void)) {
char old_id = get_prg_bank();
set_prg_bank(bank_id);
method();
set_prg_bank(old_id);
}

__attribute__((weak)) void set_chr_bank_0(char bank_id) {
_CHR_BANK0 = bank_id;
}
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/nes-mmc1/bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern volatile const char MMC1_CTRL_CUR;
// Switch to another bank and call this function.
// Note: Using banked_call to call a second function from within
// another banked_call is safe.
void banked_call(char bank_id, void (*method)(void));
__attribute__((leaf, callback(2))) void banked_call(char bank_id, void (*method)(void));

// Switch to the given bank (to $8000-bfff). Your prior bank is not saved.
// Can be used for reading data with a function in the fixed bank.
Expand Down
18 changes: 18 additions & 0 deletions mos-platform/nes-mmc1/bank.s
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ set_prg_bank:
tya
jmp .Lset



.section .text.banked_call,"ax",@progbits
.weak banked_call
banked_call:
tay
lda _PRG_BANK
pha
tya
jsr __set_prg_bank
lda mos8(__rc2)
sta mos8(__rc18)
lda mos8(__rc3)
sta mos8(__rc19)
jsr __call_indir
pla
jsr __set_prg_bank
rts

0 comments on commit 79f20a5

Please sign in to comment.