From 08d1dd99ad7c9a52d2f745baade8ac187edd7d61 Mon Sep 17 00:00:00 2001 From: g012 Date: Sat, 23 Dec 2017 16:36:02 +0100 Subject: [PATCH] NES Hello World sample modified to define CHR data directly in source, like the VCS sample. --- nes.l65 | 39 +++++++++++++++++++++++++++++++------ samples/nes_ascii.chr | Bin 8192 -> 0 bytes samples/nes_hello.l65 | 44 ++++++++++++++++++++++++++++++++---------- vcs.l65 | 2 +- 4 files changed, 68 insertions(+), 17 deletions(-) delete mode 100644 samples/nes_ascii.chr 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 61cc2aaa2aa1f0db993d473054426ddf4b7d3df4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeH`A&=WI6vrPbimF0`1E-;Zf`EYlYv@!B4NX(QfK^r2fHf5y2(SVM`T>UaA@(7n z0&AcOJPn+xp`fWcG#!Yd{T=6Zokngd+3E5CdXB42XgM$v~dxGs<&(60Lo96Zg;jR~PxK_xa)LEuEOpuHzh-eqg-5G3NtZrsHBJ}vCl)vF-Yi#|PAul@YSB9|gXSUSpl|CY4C51z)>hUYiK(N0_-9ThlMotD z%;x^_;qks9W{n7;CuTVIcQ{cxvHf{yVm{IzQ9a`MM|McNx+bPa^WjHD%+6ZBbS*J` zsC_!0#QxI^Q4q6jce@?-$Her`6$Sm~U4IN8ktc5VWnS*L#6)|cRP0Zzn$P*F?TGoL zL%yV`$h7w;eVq%!n83v3@^SW_< z7hiS!J>pLyhAOpO=1gPOt}J7JVtiW=Xc_|Re*1zrBOc#5T`w;(lq&P#=ix z=qw{*I=_i!Vrt{F5_zIh9t&q!KM{S17qS1u=f!Nu6W=1{$eC8F`2sl;!?fBA;|Kby ZV&hR~;!;8khygJm2E>3E5Caz&_yxKQn5+N* 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)