62 Commits

Author SHA1 Message Date
VetriTheRetri
51f39d5fb1 Fix typo in fill_bkg_rect/fill_win_rect description: 0-31 -> 1-32 width/height range (#814)
* address typo in fill_bkg_rect/fill_win_rect description: 0-31 -> 1-32 width/height range
2025-09-05 16:32:52 -07:00
Michel Iwaniec
62de8abb87 NES: Add support for various tilemap layout (mirroring) configurations (#783)
* NES: Add support for various tilemap layout (mirroring) configurations

- Introduce platform configuration, mainly to define tilemap layout NES_TILEMAP_[F|H|V|S] in platform_cfg.s
  + Add NES_TILEMAP_S|H|V|F setting for tilemap layout, and hard-code to NES_TILEMAP_S for now
  + Add NES_LOMEM setting to enable current default of using part of stack instead of BSS for attribute shadow buffer
  + Edit Makefile to copy platform_cfg.s (if it exists) to platform directory after build

- Updates to attribute shadow buffer and dirty bits:
  + Add NUM_NT define for number of nametables used by a layout, and AT_SHADOW_WIDTH/_HEIGHT to denote the variable dimensions
  + Add convenience defines NT_2W / NT_2H to quickly test whether tilemap layout is two screens wide / high
  + Define _attribute_shadow and _attribute_row/_column_dirty in terms of NUM_NT
  + Update flush_attributes to support all layouts
  + Update get_bkg_xy_addr / set_bkg_tile_xy to support all layouts
  + Update set_bkg_attribute_xy[_nes16x16] to support all layouts
  + Update set_bkg_attributes[_nes16x16] to support all layouts, and correctly wrap to next AT in both directions
  + Update set_bkg_submap_attributes[_nes16x16] to support all layouts
  + Update set_bkg_submap to support all layouts, and contain common inner subroutine .set_bkg_common
  + Replace set_bkg_tiles with simpler implementation calling .set_bkg_common, and correctly wraps to next NT in both directions
  + Add set_bkg_based_tiles / set_bkg_based_submap implementations using the new common subroutine

- Updates to C include files:
  + Define DEVICE_SCREEN_BUFFER_WIDTH/_HEIGHT based on NES_TILEMAP_ setting, doubling high-level size of WIDTH / HEIGHT conditionally
  + Add typedefs scroll_x_t / scroll_y_t as uint8_t or uint16_t based on NES_TILEMAP_ setting
  + Make move_bkg use scroll_x/y_t typedefs, set 9th scroll bit in shadow_PPUCTRL where needed, and compensate for 239->0 y wrapping

- Updates to examples:
  + Update large_map example to use platform-agnostic settings for scroll wrapping and offset
  + Update rle_map to use a uint16_t for scroll position, to support NES_TILEMAP_H and NES_TILEMAP_F settings
2025-05-19 12:44:45 +01:00
Michel Iwaniec
5acc7cfbae NES: Improve TIMER interrupt emulation (#774)
- Move TIM ISR emulation to dedicated function .tim_emulation and dedicated file timer_isr.s

- Make TIM ISR emulation save entirety of ALL_REGTEMPS_BEGIN to ALL_REGTEMPS_END

- Improve emulation to allow average TIM rate to be faster compared to vblank rate

- Add support for consistent average TIM rate on PAL, for a less system-dependent timer

- Add support for different base dividers defined by GB-like TAC_REG variable

- Add defines values for "vblank parity mode" to global.s and nes.h

- Update crt0 init code to set TMA_REG to vblank parity mode correctly for PAL/Dendy

- Update documentation, describing the improved GB TIM emulation and vblank parity mode

- Update cross-platform IRQ example to better showcase the emulation
2025-05-06 11:40:17 +01:00
bbbbbr
0f073ab408 Docs: text changelog, other minor updates 2025-04-25 00:04:39 -07:00
Michel Iwaniec
03613b5550 NES: Make sure TIM ISR handlers are thread-safe (#760)
* NES: Make sure TIM ISR handlers are thread-safe

- Backup and restore REGTEMP area when calling TIM ISR in vblank

- Update irq example to use #pragma nooverlay for tim handler

- Add warning and explanation about having to use #pragma for TIM handlers in NES section of docs

- Add @anchor to docs, and a code example for #pragma nooverlay

- Update irq.c with `#pragma nooverlay` only being applied if NINTENDO_NES is defined

- Add more detailed comment of `#pragma nooverlay` in irq.c

- Add reference to docs in gb.h

- Add similar reference to nes.h
2025-04-22 08:36:41 +01:00
Michel Iwaniec
ac571c1dab NES: Align coordinates and scanline counting in LCD ISR implementation with GB, add SCX / SCY / LYC defines (#755)
NES: Align coordinates and scanline counting in LCD ISR implementation with GB, add SCX / SCY / LYC defines

- Change definition of _lcd_scanline to be -1 less than current, aligning with GB LYC register

- Change definition of _bkg_scroll_y to match GB's SCY, being relative to current scanline

- Refactor do_hblank_writes, delay_fractional and delay_to_scanline subroutines in crt0

- Add "#define LYC_REG" and "#define LY_REG" as aliases of _lcd_scanline

- Add #defines for SCX and SCY to alias _bkg_scroll_x / _bkg_scroll_y shadow variables

- Change text scroller example to use LYC_REG / SCX / SCY instead of _lcd_scanline / move_bkg, remove redundant #ifdefs

- Add subtle shake in y direction to text scroller example, to check that GB / NES coordinates match

- Update "From Game Boy to NES" section's descriptions of LCD handlers

- Update "Migrating to new GBDK versions" with a short description of bkg_scroll_y changing from absolute to relative Y coordinates for 4.4.0
2025-03-30 23:43:39 +01:00
Michel Iwaniec
37186a5b7a NES: Timer interrupt emulation + support for set_interrupts(...)
- Add add_TIM / remove_TIM functions to nes.h

- Refactor implementation in lcd.s to support add_TIM / remove_TIM

- Add TMA_REG / TIMA_REG / TAC_REG vars to emulate GB hardware timer register

- Add call to TIM function at end of NMI handler in crt0.s, and make it use TMA_REG / TIMA_REG vars

- Add implementation for set_interrupts in lcd.s, replacing JMP instruction with RTS when disabled

- Enable NES target in examples/cross-platform/irq and replace delay(1000) call with 60 vsyncs

- Update examples/cross-platform/scroller and examples/cross-platform/irq to use set_interrupts

- Update documentation to describe use-cases and limitations of TIM handler
2025-03-09 03:07:44 +00:00
Michel Iwaniec
fbd7653313 NES: Fix bugs with non-multiple-of-2 (/4) map width in set_bkg_submap_attributes (#722)
* Add +1 before shift in inline function set_bkg_submap_attributes
* Add-with carry after right-shift of width in set_bkg_submap_attributes_nes16x16
2024-10-20 00:59:54 +01:00
Michel Iwaniec
94793354ab NES: Add reset function for compatibility (#719) 2024-10-16 00:57:33 +01:00
Michel Iwaniec
54dbf0722e NES: Add BCD support
* Copy gbdk-lib/include/gb/bcd.h to gbdk-lib/include/nes/bcd.h
* Add bcd asm implementation in libc/asm/mos6502/bcd.s
* Update bcd.h to accept NES target
* Update examples/cross-platform/bcd to build for nes
2024-05-18 02:09:44 +01:00
Michel Iwaniec
0b424fafc7 NES: Add deferred hblank system for fake LCD ISRs
* Refactor .delay_to_lcd_scanline to not use Y register. Remove outdated comments.
* Move .jmp_to_LCD_isr call to vsync routine, and have it copy shadow PPU register values to a buffer
* Add MAX_LCD_ISR_CALLS define to limit the deferred PPU register write buffer size
* Add .do_lcd_ppu_reg_writes for writing buffer aligned to hblank, and calls to .delay_to_lcd_scanline
* Make .do_lcd_ppu_reg_write restore Y-scroll for start-of-frame after every update, to mitigate glitches in lag frames
* Have LCD at scanline#0 be treated as a special-case, where VBL shadow values are replaced without adding to the buffer
* Re-introduce variable to skip NMI as __crt0_disableNMI, and set it in vsync during buffer building

Update text_scroller example:
* Fix NES-version of code to do multiple splits like the other platforms do
* Fill nametable with '*' to make splits more visible
* TODO: Find out why fill_bkg_rect isn't working on GB
2024-05-14 23:54:55 +01:00
Michel Iwaniec
350c221b22 Changes in response to PR review:
* Name change for consistency with other platforms: _system_bits -> _SYSTEM
* Add _SYSTEM extern to msx.h and sms.h
* Make all platforms have SYSTEM_60HZ and 0x00 and SYSTEM_50HZ as 0x01
* Make _SYSTEM have uint8_t type instead of UBYTE
2024-04-28 17:55:32 +01:00
Michel Iwaniec
9f8103ad4d NES: Add PAL support
* Add new zeropage variable _system_bits to indicate NTSC/PAL/Dendy system
* Modify init code to detect NTSC/PAL/Dendy via cycle counting, storing result in _system_bits
* Modify fake-LCD-ISR delays in NMI handler to accommodate PAL timings

Cross-platform:
* Change existing SYSTEM_NTSC / SYSTEM_PAL defines in sms.h to SYSTEM_60HZ / SYSTEM_50HZ, and copy them to gb.h / nes.h / msx.h
* Add new cross-platform function get_system for all ports, to query whether running on a 60Hz or 50Hz system
* Add minimal cross-platform display_system example to exercise get_system
2024-04-28 00:54:55 +01:00
Toxa
de1bd7b473 define SET_BORDER_COLOR() macro for all platforms 2024-03-28 16:20:39 +03:00
bbbbbr
35c687f23d Docs: set_palette() for SMS/GG, clarify display_off behavior for GB and NES 2024-03-03 04:03:36 -08:00
Toxa
53445a6b8e remove legacy types from the metasprites api 2024-01-03 22:05:36 +03:00
Michel Iwaniec
f859c9c2eb NES: Move inline set_sprite* routines to asm file, and add NO_OVERLAY_LOCALS function property 2023-10-06 23:24:37 +01:00
Michel Iwaniec
9ec18dbb07 Reduce zeropage use for locals, by making gbdk-nes functions use its own dedicated overlay segment instead of SDCC's overlay segment
* Update gbdk_build_and_package.yml and gbdk_build_examples.yml to use gbdk-4.2.0-Next SDCC build
* Update nes.h to declare all gbdk functions with the new __no_overlay_locals function attribute
* Introduce new dedicated 16-byte overlay segment GBDKOVR, and make all assembly functions use this instead of OSEG
* Update LCC file targets.c to reserve space for both OSEG and GBDKOVR
2023-10-05 02:17:49 +01:00
bbbbbr
01fc176bd7 Docs: FAQ: some info about common warnings
docs: set_sprite_prop() Remove non-constant example and change constant exampel to use bitwise or instead of addition
2023-10-03 00:00:16 -07:00
bbbbbr
2e435bf7c0 Merge pull request #486 from Adam-Shea/develop
Updated documentation for set_sprite_prop()
2023-10-02 23:52:43 -07:00
Michel Iwaniec
174ceedd84 NES: Fix support for 4-player controllers using fourscore
* Reverse order of bits in joypad byte and bitmasks for buttons, to conform to more common order in nesdev
* Bump MAX_JOYPADS definition in joypad_ex.s from 2 to 4
* Add label read_joypad_no_strobe, to avoid repeated strobing when reading multiple controllers
* Update joypad_ex function to call read_joypad_no_strobe repeatedly for as many controllers as initialized in joypads_t struct
2023-09-28 01:47:55 +01:00
Toxa
8cf112460b NES: remove OLDCALL attribute from the function declarations in the nes.h which has no sense 2023-09-12 20:16:58 +03:00
bbbbbr
d5f16c367e Merge pull request #558 from bbbbbr/docs_4_2_0
Docs: 4.2.0 updates + update undefs for platform header files
2023-07-28 03:21:50 -07:00
Toxa
d60d21317e Merge pull request #553 from michel-iwaniec/const_set_palette_functions
Make set_bkg_palette and set_sprite_palette take const pointers
2023-07-28 13:04:31 +03:00
bbbbbr
f979379b67 Update console un-defines in main port platform files 2023-07-28 02:52:06 -07:00
bbbbbr
f669ee9000 Docs: some rough NES info in supported consolses pages
Also:
- Minor cgb attrib related change
2023-07-28 02:15:19 -07:00
bbbbbr
3873b9bd5d Examples & Headers: fix a few minor warnings 2023-07-24 16:43:34 -07:00
Michel Iwaniec
c05d47afdd Make set_bkg_palette and set_sprite_palette take const pointers
* Update set_bkg_palette and set_sprite_palette in gbdk-lib/include/gb/cgb.h
* Update set_bkg_palette and set_sprite_palette in gbdk-lib/include/nes/nes.h
2023-07-23 23:40:07 +01:00
Michel Iwaniec
2dbb8029a3 NES: Change system define: NINTENDO_ENTERTAINMENT_SYSTEM -> NINTENDO_NES 2023-07-23 20:43:08 +01:00
Michel Iwaniec
863d24725b Add set_bkg_native_data / set_sprite_native_data functions to allow using native tile format with set_bkg_data / set_sprite_data functionality
* Update gbdk-lib/include/gb/gb.h to forward set_bkg_native_data / set_sprite_native_data to set_bkg_data / set_sprite_data functions
* Update gbdk-lib/include/sms/sms.h to forward set_bkg_native_data / set_sprite_data to set_bkg_4bpp_data / set_sprite_4bpp_data
* Add implementation for set_bkg_native_data / set_sprite_native_data in gbdk-lib/libc/targets/mos6502/nes/set_native_data.s
* Update gbdk-lib/include/nes/nes.h to include function declarations for set_bkg_native_data / set_sprite_native_data
* Update gbdk-lib/inlcude/nes/nes.h to implement set_native_tile_data in terms of set_bkg_native_data / set_sprite_native_data
* Update gbdk-lib/inlcude/nes/nes.h to implement set_tile_data in terms of set_bkg_data / set_sprite_data
* Remove old (/broken for indirect mode) code for set_tile_data / set_native_tile_data from set_data.s / set_native_data.s
* Update png2asset to include NES among the supported PackModes
* Update examples/cross-platform/logo .meta file to specify NES PackFormat for NES build
* Update examples/cross-platform/large_map Makefile to specify NES PackFormat for NES build
2023-07-21 01:35:40 +01:00
bbbbbr
6403ec586b Docs: misc 4.2 updates, formatting 2023-07-17 15:52:42 -07:00
Michel Iwaniec
c4621b8c0f Add support functions for setting an individual map attribute
* Add dedicated NES function set_bkg_attribute_xy_nes16x16 for setting an individual (shadow) attribute in gbdk-lib/libc/targets/mos6502/nes/set_attribute.s
* Add inline adapter NES function set_bkg_attribute_xy, which calls set_bkg_attribute_xy_nes16x16
* Change NES functionality to call _flush_shadow_attributes from wait_vbl_done
* Remove calls to _flush_shadow_attributes in set_bkg_attributes and set_bkg_submap_attributes
* Add dedicated SMS/GG function set_attribute_xy in gbdk-lib/libc/targets/z80/set_tile.s
* Add inline adapter GBC function set_bkg_attribute_xy in gbdk-lib/include/gb/gb.h
2023-07-17 19:46:44 +01:00
Toxa
825a20758a NES: add display_on() declaration; fix "warning 283: function declarator with no prototype" when using BANKREF macro 2023-07-14 19:04:00 +03:00
Michel Iwaniec
01db002764 NES: Add support for fake VBL / LCD ISR handling to support simple split screen / top status bar
* Add implementation for add_VBL / add_LCD and remove_VBL / remove_LCD in libc/targets/mos6502/nes/lcd.s, supporting just 1 handler to conserve memory
* Make wait_vbl_done call VBL handler, so it occurs before vblank
* Add variable _lcd_scanline, and make default vblank NMI call LCD handler after running a delay loop for this many scanlines
* Update docs to specify the limitations of the nes implementation
* Enable examples/cross-platform/scroller for nes target
* Change incorrect DEVICE_SCREEN_MAP_ENTRY_SIZE value of 2 to 1 in gbdk-lib/include/nes/hardware.h
2023-07-11 01:39:58 +01:00
Michel Iwaniec
3009f84b09 NES: Add support for bank-switching
Changes to gbdk-lib/include library headers:
* Make NONBANKED / BANKED macros in asm/mos6502/types.h expand to respective keywords instead of being no-ops
* Remove force-zero-bank version of INCBIN macros in gbdk/incbin.h in favour of regular version
* Make BANK / BANKREF macros in nes/nes.h use appropriate implementation instead of stubs
* Add SWITCH_ROM_UNROM macro, and make SWITCH_ROM use it in place of SWITCH_ROM_DUMMY in nes.h
* Add stubbed no-op versions for SWITCH_RAM / ENABLE_RAM / DISABLE_RAM in nes.h, to support cross-platform tests

changes to gbdk-support tools:
* Remove CODEFIXED segment at 0xE000 in lcc/targets.c, relying only on _CODE at 0xC000
* Make ld command use -a nes, to use virtual address translation from sdld_virtual_address_translation.patch
* Update bankpack to support "nes" as option (uses GB platform)
* Update makebin to perform NES specific bank fix (rotates ROM by one bank, putting first bank as last)
* Update png2asset to initialize bank to -1 and write #pragma bank for banks = 0, to remove assumption on bank 0 being the fixed bank

Changes to gbdk-lib/libc implementations:
* Add implementation of to_far_ptr and call__banked in targets/mos6502/far_ptr.s
* Add UNROM bank switching macros in targets/mos6502/nes/mapper_macros.s, and __swith_prg0 function in targets/mos6502/nes/mapper.s
* Add banked call support routine ___sdcc_bcall in targets/mos6502/nes/sdcc_bcall.s
* Add code to initialize switchable bank to 0 at reset in crt0

Depends on sdcc_mos6502_underscored_areas.patch, sdcc_mos6502_bank_support.patch and sdld_virtual_address_translation.patch applied to SDCC
2023-06-02 23:34:20 +01:00
Adam Shea
086db793c3 added reference to gbdk constants 2023-03-13 10:31:56 +00:00
Adam Shea
ddbf7e63fd Updated documentation for set_sprite_prop() 2023-03-12 21:59:42 +00:00
bbbbbr
ea6e9d4a8c Docs: Update metasprite info for base_props parameter
- Centralize long desription in GB header file, link others to it
2023-03-01 23:41:52 -08:00
bbbbbr
0604e99eed Docs: 4.2
- more details for for new metasprite functions
- GB: more details for BGP/OBP0/OBP1
- Remove some trailing spaces in metasprite headers
- Re-add Obsolete keyword to pre-deprecated functions
- Entries for release notes, migration notes
2023-02-22 01:45:02 -08:00
bbbbbr
ab02f7a43a Docs: 4.2
- Add note about initializing SRAM
- Add CGB section to Supported Consoles with overview, api links and list of examples (@anchor using_cgb_features)
- Initial note 4.2 migration and release notes
- API doc improvements
2023-02-17 00:23:41 -08:00
Michel Iwaniec
6bf9ce614a NES: Fix PPU register definitions
* Change defines in hardware.h to use volatile __at(addr) for regs, and extern volatile for shadow regs
2023-02-12 13:33:29 +00:00
Toxa
83d4744729 fix most of the "function declarator with no prototype" warnings 2023-02-06 01:24:16 +03:00
Michel Iwaniec
49edec1d14 NES: Add metasprite clipping support
* Change x / y parameters of move_metasprite* function definitions from uint8 to int16
* Update move_metasprite* to do 16-bit math, and reject hardware sprites outside screen
* Move flip[x/y] move_metasprite* functions into separate files for independent linking
* Move .move_metasprite_prologue / _epilogue functions into new file metasprites_common.s
2023-01-29 19:10:20 +00:00
Michel Iwaniec
6fefa11c73 NES: Add set_bkg_submap_attributes implementations
* Add definitions for ATTRIBUTE_WIDTH/_HEIGHT and ATTRIBUTE_PACKED_WIDTH/_HEIGHT to global.s
* Add subroutine set_bkg_submap_attributes_nes16x16 in gbdk-lib/libc/targets/mos6502/nes/set_tile_submap_attributes.s
* Add wrapper function set_bkg_submap_attributes working in 8x8 tile coordinate system for compatibility
* Update Makefile for lib
2023-01-15 19:10:08 +00:00
Michel Iwaniec
f82135ceab NES: Refactor attributes to use 8x8 attribute coordinate system, to be more consistent with other platforms
* Move _flush_shadow_attributes subroutine to its own file flush_attributes.s
* Add bitfield _attribute_column_dirty, and add handling of dirtied columns to _flush_attributes
* Update cross-platform/logo/src/main.c to use 8x8 coordinate system for NES

png2asset:
* Fix bug in PackMapAttributes where height was always being set to width
* Refactor BuildPalettesAndAttributes palette search into its own function FindOrCreateSubPalette
* Change BuildPalettesAndAttributes to force subPalIndex to 0 instead of causing segfault when there's too many colors for an attribute region
* Add new function AlignMapAttributes to ensure map is properly aligned for set_bkg_submap
* Change #define MAP_ATTRIBUTES_WIDTH/HEIGHT to use new 8x8 coordinate system
2023-01-14 15:26:31 +00:00
Michel Iwaniec
93cec8d24a Rename HARDWARE_SPRITE_CAN_FLIP_* defines to align with new flipx/flipy naming
* HARDWARE_SPRITE_CAN_FLIP_H -> HARDWARE_SPRITE_CAN_FLIP_X
* HARDWARE_SPRITE_CAN_FLIP_V -> HARDWARE_SPRITE_CAN_FLIP_Y
2022-11-30 23:44:53 +00:00
Michel Iwaniec
fd6a793dfc NES: Refactor metasprite functions to match GB refactoring
* Introduce global __current_base_prop and apply as offset in move_metasprite_* asm implementation
* Update move_metasprite_* functions in metasprites.h to set __current_base_prop global
2022-11-29 23:10:39 +00:00
Toxa
585b1e3cdb refactor metasprite functions, add offset for the sprite properties 2022-11-29 22:46:45 +03:00
Toxa
b0d77a5cd1 vsync() alias for wait_vbl_done() 2022-11-29 21:43:36 +03:00
Michel Iwaniec
6f2fa3c361 png2asset: Make props in generated metasprites cross-platform
* Update printing of METASPR_ITEM in png2asset to extract X/Y flip and palette number, print them as symbolic names S_FLIPX, S_FLIPY and S_PAL(...)
* (...and adjust output formatting to one METASPR_ITEM per line, for better readability)
* Add #define for S_PAL to gb.h, nes.h, msx.h and sms.h
* Remove "TODO:" comments from gbdk-lib/libc/targets/mos6502/nes/metasprites.s
2022-11-27 15:20:24 +00:00