553 Commits

Author SHA1 Message Date
Phidias618
7e0e1d9bcf Optimization of memset small for the duck port 2026-03-08 19:01:58 +01:00
Phidias618
f0279fb197 Optimize memset function in crt0.s for the gb 2026-03-08 18:53:20 +01:00
Toxa
ec24d3138a Merge pull request #867 from Phidias618/patch-2 2026-03-08 11:42:53 +03:00
Phidias618
7611b022b4 Revert "Fix divisions by one" 2026-03-07 19:07:58 +01:00
Phidias618
3cc6827b8b Fix divisions by one 2026-03-02 12:42:10 +01:00
Toxa
2f79d89430 changed attributing of div.s and mul.s for the SM83 target, because that is now the original implementation 2026-02-08 14:53:38 +03:00
Phidias618
428d49338c Optimization of multiplications (#859)
Optimization of multiplications
2026-02-08 11:46:51 +03:00
Toxa
ff0e55bd3b GB/SMS/GG: remove obsolete EMU_profiler_message() support which caused problems when building with --debug and have no sense anymore 2026-02-04 19:23:36 +03:00
Phidias618
230971708a Optimisation of divisions (#856)
Optimisation of the integer divisions
2026-01-21 18:52:10 +03:00
Phidias618
cfedcea675 Minor optimisation of .MemsetSmall for the sm83 2026-01-21 12:25:05 +01:00
Toxa
bab52712cf GB: a few minor optimizations to the integer division routines 2026-01-13 19:23:54 +03:00
Toxa
a51b4e04cc GB: fix the crash_handler 2026-01-04 00:21:34 +03:00
Michel Iwaniec
8ffaa2ce95 NES: Refactor fill_bkg_rect to call set_bkg_tile_xy
- Somewhat slower code, but smaller

- Enables correct wrap-around over screen edges

- Works for all nametable layouts
2025-12-27 12:56:47 +00:00
Toxa
48d8b5207b SMS/GG/MSX: Unify banked call functions file names, put out legacy ___sdcc_bcall trampoline which saves a few bytes 2025-12-02 11:40:15 +03:00
Toxa
9e18a081bb GB: Improve performance of the banked calls 2025-12-02 01:34:47 +03:00
Toxa
0f5160316f GB: refactor get_bkg_xy_addr()/get_win_xy_addr() 2025-11-23 02:11:19 +03:00
Toxa
d2be3941d4 SMS/GG: tilemap width was not set correctly in the set_tile_submap_compat() function 2025-09-12 17:26:14 +03:00
Toxa
d59bd395a8 SMS/GG: fix parameter order on the set_tile_submap/set_tile_submap_compat 2025-09-12 15:37:28 +03:00
Toxa
a2de13022e GB, SMS, MSX: include ZX0 decompressor into the library 2025-09-11 15:03:44 +03:00
Toxa
c2a4e9c4ee GB: align __current_bank by the 0xff90 address for compatibility reasons 2025-09-07 01:36:49 +03:00
Toxa
3e7ce5d54b GB: ability to dynamically allocate variables in HRAM on the SM83 targets 2025-09-07 01:00:20 +03:00
bbbbbr
04bac46997 Duck: changes resulting from printer research and example work (#807)
- Rework printer status functions
- Add printer query function
2025-08-11 16:55:57 -07:00
Michel Iwaniec
4f7507f94e NES remove broken and unused FAST_DIV8 macro (#794) 2025-06-28 10:31:35 +01:00
Toxa
64eb14fb97 SMS/GG/MSX remove broken and unused FAST_DIV8 macro 2025-06-09 00:46:56 +03:00
Toxa
74cfc853da fix escaping % symbol in printf and sprintf 2025-06-08 21:21:21 +03: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
Michel Iwaniec
b1e1dc04a2 NES: Merge all temp registers into one file, to ensure a continuous section of ZP (#773)
- Merge _dptr.s and _ret*.s into _temp.s

- Add ALL_REGTEMPS_BEGIN / ALL_REGTEMPS_END labels so interrupts can easily push / pop temps
2025-05-05 23:53:09 +01:00
Michel Iwaniec
2b633b83cd NES: Refactor display_on / display_off and deferred isr code (#768)
- Move code for deferred isr buffer building to separate function .deferred_isr_run in file deferred_isr.s

- Introduce function .deferred_isr_reset to write shadow regs as first (VBL) buffer entry

- Add new subroutine .deferred_isr_reset_and_init that runs .deferred_isr_reset and .deferred_isr_run twice

- Drain buffer when DISPLAY_OFF is called, by making sure a single NMI execution happens before screen is turned off in vblank

- Change DISPLAY_OFF to write only DISPLAY_OFF flag and PPUMASK, but leave shadow_PPU_MASK unchanged

- Call .deferred_isr_reset_and_init in DISPLAY_ON when display changes from off to on

- Make DISPLAY_ON run run VBL / LCD handlers to reinitialize buffers when display switches from off to on

- Change early-out in NMI handler to rely on DISPLAY_OFF flag instead of shadow_PPUMASK

- Remove mentioned of manual-draining caveat in docs, as it no longer applies

- Add minor size/speed optimization of frame counter increment in NMI, to prevent branch penalties / incorrect system detection
2025-04-27 10:38:06 +01:00
Michel Iwaniec
10cc14645a NES: Fix bug in ISR removal (#767)
NES: Fix bug in ISR removal (#767)

- Replace incorrect code copying jmp address's opcodes with the actual address
2025-04-26 13:24:24 +01:00
Michel Iwaniec
bbc6375fe3 NES: Fix problem with screen being blank before first vsync() call (#765)
NES: Fix problem with screen being blank before first vsync() call (#765)

- Call .write_shadow_registers_to_buffer at reset, to initialize VBL buffer
2025-04-22 19:01:26 +01: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
8df4497c47 NES: Re-introduce optimization to exit NMI handler early if LCD ISR is disabled (#754)
- Add check to terminate buffer if LCD-ISR disabled (.jmp_to_LCD_isr starts with RTS opcode) in vsync
2025-03-26 15:10:21 +00:00
Michel Iwaniec
3303094718 NES: Reduce zeropage usage by merging flag for oam validity and forced blanking to one byte (#753) 2025-03-24 00:35:02 +00:00
Michel Iwaniec
79bd1341eb NES: Double-buffered deferred LCD ISR support for less graphics glitches, at expense of more RAM usage. (#751)
- Define new constant .MAX_DEFERRED_ISR_CALLS as .MAX_LCD_ISR_CALLS+1

- Refactor vsync function for double-buffering, and have it flip the read index at completion

- Refactor .do_lcd_ppu_reg_writes, and rename to .do_hblank_writes

- Remove scroll glitch mitigation in .do_hblank_writes, as no longer needed

- Redefine __lcd_isr_ arrays sizes as 2*.MAX_DEFERRED_ISR_CALLS

- remove redundant ZP variable __crt0_disableNMI, as no longer needed

- TAB -> space conversion
2025-03-21 14:35:24 +00:00
bbbbbr
a2aa923973 Merge pull request #749 from bbbbbr/megaduck/laptop_io_updates
MegaDuck: Updated on duck laptop IO commands, expose a few vars
- Printer command labeled and some query commands for the init result
- Run cart command labeled
2025-03-13 01:59:15 -07:00
bbbbbr
692aec8b2d MegaDuck: Updated on duck laptop IO commands, expose a few vars
- Printer command labeled and some query commands for the init result
- Run cart command labeled
2025-03-13 01:55:39 -07: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
Toxa
bd99d4ce69 SMS/GG: Timer interrupt emulation 2025-02-24 23:02:36 +03:00
Toxa
2d32eedb6e SMS/GG: Improve metasprite clipping by Y, change coordinate type to signed int16 2024-12-17 22:39:10 +03:00
Michel Iwaniec
d2a4c10458 NES: Fix bug with set_bkg_1bpp_data not working in buffered mode (#734)
Replace direct PPUADDR / PPUDATA writes with calls to _set_vram_byte.
2024-12-16 21:16:31 +00:00
Toxa
64cd76351b GB: prevent halt bug triggering if hblank_copy_vram() was called at the unlucky moment 2024-12-05 19:41:27 +03:00
bbbbbr
2dba64d663 Merge pull request #723 from bbbbbr/examples/mbc7_accelerometer
Examples: MBC7 support and example
2024-10-23 03:11:49 -07:00
bbbbbr
cd9be14784 Export _vbl_done for z80 platforms as well
- Also fix incorrect flag state comment for gb version
2024-10-23 03:05:34 -07:00
bbbbbr
0e2243641b Examples: MBC7 support and example 2024-10-23 01:47:38 -07: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
d009bfeeda NES: Fix bug with multiple column attribute updates (#721)
* Make sure that each column re-adds PPU lo offset instead of storing it
* Wrap functionality in a macro WRITEVERT
2024-10-20 00:10:49 +01:00
Michel Iwaniec
0c243451c5 NES: Refactor NES palette setting functions for smaller code (#720)
* Refactor set_bkg_palette / set_sprite_palette
* Refactor set_bkg_palette_entry / set_sprite_palette_entry
2024-10-19 22:57:08 +01:00
Michel Iwaniec
2de8c0dc5b NES: Add delay function for compatibility (#718) 2024-10-15 14:44:17 +01:00