<commit_before>; freemlib for Neo-Geo: Sound Driver (ROM)
; assemble with vasm z80 (oldstyle syntax)
;==============================================================================;
; Defines for RST usage, in case the locations change later.
rst_PortDelay1	= $08
rst_PortDelay2	= $10
rst_Write45		= $18
rst_Write67		= $20
rst_BusyWait	= $28
;==============================================================================;
	include "sounddef.inc"
	include "sysmacro.inc"
;==============================================================================;
	section start
; $0000: Disable interrupts and jump to the real entry point
Start:
	di						; Disable interrupts (Z80)
	jp		EntryPoint
;==============================================================================;
	section delay1
; Port Delay Write for Addresses
portWriteDelayPart1:
	jp		portWriteDelayPart2
;==============================================================================;
	section delay2
; Port Delay Write for Data
portWriteDelayPart3:
	jp		portWriteDelayPart4
;==============================================================================;
	section write45
j_write45:
	jp		write_45
;==============================================================================;
	section write67
j_write67:
	jp		write_67
;==============================================================================;
	section ymwait
; Keep checking the busy flag in Status 0 until it's clear.

; Code from smkdan's example M1 driver (adpcma_demo2/sound_M1.asm), where he
; uses this instead of portWriteDelayPart2 and portWriteDelayPart4.
; It's noted that "MAME doesn't care". The hardware does, however.

CheckBusyFlag:
	in		a,(YM_Status0) ; read Status 0 (busy flag in bit 7)
	add		a
	jr		C,CheckBusyFlag
	ret
;==============================================================================;
	;org $0030
;==============================================================================;
	section IRQ
; the IRQ belongs here.
j_IRQ:
	di
	jp		IRQ
;==============================================================================;
	section idstr
; driver signature; subject to change.
driverSig:
	asc "freemlib "
	ifd TARGET_CD
		asc	"Neo-CD"
	else
		asc	"NG-ROM"
	endif

	asc	" SoundDriver v000"
;==============================================================================;
	section NMI
; NMI
; Inter-processor communications.

; In this driver, the NMI gets the command from the 68K and interprets it.

NMI:
	; save registers
	push	af
	push	bc
	push	de
	push	hl

	in		a,(0)			; Acknowledge NMI, get command from 68K via Port 0
	ld		b,a				; save command into b for later

	; "Commands $01 and $03 are always expected to be implemented as they
	; are used by the BIOSes for initialization purposes." - NeoGeoDev Wiki
	cp		1				; Command 1 (Slot Switch)
	jp		Z,doCmd01
	cp		3				; Command 3 (Soft Reset)
	jp		Z,doCmd03
	or		a				; check if Command is 0
	jp		Z,endNMI		; exit if Command 0

	; do NMI crap/handle communication... I'm not fully sure what to do yet.
	ld		(curCommand),a	; update curCommand
	call	HandleCommand

	; update previous command<commit_msg>NGCD sound driver target renamed from "Neo-CD" to "NG-CDA"<commit_after>; freemlib for Neo-Geo: Sound Driver (ROM)
; assemble with vasm z80 (oldstyle syntax)
;==============================================================================;
; Defines for RST usage, in case the locations change later.
rst_PortDelay1	= $08
rst_PortDelay2	= $10
rst_Write45		= $18
rst_Write67		= $20
rst_BusyWait	= $28
;==============================================================================;
	include "sounddef.inc"
	include "sysmacro.inc"
;==============================================================================;
	section start
; $0000: Disable interrupts and jump to the real entry point
Start:
	di						; Disable interrupts (Z80)
	jp		EntryPoint
;==============================================================================;
	section delay1
; Port Delay Write for Addresses
portWriteDelayPart1:
	jp		portWriteDelayPart2
;==============================================================================;
	section delay2
; Port Delay Write for Data
portWriteDelayPart3:
	jp		portWriteDelayPart4
;==============================================================================;
	section write45
j_write45:
	jp		write_45
;==============================================================================;
	section write67
j_write67:
	jp		write_67
;==============================================================================;
	section ymwait
; Keep checking the busy flag in Status 0 until it's clear.

; Code from smkdan's example M1 driver (adpcma_demo2/sound_M1.asm), where he
; uses this instead of portWriteDelayPart2 and portWriteDelayPart4.
; It's noted that "MAME doesn't care". The hardware does, however.

CheckBusyFlag:
	in		a,(YM_Status0) ; read Status 0 (busy flag in bit 7)
	add		a
	jr		C,CheckBusyFlag
	ret
;==============================================================================;
	;org $0030
;==============================================================================;
	section IRQ
; the IRQ belongs here.
j_IRQ:
	di
	jp		IRQ
;==============================================================================;
	section idstr
; driver signature; subject to change.
driverSig:
	asc "freemlib "
	ifd TARGET_CD
		asc "NG-CDA"
	else
		asc "NG-ROM"
	endif

	asc " SoundDriver v000"
;==============================================================================;
	section NMI
; NMI
; Inter-processor communications.

; In this driver, the NMI gets the command from the 68K and interprets it.

NMI:
	; save registers
	push	af
	push	bc
	push	de
	push	hl

	in		a,(0)			; Acknowledge NMI, get command from 68K via Port 0
	ld		b,a				; save command into b for later

	; "Commands $01 and $03 are always expected to be implemented as they
	; are used by the BIOSes for initialization purposes." - NeoGeoDev Wiki
	cp		1				; Command 1 (Slot Switch)
	jp		Z,doCmd01
	cp		3				; Command 3 (Soft Reset)
	jp		Z,doCmd03
	or		a				; check if Command is 0
	jp		Z,endNMI		; exit if Command 0

	; do NMI crap/handle communication... I'm not fully sure what to do yet.
	ld		(curCommand),a	; update curCommand
	call	HandleCommand

	; update previous command
{'fraction_non_alphanumeric': 0.3519436890097584, 'fraction_numerical': 0.02495600703887378, 'mean_word_length': 5.6158730158730155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841587', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1702, 'n_words': 597}