Hello,
Can someone give me some light on this issue, please?
The code below is supposed to read a .sc2 file (without the header) to vram, by copying 128 bytes from the file each time. As much as I can see in the debug, the code is copying all the data correctly. Despite that, all I see is garbage on screen. Is there anything I'm doing terrible wrong here or maybe I am copying data wrong (and I couldn't see when debugging) ?
BDOS: equ 00005H
STROUT: EQU 00009H
FOPEN: EQU 0000FH
FCLOSE: EQU 00010H
RDSEQ: EQU 00014H
SETDTA: EQU 0001AH
CHGMOD: EQU 005FH
ldirvm: equ 0x005C
CALSLT: equ 0x001C
EXPTBL: equ 0xFCC1
org 0x100
START:
ld a,2 ;sets screen 2
ld iy,(EXPTBL-1)
ld ix,CHGMOD
call CALSLT
; GETS THE NAME OF THE FILE (WITHOUT EXTENSION)
; AND PUTS in the FCB.
LD HL,082H
LD DE,FCB+1
START0:
LD A,(HL)
CP 0DH
JR Z,START1
LD (DE),A
INC HL
INC DE
JR START0
; Open file
START1:
LD DE,FCB ;
LD C,FOPEN ;
CALL BDOS
INC A
JP Z,ERROR1
; starts reading file, 128 bytes each time.
LD DE,BUFFER
LD HL,080H
LD IX,0
; LOOP that reads 128 bytes each turn and writes in BUFFER
; DE = fist empty position of the buffer
START2:
PUSH IX
PUSH DE
PUSH HL
LD C,SETDTA
CALL BDOS
LD DE,FCB
LD C,RDSEQ
CALL BDOS
DEC A
JR Z,START3
POP DE
POP HL
POP IX
INC IX
ADD HL,DE
EX DE,HL
; copy 128 bytes to VRAM;
push HL
push DE
ld h,d
ld l,e
ld d,0
ld e,80h
SBC HL,DE ; HL = DE - 80H (HL = START OF BUFFER)
pop DE ; DE = FIRST BYTE EMPTY IN BUFFER
push DE
push HL ;
LD DE,BUFFER
SBC HL, DE
ld d, h
ld e, l ;
pop HL
PUSH IX;
ld iy,(EXPTBL-1)
ld ix,ldirvm
call CALSLT
POP IX;
pop DE
pop HL
JR START2
LD DE,FCB
LD C,FCLOSE
CALL BDOS
JP 0
START3:
ERROR1:
RET
ERROR2:
RET
TOTAL: DW 0
FCB: DB 0
DB 32,32,32,32
DB 32,32,32,32
DB 'SC2'
DB 0,0,0,0,0,0,0,0,0,0,0
DB 0,0,0,0,0,0,0,0,0,0,0
DB 0,0,0,0,0,0,0,0,0,0,0
DB 0,0,0,0,0,0,0,0,0,0,0
BUFFER:
end