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

Famicom support

This commit is contained in:
Karol Stasiak
2018-03-15 23:46:16 +01:00
parent 8a347e5058
commit 9680423691
10 changed files with 511 additions and 6 deletions
+86
View File
@@ -0,0 +1,86 @@
byte ppu_ctrl @$2000
byte ppu_mask @$2001
byte ppu_status @$2002
byte oam_addr @$2003
byte oam_data @$2004
byte ppu_scroll @$2005
byte ppu_addr @$2006
byte ppu_data @$2007
byte oam_dma @$4014
// TODO: better names
byte apu_pulse1_ctrl @$4000
byte apu_pulse1_sweep @$4001
word apu_pulse1_period @$4002
byte apu_pulse2_ctrl @$4004
byte apu_pulse2_sweep @$4005
word apu_pulse2_period @$4006
byte apu_triangle_unmute @$4008
word apu_triangle_period @$400A
byte apu_noise_ctrl @$400C
byte apu_noise_period @$400E
byte apu_dmc_ctrl @$4010
byte apu_dmc_load @$4011
byte apu_dmc_sample_addr @$4012
byte apu_dmc_sample_length @$4013
byte apu_status @$4015
byte apu_frame_counter @$4017
byte joypad1_ctrl @$4016
byte joypad2_ctrl @$4017
inline asm byte strobe_joypad() {
? LDA #1
STA joypad1_ctrl
LSR
STA joypad1_ctrl
? RTS
}
inline asm byte read_joypad1() {
LDA joypad1_ctrl
? RTS
}
inline asm byte read_joypad2() {
LDA joypad2_ctrl
? RTS
}
macro asm void simulate_reset() {
JMP (reset_vector.addr)
}
inline asm void ppu_set_addr(word ax) {
STX ppu_addr
STA ppu_addr
?RTS
}
inline asm byte read_ppu_status() {
LDA ppu_status
? RTS
}
inline asm void ppu_set_scroll(word a, word x) {
STA ppu_scroll
STX ppu_scroll
?RTS
}
inline asm void ppu_write_data(byte a) {
STA ppu_data
?RTS
}
inline asm void ppu_oam_dma_write(byte a) {
STA oam_dma
?RTS
}
+65
View File
@@ -0,0 +1,65 @@
asm void on_reset() {
SEI
CLD
LDX #$40
STX $4017
LDX #$ff
TXS
INX
STX ppu_ctrl
STX ppu_mask
STX $4010
BIT ppu_status
vwait1:
BIT ppu_status
BPL vwait1
vwait2:
BIT ppu_status
BPL vwait2
LDA #$00
LDX #$00
clean_byte:
STA $000,x
STA $100,x
STA $200,x
STA $300,x
STA $400,x
STA $500,x
STA $600,x
STA $700,x
INX
BNE clean_byte
LDA #$00
STA $2000
STA $2001
JMP main
JMP on_reset
}
interrupt void on_irq() {
irq()
}
interrupt void on_nmi() {
nmi()
}
array nmi_vector @$FFFA = [
on_nmi.addr.lo,
on_nmi.addr.hi
]
array reset_vector @$FFFC = [
on_reset.addr.lo,
on_reset.addr.hi
]
array irq_vector @$FFFE = [
on_irq.addr.lo,
on_irq.addr.hi
]
+31
View File
@@ -0,0 +1,31 @@
; a very simple NES cartridge format
; uses mapper 0 and no bankswitching, so it's only good for very simple games
; assumes CHRROM is at chrrom:$0000-$3fff and PRGROM is at prgrom:$8000-$ffff
; uses horizontal mirroring; to use vertical mirroring, change byte #6 of the header from 0 to 1
[compilation]
arch=ricoh
modules=nes_hardware,nes_routines,default_panic
ro_arrays=true
[allocation]
zp_pointers=all
segments=default,prgrom,chrrom
default_code_segment=prgrom
segment_default_start=$200
segment_default_end=$7ff
segment_prgrom_start=$8000
segment_prgrom_end=$ffff
segment_chrrom_start=$0000
segment_chrrom_end=$3fff
[output]
style=single
format=$4E,$45,$53,$1A, 2,2,0,0, 0,0,0,0, 0,0,0,0, prgrom:$8000:$ffff, chrrom:$0000:$3fff
extension=nes