Simple DMA example

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Tue May 08, 2018 7:21 pm

I had a look at Tim's docs. I would have to bite the bullet if I upgrade the firmware and I'm sure I will at some point. Storing data on the SDCARD really helps speed up development rather than downloading it all the time and that's where NextPaint comes in to play as it builds the SDCARD WAD (Doom fashion). My game uses a lot of data so it's not practical to download each build - thus only needing to download code that changes is acceptable at the current max baud rate. I will have a better idea of what is required UART speed wise later in the year.

VGA timing 2 is the only mode that seems to work with my monitor. I'm happy with the video output. I have to address these issues later in my development timeline as I will need to make sure my game works on the various configurations that the community use. I know it will require 2MB of RAM. DMA will play a large roll in my code as I didn't use it much in my Terminator demo because the DMA didn't work properly when I first started coding the Next.
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Simple DMA example

Post by SevenFFF » Tue May 08, 2018 10:33 pm

Sounds good! Word of warning though, 50_60Hz=1 and HDMI timing 7 gives you significantly less T-states per frame than the other configurations. If you're pushing the limits, this might be harder to address the longer you delay it... :(

Terminator demo is ace, btw!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

Alcoholics Anonymous
Posts: 508
Joined: Mon May 29, 2017 7:00 pm

Re: Simple DMA example

Post by Alcoholics Anonymous » Wed May 09, 2018 4:28 am

KevB wrote:
Tue May 08, 2018 6:17 pm
EDIT:

This gem of info is relevant to this post. Cross-development revealed strange DMA behavior on the Next when the registers were not set correctly or in the right order. For example, I had an issue where memory paged in at location 0 was wiped. I put it down to the DMA starting before the register setup was complete. Hope this helps.
Writing WR3 with bit 6 set will start the dma immediately as it's equivalent to an ENABLE_DMA command. There is some old code floating around that erroneously did this and will start the dma prematurely. Maybe you've run into this?

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Wed May 09, 2018 3:40 pm

Alcoholics Anonymous wrote:
Wed May 09, 2018 4:28 am
Writing WR3 with bit 6 set will start the dma immediately as it's equivalent to an ENABLE_DMA command. There is some old code floating around that erroneously did this and will start the dma prematurely. Maybe you've run into this?
Thanks for the conformation. Here's the DMA fill routine that I fixed and as you can see, R3 was causing the bug. When run from a fresh power on, memory paged in a location would be corrupted although the destination would be filled with the correct BYTE.

The bug only happens once so consecutive calls would not cause the corruption until the board was powered off and on again. It went unnoticed for some time as the ROM was normally paged in at location 0. I did use reference code initially from various sources as information on the DMA was limited back in Januray 2018. Garbage in, Garbage out lol

Code: Select all

; --------------------------------------------------------------------------


; DMA fill program (fixed source address, incrementing destination).

			
dma_fill	defb	10000011b	; R6 Disable DMA **ADDED FOR SAFETY**

;;;		defb	11000011b	; R6 Reset DMA **REMOVED**
;;;		defb	11000111b	; R6 Reset port A timing **REMOVED**
;;;		defb	11001011b	; R6 Set port B timing same as port A **REMOVED**

		defb	01111101b	; R0 Operation 01 + port A and length write
		defw	solid_fill	; R0 Port A address (source)
dma_length	defw	6912		; R0 Block length (size)

		defb	01100100b 	; R1 Port A fixed + timing byte write
		defb	2		; R1 Cycle length port A
		  
		defb	01010000b	; R2 Port B increments + timing byte write
		defb	2		; R2 Cycle length port B
	
;;;		defb	11000000b	; R3 Enable DMA **CAUSES ADDRESS 0 BUG**
	  
		defb	10101101b 	; R4 Operation mode 01 + port B write
dma_address	defw	16384		; R4 Port B address (destination)
		  
		defb	10000010b	; R5 Stop on end of block, read active LOW
	 
		defb	11001111b	; R6 Load
;;;		defb	10110011b	; R6 Force ready **REMOVED**
		defb	10000111b	; R6 Enable DMA
dma_end


; --------------------------------------------------------------------------
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Wed May 09, 2018 3:57 pm

SevenFFF wrote:
Tue May 08, 2018 10:33 pm
Sounds good! Word of warning though, 50_60Hz=1 and HDMI timing 7 gives you significantly less T-states per frame than the other configurations. If you're pushing the limits, this might be harder to address the longer you delay it... :(

Terminator demo is ace, btw!
I've got to leave myself plenty of headroom and develop for 60hz rather than just try and speed things up later... I have to wave goodbye to those extra cycles as I know I cannot have them :(

Thanks :)
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: Simple DMA example

Post by SamusDrake » Wed May 09, 2018 6:37 pm

KevB - you have a Sega Multi-Mega? Gawd, I wanted one of those as a youngster! Does yours still work?

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Wed May 09, 2018 6:53 pm

SamusDrake wrote:
Wed May 09, 2018 6:37 pm
KevB - you have a Sega Multi-Mega? Gawd, I wanted one of those as a youngster! Does yours still work?
It does still work although the CD drive packed up around 2000 lol. It was in the bargain bin of some high street electrical store for £89... they didn't sell but not surprised at £399 so the store was trying to get rid of them.
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: Simple DMA example

Post by SamusDrake » Wed May 09, 2018 8:02 pm

KevB wrote:
Wed May 09, 2018 6:53 pm
SamusDrake wrote:
Wed May 09, 2018 6:37 pm
KevB - you have a Sega Multi-Mega? Gawd, I wanted one of those as a youngster! Does yours still work?
It does still work although the CD drive packed up around 2000 lol. It was in the bargain bin of some high street electrical store for £89... they didn't sell but not surprised at £399 so the store was trying to get rid of them.
OMG, I remember that price tag...ouch! :shock:

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Wed May 09, 2018 8:03 pm

It was way too high even for a machine with DMA lol
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

User avatar
KevB
Posts: 57
Joined: Tue Dec 19, 2017 6:34 pm
Location: Yorkshire, United Kingdom
Contact:

Re: Simple DMA example

Post by KevB » Wed May 09, 2018 8:33 pm

KevB wrote:
Tue May 08, 2018 6:59 pm
I think I'm on standard VGA timings (2).
I had a quick check and turns out that I am on VGA timing 0 which was the default VGA setting shipped with the Next distribution. My monitor reports 30KHz / 49.2Hz 700x575.
128K+, +2, +3, MF3, TBBlue 2A (2MB). ZX Spectrum fan since 1985. Next developer https://twitter.com/9bitcolor :: http://www.9bitcolor.com/

Post Reply