Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a phrase with literals #11

Closed
dmemphis opened this issue Apr 10, 2015 · 2 comments
Closed

Building a phrase with literals #11

dmemphis opened this issue Apr 10, 2015 · 2 comments

Comments

@dmemphis
Copy link

So I was trying to make the phrases more legible than hex numbers.
But I ran into a snag I think- you can't use consts to build a phrase?
Check this out- I build a phrase with hex digits and build the same
phrase with constants. They don't display the same thing.
It would be nice if this was supported. What do you think?

: font
0x20 0x20 0x20 0x00 0x20 0xF0 0x10 0x70 0x00 0x40 0xE0 0x90 0xE0 0x90 0x90 0x90
0xE0 0x90 0xE0 0x90 0xE0 0x80 0x80 0xD0 0xB0 0xB0 0x90 0x90 0x90 0x90 0x60 0x60
0x90 0x90 0x90 0x60 0x90 0xD0 0xB0 0x90 0x90 0x90 0x50 0x20 0x40 0x00 0x00 0x00
0x00 0x00 0x60 0x90 0xF0 0x90 0x90 0xF0 0x90 0x90 0xF0 0x80 0xE0 0x80 0x80 0x80
0x80 0xF0 0x80 0xE0 0x80 0xF0 0x40 0x40 0x40 0xF0 0x20 0x40 0x80 0xF0 0x20 0x20
0x20 0xC0 0x60 0x90 0x80 0x90 0x60 0x90 0x90 0xB0 0x70 0x80 0xB0 0x90 0x70 0x80
0x60 0x10 0xE0 0x90 0xA0 0xC0 0xA0 0x90 0x90 0xB0 0xB0 0xD0 0xF0 0x40 0x40 0x40
0x40 0x90 0x90 0x70 0x10 0xE0

: readyLiteral
0x0A 0x41 0x32 0x0C 0x71

:const iR 0x0A
:const iE 0x41
:const iA 0x32
:const iD 0x0C
:const iY 0x71

: readyConst
iR iE iA iD iY

: draw-text
v1 := 2 # x
#v2 := 1 # y
v3 := 0 # byte
# v4 contains length
loop
: text-addr i := 0 # draw phrase modifies to phrase addr
i += v3 # inc to next char in phrase
load v0 # lad char offest into v0 from i
i := font # now make i beginging of font
i += v0 # add char offset. i is pointing to sprite.

    sprite v1 v2 5
    v1 += 5
    if v1 == 62 then v2 += 6
    if v1 == 62 then v1 := 2
    v3 += 1
    if v3 != v4 then
again

;

: draw-ready-literal
:unpack 0xA readyLiteral # Get address of phrase into v1 v2
i := text-addr # load addrss of loop init in draw-text
save v1 # save v1/v2 into loop init code
v4 := 5 # load count of chars
draw-text
;

: draw-ready-const
:unpack 0xA readyConst
i := text-addr
save v1
v4 := 5
draw-text
;

: wait
v0 := 128
delay := v0
loop
v0 := delay
if v0 != 0 then
again
;

: stop
: here jump here

: main
v2 := 1
draw-ready-literal
v2 := 10
draw-ready-const
stop

@JohnEarnest
Copy link
Owner

I replied to your email, but just for the purposes of keeping things documented I'll summarize here:

Constants declared with :const are treated exactly like labels when used outside of instructions. The difference between the patterns here is that the constant references are compiled into calls to subroutines. This functionality is already used for building jump tables and by the disassembler for various reasons. It would be possible to alter the semantics of :const to get the desired behavior, but I think a better resolution would be to create a new construct with this type of purpose in mind.

One proposal is the addition of a :macro operative which would allow you to assign a name to a pattern of bytes which would be inlined wherever the name of the macro was used. A particularly nice aspect of this system is it could serve to simplify some parts of the existing assembler and make it easier to experiment with custom extended instruction sets. I'll give the precise syntax and semantics some thought and update this issue when I come to a final decision.

@JohnEarnest
Copy link
Owner

The new :macro facility resolves this nicely, as I'd hoped when I originally suggested it. The following program:

:macro foo { 0xAA }
:macro bar { 0xBB }

: main
	foo
	bar

Will compile as the bytes 0xAA 0xBB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants