Accessing sideways ram from an event handler

discussion of beeb/electron applications, languages, utils and educational s/w
Post Reply
User avatar
jms2
Posts: 2294
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Accessing sideways ram from an event handler

Post by jms2 » Tue Apr 23, 2019 11:45 am

I have written a short piece of event-driven code which I'm using to monitor the contents of sideways ram for hardware testing purposes. It works, but is not 100% reliable - ie it crashes about 4 times out of 5. I suspect that some aspect of the way I am handling events is not quite right, but I can't figure it out. I'd appreciate some pointers as to what I'm doing wrong.

There are two elements to the program:

1) An event handler, driven by VSYNC, which pages in the selected bank, copies the first 256 bytes as raw data to screen memory, then pages the original ROM (typically BASIC) back in. Thus it provides a "live" picture of what is in that chunk of memory (in the form of pixels). What I'm looking for is any unexpected glitches.

2) A facility to write that chunk of sideways ram with a specified value (this then becomes visible on the screen due to the event handler).

Part 1 works fine, on the surface at least.
Part 2 is the bit that sometimes fails. It does this even in an emulator, so I know it's my programming at fault rather than the hardware.

I had a hunch that the event handler was causing the "write" routine to fail, so I switched it off during the writing process using *FX13,4. This seems to have cured the problem, so I think my event handler must be doing something illegal. This solution is fine for my purposes, and I can leave it like that, but I'd like to understand what the problem was. The event handler seems correct to me:

- It saves and restores all the registers.
- it does not use any OS routines.
- when finished it does a JMP (oldvector)

The only thing I can think of is that the time taken to copy 256 bytes is perhaps a bit too long?

cmorley
Posts: 1007
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford
Contact:

Re: Accessing sideways ram from an event handler

Post by cmorley » Tue Apr 23, 2019 12:01 pm

Did you update the OS copy of the ROM page register (&F4) before changing the register?

User avatar
jms2
Posts: 2294
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Re: Accessing sideways ram from an event handler

Post by jms2 » Tue Apr 23, 2019 12:33 pm

Good call. Yes I did, from memory I did:

LDA romnumber
STA &F4
STA &FE05

I also used the Electron-specific "double select" method where you select a high-numbered rom first and then the required rom.

Another thing that I realized you need to do is read the current rom number from &F4 rather than from &FE05, because the latter is a write-only register.

User avatar
jgharston
Posts: 3718
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Accessing sideways ram from an event handler

Post by jgharston » Tue Apr 23, 2019 2:02 pm

jms2 wrote:
Tue Apr 23, 2019 12:33 pm
Good call. Yes I did, from memory I did:
LDA romnumber
STA &F4
STA &FE05
I also used the Electron-specific "double select" method where you select a high-numbered rom first and then the required rom.
Are you doing it *both* times? Eg:
; X=rom number
.SelectROM
LDA #12:JSR SelectROM2:TXA
.SelectROM2
STA &F4:STA &FE05:RTS

alternatively,
; A=rom number
.SelectROM
LDX #12:JSR SelectROM2:TAX
.SelectROM2
STX &F4:STX &FE05:RTS

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jms2
Posts: 2294
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Re: Accessing sideways ram from an event handler

Post by jms2 » Tue Apr 23, 2019 2:10 pm

Yes, I'm pretty sure... although my code doesn't use the JSR:

\A=rom number
PHA
LDA#12
STA &F4
STA &FE05

PLA
STA &F4
STA &FE05

Am I OK using the stack in this way?

cmorley
Posts: 1007
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford
Contact:

Re: Accessing sideways ram from an event handler

Post by cmorley » Tue Apr 23, 2019 3:25 pm

Well, that is what the stack is for!

Remove stuff until you have a minimal example which crashes and post the code. It isn't clear to me what machine you are targetting either, is it the Elk then?

User avatar
tricky
Posts: 3772
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Accessing sideways ram from an event handler

Post by tricky » Tue Apr 23, 2019 3:54 pm

I don't know about the elk, nor if it is legal on the beeb, but in an interrupt, not calling the is or unknown code, I don't change &F4, but use it to restore romsel.

User avatar
jms2
Posts: 2294
Joined: Mon Jan 08, 2007 6:38 am
Location: Derby, UK
Contact:

Re: Accessing sideways ram from an event handler

Post by jms2 » Tue Apr 23, 2019 6:44 pm

cmorley wrote:
Tue Apr 23, 2019 3:25 pm
It isn't clear to me what machine you are targetting either, is it the Elk then?
Whoops, yes I should have said that.
tricky wrote:
Tue Apr 23, 2019 3:54 pm
I don't know about the elk, nor if it is legal on the beeb, but in an interrupt, not calling the is or unknown code, I don't change &F4, but use it to restore romsel.
I suspect that may not be legal... but it is probably OK. Anyway, it's not what I've done in this case.

The code is pretty minimal so here it is - not the full source but the relevant chunks. This is the event driven bit:

Code: Select all

\store eventv
LDA evntv:STA oldevntv
LDA evntv+1:STA oldevntv+1

...

\default rom=3
LDA#3
JSR romselect

\enable eventv
LDA #LO(show):STA evntv
LDA #HI(show):STA evntv+1
LDA #14:LDX #4: JSR osbyte

\Drop back to BASIC
RTS

\display contents of memory window
.show
PHP:PHA:TXA:PHA:TYA:PHA \save registers

\save rom
LDA &F4
STA oldrom

\insert rom
LDA romslot
JSR insrom

LDY #0
.showloop
LDA &8000,Y
STA screen,Y
INY
BNE showloop

\put back old rom
LDA oldrom
JSR insrom

PLA:TAY:PLA:TAX:PLA:PLP \restore registers

JMP (oldevntv)

...

\insert rom in A
.insrom
PHA
LDA #&0C
STA &F4
STA romsel

PLA
STA &F4
STA romsel
RTS

This is the "write memory" routine. It only fills up as far as &80C0, but that's not relevant. This version has the theoretically-redundant switching off of the VSYNC event - ie, the bit I needed to add to make it work.

Code: Select all

\Fill &8000-&80C0
.fill
PHA

\turn off vsync event
LDA#13
LDX#4
JSR osbyte

\save rom
LDA &F4
STA oldrom

\insert rom
LDA romslot
JSR insrom

PLA
LDY #0
.fillloop
STA &8000,Y
INY
CPY#&C0
BNE fillloop

\put back old rom
LDA oldrom
JSR insrom

\turn vsync event back on
LDA#14
LDX#4
JSR osbyte

RTS
I am encouraged that nobody has pointed out, so far, that I'm doing anything really stupid! But then again, that was before anyone saw my code...
Last edited by jms2 on Tue Apr 23, 2019 6:48 pm, edited 2 times in total.

Post Reply