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

Possibility set ADL offset for non-ADL code #78

Closed
nihirash opened this issue Apr 17, 2024 · 8 comments
Closed

Possibility set ADL offset for non-ADL code #78

nihirash opened this issue Apr 17, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@nihirash
Copy link

Sometimes, if you're writing code for legacy mode, you'll need use prefixed commands like LD.LIL for example:

ld.lil hl, (dma_ptr)

And current version will built binary with zero offset but MOS applications use $40000 base offset for all addresses and some of my code works in next page(with base offset $50000).

Currently, I'm using workaround with adding numeric constant for basic address offset like:

ld.lil hl, ($50000 + dma_ptr)

But if we'll introduce possibility compile non ADL programs with specified MB-offset - it will be great!

@envenomator
Copy link
Owner

envenomator commented Apr 18, 2024

The LD.LIL HL, (Mmn) opcode expects a 24-bit address to access the ADL space outside the non-ADL boundary of 64KB that the assembler works with in non-ADL mode.

@envenomator
Copy link
Owner

envenomator commented Apr 18, 2024

It's up to the programmer to specify an outside address, potentially derived from an outside-of-the assembler source.
However, it looks like you're trying to build a larger than 64KB binary, loaded by MOS as non-ADL mode and still reference data in that same binary in memory using the ADL statement.
Creating a 'mode' that requires checking every label statement AND they way it is used (adl/non-adl) for such a specific case; is that what you are asking?
I'm pretty sure this will have significant performance impact during assembly

@envenomator envenomator added the enhancement New feature or request label Apr 18, 2024
@nihirash
Copy link
Author

Let me show you on example: https://github.com/nihirash/ZINC/

I'm working on CP/M emulation layer for MOS and you can check my code 😸

For example, if I'll make something like(src/edos/edos.asm):

    ASSUME ADL=1
    org $5f000
    ASSUME ADL=0

It should work as I expect but it breaks on function table in edos/core.asm(cause addresses are 24 bit already and too large to fit into word-sized var).

Why I need ADL pointers? Cause MOS still have ADL only functions in file api and I need to provide full 24-bit address for them like for fread/fwrite(edos/disk.asm).

I'll be glad to any solution if it will make my code less magical.

But if it'll break usual use cases - I can keep this parts the same as now.

@envenomator
Copy link
Owner

I'm sure that your ask is legitimate, however it's still not clear to me what exactly it is you are asking.
It's a lot to ask anyone to 'check my code' to get an understanding of what they are actually asking. I've even perused some of it, but it's still not clear to me.

@nihirash
Copy link
Author

nihirash commented Apr 18, 2024

I need compile non ADL code with possibility use full prefixed full addressing commands(like here: https://github.com/nihirash/ZINC/blob/1ef1c1025fac78c328a38a7c74e3ee31378b39ac/src/edos/disk.asm#L209 )

I've spend some time with thinking about it and found that best way will be allow truncating addresses in ADL=0 mode to words(for this: https://github.com/nihirash/ZINC/blob/1ef1c1025fac78c328a38a7c74e3ee31378b39ac/src/edos/core.asm#L72 usage).

You can produce warning about truncating value to just 16 bit but allow storing them as words(in ADL=0 mode at least).

If I'll specify in ADL=1 mode full address obviously - it will be correct way to use it in prefixed mode and don't produce corner cases.

And after switching ADL off, I'd like have possibility store 16 bit pointers to links(warning here is ok).

For making things a bit more clear I've prepared isolated test-case:

    ASSUME ADL=1
    org $50100 ;; Setting address EXPLICITLY in ADL mode with MB page 

    ASSUME ADL=0 ;; Going to ADL off mode
start:
    ld.lil hl, test ;; Loading HL  with full address $5xxxx - this works fine here!
    ret

;; But I need use function table
fun_table:
    dw fun1 ;; Here should be 16 bit address $xxxx possibly with warning that address was truncated to 16 bits
    dw fun2 ;; but now compilations is failed
    dw fun3 ;; 

fun1:
    ld hl, 1
    ret

fun2:
    ld bc, 1
    ret

fun3:
    ld hl, 3
    ret
    
test:
    db "Hello"

Sorry for unclear explanation

@envenomator
Copy link
Owner

I think I understand what you are trying to do.
Normal immediate emission at an opcode doesn't even check the length in ADL=0, so for example LD HL,0xffffff in ADL=0 produces 0xffff as immediate after the 0x21 opcode without a warning currently.
The only place where I'm checking for the length of a value is in either DW or BLK*, which is what you need for the jumptable.

Let me ponder how to best approach this

@envenomator
Copy link
Owner

fixed in 24b86a9

@nihirash
Copy link
Author

Fix confirmed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants