← Optimizing Buggy Boy (1)Optimizing Buggy Boy (2) →
  Overlay Memory
Sun 10th May 2020   
A commonly misunderstood element of Oric computers is the actual memory layout and amount: Does the Oric has 48KB or RAM, as the Atmos label says, or 64KB as claims the Oric Nova 64?

The actual truth is somewhat in-between!

8 bit processor

The 6502 processor, like many other 8 bit processors, is only able to address a 16 bit address range, from $0000 (0) to $FFFF (65535).

In this address range we must be able to fit the zero page, the I/O area to talk with hardware expansion, the video memory, and the system ROM.

Many machines are using some more or less complicated "banking" systems allowing you to select what will be accessible in some particular areas of the addressing range, which makes it possible to provide more RAM or ROM by dynamically enabling or disabling parts of the system so other can be used.

Some, like the C64 even include this feature on the processor itself1

The Oric Telestrat uses a second VIA to perform the access to the two possible cartridge ports, but I will not speak more about this machine specific set of features.

Atmos 48K or 64K?

So, to go back to the previous question, the answer is that the Oric Atmos 48K does have 64K of RAM, unfortunately since the machine was built using as few as possible components2, the top 16K of memory are not accessible at all because they are hidden behind the 16KB of ROM containing the Oric BASIC.

So yes, it's an Atmos 64K, but consumer associations would probably have contested the claim in a court of law, so there you go.

Now, the good thing is that it is possible to use these additional 16KB of RAM, at the condition that you use a floppy disk controller.

4 video modes

Oric Disk Controller

When you connect an Oric floppy disk unit (Microdisc or Jasmin will both work fine), the controller board brings the missing part of the puzzle in the form of additional hardware registers you can access in page 3.

A part of these registers are used to talk to the Western Digital Floppy Disk Controller chip, but also to select what you will see when you try to access the top 16K of RAM.

On the Microdisc, the location $314 points to a 8bit register which contains two interesting bits for us:
  • Bit 1: Disables the internal BASIC ROM when set to zero
  • Bit 7: Disables the disk controller boot EPROM
So basically, all you have to do3 to access the top 16K of RAM is the following:

lda #%11111101
sta $314

What that means in practice, is that if you are making a small single file Oric game or demo, if you are running out of memory you can just very simply use Tap2DSK to make a Floppy version of your demo, and with these two lines of codes you can get the additional memory!

The Jasmin disk drive controller has something similar, except is uses two different registers:
  • Bit 0 of location $3FA: Enables the Overlay RAM when set to one
  • Bit 0 of location $3FB: Disables the internal BASIC ROM when set to one
If you are wondering what happens when both the Overlay RAM AND the Basic ROM are disabled, well, that's easy:

The Disk controller maps its own Eprom that contains the bootstrap code.

Before you jump with your two feet forward and try to take this RAM all for you, you need to consider the negative consequences!

Negatives

Obviously, if you disable the ROM, it means you don't have access to the ROM functions, which probably means that many of the OSDK functions that were just simple mappings to the Oric Atmos Rom will stop working: paper, ink, hires, text, key, get, printf, curset, draw, fill, sound, play, music, etc... are all ROM functions, so these will stop working.

Another important parameter is that you will have to implement your own IRQ handler, because the normal Oric IRQ that handles keyboard, timers, and your own callback in page 2 will not happen, and most probably the machine will crash as soon as it tries to perform an IRQ!

Positives

Among the positive things, we can find the following:
  • Pretty much all the top 16K of RAM are free for you to use!
  • The Page 2 is free for you to use as well!
  • As is the entire zero page!
  • And the Page 4 is free as well
  • Much faster IRQ!
You get the faster IRQ because instead of having a trampoline system with some intermediate hook points to allow for user defined timer routines, running at a 100Hz frequency, you can just install your own IRQ handler, knowing exactly when it runs at half the frequency.

Implementation Example

Here is a simple example that just enables the overlay RAM on a Microdisc based system, that setups a 50HZ IRQ handler that reads the arrow keys and the space bar:


.zero

_gKey .dsb 1
_VblCounter .dsb 1

save_a .dsb 1
save_x .dsb 1
save_y .dsb 1

.text

_InstallIRQHandler
; Stop the IRQ while we are setting up stuff
sei

; Enable overlay RAM
lda #%11111101
sta $314

; Reset the VBL counter
lda #0
sta _VblCounter

; Set the VIA parameters for a 50Hz IRQ
lda #<19960
sta $306
lda #>19960
sta $307

; Our new IRQ handler
lda #<IRQHandler
sta $FFFE
lda #>IRQHandler
sta $FFFF

; Enable the IRQ again and quit
cli
rts


IRQHandler
; Mark the IRQ as served
bit $304

; For the "VSync" delay
inc _VblCounter

; Save the registers
sta save_a
stx save_x
sty save_y

; Read the first row of the keyboard
jsr ReadKeyboard

; Restore the registers
lda save_a
ldx save_x
ldy save_y

; Return from IRQ
rti


_VSync
.(
pha
loop_wait
lda _VblCounter
beq loop_wait
lda #0
sta _VblCounter
pla
rts
.)


ReadKeyboard
lda #00
sta _gKey

read_left
ldx #$df
jsr KeyboardSetUp
beq read_right
lda _gKey
ora #1
sta _gKey

read_right
ldx #$7f
jsr KeyboardSetUp
beq read_up
lda _gKey
ora #2
sta _gKey

read_up
ldx #$f7
jsr KeyboardSetUp
beq read_down
lda _gKey
ora #4
sta _gKey

read_down
ldx #$bf
jsr KeyboardSetUp
beq read_fire
lda _gKey
ora #8
sta _gKey

read_fire
ldx #$fe
jsr KeyboardSetUp
beq read_end
lda _gKey
ora #16
sta _gKey

read_end
rts


KeyboardSetUp
;x=column a=row
lda #04
sta $300
lda #$0e
sta $30f
lda #$ff
sta $30c
ldy #$dd
sty $30c
stx $30f
lda #$fd
sta $30c
sty $30c
lda $300
and #08
rts

and a small C code to go with that:

extern unsigned char gKey;

void InstallIRQHandler();
void VSync();

void main()
{
InstallIRQHandler();

do
{
VSync();
if (gKey & 1) // LEFT
{
}
if (gKey & 2) // RIGHT
{
}
if (gKey & 4) // UP
{
}
if (gKey & 8) // DOWN
{
}
}
while (!(gKey & 16)); // SPACE
}

and a final trick for you: The reason the printf command does not work, is because it calls the Text display code in the ROM, but you can still display text by using sprintf instead.

Just use (char*)0xBB80+X+Y*40 as the destination buffer address, and the string formating will properly appear on the screen!


1. The MOS 6510 is a standard 6502 with an additional set of pins to allow for bank selection
2. They could have been using the free PB5 pin on the VIA to do that
3. Obviously, if you are planning to do some disk accesses after, you should do proper masking of the bits you want to change
comments powered by Disqus

Coverity Scan Build Status