I modified this code written by Giovanni Nunes in order to load a .sc2 file from disk to RAM, and from RAM I send the data to VRAM to display the image.
The code works ok, but if I want to read a big file (for instance, an SC8 image, that has > 50 kb) ? I understand that I will have to change the record size being read (which would be the best size choice in order to not get the code too much slower ?), and keep reading / transfering, but How can I do that?
; load the contents of a file to VRAM
;
;
OpenFile: equ 0x0f
UpdateFile: equ 0x10
SetBuffer equ 0x1a
GetFileSize equ 0x23
ReadRecords: equ 0x27
CHGMOD: EQU 005FH
ldirvm: equ 0x005C
CHGET equ 0x009F
BDOS: equ 0xf37d
;
; macro that creates a FCB structure
;
macro ____fcb_struct,data
drive_of_ ## data
ds 1,0
name_of_ ## data
ds 8,0
extension_of_ ## data
ds 3,0
current_block_of_ ## data
ds 2,0
record_size_of_ ## data
ds 2,0
size_of_ ## data
ds 4,0
date_of_ ## data
ds 2,0
time_of_ ## data
ds 2,0
reserved_of_ ## data
ds 8,0
current_record_of_ ## data
ds 1,0
record_of_ ## data
ds 4,0
endm
org 0x9000-7
db 0xfe
dw programStart
dw programStop
dw programStart
programStart:
jr loadFile
filename:
db "DOUBLEDR"
db "SC2"
filesize:
dw 14343
buffer:
dw fileContent
error:
db 0xff
file:
____fcb_struct file
loadFile:
;
; put the name of the file in FCB
;
ld bc,8+3
ld hl,filename ; copy name of the file and extension
ld de,name_of_file ; to 'file'
ldir
;
; sets the RAM address that will receive the block read from file
;
ld de,fileContent ; sets the ram region to receive the data from file
ld c,SetBuffer
call BDOS
;
; 3 – open file
;
ld de,file ; points to 'file'
ld c,OpenFile ; open file
call BDOS
cp 0xff ; did it return 'File not found'?
jr z,errorCatch ; goes to error treatment
;
; Gets the size of the file
;
ld de,file ; points to 'file'
ld c,GetFileSize ; recover file size
call BDOS
cp 0xff ; anything wrong?
jr z,errorCatch ; goes to error treatment
;
; *** verify if the size of the file is correct ***
;
ld de,(size_of_file) ;
ld hl,(filesize) ;
sbc hl,de ;
ld a,h ;
xor l ;
cp 0
jr nz,errorCatch ;
; place the file pointer to the beginning of the file
;
ld hl,0 ;
ld (record_of_file),hl ;
ld (record_of_file+2),hl ;
; Defines the block size to be read (record size).
;
ld hl,(filesize) ; recovers the size
ld (record_size_of_file),hl ; everything is read at once
; transfer content of file to RAM.
;
ld hl,1 ; reads 1 record of 13343 bytes
ld de,file
ld c,ReadRecords ;
call BDOS
cp 255
jr z,errorCatch ;
; close file
;
ld de,file
ld c,UpdateFile ;
call BDOS
xor a
ld (error),a ; colocar '0' como código de erro
ld a,2 ; screen 2
call CHGMOD
di
ld a, 0x00 ; set the border color to black
out (0x99), a
ld a, 0x87
out (0x99), a
ei
ld hl,fileContent+7 ; send all image data to VRAM
ld de, 0
ld bc, 14343
call ldirvm
call CHGET ; waits for input
ret
errorCatch:
ld a,255
ld (error),a
ret
fileContent:
programStop:
db $