VOGONS


First post, by carlos12

User metadata
Rank Newbie
Rank
Newbie

Hi there! This is my first message here, long time reader. I hope I'm posting it at the right section.

As everyone knows, the IBM PC and later (except the PCjr) have a DMA controller. Channel 2 is used by the floppy controller. Maybe channel 3 is used by the hard drive controllers?

Can the DMA be used to load any DOS file into RAM by using DMA so it can be done as a background task? My aim is to achieve an effect similar to some arcade machines where the characters are still playable while new backgrounds, enemies, music or whatever, are loaded from ROM to RAM. I read some IBM and DOS programming books, including the Norton, Wilton and Abrash's ones, but I wasn't able to find any concrete information and sample code about this. All I read is too vague and abstract, too "yes, there's a DMA controller, you can use it" but nothing about how actually do it.

I found this code at https://wiki.osdev.org/ISA_DMA

initialize_floppy_DMA:
; set DMA channel 2 to transfer data from 0x1000 - 0x33ff in memory
; paging must map this _physical_ memory elsewhere and _pin_ it from paging to disk!
; set the counter to 0x23ff, the length of a track on a 1.44 MiB floppy - 1 (assuming 512 byte sectors)
; transfer length = counter + 1
out 0x0a, 0x06 ; mask DMA channel 2 and 0 (assuming 0 is already masked)
out 0x0c, 0xFF ; reset the master flip-flop
out 0x04, 0 ; address to 0 (low byte)
out 0x04, 0x10 ; address to 0x10 (high byte)
out 0x0c, 0xFF ; reset the master flip-flop (again!!!)
out 0x05, 0xFF ; count to 0x23ff (low byte)
out 0x05, 0x23 ; count to 0x23ff (high byte),
out 0x81, 0 ; external page register to 0 for total address of 00 10 00
out 0x0a, 0x02 ; unmask DMA channel 2
ret

prepare_for_floppy_DMA_read:
out 0x0a, 0x06 ; mask DMA channel 2 and 0 (assuming 0 is already masked)
out 0x0b, 0x56 ; 01010110
; single transfer, address increment, autoinit, read, channel2)
out 0x0a, 0x02 ; unmask DMA channel 2
ret

But I would like to read a file instead of reading a raw cluster or track from the disk.

I also looked at DOS' INT 21h references but wasn't able to find anything.

Thank you for your help.

Reply 1 of 1, by Mov AX, 0xDEAD

User metadata
Rank Newbie
Rank
Newbie
carlos12 wrote on 2025-04-05, 13:52:

As everyone knows, the IBM PC and later (except the PCjr) have a DMA controller. Channel 2 is used by the floppy controller. Maybe channel 3 is used by the hard drive controllers?

Can the DMA be used to load any DOS file into RAM by using DMA so it can be done as a background task? My aim is to achieve an effect similar to some arcade machines where the characters are still playable while new backgrounds, enemies, music or whatever, are loaded from ROM to RAM.

By default DOS/BIOS API is synchronous and no way to do something in background. If you want background loading on PC/XT, you can do it only with floppy because there is no single "standart" for hard drive controllers. Your software must include all low-level routines to deal with floppy controller. While you render sprites on screen, you control DMA and floppy to load next sector/track, after this was done by hardware you will IRQ triggered to do something with loaded to RAM data. Also write own FAT file system implementation if you don't like raw sectors without filesystem. Some early PC games doesn't use FAT, they load sectors direclry from know location in disk