; Cargador de Last Ninja 2
org #6000

begin_loader:

.SCR_SET_MODE   equ &BC0E
.SCR_SET_INK    equ &BC32
.SCR_SET_BORDER equ &BC38
.KL_L_ROM_DISABLE equ &B909
.KL_U_ROM_DISABLE equ &b903

.mc_start_program	equ &bd16
.kl_rom_walk		equ &bccb

;; firmware function to open a file for reading
.cas_in_open equ &bc77
;; firmware function to read an entire file (must have a AMSDOS header)
;; the file must have been opened for reading
.cas_in_direct equ &bc83
;; firmware function to close a file opened for reading
.cas_in_close equ &bc7a

ld c,&ff					;; disable all roms
ld hl,newstart					;; execution address for program
call mc_start_program

newstart:
call kl_rom_walk

ld a,1
CALL SCR_SET_MODE
LD BC,&0000 ;; Borde negro
CALL SCR_SET_BORDER

LD B,4
XOR A
next:
PUSH BC
PUSH AF
LD BC,&0000
CALL SCR_SET_INK
POP AF
INC A
POP BC
DJNZ next

LD BC,&BC01
OUT (C),C
LD BC,&BD20 ;; Solo 32 columnas
OUT (C),C
LD BC,&BC06
OUT (C),C
LD BC,&BD18 ;;Solo 24 lineas
OUT (C),C
LD BC,&BC02 ;; Movimiento horizontal
OUT (C),C
LD BC,&BD2A ;;Solo 24 lineas
OUT (C),C


ld b,end_filename3-filename3 ;;Carga de la pantalla
ld hl,filename3
ld de,0

call cas_in_open

ld hl,&C000
call cas_in_direct

call cas_in_close


LD A,0
LD BC,&1A1A
CALL SCR_SET_INK
LD A,2
LD BC,&0909
CALL SCR_SET_INK
LD A,3
LD BC,&0606
CALL SCR_SET_INK


;; B = length of the filename in characters
ld b,end_filename1-filename1

;; HL = address of the start of the filename
ld hl,filename1

;; DE = address of a 2k buffer
;; 
;; in disc mode
;; This buffer is not used when CAS IN DIRECT
;; firmware function is used, so it is safe to put it anywhere
;; you want.
ld de,0

;; firmware function to open a file for reading
call cas_in_open

;; cas_in_open returns:
;; if file was opened successfully:
;; - carry is true 
;; - HL contains address of the file's AMSDOS header
;; - DE contains the load address of the file (from the header)
;; - BC contains the length of the file (from the file header)
;; - A contains the file type (2 for binary files)

;; firmware function to load the entire file
;; this will work with files that have a AMSDOS header (ASCII
;; files do not have a header)

;; HL = load address
ld hl,&fe00
;; read file
call cas_in_direct

;; firmware function to close a file opened for reading
call cas_in_close

jp &fe00

.filename1
defb "LL.BIN"
.end_filename1
.filename2
defb "F1P2.BIN"
.end_filename2
.filename3
defb "LN.SCR"
.end_filename3

end_loader:

