Skip to content

Commit

Permalink
asm6: collect all SEGMENTs, not just zp/bss
Browse files Browse the repository at this point in the history
Turns out we need assignments within the corresponding ifdef, not
pulled out into a separate section.

for #9
  • Loading branch information
pinobatch committed Mar 31, 2019
1 parent 7b81f3e commit 66611dd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 64 deletions.
14 changes: 12 additions & 2 deletions unready/mk.sh
@@ -1,5 +1,15 @@
#!/bin/sh
set -e
python3 ../tools/pilbmp2nes.py sicktiles.png sicktiles.chr
asm6 shell.asm6 sick.nes

# Make sure we have a music file
OLDCWD=$(pwd)
echo "running in $OLDCWD"
cd ..
make obj/nes/musicseq.s
cd "$OLDCWD"

python3 ../tools/pilbmp2nes.py sicktiles.png sicktiles.chr < /dev/null
python3 sick.py < /dev/null > pently.asm6
asm6 -L shell.asm6 sick.nes sick.lst.txt
Mesen.exe sick.nes
#fceux sick.nes
25 changes: 25 additions & 0 deletions unready/ppuclear.asm6
@@ -0,0 +1,25 @@

ppu_clear_oam:
txa
and #$FC
tax
lda #$FF
@loop:
sta OAM,x
inx
inx
inx
inx
bne @loop
rts

ppu_screen_on:
stx PPUSCROLL
sty PPUSCROLL
sta PPUCTRL
lda #BG_ON
bcc @no_sprites
lda #BG_ON|OBJ_ON
@no_sprites:
sta PPUMASK
rts
34 changes: 3 additions & 31 deletions unready/shell.asm6
Expand Up @@ -36,16 +36,11 @@ enum $0010
oam_used: dsb 1
cur_keys: dsb 2
new_keys: dsb 2
pently_zptemp: dsb 5
; pently_zptemp: dsb 5
ende

OAM = $0200

; BSS variables
.enum $0300

.ende


; iNES header
db "NES",$1A
Expand Down Expand Up @@ -203,32 +198,9 @@ initial_palette:
hex 0f202a1a 0f242424 0f242424 0f242424
hex 0f27180f 0f381202 0f242424 0f242424

ppu_clear_oam:
txa
and #$FC
tax
lda #$FF
@loop:
sta OAM,x
inx
inx
inx
inx
bne @loop
rts

ppu_screen_on:
stx PPUSCROLL
sty PPUSCROLL
sta PPUCTRL
lda #BG_ON
bcc @no_sprites
lda #BG_ON|OBJ_ON
@no_sprites:
sta PPUMASK
rts

include "ppuclear.asm6"
include "metasprite.asm6"
;include "pently.asm6"

; Vectors
org $FFFA
Expand Down
66 changes: 35 additions & 31 deletions unready/sick.py
Expand Up @@ -35,7 +35,7 @@
import sys
import os
import re
from collections import defaultdict
from collections import OrderedDict
from itertools import chain

quotesRE = r"""[^"';]+|"[^"]*"|'[^']*'|;.*"""
Expand All @@ -57,6 +57,7 @@ def openreadlines(filename, xform=None):
filestoload = [
"pentlyconfig.inc", "pently.inc", "pentlyseq.inc",
"pentlysound.s", "../obj/nes/pentlybss.inc", "pentlymusic.s",
"../obj/nes/musicseq.s"
]

directive_ignore = {
Expand All @@ -75,13 +76,21 @@ def openreadlines(filename, xform=None):
lambda x: uncomment(x).strip())
for n in filestoload
]
specialseg = None
specialseg_lines = defaultdict(list)
inscope = 0
lines = []
for filename in filestoload:
lines.append('.segment ""')
lines.extend(openreadlines(os.path.join("../src", filename),
lambda x: uncomment(x).strip()))

known_segs = ['', 'ZEROPAGE', 'BSS']
seg_lines = OrderedDict()
for seg in known_segs:
seg_lines[seg] = []
cur_seg = ""
inscope = 0

anon_labels_seen = 0
anon_label_fmt = "@ca65toasm6_anonlabel_%d"
global_equates = []
def resolve_anon_ref(m):
s = m.group(0)
distance = len(s) - 2
Expand All @@ -92,7 +101,7 @@ def resolve_anon_ref(m):
else:
raise ValueError("unknown anonref %s" % s)

for line in chain(*allfiles):
for line in lines:
if not line: continue
words = line.split(None, 1)
label = None
Expand Down Expand Up @@ -121,42 +130,45 @@ def resolve_anon_ref(m):
# modify pentlyas to never omit arguments.
# https://forums.nesdev.com/viewtopic.php?f=2&t=18610
if word0 == 'ifblank':
lines.append('if 0')
seg_lines[cur_seg].append('if 0')
inscope += 1
continue
if word0 == 'ifnblank':
lines.append('if 1')
seg_lines[cur_seg].append('if 1')
inscope += 1
continue

if word0 == 'zeropage':
specialseg = 'zeropage'
cur_seg = 'ZEROPAGE'
continue
if word0 == 'bss':
specialseg = 'bss'
cur_seg = 'BSS'
continue
if word0 == 'segment':
specialseg = None
cur_seg = words[1].strip('"').upper()
seg_lines.setdefault(cur_seg, [])
continue
if word0 == 'scope':
lines.append('rept 1')
seg_lines[cur_seg].append('rept 1')
inscope += 1
continue
if word0 == 'proc':
lines.append('%s: rept 1' % words[1])
seg_lines[cur_seg].append('%s: rept 1' % words[1])
inscope += 1
continue
if word0 in ('endscope', 'endproc'):
lines.append('endr')
seg_lines[cur_seg].append('endr')
inscope -= 1
continue

# Macro is considered a "scope" so that "name =" doesn't
# get moved out to global includes
if word0 == 'macro':
lines.append('macro ' + words[1])
seg_lines[cur_seg].append('macro ' + words[1])
inscope += 1
continue
if word0 == 'endmacro':
lines.append('endm')
seg_lines[cur_seg].append('endm')
inscope -= 1
continue

Expand All @@ -174,13 +186,11 @@ def resolve_anon_ref(m):
equate = equateRE.match(line)
if equate:
label, expr = equate.groups()
# Not sure if I want EQU or =, as EQU is for string replacement
# and = is for numbers, but I don't know if = is required to be
# constant at the time that line is assembled.
# Not sure if I want EQU or =, as EQU is for string
# replacement (like ca65 .define) and = is for numbers,
# but I don't know if = is required to be constant
# at the time that line is assembled.
words = [label, "=", expr]
if False and not specialseg and not inscope:
global_equates.append(" ".join(words))
continue
label = None

if len(words) > 1:
Expand All @@ -196,14 +206,8 @@ def resolve_anon_ref(m):
line = " ".join(words)
if label:
line = "%s: %s" % (label, line)
if specialseg:
specialseg_lines[specialseg].append(line)
else:
lines.append(line)
seg_lines[cur_seg].append(line)

print("\n".join(global_equates))
for segment, seglines in specialseg_lines.items():
print(";;; VARIABLES SEGMENT %s" % segment)
for segment, seglines in seg_lines.items():
print(";;; SEGMENT %s" % segment)
print("\n".join(seglines))

print("\n".join(lines))

0 comments on commit 66611dd

Please sign in to comment.