Login
Back to forumSee the full topicGo to last reply

Posted By

Harry Potter
on 2022-06-16
10:00:55
 Re: MemBankP1 demo program error

Could it be writing to the wrong RAM location? Following are the code to write to expansion RAM:

------------------------------
_bank1_writebyte:
;jsr popa
pha
jsr popax
sta ptr1
stx ptr1+1
pla
ldy #0
jmp bank1_writebytedirect

_bank1_writeword:
;jsr popax
pha
stx tmp1
jsr popax
sta ptr1
stx ptr1+1
pla
ldx tmp1
jmp bank1_writeworddirect



.segment "MEMBANK"

bank1_writebytedirect:
;sta $FF02
pha
lda #$32
sta $FD16
pla
sta (ptr1),y
lda #$33
sta $FD16
rts

bank1_writeworddirect:
pha
lda #$32
sta $FD16
pla
sta $FF02
sta (ptr1),y
iny
txa
sta (ptr1),y
lda #$33
sta $FD16
rts
------------------
and to load the banked data:
------------------
unsigned __fastcall__ bank1_cbm_read (unsigned char lfn, void* buffer, unsigned size)
/* Reads up to "size" bytes from a file to "buffer".
* Returns the number of actually read bytes, 0 if there are no bytes left
* (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
* table below).
*/
{
static unsigned int bytesread;
static unsigned char tmp;

/* if we can't change to the inputchannel #lfn then return an error */
if (_oserror = cbm_k_chkin(lfn)) return -1;

bytesread = 0;
while (bytesread tmp = cbm_k_basin();
/* the kernal routine BASIN sets ST to EOF if the end of file
* is reached the first time, then we have store tmp.
* every subsequent call returns EOF and READ ERROR in ST, then
* we have to exit the loop here immidiatly. */
if (cbm_k_readst() & 0xBF) break;
//++*(unsigned char*)0xC00;
//((unsigned char*)buffer)[bytesread++] = tmp;
//bank1_writebyte (((unsigned char*)buffer)[bytesread++], tmp);
bank1_writebyte (((unsigned char*)buffer)[bytesread], tmp);
++bytesread;
//home(); printu (bytesread);
}
cbm_k_clrch();
//putchar ('-'); cgetc();
return bytesread;
}
--------------




Back to top


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon