diff --git a/nes.l65 b/nes.l65 index 071e52c..4c52d5b 100644 --- a/nes.l65 +++ b/nes.l65 @@ -274,7 +274,11 @@ end local n0ne = function(x) return not x or x == 0 end local val0 = function(x) return x and x or 0 end --- https://wiki.nesdev.com/w/index.php/NROM +--[[ + https://wiki.nesdev.com/w/index.php/NROM + 4kB chrroms are created, unless t.onechrrom is set, in which case only one big chrrom + location is created instead. +]] mappers.NROM = function(t) if not t then t = {} end if not t.prgsize then t.prgsize = 16384 end @@ -285,14 +289,29 @@ mappers.NROM = function(t) local prgstart = 0x10000 - t.prgsize hdrrom = location{prgstart - 16, prgstart - 1, name='header'} header(t) - prgrom = location{prgstart, 0xffff, name='prgrom'} + prgrom0 = location{prgstart, 0xffff, name='prgrom'} + prgrom = prgrom0 section{"vectors", org=0xfffa} dc.w nmi, main, irq - if (t.chrsize > 0) then chrrom = location{0x10000, 0x10000 + 0x1fff, name='chrrom'} end + if (t.chrsize > 0) then + if t.onechrrom then + chrrom0 = location{0x10000, 0x10000 + 0x1fff, name='chrrom'} + else + for ci=0,1 do + local o = 0x10000 + ci*0x1000 + _ENV['chrrom'..ci] = location{o, o+0xfff, name='chrrom'..ci} + end + end + chrrom = chrrom0 + end end mappers[0] = mappers.NROM --- https://wiki.nesdev.com/w/index.php/UxROM --- Has bus conflicts. +--[[ + https://wiki.nesdev.com/w/index.php/UxROM + Has bus conflicts. + 4kB chrroms are created, unless t.onechrrom is set, in which case only one big chrrom + location is created instead. +]] mappers.UxROM = function(t) if not t then t = {} end t.mapperid = 2 @@ -313,7 +332,15 @@ mappers.UxROM = function(t) @@bankbytes -- for handling bus conflicts for i=0,bc-2 do byte(i) end local chrstart = 0x8000 + bc*0x4000 - chrrom = location{chrstart, chrstart + 0x1fff, name='chrrom'} + if t.onechrrom then + chrrom0 = location{chrstart, chrstart + 0x1fff, name='chrrom'} + else + for ci=0,1 do + local o = chrstart + ci*0x1000 + _ENV['chrrom'..ci] = location{o, o+0xfff, name='chrrom'..ci} + end + end + chrrom = chrrom0 function switchprgrom(bankix) assert(bankix < bc-1) lda #bankix tax sta bankbytes,x diff --git a/samples/nes_ascii.chr b/samples/nes_ascii.chr deleted file mode 100644 index 61cc2aa..0000000 Binary files a/samples/nes_ascii.chr and /dev/null differ diff --git a/samples/nes_hello.l65 b/samples/nes_hello.l65 index 14a1f71..a88fd06 100644 --- a/samples/nes_hello.l65 +++ b/samples/nes_hello.l65 @@ -2,20 +2,44 @@ require'nes' mappers.NROM() -location(chrrom) +location(chrrom0) -do - -- nes_ascii.chr: MIT License Copyright (c) 2016 Doug Fraker, www.nesdoug.com - local f = assert(io.open('nes_ascii.chr', 'rb')) - local d = f:read('*a') f:close() - @@chrdata byte(d) -end +local font = section{"font", org=chrrom0.start} + dc.b 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -- + 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.b 0xee,0x66,0x66,0x7e,0x66,0x66,0xee,0x00,0xee,0x66,0x66,0x7e,0x66,0x66,0xee,0x00 -- H + dc.b 0x3c,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x3c,0x00 -- I + dc.b 0x0e,0x06,0x06,0xc6,0xc6,0xce,0x7c,0x00,0x0e,0x06,0x06,0xc6,0xc6,0xce,0x7c,0x00 -- J + dc.b 0xce,0xdc,0xf8,0xf0,0xf8,0xdc,0xce,0x00,0xce,0xdc,0xf8,0xf0,0xf8,0xdc,0xce,0x00 -- K + dc.b 0xc0,0xc0,0xc0,0xc0,0xc6,0xc6,0xfe,0x00,0xc0,0xc0,0xc0,0xc0,0xc6,0xc6,0xfe,0x00 -- L + dc.b 0xc6,0xee,0xfe,0xd6,0xc6,0xc6,0xc6,0x00,0xc6,0xee,0xfe,0xd6,0xc6,0xc6,0xc6,0x00 -- M + dc.b 0xc6,0xe6,0xf6,0xde,0xce,0xc6,0xc6,0x00,0xc6,0xe6,0xf6,0xde,0xce,0xc6,0xc6,0x00 -- N + dc.b 0x7c,0xee,0xc6,0xc6,0xc6,0xee,0x7c,0x00,0x7c,0xee,0xc6,0xc6,0xc6,0xee,0x7c,0x00 -- O + dc.b 0xfc,0xc6,0xc6,0xc6,0xfc,0xc0,0xc0,0x00,0xfc,0xc6,0xc6,0xc6,0xfc,0xc0,0xc0,0x00 -- P + dc.b 0x7c,0xce,0xc6,0xc6,0xde,0xec,0x7e,0x00,0x7c,0xce,0xc6,0xc6,0xde,0xec,0x7e,0x00 -- Q + dc.b 0xfc,0x66,0x66,0x7c,0x58,0x6c,0xe6,0x00,0xfc,0x66,0x66,0x7c,0x58,0x6c,0xe6,0x00 -- R + dc.b 0x7c,0xc6,0xc0,0x7c,0x06,0xc6,0x7c,0x00,0x7c,0xc6,0xc0,0x7c,0x06,0xc6,0x7c,0x00 -- S + dc.b 0xfe,0x92,0x10,0x10,0x10,0x10,0x38,0x00,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 location(prgrom) @@nmi rti @@irq rti -local hello = "Hello World!" +local font_start = (font.org - chrrom0.start) // 16 +charset(" abcdefghijklmnopqrstuvwxyz", \x(x+font_start)) +local hello = "hello world" @@text byte(hello) @@main @@ -29,8 +53,8 @@ local hello = "Hello World!" ldy #0 @_loadtxt lda text,y sta PPUDATA iny cpy ##hello bne _loadtxt -- reset scroll position ppu_addr(0) sta BGSCROL sta BGSCROL - -- turn screen on - lda #0x90 sta PPUCTRL lda #0x1e sta PPUMASK + -- show BG + lda #0x0a sta PPUMASK -- idle @_loop jmp _loop diff --git a/vcs.l65 b/vcs.l65 index a834aac..5df063e 100644 --- a/vcs.l65 +++ b/vcs.l65 @@ -375,7 +375,7 @@ mappers.X07 = function() end -------------------------------------------------------------------------------- --- Image converters +-- Data converters -------------------------------------------------------------------------------- image_scan = function(img, opt)