[NES] Added UNROM-512 mapper and sample

This commit is contained in:
g012 2024-04-11 14:37:13 +02:00
parent 5f71b92bcd
commit 31cccce3e1
8 changed files with 665 additions and 532 deletions

View File

@ -71,6 +71,7 @@ Table of Contents
* [Windows](#windows)
* [Linux](#linux)
* [Vim files installation](#vim-files-installation)
* [Visual Studio Code extension](#vscode-extension)
* [TODO List](#todo-list)
* [Credits](#credits)
* [License](#license)
@ -656,6 +657,10 @@ make
Note that the syntax file includes some highlighting for features only activated via pragmas: `dna`, `xsr`, `rtx` and `far`. If you do not want to use these keywords, remove them from the syntax file.
## Visual Studio Code extension
Install the "l65" extension from the marketplace or check [l65-vscode](https://github.com/g012/l65-vscode) repository.
## TODO List
* [k65](http://devkk.net/wiki/index.php?title=K65) style syntax

View File

@ -101,7 +101,8 @@ M.link = function()
end
for _,constraint in ipairs(section.constraints) do
local cstart, cfinish = address+constraint.start, address+constraint.finish
if rorg(cstart) // 0x100 == rorg(cfinish) // 0x100 then
local s, f = rorg(cstart) // 0x100, rorg(cfinish) // 0x100
if s==f or math.ceil(s)==math.floor(s) and s+1==f and cfinish-cstart==0x100 then
if constraint.type == 'crosspage' then return end
else
if constraint.type == 'samepage' then return end
@ -259,7 +260,7 @@ M.link = function()
return waste, cross, lsb
end)
if not position then
error("unable to find space for section " .. section.label)
error("unable to find space for related section '" .. section.label .. "' of size " .. section.size)
end
for section,offset in pairs(related) do
section.org = position + (section.location.start - location_start) + offset
@ -273,7 +274,7 @@ M.link = function()
table.sort(position_independent_sections, function(a,b) if a.size==b.size then return a.label>b.label end return a.size>b.size end)
for _,section in ipairs(position_independent_sections) do
if not position_section(section) then
error("unable to find space for section " .. section.label)
error("unable to find space for section '" .. section.label .. "' of size " .. section.size)
end
end

54
nes.l65
View File

@ -405,7 +405,7 @@ mappers.UxROM = function(t)
until off + sz >= t.chrsize
chrrom = chrrom0
function switchprgrom(bankix)
if bankix then assert(bankix < bc-1) lda #bankix end
if bankix then assert(bankix < bc, "mappers.switchprgrom: bank out of range: " .. bankix .. ", expected 0-" .. (bc-1)) lda #bankix end
-- lda to reverse map [n..0] to [0..n]
tax lda bankbytes,x sta bankbytes,x
end
@ -415,6 +415,58 @@ mappers.UxROM = function(t)
end
mappers[2] = mappers.UxROM
--[[
https://www.nesdev.org/wiki/UNROM_512
]]
mappers.UNROM512 = function(t)
if not t then t = {} end
t.mapperid = 30
if not t.prgsize then t.prgsize = 32 * 16384 end
assert(t.prgsize >= 0x8000 and t.prgsize <= 0x80000, "prgsize must be at least 32kB and at most 512kB")
assert(n0ne(t.chrsize), "chrsize must be 0")
if n0ne(t.chrramsize) and n0ne(t.chrbramsize) then t.chrramsize = 4 * 8192 end
local csize = val0(t.chrramsize) + val0(t.chrbramsize)
assert(csize == 0x2000 or csize == 0x4000 or csize == 0x8000, "combined chrram size must be 8, 16 or 32kB")
hdrrom = location{0x7ff0, 0x7fff, name='header'}
header(t)
local bc = t.prgsize//0x4000
for bi=0,bc-2 do
local o,ix = 0x8000 + bi*0x4000, bc-1-bi
_ENV['prgrom'..ix] = location{o, o+0x3fff, rorg=0x8000, name='prgrom'..ix}
end
local prglast = 0x8000 + (bc-1)*0x4000
prgrom0 = location{prglast, prglast+0x3fff, rorg=0xc000, name='prgrom0'}
prgrom = prgrom0
section{"vectors", org=prglast+0x3ffa} dc.w nmi, main, irq
section{ "bankbytes", align=256 } -- for handling bus conflicts
for m=0,1 do
for c=0,3 do
for p=0x1f,0,-1 do byte(m<<7 | c<<5 | p) end
end
end
function clearchrram(page_count, offset)
ppu_addr(CHAR0 + (offset or 0)) tay ldx#(page_count or 32) @_clear sta PPUDATA iny bne _clear dex bne _clear
end
function loadchrram(var, page_count, offset)
ppu_addr(CHAR0 + (offset or 0)) ldx#(page_count or 32) ldy#0 @_load lda (var),y sta PPUDATA iny bne _load inc var+1 dex bne _load
end
function switch(prgbankix, chrbankix, mirror)
if prgbankix then assert(prgbankix < bc, "mappers.switch: PRG bank out of range: " .. prgbankix .. ", expected 0-" .. (bc-1)) end
if chrbankix then assert(chrbankix < 4, "mappers.switch: CHR bank out of range: " .. chrbankix .. ", expected 0-3") end
if mirror then assert(mirror == 0 or mirror == 1, "mappers.switch: mirror out of range: " .. mirror .. ", expected 0-1") end
if prgbankix or chrbankix or mirror then
local r = (mirror or 0)<<7 | (chrbankix or 0)<<5 | (prgbankix or 1)
lda #r
end
-- lda to reverse prg map [n..0] to [0..n]
tax lda bankbytes,x sta bankbytes,x
end
mappers.init = function()
switch(1)
end
end
mappers[30] = mappers.UxROM
--[[
https://wiki.nesdev.com/w/index.php/CNROM
Has bus conflicts.

75
samples/nes_chrram.l65 Normal file
View File

@ -0,0 +1,75 @@
require'nes'
mappers.UNROM512()
location(prgrom1)
local font_size = 27 * 16
@@font
dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -- <SPC>
dc.b 0x38,0x38,0x2c,0x64,0x7e,0x46,0xce,0x00,0x38,0x38,0x2c,0x64,0x7e,0x46,0xce,0x00 -- A
dc.b 0xfc,0x62,0x66,0x7c,0x62,0x66,0xfc,0x00,0xfc,0x62,0x66,0x7c,0x62,0x66,0xfc,0x00 -- B
dc.b 0x7c,0xe6,0xc2,0xc0,0xc0,0xe6,0x7c,0x00,0x7c,0xe6,0xc2,0xc0,0xc0,0xe6,0x7c,0x00 -- C
dc.b 0xfc,0x4e,0x46,0x46,0x46,0xce,0xfc,0x00,0xfc,0x4e,0x46,0x46,0x46,0xce,0xfc,0x00 -- D
dc.b 0xfe,0x66,0x60,0x7c,0x60,0x66,0xfe,0x00,0xfe,0x66,0x60,0x7c,0x60,0x66,0xfe,0x00 -- E
dc.b 0xfe,0x66,0x60,0x7c,0x60,0x60,0xf0,0x00,0xfe,0x66,0x60,0x7c,0x60,0x60,0xf0,0x00 -- F
dc.b 0x7c,0xe6,0xc0,0xce,0xc6,0xe6,0x7c,0x00,0x7c,0xe6,0xc0,0xce,0xc6,0xe6,0x7c,0x00 -- G
dc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,0xfe,0x92,0x10,0x10,0x10,0x10,0x38,0x00 -- T
dc.b 0xe6,0xe6,0xc2,0xc2,0xc2,0xe6,0x7c,0x00,0xe6,0xe6,0xc2,0xc2,0xc2,0xe6,0x7c,0x00 -- U
dc.b 0xc6,0xc6,0xc6,0x6c,0x6c,0x38,0x38,0x00,0xc6,0xc6,0xc6,0x6c,0x6c,0x38,0x38,0x00 -- V
dc.b 0xc6,0xc6,0xd6,0xfe,0xee,0xc6,0x82,0x00,0xc6,0xc6,0xd6,0xfe,0xee,0xc6,0x82,0x00 -- W
dc.b 0x86,0xcc,0x78,0x30,0x78,0xcc,0x86,0x00,0x86,0xcc,0x78,0x30,0x78,0xcc,0x86,0x00 -- X
dc.b 0xc6,0xc6,0x6c,0x38,0x18,0x18,0x38,0x00,0xc6,0xc6,0x6c,0x38,0x18,0x18,0x38,0x00 -- Y
dc.b 0x7e,0xce,0x98,0x30,0x62,0xe6,0xfc,0x00,0x7e,0xce,0x98,0x30,0x62,0xe6,0xfc,0x00 -- Z
-- RAM
chr = 0
location(prgrom)
@@nmi rti
@@irq rti
charset(" abcdefghijklmnopqrstuvwxyz")
local hello = "hello world"
@@text byte(hello)
@@main
init()
clearchrram()
-- load font in CHR RAM
ppu_addr(CHAR0)
lda #font&0xff sta chr lda #font>>8 sta chr+1
ldy #0 @_loadfnt1 lda (chr),y sta PPUDATA iny bne _loadfnt1
inc chr+1
@_loadfnt2 lda (chr),y sta PPUDATA iny cpy #font_size-256 bne _loadfnt2
-- load BG palette in PPU RAM
ppu_addr(BGPAL)
for _,v in ipairs{ 0x1f, 0x00, 0x10, 0x20 } do lda #v sta PPUDATA end
-- load screen text in PPU RAM 0x21CA
ppu_addr(0x21ca)
ldy #0 @_loadtxt lda text,y sta PPUDATA iny cpy ##hello bne _loadtxt
-- reset scroll position
ppu_addr(0) sta BGSCROL sta BGSCROL
-- show BG
vblank_waitbegin()
lda #0x0a sta PPUMASK
-- idle
@_loop jmp _loop
writebin(filename..'.nes')
writesym(filename..'.mlb', 'mesen')
writesym(filename..'.nes', 'fceux')
print(stats)

View File

@ -577,7 +577,7 @@ syn match l65Opcode /\<sre\%(.[bw]\)\=\>/
syn match l65Opcode /\<far\>/
syn match l65Opcode /\<rtx\>/
syn match l65Opcode /\<xsr\>/
" Common alias, reomve if desired.
" Common alias, remove if desired.
syn match l65Opcode /\<dna\%(.[bw]\)\=\>/
syn match l65Keyword /\<dnaimm\>/
syn match l65Keyword /\<dnazpg\>/