Code: Select all
#define _protected_a_start = $100 // reserve $100-$1FF
#define _protected_a_end = $1FF
Code: Select all
program alloc_13K50
device = 18F13K50
// the 18F13K50 has 512 bytes of total ram, but it's split into two banks with
// an unused block of data memory in between them...
// 000-0FF 256 bytes
// 100-1FF <unused>
// 200-2FF 256 bytes (gen purpose/usb ram)
//
// by default, the SF device file has '_maxram' set for 256 bytes
// _maxram = $100
// and the bank of ram from $200-$2FF is unusable by SF
//
// here we're going to tell SF that the part has 768 bytes of ram (000-$2FF),
// but then tell it to reserve the block from $100-$1FF so as not to use it
//
#variable _maxram = $300 // 768 bytes of ram
#define _protected_a_start = $100 // reserve $100-$1FF
#define _protected_a_end = $1FF
// the SF system variables take up the first 25 bytes of bank0, so allocate
// the remaining part of the bank. normally, this would be the limit...
// 256-25 = 231 bytes of user ram
const SYSVARS = 25
dim bank0(256-SYSVARS) as byte
// now, we can allocate an additional 256 bytes of ram, and this will
// come from the $200-$2FF bank, skipping the unused area
dim bank2(256) as byte
// demonstrate that the memory allocations work
clear(bank0)
clear(bank2)
bank0(0) = $01
bank0(bound(bank0)) = $11
bank2(0) = $02
bank2(bound(bank2)) = $22
end program