;; This code shows:
;; 1. How to get the current drive number
;; 2. How to initialise the disc rom after loading this file (BASIC will disable all roms, effectively going to
;; cassette mode)
;; 3. How to set the current drive back again
;; 4. Using a list of files, and loading each file one-by-one. When we get to the end of the list
;; going back to the first file again. Good for slideshows ;)
;; This code builds with Pasmo assembler.

cas_in_open equ &bc77
cas_in_direct equ &bc83
cas_in_close equ &bc7a
kl_rom_walk equ &bccb
mc_start_program equ &bd16

loader_load_addr equ &9000

org loader_load_addr

;; when a binary program is started, all roms are disabled by BASIC

;; get the current drive from AMSDOS's variables
ld hl,(&be7d)
ld a,(hl)
ld (drive+1),a

ld c,&ff					;; disable all roms
ld hl,start					;; execution address for program
jp mc_start_program			;; start it

;; now enable all roms (disc rom and other DOSes included)
call kl_rom_walk

;; set back the drive
ld a,0
ld hl,(&be7d)
ld (hl),a

;; load each file and then go back to the start again
call get_next_filename
call load_next_file
jp load_loop


ld hl,(cur_filename)
push hl
;; get length of filename
call get_str_len
pop hl
ld de,&200		;; load address
call load_file

;; here we would so something with file (e.g. display picture on screen)

;; get next filename from list and update
;; cur_filename with the address of it
;; if we get to end of list, reset back to start
ld hl,(cur_filename)
call get_str_len
ld a,(hl)
or a
jr nz,gnf1
ld hl,filenames
ld (cur_filename),hl

;; Enter:
;; HL = address of string with 0 after
;; Exit:
;; B = length of string
ld b,0
ld a,(hl)
inc hl
or a
ret z
inc b
jr gsl1

;; the address of the current filename
defw filenames

;; list of filenames to load 
;; 0 indicates end of filename
db "01.scr",0
db "02.scr",0
db "03.scr",0
db "04.scr",0
db "05.scr",0
db "06.scr",0
db "07.scr",0
db "08.scr",0
db "09.scr",0
db "10.scr",0
db "11.scr",0
db "12.scr",0
db "13.scr",0

;; this 0 indicates end of list
defb 0

;; load a file
;; HL = address of filename
;; B = length
;; DE = load address

push de
ld de,&c000			;; address of 2k buffer, this can be any value if the files
					;; that are loaded have a header (e.g. BASIC/BINARY)
call cas_in_open	
pop hl
call cas_in_direct
jp cas_in_close