1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-29 04:41:30 +00:00
millfork/docs/stdlib/nes.md

146 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2019-07-15 12:21:50 +00:00
[< back to index](../doc_index.md)
# NES/Famicom-oriented modules
2018-12-17 16:18:29 +00:00
## nes_hardware
2019-09-27 21:36:05 +00:00
The `nes_hardware` module is imported automatically on NES targets.
It contains defintions for the NES's memory-mapped registers, as well
as some joypad and PPU management routines.
2019-09-27 21:36:05 +00:00
#### `PPU memory-mapped registers`
Named memory locations for interfacing with the PPU's memory-mapped registers.
Available variables:
* `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`
#### `byte strobe_joypad()`
2020-03-31 17:07:35 +00:00
Strobes joypads in preparation for reading new joypad states.
2019-09-27 21:36:05 +00:00
#### `byte read_joypad1()`
Get joypad1's state as a byte.
#### `byte read_joypad2()`
Get joypad2's state as a byte.
#### `void simulate_reset()`
Simulates a hardware reset by jumping to the reset vector,
which then calls main().
#### `void ppu_set_addr(word register(ax) address)`
2019-09-27 21:36:05 +00:00
Sets the PPU to point at the VRAM address at ax, usually in preparation
for a write via ppu_write_data().
#### `byte read_ppu_status()`
Gets the PPU status byte.
#### `void ppu_set_scroll(byte register(a) xscroll, byte register(x) yscroll)`
2019-09-27 21:36:05 +00:00
Sets the PPU scroll register. Parameter a defines the horizontal
(X-axis) scroll value, and parameter x defines the vertical (Y-axis)
scroll value.
#### `void ppu_write_data(byte register(a) data)`
2019-09-27 21:36:05 +00:00
Writes a byte to the PPU's VRAM at the address the PPU
is currently pointing to. Usually used after a call to ppu_set_addr().
#### `void ppu_oam_dma_write(byte register(a) page)`
2019-09-27 21:36:05 +00:00
Initiates a DMA transfer of 256 bytes from CPU memory address $xx00-$xxFF
to PPU OAM memory, where xx is the hexadecimal representation of parameter a.
2018-12-17 16:18:29 +00:00
## nes_mmc4
2019-09-27 21:36:05 +00:00
The `nes_mmc4` module is imported automatically on the NES MMC4 target
and contains routines related to MMC4 bankswitching.
#### `void set_prg_bank(byte register(a) bank)`
Changes the $8000-$BFFF PRG bank.
#### `void set_chr_bank0(byte register(a) bank)`
Changes the CHR bank 0 ($0000-$0fff in the PPU memory space).
The high nibble (0 or 1) selects between `chrrom0` and `chrrom1` segments.
The low nibble L (0-$F) selects a 4K-aligned address in the segment ($L000).
#### `void set_chr_bank1(byte register(a) bank)`
Changes the CHR bank 1 ($1000-$1fff in the PPU memory space).
The high nibble (0 or 1) selects between `chrrom0` and `chrrom1` segments.
The low nibble L (0-$F) selects a 4K-aligned address in the segment ($L000).
#### `void set_vertical_mirroring()`
Switches nametable mirroring to vertical.
#### `void set_horizontal_mirroring()`
2018-12-17 16:18:29 +00:00
Switches nametable mirroring to horizontal.
## nes_joy
2020-03-31 17:07:35 +00:00
Provides an interface for reading joypads that is compatible with the [`joy` module](./joy.md).
2018-12-17 16:18:29 +00:00
#### `alias input_a = input_btn`
2020-12-01 13:26:47 +00:00
1 if A button pressed, 0 if not pressed.
2018-12-17 16:18:29 +00:00
#### `byte input_b`
2020-12-01 13:26:47 +00:00
1 if B button pressed, 0 if not pressed.
2018-12-17 16:18:29 +00:00
#### `byte input_select`
2020-12-01 13:26:47 +00:00
1 if Select button pressed, 0 if not pressed.
2018-12-17 16:18:29 +00:00
#### `byte input_start`
2020-12-01 13:26:47 +00:00
1 if Start button pressed, 0 if not pressed.
2018-12-17 16:18:29 +00:00
#### `void read_joy1()`
Reads the joypad from the port 1.
#### `void read_joy2()`
Reads the joypad from the port 2.
#### `void read_also_joy1()`
Reads the joypad from the port 1 and adds its readouts to the current readouts.
#### `void read_also_joy2()`
Reads the joypad from the port 2 and adds its readouts to the current readouts.
#### `void nes_reset_joy()`
#### `alias reset_joy = nes_reset_joy!`
2018-12-17 16:18:29 +00:00
Resets the state variables.
## nes_joy1_default
Defines the joystick in port 1 as the default joystick.
#### `alias read_joy = read_joy1`